From 063b99593ac556203cf31325e279707c8445548c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Sep 2024 15:05:48 +0000 Subject: [PATCH 01/35] build(deps): bump github/super-linter from 6 to 7 Bumps [github/super-linter](https://github.com/github/super-linter) from 6 to 7. - [Release notes](https://github.com/github/super-linter/releases) - [Changelog](https://github.com/github/super-linter/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/super-linter/compare/4e51915f4a812abf59fed160bb14595c0a38a9e7...b807e99ddd37e444d189cfd2c2ca1274d8ae8ef1) --- updated-dependencies: - dependency-name: github/super-linter dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 42e8b99d0..ac593cbeb 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -29,7 +29,7 @@ jobs: # Run Linter against code base # ################################ - name: Lint Code Base - uses: github/super-linter/slim@4e51915f4a812abf59fed160bb14595c0a38a9e7 # v6 + uses: github/super-linter/slim@b807e99ddd37e444d189cfd2c2ca1274d8ae8ef1 # v7 env: DEFAULT_BRANCH: main VALIDATE_CPP: false From 39473607dc315b89b4614e60d134649355acda8e Mon Sep 17 00:00:00 2001 From: Lukas G <20104521+zLukas@users.noreply.github.com> Date: Mon, 16 Dec 2024 17:40:47 +0100 Subject: [PATCH 02/35] update commit sha --- .github/workflows/linter.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ac593cbeb..89d4df569 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -29,7 +29,8 @@ jobs: # Run Linter against code base # ################################ - name: Lint Code Base - uses: github/super-linter/slim@b807e99ddd37e444d189cfd2c2ca1274d8ae8ef1 # v7 + uses: github/super-linter/slim@b92721f792f381cedc002ecdbb9847a15ece5bb8 # v7 + env: DEFAULT_BRANCH: main VALIDATE_CPP: false From dcf986eb58217388454d430beb84d55d2fa89719 Mon Sep 17 00:00:00 2001 From: Lukas G <20104521+zLukas@users.noreply.github.com> Date: Wed, 19 Feb 2025 17:08:46 +0100 Subject: [PATCH 03/35] Update linter.yml --- .github/workflows/linter.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 89d4df569..0521fe467 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -39,3 +39,8 @@ jobs: VALIDATE_CHECKOV: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN + FIX_MARKDOWN_PRETTIER: true + FIX_MARKDOWN: true + FIX_PYTHON_BLACK: true + FIX_PYTHON_ISORT: true + From ef9144b60560769a31bb992592e4bcf5b026871b Mon Sep 17 00:00:00 2001 From: Lukas G <20104521+zLukas@users.noreply.github.com> Date: Wed, 19 Feb 2025 17:17:08 +0100 Subject: [PATCH 04/35] Update linter.yml --- .github/workflows/linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0521fe467..5da83523b 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -43,4 +43,5 @@ jobs: FIX_MARKDOWN: true FIX_PYTHON_BLACK: true FIX_PYTHON_ISORT: true + FIX_YAML_PRETTIER: true From b7b1840ee4748ebeed9153ea2731b1c05ecc15d9 Mon Sep 17 00:00:00 2001 From: Lukas G <20104521+zLukas@users.noreply.github.com> Date: Wed, 19 Feb 2025 21:14:59 +0100 Subject: [PATCH 05/35] Update linter.yml --- .github/workflows/linter.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 5da83523b..93db08861 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -41,7 +41,4 @@ jobs: LOG_LEVEL: WARN FIX_MARKDOWN_PRETTIER: true FIX_MARKDOWN: true - FIX_PYTHON_BLACK: true - FIX_PYTHON_ISORT: true - FIX_YAML_PRETTIER: true From 96c32b165ca60dbbe29821bdd0e9f9f41af489e0 Mon Sep 17 00:00:00 2001 From: Lukas G <20104521+zLukas@users.noreply.github.com> Date: Wed, 19 Feb 2025 22:21:02 +0100 Subject: [PATCH 06/35] Update linter.yml --- .github/workflows/linter.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 93db08861..5da83523b 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -41,4 +41,7 @@ jobs: LOG_LEVEL: WARN FIX_MARKDOWN_PRETTIER: true FIX_MARKDOWN: true + FIX_PYTHON_BLACK: true + FIX_PYTHON_ISORT: true + FIX_YAML_PRETTIER: true From 8ec42361f89461ecb5f64c2e9c4681eb89a96960 Mon Sep 17 00:00:00 2001 From: Lukas G <20104521+zLukas@users.noreply.github.com> Date: Wed, 19 Feb 2025 22:22:34 +0100 Subject: [PATCH 07/35] Update linter.yml --- .github/workflows/linter.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 5da83523b..37035550a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -39,9 +39,4 @@ jobs: VALIDATE_CHECKOV: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN - FIX_MARKDOWN_PRETTIER: true - FIX_MARKDOWN: true - FIX_PYTHON_BLACK: true - FIX_PYTHON_ISORT: true - FIX_YAML_PRETTIER: true From ced040b0725b0732d3c71cabef6ebf676a002d6a Mon Sep 17 00:00:00 2001 From: zLukas Date: Wed, 19 Feb 2025 21:25:17 +0000 Subject: [PATCH 08/35] update formatting script --- python/example/misc_util.py | 36 ++++++++---------------------- python/example/rx_timing_parser.py | 16 ++++--------- python/example/st20p_rx.py | 4 +--- python/example/st20p_rx_encode.py | 8 ++----- python/example/st20p_tx.py | 4 +--- python/example/st20p_tx_decode.py | 8 ++----- python/example/st22p_rx.py | 4 +--- python/example/st22p_tx.py | 4 +--- 8 files changed, 21 insertions(+), 63 deletions(-) diff --git a/python/example/misc_util.py b/python/example/misc_util.py index cec106230..7d2a17c51 100644 --- a/python/example/misc_util.py +++ b/python/example/misc_util.py @@ -89,16 +89,12 @@ def parse_args(is_tx): p_port_default = "0000:af:01.1" else: p_port_default = "0000:af:01.0" - parser.add_argument( - "--p_port", type=str, default=p_port_default, help="primary port name" - ) + parser.add_argument("--p_port", type=str, default=p_port_default, help="primary port name") if is_tx: p_sip_default = "192.168.108.101" else: p_sip_default = "192.168.108.102" - parser.add_argument( - "--p_sip", type=str, default=p_sip_default, help="primary local IP address" - ) + parser.add_argument("--p_sip", type=str, default=p_sip_default, help="primary local IP address") # nb_tx_desc & nb_rx_desc parser.add_argument("--nb_tx_desc", type=int, default=0, help="nb_tx_desc") parser.add_argument("--nb_rx_desc", type=int, default=0, help="nb_rx_desc") @@ -147,24 +143,18 @@ def parse_args(is_tx): ) # display parser.add_argument("--display", action="store_true", help="enable display option") - parser.add_argument( - "--display_scale_factor", type=int, default=2, help="display scale factor" - ) + parser.add_argument("--display_scale_factor", type=int, default=2, help="display scale factor") # tx_url parser.add_argument( "--tx_url", type=str, default="yuv422p10le_1080p.yuv", help="tx url file path" ) # rx_url - parser.add_argument( - "--rx_url", type=str, default="test.mp4", help="rx url file path" - ) + parser.add_argument("--rx_url", type=str, default="test.mp4", help="rx url file path") # width & height parser.add_argument("--width", type=int, default=1920, help="width") parser.add_argument("--height", type=int, default=1080, help="height") # interlaced - parser.add_argument( - "--interlaced", action="store_true", help="Enable interlaced option" - ) + parser.add_argument("--interlaced", action="store_true", help="Enable interlaced option") # udp_port parser.add_argument("--udp_port", type=int, default=20000, help="udp port") # payload_type @@ -320,9 +310,7 @@ def wait_key(): def frame_display_yuv422p8(frame, display_scale_factor): # Pack frame pointer from frame addr - ptr = (ctypes.c_ubyte * (frame.data_size)).from_address( - mtl.st_frame_addr_cpuva(frame, 0) - ) + ptr = (ctypes.c_ubyte * (frame.data_size)).from_address(mtl.st_frame_addr_cpuva(frame, 0)) width = frame.width height = frame.height @@ -336,9 +324,7 @@ def frame_display_yuv422p8(frame, display_scale_factor): def frame_display_yuv420p8(frame, display_scale_factor): # Pack frame pointer from frame addr - ptr = (ctypes.c_ubyte * (frame.data_size)).from_address( - mtl.st_frame_addr_cpuva(frame, 0) - ) + ptr = (ctypes.c_ubyte * (frame.data_size)).from_address(mtl.st_frame_addr_cpuva(frame, 0)) width = frame.width height = frame.height @@ -352,9 +338,7 @@ def frame_display_yuv420p8(frame, display_scale_factor): def frame_display_yuv422p10le(frame, display_scale_factor): # Pack frame pointer from frame addr - ptr = (ctypes.c_ubyte * (frame.data_size)).from_address( - mtl.st_frame_addr_cpuva(frame, 0) - ) + ptr = (ctypes.c_ubyte * (frame.data_size)).from_address(mtl.st_frame_addr_cpuva(frame, 0)) width = frame.width height = frame.height @@ -369,9 +353,7 @@ def frame_display_yuv422p10le(frame, display_scale_factor): def frame_display_uyvy(frame, display_scale_factor): # Pack frame pointer from frame addr - ptr = (ctypes.c_ubyte * (frame.data_size)).from_address( - mtl.st_frame_addr_cpuva(frame, 0) - ) + ptr = (ctypes.c_ubyte * (frame.data_size)).from_address(mtl.st_frame_addr_cpuva(frame, 0)) width = frame.width height = frame.height downscaled_width = width // display_scale_factor diff --git a/python/example/rx_timing_parser.py b/python/example/rx_timing_parser.py index e9974c968..c4e29cbfc 100644 --- a/python/example/rx_timing_parser.py +++ b/python/example/rx_timing_parser.py @@ -28,15 +28,9 @@ def __init__(self, max_histories, title_str): self.fig, self.ax = plt.subplots() plt.title(title_str) plt.subplots_adjust(bottom=0.2) - (self.vrx_max_line,) = self.ax.plot( - self.times, self.vrx_max_values, label="VRX Max" - ) - (self.vrx_min_line,) = self.ax.plot( - self.times, self.vrx_min_values, label="VRX Min" - ) - (self.vrx_avg_line,) = self.ax.plot( - self.times, self.vrx_avg_values, label="VRX Avg" - ) + (self.vrx_max_line,) = self.ax.plot(self.times, self.vrx_max_values, label="VRX Max") + (self.vrx_min_line,) = self.ax.plot(self.times, self.vrx_min_values, label="VRX Min") + (self.vrx_avg_line,) = self.ax.plot(self.times, self.vrx_avg_values, label="VRX Avg") # init compliance text self.ax.legend(loc="upper left") self.text_narrow = self.ax.text( @@ -188,9 +182,7 @@ def main(): # Init mtl para init_para = mtl.mtl_init_params() mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) - mtl.mtl_para_pmd_set( - init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port) - ) + mtl.mtl_para_pmd_set(init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port)) init_para.num_ports = 1 mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP diff --git a/python/example/st20p_rx.py b/python/example/st20p_rx.py index 98d377ff7..1a1d51178 100644 --- a/python/example/st20p_rx.py +++ b/python/example/st20p_rx.py @@ -64,9 +64,7 @@ def main(): # Init para init_para = mtl.mtl_init_params() mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) - mtl.mtl_para_pmd_set( - init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port) - ) + mtl.mtl_para_pmd_set(init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port)) init_para.num_ports = 1 mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP diff --git a/python/example/st20p_rx_encode.py b/python/example/st20p_rx_encode.py index 5437254e0..dec026d22 100644 --- a/python/example/st20p_rx_encode.py +++ b/python/example/st20p_rx_encode.py @@ -23,9 +23,7 @@ def main(): # Init para init_para = mtl.mtl_init_params() mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) - mtl.mtl_para_pmd_set( - init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port) - ) + mtl.mtl_para_pmd_set(init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port)) init_para.num_ports = 1 mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP @@ -93,9 +91,7 @@ def main(): for plane in range(mtl.st_frame_fmt_planes(frame.fmt)): p_size = mtl.st_frame_plane_size(frame, plane) # print(f"plane: {plane} size: {p_size}") - ptr = (ctypes.c_ubyte * p_size).from_address( - mtl.st_frame_addr_cpuva(frame, plane) - ) + ptr = (ctypes.c_ubyte * p_size).from_address(mtl.st_frame_addr_cpuva(frame, plane)) p = np.ctypeslib.as_array(ptr, (p_size,)) video_frame.planes[plane].update(p) diff --git a/python/example/st20p_tx.py b/python/example/st20p_tx.py index 5da37c9aa..61868ab21 100644 --- a/python/example/st20p_tx.py +++ b/python/example/st20p_tx.py @@ -20,9 +20,7 @@ def main(): # Init para init_para = mtl.mtl_init_params() mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) - mtl.mtl_para_pmd_set( - init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port) - ) + mtl.mtl_para_pmd_set(init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port)) init_para.num_ports = 1 mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP diff --git a/python/example/st20p_tx_decode.py b/python/example/st20p_tx_decode.py index c97e93b70..265a47456 100644 --- a/python/example/st20p_tx_decode.py +++ b/python/example/st20p_tx_decode.py @@ -29,9 +29,7 @@ def process_frame(st20p_tx, frame, av_pixel_output_format): # pyav yuv422p10le not support Conversion to numpy array, use copy mode yuv_array[:y_size] = np.frombuffer(yuv_frame.planes[0], np.uint16) - yuv_array[y_size : y_size + u_size] = np.frombuffer( - yuv_frame.planes[1], np.uint16 - ) + yuv_array[y_size : y_size + u_size] = np.frombuffer(yuv_frame.planes[1], np.uint16) yuv_array[y_size + u_size :] = np.frombuffer(yuv_frame.planes[2], np.uint16) src_p = ctypes.c_char_p(yuv_array.ctypes.data) src_address = ctypes.cast(src_p, ctypes.c_void_p).value @@ -65,9 +63,7 @@ def main(): # Init para init_para = mtl.mtl_init_params() mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) - mtl.mtl_para_pmd_set( - init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port) - ) + mtl.mtl_para_pmd_set(init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port)) init_para.num_ports = 1 mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP diff --git a/python/example/st22p_rx.py b/python/example/st22p_rx.py index 1b68834e6..49e97e724 100644 --- a/python/example/st22p_rx.py +++ b/python/example/st22p_rx.py @@ -64,9 +64,7 @@ def main(): # Init para init_para = mtl.mtl_init_params() mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) - mtl.mtl_para_pmd_set( - init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port) - ) + mtl.mtl_para_pmd_set(init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port)) init_para.num_ports = 1 mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP diff --git a/python/example/st22p_tx.py b/python/example/st22p_tx.py index a451107d9..cd3916f5a 100644 --- a/python/example/st22p_tx.py +++ b/python/example/st22p_tx.py @@ -21,9 +21,7 @@ def main(): # Init para init_para = mtl.mtl_init_params() mtl.mtl_para_port_set(init_para, mtl.MTL_PORT_P, args.p_port) - mtl.mtl_para_pmd_set( - init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port) - ) + mtl.mtl_para_pmd_set(init_para, mtl.MTL_PORT_P, mtl.mtl_pmd_by_port_name(args.p_port)) init_para.num_ports = 1 mtl.mtl_para_sip_set(init_para, mtl.MTL_PORT_P, args.p_sip) init_para.flags = mtl.MTL_FLAG_BIND_NUMA | mtl.MTL_FLAG_DEV_AUTO_START_STOP From f5364e060c0d4aa6b41d54af18f1d6b6dedff0f5 Mon Sep 17 00:00:00 2001 From: zLukas Date: Wed, 19 Feb 2025 21:26:58 +0000 Subject: [PATCH 09/35] modify fornmatting script --- format-coding.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/format-coding.sh b/format-coding.sh index 27d4efd5d..b9deedd50 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -12,5 +12,7 @@ echo "clang-format check" find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' \ ! -name 'vmlinux.h' -exec clang-format --verbose -i {} + -black python/ -isort python/ + +CONFIG=".github/linters/.pyproject.toml" +black --config "$CONFIG" python/ +isort --settings-path "$CONFIG" python/ From b4deef7844bd5714cab81822d74b5f812e2ffe0d Mon Sep 17 00:00:00 2001 From: zLukas Date: Wed, 19 Feb 2025 21:34:25 +0000 Subject: [PATCH 10/35] move all linters config to the same location, provide config files in linter --- .clang-format | 1 - .markdown-lint.yml => .github/linters/.markdown-lint.yml | 0 .github/linters/.pyproject.toml | 7 +++++++ .textlintrc => .github/linters/.textlintrc | 0 .github/workflows/linter.yml | 5 +++++ 5 files changed, 12 insertions(+), 1 deletion(-) delete mode 120000 .clang-format rename .markdown-lint.yml => .github/linters/.markdown-lint.yml (100%) create mode 100644 .github/linters/.pyproject.toml rename .textlintrc => .github/linters/.textlintrc (100%) diff --git a/.clang-format b/.clang-format deleted file mode 120000 index 74d973366..000000000 --- a/.clang-format +++ /dev/null @@ -1 +0,0 @@ -.github/linters/.clang-format \ No newline at end of file diff --git a/.markdown-lint.yml b/.github/linters/.markdown-lint.yml similarity index 100% rename from .markdown-lint.yml rename to .github/linters/.markdown-lint.yml diff --git a/.github/linters/.pyproject.toml b/.github/linters/.pyproject.toml new file mode 100644 index 000000000..ae51af38e --- /dev/null +++ b/.github/linters/.pyproject.toml @@ -0,0 +1,7 @@ +[tool.black] +line-length = 100 +target-version = ['py38'] + +[tool.isort] +profile = "black" +line_length = 100 \ No newline at end of file diff --git a/.textlintrc b/.github/linters/.textlintrc similarity index 100% rename from .textlintrc rename to .github/linters/.textlintrc diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 37035550a..454b84bc0 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -39,4 +39,9 @@ jobs: VALIDATE_CHECKOV: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN + PYTHON_BLACK_CONFIG_FILE: .github/.pyproject.toml + PYTHON_ISORT_CONFIG_FILE: .github/.pyproject.toml + MARKDOWN_CONFIG_FILE: .github/.markdown-lint.yml + NATURAL_LANGUAGE_CONFIG_FILE: .github/linters/.textlintrc + GITHUB_ACTIONS_CONFIG_FILE: .github/linters/actionlint.yaml From 1becdf411914d7243a6c26204e8eea094fb8c384 Mon Sep 17 00:00:00 2001 From: zLukas Date: Wed, 19 Feb 2025 21:44:31 +0000 Subject: [PATCH 11/35] update .gitignore, remove . files --- .github/workflows/linter.yml | 6 +++--- .gitignore | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 454b84bc0..ef89514bb 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -39,9 +39,9 @@ jobs: VALIDATE_CHECKOV: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN - PYTHON_BLACK_CONFIG_FILE: .github/.pyproject.toml - PYTHON_ISORT_CONFIG_FILE: .github/.pyproject.toml - MARKDOWN_CONFIG_FILE: .github/.markdown-lint.yml + PYTHON_BLACK_CONFIG_FILE: .github/linters/.pyproject.toml + PYTHON_ISORT_CONFIG_FILE: .github/linters/.pyproject.toml + MARKDOWN_CONFIG_FILE: .github/linters/.markdown-lint.yml NATURAL_LANGUAGE_CONFIG_FILE: .github/linters/.textlintrc GITHUB_ACTIONS_CONFIG_FILE: .github/linters/actionlint.yaml diff --git a/.gitignore b/.gitignore index 7cad32293..5864c2e1a 100644 --- a/.gitignore +++ b/.gitignore @@ -52,7 +52,6 @@ Mkfile.old dkms.conf # Ours -.* *.log *.patch *.diff From 3fc19f9058eb29667b5d2f11379eb407ed8c6655 Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 11:20:33 +0000 Subject: [PATCH 12/35] test --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index ef89514bb..9eee203f3 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -43,5 +43,5 @@ jobs: PYTHON_ISORT_CONFIG_FILE: .github/linters/.pyproject.toml MARKDOWN_CONFIG_FILE: .github/linters/.markdown-lint.yml NATURAL_LANGUAGE_CONFIG_FILE: .github/linters/.textlintrc - GITHUB_ACTIONS_CONFIG_FILE: .github/linters/actionlint.yaml + # GITHUB_ACTIONS_CONFIG_FILE: .github/linters/actionlint.yaml From 2d5ffb9599af985a416e6a4871ca95c48e300e3b Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 11:22:36 +0000 Subject: [PATCH 13/35] test --- .github/workflows/linter.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 9eee203f3..482566140 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -39,9 +39,9 @@ jobs: VALIDATE_CHECKOV: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN - PYTHON_BLACK_CONFIG_FILE: .github/linters/.pyproject.toml - PYTHON_ISORT_CONFIG_FILE: .github/linters/.pyproject.toml - MARKDOWN_CONFIG_FILE: .github/linters/.markdown-lint.yml - NATURAL_LANGUAGE_CONFIG_FILE: .github/linters/.textlintrc + # PYTHON_BLACK_CONFIG_FILE: .github/linters/.pyproject.toml + # PYTHON_ISORT_CONFIG_FILE: .github/linters/.pyproject.toml + # MARKDOWN_CONFIG_FILE: .github/linters/.markdown-lint.yml + # NATURAL_LANGUAGE_CONFIG_FILE: .github/linters/.textlintrc # GITHUB_ACTIONS_CONFIG_FILE: .github/linters/actionlint.yaml From d208b7f6f3adaafc28cf2f213e22df2cf9c07568 Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 11:34:18 +0000 Subject: [PATCH 14/35] remove unnecessary linters check --- .github/workflows/linter.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 482566140..3b6f5e41d 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -37,6 +37,12 @@ jobs: VALIDATE_JSCPD: false VALIDATE_JSON: false VALIDATE_CHECKOV: false + VALIDATE_GITHUB_ACTIONS: false + VALIDATE_MARKDOWN: false + VALIDATE_MARKDOWN_PRETTIER: false + VALIDATE_NATURAL_LANGUAGE: false + VALIDATE_PYTHON_BLACK: false + VALIDATE_PYTHON_PYINK: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN # PYTHON_BLACK_CONFIG_FILE: .github/linters/.pyproject.toml From eff353bb560418468dfedfd78815b91f59d456b6 Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 11:36:04 +0000 Subject: [PATCH 15/35] update linterchecks --- .github/workflows/linter.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 3b6f5e41d..e248dad56 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -39,8 +39,6 @@ jobs: VALIDATE_CHECKOV: false VALIDATE_GITHUB_ACTIONS: false VALIDATE_MARKDOWN: false - VALIDATE_MARKDOWN_PRETTIER: false - VALIDATE_NATURAL_LANGUAGE: false VALIDATE_PYTHON_BLACK: false VALIDATE_PYTHON_PYINK: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 8bca50a0201827c2713a3c965961c68adb210628 Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 11:51:53 +0000 Subject: [PATCH 16/35] update linterchecks --- .github/workflows/linter.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index e248dad56..088a1c595 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -36,16 +36,14 @@ jobs: VALIDATE_CPP: false VALIDATE_JSCPD: false VALIDATE_JSON: false + VALIDATE_JSON_PRETTIER: false + VALIDATE_YAML: false + VALIDATE_YAML_PRETTIER: false VALIDATE_CHECKOV: false VALIDATE_GITHUB_ACTIONS: false - VALIDATE_MARKDOWN: false VALIDATE_PYTHON_BLACK: false VALIDATE_PYTHON_PYINK: false + VALIDATE_NATURAL_LANGUAGE: false GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN - # PYTHON_BLACK_CONFIG_FILE: .github/linters/.pyproject.toml - # PYTHON_ISORT_CONFIG_FILE: .github/linters/.pyproject.toml - # MARKDOWN_CONFIG_FILE: .github/linters/.markdown-lint.yml - # NATURAL_LANGUAGE_CONFIG_FILE: .github/linters/.textlintrc - # GITHUB_ACTIONS_CONFIG_FILE: .github/linters/actionlint.yaml From b6200bc36d021d9a167c6d749364d912e68789be Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 12:38:12 +0000 Subject: [PATCH 17/35] fix shellcheck --- format-coding.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/format-coding.sh b/format-coding.sh index b9deedd50..3a052404b 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -10,8 +10,7 @@ set -e echo "clang-format check" find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' \ - ! -name 'vmlinux.h' -exec clang-format --verbose -i {} + - + ! -name 'vmlinux.h' -exec clang-format --style=file ".github/linters/clang-format.yaml" --verbose -i {} + CONFIG=".github/linters/.pyproject.toml" black --config "$CONFIG" python/ From 28ba401097f1e6afc275edef2259cc58252dbb5c Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 14:38:48 +0000 Subject: [PATCH 18/35] move linter config files to root dir --- .clang-format | 6 ++++++ .hadolint.yaml | 6 ++++++ .markdown-lint.yml | 36 ++++++++++++++++++++++++++++++++++++ .pyproject.toml | 7 +++++++ .python-lint | 27 +++++++++++++++++++++++++++ .textlintrc | 8 ++++++++ actionlint.yaml | 4 ++++ 7 files changed, 94 insertions(+) create mode 100644 .clang-format create mode 100644 .hadolint.yaml create mode 100644 .markdown-lint.yml create mode 100644 .pyproject.toml create mode 100644 .python-lint create mode 100644 .textlintrc create mode 100644 actionlint.yaml diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..47fef013c --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +--- +BasedOnStyle: Google +DerivePointerAlignment: false +ColumnLimit: 90 +AllowShortFunctionsOnASingleLine: None diff --git a/.hadolint.yaml b/.hadolint.yaml new file mode 100644 index 000000000..77cf69f83 --- /dev/null +++ b/.hadolint.yaml @@ -0,0 +1,6 @@ +--- +########################## +## Hadolint config file ## +########################## +ignored: + - DL3008 # Ignore pinned versions check for APT \ No newline at end of file diff --git a/.markdown-lint.yml b/.markdown-lint.yml new file mode 100644 index 000000000..d617cf48c --- /dev/null +++ b/.markdown-lint.yml @@ -0,0 +1,36 @@ +--- +########################### +########################### +## Markdown Linter rules ## +########################### +########################### + +# Linter rules doc: +# - https://github.com/DavidAnson/markdownlint +# +# Note: +# To comment out a single error: +# +# any violations you want +# +# + +############### +# Rules by id # +############### +MD004: false # Unordered list style +MD007: + indent: 2 # Unordered list indentation +MD013: + line_length: 800 # Line length 80 is far to short +MD026: + punctuation: ".,;:!。,;:" # List of not allowed +MD029: false # Ordered list item prefix +MD033: true # Allow inline HTML +MD034: true # no-bare-urls +MD036: false # Emphasis used instead of a heading + +################# +# Rules by tags # +################# +blank_lines: false # Error on blank lines diff --git a/.pyproject.toml b/.pyproject.toml new file mode 100644 index 000000000..ae51af38e --- /dev/null +++ b/.pyproject.toml @@ -0,0 +1,7 @@ +[tool.black] +line-length = 100 +target-version = ['py38'] + +[tool.isort] +profile = "black" +line_length = 100 \ No newline at end of file diff --git a/.python-lint b/.python-lint new file mode 100644 index 000000000..f8fbc33bc --- /dev/null +++ b/.python-lint @@ -0,0 +1,27 @@ +[MASTER] + +# Use multiple processes to speed up Pylint. +jobs=0 + +# Todo: remove all below define to use defaul pylint settings + +[MESSAGES CONTROL] + +# Disable duplicate-code and missing-function-docstring +disable=duplicate-code, + missing-function-docstring, + import-error, + consider-using-with + +[DESIGN] + +# Maximum number of statements in function / method body +max-statements=100 +# Maximum number of locals for function / method body +max-locals=30 +# Maximum number of return / yield for function / method body +max-returns=10 +# Maximum number of characters on a single line. +max-line-length=120 +# Maximum number of branch for function / method body +max-branches=16 diff --git a/.textlintrc b/.textlintrc new file mode 100644 index 000000000..48ea350a4 --- /dev/null +++ b/.textlintrc @@ -0,0 +1,8 @@ +{ + "filters": { + "comments": true + }, + "rules": { + "terminology": true + } +} \ No newline at end of file diff --git a/actionlint.yaml b/actionlint.yaml new file mode 100644 index 000000000..cb1ef8593 --- /dev/null +++ b/actionlint.yaml @@ -0,0 +1,4 @@ +self-hosted-runner: + labels: + - DPDK + - XDP \ No newline at end of file From f1888269f29b289d6325a25f45913e28f26833ca Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 14:45:53 +0000 Subject: [PATCH 19/35] update markdown config files --- .github/workflows/linter.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 088a1c595..c3250a732 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -44,6 +44,7 @@ jobs: VALIDATE_PYTHON_BLACK: false VALIDATE_PYTHON_PYINK: false VALIDATE_NATURAL_LANGUAGE: false + VALIDATE_MARKDOWN_PRETTIER: false + MARKDOWN_CONFIG_FILE: .markdown-lint.yml GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN - From a333d64e5dadbf6750c895795a5b31259c3d444c Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 15:01:23 +0000 Subject: [PATCH 20/35] reset to defaults --- .github/workflows/linter.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index c3250a732..86d109931 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -45,6 +45,5 @@ jobs: VALIDATE_PYTHON_PYINK: false VALIDATE_NATURAL_LANGUAGE: false VALIDATE_MARKDOWN_PRETTIER: false - MARKDOWN_CONFIG_FILE: .markdown-lint.yml GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN From bcc30cbf393c6851e5cf0b8457dd4f50e7dfc2b2 Mon Sep 17 00:00:00 2001 From: Lukas G <20104521+zLukas@users.noreply.github.com> Date: Thu, 20 Feb 2025 16:15:36 +0100 Subject: [PATCH 21/35] Update linter.yml --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 86d109931..7a5b2172b 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -29,7 +29,7 @@ jobs: # Run Linter against code base # ################################ - name: Lint Code Base - uses: github/super-linter/slim@b92721f792f381cedc002ecdbb9847a15ece5bb8 # v7 + uses: github/super-linter/slim@85f7611e0f7b53c8573cca84aa0ed4344f6f6a4d # v7.2.1 env: DEFAULT_BRANCH: main From 6df03df3d56579a22a23624c433cc789167801dd Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 17:32:35 +0000 Subject: [PATCH 22/35] add lint config path --- .github/workflows/linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 7a5b2172b..69ec6233e 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -45,5 +45,6 @@ jobs: VALIDATE_PYTHON_PYINK: false VALIDATE_NATURAL_LANGUAGE: false VALIDATE_MARKDOWN_PRETTIER: false + LINTER_RULES_PATH: .github/linters GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN From 8b4255d7868b82c556aa63b4f4e793cfd8c67424 Mon Sep 17 00:00:00 2001 From: zLukas Date: Thu, 20 Feb 2025 17:37:06 +0000 Subject: [PATCH 23/35] update rules path --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 69ec6233e..c9b0450bb 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -45,6 +45,6 @@ jobs: VALIDATE_PYTHON_PYINK: false VALIDATE_NATURAL_LANGUAGE: false VALIDATE_MARKDOWN_PRETTIER: false - LINTER_RULES_PATH: .github/linters + LINTER_RULES_PATH: ./ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN From d6059053dee3f300d6439c3c0f4f0f007472910e Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 10:10:41 +0000 Subject: [PATCH 24/35] turn off MD033 checks --- .github/linters/.markdown-lint.yml | 2 +- .github/workflows/linter.yml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/linters/.markdown-lint.yml b/.github/linters/.markdown-lint.yml index d617cf48c..ee058c83f 100644 --- a/.github/linters/.markdown-lint.yml +++ b/.github/linters/.markdown-lint.yml @@ -26,7 +26,7 @@ MD013: MD026: punctuation: ".,;:!。,;:" # List of not allowed MD029: false # Ordered list item prefix -MD033: true # Allow inline HTML +MD033: false # Allow inline HTML MD034: true # no-bare-urls MD036: false # Emphasis used instead of a heading diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index c9b0450bb..7a5b2172b 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -45,6 +45,5 @@ jobs: VALIDATE_PYTHON_PYINK: false VALIDATE_NATURAL_LANGUAGE: false VALIDATE_MARKDOWN_PRETTIER: false - LINTER_RULES_PATH: ./ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} LOG_LEVEL: WARN From e016a3d269fc229da250aec01a00106c7d9e0411 Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 10:14:23 +0000 Subject: [PATCH 25/35] apply markdow linter fix --- doc/performance.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/performance.md b/doc/performance.md index d5680fd3f..153b15700 100644 --- a/doc/performance.md +++ b/doc/performance.md @@ -14,6 +14,7 @@ APP used: RxTxApp reference app. ### 2.1 transmitter in frame mode following table shows the benchmark of max tx session number. + format | 1 port with 1 NIC | 2 port with 2 NIC --- | --- | --- 720p29.97 | 160 | 160 x 2 From 71764ef51a2b69a026bdf9abeb354aa80bea4cfc Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 10:51:37 +0000 Subject: [PATCH 26/35] cleanup --- .clang-format | 6 ------ .hadolint.yaml | 6 ------ .markdown-lint.yml | 36 ------------------------------------ .pyproject.toml | 7 ------- .python-lint | 27 --------------------------- .textlintrc | 8 -------- actionlint.yaml | 4 ---- 7 files changed, 94 deletions(-) delete mode 100644 .clang-format delete mode 100644 .hadolint.yaml delete mode 100644 .markdown-lint.yml delete mode 100644 .pyproject.toml delete mode 100644 .python-lint delete mode 100644 .textlintrc delete mode 100644 actionlint.yaml diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 47fef013c..000000000 --- a/.clang-format +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 ---- -BasedOnStyle: Google -DerivePointerAlignment: false -ColumnLimit: 90 -AllowShortFunctionsOnASingleLine: None diff --git a/.hadolint.yaml b/.hadolint.yaml deleted file mode 100644 index 77cf69f83..000000000 --- a/.hadolint.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -########################## -## Hadolint config file ## -########################## -ignored: - - DL3008 # Ignore pinned versions check for APT \ No newline at end of file diff --git a/.markdown-lint.yml b/.markdown-lint.yml deleted file mode 100644 index d617cf48c..000000000 --- a/.markdown-lint.yml +++ /dev/null @@ -1,36 +0,0 @@ ---- -########################### -########################### -## Markdown Linter rules ## -########################### -########################### - -# Linter rules doc: -# - https://github.com/DavidAnson/markdownlint -# -# Note: -# To comment out a single error: -# -# any violations you want -# -# - -############### -# Rules by id # -############### -MD004: false # Unordered list style -MD007: - indent: 2 # Unordered list indentation -MD013: - line_length: 800 # Line length 80 is far to short -MD026: - punctuation: ".,;:!。,;:" # List of not allowed -MD029: false # Ordered list item prefix -MD033: true # Allow inline HTML -MD034: true # no-bare-urls -MD036: false # Emphasis used instead of a heading - -################# -# Rules by tags # -################# -blank_lines: false # Error on blank lines diff --git a/.pyproject.toml b/.pyproject.toml deleted file mode 100644 index ae51af38e..000000000 --- a/.pyproject.toml +++ /dev/null @@ -1,7 +0,0 @@ -[tool.black] -line-length = 100 -target-version = ['py38'] - -[tool.isort] -profile = "black" -line_length = 100 \ No newline at end of file diff --git a/.python-lint b/.python-lint deleted file mode 100644 index f8fbc33bc..000000000 --- a/.python-lint +++ /dev/null @@ -1,27 +0,0 @@ -[MASTER] - -# Use multiple processes to speed up Pylint. -jobs=0 - -# Todo: remove all below define to use defaul pylint settings - -[MESSAGES CONTROL] - -# Disable duplicate-code and missing-function-docstring -disable=duplicate-code, - missing-function-docstring, - import-error, - consider-using-with - -[DESIGN] - -# Maximum number of statements in function / method body -max-statements=100 -# Maximum number of locals for function / method body -max-locals=30 -# Maximum number of return / yield for function / method body -max-returns=10 -# Maximum number of characters on a single line. -max-line-length=120 -# Maximum number of branch for function / method body -max-branches=16 diff --git a/.textlintrc b/.textlintrc deleted file mode 100644 index 48ea350a4..000000000 --- a/.textlintrc +++ /dev/null @@ -1,8 +0,0 @@ -{ - "filters": { - "comments": true - }, - "rules": { - "terminology": true - } -} \ No newline at end of file diff --git a/actionlint.yaml b/actionlint.yaml deleted file mode 100644 index cb1ef8593..000000000 --- a/actionlint.yaml +++ /dev/null @@ -1,4 +0,0 @@ -self-hosted-runner: - labels: - - DPDK - - XDP \ No newline at end of file From bed910060262156219aa65514d19d6c92dd78ae7 Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 11:03:50 +0000 Subject: [PATCH 27/35] add cpp linter --- .github/workflows/linter.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 7a5b2172b..0a889040a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -33,7 +33,6 @@ jobs: env: DEFAULT_BRANCH: main - VALIDATE_CPP: false VALIDATE_JSCPD: false VALIDATE_JSON: false VALIDATE_JSON_PRETTIER: false From 9a270291e25490da140fdf882e586e961e090af4 Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 11:40:51 +0000 Subject: [PATCH 28/35] run clang formatter on source files --- app/perf/p10le_to_rfc4175_422be10.c | 119 +- app/perf/perf_dma.c | 27 +- app/perf/rfc4175_422be10_to_le.c | 65 +- app/perf/rfc4175_422be10_to_le8.c | 65 +- app/perf/rfc4175_422be10_to_p10le.c | 119 +- app/perf/rfc4175_422be10_to_p8.c | 38 +- app/perf/rfc4175_422be10_to_v210.c | 129 +- app/perf/rfc4175_422be10_to_y210.c | 66 +- app/perf/rfc4175_422be12_to_le.c | 49 +- app/perf/rfc4175_422be12_to_p12le.c | 119 +- app/perf/rfc4175_422le10_to_be.c | 69 +- app/perf/v210_to_rfc4175_422be10.c | 78 +- app/perf/y210_to_rfc4175_422be10.c | 57 +- app/sample/dma/dma_sample.c | 48 +- .../rx_st20_redundant_combined_sample.c | 70 +- .../rx_st20_pipeline_dyn_ext_frame_sample.c | 82 +- .../ext_frame/rx_st20p_hdr_split_gpu_direct.c | 119 +- .../tx_st20_pipeline_ext_frame_sample.c | 84 +- app/sample/ext_frame/tx_video_split_sample.c | 45 +- app/sample/fwd/rx_st20_tx_st20_split_fwd.c | 76 +- .../fwd/rx_st20p_tx_st20p_downsample_fwd.c | 44 +- .../rx_st20p_tx_st20p_downsample_merge_fwd.c | 60 +- app/sample/fwd/rx_st20p_tx_st20p_fwd.c | 89 +- app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c | 61 +- app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c | 55 +- app/sample/fwd/rx_st20p_tx_st22p_fwd.c | 58 +- app/sample/legacy/rx_st20_tx_st20_fwd.c | 108 +- app/sample/legacy/rx_st22_video_sample.c | 65 +- app/sample/legacy/rx_video_sample.c | 95 +- app/sample/legacy/tx_st22_video_sample.c | 72 +- app/sample/legacy/tx_video_sample.c | 87 +- app/sample/low_level/rx_rtp_video_sample.c | 52 +- app/sample/low_level/rx_slice_video_sample.c | 77 +- app/sample/low_level/tx_rtp_video_sample.c | 47 +- app/sample/low_level/tx_slice_video_sample.c | 94 +- app/sample/msvc/imtl_sample/imtl_sample.cpp | 21 +- app/sample/rdma/rdma_rx.c | 21 +- app/sample/rdma/rdma_tx.c | 29 +- app/sample/rdma/rdma_video_rx.c | 47 +- app/sample/rdma/rdma_video_rx_multi.c | 62 +- app/sample/rdma/rdma_video_tx.c | 31 +- app/sample/rdma/rdma_video_tx_multi.c | 44 +- app/sample/rx_st20_pipeline_sample.c | 60 +- app/sample/rx_st20p_auto_detect_sample.c | 69 +- app/sample/rx_st20p_timing_parser_sample.c | 76 +- app/sample/rx_st22_pipeline_sample.c | 56 +- app/sample/rx_st30_pipeline_sample.c | 63 +- app/sample/sample_util.c | 660 ++-- app/sample/sample_util.h | 52 +- app/sample/tx_st20_pipeline_sample.c | 78 +- app/sample/tx_st22_pipeline_sample.c | 69 +- app/sample/tx_st30_pipeline_sample.c | 85 +- app/src/app_base.h | 191 +- app/src/app_platform.h | 47 +- app/src/args.c | 1033 +++---- app/src/args.h | 4 +- app/src/experimental/rx_st20r_app.c | 188 +- app/src/experimental/rx_st20r_app.h | 10 +- app/src/fmt.c | 11 +- app/src/fmt.h | 5 +- app/src/legacy/rx_audio_app.c | 212 +- app/src/legacy/rx_audio_app.h | 8 +- app/src/legacy/rx_st22_app.c | 90 +- app/src/legacy/rx_st22_app.h | 4 +- app/src/legacy/rx_video_app.c | 334 ++- app/src/legacy/rx_video_app.h | 12 +- app/src/legacy/tx_audio_app.c | 211 +- app/src/legacy/tx_audio_app.h | 6 +- app/src/legacy/tx_st22_app.c | 118 +- app/src/legacy/tx_st22_app.h | 6 +- app/src/legacy/tx_video_app.c | 363 ++- app/src/legacy/tx_video_app.h | 10 +- app/src/log.h | 45 +- app/src/parse_json.c | 1160 +++++--- app/src/parse_json.h | 38 +- app/src/player.c | 45 +- app/src/player.h | 20 +- app/src/rx_ancillary_app.c | 140 +- app/src/rx_ancillary_app.h | 6 +- app/src/rx_st20p_app.c | 179 +- app/src/rx_st20p_app.h | 12 +- app/src/rx_st22p_app.c | 139 +- app/src/rx_st22p_app.h | 10 +- app/src/rx_st30p_app.c | 117 +- app/src/rx_st30p_app.h | 8 +- app/src/rxtx_app.c | 162 +- app/src/tx_ancillary_app.c | 229 +- app/src/tx_ancillary_app.h | 6 +- app/src/tx_st20p_app.c | 150 +- app/src/tx_st20p_app.h | 8 +- app/src/tx_st22p_app.c | 112 +- app/src/tx_st22p_app.h | 6 +- app/src/tx_st30p_app.c | 96 +- app/src/tx_st30p_app.h | 8 +- app/tools/convert_app.c | 162 +- app/tools/convert_app_args.c | 65 +- app/tools/convert_app_base.h | 25 +- app/tools/lcore_shmem_mgr.c | 68 +- app/tools/log.h | 22 +- app/udp/udp_client_sample.c | 67 +- app/udp/udp_server_sample.c | 87 +- app/udp/ufd_client_sample.c | 73 +- app/udp/ufd_server_sample.c | 98 +- app/udp/usocket_client_sample.c | 54 +- app/udp/usocket_server_sample.c | 88 +- app/v4l2_to_ip/v4l2_to_ip.c | 701 +++-- ecosystem/ffmpeg_plugin/mtl_common.c | 65 +- ecosystem/ffmpeg_plugin/mtl_common.h | 163 +- ecosystem/ffmpeg_plugin/mtl_st20p_rx.c | 73 +- ecosystem/ffmpeg_plugin/mtl_st20p_tx.c | 53 +- ecosystem/ffmpeg_plugin/mtl_st22p_rx.c | 107 +- ecosystem/ffmpeg_plugin/mtl_st22p_tx.c | 90 +- ecosystem/ffmpeg_plugin/mtl_st30p_rx.c | 48 +- ecosystem/ffmpeg_plugin/mtl_st30p_tx.c | 58 +- ecosystem/obs_mtl/linux-mtl/linux-mtl.c | 56 +- ecosystem/obs_mtl/linux-mtl/linux-mtl.h | 2 +- ecosystem/obs_mtl/linux-mtl/mtl-input.c | 214 +- ecosystem/obs_mtl/linux-mtl/mtl-output.c | 108 +- format-coding.sh | 6 +- include/experimental/st20_combined_api.h | 62 +- include/mtl_api.h | 326 +- include/mtl_lcore_shm_api.h | 3 +- include/mtl_sch_api.h | 45 +- include/mudp_api.h | 51 +- include/mudp_sockfd_api.h | 45 +- include/mudp_sockfd_internal.h | 30 +- include/mudp_win.h | 21 +- include/st20_api.h | 690 +++-- include/st30_api.h | 204 +- include/st30_pipeline_api.h | 116 +- include/st40_api.h | 152 +- include/st_api.h | 53 +- include/st_convert_api.h | 395 +-- include/st_convert_internal.h | 584 ++-- include/st_pipeline_api.h | 678 +++-- ld_preload/preload_platform.h | 4 +- ld_preload/udp/udp_preload.c | 579 ++-- ld_preload/udp/udp_preload.h | 148 +- lib/src/datapath/mt_dp_socket.c | 309 +- lib/src/datapath/mt_dp_socket.h | 26 +- lib/src/datapath/mt_queue.c | 158 +- lib/src/datapath/mt_queue.h | 75 +- lib/src/datapath/mt_shared_queue.c | 296 +- lib/src/datapath/mt_shared_queue.h | 44 +- lib/src/datapath/mt_shared_rss.c | 228 +- lib/src/datapath/mt_shared_rss.h | 20 +- lib/src/dev/mt_af_xdp.c | 382 +-- lib/src/dev/mt_af_xdp.h | 69 +- lib/src/dev/mt_dev.c | 739 +++-- lib/src/dev/mt_dev.h | 76 +- lib/src/dev/mt_rdma_ud.c | 573 ++-- lib/src/dev/mt_rdma_ud.h | 69 +- lib/src/mt_admin.c | 190 +- lib/src/mt_admin.h | 4 +- lib/src/mt_arp.c | 185 +- lib/src/mt_arp.h | 12 +- lib/src/mt_cni.c | 363 +-- lib/src/mt_cni.h | 20 +- lib/src/mt_config.c | 44 +- lib/src/mt_config.h | 4 +- lib/src/mt_dhcp.c | 208 +- lib/src/mt_dhcp.h | 14 +- lib/src/mt_dma.c | 249 +- lib/src/mt_dma.h | 53 +- lib/src/mt_flow.c | 114 +- lib/src/mt_flow.h | 13 +- lib/src/mt_header.h | 2 +- lib/src/mt_instance.c | 88 +- lib/src/mt_instance.h | 24 +- lib/src/mt_log.c | 70 +- lib/src/mt_log.h | 110 +- lib/src/mt_main.c | 365 ++- lib/src/mt_main.h | 557 ++-- lib/src/mt_mcast.c | 324 +- lib/src/mt_mcast.h | 22 +- lib/src/mt_mem.h | 29 +- lib/src/mt_pcap.c | 28 +- lib/src/mt_pcap.h | 26 +- lib/src/mt_platform.h | 38 +- lib/src/mt_ptp.c | 691 +++-- lib/src/mt_ptp.h | 21 +- lib/src/mt_quirk.h | 9 +- lib/src/mt_rtcp.c | 192 +- lib/src/mt_rtcp.h | 56 +- lib/src/mt_sch.c | 440 +-- lib/src/mt_sch.h | 52 +- lib/src/mt_simd.h | 14 +- lib/src/mt_socket.c | 163 +- lib/src/mt_socket.h | 33 +- lib/src/mt_stat.c | 66 +- lib/src/mt_stat.h | 13 +- lib/src/mt_tap.c | 444 +-- lib/src/mt_tap.h | 23 +- lib/src/mt_usdt.h | 232 +- lib/src/mt_util.c | 499 ++-- lib/src/mt_util.h | 239 +- .../experimental/st20_redundant_combined_rx.c | 117 +- .../experimental/st20_redundant_combined_rx.h | 12 +- lib/src/st2110/pipeline/st20_pipeline_rx.c | 477 +-- lib/src/st2110/pipeline/st20_pipeline_rx.h | 10 +- lib/src/st2110/pipeline/st20_pipeline_tx.c | 306 +- lib/src/st2110/pipeline/st20_pipeline_tx.h | 10 +- lib/src/st2110/pipeline/st22_pipeline_rx.c | 270 +- lib/src/st2110/pipeline/st22_pipeline_rx.h | 6 +- lib/src/st2110/pipeline/st22_pipeline_tx.c | 325 +- lib/src/st2110/pipeline/st22_pipeline_tx.h | 6 +- lib/src/st2110/pipeline/st30_pipeline_rx.c | 175 +- lib/src/st2110/pipeline/st30_pipeline_rx.h | 4 +- lib/src/st2110/pipeline/st30_pipeline_tx.c | 190 +- lib/src/st2110/pipeline/st30_pipeline_tx.h | 4 +- lib/src/st2110/pipeline/st_plugin.c | 494 +-- lib/src/st2110/pipeline/st_plugin.h | 34 +- lib/src/st2110/st_ancillary.c | 201 +- lib/src/st2110/st_ancillary_transmitter.c | 53 +- lib/src/st2110/st_ancillary_transmitter.h | 9 +- lib/src/st2110/st_audio_transmitter.c | 68 +- lib/src/st2110/st_audio_transmitter.h | 14 +- lib/src/st2110/st_avx2.c | 68 +- lib/src/st2110/st_avx2.h | 12 +- lib/src/st2110/st_avx512.c | 1265 ++++---- lib/src/st2110/st_avx512.h | 176 +- lib/src/st2110/st_avx512_vbmi.c | 939 +++--- lib/src/st2110/st_avx512_vbmi.h | 91 +- lib/src/st2110/st_convert.c | 1160 ++++---- lib/src/st2110/st_convert.h | 4 +- lib/src/st2110/st_fmt.c | 684 +++-- lib/src/st2110/st_fmt.h | 31 +- lib/src/st2110/st_header.h | 398 +-- lib/src/st2110/st_main.h | 4 +- lib/src/st2110/st_pkt.h | 10 +- lib/src/st2110/st_rx_ancillary_session.c | 418 +-- lib/src/st2110/st_rx_ancillary_session.h | 2 +- lib/src/st2110/st_rx_audio_session.c | 601 ++-- lib/src/st2110/st_rx_audio_session.h | 2 +- lib/src/st2110/st_rx_timing_parser.c | 259 +- lib/src/st2110/st_rx_timing_parser.h | 34 +- lib/src/st2110/st_rx_video_session.c | 1975 ++++++------ lib/src/st2110/st_rx_video_session.h | 84 +- lib/src/st2110/st_tx_ancillary_session.c | 942 +++--- lib/src/st2110/st_tx_ancillary_session.h | 2 +- lib/src/st2110/st_tx_audio_session.c | 1122 +++---- lib/src/st2110/st_tx_audio_session.h | 2 +- lib/src/st2110/st_tx_video_session.c | 1806 ++++++----- lib/src/st2110/st_tx_video_session.h | 72 +- lib/src/st2110/st_video_transmitter.c | 258 +- lib/src/st2110/st_video_transmitter.h | 21 +- lib/src/udp/udp_main.c | 722 +++-- lib/src/udp/udp_main.h | 26 +- lib/src/udp/udp_rxq.c | 166 +- lib/src/udp/udp_rxq.h | 38 +- lib/src/udp/ufd_main.c | 247 +- lib/src/udp/ufd_main.h | 6 +- lib/windows/win_posix.c | 62 +- lib/windows/win_posix.h | 35 +- manager/logging.hpp | 41 +- manager/mtl.xdp.c | 29 +- manager/mtl_instance.hpp | 204 +- manager/mtl_interface.hpp | 65 +- manager/mtl_lcore.hpp | 23 +- manager/mtl_manager.cpp | 58 +- plugins/log.h | 28 +- plugins/plugin_platform.h | 25 +- plugins/sample/convert_plugin_sample.c | 89 +- plugins/sample/convert_plugin_sample.h | 4 +- plugins/sample/st22_plugin_sample.c | 102 +- plugins/sample/st22_plugin_sample.h | 6 +- plugins/st22_avcodec/st22_avcodec_plugin.c | 176 +- plugins/st22_avcodec/st22_avcodec_plugin.h | 24 +- rdma/mt_rdma.c | 10 +- rdma/mt_rdma.h | 127 +- rdma/mt_rdma_rx.c | 296 +- rdma/mt_rdma_tx.c | 378 +-- rdma/mtl_rdma_api.h | 63 +- tests/src/cvt_test.cpp | 2646 ++++++++++------- tests/src/dma_test.cpp | 163 +- tests/src/log.h | 28 +- tests/src/sch_test.cpp | 32 +- tests/src/st20_test.cpp | 1620 +++++----- tests/src/st20p_test.cpp | 524 ++-- tests/src/st22_test.cpp | 499 ++-- tests/src/st22p_test.cpp | 484 +-- tests/src/st30_test.cpp | 466 +-- tests/src/st30p_test.cpp | 199 +- tests/src/st40_test.cpp | 345 ++- tests/src/st_test.cpp | 184 +- tests/src/test_platform.h | 25 +- tests/src/test_util.cpp | 14 +- tests/src/test_util.h | 26 +- tests/src/tests.cpp | 500 ++-- tests/src/tests.h | 961 +++--- tests/src/ufd_loop_test.cpp | 137 +- tests/src/ufd_test.cpp | 237 +- tests/src/ufd_test.h | 2 +- tests/src/upl_loop_test.cpp | 186 +- tests/src/upl_test.cpp | 92 +- tests/src/upl_test.h | 10 +- tools/ebpf/et.c | 111 +- tools/ebpf/et.h | 4 +- tools/ebpf/fentry.bpf.c | 16 +- tools/ebpf/lcore_monitor.bpf.c | 58 +- tools/ebpf/lcore_monitor.c | 90 +- tools/ebpf/log.h | 28 +- tools/ebpf/udp_monitor.bpf.c | 16 +- tools/ebpf/udp_monitor.c | 163 +- tools/readpcap/readpcap.c | 16 +- tools/readpcap/readpcap_31.c | 40 +- tools/sch_smi_emulate/sch_smi_emulate.c | 30 +- 307 files changed, 29970 insertions(+), 24075 deletions(-) diff --git a/app/perf/p10le_to_rfc4175_422be10.c b/app/perf/p10le_to_rfc4175_422be10.c index 60dec38c5..cfcb92d01 100644 --- a/app/perf/p10le_to_rfc4175_422be10.c +++ b/app/perf/p10le_to_rfc4175_422be10.c @@ -12,7 +12,8 @@ #include "../sample/sample_util.h" -static void fill_422_planar_le(uint16_t* y, uint16_t* b, uint16_t* r, int w, int h) { +static void fill_422_planar_le(uint16_t *y, uint16_t *b, uint16_t *r, int w, + int h) { int pg_size = w * h / 2; for (int pg = 0; pg < pg_size; pg++) { @@ -23,32 +24,35 @@ static void fill_422_planar_le(uint16_t* y, uint16_t* b, uint16_t* r, int w, int } } -static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, + int frames, int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)malloc(fb_pg2_size * fb_cnt); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)malloc(fb_pg2_size * fb_cnt); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); float planar_size_m = (float)planar_size / 1024 / 1024; - uint16_t* p10_u16 = (uint16_t*)mtl_hp_malloc(st, planar_size * fb_cnt, MTL_PORT_P); - uint16_t* p10_u16_b = p10_u16 + w * h; - uint16_t* p10_u16_r = p10_u16 + w * h * 3 / 2; + uint16_t *p10_u16 = + (uint16_t *)mtl_hp_malloc(st, planar_size * fb_cnt, MTL_PORT_P); + uint16_t *p10_u16_b = p10_u16 + w * h; + uint16_t *p10_u16_r = p10_u16 + w * h * 3 / 2; mtl_iova_t p10_u16_y_iova = mtl_hp_virt2iova(st, p10_u16); mtl_iova_t p10_u16_b_iova = p10_u16_y_iova + planar_size / 2; mtl_iova_t p10_u16_r_iova = p10_u16_b_iova + planar_size / 4; mtl_iova_t p10_u16_y_in_iova, p10_u16_b_in_iova, p10_u16_r_in_iova; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_10_pg2_be* pg_be_out; - uint16_t* p10_u16_in; - uint16_t* p10_u16_b_in; - uint16_t* p10_u16_r_in; + struct st20_rfc4175_422_10_pg2_be *pg_be_out; + uint16_t *p10_u16_in; + uint16_t *p10_u16_b_in; + uint16_t *p10_u16_r_in; for (int i = 0; i < fb_cnt; i++) { p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_in = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); fill_422_planar_le(p10_u16_in, p10_u16_b_in, p10_u16_r_in, w, h); } @@ -59,49 +63,58 @@ static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, int fra for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, p10_u16_r_in, - pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); + p10_u16_b_in = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, + p10_u16_r_in, pg_be_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, p10_u16_r_in, - pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); + p10_u16_b_in = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, + p10_u16_r_in, pg_be_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_in = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); p10_u16_y_in_iova = p10_u16_y_iova + (i % fb_cnt) * (planar_size); p10_u16_b_in_iova = p10_u16_b_iova + (i % fb_cnt) * (planar_size); p10_u16_r_in_iova = p10_u16_r_iova + (i % fb_cnt) * (planar_size); st20_yuv422p10le_to_rfc4175_422be10_simd_dma( dma, p10_u16_in, p10_u16_y_in_iova, p10_u16_b_in, p10_u16_b_in_iova, - p10_u16_r_in, p10_u16_r_in_iova, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); + p10_u16_r_in, p10_u16_r_in_iova, pg_be_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512+dma, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512+dma, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512+dma, %fx performance to scalar\n", duration / duration_simd); } } @@ -111,24 +124,28 @@ static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, int fra for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, p10_u16_r_in, - pg_be_out, w, h, + p10_u16_b_in = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, + p10_u16_r_in, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_in = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); p10_u16_y_in_iova = p10_u16_y_iova + (i % fb_cnt) * (planar_size); p10_u16_b_in_iova = p10_u16_b_iova + (i % fb_cnt) * (planar_size); p10_u16_r_in_iova = p10_u16_r_iova + (i % fb_cnt) * (planar_size); @@ -141,19 +158,21 @@ static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, int fra float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("avx512_vbmi+dma, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("avx512_vbmi+dma, %fx performance to scalar\n", duration / duration_simd); + info("avx512_vbmi+dma, %fx performance to scalar\n", + duration / duration_simd); } } free(pg_be); mtl_hp_free(st, p10_u16); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -169,21 +188,24 @@ static void* perf_thread(void* arg) { perf_cvt_planar_le_to_422_10_pg2(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); - perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); + perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 2, 1080 * 2, frames, + fb_cnt); + perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 4, 1080 * 4, frames, + fb_cnt); mtl_put_lcore(dev_handle, lcore); return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -193,7 +215,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/perf_dma.c b/app/perf/perf_dma.c index 04ad84d65..315d1006e 100644 --- a/app/perf/perf_dma.c +++ b/app/perf/perf_dma.c @@ -4,13 +4,14 @@ #include "../sample/sample_util.h" -static inline void rand_data(uint8_t* p, size_t sz, uint8_t base) { +static inline void rand_data(uint8_t *p, size_t sz, uint8_t base) { for (size_t i = 0; i < sz; i++) { p[i] = rand() + base; } } -static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) { +static int dma_copy_perf(mtl_handle st, int w, int h, int frames, + int pkt_size) { mtl_udma_handle dma; int ret; uint16_t nb_desc = 1024; @@ -45,7 +46,7 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) return -ENOMEM; } fb_src_iova = mtl_hp_virt2iova(st, fb_src); - rand_data((uint8_t*)fb_src, fb_size, 0); + rand_data((uint8_t *)fb_src, fb_size, 0); clock_t start, end; float duration_cpu, duration_simd, duration_dma; @@ -60,8 +61,8 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) } end = clock(); duration_cpu = (float)(end - start) / CLOCKS_PER_SEC; - info("cpu, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", duration_cpu, - frames, w, h, fb_size_m, pkt_size); + info("cpu, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", + duration_cpu, frames, w, h, fb_size_m, pkt_size); start = clock(); for (int idx = 0; idx < frames; idx++) { @@ -73,8 +74,8 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) } end = clock(); duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("simd, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", duration_simd, - frames, w, h, fb_size_m, pkt_size); + info("simd, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", + duration_simd, frames, w, h, fb_size_m, pkt_size); info("simd, %fx performance to cpu\n", duration_cpu / duration_simd); start = clock(); @@ -84,7 +85,8 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) while (fb_src_iova_off < fb_size) { ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, pkt_size); - if (ret < 0) break; + if (ret < 0) + break; fb_src_iova_off += pkt_size; } /* submit */ @@ -97,8 +99,8 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) } end = clock(); duration_dma = (float)(end - start) / CLOCKS_PER_SEC; - info("dma, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", duration_dma, - frames, w, h, fb_size_m, pkt_size); + info("dma, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", + duration_dma, frames, w, h, fb_size_m, pkt_size); info("dma, %fx performance to cpu\n", duration_cpu / duration_dma); info("\n"); @@ -109,13 +111,14 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = dma_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { diff --git a/app/perf/rfc4175_422be10_to_le.c b/app/perf/rfc4175_422be10_to_le.c index e5e3778a8..9a53299b0 100644 --- a/app/perf/rfc4175_422be10_to_le.c +++ b/app/perf/rfc4175_422be10_to_le.c @@ -8,19 +8,19 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, int fb_cnt) { size_t fb_pg2_size = w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, - MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)malloc(fb_pg2_size * fb_cnt); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( + st, fb_pg2_size * fb_cnt, MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)malloc(fb_pg2_size * fb_cnt); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = fb_pg2_size; float planar_size_m = (float)planar_size / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_10_pg2_be* pg_be_in; - struct st20_rfc4175_422_10_pg2_le* pg_le_out; + struct st20_rfc4175_422_10_pg2_be *pg_be_in; + struct st20_rfc4175_422_10_pg2_le *pg_le_out; for (int i = 0; i < fb_cnt; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); @@ -34,12 +34,13 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames * 1; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX2) { start = clock(); @@ -51,8 +52,8 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, - w, h, fb_cnt); + info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx2, %fx performance to scalar\n", duration / duration_simd); } @@ -66,8 +67,8 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -76,13 +77,14 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_le_out, - w, h, MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, + pg_le_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -97,8 +99,8 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -107,26 +109,29 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_le_out, - w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, + pg_le_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", + duration / duration_vbmi); } } mtl_hp_free(st, pg_be); free(pg_le); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -150,13 +155,14 @@ static void* perf_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -166,7 +172,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_le8.c b/app/perf/rfc4175_422be10_to_le8.c index 973927123..8d395c784 100644 --- a/app/perf/rfc4175_422be10_to_le8.c +++ b/app/perf/rfc4175_422be10_to_le8.c @@ -4,23 +4,23 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, + int frames, int fb_cnt) { size_t fb_pg10_size = (size_t)w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_10 = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_malloc(st, fb_pg10_size * fb_cnt, - MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_10 = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( + st, fb_pg10_size * fb_cnt, MTL_PORT_P); mtl_iova_t pg_10_iova = mtl_hp_virt2iova(st, pg_10); mtl_iova_t pg_10_in_iova; size_t fb_pg8_size = (size_t)w * h * 2; float fb_pg8_size_m = (float)fb_pg8_size / 1024 / 1024; - struct st20_rfc4175_422_8_pg2_le* pg_8 = - (struct st20_rfc4175_422_8_pg2_le*)malloc(fb_pg8_size * fb_cnt); + struct st20_rfc4175_422_8_pg2_le *pg_8 = + (struct st20_rfc4175_422_8_pg2_le *)malloc(fb_pg8_size * fb_cnt); enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_10_pg2_be* pg_10_in; - struct st20_rfc4175_422_8_pg2_le* pg_8_out; + struct st20_rfc4175_422_10_pg2_be *pg_10_in; + struct st20_rfc4175_422_8_pg2_le *pg_8_out; for (int i = 0; i < fb_cnt; i++) { pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); @@ -34,12 +34,13 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, int frames for (int i = 0; i < frames; i++) { pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_422le8_simd(pg_10_in, pg_8_out, w, h, MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422be10_to_422le8_simd(pg_10_in, pg_8_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, fb_pg8_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, fb_pg8_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); @@ -51,8 +52,8 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, int frames } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -61,13 +62,14 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, int frames pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_10_in_iova = pg_10_iova + (i % fb_cnt) * (fb_pg10_size); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, pg_8_out, w, - h, MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, + pg_8_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -82,8 +84,8 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, int frames } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -92,26 +94,29 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, int frames pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_10_in_iova = pg_10_iova + (i % fb_cnt) * (fb_pg10_size); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, pg_8_out, w, - h, MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, + pg_8_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", + duration / duration_vbmi); } } mtl_hp_free(st, pg_10); free(pg_8); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -135,13 +140,14 @@ static void* perf_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -151,7 +157,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_p10le.c b/app/perf/rfc4175_422be10_to_p10le.c index ddb6076e8..f220432ac 100644 --- a/app/perf/rfc4175_422be10_to_p10le.c +++ b/app/perf/rfc4175_422be10_to_p10le.c @@ -4,26 +4,26 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, + int frames, int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, - MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( + st, fb_pg2_size * fb_cnt, MTL_PORT_P); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); float planar_size_m = (float)planar_size / 1024 / 1024; - uint16_t* p10_u16 = (uint16_t*)malloc(planar_size * fb_cnt); - uint16_t* p10_u16_b = p10_u16 + w * h; - uint16_t* p10_u16_r = p10_u16 + w * h * 3 / 2; + uint16_t *p10_u16 = (uint16_t *)malloc(planar_size * fb_cnt); + uint16_t *p10_u16_b = p10_u16 + w * h; + uint16_t *p10_u16_r = p10_u16 + w * h * 3 / 2; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_10_pg2_be* pg_be_in; - uint16_t* p10_u16_out; - uint16_t* p10_u16_b_out; - uint16_t* p10_u16_r_out; + struct st20_rfc4175_422_10_pg2_be *pg_be_in; + uint16_t *p10_u16_out; + uint16_t *p10_u16_b_out; + uint16_t *p10_u16_r_out; for (int i = 0; i < fb_cnt; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); @@ -37,31 +37,36 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, int fra for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, p10_u16_b_out, - p10_u16_r_out, w, h, MTL_SIMD_LEVEL_NONE); + p10_u16_b_out = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, + p10_u16_b_out, p10_u16_r_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, p10_u16_b_out, - p10_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512); + p10_u16_b_out = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, + p10_u16_b_out, p10_u16_r_out, w, + h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -70,16 +75,18 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, int fra pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_out = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); st20_rfc4175_422be10_to_yuv422p10le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, p10_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512); + dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, + p10_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -89,16 +96,18 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, int fra for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, p10_u16_b_out, - p10_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + p10_u16_b_out = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, + p10_u16_b_out, p10_u16_r_out, w, + h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -107,29 +116,33 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, int fra pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_out = + p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = + p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); st20_rfc4175_422be10_to_yuv422p10le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, p10_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, + p10_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", + duration / duration_vbmi); } } mtl_hp_free(st, pg_be); free(p10_u16); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -145,21 +158,24 @@ static void* perf_thread(void* arg) { perf_cvt_422_10_pg2_to_planar_le(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); - perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); + perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, + fb_cnt); + perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, + fb_cnt); mtl_put_lcore(dev_handle, lcore); return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -169,7 +185,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_p8.c b/app/perf/rfc4175_422be10_to_p8.c index 63c1ed1cf..92c4b2e67 100644 --- a/app/perf/rfc4175_422be10_to_p8.c +++ b/app/perf/rfc4175_422be10_to_p8.c @@ -7,16 +7,16 @@ static int perf_cvt_422_10_pg2_be_to_p8(mtl_handle st, int w, int h, int frames, int fb_cnt) { size_t fb_pg10_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg_10 = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_malloc(st, fb_pg10_size * fb_cnt, - MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_10 = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( + st, fb_pg10_size * fb_cnt, MTL_PORT_P); size_t fb_pg8_size = (size_t)w * h * 2; float fb_pg8_size_m = (float)fb_pg8_size / 1024 / 1024; - uint8_t* pg_8 = (uint8_t*)malloc(fb_pg8_size * fb_cnt); + uint8_t *pg_8 = (uint8_t *)malloc(fb_pg8_size * fb_cnt); enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_10_pg2_be* pg_10_in; - uint8_t* pg_8_out; + struct st20_rfc4175_422_10_pg2_be *pg_10_in; + uint8_t *pg_8_out; for (int i = 0; i < fb_cnt; i++) { pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); @@ -36,22 +36,22 @@ static int perf_cvt_422_10_pg2_be_to_p8(mtl_handle st, int w, int h, int frames, } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, fb_pg8_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, fb_pg8_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_yuv422p8_simd(pg_10_in, pg_8_out, pg_8_out + w * h, - pg_8_out + w * h * 3 / 2, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be10_to_yuv422p8_simd( + pg_10_in, pg_8_out, pg_8_out + w * h, pg_8_out + w * h * 3 / 2, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); } @@ -61,8 +61,8 @@ static int perf_cvt_422_10_pg2_be_to_p8(mtl_handle st, int w, int h, int frames, return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -86,13 +86,14 @@ static void* perf_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -102,7 +103,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_v210.c b/app/perf/rfc4175_422be10_to_v210.c index ea30997d1..c8b3ebaa6 100644 --- a/app/perf/rfc4175_422be10_to_v210.c +++ b/app/perf/rfc4175_422be10_to_v210.c @@ -6,29 +6,30 @@ #define TEST_2_STEPS (0) -static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, + int frames, int fb_cnt) { size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, - MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)malloc(fb_pg2_size * fb_cnt); - uint8_t* pg_v210 = (uint8_t*)malloc(fb_pg2_size_v210 * fb_cnt); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( + st, fb_pg2_size * fb_cnt, MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)malloc(fb_pg2_size * fb_cnt); + uint8_t *pg_v210 = (uint8_t *)malloc(fb_pg2_size_v210 * fb_cnt); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = fb_pg2_size; float planar_size_m = (float)planar_size / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - size_t be_1line_size = st_frame_size(ST_FRAME_FMT_YUV422RFC4175PG2BE10, w, 1, false); + size_t be_1line_size = + st_frame_size(ST_FRAME_FMT_YUV422RFC4175PG2BE10, w, 1, false); size_t v210_1line_size = st_frame_size(ST_FRAME_FMT_V210, w, 1, false); info("v210_1line_size %" PRIu64 "\n", v210_1line_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_in; - uint8_t* pg_v210_out; + struct st20_rfc4175_422_10_pg2_be *pg_be_in; + uint8_t *pg_v210_out; for (int i = 0; i < fb_cnt; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); @@ -42,26 +43,29 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, MTL_SIMD_LEVEL_NONE); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (v210_1line_size) { @@ -69,7 +73,8 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); for (int j = 0; j < h; j++) { st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, 1, @@ -82,7 +87,8 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("avx512_1line, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("avx512_1line, %fx performance to scalar\n", duration / duration_simd); + info("avx512_1line, %fx performance to scalar\n", + duration / duration_simd); } if (dma) { @@ -90,14 +96,16 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_v210_out, - w, h, MTL_SIMD_LEVEL_AVX512); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, + pg_v210_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -105,14 +113,15 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -120,50 +129,56 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_v210_out, - w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, + pg_v210_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", + duration / duration_vbmi); } } #if TEST_2_STEPS - struct st20_rfc4175_422_10_pg2_le* pg_le_out; + struct st20_rfc4175_422_10_pg2_le *pg_le_out; info("2 steps conversion (be->le->v210)\n"); start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_NONE); - st20_rfc4175_422le10_to_v210_simd((uint8_t*)pg_le_out, pg_v210_out, w, h, + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, + MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le_out, pg_v210_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_AVX512); - st20_rfc4175_422le10_to_v210_simd((uint8_t*)pg_le_out, pg_v210_out, w, h, + st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le_out, pg_v210_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); } @@ -172,16 +187,17 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = + pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); - st20_rfc4175_422le10_to_v210_simd((uint8_t*)pg_le_out, pg_v210_out, w, h, + st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le_out, pg_v210_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); } #endif @@ -189,13 +205,14 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frame mtl_hp_free(st, pg_be); free(pg_le); free(pg_v210); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -211,21 +228,24 @@ static void* perf_thread(void* arg) { perf_cvt_422_10_pg2_be_to_v210(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); - perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); + perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 2, 1080 * 2, frames, + fb_cnt); + perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 4, 1080 * 4, frames, + fb_cnt); mtl_put_lcore(dev_handle, lcore); return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -235,7 +255,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_y210.c b/app/perf/rfc4175_422be10_to_y210.c index 67f63fecf..acb4a24f2 100644 --- a/app/perf/rfc4175_422be10_to_y210.c +++ b/app/perf/rfc4175_422be10_to_y210.c @@ -4,23 +4,23 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, + int frames, int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; size_t fb_pg2_size_y210 = (size_t)w * h * 4; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, - MTL_PORT_P); - uint16_t* pg_y210 = (uint16_t*)malloc(fb_pg2_size_y210 * fb_cnt); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( + st, fb_pg2_size * fb_cnt, MTL_PORT_P); + uint16_t *pg_y210 = (uint16_t *)malloc(fb_pg2_size_y210 * fb_cnt); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = fb_pg2_size; float planar_size_m = (float)planar_size / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_10_pg2_be* pg_be_in; - uint16_t* pg_y210_out; + struct st20_rfc4175_422_10_pg2_be *pg_be_in; + uint16_t *pg_y210_out; for (int i = 0; i < fb_cnt; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); @@ -33,26 +33,29 @@ static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, int frame start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_y210_out = pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); - st20_rfc4175_422be10_to_y210_simd(pg_be_in, pg_y210_out, w, h, MTL_SIMD_LEVEL_NONE); + pg_y210_out = + pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); + st20_rfc4175_422be10_to_y210_simd(pg_be_in, pg_y210_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_y210_out = pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); + pg_y210_out = + pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); st20_rfc4175_422be10_to_y210_simd(pg_be_in, pg_y210_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -60,27 +63,30 @@ static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, int frame for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); - pg_y210_out = pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); - st20_rfc4175_422be10_to_y210_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_y210_out, - w, h, MTL_SIMD_LEVEL_AVX512); + pg_y210_out = + pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); + st20_rfc4175_422be10_to_y210_simd_dma(dma, pg_be_in, pg_be_in_iova, + pg_y210_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_be); free(pg_y210); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -96,21 +102,24 @@ static void* perf_thread(void* arg) { perf_cvt_422_10_pg2_be_to_y210(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); - perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); + perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 2, 1080 * 2, frames, + fb_cnt); + perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 4, 1080 * 4, frames, + fb_cnt); mtl_put_lcore(dev_handle, lcore); return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -120,7 +129,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be12_to_le.c b/app/perf/rfc4175_422be12_to_le.c index b81ea2615..a228859ae 100644 --- a/app/perf/rfc4175_422be12_to_le.c +++ b/app/perf/rfc4175_422be12_to_le.c @@ -8,19 +8,19 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 3; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, - MTL_PORT_P); - struct st20_rfc4175_422_12_pg2_le* pg_le = - (struct st20_rfc4175_422_12_pg2_le*)malloc(fb_pg2_size * fb_cnt); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_malloc( + st, fb_pg2_size * fb_cnt, MTL_PORT_P); + struct st20_rfc4175_422_12_pg2_le *pg_le = + (struct st20_rfc4175_422_12_pg2_le *)malloc(fb_pg2_size * fb_cnt); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = fb_pg2_size; float planar_size_m = (float)planar_size / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_12_pg2_be* pg_be_in; - struct st20_rfc4175_422_12_pg2_le* pg_le_out; + struct st20_rfc4175_422_12_pg2_be *pg_be_in; + struct st20_rfc4175_422_12_pg2_le *pg_le_out; for (int i = 0; i < fb_cnt; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); @@ -34,12 +34,13 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames * 1; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be12_to_422le12_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422be12_to_422le12_simd(pg_be_in, pg_le_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); @@ -51,8 +52,8 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -61,26 +62,28 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be12_to_422le12_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_le_out, - w, h, MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be12_to_422le12_simd_dma(dma, pg_be_in, pg_be_in_iova, + pg_le_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_be); free(pg_le); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -104,13 +107,14 @@ static void* perf_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -120,7 +124,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be12_to_p12le.c b/app/perf/rfc4175_422be12_to_p12le.c index 326409037..c1ccd08a0 100644 --- a/app/perf/rfc4175_422be12_to_p12le.c +++ b/app/perf/rfc4175_422be12_to_p12le.c @@ -4,26 +4,26 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, + int frames, int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 6 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, - MTL_PORT_P); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_malloc( + st, fb_pg2_size * fb_cnt, MTL_PORT_P); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); float planar_size_m = (float)planar_size / 1024 / 1024; - uint16_t* p12_u16 = (uint16_t*)malloc(planar_size * fb_cnt); - uint16_t* p12_u16_b = p12_u16 + w * h; - uint16_t* p12_u16_r = p12_u16 + w * h * 3 / 2; + uint16_t *p12_u16 = (uint16_t *)malloc(planar_size * fb_cnt); + uint16_t *p12_u16_b = p12_u16 + w * h; + uint16_t *p12_u16_r = p12_u16 + w * h * 3 / 2; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_12_pg2_be* pg_be_in; - uint16_t* p12_u16_out; - uint16_t* p12_u16_b_out; - uint16_t* p12_u16_r_out; + struct st20_rfc4175_422_12_pg2_be *pg_be_in; + uint16_t *p12_u16_out; + uint16_t *p12_u16_b_out; + uint16_t *p12_u16_r_out; for (int i = 0; i < fb_cnt; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); @@ -37,31 +37,36 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, int fra for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); - st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, p12_u16_b_out, - p12_u16_r_out, w, h, MTL_SIMD_LEVEL_NONE); + p12_u16_b_out = + p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = + p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, + p12_u16_b_out, p12_u16_r_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); - st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, p12_u16_b_out, - p12_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512); + p12_u16_b_out = + p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = + p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, + p12_u16_b_out, p12_u16_r_out, w, + h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -70,16 +75,18 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, int fra pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + p12_u16_b_out = + p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = + p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); st20_rfc4175_422be12_to_yuv422p12le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, p12_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512); + dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, + p12_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -89,16 +96,18 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, int fra for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); - st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, p12_u16_b_out, - p12_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + p12_u16_b_out = + p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = + p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, + p12_u16_b_out, p12_u16_r_out, w, + h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -107,29 +116,33 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, int fra pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + p12_u16_b_out = + p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = + p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); st20_rfc4175_422be12_to_yuv422p12le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, p12_u16_r_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, + p12_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", + duration / duration_vbmi); } } mtl_hp_free(st, pg_be); free(p12_u16); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -145,21 +158,24 @@ static void* perf_thread(void* arg) { perf_cvt_422_12_pg2_to_planar_le(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); - perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); + perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, + fb_cnt); + perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, + fb_cnt); mtl_put_lcore(dev_handle, lcore); return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -169,7 +185,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422le10_to_be.c b/app/perf/rfc4175_422le10_to_be.c index f40d03454..6c6fc16bf 100644 --- a/app/perf/rfc4175_422le10_to_be.c +++ b/app/perf/rfc4175_422le10_to_be.c @@ -4,8 +4,8 @@ #include "../sample/sample_util.h" -static void fill_422_10_pg2_le_data(struct st20_rfc4175_422_10_pg2_le* data, int w, - int h) { +static void fill_422_10_pg2_le_data(struct st20_rfc4175_422_10_pg2_le *data, + int w, int h) { int pg_size = w * h / 2; uint16_t cb, y0, cr, y1; /* 10 bit */ @@ -37,19 +37,19 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, int fb_cnt) { size_t fb_pg2_size = w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, - MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)mtl_hp_malloc( + st, fb_pg2_size * fb_cnt, MTL_PORT_P); mtl_iova_t pg_le_iova = mtl_hp_virt2iova(st, pg_le); mtl_iova_t pg_le_in_iova; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)malloc(fb_pg2_size * fb_cnt); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)malloc(fb_pg2_size * fb_cnt); size_t planar_size = fb_pg2_size; float planar_size_m = (float)planar_size / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - struct st20_rfc4175_422_10_pg2_le* pg_le_in; - struct st20_rfc4175_422_10_pg2_be* pg_be_out; + struct st20_rfc4175_422_10_pg2_le *pg_le_in; + struct st20_rfc4175_422_10_pg2_be *pg_be_out; for (int i = 0; i < fb_cnt; i++) { pg_le_in = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); @@ -63,12 +63,13 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames * 1; i++) { pg_le_in = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422le10_to_422be10_simd(pg_le_in, pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422le10_to_422be10_simd(pg_le_in, pg_be_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX2) { start = clock(); @@ -80,8 +81,8 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, - w, h, fb_cnt); + info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx2, %fx performance to scalar\n", duration / duration_simd); } @@ -95,8 +96,8 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -105,13 +106,14 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, pg_le_in_iova = pg_le_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_in = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, pg_be_out, - w, h, MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, + pg_be_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -126,8 +128,8 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { start = clock(); @@ -135,26 +137,29 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, pg_le_in_iova = pg_le_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_in = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, pg_be_out, - w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, + pg_be_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_simd); + info("dma+avx512_vbmi, %fx performance to scalar\n", + duration / duration_simd); } } mtl_hp_free(st, pg_le); free(pg_be); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -178,13 +183,14 @@ static void* perf_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -194,7 +200,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/v210_to_rfc4175_422be10.c b/app/perf/v210_to_rfc4175_422be10.c index ae0424db7..2f424d9e6 100644 --- a/app/perf/v210_to_rfc4175_422be10.c +++ b/app/perf/v210_to_rfc4175_422be10.c @@ -4,27 +4,30 @@ #include "../sample/sample_util.h" -static void fill_rand_v210(uint8_t* p, size_t sz) { +static void fill_rand_v210(uint8_t *p, size_t sz) { for (size_t i = 0; i < sz; i++) { p[i] = rand(); - if ((i % 4) == 3) p[i] &= 0x3F; + if ((i % 4) == 3) + p[i] &= 0x3F; } } -static int perf_cvt_v210_to_be(mtl_handle st, int w, int h, int frames, int fb_cnt) { +static int perf_cvt_v210_to_be(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg2_size = w * h * 5 / 2; size_t fb_size_v210 = w * h * 8 / 3; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)malloc(fb_pg2_size * fb_cnt); - uint8_t* pg_v210 = (uint8_t*)mtl_hp_malloc(st, fb_size_v210 * fb_cnt, MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)malloc(fb_pg2_size * fb_cnt); + uint8_t *pg_v210 = + (uint8_t *)mtl_hp_malloc(st, fb_size_v210 * fb_cnt, MTL_PORT_P); mtl_iova_t pg_v210_iova = mtl_hp_virt2iova(st, pg_v210); mtl_iova_t pg_v210_in_iova; float fb_size_v210_m = (float)fb_size_v210 / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - uint8_t* pg_v210_in; - struct st20_rfc4175_422_10_pg2_be* pg_be_out; + uint8_t *pg_v210_in; + struct st20_rfc4175_422_10_pg2_be *pg_be_out; for (int i = 0; i < fb_cnt; i++) { pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); @@ -38,81 +41,90 @@ static int perf_cvt_v210_to_be(mtl_handle st, int w, int h, int frames, int fb_c for (int i = 0; i < frames; i++) { pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); + st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, fb_size_v210_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, fb_size_v210_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = + pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = + pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_v210_in_iova = pg_v210_iova + (i % fb_cnt) * (fb_size_v210); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, pg_be_out, - w, h, MTL_SIMD_LEVEL_AVX512); + st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, + pg_be_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } if (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = + pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, - frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_vbmi, frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = + pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_v210_in_iova = pg_v210_iova + (i % fb_cnt) * (fb_size_v210); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, pg_be_out, - w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, + pg_be_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_simd); + info("dma+avx512_vbmi, %fx performance to scalar\n", + duration / duration_simd); } } mtl_hp_free(st, pg_v210); free(pg_be); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -136,13 +148,14 @@ static void* perf_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -152,7 +165,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/y210_to_rfc4175_422be10.c b/app/perf/y210_to_rfc4175_422be10.c index 1760e998d..b8510c95b 100644 --- a/app/perf/y210_to_rfc4175_422be10.c +++ b/app/perf/y210_to_rfc4175_422be10.c @@ -12,26 +12,28 @@ #include "../sample/sample_util.h" -static void fill_rand_y210(uint16_t* p, size_t sz) { +static void fill_rand_y210(uint16_t *p, size_t sz) { for (size_t i = 0; i < sz / 2; i++) { p[i] = rand() & 0x3FF; } } -static int perf_cvt_y210_to_be(mtl_handle st, int w, int h, int frames, int fb_cnt) { +static int perf_cvt_y210_to_be(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; size_t fb_size_y210 = (size_t)w * h * 4; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)malloc(fb_pg2_size * fb_cnt); - uint16_t* pg_y210 = (uint16_t*)mtl_hp_malloc(st, fb_size_y210 * fb_cnt, MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)malloc(fb_pg2_size * fb_cnt); + uint16_t *pg_y210 = + (uint16_t *)mtl_hp_malloc(st, fb_size_y210 * fb_cnt, MTL_PORT_P); mtl_iova_t pg_y210_iova = mtl_hp_virt2iova(st, pg_y210); mtl_iova_t pg_y210_in_iova; float fb_size_y210_m = (float)fb_size_y210 / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - uint16_t* pg_y210_in; - struct st20_rfc4175_422_10_pg2_be* pg_be_out; + uint16_t *pg_y210_in; + struct st20_rfc4175_422_10_pg2_be *pg_be_out; for (int i = 0; i < fb_cnt; i++) { pg_y210_in = pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); @@ -45,52 +47,57 @@ static int perf_cvt_y210_to_be(mtl_handle st, int w, int h, int frames, int fb_c for (int i = 0; i < frames; i++) { pg_y210_in = pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_y210_to_rfc4175_422be10_simd(pg_y210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); + st20_y210_to_rfc4175_422be10_simd(pg_y210_in, pg_be_out, w, h, + MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, - w, h, fb_size_y210_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, + frames, w, h, fb_size_y210_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { - pg_y210_in = pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); + pg_y210_in = + pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); st20_y210_to_rfc4175_422be10_simd(pg_y210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { - pg_y210_in = pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); + pg_y210_in = + pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); pg_y210_in_iova = pg_y210_iova + (i % fb_cnt) * (fb_size_y210); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210_in, pg_y210_in_iova, pg_be_out, - w, h, MTL_SIMD_LEVEL_AVX512); + st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210_in, pg_y210_in_iova, + pg_be_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, - frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", + duration_simd, frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_y210); free(pg_be); - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return 0; } -static void* perf_thread(void* arg) { - struct st_sample_context* ctx = arg; +static void *perf_thread(void *arg) { + struct st_sample_context *ctx = arg; mtl_handle dev_handle = ctx->st; int frames = ctx->perf_frames; int fb_cnt = ctx->perf_fb_cnt; @@ -114,13 +121,14 @@ static void* perf_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -130,7 +138,8 @@ int main(int argc, char** argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) goto exit; + if (ret) + goto exit; pthread_join(thread, NULL); exit: diff --git a/app/sample/dma/dma_sample.c b/app/sample/dma/dma_sample.c index 77e9b00fa..5cf720461 100644 --- a/app/sample/dma/dma_sample.c +++ b/app/sample/dma/dma_sample.c @@ -6,7 +6,7 @@ #include "../sample_util.h" -static inline void rand_data(uint8_t* p, size_t sz, uint8_t base) { +static inline void rand_data(uint8_t *p, size_t sz, uint8_t base) { for (size_t i = 0; i < sz; i++) { p[i] = rand() + base; } @@ -48,8 +48,8 @@ static int dma_copy_sample(mtl_handle st) { return -ENOMEM; } fb_src_iova = mtl_hp_virt2iova(st, fb_src); - rand_data((uint8_t*)fb_src, fb_size, 0); - st_sha256((unsigned char*)fb_src, fb_size, fb_src_shas); + rand_data((uint8_t *)fb_src, fb_size, 0); + st_sha256((unsigned char *)fb_src, fb_size, fb_src_shas); uint64_t start_ns = mtl_ptp_read_time(st); while (fb_dst_iova_off < fb_size) { @@ -57,7 +57,8 @@ static int dma_copy_sample(mtl_handle st) { while (fb_src_iova_off < fb_size) { ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, element_size); - if (ret < 0) break; + if (ret < 0) + break; fb_src_iova_off += element_size; } /* submit */ @@ -72,7 +73,7 @@ static int dma_copy_sample(mtl_handle st) { uint64_t end_ns = mtl_ptp_read_time(st); /* all copy completed, check sha */ - st_sha256((unsigned char*)fb_dst, fb_size, fb_dst_shas); + st_sha256((unsigned char *)fb_dst, fb_size, fb_dst_shas); ret = memcmp(fb_dst_shas, fb_src_shas, SHA256_DIGEST_LENGTH); if (ret != 0) { err("sha check fail\n"); @@ -119,7 +120,7 @@ static int dma_map_copy_sample(mtl_handle st) { ret = -ENOMEM; goto out; } - fb_dst = (void*)MTL_ALIGN((uint64_t)fb_dst_malloc, pg_sz); + fb_dst = (void *)MTL_ALIGN((uint64_t)fb_dst_malloc, pg_sz); fb_dst_iova = mtl_dma_map(st, fb_dst, fb_size); if (fb_dst_iova == MTL_BAD_IOVA) { err("%s: fb dst mmap fail\n", __func__); @@ -133,7 +134,7 @@ static int dma_map_copy_sample(mtl_handle st) { ret = -ENOMEM; goto out; } - fb_src = (void*)MTL_ALIGN((uint64_t)fb_src_malloc, pg_sz); + fb_src = (void *)MTL_ALIGN((uint64_t)fb_src_malloc, pg_sz); fb_src_iova = mtl_dma_map(st, fb_src, fb_size); if (fb_src_iova == MTL_BAD_IOVA) { err("%s: fb src mmap fail\n", __func__); @@ -141,8 +142,8 @@ static int dma_map_copy_sample(mtl_handle st) { goto out; } - rand_data((uint8_t*)fb_src, fb_size, 0); - st_sha256((unsigned char*)fb_src, fb_size, fb_src_shas); + rand_data((uint8_t *)fb_src, fb_size, 0); + st_sha256((unsigned char *)fb_src, fb_size, fb_src_shas); uint64_t start_ns = mtl_ptp_read_time(st); while (fb_dst_iova_off < fb_size) { @@ -150,7 +151,8 @@ static int dma_map_copy_sample(mtl_handle st) { while (fb_src_iova_off < fb_size) { ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, element_size); - if (ret < 0) break; + if (ret < 0) + break; fb_src_iova_off += element_size; } /* submit */ @@ -165,35 +167,39 @@ static int dma_map_copy_sample(mtl_handle st) { uint64_t end_ns = mtl_ptp_read_time(st); /* all copy completed, check sha */ - st_sha256((unsigned char*)fb_dst, fb_size, fb_dst_shas); + st_sha256((unsigned char *)fb_dst, fb_size, fb_dst_shas); ret = memcmp(fb_dst_shas, fb_src_shas, SHA256_DIGEST_LENGTH); if (ret != 0) { err("%s: sha check fail\n", __func__); } else { - info("%s: dma map copy %" PRIu64 "k with time %dus\n", __func__, fb_size / 1024, - (int)(end_ns - start_ns) / 1000); + info("%s: dma map copy %" PRIu64 "k with time %dus\n", __func__, + fb_size / 1024, (int)(end_ns - start_ns) / 1000); } out: if (fb_src_malloc) { - if (fb_src_iova != MTL_BAD_IOVA) mtl_dma_unmap(st, fb_src, fb_src_iova, fb_size); + if (fb_src_iova != MTL_BAD_IOVA) + mtl_dma_unmap(st, fb_src, fb_src_iova, fb_size); free(fb_src_malloc); } if (fb_dst_malloc) { - if (fb_dst_iova != MTL_BAD_IOVA) mtl_dma_unmap(st, fb_dst, fb_dst_iova, fb_size); + if (fb_dst_iova != MTL_BAD_IOVA) + mtl_dma_unmap(st, fb_dst, fb_dst_iova, fb_size); free(fb_dst_malloc); } - if (dma) mtl_udma_free(dma); + if (dma) + mtl_udma_free(dma); return ret; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = dma_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -203,10 +209,12 @@ int main(int argc, char** argv) { /* dma copy with st_hp_*** memory */ ret = dma_copy_sample(ctx.st); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; /* dma copy with malloc/free memory, use map before passing to DMA */ ret = dma_map_copy_sample(ctx.st); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; exit: /* release sample(st) dev */ diff --git a/app/sample/experimental/rx_st20_redundant_combined_sample.c b/app/sample/experimental/rx_st20_redundant_combined_sample.c index 0fd2246d9..3672ce32a 100644 --- a/app/sample/experimental/rx_st20_redundant_combined_sample.c +++ b/app/sample/experimental/rx_st20_redundant_combined_sample.c @@ -20,12 +20,13 @@ struct st20rc_sample_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_rx_frame* framebuffs; + struct st_rx_frame *framebuffs; }; -static int rx_video_enqueue_frame(struct st20rc_sample_ctx* s, void* frame, size_t size) { +static int rx_video_enqueue_frame(struct st20rc_sample_ctx *s, void *frame, + size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -36,16 +37,18 @@ static int rx_video_enqueue_frame(struct st20rc_sample_ctx* s, void* frame, size framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int rx_video_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - struct st20rc_sample_ctx* s = (struct st20rc_sample_ctx*)priv; +static int rx_video_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct st20rc_sample_ctx *s = (struct st20rc_sample_ctx *)priv; - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -68,7 +71,7 @@ static int rx_video_frame_ready(void* priv, void* frame, return 0; } -static void rx_video_consume_frame(struct st20rc_sample_ctx* s, void* frame, +static void rx_video_consume_frame(struct st20rc_sample_ctx *s, void *frame, size_t frame_size) { MTL_MAY_UNUSED(frame); MTL_MAY_UNUSED(frame_size); @@ -79,11 +82,11 @@ static void rx_video_consume_frame(struct st20rc_sample_ctx* s, void* frame, s->fb_rec++; } -static void* rx_video_frame_thread(void* arg) { - struct st20rc_sample_ctx* s = arg; +static void *rx_video_frame_thread(void *arg) { + struct st20rc_sample_ctx *s = arg; int idx = s->idx; int consumer_idx; - struct st_rx_frame* framebuff; + struct st_rx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->stop) { @@ -92,7 +95,8 @@ static void* rx_video_frame_thread(void* arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -105,7 +109,8 @@ static void* rx_video_frame_thread(void* arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -114,7 +119,7 @@ static void* rx_video_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret = -EIO; @@ -133,13 +138,14 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st20rc_rx_handle rx_handle[session_num]; - struct st20rc_sample_ctx* app[session_num]; + struct st20rc_sample_ctx *app[session_num]; uint64_t sart_time_ns; int loop = 0; // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = (struct st20rc_sample_ctx*)malloc(sizeof(struct st20rc_sample_ctx)); + app[i] = + (struct st20rc_sample_ctx *)malloc(sizeof(struct st20rc_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -151,8 +157,8 @@ int main(int argc, char** argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = - (struct st_rx_frame*)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = (struct st_rx_frame *)malloc( + sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -166,7 +172,7 @@ int main(int argc, char** argv) { struct st20rc_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20rc_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 2; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -186,7 +192,8 @@ int main(int argc, char** argv) { ops_rx.framebuff_cnt = app[i]->framebuff_cnt; ops_rx.payload_type = ctx.payload_type; ops_rx.notify_frame_ready = rx_video_frame_ready; - if (ctx.hdr_split) ops_rx.flags |= ST20RC_RX_FLAG_HDR_SPLIT; + if (ctx.hdr_split) + ops_rx.flags |= ST20RC_RX_FLAG_HDR_SPLIT; rx_handle[i] = st20rc_rx_create(ctx.st, &ops_rx); if (!rx_handle[i]) { @@ -196,7 +203,8 @@ int main(int argc, char** argv) { } app[i]->handle = rx_handle[i]; - ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); goto error; @@ -210,11 +218,13 @@ int main(int argc, char** argv) { loop++; if (0 == (loop % 10)) { uint64_t end_time_ns = mtl_ptp_read_time(ctx.st); - double time_sec = (double)(end_time_ns - sart_time_ns) / (1000 * 1000 * 1000); + double time_sec = + (double)(end_time_ns - sart_time_ns) / (1000 * 1000 * 1000); for (int i = 0; i < session_num; i++) { int fb_rec = app[i]->fb_rec - app[i]->stat_fb_rec; double framerate = fb_rec / time_sec; - info("%s(%d), fps %f, %d frame received\n", __func__, i, framerate, fb_rec); + info("%s(%d), fps %f, %d frame received\n", __func__, i, framerate, + fb_rec); app[i]->stat_fb_rec = app[i]->fb_rec; } sart_time_ns = end_time_ns; @@ -234,7 +244,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_rec); ret = -EIO; } } @@ -242,11 +253,14 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20rc_rx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20rc_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) free(app[i]->framebuffs); + if (app[i]->framebuffs) + free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c b/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c index 894b3129b..36b498614 100644 --- a/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c +++ b/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c @@ -17,18 +17,18 @@ struct rx_st20p_sample_ctx { size_t frame_size; int dst_fd; - uint8_t* dst_begin; - uint8_t* dst_end; - uint8_t* dst_cursor; + uint8_t *dst_begin; + uint8_t *dst_end; + uint8_t *dst_cursor; mtl_dma_mem_handle dma_mem; - struct st20_ext_frame* ext_frames; + struct st20_ext_frame *ext_frames; int ext_idx; int fb_cnt; }; -static int rx_st20p_frame_available(void* priv) { - struct rx_st20p_sample_ctx* s = priv; +static int rx_st20p_frame_available(void *priv) { + struct rx_st20p_sample_ctx *s = priv; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -37,9 +37,9 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static int rx_st20p_query_ext_frame(void* priv, struct st_ext_frame* ext_frame, - struct st20_rx_frame_meta* meta) { - struct rx_st20p_sample_ctx* s = priv; +static int rx_st20p_query_ext_frame(void *priv, struct st_ext_frame *ext_frame, + struct st20_rx_frame_meta *meta) { + struct rx_st20p_sample_ctx *s = priv; int i = s->ext_idx; MTL_MAY_UNUSED(meta); @@ -52,12 +52,13 @@ static int rx_st20p_query_ext_frame(void* priv, struct st_ext_frame* ext_frame, /* save your private data here get it from st_frame.opaque */ /* ext_frame->opaque = ?; */ - if (++s->ext_idx >= s->fb_cnt) s->ext_idx = 0; + if (++s->ext_idx >= s->fb_cnt) + s->ext_idx = 0; return 0; } -static int rx_st20p_close_source(struct rx_st20p_sample_ctx* s) { +static int rx_st20p_close_source(struct rx_st20p_sample_ctx *s) { if (s->dst_begin) { munmap(s->dst_begin, s->dst_end - s->dst_begin); s->dst_begin = NULL; @@ -70,7 +71,8 @@ static int rx_st20p_close_source(struct rx_st20p_sample_ctx* s) { return 0; } -static int rx_st20p_open_source(struct rx_st20p_sample_ctx* s, const char* file) { +static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, + const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -89,7 +91,7 @@ static int rx_st20p_open_source(struct rx_st20p_sample_ctx* s, const char* file) return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, file); close(fd); @@ -100,15 +102,16 @@ static int rx_st20p_open_source(struct rx_st20p_sample_ctx* s, const char* file) s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, - file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, fb_cnt, file, m, f_size); return 0; } -static void rx_st20p_consume_frame(struct rx_st20p_sample_ctx* s, - struct st_frame* frame) { - if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; +static void rx_st20p_consume_frame(struct rx_st20p_sample_ctx *s, + struct st_frame *frame) { + if (s->dst_cursor + s->frame_size > s->dst_end) + s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; /* parse private data for dynamic ext frame @@ -119,17 +122,18 @@ static void rx_st20p_consume_frame(struct rx_st20p_sample_ctx* s, s->fb_recv++; } -static void* rx_st20p_frame_thread(void* arg) { - struct rx_st20p_sample_ctx* s = arg; +static void *rx_st20p_frame_thread(void *arg) { + struct rx_st20p_sample_ctx *s = arg; st20p_rx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { frame = st20p_rx_get_frame(handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -141,14 +145,15 @@ static void* rx_st20p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -159,7 +164,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct rx_st20p_sample_ctx* app[session_num]; + struct rx_st20p_sample_ctx *app[session_num]; bool equal = st_frame_fmt_equal_transport(ctx.output_fmt, ctx.fmt); // create and register rx session @@ -181,7 +186,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -201,8 +206,8 @@ int main(int argc, char** argv) { if (equal) { /* no convert, use ext frame for example */ - app[i]->ext_frames = - (struct st20_ext_frame*)malloc(sizeof(*app[i]->ext_frames) * app[i]->fb_cnt); + app[i]->ext_frames = (struct st20_ext_frame *)malloc( + sizeof(*app[i]->ext_frames) * app[i]->fb_cnt); size_t framebuff_size = st20_frame_size(ops_rx.transport_fmt, ops_rx.width, ops_rx.height); size_t fb_size = framebuff_size * app[i]->fb_cnt; @@ -216,8 +221,10 @@ int main(int argc, char** argv) { app[i]->dma_mem = dma_mem; for (int j = 0; j < app[i]->fb_cnt; ++j) { - app[i]->ext_frames[j].buf_addr = mtl_dma_mem_addr(dma_mem) + j * framebuff_size; - app[i]->ext_frames[j].buf_iova = mtl_dma_mem_iova(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_addr = + mtl_dma_mem_addr(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_iova = + mtl_dma_mem_iova(dma_mem) + j * framebuff_size; app[i]->ext_frames[j].buf_len = framebuff_size; } app[i]->ext_idx = 0; @@ -241,7 +248,8 @@ int main(int argc, char** argv) { goto error; } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -268,7 +276,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_recv); ret = -EIO; } } @@ -276,9 +285,12 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st20p_rx_free(app[i]->handle); - if (ctx.st && app[i]->dma_mem) mtl_dma_mem_free(ctx.st, app[i]->dma_mem); - if (app[i]->ext_frames) free(app[i]->ext_frames); + if (app[i]->handle) + st20p_rx_free(app[i]->handle); + if (ctx.st && app[i]->dma_mem) + mtl_dma_mem_free(ctx.st, app[i]->dma_mem); + if (app[i]->ext_frames) + free(app[i]->ext_frames); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c b/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c index d421a86aa..59ea396f0 100644 --- a/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c +++ b/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c @@ -5,11 +5,13 @@ #include "../sample_util.h" /* usage: - * tx: ./build/app/TxSt20PipelineSample --p_sip 192.168.70.12 --p_tx_ip 239.168.70.100 + * tx: ./build/app/TxSt20PipelineSample --p_sip 192.168.70.12 --p_tx_ip + * 239.168.70.100 * --p_port 0000:18:00.0 --udp_port 6970 * * rx: sudo ./build/app/RxSt20pHdrSplitGpuDirect --p_sip 192.168.70.13 --p_rx_ip - * 239.168.70.100 --p_port 0000:18:00.1 --udp_port 6970 --gddr_pa 0x394200000000 + * 239.168.70.100 --p_port 0000:18:00.1 --udp_port 6970 --gddr_pa + * 0x394200000000 * --pipeline_fmt YUV422RFC4175PG2BE10 */ @@ -26,9 +28,9 @@ struct rx_st20p_hg_ctx { size_t frame_size; int dst_fd; - uint8_t* dst_begin; - uint8_t* dst_end; - uint8_t* dst_cursor; + uint8_t *dst_begin; + uint8_t *dst_end; + uint8_t *dst_cursor; int fb_cnt; size_t pg_sz; @@ -38,23 +40,25 @@ struct rx_st20p_hg_ctx { off_t cpu_copy_offset; }; -static int gaddr_profiling(struct rx_st20p_hg_ctx* ctx) { +static int gaddr_profiling(struct rx_st20p_hg_ctx *ctx) { clock_t start, end; float sec; - struct st_ext_frame* frame = &ctx->gddr_frame; + struct st_ext_frame *frame = &ctx->gddr_frame; int loop_cnt; float throughput_bit; uint8_t buf[256]; - info("%s, start on %p, size %" PRIu64 "\n", __func__, frame->addr[0], frame->size); + info("%s, start on %p, size %" PRIu64 "\n", __func__, frame->addr[0], + frame->size); /* read */ loop_cnt = 3; start = clock(); /* read is very slow, not known why */ size_t r_sz = 0x100000; - if (frame->size < r_sz) r_sz = frame->size; + if (frame->size < r_sz) + r_sz = frame->size; for (int loop = 0; loop < loop_cnt; loop++) { - uint8_t* addr = (uint8_t*)frame->addr[0]; + uint8_t *addr = (uint8_t *)frame->addr[0]; for (size_t i = 0; i < r_sz; i++) { buf[i & 0xFF] = addr[i]; dbg("%s, value %u at %d\n", __func__, addr[i], (int)i); @@ -70,7 +74,7 @@ static int gaddr_profiling(struct rx_st20p_hg_ctx* ctx) { loop_cnt = 20; start = clock(); for (int loop = 0; loop < loop_cnt; loop++) { - uint8_t* addr = (uint8_t*)frame->addr[0]; + uint8_t *addr = (uint8_t *)frame->addr[0]; for (size_t i = 0; i < frame->size; i++) { addr[i] = buf[i & 0xFF]; } @@ -83,15 +87,16 @@ static int gaddr_profiling(struct rx_st20p_hg_ctx* ctx) { return 0; } -static int gddr_map(struct st_sample_context* ctx, struct st_ext_frame* frame, size_t sz, - int fd) { +static int gddr_map(struct st_sample_context *ctx, struct st_ext_frame *frame, + size_t sz, int fd) { off_t off = ctx->gddr_pa + ctx->gddr_offset; - void* map = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off); + void *map = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off); if (MAP_FAILED == map) { err("%s, map size %" PRIu64 " fail\n", __func__, sz); return -EIO; } - info("%s, map %p with size %" PRIu64 " offset %" PRIx64 "\n", __func__, map, sz, off); + info("%s, map %p with size %" PRIu64 " offset %" PRIx64 "\n", __func__, map, + sz, off); mtl_iova_t iova; if (mtl_iova_mode_get(ctx->st) == MTL_IOVA_MODE_PA) { @@ -101,7 +106,8 @@ static int gddr_map(struct st_sample_context* ctx, struct st_ext_frame* frame, s dbg("%s, iova va mode\n", __func__); iova = mtl_dma_map(ctx->st, map, sz); if (MTL_BAD_IOVA == iova) { - err("%s, dma map fail for va %p sz %" PRIu64 " fail\n", __func__, map, sz); + err("%s, dma map fail for va %p sz %" PRIu64 " fail\n", __func__, map, + sz); munmap(map, sz); return -EIO; } @@ -114,8 +120,8 @@ static int gddr_map(struct st_sample_context* ctx, struct st_ext_frame* frame, s return 0; } -static int rx_st20p_frame_available(void* priv) { - struct rx_st20p_hg_ctx* s = priv; +static int rx_st20p_frame_available(void *priv) { + struct rx_st20p_hg_ctx *s = priv; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -124,7 +130,7 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static int rx_st20p_close_source(struct rx_st20p_hg_ctx* s) { +static int rx_st20p_close_source(struct rx_st20p_hg_ctx *s) { if (s->dst_begin) { munmap(s->dst_begin, s->dst_end - s->dst_begin); s->dst_begin = NULL; @@ -137,7 +143,7 @@ static int rx_st20p_close_source(struct rx_st20p_hg_ctx* s) { return 0; } -static int rx_st20p_open_source(struct rx_st20p_hg_ctx* s, const char* file) { +static int rx_st20p_open_source(struct rx_st20p_hg_ctx *s, const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -156,7 +162,7 @@ static int rx_st20p_open_source(struct rx_st20p_hg_ctx* s, const char* file) { return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, file); close(fd); @@ -167,46 +173,51 @@ static int rx_st20p_open_source(struct rx_st20p_hg_ctx* s, const char* file) { s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, - file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, fb_cnt, file, m, f_size); return 0; } -static void rx_st20p_consume_frame(struct rx_st20p_hg_ctx* s, struct st_frame* frame) { +static void rx_st20p_consume_frame(struct rx_st20p_hg_ctx *s, + struct st_frame *frame) { if (s->dst_fd > 0) { - if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) + s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; } else { - uint32_t* d; + uint32_t *d; if (s->use_cpu_copy) { - if (s->cpu_copy_offset + s->frame_size > s->gddr_frame.size) s->cpu_copy_offset = 0; - void* gddr = s->gddr_frame.addr[0] + s->cpu_copy_offset; + if (s->cpu_copy_offset + s->frame_size > s->gddr_frame.size) + s->cpu_copy_offset = 0; + void *gddr = s->gddr_frame.addr[0] + s->cpu_copy_offset; mtl_memcpy(gddr, frame->addr[0], s->frame_size); - d = (uint32_t*)gddr; + d = (uint32_t *)gddr; s->cpu_copy_offset += s->frame_size; } else { - d = (uint32_t*)frame->addr[0]; + d = (uint32_t *)frame->addr[0]; } if (0 == (s->fb_recv % 60)) { - info("%s(%d), frame %p, value 0x%x 0x%x\n", __func__, s->idx, d, d[0], d[1]); + info("%s(%d), frame %p, value 0x%x 0x%x\n", __func__, s->idx, d, d[0], + d[1]); } } s->fb_recv++; } -static void* rx_st20p_frame_thread(void* arg) { - struct rx_st20p_hg_ctx* s = arg; +static void *rx_st20p_frame_thread(void *arg) { + struct rx_st20p_hg_ctx *s = arg; st20p_rx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { frame = st20p_rx_get_frame(handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -218,7 +229,7 @@ static void* rx_st20p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; int dev_mem_fd = -EIO; @@ -226,7 +237,8 @@ int main(int argc, char** argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; if (!ctx.use_cpu_copy) { /* enable hdr split */ @@ -242,7 +254,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct rx_st20p_hg_ctx* app[session_num]; + struct rx_st20p_hg_ctx *app[session_num]; memset(app, 0x0, sizeof(app)); @@ -275,7 +287,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -299,13 +311,16 @@ int main(int argc, char** argv) { ops_rx.notify_frame_available = rx_st20p_frame_available; /* map gddr */ - app[i]->frame_size = - st_frame_size(ops_rx.output_fmt, ops_rx.width, ops_rx.height, ops_rx.interlaced); - size_t fb_sz = app[i]->frame_size * (app[i]->fb_cnt + 1) + app[i]->pg_sz * 2; + app[i]->frame_size = st_frame_size(ops_rx.output_fmt, ops_rx.width, + ops_rx.height, ops_rx.interlaced); + size_t fb_sz = + app[i]->frame_size * (app[i]->fb_cnt + 1) + app[i]->pg_sz * 2; fb_sz = mtl_size_page_align(fb_sz, app[i]->pg_sz); ret = gddr_map(&ctx, &app[i]->gddr_frame, fb_sz, dev_mem_fd); - if (ret < 0) goto error; - if (ctx.profiling_gddr) gaddr_profiling(app[i]); + if (ret < 0) + goto error; + if (ctx.profiling_gddr) + gaddr_profiling(app[i]); if (!ctx.use_cpu_copy) { ops_rx.flags |= ST20P_RX_FLAG_HDR_SPLIT; @@ -327,7 +342,8 @@ int main(int argc, char** argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -354,7 +370,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_recv); ret = -EIO; } } @@ -362,11 +379,12 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st20p_rx_free(app[i]->handle); + if (app[i]->handle) + st20p_rx_free(app[i]->handle); if (app[i]->gddr_frame.iova[0]) { if (mtl_iova_mode_get(ctx.st) != MTL_IOVA_MODE_PA) { - mtl_dma_unmap(ctx.st, app[i]->gddr_frame.addr[0], app[i]->gddr_frame.iova[0], - app[i]->gddr_frame.size); + mtl_dma_unmap(ctx.st, app[i]->gddr_frame.addr[0], + app[i]->gddr_frame.iova[0], app[i]->gddr_frame.size); } } if (app[i]->gddr_frame.addr[0]) { @@ -378,7 +396,8 @@ int main(int argc, char** argv) { } } - if (dev_mem_fd > 0) close(dev_mem_fd); + if (dev_mem_fd > 0) + close(dev_mem_fd); /* release sample(st) dev */ if (ctx.st) { mtl_uninit(ctx.st); diff --git a/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c b/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c index b15226b21..8339a3cc1 100644 --- a/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c +++ b/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c @@ -17,25 +17,26 @@ struct tx_st20p_sample_ctx { pthread_mutex_t wake_mutex; size_t frame_size; - uint8_t* source_begin; + uint8_t *source_begin; mtl_iova_t source_begin_iova; - uint8_t* source_end; - uint8_t* frame_cursor; + uint8_t *source_end; + uint8_t *frame_cursor; mtl_dma_mem_handle dma_mem; }; -static int tx_st20p_close_source(struct tx_st20p_sample_ctx* s) { - if (s->dma_mem) mtl_dma_mem_free(s->st, s->dma_mem); +static int tx_st20p_close_source(struct tx_st20p_sample_ctx *s) { + if (s->dma_mem) + mtl_dma_mem_free(s->st, s->dma_mem); return 0; } -static int tx_st20p_open_source(struct tx_st20p_sample_ctx* s, char* file) { +static int tx_st20p_open_source(struct tx_st20p_sample_ctx *s, char *file) { int fd = -EIO; struct stat i; int frame_cnt = 2; - uint8_t* m = NULL; + uint8_t *m = NULL; size_t fbs_size = s->frame_size * frame_cnt; fd = st_open(file, O_RDONLY); @@ -56,8 +57,8 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx* s, char* file) { return -EIO; } if (i.st_size % s->frame_size) { - err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", __func__, file, - s->frame_size); + err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", + __func__, file, s->frame_size); close(fd); return -EIO; } @@ -81,8 +82,10 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx* s, char* file) { mtl_dma_mem_handle dma_mem = mtl_dma_mem_alloc(s->st, fbs_size); if (!dma_mem) { err("%s(%d), dma mem alloc/map fail\n", __func__, s->idx); - if (m) munmap(m, fbs_size); - if (fd >= 0) close(fd); + if (m) + munmap(m, fbs_size); + if (fd >= 0) + close(fd); return -EIO; } s->dma_mem = dma_mem; @@ -100,15 +103,17 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx* s, char* file) { munmap(m, fbs_size); } s->source_end = s->source_begin + fbs_size; - info("%s, source begin at %p, end at %p\n", __func__, s->source_begin, s->source_end); + info("%s, source begin at %p, end at %p\n", __func__, s->source_begin, + s->source_end); - if (fd >= 0) close(fd); + if (fd >= 0) + close(fd); return 0; } -static int tx_st20p_frame_available(void* priv) { - struct tx_st20p_sample_ctx* s = priv; +static int tx_st20p_frame_available(void *priv) { + struct tx_st20p_sample_ctx *s = priv; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -117,7 +122,7 @@ static int tx_st20p_frame_available(void* priv) { return 0; } -static int tx_st20p_frame_done(void* priv, struct st_frame* frame) { +static int tx_st20p_frame_done(void *priv, struct st_frame *frame) { MTL_MAY_UNUSED(priv); MTL_MAY_UNUSED(frame); @@ -127,32 +132,36 @@ static int tx_st20p_frame_done(void* priv, struct st_frame* frame) { return 0; } -static void* tx_st20p_frame_thread(void* arg) { - struct tx_st20p_sample_ctx* s = arg; +static void *tx_st20p_frame_thread(void *arg) { + struct tx_st20p_sample_ctx *s = arg; st20p_tx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { frame = st20p_tx_get_frame(handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } struct st_ext_frame ext_frame; ext_frame.addr[0] = s->frame_cursor; - ext_frame.iova[0] = s->source_begin_iova + (s->frame_cursor - s->source_begin); - ext_frame.linesize[0] = st_frame_least_linesize(frame->fmt, frame->width, 0); + ext_frame.iova[0] = + s->source_begin_iova + (s->frame_cursor - s->source_begin); + ext_frame.linesize[0] = + st_frame_least_linesize(frame->fmt, frame->width, 0); uint8_t planes = st_frame_fmt_planes(frame->fmt); - for (uint8_t plane = 1; plane < planes; plane++) { /* assume planes continous */ + for (uint8_t plane = 1; plane < planes; + plane++) { /* assume planes continous */ ext_frame.linesize[plane] = st_frame_least_linesize(frame->fmt, frame->width, plane); - ext_frame.addr[plane] = (uint8_t*)ext_frame.addr[plane - 1] + + ext_frame.addr[plane] = (uint8_t *)ext_frame.addr[plane - 1] + + ext_frame.linesize[plane - 1] * frame->height; + ext_frame.iova[plane] = ext_frame.iova[plane - 1] + ext_frame.linesize[plane - 1] * frame->height; - ext_frame.iova[plane] = - ext_frame.iova[plane - 1] + ext_frame.linesize[plane - 1] * frame->height; } ext_frame.size = s->frame_size; ext_frame.opaque = NULL; @@ -171,14 +180,15 @@ static void* tx_st20p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -189,7 +199,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct tx_st20p_sample_ctx* app[session_num]; + struct tx_st20p_sample_ctx *app[session_num]; // create and register tx session for (int i = 0; i < session_num; i++) { @@ -209,16 +219,16 @@ int main(int argc, char** argv) { struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], + ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -251,7 +261,8 @@ int main(int argc, char** argv) { goto error; } - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -288,7 +299,8 @@ int main(int argc, char** argv) { if (app[i]) { st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->handle) st20p_tx_free(app[i]->handle); + if (app[i]->handle) + st20p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/ext_frame/tx_video_split_sample.c b/app/sample/ext_frame/tx_video_split_sample.c index 7fc770cd2..66a6eae1b 100644 --- a/app/sample/ext_frame/tx_video_split_sample.c +++ b/app/sample/ext_frame/tx_video_split_sample.c @@ -21,13 +21,14 @@ struct tv_split_sample_ctx { mtl_dma_mem_handle dma_mem; }; -static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct tv_split_sample_ctx* s = priv; +static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct tv_split_sample_ctx *s = priv; int ret = 0; MTL_MAY_UNUSED(meta); - if (!s->handle) return -EIO; /* not ready */ + if (!s->handle) + return -EIO; /* not ready */ /* the fb_idx of each session is not synced here, * which may need to consider in real production */ @@ -41,16 +42,19 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, *next_frame_idx = s->nfi; s->nfi++; - if (s->nfi >= s->fb_cnt) s->nfi = 0; + if (s->nfi >= s->fb_cnt) + s->nfi = 0; s->fb_idx++; - if (s->fb_idx >= s->fb_total) s->fb_idx = 0; + if (s->fb_idx >= s->fb_total) + s->fb_idx = 0; return ret; } -int tx_video_frame_done(void* priv, uint16_t frame_idx, struct st20_tx_frame_meta* meta) { - struct tv_split_sample_ctx* s = priv; +int tx_video_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct tv_split_sample_ctx *s = priv; MTL_MAY_UNUSED(frame_idx); MTL_MAY_UNUSED(meta); @@ -60,10 +64,10 @@ int tx_video_frame_done(void* priv, uint16_t frame_idx, struct st20_tx_frame_met return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int session_num = 4; mtl_dma_mem_handle dma_mem = NULL; - uint8_t* m = NULL; + uint8_t *m = NULL; size_t map_size = 0; struct st_sample_context ctx; int ret; @@ -84,12 +88,13 @@ int main(int argc, char** argv) { st20_tx_handle tx_handle[session_num]; memset(tx_handle, 0, sizeof(tx_handle)); - struct tv_split_sample_ctx* app[session_num]; + struct tv_split_sample_ctx *app[session_num]; memset(app, 0, sizeof(app)); // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = (struct tv_split_sample_ctx*)malloc(sizeof(struct tv_split_sample_ctx)); + app[i] = (struct tv_split_sample_ctx *)malloc( + sizeof(struct tv_split_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -105,7 +110,7 @@ int main(int argc, char** argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_tx"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -158,7 +163,8 @@ int main(int argc, char** argv) { goto error; } if (st.st_size < (app[i]->fb_size * app[i]->fb_cnt)) { - err("%s, %s file size too small %" PRIu64 "\n", __func__, ctx.tx_url, st.st_size); + err("%s, %s file size too small %" PRIu64 "\n", __func__, ctx.tx_url, + st.st_size); close(fd); ret = -EIO; goto error; @@ -180,7 +186,7 @@ int main(int argc, char** argv) { goto error; } if (m) { - void* dst = mtl_dma_mem_addr(dma_mem); + void *dst = mtl_dma_mem_addr(dma_mem); mtl_memcpy(dst, m, map_size); munmap(m, map_size); } @@ -211,12 +217,15 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20_tx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20_tx_free(app[i]->handle); info("%s(%d), sent frames %d\n", __func__, i, app[i]->fb_send); free(app[i]); } - if (dma_mem) mtl_dma_mem_free(ctx.st, dma_mem); + if (dma_mem) + mtl_dma_mem_free(ctx.st, dma_mem); /* release sample(st) dev */ if (ctx.st) { diff --git a/app/sample/fwd/rx_st20_tx_st20_split_fwd.c b/app/sample/fwd/rx_st20_tx_st20_split_fwd.c index 8c7799123..c0f9a6ed9 100644 --- a/app/sample/fwd/rx_st20_tx_st20_split_fwd.c +++ b/app/sample/fwd/rx_st20_tx_st20_split_fwd.c @@ -11,7 +11,7 @@ #define FB_CNT (4) /* 2 is not enough for this case */ struct frame_info { - void* frame_addr; + void *frame_addr; atomic_int refcnt; uint64_t tmstamp; TAILQ_ENTRY(frame_info) tailq; @@ -20,7 +20,7 @@ struct frame_info { TAILQ_HEAD(frameq, frame_info); struct tx_ctx { - void* app; + void *app; st20_tx_handle tx_handle; size_t fb_offset; int fb_idx; @@ -31,7 +31,7 @@ struct split_fwd_sample_ctx { st20_rx_handle rx_handle; struct frameq q; - struct frame_info* sending_frames[FB_CNT]; + struct frame_info *sending_frames[FB_CNT]; struct tx_ctx tx[4]; size_t fb_size; @@ -41,8 +41,8 @@ struct split_fwd_sample_ctx { int fb_fwd; }; -static int sending_frames_insert(struct split_fwd_sample_ctx* app, - struct frame_info* fi) { +static int sending_frames_insert(struct split_fwd_sample_ctx *app, + struct frame_info *fi) { int i; for (i = 0; i < FB_CNT; i++) { if (app->sending_frames[i] == NULL) { @@ -57,10 +57,11 @@ static int sending_frames_insert(struct split_fwd_sample_ctx* app, return 0; } -static int sending_frames_delete(struct split_fwd_sample_ctx* app, uint64_t tmstamp) { +static int sending_frames_delete(struct split_fwd_sample_ctx *app, + uint64_t tmstamp) { int i; for (i = 0; i < FB_CNT; i++) { - struct frame_info* fi = app->sending_frames[i]; + struct frame_info *fi = app->sending_frames[i]; if (fi && fi->tmstamp == tmstamp) { atomic_fetch_sub(&fi->refcnt, 1); if (atomic_load(&fi->refcnt) == 0) { @@ -80,18 +81,22 @@ static int sending_frames_delete(struct split_fwd_sample_ctx* app, uint64_t tmst return 0; } -static int rx_st20_frame_ready(void* priv, void* frame, struct st20_rx_frame_meta* meta) { - struct split_fwd_sample_ctx* s = (struct split_fwd_sample_ctx*)priv; +static int rx_st20_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct split_fwd_sample_ctx *s = (struct split_fwd_sample_ctx *)priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; /* incomplete frame */ - if (!st_is_frame_complete(meta->status) || meta->tfmt != ST10_TIMESTAMP_FMT_MEDIA_CLK) { + if (!st_is_frame_complete(meta->status) || + meta->tfmt != ST10_TIMESTAMP_FMT_MEDIA_CLK) { st20_rx_put_framebuff(s->rx_handle, frame); return -EIO; } - struct frame_info* fi = (struct frame_info*)malloc(sizeof(struct frame_info)); + struct frame_info *fi = + (struct frame_info *)malloc(sizeof(struct frame_info)); if (!fi) { st20_rx_put_framebuff(s->rx_handle, frame); return -EIO; @@ -107,17 +112,18 @@ static int rx_st20_frame_ready(void* priv, void* frame, struct st20_rx_frame_met return 0; } -static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct tx_ctx* s = priv; - struct split_fwd_sample_ctx* app = s->app; +static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct tx_ctx *s = priv; + struct split_fwd_sample_ctx *app = s->app; - if (!app->ready) return -EIO; + if (!app->ready) + return -EIO; int ret; int consumer_idx = s->fb_idx; - struct frame_info* fi = TAILQ_FIRST(&app->q); + struct frame_info *fi = TAILQ_FIRST(&app->q); if (fi) { ret = 0; *next_frame_idx = consumer_idx; @@ -126,7 +132,8 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, struct st20_ext_frame ext_frame; ext_frame.buf_addr = fi->frame_addr + s->fb_offset; - ext_frame.buf_iova = mtl_hp_virt2iova(app->st, fi->frame_addr) + s->fb_offset; + ext_frame.buf_iova = + mtl_hp_virt2iova(app->st, fi->frame_addr) + s->fb_offset; ext_frame.buf_len = app->fb_size / 2; st20_tx_set_ext_frame(s->tx_handle, consumer_idx, &ext_frame); @@ -143,7 +150,8 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, } consumer_idx++; - if (consumer_idx >= FB_CNT) consumer_idx = 0; + if (consumer_idx >= FB_CNT) + consumer_idx = 0; s->fb_idx = consumer_idx; } else { /* not ready */ @@ -153,19 +161,20 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int tx_video_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - struct tx_ctx* s = priv; - struct split_fwd_sample_ctx* app = s->app; +static int tx_video_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct tx_ctx *s = priv; + struct split_fwd_sample_ctx *app = s->app; MTL_MAY_UNUSED(frame_idx); /* try to release the sending frame */ - if (app->ready) sending_frames_delete(app, meta->timestamp); + if (app->ready) + sending_frames_delete(app, meta->timestamp); return 0; } -static int split_fwd_sample_free_app(struct split_fwd_sample_ctx* app) { +static int split_fwd_sample_free_app(struct split_fwd_sample_ctx *app) { for (int i = 0; i < 4; i++) { if (app->tx[i].tx_handle) { st20_tx_free(app->tx[i].tx_handle); @@ -173,7 +182,7 @@ static int split_fwd_sample_free_app(struct split_fwd_sample_ctx* app) { } } - struct frame_info* fi = NULL; + struct frame_info *fi = NULL; while (!TAILQ_EMPTY(&app->q)) { fi = TAILQ_FIRST(&app->q); TAILQ_REMOVE(&app->q, fi, tailq); @@ -188,7 +197,7 @@ static int split_fwd_sample_free_app(struct split_fwd_sample_ctx* app) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int session_num = 4; struct st_sample_context ctx; int ret = -EIO; @@ -221,10 +230,12 @@ int main(int argc, char** argv) { ops_rx.name = "st20_fwd"; ops_rx.priv = &app; ops_rx.num_port = 1; - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - ops_rx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port; // user config the udp port. + ops_rx.udp_port[MTL_SESSION_PORT_P] = + ctx.udp_port; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_FRAME_LEVEL; ops_rx.width = ctx.width; @@ -245,7 +256,7 @@ int main(int argc, char** argv) { app.rx_handle = rx_handle; for (int i = 0; i < 4; i++) { - struct tx_ctx* tx = &app.tx[i]; + struct tx_ctx *tx = &app.tx[i]; tx->app = &app; struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); @@ -283,7 +294,8 @@ int main(int argc, char** argv) { app.tx[0].fb_offset = 0; /* origin */ app.tx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.tx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.tx[2].fb_offset = + (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.tx[3].fb_offset = app.tx[2].fb_offset + app.tx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; diff --git a/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c index 20e3318fb..fad7eeaf2 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c @@ -21,10 +21,11 @@ struct rx_st20p_tx_st20p_sample_ctx { struct st20_pgroup st20_pg; }; -static int tx_st20p_frame_available(void* priv) { - struct rx_st20p_tx_st20p_sample_ctx* s = priv; +static int tx_st20p_frame_available(void *priv) { + struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -33,10 +34,11 @@ static int tx_st20p_frame_available(void* priv) { return 0; } -static int rx_st20p_frame_available(void* priv) { - struct rx_st20p_tx_st20p_sample_ctx* s = priv; +static int rx_st20p_frame_available(void *priv) { + struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -45,16 +47,17 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx* s, - struct st_frame* frame) { +static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx *s, + struct st_frame *frame) { st20p_tx_handle tx_handle = s->tx_handle; - struct st_frame* tx_frame; + struct st_frame *tx_frame; while (!s->stop) { tx_frame = st20p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -67,17 +70,18 @@ static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx* s, } } -static void* st20_fwd_st20_thread(void* arg) { - struct rx_st20p_tx_st20p_sample_ctx* s = arg; +static void *st20_fwd_st20_thread(void *arg) { + struct rx_st20p_tx_st20p_sample_ctx *s = arg; st20p_rx_handle rx_handle = s->rx_handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -90,7 +94,8 @@ static void* st20_fwd_st20_thread(void* arg) { return NULL; } -static int rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx* app) { +static int +rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx *app) { if (app->tx_handle) { st20p_tx_free(app->tx_handle); app->tx_handle = NULL; @@ -105,14 +110,15 @@ static int rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx* app) return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -135,7 +141,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -164,7 +170,7 @@ int main(int argc, char** argv) { struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_fwd"; - ops_tx.priv = &app; // app handle register to lib + ops_tx.priv = &app; // app handle register to lib ops_tx.port.num_port = 1; memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); diff --git a/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c index 371d2df21..734cf0118 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c @@ -9,7 +9,7 @@ struct rx_ctx { size_t fb_offset; pthread_cond_t rx_wake_cond; pthread_mutex_t rx_wake_mutex; - void* app; + void *app; int fb_rcv; }; @@ -30,10 +30,11 @@ struct merge_fwd_sample_ctx { bool sync_tmstamp; }; -static int tx_st20p_frame_available(void* priv) { - struct merge_fwd_sample_ctx* s = priv; +static int tx_st20p_frame_available(void *priv) { + struct merge_fwd_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->tx_wake_mutex); st_pthread_cond_signal(&s->tx_wake_cond); @@ -42,11 +43,12 @@ static int tx_st20p_frame_available(void* priv) { return 0; } -static int rx_st20p_frame_available(void* priv) { - struct rx_ctx* s = priv; - struct merge_fwd_sample_ctx* app = s->app; +static int rx_st20p_frame_available(void *priv) { + struct rx_ctx *s = priv; + struct merge_fwd_sample_ctx *app = s->app; - if (!app->ready) return -EIO; + if (!app->ready) + return -EIO; st_pthread_mutex_lock(&s->rx_wake_mutex); st_pthread_cond_signal(&s->rx_wake_cond); @@ -55,14 +57,14 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static void* tx_st20p_fwd_thread(void* args) { - struct merge_fwd_sample_ctx* s = args; +static void *tx_st20p_fwd_thread(void *args) { + struct merge_fwd_sample_ctx *s = args; st20p_tx_handle tx_handle = s->tx_handle; - struct st_frame* frame; + struct st_frame *frame; struct st_frame down_frame = {0}; /* empty temp frame*/ /* in case when timestamp mismatch */ - struct st_frame* rx_restore_frame = NULL; + struct st_frame *rx_restore_frame = NULL; int rx_restore_idx = -1; loop_entry: @@ -71,20 +73,22 @@ static void* tx_st20p_fwd_thread(void* args) { frame = st20p_tx_get_frame(tx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->tx_wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); st_pthread_mutex_unlock(&s->tx_wake_mutex); continue; } /* set downsample frame */ - down_frame.linesize[0] = frame->linesize[0]; /* leave paddings for neighbor frame */ + down_frame.linesize[0] = + frame->linesize[0]; /* leave paddings for neighbor frame */ down_frame.width = frame->width / 2; down_frame.height = frame->height / 2; down_frame.fmt = frame->fmt; for (int i = 0; i < 4; i++) { - struct rx_ctx* rx = &s->rx[i]; + struct rx_ctx *rx = &s->rx[i]; st20p_rx_handle rx_handle = rx->rx_handle; - struct st_frame* rx_frame = NULL; + struct st_frame *rx_frame = NULL; while (!s->stop && !rx_frame) { if (rx_restore_frame && rx_restore_idx == i) { @@ -93,14 +97,16 @@ static void* tx_st20p_fwd_thread(void* args) { rx_frame = st20p_rx_get_frame(rx_handle); if (!rx_frame) { /* no frame */ st_pthread_mutex_lock(&rx->rx_wake_mutex); - if (!s->stop) st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); st_pthread_mutex_unlock(&rx->rx_wake_mutex); continue; } } if (s->sync_tmstamp) { uint64_t tmstamp = rx_frame->timestamp; - if (!tx_tmstamp) tx_tmstamp = tmstamp; + if (!tx_tmstamp) + tx_tmstamp = tmstamp; if (tx_tmstamp < tmstamp) { err("%s, newer timestamp occurs %" PRIu64 ", frame %" PRIu64 " may have dropped packets\n", @@ -140,7 +146,7 @@ static void* tx_st20p_fwd_thread(void* args) { return NULL; } -static int split_fwd_sample_free_app(struct merge_fwd_sample_ctx* app) { +static int split_fwd_sample_free_app(struct merge_fwd_sample_ctx *app) { for (int i = 0; i < 4; i++) { if (app->rx[i].rx_handle) { st20p_rx_free(app->rx[i].rx_handle); @@ -159,7 +165,7 @@ static int split_fwd_sample_free_app(struct merge_fwd_sample_ctx* app) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int session_num = 4; struct st_sample_context ctx; int ret; @@ -185,8 +191,8 @@ int main(int argc, char** argv) { app.st = ctx.st; st_pthread_mutex_init(&app.tx_wake_mutex, NULL); st_pthread_cond_init(&app.tx_wake_cond, NULL); - app.sync_tmstamp = true; /* make sure frames to be merged have same timestamp, otherwise - disable this option */ + app.sync_tmstamp = true; /* make sure frames to be merged have same timestamp, + otherwise disable this option */ struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); @@ -207,7 +213,8 @@ int main(int argc, char** argv) { ops_tx.transport_fmt = ctx.fmt; ops_tx.device = ST_PLUGIN_DEVICE_AUTO; ops_tx.framebuff_cnt = ctx.framebuff_cnt; - if (app.sync_tmstamp) ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; + if (app.sync_tmstamp) + ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; ops_tx.notify_frame_available = tx_st20p_frame_available; st20p_tx_handle tx_handle = st20p_tx_create(ctx.st, &ops_tx); if (!tx_handle) { @@ -218,7 +225,7 @@ int main(int argc, char** argv) { app.tx_handle = tx_handle; for (int i = 0; i < 4; i++) { - struct rx_ctx* rx = &app.rx[i]; + struct rx_ctx *rx = &app.rx[i]; st_pthread_mutex_init(&rx->rx_wake_mutex, NULL); st_pthread_cond_init(&rx->rx_wake_cond, NULL); rx->app = &app; @@ -263,7 +270,8 @@ int main(int argc, char** argv) { st20_get_pgroup(ctx.fmt, &st20_pg); app.rx[0].fb_offset = 0; app.rx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.rx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.rx[2].fb_offset = + (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.rx[3].fb_offset = app.rx[2].fb_offset + app.rx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; @@ -279,7 +287,7 @@ int main(int argc, char** argv) { st_pthread_cond_signal(&app.tx_wake_cond); st_pthread_mutex_unlock(&app.tx_wake_mutex); for (int i = 0; i < 4; i++) { - struct rx_ctx* rx = &app.rx[i]; + struct rx_ctx *rx = &app.rx[i]; st_pthread_mutex_lock(&rx->rx_wake_mutex); st_pthread_cond_signal(&rx->rx_wake_cond); st_pthread_mutex_unlock(&rx->rx_wake_mutex); diff --git a/app/sample/fwd/rx_st20p_tx_st20p_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_fwd.c index 574f62c9e..bc59dd878 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_fwd.c @@ -19,20 +19,20 @@ struct rx_st20p_tx_st20p_sample_ctx { pthread_mutex_t wake_mutex; size_t framebuff_size; - struct st_frame** framebuffs; + struct st_frame **framebuffs; uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; /* logo */ - void* logo_buf; + void *logo_buf; struct st_frame logo_meta; bool zero_copy; }; -static int rx_st20p_enqueue_frame(struct rx_st20p_tx_st20p_sample_ctx* s, - struct st_frame* frame) { +static int rx_st20p_enqueue_frame(struct rx_st20p_tx_st20p_sample_ctx *s, + struct st_frame *frame) { uint16_t producer_idx = s->framebuff_producer_idx; if (s->framebuffs[producer_idx] != NULL) { err("%s, queue full!\n", __func__); @@ -41,25 +41,29 @@ static int rx_st20p_enqueue_frame(struct rx_st20p_tx_st20p_sample_ctx* s, s->framebuffs[producer_idx] = frame; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -struct st_frame* rx_st20p_dequeue_frame(struct rx_st20p_tx_st20p_sample_ctx* s) { +struct st_frame * +rx_st20p_dequeue_frame(struct rx_st20p_tx_st20p_sample_ctx *s) { uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_frame* frame = s->framebuffs[consumer_idx]; + struct st_frame *frame = s->framebuffs[consumer_idx]; s->framebuffs[consumer_idx] = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; return frame; } -static int st20_fwd_open_logo(struct st_sample_context* ctx, - struct rx_st20p_tx_st20p_sample_ctx* s, char* file) { - FILE* fp_logo = st_fopen(file, "rb"); +static int st20_fwd_open_logo(struct st_sample_context *ctx, + struct rx_st20p_tx_st20p_sample_ctx *s, + char *file) { + FILE *fp_logo = st_fopen(file, "rb"); if (!fp_logo) { err("%s, open %s fail\n", __func__, file); return -EIO; @@ -93,14 +97,15 @@ static int st20_fwd_open_logo(struct st_sample_context* ctx, } /* only used when zero_copy enabled */ -static int tx_st20p_frame_done(void* priv, struct st_frame* frame) { - struct rx_st20p_tx_st20p_sample_ctx* s = priv; +static int tx_st20p_frame_done(void *priv, struct st_frame *frame) { + struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st20p_rx_handle rx_handle = s->rx_handle; - struct st_frame* rx_frame = rx_st20p_dequeue_frame(s); + struct st_frame *rx_frame = rx_st20p_dequeue_frame(s); if (frame->addr[0] != rx_frame->addr[0]) { err("%s, frame ooo, should not happen!\n", __func__); return -EIO; @@ -109,10 +114,11 @@ static int tx_st20p_frame_done(void* priv, struct st_frame* frame) { return 0; } -static int tx_st20p_frame_available(void* priv) { - struct rx_st20p_tx_st20p_sample_ctx* s = priv; +static int tx_st20p_frame_available(void *priv) { + struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -121,10 +127,12 @@ static int tx_st20p_frame_available(void* priv) { return 0; } -static int rx_st20p_frame_available(void* priv) { - struct rx_st20p_tx_st20p_sample_ctx* s = (struct rx_st20p_tx_st20p_sample_ctx*)priv; +static int rx_st20p_frame_available(void *priv) { + struct rx_st20p_tx_st20p_sample_ctx *s = + (struct rx_st20p_tx_st20p_sample_ctx *)priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -133,14 +141,14 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx* s, - struct st_frame* frame) { +static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx *s, + struct st_frame *frame) { st20p_tx_handle tx_handle = s->tx_handle; - struct st_frame* tx_frame; + struct st_frame *tx_frame; if (frame->data_size != s->framebuff_size) { - err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, s->idx, - frame->data_size, s->framebuff_size); + err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, + s->idx, frame->data_size, s->framebuff_size); return; } @@ -148,7 +156,8 @@ static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx* s, tx_frame = st20p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -174,17 +183,18 @@ static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx* s, } } -static void* st20_fwd_st20_thread(void* arg) { - struct rx_st20p_tx_st20p_sample_ctx* s = arg; +static void *st20_fwd_st20_thread(void *arg) { + struct rx_st20p_tx_st20p_sample_ctx *s = arg; st20p_rx_handle rx_handle = s->rx_handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -207,7 +217,8 @@ static void* st20_fwd_st20_thread(void* arg) { return NULL; } -static int rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx* app) { +static int +rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx *app) { if (app->tx_handle) { st20p_tx_free(app->tx_handle); app->tx_handle = NULL; @@ -230,14 +241,15 @@ static int rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx* app) return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -259,7 +271,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -288,7 +300,7 @@ int main(int argc, char** argv) { struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_fwd"; - ops_tx.priv = &app; // app handle register to lib + ops_tx.priv = &app; // app handle register to lib ops_tx.port.num_port = 1; memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -320,13 +332,14 @@ int main(int argc, char** argv) { app.framebuff_size = st20p_tx_frame_size(tx_handle); app.framebuff_cnt = ops_tx.framebuff_cnt; app.framebuffs = - (struct st_frame**)malloc(sizeof(struct st_frame*) * app.framebuff_cnt); + (struct st_frame **)malloc(sizeof(struct st_frame *) * app.framebuff_cnt); if (!app.framebuffs) { err("%s, framebuffs ctx malloc fail\n", __func__); ret = -ENOMEM; goto error; } - for (uint16_t j = 0; j < app.framebuff_cnt; j++) app.framebuffs[j] = NULL; + for (uint16_t j = 0; j < app.framebuff_cnt; j++) + app.framebuffs[j] = NULL; app.framebuff_producer_idx = 0; app.framebuff_consumer_idx = 0; diff --git a/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c index 527f8d4a8..b161dfaf7 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c @@ -9,7 +9,7 @@ struct rx_ctx { size_t fb_offset; pthread_cond_t rx_wake_cond; pthread_mutex_t rx_wake_mutex; - void* app; + void *app; int fb_rcv; }; @@ -30,10 +30,11 @@ struct merge_fwd_sample_ctx { bool sync_tmstamp; }; -static int tx_st20p_frame_available(void* priv) { - struct merge_fwd_sample_ctx* s = priv; +static int tx_st20p_frame_available(void *priv) { + struct merge_fwd_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->tx_wake_mutex); st_pthread_cond_signal(&s->tx_wake_cond); @@ -42,11 +43,12 @@ static int tx_st20p_frame_available(void* priv) { return 0; } -static int rx_st20p_frame_available(void* priv) { - struct rx_ctx* s = priv; - struct merge_fwd_sample_ctx* app = s->app; +static int rx_st20p_frame_available(void *priv) { + struct rx_ctx *s = priv; + struct merge_fwd_sample_ctx *app = s->app; - if (!app->ready) return -EIO; + if (!app->ready) + return -EIO; st_pthread_mutex_lock(&s->rx_wake_mutex); st_pthread_cond_signal(&s->rx_wake_cond); @@ -55,13 +57,13 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static void* tx_st20p_fwd_thread(void* args) { - struct merge_fwd_sample_ctx* s = args; +static void *tx_st20p_fwd_thread(void *args) { + struct merge_fwd_sample_ctx *s = args; st20p_tx_handle tx_handle = s->tx_handle; - struct st_frame* frame; + struct st_frame *frame; /* in case when timestamp mismatch */ - struct st_frame* rx_restore_frame = NULL; + struct st_frame *rx_restore_frame = NULL; int rx_restore_idx = -1; loop_entry: @@ -70,15 +72,16 @@ static void* tx_st20p_fwd_thread(void* args) { frame = st20p_tx_get_frame(tx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->tx_wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); st_pthread_mutex_unlock(&s->tx_wake_mutex); continue; } for (int i = 0; i < 4; i++) { - struct rx_ctx* rx = &s->rx[i]; + struct rx_ctx *rx = &s->rx[i]; st20p_rx_handle rx_handle = rx->rx_handle; - struct st_frame* rx_frame = NULL; + struct st_frame *rx_frame = NULL; while (!s->stop && !rx_frame) { if (rx_restore_frame && rx_restore_idx == i) { @@ -87,14 +90,16 @@ static void* tx_st20p_fwd_thread(void* args) { rx_frame = st20p_rx_get_frame(rx_handle); if (!rx_frame) { /* no frame */ st_pthread_mutex_lock(&rx->rx_wake_mutex); - if (!s->stop) st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); st_pthread_mutex_unlock(&rx->rx_wake_mutex); continue; } } if (s->sync_tmstamp) { uint64_t tmstamp = rx_frame->timestamp; - if (!tx_tmstamp) tx_tmstamp = tmstamp; + if (!tx_tmstamp) + tx_tmstamp = tmstamp; if (tx_tmstamp < tmstamp) { err("%s, newer timestamp occurs %" PRIu64 ", frame %" PRIu64 " may have dropped packets\n", @@ -112,8 +117,8 @@ static void* tx_st20p_fwd_thread(void* args) { } /* copy frame */ - uint8_t* src = rx_frame->addr[0]; - uint8_t* dst = frame->addr[0] + rx->fb_offset; + uint8_t *src = rx_frame->addr[0]; + uint8_t *dst = frame->addr[0] + rx->fb_offset; uint32_t src_linesize = rx_frame->linesize[0]; uint32_t dst_linesize = frame->linesize[0]; for (int line = 0; line < rx_frame->height; line++) { @@ -142,7 +147,7 @@ static void* tx_st20p_fwd_thread(void* args) { return NULL; } -static int split_fwd_sample_free_app(struct merge_fwd_sample_ctx* app) { +static int split_fwd_sample_free_app(struct merge_fwd_sample_ctx *app) { for (int i = 0; i < 4; i++) { if (app->rx[i].rx_handle) { st20p_rx_free(app->rx[i].rx_handle); @@ -161,7 +166,7 @@ static int split_fwd_sample_free_app(struct merge_fwd_sample_ctx* app) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int session_num = 4; struct st_sample_context ctx; int ret; @@ -187,8 +192,8 @@ int main(int argc, char** argv) { app.st = ctx.st; st_pthread_mutex_init(&app.tx_wake_mutex, NULL); st_pthread_cond_init(&app.tx_wake_cond, NULL); - app.sync_tmstamp = true; /* make sure frames to be merged have same timestamp, otherwise - disable this option */ + app.sync_tmstamp = true; /* make sure frames to be merged have same timestamp, + otherwise disable this option */ struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); @@ -209,7 +214,8 @@ int main(int argc, char** argv) { ops_tx.transport_fmt = ctx.fmt; ops_tx.device = ST_PLUGIN_DEVICE_AUTO; ops_tx.framebuff_cnt = ctx.framebuff_cnt; - if (app.sync_tmstamp) ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; + if (app.sync_tmstamp) + ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; ops_tx.notify_frame_available = tx_st20p_frame_available; st20p_tx_handle tx_handle = st20p_tx_create(ctx.st, &ops_tx); if (!tx_handle) { @@ -220,7 +226,7 @@ int main(int argc, char** argv) { app.tx_handle = tx_handle; for (int i = 0; i < 4; i++) { - struct rx_ctx* rx = &app.rx[i]; + struct rx_ctx *rx = &app.rx[i]; st_pthread_mutex_init(&rx->rx_wake_mutex, NULL); st_pthread_cond_init(&rx->rx_wake_cond, NULL); rx->app = &app; @@ -265,7 +271,8 @@ int main(int argc, char** argv) { st20_get_pgroup(ctx.fmt, &st20_pg); app.rx[0].fb_offset = 0; app.rx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.rx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.rx[2].fb_offset = + (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.rx[3].fb_offset = app.rx[2].fb_offset + app.rx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; @@ -281,7 +288,7 @@ int main(int argc, char** argv) { st_pthread_cond_signal(&app.tx_wake_cond); st_pthread_mutex_unlock(&app.tx_wake_mutex); for (int i = 0; i < 4; i++) { - struct rx_ctx* rx = &app.rx[i]; + struct rx_ctx *rx = &app.rx[i]; st_pthread_mutex_lock(&rx->rx_wake_mutex); st_pthread_cond_signal(&rx->rx_wake_cond); st_pthread_mutex_unlock(&rx->rx_wake_mutex); diff --git a/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c index 889012e20..9ff6a5728 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c @@ -9,7 +9,7 @@ struct tx_ctx { size_t fb_offset; pthread_cond_t tx_wake_cond; pthread_mutex_t tx_wake_mutex; - void* app; + void *app; }; struct split_fwd_sample_ctx { @@ -27,11 +27,12 @@ struct split_fwd_sample_ctx { int fb_fwd; }; -static int tx_st20p_frame_available(void* priv) { - struct tx_ctx* s = priv; - struct split_fwd_sample_ctx* app = s->app; +static int tx_st20p_frame_available(void *priv) { + struct tx_ctx *s = priv; + struct split_fwd_sample_ctx *app = s->app; - if (!app->ready) return -EIO; + if (!app->ready) + return -EIO; st_pthread_mutex_lock(&s->tx_wake_mutex); st_pthread_cond_signal(&s->tx_wake_cond); @@ -40,10 +41,11 @@ static int tx_st20p_frame_available(void* priv) { return 0; } -static int rx_st20p_frame_available(void* priv) { - struct split_fwd_sample_ctx* s = priv; +static int rx_st20p_frame_available(void *priv) { + struct split_fwd_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->rx_wake_mutex); st_pthread_cond_signal(&s->rx_wake_cond); @@ -52,35 +54,37 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static void* tx_st20p_fwd_thread(void* args) { - struct split_fwd_sample_ctx* s = args; +static void *tx_st20p_fwd_thread(void *args) { + struct split_fwd_sample_ctx *s = args; st20p_rx_handle rx_handle = s->rx_handle; - struct st_frame* frame; + struct st_frame *frame; while (!s->stop) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->rx_wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->rx_wake_cond, &s->rx_wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->rx_wake_cond, &s->rx_wake_mutex); st_pthread_mutex_unlock(&s->rx_wake_mutex); continue; } for (int i = 0; i < 4; i++) { - struct tx_ctx* tx = &s->tx[i]; + struct tx_ctx *tx = &s->tx[i]; st20p_tx_handle tx_handle = tx->tx_handle; - struct st_frame* tx_frame = NULL; + struct st_frame *tx_frame = NULL; while (!s->stop && !tx_frame) { tx_frame = st20p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&tx->tx_wake_mutex); - if (!s->stop) st_pthread_cond_wait(&tx->tx_wake_cond, &tx->tx_wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&tx->tx_wake_cond, &tx->tx_wake_mutex); st_pthread_mutex_unlock(&tx->tx_wake_mutex); continue; } - uint8_t* src = frame->addr[0] + tx->fb_offset; - uint8_t* dst = tx_frame->addr[0]; + uint8_t *src = frame->addr[0] + tx->fb_offset; + uint8_t *dst = tx_frame->addr[0]; uint32_t src_linesize = frame->linesize[0]; uint32_t dst_linesize = tx_frame->linesize[0]; for (int line = 0; line < tx_frame->height; line++) { @@ -102,7 +106,7 @@ static void* tx_st20p_fwd_thread(void* args) { return NULL; } -static int split_fwd_sample_free_app(struct split_fwd_sample_ctx* app) { +static int split_fwd_sample_free_app(struct split_fwd_sample_ctx *app) { for (int i = 0; i < 4; i++) { if (app->tx[i].tx_handle) { st20p_tx_free(app->tx[i].tx_handle); @@ -121,7 +125,7 @@ static int split_fwd_sample_free_app(struct split_fwd_sample_ctx* app) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int session_num = 4; struct st_sample_context ctx; int ret; @@ -151,7 +155,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_rx"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -178,7 +182,7 @@ int main(int argc, char** argv) { app.rx_handle = rx_handle; for (int i = 0; i < 4; i++) { - struct tx_ctx* tx = &app.tx[i]; + struct tx_ctx *tx = &app.tx[i]; tx->app = &app; st_pthread_mutex_init(&tx->tx_wake_mutex, NULL); st_pthread_cond_init(&tx->tx_wake_cond, NULL); @@ -187,8 +191,8 @@ int main(int argc, char** argv) { ops_tx.name = "st20p_fwd"; ops_tx.priv = tx; ops_tx.port.num_port = 1; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; @@ -223,7 +227,8 @@ int main(int argc, char** argv) { st20_get_pgroup(ctx.fmt, &st20_pg); app.tx[0].fb_offset = 0; app.tx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.tx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.tx[2].fb_offset = + (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.tx[3].fb_offset = app.tx[2].fb_offset + app.tx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; @@ -239,7 +244,7 @@ int main(int argc, char** argv) { st_pthread_cond_signal(&app.rx_wake_cond); st_pthread_mutex_unlock(&app.rx_wake_mutex); for (int i = 0; i < 4; i++) { - struct tx_ctx* tx = &app.tx[i]; + struct tx_ctx *tx = &app.tx[i]; st_pthread_mutex_lock(&tx->tx_wake_mutex); st_pthread_cond_signal(&tx->tx_wake_cond); st_pthread_mutex_unlock(&tx->tx_wake_mutex); diff --git a/app/sample/fwd/rx_st20p_tx_st22p_fwd.c b/app/sample/fwd/rx_st20p_tx_st22p_fwd.c index 668202341..b9fc8ac5b 100644 --- a/app/sample/fwd/rx_st20p_tx_st22p_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st22p_fwd.c @@ -21,13 +21,14 @@ struct rx_st20p_tx_st22p_sample_ctx { size_t framebuff_size; /* logo */ - void* logo_buf; + void *logo_buf; struct st_frame logo_meta; }; -static int st22_fwd_open_logo(struct st_sample_context* ctx, - struct rx_st20p_tx_st22p_sample_ctx* s, char* file) { - FILE* fp_logo = st_fopen(file, "rb"); +static int st22_fwd_open_logo(struct st_sample_context *ctx, + struct rx_st20p_tx_st22p_sample_ctx *s, + char *file) { + FILE *fp_logo = st_fopen(file, "rb"); if (!fp_logo) { err("%s, open %s fail\n", __func__, file); return -EIO; @@ -60,10 +61,11 @@ static int st22_fwd_open_logo(struct st_sample_context* ctx, return 0; } -static int tx_st22p_frame_available(void* priv) { - struct rx_st20p_tx_st22p_sample_ctx* s = priv; +static int tx_st22p_frame_available(void *priv) { + struct rx_st20p_tx_st22p_sample_ctx *s = priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -72,10 +74,12 @@ static int tx_st22p_frame_available(void* priv) { return 0; } -static int rx_st20p_frame_available(void* priv) { - struct rx_st20p_tx_st22p_sample_ctx* s = (struct rx_st20p_tx_st22p_sample_ctx*)priv; +static int rx_st20p_frame_available(void *priv) { + struct rx_st20p_tx_st22p_sample_ctx *s = + (struct rx_st20p_tx_st22p_sample_ctx *)priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -84,14 +88,14 @@ static int rx_st20p_frame_available(void* priv) { return 0; } -static void fwd_st22_consume_frame(struct rx_st20p_tx_st22p_sample_ctx* s, - struct st_frame* frame) { +static void fwd_st22_consume_frame(struct rx_st20p_tx_st22p_sample_ctx *s, + struct st_frame *frame) { st22p_tx_handle tx_handle = s->tx_handle; - struct st_frame* tx_frame; + struct st_frame *tx_frame; if (frame->data_size != s->framebuff_size) { - err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, s->idx, - frame->data_size, s->framebuff_size); + err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, + s->idx, frame->data_size, s->framebuff_size); return; } @@ -99,7 +103,8 @@ static void fwd_st22_consume_frame(struct rx_st20p_tx_st22p_sample_ctx* s, tx_frame = st22p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -113,17 +118,18 @@ static void fwd_st22_consume_frame(struct rx_st20p_tx_st22p_sample_ctx* s, } } -static void* st20_fwd_st22_thread(void* arg) { - struct rx_st20p_tx_st22p_sample_ctx* s = arg; +static void *st20_fwd_st22_thread(void *arg) { + struct rx_st20p_tx_st22p_sample_ctx *s = arg; st20p_rx_handle rx_handle = s->rx_handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -136,7 +142,8 @@ static void* st20_fwd_st22_thread(void* arg) { return NULL; } -static int rx_st20p_tx_st22p_free_app(struct rx_st20p_tx_st22p_sample_ctx* app) { +static int +rx_st20p_tx_st22p_free_app(struct rx_st20p_tx_st22p_sample_ctx *app) { if (app->tx_handle) { st22p_tx_free(app->tx_handle); app->tx_handle = NULL; @@ -155,7 +162,7 @@ static int rx_st20p_tx_st22p_free_app(struct rx_st20p_tx_st22p_sample_ctx* app) return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int bpp = 3; struct st_sample_context ctx; int ret; @@ -163,7 +170,8 @@ int main(int argc, char** argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -184,7 +192,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -213,7 +221,7 @@ int main(int argc, char** argv) { struct st22p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st22_fwd"; - ops_tx.priv = &app; // app handle register to lib + ops_tx.priv = &app; // app handle register to lib ops_tx.port.num_port = 1; memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); diff --git a/app/sample/legacy/rx_st20_tx_st20_fwd.c b/app/sample/legacy/rx_st20_tx_st20_fwd.c index 3cccd4295..2cd6642cd 100644 --- a/app/sample/legacy/rx_st20_tx_st20_fwd.c +++ b/app/sample/legacy/rx_st20_tx_st20_fwd.c @@ -22,22 +22,23 @@ struct rx_st20_tx_st20_sample_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_rx_frame* framebuffs; + struct st_rx_frame *framebuffs; uint16_t tx_framebuff_producer_idx; uint16_t tx_framebuff_consumer_idx; - struct st_tx_frame* tx_framebuffs; + struct st_tx_frame *tx_framebuffs; bool zero_copy; /* logo */ - void* logo_buf; + void *logo_buf; struct st_frame logo_meta; }; -static int st20_fwd_open_logo(struct st_sample_context* ctx, - struct rx_st20_tx_st20_sample_ctx* s, char* file) { - FILE* fp_logo = st_fopen(file, "rb"); +static int st20_fwd_open_logo(struct st_sample_context *ctx, + struct rx_st20_tx_st20_sample_ctx *s, + char *file) { + FILE *fp_logo = st_fopen(file, "rb"); if (!fp_logo) { err("%s, open %s fail\n", __func__, file); return -EIO; @@ -70,10 +71,10 @@ static int st20_fwd_open_logo(struct st_sample_context* ctx, return 0; } -static int rx_st20_enqueue_frame(struct rx_st20_tx_st20_sample_ctx* s, void* frame, - size_t size) { +static int rx_st20_enqueue_frame(struct rx_st20_tx_st20_sample_ctx *s, + void *frame, size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -84,15 +85,19 @@ static int rx_st20_enqueue_frame(struct rx_st20_tx_st20_sample_ctx* s, void* fra framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int rx_st20_frame_ready(void* priv, void* frame, struct st20_rx_frame_meta* meta) { - struct rx_st20_tx_st20_sample_ctx* s = (struct rx_st20_tx_st20_sample_ctx*)priv; +static int rx_st20_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct rx_st20_tx_st20_sample_ctx *s = + (struct rx_st20_tx_st20_sample_ctx *)priv; - if (!s->ready) return -EIO; + if (!s->ready) + return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -116,12 +121,12 @@ static int rx_st20_frame_ready(void* priv, void* frame, struct st20_rx_frame_met return 0; } -static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct rx_st20_tx_st20_sample_ctx* s = priv; +static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct rx_st20_tx_st20_sample_ctx *s = priv; int ret; uint16_t consumer_idx = s->tx_framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->tx_framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->tx_framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->wake_mutex); @@ -132,7 +137,8 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->tx_framebuff_consumer_idx = consumer_idx; } else { /* not ready */ @@ -144,15 +150,15 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int tx_video_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - struct rx_st20_tx_st20_sample_ctx* s = priv; +static int tx_video_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct rx_st20_tx_st20_sample_ctx *s = priv; int ret; - struct st_tx_frame* framebuff = &s->tx_framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->tx_framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); if (s->zero_copy) { /* rx framebuffer put back to lib here */ - void* frame_addr = st20_tx_get_framebuffer(s->tx_handle, frame_idx); + void *frame_addr = st20_tx_get_framebuffer(s->tx_handle, frame_idx); st20_rx_put_framebuff(s->rx_handle, frame_addr); } @@ -163,8 +169,8 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, s->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -172,15 +178,15 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, return ret; } -static void rx_fwd_consume_frame(struct rx_st20_tx_st20_sample_ctx* s, void* frame, - size_t frame_size) { +static void rx_fwd_consume_frame(struct rx_st20_tx_st20_sample_ctx *s, + void *frame, size_t frame_size) { uint16_t producer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; struct st_frame tx_frame; if (frame_size != s->framebuff_size) { - err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, s->idx, - frame_size, s->framebuff_size); + err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, + s->idx, frame_size, s->framebuff_size); return; } @@ -200,7 +206,7 @@ static void rx_fwd_consume_frame(struct rx_st20_tx_st20_sample_ctx* s, void* fra ext_frame.buf_len = s->framebuff_size; st20_tx_set_ext_frame(s->tx_handle, producer_idx, &ext_frame); } else { - void* frame_addr = st20_tx_get_framebuffer(s->tx_handle, producer_idx); + void *frame_addr = st20_tx_get_framebuffer(s->tx_handle, producer_idx); mtl_memcpy(frame_addr, frame, s->framebuff_size); } @@ -217,15 +223,16 @@ static void rx_fwd_consume_frame(struct rx_st20_tx_st20_sample_ctx* s, void* fra framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->tx_framebuff_producer_idx = producer_idx; s->fb_fwd++; } -static void* fwd_thread(void* arg) { - struct rx_st20_tx_st20_sample_ctx* s = arg; - struct st_rx_frame* rx_framebuff; +static void *fwd_thread(void *arg) { + struct rx_st20_tx_st20_sample_ctx *s = arg; + struct st_rx_frame *rx_framebuff; int consumer_idx; info("%s(%d), start\n", __func__, s->idx); @@ -235,7 +242,8 @@ static void* fwd_thread(void* arg) { rx_framebuff = &s->framebuffs[consumer_idx]; if (!rx_framebuff->frame) { /* no ready frame */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -247,7 +255,8 @@ static void* fwd_thread(void* arg) { /* point to next */ rx_framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -256,7 +265,7 @@ static void* fwd_thread(void* arg) { return NULL; } -static int rx_st20_tx_st20_free_app(struct rx_st20_tx_st20_sample_ctx* app) { +static int rx_st20_tx_st20_free_app(struct rx_st20_tx_st20_sample_ctx *app) { if (app->tx_handle) { st20_tx_free(app->tx_handle); app->tx_handle = NULL; @@ -283,14 +292,15 @@ static int rx_st20_tx_st20_free_app(struct rx_st20_tx_st20_sample_ctx* app) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -310,18 +320,19 @@ int main(int argc, char** argv) { app.framebuff_cnt = ctx.framebuff_cnt; app.framebuffs = - (struct st_rx_frame*)malloc(sizeof(*app.framebuffs) * app.framebuff_cnt); + (struct st_rx_frame *)malloc(sizeof(*app.framebuffs) * app.framebuff_cnt); if (!app.framebuffs) { err("%s, rx framebuffs ctx malloc fail\n", __func__); ret = -EIO; goto error; } - for (uint16_t j = 0; j < app.framebuff_cnt; j++) app.framebuffs[j].frame = NULL; + for (uint16_t j = 0; j < app.framebuff_cnt; j++) + app.framebuffs[j].frame = NULL; app.framebuff_producer_idx = 0; app.framebuff_consumer_idx = 0; - app.tx_framebuffs = - (struct st_tx_frame*)malloc(sizeof(*app.tx_framebuffs) * app.framebuff_cnt); + app.tx_framebuffs = (struct st_tx_frame *)malloc(sizeof(*app.tx_framebuffs) * + app.framebuff_cnt); if (!app.tx_framebuffs) { err("%s, tx framebuffs ctx malloc fail\n", __func__); ret = -EIO; @@ -337,10 +348,12 @@ int main(int argc, char** argv) { ops_rx.name = "st20_fwd"; ops_rx.priv = &app; ops_rx.num_port = 1; - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - ops_rx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port; // user config the udp port. + ops_rx.udp_port[MTL_SESSION_PORT_P] = + ctx.udp_port; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_FRAME_LEVEL; ops_rx.width = ctx.width; @@ -378,7 +391,8 @@ int main(int argc, char** argv) { ops_tx.interlaced = ctx.interlaced; ops_tx.fmt = ctx.fmt; ops_tx.payload_type = ctx.payload_type; - if (app.zero_copy) ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; + if (app.zero_copy) + ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; ops_tx.framebuff_cnt = app.framebuff_cnt; ops_tx.get_next_frame = tx_video_next_frame; ops_tx.notify_frame_done = tx_video_frame_done; diff --git a/app/sample/legacy/rx_st22_video_sample.c b/app/sample/legacy/rx_st22_video_sample.c index a9e250ebd..654d2b832 100644 --- a/app/sample/legacy/rx_st22_video_sample.c +++ b/app/sample/legacy/rx_st22_video_sample.c @@ -17,12 +17,13 @@ struct rx_st22_sample_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_rx_frame* framebuffs; + struct st_rx_frame *framebuffs; }; -static int rx_st22_enqueue_frame(struct rx_st22_sample_ctx* s, void* frame, size_t size) { +static int rx_st22_enqueue_frame(struct rx_st22_sample_ctx *s, void *frame, + size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -33,15 +34,18 @@ static int rx_st22_enqueue_frame(struct rx_st22_sample_ctx* s, void* frame, size framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int rx_st22_frame_ready(void* priv, void* frame, struct st22_rx_frame_meta* meta) { - struct rx_st22_sample_ctx* s = (struct rx_st22_sample_ctx*)priv; +static int rx_st22_frame_ready(void *priv, void *frame, + struct st22_rx_frame_meta *meta) { + struct rx_st22_sample_ctx *s = (struct rx_st22_sample_ctx *)priv; - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); int ret = rx_st22_enqueue_frame(s, frame, meta->frame_total_size); @@ -58,8 +62,8 @@ static int rx_st22_frame_ready(void* priv, void* frame, struct st22_rx_frame_met return 0; } -static void st22_decode_frame(struct rx_st22_sample_ctx* s, void* codestream_addr, - size_t codestream_size) { +static void st22_decode_frame(struct rx_st22_sample_ctx *s, + void *codestream_addr, size_t codestream_size) { MTL_MAY_UNUSED(codestream_addr); MTL_MAY_UNUSED(codestream_size); @@ -70,11 +74,11 @@ static void st22_decode_frame(struct rx_st22_sample_ctx* s, void* codestream_add s->fb_decoded++; } -static void* st22_decode_thread(void* arg) { - struct rx_st22_sample_ctx* s = arg; +static void *st22_decode_thread(void *arg) { + struct rx_st22_sample_ctx *s = arg; int idx = s->idx; int consumer_idx; - struct st_rx_frame* framebuff; + struct st_rx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->stop) { @@ -83,7 +87,8 @@ static void* st22_decode_thread(void* arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -96,7 +101,8 @@ static void* st22_decode_thread(void* arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -105,7 +111,7 @@ static void* st22_decode_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int bpp = 3; /* 3bit per pixel */ struct st_sample_context ctx; int ret; @@ -113,7 +119,8 @@ int main(int argc, char** argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -125,11 +132,12 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st22_rx_handle rx_handle[session_num]; - struct rx_st22_sample_ctx* app[session_num]; + struct rx_st22_sample_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = (struct rx_st22_sample_ctx*)malloc(sizeof(struct rx_st22_sample_ctx)); + app[i] = + (struct rx_st22_sample_ctx *)malloc(sizeof(struct rx_st22_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -140,8 +148,8 @@ int main(int argc, char** argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = - (struct st_rx_frame*)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = (struct st_rx_frame *)malloc( + sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -155,7 +163,7 @@ int main(int argc, char** argv) { struct st22_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st22_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -185,7 +193,8 @@ int main(int argc, char** argv) { app[i]->handle = rx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->decode_thread, NULL, st22_decode_thread, app[i]); + ret = pthread_create(&app[i]->decode_thread, NULL, st22_decode_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -210,7 +219,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_decoded <= 0) { - err("%s(%d), error, no decoded frames %d\n", __func__, i, app[i]->fb_decoded); + err("%s(%d), error, no decoded frames %d\n", __func__, i, + app[i]->fb_decoded); ret = -EIO; } } @@ -218,11 +228,14 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st22_rx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st22_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) free(app[i]->framebuffs); + if (app[i]->framebuffs) + free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/legacy/rx_video_sample.c b/app/sample/legacy/rx_video_sample.c index b51b9ad04..2945d7f5e 100644 --- a/app/sample/legacy/rx_video_sample.c +++ b/app/sample/legacy/rx_video_sample.c @@ -17,15 +17,16 @@ struct rv_sample_context { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_rx_frame* framebuffs; + struct st_rx_frame *framebuffs; mtl_dma_mem_handle dma_mem; - struct st20_ext_frame* ext_frames; + struct st20_ext_frame *ext_frames; }; -static int rx_video_enqueue_frame(struct rv_sample_context* s, void* frame, size_t size) { +static int rx_video_enqueue_frame(struct rv_sample_context *s, void *frame, + size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -36,23 +37,26 @@ static int rx_video_enqueue_frame(struct rv_sample_context* s, void* frame, size framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int rx_video_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - struct rv_sample_context* s = (struct rv_sample_context*)priv; +static int rx_video_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct rv_sample_context *s = (struct rv_sample_context *)priv; - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; if (meta->user_meta) { - const struct st_frame_user_meta* user_meta = meta->user_meta; + const struct st_frame_user_meta *user_meta = meta->user_meta; if (meta->user_meta_size != sizeof(*user_meta)) { err("%s(%d), user_meta_size wrong\n", __func__, s->idx); } - info("%s(%d), user_meta %d %s\n", __func__, s->idx, user_meta->idx, user_meta->dummy); + info("%s(%d), user_meta %d %s\n", __func__, s->idx, user_meta->idx, + user_meta->dummy); } /* incomplete frame */ @@ -76,7 +80,7 @@ static int rx_video_frame_ready(void* priv, void* frame, return 0; } -static void rx_video_consume_frame(struct rv_sample_context* s, void* frame, +static void rx_video_consume_frame(struct rv_sample_context *s, void *frame, size_t frame_size) { MTL_MAY_UNUSED(frame); MTL_MAY_UNUSED(frame_size); @@ -87,11 +91,11 @@ static void rx_video_consume_frame(struct rv_sample_context* s, void* frame, s->fb_rec++; } -static void* rx_video_frame_thread(void* arg) { - struct rv_sample_context* s = arg; +static void *rx_video_frame_thread(void *arg) { + struct rv_sample_context *s = arg; int idx = s->idx; int consumer_idx; - struct st_rx_frame* framebuff; + struct st_rx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->stop) { @@ -100,7 +104,8 @@ static void* rx_video_frame_thread(void* arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -113,7 +118,8 @@ static void* rx_video_frame_thread(void* arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -122,14 +128,15 @@ static void* rx_video_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -141,10 +148,11 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st20_rx_handle rx_handle[session_num]; - struct rv_sample_context* app[session_num]; + struct rv_sample_context *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = (struct rv_sample_context*)malloc(sizeof(struct rv_sample_context)); + app[i] = + (struct rv_sample_context *)malloc(sizeof(struct rv_sample_context)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -155,8 +163,8 @@ int main(int argc, char** argv) { app[i]->framebuff_cnt = ctx.framebuff_cnt; st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - app[i]->framebuffs = - (struct st_rx_frame*)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = (struct st_rx_frame *)malloc( + sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -170,14 +178,14 @@ int main(int argc, char** argv) { struct st20_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20_rx"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_rx.udp_port[MTL_SESSION_PORT_P] = - ctx.udp_port + i * 2; // user config the udp port. + ctx.udp_port + i * 2; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_FRAME_LEVEL; ops_rx.width = ctx.width; @@ -187,18 +195,20 @@ int main(int argc, char** argv) { ops_rx.fmt = ctx.fmt; ops_rx.framebuff_cnt = app[i]->framebuff_cnt; ops_rx.payload_type = ctx.payload_type; - // app register non-block func, app get a frame ready notification info by this cb + // app register non-block func, app get a frame ready notification info by + // this cb ops_rx.notify_frame_ready = rx_video_frame_ready; if (ops_rx.ext_frames) { - app[i]->ext_frames = (struct st20_ext_frame*)malloc(sizeof(*app[i]->ext_frames) * - app[i]->framebuff_cnt); + app[i]->ext_frames = (struct st20_ext_frame *)malloc( + sizeof(*app[i]->ext_frames) * app[i]->framebuff_cnt); if (!app[i]->ext_frames) { err("%s(%d), ext_frames malloc fail\n", __func__, i); ret = -ENOMEM; goto error; } - size_t framebuff_size = st20_frame_size(ops_rx.fmt, ops_rx.width, ops_rx.height); + size_t framebuff_size = + st20_frame_size(ops_rx.fmt, ops_rx.width, ops_rx.height); size_t fb_size = framebuff_size * app[i]->framebuff_cnt; /* alloc enough memory to hold framebuffers and map to iova */ mtl_dma_mem_handle dma_mem = mtl_dma_mem_alloc(ctx.st, fb_size); @@ -210,8 +220,10 @@ int main(int argc, char** argv) { app[i]->dma_mem = dma_mem; for (int j = 0; j < app[i]->framebuff_cnt; ++j) { - app[i]->ext_frames[j].buf_addr = mtl_dma_mem_addr(dma_mem) + j * framebuff_size; - app[i]->ext_frames[j].buf_iova = mtl_dma_mem_iova(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_addr = + mtl_dma_mem_addr(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_iova = + mtl_dma_mem_iova(dma_mem) + j * framebuff_size; app[i]->ext_frames[j].buf_len = framebuff_size; } ops_rx.ext_frames = app[i]->ext_frames; @@ -226,7 +238,8 @@ int main(int argc, char** argv) { app[i]->handle = rx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -251,7 +264,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_rec); ret = -EIO; } } @@ -259,14 +273,19 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20_rx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->dma_mem) mtl_dma_mem_free(ctx.st, app[i]->dma_mem); - if (app[i]->framebuffs) free(app[i]->framebuffs); - if (app[i]->ext_frames) free(app[i]->ext_frames); + if (app[i]->dma_mem) + mtl_dma_mem_free(ctx.st, app[i]->dma_mem); + if (app[i]->framebuffs) + free(app[i]->framebuffs); + if (app[i]->ext_frames) + free(app[i]->ext_frames); free(app[i]); } diff --git a/app/sample/legacy/tx_st22_video_sample.c b/app/sample/legacy/tx_st22_video_sample.c index cbd5d7d65..34a5b8f7a 100644 --- a/app/sample/legacy/tx_st22_video_sample.c +++ b/app/sample/legacy/tx_st22_video_sample.c @@ -12,7 +12,7 @@ struct tx_st22_sample_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_tx_frame* framebuffs; + struct st_tx_frame *framebuffs; bool stop; pthread_t encode_thread; @@ -22,12 +22,12 @@ struct tx_st22_sample_ctx { pthread_mutex_t wake_mutex; }; -static int tx_st22_next_frame(void* priv, uint16_t* next_frame_idx, - struct st22_tx_frame_meta* meta) { - struct tx_st22_sample_ctx* s = priv; +static int tx_st22_next_frame(void *priv, uint16_t *next_frame_idx, + struct st22_tx_frame_meta *meta) { + struct tx_st22_sample_ctx *s = priv; int ret; uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; st_pthread_mutex_lock(&s->wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { @@ -38,7 +38,8 @@ static int tx_st22_next_frame(void* priv, uint16_t* next_frame_idx, meta->codestream_size = framebuff->size; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ @@ -50,11 +51,11 @@ static int tx_st22_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int tx_st22_frame_done(void* priv, uint16_t frame_idx, - struct st22_tx_frame_meta* meta) { - struct tx_st22_sample_ctx* s = priv; +static int tx_st22_frame_done(void *priv, uint16_t frame_idx, + struct st22_tx_frame_meta *meta) { + struct tx_st22_sample_ctx *s = priv; int ret; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->wake_mutex); @@ -65,8 +66,8 @@ static int tx_st22_frame_done(void* priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -74,8 +75,9 @@ static int tx_st22_frame_done(void* priv, uint16_t frame_idx, return ret; } -static void st22_encode_frame(struct tx_st22_sample_ctx* s, void* codestream_addr, - size_t max_codestream_size, size_t* codestream_size) { +static void st22_encode_frame(struct tx_st22_sample_ctx *s, + void *codestream_addr, size_t max_codestream_size, + size_t *codestream_size) { MTL_MAY_UNUSED(codestream_addr); MTL_MAY_UNUSED(max_codestream_size); @@ -84,10 +86,10 @@ static void st22_encode_frame(struct tx_st22_sample_ctx* s, void* codestream_add *codestream_size = s->bytes_per_frame; } -static void* st22_encode_thread(void* arg) { - struct tx_st22_sample_ctx* s = arg; +static void *st22_encode_thread(void *arg) { + struct tx_st22_sample_ctx *s = arg; uint16_t producer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -96,13 +98,14 @@ static void* st22_encode_thread(void* arg) { framebuff = &s->framebuffs[producer_idx]; if (ST_TX_FRAME_FREE != framebuff->stat) { /* not in free */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } st_pthread_mutex_unlock(&s->wake_mutex); - void* frame_addr = st22_tx_get_fb_addr(s->handle, producer_idx); + void *frame_addr = st22_tx_get_fb_addr(s->handle, producer_idx); size_t max_framesize = s->bytes_per_frame; size_t codestream_size = s->bytes_per_frame; st22_encode_frame(s, frame_addr, max_framesize, &codestream_size); @@ -112,7 +115,8 @@ static void* st22_encode_thread(void* arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -121,7 +125,7 @@ static void* st22_encode_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int bpp = 3; struct st_sample_context ctx; int ret; @@ -129,7 +133,8 @@ int main(int argc, char** argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -141,11 +146,12 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st22_tx_handle tx_handle[session_num]; - struct tx_st22_sample_ctx* app[session_num]; + struct tx_st22_sample_ctx *app[session_num]; // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = (struct tx_st22_sample_ctx*)malloc(sizeof(struct tx_st22_sample_ctx)); + app[i] = + (struct tx_st22_sample_ctx *)malloc(sizeof(struct tx_st22_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -157,8 +163,8 @@ int main(int argc, char** argv) { st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = - (struct st_tx_frame*)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = (struct st_tx_frame *)malloc( + sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -171,7 +177,7 @@ int main(int argc, char** argv) { struct st22_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st22_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -202,7 +208,8 @@ int main(int argc, char** argv) { app[i]->handle = tx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->encode_thread, NULL, st22_encode_thread, app[i]); + ret = pthread_create(&app[i]->encode_thread, NULL, st22_encode_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -235,12 +242,15 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st22_tx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st22_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) free(app[i]->framebuffs); + if (app[i]->framebuffs) + free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/legacy/tx_video_sample.c b/app/sample/legacy/tx_video_sample.c index 0b10de928..8c67fa060 100644 --- a/app/sample/legacy/tx_video_sample.c +++ b/app/sample/legacy/tx_video_sample.c @@ -19,7 +19,7 @@ struct tv_sample_context { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_tx_frame* framebuffs; + struct st_tx_frame *framebuffs; mtl_dma_mem_handle dma_mem; @@ -27,15 +27,16 @@ struct tv_sample_context { bool has_user_meta; }; -static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct tv_sample_context* s = priv; +static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct tv_sample_context *s = priv; int ret; uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); - if (!s->handle) return -EIO; /* not ready */ + if (!s->handle) + return -EIO; /* not ready */ st_pthread_mutex_lock(&s->wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { @@ -45,7 +46,8 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; if (s->has_user_meta) { s->meta.idx = s->fb_send; @@ -62,14 +64,15 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int tx_video_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - struct tv_sample_context* s = priv; +static int tx_video_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct tv_sample_context *s = priv; int ret; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); - if (!s->handle) return -EIO; /* not ready */ + if (!s->handle) + return -EIO; /* not ready */ st_pthread_mutex_lock(&s->wake_mutex); if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { @@ -79,8 +82,8 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -88,7 +91,7 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, return ret; } -static void tx_video_build_frame(struct tv_sample_context* s, void* frame, +static void tx_video_build_frame(struct tv_sample_context *s, void *frame, size_t frame_size) { MTL_MAY_UNUSED(s); MTL_MAY_UNUSED(frame); @@ -98,10 +101,10 @@ static void tx_video_build_frame(struct tv_sample_context* s, void* frame, st_usleep(10 * 1000); } -static void* tx_video_frame_thread(void* arg) { - struct tv_sample_context* s = arg; +static void *tx_video_frame_thread(void *arg) { + struct tv_sample_context *s = arg; uint16_t producer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -110,7 +113,8 @@ static void* tx_video_frame_thread(void* arg) { framebuff = &s->framebuffs[producer_idx]; if (ST_TX_FRAME_FREE != framebuff->stat) { /* not in free */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -119,12 +123,12 @@ static void* tx_video_frame_thread(void* arg) { struct st20_ext_frame ext_frame; ext_frame.buf_addr = mtl_dma_mem_addr(s->dma_mem) + producer_idx * s->framebuff_size; - ext_frame.buf_iova = - mtl_dma_mem_iova(s->dma_mem) + (mtl_iova_t)producer_idx * s->framebuff_size; + ext_frame.buf_iova = mtl_dma_mem_iova(s->dma_mem) + + (mtl_iova_t)producer_idx * s->framebuff_size; ext_frame.buf_len = s->framebuff_size; st20_tx_set_ext_frame(s->handle, producer_idx, &ext_frame); } else { - void* frame_addr = st20_tx_get_framebuffer(s->handle, producer_idx); + void *frame_addr = st20_tx_get_framebuffer(s->handle, producer_idx); tx_video_build_frame(s, frame_addr, s->framebuff_size); } st_pthread_mutex_lock(&s->wake_mutex); @@ -132,7 +136,8 @@ static void* tx_video_frame_thread(void* arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -141,14 +146,15 @@ static void* tx_video_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -161,12 +167,13 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st20_tx_handle tx_handle[session_num]; memset(tx_handle, 0, sizeof(tx_handle)); - struct tv_sample_context* app[session_num]; + struct tv_sample_context *app[session_num]; memset(app, 0, sizeof(app)); // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = (struct tv_sample_context*)malloc(sizeof(struct tv_sample_context)); + app[i] = + (struct tv_sample_context *)malloc(sizeof(struct tv_sample_context)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -181,8 +188,8 @@ int main(int argc, char** argv) { app[i]->has_user_meta = true; } app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = - (struct st_tx_frame*)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = (struct st_tx_frame *)malloc( + sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -195,14 +202,15 @@ int main(int argc, char** argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_tx"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - if (ctx.ext_frame) ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; - ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port + if (ctx.ext_frame) + ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; + ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port ops_tx.pacing = ST21_PACING_NARROW; ops_tx.packing = ctx.packing; ops_tx.type = ST20_TYPE_FRAME_LEVEL; @@ -248,7 +256,8 @@ int main(int argc, char** argv) { app[i]->handle = tx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->app_thread, NULL, tx_video_frame_thread, app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, tx_video_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -281,13 +290,17 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20_tx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->dma_mem) mtl_dma_mem_free(ctx.st, app[i]->dma_mem); - if (app[i]->framebuffs) free(app[i]->framebuffs); + if (app[i]->dma_mem) + mtl_dma_mem_free(ctx.st, app[i]->dma_mem); + if (app[i]->framebuffs) + free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/low_level/rx_rtp_video_sample.c b/app/sample/low_level/rx_rtp_video_sample.c index 14af335b0..801cc944e 100644 --- a/app/sample/low_level/rx_rtp_video_sample.c +++ b/app/sample/low_level/rx_rtp_video_sample.c @@ -14,8 +14,8 @@ struct rv_rtp_sample_ctx { pthread_mutex_t wake_mutex; }; -static int rx_rtp_ready(void* priv) { - struct rv_rtp_sample_ctx* s = (struct rv_rtp_sample_ctx*)priv; +static int rx_rtp_ready(void *priv) { + struct rv_rtp_sample_ctx *s = (struct rv_rtp_sample_ctx *)priv; // wake up the app thread who is waiting for the rtp buf; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -23,29 +23,31 @@ static int rx_rtp_ready(void* priv) { return 0; } -static void* app_rx_video_rtp_thread(void* arg) { - struct rv_rtp_sample_ctx* s = arg; - void* usrptr; +static void *app_rx_video_rtp_thread(void *arg) { + struct rv_rtp_sample_ctx *s = arg; + void *usrptr; uint16_t len; - void* mbuf; - struct st20_rfc4175_rtp_hdr* hdr; + void *mbuf; + struct st20_rfc4175_rtp_hdr *hdr; while (!s->stop) { mbuf = st20_rx_get_mbuf(s->handle, &usrptr, &len); if (!mbuf) { /* no buffer */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } /* get one packet */ - hdr = (struct st20_rfc4175_rtp_hdr*)usrptr; - /* handle the rtp packet, should not handle the heavy work, if the st20_rx_get_mbuf is - * not called timely, the rtp queue in the lib will be full and rtp will be enqueued - * fail in the lib, packet will be dropped*/ - if (hdr->base.marker) s->fb_rec++; + hdr = (struct st20_rfc4175_rtp_hdr *)usrptr; + /* handle the rtp packet, should not handle the heavy work, if the + * st20_rx_get_mbuf is not called timely, the rtp queue in the lib will be + * full and rtp will be enqueued fail in the lib, packet will be dropped*/ + if (hdr->base.marker) + s->fb_rec++; /* free to lib */ st20_rx_put_mbuf(s->handle, mbuf); } @@ -53,14 +55,15 @@ static void* app_rx_video_rtp_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -72,11 +75,12 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st20_rx_handle rx_handle[session_num]; - struct rv_rtp_sample_ctx* app[session_num]; + struct rv_rtp_sample_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = (struct rv_rtp_sample_ctx*)malloc(sizeof(struct rv_rtp_sample_ctx)); + app[i] = + (struct rv_rtp_sample_ctx *)malloc(sizeof(struct rv_rtp_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); return -1; @@ -89,7 +93,7 @@ int main(int argc, char** argv) { struct st20_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -111,7 +115,8 @@ int main(int argc, char** argv) { goto error; } app[i]->handle = rx_handle[i]; - ret = pthread_create(&app[i]->app_thread, NULL, app_rx_video_rtp_thread, app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, app_rx_video_rtp_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -136,7 +141,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_rec); ret = -EIO; } } @@ -144,8 +150,10 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20_rx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/sample/low_level/rx_slice_video_sample.c b/app/sample/low_level/rx_slice_video_sample.c index 65d9f3f81..67b332778 100644 --- a/app/sample/low_level/rx_slice_video_sample.c +++ b/app/sample/low_level/rx_slice_video_sample.c @@ -18,13 +18,13 @@ struct rv_slice_sample_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_rx_frame* framebuffs; + struct st_rx_frame *framebuffs; }; -static int rx_video_enqueue_frame(struct rv_slice_sample_ctx* s, void* frame, +static int rx_video_enqueue_frame(struct rv_slice_sample_ctx *s, void *frame, size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -35,18 +35,20 @@ static int rx_video_enqueue_frame(struct rv_slice_sample_ctx* s, void* frame, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int rx_video_slice_ready(void* priv, void* frame, - struct st20_rx_slice_meta* meta) { - struct rv_slice_sample_ctx* s = (struct rv_slice_sample_ctx*)priv; +static int rx_video_slice_ready(void *priv, void *frame, + struct st20_rx_slice_meta *meta) { + struct rv_slice_sample_ctx *s = (struct rv_slice_sample_ctx *)priv; MTL_MAY_UNUSED(frame); MTL_MAY_UNUSED(meta); - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; // frame_recv_lines in meta indicate the ready lines for current frame // add the slice handling logic here @@ -55,11 +57,12 @@ static int rx_video_slice_ready(void* priv, void* frame, return 0; } -static int rx_video_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - struct rv_slice_sample_ctx* s = (struct rv_slice_sample_ctx*)priv; +static int rx_video_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct rv_slice_sample_ctx *s = (struct rv_slice_sample_ctx *)priv; - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -82,7 +85,7 @@ static int rx_video_frame_ready(void* priv, void* frame, return 0; } -static void rx_video_consume_frame(struct rv_slice_sample_ctx* s, void* frame, +static void rx_video_consume_frame(struct rv_slice_sample_ctx *s, void *frame, size_t frame_size) { MTL_MAY_UNUSED(frame); MTL_MAY_UNUSED(frame_size); @@ -93,11 +96,11 @@ static void rx_video_consume_frame(struct rv_slice_sample_ctx* s, void* frame, s->fb_rec++; } -static void* rx_video_frame_thread(void* arg) { - struct rv_slice_sample_ctx* s = arg; +static void *rx_video_frame_thread(void *arg) { + struct rv_slice_sample_ctx *s = arg; int idx = s->idx; int consumer_idx; - struct st_rx_frame* framebuff; + struct st_rx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->stop) { @@ -106,7 +109,8 @@ static void* rx_video_frame_thread(void* arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -119,7 +123,8 @@ static void* rx_video_frame_thread(void* arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -128,14 +133,15 @@ static void* rx_video_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -147,11 +153,12 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st20_rx_handle rx_handle[session_num]; - struct rv_slice_sample_ctx* app[session_num]; + struct rv_slice_sample_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = (struct rv_slice_sample_ctx*)malloc(sizeof(struct rv_slice_sample_ctx)); + app[i] = (struct rv_slice_sample_ctx *)malloc( + sizeof(struct rv_slice_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -162,8 +169,8 @@ int main(int argc, char** argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = - (struct st_rx_frame*)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = (struct st_rx_frame *)malloc( + sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -177,14 +184,14 @@ int main(int argc, char** argv) { struct st20_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_rx.udp_port[MTL_SESSION_PORT_P] = - ctx.udp_port + i * 2; // user config the udp port. + ctx.udp_port + i * 2; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_SLICE_LEVEL; ops_rx.width = ctx.width; @@ -196,7 +203,8 @@ int main(int argc, char** argv) { ops_rx.payload_type = ctx.payload_type; ops_rx.flags = ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; ops_rx.notify_slice_ready = rx_video_slice_ready; - // app register non-block func, app get a frame ready notification info by this cb + // app register non-block func, app get a frame ready notification info by + // this cb ops_rx.notify_frame_ready = rx_video_frame_ready; rx_handle[i] = st20_rx_create(ctx.st, &ops_rx); if (!rx_handle[i]) { @@ -207,7 +215,8 @@ int main(int argc, char** argv) { app[i]->handle = rx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -232,7 +241,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_rec); ret = -EIO; } } @@ -240,11 +250,14 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20_rx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) free(app[i]->framebuffs); + if (app[i]->framebuffs) + free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/low_level/tx_rtp_video_sample.c b/app/sample/low_level/tx_rtp_video_sample.c index e3e8a99e8..b8b0791af 100644 --- a/app/sample/low_level/tx_rtp_video_sample.c +++ b/app/sample/low_level/tx_rtp_video_sample.c @@ -21,17 +21,18 @@ struct tv_rtp_sample_ctx { pthread_mutex_t wake_mutex; }; -static int notify_rtp_done(void* priv) { - struct tv_rtp_sample_ctx* s = (struct tv_rtp_sample_ctx*)priv; +static int notify_rtp_done(void *priv) { + struct tv_rtp_sample_ctx *s = (struct tv_rtp_sample_ctx *)priv; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); return 0; } -static int app_tx_build_rtp_packet(struct tv_rtp_sample_ctx* s, - struct st20_rfc4175_rtp_hdr* rtp, uint16_t* pkt_len) { - uint8_t* payload = (uint8_t*)rtp + sizeof(*rtp); +static int app_tx_build_rtp_packet(struct tv_rtp_sample_ctx *s, + struct st20_rfc4175_rtp_hdr *rtp, + uint16_t *pkt_len) { + uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); /* update hdr */ rtp->base.tmstamp = htonl(s->rtp_tmstamp); @@ -71,8 +72,8 @@ static int app_tx_build_rtp_packet(struct tv_rtp_sample_ctx* s, return 0; } -static void* app_tx_rtp_thread(void* arg) { - struct tv_rtp_sample_ctx* s = arg; +static void *app_tx_rtp_thread(void *arg) { + struct tv_rtp_sample_ctx *s = arg; void *mbuf, *usrptr; uint16_t mbuf_len; while (!s->stop) { @@ -85,26 +86,29 @@ static void* app_tx_rtp_thread(void* arg) { if (mbuf) { st_pthread_mutex_unlock(&s->wake_mutex); } else { - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } } - app_tx_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr*)usrptr, &mbuf_len); + app_tx_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr *)usrptr, + &mbuf_len); st20_tx_put_mbuf(s->handle, mbuf, mbuf_len); } return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -116,11 +120,12 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st20_tx_handle tx_handle[session_num]; - struct tv_rtp_sample_ctx* app[session_num]; + struct tv_rtp_sample_ctx *app[session_num]; // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = (struct tv_rtp_sample_ctx*)malloc(sizeof(struct tv_rtp_sample_ctx)); + app[i] = + (struct tv_rtp_sample_ctx *)malloc(sizeof(struct tv_rtp_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -134,7 +139,7 @@ int main(int argc, char** argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -148,15 +153,17 @@ int main(int argc, char** argv) { ops_tx.fps = ctx.fps; ops_tx.fmt = ctx.fmt; ops_tx.payload_type = ctx.payload_type; - ops_tx.rtp_ring_size = 1024; // the rtp ring size between app and lib. app is the - // producer, lib is the consumer, should be 2^n + ops_tx.rtp_ring_size = + 1024; // the rtp ring size between app and lib. app is the + // producer, lib is the consumer, should be 2^n // app register non-block func, app could get the rtp tx done ops_tx.notify_rtp_done = notify_rtp_done; // 4320 for ex. it is for 1080p, each line, we have 4 packet. ops_tx.rtp_frame_total_pkts = 4320; ops_tx.rtp_pkt_size = 1200 + sizeof(struct st_rfc3550_rtp_hdr); - // rtp_frame_total_pkts x rtp_pkt_size will be used for Rate limit in the lib. + // rtp_frame_total_pkts x rtp_pkt_size will be used for Rate limit in the + // lib. tx_handle[i] = st20_tx_create(ctx.st, &ops_tx); if (!tx_handle[i]) { @@ -203,8 +210,10 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20_tx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/sample/low_level/tx_slice_video_sample.c b/app/sample/low_level/tx_slice_video_sample.c index 01872a237..8e88f55c9 100644 --- a/app/sample/low_level/tx_slice_video_sample.c +++ b/app/sample/low_level/tx_slice_video_sample.c @@ -7,7 +7,7 @@ struct tv_slice_sample_ctx { int idx; int fb_send; - void* handle; + void *handle; bool stop; pthread_t app_thread; @@ -18,18 +18,18 @@ struct tv_slice_sample_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_tx_frame* framebuffs; + struct st_tx_frame *framebuffs; int lines_per_slice; int height; }; -static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct tv_slice_sample_ctx* s = priv; +static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct tv_slice_sample_ctx *s = priv; int ret; uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->wake_mutex); @@ -40,7 +40,8 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ @@ -52,11 +53,11 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int tx_video_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - struct tv_slice_sample_ctx* s = priv; +static int tx_video_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct tv_slice_sample_ctx *s = priv; int ret; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->wake_mutex); @@ -67,8 +68,8 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -76,10 +77,10 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, return ret; } -static int tx_video_frame_lines_ready(void* priv, uint16_t frame_idx, - struct st20_tx_slice_meta* meta) { - struct tv_slice_sample_ctx* s = priv; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; +static int tx_video_frame_lines_ready(void *priv, uint16_t frame_idx, + struct st20_tx_slice_meta *meta) { + struct tv_slice_sample_ctx *s = priv; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; st_pthread_mutex_lock(&s->wake_mutex); framebuff->slice_trigger = true; @@ -91,8 +92,9 @@ static int tx_video_frame_lines_ready(void* priv, uint16_t frame_idx, return 0; } -static void tx_video_build_slice(struct tv_slice_sample_ctx* s, - struct st_tx_frame* framebuff, void* frame_addr) { +static void tx_video_build_slice(struct tv_slice_sample_ctx *s, + struct st_tx_frame *framebuff, + void *frame_addr) { int lines_build = 0; int slices = (s->height / s->lines_per_slice) + 1; MTL_MAY_UNUSED(frame_addr); @@ -112,17 +114,18 @@ static void tx_video_build_slice(struct tv_slice_sample_ctx* s, st_pthread_mutex_lock(&s->wake_mutex); lines_build += s->lines_per_slice; - if (lines_build > s->height) lines_build = s->height; + if (lines_build > s->height) + lines_build = s->height; framebuff->lines_ready = lines_build; st_pthread_mutex_unlock(&s->wake_mutex); } } -static void* tx_video_slice_thread(void* arg) { - struct tv_slice_sample_ctx* s = arg; +static void *tx_video_slice_thread(void *arg) { + struct tv_slice_sample_ctx *s = arg; uint16_t producer_idx; uint16_t consumer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; dbg("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -131,16 +134,18 @@ static void* tx_video_slice_thread(void* arg) { consumer_idx = s->framebuff_consumer_idx; framebuff = &s->framebuffs[producer_idx]; /* limit the producer to simulate the slice timing */ - if ((producer_idx != consumer_idx) || (ST_TX_FRAME_FREE != framebuff->stat)) { + if ((producer_idx != consumer_idx) || + (ST_TX_FRAME_FREE != framebuff->stat)) { /* not in free */ - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } - dbg("%s(%d), producer_idx %d consumer_idx %d\n", __func__, s->idx, producer_idx, - consumer_idx); - void* frame_addr = st20_tx_get_framebuffer(s->handle, producer_idx); + dbg("%s(%d), producer_idx %d consumer_idx %d\n", __func__, s->idx, + producer_idx, consumer_idx); + void *frame_addr = st20_tx_get_framebuffer(s->handle, producer_idx); framebuff->size = s->framebuff_size; framebuff->lines_ready = 0; @@ -148,7 +153,8 @@ static void* tx_video_slice_thread(void* arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); @@ -159,14 +165,15 @@ static void* tx_video_slice_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -178,11 +185,12 @@ int main(int argc, char** argv) { uint32_t session_num = ctx.sessions; st20_tx_handle tx_handle[session_num]; - struct tv_slice_sample_ctx* app[session_num]; + struct tv_slice_sample_ctx *app[session_num]; // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = (struct tv_slice_sample_ctx*)malloc(sizeof(struct tv_slice_sample_ctx)); + app[i] = (struct tv_slice_sample_ctx *)malloc( + sizeof(struct tv_slice_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -193,8 +201,8 @@ int main(int argc, char** argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = - (struct st_tx_frame*)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = (struct st_tx_frame *)malloc( + sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -208,13 +216,13 @@ int main(int argc, char** argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_tx"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port + ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port ops_tx.pacing = ST21_PACING_NARROW; ops_tx.type = ST20_TYPE_SLICE_LEVEL; ops_tx.width = ctx.width; @@ -241,7 +249,8 @@ int main(int argc, char** argv) { app[i]->framebuff_size = st20_tx_get_framebuffer_size(tx_handle[i]); app[i]->height = ops_tx.height; app[i]->lines_per_slice = app[i]->height / 30; - ret = pthread_create(&app[i]->app_thread, NULL, tx_video_slice_thread, app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, tx_video_slice_thread, + app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -274,12 +283,15 @@ int main(int argc, char** argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; - if (app[i]->handle) st20_tx_free(app[i]->handle); + if (!app[i]) + continue; + if (app[i]->handle) + st20_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) free(app[i]->framebuffs); + if (app[i]->framebuffs) + free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/msvc/imtl_sample/imtl_sample.cpp b/app/sample/msvc/imtl_sample/imtl_sample.cpp index 4ddc83736..15e52ed28 100644 --- a/app/sample/msvc/imtl_sample/imtl_sample.cpp +++ b/app/sample/msvc/imtl_sample/imtl_sample.cpp @@ -22,16 +22,18 @@ static mtl_handle g_st = NULL; void signalHandler(int signum) { std::cout << "SIGINT received - exiting!\n"; switch (signum) { - case SIGINT: - stop = true; - if (g_st != NULL) mtl_abort(g_st); - break; + case SIGINT: + stop = true; + if (g_st != NULL) + mtl_abort(g_st); + break; } } int main() { int ret = 0; - std::cout << "Starting MTL sample..." << std::endl << mtl_version() << std::endl; + std::cout << "Starting MTL sample..." << std::endl + << mtl_version() << std::endl; std::signal(SIGINT, signalHandler); @@ -76,11 +78,11 @@ int main() { ops_tx.transport_fmt = ST20_FMT_YUV_422_10BIT; ops_tx.device = ST_PLUGIN_DEVICE_AUTO; ops_tx.framebuff_cnt = 3; - auto sample_frame_available = [](void* priv) { + auto sample_frame_available = [](void *priv) { cv.notify_one(); return 0; }; - auto sample_frame_done = [](void* priv, struct st_frame* frame) { + auto sample_frame_done = [](void *priv, struct st_frame *frame) { fb_done++; return 0; }; @@ -94,7 +96,7 @@ int main() { } auto sample_frame_thread = [tx_handle]() { - struct st_frame* frame; + struct st_frame *frame; while (!stop) { frame = st20p_tx_get_frame(tx_handle); if (!frame) { /* no frame */ @@ -119,7 +121,8 @@ int main() { cv.notify_one(); frame_thread.join(); - if (tx_handle) st20p_tx_free(tx_handle); + if (tx_handle) + st20p_tx_free(tx_handle); /* uninit mtl */ if (st != NULL) { diff --git a/app/sample/rdma/rdma_rx.c b/app/sample/rdma/rdma_rx.c index 60ca7e2ad..376500f53 100644 --- a/app/sample/rdma/rdma_rx.c +++ b/app/sample/rdma/rdma_rx.c @@ -13,7 +13,7 @@ static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -static int rx_notify_buffer_ready(void* priv, struct mtl_rdma_buffer* buffer) { +static int rx_notify_buffer_ready(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); (void)(buffer); pthread_mutex_lock(&mtx); @@ -22,13 +22,13 @@ static int rx_notify_buffer_ready(void* priv, struct mtl_rdma_buffer* buffer) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { if (argc != 4) { printf("Usage: %s \n", argv[0]); return -1; } int ret = 0; - void* buffers[3] = {}; + void *buffers[3] = {}; mtl_rdma_handle mrh = NULL; mtl_rdma_rx_handle rx = NULL; struct mtl_rdma_init_params p = { @@ -70,7 +70,7 @@ int main(int argc, char** argv) { int total = 100; int buffer_consumed = 0; - struct mtl_rdma_buffer* buffer = NULL; + struct mtl_rdma_buffer *buffer = NULL; while (buffer_consumed < total) { buffer = mtl_rdma_rx_get_buffer(rx); if (!buffer) { @@ -82,9 +82,9 @@ int main(int argc, char** argv) { } /* print buffer string */ - printf("Received buffer %d: %s\n", buffer_consumed, (char*)buffer->addr); + printf("Received buffer %d: %s\n", buffer_consumed, (char *)buffer->addr); if (buffer->user_meta && buffer->user_meta_size) { - printf("User meta: %d\n", *(int*)buffer->user_meta); + printf("User meta: %d\n", *(int *)buffer->user_meta); } usleep(10000); /* simulate consuming */ @@ -99,13 +99,16 @@ int main(int argc, char** argv) { } out: - if (rx) mtl_rdma_rx_free(rx); + if (rx) + mtl_rdma_rx_free(rx); for (int i = 0; i < 3; i++) { - if (buffers[i]) free(buffers[i]); + if (buffers[i]) + free(buffers[i]); } - if (mrh) mtl_rdma_uinit(mrh); + if (mrh) + mtl_rdma_uinit(mrh); return 0; } \ No newline at end of file diff --git a/app/sample/rdma/rdma_tx.c b/app/sample/rdma/rdma_tx.c index 006dcf7af..5f70b4d28 100644 --- a/app/sample/rdma/rdma_tx.c +++ b/app/sample/rdma/rdma_tx.c @@ -15,29 +15,29 @@ static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static int buffer_acked = -3; -static int tx_notify_buffer_sent(void* priv, struct mtl_rdma_buffer* buffer) { +static int tx_notify_buffer_sent(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); - printf("Sent buffer: %s\n", (char*)buffer->addr); + printf("Sent buffer: %s\n", (char *)buffer->addr); return 0; } -static int tx_notify_buffer_done(void* priv, struct mtl_rdma_buffer* buffer) { +static int tx_notify_buffer_done(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); buffer_acked++; - printf("ACKed buffer: %s\n", (char*)buffer->addr); + printf("ACKed buffer: %s\n", (char *)buffer->addr); pthread_mutex_lock(&mtx); pthread_cond_signal(&cond); pthread_mutex_unlock(&mtx); return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { if (argc != 3) { printf("Usage: %s \n", argv[0]); return -1; } int ret = 0; - void* buffers[3] = {}; + void *buffers[3] = {}; int meta[3] = {}; int meta_idx = 0; mtl_rdma_handle mrh = NULL; @@ -80,7 +80,7 @@ int main(int argc, char** argv) { } int count = 100; - struct mtl_rdma_buffer* buffer = NULL; + struct mtl_rdma_buffer *buffer = NULL; for (int i = 0; i < count; i++) { buffer = mtl_rdma_tx_get_buffer(tx); if (!buffer) { @@ -93,9 +93,9 @@ int main(int argc, char** argv) { } meta[meta_idx] = buffer_acked; - snprintf((char*)buffer->addr, buffer->capacity, "Hello, RDMA! id %d acked %d", i, - meta[meta_idx]); - buffer->size = strlen((char*)buffer->addr) + 1; + snprintf((char *)buffer->addr, buffer->capacity, + "Hello, RDMA! id %d acked %d", i, meta[meta_idx]); + buffer->size = strlen((char *)buffer->addr) + 1; buffer->user_meta = &meta[meta_idx]; buffer->user_meta_size = sizeof(int); meta_idx = (meta_idx + 1) % 3; @@ -118,13 +118,16 @@ int main(int argc, char** argv) { out: - if (tx) mtl_rdma_tx_free(tx); + if (tx) + mtl_rdma_tx_free(tx); for (int i = 0; i < 3; i++) { - if (buffers[i]) free(buffers[i]); + if (buffers[i]) + free(buffers[i]); } - if (mrh) mtl_rdma_uinit(mrh); + if (mrh) + mtl_rdma_uinit(mrh); return ret; } \ No newline at end of file diff --git a/app/sample/rdma/rdma_video_rx.c b/app/sample/rdma/rdma_video_rx.c index 0bde7f3e1..920de90d5 100644 --- a/app/sample/rdma/rdma_video_rx.c +++ b/app/sample/rdma/rdma_video_rx.c @@ -26,12 +26,12 @@ static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static atomic_bool keep_running = true; #ifdef APP_HAS_SDL2 -static SDL_Window* window = NULL; -static SDL_Renderer* renderer = NULL; -static SDL_Texture* texture = NULL; +static SDL_Window *window = NULL; +static SDL_Renderer *renderer = NULL; +static SDL_Texture *texture = NULL; #endif -static int rx_notify_buffer_ready(void* priv, struct mtl_rdma_buffer* buffer) { +static int rx_notify_buffer_ready(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); (void)(buffer); pthread_mutex_lock(&mtx); @@ -55,8 +55,9 @@ int sdl_init(size_t width, size_t height) { return -1; } - window = SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); + window = + SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); if (!window) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -68,8 +69,8 @@ int sdl_init(size_t width, size_t height) { return -1; } - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, SDL_TEXTUREACCESS_STREAMING, - width, height); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, + SDL_TEXTUREACCESS_STREAMING, width, height); if (!texture) { printf("Texture could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -78,24 +79,27 @@ int sdl_init(size_t width, size_t height) { return 0; } -void sdl_display_frame(void* frame, size_t width, size_t height) { +void sdl_display_frame(void *frame, size_t width, size_t height) { (void)(height); SDL_UpdateTexture(texture, NULL, frame, - width * 2); // Assuming UYVY (2 bytes per pixel) + width * 2); // Assuming UYVY (2 bytes per pixel) SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } void sdl_cleanup() { - if (texture) SDL_DestroyTexture(texture); - if (renderer) SDL_DestroyRenderer(renderer); - if (window) SDL_DestroyWindow(window); + if (texture) + SDL_DestroyTexture(texture); + if (renderer) + SDL_DestroyRenderer(renderer); + if (window) + SDL_DestroyWindow(window); SDL_Quit(); } #endif -int main(int argc, char** argv) { +int main(int argc, char **argv) { #ifdef APP_HAS_SDL2 if (sdl_init(1920, 1080) != 0) { fprintf(stderr, "Failed to initialize SDL.\n"); @@ -110,7 +114,7 @@ int main(int argc, char** argv) { signal(SIGINT, int_handler); int ret = 0; - void* buffers[3] = {}; + void *buffers[3] = {}; mtl_rdma_handle mrh = NULL; mtl_rdma_rx_handle rx = NULL; struct mtl_rdma_init_params p = { @@ -162,7 +166,7 @@ int main(int argc, char** argv) { printf("Starting to receive frames\n"); int frames_consumed = 0; - struct mtl_rdma_buffer* buffer = NULL; + struct mtl_rdma_buffer *buffer = NULL; while (keep_running) { buffer = mtl_rdma_rx_get_buffer(rx); if (!buffer) { @@ -178,7 +182,7 @@ int main(int argc, char** argv) { clock_gettime(CLOCK_REALTIME, &now); uint64_t recv_time_ns = ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; - uint64_t send_time_ns = *(uint64_t*)buffer->user_meta; + uint64_t send_time_ns = *(uint64_t *)buffer->user_meta; printf("Latency: %.2f us\n", (recv_time_ns - send_time_ns) / 1000.0); } @@ -211,13 +215,16 @@ int main(int argc, char** argv) { printf("Received %d frames\n", frames_consumed); out: - if (rx) mtl_rdma_rx_free(rx); + if (rx) + mtl_rdma_rx_free(rx); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) + munmap(buffers[i], frame_size); } - if (mrh) mtl_rdma_uinit(mrh); + if (mrh) + mtl_rdma_uinit(mrh); #ifdef APP_HAS_SDL2 sdl_cleanup(); diff --git a/app/sample/rdma/rdma_video_rx_multi.c b/app/sample/rdma/rdma_video_rx_multi.c index 7b2447609..dac5efecb 100644 --- a/app/sample/rdma/rdma_video_rx_multi.c +++ b/app/sample/rdma/rdma_video_rx_multi.c @@ -26,12 +26,12 @@ static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static atomic_bool keep_running = true; #ifdef APP_HAS_SDL2 -static SDL_Window* window = NULL; -static SDL_Renderer* renderer = NULL; -static SDL_Texture* texture = NULL; +static SDL_Window *window = NULL; +static SDL_Renderer *renderer = NULL; +static SDL_Texture *texture = NULL; #endif -static int rx_notify_buffer_ready(void* priv, struct mtl_rdma_buffer* buffer) { +static int rx_notify_buffer_ready(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); (void)(buffer); pthread_mutex_lock(&mtx); @@ -55,8 +55,9 @@ int sdl_init(size_t width, size_t height) { return -1; } - window = SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); + window = + SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); if (!window) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -68,8 +69,8 @@ int sdl_init(size_t width, size_t height) { return -1; } - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, SDL_TEXTUREACCESS_STREAMING, - width, height); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, + SDL_TEXTUREACCESS_STREAMING, width, height); if (!texture) { printf("Texture could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -78,24 +79,27 @@ int sdl_init(size_t width, size_t height) { return 0; } -void sdl_display_frame(void* frame, size_t width, size_t height) { +void sdl_display_frame(void *frame, size_t width, size_t height) { (void)(height); SDL_UpdateTexture(texture, NULL, frame, - width * 2); // Assuming UYVY (2 bytes per pixel) + width * 2); // Assuming UYVY (2 bytes per pixel) SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } void sdl_cleanup() { - if (texture) SDL_DestroyTexture(texture); - if (renderer) SDL_DestroyRenderer(renderer); - if (window) SDL_DestroyWindow(window); + if (texture) + SDL_DestroyTexture(texture); + if (renderer) + SDL_DestroyRenderer(renderer); + if (window) + SDL_DestroyWindow(window); SDL_Quit(); } #endif -int main(int argc, char** argv) { +int main(int argc, char **argv) { #ifdef APP_HAS_SDL2 if (sdl_init(1920, 1080) != 0) { fprintf(stderr, "Failed to initialize SDL.\n"); @@ -110,8 +114,8 @@ int main(int argc, char** argv) { signal(SIGINT, int_handler); int ret = 0; - void* buffers[3] = {}; - void* buffers1[3] = {}; + void *buffers[3] = {}; + void *buffers1[3] = {}; mtl_rdma_handle mrh = NULL; mtl_rdma_rx_handle rx0 = NULL; mtl_rdma_rx_handle rx1 = NULL; @@ -176,10 +180,11 @@ int main(int argc, char** argv) { printf("Starting to receive frames\n"); int frames_consumed = 0; - struct mtl_rdma_buffer* buffer = NULL; - struct mtl_rdma_buffer* buffer1 = NULL; + struct mtl_rdma_buffer *buffer = NULL; + struct mtl_rdma_buffer *buffer1 = NULL; while (keep_running) { - if (!buffer) buffer = mtl_rdma_rx_get_buffer(rx0); + if (!buffer) + buffer = mtl_rdma_rx_get_buffer(rx0); if (!buffer) { /* wait for buffer ready */ pthread_mutex_lock(&mtx); @@ -187,7 +192,8 @@ int main(int argc, char** argv) { pthread_mutex_unlock(&mtx); continue; } - if (!buffer1) buffer1 = mtl_rdma_rx_get_buffer(rx1); + if (!buffer1) + buffer1 = mtl_rdma_rx_get_buffer(rx1); if (!buffer1) { /* wait for buffer ready */ pthread_mutex_lock(&mtx); @@ -201,12 +207,12 @@ int main(int argc, char** argv) { clock_gettime(CLOCK_REALTIME, &now); uint64_t recv_time_ns = ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; - uint64_t send_time_ns = *(uint64_t*)buffer->user_meta; + uint64_t send_time_ns = *(uint64_t *)buffer->user_meta; printf("Latency: %.2f us\n", (recv_time_ns - send_time_ns) / 1000.0); } if (buffer1->user_meta && buffer1->user_meta_size) { - int sent = *(int*)buffer1->user_meta; + int sent = *(int *)buffer1->user_meta; printf("Buffer sent: %d\n", sent); } @@ -248,14 +254,18 @@ int main(int argc, char** argv) { printf("Received %d frames\n", frames_consumed); out: - if (rx0) mtl_rdma_rx_free(rx0); - if (rx1) mtl_rdma_rx_free(rx1); + if (rx0) + mtl_rdma_rx_free(rx0); + if (rx1) + mtl_rdma_rx_free(rx1); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) + munmap(buffers[i], frame_size); } - if (mrh) mtl_rdma_uinit(mrh); + if (mrh) + mtl_rdma_uinit(mrh); #ifdef APP_HAS_SDL2 sdl_cleanup(); diff --git a/app/sample/rdma/rdma_video_tx.c b/app/sample/rdma/rdma_video_tx.c index 9c996f021..8d77b60a2 100644 --- a/app/sample/rdma/rdma_video_tx.c +++ b/app/sample/rdma/rdma_video_tx.c @@ -26,14 +26,15 @@ static atomic_bool keep_running = true; static int frames_sent = 0; static int frames_acked = -3; -static void control_fps(struct timespec* start_time) { +static void control_fps(struct timespec *start_time) { struct timespec end_time; long long elapsed_time, time_to_wait; clock_gettime(CLOCK_MONOTONIC, &end_time); - elapsed_time = (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + - (end_time.tv_nsec - start_time->tv_nsec); + elapsed_time = + (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + + (end_time.tv_nsec - start_time->tv_nsec); time_to_wait = DESIRED_FRAME_DURATION - elapsed_time; if (time_to_wait > 0) { @@ -46,14 +47,14 @@ static void control_fps(struct timespec* start_time) { clock_gettime(CLOCK_MONOTONIC, start_time); } -static int tx_notify_buffer_sent(void* priv, struct mtl_rdma_buffer* buffer) { +static int tx_notify_buffer_sent(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); (void)(buffer); frames_sent++; return 0; } -static int tx_notify_buffer_done(void* priv, struct mtl_rdma_buffer* buffer) { +static int tx_notify_buffer_done(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); (void)(buffer); frames_acked++; @@ -71,7 +72,7 @@ void int_handler(int dummy) { pthread_mutex_unlock(&mtx); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { if (argc != 4) { printf("Usage: %s \n", argv[0]); return -1; @@ -79,7 +80,7 @@ int main(int argc, char** argv) { signal(SIGINT, int_handler); int ret = 0; - void* buffers[3] = {}; + void *buffers[3] = {}; mtl_rdma_handle mrh = NULL; mtl_rdma_tx_handle tx = NULL; struct mtl_rdma_init_params p = { @@ -122,7 +123,7 @@ int main(int argc, char** argv) { goto out; } - FILE* yuv_file = fopen(argv[3], "rb"); + FILE *yuv_file = fopen(argv[3], "rb"); if (!yuv_file) { printf("Failed to open YUV file\n"); ret = -1; @@ -134,7 +135,7 @@ int main(int argc, char** argv) { struct timespec start_time; clock_gettime(CLOCK_MONOTONIC, &start_time); while (keep_running) { - struct mtl_rdma_buffer* buffer = mtl_rdma_tx_get_buffer(tx); + struct mtl_rdma_buffer *buffer = mtl_rdma_tx_get_buffer(tx); if (!buffer) { /* wait for buffer done */ pthread_mutex_lock(&mtx); @@ -157,7 +158,8 @@ int main(int argc, char** argv) { struct timespec now; clock_gettime(CLOCK_REALTIME, &now); - uint64_t send_time_ns = ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; + uint64_t send_time_ns = + ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; buffer->size = frame_size; buffer->user_meta = &send_time_ns; @@ -177,13 +179,16 @@ int main(int argc, char** argv) { out: - if (tx) mtl_rdma_tx_free(tx); + if (tx) + mtl_rdma_tx_free(tx); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) + munmap(buffers[i], frame_size); } - if (mrh) mtl_rdma_uinit(mrh); + if (mrh) + mtl_rdma_uinit(mrh); return ret; } \ No newline at end of file diff --git a/app/sample/rdma/rdma_video_tx_multi.c b/app/sample/rdma/rdma_video_tx_multi.c index 112b2fcf2..5c67a804a 100644 --- a/app/sample/rdma/rdma_video_tx_multi.c +++ b/app/sample/rdma/rdma_video_tx_multi.c @@ -26,14 +26,15 @@ static atomic_bool keep_running = true; static int frames_sent = 0; static int frames_acked = -3; -static void control_fps(struct timespec* start_time) { +static void control_fps(struct timespec *start_time) { struct timespec end_time; long long elapsed_time, time_to_wait; clock_gettime(CLOCK_MONOTONIC, &end_time); - elapsed_time = (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + - (end_time.tv_nsec - start_time->tv_nsec); + elapsed_time = + (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + + (end_time.tv_nsec - start_time->tv_nsec); time_to_wait = DESIRED_FRAME_DURATION - elapsed_time; if (time_to_wait > 0) { @@ -46,14 +47,14 @@ static void control_fps(struct timespec* start_time) { clock_gettime(CLOCK_MONOTONIC, start_time); } -static int tx_notify_buffer_sent(void* priv, struct mtl_rdma_buffer* buffer) { +static int tx_notify_buffer_sent(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); (void)(buffer); frames_sent++; return 0; } -static int tx_notify_buffer_done(void* priv, struct mtl_rdma_buffer* buffer) { +static int tx_notify_buffer_done(void *priv, struct mtl_rdma_buffer *buffer) { (void)(priv); (void)(buffer); frames_acked++; @@ -71,7 +72,7 @@ void int_handler(int dummy) { pthread_mutex_unlock(&mtx); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { if (argc != 5) { printf("Usage: %s \n", argv[0]); return -1; @@ -79,8 +80,8 @@ int main(int argc, char** argv) { signal(SIGINT, int_handler); int ret = 0; - void* buffers[3] = {}; - void* buffers1[3] = {}; + void *buffers[3] = {}; + void *buffers1[3] = {}; mtl_rdma_handle mrh = NULL; mtl_rdma_tx_handle tx0 = NULL; mtl_rdma_tx_handle tx1 = NULL; @@ -136,7 +137,7 @@ int main(int argc, char** argv) { goto out; } - FILE* yuv_file = fopen(argv[4], "rb"); + FILE *yuv_file = fopen(argv[4], "rb"); if (!yuv_file) { printf("Failed to open YUV file\n"); ret = -1; @@ -147,10 +148,11 @@ int main(int argc, char** argv) { struct timespec start_time; clock_gettime(CLOCK_MONOTONIC, &start_time); - struct mtl_rdma_buffer* buffer = NULL; - struct mtl_rdma_buffer* buffer1 = NULL; + struct mtl_rdma_buffer *buffer = NULL; + struct mtl_rdma_buffer *buffer1 = NULL; while (keep_running) { - if (!buffer) buffer = mtl_rdma_tx_get_buffer(tx0); + if (!buffer) + buffer = mtl_rdma_tx_get_buffer(tx0); if (!buffer) { /* wait for buffer done */ pthread_mutex_lock(&mtx); @@ -158,7 +160,8 @@ int main(int argc, char** argv) { pthread_mutex_unlock(&mtx); continue; } - if (!buffer1) buffer1 = mtl_rdma_tx_get_buffer(tx1); + if (!buffer1) + buffer1 = mtl_rdma_tx_get_buffer(tx1); if (!buffer1) { /* wait for buffer done */ pthread_mutex_lock(&mtx); @@ -181,7 +184,8 @@ int main(int argc, char** argv) { struct timespec now; clock_gettime(CLOCK_REALTIME, &now); - uint64_t send_time_ns = ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; + uint64_t send_time_ns = + ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; buffer->size = frame_size / 2; buffer->user_meta = &send_time_ns; @@ -214,14 +218,18 @@ int main(int argc, char** argv) { out: - if (tx0) mtl_rdma_tx_free(tx0); - if (tx1) mtl_rdma_tx_free(tx1); + if (tx0) + mtl_rdma_tx_free(tx0); + if (tx1) + mtl_rdma_tx_free(tx1); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) + munmap(buffers[i], frame_size); } - if (mrh) mtl_rdma_uinit(mrh); + if (mrh) + mtl_rdma_uinit(mrh); return ret; } \ No newline at end of file diff --git a/app/sample/rx_st20_pipeline_sample.c b/app/sample/rx_st20_pipeline_sample.c index 006970d8e..df23816bb 100644 --- a/app/sample/rx_st20_pipeline_sample.c +++ b/app/sample/rx_st20_pipeline_sample.c @@ -15,14 +15,14 @@ struct rx_st20p_sample_ctx { size_t frame_size; int dst_fd; - uint8_t* dst_begin; - uint8_t* dst_end; - uint8_t* dst_cursor; + uint8_t *dst_begin; + uint8_t *dst_end; + uint8_t *dst_cursor; int fb_cnt; }; -static int rx_st20p_close_source(struct rx_st20p_sample_ctx* s) { +static int rx_st20p_close_source(struct rx_st20p_sample_ctx *s) { if (s->dst_begin) { munmap(s->dst_begin, s->dst_end - s->dst_begin); s->dst_begin = NULL; @@ -35,7 +35,8 @@ static int rx_st20p_close_source(struct rx_st20p_sample_ctx* s) { return 0; } -static int rx_st20p_open_source(struct rx_st20p_sample_ctx* s, const char* file) { +static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, + const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -54,7 +55,7 @@ static int rx_st20p_open_source(struct rx_st20p_sample_ctx* s, const char* file) return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, file); close(fd); @@ -65,26 +66,28 @@ static int rx_st20p_open_source(struct rx_st20p_sample_ctx* s, const char* file) s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, - file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, fb_cnt, file, m, f_size); return 0; } -static void rx_st20p_consume_frame(struct rx_st20p_sample_ctx* s, - struct st_frame* frame) { +static void rx_st20p_consume_frame(struct rx_st20p_sample_ctx *s, + struct st_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) return; /* no dump */ + if (s->dst_fd < 0) + return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) + s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; } -static void* rx_st20p_frame_thread(void* arg) { - struct rx_st20p_sample_ctx* s = arg; +static void *rx_st20p_frame_thread(void *arg) { + struct rx_st20p_sample_ctx *s = arg; st20p_rx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -95,7 +98,7 @@ static void* rx_st20p_frame_thread(void* arg) { } dbg("%s(%d), one new frame\n", __func__, s->idx); if (frame->user_meta) { - const struct st_frame_user_meta* user_meta = frame->user_meta; + const struct st_frame_user_meta *user_meta = frame->user_meta; if (frame->user_meta_size != sizeof(*user_meta)) { err("%s(%d), user_meta_size wrong\n", __func__, s->idx); } @@ -110,14 +113,15 @@ static void* rx_st20p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -128,7 +132,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct rx_st20p_sample_ctx* app[session_num]; + struct rx_st20p_sample_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { @@ -147,7 +151,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = ctx.param.num_ports; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -155,8 +159,8 @@ int main(int argc, char** argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], + ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -194,7 +198,8 @@ int main(int argc, char** argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -209,7 +214,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st20p_rx_wake_block(app[i]->handle); + if (app[i]->handle) + st20p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -219,7 +225,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_recv); ret = -EIO; } } @@ -227,7 +234,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st20p_rx_free(app[i]->handle); + if (app[i]->handle) + st20p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st20p_auto_detect_sample.c b/app/sample/rx_st20p_auto_detect_sample.c index 6aa5aacf9..f8e586e74 100644 --- a/app/sample/rx_st20p_auto_detect_sample.c +++ b/app/sample/rx_st20p_auto_detect_sample.c @@ -10,20 +10,20 @@ struct rx_st20p_auto_detect_ctx { bool stop; pthread_t frame_thread; - struct st_sample_context* ctx; + struct st_sample_context *ctx; int fb_recv; size_t frame_size; int dst_fd; - uint8_t* dst_begin; - uint8_t* dst_end; - uint8_t* dst_cursor; + uint8_t *dst_begin; + uint8_t *dst_end; + uint8_t *dst_cursor; int fb_cnt; }; -static int rx_st20p_close_source(struct rx_st20p_auto_detect_ctx* s) { +static int rx_st20p_close_source(struct rx_st20p_auto_detect_ctx *s) { if (s->dst_begin) { munmap(s->dst_begin, s->dst_end - s->dst_begin); s->dst_begin = NULL; @@ -36,7 +36,8 @@ static int rx_st20p_close_source(struct rx_st20p_auto_detect_ctx* s) { return 0; } -static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx* s, const char* file) { +static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx *s, + const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -55,7 +56,7 @@ static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx* s, const char* return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, file); close(fd); @@ -66,26 +67,28 @@ static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx* s, const char* s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, - file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, fb_cnt, file, m, f_size); return 0; } -static void rx_st20p_consume_frame(struct rx_st20p_auto_detect_ctx* s, - struct st_frame* frame) { +static void rx_st20p_consume_frame(struct rx_st20p_auto_detect_ctx *s, + struct st_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) return; /* no dump */ + if (s->dst_fd < 0) + return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) + s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; } -static void* rx_st20p_frame_thread(void* arg) { - struct rx_st20p_auto_detect_ctx* s = arg; +static void *rx_st20p_frame_thread(void *arg) { + struct rx_st20p_auto_detect_ctx *s = arg; st20p_rx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -96,7 +99,7 @@ static void* rx_st20p_frame_thread(void* arg) { } dbg("%s(%d), one new frame\n", __func__, s->idx); if (frame->user_meta) { - const struct st_frame_user_meta* user_meta = frame->user_meta; + const struct st_frame_user_meta *user_meta = frame->user_meta; if (frame->user_meta_size != sizeof(*user_meta)) { err("%s(%d), user_meta_size wrong\n", __func__, s->idx); } @@ -111,9 +114,10 @@ static void* rx_st20p_frame_thread(void* arg) { return NULL; } -static int rx_st20p_notify_detected(void* priv, const struct st20_detect_meta* meta, - struct st20_detect_reply* reply) { - struct rx_st20p_auto_detect_ctx* s = priv; +static int rx_st20p_notify_detected(void *priv, + const struct st20_detect_meta *meta, + struct st20_detect_reply *reply) { + struct rx_st20p_auto_detect_ctx *s = priv; MTL_MAY_UNUSED(meta); MTL_MAY_UNUSED(reply); @@ -126,14 +130,15 @@ static int rx_st20p_notify_detected(void* priv, const struct st20_detect_meta* m return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -144,7 +149,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct rx_st20p_auto_detect_ctx* app[session_num]; + struct rx_st20p_auto_detect_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { @@ -164,7 +169,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = ctx.param.num_ports; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -172,8 +177,8 @@ int main(int argc, char** argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], + ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -203,7 +208,8 @@ int main(int argc, char** argv) { } app[i]->handle = rx_handle; - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -218,7 +224,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st20p_rx_wake_block(app[i]->handle); + if (app[i]->handle) + st20p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -228,7 +235,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_recv); ret = -EIO; } } @@ -236,7 +244,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st20p_rx_free(app[i]->handle); + if (app[i]->handle) + st20p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st20p_timing_parser_sample.c b/app/sample/rx_st20p_timing_parser_sample.c index 387a4559c..c8cd6bc30 100644 --- a/app/sample/rx_st20p_timing_parser_sample.c +++ b/app/sample/rx_st20p_timing_parser_sample.c @@ -43,7 +43,7 @@ struct rx_timing_parser_sample_ctx { uint8_t num_port; }; -static void rx_st20p_tp_stat_init(struct rx_tp_stat* stat) { +static void rx_st20p_tp_stat_init(struct rx_tp_stat *stat) { memset(stat, 0, sizeof(*stat)); stat->cinst_max = INT_MIN; @@ -62,34 +62,40 @@ static void rx_st20p_tp_stat_init(struct rx_tp_stat* stat) { stat->rtp_ts_delta_min = INT_MAX; } -static void rx_st20p_tp_stat_print(struct rx_timing_parser_sample_ctx* s, - enum mtl_session_port port, struct rx_tp_stat* stat) { +static void rx_st20p_tp_stat_print(struct rx_timing_parser_sample_ctx *s, + enum mtl_session_port port, + struct rx_tp_stat *stat) { int idx = s->idx; - info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, port, - stat->compliant_result[ST_RX_TP_COMPLIANT_NARROW], + info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, + port, stat->compliant_result[ST_RX_TP_COMPLIANT_NARROW], stat->compliant_result[ST_RX_TP_COMPLIANT_WIDE], stat->compliant_result[ST_RX_TP_COMPLIANT_FAILED]); - info("%s(%d), CINST MIN %d MAX %d!\n", __func__, idx, stat->cinst_min, stat->cinst_max); - info("%s(%d), VRX MIN %d MAX %d!\n", __func__, idx, stat->vrx_min, stat->vrx_max); - info("%s(%d), IPT MIN %d MAX %d!\n", __func__, idx, stat->ipt_min, stat->ipt_max); - info("%s(%d), FPT MIN %d MAX %d!\n", __func__, idx, stat->fpt_min, stat->fpt_max); + info("%s(%d), CINST MIN %d MAX %d!\n", __func__, idx, stat->cinst_min, + stat->cinst_max); + info("%s(%d), VRX MIN %d MAX %d!\n", __func__, idx, stat->vrx_min, + stat->vrx_max); + info("%s(%d), IPT MIN %d MAX %d!\n", __func__, idx, stat->ipt_min, + stat->ipt_max); + info("%s(%d), FPT MIN %d MAX %d!\n", __func__, idx, stat->fpt_min, + stat->fpt_max); info("%s(%d), LATENCY MIN %d MAX %d!\n", __func__, idx, stat->latency_min, stat->latency_max); - info("%s(%d), RTP OFFSET MIN %d MAX %d!\n", __func__, idx, stat->rtp_offset_min, - stat->rtp_offset_max); - info("%s(%d), RTP TS DELTA MIN %d MAX %d!\n", __func__, idx, stat->rtp_ts_delta_min, - stat->rtp_ts_delta_max); + info("%s(%d), RTP OFFSET MIN %d MAX %d!\n", __func__, idx, + stat->rtp_offset_min, stat->rtp_offset_max); + info("%s(%d), RTP TS DELTA MIN %d MAX %d!\n", __func__, idx, + stat->rtp_ts_delta_min, stat->rtp_ts_delta_max); } -static int rx_st20p_tp_consume(struct rx_timing_parser_sample_ctx* s, - enum mtl_session_port port, struct st20_rx_tp_meta* tp) { +static int rx_st20p_tp_consume(struct rx_timing_parser_sample_ctx *s, + enum mtl_session_port port, + struct st20_rx_tp_meta *tp) { if (tp->compliant != ST_RX_TP_COMPLIANT_NARROW) { - dbg("%s(%d), compliant failed %d cause: %s, frame idx %d\n", __func__, s->idx, - tp->compliant, tp->failed_cause, s->fb_recv); + dbg("%s(%d), compliant failed %d cause: %s, frame idx %d\n", __func__, + s->idx, tp->compliant, tp->failed_cause, s->fb_recv); } /* update stat */ - struct rx_tp_stat* stat = &s->stat[port]; + struct rx_tp_stat *stat = &s->stat[port]; stat->vrx_min = ST_MIN(tp->vrx_min, stat->vrx_min); stat->vrx_max = ST_MAX(tp->vrx_max, stat->vrx_max); stat->cinst_min = ST_MIN(tp->cinst_min, stat->cinst_min); @@ -110,10 +116,10 @@ static int rx_st20p_tp_consume(struct rx_timing_parser_sample_ctx* s, return 0; } -static void* rx_st20p_tp_thread(void* arg) { - struct rx_timing_parser_sample_ctx* s = arg; +static void *rx_st20p_tp_thread(void *arg) { + struct rx_timing_parser_sample_ctx *s = arg; st20p_rx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; int idx = s->idx; int ret; @@ -128,7 +134,8 @@ static void* rx_st20p_tp_thread(void* arg) { ret = st20p_rx_timing_parser_critical(handle, &s->pass); if (ret >= 0) { s->pass_get = true; - info("%s(%d), pass critical, cinst narrow %d wide %d, vrx narrow %d wide %d\n", + info("%s(%d), pass critical, cinst narrow %d wide %d, vrx narrow %d " + "wide %d\n", __func__, idx, s->pass.cinst_max_narrow, s->pass.cinst_max_wide, s->pass.vrx_max_narrow, s->pass.vrx_max_wide); } @@ -145,14 +152,15 @@ static void* rx_st20p_tp_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable hw offload timestamp */ ctx.param.flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; @@ -166,7 +174,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct rx_timing_parser_sample_ctx* app[session_num]; + struct rx_timing_parser_sample_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { @@ -188,7 +196,7 @@ int main(int argc, char** argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = app[i]->num_port; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -196,8 +204,8 @@ int main(int argc, char** argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], + ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -228,7 +236,8 @@ int main(int argc, char** argv) { } app[i]->handle = rx_handle; - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_tp_thread, app[i]); + ret = + pthread_create(&app[i]->frame_thread, NULL, rx_st20p_tp_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -257,7 +266,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st20p_rx_wake_block(app[i]->handle); + if (app[i]->handle) + st20p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); } @@ -265,7 +275,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_recv); ret = -EIO; } } @@ -273,7 +284,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st20p_rx_free(app[i]->handle); + if (app[i]->handle) + st20p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st22_pipeline_sample.c b/app/sample/rx_st22_pipeline_sample.c index 36daad2b5..c22786500 100644 --- a/app/sample/rx_st22_pipeline_sample.c +++ b/app/sample/rx_st22_pipeline_sample.c @@ -15,12 +15,12 @@ struct rx_st22p_sample_ctx { size_t frame_size; int dst_fd; - uint8_t* dst_begin; - uint8_t* dst_end; - uint8_t* dst_cursor; + uint8_t *dst_begin; + uint8_t *dst_end; + uint8_t *dst_cursor; }; -static int rx_st22p_close_source(struct rx_st22p_sample_ctx* s) { +static int rx_st22p_close_source(struct rx_st22p_sample_ctx *s) { if (s->dst_begin) { munmap(s->dst_begin, s->dst_end - s->dst_begin); s->dst_begin = NULL; @@ -33,7 +33,8 @@ static int rx_st22p_close_source(struct rx_st22p_sample_ctx* s) { return 0; } -static int rx_st22p_open_source(struct rx_st22p_sample_ctx* s, const char* file) { +static int rx_st22p_open_source(struct rx_st22p_sample_ctx *s, + const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -52,7 +53,7 @@ static int rx_st22p_open_source(struct rx_st22p_sample_ctx* s, const char* file) return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, file); close(fd); @@ -63,21 +64,23 @@ static int rx_st22p_open_source(struct rx_st22p_sample_ctx* s, const char* file) s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, - file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, fb_cnt, file, m, f_size); return 0; } -static void rx_st22p_consume_frame(struct rx_st22p_sample_ctx* s, - struct st_frame* frame) { +static void rx_st22p_consume_frame(struct rx_st22p_sample_ctx *s, + struct st_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) return; /* no dump */ + if (s->dst_fd < 0) + return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) + s->dst_cursor = s->dst_begin; uint8_t planes = st_frame_fmt_planes(frame->fmt); - uint8_t* dst = s->dst_cursor; + uint8_t *dst = s->dst_cursor; for (uint8_t plane = 0; plane < planes; plane++) { size_t plane_sz = st_frame_plane_size(frame, plane); mtl_memcpy(dst, frame->addr[plane], plane_sz); @@ -86,10 +89,10 @@ static void rx_st22p_consume_frame(struct rx_st22p_sample_ctx* s, s->dst_cursor += s->frame_size; } -static void* rx_st22p_frame_thread(void* arg) { - struct rx_st22p_sample_ctx* s = arg; +static void *rx_st22p_frame_thread(void *arg) { + struct rx_st22p_sample_ctx *s = arg; st22p_rx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -106,14 +109,15 @@ static void* rx_st22p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -124,7 +128,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct rx_st22p_sample_ctx* app[session_num]; + struct rx_st22p_sample_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { @@ -142,7 +146,7 @@ int main(int argc, char** argv) { struct st22p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st22p_sample"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -184,7 +188,8 @@ int main(int argc, char** argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st22p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st22p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -199,7 +204,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st22p_rx_wake_block(app[i]->handle); + if (app[i]->handle) + st22p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -209,7 +215,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_recv); ret = -EIO; } } @@ -217,7 +224,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st22p_rx_free(app[i]->handle); + if (app[i]->handle) + st22p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st30_pipeline_sample.c b/app/sample/rx_st30_pipeline_sample.c index 646596979..9f302d2c1 100644 --- a/app/sample/rx_st30_pipeline_sample.c +++ b/app/sample/rx_st30_pipeline_sample.c @@ -15,14 +15,14 @@ struct rx_st30p_sample_ctx { size_t frame_size; int dst_fd; - uint8_t* dst_begin; - uint8_t* dst_end; - uint8_t* dst_cursor; + uint8_t *dst_begin; + uint8_t *dst_end; + uint8_t *dst_cursor; int fb_cnt; }; -static int rx_st30p_close_source(struct rx_st30p_sample_ctx* s) { +static int rx_st30p_close_source(struct rx_st30p_sample_ctx *s) { if (s->dst_begin) { munmap(s->dst_begin, s->dst_end - s->dst_begin); s->dst_begin = NULL; @@ -35,7 +35,8 @@ static int rx_st30p_close_source(struct rx_st30p_sample_ctx* s) { return 0; } -static int rx_st30p_open_source(struct rx_st30p_sample_ctx* s, const char* file) { +static int rx_st30p_open_source(struct rx_st30p_sample_ctx *s, + const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 1000 * 10; /* dump 10s */ @@ -54,7 +55,7 @@ static int rx_st30p_open_source(struct rx_st30p_sample_ctx* s, const char* file) return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, file); close(fd); @@ -65,26 +66,28 @@ static int rx_st30p_open_source(struct rx_st30p_sample_ctx* s, const char* file) s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, - file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, fb_cnt, file, m, f_size); return 0; } -static void rx_st30p_consume_frame(struct rx_st30p_sample_ctx* s, - struct st30_frame* frame) { +static void rx_st30p_consume_frame(struct rx_st30p_sample_ctx *s, + struct st30_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) return; /* no dump */ + if (s->dst_fd < 0) + return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) + s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr, s->frame_size); s->dst_cursor += s->frame_size; } -static void* rx_st30p_frame_thread(void* arg) { - struct rx_st30p_sample_ctx* s = arg; +static void *rx_st30p_frame_thread(void *arg) { + struct rx_st30p_sample_ctx *s = arg; st30p_rx_handle handle = s->handle; - struct st30_frame* frame; + struct st30_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -102,14 +105,15 @@ static void* rx_st30p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -120,7 +124,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct rx_st30p_sample_ctx* app[session_num]; + struct rx_st30p_sample_ctx *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { @@ -139,7 +143,7 @@ int main(int argc, char** argv) { struct st30p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st30p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = ctx.param.num_ports; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -147,8 +151,8 @@ int main(int argc, char** argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.audio_udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], + ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.audio_udp_port + i * 2; @@ -167,8 +171,9 @@ int main(int argc, char** argv) { ops_rx.ptime = ctx.audio_ptime; /* set frame size to 10ms time */ - int framebuff_size = st30_calculate_framebuff_size( - ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel, 10 * NS_PER_MS, NULL); + int framebuff_size = + st30_calculate_framebuff_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, + ops_rx.channel, 10 * NS_PER_MS, NULL); ops_rx.framebuff_size = framebuff_size; st30p_rx_handle rx_handle = st30p_rx_create(ctx.st, &ops_rx); @@ -188,7 +193,8 @@ int main(int argc, char** argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st30p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st30p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -203,7 +209,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st30p_rx_wake_block(app[i]->handle); + if (app[i]->handle) + st30p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -213,7 +220,8 @@ int main(int argc, char** argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, + app[i]->fb_recv); ret = -EIO; } } @@ -221,7 +229,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st30p_rx_free(app[i]->handle); + if (app[i]->handle) + st30p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/sample_util.c b/app/sample/sample_util.c index 66e697d0c..5d2cddeb2 100644 --- a/app/sample/sample_util.c +++ b/app/sample/sample_util.c @@ -151,348 +151,354 @@ static struct option sample_args_options[] = { {0, 0, 0, 0}}; -static int sample_args_parse_tx_mac(struct st_sample_context* ctx, char* mac_str, - enum mtl_port port) { +static int sample_args_parse_tx_mac(struct st_sample_context *ctx, + char *mac_str, enum mtl_port port) { int ret; - uint8_t* mac; + uint8_t *mac; - if (!mac_str) return -EIO; + if (!mac_str) + return -EIO; dbg("%s, tx dst mac %s\n", __func__, mac_str); mac = &ctx->tx_dst_mac[port][0]; - ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], &mac[1], - &mac[2], &mac[3], &mac[4], &mac[5]); - if (ret < 0) return ret; + ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], + &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); + if (ret < 0) + return ret; ctx->has_tx_dst_mac[port] = true; return 0; } -static int _sample_parse_args(struct st_sample_context* ctx, int argc, char** argv) { +static int _sample_parse_args(struct st_sample_context *ctx, int argc, + char **argv) { int cmd = -1, optIdx = 0; - struct mtl_init_params* p = &ctx->param; + struct mtl_init_params *p = &ctx->param; while (1) { cmd = getopt_long_only(argc, argv, "hv", sample_args_options, &optIdx); - if (cmd == -1) break; + if (cmd == -1) + break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case SAMPLE_ARG_P_PORT: - snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); - p->num_ports++; - break; - case SAMPLE_ARG_R_PORT: - snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); - p->num_ports++; - break; - case SAMPLE_ARG_DMA_PORT: - snprintf(p->dma_dev_port[0], sizeof(p->dma_dev_port[0]), "%s", optarg); - p->num_dma_dev_port = 1; - break; - case SAMPLE_ARG_P_SIP: - inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); - break; - case SAMPLE_ARG_R_SIP: - inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); - break; - case SAMPLE_ARG_UDP_PORT: - ctx->udp_port = atoi(optarg); - ctx->audio_udp_port = atoi(optarg); - break; - case SAMPLE_ARG_PAYLOAD_TYPE: - ctx->payload_type = atoi(optarg); - ctx->audio_payload_type = atoi(optarg); - break; - case SAMPLE_ARG_FPS: { - enum st_fps fps = st_name_to_fps(optarg); - if (fps < ST_FPS_MAX) { - ctx->fps = fps; - } else { - err("%s, unknown fps name %s\n", __func__, optarg); - } - break; + case SAMPLE_ARG_P_PORT: + snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); + p->num_ports++; + break; + case SAMPLE_ARG_R_PORT: + snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); + p->num_ports++; + break; + case SAMPLE_ARG_DMA_PORT: + snprintf(p->dma_dev_port[0], sizeof(p->dma_dev_port[0]), "%s", optarg); + p->num_dma_dev_port = 1; + break; + case SAMPLE_ARG_P_SIP: + inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); + break; + case SAMPLE_ARG_R_SIP: + inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); + break; + case SAMPLE_ARG_UDP_PORT: + ctx->udp_port = atoi(optarg); + ctx->audio_udp_port = atoi(optarg); + break; + case SAMPLE_ARG_PAYLOAD_TYPE: + ctx->payload_type = atoi(optarg); + ctx->audio_payload_type = atoi(optarg); + break; + case SAMPLE_ARG_FPS: { + enum st_fps fps = st_name_to_fps(optarg); + if (fps < ST_FPS_MAX) { + ctx->fps = fps; + } else { + err("%s, unknown fps name %s\n", __func__, optarg); } - case SAMPLE_ARG_INTERLACED: - ctx->interlaced = true; - break; - case SAMPLE_ARG_P_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); - break; - case SAMPLE_ARG_P_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); - break; - case SAMPLE_ARG_P_FWD_IP: - inet_pton(AF_INET, optarg, ctx->fwd_dip_addr[MTL_PORT_P]); - break; - case SAMPLE_ARG_P_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); - break; - case SAMPLE_ARG_P_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); - break; - case SAMPLE_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case SAMPLE_ARG_DEV_AUTO_START: - p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; - break; - case SAMPLE_ARG_SHARED_TX_QUEUES: - p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - break; - case SAMPLE_ARG_SHARED_RX_QUEUES: - p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - break; - case SAMPLE_ARG_PTP_TSC: - p->flags |= MTL_FLAG_PTP_SOURCE_TSC; - break; - case SAMPLE_ARG_LIB_PTP: - p->flags |= MTL_FLAG_PTP_ENABLE; - break; - case SAMPLE_ARG_UDP_LCORE: - p->flags |= MTL_FLAG_UDP_LCORE; - break; - case SAMPLE_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; port++) - p->net_proto[port] = MTL_PROTO_DHCP; - break; - case SAMPLE_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case SAMPLE_ARG_PACING_WAY: - if (!strcmp(optarg, "auto")) - p->pacing = ST21_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - p->pacing = ST21_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsn")) - p->pacing = ST21_TX_PACING_WAY_TSN; - else if (!strcmp(optarg, "tsc")) - p->pacing = ST21_TX_PACING_WAY_TSC; - else if (!strcmp(optarg, "tsc_narrow")) - p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; - else if (!strcmp(optarg, "ptp")) - p->pacing = ST21_TX_PACING_WAY_PTP; - else if (!strcmp(optarg, "be")) - p->pacing = ST21_TX_PACING_WAY_BE; - else - err("%s, unknow pacing way %s\n", __func__, optarg); - break; - case SAMPLE_ARG_NB_TX_DESC: - p->nb_tx_desc = atoi(optarg); - break; - case SAMPLE_ARG_NB_RX_DESC: - p->nb_rx_desc = atoi(optarg); - break; - case SAMPLE_ARG_RX_BURST_SZ: - ctx->rx_burst_size = atoi(optarg); - break; - case SAMPLE_ARG_QUEUES_CNT: + break; + } + case SAMPLE_ARG_INTERLACED: + ctx->interlaced = true; + break; + case SAMPLE_ARG_P_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); + break; + case SAMPLE_ARG_P_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); + break; + case SAMPLE_ARG_P_FWD_IP: + inet_pton(AF_INET, optarg, ctx->fwd_dip_addr[MTL_PORT_P]); + break; + case SAMPLE_ARG_P_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); + break; + case SAMPLE_ARG_P_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); + break; + case SAMPLE_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case SAMPLE_ARG_DEV_AUTO_START: + p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; + break; + case SAMPLE_ARG_SHARED_TX_QUEUES: + p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + break; + case SAMPLE_ARG_SHARED_RX_QUEUES: + p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + break; + case SAMPLE_ARG_PTP_TSC: + p->flags |= MTL_FLAG_PTP_SOURCE_TSC; + break; + case SAMPLE_ARG_LIB_PTP: + p->flags |= MTL_FLAG_PTP_ENABLE; + break; + case SAMPLE_ARG_UDP_LCORE: + p->flags |= MTL_FLAG_UDP_LCORE; + break; + case SAMPLE_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; port++) + p->net_proto[port] = MTL_PROTO_DHCP; + break; + case SAMPLE_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case SAMPLE_ARG_PACING_WAY: + if (!strcmp(optarg, "auto")) + p->pacing = ST21_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + p->pacing = ST21_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsn")) + p->pacing = ST21_TX_PACING_WAY_TSN; + else if (!strcmp(optarg, "tsc")) + p->pacing = ST21_TX_PACING_WAY_TSC; + else if (!strcmp(optarg, "tsc_narrow")) + p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; + else if (!strcmp(optarg, "ptp")) + p->pacing = ST21_TX_PACING_WAY_PTP; + else if (!strcmp(optarg, "be")) + p->pacing = ST21_TX_PACING_WAY_BE; + else + err("%s, unknow pacing way %s\n", __func__, optarg); + break; + case SAMPLE_ARG_NB_TX_DESC: + p->nb_tx_desc = atoi(optarg); + break; + case SAMPLE_ARG_NB_RX_DESC: + p->nb_rx_desc = atoi(optarg); + break; + case SAMPLE_ARG_RX_BURST_SZ: + ctx->rx_burst_size = atoi(optarg); + break; + case SAMPLE_ARG_QUEUES_CNT: + for (int i = 0; i < MTL_PORT_MAX; i++) { + p->rx_queues_cnt[i] = atoi(optarg); + p->tx_queues_cnt[i] = p->rx_queues_cnt[i]; + } + break; + case SAMPLE_ARG_P_TX_DST_MAC: + sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); + break; + case SAMPLE_ARG_R_TX_DST_MAC: + sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); + break; + case SAMPLE_ARG_TX_URL: + snprintf(ctx->tx_url, sizeof(ctx->tx_url), "%s", optarg); + snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); + break; + case SAMPLE_ARG_RX_URL: + snprintf(ctx->rx_url, sizeof(ctx->rx_url), "%s", optarg); + snprintf(ctx->rx_audio_url, sizeof(ctx->rx_audio_url), "%s", optarg); + break; + case SAMPLE_ARG_AUDIO_FMT: + if (!strcmp(optarg, "pcm8")) + ctx->audio_fmt = ST30_FMT_PCM8; + else if (!strcmp(optarg, "pcm16")) + ctx->audio_fmt = ST30_FMT_PCM16; + else if (!strcmp(optarg, "pcm24")) + ctx->audio_fmt = ST30_FMT_PCM24; + else if (!strcmp(optarg, "am824")) + ctx->audio_fmt = ST31_FMT_AM824; + else + err("%s, unknow audio_fmt %s\n", __func__, optarg); + break; + case SAMPLE_ARG_AUDIO_CHANNEL: + ctx->audio_channel = atoi(optarg); + break; + case SAMPLE_ARG_AUDIO_SAMPLING: + if (!strcmp(optarg, "48k")) + ctx->audio_sampling = ST30_SAMPLING_48K; + else if (!strcmp(optarg, "96k")) + ctx->audio_sampling = ST30_SAMPLING_96K; + else if (!strcmp(optarg, "44k")) + ctx->audio_sampling = ST31_SAMPLING_44K; + else + err("%s, unknow audio_sampling %s\n", __func__, optarg); + break; + case SAMPLE_ARG_AUDIO_PTIME: + if (!strcmp(optarg, "1ms")) { + ctx->audio_ptime = ST30_PTIME_1MS; + } else if (!strcmp(optarg, "125us")) { + ctx->audio_ptime = ST30_PTIME_125US; for (int i = 0; i < MTL_PORT_MAX; i++) { - p->rx_queues_cnt[i] = atoi(optarg); - p->tx_queues_cnt[i] = p->rx_queues_cnt[i]; - } - break; - case SAMPLE_ARG_P_TX_DST_MAC: - sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); - break; - case SAMPLE_ARG_R_TX_DST_MAC: - sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); - break; - case SAMPLE_ARG_TX_URL: - snprintf(ctx->tx_url, sizeof(ctx->tx_url), "%s", optarg); - snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); - break; - case SAMPLE_ARG_RX_URL: - snprintf(ctx->rx_url, sizeof(ctx->rx_url), "%s", optarg); - snprintf(ctx->rx_audio_url, sizeof(ctx->rx_audio_url), "%s", optarg); - break; - case SAMPLE_ARG_AUDIO_FMT: - if (!strcmp(optarg, "pcm8")) - ctx->audio_fmt = ST30_FMT_PCM8; - else if (!strcmp(optarg, "pcm16")) - ctx->audio_fmt = ST30_FMT_PCM16; - else if (!strcmp(optarg, "pcm24")) - ctx->audio_fmt = ST30_FMT_PCM24; - else if (!strcmp(optarg, "am824")) - ctx->audio_fmt = ST31_FMT_AM824; - else - err("%s, unknow audio_fmt %s\n", __func__, optarg); - break; - case SAMPLE_ARG_AUDIO_CHANNEL: - ctx->audio_channel = atoi(optarg); - break; - case SAMPLE_ARG_AUDIO_SAMPLING: - if (!strcmp(optarg, "48k")) - ctx->audio_sampling = ST30_SAMPLING_48K; - else if (!strcmp(optarg, "96k")) - ctx->audio_sampling = ST30_SAMPLING_96K; - else if (!strcmp(optarg, "44k")) - ctx->audio_sampling = ST31_SAMPLING_44K; - else - err("%s, unknow audio_sampling %s\n", __func__, optarg); - break; - case SAMPLE_ARG_AUDIO_PTIME: - if (!strcmp(optarg, "1ms")) { - ctx->audio_ptime = ST30_PTIME_1MS; - } else if (!strcmp(optarg, "125us")) { - ctx->audio_ptime = ST30_PTIME_125US; - for (int i = 0; i < MTL_PORT_MAX; i++) { - p->tx_queues_cnt[i] += 2; - } - } else { - err("%s, unknow audio_ptime %s\n", __func__, optarg); - } - break; - case SAMPLE_ARG_LOGO_URL: - snprintf(ctx->logo_url, sizeof(ctx->rx_url), "%s", optarg); - break; - case SAMPLE_ARG_WIDTH: - ctx->width = atoi(optarg); - break; - case SAMPLE_ARG_HEIGHT: - ctx->height = atoi(optarg); - break; - case SAMPLE_ARG_SESSIONS_CNT: - ctx->sessions = atoi(optarg); - break; - case SAMPLE_ARG_EXT_FRAME: - ctx->ext_frame = true; - break; - case SAMPLE_ARG_ST22_CODEC: - ctx->st22p_codec = st_name_to_codec(optarg); - break; - case SAMPLE_ARG_PIPELINE_FMT: { - enum st_frame_fmt fmt = st_frame_name_to_fmt(optarg); - if (fmt < ST_FRAME_FMT_MAX) { - ctx->input_fmt = fmt; - ctx->output_fmt = fmt; - } else { - err("%s, unknown fmt %s\n", __func__, optarg); + p->tx_queues_cnt[i] += 2; } - break; + } else { + err("%s, unknow audio_ptime %s\n", __func__, optarg); } - case SAMPLE_ARG_TRANSPORT_FMT: { - enum st20_fmt fmt = st20_name_to_fmt(optarg); - if (fmt < ST20_FMT_MAX) { - ctx->fmt = fmt; - } else { - err("%s, unknown fmt %s\n", __func__, optarg); - } - break; + break; + case SAMPLE_ARG_LOGO_URL: + snprintf(ctx->logo_url, sizeof(ctx->rx_url), "%s", optarg); + break; + case SAMPLE_ARG_WIDTH: + ctx->width = atoi(optarg); + break; + case SAMPLE_ARG_HEIGHT: + ctx->height = atoi(optarg); + break; + case SAMPLE_ARG_SESSIONS_CNT: + ctx->sessions = atoi(optarg); + break; + case SAMPLE_ARG_EXT_FRAME: + ctx->ext_frame = true; + break; + case SAMPLE_ARG_ST22_CODEC: + ctx->st22p_codec = st_name_to_codec(optarg); + break; + case SAMPLE_ARG_PIPELINE_FMT: { + enum st_frame_fmt fmt = st_frame_name_to_fmt(optarg); + if (fmt < ST_FRAME_FMT_MAX) { + ctx->input_fmt = fmt; + ctx->output_fmt = fmt; + } else { + err("%s, unknown fmt %s\n", __func__, optarg); } - case SAMPLE_ARG_PACKING: - if (!strcmp(optarg, "bpm")) - ctx->packing = ST20_PACKING_BPM; - else if (!strcmp(optarg, "gpm")) - ctx->packing = ST20_PACKING_GPM; - else if (!strcmp(optarg, "gpm_sl")) - ctx->packing = ST20_PACKING_GPM_SL; - else - err("%s, unknown codec %s\n", __func__, optarg); - break; - case SAMPLE_ARG_UDP_MODE: - if (!strcmp(optarg, "default")) - ctx->udp_mode = SAMPLE_UDP_DEFAULT; - else if (!strcmp(optarg, "transport")) - ctx->udp_mode = SAMPLE_UDP_TRANSPORT; - else if (!strcmp(optarg, "transport_poll")) - ctx->udp_mode = SAMPLE_UDP_TRANSPORT_POLL; - else if (!strcmp(optarg, "transport_unify_poll")) - ctx->udp_mode = SAMPLE_UDP_TRANSPORT_UNIFY_POLL; - else - err("%s, unknow udp_mode %s\n", __func__, optarg); - break; - case SAMPLE_ARG_UDP_TX_BPS_G: - ctx->udp_tx_bps = ((uint64_t)atoi(optarg)) * 1024 * 1024 * 1024; - break; - case SAMPLE_ARG_UDP_LEN: - ctx->udp_len = atoi(optarg); - break; - case SAMPLE_ARG_GDDR_PA: - ctx->gddr_pa = strtol(optarg, NULL, 0); - break; - case SAMPLE_ARG_RX_DUMP: - ctx->rx_dump = true; - break; - case SAMPLE_ARG_USER_META: - ctx->has_user_meta = true; - break; - case SAMPLE_ARG_USE_CPU_COPY: - ctx->use_cpu_copy = true; - break; - case SAMPLE_ARG_PROFILING_GDDR: - ctx->profiling_gddr = true; - break; - case SAMPLE_ARG_PERF_FRAMES: - ctx->perf_frames = atoi(optarg); - break; - case SAMPLE_ARG_PERF_FB_CNT: - ctx->perf_fb_cnt = atoi(optarg); - break; - case SAMPLE_ARG_MULTI_INC_ADDR: - ctx->multi_inc_addr = true; - break; - case SAMPLE_ARG_LCORES: - p->lcores = optarg; - break; - case '?': - break; - default: - break; + break; + } + case SAMPLE_ARG_TRANSPORT_FMT: { + enum st20_fmt fmt = st20_name_to_fmt(optarg); + if (fmt < ST20_FMT_MAX) { + ctx->fmt = fmt; + } else { + err("%s, unknown fmt %s\n", __func__, optarg); + } + break; + } + case SAMPLE_ARG_PACKING: + if (!strcmp(optarg, "bpm")) + ctx->packing = ST20_PACKING_BPM; + else if (!strcmp(optarg, "gpm")) + ctx->packing = ST20_PACKING_GPM; + else if (!strcmp(optarg, "gpm_sl")) + ctx->packing = ST20_PACKING_GPM_SL; + else + err("%s, unknown codec %s\n", __func__, optarg); + break; + case SAMPLE_ARG_UDP_MODE: + if (!strcmp(optarg, "default")) + ctx->udp_mode = SAMPLE_UDP_DEFAULT; + else if (!strcmp(optarg, "transport")) + ctx->udp_mode = SAMPLE_UDP_TRANSPORT; + else if (!strcmp(optarg, "transport_poll")) + ctx->udp_mode = SAMPLE_UDP_TRANSPORT_POLL; + else if (!strcmp(optarg, "transport_unify_poll")) + ctx->udp_mode = SAMPLE_UDP_TRANSPORT_UNIFY_POLL; + else + err("%s, unknow udp_mode %s\n", __func__, optarg); + break; + case SAMPLE_ARG_UDP_TX_BPS_G: + ctx->udp_tx_bps = ((uint64_t)atoi(optarg)) * 1024 * 1024 * 1024; + break; + case SAMPLE_ARG_UDP_LEN: + ctx->udp_len = atoi(optarg); + break; + case SAMPLE_ARG_GDDR_PA: + ctx->gddr_pa = strtol(optarg, NULL, 0); + break; + case SAMPLE_ARG_RX_DUMP: + ctx->rx_dump = true; + break; + case SAMPLE_ARG_USER_META: + ctx->has_user_meta = true; + break; + case SAMPLE_ARG_USE_CPU_COPY: + ctx->use_cpu_copy = true; + break; + case SAMPLE_ARG_PROFILING_GDDR: + ctx->profiling_gddr = true; + break; + case SAMPLE_ARG_PERF_FRAMES: + ctx->perf_frames = atoi(optarg); + break; + case SAMPLE_ARG_PERF_FB_CNT: + ctx->perf_fb_cnt = atoi(optarg); + break; + case SAMPLE_ARG_MULTI_INC_ADDR: + ctx->multi_inc_addr = true; + break; + case SAMPLE_ARG_LCORES: + p->lcores = optarg; + break; + case '?': + break; + default: + break; } }; return 0; } -static struct st_sample_context* g_sample_ctx; +static struct st_sample_context *g_sample_ctx; static void sample_sig_handler(int signo) { - struct st_sample_context* ctx = g_sample_ctx; + struct st_sample_context *ctx = g_sample_ctx; info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - ctx->exit = true; - if (ctx->st) mtl_abort(ctx->st); - if (ctx->sig_handler) ctx->sig_handler(signo); - break; + case SIGINT: /* Interrupt from keyboard */ + ctx->exit = true; + if (ctx->st) + mtl_abort(ctx->st); + if (ctx->sig_handler) + ctx->sig_handler(signo); + break; } return; } -static int sample_set_afxdp(struct st_sample_context* ctx) { - struct mtl_init_params* p = &ctx->param; +static int sample_set_afxdp(struct st_sample_context *ctx) { + struct mtl_init_params *p = &ctx->param; for (uint8_t i = 0; i < p->num_ports; i++) { p->pmd[i] = mtl_pmd_by_port_name(p->port[i]); @@ -501,9 +507,9 @@ static int sample_set_afxdp(struct st_sample_context* ctx) { return 0; } -int sample_parse_args(struct st_sample_context* ctx, int argc, char** argv, bool tx, - bool rx, bool unicast) { - struct mtl_init_params* p = &ctx->param; +int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, + bool tx, bool rx, bool unicast) { + struct mtl_init_params *p = &ctx->param; g_sample_ctx = ctx; signal(SIGINT, sample_sig_handler); @@ -539,7 +545,8 @@ int sample_parse_args(struct st_sample_context* ctx, int argc, char** argv, bool snprintf(p->dma_dev_port[0], MTL_PORT_MAX_LEN, "%s", "0000:80:04.0"); - if (!ctx->sessions) ctx->sessions = 1; + if (!ctx->sessions) + ctx->sessions = 1; ctx->framebuff_cnt = 3; ctx->width = 1920; ctx->height = 1080; @@ -575,28 +582,33 @@ int sample_parse_args(struct st_sample_context* ctx, int argc, char** argv, bool _sample_parse_args(ctx, argc, argv); /* always enable 1 port */ - if (!p->num_ports) p->num_ports = 1; + if (!p->num_ports) + p->num_ports = 1; - if (tx && !p->tx_queues_cnt[0]) sample_tx_queue_cnt_set(ctx, ctx->sessions); - if (rx && !p->rx_queues_cnt[0]) sample_rx_queue_cnt_set(ctx, ctx->sessions); + if (tx && !p->tx_queues_cnt[0]) + sample_tx_queue_cnt_set(ctx, ctx->sessions); + if (rx && !p->rx_queues_cnt[0]) + sample_rx_queue_cnt_set(ctx, ctx->sessions); sample_set_afxdp(ctx); return 0; } -int tx_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv) { +int tx_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv) { return sample_parse_args(ctx, argc, argv, true, false, false); }; -int rx_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv) { +int rx_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv) { return sample_parse_args(ctx, argc, argv, false, true, false); }; -int fwd_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv) { +int fwd_sample_parse_args(struct st_sample_context *ctx, int argc, + char **argv) { return sample_parse_args(ctx, argc, argv, true, true, false); }; -int dma_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv) { +int dma_sample_parse_args(struct st_sample_context *ctx, int argc, + char **argv) { /* init sample(st) dev */ sample_parse_args(ctx, argc, argv, false, false, false); /* enable dma port */ @@ -604,8 +616,8 @@ int dma_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv) return 0; }; -int sample_tx_queue_cnt_set(struct st_sample_context* ctx, uint16_t cnt) { - struct mtl_init_params* p = &ctx->param; +int sample_tx_queue_cnt_set(struct st_sample_context *ctx, uint16_t cnt) { + struct mtl_init_params *p = &ctx->param; for (uint8_t i = 0; i < p->num_ports; i++) { p->tx_queues_cnt[i] = cnt; @@ -614,8 +626,8 @@ int sample_tx_queue_cnt_set(struct st_sample_context* ctx, uint16_t cnt) { return 0; } -int sample_rx_queue_cnt_set(struct st_sample_context* ctx, uint16_t cnt) { - struct mtl_init_params* p = &ctx->param; +int sample_rx_queue_cnt_set(struct st_sample_context *ctx, uint16_t cnt) { + struct mtl_init_params *p = &ctx->param; for (uint8_t i = 0; i < p->num_ports; i++) { p->rx_queues_cnt[i] = cnt; @@ -624,7 +636,8 @@ int sample_rx_queue_cnt_set(struct st_sample_context* ctx, uint16_t cnt) { return 0; } -void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be* data, int w, int h) { +void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be *data, + int w, int h) { int pg_size = w * h / 2; uint16_t cb, y0, cr, y1; /* 10 bit */ @@ -652,7 +665,8 @@ void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be* data, int w } } -void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be* data, int w, int h) { +void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be *data, + int w, int h) { int pg_size = w * h / 2; uint16_t cb, y0, cr, y1; /* 12 bit */ @@ -680,7 +694,7 @@ void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be* data, int w } } -int ufd_override_check(struct st_sample_context* ctx) { +int ufd_override_check(struct st_sample_context *ctx) { struct mufd_override_params override; bool has_override = false; diff --git a/app/sample/sample_util.h b/app/sample/sample_util.h index f56dcaa22..5a81e46ad 100644 --- a/app/sample/sample_util.h +++ b/app/sample/sample_util.h @@ -27,26 +27,26 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #define ST_SAMPLE_URL_MAX_LEN (256) @@ -144,20 +144,22 @@ struct st_frame_user_meta { char dummy[512]; }; -int sample_parse_args(struct st_sample_context* ctx, int argc, char** argv, bool tx, - bool rx, bool unicast); +int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, + bool tx, bool rx, bool unicast); -int tx_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv); +int tx_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv); -int rx_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv); +int rx_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv); -int fwd_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv); +int fwd_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv); -int dma_sample_parse_args(struct st_sample_context* ctx, int argc, char** argv); +int dma_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv); -void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be* data, int w, int h); +void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be *data, + int w, int h); -void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be* data, int w, int h); +void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be *data, + int w, int h); /* Monotonic time (in nanoseconds) since some unspecified starting point. */ static inline uint64_t sample_get_monotonic_time() { @@ -167,10 +169,10 @@ static inline uint64_t sample_get_monotonic_time() { return ((uint64_t)ts.tv_sec * NS_PER_S) + ts.tv_nsec; } -int ufd_override_check(struct st_sample_context* ctx); +int ufd_override_check(struct st_sample_context *ctx); -int sample_tx_queue_cnt_set(struct st_sample_context* ctx, uint16_t cnt); +int sample_tx_queue_cnt_set(struct st_sample_context *ctx, uint16_t cnt); -int sample_rx_queue_cnt_set(struct st_sample_context* ctx, uint16_t cnt); +int sample_rx_queue_cnt_set(struct st_sample_context *ctx, uint16_t cnt); #endif diff --git a/app/sample/tx_st20_pipeline_sample.c b/app/sample/tx_st20_pipeline_sample.c index 460021570..2033d9954 100644 --- a/app/sample/tx_st20_pipeline_sample.c +++ b/app/sample/tx_st20_pipeline_sample.c @@ -16,16 +16,16 @@ struct tx_st20p_sample_ctx { int fb_send_done; size_t frame_size; - uint8_t* source_begin; + uint8_t *source_begin; mtl_iova_t source_begin_iova; - uint8_t* source_end; - uint8_t* frame_cursor; + uint8_t *source_end; + uint8_t *frame_cursor; struct st_frame_user_meta meta; bool has_user_meta; }; -static int tx_st20p_close_source(struct tx_st20p_sample_ctx* s) { +static int tx_st20p_close_source(struct tx_st20p_sample_ctx *s) { if (s->source_begin) { mtl_hp_free(s->st, s->source_begin); s->source_begin = NULL; @@ -34,11 +34,11 @@ static int tx_st20p_close_source(struct tx_st20p_sample_ctx* s) { return 0; } -static int tx_st20p_open_source(struct tx_st20p_sample_ctx* s, char* file) { +static int tx_st20p_open_source(struct tx_st20p_sample_ctx *s, char *file) { int fd = -EIO; struct stat i; int frame_cnt = 2; - uint8_t* m = NULL; + uint8_t *m = NULL; size_t fbs_size = s->frame_size * frame_cnt; fd = st_open(file, O_RDONLY); @@ -59,8 +59,8 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx* s, char* file) { return -EIO; } if (i.st_size % s->frame_size) { - err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", __func__, file, - s->frame_size); + err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", + __func__, file, s->frame_size); close(fd); return -EIO; } @@ -79,22 +79,27 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx* s, char* file) { s->source_begin = mtl_hp_zmalloc(s->st, fbs_size, MTL_PORT_P); if (!s->source_begin) { err("%s, source malloc on hugepage fail\n", __func__); - if (m) munmap(m, i.st_size); - if (fd >= 0) close(fd); + if (m) + munmap(m, i.st_size); + if (fd >= 0) + close(fd); return -EIO; } s->frame_cursor = s->source_begin; - if (m) mtl_memcpy(s->source_begin, m, fbs_size); + if (m) + mtl_memcpy(s->source_begin, m, fbs_size); s->source_end = s->source_begin + fbs_size; - if (m) munmap(m, i.st_size); - if (fd >= 0) close(fd); + if (m) + munmap(m, i.st_size); + if (fd >= 0) + close(fd); return 0; } -static int tx_st20p_frame_done(void* priv, struct st_frame* frame) { - struct tx_st20p_sample_ctx* s = priv; +static int tx_st20p_frame_done(void *priv, struct st_frame *frame) { + struct tx_st20p_sample_ctx *s = priv; MTL_MAY_UNUSED(frame); s->fb_send_done++; @@ -102,16 +107,17 @@ static int tx_st20p_frame_done(void* priv, struct st_frame* frame) { return 0; } -static void tx_st20p_build_frame(struct tx_st20p_sample_ctx* s, struct st_frame* frame) { - uint8_t* src = s->frame_cursor; +static void tx_st20p_build_frame(struct tx_st20p_sample_ctx *s, + struct st_frame *frame) { + uint8_t *src = s->frame_cursor; mtl_memcpy(frame->addr[0], src, s->frame_size); } -static void* tx_st20p_frame_thread(void* arg) { - struct tx_st20p_sample_ctx* s = arg; +static void *tx_st20p_frame_thread(void *arg) { + struct tx_st20p_sample_ctx *s = arg; st20p_tx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -121,7 +127,8 @@ static void* tx_st20p_frame_thread(void* arg) { continue; } - if (s->source_begin) tx_st20p_build_frame(s, frame); + if (s->source_begin) + tx_st20p_build_frame(s, frame); if (s->has_user_meta) { s->meta.idx = s->fb_send; frame->user_meta = &s->meta; @@ -142,14 +149,15 @@ static void* tx_st20p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -160,7 +168,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct tx_st20p_sample_ctx* app[session_num]; + struct tx_st20p_sample_ctx *app[session_num]; // create and register tx session for (int i = 0; i < session_num; i++) { @@ -175,23 +183,24 @@ int main(int argc, char** argv) { app[i]->idx = i; app[i]->stop = false; if (ctx.has_user_meta) { - snprintf(app[i]->meta.dummy, sizeof(app[i]->meta.dummy), "st20p_tx_%d", i); + snprintf(app[i]->meta.dummy, sizeof(app[i]->meta.dummy), "st20p_tx_%d", + i); app[i]->has_user_meta = true; } struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], + ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -230,7 +239,8 @@ int main(int argc, char** argv) { goto error; } - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -245,7 +255,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st20p_tx_wake_block(app[i]->handle); + if (app[i]->handle) + st20p_tx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), sent frames %d(done %d)\n", __func__, i, app[i]->fb_send, app[i]->fb_send_done); @@ -264,7 +275,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st20p_tx_free(app[i]->handle); + if (app[i]->handle) + st20p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/tx_st22_pipeline_sample.c b/app/sample/tx_st22_pipeline_sample.c index c3833a7d6..710dcf826 100644 --- a/app/sample/tx_st22_pipeline_sample.c +++ b/app/sample/tx_st22_pipeline_sample.c @@ -15,16 +15,16 @@ struct tx_st22p_sample_ctx { int fb_send; size_t frame_size; - uint8_t* source_begin; - uint8_t* source_end; - uint8_t* frame_cursor; + uint8_t *source_begin; + uint8_t *source_end; + uint8_t *frame_cursor; /* logo */ - void* logo_buf; + void *logo_buf; struct st_frame logo_meta; }; -static int tx_st22p_close_source(struct tx_st22p_sample_ctx* s) { +static int tx_st22p_close_source(struct tx_st22p_sample_ctx *s) { if (s->source_begin) { mtl_hp_free(s->st, s->source_begin); s->source_begin = NULL; @@ -38,9 +38,9 @@ static int tx_st22p_close_source(struct tx_st22p_sample_ctx* s) { return 0; } -static int tx_st22p_open_logo(struct st_sample_context* ctx, - struct tx_st22p_sample_ctx* s, char* file) { - FILE* fp_logo = st_fopen(file, "rb"); +static int tx_st22p_open_logo(struct st_sample_context *ctx, + struct tx_st22p_sample_ctx *s, char *file) { + FILE *fp_logo = st_fopen(file, "rb"); if (!fp_logo) { err("%s, open %s fail\n", __func__, file); return -EIO; @@ -73,8 +73,8 @@ static int tx_st22p_open_logo(struct st_sample_context* ctx, return 0; } -static int tx_st22p_open_source(struct st_sample_context* ctx, - struct tx_st22p_sample_ctx* s, char* file) { +static int tx_st22p_open_source(struct st_sample_context *ctx, + struct tx_st22p_sample_ctx *s, char *file) { int fd; struct stat i; @@ -96,7 +96,7 @@ static int tx_st22p_open_source(struct st_sample_context* ctx, return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s, mmap %s fail\n", __func__, file); close(fd); @@ -122,17 +122,18 @@ static int tx_st22p_open_source(struct st_sample_context* ctx, return 0; } -static void tx_st22p_build_frame(struct tx_st22p_sample_ctx* s, struct st_frame* frame) { +static void tx_st22p_build_frame(struct tx_st22p_sample_ctx *s, + struct st_frame *frame) { if (s->frame_cursor + s->frame_size > s->source_end) { s->frame_cursor = s->source_begin; } - uint8_t* src = s->frame_cursor; + uint8_t *src = s->frame_cursor; uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint8_t plane = 0; plane < planes; plane++) { size_t plane_sz = st_frame_plane_size(frame, plane); - dbg("%s(%d), src frame, plane %u size %" PRIu64 " addr %p\n", __func__, s->idx, plane, - plane_sz, frame->addr[plane]); + dbg("%s(%d), src frame, plane %u size %" PRIu64 " addr %p\n", __func__, + s->idx, plane, plane_sz, frame->addr[plane]); dbg("%s(%d), plane %u src addr %p\n", __func__, s->idx, plane, src); mtl_memcpy(frame->addr[plane], src, plane_sz); src += plane_sz; @@ -146,10 +147,10 @@ static void tx_st22p_build_frame(struct tx_st22p_sample_ctx* s, struct st_frame* s->frame_cursor += s->frame_size; } -static void* tx_st22p_frame_thread(void* arg) { - struct tx_st22p_sample_ctx* s = arg; +static void *tx_st22p_frame_thread(void *arg) { + struct tx_st22p_sample_ctx *s = arg; st22p_tx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -158,7 +159,8 @@ static void* tx_st22p_frame_thread(void* arg) { warn("%s(%d), get frame time out\n", __func__, s->idx); continue; } - if (s->source_begin) tx_st22p_build_frame(s, frame); + if (s->source_begin) + tx_st22p_build_frame(s, frame); st22p_tx_put_frame(handle, frame); s->fb_send++; } @@ -167,7 +169,7 @@ static void* tx_st22p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int bpp = 3; struct st_sample_context ctx; int ret; @@ -175,7 +177,8 @@ int main(int argc, char** argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -186,7 +189,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct tx_st22p_sample_ctx* app[session_num]; + struct tx_st22p_sample_ctx *app[session_num]; // create and register tx session for (int i = 0; i < session_num; i++) { @@ -204,16 +207,16 @@ int main(int argc, char** argv) { struct st22p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st22p_sample"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], + ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -235,7 +238,8 @@ int main(int argc, char** argv) { ops_tx.quality = ST22_QUALITY_MODE_QUALITY; ops_tx.codec_thread_cnt = 2; ops_tx.codestream_size = ops_tx.width * ops_tx.height * bpp / 8; - if (ops_tx.interlaced) ops_tx.codestream_size /= 2; + if (ops_tx.interlaced) + ops_tx.codestream_size /= 2; ops_tx.framebuff_cnt = ctx.framebuff_cnt; ops_tx.flags = ST22P_TX_FLAG_BLOCK_GET; @@ -250,7 +254,8 @@ int main(int argc, char** argv) { app[i]->frame_size = st22p_tx_frame_size(tx_handle); ret = tx_st22p_open_source(&ctx, app[i], ctx.tx_url); - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st22p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st22p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -265,7 +270,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st22p_tx_wake_block(app[i]->handle); + if (app[i]->handle) + st22p_tx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), sent frames %d\n", __func__, i, app[i]->fb_send); @@ -283,7 +289,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st22p_tx_free(app[i]->handle); + if (app[i]->handle) + st22p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/tx_st30_pipeline_sample.c b/app/sample/tx_st30_pipeline_sample.c index 571dce1ba..7912aa57b 100644 --- a/app/sample/tx_st30_pipeline_sample.c +++ b/app/sample/tx_st30_pipeline_sample.c @@ -16,13 +16,13 @@ struct tx_st30p_sample_ctx { int fb_send_done; size_t frame_size; - uint8_t* source_begin; + uint8_t *source_begin; mtl_iova_t source_begin_iova; - uint8_t* source_end; - uint8_t* frame_cursor; + uint8_t *source_end; + uint8_t *frame_cursor; }; -static int tx_st30p_close_source(struct tx_st30p_sample_ctx* s) { +static int tx_st30p_close_source(struct tx_st30p_sample_ctx *s) { if (s->source_begin) { mtl_hp_free(s->st, s->source_begin); s->source_begin = NULL; @@ -31,11 +31,11 @@ static int tx_st30p_close_source(struct tx_st30p_sample_ctx* s) { return 0; } -static int tx_st30p_open_source(struct tx_st30p_sample_ctx* s, char* file) { +static int tx_st30p_open_source(struct tx_st30p_sample_ctx *s, char *file) { int fd = -EIO; struct stat i; int frame_cnt = 2; - uint8_t* m = NULL; + uint8_t *m = NULL; size_t fbs_size = s->frame_size * frame_cnt; fd = st_open(file, O_RDONLY); @@ -56,8 +56,8 @@ static int tx_st30p_open_source(struct tx_st30p_sample_ctx* s, char* file) { return -EIO; } if (i.st_size % s->frame_size) { - err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", __func__, file, - s->frame_size); + err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", + __func__, file, s->frame_size); close(fd); return -EIO; } @@ -75,22 +75,27 @@ static int tx_st30p_open_source(struct tx_st30p_sample_ctx* s, char* file) { s->source_begin = mtl_hp_zmalloc(s->st, fbs_size, MTL_PORT_P); if (!s->source_begin) { err("%s, source malloc on hugepage fail\n", __func__); - if (m) munmap(m, i.st_size); - if (fd >= 0) close(fd); + if (m) + munmap(m, i.st_size); + if (fd >= 0) + close(fd); return -EIO; } s->frame_cursor = s->source_begin; - if (m) mtl_memcpy(s->source_begin, m, fbs_size); + if (m) + mtl_memcpy(s->source_begin, m, fbs_size); s->source_end = s->source_begin + fbs_size; - if (m) munmap(m, i.st_size); - if (fd >= 0) close(fd); + if (m) + munmap(m, i.st_size); + if (fd >= 0) + close(fd); return 0; } -static int tx_st30p_frame_done(void* priv, struct st30_frame* frame) { - struct tx_st30p_sample_ctx* s = priv; +static int tx_st30p_frame_done(void *priv, struct st30_frame *frame) { + struct tx_st30p_sample_ctx *s = priv; MTL_MAY_UNUSED(frame); s->fb_send_done++; @@ -98,17 +103,17 @@ static int tx_st30p_frame_done(void* priv, struct st30_frame* frame) { return 0; } -static void tx_st30p_build_frame(struct tx_st30p_sample_ctx* s, - struct st30_frame* frame) { - uint8_t* src = s->frame_cursor; +static void tx_st30p_build_frame(struct tx_st30p_sample_ctx *s, + struct st30_frame *frame) { + uint8_t *src = s->frame_cursor; mtl_memcpy(frame->addr, src, s->frame_size); } -static void* tx_st30p_frame_thread(void* arg) { - struct tx_st30p_sample_ctx* s = arg; +static void *tx_st30p_frame_thread(void *arg) { + struct tx_st30p_sample_ctx *s = arg; st30p_tx_handle handle = s->handle; - struct st30_frame* frame; + struct st30_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -118,7 +123,8 @@ static void* tx_st30p_frame_thread(void* arg) { continue; } - if (s->source_begin) tx_st30p_build_frame(s, frame); + if (s->source_begin) + tx_st30p_build_frame(s, frame); st30p_tx_put_frame(handle, frame); /* point to next frame */ @@ -134,14 +140,15 @@ static void* tx_st30p_frame_thread(void* arg) { return NULL; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -152,7 +159,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct tx_st30p_sample_ctx* app[session_num]; + struct tx_st30p_sample_ctx *app[session_num]; // create and register tx session for (int i = 0; i < session_num; i++) { @@ -170,16 +177,16 @@ int main(int argc, char** argv) { struct st30p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st30p_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.audio_udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], + ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.audio_udp_port + i * 2; @@ -199,8 +206,9 @@ int main(int argc, char** argv) { ops_tx.ptime = ctx.audio_ptime; /* set frame size to 10ms time */ - int framebuff_size = st30_calculate_framebuff_size( - ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel, 10 * NS_PER_MS, NULL); + int framebuff_size = + st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, + ops_tx.channel, 10 * NS_PER_MS, NULL); ops_tx.framebuff_size = framebuff_size; st30p_tx_handle tx_handle = st30p_tx_create(ctx.st, &ops_tx); @@ -217,10 +225,11 @@ int main(int argc, char** argv) { err("%s(%d), open source fail\n", __func__, i); goto error; } - info("%s(%d), frame_size %" PRId64 ", tx url %s\n", __func__, i, app[i]->frame_size, - ctx.tx_audio_url); + info("%s(%d), frame_size %" PRId64 ", tx url %s\n", __func__, i, + app[i]->frame_size, ctx.tx_audio_url); - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st30p_frame_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st30p_frame_thread, + app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -235,7 +244,8 @@ int main(int argc, char** argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) st30p_tx_wake_block(app[i]->handle); + if (app[i]->handle) + st30p_tx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), sent frames %d(done %d)\n", __func__, i, app[i]->fb_send, app[i]->fb_send_done); @@ -254,7 +264,8 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) st30p_tx_free(app[i]->handle); + if (app[i]->handle) + st30p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/src/app_base.h b/app/src/app_base.h index be8e0b08d..8a1949ec6 100644 --- a/app/src/app_base.h +++ b/app/src/app_base.h @@ -45,7 +45,7 @@ #define ST_APP_DEFAULT_FB_CNT (3) -#define ST_APP_EXPECT_NEAR(val, expect, delta) \ +#define ST_APP_EXPECT_NEAR(val, expect, delta) \ ((val > (expect - delta)) && (val < (expect + delta))) #ifndef NS_PER_S @@ -68,20 +68,20 @@ struct st_display { char name[36]; #ifdef APP_HAS_SDL2 - SDL_Window* window; - SDL_Renderer* renderer; - SDL_Texture* texture; + SDL_Window *window; + SDL_Renderer *renderer; + SDL_Texture *texture; SDL_PixelFormatEnum fmt; SDL_Rect msg_rect; #endif #ifdef APP_HAS_SDL2_TTF - TTF_Font* font; + TTF_Font *font; #endif int window_w; int window_h; int pixel_w; int pixel_h; - void* front_frame; + void *front_frame; int front_frame_size; uint32_t last_time; uint32_t frame_cnt; @@ -106,21 +106,21 @@ struct st_app_tx_video_session { st20_tx_handle handle; int handle_sch_idx; - struct st_app_context* ctx; + struct st_app_context *ctx; uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_tx_frame* framebuffs; + struct st_tx_frame *framebuffs; bool sha_check; - pcap_t* st20_pcap; + pcap_t *st20_pcap; bool st20_pcap_input; char st20_source_url[ST_APP_URL_MAX_LEN]; - uint8_t* st20_source_begin; - uint8_t* st20_source_end; - uint8_t* st20_frame_cursor; + uint8_t *st20_source_begin; + uint8_t *st20_source_end; + uint8_t *st20_frame_cursor; int st20_source_fd; bool st20_frames_copied; @@ -141,10 +141,11 @@ struct st_app_tx_video_session { /* rtp mode info */ bool st20_rtp_input; - int st20_pkts_in_line; /* GPM only, number of packets per each line, 4 for 1080p */ + int st20_pkts_in_line; /* GPM only, number of packets per each line, 4 for + 1080p */ int st20_bytes_in_line; /* bytes per line, 4800 for 1080p yuv422 10bit */ - uint32_t - st20_pkt_data_len; /* data len(byte) for each pkt, 1200 for 1080p yuv422 10bit */ + uint32_t st20_pkt_data_len; /* data len(byte) for each pkt, 1200 for 1080p + yuv422 10bit */ struct st20_rfc4175_rtp_hdr st20_rtp_base; int st20_total_pkts; /* total pkts in one frame, ex: 4320 for 1080p */ int st20_pkt_idx; /* pkt index in current frame */ @@ -162,7 +163,7 @@ struct st_app_tx_video_session { pthread_cond_t st20_wake_cond; pthread_mutex_t st20_wake_mutex; - struct st_display* display; + struct st_display *display; int lcore; }; @@ -173,19 +174,19 @@ struct st_app_tx_audio_session { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_tx_frame* framebuffs; + struct st_tx_frame *framebuffs; int st30_frame_done_cnt; int st30_packet_done_cnt; char st30_source_url[ST_APP_URL_MAX_LEN + 1]; int st30_source_fd; - pcap_t* st30_pcap; + pcap_t *st30_pcap; bool st30_pcap_input; bool st30_rtp_input; - uint8_t* st30_source_begin; - uint8_t* st30_source_end; - uint8_t* st30_frame_cursor; /* cursor to current frame */ + uint8_t *st30_source_begin; + uint8_t *st30_source_end; + uint8_t *st30_frame_cursor; /* cursor to current frame */ int st30_frame_size; int pkt_len; pthread_t st30_app_thread; @@ -205,19 +206,19 @@ struct st_app_tx_anc_session { uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_tx_frame* framebuffs; + struct st_tx_frame *framebuffs; uint32_t st40_frame_done_cnt; uint32_t st40_packet_done_cnt; char st40_source_url[ST_APP_URL_MAX_LEN + 1]; int st40_source_fd; - pcap_t* st40_pcap; + pcap_t *st40_pcap; bool st40_pcap_input; bool st40_rtp_input; - uint8_t* st40_source_begin; - uint8_t* st40_source_end; - uint8_t* st40_frame_cursor; /* cursor to current frame */ + uint8_t *st40_source_begin; + uint8_t *st40_source_end; + uint8_t *st40_frame_cursor; /* cursor to current frame */ pthread_t st40_app_thread; bool st40_app_thread_stop; pthread_cond_t st40_wake_cond; @@ -241,14 +242,14 @@ struct st_app_rx_video_session { char st20_dst_url[ST_APP_URL_MAX_LEN]; int st20_dst_fb_cnt; /* the count of received fbs will be saved to file */ int st20_dst_fd; - uint8_t* st20_dst_begin; - uint8_t* st20_dst_end; - uint8_t* st20_dst_cursor; + uint8_t *st20_dst_begin; + uint8_t *st20_dst_end; + uint8_t *st20_dst_cursor; /* frame info */ uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_rx_frame* framebuffs; + struct st_rx_frame *framebuffs; /* rtp info */ uint32_t st20_last_tmstamp; @@ -270,7 +271,7 @@ struct st_app_rx_video_session { pthread_mutex_t st20_wake_mutex; bool st20_app_thread_stop; - struct st_display* display; + struct st_display *display; uint32_t pcapng_max_pkts; bool measure_latency; @@ -286,17 +287,17 @@ struct st_app_rx_audio_session { char st30_ref_url[ST_APP_URL_MAX_LEN + 1]; int st30_ref_fd; - uint8_t* st30_ref_begin; - uint8_t* st30_ref_end; - uint8_t* st30_ref_cursor; + uint8_t *st30_ref_begin; + uint8_t *st30_ref_end; + uint8_t *st30_ref_cursor; int st30_ref_err; int st30_dump_time_s; int st30_dump_fd; char st30_dump_url[ST_APP_URL_MAX_LEN]; - uint8_t* st30_dump_begin; - uint8_t* st30_dump_end; - uint8_t* st30_dump_cursor; + uint8_t *st30_dump_begin; + uint8_t *st30_dump_end; + uint8_t *st30_dump_cursor; pthread_t st30_app_thread; pthread_cond_t st30_wake_cond; @@ -337,13 +338,13 @@ struct st22_app_tx_session { int bpp; size_t bytes_per_frame; - struct st_app_context* ctx; + struct st_app_context *ctx; mtl_handle st; uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_tx_frame* framebuffs; + struct st_tx_frame *framebuffs; pthread_cond_t wake_cond; pthread_mutex_t wake_mutex; @@ -352,9 +353,9 @@ struct st22_app_tx_session { pthread_t st22_app_thread; char st22_source_url[ST_APP_URL_MAX_LEN]; int st22_source_fd; - uint8_t* st22_source_begin; - uint8_t* st22_source_end; - uint8_t* st22_frame_cursor; + uint8_t *st22_source_begin; + uint8_t *st22_source_end; + uint8_t *st22_frame_cursor; int fb_send; }; @@ -370,7 +371,7 @@ struct st22_app_rx_session { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st_rx_frame* framebuffs; + struct st_rx_frame *framebuffs; pthread_cond_t wake_cond; pthread_mutex_t wake_mutex; @@ -382,9 +383,9 @@ struct st22_app_rx_session { char st22_dst_url[ST_APP_URL_MAX_LEN]; int st22_dst_fb_cnt; /* the count of received fbs will be saved to file */ int st22_dst_fd; - uint8_t* st22_dst_begin; - uint8_t* st22_dst_end; - uint8_t* st22_dst_cursor; + uint8_t *st22_dst_begin; + uint8_t *st22_dst_end; + uint8_t *st22_dst_cursor; }; struct st_app_tx_st22p_session { @@ -397,12 +398,12 @@ struct st_app_tx_st22p_session { int height; char st22p_source_url[ST_APP_URL_MAX_LEN]; - uint8_t* st22p_source_begin; - uint8_t* st22p_source_end; - uint8_t* st22p_frame_cursor; + uint8_t *st22p_source_begin; + uint8_t *st22p_source_end; + uint8_t *st22p_frame_cursor; int st22p_source_fd; - struct st_display* display; + struct st_display *display; double expect_fps; pthread_t st22p_app_thread; @@ -429,7 +430,7 @@ struct st_app_rx_st22p_session { pthread_t st22p_app_thread; bool st22p_app_thread_stop; - struct st_display* display; + struct st_display *display; uint32_t pcapng_max_pkts; bool measure_latency; @@ -437,7 +438,7 @@ struct st_app_rx_st22p_session { }; struct st_app_tx_st20p_session { - struct st_app_context* ctx; + struct st_app_context *ctx; int idx; st20p_tx_handle handle; @@ -451,13 +452,13 @@ struct st_app_tx_st20p_session { bool sha_check; char st20p_source_url[ST_APP_URL_MAX_LEN]; - uint8_t* st20p_source_begin; - uint8_t* st20p_source_end; - uint8_t* st20p_frame_cursor; + uint8_t *st20p_source_begin; + uint8_t *st20p_source_end; + uint8_t *st20p_frame_cursor; int st20p_source_fd; bool st20p_frames_copied; - struct st_display* display; + struct st_display *display; double expect_fps; pthread_t st20p_app_thread; @@ -486,7 +487,7 @@ struct st_app_rx_st20p_session { pthread_t st20p_app_thread; bool st20p_app_thread_stop; - struct st_display* display; + struct st_display *display; uint32_t pcapng_max_pkts; bool measure_latency; @@ -494,7 +495,7 @@ struct st_app_rx_st20p_session { }; struct st_app_tx_st30p_session { - struct st_app_context* ctx; + struct st_app_context *ctx; int idx; st30p_tx_handle handle; @@ -505,9 +506,9 @@ struct st_app_tx_st30p_session { uint64_t last_stat_time_ns; char st30p_source_url[ST_APP_URL_MAX_LEN]; - uint8_t* st30p_source_begin; - uint8_t* st30p_source_end; - uint8_t* st30p_frame_cursor; + uint8_t *st30p_source_begin; + uint8_t *st30p_source_end; + uint8_t *st30p_frame_cursor; int st30p_source_fd; bool st30p_frames_copied; @@ -544,7 +545,7 @@ struct st_app_var_params { }; struct st_app_context { - st_json_context_t* json_ctx; + st_json_context_t *json_ctx; struct mtl_init_params para; struct st_app_var_params var_para; mtl_handle st; @@ -556,7 +557,7 @@ struct st_app_context { int lcore[ST_APP_MAX_LCORES]; int rtp_lcore[ST_APP_MAX_LCORES]; - FILE* mtl_log_stream; + FILE *mtl_log_stream; uint64_t last_stat_time_ns; bool runtime_session; @@ -580,7 +581,7 @@ struct st_app_context { int64_t ptp_sync_delta_min; char tx_video_url[ST_APP_URL_MAX_LEN]; /* send video content url*/ - struct st_app_tx_video_session* tx_video_sessions; + struct st_app_tx_video_session *tx_video_sessions; int tx_video_session_cnt; int tx_video_rtp_ring_size; /* the ring size for tx video rtp type */ uint16_t tx_start_vrx; @@ -593,7 +594,7 @@ struct st_app_context { bool tx_no_bulk; bool video_sha_check; - struct st_app_tx_audio_session* tx_audio_sessions; + struct st_app_tx_audio_session *tx_audio_sessions; char tx_audio_url[ST_APP_URL_MAX_LEN]; int tx_audio_session_cnt; int tx_audio_rtp_ring_size; /* the ring size for tx audio rtp type */ @@ -604,27 +605,28 @@ struct st_app_context { int tx_audio_rl_offset_us; enum st30_tx_pacing_way tx_audio_pacing_way; - struct st_app_tx_anc_session* tx_anc_sessions; + struct st_app_tx_anc_session *tx_anc_sessions; char tx_anc_url[ST_APP_URL_MAX_LEN]; int tx_anc_session_cnt; int tx_anc_rtp_ring_size; /* the ring size for tx anc rtp type */ bool tx_anc_dedicate_queue; char tx_st22p_url[ST_APP_URL_MAX_LEN]; /* send st22p content url*/ - struct st_app_tx_st22p_session* tx_st22p_sessions; + struct st_app_tx_st22p_session *tx_st22p_sessions; int tx_st22p_session_cnt; char tx_st20p_url[ST_APP_URL_MAX_LEN]; /* send st20p content url*/ - struct st_app_tx_st20p_session* tx_st20p_sessions; + struct st_app_tx_st20p_session *tx_st20p_sessions; int tx_st20p_session_cnt; - struct st_app_tx_st30p_session* tx_st30p_sessions; + struct st_app_tx_st30p_session *tx_st30p_sessions; int tx_st30p_session_cnt; - uint8_t rx_ip_addr[MTL_PORT_MAX][MTL_IP_ADDR_LEN]; /* rx IP */ - uint8_t rx_mcast_sip_addr[MTL_PORT_MAX][MTL_IP_ADDR_LEN]; /* rx multicast source IP */ + uint8_t rx_ip_addr[MTL_PORT_MAX][MTL_IP_ADDR_LEN]; /* rx IP */ + uint8_t rx_mcast_sip_addr[MTL_PORT_MAX] + [MTL_IP_ADDR_LEN]; /* rx multicast source IP */ - struct st_app_rx_video_session* rx_video_sessions; + struct st_app_rx_video_session *rx_video_sessions; int rx_video_session_cnt; int rx_video_file_frames; /* the frames received saved to file */ int rx_video_fb_cnt; @@ -633,29 +635,29 @@ struct st_app_context { bool rx_video_multi_thread; int rx_audio_dump_time_s; /* the audio dump time */ - struct st_app_rx_audio_session* rx_audio_sessions; + struct st_app_rx_audio_session *rx_audio_sessions; int rx_audio_session_cnt; int rx_audio_rtp_ring_size; /* the ring size for rx audio rtp type */ - struct st_app_rx_anc_session* rx_anc_sessions; + struct st_app_rx_anc_session *rx_anc_sessions; int rx_anc_session_cnt; - struct st_app_rx_st22p_session* rx_st22p_sessions; + struct st_app_rx_st22p_session *rx_st22p_sessions; int rx_st22p_session_cnt; - struct st_app_rx_st20p_session* rx_st20p_sessions; + struct st_app_rx_st20p_session *rx_st20p_sessions; int rx_st20p_session_cnt; - struct st_app_rx_st30p_session* rx_st30p_sessions; + struct st_app_rx_st30p_session *rx_st30p_sessions; int rx_st30p_session_cnt; - struct st_app_rx_video_session* rx_st20r_sessions; + struct st_app_rx_video_session *rx_st20r_sessions; int rx_st20r_session_cnt; char tx_st22_url[ST_APP_URL_MAX_LEN]; /* send st22 content url*/ - struct st22_app_tx_session* tx_st22_sessions; + struct st22_app_tx_session *tx_st22_sessions; int tx_st22_session_cnt; - struct st22_app_rx_session* rx_st22_sessions; + struct st22_app_rx_session *rx_st22_sessions; int rx_st22_session_cnt; int st22_bpp; @@ -664,25 +666,22 @@ struct st_app_context { int utc_offset; }; -static inline void* st_app_malloc(size_t sz) { - return malloc(sz); -} +static inline void *st_app_malloc(size_t sz) { return malloc(sz); } -static inline void* st_app_zmalloc(size_t sz) { - void* p = malloc(sz); - if (p) memset(p, 0x0, sz); +static inline void *st_app_zmalloc(size_t sz) { + void *p = malloc(sz); + if (p) + memset(p, 0x0, sz); return p; } -static inline void st_app_free(void* p) { - free(p); -} +static inline void st_app_free(void *p) { free(p); } -static inline uint64_t st_timespec_to_ns(const struct timespec* ts) { +static inline uint64_t st_timespec_to_ns(const struct timespec *ts) { return ((uint64_t)ts->tv_sec * NS_PER_S) + ts->tv_nsec; } -static inline void st_ns_to_timespec(uint64_t ns, struct timespec* ts) { +static inline void st_ns_to_timespec(uint64_t ns, struct timespec *ts) { ts->tv_sec = ns / NS_PER_S; ts->tv_nsec = ns % NS_PER_S; } @@ -695,14 +694,14 @@ static inline uint64_t st_app_get_monotonic_time() { return st_timespec_to_ns(&ts); } -int st_app_video_get_lcore(struct st_app_context* ctx, int sch_idx, bool rtp, - unsigned int* lcore); +int st_app_video_get_lcore(struct st_app_context *ctx, int sch_idx, bool rtp, + unsigned int *lcore); -uint8_t* st_json_ip(struct st_app_context* ctx, st_json_session_base_t* base, +uint8_t *st_json_ip(struct st_app_context *ctx, st_json_session_base_t *base, enum mtl_session_port port); -int st_set_mtl_log_file(struct st_app_context* ctx, const char* file); +int st_set_mtl_log_file(struct st_app_context *ctx, const char *file); -void st_sha_dump(const char* tag, const unsigned char* sha); +void st_sha_dump(const char *tag, const unsigned char *sha); #endif diff --git a/app/src/app_platform.h b/app/src/app_platform.h index 1354d0498..889455003 100644 --- a/app/src/app_platform.h +++ b/app/src/app_platform.h @@ -79,58 +79,59 @@ struct st_tx_frame { }; struct st_rx_frame { - void* frame; + void *frame; size_t size; uint8_t shas[SHA256_DIGEST_LENGTH]; }; -static inline int st_pthread_mutex_init(pthread_mutex_t* mutex, - pthread_mutexattr_t* attr) { +static inline int st_pthread_mutex_init(pthread_mutex_t *mutex, + pthread_mutexattr_t *attr) { return pthread_mutex_init(mutex, attr); } -static inline int st_pthread_mutex_trylock(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_trylock(pthread_mutex_t *mutex) { return pthread_mutex_trylock(mutex); } -static inline int st_pthread_mutex_lock(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); } -static inline int st_pthread_mutex_unlock(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_unlock(pthread_mutex_t *mutex) { return pthread_mutex_unlock(mutex); } -static inline int st_pthread_mutex_destroy(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_destroy(pthread_mutex_t *mutex) { return pthread_mutex_destroy(mutex); } -static inline int st_pthread_cond_init(pthread_cond_t* cond, - pthread_condattr_t* cond_attr) { +static inline int st_pthread_cond_init(pthread_cond_t *cond, + pthread_condattr_t *cond_attr) { return pthread_cond_init(cond, cond_attr); } -static inline int st_pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) { +static inline int st_pthread_cond_wait(pthread_cond_t *cond, + pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } -static inline int st_pthread_cond_destroy(pthread_cond_t* cond) { +static inline int st_pthread_cond_destroy(pthread_cond_t *cond) { return pthread_cond_destroy(cond); } -static inline int st_pthread_cond_signal(pthread_cond_t* cond) { +static inline int st_pthread_cond_signal(pthread_cond_t *cond) { return pthread_cond_signal(cond); } -static inline int st_open(const char* path, int flags) { +static inline int st_open(const char *path, int flags) { return open(path, flags); } -static inline int st_open_mode(const char* path, int flags, mode_t mode) { +static inline int st_open_mode(const char *path, int flags, mode_t mode) { return open(path, flags, mode); } -static inline FILE* st_fopen(const char* path, const char* mode) { +static inline FILE *st_fopen(const char *path, const char *mode) { return fopen(path, mode); } @@ -142,8 +143,8 @@ static inline void st_pause(void) { #endif } -static inline void st_usleep( - useconds_t usec) { // windows usleep function precision is only 1~15ms +static inline void +st_usleep(useconds_t usec) { // windows usleep function precision is only 1~15ms #ifdef WINDOWSENV LARGE_INTEGER delay; HANDLE delay_timer_handle = NULL; @@ -162,22 +163,22 @@ static inline void st_usleep( #endif } -static inline int st_get_real_time(struct timespec* ts) { +static inline int st_get_real_time(struct timespec *ts) { return clock_gettime(CLOCK_REALTIME, ts); } -static inline int st_set_real_time(struct timespec* ts) { +static inline int st_set_real_time(struct timespec *ts) { return clock_settime(CLOCK_REALTIME, ts); } #ifdef APP_HAS_SSL -static inline unsigned char* st_sha256(const unsigned char* d, size_t n, - unsigned char* md) { +static inline unsigned char *st_sha256(const unsigned char *d, size_t n, + unsigned char *md) { return SHA256(d, n, md); } #else -static inline unsigned char* st_sha256(const unsigned char* d, size_t n, - unsigned char* md) { +static inline unsigned char *st_sha256(const unsigned char *d, size_t n, + unsigned char *md) { MTL_MAY_UNUSED(d); MTL_MAY_UNUSED(n); md[0] = rand(); diff --git a/app/src/args.c b/app/src/args.c index d89eaf387..7b34dd152 100644 --- a/app/src/args.c +++ b/app/src/args.c @@ -175,24 +175,32 @@ static struct option st_app_args_options[] = { {"r_rx_mcast_sip", required_argument, 0, ST_ARG_R_RX_MCAST_SIP}, {"tx_video_url", required_argument, 0, ST_ARG_TX_VIDEO_URL}, - {"tx_video_sessions_count", required_argument, 0, ST_ARG_TX_VIDEO_SESSIONS_CNT}, - {"tx_video_rtp_ring_size", required_argument, 0, ST_ARG_TX_VIDEO_RTP_RING_SIZE}, + {"tx_video_sessions_count", required_argument, 0, + ST_ARG_TX_VIDEO_SESSIONS_CNT}, + {"tx_video_rtp_ring_size", required_argument, 0, + ST_ARG_TX_VIDEO_RTP_RING_SIZE}, {"tx_audio_url", required_argument, 0, ST_ARG_TX_AUDIO_URL}, - {"tx_audio_sessions_count", required_argument, 0, ST_ARG_TX_AUDIO_SESSIONS_CNT}, - {"tx_audio_rtp_ring_size", required_argument, 0, ST_ARG_TX_AUDIO_RTP_RING_SIZE}, + {"tx_audio_sessions_count", required_argument, 0, + ST_ARG_TX_AUDIO_SESSIONS_CNT}, + {"tx_audio_rtp_ring_size", required_argument, 0, + ST_ARG_TX_AUDIO_RTP_RING_SIZE}, {"tx_anc_url", required_argument, 0, ST_ARG_TX_ANC_URL}, {"tx_anc_sessions_count", required_argument, 0, ST_ARG_TX_ANC_SESSIONS_CNT}, {"tx_anc_rtp_ring_size", required_argument, 0, ST_ARG_TX_ANC_RTP_RING_SIZE}, {"tx_st22_sessions_count", required_argument, 0, ST22_ARG_TX_SESSIONS_CNT}, {"tx_st22_url", required_argument, 0, ST22_ARG_TX_URL}, - {"rx_video_sessions_count", required_argument, 0, ST_ARG_RX_VIDEO_SESSIONS_CNT}, + {"rx_video_sessions_count", required_argument, 0, + ST_ARG_RX_VIDEO_SESSIONS_CNT}, {"rx_video_file_frames", required_argument, 0, ST_ARG_RX_VIDEO_FILE_FRAMES}, {"rx_video_fb_cnt", required_argument, 0, ST_ARG_RX_VIDEO_FB_CNT}, - {"rx_video_rtp_ring_size", required_argument, 0, ST_ARG_RX_VIDEO_RTP_RING_SIZE}, + {"rx_video_rtp_ring_size", required_argument, 0, + ST_ARG_RX_VIDEO_RTP_RING_SIZE}, {"rx_video_multi_thread", no_argument, 0, ST_ARG_RX_VIDEO_MULTI_THREADS}, - {"rx_audio_sessions_count", required_argument, 0, ST_ARG_RX_AUDIO_SESSIONS_CNT}, - {"rx_audio_rtp_ring_size", required_argument, 0, ST_ARG_RX_AUDIO_RTP_RING_SIZE}, + {"rx_audio_sessions_count", required_argument, 0, + ST_ARG_RX_AUDIO_SESSIONS_CNT}, + {"rx_audio_rtp_ring_size", required_argument, 0, + ST_ARG_RX_AUDIO_RTP_RING_SIZE}, {"rx_audio_dump_time_s", required_argument, 0, ST_ARG_RX_AUDIO_DUMP_TIME_S}, {"rx_anc_sessions_count", required_argument, 0, ST_ARG_RX_ANC_SESSIONS_CNT}, {"rx_st22_sessions_count", required_argument, 0, ST22_ARG_RX_SESSIONS_CNT}, @@ -293,49 +301,54 @@ static struct option st_app_args_options[] = { {0, 0, 0, 0}}; -static int app_args_parse_lcores(struct mtl_init_params* p, char* list) { - if (!list) return -EIO; +static int app_args_parse_lcores(struct mtl_init_params *p, char *list) { + if (!list) + return -EIO; dbg("%s, lcore list %s\n", __func__, list); p->lcores = list; return 0; } -static int app_args_parse_tx_mac(struct st_app_context* ctx, char* mac_str, +static int app_args_parse_tx_mac(struct st_app_context *ctx, char *mac_str, enum mtl_port port) { int ret; - uint8_t* mac; + uint8_t *mac; - if (!mac_str) return -EIO; + if (!mac_str) + return -EIO; dbg("%s, tx dst mac %s\n", __func__, mac_str); mac = &ctx->tx_dst_mac[port][0]; - ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], &mac[1], - &mac[2], &mac[3], &mac[4], &mac[5]); - if (ret < 0) return ret; + ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], + &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); + if (ret < 0) + return ret; ctx->has_tx_dst_mac[port] = true; return 0; } -static int app_args_dma_dev(struct mtl_init_params* p, char* in_dev) { - if (!in_dev) return -EIO; +static int app_args_dma_dev(struct mtl_init_params *p, char *in_dev) { + if (!in_dev) + return -EIO; char devs[128] = {0}; snprintf(devs, 128 - 1, "%s", in_dev); dbg("%s, dev list %s\n", __func__, devs); - char* next_dev = strtok(devs, ","); + char *next_dev = strtok(devs, ","); while (next_dev && (p->num_dma_dev_port < MTL_DMA_DEV_MAX)) { dbg("next_dev: %s\n", next_dev); - snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", next_dev); + snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", + next_dev); p->num_dma_dev_port++; next_dev = strtok(NULL, ","); } return 0; } -static int app_args_json(struct st_app_context* ctx, struct mtl_init_params* p, - char* json_file) { +static int app_args_json(struct st_app_context *ctx, struct mtl_init_params *p, + char *json_file) { ctx->json_ctx = st_app_zmalloc(sizeof(st_json_context_t)); if (!ctx->json_ctx) { err("%s, json_ctx alloc fail\n", __func__); @@ -362,10 +375,14 @@ static int app_args_json(struct st_app_context* ctx, struct mtl_init_params* p, ctx->rx_st30p_session_cnt = ctx->json_ctx->rx_st30p_session_cnt; ctx->rx_st20r_session_cnt = ctx->json_ctx->rx_st20r_session_cnt; for (int i = 0; i < ctx->json_ctx->num_interfaces; ++i) { - snprintf(p->port[i], sizeof(p->port[i]), "%s", ctx->json_ctx->interfaces[i].name); - memcpy(p->sip_addr[i], ctx->json_ctx->interfaces[i].ip_addr, sizeof(p->sip_addr[i])); - memcpy(p->netmask[i], ctx->json_ctx->interfaces[i].netmask, sizeof(p->netmask[i])); - memcpy(p->gateway[i], ctx->json_ctx->interfaces[i].gateway, sizeof(p->gateway[i])); + snprintf(p->port[i], sizeof(p->port[i]), "%s", + ctx->json_ctx->interfaces[i].name); + memcpy(p->sip_addr[i], ctx->json_ctx->interfaces[i].ip_addr, + sizeof(p->sip_addr[i])); + memcpy(p->netmask[i], ctx->json_ctx->interfaces[i].netmask, + sizeof(p->netmask[i])); + memcpy(p->gateway[i], ctx->json_ctx->interfaces[i].gateway, + sizeof(p->gateway[i])); p->net_proto[i] = ctx->json_ctx->interfaces[i].net_proto; p->tx_queues_cnt[i] = ctx->json_ctx->interfaces[i].tx_queues_cnt; p->rx_queues_cnt[i] = ctx->json_ctx->interfaces[i].rx_queues_cnt; @@ -376,22 +393,29 @@ static int app_args_json(struct st_app_context* ctx, struct mtl_init_params* p, ctx->json_ctx->sch_quota * st20_1080p59_yuv422_10bit_bandwidth_mps(); } if (ctx->json_ctx->tx_audio_sessions_max_per_sch) { - p->tx_audio_sessions_max_per_sch = ctx->json_ctx->tx_audio_sessions_max_per_sch; + p->tx_audio_sessions_max_per_sch = + ctx->json_ctx->tx_audio_sessions_max_per_sch; } if (ctx->json_ctx->rx_audio_sessions_max_per_sch) { - p->rx_audio_sessions_max_per_sch = ctx->json_ctx->rx_audio_sessions_max_per_sch; + p->rx_audio_sessions_max_per_sch = + ctx->json_ctx->rx_audio_sessions_max_per_sch; } - if (ctx->json_ctx->shared_tx_queues) p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - if (ctx->json_ctx->shared_rx_queues) p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - if (ctx->json_ctx->tx_no_chain) p->flags |= MTL_FLAG_TX_NO_CHAIN; - if (ctx->json_ctx->rss_mode) p->rss_mode = ctx->json_ctx->rss_mode; - if (ctx->json_ctx->log_file) st_set_mtl_log_file(ctx, ctx->json_ctx->log_file); + if (ctx->json_ctx->shared_tx_queues) + p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + if (ctx->json_ctx->shared_rx_queues) + p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + if (ctx->json_ctx->tx_no_chain) + p->flags |= MTL_FLAG_TX_NO_CHAIN; + if (ctx->json_ctx->rss_mode) + p->rss_mode = ctx->json_ctx->rss_mode; + if (ctx->json_ctx->log_file) + st_set_mtl_log_file(ctx, ctx->json_ctx->log_file); info("%s, json_file %s succ\n", __func__, json_file); return 0; } -static void log_prefix_time_ms(char* buf, size_t sz) { +static void log_prefix_time_ms(char *buf, size_t sz) { struct timespec ts; struct tm tm; char time_s_buf[64]; @@ -402,7 +426,8 @@ static void log_prefix_time_ms(char* buf, size_t sz) { snprintf(buf, sz, "%s.%u, ", time_s_buf, (uint32_t)(ts.tv_nsec / NS_PER_MS)); } -static void log_user_printer(enum mtl_log_level level, const char* format, ...) { +static void log_user_printer(enum mtl_log_level level, const char *format, + ...) { MTL_MAY_UNUSED(level); va_list args; @@ -414,14 +439,16 @@ static void log_user_printer(enum mtl_log_level level, const char* format, ...) va_end(args); } -static int app_args_parse_port(struct st_app_context* ctx, struct mtl_init_params* p, - char* str, enum mtl_port port) { - st_json_context_t* json_ctx = ctx->json_ctx; +static int app_args_parse_port(struct st_app_context *ctx, + struct mtl_init_params *p, char *str, + enum mtl_port port) { + st_json_context_t *json_ctx = ctx->json_ctx; if (json_ctx) { int json_num_interfaces = json_ctx->num_interfaces; - st_json_interface_t* json_interfaces = &json_ctx->interfaces[port]; + st_json_interface_t *json_interfaces = &json_ctx->interfaces[port]; if (port < json_num_interfaces) { - info("%s, override json interface for port: %d to %s\n", __func__, port, str); + info("%s, override json interface for port: %d to %s\n", __func__, port, + str); snprintf(json_interfaces->name, sizeof(json_interfaces->name), "%s", str); snprintf(p->port[port], sizeof(p->port[port]), "%s", str); } @@ -433,477 +460,479 @@ static int app_args_parse_port(struct st_app_context* ctx, struct mtl_init_param return 0; } -int st_app_parse_args(struct st_app_context* ctx, struct mtl_init_params* p, int argc, - char** argv) { +int st_app_parse_args(struct st_app_context *ctx, struct mtl_init_params *p, + int argc, char **argv) { int cmd = -1, optIdx = 0; int nb; while (1) { cmd = getopt_long_only(argc, argv, "hv", st_app_args_options, &optIdx); - if (cmd == -1) break; + if (cmd == -1) + break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case ST_ARG_P_PORT: - app_args_parse_port(ctx, p, optarg, MTL_PORT_P); - break; - case ST_ARG_R_PORT: - app_args_parse_port(ctx, p, optarg, MTL_PORT_R); - break; - case ST_ARG_P_SIP: - inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); - break; - case ST_ARG_R_SIP: - inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); - break; - case ST_ARG_P_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); - break; - case ST_ARG_R_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); - break; - case ST_ARG_P_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); - break; - case ST_ARG_R_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); - break; - case ST_ARG_P_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); - break; - case ST_ARG_R_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); - break; - case ST_ARG_P_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); - break; - case ST_ARG_R_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); - break; - case ST_ARG_P_RX_MCAST_SIP: - inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_P]); - break; - case ST_ARG_R_RX_MCAST_SIP: - inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_R]); - break; - case ST_ARG_TX_VIDEO_URL: - snprintf(ctx->tx_video_url, sizeof(ctx->tx_video_url), "%s", optarg); - break; - case ST_ARG_TX_VIDEO_RTP_RING_SIZE: - ctx->tx_video_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_TX_VIDEO_SESSIONS_CNT: - ctx->tx_video_session_cnt = atoi(optarg); - break; - case ST_ARG_TX_AUDIO_URL: - snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); - break; - case ST_ARG_TX_AUDIO_SESSIONS_CNT: - ctx->tx_audio_session_cnt = atoi(optarg); - break; - case ST_ARG_TX_AUDIO_RTP_RING_SIZE: - ctx->tx_audio_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_TX_ANC_URL: - snprintf(ctx->tx_anc_url, sizeof(ctx->tx_anc_url), "%s", optarg); - break; - case ST_ARG_TX_ANC_RTP_RING_SIZE: - ctx->tx_anc_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_TX_ANC_SESSIONS_CNT: - ctx->tx_anc_session_cnt = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_SESSIONS_CNT: - ctx->rx_video_session_cnt = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_FILE_FRAMES: - ctx->rx_video_file_frames = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_FB_CNT: - ctx->rx_video_fb_cnt = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_RTP_RING_SIZE: - ctx->rx_video_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_MULTI_THREADS: - ctx->rx_video_multi_thread = true; - break; - case ST_ARG_RX_AUDIO_SESSIONS_CNT: - ctx->rx_audio_session_cnt = atoi(optarg); - break; - case ST_ARG_RX_AUDIO_RTP_RING_SIZE: - ctx->rx_audio_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_RX_AUDIO_DUMP_TIME_S: - ctx->rx_audio_dump_time_s = atoi(optarg); - break; - case ST_ARG_RX_ANC_SESSIONS_CNT: - ctx->rx_anc_session_cnt = atoi(optarg); - break; - case ST22_ARG_TX_SESSIONS_CNT: - ctx->tx_st22_session_cnt = atoi(optarg); - break; - case ST22_ARG_TX_URL: - snprintf(ctx->tx_st22_url, sizeof(ctx->tx_st22_url), "%s", optarg); - break; - case ST22_ARG_RX_SESSIONS_CNT: - ctx->rx_st22_session_cnt = atoi(optarg); - break; - case ST_ARG_HDR_SPLIT: - ctx->enable_hdr_split = true; - break; - case ST_ARG_PACING_WAY: - if (!strcmp(optarg, "auto")) - p->pacing = ST21_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - p->pacing = ST21_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsn")) - p->pacing = ST21_TX_PACING_WAY_TSN; - else if (!strcmp(optarg, "tsc")) - p->pacing = ST21_TX_PACING_WAY_TSC; - else if (!strcmp(optarg, "tsc_narrow")) - p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; - else if (!strcmp(optarg, "ptp")) - p->pacing = ST21_TX_PACING_WAY_PTP; - else if (!strcmp(optarg, "be")) - p->pacing = ST21_TX_PACING_WAY_BE; - else - err("%s, unknow pacing way %s\n", __func__, optarg); - break; - case ST_ARG_START_VRX: - ctx->tx_start_vrx = atoi(optarg); - break; - case ST_ARG_PAD_INTERVAL: - ctx->tx_pad_interval = atoi(optarg); - break; - case ST_ARG_NO_PAD_STATIC: - ctx->tx_no_static_pad = true; - break; - case ST_ARG_TIMESTAMP_FIRST_PKT: - ctx->tx_ts_first_pkt = true; - break; - case ST_ARG_TIMESTAMP_EPOCH: - ctx->tx_ts_epoch = true; - break; - case ST_ARG_TIMESTAMP_DELTA_US: - ctx->tx_ts_delta_us = atoi(optarg); - break; - case ST_ARG_NO_BULK: - ctx->tx_no_bulk = true; - break; - case ST_ARG_TX_DISPLAY: - ctx->tx_display = true; - break; - case ST_ARG_RX_DISPLAY: - ctx->rx_display = true; - break; - case ST_ARG_DISABLE_MIGRATE: - p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; - p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; - break; - case ST_ARG_BIND_NUMA: - p->flags |= MTL_FLAG_BIND_NUMA; - break; - case ST_ARG_NOT_BIND_NUMA: - p->flags |= MTL_FLAG_NOT_BIND_NUMA; - break; - case ST_ARG_FORCE_NUMA: - for (int port = 0; port < MTL_PORT_MAX; port++) { - p->port_params[port].flags |= MTL_PORT_FLAG_FORCE_NUMA; - p->port_params[port].socket_id = atoi(optarg); - } - break; - case ST_ARG_FORCE_TX_VIDEO_NUMA: - ctx->force_tx_video_numa = atoi(optarg); - break; - case ST_ARG_FORCE_RX_VIDEO_NUMA: - ctx->force_rx_video_numa = atoi(optarg); - break; - case ST_ARG_FORCE_TX_AUDIO_NUMA: - ctx->force_tx_audio_numa = atoi(optarg); - break; - case ST_ARG_FORCE_RX_AUDIO_NUMA: - ctx->force_rx_audio_numa = atoi(optarg); - break; - case ST_ARG_SHAPING: - if (!strcmp(optarg, "narrow")) - ctx->tx_pacing_type = ST21_PACING_NARROW; - else if (!strcmp(optarg, "wide")) - ctx->tx_pacing_type = ST21_PACING_WIDE; - else if (!strcmp(optarg, "linear")) - ctx->tx_pacing_type = ST21_PACING_LINEAR; - else - err("%s, unknow shaping way %s\n", __func__, optarg); - break; - case ST_ARG_CONFIG_FILE: - app_args_json(ctx, p, optarg); - break; - case ST_ARG_PTP_UNICAST_ADDR: - p->flags |= MTL_FLAG_PTP_UNICAST_ADDR; - break; - case ST_ARG_CNI_THREAD: - p->flags |= MTL_FLAG_CNI_THREAD; - break; - case ST_ARG_CNI_TASKLET: - p->flags |= MTL_FLAG_CNI_TASKLET; - break; - case ST_ARG_TEST_TIME: - ctx->test_time_s = atoi(optarg); - break; - case ST_ARG_RX_TIMING_PARSER_STAT: - ctx->enable_timing_parser = true; - p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; - break; - case ST_ARG_RX_TIMING_PARSER_META: - ctx->enable_timing_parser_meta = true; - p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; - break; - case ST_ARG_RX_BURST_SZ: - ctx->rx_burst_size = atoi(optarg); - break; - case ST_ARG_RX_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - break; - case ST_ARG_TX_MONO_POOL: - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case ST_ARG_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case ST_ARG_RX_POOL_DATA_SIZE: - p->rx_pool_data_size = atoi(optarg); - break; - case ST_ARG_RX_SEPARATE_VIDEO_LCORE: - p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; - break; - case ST_ARG_RX_MIX_VIDEO_LCORE: - p->flags &= ~MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; - break; - case ST_ARG_DEDICATE_SYS_LCORE: - p->flags |= MTL_FLAG_DEDICATED_SYS_LCORE; - break; - case ST_ARG_TSC_PACING: + case ST_ARG_P_PORT: + app_args_parse_port(ctx, p, optarg, MTL_PORT_P); + break; + case ST_ARG_R_PORT: + app_args_parse_port(ctx, p, optarg, MTL_PORT_R); + break; + case ST_ARG_P_SIP: + inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); + break; + case ST_ARG_R_SIP: + inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); + break; + case ST_ARG_P_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); + break; + case ST_ARG_R_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); + break; + case ST_ARG_P_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); + break; + case ST_ARG_R_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); + break; + case ST_ARG_P_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); + break; + case ST_ARG_R_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); + break; + case ST_ARG_P_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); + break; + case ST_ARG_R_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); + break; + case ST_ARG_P_RX_MCAST_SIP: + inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_P]); + break; + case ST_ARG_R_RX_MCAST_SIP: + inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_R]); + break; + case ST_ARG_TX_VIDEO_URL: + snprintf(ctx->tx_video_url, sizeof(ctx->tx_video_url), "%s", optarg); + break; + case ST_ARG_TX_VIDEO_RTP_RING_SIZE: + ctx->tx_video_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_TX_VIDEO_SESSIONS_CNT: + ctx->tx_video_session_cnt = atoi(optarg); + break; + case ST_ARG_TX_AUDIO_URL: + snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); + break; + case ST_ARG_TX_AUDIO_SESSIONS_CNT: + ctx->tx_audio_session_cnt = atoi(optarg); + break; + case ST_ARG_TX_AUDIO_RTP_RING_SIZE: + ctx->tx_audio_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_TX_ANC_URL: + snprintf(ctx->tx_anc_url, sizeof(ctx->tx_anc_url), "%s", optarg); + break; + case ST_ARG_TX_ANC_RTP_RING_SIZE: + ctx->tx_anc_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_TX_ANC_SESSIONS_CNT: + ctx->tx_anc_session_cnt = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_SESSIONS_CNT: + ctx->rx_video_session_cnt = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_FILE_FRAMES: + ctx->rx_video_file_frames = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_FB_CNT: + ctx->rx_video_fb_cnt = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_RTP_RING_SIZE: + ctx->rx_video_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_MULTI_THREADS: + ctx->rx_video_multi_thread = true; + break; + case ST_ARG_RX_AUDIO_SESSIONS_CNT: + ctx->rx_audio_session_cnt = atoi(optarg); + break; + case ST_ARG_RX_AUDIO_RTP_RING_SIZE: + ctx->rx_audio_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_RX_AUDIO_DUMP_TIME_S: + ctx->rx_audio_dump_time_s = atoi(optarg); + break; + case ST_ARG_RX_ANC_SESSIONS_CNT: + ctx->rx_anc_session_cnt = atoi(optarg); + break; + case ST22_ARG_TX_SESSIONS_CNT: + ctx->tx_st22_session_cnt = atoi(optarg); + break; + case ST22_ARG_TX_URL: + snprintf(ctx->tx_st22_url, sizeof(ctx->tx_st22_url), "%s", optarg); + break; + case ST22_ARG_RX_SESSIONS_CNT: + ctx->rx_st22_session_cnt = atoi(optarg); + break; + case ST_ARG_HDR_SPLIT: + ctx->enable_hdr_split = true; + break; + case ST_ARG_PACING_WAY: + if (!strcmp(optarg, "auto")) + p->pacing = ST21_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + p->pacing = ST21_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsn")) + p->pacing = ST21_TX_PACING_WAY_TSN; + else if (!strcmp(optarg, "tsc")) p->pacing = ST21_TX_PACING_WAY_TSC; - break; - case ST_ARG_USER_LCORES: - app_args_parse_lcores(p, optarg); - break; - case ST_ARG_SCH_DATA_QUOTA: - p->data_quota_mbs_per_sch = atoi(optarg); - break; - case ST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ - nb = atoi(optarg); - if (nb > 0 && nb < 100) { - p->data_quota_mbs_per_sch = nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); - } - break; - case ST_ARG_P_TX_DST_MAC: - app_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); - break; - case ST_ARG_R_TX_DST_MAC: - app_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); - break; - case ST_ARG_NIC_RX_PROMISCUOUS: - p->flags |= MTL_FLAG_NIC_RX_PROMISCUOUS; - break; - case ST_ARG_LIB_PTP: - p->flags |= MTL_FLAG_PTP_ENABLE; - p->ptp_get_time_fn = NULL; /* clear the user ptp func */ - break; - case ST_ARG_LIB_PTP_SYNC_SYS: - p->flags |= MTL_FLAG_PTP_ENABLE; /* enable built-in ptp */ - p->ptp_get_time_fn = NULL; /* clear the user ptp func */ - ctx->ptp_systime_sync = true; - break; - case ST_ARG_LIB_PHC2SYS: - p->flags |= MTL_FLAG_PHC2SYS_ENABLE; - break; - case ST_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - app_set_log_level(p->log_level); - break; - case ST_ARG_LOG_FILE: - st_set_mtl_log_file(ctx, optarg); - break; - case ST_ARG_LOG_TIME_MS: - mtl_set_log_prefix_formatter(log_prefix_time_ms); - break; - case ST_ARG_LOG_PRINTER: - mtl_set_log_printer(log_user_printer); - break; - case ST_ARG_NB_TX_DESC: - p->nb_tx_desc = atoi(optarg); - break; - case ST_ARG_NB_RX_DESC: - p->nb_rx_desc = atoi(optarg); - break; - case ST_ARG_DMA_DEV: - app_args_dma_dev(p, optarg); - break; - case ST_ARG_PCAPNG_DUMP: - ctx->pcapng_max_pkts = atoi(optarg); - break; - case ST_ARG_RUNTIME_SESSION: - ctx->runtime_session = true; - break; - case ST_ARG_TTF_FILE: - snprintf(ctx->ttf_file, sizeof(ctx->ttf_file), "%s", optarg); - break; - case ST_ARG_AF_XDP_ZC_DISABLE: - p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; - break; - case ST_ARG_TASKLET_TIME: - p->flags |= MTL_FLAG_TASKLET_TIME_MEASURE; - break; - case ST_ARG_UTC_OFFSET: - ctx->utc_offset = atoi(optarg); - break; - case ST_ARG_NO_SYSTEM_RX_QUEUES: - p->flags |= MTL_FLAG_DISABLE_SYSTEM_RX_QUEUES; - break; - case ST_ARG_TX_COPY_ONCE: - ctx->tx_copy_once = true; - break; - case ST_ARG_TASKLET_SLEEP: - p->flags |= MTL_FLAG_TASKLET_SLEEP; - break; - case ST_ARG_TASKLET_SLEEP_US: - ctx->var_para.sch_force_sleep_us = atoi(optarg); - break; - case ST_ARG_TASKLET_THREAD: - p->flags |= MTL_FLAG_TASKLET_THREAD; - break; - case ST_ARG_APP_BIND_THREAD: - ctx->app_bind_lcore = false; - break; - case ST_ARG_APP_BIND_LCORE: - ctx->app_bind_lcore = true; - break; - case ST_ARG_RXTX_SIMD_512: - p->flags |= MTL_FLAG_RXTX_SIMD_512; - break; - case ST_ARG_PTP_PI: - p->flags |= MTL_FLAG_PTP_PI; - break; - case ST_ARG_PTP_KP: - p->kp = strtod(optarg, NULL); - break; - case ST_ARG_PTP_KI: - p->ki = strtod(optarg, NULL); - break; - case ST_ARG_PTP_TSC: - p->flags |= MTL_FLAG_PTP_SOURCE_TSC; - break; - case ST_ARG_RANDOM_SRC_PORT: - p->flags |= MTL_FLAG_RANDOM_SRC_PORT; - break; - case ST_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case ST_ARG_TX_NO_CHAIN: - p->flags |= MTL_FLAG_TX_NO_CHAIN; - break; - case ST_ARG_TX_NO_BURST_CHECK: - p->flags |= MTL_FLAG_TX_NO_BURST_CHK; - break; - case ST_ARG_MULTI_SRC_PORT: - p->flags |= MTL_FLAG_MULTI_SRC_PORT; - break; - case ST_ARG_AUDIO_BUILD_PACING: - ctx->tx_audio_build_pacing = true; - break; - case ST_ARG_AUDIO_DEDICATE_QUEUE: - ctx->tx_audio_dedicate_queue = true; - break; - case ST_ARG_AUDIO_TX_PACING: - if (!strcmp(optarg, "auto")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsc")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; - else - err("%s, unknow audio tx pacing %s\n", __func__, optarg); - break; - case ST_ARG_AUDIO_RL_ACCURACY_US: - ctx->tx_audio_rl_accuracy_us = atoi(optarg); - break; - case ST_ARG_AUDIO_RL_OFFSET_US: - ctx->tx_audio_rl_offset_us = atoi(optarg); - break; - case ST_ARG_AUDIO_FIFO_SIZE: - ctx->tx_audio_fifo_size = atoi(optarg); - break; - case ST_ARG_ANC_DEDICATE_QUEUE: - ctx->tx_anc_dedicate_queue = true; - break; - case ST_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; ++port) - p->net_proto[port] = MTL_PROTO_DHCP; - break; - case ST_ARG_IOVA_MODE: - if (!strcmp(optarg, "va")) - p->iova_mode = MTL_IOVA_MODE_VA; - else if (!strcmp(optarg, "pa")) - p->iova_mode = MTL_IOVA_MODE_PA; - else - err("%s, unknow iova mode %s\n", __func__, optarg); - break; - case ST_ARG_SHARED_TX_QUEUES: - p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - break; - case ST_ARG_SHARED_RX_QUEUES: - p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - break; - case ST_ARG_RX_USE_CNI: - p->flags |= MTL_FLAG_RX_USE_CNI; - break; - case ST_ARG_RX_UDP_PORT_ONLY: - p->flags |= MTL_FLAG_RX_UDP_PORT_ONLY; - break; - case ST_ARG_VIRTIO_USER: - p->flags |= MTL_FLAG_VIRTIO_USER; - break; - case ST_ARG_VIDEO_SHA_CHECK: - ctx->video_sha_check = true; - break; - case ST_ARG_ARP_TIMEOUT_S: - p->arp_timeout_s = atoi(optarg); - break; - case ST_ARG_RSS_SCH_NB: - for (enum mtl_port port = MTL_PORT_P; port < MTL_PORT_MAX; port++) { - p->rss_sch_nb[port] = atoi(optarg); - } - break; - case ST_ARG_ALLOW_ACROSS_NUMA_CORE: - p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; - break; - case ST_ARG_NO_MULTICAST: - p->flags |= MTL_FLAG_NO_MULTICAST; - break; - case '?': - break; - default: - break; + else if (!strcmp(optarg, "tsc_narrow")) + p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; + else if (!strcmp(optarg, "ptp")) + p->pacing = ST21_TX_PACING_WAY_PTP; + else if (!strcmp(optarg, "be")) + p->pacing = ST21_TX_PACING_WAY_BE; + else + err("%s, unknow pacing way %s\n", __func__, optarg); + break; + case ST_ARG_START_VRX: + ctx->tx_start_vrx = atoi(optarg); + break; + case ST_ARG_PAD_INTERVAL: + ctx->tx_pad_interval = atoi(optarg); + break; + case ST_ARG_NO_PAD_STATIC: + ctx->tx_no_static_pad = true; + break; + case ST_ARG_TIMESTAMP_FIRST_PKT: + ctx->tx_ts_first_pkt = true; + break; + case ST_ARG_TIMESTAMP_EPOCH: + ctx->tx_ts_epoch = true; + break; + case ST_ARG_TIMESTAMP_DELTA_US: + ctx->tx_ts_delta_us = atoi(optarg); + break; + case ST_ARG_NO_BULK: + ctx->tx_no_bulk = true; + break; + case ST_ARG_TX_DISPLAY: + ctx->tx_display = true; + break; + case ST_ARG_RX_DISPLAY: + ctx->rx_display = true; + break; + case ST_ARG_DISABLE_MIGRATE: + p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; + p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; + break; + case ST_ARG_BIND_NUMA: + p->flags |= MTL_FLAG_BIND_NUMA; + break; + case ST_ARG_NOT_BIND_NUMA: + p->flags |= MTL_FLAG_NOT_BIND_NUMA; + break; + case ST_ARG_FORCE_NUMA: + for (int port = 0; port < MTL_PORT_MAX; port++) { + p->port_params[port].flags |= MTL_PORT_FLAG_FORCE_NUMA; + p->port_params[port].socket_id = atoi(optarg); + } + break; + case ST_ARG_FORCE_TX_VIDEO_NUMA: + ctx->force_tx_video_numa = atoi(optarg); + break; + case ST_ARG_FORCE_RX_VIDEO_NUMA: + ctx->force_rx_video_numa = atoi(optarg); + break; + case ST_ARG_FORCE_TX_AUDIO_NUMA: + ctx->force_tx_audio_numa = atoi(optarg); + break; + case ST_ARG_FORCE_RX_AUDIO_NUMA: + ctx->force_rx_audio_numa = atoi(optarg); + break; + case ST_ARG_SHAPING: + if (!strcmp(optarg, "narrow")) + ctx->tx_pacing_type = ST21_PACING_NARROW; + else if (!strcmp(optarg, "wide")) + ctx->tx_pacing_type = ST21_PACING_WIDE; + else if (!strcmp(optarg, "linear")) + ctx->tx_pacing_type = ST21_PACING_LINEAR; + else + err("%s, unknow shaping way %s\n", __func__, optarg); + break; + case ST_ARG_CONFIG_FILE: + app_args_json(ctx, p, optarg); + break; + case ST_ARG_PTP_UNICAST_ADDR: + p->flags |= MTL_FLAG_PTP_UNICAST_ADDR; + break; + case ST_ARG_CNI_THREAD: + p->flags |= MTL_FLAG_CNI_THREAD; + break; + case ST_ARG_CNI_TASKLET: + p->flags |= MTL_FLAG_CNI_TASKLET; + break; + case ST_ARG_TEST_TIME: + ctx->test_time_s = atoi(optarg); + break; + case ST_ARG_RX_TIMING_PARSER_STAT: + ctx->enable_timing_parser = true; + p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; + break; + case ST_ARG_RX_TIMING_PARSER_META: + ctx->enable_timing_parser_meta = true; + p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; + break; + case ST_ARG_RX_BURST_SZ: + ctx->rx_burst_size = atoi(optarg); + break; + case ST_ARG_RX_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + break; + case ST_ARG_TX_MONO_POOL: + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case ST_ARG_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case ST_ARG_RX_POOL_DATA_SIZE: + p->rx_pool_data_size = atoi(optarg); + break; + case ST_ARG_RX_SEPARATE_VIDEO_LCORE: + p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; + break; + case ST_ARG_RX_MIX_VIDEO_LCORE: + p->flags &= ~MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; + break; + case ST_ARG_DEDICATE_SYS_LCORE: + p->flags |= MTL_FLAG_DEDICATED_SYS_LCORE; + break; + case ST_ARG_TSC_PACING: + p->pacing = ST21_TX_PACING_WAY_TSC; + break; + case ST_ARG_USER_LCORES: + app_args_parse_lcores(p, optarg); + break; + case ST_ARG_SCH_DATA_QUOTA: + p->data_quota_mbs_per_sch = atoi(optarg); + break; + case ST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ + nb = atoi(optarg); + if (nb > 0 && nb < 100) { + p->data_quota_mbs_per_sch = + nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); + } + break; + case ST_ARG_P_TX_DST_MAC: + app_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); + break; + case ST_ARG_R_TX_DST_MAC: + app_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); + break; + case ST_ARG_NIC_RX_PROMISCUOUS: + p->flags |= MTL_FLAG_NIC_RX_PROMISCUOUS; + break; + case ST_ARG_LIB_PTP: + p->flags |= MTL_FLAG_PTP_ENABLE; + p->ptp_get_time_fn = NULL; /* clear the user ptp func */ + break; + case ST_ARG_LIB_PTP_SYNC_SYS: + p->flags |= MTL_FLAG_PTP_ENABLE; /* enable built-in ptp */ + p->ptp_get_time_fn = NULL; /* clear the user ptp func */ + ctx->ptp_systime_sync = true; + break; + case ST_ARG_LIB_PHC2SYS: + p->flags |= MTL_FLAG_PHC2SYS_ENABLE; + break; + case ST_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + app_set_log_level(p->log_level); + break; + case ST_ARG_LOG_FILE: + st_set_mtl_log_file(ctx, optarg); + break; + case ST_ARG_LOG_TIME_MS: + mtl_set_log_prefix_formatter(log_prefix_time_ms); + break; + case ST_ARG_LOG_PRINTER: + mtl_set_log_printer(log_user_printer); + break; + case ST_ARG_NB_TX_DESC: + p->nb_tx_desc = atoi(optarg); + break; + case ST_ARG_NB_RX_DESC: + p->nb_rx_desc = atoi(optarg); + break; + case ST_ARG_DMA_DEV: + app_args_dma_dev(p, optarg); + break; + case ST_ARG_PCAPNG_DUMP: + ctx->pcapng_max_pkts = atoi(optarg); + break; + case ST_ARG_RUNTIME_SESSION: + ctx->runtime_session = true; + break; + case ST_ARG_TTF_FILE: + snprintf(ctx->ttf_file, sizeof(ctx->ttf_file), "%s", optarg); + break; + case ST_ARG_AF_XDP_ZC_DISABLE: + p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; + break; + case ST_ARG_TASKLET_TIME: + p->flags |= MTL_FLAG_TASKLET_TIME_MEASURE; + break; + case ST_ARG_UTC_OFFSET: + ctx->utc_offset = atoi(optarg); + break; + case ST_ARG_NO_SYSTEM_RX_QUEUES: + p->flags |= MTL_FLAG_DISABLE_SYSTEM_RX_QUEUES; + break; + case ST_ARG_TX_COPY_ONCE: + ctx->tx_copy_once = true; + break; + case ST_ARG_TASKLET_SLEEP: + p->flags |= MTL_FLAG_TASKLET_SLEEP; + break; + case ST_ARG_TASKLET_SLEEP_US: + ctx->var_para.sch_force_sleep_us = atoi(optarg); + break; + case ST_ARG_TASKLET_THREAD: + p->flags |= MTL_FLAG_TASKLET_THREAD; + break; + case ST_ARG_APP_BIND_THREAD: + ctx->app_bind_lcore = false; + break; + case ST_ARG_APP_BIND_LCORE: + ctx->app_bind_lcore = true; + break; + case ST_ARG_RXTX_SIMD_512: + p->flags |= MTL_FLAG_RXTX_SIMD_512; + break; + case ST_ARG_PTP_PI: + p->flags |= MTL_FLAG_PTP_PI; + break; + case ST_ARG_PTP_KP: + p->kp = strtod(optarg, NULL); + break; + case ST_ARG_PTP_KI: + p->ki = strtod(optarg, NULL); + break; + case ST_ARG_PTP_TSC: + p->flags |= MTL_FLAG_PTP_SOURCE_TSC; + break; + case ST_ARG_RANDOM_SRC_PORT: + p->flags |= MTL_FLAG_RANDOM_SRC_PORT; + break; + case ST_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case ST_ARG_TX_NO_CHAIN: + p->flags |= MTL_FLAG_TX_NO_CHAIN; + break; + case ST_ARG_TX_NO_BURST_CHECK: + p->flags |= MTL_FLAG_TX_NO_BURST_CHK; + break; + case ST_ARG_MULTI_SRC_PORT: + p->flags |= MTL_FLAG_MULTI_SRC_PORT; + break; + case ST_ARG_AUDIO_BUILD_PACING: + ctx->tx_audio_build_pacing = true; + break; + case ST_ARG_AUDIO_DEDICATE_QUEUE: + ctx->tx_audio_dedicate_queue = true; + break; + case ST_ARG_AUDIO_TX_PACING: + if (!strcmp(optarg, "auto")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsc")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; + else + err("%s, unknow audio tx pacing %s\n", __func__, optarg); + break; + case ST_ARG_AUDIO_RL_ACCURACY_US: + ctx->tx_audio_rl_accuracy_us = atoi(optarg); + break; + case ST_ARG_AUDIO_RL_OFFSET_US: + ctx->tx_audio_rl_offset_us = atoi(optarg); + break; + case ST_ARG_AUDIO_FIFO_SIZE: + ctx->tx_audio_fifo_size = atoi(optarg); + break; + case ST_ARG_ANC_DEDICATE_QUEUE: + ctx->tx_anc_dedicate_queue = true; + break; + case ST_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; ++port) + p->net_proto[port] = MTL_PROTO_DHCP; + break; + case ST_ARG_IOVA_MODE: + if (!strcmp(optarg, "va")) + p->iova_mode = MTL_IOVA_MODE_VA; + else if (!strcmp(optarg, "pa")) + p->iova_mode = MTL_IOVA_MODE_PA; + else + err("%s, unknow iova mode %s\n", __func__, optarg); + break; + case ST_ARG_SHARED_TX_QUEUES: + p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + break; + case ST_ARG_SHARED_RX_QUEUES: + p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + break; + case ST_ARG_RX_USE_CNI: + p->flags |= MTL_FLAG_RX_USE_CNI; + break; + case ST_ARG_RX_UDP_PORT_ONLY: + p->flags |= MTL_FLAG_RX_UDP_PORT_ONLY; + break; + case ST_ARG_VIRTIO_USER: + p->flags |= MTL_FLAG_VIRTIO_USER; + break; + case ST_ARG_VIDEO_SHA_CHECK: + ctx->video_sha_check = true; + break; + case ST_ARG_ARP_TIMEOUT_S: + p->arp_timeout_s = atoi(optarg); + break; + case ST_ARG_RSS_SCH_NB: + for (enum mtl_port port = MTL_PORT_P; port < MTL_PORT_MAX; port++) { + p->rss_sch_nb[port] = atoi(optarg); + } + break; + case ST_ARG_ALLOW_ACROSS_NUMA_CORE: + p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; + break; + case ST_ARG_NO_MULTICAST: + p->flags |= MTL_FLAG_NO_MULTICAST; + break; + case '?': + break; + default: + break; } }; diff --git a/app/src/args.h b/app/src/args.h index ec1ac12b3..ba2ddf9f8 100644 --- a/app/src/args.h +++ b/app/src/args.h @@ -7,7 +7,7 @@ #ifndef _ST_APP_ARGS_HEAD_H_ #define _ST_APP_ARGS_HEAD_H_ -int st_app_parse_args(struct st_app_context* ctx, struct mtl_init_params* p, int argc, - char** argv); +int st_app_parse_args(struct st_app_context *ctx, struct mtl_init_params *p, + int argc, char **argv); #endif diff --git a/app/src/experimental/rx_st20r_app.c b/app/src/experimental/rx_st20r_app.c index 79a28cc8a..fb0245709 100644 --- a/app/src/experimental/rx_st20r_app.c +++ b/app/src/experimental/rx_st20r_app.c @@ -4,10 +4,10 @@ #include "rx_st20r_app.h" -static int app_rx_st20r_enqueue_frame(struct st_app_rx_video_session* s, void* frame, - size_t size) { +static int app_rx_st20r_enqueue_frame(struct st_app_rx_video_session *s, + void *frame, size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -18,21 +18,23 @@ static int app_rx_st20r_enqueue_frame(struct st_app_rx_video_session* s, void* f framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static void app_rx_st20r_consume_frame(struct st_app_rx_video_session* s, void* frame, - size_t frame_size) { - struct st_display* d = s->display; +static void app_rx_st20r_consume_frame(struct st_app_rx_video_session *s, + void *frame, size_t frame_size) { + struct st_display *d = s->display; if (d && d->front_frame) { if (st_pthread_mutex_trylock(&d->display_frame_mutex) == 0) { if (s->st20_pg.fmt == ST20_FMT_YUV_422_8BIT) mtl_memcpy(d->front_frame, frame, d->front_frame_size); else if (s->st20_pg.fmt == ST20_FMT_YUV_422_10BIT) - st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, s->height); + st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, + s->height); else /* fmt mismatch*/ { st_pthread_mutex_unlock(&d->display_frame_mutex); return; @@ -45,18 +47,18 @@ static void app_rx_st20r_consume_frame(struct st_app_rx_video_session* s, void* } else { if (s->st20_dst_cursor + frame_size > s->st20_dst_end) s->st20_dst_cursor = s->st20_dst_begin; - dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, s->st20_dst_cursor, - frame, frame_size); + dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, + s->st20_dst_cursor, frame, frame_size); mtl_memcpy(s->st20_dst_cursor, frame, frame_size); s->st20_dst_cursor += frame_size; } } -static void* app_rx_st20r_frame_thread(void* arg) { - struct st_app_rx_video_session* s = arg; +static void *app_rx_st20r_frame_thread(void *arg) { + struct st_app_rx_video_session *s = arg; int idx = s->idx; int consumer_idx; - struct st_rx_frame* framebuff; + struct st_rx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->st20_app_thread_stop) { @@ -79,7 +81,8 @@ static void* app_rx_st20r_frame_thread(void* arg) { st_pthread_mutex_lock(&s->st20_wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->st20_wake_mutex); } @@ -88,7 +91,7 @@ static void* app_rx_st20r_frame_thread(void* arg) { return NULL; } -static int app_rx_st20r_close_source(struct st_app_rx_video_session* s) { +static int app_rx_st20r_close_source(struct st_app_rx_video_session *s) { if (s->st20_dst_fd >= 0) { munmap(s->st20_dst_begin, s->st20_dst_end - s->st20_dst_begin); close(s->st20_dst_fd); @@ -98,12 +101,13 @@ static int app_rx_st20r_close_source(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_st20r_open_source(struct st_app_rx_video_session* s) { +static int app_rx_st20r_open_source(struct st_app_rx_video_session *s) { int fd, ret, idx = s->idx; off_t f_size; /* user do not require fb save to file */ - if (s->st20_dst_fb_cnt < 1) return 0; + if (s->st20_dst_fb_cnt < 1) + return 0; fd = st_open_mode(s->st20_dst_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -119,7 +123,7 @@ static int app_rx_st20r_open_source(struct st_app_rx_video_session* s) { return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, s->st20_dst_url); close(fd); @@ -130,17 +134,18 @@ static int app_rx_st20r_open_source(struct st_app_rx_video_session* s) { s->st20_dst_cursor = m; s->st20_dst_end = m + f_size; s->st20_dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, - s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); return 0; } -static int app_rx_st20r_init_frame_thread(struct st_app_rx_video_session* s) { +static int app_rx_st20r_init_frame_thread(struct st_app_rx_video_session *s) { int ret, idx = s->idx; /* user do not require fb save to file or display */ - if (s->st20_dst_fb_cnt < 1 && s->display == NULL) return 0; + if (s->st20_dst_fb_cnt < 1 && s->display == NULL) + return 0; ret = pthread_create(&s->st20_app_thread, NULL, app_rx_st20r_frame_thread, s); if (ret < 0) { @@ -155,12 +160,13 @@ static int app_rx_st20r_init_frame_thread(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_st20r_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - struct st_app_rx_video_session* s = priv; +static int app_rx_st20r_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct st_app_rx_video_session *s = priv; int ret; - if (!s->st20r_handle) return -EIO; + if (!s->st20r_handle) + return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -208,7 +214,7 @@ static int app_rx_st20r_frame_ready(void* priv, void* frame, return 0; } -static int app_rx_st20r_uinit(struct st_app_rx_video_session* s) { +static int app_rx_st20r_uinit(struct st_app_rx_video_session *s) { int ret, idx = s->idx; st_app_uinit_display(s->display); @@ -231,7 +237,8 @@ static int app_rx_st20r_uinit(struct st_app_rx_video_session* s) { if (s->st20r_handle) { ret = st20rc_rx_free(s->st20r_handle); - if (ret < 0) err("%s(%d), st20rc_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st20rc_rx_free fail %d\n", __func__, idx, ret); s->st20r_handle = NULL; } app_rx_st20r_close_source(s); @@ -243,8 +250,9 @@ static int app_rx_st20r_uinit(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_st20r_init(struct st_app_context* ctx, st_json_video_session_t* video, - struct st_app_rx_video_session* s) { +static int app_rx_st20r_init(struct st_app_context *ctx, + st_json_video_session_t *video, + struct st_app_rx_video_session *s) { int idx = s->idx, ret; struct st20rc_rx_ops ops; char name[32]; @@ -259,54 +267,61 @@ static int app_rx_st20r_init(struct st_app_context* ctx, st_json_video_session_t video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy( - ops.mcast_sip_addr[MTL_SESSION_PORT_P], - video ? video->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], + video ? video->base.mcast_src_ip[MTL_PORT_P] + : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = video ? video->base.udp_port : (10000 + s->idx); + video ? video->base.inf[MTL_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = + video ? video->base.udp_port : (10000 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy( - ops.mcast_sip_addr[MTL_SESSION_PORT_R], - video ? video->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = video ? video->base.udp_port : (10000 + s->idx); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], + video ? video->base.mcast_src_ip[MTL_PORT_R] + : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = + video ? video->base.udp_port : (10000 + s->idx); } ops.pacing = ST21_PACING_NARROW; ops.flags = ST20RC_RX_FLAG_DMA_OFFLOAD; ops.width = video ? st_app_get_width(video->info.video_format) : 1920; ops.height = video ? st_app_get_height(video->info.video_format) : 1080; ops.fps = video ? st_app_get_fps(video->info.video_format) : ST_FPS_P59_94; - ops.interlaced = video ? st_app_get_interlaced(video->info.video_format) : false; + ops.interlaced = + video ? st_app_get_interlaced(video->info.video_format) : false; ops.fmt = video ? video->info.pg_format : ST20_FMT_YUV_422_10BIT; - ops.payload_type = video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.payload_type = + video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.notify_frame_ready = app_rx_st20r_frame_ready; ops.framebuff_cnt = s->framebuff_cnt; - if (ctx->enable_hdr_split) ops.flags |= ST20RC_RX_FLAG_HDR_SPLIT; + if (ctx->enable_hdr_split) + ops.flags |= ST20RC_RX_FLAG_HDR_SPLIT; st_pthread_mutex_init(&s->st20_wake_mutex, NULL); st_pthread_cond_init(&s->st20_wake_cond, NULL); if (mtl_pmd_by_port_name(ops.port[MTL_SESSION_PORT_P]) != MTL_PMD_DPDK_USER) { - snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d.yuv", idx, ops.width, - ops.height); + snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d.yuv", idx, + ops.width, ops.height); } else { uint32_t soc = 0, b = 0, d = 0, f = 0; sscanf(ops.port[MTL_SESSION_PORT_P], "%x:%x:%x.%x", &soc, &b, &d, &f); snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, - "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, ops.height, soc, b, - d, f); + "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, + ops.height, soc, b, d, f); } ret = st20_get_pgroup(ops.fmt, &s->st20_pg); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->width = ops.width; s->height = ops.height; @@ -318,15 +333,16 @@ static int app_rx_st20r_init(struct st_app_context* ctx, st_json_video_session_t s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = - (struct st_rx_frame*)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); - if (!s->framebuffs) return -ENOMEM; + s->framebuffs = (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * + s->framebuff_cnt); + if (!s->framebuffs) + return -ENOMEM; for (int j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].frame = NULL; } if ((video && video->display) || ctx->rx_display) { - struct st_display* d = st_app_zmalloc(sizeof(struct st_display)); + struct st_display *d = st_app_zmalloc(sizeof(struct st_display)); ret = st_app_init_display(d, name, s->width, s->height, ctx->ttf_file); if (ret < 0) { err("%s(%d), st_app_init_display fail %d\n", __func__, idx, ret); @@ -368,7 +384,7 @@ static int app_rx_st20r_init(struct st_app_context* ctx, st_json_video_session_t return 0; } -static int app_rx_st20r_stat(struct st_app_rx_video_session* s) { +static int app_rx_st20r_stat(struct st_app_rx_video_session *s) { uint64_t cur_time_ns = st_app_get_monotonic_time(); double time_sec = (double)(cur_time_ns - s->stat_last_time) / NS_PER_S; double framerate = s->stat_frame_received / time_sec; @@ -376,7 +392,8 @@ static int app_rx_st20r_stat(struct st_app_rx_video_session* s) { info("%s(%d), fps %f, %d frame received\n", __func__, s->idx, framerate, s->stat_frame_received); if (s->measure_latency && s->stat_frame_received) { - double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = + (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -386,36 +403,41 @@ static int app_rx_st20r_stat(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_st20r_result(struct st_app_rx_video_session* s) { +static int app_rx_st20r_result(struct st_app_rx_video_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) return -EINVAL; + if (!s->stat_frame_total_received) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) + ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } -static int app_rx_st20r_pcap(struct st_app_rx_video_session* s) { +static int app_rx_st20r_pcap(struct st_app_rx_video_session *s) { if (s->pcapng_max_pkts) st20rc_rx_pcapng_dump(s->st20r_handle, s->pcapng_max_pkts, false, NULL); return 0; } -int st_app_rx_st20r_sessions_init(struct st_app_context* ctx) { +int st_app_rx_st20r_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_rx_video_session* s; + struct st_app_rx_video_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) fb_cnt = 3; + if (fb_cnt <= 0) + fb_cnt = 3; - ctx->rx_st20r_sessions = (struct st_app_rx_video_session*)st_app_zmalloc( + ctx->rx_st20r_sessions = (struct st_app_rx_video_session *)st_app_zmalloc( sizeof(*ctx->rx_st20r_sessions) * ctx->rx_st20r_session_cnt); - if (!ctx->rx_st20r_sessions) return -ENOMEM; + if (!ctx->rx_st20r_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; s->idx = i; @@ -435,10 +457,11 @@ int st_app_rx_st20r_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_rx_st20r_sessions_uinit(struct st_app_context* ctx) { +int st_app_rx_st20r_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_rx_video_session* s; - if (!ctx->rx_st20r_sessions) return 0; + struct st_app_rx_video_session *s; + if (!ctx->rx_st20r_sessions) + return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; app_rx_st20r_uinit(s); @@ -448,10 +471,11 @@ int st_app_rx_st20r_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_rx_st20r_sessions_stat(struct st_app_context* ctx) { +int st_app_rx_st20r_sessions_stat(struct st_app_context *ctx) { int i; - struct st_app_rx_video_session* s; - if (!ctx->rx_st20r_sessions) return 0; + struct st_app_rx_video_session *s; + if (!ctx->rx_st20r_sessions) + return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; @@ -461,11 +485,12 @@ int st_app_rx_st20r_sessions_stat(struct st_app_context* ctx) { return 0; } -int st_app_rx_st20r_sessions_result(struct st_app_context* ctx) { +int st_app_rx_st20r_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_video_session* s; + struct st_app_rx_video_session *s; - if (!ctx->rx_st20r_sessions) return 0; + if (!ctx->rx_st20r_sessions) + return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; @@ -475,11 +500,12 @@ int st_app_rx_st20r_sessions_result(struct st_app_context* ctx) { return ret; } -int st_app_rx_st20r_sessions_pcap(struct st_app_context* ctx) { +int st_app_rx_st20r_sessions_pcap(struct st_app_context *ctx) { int i; - struct st_app_rx_video_session* s; + struct st_app_rx_video_session *s; - if (!ctx->rx_st20r_sessions) return 0; + if (!ctx->rx_st20r_sessions) + return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; diff --git a/app/src/experimental/rx_st20r_app.h b/app/src/experimental/rx_st20r_app.h index a1814d309..9b1204cd8 100644 --- a/app/src/experimental/rx_st20r_app.h +++ b/app/src/experimental/rx_st20r_app.h @@ -15,14 +15,14 @@ #ifndef _RX_APP_ST20R_HEAD_H_ #define _RX_APP_ST20R_HEAD_H_ -int st_app_rx_st20r_sessions_init(struct st_app_context* ctx); +int st_app_rx_st20r_sessions_init(struct st_app_context *ctx); -int st_app_rx_st20r_sessions_uinit(struct st_app_context* ctx); +int st_app_rx_st20r_sessions_uinit(struct st_app_context *ctx); -int st_app_rx_st20r_sessions_stat(struct st_app_context* ctx); +int st_app_rx_st20r_sessions_stat(struct st_app_context *ctx); -int st_app_rx_st20r_sessions_result(struct st_app_context* ctx); +int st_app_rx_st20r_sessions_result(struct st_app_context *ctx); -int st_app_rx_st20r_sessions_pcap(struct st_app_context* ctx); +int st_app_rx_st20r_sessions_pcap(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/fmt.c b/app/src/fmt.c index 2fbc68381..0edeae16a 100644 --- a/app/src/fmt.c +++ b/app/src/fmt.c @@ -6,7 +6,7 @@ #include "log.h" -int user_get_pgroup(enum user_pg_fmt fmt, struct user_pgroup* pg) { +int user_get_pgroup(enum user_pg_fmt fmt, struct user_pgroup *pg) { int i; for (i = 0; i < ARRAY_SIZE(user_pgroups); i++) { @@ -20,9 +20,12 @@ int user_get_pgroup(enum user_pg_fmt fmt, struct user_pgroup* pg) { return -1; } -void convert_uyvy10b_to_uyvy8b(uint8_t* yuv_8b, uint8_t const* yuv_10b, int pg_count) { - struct st20_rfc4175_422_8_pg2_le* pg_8 = (struct st20_rfc4175_422_8_pg2_le*)yuv_8b; - struct st20_rfc4175_422_10_pg2_be* pg_10 = (struct st20_rfc4175_422_10_pg2_be*)yuv_10b; +void convert_uyvy10b_to_uyvy8b(uint8_t *yuv_8b, uint8_t const *yuv_10b, + int pg_count) { + struct st20_rfc4175_422_8_pg2_le *pg_8 = + (struct st20_rfc4175_422_8_pg2_le *)yuv_8b; + struct st20_rfc4175_422_10_pg2_be *pg_10 = + (struct st20_rfc4175_422_10_pg2_be *)yuv_10b; st20_rfc4175_422be10_to_422le8(pg_10, pg_8, pg_count, 2); } diff --git a/app/src/fmt.h b/app/src/fmt.h index 057dafb87..4525e8d39 100644 --- a/app/src/fmt.h +++ b/app/src/fmt.h @@ -39,8 +39,9 @@ static const struct user_pgroup user_pgroups[] = { }, }; -int user_get_pgroup(enum user_pg_fmt fmt, struct user_pgroup* pg); +int user_get_pgroup(enum user_pg_fmt fmt, struct user_pgroup *pg); -void convert_uyvy10b_to_uyvy8b(uint8_t* yuv_8b, uint8_t const* yuv_10b, int pg_count); +void convert_uyvy10b_to_uyvy8b(uint8_t *yuv_8b, uint8_t const *yuv_10b, + int pg_count); #endif \ No newline at end of file diff --git a/app/src/legacy/rx_audio_app.c b/app/src/legacy/rx_audio_app.c index a11b36c81..7f06f801a 100644 --- a/app/src/legacy/rx_audio_app.c +++ b/app/src/legacy/rx_audio_app.c @@ -4,7 +4,7 @@ #include "rx_audio_app.h" -static int app_rx_audio_close_dump(struct st_app_rx_audio_session* s) { +static int app_rx_audio_close_dump(struct st_app_rx_audio_session *s) { if (s->st30_dump_fd >= 0) { munmap(s->st30_dump_begin, s->st30_dump_end - s->st30_dump_begin); close(s->st30_dump_fd); @@ -14,12 +14,13 @@ static int app_rx_audio_close_dump(struct st_app_rx_audio_session* s) { return 0; } -static int app_rx_audio_open_dump(struct st_app_rx_audio_session* s) { +static int app_rx_audio_open_dump(struct st_app_rx_audio_session *s) { int fd, ret, idx = s->idx; off_t f_size; /* user do not require dump to file */ - if (s->st30_dump_time_s < 1) return 0; + if (s->st30_dump_time_s < 1) + return 0; fd = st_open_mode(s->st30_dump_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -35,7 +36,7 @@ static int app_rx_audio_open_dump(struct st_app_rx_audio_session* s) { return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, s->st30_dump_url); close(fd); @@ -52,9 +53,10 @@ static int app_rx_audio_open_dump(struct st_app_rx_audio_session* s) { return 0; } -static int app_rx_audio_close_source(struct st_app_rx_audio_session* session) { +static int app_rx_audio_close_source(struct st_app_rx_audio_session *session) { if (session->st30_ref_fd >= 0) { - munmap(session->st30_ref_begin, session->st30_ref_end - session->st30_ref_begin); + munmap(session->st30_ref_begin, + session->st30_ref_end - session->st30_ref_begin); close(session->st30_ref_fd); session->st30_ref_fd = -1; } @@ -62,7 +64,7 @@ static int app_rx_audio_close_source(struct st_app_rx_audio_session* session) { return 0; } -static int app_rx_audio_open_ref(struct st_app_rx_audio_session* session) { +static int app_rx_audio_open_ref(struct st_app_rx_audio_session *session) { int fd, idx = session->idx; struct stat i; @@ -77,7 +79,7 @@ static int app_rx_audio_open_ref(struct st_app_rx_audio_session* session) { close(fd); return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, session->st30_ref_url); close(fd); @@ -93,19 +95,21 @@ static int app_rx_audio_open_ref(struct st_app_rx_audio_session* session) { return 0; } -static int app_rx_audio_compare_with_ref(struct st_app_rx_audio_session* session, - void* frame) { +static int +app_rx_audio_compare_with_ref(struct st_app_rx_audio_session *session, + void *frame) { int ret = -1; bool rewind = false; int count = 0; - uint8_t* old_ref = session->st30_ref_cursor; + uint8_t *old_ref = session->st30_ref_cursor; while (ret) { ret = memcmp(frame, session->st30_ref_cursor, session->st30_frame_size); /* calculate new reference frame */ session->st30_ref_cursor += session->st30_frame_size; if ((session->st30_ref_cursor >= session->st30_ref_end) || - ((session->st30_ref_end - session->st30_ref_cursor) < session->st30_frame_size)) { + ((session->st30_ref_end - session->st30_ref_cursor) < + session->st30_frame_size)) { session->st30_ref_cursor = session->st30_ref_begin; } @@ -118,8 +122,8 @@ static int app_rx_audio_compare_with_ref(struct st_app_rx_audio_session* session } if (session->st30_ref_cursor == old_ref) { if (ret) { - info("%s(%d), bad audio, stop referencing for current frame\n", __func__, - session->idx); + info("%s(%d), bad audio, stop referencing for current frame\n", + __func__, session->idx); session->st30_ref_err++; if (session->st30_ref_err > 100) { err("%s(%d), too many bad audio err, stop referencing\n", __func__, @@ -139,26 +143,27 @@ static int app_rx_audio_compare_with_ref(struct st_app_rx_audio_session* session return 0; } -static int app_rx_audio_handle_rtp(struct st_app_rx_audio_session* s, - struct st_rfc3550_rtp_hdr* hdr) { +static int app_rx_audio_handle_rtp(struct st_app_rx_audio_session *s, + struct st_rfc3550_rtp_hdr *hdr) { /* only compare each packet with reference now */ - uint8_t* payload = (uint8_t*)hdr + sizeof(*hdr); + uint8_t *payload = (uint8_t *)hdr + sizeof(*hdr); s->stat_frame_total_received++; if (!s->stat_frame_first_rx_time) s->stat_frame_first_rx_time = st_app_get_monotonic_time(); - if (s->st30_ref_fd > 0) app_rx_audio_compare_with_ref(s, payload); + if (s->st30_ref_fd > 0) + app_rx_audio_compare_with_ref(s, payload); return 0; } -static void* app_rx_audio_rtp_thread(void* arg) { - struct st_app_rx_audio_session* s = arg; +static void *app_rx_audio_rtp_thread(void *arg) { + struct st_app_rx_audio_session *s = arg; int idx = s->idx; - void* usrptr; + void *usrptr; uint16_t len; - void* mbuf; - struct st_rfc3550_rtp_hdr* hdr; + void *mbuf; + struct st_rfc3550_rtp_hdr *hdr; info("%s(%d), start\n", __func__, idx); while (!s->st30_app_thread_stop) { @@ -173,7 +178,7 @@ static void* app_rx_audio_rtp_thread(void* arg) { } /* get one packet */ - hdr = (struct st_rfc3550_rtp_hdr*)usrptr; + hdr = (struct st_rfc3550_rtp_hdr *)usrptr; app_rx_audio_handle_rtp(s, hdr); /* free to lib */ st30_rx_put_mbuf(s->handle, mbuf); @@ -183,7 +188,7 @@ static void* app_rx_audio_rtp_thread(void* arg) { return NULL; } -static int app_rx_audio_init_rtp_thread(struct st_app_rx_audio_session* s) { +static int app_rx_audio_init_rtp_thread(struct st_app_rx_audio_session *s) { int ret, idx = s->idx; ret = pthread_create(&s->st30_app_thread, NULL, app_rx_audio_rtp_thread, s); @@ -199,24 +204,26 @@ static int app_rx_audio_init_rtp_thread(struct st_app_rx_audio_session* s) { return 0; } -static int app_rx_audio_frame_ready(void* priv, void* frame, - struct st30_rx_frame_meta* meta) { - struct st_app_rx_audio_session* s = priv; +static int app_rx_audio_frame_ready(void *priv, void *frame, + struct st30_rx_frame_meta *meta) { + struct st_app_rx_audio_session *s = priv; MTL_MAY_UNUSED(meta); - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; s->stat_frame_total_received++; if (!s->stat_frame_first_rx_time) s->stat_frame_first_rx_time = st_app_get_monotonic_time(); - if (s->st30_ref_fd > 0) app_rx_audio_compare_with_ref(s, frame); + if (s->st30_ref_fd > 0) + app_rx_audio_compare_with_ref(s, frame); if (s->st30_dump_fd > 0) { if (s->st30_dump_cursor + s->st30_frame_size > s->st30_dump_end) s->st30_dump_cursor = s->st30_dump_begin; - dbg("%s(%d), dst %p src %p size %d\n", __func__, s->idx, s->st30_dump_cursor, frame, - s->st30_frame_size); + dbg("%s(%d), dst %p src %p size %d\n", __func__, s->idx, + s->st30_dump_cursor, frame, s->st30_frame_size); mtl_memcpy(s->st30_dump_cursor, frame, s->st30_frame_size); s->st30_dump_cursor += s->st30_frame_size; } @@ -226,8 +233,8 @@ static int app_rx_audio_frame_ready(void* priv, void* frame, return 0; } -static int app_rx_audio_rtp_ready(void* priv) { - struct st_app_rx_audio_session* s = priv; +static int app_rx_audio_rtp_ready(void *priv) { + struct st_app_rx_audio_session *s = priv; st_pthread_mutex_lock(&s->st30_wake_mutex); st_pthread_cond_signal(&s->st30_wake_cond); @@ -236,24 +243,25 @@ static int app_rx_audio_rtp_ready(void* priv) { return 0; } -static int app_rx_audio_timing_parser_result(void* priv, enum mtl_session_port port, - struct st30_rx_tp_meta* tp) { - struct st_app_rx_audio_session* s = priv; +static int app_rx_audio_timing_parser_result(void *priv, + enum mtl_session_port port, + struct st30_rx_tp_meta *tp) { + struct st_app_rx_audio_session *s = priv; s->stat_compliant_result[tp->compliant]++; s->ipt_max = ST_MAX(s->ipt_max, tp->ipt_max); if (tp->compliant != ST_RX_TP_COMPLIANT_NARROW) { - warn("%s(%d,%d), compliant %d, failed cause %s, pkts_cnt %u\n", __func__, s->idx, - port, tp->compliant, tp->failed_cause, tp->pkts_cnt); - warn("%s(%d,%d), tsdf %dus, ipt(ns) min %d max %d avg %f\n", __func__, s->idx, port, - tp->tsdf, tp->ipt_min, tp->ipt_max, tp->ipt_avg); + warn("%s(%d,%d), compliant %d, failed cause %s, pkts_cnt %u\n", __func__, + s->idx, port, tp->compliant, tp->failed_cause, tp->pkts_cnt); + warn("%s(%d,%d), tsdf %dus, ipt(ns) min %d max %d avg %f\n", __func__, + s->idx, port, tp->tsdf, tp->ipt_min, tp->ipt_max, tp->ipt_avg); dbg("%s(%d,%d), dpvr(us) min %d max %d avg %f\n", __func__, s->idx, port, tp->dpvr_min, tp->dpvr_max, tp->dpvr_avg); } return 0; } -static int app_rx_audio_uinit(struct st_app_rx_audio_session* s) { +static int app_rx_audio_uinit(struct st_app_rx_audio_session *s) { int ret, idx = s->idx; s->st30_app_thread_stop = true; @@ -271,7 +279,8 @@ static int app_rx_audio_uinit(struct st_app_rx_audio_session* s) { if (s->handle) { ret = st30_rx_free(s->handle); - if (ret < 0) err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } app_rx_audio_close_source(s); @@ -280,30 +289,35 @@ static int app_rx_audio_uinit(struct st_app_rx_audio_session* s) { return 0; } -static int app_rx_audio_result(struct st_app_rx_audio_session* s) { +static int app_rx_audio_result(struct st_app_rx_audio_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) return -EINVAL; + if (!s->stat_frame_total_received) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) + ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } -static int app_rx_audio_stat(struct st_app_rx_audio_session* s) { +static int app_rx_audio_stat(struct st_app_rx_audio_session *s) { s->stat_dump_cnt++; if (s->enable_timing_parser_meta) { if ((s->stat_dump_cnt % 6) == 0) { /* report every 1 min */ - warn("%s(%d), COMPLIANT NARROW %d WIDE %d FAILED %d, ipt max %fus\n", __func__, - s->idx, s->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], + warn("%s(%d), COMPLIANT NARROW %d WIDE %d FAILED %d, ipt max %fus\n", + __func__, s->idx, + s->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], s->stat_compliant_result[ST_RX_TP_COMPLIANT_WIDE], - s->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED], (float)s->ipt_max / 1000); + s->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED], + (float)s->ipt_max / 1000); memset(s->stat_compliant_result, 0, sizeof(s->stat_compliant_result)); s->ipt_max = 0; } @@ -311,8 +325,9 @@ static int app_rx_audio_stat(struct st_app_rx_audio_session* s) { return 0; } -static int app_rx_audio_init(struct st_app_context* ctx, st_json_audio_session_t* audio, - struct st_app_rx_audio_session* s) { +static int app_rx_audio_init(struct st_app_context *ctx, + st_json_audio_session_t *audio, + struct st_app_rx_audio_session *s) { int idx = s->idx, ret; struct st30_rx_ops ops; char name[32]; @@ -327,36 +342,41 @@ static int app_rx_audio_init(struct st_app_context* ctx, st_json_audio_session_t audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy( - ops.mcast_sip_addr[MTL_SESSION_PORT_P], - audio ? audio->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = audio ? audio->base.udp_port : (10100 + s->idx); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], + audio ? audio->base.mcast_src_ip[MTL_PORT_P] + : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + audio ? audio->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = + audio ? audio->base.udp_port : (10100 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy( - ops.mcast_sip_addr[MTL_SESSION_PORT_R], - audio ? audio->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], + audio ? audio->base.mcast_src_ip[MTL_PORT_R] + : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_PORT_R]->name : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = audio ? audio->base.udp_port : (10100 + s->idx); + audio ? audio->base.inf[MTL_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = + audio ? audio->base.udp_port : (10100 + s->idx); } ops.notify_frame_ready = app_rx_audio_frame_ready; ops.notify_rtp_ready = app_rx_audio_rtp_ready; ops.type = audio ? audio->info.type : ST30_TYPE_FRAME_LEVEL; ops.fmt = audio ? audio->info.audio_format : ST30_FMT_PCM16; - ops.payload_type = audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.payload_type = + audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; ops.channel = audio ? audio->info.audio_channel : 2; ops.sampling = audio ? audio->info.audio_sampling : ST30_SAMPLING_48K; ops.ptime = audio ? audio->info.audio_ptime : ST30_PTIME_1MS; - s->pkt_len = st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); + s->pkt_len = + st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); if (s->pkt_len < 0) { err("%s(%d), st30_get_packet_size fail\n", __func__, idx); app_rx_audio_uinit(s); @@ -371,13 +391,17 @@ static int app_rx_audio_init(struct st_app_context* ctx, st_json_audio_session_t } s->st30_frame_size = pkt_per_frame * s->pkt_len; - s->expect_fps = (double)NS_PER_S / st30_get_packet_time(ops.ptime) / pkt_per_frame; + s->expect_fps = + (double)NS_PER_S / st30_get_packet_time(ops.ptime) / pkt_per_frame; ops.framebuff_size = s->st30_frame_size; ops.framebuff_cnt = s->framebuff_cnt; - ops.rtp_ring_size = ctx->rx_audio_rtp_ring_size ? ctx->rx_audio_rtp_ring_size : 16; - if (audio && audio->enable_rtcp) ops.flags |= ST30_RX_FLAG_ENABLE_RTCP; - if (ctx->enable_timing_parser) ops.flags |= ST30_RX_FLAG_TIMING_PARSER_STAT; + ops.rtp_ring_size = + ctx->rx_audio_rtp_ring_size ? ctx->rx_audio_rtp_ring_size : 16; + if (audio && audio->enable_rtcp) + ops.flags |= ST30_RX_FLAG_ENABLE_RTCP; + if (ctx->enable_timing_parser) + ops.flags |= ST30_RX_FLAG_TIMING_PARSER_STAT; if (ctx->enable_timing_parser_meta) { ops.notify_timing_parser_result = app_rx_audio_timing_parser_result; ops.flags |= ST30_RX_FLAG_TIMING_PARSER_META; @@ -403,9 +427,9 @@ static int app_rx_audio_init(struct st_app_context* ctx, st_json_audio_session_t } /* dump */ - snprintf(s->st30_dump_url, ST_APP_URL_MAX_LEN, "st_audio_app%d_%d_%d_c%u.pcm", idx, - st30_get_sample_rate(ops.sampling), st30_get_sample_size(ops.fmt) * 8, - ops.channel); + snprintf(s->st30_dump_url, ST_APP_URL_MAX_LEN, "st_audio_app%d_%d_%d_c%u.pcm", + idx, st30_get_sample_rate(ops.sampling), + st30_get_sample_size(ops.fmt) * 8, ops.channel); ret = app_rx_audio_open_dump(s); if (ret < 0) { err("%s(%d), app_rx_audio_open_dump fail %d\n", __func__, idx, ret); @@ -424,8 +448,8 @@ static int app_rx_audio_init(struct st_app_context* ctx, st_json_audio_session_t ret = app_rx_audio_init_rtp_thread(s); } if (ret < 0) { - err("%s(%d), app_rx_audio_init_thread fail %d, type %d\n", __func__, idx, ret, - ops.type); + err("%s(%d), app_rx_audio_init_thread fail %d, type %d\n", __func__, idx, + ret, ops.type); app_rx_audio_uinit(s); return -EIO; } @@ -433,12 +457,13 @@ static int app_rx_audio_init(struct st_app_context* ctx, st_json_audio_session_t return 0; } -int st_app_rx_audio_sessions_init(struct st_app_context* ctx) { +int st_app_rx_audio_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_rx_audio_session* s; - ctx->rx_audio_sessions = (struct st_app_rx_audio_session*)st_app_zmalloc( + struct st_app_rx_audio_session *s; + ctx->rx_audio_sessions = (struct st_app_rx_audio_session *)st_app_zmalloc( sizeof(struct st_app_rx_audio_session) * ctx->rx_audio_session_cnt); - if (!ctx->rx_audio_sessions) return -ENOMEM; + if (!ctx->rx_audio_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; s->idx = i; @@ -458,10 +483,11 @@ int st_app_rx_audio_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_rx_audio_sessions_uinit(struct st_app_context* ctx) { +int st_app_rx_audio_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_rx_audio_session* s; - if (!ctx->rx_audio_sessions) return 0; + struct st_app_rx_audio_session *s; + if (!ctx->rx_audio_sessions) + return 0; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; @@ -472,11 +498,12 @@ int st_app_rx_audio_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_rx_audio_sessions_result(struct st_app_context* ctx) { +int st_app_rx_audio_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_audio_session* s; + struct st_app_rx_audio_session *s; - if (!ctx->rx_audio_sessions) return 0; + if (!ctx->rx_audio_sessions) + return 0; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; ret += app_rx_audio_result(s); @@ -485,11 +512,12 @@ int st_app_rx_audio_sessions_result(struct st_app_context* ctx) { return ret; } -int st_app_rx_audio_sessions_stat(struct st_app_context* ctx) { +int st_app_rx_audio_sessions_stat(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_audio_session* s; + struct st_app_rx_audio_session *s; - if (!ctx->rx_audio_sessions) return 0; + if (!ctx->rx_audio_sessions) + return 0; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; ret += app_rx_audio_stat(s); diff --git a/app/src/legacy/rx_audio_app.h b/app/src/legacy/rx_audio_app.h index 950ba91b5..90df3614c 100644 --- a/app/src/legacy/rx_audio_app.h +++ b/app/src/legacy/rx_audio_app.h @@ -13,12 +13,12 @@ #ifndef _RX_APP_AUDIO_HEAD_H_ #define _RX_APP_AUDIO_HEAD_H_ -int st_app_rx_audio_sessions_init(struct st_app_context* ctx); +int st_app_rx_audio_sessions_init(struct st_app_context *ctx); -int st_app_rx_audio_sessions_uinit(struct st_app_context* ctx); +int st_app_rx_audio_sessions_uinit(struct st_app_context *ctx); -int st_app_rx_audio_sessions_result(struct st_app_context* ctx); +int st_app_rx_audio_sessions_result(struct st_app_context *ctx); -int st_app_rx_audio_sessions_stat(struct st_app_context* ctx); +int st_app_rx_audio_sessions_stat(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/legacy/rx_st22_app.c b/app/src/legacy/rx_st22_app.c index 110eccdd5..94bdc8b00 100644 --- a/app/src/legacy/rx_st22_app.c +++ b/app/src/legacy/rx_st22_app.c @@ -4,7 +4,7 @@ #include "rx_st22_app.h" -static int app_rx_st22_close_source(struct st22_app_rx_session* s) { +static int app_rx_st22_close_source(struct st22_app_rx_session *s) { if (s->st22_dst_fd >= 0) { munmap(s->st22_dst_begin, s->st22_dst_end - s->st22_dst_begin); close(s->st22_dst_fd); @@ -14,12 +14,13 @@ static int app_rx_st22_close_source(struct st22_app_rx_session* s) { return 0; } -static int app_rx_st22_open_source(struct st22_app_rx_session* s) { +static int app_rx_st22_open_source(struct st22_app_rx_session *s) { int fd, ret, idx = s->idx; off_t f_size; /* user do not require fb save to file */ - if (s->st22_dst_fb_cnt <= 1) return 0; + if (s->st22_dst_fb_cnt <= 1) + return 0; fd = st_open_mode(s->st22_dst_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -35,7 +36,7 @@ static int app_rx_st22_open_source(struct st22_app_rx_session* s) { return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, s->st22_dst_url); close(fd); @@ -46,15 +47,15 @@ static int app_rx_st22_open_source(struct st22_app_rx_session* s) { s->st22_dst_cursor = m; s->st22_dst_end = m + f_size; s->st22_dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, - s->st22_dst_fb_cnt, s->st22_dst_url, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, s->st22_dst_fb_cnt, s->st22_dst_url, m, f_size); return 0; } -static int app_rx_st22_enqueue_frame(struct st22_app_rx_session* s, void* frame, +static int app_rx_st22_enqueue_frame(struct st22_app_rx_session *s, void *frame, size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -65,16 +66,18 @@ static int app_rx_st22_enqueue_frame(struct st22_app_rx_session* s, void* frame, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int app_rx_st22_frame_ready(void* priv, void* frame, - struct st22_rx_frame_meta* meta) { - struct st22_app_rx_session* s = (struct st22_app_rx_session*)priv; +static int app_rx_st22_frame_ready(void *priv, void *frame, + struct st22_rx_frame_meta *meta) { + struct st22_app_rx_session *s = (struct st22_app_rx_session *)priv; - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; st_pthread_mutex_lock(&s->wake_mutex); int ret = app_rx_st22_enqueue_frame(s, frame, meta->frame_total_size); @@ -91,7 +94,8 @@ static int app_rx_st22_frame_ready(void* priv, void* frame, return 0; } -static void app_rx_st22_decode_frame(struct st22_app_rx_session* s, void* codestream_addr, +static void app_rx_st22_decode_frame(struct st22_app_rx_session *s, + void *codestream_addr, size_t codestream_size) { if (s->st22_dst_cursor + codestream_size > s->st22_dst_end) s->st22_dst_cursor = s->st22_dst_begin; @@ -102,11 +106,11 @@ static void app_rx_st22_decode_frame(struct st22_app_rx_session* s, void* codest s->fb_decoded++; } -static void* app_rx_st22_decode_thread(void* arg) { - struct st22_app_rx_session* s = arg; +static void *app_rx_st22_decode_thread(void *arg) { + struct st22_app_rx_session *s = arg; int idx = s->idx; int consumer_idx; - struct st_rx_frame* framebuff; + struct st_rx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->st22_app_thread_stop) { @@ -115,7 +119,8 @@ static void* app_rx_st22_decode_thread(void* arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->st22_app_thread_stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->st22_app_thread_stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -128,7 +133,8 @@ static void* app_rx_st22_decode_thread(void* arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -137,7 +143,7 @@ static void* app_rx_st22_decode_thread(void* arg) { return NULL; } -static int app_rx_st22_uinit(struct st22_app_rx_session* s) { +static int app_rx_st22_uinit(struct st22_app_rx_session *s) { int ret, idx = s->idx; s->st22_app_thread_stop = true; @@ -155,7 +161,8 @@ static int app_rx_st22_uinit(struct st22_app_rx_session* s) { if (s->handle) { ret = st22_rx_free(s->handle); - if (ret < 0) err("%s(%d), st22_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st22_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } app_rx_st22_close_source(s); @@ -168,8 +175,8 @@ static int app_rx_st22_uinit(struct st22_app_rx_session* s) { return 0; } -static int app_rx_st22_init(struct st_app_context* ctx, struct st22_app_rx_session* s, - int bpp) { +static int app_rx_st22_init(struct st_app_context *ctx, + struct st22_app_rx_session *s, int bpp) { int idx = s->idx, ret; struct st22_rx_ops ops; char name[32]; @@ -184,23 +191,25 @@ static int app_rx_st22_init(struct st_app_context* ctx, struct st22_app_rx_sessi uint32_t soc = 0, b = 0, d = 0, f = 0; sscanf(ctx->para.port[MTL_PORT_P], "%x:%x:%x.%x", &soc, &b, &d, &f); snprintf(s->st22_dst_url, ST_APP_URL_MAX_LEN, - "st22_app%d_%d_%d_%02x_%02x_%02x_%02x.raw", idx, s->width, s->height, soc, b, - d, f); + "st22_app%d_%d_%d_%02x_%02x_%02x_%02x.raw", idx, s->width, s->height, + soc, b, d, f); snprintf(name, 32, "app_rx_st22_%d", idx); ops.name = name; ops.priv = s; ops.num_port = ctx->para.num_ports; - memcpy(ops.ip_addr[MTL_SESSION_PORT_P], ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], ctx->rx_mcast_sip_addr[MTL_PORT_P], + memcpy(ops.ip_addr[MTL_SESSION_PORT_P], ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], + ctx->rx_mcast_sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops.udp_port[MTL_SESSION_PORT_P] = 15000 + s->idx; if (ops.num_port > 1) { - memcpy(ops.ip_addr[MTL_SESSION_PORT_R], ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], ctx->rx_mcast_sip_addr[MTL_PORT_R], + memcpy(ops.ip_addr[MTL_SESSION_PORT_R], ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], + ctx->rx_mcast_sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops.udp_port[MTL_SESSION_PORT_R] = 15000 + s->idx; @@ -219,9 +228,10 @@ static int app_rx_st22_init(struct st_app_context* ctx, struct st22_app_rx_sessi s->framebuff_cnt = ops.framebuff_cnt; s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = - (struct st_rx_frame*)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); - if (!s->framebuffs) return -ENOMEM; + s->framebuffs = (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * + s->framebuff_cnt); + if (!s->framebuffs) + return -ENOMEM; for (uint16_t j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].frame = NULL; } @@ -259,12 +269,13 @@ static int app_rx_st22_init(struct st_app_context* ctx, struct st22_app_rx_sessi return 0; } -int st22_app_rx_sessions_init(struct st_app_context* ctx) { +int st22_app_rx_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st22_app_rx_session* s; - ctx->rx_st22_sessions = (struct st22_app_rx_session*)st_app_zmalloc( + struct st22_app_rx_session *s; + ctx->rx_st22_sessions = (struct st22_app_rx_session *)st_app_zmalloc( sizeof(struct st22_app_rx_session) * ctx->rx_st22_session_cnt); - if (!ctx->rx_st22_sessions) return -ENOMEM; + if (!ctx->rx_st22_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_st22_session_cnt; i++) { s = &ctx->rx_st22_sessions[i]; s->idx = i; @@ -281,10 +292,11 @@ int st22_app_rx_sessions_init(struct st_app_context* ctx) { return 0; } -int st22_app_rx_sessions_uinit(struct st_app_context* ctx) { +int st22_app_rx_sessions_uinit(struct st_app_context *ctx) { int i; - struct st22_app_rx_session* s; - if (!ctx->rx_st22_sessions) return 0; + struct st22_app_rx_session *s; + if (!ctx->rx_st22_sessions) + return 0; for (i = 0; i < ctx->rx_st22_session_cnt; i++) { s = &ctx->rx_st22_sessions[i]; app_rx_st22_uinit(s); diff --git a/app/src/legacy/rx_st22_app.h b/app/src/legacy/rx_st22_app.h index 5debfa0a3..3df9ff4c8 100644 --- a/app/src/legacy/rx_st22_app.h +++ b/app/src/legacy/rx_st22_app.h @@ -14,7 +14,7 @@ #ifndef _RX_APP_ST22_HEAD_H_ #define _RX_APP_ST22_HEAD_H_ -int st22_app_rx_sessions_init(struct st_app_context* ctx); -int st22_app_rx_sessions_uinit(struct st_app_context* ctx); +int st22_app_rx_sessions_init(struct st_app_context *ctx); +int st22_app_rx_sessions_uinit(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/legacy/rx_video_app.c b/app/src/legacy/rx_video_app.c index c53386e44..87bb3d6da 100644 --- a/app/src/legacy/rx_video_app.c +++ b/app/src/legacy/rx_video_app.c @@ -4,9 +4,9 @@ #include "rx_video_app.h" -static int pg_convert_callback(void* priv, void* frame, - struct st20_rx_uframe_pg_meta* meta) { - struct st_app_rx_video_session* s = priv; +static int pg_convert_callback(void *priv, void *frame, + struct st20_rx_uframe_pg_meta *meta) { + struct st_app_rx_video_session *s = priv; uint32_t offset = (meta->row_number * s->width + meta->row_offset) / s->user_pg.coverage * s->user_pg.size; @@ -23,10 +23,11 @@ static inline bool app_rx_video_is_frame_type(enum st20_type type) { return false; } -static int app_rx_video_enqueue_frame(struct st_app_rx_video_session* s, void* frame, - struct st20_rx_frame_meta* meta) { +static int app_rx_video_enqueue_frame(struct st_app_rx_video_session *s, + void *frame, + struct st20_rx_frame_meta *meta) { uint16_t producer_idx = s->framebuff_producer_idx; - struct st_rx_frame* framebuff = &s->framebuffs[producer_idx]; + struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; if (framebuff->frame) { return -EBUSY; @@ -46,14 +47,15 @@ static int app_rx_video_enqueue_frame(struct st_app_rx_video_session* s, void* f framebuff->size = meta->frame_total_size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static void app_rx_video_consume_frame(struct st_app_rx_video_session* s, void* frame, - size_t frame_size) { - struct st_display* d = s->display; +static void app_rx_video_consume_frame(struct st_app_rx_video_session *s, + void *frame, size_t frame_size) { + struct st_display *d = s->display; if (d && d->front_frame) { if (st_pthread_mutex_trylock(&d->display_frame_mutex) == 0) { @@ -61,7 +63,8 @@ static void app_rx_video_consume_frame(struct st_app_rx_video_session* s, void* s->user_pg.fmt == USER_FMT_YUV_422_8BIT) mtl_memcpy(d->front_frame, frame, d->front_frame_size); else if (s->st20_pg.fmt == ST20_FMT_YUV_422_10BIT) - st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, s->height); + st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, + s->height); else /* fmt mismatch*/ { st_pthread_mutex_unlock(&d->display_frame_mutex); return; @@ -74,18 +77,18 @@ static void app_rx_video_consume_frame(struct st_app_rx_video_session* s, void* } else if (s->st20_dst_fd > 0) { if (s->st20_dst_cursor + frame_size > s->st20_dst_end) s->st20_dst_cursor = s->st20_dst_begin; - dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, s->st20_dst_cursor, - frame, frame_size); + dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, + s->st20_dst_cursor, frame, frame_size); mtl_memcpy(s->st20_dst_cursor, frame, frame_size); s->st20_dst_cursor += frame_size; } } -static void* app_rx_video_frame_thread(void* arg) { - struct st_app_rx_video_session* s = arg; +static void *app_rx_video_frame_thread(void *arg) { + struct st_app_rx_video_session *s = arg; int idx = s->idx; int consumer_idx; - struct st_rx_frame* framebuff; + struct st_rx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->st20_app_thread_stop) { @@ -105,9 +108,10 @@ static void* app_rx_video_frame_thread(void* arg) { app_rx_video_consume_frame(s, framebuff->frame, framebuff->size); if (s->sha_check) { uint8_t shas[SHA256_DIGEST_LENGTH]; - st_sha256((unsigned char*)framebuff->frame, framebuff->size, shas); + st_sha256((unsigned char *)framebuff->frame, framebuff->size, shas); if (memcmp(shas, framebuff->shas, sizeof(shas))) { - err("%s(%d), sha check fail for frame idx %d\n", __func__, idx, consumer_idx); + err("%s(%d), sha check fail for frame idx %d\n", __func__, idx, + consumer_idx); st_sha_dump("user meta sha:", framebuff->shas); st_sha_dump("frame sha:", shas); } @@ -117,7 +121,8 @@ static void* app_rx_video_frame_thread(void* arg) { st_pthread_mutex_lock(&s->st20_wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->st20_wake_mutex); } @@ -126,16 +131,16 @@ static void* app_rx_video_frame_thread(void* arg) { return NULL; } -static int app_rx_video_handle_rtp(struct st_app_rx_video_session* s, - struct st20_rfc4175_rtp_hdr* hdr) { +static int app_rx_video_handle_rtp(struct st_app_rx_video_session *s, + struct st20_rfc4175_rtp_hdr *hdr) { int idx = s->idx; uint32_t tmstamp = ntohl(hdr->base.tmstamp); - struct st20_rfc4175_extra_rtp_hdr* e_hdr = NULL; + struct st20_rfc4175_extra_rtp_hdr *e_hdr = NULL; uint16_t row_number; /* 0 to 1079 for 1080p */ uint16_t row_offset; /* [0, 480, 960, 1440] for 1080p */ uint16_t row_length; /* 1200 for 1080p */ - uint8_t* frame; - uint8_t* payload; + uint8_t *frame; + uint8_t *payload; dbg("%s(%d),tmstamp: 0x%x\n", __func__, idx, tmstamp); if (tmstamp != s->st20_last_tmstamp) { @@ -151,18 +156,20 @@ static int app_rx_video_handle_rtp(struct st_app_rx_video_session* s, s->st20_dst_cursor = s->st20_dst_begin; } - if (s->st20_dst_fd < 0) return 0; + if (s->st20_dst_fd < 0) + return 0; frame = s->st20_dst_cursor; - payload = (uint8_t*)hdr + sizeof(*hdr); + payload = (uint8_t *)hdr + sizeof(*hdr); row_number = ntohs(hdr->row_number); row_offset = ntohs(hdr->row_offset); row_length = ntohs(hdr->row_length); - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, row_length); + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, + row_length); if (row_offset & ST20_SRD_OFFSET_CONTINUATION) { /* additional Sample Row Data */ row_offset &= ~ST20_SRD_OFFSET_CONTINUATION; - e_hdr = (struct st20_rfc4175_extra_rtp_hdr*)payload; + e_hdr = (struct st20_rfc4175_extra_rtp_hdr *)payload; payload += sizeof(*e_hdr); } @@ -171,8 +178,8 @@ static int app_rx_video_handle_rtp(struct st_app_rx_video_session* s, } /* copy the payload to target frame */ - uint32_t offset = - (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; + uint32_t offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * + s->st20_pg.size; if ((offset + row_length) > s->st20_frame_size) { err("%s(%d: invalid offset %u frame size %d\n", __func__, idx, offset, s->st20_frame_size); @@ -188,12 +195,13 @@ static int app_rx_video_handle_rtp(struct st_app_rx_video_session* s, row2_number &= ~ST20_SECOND_FIELD; } - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, row2_length); - uint32_t offset2 = - (row2_number * s->width + row2_offset) / s->st20_pg.coverage * s->st20_pg.size; + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, + row2_length); + uint32_t offset2 = (row2_number * s->width + row2_offset) / + s->st20_pg.coverage * s->st20_pg.size; if ((offset2 + row2_length) > s->st20_frame_size) { - err("%s(%d: invalid offset %u frame size %d for extra hdr\n", __func__, idx, - offset2, s->st20_frame_size); + err("%s(%d: invalid offset %u frame size %d for extra hdr\n", __func__, + idx, offset2, s->st20_frame_size); return -EIO; } mtl_memcpy(frame + offset2, payload + row_length, row2_length); @@ -202,13 +210,13 @@ static int app_rx_video_handle_rtp(struct st_app_rx_video_session* s, return 0; } -static void* app_rx_video_rtp_thread(void* arg) { - struct st_app_rx_video_session* s = arg; +static void *app_rx_video_rtp_thread(void *arg) { + struct st_app_rx_video_session *s = arg; int idx = s->idx; - void* usrptr; + void *usrptr; uint16_t len; - void* mbuf; - struct st20_rfc4175_rtp_hdr* hdr; + void *mbuf; + struct st20_rfc4175_rtp_hdr *hdr; info("%s(%d), start\n", __func__, idx); while (!s->st20_app_thread_stop) { @@ -223,7 +231,7 @@ static void* app_rx_video_rtp_thread(void* arg) { } /* get one packet */ - hdr = (struct st20_rfc4175_rtp_hdr*)usrptr; + hdr = (struct st20_rfc4175_rtp_hdr *)usrptr; app_rx_video_handle_rtp(s, hdr); /* free to lib */ st20_rx_put_mbuf(s->handle, mbuf); @@ -233,7 +241,7 @@ static void* app_rx_video_rtp_thread(void* arg) { return NULL; } -static int app_rx_video_close_source(struct st_app_rx_video_session* s) { +static int app_rx_video_close_source(struct st_app_rx_video_session *s) { if (s->st20_dst_fd >= 0) { munmap(s->st20_dst_begin, s->st20_dst_end - s->st20_dst_begin); close(s->st20_dst_fd); @@ -243,12 +251,13 @@ static int app_rx_video_close_source(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_video_open_source(struct st_app_rx_video_session* s) { +static int app_rx_video_open_source(struct st_app_rx_video_session *s) { int fd, ret, idx = s->idx; off_t f_size; /* user do not require fb save to file */ - if (s->st20_dst_fb_cnt < 1) return 0; + if (s->st20_dst_fb_cnt < 1) + return 0; fd = st_open_mode(s->st20_dst_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -264,7 +273,7 @@ static int app_rx_video_open_source(struct st_app_rx_video_session* s) { return -EIO; } - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s(%d), mmap %s fail\n", __func__, idx, s->st20_dst_url); close(fd); @@ -275,17 +284,18 @@ static int app_rx_video_open_source(struct st_app_rx_video_session* s) { s->st20_dst_cursor = m; s->st20_dst_end = m + f_size; s->st20_dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, - s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, + idx, s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); return 0; } -static int app_rx_video_init_frame_thread(struct st_app_rx_video_session* s) { +static int app_rx_video_init_frame_thread(struct st_app_rx_video_session *s) { int ret, idx = s->idx; /* user do not require fb save to file or display */ - if (s->st20_dst_fb_cnt < 1 && !s->display && !s->sha_check) return 0; + if (s->st20_dst_fb_cnt < 1 && !s->display && !s->sha_check) + return 0; ret = pthread_create(&s->st20_app_thread, NULL, app_rx_video_frame_thread, s); if (ret < 0) { @@ -300,7 +310,7 @@ static int app_rx_video_init_frame_thread(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_video_init_rtp_thread(struct st_app_rx_video_session* s) { +static int app_rx_video_init_rtp_thread(struct st_app_rx_video_session *s) { int ret, idx = s->idx; ret = pthread_create(&s->st20_app_thread, NULL, app_rx_video_rtp_thread, s); @@ -312,23 +322,26 @@ static int app_rx_video_init_rtp_thread(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_video_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - struct st_app_rx_video_session* s = priv; +static int app_rx_video_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct st_app_rx_video_session *s = priv; int ret, idx = s->idx; - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; if (s->num_port > 1) { dbg("%s(%d): pkts_total %u, pkts per port P %u R %u\n", __func__, idx, meta->pkts_total, meta->pkts_recv[MTL_SESSION_PORT_P], meta->pkts_recv[MTL_SESSION_PORT_R]); if (meta->pkts_recv[MTL_SESSION_PORT_P] < (meta->pkts_total / 2)) - warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", __func__, idx, - meta->pkts_recv[MTL_SESSION_PORT_P], meta->pkts_total); + warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", + __func__, idx, meta->pkts_recv[MTL_SESSION_PORT_P], + meta->pkts_total); if (meta->pkts_recv[MTL_SESSION_PORT_R] < (meta->pkts_total / 2)) - warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", __func__, idx, - meta->pkts_recv[MTL_SESSION_PORT_R], meta->pkts_total); + warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", + __func__, idx, meta->pkts_recv[MTL_SESSION_PORT_R], + meta->pkts_total); } /* incomplete frame */ @@ -377,30 +390,32 @@ static int app_rx_video_frame_ready(void* priv, void* frame, return 0; } -static int app_rx_video_slice_ready(void* priv, void* frame, - struct st20_rx_slice_meta* meta) { - struct st_app_rx_video_session* s = priv; +static int app_rx_video_slice_ready(void *priv, void *frame, + struct st20_rx_slice_meta *meta) { + struct st_app_rx_video_session *s = priv; int idx = s->idx; size_t frame_ready_size; MTL_MAY_UNUSED(frame); - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; frame_ready_size = meta->frame_recv_lines * s->width * s->st20_pg.size / s->st20_pg.coverage; - dbg("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " \n", __func__, idx, - meta->frame_recv_lines, frame_ready_size, meta->frame_recv_size); + dbg("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " \n", __func__, + idx, meta->frame_recv_lines, frame_ready_size, meta->frame_recv_size); if (meta->frame_recv_size < frame_ready_size) { - err("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " error\n", __func__, idx, - meta->frame_recv_lines, frame_ready_size, meta->frame_recv_size); + err("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " error\n", + __func__, idx, meta->frame_recv_lines, frame_ready_size, + meta->frame_recv_size); } return 0; } -static int app_rx_video_rtp_ready(void* priv) { - struct st_app_rx_video_session* s = priv; +static int app_rx_video_rtp_ready(void *priv) { + struct st_app_rx_video_session *s = priv; st_pthread_mutex_lock(&s->st20_wake_mutex); st_pthread_cond_signal(&s->st20_wake_cond); @@ -409,14 +424,17 @@ static int app_rx_video_rtp_ready(void* priv) { return 0; } -static int app_rx_video_detected(void* priv, const struct st20_detect_meta* meta, - struct st20_detect_reply* reply) { - struct st_app_rx_video_session* s = priv; +static int app_rx_video_detected(void *priv, + const struct st20_detect_meta *meta, + struct st20_detect_reply *reply) { + struct st_app_rx_video_session *s = priv; - if (s->slice) reply->slice_lines = meta->height / 32; + if (s->slice) + reply->slice_lines = meta->height / 32; if (s->user_pg.fmt != USER_FMT_MAX) { int ret = user_get_pgroup(s->user_pg.fmt, &s->user_pg); - if (ret < 0) return ret; + if (ret < 0) + return ret; reply->uframe_size = meta->width * meta->height * s->user_pg.size / s->user_pg.coverage; } @@ -424,7 +442,7 @@ static int app_rx_video_detected(void* priv, const struct st20_detect_meta* meta return 0; } -static int app_rx_video_uinit(struct st_app_rx_video_session* s) { +static int app_rx_video_uinit(struct st_app_rx_video_session *s) { int ret, idx = s->idx; if (s->display) { @@ -447,7 +465,8 @@ static int app_rx_video_uinit(struct st_app_rx_video_session* s) { if (s->handle) { ret = st20_rx_free(s->handle); - if (ret < 0) err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } app_rx_video_close_source(s); @@ -459,7 +478,7 @@ static int app_rx_video_uinit(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_video_io_stat(struct st_app_rx_video_session* s) { +static int app_rx_video_io_stat(struct st_app_rx_video_session *s) { int idx = s->idx; uint64_t cur_time = st_app_get_monotonic_time(); double time_sec = (double)(cur_time - s->last_stat_time_ns) / NS_PER_S; @@ -467,11 +486,13 @@ static int app_rx_video_io_stat(struct st_app_rx_video_session* s) { int ret; struct st20_rx_port_status stats; - if (!s->handle) return 0; + if (!s->handle) + return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20_rx_get_port_stats(s->handle, port, &stats); - if (ret < 0) return ret; + if (ret < 0) + return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -483,8 +504,9 @@ static int app_rx_video_io_stat(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t* video, - struct st_app_rx_video_session* s) { +static int app_rx_video_init(struct st_app_context *ctx, + st_json_video_session_t *video, + struct st_app_rx_video_session *s) { int idx = s->idx, ret; struct st20_rx_ops ops; char name[32]; @@ -502,27 +524,29 @@ static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy( - ops.mcast_sip_addr[MTL_SESSION_PORT_P], - video ? video->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = video ? video->base.udp_port : (10000 + s->idx); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], + video ? video->base.mcast_src_ip[MTL_PORT_P] + : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = + video ? video->base.udp_port : (10000 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy( - ops.mcast_sip_addr[MTL_SESSION_PORT_R], - video ? video->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = video ? video->base.udp_port : (10000 + s->idx); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], + video ? video->base.mcast_src_ip[MTL_PORT_R] + : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = + video ? video->base.udp_port : (10000 + s->idx); } ops.pacing = ST21_PACING_NARROW; if (ctx->rx_video_rtp_ring_size > 0) @@ -541,8 +565,10 @@ static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t ops.fps = video ? st_app_get_fps(video->info.video_format) : ST_FPS_P59_94; } ops.fmt = video ? video->info.pg_format : ST20_FMT_YUV_422_10BIT; - ops.payload_type = video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; - ops.interlaced = video ? st_app_get_interlaced(video->info.video_format) : false; + ops.payload_type = + video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.interlaced = + video ? st_app_get_interlaced(video->info.video_format) : false; ops.notify_frame_ready = app_rx_video_frame_ready; ops.slice_lines = ops.height / 32; ops.notify_slice_ready = app_rx_video_slice_ready; @@ -550,20 +576,24 @@ static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t ops.notify_detected = app_rx_video_detected; ops.framebuff_cnt = s->framebuff_cnt; ops.rtp_ring_size = ctx->rx_video_rtp_ring_size; - if (!ops.rtp_ring_size) ops.rtp_ring_size = 1024; + if (!ops.rtp_ring_size) + ops.rtp_ring_size = 1024; if (ops.type == ST20_TYPE_SLICE_LEVEL) { ops.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; s->slice = true; } else { s->slice = false; } - if (ctx->enable_hdr_split) ops.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (ctx->enable_hdr_split) + ops.flags |= ST20_RX_FLAG_HDR_SPLIT; if (video && video->enable_rtcp) { ops.flags |= ST20_RX_FLAG_ENABLE_RTCP; ops.rtcp.nack_interval_us = 250; } - if (ctx->enable_timing_parser) ops.flags |= ST20_RX_FLAG_TIMING_PARSER_STAT; - if (ctx->rx_video_multi_thread) ops.flags |= ST20_RX_FLAG_USE_MULTI_THREADS; + if (ctx->enable_timing_parser) + ops.flags |= ST20_RX_FLAG_TIMING_PARSER_STAT; + if (ctx->rx_video_multi_thread) + ops.flags |= ST20_RX_FLAG_USE_MULTI_THREADS; ops.rx_burst_size = ctx->rx_burst_size; if (ctx->force_rx_video_numa >= 0) { ops.flags |= ST20_RX_FLAG_FORCE_NUMA; @@ -574,22 +604,25 @@ static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t st_pthread_cond_init(&s->st20_wake_cond, NULL); if (mtl_pmd_by_port_name(ops.port[MTL_SESSION_PORT_P]) != MTL_PMD_DPDK_USER) { - snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d_%s.yuv", idx, ops.width, - ops.height, ops.port[MTL_SESSION_PORT_P]); + snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d_%s.yuv", idx, + ops.width, ops.height, ops.port[MTL_SESSION_PORT_P]); } else { uint32_t soc = 0, b = 0, d = 0, f = 0; sscanf(ops.port[MTL_SESSION_PORT_P], "%x:%x:%x.%x", &soc, &b, &d, &f); snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, - "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, ops.height, soc, b, - d, f); + "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, + ops.height, soc, b, d, f); } ret = st20_get_pgroup(ops.fmt, &s->st20_pg); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->user_pg.fmt = video ? video->user_pg_format : USER_FMT_MAX; if (s->user_pg.fmt != USER_FMT_MAX) { ret = user_get_pgroup(s->user_pg.fmt, &s->user_pg); - if (ret < 0) return ret; - ops.uframe_size = ops.width * ops.height * s->user_pg.size / s->user_pg.coverage; + if (ret < 0) + return ret; + ops.uframe_size = + ops.width * ops.height * s->user_pg.size / s->user_pg.coverage; ops.uframe_pg_callback = pg_convert_callback; } @@ -604,15 +637,16 @@ static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = - (struct st_rx_frame*)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); - if (!s->framebuffs) return -ENOMEM; + s->framebuffs = (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * + s->framebuff_cnt); + if (!s->framebuffs) + return -ENOMEM; for (int j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].frame = NULL; } if ((video && video->display) || ctx->rx_display) { - struct st_display* d = st_app_zmalloc(sizeof(struct st_display)); + struct st_display *d = st_app_zmalloc(sizeof(struct st_display)); ret = st_app_init_display(d, name, s->width, s->height, ctx->ttf_file); if (ret < 0) { err("%s(%d), st_app_init_display fail %d\n", __func__, idx, ret); @@ -650,8 +684,8 @@ static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t ret = -EINVAL; } if (ret < 0) { - err("%s(%d), app_rx_video_init_thread fail %d, type %d\n", __func__, idx, ret, - ops.type); + err("%s(%d), app_rx_video_init_thread fail %d, type %d\n", __func__, idx, + ret, ops.type); app_rx_video_uinit(s); return -EIO; } @@ -662,7 +696,7 @@ static int app_rx_video_init(struct st_app_context* ctx, st_json_video_session_t return 0; } -static int app_rx_video_stat(struct st_app_rx_video_session* s) { +static int app_rx_video_stat(struct st_app_rx_video_session *s) { uint64_t cur_time_ns = st_app_get_monotonic_time(); #ifdef DEBUG double time_sec = (double)(cur_time_ns - s->stat_last_time) / NS_PER_S; @@ -671,7 +705,8 @@ static int app_rx_video_stat(struct st_app_rx_video_session* s) { s->stat_frame_received); #endif if (s->measure_latency && s->stat_frame_received) { - double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = + (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -681,35 +716,41 @@ static int app_rx_video_stat(struct st_app_rx_video_session* s) { return 0; } -static int app_rx_video_result(struct st_app_rx_video_session* s) { +static int app_rx_video_result(struct st_app_rx_video_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) return -EINVAL; + if (!s->stat_frame_total_received) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) + ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } -static int app_rx_video_pcap(struct st_app_rx_video_session* s) { - if (s->pcapng_max_pkts) st20_rx_pcapng_dump(s->handle, s->pcapng_max_pkts, false, NULL); +static int app_rx_video_pcap(struct st_app_rx_video_session *s) { + if (s->pcapng_max_pkts) + st20_rx_pcapng_dump(s->handle, s->pcapng_max_pkts, false, NULL); return 0; } -int st_app_rx_video_sessions_init(struct st_app_context* ctx) { +int st_app_rx_video_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_rx_video_session* s; + struct st_app_rx_video_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) + fb_cnt = ST_APP_DEFAULT_FB_CNT; - ctx->rx_video_sessions = (struct st_app_rx_video_session*)st_app_zmalloc( + ctx->rx_video_sessions = (struct st_app_rx_video_session *)st_app_zmalloc( sizeof(struct st_app_rx_video_session) * ctx->rx_video_session_cnt); - if (!ctx->rx_video_sessions) return -ENOMEM; + if (!ctx->rx_video_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; s->idx = i; @@ -729,10 +770,11 @@ int st_app_rx_video_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_rx_video_sessions_uinit(struct st_app_context* ctx) { +int st_app_rx_video_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_rx_video_session* s; - if (!ctx->rx_video_sessions) return 0; + struct st_app_rx_video_session *s; + if (!ctx->rx_video_sessions) + return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; app_rx_video_uinit(s); @@ -742,10 +784,11 @@ int st_app_rx_video_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_rx_video_sessions_stat(struct st_app_context* ctx) { +int st_app_rx_video_sessions_stat(struct st_app_context *ctx) { int i; - struct st_app_rx_video_session* s; - if (!ctx->rx_video_sessions) return 0; + struct st_app_rx_video_session *s; + if (!ctx->rx_video_sessions) + return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; @@ -755,11 +798,12 @@ int st_app_rx_video_sessions_stat(struct st_app_context* ctx) { return 0; } -int st_app_rx_video_sessions_result(struct st_app_context* ctx) { +int st_app_rx_video_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_video_session* s; + struct st_app_rx_video_session *s; - if (!ctx->rx_video_sessions) return 0; + if (!ctx->rx_video_sessions) + return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; @@ -769,11 +813,12 @@ int st_app_rx_video_sessions_result(struct st_app_context* ctx) { return ret; } -int st_app_rx_video_sessions_pcap(struct st_app_context* ctx) { +int st_app_rx_video_sessions_pcap(struct st_app_context *ctx) { int i; - struct st_app_rx_video_session* s; + struct st_app_rx_video_session *s; - if (!ctx->rx_video_sessions) return 0; + if (!ctx->rx_video_sessions) + return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; @@ -783,10 +828,11 @@ int st_app_rx_video_sessions_pcap(struct st_app_context* ctx) { return 0; } -int st_app_rx_videos_io_stat(struct st_app_context* ctx) { +int st_app_rx_videos_io_stat(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_video_session* s; - if (!ctx->rx_video_sessions) return 0; + struct st_app_rx_video_session *s; + if (!ctx->rx_video_sessions) + return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; diff --git a/app/src/legacy/rx_video_app.h b/app/src/legacy/rx_video_app.h index ea9b28cf3..848710bc4 100644 --- a/app/src/legacy/rx_video_app.h +++ b/app/src/legacy/rx_video_app.h @@ -15,16 +15,16 @@ #ifndef _RX_APP_VIDEO_HEAD_H_ #define _RX_APP_VIDEO_HEAD_H_ -int st_app_rx_video_sessions_init(struct st_app_context* ctx); +int st_app_rx_video_sessions_init(struct st_app_context *ctx); -int st_app_rx_video_sessions_uinit(struct st_app_context* ctx); +int st_app_rx_video_sessions_uinit(struct st_app_context *ctx); -int st_app_rx_video_sessions_stat(struct st_app_context* ctx); +int st_app_rx_video_sessions_stat(struct st_app_context *ctx); -int st_app_rx_video_sessions_result(struct st_app_context* ctx); +int st_app_rx_video_sessions_result(struct st_app_context *ctx); -int st_app_rx_video_sessions_pcap(struct st_app_context* ctx); +int st_app_rx_video_sessions_pcap(struct st_app_context *ctx); -int st_app_rx_videos_io_stat(struct st_app_context* ctx); +int st_app_rx_videos_io_stat(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/legacy/tx_audio_app.c b/app/src/legacy/tx_audio_app.c index 8911038e3..127eb21e5 100644 --- a/app/src/legacy/tx_audio_app.c +++ b/app/src/legacy/tx_audio_app.c @@ -4,29 +4,32 @@ #include "tx_audio_app.h" -static int app_tx_audio_next_frame(void* priv, uint16_t* next_frame_idx, - struct st30_tx_frame_meta* meta) { - struct st_app_tx_audio_session* s = priv; +static int app_tx_audio_next_frame(void *priv, uint16_t *next_frame_idx, + struct st30_tx_frame_meta *meta) { + struct st_app_tx_audio_session *s = priv; int ret; uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->st30_wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { - dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, - s->idx, consumer_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, st30_get_sample_rate(s->sampling))); + dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", + __func__, s->idx, consumer_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, + st30_get_sample_rate(s->sampling))); ret = 0; framebuff->stat = ST_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, + framebuff->stat); ret = -EIO; } st_pthread_cond_signal(&s->st30_wake_cond); @@ -34,24 +37,25 @@ static int app_tx_audio_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int app_tx_audio_frame_done(void* priv, uint16_t frame_idx, - struct st30_tx_frame_meta* meta) { - struct st_app_tx_audio_session* s = priv; +static int app_tx_audio_frame_done(void *priv, uint16_t frame_idx, + struct st30_tx_frame_meta *meta) { + struct st_app_tx_audio_session *s = priv; int ret; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->st30_wake_mutex); if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { ret = 0; framebuff->stat = ST_TX_FRAME_FREE; - dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, - s->idx, frame_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, st30_get_sample_rate(s->sampling))); + dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", + __func__, s->idx, frame_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, + st30_get_sample_rate(s->sampling))); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->st30_wake_cond); st_pthread_mutex_unlock(&s->st30_wake_mutex); @@ -61,8 +65,8 @@ static int app_tx_audio_frame_done(void* priv, uint16_t frame_idx, return ret; } -static int app_tx_audio_rtp_done(void* priv) { - struct st_app_tx_audio_session* s = priv; +static int app_tx_audio_rtp_done(void *priv) { + struct st_app_tx_audio_session *s = priv; st_pthread_mutex_lock(&s->st30_wake_mutex); st_pthread_cond_signal(&s->st30_wake_cond); st_pthread_mutex_unlock(&s->st30_wake_mutex); @@ -70,10 +74,10 @@ static int app_tx_audio_rtp_done(void* priv) { return 0; } -static void app_tx_audio_build_frame(struct st_app_tx_audio_session* s, void* frame, - size_t frame_size) { - uint8_t* src = s->st30_frame_cursor; - uint8_t* dst = frame; +static void app_tx_audio_build_frame(struct st_app_tx_audio_session *s, + void *frame, size_t frame_size) { + uint8_t *src = s->st30_frame_cursor; + uint8_t *dst = frame; if (s->st30_frame_cursor + frame_size > s->st30_source_end) { /* reset to the start */ @@ -86,11 +90,11 @@ static void app_tx_audio_build_frame(struct st_app_tx_audio_session* s, void* fr } } -static void* app_tx_audio_frame_thread(void* arg) { - struct st_app_tx_audio_session* s = arg; +static void *app_tx_audio_frame_thread(void *arg) { + struct st_app_tx_audio_session *s = arg; int idx = s->idx; uint16_t producer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->st30_app_thread_stop) { @@ -106,7 +110,7 @@ static void* app_tx_audio_frame_thread(void* arg) { } st_pthread_mutex_unlock(&s->st30_wake_mutex); - void* frame_addr = st30_tx_get_framebuffer(s->handle, producer_idx); + void *frame_addr = st30_tx_get_framebuffer(s->handle, producer_idx); app_tx_audio_build_frame(s, frame_addr, s->st30_frame_size); st_pthread_mutex_lock(&s->st30_wake_mutex); @@ -114,7 +118,8 @@ static void* app_tx_audio_frame_thread(void* arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->st30_wake_mutex); } @@ -123,16 +128,16 @@ static void* app_tx_audio_frame_thread(void* arg) { return NULL; } -static void* app_tx_audio_pcap_thread(void* arg) { - struct st_app_tx_audio_session* s = arg; +static void *app_tx_audio_pcap_thread(void *arg) { + struct st_app_tx_audio_session *s = arg; int idx = s->idx; - void* mbuf; - void* usrptr = NULL; + void *mbuf; + void *usrptr = NULL; struct pcap_pkthdr hdr; - uint8_t* packet; - struct ether_header* eth_hdr; - struct ip* ip_hdr; - struct udphdr* udp_hdr; + uint8_t *packet; + struct ether_header *eth_hdr; + struct ip *ip_hdr; + struct udphdr *udp_hdr; uint16_t udp_data_len; info("%s(%d), start\n", __func__, idx); @@ -153,14 +158,14 @@ static void* app_tx_audio_pcap_thread(void* arg) { } } udp_data_len = 0; - packet = (uint8_t*)pcap_next(s->st30_pcap, &hdr); + packet = (uint8_t *)pcap_next(s->st30_pcap, &hdr); if (packet) { - eth_hdr = (struct ether_header*)packet; + eth_hdr = (struct ether_header *)packet; if (ntohs(eth_hdr->ether_type) == ETHERTYPE_IP) { - ip_hdr = (struct ip*)(packet + sizeof(struct ether_header)); + ip_hdr = (struct ip *)(packet + sizeof(struct ether_header)); if (ip_hdr->ip_p == IPPROTO_UDP) { - udp_hdr = - (struct udphdr*)(packet + sizeof(struct ether_header) + sizeof(struct ip)); + udp_hdr = (struct udphdr *)(packet + sizeof(struct ether_header) + + sizeof(struct ip)); udp_data_len = ntohs(udp_hdr->len) - sizeof(struct udphdr); mtl_memcpy(usrptr, packet + sizeof(struct ether_header) + sizeof(struct ip) + @@ -174,7 +179,8 @@ static void* app_tx_audio_pcap_thread(void* arg) { /* open capture file for offline processing */ s->st30_pcap = pcap_open_offline(s->st30_source_url, err_buf); if (s->st30_pcap == NULL) { - err("pcap_open_offline %s() failed: %s\n:", s->st30_source_url, err_buf); + err("pcap_open_offline %s() failed: %s\n:", s->st30_source_url, + err_buf); return NULL; } } @@ -186,11 +192,11 @@ static void* app_tx_audio_pcap_thread(void* arg) { return NULL; } -static void app_tx_audio_build_rtp(struct st_app_tx_audio_session* s, void* usrptr, - uint16_t* mbuf_len) { +static void app_tx_audio_build_rtp(struct st_app_tx_audio_session *s, + void *usrptr, uint16_t *mbuf_len) { /* generate one anc rtp for test purpose */ - struct st_rfc3550_rtp_hdr* rtp = (struct st_rfc3550_rtp_hdr*)usrptr; - uint8_t* payload = (uint8_t*)&rtp[1]; + struct st_rfc3550_rtp_hdr *rtp = (struct st_rfc3550_rtp_hdr *)usrptr; + uint8_t *payload = (uint8_t *)&rtp[1]; /* rtp hdr */ memset(rtp, 0x0, sizeof(*rtp)); rtp->csrc_count = 0; @@ -215,11 +221,11 @@ static void app_tx_audio_build_rtp(struct st_app_tx_audio_session* s, void* usrp *mbuf_len = sizeof(struct st_rfc3550_rtp_hdr) + s->pkt_len; } -static void* app_tx_audio_rtp_thread(void* arg) { - struct st_app_tx_audio_session* s = arg; +static void *app_tx_audio_rtp_thread(void *arg) { + struct st_app_tx_audio_session *s = arg; int idx = s->idx; - void* mbuf; - void* usrptr = NULL; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; info("%s(%d), start\n", __func__, idx); @@ -250,7 +256,7 @@ static void* app_tx_audio_rtp_thread(void* arg) { return NULL; } -static int app_tx_audio_open_source(struct st_app_tx_audio_session* s) { +static int app_tx_audio_open_source(struct st_app_tx_audio_session *s) { if (!s->st30_pcap_input) { struct stat i; @@ -263,7 +269,8 @@ static int app_tx_audio_open_source(struct st_app_tx_audio_session* s) { return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st30_source_fd, 0); + uint8_t *m = + mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st30_source_fd, 0); if (MAP_FAILED != m) { s->st30_source_begin = m; @@ -293,7 +300,7 @@ static int app_tx_audio_open_source(struct st_app_tx_audio_session* s) { return 0; } -static int app_tx_audio_close_source(struct st_app_tx_audio_session* s) { +static int app_tx_audio_close_source(struct st_app_tx_audio_session *s) { if (s->st30_source_fd >= 0) { munmap(s->st30_source_begin, s->st30_source_end - s->st30_source_begin); close(s->st30_source_fd); @@ -307,17 +314,20 @@ static int app_tx_audio_close_source(struct st_app_tx_audio_session* s) { return 0; } -static int app_tx_audio_start_source(struct st_app_tx_audio_session* s) { +static int app_tx_audio_start_source(struct st_app_tx_audio_session *s) { int ret = -EINVAL; int idx = s->idx; s->st30_app_thread_stop = false; if (s->st30_pcap_input) - ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_pcap_thread, (void*)s); + ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_pcap_thread, + (void *)s); else if (s->st30_rtp_input) - ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_rtp_thread, (void*)s); + ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_rtp_thread, + (void *)s); else - ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_frame_thread, (void*)s); + ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_frame_thread, + (void *)s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); @@ -331,25 +341,27 @@ static int app_tx_audio_start_source(struct st_app_tx_audio_session* s) { return 0; } -static void app_tx_audio_stop_source(struct st_app_tx_audio_session* s) { +static void app_tx_audio_stop_source(struct st_app_tx_audio_session *s) { if (s->st30_source_fd >= 0 || s->st30_pcap) { s->st30_app_thread_stop = true; /* wake up the thread */ st_pthread_mutex_lock(&s->st30_wake_mutex); st_pthread_cond_signal(&s->st30_wake_cond); st_pthread_mutex_unlock(&s->st30_wake_mutex); - if (s->st30_app_thread) (void)pthread_join(s->st30_app_thread, NULL); + if (s->st30_app_thread) + (void)pthread_join(s->st30_app_thread, NULL); } } -static int app_tx_audio_uinit(struct st_app_tx_audio_session* s) { +static int app_tx_audio_uinit(struct st_app_tx_audio_session *s) { int ret; app_tx_audio_stop_source(s); if (s->handle) { ret = st30_tx_free(s->handle); - if (ret < 0) err("%s(%d), st30_tx_free fail %d\n", __func__, s->idx, ret); + if (ret < 0) + err("%s(%d), st30_tx_free fail %d\n", __func__, s->idx, ret); s->handle = NULL; } @@ -364,8 +376,9 @@ static int app_tx_audio_uinit(struct st_app_tx_audio_session* s) { return 0; } -static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t* audio, - struct st_app_tx_audio_session* s) { +static int app_tx_audio_init(struct st_app_context *ctx, + st_json_audio_session_t *audio, + struct st_app_tx_audio_session *s) { int idx = s->idx, ret; struct st30_tx_ops ops; char name[32]; @@ -375,8 +388,8 @@ static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t s->framebuff_cnt = 2; s->st30_seq_id = 1; - s->framebuffs = - (struct st_tx_frame*)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); + s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * + s->framebuff_cnt); if (!s->framebuffs) { return -ENOMEM; } @@ -400,31 +413,36 @@ static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = audio ? audio->base.udp_port : (10100 + s->idx); + snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + audio ? audio->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = + audio ? audio->base.udp_port : (10100 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); ops.flags |= ST30_TX_FLAG_USER_P_MAC; } - if (ctx->tx_audio_build_pacing) ops.flags |= ST30_TX_FLAG_BUILD_PACING; - if (ctx->tx_audio_dedicate_queue) ops.flags |= ST30_TX_FLAG_DEDICATE_QUEUE; + if (ctx->tx_audio_build_pacing) + ops.flags |= ST30_TX_FLAG_BUILD_PACING; + if (ctx->tx_audio_dedicate_queue) + ops.flags |= ST30_TX_FLAG_DEDICATE_QUEUE; ops.pacing_way = ctx->tx_audio_pacing_way; - if (ctx->tx_audio_fifo_size) ops.fifo_size = ctx->tx_audio_fifo_size; + if (ctx->tx_audio_fifo_size) + ops.fifo_size = ctx->tx_audio_fifo_size; if (ops.num_port > 1) { memcpy(ops.dip_addr[MTL_SESSION_PORT_R], audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = audio ? audio->base.udp_port : (10100 + s->idx); + snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + audio ? audio->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = + audio ? audio->base.udp_port : (10100 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], - MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], + ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); ops.flags |= ST30_TX_FLAG_USER_R_MAC; } } @@ -437,7 +455,8 @@ static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t ops.sampling = audio ? audio->info.audio_sampling : ST30_SAMPLING_48K; ops.ptime = audio ? audio->info.audio_ptime : ST30_PTIME_1MS; s->sampling = ops.sampling; - s->pkt_len = st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); + s->pkt_len = + st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); if (s->pkt_len < 0) { err("%s(%d), st30_get_packet_size fail\n", __func__, idx); app_tx_audio_uinit(s); @@ -453,7 +472,8 @@ static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t s->st30_frame_size = pkt_per_frame * s->pkt_len; ops.framebuff_size = s->st30_frame_size; - ops.payload_type = audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.payload_type = + audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; s->st30_pcap_input = false; ops.type = audio ? audio->info.type : ST30_TYPE_FRAME_LEVEL; @@ -472,7 +492,8 @@ static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t else ops.rtp_ring_size = 16; } - if (audio && audio->enable_rtcp) ops.flags |= ST30_TX_FLAG_ENABLE_RTCP; + if (audio && audio->enable_rtcp) + ops.flags |= ST30_TX_FLAG_ENABLE_RTCP; ops.rl_accuracy_ns = ctx->tx_audio_rl_accuracy_us * 1000; ops.rl_offset_ns = ctx->tx_audio_rl_offset_us * 1000; @@ -499,7 +520,8 @@ static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t ret = app_tx_audio_start_source(s); if (ret < 0) { - err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, ret); + err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, + ret); app_tx_audio_uinit(s); return ret; } @@ -507,9 +529,10 @@ static int app_tx_audio_init(struct st_app_context* ctx, st_json_audio_session_t return 0; } -int st_app_tx_audio_sessions_stop(struct st_app_context* ctx) { - struct st_app_tx_audio_session* s; - if (!ctx->tx_audio_sessions) return 0; +int st_app_tx_audio_sessions_stop(struct st_app_context *ctx) { + struct st_app_tx_audio_session *s; + if (!ctx->tx_audio_sessions) + return 0; for (int i = 0; i < ctx->tx_audio_session_cnt; i++) { s = &ctx->tx_audio_sessions[i]; app_tx_audio_stop_source(s); @@ -518,12 +541,13 @@ int st_app_tx_audio_sessions_stop(struct st_app_context* ctx) { return 0; } -int st_app_tx_audio_sessions_init(struct st_app_context* ctx) { +int st_app_tx_audio_sessions_init(struct st_app_context *ctx) { int ret; - struct st_app_tx_audio_session* s; - ctx->tx_audio_sessions = (struct st_app_tx_audio_session*)st_app_zmalloc( + struct st_app_tx_audio_session *s; + ctx->tx_audio_sessions = (struct st_app_tx_audio_session *)st_app_zmalloc( sizeof(struct st_app_tx_audio_session) * ctx->tx_audio_session_cnt); - if (!ctx->tx_audio_sessions) return -ENOMEM; + if (!ctx->tx_audio_sessions) + return -ENOMEM; for (int i = 0; i < ctx->tx_audio_session_cnt; i++) { s = &ctx->tx_audio_sessions[i]; @@ -539,10 +563,11 @@ int st_app_tx_audio_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_tx_audio_sessions_uinit(struct st_app_context* ctx) { - struct st_app_tx_audio_session* s; +int st_app_tx_audio_sessions_uinit(struct st_app_context *ctx) { + struct st_app_tx_audio_session *s; - if (!ctx->tx_audio_sessions) return 0; + if (!ctx->tx_audio_sessions) + return 0; for (int i = 0; i < ctx->tx_audio_session_cnt; i++) { s = &ctx->tx_audio_sessions[i]; diff --git a/app/src/legacy/tx_audio_app.h b/app/src/legacy/tx_audio_app.h index 89991b03c..457271a14 100644 --- a/app/src/legacy/tx_audio_app.h +++ b/app/src/legacy/tx_audio_app.h @@ -12,9 +12,9 @@ #ifndef _TX_APP_AUDIO_HEAD_H_ #define _TX_APP_AUDIO_HEAD_H_ -int st_app_tx_audio_sessions_init(struct st_app_context* ctx); +int st_app_tx_audio_sessions_init(struct st_app_context *ctx); -int st_app_tx_audio_sessions_uinit(struct st_app_context* ctx); +int st_app_tx_audio_sessions_uinit(struct st_app_context *ctx); -int st_app_tx_audio_sessions_stop(struct st_app_context* ctx); +int st_app_tx_audio_sessions_stop(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/legacy/tx_st22_app.c b/app/src/legacy/tx_st22_app.c index 27857a812..0fd746c2b 100644 --- a/app/src/legacy/tx_st22_app.c +++ b/app/src/legacy/tx_st22_app.c @@ -4,12 +4,12 @@ #include "tx_st22_app.h" -static int app_tx_st22_next_frame(void* priv, uint16_t* next_frame_idx, - struct st22_tx_frame_meta* meta) { - struct st22_app_tx_session* s = priv; +static int app_tx_st22_next_frame(void *priv, uint16_t *next_frame_idx, + struct st22_tx_frame_meta *meta) { + struct st22_app_tx_session *s = priv; int ret; uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->wake_mutex); @@ -21,12 +21,14 @@ static int app_tx_st22_next_frame(void* priv, uint16_t* next_frame_idx, meta->codestream_size = framebuff->size; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ ret = -EIO; - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, + framebuff->stat); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -34,11 +36,11 @@ static int app_tx_st22_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int app_tx_st22_frame_done(void* priv, uint16_t frame_idx, - struct st22_tx_frame_meta* meta) { - struct st22_app_tx_session* s = priv; +static int app_tx_st22_frame_done(void *priv, uint16_t frame_idx, + struct st22_tx_frame_meta *meta) { + struct st22_app_tx_session *s = priv; int ret; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->wake_mutex); @@ -49,8 +51,8 @@ static int app_tx_st22_frame_done(void* priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -58,10 +60,12 @@ static int app_tx_st22_frame_done(void* priv, uint16_t frame_idx, return ret; } -static void app_tx_st22_build_frame(struct st22_app_tx_session* s, void* codestream_addr, - size_t max_codestream_size, size_t* codestream_size) { - uint8_t* src = s->st22_frame_cursor; - uint8_t* dst = codestream_addr; +static void app_tx_st22_build_frame(struct st22_app_tx_session *s, + void *codestream_addr, + size_t max_codestream_size, + size_t *codestream_size) { + uint8_t *src = s->st22_frame_cursor; + uint8_t *dst = codestream_addr; int framesize = s->bytes_per_frame; MTL_MAY_UNUSED(max_codestream_size); @@ -77,11 +81,11 @@ static void app_tx_st22_build_frame(struct st22_app_tx_session* s, void* codestr *codestream_size = framesize; } -static void* app_tx_st22_frame_thread(void* arg) { - struct st22_app_tx_session* s = arg; +static void *app_tx_st22_frame_thread(void *arg) { + struct st22_app_tx_session *s = arg; int idx = s->idx; uint16_t producer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->st22_app_thread_stop) { @@ -90,13 +94,14 @@ static void* app_tx_st22_frame_thread(void* arg) { framebuff = &s->framebuffs[producer_idx]; if (ST_TX_FRAME_FREE != framebuff->stat) { /* not in free */ - if (!s->st22_app_thread_stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->st22_app_thread_stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } st_pthread_mutex_unlock(&s->wake_mutex); - void* frame_addr = st22_tx_get_fb_addr(s->handle, producer_idx); + void *frame_addr = st22_tx_get_fb_addr(s->handle, producer_idx); size_t max_framesize = s->bytes_per_frame; size_t codestream_size = s->bytes_per_frame; app_tx_st22_build_frame(s, frame_addr, max_framesize, &codestream_size); @@ -106,7 +111,8 @@ static void* app_tx_st22_frame_thread(void* arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -115,7 +121,7 @@ static void* app_tx_st22_frame_thread(void* arg) { return NULL; } -static void app_tx_st22_stop_source(struct st22_app_tx_session* s) { +static void app_tx_st22_stop_source(struct st22_app_tx_session *s) { s->st22_app_thread_stop = true; /* wake up the thread */ st_pthread_mutex_lock(&s->wake_mutex); @@ -127,7 +133,7 @@ static void app_tx_st22_stop_source(struct st22_app_tx_session* s) { } } -static int app_tx_st22_start_source(struct st22_app_tx_session* s) { +static int app_tx_st22_start_source(struct st22_app_tx_session *s) { int ret = -EINVAL; int idx = s->idx; @@ -145,7 +151,7 @@ static int app_tx_st22_start_source(struct st22_app_tx_session* s) { return 0; } -static int app_tx_st22_close_source(struct st22_app_tx_session* s) { +static int app_tx_st22_close_source(struct st22_app_tx_session *s) { if (s->st22_source_fd >= 0) { munmap(s->st22_source_begin, s->st22_source_end - s->st22_source_begin); close(s->st22_source_fd); @@ -155,7 +161,7 @@ static int app_tx_st22_close_source(struct st22_app_tx_session* s) { return 0; } -static int app_tx_st22_open_source(struct st22_app_tx_session* s) { +static int app_tx_st22_open_source(struct st22_app_tx_session *s) { int fd; struct stat i; @@ -171,13 +177,13 @@ static int app_tx_st22_open_source(struct st22_app_tx_session* s) { return -EIO; } if (i.st_size < s->bytes_per_frame) { - err("%s, %s file size small then a frame %" PRIu64 "\n", __func__, s->st22_source_url, - s->bytes_per_frame); + err("%s, %s file size small then a frame %" PRIu64 "\n", __func__, + s->st22_source_url, s->bytes_per_frame); close(fd); return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s, mmap %s fail\n", __func__, s->st22_source_url); close(fd); @@ -192,20 +198,21 @@ static int app_tx_st22_open_source(struct st22_app_tx_session* s) { return 0; } -static int app_tx_st22_handle_free(struct st22_app_tx_session* s) { +static int app_tx_st22_handle_free(struct st22_app_tx_session *s) { int ret; int idx = s->idx; if (s->handle) { ret = st22_tx_free(s->handle); - if (ret < 0) err("%s(%d), st22_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st22_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_tx_st22_uinit(struct st22_app_tx_session* s) { +static int app_tx_st22_uinit(struct st22_app_tx_session *s) { app_tx_st22_stop_source(s); app_tx_st22_handle_free(s); app_tx_st22_close_source(s); @@ -221,8 +228,8 @@ static int app_tx_st22_uinit(struct st22_app_tx_session* s) { return 0; } -static int app_tx_st22_init(struct st_app_context* ctx, struct st22_app_tx_session* s, - int bpp) { +static int app_tx_st22_init(struct st_app_context *ctx, + struct st22_app_tx_session *s, int bpp) { int idx = s->idx, ret; struct st22_tx_ops ops; char name[32]; @@ -242,7 +249,8 @@ static int app_tx_st22_init(struct st_app_context* ctx, struct st22_app_tx_sessi ops.name = name; ops.priv = s; ops.num_port = ctx->para.num_ports; - memcpy(ops.dip_addr[MTL_SESSION_PORT_P], ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops.dip_addr[MTL_SESSION_PORT_P], ctx->tx_dip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops.udp_port[MTL_SESSION_PORT_P] = 15000 + s->idx; @@ -258,8 +266,8 @@ static int app_tx_st22_init(struct st_app_context* ctx, struct st22_app_tx_sessi ctx->para.port[MTL_PORT_R]); ops.udp_port[MTL_SESSION_PORT_R] = 15000 + s->idx; if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], - MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], + ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); ops.flags |= ST22_TX_FLAG_USER_R_MAC; } } @@ -273,14 +281,16 @@ static int app_tx_st22_init(struct st_app_context* ctx, struct st22_app_tx_sessi ops.framebuff_max_size = s->bytes_per_frame; ops.get_next_frame = app_tx_st22_next_frame; ops.notify_frame_done = app_tx_st22_frame_done; - if (ctx->tx_no_bulk) ops.flags |= ST22_TX_FLAG_DISABLE_BULK; + if (ctx->tx_no_bulk) + ops.flags |= ST22_TX_FLAG_DISABLE_BULK; s->framebuff_cnt = ops.framebuff_cnt; s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = - (struct st_tx_frame*)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); - if (!s->framebuffs) return -ENOMEM; + s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * + s->framebuff_cnt); + if (!s->framebuffs) + return -ENOMEM; for (uint16_t j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].stat = ST_TX_FRAME_FREE; } @@ -311,16 +321,18 @@ static int app_tx_st22_init(struct st_app_context* ctx, struct st22_app_tx_sessi return ret; } - info("%s(%d), bytes_per_frame %" PRIu64 "\n", __func__, idx, s->bytes_per_frame); + info("%s(%d), bytes_per_frame %" PRIu64 "\n", __func__, idx, + s->bytes_per_frame); return 0; } -int st22_app_tx_sessions_init(struct st_app_context* ctx) { +int st22_app_tx_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st22_app_tx_session* s; - ctx->tx_st22_sessions = (struct st22_app_tx_session*)st_app_zmalloc( + struct st22_app_tx_session *s; + ctx->tx_st22_sessions = (struct st22_app_tx_session *)st_app_zmalloc( sizeof(struct st22_app_tx_session) * ctx->tx_st22_session_cnt); - if (!ctx->tx_st22_sessions) return -ENOMEM; + if (!ctx->tx_st22_sessions) + return -ENOMEM; for (i = 0; i < ctx->tx_st22_session_cnt; i++) { s = &ctx->tx_st22_sessions[i]; s->idx = i; @@ -334,9 +346,10 @@ int st22_app_tx_sessions_init(struct st_app_context* ctx) { return 0; } -int st22_app_tx_sessions_stop(struct st_app_context* ctx) { - struct st22_app_tx_session* s; - if (!ctx->tx_st22_sessions) return 0; +int st22_app_tx_sessions_stop(struct st_app_context *ctx) { + struct st22_app_tx_session *s; + if (!ctx->tx_st22_sessions) + return 0; for (int i = 0; i < ctx->tx_st22_session_cnt; i++) { s = &ctx->tx_st22_sessions[i]; app_tx_st22_stop_source(s); @@ -345,10 +358,11 @@ int st22_app_tx_sessions_stop(struct st_app_context* ctx) { return 0; } -int st22_app_tx_sessions_uinit(struct st_app_context* ctx) { +int st22_app_tx_sessions_uinit(struct st_app_context *ctx) { int i; - struct st22_app_tx_session* s; - if (!ctx->tx_st22_sessions) return 0; + struct st22_app_tx_session *s; + if (!ctx->tx_st22_sessions) + return 0; for (i = 0; i < ctx->tx_st22_session_cnt; i++) { s = &ctx->tx_st22_sessions[i]; s->idx = i; diff --git a/app/src/legacy/tx_st22_app.h b/app/src/legacy/tx_st22_app.h index d687ea2ee..46b9c357d 100644 --- a/app/src/legacy/tx_st22_app.h +++ b/app/src/legacy/tx_st22_app.h @@ -14,8 +14,8 @@ #ifndef _TX_APP_ST22_HEAD_H_ #define _TX_APP_ST22_HEAD_H_ -int st22_app_tx_sessions_init(struct st_app_context* ctx); -int st22_app_tx_sessions_stop(struct st_app_context* ctx); -int st22_app_tx_sessions_uinit(struct st_app_context* ctx); +int st22_app_tx_sessions_init(struct st_app_context *ctx); +int st22_app_tx_sessions_stop(struct st_app_context *ctx); +int st22_app_tx_sessions_uinit(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/legacy/tx_video_app.c b/app/src/legacy/tx_video_app.c index 7180f75cd..c0f61d33c 100644 --- a/app/src/legacy/tx_video_app.c +++ b/app/src/legacy/tx_video_app.c @@ -4,10 +4,11 @@ #include "tx_video_app.h" -static int app_tx_video_notify_event(void* priv, enum st_event event, void* args) { - struct st_app_tx_video_session* s = priv; +static int app_tx_video_notify_event(void *priv, enum st_event event, + void *args) { + struct st_app_tx_video_session *s = priv; if (event == ST_EVENT_VSYNC) { - struct st10_vsync_meta* meta = args; + struct st10_vsync_meta *meta = args; info("%s(%d), epoch %" PRIu64 "\n", __func__, s->idx, meta->epoch); } else if (event == ST_EVENT_FATAL_ERROR) { err("%s(%d), ST_EVENT_FATAL_ERROR\n", __func__, s->idx); @@ -18,15 +19,17 @@ static int app_tx_video_notify_event(void* priv, enum st_event event, void* args return 0; } -static void app_tx_video_display_frame(struct st_app_tx_video_session* s, void* frame) { - struct st_display* d = s->display; +static void app_tx_video_display_frame(struct st_app_tx_video_session *s, + void *frame) { + struct st_display *d = s->display; if (d && d->front_frame) { if (st_pthread_mutex_trylock(&d->display_frame_mutex) == 0) { if (s->st20_pg.fmt == ST20_FMT_YUV_422_8BIT) mtl_memcpy(d->front_frame, frame, d->front_frame_size); else if (s->st20_pg.fmt == ST20_FMT_YUV_422_10BIT) - st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, s->height); + st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, + s->height); else /* fmt mismatch*/ { st_pthread_mutex_unlock(&d->display_frame_mutex); return; @@ -39,19 +42,20 @@ static void app_tx_video_display_frame(struct st_app_tx_video_session* s, void* } } -static int app_tx_video_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct st_app_tx_video_session* s = priv; +static int app_tx_video_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct st_app_tx_video_session *s = priv; int ret; uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->st20_wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { - dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, - s->idx, consumer_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", + __func__, s->idx, consumer_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, + ST10_VIDEO_SAMPLING_RATE_90K)); ret = 0; framebuff->stat = ST_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = consumer_idx; @@ -62,12 +66,14 @@ static int app_tx_video_next_frame(void* priv, uint16_t* next_frame_idx, } /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ ret = -EIO; - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, + framebuff->stat); } st_pthread_cond_signal(&s->st20_wake_cond); st_pthread_mutex_unlock(&s->st20_wake_mutex); @@ -75,24 +81,25 @@ static int app_tx_video_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int app_tx_video_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - struct st_app_tx_video_session* s = priv; +static int app_tx_video_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct st_app_tx_video_session *s = priv; int ret; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->st20_wake_mutex); if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { ret = 0; framebuff->stat = ST_TX_FRAME_FREE; - dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, - s->idx, frame_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", + __func__, s->idx, frame_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, + ST10_VIDEO_SAMPLING_RATE_90K)); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->st20_wake_cond); st_pthread_mutex_unlock(&s->st20_wake_mutex); @@ -104,10 +111,10 @@ static int app_tx_video_frame_done(void* priv, uint16_t frame_idx, return ret; } -static int app_tx_video_frame_lines_ready(void* priv, uint16_t frame_idx, - struct st20_tx_slice_meta* meta) { - struct st_app_tx_video_session* s = priv; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; +static int app_tx_video_frame_lines_ready(void *priv, uint16_t frame_idx, + struct st20_tx_slice_meta *meta) { + struct st_app_tx_video_session *s = priv; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; st_pthread_mutex_lock(&s->st20_wake_mutex); framebuff->slice_trigger = true; @@ -119,8 +126,8 @@ static int app_tx_video_frame_lines_ready(void* priv, uint16_t frame_idx, return 0; } -static int app_tx_video_rtp_done(void* priv) { - struct st_app_tx_video_session* s = priv; +static int app_tx_video_rtp_done(void *priv) { + struct st_app_tx_video_session *s = priv; st_pthread_mutex_lock(&s->st20_wake_mutex); st_pthread_cond_signal(&s->st20_wake_cond); @@ -129,13 +136,14 @@ static int app_tx_video_rtp_done(void* priv) { return 0; } -static void app_tx_video_thread_bind(struct st_app_tx_video_session* s) { +static void app_tx_video_thread_bind(struct st_app_tx_video_session *s) { if (s->lcore != -1) { mtl_bind_to_lcore(s->st, pthread_self(), s->lcore); } } -static void app_tx_video_check_lcore(struct st_app_tx_video_session* s, bool rtp) { +static void app_tx_video_check_lcore(struct st_app_tx_video_session *s, + bool rtp) { int sch_idx = st20_tx_get_sch_idx(s->handle); if (s->ctx->app_bind_lcore && (s->handle_sch_idx != sch_idx)) { @@ -150,9 +158,9 @@ static void app_tx_video_check_lcore(struct st_app_tx_video_session* s, bool rtp } } -static void app_tx_video_build_frame(struct st_app_tx_video_session* s, void* frame, - size_t frame_size) { - uint8_t* src = s->st20_frame_cursor; +static void app_tx_video_build_frame(struct st_app_tx_video_session *s, + void *frame, size_t frame_size) { + uint8_t *src = s->st20_frame_cursor; if (!s->ctx->tx_copy_once || !s->st20_frames_copied) { mtl_memcpy(frame, src, frame_size); @@ -167,8 +175,9 @@ static void app_tx_video_build_frame(struct st_app_tx_video_session* s, void* fr app_tx_video_display_frame(s, frame); } -static void app_tx_video_build_slice(struct st_app_tx_video_session* s, - struct st_tx_frame* framebuff, void* frame_addr) { +static void app_tx_video_build_slice(struct st_app_tx_video_session *s, + struct st_tx_frame *framebuff, + void *frame_addr) { int lines_build = 0; int bytes_per_slice = framebuff->size / s->height * s->lines_per_slice; int frame_size = framebuff->size; @@ -176,8 +185,8 @@ static void app_tx_video_build_slice(struct st_app_tx_video_session* s, if (s->st20_frame_cursor + frame_size > s->st20_source_end) { s->st20_frame_cursor = s->st20_source_begin; } - uint8_t* src = s->st20_frame_cursor; - uint8_t* dst = frame_addr; + uint8_t *src = s->st20_frame_cursor; + uint8_t *dst = frame_addr; /* point to next frame */ s->st20_frame_cursor += frame_size; @@ -197,7 +206,8 @@ static void app_tx_video_build_slice(struct st_app_tx_video_session* s, while (lines_build < s->height) { int lines = s->lines_per_slice; - if ((lines_build + lines) > s->height) lines = s->height - lines_build; + if ((lines_build + lines) > s->height) + lines = s->height - lines_build; int bytes_slice = framebuff->size / s->height * lines; lines_build += lines; @@ -211,11 +221,11 @@ static void app_tx_video_build_slice(struct st_app_tx_video_session* s, } } -static void* app_tx_video_frame_thread(void* arg) { - struct st_app_tx_video_session* s = arg; +static void *app_tx_video_frame_thread(void *arg) { + struct st_app_tx_video_session *s = arg; int idx = s->idx; uint16_t producer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; app_tx_video_thread_bind(s); @@ -235,13 +245,14 @@ static void* app_tx_video_frame_thread(void* arg) { app_tx_video_check_lcore(s, false); - void* frame_addr = st20_tx_get_framebuffer(s->handle, producer_idx); + void *frame_addr = st20_tx_get_framebuffer(s->handle, producer_idx); if (!s->slice) { /* interlaced use different layout? */ app_tx_video_build_frame(s, frame_addr, s->st20_frame_size); } if (s->sha_check) { - st_sha256((unsigned char*)frame_addr, s->st20_frame_size, framebuff->shas); + st_sha256((unsigned char *)frame_addr, s->st20_frame_size, + framebuff->shas); // st_sha_dump("frame sha:", framebuff->shas); } @@ -251,7 +262,8 @@ static void* app_tx_video_frame_thread(void* arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; if (s->interlaced) { s->second_field = !s->second_field; @@ -267,16 +279,16 @@ static void* app_tx_video_frame_thread(void* arg) { return NULL; } -static void* app_tx_video_pcap_thread(void* arg) { - struct st_app_tx_video_session* s = arg; +static void *app_tx_video_pcap_thread(void *arg) { + struct st_app_tx_video_session *s = arg; int idx = s->idx; - void* mbuf; - void* usrptr = NULL; + void *mbuf; + void *usrptr = NULL; struct pcap_pkthdr hdr; - uint8_t* packet; - struct ether_header* eth_hdr; - struct ip* ip_hdr; - struct udphdr* udp_hdr; + uint8_t *packet; + struct ether_header *eth_hdr; + struct ip *ip_hdr; + struct udphdr *udp_hdr; uint16_t udp_data_len; app_tx_video_thread_bind(s); @@ -299,17 +311,18 @@ static void* app_tx_video_pcap_thread(void* arg) { } } udp_data_len = 0; - packet = (uint8_t*)pcap_next(s->st20_pcap, &hdr); + packet = (uint8_t *)pcap_next(s->st20_pcap, &hdr); dbg("%s(%d), packet %p\n", __func__, idx, packet); if (packet) { - eth_hdr = (struct ether_header*)packet; + eth_hdr = (struct ether_header *)packet; if (ntohs(eth_hdr->ether_type) == ETHERTYPE_IP) { - ip_hdr = (struct ip*)(packet + sizeof(struct ether_header)); + ip_hdr = (struct ip *)(packet + sizeof(struct ether_header)); if (ip_hdr->ip_p == IPPROTO_UDP) { - udp_hdr = - (struct udphdr*)(packet + sizeof(struct ether_header) + sizeof(struct ip)); + udp_hdr = (struct udphdr *)(packet + sizeof(struct ether_header) + + sizeof(struct ip)); udp_data_len = ntohs(udp_hdr->len) - sizeof(struct udphdr); - dbg("%s(%d), packet %p udp_data_len %u\n", __func__, idx, packet, udp_data_len); + dbg("%s(%d), packet %p udp_data_len %u\n", __func__, idx, packet, + udp_data_len); mtl_memcpy(usrptr, packet + sizeof(struct ether_header) + sizeof(struct ip) + sizeof(struct udphdr), @@ -322,12 +335,13 @@ static void* app_tx_video_pcap_thread(void* arg) { /* open capture file for offline processing */ s->st20_pcap = pcap_open_offline(s->st20_source_url, err_buf); if (s->st20_pcap == NULL) { - err("pcap_open_offline %s() failed: %s\n:", s->st20_source_url, err_buf); + err("pcap_open_offline %s() failed: %s\n:", s->st20_source_url, + err_buf); return NULL; } } - struct st_rfc3550_rtp_hdr* hdr = (struct st_rfc3550_rtp_hdr*)usrptr; + struct st_rfc3550_rtp_hdr *hdr = (struct st_rfc3550_rtp_hdr *)usrptr; if (hdr->payload_type != s->payload_type) { udp_data_len = 0; err("%s(%d), expect payload_type %u but pcap is %u, please correct the " @@ -344,40 +358,43 @@ static void* app_tx_video_pcap_thread(void* arg) { return NULL; } -static int app_tx_video_init_rtp(struct st_app_tx_video_session* s, - struct st20_tx_ops* ops) { +static int app_tx_video_init_rtp(struct st_app_tx_video_session *s, + struct st20_tx_ops *ops) { int idx = s->idx; - struct st20_rfc4175_rtp_hdr* rtp = &s->st20_rtp_base; + struct st20_rfc4175_rtp_hdr *rtp = &s->st20_rtp_base; /* 4800 if 1080p yuv422 */ s->st20_bytes_in_line = ops->width * s->st20_pg.size / s->st20_pg.coverage; s->st20_pkt_idx = 0; s->st20_seq_id = 1; int height = ops->height; - if (ops->interlaced) height = height >> 1; + if (ops->interlaced) + height = height >> 1; if (ops->packing == ST20_PACKING_GPM_SL) { /* calculate pkts in line for rtp */ size_t bytes_in_pkt = MTL_PKT_MAX_RTP_BYTES - sizeof(*rtp); s->st20_pkts_in_line = (s->st20_bytes_in_line / bytes_in_pkt) + 1; s->st20_total_pkts = height * s->st20_pkts_in_line; - int pixels_in_pkts = (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; + int pixels_in_pkts = + (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; s->st20_pkt_data_len = (pixels_in_pkts + s->st20_pg.coverage - 1) / s->st20_pg.coverage * s->st20_pg.size; info("%s(%d), %d pkts(%d) in line\n", __func__, idx, s->st20_pkts_in_line, s->st20_pkt_data_len); } else if (ops->packing == ST20_PACKING_BPM) { s->st20_pkt_data_len = 1260; - int pixels_in_pkts = s->st20_pkt_data_len * s->st20_pg.coverage / s->st20_pg.size; + int pixels_in_pkts = + s->st20_pkt_data_len * s->st20_pg.coverage / s->st20_pg.size; s->st20_total_pkts = ceil((double)ops->width * height / pixels_in_pkts); info("%s(%d), %d pkts(%d) in frame\n", __func__, idx, s->st20_total_pkts, s->st20_pkt_data_len); } else if (ops->packing == ST20_PACKING_GPM) { - int max_data_len = - MTL_PKT_MAX_RTP_BYTES - sizeof(*rtp) - sizeof(struct st20_rfc4175_extra_rtp_hdr); + int max_data_len = MTL_PKT_MAX_RTP_BYTES - sizeof(*rtp) - + sizeof(struct st20_rfc4175_extra_rtp_hdr); int pg_per_pkt = max_data_len / s->st20_pg.size; - s->st20_total_pkts = - (ceil)((double)ops->width * height / (s->st20_pg.coverage * pg_per_pkt)); + s->st20_total_pkts = (ceil)((double)ops->width * height / + (s->st20_pg.coverage * pg_per_pkt)); s->st20_pkt_data_len = pg_per_pkt * s->st20_pg.size; } else { err("%s(%d), invalid packing mode: %d\n", __func__, idx, ops->packing); @@ -401,27 +418,31 @@ static int app_tx_video_init_rtp(struct st_app_tx_video_session* s, return 0; } -static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session* s, - struct st20_rfc4175_rtp_hdr* rtp, - uint16_t* pkt_len) { - struct st20_rfc4175_extra_rtp_hdr* e_rtp = NULL; +static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session *s, + struct st20_rfc4175_rtp_hdr *rtp, + uint16_t *pkt_len) { + struct st20_rfc4175_extra_rtp_hdr *e_rtp = NULL; uint32_t offset; uint16_t row_number, row_offset; - uint8_t* frame = s->st20_frame_cursor; - uint8_t* payload = (uint8_t*)rtp + sizeof(*rtp); + uint8_t *frame = s->st20_frame_cursor; + uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); if (s->single_line) { row_number = s->st20_pkt_idx / s->st20_pkts_in_line; - int pixels_in_pkt = s->st20_pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; + int pixels_in_pkt = + s->st20_pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; row_offset = pixels_in_pkt * (s->st20_pkt_idx % s->st20_pkts_in_line); - offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; + offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * + s->st20_pg.size; } else { offset = s->st20_pkt_data_len * s->st20_pkt_idx; row_number = offset / s->st20_bytes_in_line; - row_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; - if ((offset + s->st20_pkt_data_len > (row_number + 1) * s->st20_bytes_in_line) && + row_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / + s->st20_pg.size; + if ((offset + s->st20_pkt_data_len > + (row_number + 1) * s->st20_bytes_in_line) && (offset + s->st20_pkt_data_len < s->st20_frame_size)) { - e_rtp = (struct st20_rfc4175_extra_rtp_hdr*)payload; + e_rtp = (struct st20_rfc4175_extra_rtp_hdr *)payload; payload += sizeof(*e_rtp); } } @@ -439,9 +460,10 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session* s, rtp->seq_number_ext = htons((uint16_t)(s->st20_seq_id >> 16)); s->st20_seq_id++; - int temp = s->single_line - ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (s->st20_frame_size - offset); + int temp = + s->single_line + ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (s->st20_frame_size - offset); uint16_t data_len = s->st20_pkt_data_len > temp ? temp : s->st20_pkt_data_len; rtp->row_length = htons(data_len); *pkt_len = data_len + sizeof(*rtp); @@ -470,8 +492,8 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session* s, data_len); else mtl_memcpy(payload, - frame + (2 * row_number * s->width + row_offset) / s->st20_pg.coverage * - s->st20_pg.size, + frame + (2 * row_number * s->width + row_offset) / + s->st20_pg.coverage * s->st20_pg.size, data_len); } @@ -486,11 +508,13 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session* s, s->st20_frame_done_cnt++; if (!s->stat_frame_first_tx_time) s->stat_frame_first_tx_time = st_app_get_monotonic_time(); - int frame_size = s->interlaced ? s->st20_frame_size * 2 : s->st20_frame_size; + int frame_size = + s->interlaced ? s->st20_frame_size * 2 : s->st20_frame_size; if (!s->interlaced) { s->st20_frame_cursor += frame_size; } else { - if (s->st20_second_field) s->st20_frame_cursor += frame_size; + if (s->st20_second_field) + s->st20_frame_cursor += frame_size; s->st20_second_field = !s->st20_second_field; } if ((s->st20_frame_cursor + frame_size) > s->st20_source_end) @@ -500,11 +524,11 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session* s, return 0; } -static void* app_tx_video_rtp_thread(void* arg) { - struct st_app_tx_video_session* s = arg; +static void *app_tx_video_rtp_thread(void *arg) { + struct st_app_tx_video_session *s = arg; int idx = s->idx; - void* mbuf; - void* usrptr = NULL; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; app_tx_video_thread_bind(s); @@ -528,7 +552,8 @@ static void* app_tx_video_rtp_thread(void* arg) { } /* build the rtp pkt */ - app_tx_video_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr*)usrptr, &mbuf_len); + app_tx_video_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr *)usrptr, + &mbuf_len); st20_tx_put_mbuf(s->handle, mbuf, mbuf_len); @@ -539,7 +564,7 @@ static void* app_tx_video_rtp_thread(void* arg) { return NULL; } -static int app_tx_video_open_source(struct st_app_tx_video_session* s) { +static int app_tx_video_open_source(struct st_app_tx_video_session *s) { if (!s->st20_pcap_input) { int fd; struct stat i; @@ -556,13 +581,13 @@ static int app_tx_video_open_source(struct st_app_tx_video_session* s) { return -EIO; } if (i.st_size < s->st20_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, s->st20_source_url, - s->st20_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, + s->st20_source_url, s->st20_frame_size); close(fd); return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s, mmap fail '%s'\n", __func__, s->st20_source_url); close(fd); @@ -596,16 +621,18 @@ static int app_tx_video_open_source(struct st_app_tx_video_session* s) { return 0; } -static int app_tx_video_start_source(struct st_app_tx_video_session* s) { +static int app_tx_video_start_source(struct st_app_tx_video_session *s) { int ret = -EINVAL; int idx = s->idx; if (s->st20_pcap_input) - ret = pthread_create(&s->st20_app_thread, NULL, app_tx_video_pcap_thread, s); + ret = + pthread_create(&s->st20_app_thread, NULL, app_tx_video_pcap_thread, s); else if (s->st20_rtp_input) ret = pthread_create(&s->st20_app_thread, NULL, app_tx_video_rtp_thread, s); else - ret = pthread_create(&s->st20_app_thread, NULL, app_tx_video_frame_thread, s); + ret = + pthread_create(&s->st20_app_thread, NULL, app_tx_video_frame_thread, s); if (ret < 0) { err("%s(%d), st20_app_thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -619,7 +646,7 @@ static int app_tx_video_start_source(struct st_app_tx_video_session* s) { return 0; } -static void app_tx_video_stop_source(struct st_app_tx_video_session* s) { +static void app_tx_video_stop_source(struct st_app_tx_video_session *s) { s->st20_app_thread_stop = true; /* wake up the thread */ st_pthread_mutex_lock(&s->st20_wake_mutex); @@ -631,7 +658,7 @@ static void app_tx_video_stop_source(struct st_app_tx_video_session* s) { } } -static int app_tx_video_close_source(struct st_app_tx_video_session* s) { +static int app_tx_video_close_source(struct st_app_tx_video_session *s) { if (s->st20_source_fd < 0 && s->st20_source_begin) { mtl_hp_free(s->st, s->st20_source_begin); s->st20_source_begin = NULL; @@ -649,20 +676,21 @@ static int app_tx_video_close_source(struct st_app_tx_video_session* s) { return 0; } -static int app_tx_video_handle_free(struct st_app_tx_video_session* s) { +static int app_tx_video_handle_free(struct st_app_tx_video_session *s) { int ret; int idx = s->idx; if (s->handle) { ret = st20_tx_free(s->handle); - if (ret < 0) err("%s(%d), st20_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st20_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_tx_video_uinit(struct st_app_tx_video_session* s) { +static int app_tx_video_uinit(struct st_app_tx_video_session *s) { app_tx_video_stop_source(s); app_tx_video_handle_free(s); app_tx_video_close_source(s); @@ -682,22 +710,25 @@ static int app_tx_video_uinit(struct st_app_tx_video_session* s) { return 0; } -static int app_tx_video_result(struct st_app_tx_video_session* s) { +static int app_tx_video_result(struct st_app_tx_video_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_tx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_tx_time) / NS_PER_S; double framerate = s->st20_frame_done_cnt / time_sec; - if (!s->st20_frame_done_cnt) return -EINVAL; + if (!s->st20_frame_done_cnt) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frames send\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) + ? "OK" + : "FAILED", framerate, s->st20_frame_done_cnt); return 0; } -static int app_tx_video_io_stat(struct st_app_tx_video_session* s) { +static int app_tx_video_io_stat(struct st_app_tx_video_session *s) { int idx = s->idx; uint64_t cur_time = st_app_get_monotonic_time(); double time_sec = (double)(cur_time - s->last_stat_time_ns) / NS_PER_S; @@ -705,11 +736,13 @@ static int app_tx_video_io_stat(struct st_app_tx_video_session* s) { int ret; struct st20_tx_port_status stats; - if (!s->handle) return 0; + if (!s->handle) + return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20_tx_get_port_stats(s->handle, port, &stats); - if (ret < 0) return ret; + if (ret < 0) + return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -721,8 +754,9 @@ static int app_tx_video_io_stat(struct st_app_tx_video_session* s) { return 0; } -static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t* video, - struct st_app_tx_video_session* s) { +static int app_tx_video_init(struct st_app_context *ctx, + st_json_video_session_t *video, + struct st_app_tx_video_session *s) { int idx = s->idx, ret; struct st20_tx_ops ops; char name[32]; @@ -742,10 +776,11 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = video ? video->base.udp_port : (10000 + s->idx); + snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = + video ? video->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -756,13 +791,14 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf( - ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = video ? video->base.udp_port : (10000 + s->idx); + snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = + video ? video->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], - MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], + ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); ops.flags |= ST20_TX_FLAG_USER_R_MAC; } } @@ -775,22 +811,29 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t ops.height = video ? st_app_get_height(video->info.video_format) : 1080; ops.fps = video ? st_app_get_fps(video->info.video_format) : ST_FPS_P59_94; ops.fmt = video ? video->info.pg_format : ST20_FMT_YUV_422_10BIT; - ops.interlaced = video ? st_app_get_interlaced(video->info.video_format) : false; + ops.interlaced = + video ? st_app_get_interlaced(video->info.video_format) : false; ops.get_next_frame = app_tx_video_next_frame; ops.notify_frame_done = app_tx_video_frame_done; ops.query_frame_lines_ready = app_tx_video_frame_lines_ready; ops.notify_rtp_done = app_tx_video_rtp_done; ops.notify_event = app_tx_video_notify_event; ops.framebuff_cnt = 2; - ops.payload_type = video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.payload_type = + video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.start_vrx = ctx->tx_start_vrx; ops.pad_interval = ctx->tx_pad_interval; ops.rtp_timestamp_delta_us = ctx->tx_ts_delta_us; - if (s->enable_vsync) ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; - if (ctx->tx_no_static_pad) ops.flags |= ST20_TX_FLAG_DISABLE_STATIC_PAD_P; - if (ctx->tx_ts_first_pkt) ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; - if (ctx->tx_ts_epoch) ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH; - if (ctx->tx_no_bulk) ops.flags |= ST20_TX_FLAG_DISABLE_BULK; + if (s->enable_vsync) + ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; + if (ctx->tx_no_static_pad) + ops.flags |= ST20_TX_FLAG_DISABLE_STATIC_PAD_P; + if (ctx->tx_ts_first_pkt) + ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; + if (ctx->tx_ts_epoch) + ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH; + if (ctx->tx_no_bulk) + ops.flags |= ST20_TX_FLAG_DISABLE_BULK; if (ctx->force_tx_video_numa >= 0) { ops.flags |= ST20_TX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_tx_video_numa; @@ -802,7 +845,8 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t } ret = st20_get_pgroup(ops.fmt, &s->st20_pg); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->width = ops.width; s->height = ops.height; if (ops.interlaced) { @@ -824,8 +868,8 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t s->lines_per_slice = ops.height / 30; s->st20_source_fd = -1; - s->framebuffs = - (struct st_tx_frame*)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); + s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * + s->framebuff_cnt); if (!s->framebuffs) { return -ENOMEM; } @@ -865,11 +909,13 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t s->handle_sch_idx = st20_tx_get_sch_idx(handle); unsigned int lcore; bool rtp = false; - if (ops.type == ST20_TYPE_RTP_LEVEL) rtp = true; + if (ops.type == ST20_TYPE_RTP_LEVEL) + rtp = true; if (ctx->app_bind_lcore) { ret = st_app_video_get_lcore(ctx, s->handle_sch_idx, rtp, &lcore); - if (ret >= 0) s->lcore = lcore; + if (ret >= 0) + s->lcore = lcore; } ret = app_tx_video_open_source(s); @@ -886,7 +932,7 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t } if ((video && video->display) || ctx->tx_display) { - struct st_display* d = st_app_zmalloc(sizeof(struct st_display)); + struct st_display *d = st_app_zmalloc(sizeof(struct st_display)); ret = st_app_init_display(d, name, s->width, s->height, ctx->ttf_file); if (ret < 0) { err("%s(%d), st_app_init_display fail %d\n", __func__, idx, ret); @@ -899,12 +945,13 @@ static int app_tx_video_init(struct st_app_context* ctx, st_json_video_session_t return 0; } -int st_app_tx_video_sessions_init(struct st_app_context* ctx) { +int st_app_tx_video_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_tx_video_session* s; - ctx->tx_video_sessions = (struct st_app_tx_video_session*)st_app_zmalloc( + struct st_app_tx_video_session *s; + ctx->tx_video_sessions = (struct st_app_tx_video_session *)st_app_zmalloc( sizeof(struct st_app_tx_video_session) * ctx->tx_video_session_cnt); - if (!ctx->tx_video_sessions) return -ENOMEM; + if (!ctx->tx_video_sessions) + return -ENOMEM; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; s->idx = i; @@ -920,9 +967,10 @@ int st_app_tx_video_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_tx_video_sessions_stop(struct st_app_context* ctx) { - struct st_app_tx_video_session* s; - if (!ctx->tx_video_sessions) return 0; +int st_app_tx_video_sessions_stop(struct st_app_context *ctx) { + struct st_app_tx_video_session *s; + if (!ctx->tx_video_sessions) + return 0; for (int i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; app_tx_video_stop_source(s); @@ -931,10 +979,11 @@ int st_app_tx_video_sessions_stop(struct st_app_context* ctx) { return 0; } -int st_app_tx_video_sessions_uinit(struct st_app_context* ctx) { +int st_app_tx_video_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_tx_video_session* s; - if (!ctx->tx_video_sessions) return 0; + struct st_app_tx_video_session *s; + if (!ctx->tx_video_sessions) + return 0; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; app_tx_video_uinit(s); @@ -944,10 +993,11 @@ int st_app_tx_video_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_tx_video_sessions_result(struct st_app_context* ctx) { +int st_app_tx_video_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_tx_video_session* s; - if (!ctx->tx_video_sessions) return 0; + struct st_app_tx_video_session *s; + if (!ctx->tx_video_sessions) + return 0; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; @@ -957,10 +1007,11 @@ int st_app_tx_video_sessions_result(struct st_app_context* ctx) { return ret; } -int st_app_tx_videos_io_stat(struct st_app_context* ctx) { +int st_app_tx_videos_io_stat(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_tx_video_session* s; - if (!ctx->tx_video_sessions) return 0; + struct st_app_tx_video_session *s; + if (!ctx->tx_video_sessions) + return 0; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; diff --git a/app/src/legacy/tx_video_app.h b/app/src/legacy/tx_video_app.h index 15bc3c989..39183a7d8 100644 --- a/app/src/legacy/tx_video_app.h +++ b/app/src/legacy/tx_video_app.h @@ -15,14 +15,14 @@ #ifndef _TX_APP_VIDEO_HEAD_H_ #define _TX_APP_VIDEO_HEAD_H_ -int st_app_tx_video_sessions_init(struct st_app_context* ctx); +int st_app_tx_video_sessions_init(struct st_app_context *ctx); -int st_app_tx_video_sessions_stop(struct st_app_context* ctx); +int st_app_tx_video_sessions_stop(struct st_app_context *ctx); -int st_app_tx_video_sessions_uinit(struct st_app_context* ctx); +int st_app_tx_video_sessions_uinit(struct st_app_context *ctx); -int st_app_tx_video_sessions_result(struct st_app_context* ctx); +int st_app_tx_video_sessions_result(struct st_app_context *ctx); -int st_app_tx_videos_io_stat(struct st_app_context* ctx); +int st_app_tx_videos_io_stat(struct st_app_context *ctx); #endif diff --git a/app/src/log.h b/app/src/log.h index 4a3f644cc..4c9ade9c9 100644 --- a/app/src/log.h +++ b/app/src/log.h @@ -13,34 +13,39 @@ enum mtl_log_level app_get_log_level(void); /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_DEBUG) printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_DEBUG) \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_INFO) printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_INFO) \ + printf(__VA_ARGS__); \ } while (0) -#define notce(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_NOTICE) printf(__VA_ARGS__); \ +#define notce(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_NOTICE) \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_WARNING) printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_WARNING) \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_ERR) printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_ERR) \ + printf(__VA_ARGS__); \ } while (0) -#define critical(...) \ - do { \ - printf(__VA_ARGS__); \ +#define critical(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif diff --git a/app/src/parse_json.c b/app/src/parse_json.c index 44dc0e4a8..be34a1f02 100644 --- a/app/src/parse_json.c +++ b/app/src/parse_json.c @@ -7,16 +7,19 @@ #include "app_base.h" #include "log.h" -#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ +#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ (JSON_C_VERSION_NUM < ((0 << 16) | (10 << 8) | 0)) -static inline json_object* st_json_object_object_get(json_object* obj, const char* key) { +static inline json_object *st_json_object_object_get(json_object *obj, + const char *key) { return json_object_object_get(obj, key); } #else -static inline json_object* st_json_object_object_get(json_object* obj, const char* key) { - json_object* value; +static inline json_object *st_json_object_object_get(json_object *obj, + const char *key) { + json_object *value; int ret = json_object_object_get_ex(obj, key, &value); - if (ret) return value; + if (ret) + return value; dbg("%s, can not get object with key: %s!\n", __func__, key); return NULL; } @@ -454,12 +457,12 @@ static const struct st_video_fmt_desc st_video_fmt_descs[] = { #define VNAME(name) (#name) -#define REQUIRED_ITEM(string) \ - do { \ - if (string == NULL) { \ - err("%s, can not parse %s\n", __func__, VNAME(string)); \ - return -ST_JSON_PARSE_FAIL; \ - } \ +#define REQUIRED_ITEM(string) \ + do { \ + if (string == NULL) { \ + err("%s, can not parse %s\n", __func__, VNAME(string)); \ + return -ST_JSON_PARSE_FAIL; \ + } \ } while (0) /* 7 bits payload type define in RFC3550 */ @@ -470,22 +473,24 @@ static inline bool st_json_is_valid_payload_type(int payload_type) { return false; } -static int st_json_parse_interfaces(json_object* interface_obj, - st_json_interface_t* interface) { +static int st_json_parse_interfaces(json_object *interface_obj, + st_json_interface_t *interface) { if (interface_obj == NULL || interface == NULL) { err("%s, can not parse interfaces!\n", __func__); return -ST_JSON_NULL; } - const char* name = + const char *name = json_object_get_string(st_json_object_object_get(interface_obj, "name")); REQUIRED_ITEM(name); snprintf(interface->name, sizeof(interface->name), "%s", name); - const char* ip = json_object_get_string(st_json_object_object_get(interface_obj, "ip")); - if (ip) inet_pton(AF_INET, ip, interface->ip_addr); + const char *ip = + json_object_get_string(st_json_object_object_get(interface_obj, "ip")); + if (ip) + inet_pton(AF_INET, ip, interface->ip_addr); - json_object* obj = st_json_object_object_get(interface_obj, "netmask"); + json_object *obj = st_json_object_object_get(interface_obj, "netmask"); if (obj) { inet_pton(AF_INET, json_object_get_string(obj), interface->netmask); } @@ -495,7 +500,7 @@ static int st_json_parse_interfaces(json_object* interface_obj, } obj = st_json_object_object_get(interface_obj, "proto"); if (obj) { - const char* proto = json_object_get_string(obj); + const char *proto = json_object_get_string(obj); if (strcmp(proto, "dhcp") == 0) { interface->net_proto = MTL_PROTO_DHCP; } else if (strcmp(proto, "static") == 0) { @@ -527,8 +532,10 @@ static int st_json_parse_interfaces(json_object* interface_obj, return ST_JSON_SUCCESS; } -static int parse_base_udp_port(json_object* obj, st_json_session_base_t* base, int idx) { - int start_port = json_object_get_int(st_json_object_object_get(obj, "start_port")); +static int parse_base_udp_port(json_object *obj, st_json_session_base_t *base, + int idx) { + int start_port = + json_object_get_int(st_json_object_object_get(obj, "start_port")); if (start_port <= 0 || start_port > 65535) { err("%s, invalid start port %d\n", __func__, start_port); return -ST_JSON_NOT_VALID; @@ -538,8 +545,10 @@ static int parse_base_udp_port(json_object* obj, st_json_session_base_t* base, i return ST_JSON_SUCCESS; } -static int parse_base_payload_type(json_object* obj, st_json_session_base_t* base) { - json_object* payload_type_object = st_json_object_object_get(obj, "payload_type"); +static int parse_base_payload_type(json_object *obj, + st_json_session_base_t *base) { + json_object *payload_type_object = + st_json_object_object_get(obj, "payload_type"); if (payload_type_object) { base->payload_type = json_object_get_int(payload_type_object); if (!st_json_is_valid_payload_type(base->payload_type)) { @@ -553,8 +562,10 @@ static int parse_base_payload_type(json_object* obj, st_json_session_base_t* bas return ST_JSON_SUCCESS; } -static int parse_video_type(json_object* video_obj, st_json_video_session_t* video) { - const char* type = json_object_get_string(st_json_object_object_get(video_obj, "type")); +static int parse_video_type(json_object *video_obj, + st_json_video_session_t *video) { + const char *type = + json_object_get_string(st_json_object_object_get(video_obj, "type")); REQUIRED_ITEM(type); if (strcmp(type, "frame") == 0) { video->info.type = ST20_TYPE_FRAME_LEVEL; @@ -569,8 +580,9 @@ static int parse_video_type(json_object* video_obj, st_json_video_session_t* vid return ST_JSON_SUCCESS; } -static int parse_video_pacing(json_object* video_obj, st_json_video_session_t* video) { - const char* pacing = +static int parse_video_pacing(json_object *video_obj, + st_json_video_session_t *video) { + const char *pacing = json_object_get_string(st_json_object_object_get(video_obj, "pacing")); REQUIRED_ITEM(pacing); if (strcmp(pacing, "gap") == 0) { @@ -588,8 +600,9 @@ static int parse_video_pacing(json_object* video_obj, st_json_video_session_t* v return ST_JSON_SUCCESS; } -static int parse_video_packing(json_object* video_obj, st_json_video_session_t* video) { - const char* packing = +static int parse_video_packing(json_object *video_obj, + st_json_video_session_t *video) { + const char *packing = json_object_get_string(st_json_object_object_get(video_obj, "packing")); if (packing) { if (strcmp(packing, "GPM_SL") == 0) { @@ -608,8 +621,9 @@ static int parse_video_packing(json_object* video_obj, st_json_video_session_t* return ST_JSON_SUCCESS; } -static int parse_video_tr_offset(json_object* video_obj, st_json_video_session_t* video) { - const char* tr_offset = +static int parse_video_tr_offset(json_object *video_obj, + st_json_video_session_t *video) { + const char *tr_offset = json_object_get_string(st_json_object_object_get(video_obj, "tr_offset")); REQUIRED_ITEM(tr_offset); if (strcmp(tr_offset, "default") == 0) { @@ -623,9 +637,10 @@ static int parse_video_tr_offset(json_object* video_obj, st_json_video_session_t return ST_JSON_SUCCESS; } -static int parse_video_format(json_object* video_obj, st_json_video_session_t* video) { - const char* video_format = - json_object_get_string(st_json_object_object_get(video_obj, "video_format")); +static int parse_video_format(json_object *video_obj, + st_json_video_session_t *video) { + const char *video_format = json_object_get_string( + st_json_object_object_get(video_obj, "video_format")); REQUIRED_ITEM(video_format); int i; for (i = 0; i < ARRAY_SIZE(st_video_fmt_descs); i++) { @@ -638,8 +653,9 @@ static int parse_video_format(json_object* video_obj, st_json_video_session_t* v return -ST_JSON_NOT_VALID; } -static int parse_video_pg_format(json_object* video_obj, st_json_video_session_t* video) { - const char* pg_format = +static int parse_video_pg_format(json_object *video_obj, + st_json_video_session_t *video) { + const char *pg_format = json_object_get_string(st_json_object_object_get(video_obj, "pg_format")); REQUIRED_ITEM(pg_format); if (strcmp(pg_format, "YUV_422_10bit") == 0) { @@ -685,15 +701,16 @@ static int parse_video_pg_format(json_object* video_obj, st_json_video_session_t return ST_JSON_SUCCESS; } -static int parse_url(json_object* obj, const char* name, char* url) { - const char* url_src = json_object_get_string(st_json_object_object_get(obj, name)); +static int parse_url(json_object *obj, const char *name, char *url) { + const char *url_src = + json_object_get_string(st_json_object_object_get(obj, name)); REQUIRED_ITEM(url_src); snprintf(url, ST_APP_URL_MAX_LEN, "%s", url_src); return -ST_JSON_SUCCESS; } -static int st_json_parse_tx_video(int idx, json_object* video_obj, - st_json_video_session_t* video) { +static int st_json_parse_tx_video(int idx, json_object *video_obj, + st_json_video_session_t *video) { if (video_obj == NULL || video == NULL) { err("%s, can not parse tx video session\n", __func__); return -ST_JSON_NULL; @@ -702,7 +719,8 @@ static int st_json_parse_tx_video(int idx, json_object* video_obj, /* parse udp port */ ret = parse_base_udp_port(video_obj, &video->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(video_obj, &video->base); @@ -713,45 +731,52 @@ static int st_json_parse_tx_video(int idx, json_object* video_obj, /* parse video type */ ret = parse_video_type(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse video pacing */ ret = parse_video_pacing(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse video packing mode */ ret = parse_video_packing(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse tr offset */ ret = parse_video_tr_offset(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse video format */ ret = parse_video_format(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse pixel group format */ ret = parse_video_pg_format(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse video url */ ret = parse_url(video_obj, "video_url", video->info.video_url); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse display option */ video->display = json_object_get_boolean(st_json_object_object_get(video_obj, "display")); /* parse enable rtcp */ - video->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(video_obj, "enable_rtcp")); + video->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(video_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int st_json_parse_rx_video(int idx, json_object* video_obj, - st_json_video_session_t* video) { +static int st_json_parse_rx_video(int idx, json_object *video_obj, + st_json_video_session_t *video) { if (video_obj == NULL || video == NULL) { err("%s, can not parse rx video session\n", __func__); return -ST_JSON_NULL; @@ -760,7 +785,8 @@ static int st_json_parse_rx_video(int idx, json_object* video_obj, /* parse udp port */ ret = parse_base_udp_port(video_obj, &video->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(video_obj, &video->base); @@ -771,28 +797,33 @@ static int st_json_parse_rx_video(int idx, json_object* video_obj, /* parse video type */ ret = parse_video_type(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse video pacing */ ret = parse_video_pacing(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse tr offset */ ret = parse_video_tr_offset(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse video format */ ret = parse_video_format(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse pixel group format */ ret = parse_video_pg_format(video_obj, video); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse user pixel group format */ video->user_pg_format = USER_FMT_MAX; - const char* user_pg_format = - json_object_get_string(st_json_object_object_get(video_obj, "user_pg_format")); + const char *user_pg_format = json_object_get_string( + st_json_object_object_get(video_obj, "user_pg_format")); if (user_pg_format != NULL) { if (strcmp(user_pg_format, "YUV_422_8bit") == 0) { video->user_pg_format = USER_FMT_YUV_422_8BIT; @@ -807,18 +838,20 @@ static int st_json_parse_rx_video(int idx, json_object* video_obj, json_object_get_boolean(st_json_object_object_get(video_obj, "display")); /* parse measure_latency option */ - video->measure_latency = - json_object_get_boolean(st_json_object_object_get(video_obj, "measure_latency")); + video->measure_latency = json_object_get_boolean( + st_json_object_object_get(video_obj, "measure_latency")); /* parse enable rtcp */ - video->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(video_obj, "enable_rtcp")); + video->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(video_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int parse_audio_type(json_object* audio_obj, st_json_audio_info_t* audio) { - const char* type = json_object_get_string(st_json_object_object_get(audio_obj, "type")); +static int parse_audio_type(json_object *audio_obj, + st_json_audio_info_t *audio) { + const char *type = + json_object_get_string(st_json_object_object_get(audio_obj, "type")); REQUIRED_ITEM(type); if (strcmp(type, "frame") == 0) { audio->type = ST30_TYPE_FRAME_LEVEL; @@ -831,9 +864,10 @@ static int parse_audio_type(json_object* audio_obj, st_json_audio_info_t* audio) return ST_JSON_SUCCESS; } -static int parse_audio_format(json_object* audio_obj, st_json_audio_info_t* audio) { - const char* audio_format = - json_object_get_string(st_json_object_object_get(audio_obj, "audio_format")); +static int parse_audio_format(json_object *audio_obj, + st_json_audio_info_t *audio) { + const char *audio_format = json_object_get_string( + st_json_object_object_get(audio_obj, "audio_format")); REQUIRED_ITEM(audio_format); if (strcmp(audio_format, "PCM8") == 0) { audio->audio_format = ST30_FMT_PCM8; @@ -850,8 +884,9 @@ static int parse_audio_format(json_object* audio_obj, st_json_audio_info_t* audi return ST_JSON_SUCCESS; } -static int parse_audio_channel(json_object* audio_obj, st_json_audio_info_t* audio) { - json_object* audio_channel_array = +static int parse_audio_channel(json_object *audio_obj, + st_json_audio_info_t *audio) { + json_object *audio_channel_array = st_json_object_object_get(audio_obj, "audio_channel"); if (audio_channel_array == NULL || json_object_get_type(audio_channel_array) != json_type_array) { @@ -860,8 +895,9 @@ static int parse_audio_channel(json_object* audio_obj, st_json_audio_info_t* aud } audio->audio_channel = 0; /* reset channel number*/ for (int i = 0; i < json_object_array_length(audio_channel_array); ++i) { - json_object* channel_obj = json_object_array_get_idx(audio_channel_array, i); - const char* channel = json_object_get_string(channel_obj); + json_object *channel_obj = + json_object_array_get_idx(audio_channel_array, i); + const char *channel = json_object_get_string(channel_obj); REQUIRED_ITEM(channel); if (strcmp(channel, "M") == 0) { audio->audio_channel += 1; @@ -880,7 +916,8 @@ static int parse_audio_channel(json_object* audio_obj, st_json_audio_info_t* aud channel[2] >= '0' && channel[2] <= '9' && channel[3] == '\0') { int num_channel = (channel[1] - '0') * 10 + (channel[2] - '0'); if (num_channel < 1 || num_channel > 64) { - err("%s, audio undefined channel number out of range %s\n", __func__, channel); + err("%s, audio undefined channel number out of range %s\n", __func__, + channel); return -ST_JSON_NOT_VALID; } audio->audio_channel += num_channel; @@ -892,9 +929,10 @@ static int parse_audio_channel(json_object* audio_obj, st_json_audio_info_t* aud return ST_JSON_SUCCESS; } -static int parse_audio_sampling(json_object* audio_obj, st_json_audio_info_t* audio) { - const char* audio_sampling = - json_object_get_string(st_json_object_object_get(audio_obj, "audio_sampling")); +static int parse_audio_sampling(json_object *audio_obj, + st_json_audio_info_t *audio) { + const char *audio_sampling = json_object_get_string( + st_json_object_object_get(audio_obj, "audio_sampling")); REQUIRED_ITEM(audio_sampling); if (strcmp(audio_sampling, "48kHz") == 0) { audio->audio_sampling = ST30_SAMPLING_48K; @@ -909,9 +947,10 @@ static int parse_audio_sampling(json_object* audio_obj, st_json_audio_info_t* au return ST_JSON_SUCCESS; } -static int parse_audio_ptime(json_object* audio_obj, st_json_audio_info_t* audio) { - const char* audio_ptime = - json_object_get_string(st_json_object_object_get(audio_obj, "audio_ptime")); +static int parse_audio_ptime(json_object *audio_obj, + st_json_audio_info_t *audio) { + const char *audio_ptime = json_object_get_string( + st_json_object_object_get(audio_obj, "audio_ptime")); if (audio_ptime) { if (strcmp(audio_ptime, "1") == 0) { audio->audio_ptime = ST30_PTIME_1MS; @@ -943,8 +982,8 @@ static int parse_audio_ptime(json_object* audio_obj, st_json_audio_info_t* audio return ST_JSON_SUCCESS; } -static int st_json_parse_tx_audio(int idx, json_object* audio_obj, - st_json_audio_session_t* audio) { +static int st_json_parse_tx_audio(int idx, json_object *audio_obj, + st_json_audio_session_t *audio) { if (audio_obj == NULL || audio == NULL) { err("%s, can not parse tx audio session\n", __func__); return -ST_JSON_NULL; @@ -953,7 +992,8 @@ static int st_json_parse_tx_audio(int idx, json_object* audio_obj, /* parse udp port */ ret = parse_base_udp_port(audio_obj, &audio->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(audio_obj, &audio->base); @@ -964,37 +1004,43 @@ static int st_json_parse_tx_audio(int idx, json_object* audio_obj, /* parse audio type */ ret = parse_audio_type(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio format */ ret = parse_audio_format(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio channel */ ret = parse_audio_channel(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio sampling */ ret = parse_audio_sampling(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio packet time */ ret = parse_audio_ptime(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio url */ ret = parse_url(audio_obj, "audio_url", audio->info.audio_url); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse enable rtcp */ - audio->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(audio_obj, "enable_rtcp")); + audio->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(audio_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int st_json_parse_st30p(int idx, json_object* st30p_obj, - st_json_st30p_session_t* st30p, bool rx) { +static int st_json_parse_st30p(int idx, json_object *st30p_obj, + st_json_st30p_session_t *st30p, bool rx) { if (st30p_obj == NULL || st30p == NULL) { err("%s, can not parse tx st30p session\n", __func__); return -ST_JSON_NULL; @@ -1003,7 +1049,8 @@ static int st_json_parse_st30p(int idx, json_object* st30p_obj, /* parse udp port */ ret = parse_base_udp_port(st30p_obj, &st30p->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(st30p_obj, &st30p->base); @@ -1014,19 +1061,23 @@ static int st_json_parse_st30p(int idx, json_object* st30p_obj, /* parse audio format */ ret = parse_audio_format(st30p_obj, &st30p->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio channel */ ret = parse_audio_channel(st30p_obj, &st30p->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio sampling */ ret = parse_audio_sampling(st30p_obj, &st30p->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio packet time */ ret = parse_audio_ptime(st30p_obj, &st30p->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio url */ ret = parse_url(st30p_obj, "audio_url", st30p->info.audio_url); @@ -1040,14 +1091,14 @@ static int st_json_parse_st30p(int idx, json_object* st30p_obj, } /* parse enable rtcp */ - st30p->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(st30p_obj, "enable_rtcp")); + st30p->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(st30p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int st_json_parse_rx_audio(int idx, json_object* audio_obj, - st_json_audio_session_t* audio) { +static int st_json_parse_rx_audio(int idx, json_object *audio_obj, + st_json_audio_session_t *audio) { if (audio_obj == NULL || audio == NULL) { err("%s, can not parse rx audio session\n", __func__); return -ST_JSON_NULL; @@ -1056,7 +1107,8 @@ static int st_json_parse_rx_audio(int idx, json_object* audio_obj, /* parse udp port */ ret = parse_base_udp_port(audio_obj, &audio->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(audio_obj, &audio->base); @@ -1067,23 +1119,28 @@ static int st_json_parse_rx_audio(int idx, json_object* audio_obj, /* parse audio type */ ret = parse_audio_type(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio format */ ret = parse_audio_format(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio channel */ ret = parse_audio_channel(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio sampling */ ret = parse_audio_sampling(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio packet time */ ret = parse_audio_ptime(audio_obj, &audio->info); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse audio url */ ret = parse_url(audio_obj, "audio_url", audio->info.audio_url); @@ -1092,14 +1149,14 @@ static int st_json_parse_rx_audio(int idx, json_object* audio_obj, } /* parse enable rtcp */ - audio->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(audio_obj, "enable_rtcp")); + audio->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(audio_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int st_json_parse_tx_anc(int idx, json_object* anc_obj, - st_json_ancillary_session_t* anc) { +static int st_json_parse_tx_anc(int idx, json_object *anc_obj, + st_json_ancillary_session_t *anc) { if (anc_obj == NULL || anc == NULL) { err("%s, can not parse tx anc session\n", __func__); return -ST_JSON_NULL; @@ -1108,7 +1165,8 @@ static int st_json_parse_tx_anc(int idx, json_object* anc_obj, /* parse udp port */ ret = parse_base_udp_port(anc_obj, &anc->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(anc_obj, &anc->base); @@ -1118,7 +1176,8 @@ static int st_json_parse_tx_anc(int idx, json_object* anc_obj, } /* parse anc type */ - const char* type = json_object_get_string(st_json_object_object_get(anc_obj, "type")); + const char *type = + json_object_get_string(st_json_object_object_get(anc_obj, "type")); REQUIRED_ITEM(type); if (strcmp(type, "frame") == 0) { anc->info.type = ST40_TYPE_FRAME_LEVEL; @@ -1129,8 +1188,8 @@ static int st_json_parse_tx_anc(int idx, json_object* anc_obj, return -ST_JSON_NOT_VALID; } /* parse anc format */ - const char* anc_format = - json_object_get_string(st_json_object_object_get(anc_obj, "ancillary_format")); + const char *anc_format = json_object_get_string( + st_json_object_object_get(anc_obj, "ancillary_format")); REQUIRED_ITEM(anc_format); if (strcmp(anc_format, "closed_caption") == 0) { anc->info.anc_format = ANC_FORMAT_CLOSED_CAPTION; @@ -1140,8 +1199,8 @@ static int st_json_parse_tx_anc(int idx, json_object* anc_obj, } /* parse anc fps */ - const char* anc_fps = - json_object_get_string(st_json_object_object_get(anc_obj, "ancillary_fps")); + const char *anc_fps = json_object_get_string( + st_json_object_object_get(anc_obj, "ancillary_fps")); REQUIRED_ITEM(anc_fps); if (strcmp(anc_fps, "p59") == 0) { anc->info.anc_fps = ST_FPS_P59_94; @@ -1171,24 +1230,26 @@ static int st_json_parse_tx_anc(int idx, json_object* anc_obj, } /* parse anc interlaced */ - json_object* anc_interlaced = st_json_object_object_get(anc_obj, "interlaced"); + json_object *anc_interlaced = + st_json_object_object_get(anc_obj, "interlaced"); if (anc_interlaced) { anc->info.interlaced = json_object_get_boolean(anc_interlaced); } /* parse anc url */ ret = parse_url(anc_obj, "ancillary_url", anc->info.anc_url); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse enable rtcp */ - anc->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(anc_obj, "enable_rtcp")); + anc->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(anc_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int st_json_parse_rx_anc(int idx, json_object* anc_obj, - st_json_ancillary_session_t* anc) { +static int st_json_parse_rx_anc(int idx, json_object *anc_obj, + st_json_ancillary_session_t *anc) { if (anc_obj == NULL || anc == NULL) { err("%s, can not parse rx anc session\n", __func__); return -ST_JSON_NULL; @@ -1197,7 +1258,8 @@ static int st_json_parse_rx_anc(int idx, json_object* anc_obj, /* parse udp port */ ret = parse_base_udp_port(anc_obj, &anc->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(anc_obj, &anc->base); @@ -1207,20 +1269,23 @@ static int st_json_parse_rx_anc(int idx, json_object* anc_obj, } /* parse anc interlaced */ - json_object* anc_interlaced = st_json_object_object_get(anc_obj, "interlaced"); + json_object *anc_interlaced = + st_json_object_object_get(anc_obj, "interlaced"); if (anc_interlaced) { anc->info.interlaced = json_object_get_boolean(anc_interlaced); } /* parse enable rtcp */ - anc->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(anc_obj, "enable_rtcp")); + anc->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(anc_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int parse_st22p_width(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - int width = json_object_get_int(st_json_object_object_get(st22p_obj, "width")); +static int parse_st22p_width(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + int width = + json_object_get_int(st_json_object_object_get(st22p_obj, "width")); if (width <= 0) { err("%s, invalid width %d\n", __func__, width); return -ST_JSON_NOT_VALID; @@ -1229,8 +1294,10 @@ static int parse_st22p_width(json_object* st22p_obj, st_json_st22p_session_t* st return ST_JSON_SUCCESS; } -static int parse_st22p_height(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - int height = json_object_get_int(st_json_object_object_get(st22p_obj, "height")); +static int parse_st22p_height(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + int height = + json_object_get_int(st_json_object_object_get(st22p_obj, "height")); if (height <= 0) { err("%s, invalid height %d\n", __func__, height); return -ST_JSON_NOT_VALID; @@ -1239,8 +1306,10 @@ static int parse_st22p_height(json_object* st22p_obj, st_json_st22p_session_t* s return ST_JSON_SUCCESS; } -static int parse_st22p_fps(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - const char* fps = json_object_get_string(st_json_object_object_get(st22p_obj, "fps")); +static int parse_st22p_fps(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + const char *fps = + json_object_get_string(st_json_object_object_get(st22p_obj, "fps")); REQUIRED_ITEM(fps); if (strcmp(fps, "p59") == 0) { st22p->info.fps = ST_FPS_P59_94; @@ -1271,15 +1340,18 @@ static int parse_st22p_fps(json_object* st22p_obj, st_json_st22p_session_t* st22 return ST_JSON_SUCCESS; } -static int parse_st22p_interlace(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - json_object* obj = st_json_object_object_get(st22p_obj, "interlaced"); - if (!obj) return ST_JSON_SUCCESS; +static int parse_st22p_interlace(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + json_object *obj = st_json_object_object_get(st22p_obj, "interlaced"); + if (!obj) + return ST_JSON_SUCCESS; st22p->info.interlaced = json_object_get_boolean(obj); return ST_JSON_SUCCESS; } -static int parse_st22p_pack_type(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - const char* pack_type = +static int parse_st22p_pack_type(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + const char *pack_type = json_object_get_string(st_json_object_object_get(st22p_obj, "pack_type")); REQUIRED_ITEM(pack_type); if (strcmp(pack_type, "codestream") == 0) { @@ -1293,8 +1365,9 @@ static int parse_st22p_pack_type(json_object* st22p_obj, st_json_st22p_session_t return ST_JSON_SUCCESS; } -static int parse_st22p_codec(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - const char* codec = +static int parse_st22p_codec(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + const char *codec = json_object_get_string(st_json_object_object_get(st22p_obj, "codec")); REQUIRED_ITEM(codec); if (strcmp(codec, "JPEGXS") == 0 || strcmp(codec, "JPEG-XS") == 0) { @@ -1314,8 +1387,9 @@ static int parse_st22p_codec(json_object* st22p_obj, st_json_st22p_session_t* st return ST_JSON_SUCCESS; } -static int parse_st22p_device(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - const char* device = +static int parse_st22p_device(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + const char *device = json_object_get_string(st_json_object_object_get(st22p_obj, "device")); REQUIRED_ITEM(device); if (strcmp(device, "AUTO") == 0) { @@ -1333,8 +1407,9 @@ static int parse_st22p_device(json_object* st22p_obj, st_json_st22p_session_t* s return ST_JSON_SUCCESS; } -static int parse_st22p_quality(json_object* st22p_obj, st_json_st22p_session_t* st22p) { - const char* quality = +static int parse_st22p_quality(json_object *st22p_obj, + st_json_st22p_session_t *st22p) { + const char *quality = json_object_get_string(st_json_object_object_get(st22p_obj, "quality")); if (quality) { if (strcmp(quality, "quality") == 0) { @@ -1351,9 +1426,10 @@ static int parse_st22p_quality(json_object* st22p_obj, st_json_st22p_session_t* return ST_JSON_SUCCESS; } -static int parse_st22p_format(json_object* st22p_obj, st_json_st22p_session_t* st22p, - const char* format_name) { - const char* format = +static int parse_st22p_format(json_object *st22p_obj, + st_json_st22p_session_t *st22p, + const char *format_name) { + const char *format = json_object_get_string(st_json_object_object_get(st22p_obj, format_name)); REQUIRED_ITEM(format); if (strcmp(format, "YUV422PLANAR10LE") == 0) { @@ -1417,8 +1493,8 @@ static int parse_st22p_format(json_object* st22p_obj, st_json_st22p_session_t* s return ST_JSON_SUCCESS; } -static int st_json_parse_tx_st22p(int idx, json_object* st22p_obj, - st_json_st22p_session_t* st22p) { +static int st_json_parse_tx_st22p(int idx, json_object *st22p_obj, + st_json_st22p_session_t *st22p) { if (st22p_obj == NULL || st22p == NULL) { err("%s, can not parse tx st22p session\n", __func__); return -ST_JSON_NULL; @@ -1427,7 +1503,8 @@ static int st_json_parse_tx_st22p(int idx, json_object* st22p_obj, /* parse udp port */ ret = parse_base_udp_port(st22p_obj, &st22p->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(st22p_obj, &st22p->base); @@ -1438,61 +1515,71 @@ static int st_json_parse_tx_st22p(int idx, json_object* st22p_obj, /* parse width */ ret = parse_st22p_width(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse height */ ret = parse_st22p_height(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse fps */ ret = parse_st22p_fps(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse interlace */ ret = parse_st22p_interlace(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse pack_type */ ret = parse_st22p_pack_type(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse codec */ ret = parse_st22p_codec(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse device */ ret = parse_st22p_device(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse quality */ ret = parse_st22p_quality(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse input format */ ret = parse_st22p_format(st22p_obj, st22p, "input_format"); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse st22p url */ ret = parse_url(st22p_obj, "st22p_url", st22p->info.st22p_url); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse codec_thread_count option */ - st22p->info.codec_thread_count = - json_object_get_int(st_json_object_object_get(st22p_obj, "codec_thread_count")); + st22p->info.codec_thread_count = json_object_get_int( + st_json_object_object_get(st22p_obj, "codec_thread_count")); /* parse display option */ st22p->display = json_object_get_boolean(st_json_object_object_get(st22p_obj, "display")); /* parse enable rtcp */ - st22p->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(st22p_obj, "enable_rtcp")); + st22p->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(st22p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int st_json_parse_rx_st22p(int idx, json_object* st22p_obj, - st_json_st22p_session_t* st22p) { +static int st_json_parse_rx_st22p(int idx, json_object *st22p_obj, + st_json_st22p_session_t *st22p) { if (st22p_obj == NULL || st22p == NULL) { err("%s, can not parse rx st22p session\n", __func__); return -ST_JSON_NULL; @@ -1501,7 +1588,8 @@ static int st_json_parse_rx_st22p(int idx, json_object* st22p_obj, /* parse udp port */ ret = parse_base_udp_port(st22p_obj, &st22p->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(st22p_obj, &st22p->base); @@ -1512,61 +1600,72 @@ static int st_json_parse_rx_st22p(int idx, json_object* st22p_obj, /* parse width */ ret = parse_st22p_width(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse height */ ret = parse_st22p_height(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse fps */ ret = parse_st22p_fps(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse interlace */ ret = parse_st22p_interlace(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse pack_type */ ret = parse_st22p_pack_type(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse codec */ ret = parse_st22p_codec(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse device */ ret = parse_st22p_device(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse quality */ ret = parse_st22p_quality(st22p_obj, st22p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse output format */ ret = parse_st22p_format(st22p_obj, st22p, "output_format"); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse display option */ st22p->display = json_object_get_boolean(st_json_object_object_get(st22p_obj, "display")); /* parse measure_latency option */ - st22p->measure_latency = - json_object_get_boolean(st_json_object_object_get(st22p_obj, "measure_latency")); + st22p->measure_latency = json_object_get_boolean( + st_json_object_object_get(st22p_obj, "measure_latency")); /* parse codec_thread_count option */ - st22p->info.codec_thread_count = - json_object_get_int(st_json_object_object_get(st22p_obj, "codec_thread_count")); + st22p->info.codec_thread_count = json_object_get_int( + st_json_object_object_get(st22p_obj, "codec_thread_count")); /* parse enable rtcp */ - st22p->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(st22p_obj, "enable_rtcp")); + st22p->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(st22p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int parse_st20p_width(json_object* st20p_obj, st_json_st20p_session_t* st20p) { - int width = json_object_get_int(st_json_object_object_get(st20p_obj, "width")); +static int parse_st20p_width(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + int width = + json_object_get_int(st_json_object_object_get(st20p_obj, "width")); if (width <= 0) { err("%s, invalid width %d\n", __func__, width); return -ST_JSON_NOT_VALID; @@ -1575,8 +1674,10 @@ static int parse_st20p_width(json_object* st20p_obj, st_json_st20p_session_t* st return ST_JSON_SUCCESS; } -static int parse_st20p_height(json_object* st20p_obj, st_json_st20p_session_t* st20p) { - int height = json_object_get_int(st_json_object_object_get(st20p_obj, "height")); +static int parse_st20p_height(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + int height = + json_object_get_int(st_json_object_object_get(st20p_obj, "height")); if (height <= 0) { err("%s, invalid height %d\n", __func__, height); return -ST_JSON_NOT_VALID; @@ -1585,8 +1686,10 @@ static int parse_st20p_height(json_object* st20p_obj, st_json_st20p_session_t* s return ST_JSON_SUCCESS; } -static int parse_st20p_fps(json_object* st20p_obj, st_json_st20p_session_t* st20p) { - const char* fps = json_object_get_string(st_json_object_object_get(st20p_obj, "fps")); +static int parse_st20p_fps(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + const char *fps = + json_object_get_string(st_json_object_object_get(st20p_obj, "fps")); REQUIRED_ITEM(fps); if (strcmp(fps, "p59") == 0) { st20p->info.fps = ST_FPS_P59_94; @@ -1617,15 +1720,18 @@ static int parse_st20p_fps(json_object* st20p_obj, st_json_st20p_session_t* st20 return ST_JSON_SUCCESS; } -static int parse_st20p_interlace(json_object* st20p_obj, st_json_st20p_session_t* st20p) { - json_object* obj = st_json_object_object_get(st20p_obj, "interlaced"); - if (!obj) return ST_JSON_SUCCESS; +static int parse_st20p_interlace(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + json_object *obj = st_json_object_object_get(st20p_obj, "interlaced"); + if (!obj) + return ST_JSON_SUCCESS; st20p->info.interlaced = json_object_get_boolean(obj); return ST_JSON_SUCCESS; } -static int parse_st20p_device(json_object* st20p_obj, st_json_st20p_session_t* st20p) { - const char* device = +static int parse_st20p_device(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + const char *device = json_object_get_string(st_json_object_object_get(st20p_obj, "device")); REQUIRED_ITEM(device); if (strcmp(device, "AUTO") == 0) { @@ -1643,8 +1749,9 @@ static int parse_st20p_device(json_object* st20p_obj, st_json_st20p_session_t* s return ST_JSON_SUCCESS; } -static int parse_st20p_pacing(json_object* st20p_obj, st_json_st20p_session_t* st20p) { - const char* pacing = +static int parse_st20p_pacing(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + const char *pacing = json_object_get_string(st_json_object_object_get(st20p_obj, "pacing")); if (!pacing) { st20p->info.transport_pacing = ST21_PACING_NARROW; @@ -1665,8 +1772,9 @@ static int parse_st20p_pacing(json_object* st20p_obj, st_json_st20p_session_t* s return ST_JSON_SUCCESS; } -static int parse_st20p_packing(json_object* st20p_obj, st_json_st20p_session_t* st20p) { - const char* packing = +static int parse_st20p_packing(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + const char *packing = json_object_get_string(st_json_object_object_get(st20p_obj, "packing")); if (packing) { if (strcmp(packing, "GPM_SL") == 0) { @@ -1685,9 +1793,10 @@ static int parse_st20p_packing(json_object* st20p_obj, st_json_st20p_session_t* return ST_JSON_SUCCESS; } -static int parse_st20p_format(json_object* st20p_obj, st_json_st20p_session_t* st20p, - const char* format_name) { - const char* format = +static int parse_st20p_format(json_object *st20p_obj, + st_json_st20p_session_t *st20p, + const char *format_name) { + const char *format = json_object_get_string(st_json_object_object_get(st20p_obj, format_name)); REQUIRED_ITEM(format); if (strcmp(format, "YUV422PLANAR10LE") == 0) { @@ -1741,10 +1850,10 @@ static int parse_st20p_format(json_object* st20p_obj, st_json_st20p_session_t* s return ST_JSON_SUCCESS; } -static int parse_st20p_transport_format(json_object* st20p_obj, - st_json_st20p_session_t* st20p) { - const char* t_format = - json_object_get_string(st_json_object_object_get(st20p_obj, "transport_format")); +static int parse_st20p_transport_format(json_object *st20p_obj, + st_json_st20p_session_t *st20p) { + const char *t_format = json_object_get_string( + st_json_object_object_get(st20p_obj, "transport_format")); REQUIRED_ITEM(t_format); if (strcmp(t_format, "YUV_422_10bit") == 0) { st20p->info.transport_format = ST20_FMT_YUV_422_10BIT; @@ -1789,8 +1898,8 @@ static int parse_st20p_transport_format(json_object* st20p_obj, return ST_JSON_SUCCESS; } -static int st_json_parse_tx_st20p(int idx, json_object* st20p_obj, - st_json_st20p_session_t* st20p) { +static int st_json_parse_tx_st20p(int idx, json_object *st20p_obj, + st_json_st20p_session_t *st20p) { if (st20p_obj == NULL || st20p == NULL) { err("%s, can not parse tx st20p session\n", __func__); return -ST_JSON_NULL; @@ -1799,7 +1908,8 @@ static int st_json_parse_tx_st20p(int idx, json_object* st20p_obj, /* parse udp port */ ret = parse_base_udp_port(st20p_obj, &st20p->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(st20p_obj, &st20p->base); @@ -1810,57 +1920,67 @@ static int st_json_parse_tx_st20p(int idx, json_object* st20p_obj, /* parse width */ ret = parse_st20p_width(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse height */ ret = parse_st20p_height(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse fps */ ret = parse_st20p_fps(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse interlace */ ret = parse_st20p_interlace(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse device */ ret = parse_st20p_device(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse input format */ ret = parse_st20p_format(st20p_obj, st20p, "input_format"); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse transport pacing */ ret = parse_st20p_pacing(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse transport packing */ ret = parse_st20p_packing(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse transport format */ ret = parse_st20p_transport_format(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse st20p url */ ret = parse_url(st20p_obj, "st20p_url", st20p->info.st20p_url); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse display option */ st20p->display = json_object_get_boolean(st_json_object_object_get(st20p_obj, "display")); /* parse enable rtcp */ - st20p->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(st20p_obj, "enable_rtcp")); + st20p->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(st20p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int st_json_parse_rx_st20p(int idx, json_object* st20p_obj, - st_json_st20p_session_t* st20p) { +static int st_json_parse_rx_st20p(int idx, json_object *st20p_obj, + st_json_st20p_session_t *st20p) { if (st20p_obj == NULL || st20p == NULL) { err("%s, can not parse rx st20p session\n", __func__); return -ST_JSON_NULL; @@ -1869,7 +1989,8 @@ static int st_json_parse_rx_st20p(int idx, json_object* st20p_obj, /* parse udp port */ ret = parse_base_udp_port(st20p_obj, &st20p->base, idx); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse payload type */ ret = parse_base_payload_type(st20p_obj, &st20p->base); @@ -1880,62 +2001,73 @@ static int st_json_parse_rx_st20p(int idx, json_object* st20p_obj, /* parse width */ ret = parse_st20p_width(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse height */ ret = parse_st20p_height(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse fps */ ret = parse_st20p_fps(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse interlace */ ret = parse_st20p_interlace(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse device */ ret = parse_st20p_device(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse transport pacing */ ret = parse_st20p_pacing(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse transport packing */ ret = parse_st20p_packing(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse output format */ ret = parse_st20p_format(st20p_obj, st20p, "output_format"); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse transport format */ ret = parse_st20p_transport_format(st20p_obj, st20p); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* parse display option */ st20p->display = json_object_get_boolean(st_json_object_object_get(st20p_obj, "display")); /* parse measure_latency option */ - st20p->measure_latency = - json_object_get_boolean(st_json_object_object_get(st20p_obj, "measure_latency")); + st20p->measure_latency = json_object_get_boolean( + st_json_object_object_get(st20p_obj, "measure_latency")); /* parse enable rtcp */ - st20p->enable_rtcp = - json_object_get_boolean(st_json_object_object_get(st20p_obj, "enable_rtcp")); + st20p->enable_rtcp = json_object_get_boolean( + st_json_object_object_get(st20p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int parse_session_num(json_object* group, const char* name) { +static int parse_session_num(json_object *group, const char *name) { int num = 0; - json_object* session_array = st_json_object_object_get(group, name); - if (session_array != NULL && json_object_get_type(session_array) == json_type_array) { + json_object *session_array = st_json_object_object_get(group, name); + if (session_array != NULL && + json_object_get_type(session_array) == json_type_array) { for (int j = 0; j < json_object_array_length(session_array); ++j) { - json_object* session = json_object_array_get_idx(session_array, j); - int replicas = json_object_get_int(st_json_object_object_get(session, "replicas")); + json_object *session = json_object_array_get_idx(session_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); return -ST_JSON_NOT_VALID; @@ -1946,9 +2078,10 @@ static int parse_session_num(json_object* group, const char* name) { return num; } -static const char* local_ip_prefix = "local:"; +static const char *local_ip_prefix = "local:"; -static int parse_session_ip(const char* str_ip, struct st_json_session_base* base, +static int parse_session_ip(const char *str_ip, + struct st_json_session_base *base, enum mtl_session_port port) { int ret; @@ -1971,7 +2104,8 @@ static int parse_session_ip(const char* str_ip, struct st_json_session_base* bas return 0; } -static int parse_mcast_src_ip(const char* str_ip, struct st_json_session_base* base, +static int parse_mcast_src_ip(const char *str_ip, + struct st_json_session_base *base, enum mtl_session_port port) { int ret; @@ -1984,7 +2118,7 @@ static int parse_mcast_src_ip(const char* str_ip, struct st_json_session_base* b return 0; } -void st_app_free_json(st_json_context_t* ctx) { +void st_app_free_json(st_json_context_t *ctx) { if (ctx->interfaces) { st_app_free(ctx->interfaces); ctx->interfaces = NULL; @@ -2048,14 +2182,15 @@ void st_app_free_json(st_json_context_t* ctx) { } } -int st_app_parse_json(st_json_context_t* ctx, const char* filename) { +int st_app_parse_json(st_json_context_t *ctx, const char *filename) { info("%s, using json-c version: %s\n", __func__, json_c_version()); int ret = ST_JSON_SUCCESS; - json_object* obj; + json_object *obj; - json_object* root_object = json_object_from_file(filename); + json_object *root_object = json_object_from_file(filename); if (root_object == NULL) { - err("%s, can not parse json file %s, please check the format\n", __func__, filename); + err("%s, can not parse json file %s, please check the format\n", __func__, + filename); return -ST_JSON_PARSE_FAIL; } @@ -2095,16 +2230,19 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { /* parse shared queues */ obj = st_json_object_object_get(root_object, "shared_tx_queues"); - if (obj != NULL) ctx->shared_tx_queues = json_object_get_boolean(obj); + if (obj != NULL) + ctx->shared_tx_queues = json_object_get_boolean(obj); obj = st_json_object_object_get(root_object, "shared_rx_queues"); - if (obj != NULL) ctx->shared_rx_queues = json_object_get_boolean(obj); + if (obj != NULL) + ctx->shared_rx_queues = json_object_get_boolean(obj); /* if disable the chain for tx */ obj = st_json_object_object_get(root_object, "tx_no_chain"); - if (obj != NULL) ctx->tx_no_chain = json_object_get_boolean(obj); + if (obj != NULL) + ctx->tx_no_chain = json_object_get_boolean(obj); /* rss */ obj = st_json_object_object_get(root_object, "rss_mode"); if (obj != NULL) { - const char* rss = json_object_get_string(obj); + const char *rss = json_object_get_string(obj); if (strcmp(rss, "l3") == 0) { ctx->rss_mode = MTL_RSS_MODE_L3; } else if (strcmp(rss, "l3_l4") == 0) { @@ -2119,12 +2257,13 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { /* parse log file */ obj = st_json_object_object_get(root_object, "log_file"); if (obj != NULL) { - const char* log_file = json_object_get_string(obj); + const char *log_file = json_object_get_string(obj); ctx->log_file = strdup(log_file); } /* parse interfaces for system */ - json_object* interfaces_array = st_json_object_object_get(root_object, "interfaces"); + json_object *interfaces_array = + st_json_object_object_get(root_object, "interfaces"); if (interfaces_array == NULL || json_object_get_type(interfaces_array) != json_type_array) { err("%s, can not parse interfaces\n", __func__); @@ -2137,27 +2276,30 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { ret = -ST_JSON_NOT_VALID; goto error; } - ctx->interfaces = - (st_json_interface_t*)st_app_zmalloc(num_interfaces * sizeof(st_json_interface_t)); + ctx->interfaces = (st_json_interface_t *)st_app_zmalloc( + num_interfaces * sizeof(st_json_interface_t)); if (!ctx->interfaces) { err("%s, failed to allocate interfaces\n", __func__); ret = -ST_JSON_NULL; goto error; } for (int i = 0; i < num_interfaces; ++i) { - ret = st_json_parse_interfaces(json_object_array_get_idx(interfaces_array, i), - &ctx->interfaces[i]); - if (ret) goto error; + ret = st_json_parse_interfaces( + json_object_array_get_idx(interfaces_array, i), &ctx->interfaces[i]); + if (ret) + goto error; } ctx->num_interfaces = num_interfaces; ctx->has_display = false; /* parse tx sessions */ - json_object* tx_group_array = st_json_object_object_get(root_object, "tx_sessions"); - if (tx_group_array != NULL && json_object_get_type(tx_group_array) == json_type_array) { + json_object *tx_group_array = + st_json_object_object_get(root_object, "tx_sessions"); + if (tx_group_array != NULL && + json_object_get_type(tx_group_array) == json_type_array) { /* parse session numbers for array allocation */ for (int i = 0; i < json_object_array_length(tx_group_array); ++i) { - json_object* tx_group = json_object_array_get_idx(tx_group_array, i); + json_object *tx_group = json_object_array_get_idx(tx_group_array, i); if (tx_group == NULL) { err("%s, can not parse tx session group\n", __func__); ret = -ST_JSON_PARSE_FAIL; @@ -2166,67 +2308,73 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { int num = 0; /* parse tx video sessions */ num = parse_session_num(tx_group, "video"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->tx_video_session_cnt += num; /* parse tx audio sessions */ num = parse_session_num(tx_group, "audio"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->tx_audio_session_cnt += num; /* parse tx ancillary sessions */ num = parse_session_num(tx_group, "ancillary"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->tx_anc_session_cnt += num; /* parse tx st22p sessions */ num = parse_session_num(tx_group, "st22p"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->tx_st22p_session_cnt += num; /* parse tx st20p sessions */ num = parse_session_num(tx_group, "st20p"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->tx_st20p_session_cnt += num; /* parse tx st30p sessions */ num = parse_session_num(tx_group, "st30p"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->tx_st30p_session_cnt += num; } /* allocate tx sessions */ - ctx->tx_video_sessions = (st_json_video_session_t*)st_app_zmalloc( + ctx->tx_video_sessions = (st_json_video_session_t *)st_app_zmalloc( ctx->tx_video_session_cnt * sizeof(st_json_video_session_t)); if (!ctx->tx_video_sessions) { err("%s, failed to allocate tx_video_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->tx_audio_sessions = (st_json_audio_session_t*)st_app_zmalloc( + ctx->tx_audio_sessions = (st_json_audio_session_t *)st_app_zmalloc( ctx->tx_audio_session_cnt * sizeof(st_json_audio_session_t)); if (!ctx->tx_audio_sessions) { err("%s, failed to allocate tx_audio_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->tx_anc_sessions = (st_json_ancillary_session_t*)st_app_zmalloc( + ctx->tx_anc_sessions = (st_json_ancillary_session_t *)st_app_zmalloc( ctx->tx_anc_session_cnt * sizeof(st_json_ancillary_session_t)); if (!ctx->tx_anc_sessions) { err("%s, failed to allocate tx_anc_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->tx_st22p_sessions = (st_json_st22p_session_t*)st_app_zmalloc( + ctx->tx_st22p_sessions = (st_json_st22p_session_t *)st_app_zmalloc( ctx->tx_st22p_session_cnt * sizeof(st_json_st22p_session_t)); if (!ctx->tx_st22p_sessions) { err("%s, failed to allocate tx_st22p_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->tx_st20p_sessions = (st_json_st20p_session_t*)st_app_zmalloc( + ctx->tx_st20p_sessions = (st_json_st20p_session_t *)st_app_zmalloc( ctx->tx_st20p_session_cnt * sizeof(st_json_st20p_session_t)); if (!ctx->tx_st20p_sessions) { err("%s, failed to allocate tx_st20p_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->tx_st30p_sessions = (st_json_st30p_session_t*)st_app_zmalloc( + ctx->tx_st30p_sessions = (st_json_st30p_session_t *)st_app_zmalloc( ctx->tx_st30p_session_cnt * sizeof(st_json_st30p_session_t)); if (!ctx->tx_st30p_sessions) { err("%s, failed to allocate tx_st30p_sessions\n", __func__); @@ -2243,7 +2391,7 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { int num_st30p = 0; for (int i = 0; i < json_object_array_length(tx_group_array); ++i) { - json_object* tx_group = json_object_array_get_idx(tx_group_array, i); + json_object *tx_group = json_object_array_get_idx(tx_group_array, i); if (tx_group == NULL) { err("%s, can not parse tx session group\n", __func__); ret = -ST_JSON_PARSE_FAIL; @@ -2251,10 +2399,11 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } /* parse destination ip */ - json_object* dip_p = NULL; - json_object* dip_r = NULL; - json_object* dip_array = st_json_object_object_get(tx_group, "dip"); - if (dip_array != NULL && json_object_get_type(dip_array) == json_type_array) { + json_object *dip_p = NULL; + json_object *dip_r = NULL; + json_object *dip_array = st_json_object_object_get(tx_group, "dip"); + if (dip_array != NULL && + json_object_get_type(dip_array) == json_type_array) { int len = json_object_array_length(dip_array); if (len < 1 || len > MTL_PORT_MAX) { err("%s, wrong dip number\n", __func__); @@ -2274,23 +2423,27 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { /* parse interface */ int inf_p, inf_r = 0; - json_object* interface_array = st_json_object_object_get(tx_group, "interface"); + json_object *interface_array = + st_json_object_object_get(tx_group, "interface"); if (interface_array != NULL && json_object_get_type(interface_array) == json_type_array) { int len = json_object_array_length(interface_array); if (len != num_inf) { - err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, len); + err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, + len); ret = -ST_JSON_NOT_VALID; goto error; } - inf_p = json_object_get_int(json_object_array_get_idx(interface_array, 0)); + inf_p = + json_object_get_int(json_object_array_get_idx(interface_array, 0)); if (inf_p < 0 || inf_p > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; goto error; } if (len == 2) { - inf_r = json_object_get_int(json_object_array_get_idx(interface_array, 1)); + inf_r = json_object_get_int( + json_object_array_get_idx(interface_array, 1)); if (inf_r < 0 || inf_r > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; @@ -2304,12 +2457,14 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } /* parse tx video sessions */ - json_object* video_array = st_json_object_object_get(tx_group, "video"); - if (video_array != NULL && json_object_get_type(video_array) == json_type_array) { + json_object *video_array = st_json_object_object_get(tx_group, "video"); + if (video_array != NULL && + json_object_get_type(video_array) == json_type_array) { for (int j = 0; j < json_object_array_length(video_array); ++j) { - json_object* video_session = json_object_array_get_idx(video_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(video_session, "replicas")); + json_object *video_session = + json_object_array_get_idx(video_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(video_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2317,33 +2472,40 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_video_sessions[num_video].base, MTL_SESSION_PORT_P); - ctx->tx_video_sessions[num_video].base.inf[0] = &ctx->interfaces[inf_p]; + &ctx->tx_video_sessions[num_video].base, + MTL_SESSION_PORT_P); + ctx->tx_video_sessions[num_video].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_video_sessions[num_video].base, MTL_SESSION_PORT_R); - ctx->tx_video_sessions[num_video].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->tx_video_sessions[num_video].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_video_sessions[num_video].base.num_inf = num_inf; ret = st_json_parse_tx_video(k, video_session, &ctx->tx_video_sessions[num_video]); - if (ret) goto error; - if (ctx->tx_video_sessions[num_video].display) ctx->has_display = true; + if (ret) + goto error; + if (ctx->tx_video_sessions[num_video].display) + ctx->has_display = true; num_video++; } } } /* parse tx audio sessions */ - json_object* audio_array = st_json_object_object_get(tx_group, "audio"); - if (audio_array != NULL && json_object_get_type(audio_array) == json_type_array) { + json_object *audio_array = st_json_object_object_get(tx_group, "audio"); + if (audio_array != NULL && + json_object_get_type(audio_array) == json_type_array) { for (int j = 0; j < json_object_array_length(audio_array); ++j) { - json_object* audio_session = json_object_array_get_idx(audio_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(audio_session, "replicas")); + json_object *audio_session = + json_object_array_get_idx(audio_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(audio_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2351,32 +2513,37 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_audio_sessions[num_audio].base, MTL_SESSION_PORT_P); - ctx->tx_audio_sessions[num_audio].base.inf[0] = &ctx->interfaces[inf_p]; + &ctx->tx_audio_sessions[num_audio].base, + MTL_SESSION_PORT_P); + ctx->tx_audio_sessions[num_audio].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_audio_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_audio_sessions[num_audio].base, MTL_SESSION_PORT_R); - ctx->tx_audio_sessions[num_audio].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->tx_audio_sessions[num_audio].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_audio_sessions_cnt++; } ctx->tx_audio_sessions[num_audio].base.num_inf = num_inf; ret = st_json_parse_tx_audio(k, audio_session, &ctx->tx_audio_sessions[num_audio]); - if (ret) goto error; + if (ret) + goto error; num_audio++; } } } /* parse tx ancillary sessions */ - json_object* anc_array = st_json_object_object_get(tx_group, "ancillary"); - if (anc_array != NULL && json_object_get_type(anc_array) == json_type_array) { + json_object *anc_array = st_json_object_object_get(tx_group, "ancillary"); + if (anc_array != NULL && + json_object_get_type(anc_array) == json_type_array) { for (int j = 0; j < json_object_array_length(anc_array); ++j) { - json_object* anc_session = json_object_array_get_idx(anc_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(anc_session, "replicas")); + json_object *anc_session = json_object_array_get_idx(anc_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(anc_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2384,30 +2551,37 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_anc_sessions[num_anc].base, MTL_SESSION_PORT_P); + &ctx->tx_anc_sessions[num_anc].base, + MTL_SESSION_PORT_P); ctx->tx_anc_sessions[num_anc].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_anc_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), - &ctx->tx_anc_sessions[num_anc].base, MTL_SESSION_PORT_R); - ctx->tx_anc_sessions[num_anc].base.inf[1] = &ctx->interfaces[inf_r]; + &ctx->tx_anc_sessions[num_anc].base, + MTL_SESSION_PORT_R); + ctx->tx_anc_sessions[num_anc].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_anc_sessions_cnt++; } ctx->tx_anc_sessions[num_anc].base.num_inf = num_inf; - ret = st_json_parse_tx_anc(k, anc_session, &ctx->tx_anc_sessions[num_anc]); - if (ret) goto error; + ret = st_json_parse_tx_anc(k, anc_session, + &ctx->tx_anc_sessions[num_anc]); + if (ret) + goto error; num_anc++; } } } /* parse tx st22p sessions */ - json_object* st22p_array = st_json_object_object_get(tx_group, "st22p"); - if (st22p_array != NULL && json_object_get_type(st22p_array) == json_type_array) { + json_object *st22p_array = st_json_object_object_get(tx_group, "st22p"); + if (st22p_array != NULL && + json_object_get_type(st22p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st22p_array); ++j) { - json_object* st22p_session = json_object_array_get_idx(st22p_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(st22p_session, "replicas")); + json_object *st22p_session = + json_object_array_get_idx(st22p_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(st22p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2415,33 +2589,40 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_P); - ctx->tx_st22p_sessions[num_st22p].base.inf[0] = &ctx->interfaces[inf_p]; + &ctx->tx_st22p_sessions[num_st22p].base, + MTL_SESSION_PORT_P); + ctx->tx_st22p_sessions[num_st22p].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_R); - ctx->tx_st22p_sessions[num_st22p].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->tx_st22p_sessions[num_st22p].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_st22p_sessions[num_st22p].base.num_inf = num_inf; ret = st_json_parse_tx_st22p(k, st22p_session, &ctx->tx_st22p_sessions[num_st22p]); - if (ret) goto error; - if (ctx->tx_st22p_sessions[num_st22p].display) ctx->has_display = true; + if (ret) + goto error; + if (ctx->tx_st22p_sessions[num_st22p].display) + ctx->has_display = true; num_st22p++; } } } /* parse tx st20p sessions */ - json_object* st20p_array = st_json_object_object_get(tx_group, "st20p"); - if (st20p_array != NULL && json_object_get_type(st20p_array) == json_type_array) { + json_object *st20p_array = st_json_object_object_get(tx_group, "st20p"); + if (st20p_array != NULL && + json_object_get_type(st20p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st20p_array); ++j) { - json_object* st20p_session = json_object_array_get_idx(st20p_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(st20p_session, "replicas")); + json_object *st20p_session = + json_object_array_get_idx(st20p_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(st20p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2449,54 +2630,66 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_P); - ctx->tx_st20p_sessions[num_st20p].base.inf[0] = &ctx->interfaces[inf_p]; + &ctx->tx_st20p_sessions[num_st20p].base, + MTL_SESSION_PORT_P); + ctx->tx_st20p_sessions[num_st20p].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_R); - ctx->tx_st20p_sessions[num_st20p].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->tx_st20p_sessions[num_st20p].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_st20p_sessions[num_st20p].base.num_inf = num_inf; ret = st_json_parse_tx_st20p(k, st20p_session, &ctx->tx_st20p_sessions[num_st20p]); - if (ret) goto error; - if (ctx->tx_st20p_sessions[num_st20p].display) ctx->has_display = true; + if (ret) + goto error; + if (ctx->tx_st20p_sessions[num_st20p].display) + ctx->has_display = true; num_st20p++; } } } /* parse tx st30p sessions */ - json_object* st30p_array = st_json_object_object_get(tx_group, "st30p"); - if (st30p_array != NULL && json_object_get_type(st30p_array) == json_type_array) { + json_object *st30p_array = st_json_object_object_get(tx_group, "st30p"); + if (st30p_array != NULL && + json_object_get_type(st30p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st30p_array); ++j) { - json_object* st30p_session = json_object_array_get_idx(st30p_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(st30p_session, "replicas")); + json_object *st30p_session = + json_object_array_get_idx(st30p_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(st30p_session, "replicas")); if (replicas < 0) { - err("%s, invalid replicas number: %d for st30p\n", __func__, replicas); + err("%s, invalid replicas number: %d for st30p\n", __func__, + replicas); ret = -ST_JSON_NOT_VALID; goto error; } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_P); - ctx->tx_st30p_sessions[num_st30p].base.inf[0] = &ctx->interfaces[inf_p]; + &ctx->tx_st30p_sessions[num_st30p].base, + MTL_SESSION_PORT_P); + ctx->tx_st30p_sessions[num_st30p].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_R); - ctx->tx_st30p_sessions[num_st30p].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->tx_st30p_sessions[num_st30p].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_st30p_sessions[num_st30p].base.num_inf = num_inf; - ret = st_json_parse_st30p(k, st30p_session, - &ctx->tx_st30p_sessions[num_st30p], false); - if (ret) goto error; + ret = st_json_parse_st30p( + k, st30p_session, &ctx->tx_st30p_sessions[num_st30p], false); + if (ret) + goto error; num_st30p++; } } @@ -2505,11 +2698,13 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } /* parse rx sessions */ - json_object* rx_group_array = st_json_object_object_get(root_object, "rx_sessions"); - if (rx_group_array != NULL && json_object_get_type(rx_group_array) == json_type_array) { + json_object *rx_group_array = + st_json_object_object_get(root_object, "rx_sessions"); + if (rx_group_array != NULL && + json_object_get_type(rx_group_array) == json_type_array) { /* parse session numbers for array allocation */ for (int i = 0; i < json_object_array_length(rx_group_array); ++i) { - json_object* rx_group = json_object_array_get_idx(rx_group_array, i); + json_object *rx_group = json_object_array_get_idx(rx_group_array, i); if (rx_group == NULL) { err("%s, can not parse rx session group\n", __func__); ret = -ST_JSON_PARSE_FAIL; @@ -2518,78 +2713,85 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { int num = 0; /* parse rx video sessions */ num = parse_session_num(rx_group, "video"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->rx_video_session_cnt += num; /* parse rx audio sessions */ num = parse_session_num(rx_group, "audio"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->rx_audio_session_cnt += num; /* parse rx ancillary sessions */ num = parse_session_num(rx_group, "ancillary"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->rx_anc_session_cnt += num; /* parse rx st22p sessions */ num = parse_session_num(rx_group, "st22p"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->rx_st22p_session_cnt += num; /* parse rx st20p sessions */ num = parse_session_num(rx_group, "st20p"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->rx_st20p_session_cnt += num; /* parse rx st20r sessions */ num = parse_session_num(rx_group, "st20r"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->rx_st20r_session_cnt += num; /* parse rx st30p sessions */ num = parse_session_num(rx_group, "st30p"); - if (num < 0) goto error; + if (num < 0) + goto error; ctx->rx_st30p_session_cnt += num; } /* allocate rx sessions */ - ctx->rx_video_sessions = (st_json_video_session_t*)st_app_zmalloc( + ctx->rx_video_sessions = (st_json_video_session_t *)st_app_zmalloc( ctx->rx_video_session_cnt * sizeof(st_json_video_session_t)); if (!ctx->rx_video_sessions) { err("%s, failed to allocate rx_video_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->rx_audio_sessions = (st_json_audio_session_t*)st_app_zmalloc( + ctx->rx_audio_sessions = (st_json_audio_session_t *)st_app_zmalloc( ctx->rx_audio_session_cnt * sizeof(st_json_audio_session_t)); if (!ctx->rx_audio_sessions) { err("%s, failed to allocate rx_audio_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->rx_anc_sessions = (st_json_ancillary_session_t*)st_app_zmalloc( + ctx->rx_anc_sessions = (st_json_ancillary_session_t *)st_app_zmalloc( ctx->rx_anc_session_cnt * sizeof(st_json_ancillary_session_t)); if (!ctx->rx_anc_sessions) { err("%s, failed to allocate rx_anc_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->rx_st22p_sessions = (st_json_st22p_session_t*)st_app_zmalloc( + ctx->rx_st22p_sessions = (st_json_st22p_session_t *)st_app_zmalloc( ctx->rx_st22p_session_cnt * sizeof(st_json_st22p_session_t)); if (!ctx->rx_st22p_sessions) { err("%s, failed to allocate rx_st22p_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->rx_st20p_sessions = (st_json_st20p_session_t*)st_app_zmalloc( + ctx->rx_st20p_sessions = (st_json_st20p_session_t *)st_app_zmalloc( ctx->rx_st20p_session_cnt * sizeof(st_json_st20p_session_t)); if (!ctx->rx_st20p_sessions) { err("%s, failed to allocate rx_st20p_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->rx_st30p_sessions = (st_json_st30p_session_t*)st_app_zmalloc( + ctx->rx_st30p_sessions = (st_json_st30p_session_t *)st_app_zmalloc( ctx->rx_st30p_session_cnt * sizeof(st_json_st30p_session_t)); if (!ctx->rx_st30p_sessions) { err("%s, failed to allocate rx_st30p_sessions\n", __func__); ret = -ST_JSON_NULL; goto error; } - ctx->rx_st20r_sessions = (st_json_video_session_t*)st_app_zmalloc( + ctx->rx_st20r_sessions = (st_json_video_session_t *)st_app_zmalloc( ctx->rx_st20r_session_cnt * sizeof(*ctx->rx_st20r_sessions)); if (!ctx->rx_st20r_sessions) { err("%s, failed to allocate rx_st20r_sessions\n", __func__); @@ -2607,7 +2809,7 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { int num_st30p = 0; for (int i = 0; i < json_object_array_length(rx_group_array); ++i) { - json_object* rx_group = json_object_array_get_idx(rx_group_array, i); + json_object *rx_group = json_object_array_get_idx(rx_group_array, i); if (rx_group == NULL) { err("%s, can not parse rx session group\n", __func__); ret = -ST_JSON_PARSE_FAIL; @@ -2615,14 +2817,15 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } /* parse receiving ip */ - json_object* ip_p = NULL; - json_object* ip_r = NULL; - json_object* ip_array = st_json_object_object_get(rx_group, "ip"); - json_object* mcast_src_ip_p = NULL; - json_object* mcast_src_ip_r = NULL; - json_object* mcast_src_ip_array = /* mcast_src_ip field is optional */ + json_object *ip_p = NULL; + json_object *ip_r = NULL; + json_object *ip_array = st_json_object_object_get(rx_group, "ip"); + json_object *mcast_src_ip_p = NULL; + json_object *mcast_src_ip_r = NULL; + json_object *mcast_src_ip_array = /* mcast_src_ip field is optional */ st_json_object_object_get(rx_group, "mcast_src_ip"); - if (ip_array != NULL && json_object_get_type(ip_array) == json_type_array) { + if (ip_array != NULL && + json_object_get_type(ip_array) == json_type_array) { int len = json_object_array_length(ip_array); if (len < 1 || len > MTL_SESSION_PORT_MAX) { err("%s, wrong dip number\n", __func__); @@ -2655,23 +2858,27 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { /* parse interface */ int inf_p, inf_r = 0; - json_object* interface_array = st_json_object_object_get(rx_group, "interface"); + json_object *interface_array = + st_json_object_object_get(rx_group, "interface"); if (interface_array != NULL && json_object_get_type(interface_array) == json_type_array) { int len = json_object_array_length(interface_array); if (len != num_inf) { - err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, len); + err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, + len); ret = -ST_JSON_NOT_VALID; goto error; } - inf_p = json_object_get_int(json_object_array_get_idx(interface_array, 0)); + inf_p = + json_object_get_int(json_object_array_get_idx(interface_array, 0)); if (inf_p < 0 || inf_p > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; goto error; } if (len == 2) { - inf_r = json_object_get_int(json_object_array_get_idx(interface_array, 1)); + inf_r = json_object_get_int( + json_object_array_get_idx(interface_array, 1)); if (inf_r < 0 || inf_r > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; @@ -2685,12 +2892,14 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } /* parse rx video sessions */ - json_object* video_array = st_json_object_object_get(rx_group, "video"); - if (video_array != NULL && json_object_get_type(video_array) == json_type_array) { + json_object *video_array = st_json_object_object_get(rx_group, "video"); + if (video_array != NULL && + json_object_get_type(video_array) == json_type_array) { for (int j = 0; j < json_object_array_length(video_array); ++j) { - json_object* video_session = json_object_array_get_idx(video_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(video_session, "replicas")); + json_object *video_session = + json_object_array_get_idx(video_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(video_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2698,12 +2907,14 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_video_sessions[num_video].base, MTL_SESSION_PORT_P); + &ctx->rx_video_sessions[num_video].base, + MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_video_sessions[num_video].base, MTL_SESSION_PORT_P); - ctx->rx_video_sessions[num_video].base.inf[0] = &ctx->interfaces[inf_p]; + ctx->rx_video_sessions[num_video].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2713,26 +2924,31 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_video_sessions[num_video].base, MTL_SESSION_PORT_R); - ctx->rx_video_sessions[num_video].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->rx_video_sessions[num_video].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_video_sessions[num_video].base.num_inf = num_inf; ret = st_json_parse_rx_video(k, video_session, &ctx->rx_video_sessions[num_video]); - if (ret) goto error; - if (ctx->rx_video_sessions[num_video].display) ctx->has_display = true; + if (ret) + goto error; + if (ctx->rx_video_sessions[num_video].display) + ctx->has_display = true; num_video++; } } } /* parse rx audio sessions */ - json_object* audio_array = st_json_object_object_get(rx_group, "audio"); - if (audio_array != NULL && json_object_get_type(audio_array) == json_type_array) { + json_object *audio_array = st_json_object_object_get(rx_group, "audio"); + if (audio_array != NULL && + json_object_get_type(audio_array) == json_type_array) { for (int j = 0; j < json_object_array_length(audio_array); ++j) { - json_object* audio_session = json_object_array_get_idx(audio_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(audio_session, "replicas")); + json_object *audio_session = + json_object_array_get_idx(audio_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(audio_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2740,12 +2956,14 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_audio_sessions[num_audio].base, MTL_SESSION_PORT_P); + &ctx->rx_audio_sessions[num_audio].base, + MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_audio_sessions[num_audio].base, MTL_SESSION_PORT_P); - ctx->rx_audio_sessions[num_audio].base.inf[0] = &ctx->interfaces[inf_p]; + ctx->rx_audio_sessions[num_audio].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_audio_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2755,25 +2973,28 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_audio_sessions[num_audio].base, MTL_SESSION_PORT_R); - ctx->rx_audio_sessions[num_audio].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->rx_audio_sessions[num_audio].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_audio_sessions_cnt++; } ctx->rx_audio_sessions[num_audio].base.num_inf = num_inf; ret = st_json_parse_rx_audio(k, audio_session, &ctx->rx_audio_sessions[num_audio]); - if (ret) goto error; + if (ret) + goto error; num_audio++; } } } /* parse rx ancillary sessions */ - json_object* anc_array = st_json_object_object_get(rx_group, "ancillary"); - if (anc_array != NULL && json_object_get_type(anc_array) == json_type_array) { + json_object *anc_array = st_json_object_object_get(rx_group, "ancillary"); + if (anc_array != NULL && + json_object_get_type(anc_array) == json_type_array) { for (int j = 0; j < json_object_array_length(anc_array); ++j) { - json_object* anc_session = json_object_array_get_idx(anc_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(anc_session, "replicas")); + json_object *anc_session = json_object_array_get_idx(anc_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(anc_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2781,37 +3002,45 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_P); + &ctx->rx_anc_sessions[num_anc].base, + MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), - &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_P); + &ctx->rx_anc_sessions[num_anc].base, + MTL_SESSION_PORT_P); ctx->rx_anc_sessions[num_anc].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_anc_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), - &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_R); + &ctx->rx_anc_sessions[num_anc].base, + MTL_SESSION_PORT_R); if (mcast_src_ip_r) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_R); - ctx->rx_anc_sessions[num_anc].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->rx_anc_sessions[num_anc].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_anc_sessions_cnt++; } ctx->rx_anc_sessions[num_anc].base.num_inf = num_inf; - ret = st_json_parse_rx_anc(k, anc_session, &ctx->rx_anc_sessions[num_anc]); - if (ret) goto error; + ret = st_json_parse_rx_anc(k, anc_session, + &ctx->rx_anc_sessions[num_anc]); + if (ret) + goto error; num_anc++; } } } /* parse rx st22p sessions */ - json_object* st22p_array = st_json_object_object_get(rx_group, "st22p"); - if (st22p_array != NULL && json_object_get_type(st22p_array) == json_type_array) { + json_object *st22p_array = st_json_object_object_get(rx_group, "st22p"); + if (st22p_array != NULL && + json_object_get_type(st22p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st22p_array); ++j) { - json_object* st22p_session = json_object_array_get_idx(st22p_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(st22p_session, "replicas")); + json_object *st22p_session = + json_object_array_get_idx(st22p_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(st22p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2819,12 +3048,14 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_P); + &ctx->rx_st22p_sessions[num_st22p].base, + MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_P); - ctx->rx_st22p_sessions[num_st22p].base.inf[0] = &ctx->interfaces[inf_p]; + ctx->rx_st22p_sessions[num_st22p].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2834,26 +3065,31 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_R); - ctx->rx_st22p_sessions[num_st22p].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->rx_st22p_sessions[num_st22p].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st22p_sessions[num_st22p].base.num_inf = num_inf; ret = st_json_parse_rx_st22p(k, st22p_session, &ctx->rx_st22p_sessions[num_st22p]); - if (ret) goto error; - if (ctx->rx_st22p_sessions[num_st22p].display) ctx->has_display = true; + if (ret) + goto error; + if (ctx->rx_st22p_sessions[num_st22p].display) + ctx->has_display = true; num_st22p++; } } } /* parse rx st20p sessions */ - json_object* st20p_array = st_json_object_object_get(rx_group, "st20p"); - if (st20p_array != NULL && json_object_get_type(st20p_array) == json_type_array) { + json_object *st20p_array = st_json_object_object_get(rx_group, "st20p"); + if (st20p_array != NULL && + json_object_get_type(st20p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st20p_array); ++j) { - json_object* st20p_session = json_object_array_get_idx(st20p_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(st20p_session, "replicas")); + json_object *st20p_session = + json_object_array_get_idx(st20p_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(st20p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2861,12 +3097,14 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_P); + &ctx->rx_st20p_sessions[num_st20p].base, + MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_P); - ctx->rx_st20p_sessions[num_st20p].base.inf[0] = &ctx->interfaces[inf_p]; + ctx->rx_st20p_sessions[num_st20p].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2876,26 +3114,31 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_R); - ctx->rx_st20p_sessions[num_st20p].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->rx_st20p_sessions[num_st20p].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st20p_sessions[num_st20p].base.num_inf = num_inf; ret = st_json_parse_rx_st20p(k, st20p_session, &ctx->rx_st20p_sessions[num_st20p]); - if (ret) goto error; - if (ctx->rx_st20p_sessions[num_st20p].display) ctx->has_display = true; + if (ret) + goto error; + if (ctx->rx_st20p_sessions[num_st20p].display) + ctx->has_display = true; num_st20p++; } } } /* parse rx st30p sessions */ - json_object* st30p_array = st_json_object_object_get(rx_group, "st30p"); - if (st30p_array != NULL && json_object_get_type(st30p_array) == json_type_array) { + json_object *st30p_array = st_json_object_object_get(rx_group, "st30p"); + if (st30p_array != NULL && + json_object_get_type(st30p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st30p_array); ++j) { - json_object* st30p_session = json_object_array_get_idx(st30p_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(st30p_session, "replicas")); + json_object *st30p_session = + json_object_array_get_idx(st30p_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(st30p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2903,12 +3146,14 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_P); + &ctx->rx_st30p_sessions[num_st30p].base, + MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_P); - ctx->rx_st30p_sessions[num_st30p].base.inf[0] = &ctx->interfaces[inf_p]; + ctx->rx_st30p_sessions[num_st30p].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2918,43 +3163,50 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_R); - ctx->rx_st30p_sessions[num_st30p].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->rx_st30p_sessions[num_st30p].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st30p_sessions[num_st30p].base.num_inf = num_inf; ret = st_json_parse_st30p(k, st30p_session, &ctx->rx_st30p_sessions[num_st30p], true); - if (ret) goto error; + if (ret) + goto error; num_st30p++; } } } /* parse rx st20r sessions */ - json_object* st20r_array = st_json_object_object_get(rx_group, "st20r"); - if (st20r_array != NULL && json_object_get_type(st20r_array) == json_type_array) { + json_object *st20r_array = st_json_object_object_get(rx_group, "st20r"); + if (st20r_array != NULL && + json_object_get_type(st20r_array) == json_type_array) { if (num_inf != 2) { err("%s, invalid num_inf number for st20r: %d\n", __func__, num_inf); ret = -ST_JSON_NOT_VALID; goto error; } for (int j = 0; j < json_object_array_length(st20r_array); ++j) { - json_object* st20r_session = json_object_array_get_idx(st20r_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(st20r_session, "replicas")); + json_object *st20r_session = + json_object_array_get_idx(st20r_array, j); + int replicas = json_object_get_int( + st_json_object_object_get(st20r_session, "replicas")); if (replicas < 0) { - err("%s, invalid replicas number for st20r: %d\n", __func__, replicas); + err("%s, invalid replicas number for st20r: %d\n", __func__, + replicas); ret = -ST_JSON_NOT_VALID; goto error; } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st20r_sessions[num_st20r].base, MTL_SESSION_PORT_P); + &ctx->rx_st20r_sessions[num_st20r].base, + MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st20r_sessions[num_st20r].base, MTL_SESSION_PORT_P); - ctx->rx_st20r_sessions[num_st20r].base.inf[0] = &ctx->interfaces[inf_p]; + ctx->rx_st20r_sessions[num_st20r].base.inf[0] = + &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2964,14 +3216,17 @@ int st_app_parse_json(st_json_context_t* ctx, const char* filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st20r_sessions[num_st20r].base, MTL_SESSION_PORT_R); - ctx->rx_st20r_sessions[num_st20r].base.inf[1] = &ctx->interfaces[inf_r]; + ctx->rx_st20r_sessions[num_st20r].base.inf[1] = + &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st20r_sessions[num_st20r].base.num_inf = num_inf; ret = st_json_parse_rx_video(k, st20r_session, &ctx->rx_st20r_sessions[num_st20r]); - if (ret) goto error; - if (ctx->rx_st20r_sessions[num_st20r].display) ctx->has_display = true; + if (ret) + goto error; + if (ctx->rx_st20r_sessions[num_st20r].display) + ctx->has_display = true; num_st20r++; } } @@ -3029,20 +3284,21 @@ uint32_t st_app_get_height(enum video_format fmt) { bool st_app_get_interlaced(enum video_format fmt) { switch (fmt) { - case VIDEO_FORMAT_480I_59FPS: - case VIDEO_FORMAT_576I_50FPS: - case VIDEO_FORMAT_1080I_59FPS: - case VIDEO_FORMAT_1080I_50FPS: - return true; - default: - return false; + case VIDEO_FORMAT_480I_59FPS: + case VIDEO_FORMAT_576I_50FPS: + case VIDEO_FORMAT_1080I_59FPS: + case VIDEO_FORMAT_1080I_50FPS: + return true; + default: + return false; } } -uint8_t* st_json_ip(struct st_app_context* ctx, st_json_session_base_t* base, +uint8_t *st_json_ip(struct st_app_context *ctx, st_json_session_base_t *base, enum mtl_session_port port) { if (base->type[port] == ST_JSON_IP_LOCAL_IF) { - mtl_port_ip_info(ctx->st, base->local[port], base->local_ip[port], NULL, NULL); + mtl_port_ip_info(ctx->st, base->local[port], base->local_ip[port], NULL, + NULL); return base->local_ip[port]; } else { return base->ip[port]; diff --git a/app/src/parse_json.h b/app/src/parse_json.h index 15c139e4a..54d1d8bcd 100644 --- a/app/src/parse_json.h +++ b/app/src/parse_json.h @@ -106,7 +106,7 @@ enum anc_format { struct st_video_fmt_desc { enum video_format fmt; - char* name; + char *name; uint32_t width; uint32_t height; enum st_fps fps; @@ -137,7 +137,7 @@ enum st_json_ip_type { typedef struct st_json_session_base { uint8_t ip[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; uint8_t mcast_src_ip[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - st_json_interface_t* inf[MTL_SESSION_PORT_MAX]; + st_json_interface_t *inf[MTL_SESSION_PORT_MAX]; int num_inf; uint16_t udp_port; uint8_t payload_type; @@ -257,7 +257,7 @@ typedef struct st_json_st20p_session { } st_json_st20p_session_t; typedef struct st_json_context { - st_json_interface_t* interfaces; + st_json_interface_t *interfaces; int num_interfaces; enum mtl_rss_mode rss_mode; int sch_quota; @@ -267,39 +267,39 @@ typedef struct st_json_context { bool shared_tx_queues; bool shared_rx_queues; bool tx_no_chain; - char* log_file; + char *log_file; - st_json_video_session_t* tx_video_sessions; + st_json_video_session_t *tx_video_sessions; int tx_video_session_cnt; - st_json_audio_session_t* tx_audio_sessions; + st_json_audio_session_t *tx_audio_sessions; int tx_audio_session_cnt; - st_json_ancillary_session_t* tx_anc_sessions; + st_json_ancillary_session_t *tx_anc_sessions; int tx_anc_session_cnt; - st_json_st22p_session_t* tx_st22p_sessions; + st_json_st22p_session_t *tx_st22p_sessions; int tx_st22p_session_cnt; - st_json_st20p_session_t* tx_st20p_sessions; + st_json_st20p_session_t *tx_st20p_sessions; int tx_st20p_session_cnt; - st_json_st30p_session_t* tx_st30p_sessions; + st_json_st30p_session_t *tx_st30p_sessions; int tx_st30p_session_cnt; - st_json_video_session_t* rx_video_sessions; + st_json_video_session_t *rx_video_sessions; int rx_video_session_cnt; - st_json_audio_session_t* rx_audio_sessions; + st_json_audio_session_t *rx_audio_sessions; int rx_audio_session_cnt; - st_json_ancillary_session_t* rx_anc_sessions; + st_json_ancillary_session_t *rx_anc_sessions; int rx_anc_session_cnt; - st_json_st22p_session_t* rx_st22p_sessions; + st_json_st22p_session_t *rx_st22p_sessions; int rx_st22p_session_cnt; - st_json_st20p_session_t* rx_st20p_sessions; + st_json_st20p_session_t *rx_st20p_sessions; int rx_st20p_session_cnt; - st_json_video_session_t* rx_st20r_sessions; + st_json_video_session_t *rx_st20r_sessions; int rx_st20r_session_cnt; - st_json_st30p_session_t* rx_st30p_sessions; + st_json_st30p_session_t *rx_st30p_sessions; int rx_st30p_session_cnt; } st_json_context_t; -int st_app_parse_json(st_json_context_t* ctx, const char* filename); -void st_app_free_json(st_json_context_t* ctx); +int st_app_parse_json(st_json_context_t *ctx, const char *filename); +void st_app_free_json(st_json_context_t *ctx); enum st_fps st_app_get_fps(enum video_format fmt); uint32_t st_app_get_width(enum video_format fmt); diff --git a/app/src/player.c b/app/src/player.c index 4c011b0cd..82c470ec9 100644 --- a/app/src/player.c +++ b/app/src/player.c @@ -14,7 +14,7 @@ #define MSG_WIDTH_MARGIN (5) #define MSG_HEIGHT_MARGIN (5) -int st_app_player_uinit(struct st_app_context* ctx) { +int st_app_player_uinit(struct st_app_context *ctx) { MTL_MAY_UNUSED(ctx); SDL_Quit(); @@ -24,7 +24,7 @@ int st_app_player_uinit(struct st_app_context* ctx) { return 0; } -int st_app_player_init(struct st_app_context* ctx) { +int st_app_player_init(struct st_app_context *ctx) { info("%s, SDL_Init start\n", __func__); int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); info("%s, SDL_Init result %d\n", __func__, res); @@ -46,7 +46,7 @@ int st_app_player_init(struct st_app_context* ctx) { return 0; } -static void destroy_display_context(struct st_display* d) { +static void destroy_display_context(struct st_display *d) { if (d->texture) { SDL_DestroyTexture(d->texture); d->texture = NULL; @@ -61,10 +61,10 @@ static void destroy_display_context(struct st_display* d) { } } -static int create_display_context(struct st_display* d) { - d->window = - SDL_CreateWindow(d->name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - d->window_w, d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); +static int create_display_context(struct st_display *d) { + d->window = SDL_CreateWindow( + d->name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, d->window_w, + d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (d->window == NULL) { err("%s, create window fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -78,8 +78,8 @@ static int create_display_context(struct st_display* d) { return -EIO; } - d->texture = SDL_CreateTexture(d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, - d->pixel_w, d->pixel_h); + d->texture = SDL_CreateTexture( + d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, d->pixel_w, d->pixel_h); if (d->texture == NULL) { err("%s, create texture fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -89,8 +89,8 @@ static int create_display_context(struct st_display* d) { return 0; } -static void* display_thread_func(void* arg) { - struct st_display* d = arg; +static void *display_thread_func(void *arg) { + struct st_display *d = arg; int ret = create_display_context(d); if (ret < 0) { @@ -126,8 +126,9 @@ static void* display_thread_func(void* arg) { char text[32]; sprintf(text, "FPS:\t%.2f", d->fps); SDL_Color Red = {255, 0, 0}; - SDL_Surface* surfaceMessage = TTF_RenderText_Solid(d->font, text, Red); - SDL_Texture* Message = SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); + SDL_Surface *surfaceMessage = TTF_RenderText_Solid(d->font, text, Red); + SDL_Texture *Message = + SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); SDL_RenderCopy(d->renderer, Message, NULL, &d->msg_rect); SDL_FreeSurface(surfaceMessage); @@ -141,7 +142,8 @@ static void* display_thread_func(void* arg) { SDL_Event event; while (SDL_PollEvent(&event)) { dbg("%s, SDL event: %d\n", __func__, event.type); - if (event.type == SDL_QUIT) d->display_thread_stop = true; + if (event.type == SDL_QUIT) + d->display_thread_stop = true; } #endif } @@ -149,8 +151,9 @@ static void* display_thread_func(void* arg) { return NULL; } -int st_app_uinit_display(struct st_display* d) { - if (!d) return 0; +int st_app_uinit_display(struct st_display *d) { + if (!d) + return 0; d->display_thread_stop = true; if (d->display_thread) { @@ -182,12 +185,13 @@ int st_app_uinit_display(struct st_display* d) { return 0; } -int st_app_init_display(struct st_display* d, char* name, int width, int height, - char* font) { +int st_app_init_display(struct st_display *d, char *name, int width, int height, + char *font) { int ret; MTL_MAY_UNUSED(font); - if (!d) return -ENOMEM; + if (!d) + return -ENOMEM; snprintf(d->name, 32, "%s", name); d->window_w = SCREEN_WIDTH; d->window_h = SCREEN_HEIGHT; @@ -228,6 +232,7 @@ int st_app_init_display(struct st_display* d, char* name, int width, int height, return ret; } - info("%s(%s), succ, pixel width: %d, height: %d\n", __func__, name, width, height); + info("%s(%s), succ, pixel width: %d, height: %d\n", __func__, name, width, + height); return 0; } diff --git a/app/src/player.h b/app/src/player.h index 9b5b03f21..5cba4f8a2 100644 --- a/app/src/player.h +++ b/app/src/player.h @@ -11,25 +11,25 @@ #define _PLAYER_HEAD_H_ #ifdef APP_HAS_SDL2 -int st_app_player_uinit(struct st_app_context* ctx); -int st_app_player_init(struct st_app_context* ctx); +int st_app_player_uinit(struct st_app_context *ctx); +int st_app_player_init(struct st_app_context *ctx); -int st_app_init_display(struct st_display* d, char* name, int width, int height, - char* font); -int st_app_uinit_display(struct st_display* d); +int st_app_init_display(struct st_display *d, char *name, int width, int height, + char *font); +int st_app_uinit_display(struct st_display *d); #else -static inline int st_app_player_uinit(struct st_app_context* ctx) { +static inline int st_app_player_uinit(struct st_app_context *ctx) { MTL_MAY_UNUSED(ctx); warn("%s, not support as build without SDL2\n", __func__); return -ENOTSUP; } -static inline int st_app_player_init(struct st_app_context* ctx) { +static inline int st_app_player_init(struct st_app_context *ctx) { MTL_MAY_UNUSED(ctx); warn("%s, not support as build without SDL2\n", __func__); return -ENOTSUP; } -static inline int st_app_init_display(struct st_display* d, char* name, int width, - int height, char* font) { +static inline int st_app_init_display(struct st_display *d, char *name, + int width, int height, char *font) { MTL_MAY_UNUSED(d); MTL_MAY_UNUSED(name); MTL_MAY_UNUSED(width); @@ -38,7 +38,7 @@ static inline int st_app_init_display(struct st_display* d, char* name, int widt warn("%s, not support as build without SDL2\n", __func__); return -ENOTSUP; } -static inline int st_app_uinit_display(struct st_display* d) { +static inline int st_app_uinit_display(struct st_display *d) { MTL_MAY_UNUSED(d); warn("%s, not support as build without SDL2\n", __func__); return -ENOTSUP; diff --git a/app/src/rx_ancillary_app.c b/app/src/rx_ancillary_app.c index 4a9cdeb17..ba2df9832 100644 --- a/app/src/rx_ancillary_app.c +++ b/app/src/rx_ancillary_app.c @@ -4,17 +4,20 @@ #include "rx_ancillary_app.h" -static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session* s, void* usrptr) { - struct st40_rfc8331_rtp_hdr* hdr = (struct st40_rfc8331_rtp_hdr*)usrptr; - struct st40_rfc8331_payload_hdr* payload_hdr = - (struct st40_rfc8331_payload_hdr*)(&hdr[1]); +static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session *s, + void *usrptr) { + struct st40_rfc8331_rtp_hdr *hdr = (struct st40_rfc8331_rtp_hdr *)usrptr; + struct st40_rfc8331_payload_hdr *payload_hdr = + (struct st40_rfc8331_payload_hdr *)(&hdr[1]); int anc_count = hdr->anc_count; int idx, total_size, payload_len; dbg("%s(%d), anc_count %d\n", __func__, s->idx, anc_count); for (idx = 0; idx < anc_count; idx++) { - payload_hdr->swaped_first_hdr_chunk = ntohl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = ntohl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = + ntohl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = + ntohl(payload_hdr->swaped_second_hdr_chunk); if (!st40_check_parity_bits(payload_hdr->second_hdr_chunk.did) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.sdid) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.data_count)) { @@ -25,10 +28,13 @@ static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session* s, void* usrptr) // verify checksum uint16_t checksum = 0; - checksum = st40_get_udw(udw_size + 3, (uint8_t*)&payload_hdr->second_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); + checksum = + st40_get_udw(udw_size + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = + htonl(payload_hdr->swaped_second_hdr_chunk); if (checksum != - st40_calc_checksum(3 + udw_size, (uint8_t*)&payload_hdr->second_hdr_chunk)) { + st40_calc_checksum(3 + udw_size, + (uint8_t *)&payload_hdr->second_hdr_chunk)) { err("%s(%d), anc frame checksum error\n", __func__, s->idx); return; } @@ -36,20 +42,24 @@ static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session* s, void* usrptr) #ifdef DEBUG uint16_t data; for (int i = 0; i < udw_size; i++) { - data = st40_get_udw(i + 3, (uint8_t*)&payload_hdr->second_hdr_chunk); - if (!st40_check_parity_bits(data)) err("anc udw checkParityBits error\n"); + data = st40_get_udw(i + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); + if (!st40_check_parity_bits(data)) + err("anc udw checkParityBits error\n"); dbg("%c", data & 0xff); } dbg("\n"); #endif - total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = - sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC - payload_hdr = (struct st40_rfc8331_payload_hdr*)((uint8_t*)payload_hdr + payload_len); + total_size = + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = + (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + + total_size; // Full size of one ANC + payload_hdr = (struct st40_rfc8331_payload_hdr *)((uint8_t *)payload_hdr + + payload_len); } s->stat_frame_total_received++; @@ -57,12 +67,12 @@ static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session* s, void* usrptr) s->stat_frame_first_rx_time = st_app_get_monotonic_time(); } -static void* app_rx_anc_read_thread(void* arg) { - struct st_app_rx_anc_session* s = arg; +static void *app_rx_anc_read_thread(void *arg) { + struct st_app_rx_anc_session *s = arg; int idx = s->idx; - void* usrptr; + void *usrptr; uint16_t len; - void* mbuf; + void *mbuf; info("%s(%d), start\n", __func__, idx); while (!s->st40_app_thread_stop) { @@ -84,8 +94,8 @@ static void* app_rx_anc_read_thread(void* arg) { return NULL; } -static int app_rx_anc_rtp_ready(void* priv) { - struct st_app_rx_anc_session* s = priv; +static int app_rx_anc_rtp_ready(void *priv) { + struct st_app_rx_anc_session *s = priv; st_pthread_mutex_lock(&s->st40_wake_mutex); st_pthread_cond_signal(&s->st40_wake_cond); @@ -93,7 +103,7 @@ static int app_rx_anc_rtp_ready(void* priv) { return 0; } -static int app_rx_anc_uinit(struct st_app_rx_anc_session* s) { +static int app_rx_anc_uinit(struct st_app_rx_anc_session *s) { int ret, idx = s->idx; s->st40_app_thread_stop = true; if (s->st40_app_thread) { @@ -106,7 +116,8 @@ static int app_rx_anc_uinit(struct st_app_rx_anc_session* s) { } if (s->handle) { ret = st40_rx_free(s->handle); - if (ret < 0) err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } st_pthread_mutex_destroy(&s->st40_wake_mutex); @@ -115,8 +126,9 @@ static int app_rx_anc_uinit(struct st_app_rx_anc_session* s) { return 0; } -static int app_rx_anc_init(struct st_app_context* ctx, st_json_ancillary_session_t* anc, - struct st_app_rx_anc_session* s) { +static int app_rx_anc_init(struct st_app_context *ctx, + st_json_ancillary_session_t *anc, + struct st_app_rx_anc_session *s) { int idx = s->idx, ret; struct st40_rx_ops ops; char name[32]; @@ -127,33 +139,41 @@ static int app_rx_anc_init(struct st_app_context* ctx, st_json_ancillary_session ops.name = name; ops.priv = s; ops.num_port = anc ? anc->base.num_inf : ctx->para.num_ports; - memcpy( - ops.ip_addr[MTL_SESSION_PORT_P], - anc ? st_json_ip(ctx, &anc->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops.ip_addr[MTL_SESSION_PORT_P], + anc ? st_json_ip(ctx, &anc->base, MTL_SESSION_PORT_P) + : ctx->rx_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], - anc ? anc->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], + anc ? anc->base.mcast_src_ip[MTL_PORT_P] + : ctx->rx_mcast_sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = + anc ? anc->base.udp_port : (10200 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], anc ? st_json_ip(ctx, &anc->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], - anc ? anc->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], + anc ? anc->base.mcast_src_ip[MTL_PORT_R] + : ctx->rx_mcast_sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = + anc ? anc->base.udp_port : (10200 + s->idx); } ops.rtp_ring_size = 1024; - ops.payload_type = anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; + ops.payload_type = + anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; ops.interlaced = anc ? anc->info.interlaced : false; ops.notify_rtp_ready = app_rx_anc_rtp_ready; - if (anc && anc->enable_rtcp) ops.flags |= ST40_RX_FLAG_ENABLE_RTCP; + if (anc && anc->enable_rtcp) + ops.flags |= ST40_RX_FLAG_ENABLE_RTCP; st_pthread_mutex_init(&s->st40_wake_mutex, NULL); st_pthread_cond_init(&s->st40_wake_cond, NULL); @@ -182,19 +202,22 @@ static bool app_rx_anc_fps_check(double framerate) { for (enum st_fps fps = 0; fps < ST_FPS_MAX; fps++) { expect = st_frame_rate(fps); - if (ST_APP_EXPECT_NEAR(framerate, expect, expect * 0.05)) return true; + if (ST_APP_EXPECT_NEAR(framerate, expect, expect * 0.05)) + return true; } return false; } -static int app_rx_anc_result(struct st_app_rx_anc_session* s) { +static int app_rx_anc_result(struct st_app_rx_anc_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) return -EINVAL; + if (!s->stat_frame_total_received) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, app_rx_anc_fps_check(framerate) ? "OK" : "FAILED", framerate, @@ -202,18 +225,19 @@ static int app_rx_anc_result(struct st_app_rx_anc_session* s) { return 0; } -int st_app_rx_anc_sessions_init(struct st_app_context* ctx) { +int st_app_rx_anc_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_rx_anc_session* s; - ctx->rx_anc_sessions = (struct st_app_rx_anc_session*)st_app_zmalloc( + struct st_app_rx_anc_session *s; + ctx->rx_anc_sessions = (struct st_app_rx_anc_session *)st_app_zmalloc( sizeof(struct st_app_rx_anc_session) * ctx->rx_anc_session_cnt); - if (!ctx->rx_anc_sessions) return -ENOMEM; + if (!ctx->rx_anc_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_anc_session_cnt; i++) { s = &ctx->rx_anc_sessions[i]; s->idx = i; - ret = app_rx_anc_init(ctx, ctx->json_ctx ? &ctx->json_ctx->rx_anc_sessions[i] : NULL, - s); + ret = app_rx_anc_init( + ctx, ctx->json_ctx ? &ctx->json_ctx->rx_anc_sessions[i] : NULL, s); if (ret < 0) { err("%s(%d), app_rx_anc_session_init fail %d\n", __func__, i, ret); return ret; @@ -223,10 +247,11 @@ int st_app_rx_anc_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_rx_anc_sessions_uinit(struct st_app_context* ctx) { +int st_app_rx_anc_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_rx_anc_session* s; - if (!ctx->rx_anc_sessions) return 0; + struct st_app_rx_anc_session *s; + if (!ctx->rx_anc_sessions) + return 0; for (i = 0; i < ctx->rx_anc_session_cnt; i++) { s = &ctx->rx_anc_sessions[i]; app_rx_anc_uinit(s); @@ -235,10 +260,11 @@ int st_app_rx_anc_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_rx_anc_sessions_result(struct st_app_context* ctx) { +int st_app_rx_anc_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_anc_session* s; - if (!ctx->rx_anc_sessions) return 0; + struct st_app_rx_anc_session *s; + if (!ctx->rx_anc_sessions) + return 0; for (i = 0; i < ctx->rx_anc_session_cnt; i++) { s = &ctx->rx_anc_sessions[i]; diff --git a/app/src/rx_ancillary_app.h b/app/src/rx_ancillary_app.h index ecf40b950..a36c52446 100644 --- a/app/src/rx_ancillary_app.h +++ b/app/src/rx_ancillary_app.h @@ -13,10 +13,10 @@ #ifndef _RX_APP_ANC_HEAD_H_ #define _RX_APP_ANC_HEAD_H_ -int st_app_rx_anc_sessions_init(struct st_app_context* ctx); +int st_app_rx_anc_sessions_init(struct st_app_context *ctx); -int st_app_rx_anc_sessions_uinit(struct st_app_context* ctx); +int st_app_rx_anc_sessions_uinit(struct st_app_context *ctx); -int st_app_rx_anc_sessions_result(struct st_app_context* ctx); +int st_app_rx_anc_sessions_result(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/rx_st20p_app.c b/app/src/rx_st20p_app.c index bdd0fce27..be3542c75 100644 --- a/app/src/rx_st20p_app.c +++ b/app/src/rx_st20p_app.c @@ -4,9 +4,9 @@ #include "rx_st20p_app.h" -static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session* s, - struct st_frame* frame) { - struct st_display* d = s->display; +static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session *s, + struct st_frame *frame) { + struct st_display *d = s->display; int idx = s->idx; if (s->num_port > 1) { @@ -14,15 +14,18 @@ static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session* s, frame->pkts_total, frame->pkts_recv[MTL_SESSION_PORT_P], frame->pkts_recv[MTL_SESSION_PORT_R]); if (frame->pkts_recv[MTL_SESSION_PORT_P] < (frame->pkts_total / 2)) - warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", __func__, idx, - frame->pkts_recv[MTL_SESSION_PORT_P], frame->pkts_total); + warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", + __func__, idx, frame->pkts_recv[MTL_SESSION_PORT_P], + frame->pkts_total); if (frame->pkts_recv[MTL_SESSION_PORT_R] < (frame->pkts_total / 2)) - warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", __func__, idx, - frame->pkts_recv[MTL_SESSION_PORT_R], frame->pkts_total); + warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", + __func__, idx, frame->pkts_recv[MTL_SESSION_PORT_R], + frame->pkts_total); } if (frame->interlaced) { - dbg("%s(%d), %s field\n", __func__, s->idx, frame->second_field ? "second" : "first"); + dbg("%s(%d), %s field\n", __func__, s->idx, + frame->second_field ? "second" : "first"); } if (d && d->front_frame) { @@ -44,9 +47,9 @@ static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session* s, } } -static void* app_rx_st20p_frame_thread(void* arg) { - struct st_app_rx_st20p_session* s = arg; - struct st_frame* frame; +static void *app_rx_st20p_frame_thread(void *arg) { + struct st_app_rx_st20p_session *s = arg; + struct st_frame *frame; uint8_t shas[SHA256_DIGEST_LENGTH]; int idx = s->idx; @@ -81,9 +84,11 @@ static void* app_rx_st20p_frame_thread(void* arg) { err("%s(%d), invalid user meta size %" PRId64 "\n", __func__, idx, frame->user_meta_size); } else { - st_sha256((unsigned char*)frame->addr[0], st_frame_plane_size(frame, 0), shas); + st_sha256((unsigned char *)frame->addr[0], + st_frame_plane_size(frame, 0), shas); if (memcmp(shas, frame->user_meta, sizeof(shas))) { - err("%s(%d), sha check fail for frame %p\n", __func__, idx, frame->addr); + err("%s(%d), sha check fail for frame %p\n", __func__, idx, + frame->addr); st_sha_dump("user meta sha:", frame->user_meta); st_sha_dump("frame sha:", shas); } @@ -99,10 +104,11 @@ static void* app_rx_st20p_frame_thread(void* arg) { return NULL; } -static int app_rx_st20p_init_frame_thread(struct st_app_rx_st20p_session* s) { +static int app_rx_st20p_init_frame_thread(struct st_app_rx_st20p_session *s) { int ret, idx = s->idx; - ret = pthread_create(&s->st20p_app_thread, NULL, app_rx_st20p_frame_thread, s); + ret = + pthread_create(&s->st20p_app_thread, NULL, app_rx_st20p_frame_thread, s); if (ret < 0) { err("%s(%d), st20p_app_thread create fail %d\n", __func__, ret, idx); return -EIO; @@ -115,7 +121,7 @@ static int app_rx_st20p_init_frame_thread(struct st_app_rx_st20p_session* s) { return 0; } -static int app_rx_st20p_uinit(struct st_app_rx_st20p_session* s) { +static int app_rx_st20p_uinit(struct st_app_rx_st20p_session *s) { int ret, idx = s->idx; st_app_uinit_display(s->display); @@ -128,20 +134,22 @@ static int app_rx_st20p_uinit(struct st_app_rx_st20p_session* s) { if (s->st20p_app_thread_stop) { /* wake up the thread */ info("%s(%d), wait app thread stop\n", __func__, idx); - if (s->handle) st20p_rx_wake_block(s->handle); + if (s->handle) + st20p_rx_wake_block(s->handle); pthread_join(s->st20p_app_thread, NULL); } if (s->handle) { ret = st20p_rx_free(s->handle); - if (ret < 0) err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_rx_st20p_io_stat(struct st_app_rx_st20p_session* s) { +static int app_rx_st20p_io_stat(struct st_app_rx_st20p_session *s) { int idx = s->idx; uint64_t cur_time = st_app_get_monotonic_time(); double time_sec = (double)(cur_time - s->last_stat_time_ns) / NS_PER_S; @@ -149,11 +157,13 @@ static int app_rx_st20p_io_stat(struct st_app_rx_st20p_session* s) { int ret; struct st20_rx_port_status stats; - if (!s->handle) return 0; + if (!s->handle) + return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20p_rx_get_port_stats(s->handle, port, &stats); - if (ret < 0) return ret; + if (ret < 0) + return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -165,9 +175,9 @@ static int app_rx_st20p_io_stat(struct st_app_rx_st20p_session* s) { return 0; } -static int app_rx_st20p_init(struct st_app_context* ctx, - struct st_json_st20p_session* st20p, - struct st_app_rx_st20p_session* s) { +static int app_rx_st20p_init(struct st_app_context *ctx, + struct st_json_st20p_session *st20p, + struct st_app_rx_st20p_session *s) { int idx = s->idx, ret; struct st20p_rx_ops ops; char name[32]; @@ -185,26 +195,27 @@ static int app_rx_st20p_init(struct st_app_context* ctx, st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy( - ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], - st20p ? st20p->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = st20p ? st20p->base.udp_port : (10000 + s->idx); + memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], + st20p ? st20p->base.mcast_src_ip[MTL_PORT_P] + : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = + st20p ? st20p->base.udp_port : (10000 + s->idx); if (ops.port.num_port > 1) { memcpy(ops.port.ip_addr[MTL_SESSION_PORT_R], st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy( - ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], - st20p ? st20p->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], + st20p ? st20p->base.mcast_src_ip[MTL_PORT_R] + : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st20p ? st20p->base.udp_port : (10000 + s->idx); } @@ -213,18 +224,24 @@ static int app_rx_st20p_init(struct st_app_context* ctx, ops.height = st20p ? st20p->info.height : 1080; ops.fps = st20p ? st20p->info.fps : ST_FPS_P59_94; ops.interlaced = st20p ? st20p->info.interlaced : false; - ops.output_fmt = st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; - ops.transport_fmt = st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; - ops.port.payload_type = st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.output_fmt = + st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.transport_fmt = + st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; + ops.port.payload_type = + st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.device = st20p ? st20p->info.device : ST_PLUGIN_DEVICE_AUTO; ops.flags |= ST20P_RX_FLAG_BLOCK_GET; ops.rx_burst_size = ctx->rx_burst_size; ops.framebuff_cnt = s->framebuff_cnt; /* always try to enable DMA offload */ ops.flags |= ST20P_RX_FLAG_DMA_OFFLOAD; - if (st20p && st20p->enable_rtcp) ops.flags |= ST20P_RX_FLAG_ENABLE_RTCP; - if (ctx->enable_timing_parser) ops.flags |= ST20P_RX_FLAG_TIMING_PARSER_STAT; - if (ctx->rx_video_multi_thread) ops.flags |= ST20P_RX_FLAG_USE_MULTI_THREADS; + if (st20p && st20p->enable_rtcp) + ops.flags |= ST20P_RX_FLAG_ENABLE_RTCP; + if (ctx->enable_timing_parser) + ops.flags |= ST20P_RX_FLAG_TIMING_PARSER_STAT; + if (ctx->rx_video_multi_thread) + ops.flags |= ST20P_RX_FLAG_USE_MULTI_THREADS; if (ctx->force_rx_video_numa >= 0) { ops.flags |= ST20P_RX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_rx_video_numa; @@ -241,7 +258,7 @@ static int app_rx_st20p_init(struct st_app_context* ctx, s->expect_fps = st_frame_rate(ops.fps); if ((st20p && st20p->display) || ctx->rx_display) { - struct st_display* d = st_app_zmalloc(sizeof(struct st_display)); + struct st_display *d = st_app_zmalloc(sizeof(struct st_display)); ret = st_app_init_display(d, name, s->width, s->height, ctx->ttf_file); if (ret < 0) { err("%s(%d), st_app_init_display fail %d\n", __func__, idx, ret); @@ -276,7 +293,7 @@ static int app_rx_st20p_init(struct st_app_context* ctx, return 0; } -static int app_rx_st20p_stat(struct st_app_rx_st20p_session* s) { +static int app_rx_st20p_stat(struct st_app_rx_st20p_session *s) { uint64_t cur_time_ns = st_app_get_monotonic_time(); #ifdef DEBUG double time_sec = (double)(cur_time_ns - s->stat_last_time) / NS_PER_S; @@ -285,7 +302,8 @@ static int app_rx_st20p_stat(struct st_app_rx_st20p_session* s) { s->stat_frame_received); #endif if (s->measure_latency && s->stat_frame_received) { - double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = + (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -295,37 +313,43 @@ static int app_rx_st20p_stat(struct st_app_rx_st20p_session* s) { return 0; } -static int app_rx_st20p_result(struct st_app_rx_st20p_session* s) { +static int app_rx_st20p_result(struct st_app_rx_st20p_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) return -EINVAL; + if (!s->stat_frame_total_received) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) + ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } -static int app_rx_st20p_pcap(struct st_app_rx_st20p_session* s) { +static int app_rx_st20p_pcap(struct st_app_rx_st20p_session *s) { if (s->pcapng_max_pkts) st20p_rx_pcapng_dump(s->handle, s->pcapng_max_pkts, false, NULL); return 0; } -int st_app_rx_st20p_sessions_init(struct st_app_context* ctx) { +int st_app_rx_st20p_sessions_init(struct st_app_context *ctx) { int ret = 0, i = 0; - struct st_app_rx_st20p_session* s; + struct st_app_rx_st20p_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) + fb_cnt = ST_APP_DEFAULT_FB_CNT; - dbg("%s(%d), rx_st20p_session_cnt %d\n", __func__, i, ctx->rx_st20p_session_cnt); - ctx->rx_st20p_sessions = (struct st_app_rx_st20p_session*)st_app_zmalloc( + dbg("%s(%d), rx_st20p_session_cnt %d\n", __func__, i, + ctx->rx_st20p_session_cnt); + ctx->rx_st20p_sessions = (struct st_app_rx_st20p_session *)st_app_zmalloc( sizeof(struct st_app_rx_st20p_session) * ctx->rx_st20p_session_cnt); - if (!ctx->rx_st20p_sessions) return -ENOMEM; + if (!ctx->rx_st20p_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; s->idx = i; @@ -343,10 +367,11 @@ int st_app_rx_st20p_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_rx_st20p_sessions_uinit(struct st_app_context* ctx) { +int st_app_rx_st20p_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_rx_st20p_session* s; - if (!ctx->rx_st20p_sessions) return 0; + struct st_app_rx_st20p_session *s; + if (!ctx->rx_st20p_sessions) + return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; app_rx_st20p_uinit(s); @@ -356,10 +381,11 @@ int st_app_rx_st20p_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_rx_st20p_sessions_stat(struct st_app_context* ctx) { +int st_app_rx_st20p_sessions_stat(struct st_app_context *ctx) { int i; - struct st_app_rx_st20p_session* s; - if (!ctx->rx_st20p_sessions) return 0; + struct st_app_rx_st20p_session *s; + if (!ctx->rx_st20p_sessions) + return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; @@ -369,11 +395,12 @@ int st_app_rx_st20p_sessions_stat(struct st_app_context* ctx) { return 0; } -int st_app_rx_st20p_sessions_result(struct st_app_context* ctx) { +int st_app_rx_st20p_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_st20p_session* s; + struct st_app_rx_st20p_session *s; - if (!ctx->rx_st20p_sessions) return 0; + if (!ctx->rx_st20p_sessions) + return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; @@ -383,11 +410,12 @@ int st_app_rx_st20p_sessions_result(struct st_app_context* ctx) { return ret; } -int st_app_rx_st20p_sessions_pcap(struct st_app_context* ctx) { +int st_app_rx_st20p_sessions_pcap(struct st_app_context *ctx) { int i; - struct st_app_rx_st20p_session* s; + struct st_app_rx_st20p_session *s; - if (!ctx->rx_st20p_sessions) return 0; + if (!ctx->rx_st20p_sessions) + return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; @@ -397,10 +425,11 @@ int st_app_rx_st20p_sessions_pcap(struct st_app_context* ctx) { return 0; } -int st_app_rx_st20p_io_stat(struct st_app_context* ctx) { +int st_app_rx_st20p_io_stat(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_st20p_session* s; - if (!ctx->rx_st20p_sessions) return 0; + struct st_app_rx_st20p_session *s; + if (!ctx->rx_st20p_sessions) + return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; diff --git a/app/src/rx_st20p_app.h b/app/src/rx_st20p_app.h index 4224a6301..885af7331 100644 --- a/app/src/rx_st20p_app.h +++ b/app/src/rx_st20p_app.h @@ -14,11 +14,11 @@ #ifndef _RX_APP_ST20P_HEAD_H_ #define _RX_APP_ST20P_HEAD_H_ -int st_app_rx_st20p_sessions_init(struct st_app_context* ctx); -int st_app_rx_st20p_sessions_uinit(struct st_app_context* ctx); -int st_app_rx_st20p_sessions_stat(struct st_app_context* ctx); -int st_app_rx_st20p_sessions_result(struct st_app_context* ctx); -int st_app_rx_st20p_sessions_pcap(struct st_app_context* ctx); -int st_app_rx_st20p_io_stat(struct st_app_context* ctx); +int st_app_rx_st20p_sessions_init(struct st_app_context *ctx); +int st_app_rx_st20p_sessions_uinit(struct st_app_context *ctx); +int st_app_rx_st20p_sessions_stat(struct st_app_context *ctx); +int st_app_rx_st20p_sessions_result(struct st_app_context *ctx); +int st_app_rx_st20p_sessions_pcap(struct st_app_context *ctx); +int st_app_rx_st20p_io_stat(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/rx_st22p_app.c b/app/src/rx_st22p_app.c index 80567e688..ae67b6f45 100644 --- a/app/src/rx_st22p_app.c +++ b/app/src/rx_st22p_app.c @@ -4,12 +4,13 @@ #include "rx_st22p_app.h" -static void app_rx_st22p_consume_frame(struct st_app_rx_st22p_session* s, - struct st_frame* frame) { - struct st_display* d = s->display; +static void app_rx_st22p_consume_frame(struct st_app_rx_st22p_session *s, + struct st_frame *frame) { + struct st_display *d = s->display; if (frame->interlaced) { - dbg("%s(%d), %s field\n", __func__, s->idx, frame->second_field ? "second" : "first"); + dbg("%s(%d), %s field\n", __func__, s->idx, + frame->second_field ? "second" : "first"); } if (d && d->front_frame) { @@ -31,9 +32,9 @@ static void app_rx_st22p_consume_frame(struct st_app_rx_st22p_session* s, } } -static void* app_rx_st22p_frame_thread(void* arg) { - struct st_app_rx_st22p_session* s = arg; - struct st_frame* frame; +static void *app_rx_st22p_frame_thread(void *arg) { + struct st_app_rx_st22p_session *s = arg; + struct st_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->st22p_app_thread_stop) { @@ -71,10 +72,11 @@ static void* app_rx_st22p_frame_thread(void* arg) { return NULL; } -static int app_rx_st22p_init_frame_thread(struct st_app_rx_st22p_session* s) { +static int app_rx_st22p_init_frame_thread(struct st_app_rx_st22p_session *s) { int ret, idx = s->idx; - ret = pthread_create(&s->st22p_app_thread, NULL, app_rx_st22p_frame_thread, s); + ret = + pthread_create(&s->st22p_app_thread, NULL, app_rx_st22p_frame_thread, s); if (ret < 0) { err("%s(%d), st22p_app_thread create fail %d\n", __func__, ret, idx); return -EIO; @@ -87,7 +89,7 @@ static int app_rx_st22p_init_frame_thread(struct st_app_rx_st22p_session* s) { return 0; } -static int app_rx_st22p_uinit(struct st_app_rx_st22p_session* s) { +static int app_rx_st22p_uinit(struct st_app_rx_st22p_session *s) { int ret, idx = s->idx; st_app_uinit_display(s->display); @@ -99,22 +101,24 @@ static int app_rx_st22p_uinit(struct st_app_rx_st22p_session* s) { s->st22p_app_thread_stop = true; if (s->st22p_app_thread_stop) { info("%s(%d), wait app thread stop\n", __func__, idx); - if (s->handle) st22p_rx_wake_block(s->handle); + if (s->handle) + st22p_rx_wake_block(s->handle); pthread_join(s->st22p_app_thread, NULL); } if (s->handle) { ret = st22p_rx_free(s->handle); - if (ret < 0) err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_rx_st22p_init(struct st_app_context* ctx, - struct st_json_st22p_session* st22p, - struct st_app_rx_st22p_session* s) { +static int app_rx_st22p_init(struct st_app_context *ctx, + struct st_json_st22p_session *st22p, + struct st_app_rx_st22p_session *s) { int idx = s->idx, ret; struct st22p_rx_ops ops; char name[32]; @@ -129,26 +133,27 @@ static int app_rx_st22p_init(struct st_app_context* ctx, st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy( - ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], - st22p ? st22p->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = st22p ? st22p->base.udp_port : (10000 + s->idx); + memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], + st22p ? st22p->base.mcast_src_ip[MTL_PORT_P] + : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = + st22p ? st22p->base.udp_port : (10000 + s->idx); if (ops.port.num_port > 1) { memcpy(ops.port.ip_addr[MTL_SESSION_PORT_R], st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy( - ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], - st22p ? st22p->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], + st22p ? st22p->base.mcast_src_ip[MTL_PORT_R] + : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st22p ? st22p->base.udp_port : (10000 + s->idx); } @@ -157,8 +162,10 @@ static int app_rx_st22p_init(struct st_app_context* ctx, ops.height = st22p ? st22p->info.height : 1080; ops.fps = st22p ? st22p->info.fps : ST_FPS_P59_94; ops.interlaced = st22p ? st22p->info.interlaced : false; - ops.output_fmt = st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; - ops.port.payload_type = st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; + ops.output_fmt = + st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.port.payload_type = + st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; ops.pack_type = st22p ? st22p->info.pack_type : ST22_PACK_CODESTREAM; ops.codec = st22p ? st22p->info.codec : ST22_CODEC_JPEGXS; ops.device = st22p ? st22p->info.device : ST_PLUGIN_DEVICE_AUTO; @@ -166,7 +173,8 @@ static int app_rx_st22p_init(struct st_app_context* ctx, ops.max_codestream_size = 0; ops.flags |= ST22P_RX_FLAG_BLOCK_GET; ops.framebuff_cnt = s->framebuff_cnt; - if (st22p && st22p->enable_rtcp) ops.flags |= ST22P_RX_FLAG_ENABLE_RTCP; + if (st22p && st22p->enable_rtcp) + ops.flags |= ST22P_RX_FLAG_ENABLE_RTCP; if (ctx->force_rx_video_numa >= 0) { ops.flags |= ST22P_RX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_rx_video_numa; @@ -182,7 +190,7 @@ static int app_rx_st22p_init(struct st_app_context* ctx, s->expect_fps = st_frame_rate(ops.fps); if ((st22p && st22p->display) || ctx->rx_display) { - struct st_display* d = st_app_zmalloc(sizeof(struct st_display)); + struct st_display *d = st_app_zmalloc(sizeof(struct st_display)); ret = st_app_init_display(d, name, s->width, s->height, ctx->ttf_file); if (ret < 0) { err("%s(%d), st_app_init_display fail %d\n", __func__, idx, ret); @@ -217,7 +225,7 @@ static int app_rx_st22p_init(struct st_app_context* ctx, return 0; } -static int app_rx_st22p_stat(struct st_app_rx_st22p_session* s) { +static int app_rx_st22p_stat(struct st_app_rx_st22p_session *s) { uint64_t cur_time_ns = st_app_get_monotonic_time(); #ifdef DEBUG double time_sec = (double)(cur_time_ns - s->stat_last_time) / NS_PER_S; @@ -226,7 +234,8 @@ static int app_rx_st22p_stat(struct st_app_rx_st22p_session* s) { s->stat_frame_received); #endif if (s->measure_latency && s->stat_frame_received) { - double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = + (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -236,37 +245,43 @@ static int app_rx_st22p_stat(struct st_app_rx_st22p_session* s) { return 0; } -static int app_rx_st22p_result(struct st_app_rx_st22p_session* s) { +static int app_rx_st22p_result(struct st_app_rx_st22p_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) return -EINVAL; + if (!s->stat_frame_total_received) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) + ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } -static int app_rx_st22p_pcap(struct st_app_rx_st22p_session* s) { +static int app_rx_st22p_pcap(struct st_app_rx_st22p_session *s) { if (s->pcapng_max_pkts) st22p_rx_pcapng_dump(s->handle, s->pcapng_max_pkts, false, NULL); return 0; } -int st_app_rx_st22p_sessions_init(struct st_app_context* ctx) { +int st_app_rx_st22p_sessions_init(struct st_app_context *ctx) { int ret = 0, i = 0; - struct st_app_rx_st22p_session* s; + struct st_app_rx_st22p_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) + fb_cnt = ST_APP_DEFAULT_FB_CNT; - dbg("%s(%d), rx_st22p_session_cnt %d\n", __func__, i, ctx->rx_st22p_session_cnt); - ctx->rx_st22p_sessions = (struct st_app_rx_st22p_session*)st_app_zmalloc( + dbg("%s(%d), rx_st22p_session_cnt %d\n", __func__, i, + ctx->rx_st22p_session_cnt); + ctx->rx_st22p_sessions = (struct st_app_rx_st22p_session *)st_app_zmalloc( sizeof(struct st_app_rx_st22p_session) * ctx->rx_st22p_session_cnt); - if (!ctx->rx_st22p_sessions) return -ENOMEM; + if (!ctx->rx_st22p_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; s->idx = i; @@ -284,10 +299,11 @@ int st_app_rx_st22p_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_rx_st22p_sessions_uinit(struct st_app_context* ctx) { +int st_app_rx_st22p_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_rx_st22p_session* s; - if (!ctx->rx_st22p_sessions) return 0; + struct st_app_rx_st22p_session *s; + if (!ctx->rx_st22p_sessions) + return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; app_rx_st22p_uinit(s); @@ -297,10 +313,11 @@ int st_app_rx_st22p_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_rx_st22p_sessions_stat(struct st_app_context* ctx) { +int st_app_rx_st22p_sessions_stat(struct st_app_context *ctx) { int i; - struct st_app_rx_st22p_session* s; - if (!ctx->rx_st22p_sessions) return 0; + struct st_app_rx_st22p_session *s; + if (!ctx->rx_st22p_sessions) + return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; @@ -310,11 +327,12 @@ int st_app_rx_st22p_sessions_stat(struct st_app_context* ctx) { return 0; } -int st_app_rx_st22p_sessions_result(struct st_app_context* ctx) { +int st_app_rx_st22p_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_st22p_session* s; + struct st_app_rx_st22p_session *s; - if (!ctx->rx_st22p_sessions) return 0; + if (!ctx->rx_st22p_sessions) + return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; @@ -324,11 +342,12 @@ int st_app_rx_st22p_sessions_result(struct st_app_context* ctx) { return ret; } -int st_app_rx_st22p_sessions_pcap(struct st_app_context* ctx) { +int st_app_rx_st22p_sessions_pcap(struct st_app_context *ctx) { int i; - struct st_app_rx_st22p_session* s; + struct st_app_rx_st22p_session *s; - if (!ctx->rx_st22p_sessions) return 0; + if (!ctx->rx_st22p_sessions) + return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; diff --git a/app/src/rx_st22p_app.h b/app/src/rx_st22p_app.h index 208912d54..8e8b2905a 100644 --- a/app/src/rx_st22p_app.h +++ b/app/src/rx_st22p_app.h @@ -14,10 +14,10 @@ #ifndef _RX_APP_ST22P_HEAD_H_ #define _RX_APP_ST22P_HEAD_H_ -int st_app_rx_st22p_sessions_init(struct st_app_context* ctx); -int st_app_rx_st22p_sessions_uinit(struct st_app_context* ctx); -int st_app_rx_st22p_sessions_stat(struct st_app_context* ctx); -int st_app_rx_st22p_sessions_result(struct st_app_context* ctx); -int st_app_rx_st22p_sessions_pcap(struct st_app_context* ctx); +int st_app_rx_st22p_sessions_init(struct st_app_context *ctx); +int st_app_rx_st22p_sessions_uinit(struct st_app_context *ctx); +int st_app_rx_st22p_sessions_stat(struct st_app_context *ctx); +int st_app_rx_st22p_sessions_result(struct st_app_context *ctx); +int st_app_rx_st22p_sessions_pcap(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/rx_st30p_app.c b/app/src/rx_st30p_app.c index b7204fe67..9f86e053e 100644 --- a/app/src/rx_st30p_app.c +++ b/app/src/rx_st30p_app.c @@ -4,17 +4,17 @@ #include "rx_st30p_app.h" -static void app_rx_st30p_consume_frame(struct st_app_rx_st30p_session* s, - struct st30_frame* frame) { +static void app_rx_st30p_consume_frame(struct st_app_rx_st30p_session *s, + struct st30_frame *frame) { // int idx = s->idx; // todo MTL_MAY_UNUSED(s); MTL_MAY_UNUSED(frame); } -static void* app_rx_st30p_frame_thread(void* arg) { - struct st_app_rx_st30p_session* s = arg; - struct st30_frame* frame; +static void *app_rx_st30p_frame_thread(void *arg) { + struct st_app_rx_st30p_session *s = arg; + struct st30_frame *frame; info("%s(%d), start\n", __func__, s->idx); while (!s->st30p_app_thread_stop) { @@ -36,10 +36,11 @@ static void* app_rx_st30p_frame_thread(void* arg) { return NULL; } -static int app_rx_st30p_init_frame_thread(struct st_app_rx_st30p_session* s) { +static int app_rx_st30p_init_frame_thread(struct st_app_rx_st30p_session *s) { int ret, idx = s->idx; - ret = pthread_create(&s->st30p_app_thread, NULL, app_rx_st30p_frame_thread, s); + ret = + pthread_create(&s->st30p_app_thread, NULL, app_rx_st30p_frame_thread, s); if (ret < 0) { err("%s(%d), st30p_app_thread create fail %d\n", __func__, ret, idx); return -EIO; @@ -52,29 +53,31 @@ static int app_rx_st30p_init_frame_thread(struct st_app_rx_st30p_session* s) { return 0; } -static int app_rx_st30p_uinit(struct st_app_rx_st30p_session* s) { +static int app_rx_st30p_uinit(struct st_app_rx_st30p_session *s) { int ret, idx = s->idx; s->st30p_app_thread_stop = true; if (s->st30p_app_thread_stop) { /* wake up the thread */ info("%s(%d), wait app thread stop\n", __func__, idx); - if (s->handle) st30p_rx_wake_block(s->handle); + if (s->handle) + st30p_rx_wake_block(s->handle); pthread_join(s->st30p_app_thread, NULL); } if (s->handle) { ret = st30p_rx_free(s->handle); - if (ret < 0) err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_rx_st30p_init(struct st_app_context* ctx, - struct st_json_st30p_session* st30p, - struct st_app_rx_st30p_session* s) { +static int app_rx_st30p_init(struct st_app_context *ctx, + struct st_json_st30p_session *st30p, + struct st_app_rx_st30p_session *s) { int idx = s->idx, ret; struct st30p_rx_ops ops; char name[32]; @@ -91,30 +94,32 @@ static int app_rx_st30p_init(struct st_app_context* ctx, st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy( - ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], - st30p ? st30p->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = st30p ? st30p->base.udp_port : (10000 + s->idx); + memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], + st30p ? st30p->base.mcast_src_ip[MTL_PORT_P] + : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = + st30p ? st30p->base.udp_port : (10000 + s->idx); if (ops.port.num_port > 1) { memcpy(ops.port.ip_addr[MTL_SESSION_PORT_R], st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy( - ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], - st30p ? st30p->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], + st30p ? st30p->base.mcast_src_ip[MTL_PORT_R] + : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st30p ? st30p->base.udp_port : (10000 + s->idx); } - ops.port.payload_type = st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.port.payload_type = + st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; ops.fmt = st30p ? st30p->info.audio_format : ST30_FMT_PCM24; ops.channel = st30p ? st30p->info.audio_channel : 2; @@ -122,7 +127,8 @@ static int app_rx_st30p_init(struct st_app_context* ctx, ops.ptime = st30p ? st30p->info.audio_ptime : ST30_PTIME_1MS; /* set frame size to 10ms time */ int framebuff_size = st30_calculate_framebuff_size( - ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, &s->expect_fps); + ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, + &s->expect_fps); ops.framebuff_size = framebuff_size; ops.flags |= ST30P_RX_FLAG_BLOCK_GET; @@ -158,7 +164,7 @@ static int app_rx_st30p_init(struct st_app_context* ctx, return 0; } -static int app_rx_st30p_stat(struct st_app_rx_st30p_session* s) { +static int app_rx_st30p_stat(struct st_app_rx_st30p_session *s) { uint64_t cur_time_ns = st_app_get_monotonic_time(); #ifdef DEBUG double time_sec = (double)(cur_time_ns - s->stat_last_time) / NS_PER_S; @@ -172,31 +178,37 @@ static int app_rx_st30p_stat(struct st_app_rx_st30p_session* s) { return 0; } -static int app_rx_st30p_result(struct st_app_rx_st30p_session* s) { +static int app_rx_st30p_result(struct st_app_rx_st30p_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) return -EINVAL; + if (!s->stat_frame_total_received) + return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) + ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } -int st_app_rx_st30p_sessions_init(struct st_app_context* ctx) { +int st_app_rx_st30p_sessions_init(struct st_app_context *ctx) { int ret = 0, i = 0; - struct st_app_rx_st30p_session* s; + struct st_app_rx_st30p_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) + fb_cnt = ST_APP_DEFAULT_FB_CNT; - dbg("%s(%d), rx_st30p_session_cnt %d\n", __func__, i, ctx->rx_st30p_session_cnt); - ctx->rx_st30p_sessions = (struct st_app_rx_st30p_session*)st_app_zmalloc( + dbg("%s(%d), rx_st30p_session_cnt %d\n", __func__, i, + ctx->rx_st30p_session_cnt); + ctx->rx_st30p_sessions = (struct st_app_rx_st30p_session *)st_app_zmalloc( sizeof(struct st_app_rx_st30p_session) * ctx->rx_st30p_session_cnt); - if (!ctx->rx_st30p_sessions) return -ENOMEM; + if (!ctx->rx_st30p_sessions) + return -ENOMEM; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; s->idx = i; @@ -214,10 +226,11 @@ int st_app_rx_st30p_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_rx_st30p_sessions_uinit(struct st_app_context* ctx) { +int st_app_rx_st30p_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_rx_st30p_session* s; - if (!ctx->rx_st30p_sessions) return 0; + struct st_app_rx_st30p_session *s; + if (!ctx->rx_st30p_sessions) + return 0; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; app_rx_st30p_uinit(s); @@ -227,10 +240,11 @@ int st_app_rx_st30p_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_rx_st30p_sessions_stat(struct st_app_context* ctx) { +int st_app_rx_st30p_sessions_stat(struct st_app_context *ctx) { int i; - struct st_app_rx_st30p_session* s; - if (!ctx->rx_st30p_sessions) return 0; + struct st_app_rx_st30p_session *s; + if (!ctx->rx_st30p_sessions) + return 0; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; @@ -240,11 +254,12 @@ int st_app_rx_st30p_sessions_stat(struct st_app_context* ctx) { return 0; } -int st_app_rx_st30p_sessions_result(struct st_app_context* ctx) { +int st_app_rx_st30p_sessions_result(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_rx_st30p_session* s; + struct st_app_rx_st30p_session *s; - if (!ctx->rx_st30p_sessions) return 0; + if (!ctx->rx_st30p_sessions) + return 0; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; diff --git a/app/src/rx_st30p_app.h b/app/src/rx_st30p_app.h index 8c7b51591..280c0e4ad 100644 --- a/app/src/rx_st30p_app.h +++ b/app/src/rx_st30p_app.h @@ -13,9 +13,9 @@ #ifndef _RX_APP_ST30P_HEAD_H_ #define _RX_APP_ST30P_HEAD_H_ -int st_app_rx_st30p_sessions_init(struct st_app_context* ctx); -int st_app_rx_st30p_sessions_uinit(struct st_app_context* ctx); -int st_app_rx_st30p_sessions_stat(struct st_app_context* ctx); -int st_app_rx_st30p_sessions_result(struct st_app_context* ctx); +int st_app_rx_st30p_sessions_init(struct st_app_context *ctx); +int st_app_rx_st30p_sessions_uinit(struct st_app_context *ctx); +int st_app_rx_st30p_sessions_stat(struct st_app_context *ctx); +int st_app_rx_st30p_sessions_result(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/rxtx_app.c b/app/src/rxtx_app.c index 5c17be47f..ce1479172 100644 --- a/app/src/rxtx_app.c +++ b/app/src/rxtx_app.c @@ -27,10 +27,10 @@ #include "tx_st22p_app.h" #include "tx_st30p_app.h" -static struct st_app_context* g_app_ctx; /* only for st_app_sig_handler */ +static struct st_app_context *g_app_ctx; /* only for st_app_sig_handler */ static enum mtl_log_level app_log_level; -static int app_dump_io_stat(struct st_app_context* ctx) { +static int app_dump_io_stat(struct st_app_context *ctx) { struct mtl_fix_info fix; struct mtl_port_status stats; int ret; @@ -39,16 +39,19 @@ static int app_dump_io_stat(struct st_app_context* ctx) { double tx_rate_m, rx_rate_m; ret = mtl_get_fix_info(ctx->st, &fix); - if (ret < 0) return ret; + if (ret < 0) + return ret; for (uint8_t port = 0; port < fix.num_ports; port++) { ret = mtl_get_port_stats(ctx->st, port, &stats); - if (ret < 0) return ret; + if (ret < 0) + return ret; tx_rate_m = (double)stats.tx_bytes * 8 / time_sec / MTL_STAT_M_UNIT; rx_rate_m = (double)stats.rx_bytes * 8 / time_sec / MTL_STAT_M_UNIT; - info("%s(%u), tx %f Mb/s rx %f Mb/s\n", __func__, port, tx_rate_m, rx_rate_m); - if (stats.rx_hw_dropped_packets || stats.rx_err_packets || stats.rx_nombuf_packets || - stats.tx_err_packets) { + info("%s(%u), tx %f Mb/s rx %f Mb/s\n", __func__, port, tx_rate_m, + rx_rate_m); + if (stats.rx_hw_dropped_packets || stats.rx_err_packets || + stats.rx_nombuf_packets || stats.tx_err_packets) { warn("%s(%u), hw drop %" PRIu64 " rx err %" PRIu64 " no mbuf %" PRIu64 " tx err %" PRIu64 "\n", __func__, port, stats.rx_hw_dropped_packets, stats.rx_err_packets, @@ -60,7 +63,7 @@ static int app_dump_io_stat(struct st_app_context* ctx) { return 0; } -static int app_dump_ptp_sync_stat(struct st_app_context* ctx) { +static int app_dump_ptp_sync_stat(struct st_app_context *ctx) { info("%s, cnt %d max %" PRId64 " min %" PRId64 " average %fus\n", __func__, ctx->ptp_sync_cnt, ctx->ptp_sync_delta_max, ctx->ptp_sync_delta_min, (float)ctx->ptp_sync_delta_sum / ctx->ptp_sync_cnt / NS_PER_US); @@ -71,10 +74,11 @@ static int app_dump_ptp_sync_stat(struct st_app_context* ctx) { return 0; } -static void app_stat(void* priv) { - struct st_app_context* ctx = priv; +static void app_stat(void *priv) { + struct st_app_context *ctx = priv; - if (ctx->stop) return; + if (ctx->stop) + return; if (ctx->mtl_log_stream) { app_dump_io_stat(ctx); @@ -98,9 +102,11 @@ static void app_stat(void* priv) { ctx->last_stat_time_ns = st_app_get_monotonic_time(); } -static void app_ptp_sync_notify(void* priv, struct mtl_ptp_sync_notify_meta* meta) { - struct st_app_context* ctx = priv; - if (!ctx->ptp_systime_sync) return; +static void app_ptp_sync_notify(void *priv, + struct mtl_ptp_sync_notify_meta *meta) { + struct st_app_context *ctx = priv; + if (!ctx->ptp_systime_sync) + return; /* sync raw ptp to sys time */ uint64_t to_ns = mtl_ptp_read_time_raw(ctx->st); @@ -114,44 +120,44 @@ static void app_ptp_sync_notify(void* priv, struct mtl_ptp_sync_notify_meta* met int64_t delta = to_ns - from_ns; ctx->ptp_sync_cnt++; ctx->ptp_sync_delta_sum += delta; - if (delta > ctx->ptp_sync_delta_max) ctx->ptp_sync_delta_max = delta; - if (delta < ctx->ptp_sync_delta_min) ctx->ptp_sync_delta_min = delta; + if (delta > ctx->ptp_sync_delta_max) + ctx->ptp_sync_delta_max = delta; + if (delta < ctx->ptp_sync_delta_min) + ctx->ptp_sync_delta_min = delta; - /* sample just offset the system time delta, better to calibrate as phc2sys way which - * adjust the time frequency also */ + /* sample just offset the system time delta, better to calibrate as phc2sys + * way which adjust the time frequency also */ st_ns_to_timespec(to_ns, &to_ts); to_ts.tv_sec -= meta->master_utc_offset; /* utc offset */ ret = st_set_real_time(&to_ts); if (ret < 0) { - err("%s, set real time to %" PRIu64 " fail, delta %" PRId64 "\n", __func__, to_ns, - delta); + err("%s, set real time to %" PRIu64 " fail, delta %" PRId64 "\n", __func__, + to_ns, delta); if (ret == -EPERM) - err("%s, please add capability to the app: sudo setcap 'cap_sys_time+ep' \n", + err("%s, please add capability to the app: sudo setcap 'cap_sys_time+ep' " + "\n", __func__); } - dbg("%s, from_ns %" PRIu64 " to_ns %" PRIu64 " delta %" PRId64 " done\n", __func__, - from_ns, to_ns, delta); + dbg("%s, from_ns %" PRIu64 " to_ns %" PRIu64 " delta %" PRId64 " done\n", + __func__, from_ns, to_ns, delta); return; } -void app_set_log_level(enum mtl_log_level level) { - app_log_level = level; -} +void app_set_log_level(enum mtl_log_level level) { app_log_level = level; } -enum mtl_log_level app_get_log_level(void) { - return app_log_level; -} +enum mtl_log_level app_get_log_level(void) { return app_log_level; } -static uint64_t app_ptp_from_tai_time(void* priv) { - struct st_app_context* ctx = priv; +static uint64_t app_ptp_from_tai_time(void *priv) { + struct st_app_context *ctx = priv; struct timespec spec; st_get_real_time(&spec); spec.tv_sec -= ctx->utc_offset; return ((uint64_t)spec.tv_sec * NS_PER_S) + spec.tv_nsec; } -static void user_param_init(struct st_app_context* ctx, struct mtl_init_params* p) { +static void user_param_init(struct st_app_context *ctx, + struct mtl_init_params *p) { memset(p, 0x0, sizeof(*p)); p->pmd[MTL_PORT_P] = MTL_PMD_DPDK_USER; @@ -167,12 +173,12 @@ static void user_param_init(struct st_app_context* ctx, struct mtl_init_params* app_set_log_level(p->log_level); } -static void var_param_init(struct st_app_context* ctx) { +static void var_param_init(struct st_app_context *ctx) { if (ctx->var_para.sch_force_sleep_us) mtl_sch_set_sleep_us(ctx->st, ctx->var_para.sch_force_sleep_us); } -static void st_app_ctx_init(struct st_app_context* ctx) { +static void st_app_ctx_init(struct st_app_context *ctx) { user_param_init(ctx, &ctx->para); /* tx */ @@ -184,9 +190,11 @@ static void st_app_ctx_init(struct st_app_context* ctx) { ctx->tx_anc_session_cnt = 0; snprintf(ctx->tx_st22_url, sizeof(ctx->tx_st22_url), "%s", "test.raw"); ctx->tx_st22_session_cnt = 0; - snprintf(ctx->tx_st22p_url, sizeof(ctx->tx_st22p_url), "%s", "test_rfc4175.yuv"); + snprintf(ctx->tx_st22p_url, sizeof(ctx->tx_st22p_url), "%s", + "test_rfc4175.yuv"); ctx->tx_st22p_session_cnt = 0; - snprintf(ctx->tx_st20p_url, sizeof(ctx->tx_st20p_url), "%s", "test_rfc4175.yuv"); + snprintf(ctx->tx_st20p_url, sizeof(ctx->tx_st20p_url), "%s", + "test_rfc4175.yuv"); ctx->tx_st20p_session_cnt = 0; /* rx */ @@ -220,8 +228,8 @@ static void st_app_ctx_init(struct st_app_context* ctx) { ctx->last_stat_time_ns = st_app_get_monotonic_time(); } -int st_app_video_get_lcore(struct st_app_context* ctx, int sch_idx, bool rtp, - unsigned int* lcore) { +int st_app_video_get_lcore(struct st_app_context *ctx, int sch_idx, bool rtp, + unsigned int *lcore) { int ret; unsigned int video_lcore; @@ -233,14 +241,17 @@ int st_app_video_get_lcore(struct st_app_context* ctx, int sch_idx, bool rtp, if (rtp) { if (ctx->rtp_lcore[sch_idx] < 0) { ret = mtl_get_lcore(ctx->st, &video_lcore); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx->rtp_lcore[sch_idx] = video_lcore; - info("%s, new rtp lcore %d for sch idx %d\n", __func__, video_lcore, sch_idx); + info("%s, new rtp lcore %d for sch idx %d\n", __func__, video_lcore, + sch_idx); } } else { if (ctx->lcore[sch_idx] < 0) { ret = mtl_get_lcore(ctx->st, &video_lcore); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx->lcore[sch_idx] = video_lcore; info("%s, new lcore %d for sch idx %d\n", __func__, video_lcore, sch_idx); } @@ -253,7 +264,7 @@ int st_app_video_get_lcore(struct st_app_context* ctx, int sch_idx, bool rtp, return 0; } -static int st_mtl_log_file_free(struct st_app_context* ctx) { +static int st_mtl_log_file_free(struct st_app_context *ctx) { if (ctx->mtl_log_stream) { fclose(ctx->mtl_log_stream); ctx->mtl_log_stream = NULL; @@ -262,7 +273,7 @@ static int st_mtl_log_file_free(struct st_app_context* ctx) { return 0; } -static void st_app_ctx_free(struct st_app_context* ctx) { +static void st_app_ctx_free(struct st_app_context *ctx) { st_app_tx_video_sessions_uinit(ctx); st_app_tx_audio_sessions_uinit(ctx); st_app_tx_anc_sessions_uinit(ctx); @@ -281,7 +292,8 @@ static void st_app_ctx_free(struct st_app_context* ctx) { st22_app_rx_sessions_uinit(ctx); if (ctx->runtime_session) { - if (ctx->st) mtl_stop(ctx->st); + if (ctx->st) + mtl_stop(ctx->st); } if (ctx->json_ctx) { @@ -309,7 +321,7 @@ static void st_app_ctx_free(struct st_app_context* ctx) { st_app_free(ctx); } -static int st_app_result(struct st_app_context* ctx) { +static int st_app_result(struct st_app_context *ctx) { int result = 0; result += st_app_tx_video_sessions_result(ctx); @@ -323,7 +335,7 @@ static int st_app_result(struct st_app_context* ctx) { return result; } -static int st_app_pcap(struct st_app_context* ctx) { +static int st_app_pcap(struct st_app_context *ctx) { st_app_rx_video_sessions_pcap(ctx); st_app_rx_st22p_sessions_pcap(ctx); st_app_rx_st20p_sessions_pcap(ctx); @@ -332,22 +344,23 @@ static int st_app_pcap(struct st_app_context* ctx) { } static void st_app_sig_handler(int signo) { - struct st_app_context* ctx = g_app_ctx; + struct st_app_context *ctx = g_app_ctx; info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - if (ctx->st) mtl_abort(ctx->st); - ctx->stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + if (ctx->st) + mtl_abort(ctx->st); + ctx->stop = true; + break; } return; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int ret; - struct st_app_context* ctx; + struct st_app_context *ctx; int run_time_s = 0; int test_time_s; @@ -391,28 +404,31 @@ int main(int argc, char** argv) { if (!ctx->para.tx_queues_cnt[i]) { if (ctx->json_ctx) { /* get from the assigned sessions on each interface */ - ctx->para.tx_queues_cnt[i] = - st_tx_sessions_queue_cnt(ctx->json_ctx->interfaces[i].tx_video_sessions_cnt, - ctx->json_ctx->interfaces[i].tx_audio_sessions_cnt, - ctx->json_ctx->interfaces[i].tx_anc_sessions_cnt); + ctx->para.tx_queues_cnt[i] = st_tx_sessions_queue_cnt( + ctx->json_ctx->interfaces[i].tx_video_sessions_cnt, + ctx->json_ctx->interfaces[i].tx_audio_sessions_cnt, + ctx->json_ctx->interfaces[i].tx_anc_sessions_cnt); } else { ctx->para.tx_queues_cnt[i] = st_tx_sessions_queue_cnt( - tx_st20_sessions, ctx->tx_audio_session_cnt, ctx->tx_anc_session_cnt); + tx_st20_sessions, ctx->tx_audio_session_cnt, + ctx->tx_anc_session_cnt); } - if (ctx->para.tx_queues_cnt[i] && (ctx->para.pmd[i] == MTL_PMD_DPDK_USER)) { + if (ctx->para.tx_queues_cnt[i] && + (ctx->para.pmd[i] == MTL_PMD_DPDK_USER)) { ctx->para.tx_queues_cnt[i] += 4; /* add extra 4 queues for recovery */ } } if (!ctx->para.rx_queues_cnt[i]) { if (ctx->json_ctx) { /* get from the assigned sessions on each interface */ - ctx->para.rx_queues_cnt[i] = - st_rx_sessions_queue_cnt(ctx->json_ctx->interfaces[i].rx_video_sessions_cnt, - ctx->json_ctx->interfaces[i].rx_audio_sessions_cnt, - ctx->json_ctx->interfaces[i].rx_anc_sessions_cnt); + ctx->para.rx_queues_cnt[i] = st_rx_sessions_queue_cnt( + ctx->json_ctx->interfaces[i].rx_video_sessions_cnt, + ctx->json_ctx->interfaces[i].rx_audio_sessions_cnt, + ctx->json_ctx->interfaces[i].rx_anc_sessions_cnt); } else { ctx->para.rx_queues_cnt[i] = st_rx_sessions_queue_cnt( - rx_st20_sessions, ctx->rx_audio_session_cnt, ctx->rx_anc_session_cnt); + rx_st20_sessions, ctx->rx_audio_session_cnt, + ctx->rx_anc_session_cnt); } } } @@ -422,7 +438,8 @@ int main(int argc, char** argv) { ctx->para.nb_rx_hdr_split_queues = ctx->rx_video_session_cnt; } - if (ctx->ptp_systime_sync) ctx->para.ptp_sync_notify = app_ptp_sync_notify; + if (ctx->ptp_systime_sync) + ctx->para.ptp_sync_notify = app_ptp_sync_notify; ctx->st = mtl_init(&ctx->para); if (!ctx->st) { @@ -581,7 +598,8 @@ int main(int argc, char** argv) { while (!ctx->stop) { sleep(1); run_time_s++; - if (test_time_s && (run_time_s > test_time_s)) break; + if (test_time_s && (run_time_s > test_time_s)) + break; if (ctx->pcapng_max_pkts && (run_time_s == 10)) { /* trigger pcap dump if */ st_app_pcap(ctx); } @@ -590,7 +608,8 @@ int main(int argc, char** argv) { if (!ctx->runtime_session) { /* stop st first */ - if (ctx->st) mtl_stop(ctx->st); + if (ctx->st) + mtl_stop(ctx->st); } ret = st_app_result(ctx); @@ -601,8 +620,8 @@ int main(int argc, char** argv) { return ret; } -int st_set_mtl_log_file(struct st_app_context* ctx, const char* file) { - FILE* f = fopen(file, "w"); +int st_set_mtl_log_file(struct st_app_context *ctx, const char *file) { + FILE *f = fopen(file, "w"); if (!f) { err("%s, fail(%s) to open %s\n", __func__, strerror(errno), file); return -EIO; @@ -622,8 +641,9 @@ int st_set_mtl_log_file(struct st_app_context* ctx, const char* file) { return 0; } -void st_sha_dump(const char* tag, const unsigned char* sha) { - if (tag) info("%s, ", tag); +void st_sha_dump(const char *tag, const unsigned char *sha) { + if (tag) + info("%s, ", tag); for (size_t i = 0; i < SHA256_DIGEST_LENGTH; i++) { info("0x%02x ", sha[i]); } diff --git a/app/src/tx_ancillary_app.c b/app/src/tx_ancillary_app.c index 9e57ae072..d61d8eac5 100644 --- a/app/src/tx_ancillary_app.c +++ b/app/src/tx_ancillary_app.c @@ -4,29 +4,32 @@ #include "tx_ancillary_app.h" -static int app_tx_anc_next_frame(void* priv, uint16_t* next_frame_idx, - struct st40_tx_frame_meta* meta) { - struct st_app_tx_anc_session* s = priv; +static int app_tx_anc_next_frame(void *priv, uint16_t *next_frame_idx, + struct st40_tx_frame_meta *meta) { + struct st_app_tx_anc_session *s = priv; int ret; uint16_t consumer_idx = s->framebuff_consumer_idx; - struct st_tx_frame* framebuff = &s->framebuffs[consumer_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->st40_wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { - dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, - s->idx, consumer_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", + __func__, s->idx, consumer_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, + ST10_VIDEO_SAMPLING_RATE_90K)); ret = 0; framebuff->stat = ST_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) + consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, + framebuff->stat); ret = -EIO; } st_pthread_cond_signal(&s->st40_wake_cond); @@ -34,24 +37,25 @@ static int app_tx_anc_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int app_tx_anc_frame_done(void* priv, uint16_t frame_idx, - struct st40_tx_frame_meta* meta) { - struct st_app_tx_anc_session* s = priv; +static int app_tx_anc_frame_done(void *priv, uint16_t frame_idx, + struct st40_tx_frame_meta *meta) { + struct st_app_tx_anc_session *s = priv; int ret; - struct st_tx_frame* framebuff = &s->framebuffs[frame_idx]; + struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); st_pthread_mutex_lock(&s->st40_wake_mutex); if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { ret = 0; framebuff->stat = ST_TX_FRAME_FREE; - dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, - s->idx, frame_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", + __func__, s->idx, frame_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, + ST10_VIDEO_SAMPLING_RATE_90K)); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, + framebuff->stat, frame_idx); } st_pthread_cond_signal(&s->st40_wake_cond); st_pthread_mutex_unlock(&s->st40_wake_mutex); @@ -61,8 +65,8 @@ static int app_tx_anc_frame_done(void* priv, uint16_t frame_idx, return ret; } -static int app_tx_anc_rtp_done(void* priv) { - struct st_app_tx_anc_session* s = priv; +static int app_tx_anc_rtp_done(void *priv) { + struct st_app_tx_anc_session *s = priv; st_pthread_mutex_lock(&s->st40_wake_mutex); st_pthread_cond_signal(&s->st40_wake_cond); st_pthread_mutex_unlock(&s->st40_wake_mutex); @@ -70,8 +74,8 @@ static int app_tx_anc_rtp_done(void* priv) { return 0; } -static void app_tx_anc_build_frame(struct st_app_tx_anc_session* s, - struct st40_frame* dst) { +static void app_tx_anc_build_frame(struct st_app_tx_anc_session *s, + struct st40_frame *dst) { uint16_t udw_size = s->st40_source_end - s->st40_frame_cursor > 255 ? 255 : s->st40_source_end - s->st40_frame_cursor; @@ -92,11 +96,11 @@ static void app_tx_anc_build_frame(struct st_app_tx_anc_session* s, s->st40_frame_cursor = s->st40_source_begin; } -static void* app_tx_anc_frame_thread(void* arg) { - struct st_app_tx_anc_session* s = arg; +static void *app_tx_anc_frame_thread(void *arg) { + struct st_app_tx_anc_session *s = arg; int idx = s->idx; uint16_t producer_idx; - struct st_tx_frame* framebuff; + struct st_tx_frame *framebuff; info("%s(%d), start\n", __func__, idx); while (!s->st40_app_thread_stop) { @@ -112,7 +116,8 @@ static void* app_tx_anc_frame_thread(void* arg) { } st_pthread_mutex_unlock(&s->st40_wake_mutex); - struct st40_frame* frame_addr = st40_tx_get_framebuffer(s->handle, producer_idx); + struct st40_frame *frame_addr = + st40_tx_get_framebuffer(s->handle, producer_idx); app_tx_anc_build_frame(s, frame_addr); st_pthread_mutex_lock(&s->st40_wake_mutex); @@ -120,7 +125,8 @@ static void* app_tx_anc_frame_thread(void* arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) + producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->st40_wake_mutex); } @@ -129,16 +135,16 @@ static void* app_tx_anc_frame_thread(void* arg) { return NULL; } -static void* app_tx_anc_pcap_thread(void* arg) { - struct st_app_tx_anc_session* s = arg; +static void *app_tx_anc_pcap_thread(void *arg) { + struct st_app_tx_anc_session *s = arg; int idx = s->idx; - void* mbuf; - void* usrptr = NULL; + void *mbuf; + void *usrptr = NULL; struct pcap_pkthdr hdr; - uint8_t* packet; - struct ether_header* eth_hdr; - struct ip* ip_hdr; - struct udphdr* udp_hdr; + uint8_t *packet; + struct ether_header *eth_hdr; + struct ip *ip_hdr; + struct udphdr *udp_hdr; uint16_t udp_data_len; info("%s(%d), start\n", __func__, idx); @@ -159,14 +165,14 @@ static void* app_tx_anc_pcap_thread(void* arg) { } } udp_data_len = 0; - packet = (uint8_t*)pcap_next(s->st40_pcap, &hdr); + packet = (uint8_t *)pcap_next(s->st40_pcap, &hdr); if (packet) { - eth_hdr = (struct ether_header*)packet; + eth_hdr = (struct ether_header *)packet; if (ntohs(eth_hdr->ether_type) == ETHERTYPE_IP) { - ip_hdr = (struct ip*)(packet + sizeof(struct ether_header)); + ip_hdr = (struct ip *)(packet + sizeof(struct ether_header)); if (ip_hdr->ip_p == IPPROTO_UDP) { - udp_hdr = - (struct udphdr*)(packet + sizeof(struct ether_header) + sizeof(struct ip)); + udp_hdr = (struct udphdr *)(packet + sizeof(struct ether_header) + + sizeof(struct ip)); udp_data_len = ntohs(udp_hdr->len) - sizeof(struct udphdr); mtl_memcpy(usrptr, packet + sizeof(struct ether_header) + sizeof(struct ip) + @@ -180,7 +186,8 @@ static void* app_tx_anc_pcap_thread(void* arg) { /* open capture file for offline processing */ s->st40_pcap = pcap_open_offline(s->st40_source_url, err_buf); if (s->st40_pcap == NULL) { - err("pcap_open_offline %s() failed: %s\n:", s->st40_source_url, err_buf); + err("pcap_open_offline %s() failed: %s\n:", s->st40_source_url, + err_buf); return NULL; } } @@ -192,12 +199,12 @@ static void* app_tx_anc_pcap_thread(void* arg) { return NULL; } -static void app_tx_anc_build_rtp(struct st_app_tx_anc_session* s, void* usrptr, - uint16_t* mbuf_len) { +static void app_tx_anc_build_rtp(struct st_app_tx_anc_session *s, void *usrptr, + uint16_t *mbuf_len) { /* generate one anc rtp for test purpose */ - struct st40_rfc8331_rtp_hdr* hdr = (struct st40_rfc8331_rtp_hdr*)usrptr; - struct st40_rfc8331_payload_hdr* payload_hdr = - (struct st40_rfc8331_payload_hdr*)(&hdr[1]); + struct st40_rfc8331_rtp_hdr *hdr = (struct st40_rfc8331_rtp_hdr *)usrptr; + struct st40_rfc8331_payload_hdr *payload_hdr = + (struct st40_rfc8331_payload_hdr *)(&hdr[1]); uint16_t udw_size = s->st40_source_end - s->st40_frame_cursor > 255 ? 255 : s->st40_source_end - s->st40_frame_cursor; @@ -225,21 +232,27 @@ static void app_tx_anc_build_rtp(struct st_app_tx_anc_session* s, void* usrptr, payload_hdr->second_hdr_chunk.did = st40_add_parity_bits(0x43); payload_hdr->second_hdr_chunk.sdid = st40_add_parity_bits(0x02); payload_hdr->second_hdr_chunk.data_count = st40_add_parity_bits(udw_size); - payload_hdr->swaped_first_hdr_chunk = htonl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = + htonl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = + htonl(payload_hdr->swaped_second_hdr_chunk); for (int i = 0; i < udw_size; i++) { st40_set_udw(i + 3, st40_add_parity_bits(s->st40_frame_cursor[i]), - (uint8_t*)&payload_hdr->second_hdr_chunk); + (uint8_t *)&payload_hdr->second_hdr_chunk); } - check_sum = st40_calc_checksum(3 + udw_size, (uint8_t*)&payload_hdr->second_hdr_chunk); - st40_set_udw(udw_size + 3, check_sum, (uint8_t*)&payload_hdr->second_hdr_chunk); - total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = - sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC + check_sum = st40_calc_checksum(3 + udw_size, + (uint8_t *)&payload_hdr->second_hdr_chunk); + st40_set_udw(udw_size + 3, check_sum, + (uint8_t *)&payload_hdr->second_hdr_chunk); + total_size = + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = + (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + + total_size; // Full size of one ANC *mbuf_len = payload_len + sizeof(struct st40_rfc8331_rtp_hdr); hdr->length = htons(payload_len); s->st40_frame_cursor += udw_size; @@ -247,11 +260,11 @@ static void app_tx_anc_build_rtp(struct st_app_tx_anc_session* s, void* usrptr, s->st40_frame_cursor = s->st40_source_begin; } -static void* app_tx_anc_rtp_thread(void* arg) { - struct st_app_tx_anc_session* s = arg; +static void *app_tx_anc_rtp_thread(void *arg) { + struct st_app_tx_anc_session *s = arg; int idx = s->idx; - void* mbuf; - void* usrptr = NULL; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; info("%s(%d), start\n", __func__, idx); @@ -282,7 +295,7 @@ static void* app_tx_anc_rtp_thread(void* arg) { return NULL; } -static int app_tx_anc_open_source(struct st_app_tx_anc_session* s) { +static int app_tx_anc_open_source(struct st_app_tx_anc_session *s) { if (!s->st40_pcap_input) { struct stat i; @@ -295,7 +308,8 @@ static int app_tx_anc_open_source(struct st_app_tx_anc_session* s) { return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st40_source_fd, 0); + uint8_t *m = + mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st40_source_fd, 0); if (MAP_FAILED != m) { s->st40_source_begin = m; @@ -325,7 +339,7 @@ static int app_tx_anc_open_source(struct st_app_tx_anc_session* s) { return 0; } -static int app_tx_anc_close_source(struct st_app_tx_anc_session* s) { +static int app_tx_anc_close_source(struct st_app_tx_anc_session *s) { if (s->st40_source_fd >= 0) { munmap(s->st40_source_begin, s->st40_source_end - s->st40_source_begin); close(s->st40_source_fd); @@ -339,17 +353,20 @@ static int app_tx_anc_close_source(struct st_app_tx_anc_session* s) { return 0; } -static int app_tx_anc_start_source(struct st_app_tx_anc_session* s) { +static int app_tx_anc_start_source(struct st_app_tx_anc_session *s) { int ret = -EINVAL; int idx = s->idx; s->st40_app_thread_stop = false; if (s->st40_pcap_input) - ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_pcap_thread, (void*)s); + ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_pcap_thread, + (void *)s); else if (s->st40_rtp_input) - ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_rtp_thread, (void*)s); + ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_rtp_thread, + (void *)s); else - ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_frame_thread, (void*)s); + ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_frame_thread, + (void *)s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -362,25 +379,27 @@ static int app_tx_anc_start_source(struct st_app_tx_anc_session* s) { return 0; } -static void app_tx_anc_stop_source(struct st_app_tx_anc_session* s) { +static void app_tx_anc_stop_source(struct st_app_tx_anc_session *s) { if (s->st40_source_fd >= 0) { s->st40_app_thread_stop = true; /* wake up the thread */ st_pthread_mutex_lock(&s->st40_wake_mutex); st_pthread_cond_signal(&s->st40_wake_cond); st_pthread_mutex_unlock(&s->st40_wake_mutex); - if (s->st40_app_thread) (void)pthread_join(s->st40_app_thread, NULL); + if (s->st40_app_thread) + (void)pthread_join(s->st40_app_thread, NULL); } } -int app_tx_anc_uinit(struct st_app_tx_anc_session* s) { +int app_tx_anc_uinit(struct st_app_tx_anc_session *s) { int ret; app_tx_anc_stop_source(s); if (s->handle) { ret = st40_tx_free(s->handle); - if (ret < 0) err("%s(%d), st_tx_anc_session_free fail %d\n", __func__, s->idx, ret); + if (ret < 0) + err("%s(%d), st_tx_anc_session_free fail %d\n", __func__, s->idx, ret); s->handle = NULL; } @@ -397,8 +416,9 @@ int app_tx_anc_uinit(struct st_app_tx_anc_session* s) { return 0; } -static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session_t* anc, - struct st_app_tx_anc_session* s) { +static int app_tx_anc_init(struct st_app_context *ctx, + st_json_ancillary_session_t *anc, + struct st_app_tx_anc_session *s) { int idx = s->idx, ret; struct st40_tx_ops ops; char name[32]; @@ -408,8 +428,8 @@ static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session s->framebuff_cnt = 2; s->st40_seq_id = 1; - s->framebuffs = - (struct st_tx_frame*)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); + s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * + s->framebuff_cnt); if (!s->framebuffs) { return -ENOMEM; } @@ -431,8 +451,10 @@ static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = + anc ? anc->base.udp_port : (10200 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -444,11 +466,13 @@ static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = + anc ? anc->base.udp_port : (10200 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], - MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], + ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); ops.flags |= ST40_TX_FLAG_USER_R_MAC; } } @@ -460,7 +484,8 @@ static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session s->st40_pcap_input = false; ops.type = anc ? anc->info.type : ST40_TYPE_FRAME_LEVEL; ops.interlaced = anc ? anc->info.interlaced : false; - ops.payload_type = anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; + ops.payload_type = + anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; /* select rtp type for pcap file or tx_video_rtp_ring_size */ if (strstr(s->st40_source_url, ".pcap")) { ops.type = ST40_TYPE_RTP_LEVEL; @@ -476,8 +501,10 @@ static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session else ops.rtp_ring_size = 16; } - if (anc && anc->enable_rtcp) ops.flags |= ST40_TX_FLAG_ENABLE_RTCP; - if (ctx->tx_anc_dedicate_queue) ops.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; + if (anc && anc->enable_rtcp) + ops.flags |= ST40_TX_FLAG_ENABLE_RTCP; + if (ctx->tx_anc_dedicate_queue) + ops.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; handle = st40_tx_create(ctx->st, &ops); if (!handle) { @@ -499,7 +526,8 @@ static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session ret = app_tx_anc_start_source(s); if (ret < 0) { - err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, ret); + err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, + ret); app_tx_anc_uinit(s); return ret; } @@ -507,9 +535,10 @@ static int app_tx_anc_init(struct st_app_context* ctx, st_json_ancillary_session return 0; } -int st_app_tx_anc_sessions_stop(struct st_app_context* ctx) { - struct st_app_tx_anc_session* s; - if (!ctx->tx_anc_sessions) return 0; +int st_app_tx_anc_sessions_stop(struct st_app_context *ctx) { + struct st_app_tx_anc_session *s; + if (!ctx->tx_anc_sessions) + return 0; for (int i = 0; i < ctx->tx_anc_session_cnt; i++) { s = &ctx->tx_anc_sessions[i]; app_tx_anc_stop_source(s); @@ -518,18 +547,19 @@ int st_app_tx_anc_sessions_stop(struct st_app_context* ctx) { return 0; } -int st_app_tx_anc_sessions_init(struct st_app_context* ctx) { +int st_app_tx_anc_sessions_init(struct st_app_context *ctx) { int ret; - struct st_app_tx_anc_session* s; - ctx->tx_anc_sessions = (struct st_app_tx_anc_session*)st_app_zmalloc( + struct st_app_tx_anc_session *s; + ctx->tx_anc_sessions = (struct st_app_tx_anc_session *)st_app_zmalloc( sizeof(struct st_app_tx_anc_session) * ctx->tx_anc_session_cnt); - if (!ctx->tx_anc_sessions) return -ENOMEM; + if (!ctx->tx_anc_sessions) + return -ENOMEM; for (int i = 0; i < ctx->tx_anc_session_cnt; i++) { s = &ctx->tx_anc_sessions[i]; s->idx = i; - ret = app_tx_anc_init(ctx, ctx->json_ctx ? &ctx->json_ctx->tx_anc_sessions[i] : NULL, - s); + ret = app_tx_anc_init( + ctx, ctx->json_ctx ? &ctx->json_ctx->tx_anc_sessions[i] : NULL, s); if (ret < 0) { err("%s(%d), app_tx_anc_session_init fail %d\n", __func__, i, ret); return ret; @@ -539,9 +569,10 @@ int st_app_tx_anc_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_tx_anc_sessions_uinit(struct st_app_context* ctx) { - struct st_app_tx_anc_session* s; - if (!ctx->tx_anc_sessions) return 0; +int st_app_tx_anc_sessions_uinit(struct st_app_context *ctx) { + struct st_app_tx_anc_session *s; + if (!ctx->tx_anc_sessions) + return 0; for (int i = 0; i < ctx->tx_anc_session_cnt; i++) { s = &ctx->tx_anc_sessions[i]; diff --git a/app/src/tx_ancillary_app.h b/app/src/tx_ancillary_app.h index 7f3bbcc82..019cfbd2e 100644 --- a/app/src/tx_ancillary_app.h +++ b/app/src/tx_ancillary_app.h @@ -12,8 +12,8 @@ #ifndef _TX_APP_ANC_HEAD_H_ #define _TX_APP_ANC_HEAD_H_ -int st_app_tx_anc_sessions_init(struct st_app_context* ctx); +int st_app_tx_anc_sessions_init(struct st_app_context *ctx); -int st_app_tx_anc_sessions_uinit(struct st_app_context* ctx); -int st_app_tx_anc_sessions_stop(struct st_app_context* ctx); +int st_app_tx_anc_sessions_uinit(struct st_app_context *ctx); +int st_app_tx_anc_sessions_stop(struct st_app_context *ctx); #endif \ No newline at end of file diff --git a/app/src/tx_st20p_app.c b/app/src/tx_st20p_app.c index 65c5bb782..4a785144d 100644 --- a/app/src/tx_st20p_app.c +++ b/app/src/tx_st20p_app.c @@ -4,9 +4,9 @@ #include "tx_st20p_app.h" -static void app_tx_st20p_display_frame(struct st_app_tx_st20p_session* s, - struct st_frame* frame) { - struct st_display* d = s->display; +static void app_tx_st20p_display_frame(struct st_app_tx_st20p_session *s, + struct st_frame *frame) { + struct st_display *d = s->display; if (d && d->front_frame) { if (st_pthread_mutex_trylock(&d->display_frame_mutex) == 0) { @@ -27,10 +27,11 @@ static void app_tx_st20p_display_frame(struct st_app_tx_st20p_session* s, } } -static int app_tx_st20p_notify_event(void* priv, enum st_event event, void* args) { - struct st_app_tx_st20p_session* s = priv; +static int app_tx_st20p_notify_event(void *priv, enum st_event event, + void *args) { + struct st_app_tx_st20p_session *s = priv; if (event == ST_EVENT_VSYNC) { - struct st10_vsync_meta* meta = args; + struct st10_vsync_meta *meta = args; info("%s(%d), epoch %" PRIu64 "\n", __func__, s->idx, meta->epoch); } else if (event == ST_EVENT_FATAL_ERROR) { err("%s(%d), ST_EVENT_FATAL_ERROR\n", __func__, s->idx); @@ -41,9 +42,10 @@ static int app_tx_st20p_notify_event(void* priv, enum st_event event, void* args return 0; } -static void app_tx_st20p_build_frame(struct st_app_tx_st20p_session* s, - struct st_frame* frame, size_t frame_size) { - uint8_t* src = s->st20p_frame_cursor; +static void app_tx_st20p_build_frame(struct st_app_tx_st20p_session *s, + struct st_frame *frame, + size_t frame_size) { + uint8_t *src = s->st20p_frame_cursor; if (!s->ctx->tx_copy_once || !s->st20p_frames_copied) { mtl_memcpy(frame->addr[0], src, frame_size); @@ -58,11 +60,11 @@ static void app_tx_st20p_build_frame(struct st_app_tx_st20p_session* s, app_tx_st20p_display_frame(s, frame); } -static void* app_tx_st20p_frame_thread(void* arg) { - struct st_app_tx_st20p_session* s = arg; +static void *app_tx_st20p_frame_thread(void *arg) { + struct st_app_tx_st20p_session *s = arg; st20p_tx_handle handle = s->handle; int idx = s->idx; - struct st_frame* frame; + struct st_frame *frame; uint8_t shas[SHA256_DIGEST_LENGTH]; info("%s(%d), start\n", __func__, idx); @@ -74,7 +76,8 @@ static void* app_tx_st20p_frame_thread(void* arg) { } app_tx_st20p_build_frame(s, frame, s->st20p_frame_size); if (s->sha_check) { - st_sha256((unsigned char*)frame->addr[0], st_frame_plane_size(frame, 0), shas); + st_sha256((unsigned char *)frame->addr[0], st_frame_plane_size(frame, 0), + shas); frame->user_meta = shas; frame->user_meta_size = sizeof(shas); } @@ -85,7 +88,7 @@ static void* app_tx_st20p_frame_thread(void* arg) { return NULL; } -static int app_tx_st20p_open_source(struct st_app_tx_st20p_session* s) { +static int app_tx_st20p_open_source(struct st_app_tx_st20p_session *s) { int fd; struct stat i; @@ -101,13 +104,13 @@ static int app_tx_st20p_open_source(struct st_app_tx_st20p_session* s) { return -EIO; } if (i.st_size < s->st20p_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, s->st20p_source_url, - s->st20p_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, + s->st20p_source_url, s->st20p_frame_size); close(fd); return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s, mmap fail '%s'\n", __func__, s->st20p_source_url); close(fd); @@ -131,11 +134,12 @@ static int app_tx_st20p_open_source(struct st_app_tx_st20p_session* s) { return 0; } -static int app_tx_st20p_start_source(struct st_app_tx_st20p_session* s) { +static int app_tx_st20p_start_source(struct st_app_tx_st20p_session *s) { int ret = -EINVAL; int idx = s->idx; - ret = pthread_create(&s->st20p_app_thread, NULL, app_tx_st20p_frame_thread, s); + ret = + pthread_create(&s->st20p_app_thread, NULL, app_tx_st20p_frame_thread, s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -149,17 +153,18 @@ static int app_tx_st20p_start_source(struct st_app_tx_st20p_session* s) { return 0; } -static void app_tx_st20p_stop_source(struct st_app_tx_st20p_session* s) { +static void app_tx_st20p_stop_source(struct st_app_tx_st20p_session *s) { s->st20p_app_thread_stop = true; if (s->st20p_app_thread) { info("%s(%d), wait app thread stop\n", __func__, s->idx); - if (s->handle) st20p_tx_wake_block(s->handle); + if (s->handle) + st20p_tx_wake_block(s->handle); pthread_join(s->st20p_app_thread, NULL); s->st20p_app_thread = 0; } } -static int app_tx_st20p_close_source(struct st_app_tx_st20p_session* s) { +static int app_tx_st20p_close_source(struct st_app_tx_st20p_session *s) { if (s->st20p_source_fd < 0 && s->st20p_source_begin) { mtl_hp_free(s->st, s->st20p_source_begin); s->st20p_source_begin = NULL; @@ -173,20 +178,21 @@ static int app_tx_st20p_close_source(struct st_app_tx_st20p_session* s) { return 0; } -static int app_tx_st20p_handle_free(struct st_app_tx_st20p_session* s) { +static int app_tx_st20p_handle_free(struct st_app_tx_st20p_session *s) { int ret; int idx = s->idx; if (s->handle) { ret = st20p_tx_free(s->handle); - if (ret < 0) err("%s(%d), st20p_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st20p_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_tx_st20p_uinit(struct st_app_tx_st20p_session* s) { +static int app_tx_st20p_uinit(struct st_app_tx_st20p_session *s) { app_tx_st20p_stop_source(s); app_tx_st20p_handle_free(s); app_tx_st20p_close_source(s); @@ -199,7 +205,7 @@ static int app_tx_st20p_uinit(struct st_app_tx_st20p_session* s) { return 0; } -static int app_tx_st20p_io_stat(struct st_app_tx_st20p_session* s) { +static int app_tx_st20p_io_stat(struct st_app_tx_st20p_session *s) { int idx = s->idx; uint64_t cur_time = st_app_get_monotonic_time(); double time_sec = (double)(cur_time - s->last_stat_time_ns) / NS_PER_S; @@ -207,11 +213,13 @@ static int app_tx_st20p_io_stat(struct st_app_tx_st20p_session* s) { int ret; struct st20_tx_port_status stats; - if (!s->handle) return 0; + if (!s->handle) + return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20p_tx_get_port_stats(s->handle, port, &stats); - if (ret < 0) return ret; + if (ret < 0) + return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -223,8 +231,9 @@ static int app_tx_st20p_io_stat(struct st_app_tx_st20p_session* s) { return 0; } -static int app_tx_st20p_init(struct st_app_context* ctx, st_json_st20p_session_t* st20p, - struct st_app_tx_st20p_session* s) { +static int app_tx_st20p_init(struct st_app_context *ctx, + st_json_st20p_session_t *st20p, + struct st_app_tx_st20p_session *s) { int idx = s->idx, ret; struct st20p_tx_ops ops; char name[32]; @@ -243,10 +252,11 @@ static int app_tx_st20p_init(struct st_app_context* ctx, st_json_st20p_session_t st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = st20p ? st20p->base.udp_port : (10000 + s->idx); + snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = + st20p ? st20p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -257,28 +267,33 @@ static int app_tx_st20p_init(struct st_app_context* ctx, st_json_st20p_session_t st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st20p ? st20p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], - MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], + ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); ops.flags |= ST20P_TX_FLAG_USER_R_MAC; } } - ops.port.payload_type = st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.port.payload_type = + st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.width = st20p ? st20p->info.width : 1920; ops.height = st20p ? st20p->info.height : 1080; ops.fps = st20p ? st20p->info.fps : ST_FPS_P59_94; ops.interlaced = st20p ? st20p->info.interlaced : false; - ops.input_fmt = st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; - ops.transport_pacing = st20p ? st20p->info.transport_pacing : ST21_PACING_NARROW; + ops.input_fmt = + st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.transport_pacing = + st20p ? st20p->info.transport_pacing : ST21_PACING_NARROW; if (ctx->tx_pacing_type) /* override if args has pacing defined */ ops.transport_pacing = ctx->tx_pacing_type; - ops.transport_packing = st20p ? st20p->info.transport_packing : ST20_PACKING_BPM; - ops.transport_fmt = st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; + ops.transport_packing = + st20p ? st20p->info.transport_packing : ST20_PACKING_BPM; + ops.transport_fmt = + st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; ops.device = st20p ? st20p->info.device : ST_PLUGIN_DEVICE_AUTO; ops.framebuff_cnt = 2; ops.flags |= ST20P_TX_FLAG_BLOCK_GET; @@ -286,11 +301,16 @@ static int app_tx_st20p_init(struct st_app_context* ctx, st_json_st20p_session_t ops.pad_interval = ctx->tx_pad_interval; ops.rtp_timestamp_delta_us = ctx->tx_ts_delta_us; ops.notify_event = app_tx_st20p_notify_event; - if (ctx->tx_no_static_pad) ops.flags |= ST20P_TX_FLAG_DISABLE_STATIC_PAD_P; - if (st20p && st20p->enable_rtcp) ops.flags |= ST20P_TX_FLAG_ENABLE_RTCP; - if (ctx->tx_ts_first_pkt) ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; - if (ctx->tx_ts_epoch) ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH; - if (ctx->tx_no_bulk) ops.flags |= ST20P_TX_FLAG_DISABLE_BULK; + if (ctx->tx_no_static_pad) + ops.flags |= ST20P_TX_FLAG_DISABLE_STATIC_PAD_P; + if (st20p && st20p->enable_rtcp) + ops.flags |= ST20P_TX_FLAG_ENABLE_RTCP; + if (ctx->tx_ts_first_pkt) + ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; + if (ctx->tx_ts_epoch) + ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH; + if (ctx->tx_no_bulk) + ops.flags |= ST20P_TX_FLAG_DISABLE_BULK; if (ctx->force_tx_video_numa >= 0) { ops.flags |= ST20P_TX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_tx_video_numa; @@ -333,7 +353,7 @@ static int app_tx_st20p_init(struct st_app_context* ctx, st_json_st20p_session_t } if ((st20p && st20p->display) || ctx->tx_display) { - struct st_display* d = st_app_zmalloc(sizeof(struct st_display)); + struct st_display *d = st_app_zmalloc(sizeof(struct st_display)); ret = st_app_init_display(d, name, s->width, s->height, ctx->ttf_file); if (ret < 0) { err("%s(%d), st_app_init_display fail %d\n", __func__, idx, ret); @@ -346,12 +366,13 @@ static int app_tx_st20p_init(struct st_app_context* ctx, st_json_st20p_session_t return 0; } -int st_app_tx_st20p_sessions_init(struct st_app_context* ctx) { +int st_app_tx_st20p_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_tx_st20p_session* s; - ctx->tx_st20p_sessions = (struct st_app_tx_st20p_session*)st_app_zmalloc( + struct st_app_tx_st20p_session *s; + ctx->tx_st20p_sessions = (struct st_app_tx_st20p_session *)st_app_zmalloc( sizeof(struct st_app_tx_st20p_session) * ctx->tx_st20p_session_cnt); - if (!ctx->tx_st20p_sessions) return -ENOMEM; + if (!ctx->tx_st20p_sessions) + return -ENOMEM; for (i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; s->idx = i; @@ -366,9 +387,10 @@ int st_app_tx_st20p_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_tx_st20p_sessions_stop(struct st_app_context* ctx) { - struct st_app_tx_st20p_session* s; - if (!ctx->tx_st20p_sessions) return 0; +int st_app_tx_st20p_sessions_stop(struct st_app_context *ctx) { + struct st_app_tx_st20p_session *s; + if (!ctx->tx_st20p_sessions) + return 0; for (int i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; app_tx_st20p_stop_source(s); @@ -377,10 +399,11 @@ int st_app_tx_st20p_sessions_stop(struct st_app_context* ctx) { return 0; } -int st_app_tx_st20p_sessions_uinit(struct st_app_context* ctx) { +int st_app_tx_st20p_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_tx_st20p_session* s; - if (!ctx->tx_st20p_sessions) return 0; + struct st_app_tx_st20p_session *s; + if (!ctx->tx_st20p_sessions) + return 0; for (i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; app_tx_st20p_uinit(s); @@ -390,10 +413,11 @@ int st_app_tx_st20p_sessions_uinit(struct st_app_context* ctx) { return 0; } -int st_app_tx_st20p_io_stat(struct st_app_context* ctx) { +int st_app_tx_st20p_io_stat(struct st_app_context *ctx) { int i, ret = 0; - struct st_app_tx_st20p_session* s; - if (!ctx->tx_st20p_sessions) return 0; + struct st_app_tx_st20p_session *s; + if (!ctx->tx_st20p_sessions) + return 0; for (i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; diff --git a/app/src/tx_st20p_app.h b/app/src/tx_st20p_app.h index 4a77bc78c..26e5a567f 100644 --- a/app/src/tx_st20p_app.h +++ b/app/src/tx_st20p_app.h @@ -16,12 +16,12 @@ #ifndef _TX_APP_ST20P_HEAD_H_ #define _TX_APP_ST20P_HEAD_H_ -int st_app_tx_st20p_sessions_init(struct st_app_context* ctx); +int st_app_tx_st20p_sessions_init(struct st_app_context *ctx); -int st_app_tx_st20p_sessions_stop(struct st_app_context* ctx); +int st_app_tx_st20p_sessions_stop(struct st_app_context *ctx); -int st_app_tx_st20p_sessions_uinit(struct st_app_context* ctx); +int st_app_tx_st20p_sessions_uinit(struct st_app_context *ctx); -int st_app_tx_st20p_io_stat(struct st_app_context* ctx); +int st_app_tx_st20p_io_stat(struct st_app_context *ctx); #endif diff --git a/app/src/tx_st22p_app.c b/app/src/tx_st22p_app.c index 7aa65b366..02d8d399c 100644 --- a/app/src/tx_st22p_app.c +++ b/app/src/tx_st22p_app.c @@ -4,9 +4,9 @@ #include "tx_st22p_app.h" -static void app_tx_st22p_display_frame(struct st_app_tx_st22p_session* s, - struct st_frame* frame) { - struct st_display* d = s->display; +static void app_tx_st22p_display_frame(struct st_app_tx_st22p_session *s, + struct st_frame *frame) { + struct st_display *d = s->display; if (d && d->front_frame) { if (st_pthread_mutex_trylock(&d->display_frame_mutex) == 0) { @@ -27,29 +27,30 @@ static void app_tx_st22p_display_frame(struct st_app_tx_st22p_session* s, } } -static void app_tx_st22p_build_frame(struct st_app_tx_st22p_session* s, - struct st_frame* frame) { +static void app_tx_st22p_build_frame(struct st_app_tx_st22p_session *s, + struct st_frame *frame) { if (s->st22p_frame_cursor + s->st22p_frame_size > s->st22p_source_end) { s->st22p_frame_cursor = s->st22p_source_begin; } - uint8_t* src = s->st22p_frame_cursor; + uint8_t *src = s->st22p_frame_cursor; mtl_memcpy(frame->addr[0], src, s->st22p_frame_size); /* point to next frame */ s->st22p_frame_cursor += s->st22p_frame_size; if (frame->interlaced) { - dbg("%s(%d), %s field\n", __func__, s->idx, frame->second_field ? "second" : "first"); + dbg("%s(%d), %s field\n", __func__, s->idx, + frame->second_field ? "second" : "first"); } app_tx_st22p_display_frame(s, frame); } -static void* app_tx_st22p_frame_thread(void* arg) { - struct st_app_tx_st22p_session* s = arg; +static void *app_tx_st22p_frame_thread(void *arg) { + struct st_app_tx_st22p_session *s = arg; st22p_tx_handle handle = s->handle; int idx = s->idx; - struct st_frame* frame; + struct st_frame *frame; info("%s(%d), start\n", __func__, idx); while (!s->st22p_app_thread_stop) { @@ -66,7 +67,7 @@ static void* app_tx_st22p_frame_thread(void* arg) { return NULL; } -static int app_tx_st22p_open_source(struct st_app_tx_st22p_session* s) { +static int app_tx_st22p_open_source(struct st_app_tx_st22p_session *s) { int fd; struct stat i; @@ -82,13 +83,13 @@ static int app_tx_st22p_open_source(struct st_app_tx_st22p_session* s) { return -EIO; } if (i.st_size < s->st22p_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, s->st22p_source_url, - s->st22p_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, + s->st22p_source_url, s->st22p_frame_size); close(fd); return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s, mmap fail '%s'\n", __func__, s->st22p_source_url); close(fd); @@ -112,11 +113,12 @@ static int app_tx_st22p_open_source(struct st_app_tx_st22p_session* s) { return 0; } -static int app_tx_st22p_start_source(struct st_app_tx_st22p_session* s) { +static int app_tx_st22p_start_source(struct st_app_tx_st22p_session *s) { int ret = -EINVAL; int idx = s->idx; - ret = pthread_create(&s->st22p_app_thread, NULL, app_tx_st22p_frame_thread, s); + ret = + pthread_create(&s->st22p_app_thread, NULL, app_tx_st22p_frame_thread, s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -130,18 +132,19 @@ static int app_tx_st22p_start_source(struct st_app_tx_st22p_session* s) { return 0; } -static void app_tx_st22p_stop_source(struct st_app_tx_st22p_session* s) { +static void app_tx_st22p_stop_source(struct st_app_tx_st22p_session *s) { s->st22p_app_thread_stop = true; /* wake up the thread */ if (s->st22p_app_thread) { info("%s(%d), wait app thread stop\n", __func__, s->idx); - if (s->handle) st22p_tx_wake_block(s->handle); + if (s->handle) + st22p_tx_wake_block(s->handle); pthread_join(s->st22p_app_thread, NULL); s->st22p_app_thread = 0; } } -static int app_tx_st22p_close_source(struct st_app_tx_st22p_session* s) { +static int app_tx_st22p_close_source(struct st_app_tx_st22p_session *s) { if (s->st22p_source_fd < 0 && s->st22p_source_begin) { mtl_hp_free(s->st, s->st22p_source_begin); s->st22p_source_begin = NULL; @@ -155,20 +158,21 @@ static int app_tx_st22p_close_source(struct st_app_tx_st22p_session* s) { return 0; } -static int app_tx_st22p_handle_free(struct st_app_tx_st22p_session* s) { +static int app_tx_st22p_handle_free(struct st_app_tx_st22p_session *s) { int ret; int idx = s->idx; if (s->handle) { ret = st22p_tx_free(s->handle); - if (ret < 0) err("%s(%d), st22p_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st22p_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_tx_st22p_uinit(struct st_app_tx_st22p_session* s) { +static int app_tx_st22p_uinit(struct st_app_tx_st22p_session *s) { app_tx_st22p_stop_source(s); app_tx_st22p_handle_free(s); app_tx_st22p_close_source(s); @@ -181,8 +185,9 @@ static int app_tx_st22p_uinit(struct st_app_tx_st22p_session* s) { return 0; } -static int app_tx_st22p_init(struct st_app_context* ctx, st_json_st22p_session_t* st22p, - struct st_app_tx_st22p_session* s) { +static int app_tx_st22p_init(struct st_app_context *ctx, + st_json_st22p_session_t *st22p, + struct st_app_tx_st22p_session *s) { int idx = s->idx, ret; struct st22p_tx_ops ops; char name[32]; @@ -197,10 +202,11 @@ static int app_tx_st22p_init(struct st_app_context* ctx, st_json_st22p_session_t st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = st22p ? st22p->base.udp_port : (10000 + s->idx); + snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = + st22p ? st22p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -211,34 +217,39 @@ static int app_tx_st22p_init(struct st_app_context* ctx, st_json_st22p_session_t st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st22p ? st22p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], - MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], + ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); ops.flags |= ST22P_TX_FLAG_USER_R_MAC; } } - ops.port.payload_type = st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; + ops.port.payload_type = + st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; ops.width = st22p ? st22p->info.width : 1920; ops.height = st22p ? st22p->info.height : 1080; ops.fps = st22p ? st22p->info.fps : ST_FPS_P59_94; ops.interlaced = st22p ? st22p->info.interlaced : false; - ops.input_fmt = st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.input_fmt = + st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; ops.pack_type = st22p ? st22p->info.pack_type : ST22_PACK_CODESTREAM; ops.codec = st22p ? st22p->info.codec : ST22_CODEC_JPEGXS; ops.device = st22p ? st22p->info.device : ST_PLUGIN_DEVICE_AUTO; ops.quality = st22p ? st22p->info.quality : ST22_QUALITY_MODE_SPEED; ops.codec_thread_cnt = st22p ? st22p->info.codec_thread_count : 0; ops.codestream_size = ops.width * ops.height * 3 / 8; - if (ops.interlaced) ops.codestream_size /= 2; /* the size is for each field */ + if (ops.interlaced) + ops.codestream_size /= 2; /* the size is for each field */ ops.framebuff_cnt = 2; ops.flags |= ST22P_TX_FLAG_BLOCK_GET; - if (st22p && st22p->enable_rtcp) ops.flags |= ST22P_TX_FLAG_ENABLE_RTCP; - if (ctx->tx_no_bulk) ops.flags |= ST22P_TX_FLAG_DISABLE_BULK; + if (st22p && st22p->enable_rtcp) + ops.flags |= ST22P_TX_FLAG_ENABLE_RTCP; + if (ctx->tx_no_bulk) + ops.flags |= ST22P_TX_FLAG_DISABLE_BULK; if (ctx->force_tx_video_numa >= 0) { ops.flags |= ST22P_TX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_tx_video_numa; @@ -280,7 +291,7 @@ static int app_tx_st22p_init(struct st_app_context* ctx, st_json_st22p_session_t } if ((st22p && st22p->display) || ctx->tx_display) { - struct st_display* d = st_app_zmalloc(sizeof(struct st_display)); + struct st_display *d = st_app_zmalloc(sizeof(struct st_display)); ret = st_app_init_display(d, name, s->width, s->height, ctx->ttf_file); if (ret < 0) { err("%s(%d), st_app_init_display fail %d\n", __func__, idx, ret); @@ -293,12 +304,13 @@ static int app_tx_st22p_init(struct st_app_context* ctx, st_json_st22p_session_t return 0; } -int st_app_tx_st22p_sessions_init(struct st_app_context* ctx) { +int st_app_tx_st22p_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_tx_st22p_session* s; - ctx->tx_st22p_sessions = (struct st_app_tx_st22p_session*)st_app_zmalloc( + struct st_app_tx_st22p_session *s; + ctx->tx_st22p_sessions = (struct st_app_tx_st22p_session *)st_app_zmalloc( sizeof(struct st_app_tx_st22p_session) * ctx->tx_st22p_session_cnt); - if (!ctx->tx_st22p_sessions) return -ENOMEM; + if (!ctx->tx_st22p_sessions) + return -ENOMEM; for (i = 0; i < ctx->tx_st22p_session_cnt; i++) { s = &ctx->tx_st22p_sessions[i]; s->idx = i; @@ -313,9 +325,10 @@ int st_app_tx_st22p_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_tx_st22p_sessions_stop(struct st_app_context* ctx) { - struct st_app_tx_st22p_session* s; - if (!ctx->tx_st22p_sessions) return 0; +int st_app_tx_st22p_sessions_stop(struct st_app_context *ctx) { + struct st_app_tx_st22p_session *s; + if (!ctx->tx_st22p_sessions) + return 0; for (int i = 0; i < ctx->tx_st22p_session_cnt; i++) { s = &ctx->tx_st22p_sessions[i]; app_tx_st22p_stop_source(s); @@ -324,10 +337,11 @@ int st_app_tx_st22p_sessions_stop(struct st_app_context* ctx) { return 0; } -int st_app_tx_st22p_sessions_uinit(struct st_app_context* ctx) { +int st_app_tx_st22p_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_tx_st22p_session* s; - if (!ctx->tx_st22p_sessions) return 0; + struct st_app_tx_st22p_session *s; + if (!ctx->tx_st22p_sessions) + return 0; for (i = 0; i < ctx->tx_st22p_session_cnt; i++) { s = &ctx->tx_st22p_sessions[i]; app_tx_st22p_uinit(s); diff --git a/app/src/tx_st22p_app.h b/app/src/tx_st22p_app.h index cb3c92a78..0c043e7bc 100644 --- a/app/src/tx_st22p_app.h +++ b/app/src/tx_st22p_app.h @@ -15,10 +15,10 @@ #ifndef _TX_APP_ST22P_HEAD_H_ #define _TX_APP_ST22P_HEAD_H_ -int st_app_tx_st22p_sessions_init(struct st_app_context* ctx); +int st_app_tx_st22p_sessions_init(struct st_app_context *ctx); -int st_app_tx_st22p_sessions_stop(struct st_app_context* ctx); +int st_app_tx_st22p_sessions_stop(struct st_app_context *ctx); -int st_app_tx_st22p_sessions_uinit(struct st_app_context* ctx); +int st_app_tx_st22p_sessions_uinit(struct st_app_context *ctx); #endif diff --git a/app/src/tx_st30p_app.c b/app/src/tx_st30p_app.c index daac30048..f261bae29 100644 --- a/app/src/tx_st30p_app.c +++ b/app/src/tx_st30p_app.c @@ -4,9 +4,10 @@ #include "tx_st30p_app.h" -static void app_tx_st30p_build_frame(struct st_app_tx_st30p_session* s, - struct st30_frame* frame, size_t frame_size) { - uint8_t* src = s->st30p_frame_cursor; +static void app_tx_st30p_build_frame(struct st_app_tx_st30p_session *s, + struct st30_frame *frame, + size_t frame_size) { + uint8_t *src = s->st30p_frame_cursor; mtl_memcpy(frame->addr, src, frame_size); @@ -18,11 +19,11 @@ static void app_tx_st30p_build_frame(struct st_app_tx_st30p_session* s, } } -static void* app_tx_st30p_frame_thread(void* arg) { - struct st_app_tx_st30p_session* s = arg; +static void *app_tx_st30p_frame_thread(void *arg) { + struct st_app_tx_st30p_session *s = arg; st30p_tx_handle handle = s->handle; int idx = s->idx; - struct st30_frame* frame; + struct st30_frame *frame; info("%s(%d), start\n", __func__, idx); while (!s->st30p_app_thread_stop) { @@ -39,7 +40,7 @@ static void* app_tx_st30p_frame_thread(void* arg) { return NULL; } -static int app_tx_st30p_open_source(struct st_app_tx_st30p_session* s) { +static int app_tx_st30p_open_source(struct st_app_tx_st30p_session *s) { int fd; struct stat i; @@ -55,13 +56,13 @@ static int app_tx_st30p_open_source(struct st_app_tx_st30p_session* s) { return -EIO; } if (i.st_size < s->st30p_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, s->st30p_source_url, - s->st30p_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, + s->st30p_source_url, s->st30p_frame_size); close(fd); return -EIO; } - uint8_t* m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { err("%s, mmap fail '%s'\n", __func__, s->st30p_source_url); close(fd); @@ -85,11 +86,12 @@ static int app_tx_st30p_open_source(struct st_app_tx_st30p_session* s) { return 0; } -static int app_tx_st30p_start_source(struct st_app_tx_st30p_session* s) { +static int app_tx_st30p_start_source(struct st_app_tx_st30p_session *s) { int ret = -EINVAL; int idx = s->idx; - ret = pthread_create(&s->st30p_app_thread, NULL, app_tx_st30p_frame_thread, s); + ret = + pthread_create(&s->st30p_app_thread, NULL, app_tx_st30p_frame_thread, s); if (ret < 0) { err("%s(%d), thread create fail ret %d\n", __func__, idx, ret); return ret; @@ -103,17 +105,18 @@ static int app_tx_st30p_start_source(struct st_app_tx_st30p_session* s) { return 0; } -static void app_tx_st30p_stop_source(struct st_app_tx_st30p_session* s) { +static void app_tx_st30p_stop_source(struct st_app_tx_st30p_session *s) { s->st30p_app_thread_stop = true; if (s->st30p_app_thread) { info("%s(%d), wait app thread stop\n", __func__, s->idx); - if (s->handle) st30p_tx_wake_block(s->handle); + if (s->handle) + st30p_tx_wake_block(s->handle); pthread_join(s->st30p_app_thread, NULL); s->st30p_app_thread = 0; } } -static int app_tx_st30p_close_source(struct st_app_tx_st30p_session* s) { +static int app_tx_st30p_close_source(struct st_app_tx_st30p_session *s) { if (s->st30p_source_fd < 0 && s->st30p_source_begin) { mtl_hp_free(s->st, s->st30p_source_begin); s->st30p_source_begin = NULL; @@ -127,28 +130,30 @@ static int app_tx_st30p_close_source(struct st_app_tx_st30p_session* s) { return 0; } -static int app_tx_st30p_handle_free(struct st_app_tx_st30p_session* s) { +static int app_tx_st30p_handle_free(struct st_app_tx_st30p_session *s) { int ret; int idx = s->idx; if (s->handle) { ret = st30p_tx_free(s->handle); - if (ret < 0) err("%s(%d), st30p_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), st30p_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } return 0; } -static int app_tx_st30p_uinit(struct st_app_tx_st30p_session* s) { +static int app_tx_st30p_uinit(struct st_app_tx_st30p_session *s) { app_tx_st30p_stop_source(s); app_tx_st30p_handle_free(s); app_tx_st30p_close_source(s); return 0; } -static int app_tx_st30p_init(struct st_app_context* ctx, st_json_st30p_session_t* st30p, - struct st_app_tx_st30p_session* s) { +static int app_tx_st30p_init(struct st_app_context *ctx, + st_json_st30p_session_t *st30p, + struct st_app_tx_st30p_session *s) { int idx = s->idx, ret; struct st30p_tx_ops ops; char name[32]; @@ -166,10 +171,11 @@ static int app_tx_st30p_init(struct st_app_context* ctx, st_json_st30p_session_t st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = st30p ? st30p->base.udp_port : (10000 + s->idx); + snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name + : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = + st30p ? st30p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -180,25 +186,27 @@ static int app_tx_st30p_init(struct st_app_context* ctx, st_json_st30p_session_t st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf( - ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name + : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st30p ? st30p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], - MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], + ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); ops.flags |= ST30P_TX_FLAG_USER_R_MAC; } } - ops.port.payload_type = st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.port.payload_type = + st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; ops.fmt = st30p ? st30p->info.audio_format : ST30_FMT_PCM24; ops.channel = st30p ? st30p->info.audio_channel : 2; ops.sampling = st30p ? st30p->info.audio_sampling : ST30_SAMPLING_48K; ops.ptime = st30p ? st30p->info.audio_ptime : ST30_PTIME_1MS; /* set frame size to 10ms time */ int framebuff_size = st30_calculate_framebuff_size( - ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, &s->expect_fps); + ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, + &s->expect_fps); ops.framebuff_size = framebuff_size; ops.framebuff_cnt = 3; @@ -211,7 +219,8 @@ static int app_tx_st30p_init(struct st_app_context* ctx, st_json_st30p_session_t s->framebuff_cnt = ops.framebuff_cnt; s->st30p_source_fd = -1; - if (ctx->tx_audio_dedicate_queue) ops.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; + if (ctx->tx_audio_dedicate_queue) + ops.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; if (ctx->force_tx_audio_numa >= 0) { ops.flags |= ST30P_TX_FLAG_FORCE_NUMA; @@ -243,12 +252,13 @@ static int app_tx_st30p_init(struct st_app_context* ctx, st_json_st30p_session_t return 0; } -int st_app_tx_st30p_sessions_init(struct st_app_context* ctx) { +int st_app_tx_st30p_sessions_init(struct st_app_context *ctx) { int ret, i; - struct st_app_tx_st30p_session* s; - ctx->tx_st30p_sessions = (struct st_app_tx_st30p_session*)st_app_zmalloc( + struct st_app_tx_st30p_session *s; + ctx->tx_st30p_sessions = (struct st_app_tx_st30p_session *)st_app_zmalloc( sizeof(struct st_app_tx_st30p_session) * ctx->tx_st30p_session_cnt); - if (!ctx->tx_st30p_sessions) return -ENOMEM; + if (!ctx->tx_st30p_sessions) + return -ENOMEM; for (i = 0; i < ctx->tx_st30p_session_cnt; i++) { s = &ctx->tx_st30p_sessions[i]; s->idx = i; @@ -263,9 +273,10 @@ int st_app_tx_st30p_sessions_init(struct st_app_context* ctx) { return 0; } -int st_app_tx_st30p_sessions_stop(struct st_app_context* ctx) { - struct st_app_tx_st30p_session* s; - if (!ctx->tx_st30p_sessions) return 0; +int st_app_tx_st30p_sessions_stop(struct st_app_context *ctx) { + struct st_app_tx_st30p_session *s; + if (!ctx->tx_st30p_sessions) + return 0; for (int i = 0; i < ctx->tx_st30p_session_cnt; i++) { s = &ctx->tx_st30p_sessions[i]; app_tx_st30p_stop_source(s); @@ -274,10 +285,11 @@ int st_app_tx_st30p_sessions_stop(struct st_app_context* ctx) { return 0; } -int st_app_tx_st30p_sessions_uinit(struct st_app_context* ctx) { +int st_app_tx_st30p_sessions_uinit(struct st_app_context *ctx) { int i; - struct st_app_tx_st30p_session* s; - if (!ctx->tx_st30p_sessions) return 0; + struct st_app_tx_st30p_session *s; + if (!ctx->tx_st30p_sessions) + return 0; for (i = 0; i < ctx->tx_st30p_session_cnt; i++) { s = &ctx->tx_st30p_sessions[i]; app_tx_st30p_uinit(s); diff --git a/app/src/tx_st30p_app.h b/app/src/tx_st30p_app.h index 5f29ccb2a..05dc488ac 100644 --- a/app/src/tx_st30p_app.h +++ b/app/src/tx_st30p_app.h @@ -16,12 +16,12 @@ #ifndef _TX_APP_ST30P_HEAD_H_ #define _TX_APP_ST30P_HEAD_H_ -int st_app_tx_st30p_sessions_init(struct st_app_context* ctx); +int st_app_tx_st30p_sessions_init(struct st_app_context *ctx); -int st_app_tx_st30p_sessions_stop(struct st_app_context* ctx); +int st_app_tx_st30p_sessions_stop(struct st_app_context *ctx); -int st_app_tx_st30p_sessions_uinit(struct st_app_context* ctx); +int st_app_tx_st30p_sessions_uinit(struct st_app_context *ctx); -int st_app_tx_st30p_io_stat(struct st_app_context* ctx); +int st_app_tx_st30p_io_stat(struct st_app_context *ctx); #endif diff --git a/app/tools/convert_app.c b/app/tools/convert_app.c index e8de3a5d3..c4d2dc397 100644 --- a/app/tools/convert_app.c +++ b/app/tools/convert_app.c @@ -14,43 +14,43 @@ static enum st_frame_fmt fmt_cvt2frame(enum cvt_frame_fmt fmt) { switch (fmt) { - case CVT_FRAME_FMT_YUV422PLANAR10LE: - return ST_FRAME_FMT_YUV422PLANAR10LE; - case CVT_FRAME_FMT_YUV422PLANAR12LE: - return ST_FRAME_FMT_YUV422PLANAR12LE; - case CVT_FRAME_FMT_V210: - return ST_FRAME_FMT_V210; - case CVT_FRAME_FMT_Y210: - return ST_FRAME_FMT_Y210; - case CVT_FRAME_FMT_YUV444PLANAR10LE: - return ST_FRAME_FMT_YUV444PLANAR10LE; - case CVT_FRAME_FMT_YUV444PLANAR12LE: - return ST_FRAME_FMT_YUV444PLANAR12LE; - case CVT_FRAME_FMT_GBRPLANAR10LE: - return ST_FRAME_FMT_GBRPLANAR10LE; - case CVT_FRAME_FMT_GBRPLANAR12LE: - return ST_FRAME_FMT_GBRPLANAR12LE; - case CVT_FRAME_FMT_YUV422RFC4175PG2BE10: - return ST_FRAME_FMT_YUV422RFC4175PG2BE10; - case CVT_FRAME_FMT_YUV422RFC4175PG2BE12: - return ST_FRAME_FMT_YUV422RFC4175PG2BE12; - case CVT_FRAME_FMT_YUV444RFC4175PG4BE10: - return ST_FRAME_FMT_YUV444RFC4175PG4BE10; - case CVT_FRAME_FMT_YUV444RFC4175PG2BE12: - return ST_FRAME_FMT_YUV444RFC4175PG2BE12; - case CVT_FRAME_FMT_RGBRFC4175PG4BE10: - return ST_FRAME_FMT_RGBRFC4175PG4BE10; - case CVT_FRAME_FMT_RGBRFC4175PG2BE12: - return ST_FRAME_FMT_RGBRFC4175PG2BE12; - default: - break; + case CVT_FRAME_FMT_YUV422PLANAR10LE: + return ST_FRAME_FMT_YUV422PLANAR10LE; + case CVT_FRAME_FMT_YUV422PLANAR12LE: + return ST_FRAME_FMT_YUV422PLANAR12LE; + case CVT_FRAME_FMT_V210: + return ST_FRAME_FMT_V210; + case CVT_FRAME_FMT_Y210: + return ST_FRAME_FMT_Y210; + case CVT_FRAME_FMT_YUV444PLANAR10LE: + return ST_FRAME_FMT_YUV444PLANAR10LE; + case CVT_FRAME_FMT_YUV444PLANAR12LE: + return ST_FRAME_FMT_YUV444PLANAR12LE; + case CVT_FRAME_FMT_GBRPLANAR10LE: + return ST_FRAME_FMT_GBRPLANAR10LE; + case CVT_FRAME_FMT_GBRPLANAR12LE: + return ST_FRAME_FMT_GBRPLANAR12LE; + case CVT_FRAME_FMT_YUV422RFC4175PG2BE10: + return ST_FRAME_FMT_YUV422RFC4175PG2BE10; + case CVT_FRAME_FMT_YUV422RFC4175PG2BE12: + return ST_FRAME_FMT_YUV422RFC4175PG2BE12; + case CVT_FRAME_FMT_YUV444RFC4175PG4BE10: + return ST_FRAME_FMT_YUV444RFC4175PG4BE10; + case CVT_FRAME_FMT_YUV444RFC4175PG2BE12: + return ST_FRAME_FMT_YUV444RFC4175PG2BE12; + case CVT_FRAME_FMT_RGBRFC4175PG4BE10: + return ST_FRAME_FMT_RGBRFC4175PG4BE10; + case CVT_FRAME_FMT_RGBRFC4175PG2BE12: + return ST_FRAME_FMT_RGBRFC4175PG2BE12; + default: + break; } err("%s, unknown fmt %d\n", __func__, fmt); return ST_FRAME_FMT_MAX; } -static int convert(struct conv_app_context* ctx) { +static int convert(struct conv_app_context *ctx) { enum cvt_frame_fmt fmt_in = ctx->fmt_in; enum cvt_frame_fmt fmt_out = ctx->fmt_out; uint32_t w = ctx->w; @@ -61,7 +61,8 @@ static int convert(struct conv_app_context* ctx) { void *buf_in = NULL, *buf_out = NULL; int ret = -EIO; - if (!frame_size_in || !frame_size_out) return -EIO; + if (!frame_size_in || !frame_size_out) + return -EIO; fp_in = st_fopen(ctx->file_in, "rb"); if (!fp_in) { @@ -96,8 +97,8 @@ static int convert(struct conv_app_context* ctx) { ret = -EIO; goto out; } - info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s(%d)\n", __func__, size, - frame_num, w, h, ctx->file_in, fmt_in, ctx->file_out, fmt_out); + info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s(%d)\n", __func__, + size, frame_num, w, h, ctx->file_in, fmt_in, ctx->file_out, fmt_out); fseek(fp_in, 0, SEEK_SET); for (int i = 0; i < frame_num; i++) { @@ -111,11 +112,11 @@ static int convert(struct conv_app_context* ctx) { if (fmt_in == CVT_FRAME_FMT_YUV422PLANAR10LE) { if (fmt_out == CVT_FRAME_FMT_YUV422RFC4175PG2BE10) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_in; + y = (uint16_t *)buf_in; b = y + w * h; r = b + w * h / 2; st20_yuv422p10le_to_rfc4175_422be10( - y, b, r, (struct st20_rfc4175_422_10_pg2_be*)buf_out, w, h); + y, b, r, (struct st20_rfc4175_422_10_pg2_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -124,11 +125,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_YUV422PLANAR12LE) { if (fmt_out == CVT_FRAME_FMT_YUV422RFC4175PG2BE12) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_in; + y = (uint16_t *)buf_in; b = y + w * h; r = b + w * h / 2; st20_yuv422p12le_to_rfc4175_422be12( - y, b, r, (struct st20_rfc4175_422_12_pg2_be*)buf_out, w, h); + y, b, r, (struct st20_rfc4175_422_12_pg2_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -136,8 +137,8 @@ static int convert(struct conv_app_context* ctx) { } } else if (fmt_in == CVT_FRAME_FMT_V210) { if (fmt_out == CVT_FRAME_FMT_YUV422RFC4175PG2BE10) { - st20_v210_to_rfc4175_422be10(buf_in, (struct st20_rfc4175_422_10_pg2_be*)buf_out, - w, h); + st20_v210_to_rfc4175_422be10( + buf_in, (struct st20_rfc4175_422_10_pg2_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -145,8 +146,8 @@ static int convert(struct conv_app_context* ctx) { } } else if (fmt_in == CVT_FRAME_FMT_Y210) { if (fmt_out == CVT_FRAME_FMT_YUV422RFC4175PG2BE10) { - st20_y210_to_rfc4175_422be10(buf_in, (struct st20_rfc4175_422_10_pg2_be*)buf_out, - w, h); + st20_y210_to_rfc4175_422be10( + buf_in, (struct st20_rfc4175_422_10_pg2_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -155,11 +156,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_YUV444PLANAR10LE) { if (fmt_out == CVT_FRAME_FMT_YUV444RFC4175PG4BE10) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_in; + y = (uint16_t *)buf_in; b = y + w * h; r = b + w * h; st20_yuv444p10le_to_rfc4175_444be10( - y, b, r, (struct st20_rfc4175_444_10_pg4_be*)buf_out, w, h); + y, b, r, (struct st20_rfc4175_444_10_pg4_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -168,11 +169,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_YUV444PLANAR12LE) { if (fmt_out == CVT_FRAME_FMT_YUV444RFC4175PG2BE12) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_in; + y = (uint16_t *)buf_in; b = y + w * h; r = b + w * h; st20_yuv444p12le_to_rfc4175_444be12( - y, b, r, (struct st20_rfc4175_444_12_pg2_be*)buf_out, w, h); + y, b, r, (struct st20_rfc4175_444_12_pg2_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -181,11 +182,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_GBRPLANAR10LE) { if (fmt_out == CVT_FRAME_FMT_RGBRFC4175PG4BE10) { uint16_t *g, *b, *r; - g = (uint16_t*)buf_in; + g = (uint16_t *)buf_in; b = g + w * h; r = b + w * h; st20_gbrp10le_to_rfc4175_444be10( - g, b, r, (struct st20_rfc4175_444_10_pg4_be*)buf_out, w, h); + g, b, r, (struct st20_rfc4175_444_10_pg4_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -194,11 +195,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_GBRPLANAR12LE) { if (fmt_out == CVT_FRAME_FMT_RGBRFC4175PG2BE12) { uint16_t *g, *b, *r; - g = (uint16_t*)buf_in; + g = (uint16_t *)buf_in; b = g + w * h; r = b + w * h; st20_gbrp12le_to_rfc4175_444be12( - g, b, r, (struct st20_rfc4175_444_12_pg2_be*)buf_out, w, h); + g, b, r, (struct st20_rfc4175_444_12_pg2_be *)buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -207,17 +208,17 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_YUV422RFC4175PG2BE10) { if (fmt_out == CVT_FRAME_FMT_YUV422PLANAR10LE) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_out; + y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h / 2; - st20_rfc4175_422be10_to_yuv422p10le((struct st20_rfc4175_422_10_pg2_be*)buf_in, y, - b, r, w, h); + st20_rfc4175_422be10_to_yuv422p10le( + (struct st20_rfc4175_422_10_pg2_be *)buf_in, y, b, r, w, h); } else if (fmt_out == CVT_FRAME_FMT_V210) { - st20_rfc4175_422be10_to_v210((struct st20_rfc4175_422_10_pg2_be*)buf_in, buf_out, - w, h); + st20_rfc4175_422be10_to_v210( + (struct st20_rfc4175_422_10_pg2_be *)buf_in, buf_out, w, h); } else if (fmt_out == CVT_FRAME_FMT_Y210) { - st20_rfc4175_422be10_to_y210((struct st20_rfc4175_422_10_pg2_be*)buf_in, buf_out, - w, h); + st20_rfc4175_422be10_to_y210( + (struct st20_rfc4175_422_10_pg2_be *)buf_in, buf_out, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -226,11 +227,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_YUV422RFC4175PG2BE12) { if (fmt_out == CVT_FRAME_FMT_YUV422PLANAR12LE) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_out; + y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h / 2; - st20_rfc4175_422be12_to_yuv422p12le((struct st20_rfc4175_422_12_pg2_be*)buf_in, y, - b, r, w, h); + st20_rfc4175_422be12_to_yuv422p12le( + (struct st20_rfc4175_422_12_pg2_be *)buf_in, y, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -239,11 +240,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_YUV444RFC4175PG4BE10) { if (fmt_out == CVT_FRAME_FMT_YUV444PLANAR10LE) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_out; + y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h; - st20_rfc4175_444be10_to_yuv444p10le((struct st20_rfc4175_444_10_pg4_be*)buf_in, y, - b, r, w, h); + st20_rfc4175_444be10_to_yuv444p10le( + (struct st20_rfc4175_444_10_pg4_be *)buf_in, y, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -252,11 +253,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_YUV444RFC4175PG2BE12) { if (fmt_out == CVT_FRAME_FMT_YUV444PLANAR12LE) { uint16_t *y, *b, *r; - y = (uint16_t*)buf_out; + y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h; - st20_rfc4175_444be12_to_yuv444p12le((struct st20_rfc4175_444_12_pg2_be*)buf_in, y, - b, r, w, h); + st20_rfc4175_444be12_to_yuv444p12le( + (struct st20_rfc4175_444_12_pg2_be *)buf_in, y, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -265,11 +266,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_RGBRFC4175PG4BE10) { if (fmt_out == CVT_FRAME_FMT_GBRPLANAR10LE) { uint16_t *g, *b, *r; - g = (uint16_t*)buf_out; + g = (uint16_t *)buf_out; b = g + w * h; r = b + w * h; - st20_rfc4175_444be10_to_gbrp10le((struct st20_rfc4175_444_10_pg4_be*)buf_in, g, b, - r, w, h); + st20_rfc4175_444be10_to_gbrp10le( + (struct st20_rfc4175_444_10_pg4_be *)buf_in, g, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -278,11 +279,11 @@ static int convert(struct conv_app_context* ctx) { } else if (fmt_in == CVT_FRAME_FMT_RGBRFC4175PG2BE12) { if (fmt_out == CVT_FRAME_FMT_GBRPLANAR12LE) { uint16_t *g, *b, *r; - g = (uint16_t*)buf_out; + g = (uint16_t *)buf_out; b = g + w * h; r = b + w * h; - st20_rfc4175_444be12_to_gbrp12le((struct st20_rfc4175_444_12_pg2_be*)buf_in, g, b, - r, w, h); + st20_rfc4175_444be12_to_gbrp12le( + (struct st20_rfc4175_444_12_pg2_be *)buf_in, g, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -318,17 +319,18 @@ static int convert(struct conv_app_context* ctx) { return ret; } -static int frame2field(struct conv_app_context* ctx) { +static int frame2field(struct conv_app_context *ctx) { enum cvt_frame_fmt fmt = ctx->fmt_in; uint32_t w = ctx->w; uint32_t h = ctx->h; size_t frame_size = st_frame_size(fmt_cvt2frame(fmt), w, h, false); size_t line_size = frame_size / h; FILE *fp_in = NULL, *fp_out = NULL; - void* buf_in = NULL; + void *buf_in = NULL; int ret = -EIO; - if (!frame_size) return -EIO; + if (!frame_size) + return -EIO; fp_in = st_fopen(ctx->file_in, "rb"); if (!fp_in) { @@ -358,8 +360,8 @@ static int frame2field(struct conv_app_context* ctx) { ret = -EIO; goto out; } - info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s\n", __func__, size, - frame_num, w, h, ctx->file_in, fmt, ctx->file_out); + info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s\n", __func__, + size, frame_num, w, h, ctx->file_in, fmt, ctx->file_out); fseek(fp_in, 0, SEEK_SET); for (int i = 0; i < frame_num; i++) { @@ -370,7 +372,7 @@ static int frame2field(struct conv_app_context* ctx) { goto out; } - void* frame = buf_in; + void *frame = buf_in; /* write the first field */ for (uint32_t line = 0; line < h; line += 2) { fwrite(frame, 1, line_size, fp_out); @@ -402,9 +404,9 @@ static int frame2field(struct conv_app_context* ctx) { return ret; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int ret = -EIO; - struct conv_app_context* ctx; + struct conv_app_context *ctx; ctx = conv_app_zmalloc(sizeof(*ctx)); if (!ctx) { diff --git a/app/tools/convert_app_args.c b/app/tools/convert_app_args.c index abd5e4cc5..f336f0a90 100644 --- a/app/tools/convert_app_args.c +++ b/app/tools/convert_app_args.c @@ -47,7 +47,7 @@ static void conv_app_print_app() { printf("\n"); } -static enum cvt_frame_fmt cvt_parse_fmt(const char* sfmt) { +static enum cvt_frame_fmt cvt_parse_fmt(const char *sfmt) { if (!strcmp(sfmt, "yuv422p10le")) { return CVT_FRAME_FMT_YUV422PLANAR10LE; } @@ -95,45 +95,46 @@ static enum cvt_frame_fmt cvt_parse_fmt(const char* sfmt) { return CVT_FRAME_FMT_MAX; } -int conv_app_parse_args(struct conv_app_context* ctx, int argc, char** argv) { +int conv_app_parse_args(struct conv_app_context *ctx, int argc, char **argv) { int cmd = -1, optIdx = 0; int ret = 0; while (1) { cmd = getopt_long_only(argc, argv, "hv", conv_app_args_options, &optIdx); - if (cmd == -1) break; + if (cmd == -1) + break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case CONV_ARG_FORMAT_IN: - ctx->fmt_in = cvt_parse_fmt(optarg); - break; - case CONV_ARG_FORMAT_OUT: - ctx->fmt_out = cvt_parse_fmt(optarg); - break; - case CONV_ARG_W: - ctx->w = atoi(optarg); - break; - case CONV_ARG_H: - ctx->h = atoi(optarg); - break; - case CONV_ARG_FILE_IN: - snprintf(ctx->file_in, sizeof(ctx->file_in), "%s", optarg); - break; - case CONV_ARG_FILE_OUT: - snprintf(ctx->file_out, sizeof(ctx->file_out), "%s", optarg); - break; - case CONV_ARG_FRAME2FIELD: - ctx->frame2field = true; - break; - case CONV_ARG_HELP: - conv_app_print_app(); - ret = -EIO; - break; - default: - conv_app_print_app(); - ret = -EIO; - break; + case CONV_ARG_FORMAT_IN: + ctx->fmt_in = cvt_parse_fmt(optarg); + break; + case CONV_ARG_FORMAT_OUT: + ctx->fmt_out = cvt_parse_fmt(optarg); + break; + case CONV_ARG_W: + ctx->w = atoi(optarg); + break; + case CONV_ARG_H: + ctx->h = atoi(optarg); + break; + case CONV_ARG_FILE_IN: + snprintf(ctx->file_in, sizeof(ctx->file_in), "%s", optarg); + break; + case CONV_ARG_FILE_OUT: + snprintf(ctx->file_out, sizeof(ctx->file_out), "%s", optarg); + break; + case CONV_ARG_FRAME2FIELD: + ctx->frame2field = true; + break; + case CONV_ARG_HELP: + conv_app_print_app(); + ret = -EIO; + break; + default: + conv_app_print_app(); + ret = -EIO; + break; } }; diff --git a/app/tools/convert_app_base.h b/app/tools/convert_app_base.h index f7c0a5c1e..4bfb085bf 100644 --- a/app/tools/convert_app_base.h +++ b/app/tools/convert_app_base.h @@ -38,13 +38,17 @@ enum cvt_frame_fmt { CVT_FRAME_FMT_GBRPLANAR10LE, /** GBR planar 12bit little endian */ CVT_FRAME_FMT_GBRPLANAR12LE, - /** RFC4175 in ST2110, two YUV 422 10 bit pixel groups on 5 bytes, big endian */ + /** RFC4175 in ST2110, two YUV 422 10 bit pixel groups on 5 bytes, big endian + */ CVT_FRAME_FMT_YUV422RFC4175PG2BE10, - /** RFC4175 in ST2110, two YUV 422 12 bit pixel groups on 6 bytes, big endian */ + /** RFC4175 in ST2110, two YUV 422 12 bit pixel groups on 6 bytes, big endian + */ CVT_FRAME_FMT_YUV422RFC4175PG2BE12, - /** RFC4175 in ST2110, four YUV 444 10 bit pixel groups on 15 bytes, big endian */ + /** RFC4175 in ST2110, four YUV 444 10 bit pixel groups on 15 bytes, big + endian */ CVT_FRAME_FMT_YUV444RFC4175PG4BE10, - /** RFC4175 in ST2110, two YUV 444 12 bit pixel groups on 9 bytes, big endian */ + /** RFC4175 in ST2110, two YUV 444 12 bit pixel groups on 9 bytes, big endian + */ CVT_FRAME_FMT_YUV444RFC4175PG2BE12, /** RFC4175 in ST2110, four RGB 10 bit pixel groups on 15 bytes, big endian */ CVT_FRAME_FMT_RGBRFC4175PG4BE10, @@ -64,16 +68,15 @@ struct conv_app_context { bool frame2field; }; -static inline void* conv_app_zmalloc(size_t sz) { - void* p = malloc(sz); - if (p) memset(p, 0x0, sz); +static inline void *conv_app_zmalloc(size_t sz) { + void *p = malloc(sz); + if (p) + memset(p, 0x0, sz); return p; } -static inline void conv_app_free(void* p) { - free(p); -} +static inline void conv_app_free(void *p) { free(p); } -int conv_app_parse_args(struct conv_app_context* ctx, int argc, char** argv); +int conv_app_parse_args(struct conv_app_context *ctx, int argc, char **argv); #endif diff --git a/app/tools/lcore_shmem_mgr.c b/app/tools/lcore_shmem_mgr.c index fcb998ef7..eef571846 100644 --- a/app/tools/lcore_shmem_mgr.c +++ b/app/tools/lcore_shmem_mgr.c @@ -41,52 +41,54 @@ static void lsm_print_help() { printf("Params:\n"); printf(" --help: Print the help information\n"); printf(" --info: Print lcore shared manager detail info\n"); - printf(" --clean_pid_auto_check: Clean the dead entries if PID is not active\n"); + printf( + " --clean_pid_auto_check: Clean the dead entries if PID is not active\n"); printf(" --clean_lcore : Clean the entry by lcore ID\n"); printf("\n"); } -int main(int argc, char** argv) { +int main(int argc, char **argv) { int cmd = -1, opt_idx = 0; int ret; while (1) { cmd = getopt_long_only(argc, argv, "hv", lsm_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; switch (cmd) { - case LSM_ARG_INFO: - mtl_lcore_shm_print(); - break; - case LSM_ARG_CLEAN_PID_AUTO_CHECK: - ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_PID_AUTO_CHECK, NULL, 0); - if (ret > 0) - info("Total %d dead lcores detected and deleted\n", ret); - else if (ret == 0) - info("No dead lcores detected\n"); - else - err("Fail %d to clean shm by auto PID check\n", ret); - break; - case LSM_ARG_CLEAN_LCORE: { - int lcore = atoi(optarg); - if (lcore < 0) { - err("lcore %d is not valid\n", lcore); - return -EIO; - } - struct mtl_lcore_clean_pid_info pid; - pid.lcore = lcore; - ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_LCORE, &pid, sizeof(pid)); - if (ret >= 0) - info("Succ to delete lcore %d\n", lcore); - else - err("Fail %d to delete lcore %d\n", ret, lcore); - break; + case LSM_ARG_INFO: + mtl_lcore_shm_print(); + break; + case LSM_ARG_CLEAN_PID_AUTO_CHECK: + ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_PID_AUTO_CHECK, NULL, 0); + if (ret > 0) + info("Total %d dead lcores detected and deleted\n", ret); + else if (ret == 0) + info("No dead lcores detected\n"); + else + err("Fail %d to clean shm by auto PID check\n", ret); + break; + case LSM_ARG_CLEAN_LCORE: { + int lcore = atoi(optarg); + if (lcore < 0) { + err("lcore %d is not valid\n", lcore); + return -EIO; } - case LSM_ARG_HELP: - default: - lsm_print_help(); - return -1; + struct mtl_lcore_clean_pid_info pid; + pid.lcore = lcore; + ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_LCORE, &pid, sizeof(pid)); + if (ret >= 0) + info("Succ to delete lcore %d\n", lcore); + else + err("Fail %d to delete lcore %d\n", ret, lcore); + break; + } + case LSM_ARG_HELP: + default: + lsm_print_help(); + return -1; } } diff --git a/app/tools/log.h b/app/tools/log.h index a7f28cd6e..9bbe496ee 100644 --- a/app/tools/log.h +++ b/app/tools/log.h @@ -10,22 +10,22 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif diff --git a/app/udp/udp_client_sample.c b/app/udp/udp_client_sample.c index 445196cc0..c154b5388 100644 --- a/app/udp/udp_client_sample.c +++ b/app/udp/udp_client_sample.c @@ -35,8 +35,8 @@ struct udp_client_sample_ctx { int recv_cnt_total; }; -static void* udp_client_thread(void* arg) { - struct udp_client_sample_ctx* s = arg; +static void *udp_client_thread(void *arg) { + struct udp_client_sample_ctx *s = arg; mudp_handle socket = s->socket; ssize_t udp_len = s->udp_len; @@ -49,12 +49,13 @@ static void* udp_client_thread(void* arg) { int idx_pos = udp_len / 2; int send_idx = 0; - info("%s(%d), start socket %p udp len %d\n", __func__, s->idx, socket, (int)udp_len); + info("%s(%d), start socket %p udp len %d\n", __func__, s->idx, socket, + (int)udp_len); while (!s->stop) { send_buf[idx_pos] = send_idx++; - ssize_t send = - mudp_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr*)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = mudp_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, + sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -62,7 +63,8 @@ static void* udp_client_thread(void* arg) { s->send_cnt++; s->send_cnt_total++; - ssize_t recv = mudp_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); + ssize_t recv = + mudp_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); if (recv != udp_len) { dbg("%s(%d), only recv %d bytes\n", __func__, s->idx, (int)recv); s->recv_fail_cnt++; @@ -72,8 +74,8 @@ static void* udp_client_thread(void* arg) { char expect_rx_idx = last_rx_idx + 1; last_rx_idx = recv_buf[idx_pos]; if (last_rx_idx != expect_rx_idx) { - err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, expect_rx_idx, - last_rx_idx); + err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, + expect_rx_idx, last_rx_idx); s->recv_err_cnt++; continue; } @@ -86,8 +88,8 @@ static void* udp_client_thread(void* arg) { return NULL; } -static void* udp_client_transport_thread(void* arg) { - struct udp_client_sample_ctx* s = arg; +static void *udp_client_transport_thread(void *arg) { + struct udp_client_sample_ctx *s = arg; mudp_handle socket = s->socket; ssize_t udp_len = s->udp_len; @@ -96,11 +98,12 @@ static void* udp_client_transport_thread(void* arg) { send_buf[i] = i; } - info("%s(%d), start socket %p, udp len %d\n", __func__, s->idx, socket, (int)udp_len); + info("%s(%d), start socket %p, udp len %d\n", __func__, s->idx, socket, + (int)udp_len); while (!s->stop) { - ssize_t send = - mudp_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr*)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = mudp_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, + sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -113,15 +116,15 @@ static void* udp_client_transport_thread(void* arg) { return NULL; } -static void udp_client_status(struct udp_client_sample_ctx* s) { +static void udp_client_status(struct udp_client_sample_ctx *s) { uint64_t cur_ts = sample_get_monotonic_time(); double time_sec = (double)(cur_ts - s->last_stat_time) / NS_PER_S; double bps = (double)s->send_cnt * s->udp_len * 8 / time_sec; double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, s->send_cnt, bps_g, - s->recv_cnt); + info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, + s->send_cnt, bps_g, s->recv_cnt); s->send_cnt = 0; s->recv_cnt = 0; if (s->recv_fail_cnt) { @@ -134,13 +137,14 @@ static void udp_client_status(struct udp_client_sample_ctx* s) { } } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, true, true); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -149,7 +153,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct udp_client_sample_ctx* app[session_num]; + struct udp_client_sample_ctx *app[session_num]; memset(app, 0, sizeof(app)); for (int i = 0; i < session_num; i++) { @@ -171,7 +175,8 @@ int main(int argc, char** argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], ctx.udp_port + i); + mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], + ctx.udp_port + i); app[i]->socket = mudp_socket(ctx.st, AF_INET, SOCK_DGRAM, 0); if (!app[i]->socket) { @@ -179,14 +184,16 @@ int main(int argc, char** argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) + mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mudp_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, + sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -195,7 +202,8 @@ int main(int argc, char** argv) { if ((ctx.udp_mode == SAMPLE_UDP_TRANSPORT) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL)) - ret = pthread_create(&app[i]->thread, NULL, udp_client_transport_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, udp_client_transport_thread, + app[i]); else ret = pthread_create(&app[i]->thread, NULL, udp_client_thread, app[i]); if (ret < 0) { @@ -234,15 +242,18 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; + if (!app[i]) + continue; // stop app thread app[i]->stop = true; st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) pthread_join(app[i]->thread, NULL); + if (app[i]->thread) + pthread_join(app[i]->thread, NULL); - if (app[i]->socket) mudp_close(app[i]->socket); + if (app[i]->socket) + mudp_close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/udp/udp_server_sample.c b/app/udp/udp_server_sample.c index a50a27bf5..c7d9acedb 100644 --- a/app/udp/udp_server_sample.c +++ b/app/udp/udp_server_sample.c @@ -34,7 +34,7 @@ struct udp_server_sample_ctx { }; struct udp_server_samples_ctx { - struct udp_server_sample_ctx** apps; + struct udp_server_sample_ctx **apps; int apps_cnt; bool stop; @@ -43,8 +43,8 @@ struct udp_server_samples_ctx { pthread_mutex_t wake_mutex; }; -static void* udp_server_thread(void* arg) { - struct udp_server_sample_ctx* s = arg; +static void *udp_server_thread(void *arg) { + struct udp_server_sample_ctx *s = arg; mudp_handle socket = s->socket; ssize_t udp_len = MUDP_MAX_BYTES; char buf[udp_len]; @@ -53,8 +53,8 @@ static void* udp_server_thread(void* arg) { info("%s(%d), start socket %p\n", __func__, s->idx, socket); while (!s->stop) { - ssize_t recv = mudp_recvfrom(socket, buf, sizeof(buf), 0, (struct sockaddr*)&cli_addr, - &cli_addr_len); + ssize_t recv = mudp_recvfrom(socket, buf, sizeof(buf), 0, + (struct sockaddr *)&cli_addr, &cli_addr_len); if (recv < 0) { dbg("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); continue; @@ -63,8 +63,8 @@ static void* udp_server_thread(void* arg) { s->recv_cnt_total++; s->recv_len += recv; dbg("%s(%d), recv %d bytes\n", __func__, s->idx, (int)recv); - ssize_t send = mudp_sendto(socket, buf, recv, 0, (const struct sockaddr*)&cli_addr, - cli_addr_len); + ssize_t send = mudp_sendto( + socket, buf, recv, 0, (const struct sockaddr *)&cli_addr, cli_addr_len); if (send != recv) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -77,8 +77,8 @@ static void* udp_server_thread(void* arg) { return NULL; } -static void* udp_server_transport_thread(void* arg) { - struct udp_server_sample_ctx* s = arg; +static void *udp_server_transport_thread(void *arg) { + struct udp_server_sample_ctx *s = arg; mudp_handle socket = s->socket; ssize_t udp_len = MUDP_MAX_BYTES; char buf[udp_len]; @@ -99,8 +99,8 @@ static void* udp_server_transport_thread(void* arg) { return NULL; } -static void* udp_server_transport_poll_thread(void* arg) { - struct udp_server_sample_ctx* s = arg; +static void *udp_server_transport_poll_thread(void *arg) { + struct udp_server_sample_ctx *s = arg; mudp_handle socket = s->socket; ssize_t udp_len = MUDP_MAX_BYTES; char buf[udp_len]; @@ -113,7 +113,8 @@ static void* udp_server_transport_poll_thread(void* arg) { info("%s(%d), start socket %p\n", __func__, s->idx, socket); while (!s->stop) { int ret = mudp_poll(fds, 1, 100); - if (ret <= 0) continue; + if (ret <= 0) + continue; ssize_t recv = mudp_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); if (recv < 0) { err("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); @@ -128,9 +129,9 @@ static void* udp_server_transport_poll_thread(void* arg) { return NULL; } -static void* udp_servers_poll_thread(void* arg) { - struct udp_server_samples_ctx* ctxs = arg; - struct udp_server_sample_ctx* s = NULL; +static void *udp_servers_poll_thread(void *arg) { + struct udp_server_samples_ctx *ctxs = arg; + struct udp_server_sample_ctx *s = NULL; int apps_cnt = ctxs->apps_cnt; mudp_handle socket; ssize_t udp_len = MUDP_MAX_BYTES; @@ -147,9 +148,11 @@ static void* udp_servers_poll_thread(void* arg) { info("%s, start at %p\n", __func__, ctxs); while (!ctxs->stop) { int ret = mudp_poll(fds, apps_cnt, 100); - if (ret <= 0) continue; + if (ret <= 0) + continue; for (int i = 0; i < apps_cnt; i++) { - if (!fds[i].revents) continue; /* pkt not ready */ + if (!fds[i].revents) + continue; /* pkt not ready */ s = ctxs->apps[i]; socket = s->socket; ssize_t recv = mudp_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); @@ -167,28 +170,29 @@ static void* udp_servers_poll_thread(void* arg) { return NULL; } -static void udp_server_status(struct udp_server_sample_ctx* s) { +static void udp_server_status(struct udp_server_sample_ctx *s) { uint64_t cur_ts = sample_get_monotonic_time(); double time_sec = (double)(cur_ts - s->last_stat_time) / NS_PER_S; double bps = (double)s->recv_len * 8 / time_sec; double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, s->send_cnt, - s->recv_cnt, bps_g); + info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, + s->send_cnt, s->recv_cnt, bps_g); s->send_cnt = 0; s->recv_cnt = 0; s->recv_len = 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; struct udp_server_samples_ctx ctxs; int ret; memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, true, true); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -197,7 +201,7 @@ int main(int argc, char** argv) { } uint32_t session_num = ctx.sessions; - struct udp_server_sample_ctx* app[session_num]; + struct udp_server_sample_ctx *app[session_num]; memset(app, 0, sizeof(app)); ctxs.apps = NULL; @@ -235,7 +239,8 @@ int main(int argc, char** argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) + mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mudp_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); mudp_init_sockaddr(&app[i]->client_addr, ctx.rx_ip_addr[MTL_PORT_P], @@ -250,7 +255,7 @@ int main(int argc, char** argv) { mudp_init_sockaddr(&app[i]->bind_addr, ctx.param.sip_addr[MTL_PORT_P], ctx.udp_port + i); } - ret = mudp_bind(app[i]->socket, (const struct sockaddr*)&app[i]->bind_addr, + ret = mudp_bind(app[i]->socket, (const struct sockaddr *)&app[i]->bind_addr, sizeof(app[i]->bind_addr)); if (ret < 0) { err("%s(%d), bind fail %d\n", __func__, i, ret); @@ -260,7 +265,8 @@ int main(int argc, char** argv) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, + sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -272,9 +278,10 @@ int main(int argc, char** argv) { /* multicast addr */ mreq.imr_multiaddr.s_addr = app[i]->client_addr.sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - ret = mudp_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, - sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + ret = mudp_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, + &mreq, sizeof(mreq)); if (ret < 0) { err("%s(%d), join multicast fail %d\n", __func__, i, ret); goto error; @@ -283,14 +290,16 @@ int main(int argc, char** argv) { } if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT) { - ret = pthread_create(&app[i]->thread, NULL, udp_server_transport_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, udp_server_transport_thread, + app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) { - ret = - pthread_create(&app[i]->thread, NULL, udp_server_transport_poll_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, + udp_server_transport_poll_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL) { ctxs.apps[i] = app[i]; if ((i + 1) == session_num) { - ret = pthread_create(&ctxs.thread, NULL, udp_servers_poll_thread, &ctxs); + ret = + pthread_create(&ctxs.thread, NULL, udp_servers_poll_thread, &ctxs); } } else { ret = pthread_create(&app[i]->thread, NULL, udp_server_thread, app[i]); @@ -336,18 +345,21 @@ int main(int argc, char** argv) { st_pthread_mutex_lock(&ctxs.wake_mutex); st_pthread_cond_signal(&ctxs.wake_cond); st_pthread_mutex_unlock(&ctxs.wake_mutex); - if (ctxs.thread) pthread_join(ctxs.thread, NULL); + if (ctxs.thread) + pthread_join(ctxs.thread, NULL); } for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; + if (!app[i]) + continue; // stop app thread app[i]->stop = true; dbg("%s(%d), stop thread\n", __func__, i); st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) pthread_join(app[i]->thread, NULL); + if (app[i]->thread) + pthread_join(app[i]->thread, NULL); if (app[i]->socket) { bool mcast = mudp_is_multicast(&app[i]->client_addr); @@ -368,7 +380,8 @@ int main(int argc, char** argv) { st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); } - if (ctxs.apps) free(ctxs.apps); + if (ctxs.apps) + free(ctxs.apps); st_pthread_mutex_destroy(&ctxs.wake_mutex); st_pthread_cond_destroy(&ctxs.wake_cond); /* release sample(st) dev */ diff --git a/app/udp/ufd_client_sample.c b/app/udp/ufd_client_sample.c index 010f7112c..2159a8d2a 100644 --- a/app/udp/ufd_client_sample.c +++ b/app/udp/ufd_client_sample.c @@ -34,8 +34,8 @@ struct ufd_client_sample_ctx { int recv_cnt_total; }; -static void* ufd_client_thread(void* arg) { - struct ufd_client_sample_ctx* s = arg; +static void *ufd_client_thread(void *arg) { + struct ufd_client_sample_ctx *s = arg; int socket = s->socket; ssize_t ufd_len = s->udp_len; @@ -48,12 +48,13 @@ static void* ufd_client_thread(void* arg) { int idx_pos = ufd_len / 2; int send_idx = 0; - info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, (int)ufd_len); + info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, + (int)ufd_len); while (!s->stop) { send_buf[idx_pos] = send_idx++; - ssize_t send = - mufd_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr*)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = mufd_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, + sizeof(s->serv_addr)); if (send != ufd_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -61,7 +62,8 @@ static void* ufd_client_thread(void* arg) { s->send_cnt++; s->send_cnt_total++; - ssize_t recv = mufd_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); + ssize_t recv = + mufd_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); if (recv != ufd_len) { dbg("%s(%d), only recv %d bytes\n", __func__, s->idx, (int)recv); s->recv_fail_cnt++; @@ -71,8 +73,8 @@ static void* ufd_client_thread(void* arg) { char expect_rx_idx = last_rx_idx + 1; last_rx_idx = recv_buf[idx_pos]; if (last_rx_idx != expect_rx_idx) { - err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, expect_rx_idx, - last_rx_idx); + err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, + expect_rx_idx, last_rx_idx); s->recv_err_cnt++; continue; } @@ -85,8 +87,8 @@ static void* ufd_client_thread(void* arg) { return NULL; } -static void* ufd_client_transport_thread(void* arg) { - struct ufd_client_sample_ctx* s = arg; +static void *ufd_client_transport_thread(void *arg) { + struct ufd_client_sample_ctx *s = arg; int socket = s->socket; ssize_t ufd_len = s->udp_len; @@ -95,11 +97,12 @@ static void* ufd_client_transport_thread(void* arg) { send_buf[i] = i; } - info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, (int)ufd_len); + info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, + (int)ufd_len); while (!s->stop) { - ssize_t send = - mufd_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr*)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = mufd_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, + sizeof(s->serv_addr)); if (send != ufd_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -112,15 +115,15 @@ static void* ufd_client_transport_thread(void* arg) { return NULL; } -static void ufd_client_status(struct ufd_client_sample_ctx* s) { +static void ufd_client_status(struct ufd_client_sample_ctx *s) { uint64_t cur_ts = sample_get_monotonic_time(); double time_sec = (double)(cur_ts - s->last_stat_time) / NS_PER_S; double bps = (double)s->send_cnt * s->udp_len * 8 / time_sec; double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, s->send_cnt, bps_g, - s->recv_cnt); + info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, + s->send_cnt, bps_g, s->recv_cnt); s->send_cnt = 0; s->recv_cnt = 0; if (s->recv_fail_cnt) { @@ -135,28 +138,29 @@ static void ufd_client_status(struct ufd_client_sample_ctx* s) { static void ufd_client_sig_handler(int signo) { switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - mufd_abort(); - break; + case SIGINT: /* Interrupt from keyboard */ + mufd_abort(); + break; } return; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, false, true); - if (ret < 0) return ret; + if (ret < 0) + return ret; ufd_override_check(&ctx); ctx.sig_handler = ufd_client_sig_handler; uint32_t session_num = ctx.sessions; - struct ufd_client_sample_ctx* app[session_num]; + struct ufd_client_sample_ctx *app[session_num]; memset(app, 0, sizeof(app)); for (int i = 0; i < session_num; i++) { @@ -177,7 +181,8 @@ int main(int argc, char** argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - mufd_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], ctx.udp_port + i); + mufd_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], + ctx.udp_port + i); app[i]->socket = mufd_socket(AF_INET, SOCK_DGRAM, 0); if (app[i]->socket < 0) { @@ -185,14 +190,16 @@ int main(int argc, char** argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) + mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mufd_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, + sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -201,7 +208,8 @@ int main(int argc, char** argv) { if ((ctx.udp_mode == SAMPLE_UDP_TRANSPORT) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL)) - ret = pthread_create(&app[i]->thread, NULL, ufd_client_transport_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, ufd_client_transport_thread, + app[i]); else ret = pthread_create(&app[i]->thread, NULL, ufd_client_thread, app[i]); if (ret < 0) { @@ -240,15 +248,18 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; + if (!app[i]) + continue; // stop app thread app[i]->stop = true; st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) pthread_join(app[i]->thread, NULL); + if (app[i]->thread) + pthread_join(app[i]->thread, NULL); - if (app[i]->socket >= 0) mufd_close(app[i]->socket); + if (app[i]->socket >= 0) + mufd_close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/udp/ufd_server_sample.c b/app/udp/ufd_server_sample.c index ce06c3cf4..eedf913a8 100644 --- a/app/udp/ufd_server_sample.c +++ b/app/udp/ufd_server_sample.c @@ -33,7 +33,7 @@ struct ufd_server_sample_ctx { }; struct ufd_server_samples_ctx { - struct ufd_server_sample_ctx** apps; + struct ufd_server_sample_ctx **apps; int apps_cnt; bool stop; @@ -42,8 +42,8 @@ struct ufd_server_samples_ctx { pthread_mutex_t wake_mutex; }; -static void* ufd_server_thread(void* arg) { - struct ufd_server_sample_ctx* s = arg; +static void *ufd_server_thread(void *arg) { + struct ufd_server_sample_ctx *s = arg; int socket = s->socket; ssize_t ufd_len = MUDP_MAX_BYTES; char buf[ufd_len]; @@ -52,8 +52,8 @@ static void* ufd_server_thread(void* arg) { info("%s(%d), start socket %d\n", __func__, s->idx, socket); while (!s->stop) { - ssize_t recv = mufd_recvfrom(socket, buf, sizeof(buf), 0, (struct sockaddr*)&cli_addr, - &cli_addr_len); + ssize_t recv = mufd_recvfrom(socket, buf, sizeof(buf), 0, + (struct sockaddr *)&cli_addr, &cli_addr_len); if (recv < 0) { dbg("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); continue; @@ -64,12 +64,13 @@ static void* ufd_server_thread(void* arg) { dbg("%s(%d), recv %d bytes\n", __func__, s->idx, (int)recv); dbg("%s(%d), sin_port %u\n", __func__, s->idx, ntohs(cli_addr.sin_port)); #ifdef DEBUG - uint8_t* ip = (uint8_t*)&cli_addr.sin_addr.s_addr; + uint8_t *ip = (uint8_t *)&cli_addr.sin_addr.s_addr; #endif - dbg("%s(%d), ip %u.%u.%u.%u\n", __func__, s->idx, ip[0], ip[1], ip[2], ip[3]); + dbg("%s(%d), ip %u.%u.%u.%u\n", __func__, s->idx, ip[0], ip[1], ip[2], + ip[3]); - ssize_t send = mufd_sendto(socket, buf, recv, 0, (const struct sockaddr*)&cli_addr, - cli_addr_len); + ssize_t send = mufd_sendto( + socket, buf, recv, 0, (const struct sockaddr *)&cli_addr, cli_addr_len); if (send != recv) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -82,8 +83,8 @@ static void* ufd_server_thread(void* arg) { return NULL; } -static void* ufd_server_transport_thread(void* arg) { - struct ufd_server_sample_ctx* s = arg; +static void *ufd_server_transport_thread(void *arg) { + struct ufd_server_sample_ctx *s = arg; int socket = s->socket; ssize_t ufd_len = MUDP_MAX_BYTES; char buf[ufd_len]; @@ -104,8 +105,8 @@ static void* ufd_server_transport_thread(void* arg) { return NULL; } -static void* ufd_server_transport_poll_thread(void* arg) { - struct ufd_server_sample_ctx* s = arg; +static void *ufd_server_transport_poll_thread(void *arg) { + struct ufd_server_sample_ctx *s = arg; int socket = s->socket; ssize_t ufd_len = MUDP_MAX_BYTES; char buf[ufd_len]; @@ -118,7 +119,8 @@ static void* ufd_server_transport_poll_thread(void* arg) { info("%s(%d), start socket %d\n", __func__, s->idx, socket); while (!s->stop) { int ret = mufd_poll(fds, 1, 100); - if (ret <= 0) continue; + if (ret <= 0) + continue; ssize_t recv = mufd_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); if (recv < 0) { err("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); @@ -133,9 +135,9 @@ static void* ufd_server_transport_poll_thread(void* arg) { return NULL; } -static void* ufd_servers_poll_thread(void* arg) { - struct ufd_server_samples_ctx* ctxs = arg; - struct ufd_server_sample_ctx* s = NULL; +static void *ufd_servers_poll_thread(void *arg) { + struct ufd_server_samples_ctx *ctxs = arg; + struct ufd_server_sample_ctx *s = NULL; int apps_cnt = ctxs->apps_cnt; int socket; ssize_t ufd_len = MUDP_MAX_BYTES; @@ -152,9 +154,11 @@ static void* ufd_servers_poll_thread(void* arg) { info("%s, start at %p\n", __func__, ctxs); while (!ctxs->stop) { int ret = mufd_poll(fds, apps_cnt, 100); - if (ret <= 0) continue; + if (ret <= 0) + continue; for (int i = 0; i < apps_cnt; i++) { - if (!fds[i].revents) continue; /* pkt not ready */ + if (!fds[i].revents) + continue; /* pkt not ready */ s = ctxs->apps[i]; socket = s->socket; ssize_t recv = mufd_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); @@ -172,15 +176,15 @@ static void* ufd_servers_poll_thread(void* arg) { return NULL; } -static void ufd_server_status(struct ufd_server_sample_ctx* s) { +static void ufd_server_status(struct ufd_server_sample_ctx *s) { uint64_t cur_ts = sample_get_monotonic_time(); double time_sec = (double)(cur_ts - s->last_stat_time) / NS_PER_S; double bps = (double)s->recv_len * 8 / time_sec; double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, s->send_cnt, - s->recv_cnt, bps_g); + info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, + s->send_cnt, s->recv_cnt, bps_g); s->send_cnt = 0; s->recv_cnt = 0; s->recv_len = 0; @@ -188,29 +192,30 @@ static void ufd_server_status(struct ufd_server_sample_ctx* s) { static void ufd_server_sig_handler(int signo) { switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - mufd_abort(); - break; + case SIGINT: /* Interrupt from keyboard */ + mufd_abort(); + break; } return; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; struct ufd_server_samples_ctx ctxs; int ret; memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, false, true, true); - if (ret < 0) return ret; + if (ret < 0) + return ret; ufd_override_check(&ctx); ctx.sig_handler = ufd_server_sig_handler; uint32_t session_num = ctx.sessions; - struct ufd_server_sample_ctx* app[session_num]; + struct ufd_server_sample_ctx *app[session_num]; memset(app, 0, sizeof(app)); ctxs.apps = NULL; @@ -247,7 +252,8 @@ int main(int argc, char** argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) + mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mufd_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); mufd_init_sockaddr(&app[i]->client_addr, ctx.rx_ip_addr[MTL_PORT_P], @@ -261,7 +267,7 @@ int main(int argc, char** argv) { mufd_port_ip_info(MTL_PORT_P, sip, NULL, NULL); mudp_init_sockaddr(&app[i]->bind_addr, sip, ctx.udp_port + i); } - ret = mufd_bind(app[i]->socket, (const struct sockaddr*)&app[i]->bind_addr, + ret = mufd_bind(app[i]->socket, (const struct sockaddr *)&app[i]->bind_addr, sizeof(app[i]->bind_addr)); if (ret < 0) { err("%s(%d), bind fail %d\n", __func__, i, ret); @@ -271,7 +277,8 @@ int main(int argc, char** argv) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, + sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -283,9 +290,10 @@ int main(int argc, char** argv) { /* multicast addr */ mreq.imr_multiaddr.s_addr = app[i]->client_addr.sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - ret = mufd_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, - sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + ret = mufd_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, + &mreq, sizeof(mreq)); if (ret < 0) { err("%s(%d), join multicast fail %d\n", __func__, i, ret); goto error; @@ -294,14 +302,16 @@ int main(int argc, char** argv) { } if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT) { - ret = pthread_create(&app[i]->thread, NULL, ufd_server_transport_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, ufd_server_transport_thread, + app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) { - ret = - pthread_create(&app[i]->thread, NULL, ufd_server_transport_poll_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, + ufd_server_transport_poll_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL) { ctxs.apps[i] = app[i]; if ((i + 1) == session_num) { - ret = pthread_create(&ctxs.thread, NULL, ufd_servers_poll_thread, &ctxs); + ret = + pthread_create(&ctxs.thread, NULL, ufd_servers_poll_thread, &ctxs); } } else { ret = pthread_create(&app[i]->thread, NULL, ufd_server_thread, app[i]); @@ -347,18 +357,21 @@ int main(int argc, char** argv) { st_pthread_mutex_lock(&ctxs.wake_mutex); st_pthread_cond_signal(&ctxs.wake_cond); st_pthread_mutex_unlock(&ctxs.wake_mutex); - if (ctxs.thread) pthread_join(ctxs.thread, NULL); + if (ctxs.thread) + pthread_join(ctxs.thread, NULL); } for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; + if (!app[i]) + continue; // stop app thread app[i]->stop = true; dbg("%s(%d), stop thread\n", __func__, i); st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) pthread_join(app[i]->thread, NULL); + if (app[i]->thread) + pthread_join(app[i]->thread, NULL); if (app[i]->socket >= 0) { bool mcast = mudp_is_multicast(&app[i]->client_addr); @@ -379,7 +392,8 @@ int main(int argc, char** argv) { st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); } - if (ctxs.apps) free(ctxs.apps); + if (ctxs.apps) + free(ctxs.apps); st_pthread_mutex_destroy(&ctxs.wake_mutex); st_pthread_cond_destroy(&ctxs.wake_cond); diff --git a/app/udp/usocket_client_sample.c b/app/udp/usocket_client_sample.c index 4f2cab527..368ec3ea1 100644 --- a/app/udp/usocket_client_sample.c +++ b/app/udp/usocket_client_sample.c @@ -31,8 +31,8 @@ struct usocket_client_sample_ctx { int recv_cnt_total; }; -static void* usocket_client_thread(void* arg) { - struct usocket_client_sample_ctx* s = arg; +static void *usocket_client_thread(void *arg) { + struct usocket_client_sample_ctx *s = arg; int socket = s->socket; ssize_t udp_len = s->udp_len; @@ -49,8 +49,9 @@ static void* usocket_client_thread(void* arg) { (int)udp_len); while (!s->stop) { send_buf[idx_pos] = send_idx++; - ssize_t send = sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr*)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = + sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -68,8 +69,8 @@ static void* usocket_client_thread(void* arg) { char expect_rx_idx = last_rx_idx + 1; last_rx_idx = recv_buf[idx_pos]; if (last_rx_idx != expect_rx_idx) { - err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, expect_rx_idx, - last_rx_idx); + err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, + expect_rx_idx, last_rx_idx); s->recv_err_cnt++; continue; } @@ -82,8 +83,8 @@ static void* usocket_client_thread(void* arg) { return NULL; } -static void* usocket_client_transport_thread(void* arg) { - struct usocket_client_sample_ctx* s = arg; +static void *usocket_client_transport_thread(void *arg) { + struct usocket_client_sample_ctx *s = arg; int socket = s->socket; ssize_t udp_len = s->udp_len; @@ -95,8 +96,9 @@ static void* usocket_client_transport_thread(void* arg) { info("%s(%d), start socket %d, usocket len %d\n", __func__, s->idx, socket, (int)udp_len); while (!s->stop) { - ssize_t send = sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr*)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = + sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -109,15 +111,15 @@ static void* usocket_client_transport_thread(void* arg) { return NULL; } -static void usocket_client_status(struct usocket_client_sample_ctx* s) { +static void usocket_client_status(struct usocket_client_sample_ctx *s) { uint64_t cur_ts = sample_get_monotonic_time(); double time_sec = (double)(cur_ts - s->last_stat_time) / NS_PER_S; double bps = (double)s->send_cnt * s->udp_len * 8 / time_sec; double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, s->send_cnt, bps_g, - s->recv_cnt); + info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, + s->send_cnt, bps_g, s->recv_cnt); s->send_cnt = 0; s->recv_cnt = 0; if (s->recv_fail_cnt) { @@ -130,16 +132,17 @@ static void usocket_client_status(struct usocket_client_sample_ctx* s) { } } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, false, true); - if (ret < 0) return ret; + if (ret < 0) + return ret; uint32_t session_num = ctx.sessions; - struct usocket_client_sample_ctx* app[session_num]; + struct usocket_client_sample_ctx *app[session_num]; memset(app, 0, sizeof(app)); for (int i = 0; i < session_num; i++) { @@ -160,7 +163,8 @@ int main(int argc, char** argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], ctx.udp_port + i); + mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], + ctx.udp_port + i); app[i]->socket = socket(AF_INET, SOCK_DGRAM, 0); if (app[i]->socket < 0) { @@ -181,10 +185,11 @@ int main(int argc, char** argv) { if ((ctx.udp_mode == SAMPLE_UDP_TRANSPORT) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL)) - ret = - pthread_create(&app[i]->thread, NULL, usocket_client_transport_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, + usocket_client_transport_thread, app[i]); else - ret = pthread_create(&app[i]->thread, NULL, usocket_client_thread, app[i]); + ret = + pthread_create(&app[i]->thread, NULL, usocket_client_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); goto error; @@ -221,15 +226,18 @@ int main(int argc, char** argv) { error: for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; + if (!app[i]) + continue; // stop app thread app[i]->stop = true; st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) pthread_join(app[i]->thread, NULL); + if (app[i]->thread) + pthread_join(app[i]->thread, NULL); - if (app[i]->socket) close(app[i]->socket); + if (app[i]->socket) + close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/udp/usocket_server_sample.c b/app/udp/usocket_server_sample.c index 97c458701..2f5cf9e8a 100644 --- a/app/udp/usocket_server_sample.c +++ b/app/udp/usocket_server_sample.c @@ -30,7 +30,7 @@ struct usocket_server_sample_ctx { }; struct usocket_server_samples_ctx { - struct usocket_server_sample_ctx** apps; + struct usocket_server_sample_ctx **apps; int apps_cnt; bool stop; @@ -39,8 +39,8 @@ struct usocket_server_samples_ctx { pthread_mutex_t wake_mutex; }; -static void* usocket_server_thread(void* arg) { - struct usocket_server_sample_ctx* s = arg; +static void *usocket_server_thread(void *arg) { + struct usocket_server_sample_ctx *s = arg; int socket = s->socket; ssize_t usocket_len = MUDP_MAX_BYTES; char buf[usocket_len]; @@ -49,8 +49,8 @@ static void* usocket_server_thread(void* arg) { info("%s(%d), start socket %d\n", __func__, s->idx, socket); while (!s->stop) { - ssize_t recv = - recvfrom(socket, buf, sizeof(buf), 0, (struct sockaddr*)&cli_addr, &cli_addr_len); + ssize_t recv = recvfrom(socket, buf, sizeof(buf), 0, + (struct sockaddr *)&cli_addr, &cli_addr_len); if (recv < 0) { dbg("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); continue; @@ -59,8 +59,8 @@ static void* usocket_server_thread(void* arg) { s->recv_cnt_total++; s->recv_len += recv; dbg("%s(%d), recv %d bytes\n", __func__, s->idx, (int)recv); - ssize_t send = - sendto(socket, buf, recv, 0, (const struct sockaddr*)&cli_addr, cli_addr_len); + ssize_t send = sendto(socket, buf, recv, 0, + (const struct sockaddr *)&cli_addr, cli_addr_len); if (send != recv) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -73,8 +73,8 @@ static void* usocket_server_thread(void* arg) { return NULL; } -static void* usocket_server_transport_thread(void* arg) { - struct usocket_server_sample_ctx* s = arg; +static void *usocket_server_transport_thread(void *arg) { + struct usocket_server_sample_ctx *s = arg; int socket = s->socket; ssize_t usocket_len = MUDP_MAX_BYTES; char buf[usocket_len]; @@ -95,8 +95,8 @@ static void* usocket_server_transport_thread(void* arg) { return NULL; } -static void* usocket_server_transport_poll_thread(void* arg) { - struct usocket_server_sample_ctx* s = arg; +static void *usocket_server_transport_poll_thread(void *arg) { + struct usocket_server_sample_ctx *s = arg; int socket = s->socket; ssize_t usocket_len = MUDP_MAX_BYTES; char buf[usocket_len]; @@ -109,7 +109,8 @@ static void* usocket_server_transport_poll_thread(void* arg) { info("%s(%d), start socket %d\n", __func__, s->idx, socket); while (!s->stop) { int ret = poll(fds, 1, 100); - if (ret <= 0) continue; + if (ret <= 0) + continue; ssize_t recv = recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); if (recv < 0) { err("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); @@ -123,9 +124,9 @@ static void* usocket_server_transport_poll_thread(void* arg) { return NULL; } -static void* usocket_servers_poll_thread(void* arg) { - struct usocket_server_samples_ctx* ctxs = arg; - struct usocket_server_sample_ctx* s = NULL; +static void *usocket_servers_poll_thread(void *arg) { + struct usocket_server_samples_ctx *ctxs = arg; + struct usocket_server_sample_ctx *s = NULL; int apps_cnt = ctxs->apps_cnt; int socket; ssize_t usocket_len = MUDP_MAX_BYTES; @@ -142,9 +143,11 @@ static void* usocket_servers_poll_thread(void* arg) { info("%s, start at %p\n", __func__, ctxs); while (!ctxs->stop) { int ret = poll(fds, apps_cnt, 100); - if (ret <= 0) continue; + if (ret <= 0) + continue; for (int i = 0; i < apps_cnt; i++) { - if (!fds[i].revents) continue; /* pkt not ready */ + if (!fds[i].revents) + continue; /* pkt not ready */ s = ctxs->apps[i]; socket = s->socket; ssize_t recv = recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); @@ -162,31 +165,32 @@ static void* usocket_servers_poll_thread(void* arg) { return NULL; } -static void usocket_server_status(struct usocket_server_sample_ctx* s) { +static void usocket_server_status(struct usocket_server_sample_ctx *s) { uint64_t cur_ts = sample_get_monotonic_time(); double time_sec = (double)(cur_ts - s->last_stat_time) / NS_PER_S; double bps = (double)s->recv_len * 8 / time_sec; double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, s->send_cnt, - s->recv_cnt, bps_g); + info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, + s->send_cnt, s->recv_cnt, bps_g); s->send_cnt = 0; s->recv_cnt = 0; s->recv_len = 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct st_sample_context ctx; struct usocket_server_samples_ctx ctxs; int ret; memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, false, true, true); - if (ret < 0) return ret; + if (ret < 0) + return ret; uint32_t session_num = ctx.sessions; - struct usocket_server_sample_ctx* app[session_num]; + struct usocket_server_sample_ctx *app[session_num]; memset(app, 0, sizeof(app)); ctxs.apps = NULL; @@ -232,7 +236,7 @@ int main(int argc, char** argv) { else mudp_init_sockaddr(&app[i]->bind_addr, ctx.param.sip_addr[MTL_PORT_P], ctx.udp_port + i); - ret = bind(app[i]->socket, (const struct sockaddr*)&app[i]->bind_addr, + ret = bind(app[i]->socket, (const struct sockaddr *)&app[i]->bind_addr, sizeof(app[i]->bind_addr)); if (ret < 0) { err("%s(%d), bind fail %d\n", __func__, i, ret); @@ -254,9 +258,10 @@ int main(int argc, char** argv) { /* multicast addr */ mreq.imr_multiaddr.s_addr = app[i]->client_addr.sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - ret = - setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + ret = setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, + sizeof(mreq)); if (ret < 0) { err("%s(%d), join multicast fail %d\n", __func__, i, ret); goto error; @@ -265,18 +270,20 @@ int main(int argc, char** argv) { } if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT) { - ret = - pthread_create(&app[i]->thread, NULL, usocket_server_transport_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, + usocket_server_transport_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) { - ret = pthread_create(&app[i]->thread, NULL, usocket_server_transport_poll_thread, - app[i]); + ret = pthread_create(&app[i]->thread, NULL, + usocket_server_transport_poll_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL) { ctxs.apps[i] = app[i]; if ((i + 1) == session_num) { - ret = pthread_create(&ctxs.thread, NULL, usocket_servers_poll_thread, &ctxs); + ret = pthread_create(&ctxs.thread, NULL, usocket_servers_poll_thread, + &ctxs); } } else { - ret = pthread_create(&app[i]->thread, NULL, usocket_server_thread, app[i]); + ret = + pthread_create(&app[i]->thread, NULL, usocket_server_thread, app[i]); } if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); @@ -319,25 +326,30 @@ int main(int argc, char** argv) { st_pthread_mutex_lock(&ctxs.wake_mutex); st_pthread_cond_signal(&ctxs.wake_cond); st_pthread_mutex_unlock(&ctxs.wake_mutex); - if (ctxs.thread) pthread_join(ctxs.thread, NULL); + if (ctxs.thread) + pthread_join(ctxs.thread, NULL); } for (int i = 0; i < session_num; i++) { - if (!app[i]) continue; + if (!app[i]) + continue; // stop app thread app[i]->stop = true; dbg("%s(%d), stop thread\n", __func__, i); st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) pthread_join(app[i]->thread, NULL); + if (app[i]->thread) + pthread_join(app[i]->thread, NULL); - if (app[i]->socket > 0) close(app[i]->socket); + if (app[i]->socket > 0) + close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); } - if (ctxs.apps) free(ctxs.apps); + if (ctxs.apps) + free(ctxs.apps); st_pthread_mutex_destroy(&ctxs.wake_mutex); st_pthread_cond_destroy(&ctxs.wake_cond); /* release sample(st) dev */ diff --git a/app/v4l2_to_ip/v4l2_to_ip.c b/app/v4l2_to_ip/v4l2_to_ip.c index 28ac69d37..3c9de5623 100644 --- a/app/v4l2_to_ip/v4l2_to_ip.c +++ b/app/v4l2_to_ip/v4l2_to_ip.c @@ -59,7 +59,8 @@ #ifndef VIDIOC_IPU_GET_DRIVER_VERSION #define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */ -#define VIDIOC_IPU_GET_DRIVER_VERSION _IOWR('v', BASE_VIDIOC_PRIVATE + 3, uint32_t) +#define VIDIOC_IPU_GET_DRIVER_VERSION \ + _IOWR('v', BASE_VIDIOC_PRIVATE + 3, uint32_t) #endif #define V4L2_FMT_WIDTH (1920) @@ -97,7 +98,7 @@ struct tx_frame_buff { }; struct tx_frame_buff_ct { - struct tx_frame_buff* buffs; + struct tx_frame_buff *buffs; unsigned int cnt; unsigned int receive_idx; unsigned int ready_idx; @@ -108,19 +109,19 @@ struct tx_frame_buff_ct { struct st_display { int idx; - SDL_Window* window; - SDL_Renderer* renderer; - SDL_Texture* texture; + SDL_Window *window; + SDL_Renderer *renderer; + SDL_Texture *texture; SDL_PixelFormatEnum fmt; #ifdef APP_HAS_SDL2_TTF - TTF_Font* font; + TTF_Font *font; #endif SDL_Rect msg_rect; int window_w; int window_h; int pixel_w; int pixel_h; - void* front_frame; + void *front_frame; int front_frame_size; uint32_t last_time; uint32_t frame_cnt; @@ -135,14 +136,14 @@ struct st_display { struct st_v4l2_tx_video_session { int idx; - struct st_v4l2_tx_context* ctx; + struct st_v4l2_tx_context *ctx; st20_tx_handle handle; struct st20_tx_ops ops_tx; int framebuff_size; - struct st20_ext_frame* ext_frames; + struct st20_ext_frame *ext_frames; int width; int height; @@ -166,7 +167,7 @@ struct buffer { unsigned int idx; unsigned int padding[VIDEO_MAX_PLANES]; unsigned int size[VIDEO_MAX_PLANES]; - void* mem[VIDEO_MAX_PLANES]; + void *mem[VIDEO_MAX_PLANES]; }; struct device { @@ -176,7 +177,7 @@ struct device { enum v4l2_buf_type type; enum v4l2_memory memtype; unsigned int nbufs; - struct buffer* buffers; + struct buffer *buffers; unsigned int width; unsigned int height; @@ -188,7 +189,7 @@ struct device { unsigned char num_planes; struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES]; - void* pattern[VIDEO_MAX_PLANES]; + void *pattern[VIDEO_MAX_PLANES]; unsigned int patternsize[VIDEO_MAX_PLANES]; bool write_data_prefix; @@ -200,7 +201,7 @@ struct st_v4l2_tx_context { bool stop; - struct st_v4l2_tx_video_session* tx_video_sessions; + struct st_v4l2_tx_video_session *tx_video_sessions; int tx_video_session_cnt; struct device dev; @@ -225,11 +226,12 @@ static uint8_t g_tx_video_local_ip[MTL_IP_ADDR_LEN] = {192, 168, 22, 85}; /* dst ip address for tx video session */ static uint8_t g_tx_video_dst_ip[MTL_IP_ADDR_LEN] = {239, 168, 22, 85}; -static struct st_v4l2_tx_context* g_st_v4l2_tx = NULL; +static struct st_v4l2_tx_context *g_st_v4l2_tx = NULL; /*function dec*/ -int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t* cpuset); +int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, + const cpu_set_t *cpuset); /*code*/ @@ -238,22 +240,27 @@ static int video_set_realtime(pthread_t thread, int priority, int cpu) { struct sched_param sp; int err, policy; - if (priority < 0) return -1; + if (priority < 0) + return -1; err = pthread_getschedparam(thread, &policy, &sp); - if (err) return -1; + if (err) + return -1; sp.sched_priority = priority; err = pthread_setschedparam(thread, SCHED_FIFO, &sp); - if (err) return -1; + if (err) + return -1; - if (cpu < 0) return -1; + if (cpu < 0) + return -1; CPU_ZERO(&cpuset); CPU_SET(cpu, &cpuset); err = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); - if (err) return -1; + if (err) + return -1; return 0; } @@ -288,7 +295,7 @@ static int app_player_init(void) { return 0; } -static void destroy_display_context(struct st_display* d) { +static void destroy_display_context(struct st_display *d) { if (d->texture) { SDL_DestroyTexture(d->texture); d->texture = NULL; @@ -303,13 +310,13 @@ static void destroy_display_context(struct st_display* d) { } } -static int create_display_context(struct st_display* d) { +static int create_display_context(struct st_display *d) { char title[32]; sprintf(title, "v4l2-display-%d", d->idx); - d->window = - SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - d->window_w, d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + d->window = SDL_CreateWindow( + title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, d->window_w, + d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (d->window == NULL) { printf("%s, create window fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -323,8 +330,8 @@ static int create_display_context(struct st_display* d) { return -EIO; } - d->texture = SDL_CreateTexture(d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, - d->pixel_w, d->pixel_h); + d->texture = SDL_CreateTexture( + d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, d->pixel_w, d->pixel_h); if (d->texture == NULL) { printf("%s, create texture fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -334,8 +341,8 @@ static int create_display_context(struct st_display* d) { return 0; } -static void* display_thread_func(void* arg) { - struct st_display* d = arg; +static void *display_thread_func(void *arg) { + struct st_display *d = arg; int idx = d->idx; #ifdef WINDOWSENV @@ -375,8 +382,9 @@ static void* display_thread_func(void* arg) { char text[32]; sprintf(text, "FPS:\t%.2f", d->fps); SDL_Color Red = {255, 0, 0}; - SDL_Surface* surfaceMessage = TTF_RenderText_Solid(d->font, text, Red); - SDL_Texture* Message = SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); + SDL_Surface *surfaceMessage = TTF_RenderText_Solid(d->font, text, Red); + SDL_Texture *Message = + SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); SDL_RenderCopy(d->renderer, Message, NULL, &d->msg_rect); SDL_FreeSurface(surfaceMessage); @@ -387,7 +395,8 @@ static void* display_thread_func(void* arg) { SDL_RenderPresent(d->renderer); #ifdef WINDOWSENV while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) d->display_thread_stop = true; + if (event.type == SDL_QUIT) + d->display_thread_stop = true; } #endif } @@ -395,18 +404,21 @@ static void* display_thread_func(void* arg) { return NULL; } -static int display_thread_create(struct st_v4l2_tx_video_session* tx_video_session, - unsigned int priority, unsigned int cpu) { +static int +display_thread_create(struct st_v4l2_tx_video_session *tx_video_session, + unsigned int priority, unsigned int cpu) { int ret = 0; if (pthread_create(&(tx_video_session->display.display_thread), NULL, display_thread_func, &(tx_video_session->display))) { - printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), errno); + printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), + errno); ret = -EIO; return ret; } - if (video_set_realtime(tx_video_session->display.display_thread, priority, cpu) < 0) { + if (video_set_realtime(tx_video_session->display.display_thread, priority, + cpu) < 0) { printf("%s video_set_realtime Failed\n", __func__); ret = -EIO; return ret; @@ -415,9 +427,10 @@ static int display_thread_create(struct st_v4l2_tx_video_session* tx_video_sessi return ret; } -static void display_consume_frame(struct st_v4l2_tx_video_session* tx_video_session, - void* frame) { - struct st_display* display = &(tx_video_session->display); +static void +display_consume_frame(struct st_v4l2_tx_video_session *tx_video_session, + void *frame) { + struct st_display *display = &(tx_video_session->display); if (display->front_frame) { if (pthread_mutex_trylock(&display->display_frame_mutex) == 0) { @@ -431,8 +444,9 @@ static void display_consume_frame(struct st_v4l2_tx_video_session* tx_video_sess } } -static int app_uinit_display(struct st_display* d) { - if (!d) return 0; +static int app_uinit_display(struct st_display *d) { + if (!d) + return 0; int idx = d->idx; d->display_thread_stop = true; @@ -465,10 +479,11 @@ static int app_uinit_display(struct st_display* d) { return 0; } -static int app_init_display(struct st_display* d, int idx, int width, int height, - char* font) { +static int app_init_display(struct st_display *d, int idx, int width, + int height, char *font) { int ret; - if (!d) return -ENOMEM; + if (!d) + return -ENOMEM; MTL_MAY_UNUSED(font); d->idx = idx; @@ -480,7 +495,8 @@ static int app_init_display(struct st_display* d, int idx, int width, int height #ifdef APP_HAS_SDL2_TTF d->font = TTF_OpenFont(font, 40); if (!d->font) - printf("%s, open font fail, won't show info: %s\n", __func__, TTF_GetError()); + printf("%s, open font fail, won't show info: %s\n", __func__, + TTF_GetError()); #endif if (d->fmt == SDL_PIXELFORMAT_UYVY) { d->front_frame_size = width * height * 2; @@ -519,23 +535,23 @@ static int app_init_display(struct st_display* d, int idx, int width, int height /**/ -static bool video_is_mplane(struct device* dev) { +static bool video_is_mplane(struct device *dev) { return dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; } -static bool video_is_capture(struct device* dev) { +static bool video_is_capture(struct device *dev) { return dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE || dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE; } -static bool video_is_output(struct device* dev) { +static bool video_is_output(struct device *dev) { return dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE || dev->type == V4L2_BUF_TYPE_VIDEO_OUTPUT; } static struct v4l2_format_info { - const char* name; + const char *name; unsigned int fourcc; unsigned char n_planes; } pixel_formats[] = { @@ -618,23 +634,26 @@ static struct v4l2_format_info { // { "Y210", V4L2_PIX_FMT_Y210, 1 }, }; -static const struct v4l2_format_info* v4l2_format_by_fourcc(unsigned int fourcc) { +static const struct v4l2_format_info * +v4l2_format_by_fourcc(unsigned int fourcc) { unsigned int i; for (i = 0; i < ARRAY_SIZE(pixel_formats); ++i) { - if (pixel_formats[i].fourcc == fourcc) return &pixel_formats[i]; + if (pixel_formats[i].fourcc == fourcc) + return &pixel_formats[i]; } return NULL; } -static const char* v4l2_format_name(unsigned int fourcc) { - const struct v4l2_format_info* info; +static const char *v4l2_format_name(unsigned int fourcc) { + const struct v4l2_format_info *info; static char name[5]; unsigned int i; info = v4l2_format_by_fourcc(fourcc); - if (info) return info->name; + if (info) + return info->name; for (i = 0; i < 4; ++i) { name[i] = fourcc & 0xff; @@ -646,7 +665,7 @@ static const char* v4l2_format_name(unsigned int fourcc) { } static const struct { - const char* name; + const char *name; enum v4l2_field field; } fields[] = { {"any", V4L2_FIELD_ANY}, @@ -661,21 +680,22 @@ static const struct { {"interlaced-bt", V4L2_FIELD_INTERLACED_BT}, }; -static const char* v4l2_field_name(enum v4l2_field field) { +static const char *v4l2_field_name(enum v4l2_field field) { unsigned int i; for (i = 0; i < ARRAY_SIZE(fields); ++i) { - if (fields[i].field == field) return fields[i].name; + if (fields[i].field == field) + return fields[i].name; } return "unknown"; } -static void video_set_buf_type(struct device* dev, enum v4l2_buf_type type) { +static void video_set_buf_type(struct device *dev, enum v4l2_buf_type type) { dev->type = type; } -static void video_init(struct device* dev) { +static void video_init(struct device *dev) { memset(dev, 0, sizeof *dev); dev->fd = -1; dev->memtype = V4L2_MEMORY_MMAP; @@ -683,11 +703,9 @@ static void video_init(struct device* dev) { dev->type = (enum v4l2_buf_type) - 1; } -static bool video_has_fd(struct device* dev) { - return dev->fd != -1; -} +static bool video_has_fd(struct device *dev) { return dev->fd != -1; } -static int video_open(struct device* dev, const char* devname) { +static int video_open(struct device *dev, const char *devname) { if (video_has_fd(dev)) { printf("Can't open device (already open).\n"); return -1; @@ -695,7 +713,8 @@ static int video_open(struct device* dev, const char* devname) { dev->fd = open(devname, O_RDWR); if (dev->fd < 0) { - printf("Error opening device %s: %s (%d).\n", devname, strerror(errno), errno); + printf("Error opening device %s: %s (%d).\n", devname, strerror(errno), + errno); return dev->fd; } @@ -706,35 +725,40 @@ static int video_open(struct device* dev, const char* devname) { return 0; } -static int do_print_ipu_version(struct device* dev) { +static int do_print_ipu_version(struct device *dev) { unsigned int version; int ret; ret = ioctl(dev->fd, VIDIOC_IPU_GET_DRIVER_VERSION, &version); - if (ret < 0) return 0; + if (ret < 0) + return 0; printf("IPU driver version: %d.%d\n", version >> 16, version & 0xFFFF); return 0; } -static int video_querycap(struct device* dev, unsigned int* capabilities) { +static int video_querycap(struct device *dev, unsigned int *capabilities) { struct v4l2_capability cap; unsigned int caps; int ret; memset(&cap, 0, sizeof cap); ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap); - if (ret < 0) return 0; + if (ret < 0) + return 0; - caps = cap.capabilities & V4L2_CAP_DEVICE_CAPS ? cap.device_caps : cap.capabilities; + caps = cap.capabilities & V4L2_CAP_DEVICE_CAPS ? cap.device_caps + : cap.capabilities; - printf( - "Device `%s' on `%s' is a video %s (%s mplanes) device.\n", cap.card, cap.bus_info, - caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_CAPTURE) ? "capture" - : "output", - caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE) ? "with" - : "without"); + printf("Device `%s' on `%s' is a video %s (%s mplanes) device.\n", cap.card, + cap.bus_info, + caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_CAPTURE) + ? "capture" + : "output", + caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE) + ? "with" + : "without"); *capabilities = caps; @@ -758,20 +782,22 @@ static int cap_get_buf_type(unsigned int capabilities) { return 0; } -static void video_close(struct device* dev) { +static void video_close(struct device *dev) { unsigned int i; - for (i = 0; i < dev->num_planes; i++) free(dev->pattern[i]); + for (i = 0; i < dev->num_planes; i++) + free(dev->pattern[i]); free(dev->buffers); - if (dev->opened) close(dev->fd); + if (dev->opened) + close(dev->fd); } -static void video_log_status(struct device* dev) { +static void video_log_status(struct device *dev) { ioctl(dev->fd, VIDIOC_LOG_STATUS); } -static int video_get_format(struct device* dev) { +static int video_get_format(struct device *dev) { struct v4l2_format v_fmt; unsigned int i; int ret; @@ -790,10 +816,12 @@ static int video_get_format(struct device* dev) { dev->num_planes = v_fmt.fmt.pix_mp.num_planes; for (i = 0; i < v_fmt.fmt.pix_mp.num_planes; i++) { - dev->plane_fmt[i].bytesperline = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline; - dev->plane_fmt[i].sizeimage = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline - ? v_fmt.fmt.pix_mp.plane_fmt[i].sizeimage - : 0; + dev->plane_fmt[i].bytesperline = + v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline; + dev->plane_fmt[i].sizeimage = + v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline + ? v_fmt.fmt.pix_mp.plane_fmt[i].sizeimage + : 0; } } else { dev->width = v_fmt.fmt.pix.width; @@ -808,7 +836,7 @@ static int video_get_format(struct device* dev) { return 0; } -static int video_set_format(struct device* dev, unsigned int w, unsigned int h, +static int video_set_format(struct device *dev, unsigned int w, unsigned int h, unsigned int format, unsigned int stride, unsigned int buffer_size, enum v4l2_field field, unsigned int flags) { @@ -820,7 +848,7 @@ static int video_set_format(struct device* dev, unsigned int w, unsigned int h, fmt.type = dev->type; if (video_is_mplane(dev)) { - const struct v4l2_format_info* info = v4l2_format_by_fourcc(format); + const struct v4l2_format_info *info = v4l2_format_by_fourcc(format); fmt.fmt.pix_mp.width = w; fmt.fmt.pix_mp.height = h; @@ -846,17 +874,19 @@ static int video_set_format(struct device* dev, unsigned int w, unsigned int h, ret = ioctl(dev->fd, VIDIOC_S_FMT, &fmt); if (ret < 0) { - printf("Failed to configure video format: %s (%d).\n", strerror(errno), errno); + printf("Failed to configure video format: %s (%d).\n", strerror(errno), + errno); return ret; } if (video_is_mplane(dev)) { - printf( - "Video attributes, pixel format: %s (%08x), resolution: %ux%u field: %s, number " - "of planes: %u\n", - v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat, - fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height, - v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix_mp.num_planes); + printf("Video attributes, pixel format: %s (%08x), resolution: %ux%u " + "field: %s, number " + "of planes: %u\n", + v4l2_format_name(fmt.fmt.pix_mp.pixelformat), + fmt.fmt.pix_mp.pixelformat, fmt.fmt.pix_mp.width, + fmt.fmt.pix_mp.height, v4l2_field_name(fmt.fmt.pix_mp.field), + fmt.fmt.pix_mp.num_planes); for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) { printf("Plane %d attributes, stride: %u, buffer size: %u\n", i, @@ -864,19 +894,19 @@ static int video_set_format(struct device* dev, unsigned int w, unsigned int h, fmt.fmt.pix_mp.plane_fmt[i].sizeimage); } } else { - printf( - "Video attributes, pixel format: %s (%08x), resolution: %ux%u, stride: %u, " - "field: %s buffer size %u\n", - v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat, - fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline, - v4l2_field_name(fmt.fmt.pix.field), fmt.fmt.pix.sizeimage); + printf("Video attributes, pixel format: %s (%08x), resolution: %ux%u, " + "stride: %u, " + "field: %s buffer size %u\n", + v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat, + fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline, + v4l2_field_name(fmt.fmt.pix.field), fmt.fmt.pix.sizeimage); } return 0; } -static int video_buffer_mmap(struct device* dev, struct buffer* buffer, - struct v4l2_buffer* v4l2buf) { +static int video_buffer_mmap(struct device *dev, struct buffer *buffer, + struct v4l2_buffer *v4l2buf) { unsigned int length; unsigned int offset; unsigned int i; @@ -890,31 +920,33 @@ static int video_buffer_mmap(struct device* dev, struct buffer* buffer, offset = v4l2buf->m.offset; } - buffer->mem[i] = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, dev->fd, offset); + buffer->mem[i] = + mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, dev->fd, offset); if (buffer->mem[i] == MAP_FAILED) { - printf("Unable to map buffer %u/%u: %s (%d)\n", buffer->idx, i, strerror(errno), - errno); + printf("Unable to map buffer %u/%u: %s (%d)\n", buffer->idx, i, + strerror(errno), errno); return -1; } buffer->size[i] = length; buffer->padding[i] = 0; - printf("Buffer %u/%u mapped at address %p.\n", buffer->idx, i, buffer->mem[i]); + printf("Buffer %u/%u mapped at address %p.\n", buffer->idx, i, + buffer->mem[i]); } return 0; } -static int video_buffer_munmap(struct device* dev, struct buffer* buffer) { +static int video_buffer_munmap(struct device *dev, struct buffer *buffer) { unsigned int i; int ret; for (i = 0; i < dev->num_planes; i++) { ret = munmap(buffer->mem[i], buffer->size[i]); if (ret < 0) { - printf("Unable to unmap buffer %u/%u: %s (%d)\n", buffer->idx, i, strerror(errno), - errno); + printf("Unable to unmap buffer %u/%u: %s (%d)\n", buffer->idx, i, + strerror(errno), errno); } buffer->mem[i] = NULL; @@ -923,8 +955,9 @@ static int video_buffer_munmap(struct device* dev, struct buffer* buffer) { return 0; } -static int video_buffer_alloc_userptr(struct device* dev, struct buffer* buffer, - struct v4l2_buffer* v4l2buf, unsigned int offset, +static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer, + struct v4l2_buffer *v4l2buf, + unsigned int offset, unsigned int padding) { int page_size = getpagesize(); unsigned int length; @@ -937,8 +970,8 @@ static int video_buffer_alloc_userptr(struct device* dev, struct buffer* buffer, else length = v4l2buf->length; - ret = - posix_memalign(&buffer->mem[i], page_size, length + offset + padding + page_size); + ret = posix_memalign(&buffer->mem[i], page_size, + length + offset + padding + page_size); if (ret < 0) { printf("Unable to allocate buffer %u/%u (%d)\n", buffer->idx, i, ret); return -ENOMEM; @@ -948,14 +981,15 @@ static int video_buffer_alloc_userptr(struct device* dev, struct buffer* buffer, buffer->size[i] = length; buffer->padding[i] = padding; - printf("Buffer %u/%u allocated at address %p length %u page %u.\n", buffer->idx, i, - buffer->mem[i], length, page_size); + printf("Buffer %u/%u allocated at address %p length %u page %u.\n", + buffer->idx, i, buffer->mem[i], length, page_size); } return 0; } -static void video_buffer_free_userptr(struct device* dev, struct buffer* buffer) { +static void video_buffer_free_userptr(struct device *dev, + struct buffer *buffer) { unsigned int i; for (i = 0; i < dev->num_planes; i++) { @@ -964,38 +998,39 @@ static void video_buffer_free_userptr(struct device* dev, struct buffer* buffer) } } -static void get_ts_flags(uint32_t flags, const char** ts_type, const char** ts_source) { +static void get_ts_flags(uint32_t flags, const char **ts_type, + const char **ts_source) { switch (flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) { - case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN: - *ts_type = "unk"; - break; - case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC: - *ts_type = "mono"; - break; - case V4L2_BUF_FLAG_TIMESTAMP_COPY: - *ts_type = "copy"; - break; - default: - *ts_type = "inv"; + case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN: + *ts_type = "unk"; + break; + case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC: + *ts_type = "mono"; + break; + case V4L2_BUF_FLAG_TIMESTAMP_COPY: + *ts_type = "copy"; + break; + default: + *ts_type = "inv"; } switch (flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) { - case V4L2_BUF_FLAG_TSTAMP_SRC_EOF: - *ts_source = "EoF"; - break; - case V4L2_BUF_FLAG_TSTAMP_SRC_SOE: - *ts_source = "SoE"; - break; - default: - *ts_source = "inv"; + case V4L2_BUF_FLAG_TSTAMP_SRC_EOF: + *ts_source = "EoF"; + break; + case V4L2_BUF_FLAG_TSTAMP_SRC_SOE: + *ts_source = "SoE"; + break; + default: + *ts_source = "inv"; } } -static int video_alloc_buffers(struct device* dev, int nbufs, unsigned int offset, - unsigned int padding) { +static int video_alloc_buffers(struct device *dev, int nbufs, + unsigned int offset, unsigned int padding) { struct v4l2_plane planes[VIDEO_MAX_PLANES]; struct v4l2_requestbuffers rb; struct v4l2_buffer buf; - struct buffer* buffers; + struct buffer *buffers; unsigned int i; int ret; @@ -1013,7 +1048,8 @@ static int video_alloc_buffers(struct device* dev, int nbufs, unsigned int offse printf("%u buffers requested.\n", rb.count); buffers = malloc(rb.count * sizeof buffers[0]); - if (buffers == NULL) return -ENOMEM; + if (buffers == NULL) + return -ENOMEM; /* Map the buffers. */ for (i = 0; i < rb.count; ++i) { @@ -1030,7 +1066,8 @@ static int video_alloc_buffers(struct device* dev, int nbufs, unsigned int offse ret = ioctl(dev->fd, VIDIOC_QUERYBUF, &buf); if (ret < 0) { - printf("Unable to query buffer %u: %s (%d).\n", i, strerror(errno), errno); + printf("Unable to query buffer %u: %s (%d).\n", i, strerror(errno), + errno); return ret; } get_ts_flags(buf.flags, &ts_type, &ts_source); @@ -1040,19 +1077,20 @@ static int video_alloc_buffers(struct device* dev, int nbufs, unsigned int offse buffers[i].idx = i; switch (dev->memtype) { - case V4L2_MEMORY_MMAP: - ret = video_buffer_mmap(dev, &buffers[i], &buf); - break; + case V4L2_MEMORY_MMAP: + ret = video_buffer_mmap(dev, &buffers[i], &buf); + break; - case V4L2_MEMORY_USERPTR: - ret = video_buffer_alloc_userptr(dev, &buffers[i], &buf, offset, padding); - break; + case V4L2_MEMORY_USERPTR: + ret = video_buffer_alloc_userptr(dev, &buffers[i], &buf, offset, padding); + break; - default: - break; + default: + break; } - if (ret < 0) return ret; + if (ret < 0) + return ret; } dev->timestamp_type = buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK; @@ -1061,24 +1099,26 @@ static int video_alloc_buffers(struct device* dev, int nbufs, unsigned int offse return 0; } -static int video_free_buffers(struct device* dev) { +static int video_free_buffers(struct device *dev) { struct v4l2_requestbuffers rb; unsigned int i; int ret; - if (dev->nbufs == 0) return 0; + if (dev->nbufs == 0) + return 0; for (i = 0; i < dev->nbufs; ++i) { switch (dev->memtype) { - case V4L2_MEMORY_MMAP: - ret = video_buffer_munmap(dev, &dev->buffers[i]); - if (ret < 0) return ret; - break; - case V4L2_MEMORY_USERPTR: - video_buffer_free_userptr(dev, &dev->buffers[i]); - break; - default: - break; + case V4L2_MEMORY_MMAP: + ret = video_buffer_munmap(dev, &dev->buffers[i]); + if (ret < 0) + return ret; + break; + case V4L2_MEMORY_USERPTR: + video_buffer_free_userptr(dev, &dev->buffers[i]); + break; + default: + break; } } @@ -1102,7 +1142,8 @@ static int video_free_buffers(struct device* dev) { return 0; } -static int video_queue_buffer(struct device* dev, int index, enum buffer_fill_mode fill) { +static int video_queue_buffer(struct device *dev, int index, + enum buffer_fill_mode fill) { struct v4l2_buffer buf; struct v4l2_plane planes[VIDEO_MAX_PLANES]; int ret; @@ -1152,23 +1193,26 @@ static int video_queue_buffer(struct device* dev, int index, enum buffer_fill_mo else buf.bytesused = dev->patternsize[i]; - memcpy(dev->buffers[buf.index].mem[i], dev->pattern[i], dev->patternsize[i]); + memcpy(dev->buffers[buf.index].mem[i], dev->pattern[i], + dev->patternsize[i]); } else { if (fill & BUFFER_FILL_FRAME) - memset(dev->buffers[buf.index].mem[i], 0x55, dev->buffers[index].size[i]); + memset(dev->buffers[buf.index].mem[i], 0x55, + dev->buffers[index].size[i]); if (fill & BUFFER_FILL_PADDING) - memset(dev->buffers[buf.index].mem[i] + dev->buffers[index].size[i], 0x55, - dev->buffers[index].padding[i]); + memset(dev->buffers[buf.index].mem[i] + dev->buffers[index].size[i], + 0x55, dev->buffers[index].padding[i]); } } ret = ioctl(dev->fd, VIDIOC_QBUF, &buf); - if (ret < 0) printf("Unable to queue buffer: %s (%d).\n", strerror(errno), errno); + if (ret < 0) + printf("Unable to queue buffer: %s (%d).\n", strerror(errno), errno); return ret; } -static int video_enable(struct device* dev, int enable) { +static int video_enable(struct device *dev, int enable) { int type = dev->type; int ret; @@ -1182,7 +1226,7 @@ static int video_enable(struct device* dev, int enable) { return 0; } -static int video_load_test_pattern(struct device* dev, const char* filename) { +static int video_load_test_pattern(struct device *dev, const char *filename) { unsigned int plane; unsigned int size; int fd = -1; @@ -1209,25 +1253,27 @@ static int video_load_test_pattern(struct device* dev, const char* filename) { if (filename != NULL) { ret = read(fd, dev->pattern[plane], size); if (ret != (int)size && dev->plane_fmt[plane].bytesperline != 0) { - printf("Test pattern file size %u doesn't match image size %u\n", ret, size); + printf("Test pattern file size %u doesn't match image size %u\n", ret, + size); ret = -EINVAL; goto done; } } else { - uint8_t* data = dev->pattern[plane]; + uint8_t *data = dev->pattern[plane]; unsigned int i; if (dev->plane_fmt[plane].bytesperline == 0) { - printf( - "Compressed format detected for plane %u and no test pattern filename " - "given.\n" - "The test pattern can't be generated automatically.\n", - plane); + printf("Compressed format detected for plane %u and no test pattern " + "filename " + "given.\n" + "The test pattern can't be generated automatically.\n", + plane); ret = -EINVAL; goto done; } - for (i = 0; i < dev->plane_fmt[plane].sizeimage; ++i) *data++ = i; + for (i = 0; i < dev->plane_fmt[plane].sizeimage; ++i) + *data++ = i; } dev->patternsize[plane] = size; @@ -1236,36 +1282,42 @@ static int video_load_test_pattern(struct device* dev, const char* filename) { ret = 0; done: - if (fd != -1) close(fd); + if (fd != -1) + close(fd); return ret; } -static int video_prepare_capture(struct device* dev, int nbufs, unsigned int offset, - const char* filename, enum buffer_fill_mode fill) { +static int video_prepare_capture(struct device *dev, int nbufs, + unsigned int offset, const char *filename, + enum buffer_fill_mode fill) { unsigned int padding; int ret; /* Allocate and map buffers. */ padding = (fill & BUFFER_FILL_PADDING) ? 4096 : 0; - if ((ret = video_alloc_buffers(dev, nbufs, offset, padding)) < 0) return ret; + if ((ret = video_alloc_buffers(dev, nbufs, offset, padding)) < 0) + return ret; if (video_is_output(dev)) { ret = video_load_test_pattern(dev, filename); - if (ret < 0) return ret; + if (ret < 0) + return ret; } return 0; } -static int video_queue_all_buffers(struct device* dev, enum buffer_fill_mode fill) { +static int video_queue_all_buffers(struct device *dev, + enum buffer_fill_mode fill) { unsigned int i; int ret; /* Queue the buffers. */ for (i = 0; i < dev->nbufs; ++i) { ret = video_queue_buffer(dev, i, fill); - if (ret < 0) return ret; + if (ret < 0) + return ret; } return 0; @@ -1273,19 +1325,21 @@ static int video_queue_all_buffers(struct device* dev, enum buffer_fill_mode fil /*st20 s*/ -static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct st_v4l2_tx_video_session* tx_video_session = priv; - struct tx_frame_buff_ct* framebuff_ctl = &(tx_video_session->framebuff_ctl); +static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct st_v4l2_tx_video_session *tx_video_session = priv; + struct tx_frame_buff_ct *framebuff_ctl = &(tx_video_session->framebuff_ctl); int ret; MTL_MAY_UNUSED(meta); pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); - if (TX_FRAME_READY == framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status) { + if (TX_FRAME_READY == + framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status) { // printf("%s(%d), next frame idx %u\n", __func__, s->idx, consumer_idx); ret = 0; - framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status = TX_FRAME_TRANSMITTING; + framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status = + TX_FRAME_TRANSMITTING; *next_frame_idx = framebuff_ctl->transmit_idx; clock_gettime(CLOCK_MONOTONIC, @@ -1306,24 +1360,25 @@ static int tx_video_next_frame(void* priv, uint16_t* next_frame_idx, return ret; } -static int tx_video_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - struct st_v4l2_tx_video_session* tx_video_session = priv; - struct st_v4l2_tx_context* st_v4l2_tx = tx_video_session->ctx; - struct tx_frame_buff_ct* framebuff_ctl = &(tx_video_session->framebuff_ctl); +static int tx_video_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct st_v4l2_tx_video_session *tx_video_session = priv; + struct st_v4l2_tx_context *st_v4l2_tx = tx_video_session->ctx; + struct tx_frame_buff_ct *framebuff_ctl = &(tx_video_session->framebuff_ctl); int ret; MTL_MAY_UNUSED(meta); if (frame_idx != framebuff_ctl->receive_idx) { ret = -EIO; - printf("%s, receive_idx %d != frame_done %d\n", __func__, framebuff_ctl->receive_idx, - frame_idx); + printf("%s, receive_idx %d != frame_done %d\n", __func__, + framebuff_ctl->receive_idx, frame_idx); return ret; } pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); - if (TX_FRAME_TRANSMITTING != framebuff_ctl->buffs[framebuff_ctl->receive_idx].status) { + if (TX_FRAME_TRANSMITTING != + framebuff_ctl->buffs[framebuff_ctl->receive_idx].status) { ret = -EIO; printf("%s, receive status %d != TRASNSMIT\n", __func__, framebuff_ctl->buffs[framebuff_ctl->receive_idx].status); @@ -1344,7 +1399,8 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, tx_video_session->st20_frame_done_cnt++; - ret = video_queue_buffer(&(st_v4l2_tx->dev), frame_idx, st_v4l2_tx->fill_mode); + ret = + video_queue_buffer(&(st_v4l2_tx->dev), frame_idx, st_v4l2_tx->fill_mode); if (ret < 0) { printf("%s Unable to requeue buffer: %d\n", __func__, ret); } @@ -1353,7 +1409,8 @@ static int tx_video_frame_done(void* priv, uint16_t frame_idx, } static void tx_video_debug_output(void) { - struct st_v4l2_tx_video_session* tx_video_session = g_st_v4l2_tx->tx_video_sessions; + struct st_v4l2_tx_video_session *tx_video_session = + g_st_v4l2_tx->tx_video_sessions; for (int i = 0; i < tx_video_session->framebuff_ctl.cnt; i++) { printf("time %ld.%06ld %ld.%06ld %ld.%06ld\n", @@ -1377,22 +1434,23 @@ static void tx_video_sig_handler(int signo) { printf("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - if (g_st_v4l2_tx->st) { - mtl_abort(g_st_v4l2_tx->st); - } - g_st_v4l2_tx->stop = true; + case SIGINT: /* Interrupt from keyboard */ + if (g_st_v4l2_tx->st) { + mtl_abort(g_st_v4l2_tx->st); + } + g_st_v4l2_tx->stop = true; - tx_video_debug_output(); + tx_video_debug_output(); - break; + break; } } -static int tx_video_verify_buffer(struct st_v4l2_tx_video_session* tx_video_session, - struct v4l2_buffer* buf) { - struct st_v4l2_tx_context* st_v4l2_tx = tx_video_session->ctx; - struct device* dev = &(st_v4l2_tx->dev); +static int +tx_video_verify_buffer(struct st_v4l2_tx_video_session *tx_video_session, + struct v4l2_buffer *buf) { + struct st_v4l2_tx_context *st_v4l2_tx = tx_video_session->ctx; + struct device *dev = &(st_v4l2_tx->dev); unsigned int length; if (0 != buf->m.planes[0].data_offset) { @@ -1408,7 +1466,8 @@ static int tx_video_verify_buffer(struct st_v4l2_tx_video_session* tx_video_sess return -1; } - if (dev->plane_fmt[0].sizeimage != (length + dev->plane_fmt[0].bytesperline)) { + if (dev->plane_fmt[0].sizeimage != + (length + dev->plane_fmt[0].bytesperline)) { printf("%s bytes used %u != image size %u\n", __func__, length, dev->plane_fmt[0].sizeimage); return -1; @@ -1419,24 +1478,27 @@ static int tx_video_verify_buffer(struct st_v4l2_tx_video_session* tx_video_sess return 0; } -static int tx_video_copy_frame(struct st_v4l2_tx_video_session* tx_video_session, - struct v4l2_buffer* buf) { - struct st_v4l2_tx_context* st_v4l2_tx = tx_video_session->ctx; - struct device* dev = &(st_v4l2_tx->dev); - struct tx_frame_buff_ct* framebuff_ctl = &(tx_video_session->framebuff_ctl); - void* frame_addr; +static int +tx_video_copy_frame(struct st_v4l2_tx_video_session *tx_video_session, + struct v4l2_buffer *buf) { + struct st_v4l2_tx_context *st_v4l2_tx = tx_video_session->ctx; + struct device *dev = &(st_v4l2_tx->dev); + struct tx_frame_buff_ct *framebuff_ctl = &(tx_video_session->framebuff_ctl); + void *frame_addr; unsigned int i; - void* data = NULL; + void *data = NULL; unsigned int length = 0; pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); if (buf->index != framebuff_ctl->ready_idx) { /* out of order*/ - printf("%s(%d), ready idx out of order\n", __func__, framebuff_ctl->ready_idx); + printf("%s(%d), ready idx out of order\n", __func__, + framebuff_ctl->ready_idx); pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); return -1; } - if (TX_FRAME_RECEIVING != framebuff_ctl->buffs[framebuff_ctl->ready_idx].status) { + if (TX_FRAME_RECEIVING != + framebuff_ctl->buffs[framebuff_ctl->ready_idx].status) { /* buff full */ printf("%s(%d), buff full\n", __func__, framebuff_ctl->ready_idx); pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); @@ -1445,15 +1507,16 @@ static int tx_video_copy_frame(struct st_v4l2_tx_video_session* tx_video_session pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); if (tx_video_session->ops_tx.flags & ST20_TX_FLAG_EXT_FRAME) { - st20_tx_set_ext_frame(tx_video_session->handle, framebuff_ctl->ready_idx, - &tx_video_session->ext_frames[framebuff_ctl->ready_idx]); + st20_tx_set_ext_frame( + tx_video_session->handle, framebuff_ctl->ready_idx, + &tx_video_session->ext_frames[framebuff_ctl->ready_idx]); display_consume_frame( tx_video_session, tx_video_session->ext_frames[framebuff_ctl->ready_idx].buf_addr); } else { - frame_addr = - st20_tx_get_framebuffer(tx_video_session->handle, framebuff_ctl->ready_idx); + frame_addr = st20_tx_get_framebuffer(tx_video_session->handle, + framebuff_ctl->ready_idx); for (i = 0; i < dev->num_planes; i++) { data = dev->buffers[buf->index].mem[i]; @@ -1469,16 +1532,19 @@ static int tx_video_copy_frame(struct st_v4l2_tx_video_session* tx_video_session } } - if (data) memcpy(frame_addr, data, length); + if (data) + memcpy(frame_addr, data, length); } pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); framebuff_ctl->buffs[framebuff_ctl->ready_idx].status = TX_FRAME_READY; - framebuff_ctl->buffs[framebuff_ctl->ready_idx].size = tx_video_session->framebuff_size; + framebuff_ctl->buffs[framebuff_ctl->ready_idx].size = + tx_video_session->framebuff_size; clock_gettime(CLOCK_MONOTONIC, &(framebuff_ctl->buffs[framebuff_ctl->ready_idx].app_ts)); - framebuff_ctl->buffs[framebuff_ctl->ready_idx].v4l2_ts.tv_sec = buf->timestamp.tv_sec; + framebuff_ctl->buffs[framebuff_ctl->ready_idx].v4l2_ts.tv_sec = + buf->timestamp.tv_sec; framebuff_ctl->buffs[framebuff_ctl->ready_idx].v4l2_ts.tv_nsec = buf->timestamp.tv_usec * 1000; framebuff_ctl->buffs[framebuff_ctl->ready_idx].st20_ts.tv_sec = 0; @@ -1496,12 +1562,12 @@ static int tx_video_copy_frame(struct st_v4l2_tx_video_session* tx_video_session /*st20 e*/ -static void* tx_video_thread_capture(void* arg) { +static void *tx_video_thread_capture(void *arg) { int ret = 0; - struct st_v4l2_tx_video_session* tx_video_session = - (struct st_v4l2_tx_video_session*)arg; - struct st_v4l2_tx_context* st_v4l2_tx = tx_video_session->ctx; - struct tx_frame_buff_ct* framebuff_ctl = &(tx_video_session->framebuff_ctl); + struct st_v4l2_tx_video_session *tx_video_session = + (struct st_v4l2_tx_video_session *)arg; + struct st_v4l2_tx_context *st_v4l2_tx = tx_video_session->ctx; + struct tx_frame_buff_ct *framebuff_ctl = &(tx_video_session->framebuff_ctl); struct v4l2_plane planes[VIDEO_MAX_PLANES]; struct v4l2_buffer buf; @@ -1528,7 +1594,8 @@ static void* tx_video_thread_capture(void* arg) { ret = ioctl(st_v4l2_tx->dev.fd, VIDIOC_DQBUF, &buf); if (ret < 0) { - printf("%s Unable to dequeue buffer: %s (%d).\n", __func__, strerror(errno), errno); + printf("%s Unable to dequeue buffer: %s (%d).\n", __func__, + strerror(errno), errno); break; } @@ -1538,14 +1605,14 @@ static void* tx_video_thread_capture(void* arg) { break; } - fps = (buf.timestamp.tv_sec - last.tv_sec) * 1000000 + buf.timestamp.tv_usec - - last.tv_usec; + fps = (buf.timestamp.tv_sec - last.tv_sec) * 1000000 + + buf.timestamp.tv_usec - last.tv_usec; fps = fps ? 1000000.0 / fps : 0.0; /* printf("%u (%u) [%c] %s %u %u %ld.%06ld %.3f fps \n", i, buf.index, - (buf.flags & V4L2_BUF_FLAG_ERROR) ? 'E' : '-', v4l2_field_name(buf.field), - buf.sequence, buf.m.planes[0].bytesused, buf.timestamp.tv_sec, - buf.timestamp.tv_usec, fps); + (buf.flags & V4L2_BUF_FLAG_ERROR) ? 'E' : '-', + v4l2_field_name(buf.field), buf.sequence, buf.m.planes[0].bytesused, + buf.timestamp.tv_sec, buf.timestamp.tv_usec, fps); */ last = buf.timestamp; @@ -1560,13 +1627,15 @@ static void* tx_video_thread_capture(void* arg) { pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); if (buf.index != framebuff_ctl->ready_idx) { /* out of order*/ - printf("%s(%d), ready idx out of order\n", __func__, framebuff_ctl->ready_idx); + printf("%s(%d), ready idx out of order\n", __func__, + framebuff_ctl->ready_idx); pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); ret = -1; break; } - framebuff_ctl->buffs[framebuff_ctl->ready_idx].status = TX_FRAME_RECEIVING; + framebuff_ctl->buffs[framebuff_ctl->ready_idx].status = + TX_FRAME_RECEIVING; framebuff_ctl->ready_idx++; if (framebuff_ctl->ready_idx >= framebuff_ctl->cnt) { framebuff_ctl->ready_idx = 0; @@ -1575,7 +1644,8 @@ static void* tx_video_thread_capture(void* arg) { framebuff_ctl->transmit_idx = framebuff_ctl->ready_idx; pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); - ret = video_queue_buffer(&(st_v4l2_tx->dev), buf.index, st_v4l2_tx->fill_mode); + ret = video_queue_buffer(&(st_v4l2_tx->dev), buf.index, + st_v4l2_tx->fill_mode); if (ret < 0) { printf("%s Unable to requeue buffer: %d\n", __func__, ret); break; @@ -1595,18 +1665,21 @@ static void* tx_video_thread_capture(void* arg) { return NULL; } -static int tx_video_thread_create(struct st_v4l2_tx_video_session* tx_video_session, - unsigned int priority, unsigned int cpu) { +static int +tx_video_thread_create(struct st_v4l2_tx_video_session *tx_video_session, + unsigned int priority, unsigned int cpu) { int ret = 0; - if (pthread_create(&(tx_video_session->st20_app_thread), NULL, tx_video_thread_capture, - tx_video_session)) { - printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), errno); + if (pthread_create(&(tx_video_session->st20_app_thread), NULL, + tx_video_thread_capture, tx_video_session)) { + printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), + errno); ret = -EIO; return ret; } - if (video_set_realtime(tx_video_session->st20_app_thread, priority, cpu) < 0) { + if (video_set_realtime(tx_video_session->st20_app_thread, priority, cpu) < + 0) { printf("%s video_set_realtime Failed\n", __func__); ret = -EIO; return ret; @@ -1615,7 +1688,7 @@ static int tx_video_thread_create(struct st_v4l2_tx_video_session* tx_video_sess return ret; } -static void usage(const char* argv0) { +static void usage(const char *argv0) { printf("Usage: %s [options] device\n", argv0); printf("Supported options:\n"); printf("-h, --help Show this help screen\n"); @@ -1642,9 +1715,9 @@ static struct option opts[] = {{"capture", 1, 0, 'c'}, {"log-status", 0, 0, OPT_LOG_STATUS}, {0, 0, 0, 0}}; -int main(int argc, char* argv[]) { - struct st_v4l2_tx_context* st_v4l2_tx; - struct st_v4l2_tx_video_session* tx_video_session; +int main(int argc, char *argv[]) { + struct st_v4l2_tx_context *st_v4l2_tx; + struct st_v4l2_tx_video_session *tx_video_session; int ret; @@ -1669,7 +1742,7 @@ int main(int argc, char* argv[]) { /* Capture loop */ enum buffer_fill_mode fill_mode = BUFFER_FILL_NONE; unsigned int nframes = (unsigned int)-1; - const char* filename = NULL; + const char *filename = NULL; unsigned int v4l2_thread_priority = 90; unsigned int v4l2_thread_cpu = V4L2_TX_THREAD_CORE; @@ -1680,7 +1753,7 @@ int main(int argc, char* argv[]) { /*st20 s*/ unsigned int session_num = 1; char port[] = TX_VIDEO_PORT_BDF; - char* tx_lcore = TX_VIDEO_LCORE; + char *tx_lcore = TX_VIDEO_LCORE; enum st_fps tx_fps = ST_FPS_P50; char dst_mac[] = TX_VIDEO_DST_MAC_ADDR; @@ -1690,51 +1763,53 @@ int main(int argc, char* argv[]) { opterr = 0; while ((c = getopt_long(argc, argv, "c::hn::p:m:se", opts, NULL)) != -1) { switch (c) { - case 'c': - nframes = atoi(optarg); - break; + case 'c': + nframes = atoi(optarg); + break; - case 'h': - usage(argv[0]); - return 0; + case 'h': + usage(argv[0]); + return 0; - case 'n': - nbufs = atoi(optarg); - if (nbufs > V4L_BUFFERS_MAX) nbufs = V4L_BUFFERS_MAX; - break; + case 'n': + nbufs = atoi(optarg); + if (nbufs > V4L_BUFFERS_MAX) + nbufs = V4L_BUFFERS_MAX; + break; - case 'p': - strcpy(port, optarg); - break; + case 'p': + strcpy(port, optarg); + break; - case 'm': - strcpy(dst_mac, optarg); - break; + case 'm': + strcpy(dst_mac, optarg); + break; - case 's': - show = true; - break; + case 's': + show = true; + break; - case 'e': - ptp = true; - break; + case 'e': + ptp = true; + break; - case 't': - tsn = true; - break; + case 't': + tsn = true; + break; - case OPT_LOG_STATUS: - do_log_status = 1; - break; + case OPT_LOG_STATUS: + do_log_status = 1; + break; - default: - printf("%s Invalid option -%c\n", __func__, c); - printf("%s Run %s -h for help.\n", __func__, argv[0]); - return 1; + default: + printf("%s Invalid option -%c\n", __func__, c); + printf("%s Run %s -h for help.\n", __func__, argv[0]); + return 1; } } - st_v4l2_tx = (struct st_v4l2_tx_context*)malloc(sizeof(struct st_v4l2_tx_context)); + st_v4l2_tx = + (struct st_v4l2_tx_context *)malloc(sizeof(struct st_v4l2_tx_context)); if (!st_v4l2_tx) { printf("%s struct application malloc fail\n", __func__); return -EIO; @@ -1792,8 +1867,8 @@ int main(int argc, char* argv[]) { video_log_status(&(st_v4l2_tx->dev)); } - if (video_set_format(&(st_v4l2_tx->dev), width, height, V4L2_PIX_FMT_UYVY, 0, 0, - V4L2_FIELD_ANY, 0) < 0) { + if (video_set_format(&(st_v4l2_tx->dev), width, height, V4L2_PIX_FMT_UYVY, 0, + 0, V4L2_FIELD_ANY, 0) < 0) { video_close(&(st_v4l2_tx->dev)); free(st_v4l2_tx); return -EIO; @@ -1836,9 +1911,10 @@ int main(int argc, char* argv[]) { st_v4l2_tx->param.num_ports = 1; st_v4l2_tx->param.pmd[MTL_PORT_P] = TX_VIDEO_PMD; strncpy(st_v4l2_tx->param.port[MTL_PORT_P], port, MTL_PORT_MAX_LEN); - memcpy(st_v4l2_tx->param.sip_addr[MTL_PORT_P], g_tx_video_local_ip, MTL_IP_ADDR_LEN); + memcpy(st_v4l2_tx->param.sip_addr[MTL_PORT_P], g_tx_video_local_ip, + MTL_IP_ADDR_LEN); st_v4l2_tx->param.flags = - MTL_FLAG_BIND_NUMA | MTL_FLAG_TX_VIDEO_MIGRATE; // default bind to numa + MTL_FLAG_BIND_NUMA | MTL_FLAG_TX_VIDEO_MIGRATE; // default bind to numa if (ptp == true) { st_v4l2_tx->param.flags |= MTL_FLAG_PTP_ENABLE; } @@ -1849,8 +1925,9 @@ int main(int argc, char* argv[]) { } else { st_v4l2_tx->param.pacing = ST21_TX_PACING_WAY_AUTO; } - st_v4l2_tx->param.log_level = MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING - st_v4l2_tx->param.priv = NULL; // usr ctx pointer + st_v4l2_tx->param.log_level = + MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING + st_v4l2_tx->param.priv = NULL; // usr ctx pointer // if not registed, the internal ptp source will be used st_v4l2_tx->param.ptp_get_time_fn = NULL; st_v4l2_tx->param.tx_queues_cnt[0] = session_num; @@ -1868,17 +1945,19 @@ int main(int argc, char* argv[]) { return -EIO; } - tx_video_session = (struct st_v4l2_tx_video_session*)malloc( + tx_video_session = (struct st_v4l2_tx_video_session *)malloc( sizeof(struct st_v4l2_tx_video_session) * session_num); if (!tx_video_session) { - printf("%s struct st_v4l2_tx_video_session is not correctly malloc", __func__); + printf("%s struct st_v4l2_tx_video_session is not correctly malloc", + __func__); mtl_uninit(st_v4l2_tx->st); video_free_buffers(&(st_v4l2_tx->dev)); video_close(&(st_v4l2_tx->dev)); free(st_v4l2_tx); return -EIO; } - memset(tx_video_session, 0, sizeof(struct st_v4l2_tx_video_session) * session_num); + memset(tx_video_session, 0, + sizeof(struct st_v4l2_tx_video_session) * session_num); if (show) { ret = app_player_init(); @@ -1906,7 +1985,7 @@ int main(int argc, char* argv[]) { tx_video_session->framebuff_ctl.receive_idx = 0; tx_video_session->framebuff_ctl.transmit_idx = 0; tx_video_session->framebuff_ctl.buffs = - (struct tx_frame_buff*)malloc(sizeof(struct tx_frame_buff) * nbufs); + (struct tx_frame_buff *)malloc(sizeof(struct tx_frame_buff) * nbufs); if (!tx_video_session->framebuff_ctl.buffs) { printf("%s[%d], tx_frame_buffs malloc fail\n", __func__, i); ret = -ENOMEM; @@ -1922,7 +2001,8 @@ int main(int argc, char* argv[]) { // init ops tx_video_session->ops_tx.name = "v4l2_st20_tx"; - tx_video_session->ops_tx.priv = tx_video_session; // app handle register to lib + tx_video_session->ops_tx.priv = + tx_video_session; // app handle register to lib tx_video_session->ops_tx.num_port = 1; // tx src ip like 239.0.0.1 @@ -1935,7 +2015,8 @@ int main(int argc, char* argv[]) { tx_video_session->ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; } - tx_video_session->ops_tx.udp_port[MTL_PORT_P] = TX_VIDEO_UDP_PORT + i; // udp port + tx_video_session->ops_tx.udp_port[MTL_PORT_P] = + TX_VIDEO_UDP_PORT + i; // udp port tx_video_session->ops_tx.pacing = ST21_PACING_NARROW; tx_video_session->ops_tx.type = ST20_TYPE_FRAME_LEVEL; tx_video_session->ops_tx.width = st_v4l2_tx->dev.width; @@ -1964,7 +2045,8 @@ int main(int argc, char* argv[]) { if (tx_video_session->ops_tx.flags & ST20_TX_FLAG_EXT_FRAME) { if (st_v4l2_tx->dev.buffers->size[0] < tx_video_session->framebuff_size) { printf("%s[%d] buffers->size %d < framebuff_size %d\n", __func__, i, - st_v4l2_tx->dev.buffers->size[0], tx_video_session->framebuff_size); + st_v4l2_tx->dev.buffers->size[0], + tx_video_session->framebuff_size); ret = -EIO; goto error; } @@ -1976,17 +2058,19 @@ int main(int argc, char* argv[]) { goto error; } - tx_video_session->ext_frames = - (struct st20_ext_frame*)malloc(sizeof(struct st20_ext_frame) * nbufs); + tx_video_session->ext_frames = (struct st20_ext_frame *)malloc( + sizeof(struct st20_ext_frame) * nbufs); if (!tx_video_session->ext_frames) { printf("%s[%d], ext_frames malloc fail\n", __func__, i); ret = -EIO; goto error; } - memset(tx_video_session->ext_frames, 0, sizeof(struct st20_ext_frame) * nbufs); + memset(tx_video_session->ext_frames, 0, + sizeof(struct st20_ext_frame) * nbufs); for (int j = 0; j < nbufs; ++j) { - tx_video_session->ext_frames[j].buf_addr = st_v4l2_tx->dev.buffers[j].mem[0]; + tx_video_session->ext_frames[j].buf_addr = + st_v4l2_tx->dev.buffers[j].mem[0]; pg_size = mtl_page_size(st_v4l2_tx->st); map_size = tx_video_session->framebuff_size; map_size += (pg_size - tx_video_session->framebuff_size % pg_size); @@ -2002,8 +2086,9 @@ int main(int argc, char* argv[]) { } if (st_v4l2_tx->has_sdl) { - ret = app_init_display(&(tx_video_session->display), i, st_v4l2_tx->dev.width, - st_v4l2_tx->dev.height, st_v4l2_tx->ttf_file); + ret = app_init_display(&(tx_video_session->display), i, + st_v4l2_tx->dev.width, st_v4l2_tx->dev.height, + st_v4l2_tx->ttf_file); if (ret < 0) { printf("%s(%d), app_init_display fail %d\n", __func__, i, ret); goto error; @@ -2035,7 +2120,8 @@ int main(int argc, char* argv[]) { /*task create*/ for (int i = 0; i < session_num; i++) { tx_video_session = &(st_v4l2_tx->tx_video_sessions[i]); - ret = tx_video_thread_create(tx_video_session, v4l2_thread_priority, v4l2_thread_cpu); + ret = tx_video_thread_create(tx_video_session, v4l2_thread_priority, + v4l2_thread_cpu); if (ret < 0) { printf("%s video thread create fail %d.\n", __func__, ret); goto error; @@ -2089,7 +2175,8 @@ int main(int argc, char* argv[]) { for (int j = 0; j < nbufs; ++j) { if ((tx_video_session->ext_frames[j].buf_iova != MTL_BAD_IOVA) && (tx_video_session->ext_frames[j].buf_iova != 0)) { - ret = mtl_dma_unmap(st_v4l2_tx->st, tx_video_session->ext_frames[j].buf_addr, + ret = mtl_dma_unmap(st_v4l2_tx->st, + tx_video_session->ext_frames[j].buf_addr, tx_video_session->ext_frames[j].buf_iova, tx_video_session->ext_frames[j].buf_len); if (0 != ret) { diff --git a/ecosystem/ffmpeg_plugin/mtl_common.c b/ecosystem/ffmpeg_plugin/mtl_common.c index adc1a5ebd..32af160de 100644 --- a/ecosystem/ffmpeg_plugin/mtl_common.c +++ b/ecosystem/ffmpeg_plugin/mtl_common.c @@ -28,28 +28,31 @@ enum st_fps framerate_to_st_fps(AVRational framerate) { return st_frame_rate_to_st_fps(fps); } -mtl_handle mtl_dev_get(AVFormatContext* ctx, const struct StDevArgs* args, int* idx) { +mtl_handle mtl_dev_get(AVFormatContext *ctx, const struct StDevArgs *args, + int *idx) { struct mtl_init_params p; mtl_handle handle = NULL; if (g_mtl_shared_handle) { *idx = g_mtl_ref_cnt; g_mtl_ref_cnt++; - info(ctx, "%s, shared handle %p ref cnt %d\n", __func__, g_mtl_shared_handle, - g_mtl_ref_cnt); + info(ctx, "%s, shared handle %p ref cnt %d\n", __func__, + g_mtl_shared_handle, g_mtl_ref_cnt); return g_mtl_shared_handle; } memset(&p, 0, sizeof(p)); for (int i = 0; i < MTL_PORT_MAX; i++) { - if (!args->port[i]) break; + if (!args->port[i]) + break; snprintf(p.port[i], sizeof(p.port[i]), "%s", args->port[i]); p.pmd[i] = mtl_pmd_by_port_name(p.port[i]); if (args->sip[i]) { int ret = inet_pton(AF_INET, args->sip[i], p.sip_addr[i]); if (ret != 1) { - err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, args->sip[i]); + err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, + args->sip[i]); return NULL; } } @@ -62,11 +65,11 @@ mtl_handle mtl_dev_get(AVFormatContext* ctx, const struct StDevArgs* args, int* p.flags |= MTL_FLAG_RX_VIDEO_MIGRATE; p.flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; p.flags |= MTL_FLAG_BIND_NUMA; - p.log_level = MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING + p.log_level = MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING if (args->dma_dev) { char devs[128] = {0}; - char* next_dev; + char *next_dev; snprintf(devs, sizeof(devs), "%s", args->dma_dev); @@ -93,7 +96,7 @@ mtl_handle mtl_dev_get(AVFormatContext* ctx, const struct StDevArgs* args, int* return handle; } -int mtl_instance_put(AVFormatContext* ctx, mtl_handle handle) { +int mtl_instance_put(AVFormatContext *ctx, mtl_handle handle) { if (handle != g_mtl_shared_handle) { err(ctx, "%s, error handle %p %p\n", __func__, handle, g_mtl_shared_handle); return AVERROR(EIO); @@ -110,18 +113,21 @@ int mtl_instance_put(AVFormatContext* ctx, mtl_handle handle) { return 0; } -int mtl_parse_rx_port(AVFormatContext* ctx, const struct StDevArgs* devArgs, - const StRxSessionPortArgs* args, struct st_rx_port* port) { +int mtl_parse_rx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, + const StRxSessionPortArgs *args, + struct st_rx_port *port) { for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { /* if no special port in StRxSessionPortArgs, get from StDevArgs */ - if (!args->port[i] && !devArgs->port[i]) break; + if (!args->port[i] && !devArgs->port[i]) + break; dbg(ctx, "%s, port on %d\n", __func__, i); snprintf(port->port[i], sizeof(port->port[i]), "%s", args->port[i] ? args->port[i] : devArgs->port[i]); if (args->sip[i]) { int ret = inet_pton(AF_INET, args->sip[i], port->ip_addr[i]); if (ret != 1) { - err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, args->sip[i]); + err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, + args->sip[i]); return AVERROR(EINVAL); } } @@ -141,18 +147,21 @@ int mtl_parse_rx_port(AVFormatContext* ctx, const struct StDevArgs* devArgs, return 0; } -int mtl_parse_tx_port(AVFormatContext* ctx, const struct StDevArgs* devArgs, - const StTxSessionPortArgs* args, struct st_tx_port* port) { +int mtl_parse_tx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, + const StTxSessionPortArgs *args, + struct st_tx_port *port) { for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { /* if no special port in StTxSessionPortArgs, get from StDevArgs */ - if (!args->port[i] && !devArgs->port[i]) break; + if (!args->port[i] && !devArgs->port[i]) + break; dbg(ctx, "%s, port on %d\n", __func__, i); snprintf(port->port[i], sizeof(port->port[i]), "%s", args->port[i] ? args->port[i] : devArgs->port[i]); if (args->dip[i]) { int ret = inet_pton(AF_INET, args->dip[i], port->dip_addr[i]); if (ret != 1) { - err(ctx, "%s, %d dip %s is not valid ip address\n", __func__, i, args->dip[i]); + err(ctx, "%s, %d dip %s is not valid ip address\n", __func__, i, + args->dip[i]); return AVERROR(EINVAL); } } @@ -172,18 +181,18 @@ int mtl_parse_tx_port(AVFormatContext* ctx, const struct StDevArgs* devArgs, return 0; } -int mtl_parse_st30_sample_rate(enum st30_sampling* sample_rate, int value) { +int mtl_parse_st30_sample_rate(enum st30_sampling *sample_rate, int value) { switch (value) { - case 48000: - *sample_rate = ST30_SAMPLING_48K; - return 0; - case 96000: - *sample_rate = ST30_SAMPLING_96K; - return 0; - case 44100: - *sample_rate = ST31_SAMPLING_44K; - return 0; - default: - return AVERROR(EINVAL); + case 48000: + *sample_rate = ST30_SAMPLING_48K; + return 0; + case 96000: + *sample_rate = ST30_SAMPLING_96K; + return 0; + case 44100: + *sample_rate = ST31_SAMPLING_44K; + return 0; + default: + return AVERROR(EINVAL); } } diff --git a/ecosystem/ffmpeg_plugin/mtl_common.h b/ecosystem/ffmpeg_plugin/mtl_common.h index f19101b09..7ba481949 100644 --- a/ecosystem/ffmpeg_plugin/mtl_common.h +++ b/ecosystem/ffmpeg_plugin/mtl_common.h @@ -51,26 +51,26 @@ /* log define */ #ifdef DEBUG -#define dbg(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); \ +#define dbg(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); \ } while (0) #else -#define dbg(ctx, ...) \ - do { \ +#define dbg(ctx, ...) \ + do { \ } while (0) #endif -#define info(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_INFO, __VA_ARGS__); \ +#define info(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_INFO, __VA_ARGS__); \ } while (0) -#define warn(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_WARNING, __VA_ARGS__); \ +#define warn(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_WARNING, __VA_ARGS__); \ } while (0) -#define err(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_ERROR, __VA_ARGS__); \ +#define err(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_ERROR, __VA_ARGS__); \ } while (0) #ifndef NS_PER_MS @@ -81,76 +81,94 @@ #define NS_PER_S (1000 * NS_PER_MS) #endif -#define MTL_RX_DEV_ARGS \ - {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ - AV_OPT_TYPE_STRING, {.str = NULL}, .flags = DEC}, \ - {"p_sip", "mtl local ip", OFFSET(devArgs.sip[MTL_PORT_P]), AV_OPT_TYPE_STRING, \ - {.str = NULL}, .flags = DEC}, \ - { \ - "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ - {.str = NULL}, .flags = DEC \ +#define MTL_RX_DEV_ARGS \ + {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ + AV_OPT_TYPE_STRING, {.str = NULL}, .flags = DEC}, \ + {"p_sip", \ + "mtl local ip", \ + OFFSET(devArgs.sip[MTL_PORT_P]), \ + AV_OPT_TYPE_STRING, \ + {.str = NULL}, \ + .flags = DEC}, \ + { \ + "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ + {.str = NULL}, .flags = DEC \ } -#define MTL_RX_PORT_ARGS \ - {"p_rx_ip", "p rx ip", OFFSET(portArgs.sip[MTL_SESSION_PORT_P]), \ - AV_OPT_TYPE_STRING, {.str = NULL}, .flags = DEC}, \ - {"udp_port", \ - "UDP port", \ - OFFSET(portArgs.udp_port), \ - AV_OPT_TYPE_INT, \ - {.i64 = 20000}, \ - -1, \ - INT_MAX, \ - DEC}, \ - { \ - "payload_type", "payload type", OFFSET(portArgs.payload_type), AV_OPT_TYPE_INT, \ - {.i64 = 112}, -1, INT_MAX, DEC \ +#define MTL_RX_PORT_ARGS \ + { \ + "p_rx_ip", \ + "p rx ip", \ + OFFSET(portArgs.sip[MTL_SESSION_PORT_P]), \ + AV_OPT_TYPE_STRING, \ + {.str = NULL}, \ + .flags = DEC}, \ + {"udp_port", \ + "UDP port", \ + OFFSET(portArgs.udp_port), \ + AV_OPT_TYPE_INT, \ + {.i64 = 20000}, \ + -1, \ + INT_MAX, \ + DEC}, \ + { \ + "payload_type", "payload type", OFFSET(portArgs.payload_type), \ + AV_OPT_TYPE_INT, {.i64 = 112}, -1, INT_MAX, DEC \ } -#define MTL_TX_DEV_ARGS \ - {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ - AV_OPT_TYPE_STRING, {.str = NULL}, .flags = ENC}, \ - {"p_sip", "mtl local ip", OFFSET(devArgs.sip[MTL_PORT_P]), AV_OPT_TYPE_STRING, \ - {.str = NULL}, .flags = ENC}, \ - { \ - "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ - {.str = NULL}, .flags = ENC \ +#define MTL_TX_DEV_ARGS \ + {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ + AV_OPT_TYPE_STRING, {.str = NULL}, .flags = ENC}, \ + {"p_sip", \ + "mtl local ip", \ + OFFSET(devArgs.sip[MTL_PORT_P]), \ + AV_OPT_TYPE_STRING, \ + {.str = NULL}, \ + .flags = ENC}, \ + { \ + "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ + {.str = NULL}, .flags = ENC \ } -#define MTL_TX_PORT_ARGS \ - {"p_tx_ip", "p tx ip", OFFSET(portArgs.dip[MTL_SESSION_PORT_P]), \ - AV_OPT_TYPE_STRING, {.str = NULL}, .flags = ENC}, \ - {"udp_port", \ - "UDP port", \ - OFFSET(portArgs.udp_port), \ - AV_OPT_TYPE_INT, \ - {.i64 = 20000}, \ - -1, \ - INT_MAX, \ - ENC}, \ - { \ - "payload_type", "payload type", OFFSET(portArgs.payload_type), AV_OPT_TYPE_INT, \ - {.i64 = 112}, -1, INT_MAX, ENC \ +#define MTL_TX_PORT_ARGS \ + { \ + "p_tx_ip", \ + "p tx ip", \ + OFFSET(portArgs.dip[MTL_SESSION_PORT_P]), \ + AV_OPT_TYPE_STRING, \ + {.str = NULL}, \ + .flags = ENC}, \ + {"udp_port", \ + "UDP port", \ + OFFSET(portArgs.udp_port), \ + AV_OPT_TYPE_INT, \ + {.i64 = 20000}, \ + -1, \ + INT_MAX, \ + ENC}, \ + { \ + "payload_type", "payload type", OFFSET(portArgs.payload_type), \ + AV_OPT_TYPE_INT, {.i64 = 112}, -1, INT_MAX, ENC \ } typedef struct StDevArgs { - char* port[MTL_PORT_MAX]; - char* sip[MTL_PORT_MAX]; + char *port[MTL_PORT_MAX]; + char *sip[MTL_PORT_MAX]; int tx_queues_cnt[MTL_PORT_MAX]; int rx_queues_cnt[MTL_PORT_MAX]; - char* dma_dev; + char *dma_dev; } StDevArgs; typedef struct StTxSessionPortArgs { - char* dip[MTL_SESSION_PORT_MAX]; - char* port[MTL_SESSION_PORT_MAX]; + char *dip[MTL_SESSION_PORT_MAX]; + char *port[MTL_SESSION_PORT_MAX]; int udp_port; int payload_type; } StTxSessionPortArgs; typedef struct StRxSessionPortArgs { - char* sip[MTL_SESSION_PORT_MAX]; - char* port[MTL_SESSION_PORT_MAX]; + char *sip[MTL_SESSION_PORT_MAX]; + char *port[MTL_SESSION_PORT_MAX]; int udp_port; int payload_type; } StRxSessionPortArgs; @@ -163,11 +181,12 @@ typedef struct StFpsDecs { enum st_fps framerate_to_st_fps(AVRational framerate); -mtl_handle mtl_dev_get(AVFormatContext* ctx, const struct StDevArgs* args, int* idx); -int mtl_instance_put(AVFormatContext* ctx, mtl_handle handle); +mtl_handle mtl_dev_get(AVFormatContext *ctx, const struct StDevArgs *args, + int *idx); +int mtl_instance_put(AVFormatContext *ctx, mtl_handle handle); -int mtl_parse_rx_port(AVFormatContext* ctx, const struct StDevArgs* devArgs, - const StRxSessionPortArgs* args, struct st_rx_port* port); -int mtl_parse_tx_port(AVFormatContext* ctx, const struct StDevArgs* devArgs, - const StTxSessionPortArgs* args, struct st_tx_port* port); -int mtl_parse_st30_sample_rate(enum st30_sampling* sample_rate, int value); +int mtl_parse_rx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, + const StRxSessionPortArgs *args, struct st_rx_port *port); +int mtl_parse_tx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, + const StTxSessionPortArgs *args, struct st_tx_port *port); +int mtl_parse_st30_sample_rate(enum st30_sampling *sample_rate, int value); diff --git a/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c b/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c index 34aa5b664..c912f7aae 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c @@ -20,7 +20,7 @@ #include "mtl_common.h" typedef struct MtlSt20pDemuxerContext { - const AVClass* class; /**< Class for private options. */ + const AVClass *class; /**< Class for private options. */ int idx; /* arguments for devices */ @@ -41,8 +41,8 @@ typedef struct MtlSt20pDemuxerContext { int64_t frame_counter; } MtlSt20pDemuxerContext; -static int mtl_st20p_read_close(AVFormatContext* ctx) { - MtlSt20pDemuxerContext* s = ctx->priv_data; +static int mtl_st20p_read_close(AVFormatContext *ctx) { + MtlSt20pDemuxerContext *s = ctx->priv_data; dbg("%s(%d), start\n", __func__, s->idx); // Destroy rx session @@ -58,15 +58,16 @@ static int mtl_st20p_read_close(AVFormatContext* ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } -static int mtl_st20p_read_header(AVFormatContext* ctx) { - MtlSt20pDemuxerContext* s = ctx->priv_data; - AVStream* st = NULL; +static int mtl_st20p_read_header(AVFormatContext *ctx) { + MtlSt20pDemuxerContext *s = ctx->priv_data; + AVStream *st = NULL; enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; - const AVPixFmtDescriptor* pix_fmt_desc = NULL; + const AVPixFmtDescriptor *pix_fmt_desc = NULL; struct st20p_rx_ops ops_rx; int ret; int img_buf_size; @@ -93,28 +94,31 @@ static int mtl_st20p_read_header(AVFormatContext* ctx) { ops_rx.height = s->height; ops_rx.fps = framerate_to_st_fps(s->framerate); if (ops_rx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, + av_q2d(s->framerate)); return AVERROR(EINVAL); } /* transport_fmt is hardcode now */ pix_fmt = s->pixel_format; pix_fmt_desc = av_pix_fmt_desc_get(pix_fmt); switch (pix_fmt) { - case AV_PIX_FMT_YUV422P10LE: - ops_rx.transport_fmt = ST20_FMT_YUV_422_10BIT; - ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - break; - case AV_PIX_FMT_RGB24: - ops_rx.transport_fmt = ST20_FMT_RGB_8BIT; - ops_rx.output_fmt = ST_FRAME_FMT_RGB8; - break; - default: - err(ctx, "%s, unsupported pixel format: %s\n", __func__, pix_fmt_desc->name); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_rx.transport_fmt = ST20_FMT_YUV_422_10BIT; + ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + break; + case AV_PIX_FMT_RGB24: + ops_rx.transport_fmt = ST20_FMT_RGB_8BIT; + ops_rx.output_fmt = ST_FRAME_FMT_RGB8; + break; + default: + err(ctx, "%s, unsupported pixel format: %s\n", __func__, + pix_fmt_desc->name); + return AVERROR(EINVAL); } img_buf_size = av_image_get_buffer_size(pix_fmt, s->width, s->height, 1); if (img_buf_size < 0) { - err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, img_buf_size); + err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, + img_buf_size); return img_buf_size; } dbg(ctx, "%s, img_buf_size: %d\n", __func__, img_buf_size); @@ -143,7 +147,7 @@ static int mtl_st20p_read_header(AVFormatContext* ctx) { av_rescale_q(ctx->packet_size, (AVRational){8, 1}, st->time_base); ops_rx.name = "st20p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_rx.framebuff_cnt = s->fb_cnt; @@ -164,11 +168,13 @@ static int mtl_st20p_read_header(AVFormatContext* ctx) { } if (s->timeout_sec) - st20p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); + st20p_rx_set_block_timeout(s->rx_handle, + s->timeout_sec * (uint64_t)NS_PER_S); img_buf_size = st20p_rx_frame_size(s->rx_handle); if (img_buf_size != ctx->packet_size) { - err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, ctx->packet_size); + err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, + ctx->packet_size); mtl_st20p_read_close(ctx); return AVERROR(EIO); } @@ -184,10 +190,10 @@ static int mtl_st20p_read_header(AVFormatContext* ctx) { return 0; } -static int mtl_st20p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { - MtlSt20pDemuxerContext* s = ctx->priv_data; +static int mtl_st20p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { + MtlSt20pDemuxerContext *s = ctx->priv_data; int ret = 0; - struct st_frame* frame; + struct st_frame *frame; dbg("%s(%d), start\n", __func__, s->idx); @@ -198,8 +204,10 @@ static int mtl_st20p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { */ for (int i = 1; i <= s->session_init_retry; i++) { frame = st20p_rx_get_frame(s->rx_handle); - if (frame) break; - info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, i); + if (frame) + break; + info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, + i); } } else frame = st20p_rx_get_frame(s->rx_handle); @@ -210,7 +218,8 @@ static int mtl_st20p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { } dbg(ctx, "%s(%d), st20p_rx_get_frame: %p\n", __func__, s->idx, frame); if (frame->data_size != ctx->packet_size) { - err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", + err(ctx, + "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", __func__, s->idx, frame->data_size, ctx->packet_size); st20p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); @@ -320,7 +329,7 @@ FFInputFormat ff_mtl_st20p_demuxer = { .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .p.priv_class = &mtl_st20p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st20p_demuxer = #else @@ -338,4 +347,4 @@ AVInputFormat ff_mtl_st20p_demuxer = .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .priv_class = &mtl_st20p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 diff --git a/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c b/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c index 48c7b4aed..6bbc98a30 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c @@ -20,7 +20,7 @@ #include "mtl_common.h" typedef struct mtlSt20pMuxerContext { - const AVClass* class; /**< Class for private options. */ + const AVClass *class; /**< Class for private options. */ int idx; /* arguments for devices */ @@ -40,8 +40,8 @@ typedef struct mtlSt20pMuxerContext { int frame_size; } mtlSt20pMuxerContext; -static int mtl_st20p_write_close(AVFormatContext* ctx) { - mtlSt20pMuxerContext* s = ctx->priv_data; +static int mtl_st20p_write_close(AVFormatContext *ctx) { + mtlSt20pMuxerContext *s = ctx->priv_data; dbg("%s(%d), start\n", __func__, s->idx); // Destroy tx session @@ -57,12 +57,13 @@ static int mtl_st20p_write_close(AVFormatContext* ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } -static int mtl_st20p_write_header(AVFormatContext* ctx) { - mtlSt20pMuxerContext* s = ctx->priv_data; +static int mtl_st20p_write_header(AVFormatContext *ctx) { + mtlSt20pMuxerContext *s = ctx->priv_data; struct st20p_tx_ops ops_tx; int ret; @@ -82,7 +83,8 @@ static int mtl_st20p_write_header(AVFormatContext* ctx) { s->framerate = ctx->streams[0]->avg_frame_rate; ops_tx.fps = framerate_to_st_fps(s->framerate); if (ops_tx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, + av_q2d(s->framerate)); return AVERROR(EINVAL); } @@ -90,21 +92,21 @@ static int mtl_st20p_write_header(AVFormatContext* ctx) { /* transport_fmt is hardcode now */ switch (s->pixel_format) { - case AV_PIX_FMT_YUV422P10LE: - ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - ops_tx.transport_fmt = ST20_FMT_YUV_422_10BIT; - break; - case AV_PIX_FMT_RGB24: - ops_tx.input_fmt = ST_FRAME_FMT_RGB8; - ops_tx.transport_fmt = ST20_FMT_RGB_8BIT; - break; - default: - err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + ops_tx.transport_fmt = ST20_FMT_YUV_422_10BIT; + break; + case AV_PIX_FMT_RGB24: + ops_tx.input_fmt = ST_FRAME_FMT_RGB8; + ops_tx.transport_fmt = ST20_FMT_RGB_8BIT; + break; + default: + err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); + return AVERROR(EINVAL); } ops_tx.name = "st20p_ffmpge"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_tx.framebuff_cnt = s->fb_cnt; @@ -135,13 +137,13 @@ static int mtl_st20p_write_header(AVFormatContext* ctx) { return 0; } -static int mtl_st20p_write_packet(AVFormatContext* ctx, AVPacket* pkt) { - mtlSt20pMuxerContext* s = ctx->priv_data; - struct st_frame* frame; +static int mtl_st20p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { + mtlSt20pMuxerContext *s = ctx->priv_data; + struct st_frame *frame; if (pkt->size != s->frame_size) { - err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, s->idx, - pkt->size, s->frame_size); + err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, + s->idx, pkt->size, s->frame_size); return AVERROR(EIO); } @@ -157,7 +159,8 @@ static int mtl_st20p_write_packet(AVFormatContext* ctx, AVPacket* pkt) { st20p_tx_put_frame(s->tx_handle, frame); s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } diff --git a/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c b/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c index 5612cc6d4..7ec877ab3 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c @@ -20,7 +20,7 @@ #include "mtl_common.h" typedef struct MtlSt22pDemuxerContext { - const AVClass* class; /**< Class for private options. */ + const AVClass *class; /**< Class for private options. */ int idx; /* arguments for devices */ @@ -28,7 +28,7 @@ typedef struct MtlSt22pDemuxerContext { /* arguments for session port */ StRxSessionPortArgs portArgs; /* arguments for session */ - char* codec_str; + char *codec_str; int width, height; enum AVPixelFormat pixel_format; AVRational framerate; @@ -43,8 +43,8 @@ typedef struct MtlSt22pDemuxerContext { int64_t frame_counter; } MtlSt22pDemuxerContext; -static int mtl_st22p_read_close(AVFormatContext* ctx) { - MtlSt22pDemuxerContext* s = ctx->priv_data; +static int mtl_st22p_read_close(AVFormatContext *ctx) { + MtlSt22pDemuxerContext *s = ctx->priv_data; dbg("%s(%d), start\n", __func__, s->idx); // Destroy rx session @@ -60,16 +60,17 @@ static int mtl_st22p_read_close(AVFormatContext* ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } -static int mtl_st22p_read_header(AVFormatContext* ctx) { - MtlSt22pDemuxerContext* s = ctx->priv_data; - AVStream* st = NULL; +static int mtl_st22p_read_header(AVFormatContext *ctx) { + MtlSt22pDemuxerContext *s = ctx->priv_data; + AVStream *st = NULL; enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE; int img_buf_size; - const AVPixFmtDescriptor* pix_fmt_desc = NULL; + const AVPixFmtDescriptor *pix_fmt_desc = NULL; struct st22p_rx_ops ops_rx; int ret; @@ -108,7 +109,8 @@ static int mtl_st22p_read_header(AVFormatContext* ctx) { ops_rx.height = s->height; ops_rx.fps = framerate_to_st_fps(s->framerate); if (ops_rx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, + av_q2d(s->framerate)); return AVERROR(EINVAL); } @@ -116,20 +118,22 @@ static int mtl_st22p_read_header(AVFormatContext* ctx) { pix_fmt = s->pixel_format; pix_fmt_desc = av_pix_fmt_desc_get(pix_fmt); switch (pix_fmt) { - case AV_PIX_FMT_YUV422P10LE: - ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - break; - case AV_PIX_FMT_RGB24: - ops_rx.output_fmt = ST_FRAME_FMT_RGB8; - break; - default: - err(ctx, "%s, unsupported pixel format: %s\n", __func__, pix_fmt_desc->name); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + break; + case AV_PIX_FMT_RGB24: + ops_rx.output_fmt = ST_FRAME_FMT_RGB8; + break; + default: + err(ctx, "%s, unsupported pixel format: %s\n", __func__, + pix_fmt_desc->name); + return AVERROR(EINVAL); } img_buf_size = av_image_get_buffer_size(pix_fmt, s->width, s->height, 1); if (img_buf_size < 0) { - err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, img_buf_size); + err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, + img_buf_size); return img_buf_size; } dbg(ctx, "%s, img_buf_size: %d\n", __func__, img_buf_size); @@ -163,7 +167,7 @@ static int mtl_st22p_read_header(AVFormatContext* ctx) { } ops_rx.name = "st22p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.device = ST_PLUGIN_DEVICE_AUTO; ops_rx.framebuff_cnt = s->fb_cnt; ops_rx.codec_thread_cnt = s->codec_thread_cnt; @@ -176,11 +180,13 @@ static int mtl_st22p_read_header(AVFormatContext* ctx) { } if (s->timeout_sec) - st22p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); + st22p_rx_set_block_timeout(s->rx_handle, + s->timeout_sec * (uint64_t)NS_PER_S); img_buf_size = st22p_rx_frame_size(s->rx_handle); if (img_buf_size != ctx->packet_size) { - err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, ctx->packet_size); + err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, + ctx->packet_size); mtl_st22p_read_close(ctx); return AVERROR(EIO); } @@ -196,9 +202,9 @@ static int mtl_st22p_read_header(AVFormatContext* ctx) { return 0; } -static int mtl_st22_read_header(AVFormatContext* ctx) { - MtlSt22pDemuxerContext* s = ctx->priv_data; - AVStream* st = NULL; +static int mtl_st22_read_header(AVFormatContext *ctx) { + MtlSt22pDemuxerContext *s = ctx->priv_data; + AVStream *st = NULL; int img_buf_size; struct st22p_rx_ops ops_rx; int ret; @@ -253,7 +259,8 @@ static int mtl_st22_read_header(AVFormatContext* ctx) { ops_rx.height = s->height; ops_rx.fps = framerate_to_st_fps(s->framerate); if (ops_rx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, + av_q2d(s->framerate)); return AVERROR(EINVAL); } @@ -266,7 +273,7 @@ static int mtl_st22_read_header(AVFormatContext* ctx) { } ops_rx.name = "st22p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.device = ST_PLUGIN_DEVICE_AUTO; ops_rx.framebuff_cnt = s->fb_cnt; @@ -278,7 +285,8 @@ static int mtl_st22_read_header(AVFormatContext* ctx) { } if (s->timeout_sec) - st22p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); + st22p_rx_set_block_timeout(s->rx_handle, + s->timeout_sec * (uint64_t)NS_PER_S); img_buf_size = st22p_rx_frame_size(s->rx_handle); dbg(ctx, "%s, img_buf_size: %d\n", __func__, img_buf_size); @@ -306,15 +314,15 @@ static int mtl_st22_read_header(AVFormatContext* ctx) { return AVERROR(EIO); } - info(ctx, "%s(%d), rx handle %p, max packet_size %u\n", __func__, s->idx, s->rx_handle, - ctx->packet_size); + info(ctx, "%s(%d), rx handle %p, max packet_size %u\n", __func__, s->idx, + s->rx_handle, ctx->packet_size); return 0; } -static int mtl_st22p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { - MtlSt22pDemuxerContext* s = ctx->priv_data; +static int mtl_st22p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { + MtlSt22pDemuxerContext *s = ctx->priv_data; int ret = 0; - struct st_frame* frame; + struct st_frame *frame; dbg("%s(%d), start\n", __func__, s->idx); @@ -325,8 +333,10 @@ static int mtl_st22p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { */ for (int i = 1; i <= s->session_init_retry; i++) { frame = st22p_rx_get_frame(s->rx_handle); - if (frame) break; - info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, i); + if (frame) + break; + info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, + i); } } else frame = st22p_rx_get_frame(s->rx_handle); @@ -337,7 +347,8 @@ static int mtl_st22p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { } dbg(ctx, "%s(%d), st22p_rx_get_frame: %p\n", __func__, s->idx, frame); if (frame->data_size != ctx->packet_size) { - err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", + err(ctx, + "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", __func__, s->idx, frame->data_size, ctx->packet_size); st22p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); @@ -358,10 +369,10 @@ static int mtl_st22p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { return 0; } -static int mtl_st22_read_packet(AVFormatContext* ctx, AVPacket* pkt) { - MtlSt22pDemuxerContext* s = ctx->priv_data; +static int mtl_st22_read_packet(AVFormatContext *ctx, AVPacket *pkt) { + MtlSt22pDemuxerContext *s = ctx->priv_data; int ret = 0; - struct st_frame* frame; + struct st_frame *frame; dbg("%s(%d), start\n", __func__, s->idx); frame = st22p_rx_get_frame(s->rx_handle); @@ -371,8 +382,8 @@ static int mtl_st22_read_packet(AVFormatContext* ctx, AVPacket* pkt) { } dbg(ctx, "%s(%d), st22p_rx_get_frame: %p\n", __func__, s->idx, frame); if (frame->data_size > ctx->packet_size) { - err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (max %u)\n", __func__, - s->idx, frame->data_size, ctx->packet_size); + err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (max %u)\n", + __func__, s->idx, frame->data_size, ctx->packet_size); st22p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); } @@ -387,8 +398,8 @@ static int mtl_st22_read_packet(AVFormatContext* ctx, AVPacket* pkt) { st22p_rx_put_frame(s->rx_handle, frame); pkt->pts = pkt->dts = s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 ", size %d\n", __func__, s->idx, pkt->pts, - pkt->size); + dbg(ctx, "%s(%d), frame counter %" PRId64 ", size %d\n", __func__, s->idx, + pkt->pts, pkt->size); return 0; } @@ -495,7 +506,7 @@ const FFInputFormat ff_mtl_st22p_demuxer = { .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .p.priv_class = &mtl_st22p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st22p_demuxer = #else @@ -513,7 +524,7 @@ AVInputFormat ff_mtl_st22p_demuxer = .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .priv_class = &mtl_st22p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 #ifdef MTL_FFMPEG_7_0 const FFInputFormat ff_mtl_st22_demuxer = { @@ -528,7 +539,7 @@ const FFInputFormat ff_mtl_st22_demuxer = { .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .p.priv_class = &mtl_st22p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st22_demuxer = #else @@ -546,4 +557,4 @@ AVInputFormat ff_mtl_st22_demuxer = .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .priv_class = &mtl_st22p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 diff --git a/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c b/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c index a1efb914c..bb15025f7 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c @@ -20,7 +20,7 @@ #include "mtl_common.h" typedef struct mtlSt22pMuxerContext { - const AVClass* class; /**< Class for private options. */ + const AVClass *class; /**< Class for private options. */ int idx; /* arguments for devices */ @@ -28,7 +28,7 @@ typedef struct mtlSt22pMuxerContext { /* arguments for session port */ StTxSessionPortArgs portArgs; /* arguments for session */ - char* codec_str; + char *codec_str; int fb_cnt; float bpp; int codec_thread_cnt; @@ -43,8 +43,8 @@ typedef struct mtlSt22pMuxerContext { int frame_size; } mtlSt22pMuxerContext; -static int mtl_st22p_write_close(AVFormatContext* ctx) { - mtlSt22pMuxerContext* s = ctx->priv_data; +static int mtl_st22p_write_close(AVFormatContext *ctx) { + mtlSt22pMuxerContext *s = ctx->priv_data; dbg("%s(%d), start\n", __func__, s->idx); // Destroy tx session @@ -60,12 +60,13 @@ static int mtl_st22p_write_close(AVFormatContext* ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } -static int mtl_st22p_write_header(AVFormatContext* ctx) { - mtlSt22pMuxerContext* s = ctx->priv_data; +static int mtl_st22p_write_header(AVFormatContext *ctx) { + mtlSt22pMuxerContext *s = ctx->priv_data; struct st22p_tx_ops ops_tx; int ret; @@ -99,29 +100,30 @@ static int mtl_st22p_write_header(AVFormatContext* ctx) { s->framerate = ctx->streams[0]->avg_frame_rate; ops_tx.fps = framerate_to_st_fps(s->framerate); if (ops_tx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, + av_q2d(s->framerate)); return AVERROR(EINVAL); } s->pixel_format = ctx->streams[0]->codecpar->format; /* transport_fmt is hardcode now */ switch (s->pixel_format) { - case AV_PIX_FMT_YUV422P10LE: - ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - break; - case AV_PIX_FMT_RGB24: - ops_tx.input_fmt = ST_FRAME_FMT_RGB8; - break; - case AV_PIX_FMT_YUV420P: - ops_tx.input_fmt = ST_FRAME_FMT_YUV420PLANAR8; - break; - default: - err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + break; + case AV_PIX_FMT_RGB24: + ops_tx.input_fmt = ST_FRAME_FMT_RGB8; + break; + case AV_PIX_FMT_YUV420P: + ops_tx.input_fmt = ST_FRAME_FMT_YUV420PLANAR8; + break; + default: + err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); + return AVERROR(EINVAL); } ops_tx.name = "st22p_ffmpeg"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_tx.framebuff_cnt = s->fb_cnt; @@ -153,12 +155,12 @@ static int mtl_st22p_write_header(AVFormatContext* ctx) { return 0; } -static int mtl_st22_write_header(AVFormatContext* ctx) { - mtlSt22pMuxerContext* s = ctx->priv_data; +static int mtl_st22_write_header(AVFormatContext *ctx) { + mtlSt22pMuxerContext *s = ctx->priv_data; struct st22p_tx_ops ops_tx; int ret; enum AVCodecID codec_id; - const AVCodecDescriptor* codec_desc; + const AVCodecDescriptor *codec_desc; memset(&ops_tx, 0, sizeof(ops_tx)); @@ -198,14 +200,15 @@ static int mtl_st22_write_header(AVFormatContext* ctx) { s->framerate = ctx->streams[0]->avg_frame_rate; ops_tx.fps = framerate_to_st_fps(s->framerate); if (ops_tx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, + av_q2d(s->framerate)); return AVERROR(EINVAL); } s->pixel_format = ctx->streams[0]->codecpar->format; ops_tx.name = "st22_ffmpeg"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_tx.framebuff_cnt = s->fb_cnt; @@ -237,13 +240,13 @@ static int mtl_st22_write_header(AVFormatContext* ctx) { return 0; } -static int mtl_st22p_write_packet(AVFormatContext* ctx, AVPacket* pkt) { - mtlSt22pMuxerContext* s = ctx->priv_data; - struct st_frame* frame; +static int mtl_st22p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { + mtlSt22pMuxerContext *s = ctx->priv_data; + struct st_frame *frame; if (pkt->size != s->frame_size) { - err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, s->idx, - pkt->size, s->frame_size); + err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, + s->idx, pkt->size, s->frame_size); return AVERROR(EIO); } @@ -259,17 +262,18 @@ static int mtl_st22p_write_packet(AVFormatContext* ctx, AVPacket* pkt) { st22p_tx_put_frame(s->tx_handle, frame); s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } -static int mtl_st22_write_packet(AVFormatContext* ctx, AVPacket* pkt) { - mtlSt22pMuxerContext* s = ctx->priv_data; - struct st_frame* frame; +static int mtl_st22_write_packet(AVFormatContext *ctx, AVPacket *pkt) { + mtlSt22pMuxerContext *s = ctx->priv_data; + struct st_frame *frame; if (pkt->size > s->frame_size) { - err(ctx, "%s(%d), invalid pkt size: %d (max %d)\n", __func__, s->idx, pkt->size, - s->frame_size); + err(ctx, "%s(%d), invalid pkt size: %d (max %d)\n", __func__, s->idx, + pkt->size, s->frame_size); return AVERROR(EIO); } @@ -285,7 +289,8 @@ static int mtl_st22_write_packet(AVFormatContext* ctx, AVPacket* pkt) { st22p_tx_put_frame(s->tx_handle, frame); s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } @@ -304,7 +309,14 @@ static const AVOption mtl_st22p_tx_options[] = { 3, 8, ENC}, - {"bpp", "bit per pixel", OFFSET(bpp), AV_OPT_TYPE_FLOAT, {.dbl = 3.0}, 0.1, 8.0, ENC}, + {"bpp", + "bit per pixel", + OFFSET(bpp), + AV_OPT_TYPE_FLOAT, + {.dbl = 3.0}, + 0.1, + 8.0, + ENC}, {"codec_thread_cnt", "Codec threads count", OFFSET(codec_thread_cnt), diff --git a/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c b/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c index 0f7922ed6..2f46f2e4d 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c @@ -22,7 +22,7 @@ #include "mtl_common.h" typedef struct MtlSt30pDemuxerContext { - const AVClass* class; /**< Class for private options. */ + const AVClass *class; /**< Class for private options. */ int idx; /* arguments for devices */ @@ -36,9 +36,9 @@ typedef struct MtlSt30pDemuxerContext { int sample_rate; int channels; enum st30_fmt fmt; - char* fmt_str; + char *fmt_str; enum st30_ptime ptime; - char* ptime_str; + char *ptime_str; enum AVCodecID codec_id; mtl_handle dev_handle; @@ -47,8 +47,8 @@ typedef struct MtlSt30pDemuxerContext { int64_t frame_counter; } MtlSt30pDemuxerContext; -static int mtl_st30p_read_close(AVFormatContext* ctx) { - MtlSt30pDemuxerContext* s = ctx->priv_data; +static int mtl_st30p_read_close(AVFormatContext *ctx) { + MtlSt30pDemuxerContext *s = ctx->priv_data; dbg("%s(%d), start\n", __func__, s->idx); // Destroy rx session @@ -64,14 +64,15 @@ static int mtl_st30p_read_close(AVFormatContext* ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } -static int mtl_st30p_read_header(AVFormatContext* ctx) { - MtlSt30pDemuxerContext* s = ctx->priv_data; +static int mtl_st30p_read_header(AVFormatContext *ctx) { + MtlSt30pDemuxerContext *s = ctx->priv_data; struct st30p_rx_ops ops_rx; - AVStream* st = NULL; + AVStream *st = NULL; int ret; int frame_buf_size; @@ -123,8 +124,9 @@ static int mtl_st30p_read_header(AVFormatContext* ctx) { err(ctx, "%s, invalid sample_rate: %d\n", __func__, s->sample_rate); return ret; } - frame_buf_size = st30_calculate_framebuff_size( - ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel, 10 * NS_PER_MS, NULL); + frame_buf_size = + st30_calculate_framebuff_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, + ops_rx.channel, 10 * NS_PER_MS, NULL); ctx->packet_size = frame_buf_size; st = avformat_new_stream(ctx, NULL); @@ -146,7 +148,7 @@ static int mtl_st30p_read_header(AVFormatContext* ctx) { avpriv_set_pts_info(st, 64, 1, 100); ops_rx.name = "st30p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.framebuff_cnt = s->fb_cnt; /* set frame size to 10ms time */ ops_rx.framebuff_size = frame_buf_size; @@ -166,7 +168,8 @@ static int mtl_st30p_read_header(AVFormatContext* ctx) { } if (s->timeout_sec) - st30p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); + st30p_rx_set_block_timeout(s->rx_handle, + s->timeout_sec * (uint64_t)NS_PER_S); frame_buf_size = st30p_rx_frame_size(s->rx_handle); if (frame_buf_size != ctx->packet_size) { @@ -187,10 +190,10 @@ static int mtl_st30p_read_header(AVFormatContext* ctx) { return 0; } -static int mtl_st30p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { - MtlSt30pDemuxerContext* s = ctx->priv_data; +static int mtl_st30p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { + MtlSt30pDemuxerContext *s = ctx->priv_data; int ret = 0; - struct st30_frame* frame; + struct st30_frame *frame; dbg("%s(%d), start\n", __func__, s->idx); @@ -201,8 +204,10 @@ static int mtl_st30p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { */ for (int i = 1; i <= s->session_init_retry; i++) { frame = st30p_rx_get_frame(s->rx_handle); - if (frame) break; - info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, i); + if (frame) + break; + info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, + i); } } else frame = st30p_rx_get_frame(s->rx_handle); @@ -213,7 +218,8 @@ static int mtl_st30p_read_packet(AVFormatContext* ctx, AVPacket* pkt) { } dbg(ctx, "%s, st30p_rx_get_frame: %p\n", __func__, frame); if (frame->data_size != ctx->packet_size) { - err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", + err(ctx, + "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", __func__, s->idx, frame->data_size, ctx->packet_size); st30p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); @@ -317,7 +323,7 @@ const FFInputFormat ff_mtl_st30p_demuxer = { .p.extensions = "mtl", .p.priv_class = &mtl_st30p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st30p_demuxer = #else @@ -334,4 +340,4 @@ AVInputFormat ff_mtl_st30p_demuxer = .extensions = "mtl", .priv_class = &mtl_st30p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 diff --git a/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c b/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c index 2912ecab9..eff321017 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c @@ -22,7 +22,7 @@ #include "mtl_common.h" typedef struct mtlSt30pMuxerContext { - const AVClass* class; /**< Class for private options. */ + const AVClass *class; /**< Class for private options. */ int idx; /* arguments for devices */ @@ -32,11 +32,11 @@ typedef struct mtlSt30pMuxerContext { /* arguments for session */ int fb_cnt; int frame_size; - char* ptime_str; + char *ptime_str; enum st30_ptime ptime; int filled; - struct st30_frame* last_frame; + struct st30_frame *last_frame; mtl_handle dev_handle; st30p_tx_handle tx_handle; @@ -44,8 +44,8 @@ typedef struct mtlSt30pMuxerContext { int64_t frame_counter; } mtlSt30pMuxerContext; -static int mtl_st30p_write_close(AVFormatContext* ctx) { - mtlSt30pMuxerContext* s = ctx->priv_data; +static int mtl_st30p_write_close(AVFormatContext *ctx) { + mtlSt30pMuxerContext *s = ctx->priv_data; dbg("%s(%d), start\n", __func__, s->idx); // Destroy tx session @@ -65,18 +65,20 @@ static int mtl_st30p_write_close(AVFormatContext* ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } -static int mtl_st30p_write_header(AVFormatContext* ctx) { - mtlSt30pMuxerContext* s = ctx->priv_data; +static int mtl_st30p_write_header(AVFormatContext *ctx) { + mtlSt30pMuxerContext *s = ctx->priv_data; struct st30p_tx_ops ops_tx; int ret; - AVCodecParameters* codecpar = ctx->streams[0]->codecpar; + AVCodecParameters *codecpar = ctx->streams[0]->codecpar; if (codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { - err(ctx, "%s, codec_type %d is not audio\n", __func__, codecpar->codec_type); + err(ctx, "%s, codec_type %d is not audio\n", __func__, + codecpar->codec_type); return AVERROR(EINVAL); } @@ -126,11 +128,12 @@ static int mtl_st30p_write_header(AVFormatContext* ctx) { return AVERROR(EINVAL); } - s->frame_size = st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, - ops_tx.channel, 10 * NS_PER_MS, NULL); + s->frame_size = + st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, + ops_tx.channel, 10 * NS_PER_MS, NULL); ops_tx.name = "st30p_ffmpeg"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.framebuff_cnt = s->fb_cnt; ops_tx.framebuff_size = s->frame_size; @@ -159,12 +162,12 @@ static int mtl_st30p_write_header(AVFormatContext* ctx) { return 0; } -static struct st30_frame* mtl_st30p_fetch_frame(AVFormatContext* ctx, - mtlSt30pMuxerContext* s) { +static struct st30_frame *mtl_st30p_fetch_frame(AVFormatContext *ctx, + mtlSt30pMuxerContext *s) { if (s->last_frame) { return s->last_frame; } else { - struct st30_frame* frame; + struct st30_frame *frame; frame = st30p_tx_get_frame(s->tx_handle); dbg(ctx, "%s(%d), get frame addr %p\n", __func__, s->idx, frame->addr); s->last_frame = frame; @@ -172,23 +175,24 @@ static struct st30_frame* mtl_st30p_fetch_frame(AVFormatContext* ctx, } } -static int mtl_st30p_write_packet(AVFormatContext* ctx, AVPacket* pkt) { - mtlSt30pMuxerContext* s = ctx->priv_data; +static int mtl_st30p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { + mtlSt30pMuxerContext *s = ctx->priv_data; int size = pkt->size; - uint8_t* data = pkt->data; - struct st30_frame* frame = mtl_st30p_fetch_frame(ctx, s); + uint8_t *data = pkt->data; + struct st30_frame *frame = mtl_st30p_fetch_frame(ctx, s); if (!frame) { info(ctx, "%s(%d), fetch frame timeout\n", __func__, s->idx); return AVERROR(EIO); } - dbg(ctx, "%s(%d), pkt size %d frame size %d\n", __func__, s->idx, size, s->frame_size); + dbg(ctx, "%s(%d), pkt size %d frame size %d\n", __func__, s->idx, size, + s->frame_size); while (size > 0) { int left = s->frame_size - s->filled; - uint8_t* cur = (uint8_t*)frame->addr + s->filled; - dbg(ctx, "%s(%d), size %d left %d filled %d\n", __func__, s->idx, size, left, - s->filled); + uint8_t *cur = (uint8_t *)frame->addr + s->filled; + dbg(ctx, "%s(%d), size %d left %d filled %d\n", __func__, s->idx, size, + left, s->filled); if (size < left) { mtl_memcpy(cur, data, size); @@ -202,7 +206,8 @@ static int mtl_st30p_write_packet(AVFormatContext* ctx, AVPacket* pkt) { s->last_frame = NULL; frame = mtl_st30p_fetch_frame(ctx, s); if (!frame) { - info(ctx, "%s(%d), fetch frame timeout, size %d\n", __func__, s->idx, size); + info(ctx, "%s(%d), fetch frame timeout, size %d\n", __func__, s->idx, + size); return AVERROR(EIO); } data += left; @@ -211,7 +216,8 @@ static int mtl_st30p_write_packet(AVFormatContext* ctx, AVPacket* pkt) { } } - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, + s->frame_counter); return 0; } diff --git a/ecosystem/obs_mtl/linux-mtl/linux-mtl.c b/ecosystem/obs_mtl/linux-mtl/linux-mtl.c index 958963420..247a2d248 100644 --- a/ecosystem/obs_mtl/linux-mtl/linux-mtl.c +++ b/ecosystem/obs_mtl/linux-mtl/linux-mtl.c @@ -6,7 +6,7 @@ OBS_DECLARE_MODULE() OBS_MODULE_USE_DEFAULT_LOCALE("linux-mtl", "en-US") -MODULE_EXPORT const char* obs_module_description(void) { +MODULE_EXPORT const char *obs_module_description(void) { return "Linux MTL input/output"; } @@ -21,7 +21,7 @@ bool obs_module_load(void) { obs_register_output(&mtl_output); #endif - obs_data_t* obs_settings = obs_data_create(); + obs_data_t *obs_settings = obs_data_create(); obs_apply_private_data(obs_settings); obs_data_release(obs_settings); @@ -31,36 +31,36 @@ bool obs_module_load(void) { enum st_frame_fmt obs_to_mtl_format(enum video_format fmt) { switch (fmt) { - case VIDEO_FORMAT_UYVY: /* UYVY can be converted from YUV422BE10 */ - return ST_FRAME_FMT_UYVY; - case VIDEO_FORMAT_NV12: - case VIDEO_FORMAT_I420: - return ST_FRAME_FMT_YUV420CUSTOM8; - case VIDEO_FORMAT_YUY2: - case VIDEO_FORMAT_YVYU: - return ST_FRAME_FMT_YUV422CUSTOM8; - default: - return ST_FRAME_FMT_MAX; + case VIDEO_FORMAT_UYVY: /* UYVY can be converted from YUV422BE10 */ + return ST_FRAME_FMT_UYVY; + case VIDEO_FORMAT_NV12: + case VIDEO_FORMAT_I420: + return ST_FRAME_FMT_YUV420CUSTOM8; + case VIDEO_FORMAT_YUY2: + case VIDEO_FORMAT_YVYU: + return ST_FRAME_FMT_YUV422CUSTOM8; + default: + return ST_FRAME_FMT_MAX; } } enum st_fps obs_to_mtl_fps(uint32_t fps_num, uint32_t fps_den) { switch (fps_num) { - case 30000: - return ST_FPS_P29_97; - case 60000: - return ST_FPS_P59_94; - case 30: - return ST_FPS_P30; - case 60: - return ST_FPS_P60; - case 25: - return ST_FPS_P25; - case 24: - return ST_FPS_P24; - case 50: - return ST_FPS_P50; - default: - return ST_FPS_MAX; + case 30000: + return ST_FPS_P29_97; + case 60000: + return ST_FPS_P59_94; + case 30: + return ST_FPS_P30; + case 60: + return ST_FPS_P60; + case 25: + return ST_FPS_P25; + case 24: + return ST_FPS_P24; + case 50: + return ST_FPS_P50; + default: + return ST_FPS_MAX; } } \ No newline at end of file diff --git a/ecosystem/obs_mtl/linux-mtl/linux-mtl.h b/ecosystem/obs_mtl/linux-mtl/linux-mtl.h index 273bf6358..b64ac0fff 100644 --- a/ecosystem/obs_mtl/linux-mtl/linux-mtl.h +++ b/ecosystem/obs_mtl/linux-mtl/linux-mtl.h @@ -18,7 +18,7 @@ #include #include -#define timeval2ns(tv) \ +#define timeval2ns(tv) \ (((uint64_t)tv.tv_sec * 1000000000) + ((uint64_t)tv.tv_usec * 1000)) #define blog(level, msg, ...) blog(level, "mtl-input: " msg, ##__VA_ARGS__) diff --git a/ecosystem/obs_mtl/linux-mtl/mtl-input.c b/ecosystem/obs_mtl/linux-mtl/mtl-input.c index f7e42baf8..aae4448eb 100644 --- a/ecosystem/obs_mtl/linux-mtl/mtl-input.c +++ b/ecosystem/obs_mtl/linux-mtl/mtl-input.c @@ -4,17 +4,17 @@ #include "linux-mtl.h" -#define MTL_RX_SESSION(voidptr) struct mtl_rx_session* s = voidptr; +#define MTL_RX_SESSION(voidptr) struct mtl_rx_session *s = voidptr; /** * Data structure for the mtl source */ struct mtl_rx_session { /* settings */ - char* lcores; - char* port; - char* sip; - char* ip; + char *lcores; + char *port; + char *sip; + char *ip; uint16_t udp_port; uint8_t payload_type; uint32_t width; @@ -26,7 +26,7 @@ struct mtl_rx_session { uint8_t framebuffer_cnt; /* internal data */ - obs_source_t* source; + obs_source_t *source; mtl_handle dev_handle; int idx; @@ -39,15 +39,16 @@ struct mtl_rx_session { }; /* forward declarations */ -static void mtl_input_init(struct mtl_rx_session* s); -static void mtl_input_terminate(struct mtl_rx_session* s); -static void mtl_input_update(void* vptr, obs_data_t* settings); +static void mtl_input_init(struct mtl_rx_session *s); +static void mtl_input_terminate(struct mtl_rx_session *s); +static void mtl_input_update(void *vptr, obs_data_t *settings); /** * Prepare the frame for obs */ -static void mtl_prep_obs_frame(struct mtl_rx_session* s, struct obs_source_frame* frame, - size_t* plane_offsets) { +static void mtl_prep_obs_frame(struct mtl_rx_session *s, + struct obs_source_frame *frame, + size_t *plane_offsets) { memset(frame, 0, sizeof(struct obs_source_frame)); memset(plane_offsets, 0, sizeof(size_t) * MAX_AV_PLANES); @@ -56,37 +57,39 @@ static void mtl_prep_obs_frame(struct mtl_rx_session* s, struct obs_source_frame frame->width = s->width; frame->height = s->height; frame->format = format; - video_format_get_parameters(VIDEO_CS_DEFAULT, VIDEO_RANGE_DEFAULT, frame->color_matrix, - frame->color_range_min, frame->color_range_max); + video_format_get_parameters(VIDEO_CS_DEFAULT, VIDEO_RANGE_DEFAULT, + frame->color_matrix, frame->color_range_min, + frame->color_range_max); switch (format) { - case VIDEO_FORMAT_I420: - frame->linesize[0] = s->width; - frame->linesize[1] = s->width / 2; - frame->linesize[2] = s->width / 2; - plane_offsets[1] = s->width * s->height; - plane_offsets[2] = s->width * s->height * 5 / 4; - break; - case VIDEO_FORMAT_NV12: - frame->linesize[0] = s->width; - frame->linesize[1] = s->width; - plane_offsets[1] = s->width * s->height; - break; - case VIDEO_FORMAT_UYVY: - case VIDEO_FORMAT_YUY2: - case VIDEO_FORMAT_YVYU: - frame->linesize[0] = s->width * 2; - break; - default: - frame->linesize[0] = s->width * 2; - break; + case VIDEO_FORMAT_I420: + frame->linesize[0] = s->width; + frame->linesize[1] = s->width / 2; + frame->linesize[2] = s->width / 2; + plane_offsets[1] = s->width * s->height; + plane_offsets[2] = s->width * s->height * 5 / 4; + break; + case VIDEO_FORMAT_NV12: + frame->linesize[0] = s->width; + frame->linesize[1] = s->width; + plane_offsets[1] = s->width * s->height; + break; + case VIDEO_FORMAT_UYVY: + case VIDEO_FORMAT_YUY2: + case VIDEO_FORMAT_YVYU: + frame->linesize[0] = s->width * 2; + break; + default: + frame->linesize[0] = s->width * 2; + break; } } -static int notify_frame_available(void* priv) { +static int notify_frame_available(void *priv) { MTL_RX_SESSION(priv); - if (!s->handle) return -EIO; + if (!s->handle) + return -EIO; pthread_mutex_lock(&s->wake_mutex); pthread_cond_signal(&s->wake_cond); @@ -98,11 +101,11 @@ static int notify_frame_available(void* priv) { /* * Worker thread to get video data */ -static void* mtl_thread(void* vptr) { +static void *mtl_thread(void *vptr) { MTL_RX_SESSION(vptr); uint64_t frames; st20p_rx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; struct obs_source_frame out; size_t plane_offsets[MAX_AV_PLANES]; @@ -118,7 +121,8 @@ static void* mtl_thread(void* vptr) { frame = st20p_rx_get_frame(handle); if (!frame) { /* no frame */ pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + pthread_cond_wait(&s->wake_cond, &s->wake_mutex); pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -137,12 +141,12 @@ static void* mtl_thread(void* vptr) { return NULL; } -static const char* mtl_input_getname(void* unused) { +static const char *mtl_input_getname(void *unused) { UNUSED_PARAMETER(unused); return obs_module_text("MTLInput"); } -static void mtl_input_defaults(obs_data_t* settings) { +static void mtl_input_defaults(obs_data_t *settings) { obs_data_set_default_string(settings, "port", "0000:4b:00.1"); obs_data_set_default_string(settings, "lcores", "4,5"); obs_data_set_default_string(settings, "sip", "192.168.96.2"); @@ -167,25 +171,28 @@ static void mtl_input_defaults(obs_data_t* settings) { * @param ignore ignore this property * @param enable enable/disable all properties */ -static void mtl_props_set_enabled(obs_properties_t* props, obs_property_t* ignore, - bool enable) { - if (!props) return; +static void mtl_props_set_enabled(obs_properties_t *props, + obs_property_t *ignore, bool enable) { + if (!props) + return; - for (obs_property_t* prop = obs_properties_first(props); prop != NULL; + for (obs_property_t *prop = obs_properties_first(props); prop != NULL; obs_property_next(&prop)) { - if (prop == ignore) continue; + if (prop == ignore) + continue; obs_property_set_enabled(prop, enable); } } -static bool on_start_clicked(obs_properties_t* ps, obs_property_t* p, void* vptr) { +static bool on_start_clicked(obs_properties_t *ps, obs_property_t *p, + void *vptr) { MTL_RX_SESSION(vptr); mtl_input_init(s); obs_property_set_description(p, obs_module_text("Started")); - obs_property_t* stop = obs_properties_get(ps, "stop"); + obs_property_t *stop = obs_properties_get(ps, "stop"); obs_property_set_description(stop, obs_module_text("Stop")); obs_property_set_enabled(stop, true); @@ -194,13 +201,14 @@ static bool on_start_clicked(obs_properties_t* ps, obs_property_t* p, void* vptr return true; } -static bool on_stop_clicked(obs_properties_t* ps, obs_property_t* p, void* vptr) { +static bool on_stop_clicked(obs_properties_t *ps, obs_property_t *p, + void *vptr) { MTL_RX_SESSION(vptr); mtl_input_terminate(s); obs_property_set_description(p, obs_module_text("Stopped")); - obs_property_t* start = obs_properties_get(ps, "start"); + obs_property_t *start = obs_properties_get(ps, "start"); obs_property_set_description(start, obs_module_text("Start")); obs_property_set_enabled(p, false); @@ -209,26 +217,32 @@ static bool on_stop_clicked(obs_properties_t* ps, obs_property_t* p, void* vptr) return true; } -static obs_properties_t* mtl_input_properties(void* vptr) { +static obs_properties_t *mtl_input_properties(void *vptr) { MTL_RX_SESSION(vptr); - obs_properties_t* props = obs_properties_create(); + obs_properties_t *props = obs_properties_create(); - obs_properties_add_text(props, "port", obs_module_text("Port"), OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "port", obs_module_text("Port"), + OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), + OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), + OBS_TEXT_DEFAULT); obs_properties_add_text(props, "ip", obs_module_text("IP"), OBS_TEXT_DEFAULT); - obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, 65536, 1); - obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), 0, 255, - 1); - obs_properties_add_int(props, "framebuffer_cnt", obs_module_text("FramebuffCnt"), 2, - 128, 1); + obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, + 65536, 1); + obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), + 0, 255, 1); + obs_properties_add_int(props, "framebuffer_cnt", + obs_module_text("FramebuffCnt"), 2, 128, 1); obs_properties_add_int(props, "width", obs_module_text("Width"), 1, 65535, 1); - obs_properties_add_int(props, "height", obs_module_text("Height"), 1, 65535, 1); - obs_property_t* fps_list = obs_properties_add_list( - props, "fps", obs_module_text("FPS"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); + obs_properties_add_int(props, "height", obs_module_text("Height"), 1, 65535, + 1); + obs_property_t *fps_list = + obs_properties_add_list(props, "fps", obs_module_text("FPS"), + OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(fps_list, obs_module_text("23.98"), ST_FPS_P23_98); obs_property_list_add_int(fps_list, obs_module_text("24"), ST_FPS_P24); obs_property_list_add_int(fps_list, obs_module_text("25"), ST_FPS_P25); @@ -238,12 +252,13 @@ static obs_properties_t* mtl_input_properties(void* vptr) { obs_property_list_add_int(fps_list, obs_module_text("59.94"), ST_FPS_P59_94); obs_property_list_add_int(fps_list, obs_module_text("60"), ST_FPS_P60); obs_property_list_add_int(fps_list, obs_module_text("100"), ST_FPS_P100); - obs_property_list_add_int(fps_list, obs_module_text("119.88"), ST_FPS_P119_88); + obs_property_list_add_int(fps_list, obs_module_text("119.88"), + ST_FPS_P119_88); obs_property_list_add_int(fps_list, obs_module_text("120"), ST_FPS_P120); - obs_property_t* t_fmt_list = - obs_properties_add_list(props, "t_fmt", obs_module_text("TransportFormat"), - OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); + obs_property_t *t_fmt_list = obs_properties_add_list( + props, "t_fmt", obs_module_text("TransportFormat"), OBS_COMBO_TYPE_LIST, + OBS_COMBO_FORMAT_INT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_10bit"), ST20_FMT_YUV_422_10BIT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_8bit"), @@ -251,16 +266,21 @@ static obs_properties_t* mtl_input_properties(void* vptr) { obs_property_list_add_int(t_fmt_list, obs_module_text("YUV420_8bit"), ST20_FMT_YUV_420_8BIT); - obs_property_t* v_fmt_list = + obs_property_t *v_fmt_list = obs_properties_add_list(props, "v_fmt", obs_module_text("VideoFormat"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); - obs_property_list_add_int(v_fmt_list, obs_module_text("UYVY"), VIDEO_FORMAT_UYVY); - obs_property_list_add_int(v_fmt_list, obs_module_text("YUY2"), VIDEO_FORMAT_YUY2); - obs_property_list_add_int(v_fmt_list, obs_module_text("YVYU"), VIDEO_FORMAT_YVYU); - obs_property_list_add_int(v_fmt_list, obs_module_text("I420"), VIDEO_FORMAT_I420); - obs_property_list_add_int(v_fmt_list, obs_module_text("NV12"), VIDEO_FORMAT_NV12); - - obs_property_t* log_level_list = + obs_property_list_add_int(v_fmt_list, obs_module_text("UYVY"), + VIDEO_FORMAT_UYVY); + obs_property_list_add_int(v_fmt_list, obs_module_text("YUY2"), + VIDEO_FORMAT_YUY2); + obs_property_list_add_int(v_fmt_list, obs_module_text("YVYU"), + VIDEO_FORMAT_YVYU); + obs_property_list_add_int(v_fmt_list, obs_module_text("I420"), + VIDEO_FORMAT_I420); + obs_property_list_add_int(v_fmt_list, obs_module_text("NV12"), + VIDEO_FORMAT_NV12); + + obs_property_t *log_level_list = obs_properties_add_list(props, "log_level", obs_module_text("LogLevel"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(log_level_list, "ERROR", MTL_LOG_LEVEL_ERR); @@ -269,18 +289,20 @@ static obs_properties_t* mtl_input_properties(void* vptr) { obs_property_list_add_int(log_level_list, "WARNING", MTL_LOG_LEVEL_WARNING); obs_property_list_add_int(log_level_list, "DEBUG", MTL_LOG_LEVEL_DEBUG); - obs_properties_add_button(props, "start", obs_module_text("Start"), on_start_clicked); - obs_properties_add_button(props, "stop", obs_module_text("Stop"), on_stop_clicked); - obs_property_t* stop = obs_properties_get(props, "stop"); + obs_properties_add_button(props, "start", obs_module_text("Start"), + on_start_clicked); + obs_properties_add_button(props, "stop", obs_module_text("Stop"), + on_stop_clicked); + obs_property_t *stop = obs_properties_get(props, "stop"); obs_property_set_enabled(stop, false); - obs_data_t* settings = obs_source_get_settings(s->source); + obs_data_t *settings = obs_source_get_settings(s->source); obs_data_release(settings); return props; } -static void mtl_input_terminate(struct mtl_rx_session* s) { +static void mtl_input_terminate(struct mtl_rx_session *s) { s->stop = true; pthread_mutex_lock(&s->wake_mutex); pthread_cond_signal(&s->wake_cond); @@ -304,17 +326,18 @@ static void mtl_input_terminate(struct mtl_rx_session* s) { } } -static void mtl_input_destroy(void* vptr) { +static void mtl_input_destroy(void *vptr) { MTL_RX_SESSION(vptr); - if (!s) return; + if (!s) + return; mtl_input_terminate(s); bfree(s); } -static void mtl_input_init(struct mtl_rx_session* s) { +static void mtl_input_init(struct mtl_rx_session *s) { struct mtl_init_params param; memset(¶m, 0, sizeof(param)); @@ -322,9 +345,9 @@ static void mtl_input_init(struct mtl_rx_session* s) { snprintf(param.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); inet_pton(AF_INET, s->sip, param.sip_addr[MTL_PORT_P]); param.pmd[MTL_PORT_P] = MTL_PMD_DPDK_USER; - param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa - param.log_level = s->log_level; // mtl lib log level - param.priv = s; // usr ctx pointer + param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa + param.log_level = s->log_level; // mtl lib log level + param.priv = s; // usr ctx pointer // user register ptp func, if not register, the internal ptp will be used param.ptp_get_time_fn = NULL; param.tx_queues_cnt[MTL_PORT_P] = 0; @@ -342,11 +365,11 @@ static void mtl_input_init(struct mtl_rx_session* s) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "mtl-input"; - ops_rx.priv = s; // app handle register to lib + ops_rx.priv = s; // app handle register to lib ops_rx.port.num_port = 1; inet_pton(AF_INET, s->ip, ops_rx.port.ip_addr[MTL_PORT_P]); snprintf(ops_rx.port.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); - ops_rx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. + ops_rx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. ops_rx.width = s->width; ops_rx.height = s->height; ops_rx.fps = s->fps; @@ -354,7 +377,8 @@ static void mtl_input_init(struct mtl_rx_session* s) { ops_rx.transport_fmt = s->t_fmt; ops_rx.framebuff_cnt = s->framebuffer_cnt; ops_rx.port.payload_type = s->payload_type; - // app register non-block func, app get a frame ready notification info by this cb + // app register non-block func, app get a frame ready notification info by + // this cb ops_rx.notify_frame_available = notify_frame_available; s->handle = st20p_rx_create(dev_handle, &ops_rx); @@ -380,13 +404,13 @@ static void mtl_input_init(struct mtl_rx_session* s) { mtl_input_terminate(s); } -static void mtl_input_update(void* vptr, obs_data_t* settings) { +static void mtl_input_update(void *vptr, obs_data_t *settings) { MTL_RX_SESSION(vptr); - s->port = (char*)obs_data_get_string(settings, "port"); - s->lcores = (char*)obs_data_get_string(settings, "lcores"); - s->sip = (char*)obs_data_get_string(settings, "sip"); - s->ip = (char*)obs_data_get_string(settings, "ip"); + s->port = (char *)obs_data_get_string(settings, "port"); + s->lcores = (char *)obs_data_get_string(settings, "lcores"); + s->sip = (char *)obs_data_get_string(settings, "sip"); + s->ip = (char *)obs_data_get_string(settings, "ip"); s->udp_port = obs_data_get_int(settings, "udp_port"); s->payload_type = obs_data_get_int(settings, "payload_type"); s->width = obs_data_get_int(settings, "width"); @@ -398,8 +422,8 @@ static void mtl_input_update(void* vptr, obs_data_t* settings) { s->log_level = obs_data_get_int(settings, "log_level"); } -static void* mtl_input_create(obs_data_t* settings, obs_source_t* source) { - struct mtl_rx_session* s = bzalloc(sizeof(struct mtl_rx_session)); +static void *mtl_input_create(obs_data_t *settings, obs_source_t *source) { + struct mtl_rx_session *s = bzalloc(sizeof(struct mtl_rx_session)); s->source = source; mtl_input_update(s, settings); diff --git a/ecosystem/obs_mtl/linux-mtl/mtl-output.c b/ecosystem/obs_mtl/linux-mtl/mtl-output.c index 5e117a27d..176e677e3 100644 --- a/ecosystem/obs_mtl/linux-mtl/mtl-output.c +++ b/ecosystem/obs_mtl/linux-mtl/mtl-output.c @@ -6,17 +6,17 @@ #if TODO_OUTPUT -#define MTL_TX_SESSION(voidptr) struct mtl_tx_session* s = voidptr; +#define MTL_TX_SESSION(voidptr) struct mtl_tx_session *s = voidptr; /** * Data structure for the mtl source */ struct mtl_tx_session { /* settings */ - char* lcores; - char* port; - char* sip; - char* ip; + char *lcores; + char *port; + char *sip; + char *ip; uint16_t udp_port; uint8_t payload_type; enum st20_fmt t_fmt; @@ -24,7 +24,7 @@ struct mtl_tx_session { uint8_t framebuffer_cnt; /* internal data */ - obs_output_t* output; + obs_output_t *output; mtl_handle dev_handle; int idx; @@ -34,16 +34,16 @@ struct mtl_tx_session { }; /* forward declarations */ -static void mtl_output_init(struct mtl_tx_session* s); -static void mtl_output_terminate(struct mtl_tx_session* s); -static void mtl_output_update(void* vptr, obs_data_t* settings); +static void mtl_output_init(struct mtl_tx_session *s); +static void mtl_output_terminate(struct mtl_tx_session *s); +static void mtl_output_update(void *vptr, obs_data_t *settings); -static const char* mtl_output_getname(void* unused) { +static const char *mtl_output_getname(void *unused) { UNUSED_PARAMETER(unused); return obs_module_text("MTLOutput"); } -static void mtl_output_defaults(obs_data_t* settings) { +static void mtl_output_defaults(obs_data_t *settings) { obs_data_set_default_string(settings, "port", "0000:4b:00.1"); obs_data_set_default_string(settings, "lcores", "4,5"); obs_data_set_default_string(settings, "sip", "192.168.96.2"); @@ -55,26 +55,30 @@ static void mtl_output_defaults(obs_data_t* settings) { obs_data_set_default_int(settings, "log_level", MTL_LOG_LEVEL_ERR); } -static obs_properties_t* mtl_output_properties(void* vptr) { +static obs_properties_t *mtl_output_properties(void *vptr) { MTL_TX_SESSION(vptr); - obs_properties_t* props = obs_properties_create(); + obs_properties_t *props = obs_properties_create(); - obs_properties_add_text(props, "port", obs_module_text("Port"), OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "port", obs_module_text("Port"), + OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), + OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), + OBS_TEXT_DEFAULT); obs_properties_add_text(props, "ip", obs_module_text("IP"), OBS_TEXT_DEFAULT); - obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, 65536, 1); - obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), 0, 255, - 1); - obs_properties_add_int(props, "framebuffer_cnt", obs_module_text("FramebuffCnt"), 2, - 128, 1); + obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, + 65536, 1); + obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), + 0, 255, 1); + obs_properties_add_int(props, "framebuffer_cnt", + obs_module_text("FramebuffCnt"), 2, 128, 1); - obs_property_t* t_fmt_list = - obs_properties_add_list(props, "t_fmt", obs_module_text("TransportFormat"), - OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); + obs_property_t *t_fmt_list = obs_properties_add_list( + props, "t_fmt", obs_module_text("TransportFormat"), OBS_COMBO_TYPE_LIST, + OBS_COMBO_FORMAT_INT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_10bit"), ST20_FMT_YUV_422_10BIT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_8bit"), @@ -82,7 +86,7 @@ static obs_properties_t* mtl_output_properties(void* vptr) { obs_property_list_add_int(t_fmt_list, obs_module_text("YUV420_8bit"), ST20_FMT_YUV_420_8BIT); - obs_property_t* log_level_list = + obs_property_t *log_level_list = obs_properties_add_list(props, "log_level", obs_module_text("LogLevel"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(log_level_list, "ERROR", MTL_LOG_LEVEL_ERR); @@ -91,13 +95,13 @@ static obs_properties_t* mtl_output_properties(void* vptr) { obs_property_list_add_int(log_level_list, "WARNING", MTL_LOG_LEVEL_WARNING); obs_property_list_add_int(log_level_list, "DEBUG", MTL_LOG_LEVEL_DEBUG); - obs_data_t* settings = obs_output_get_settings(s->output); + obs_data_t *settings = obs_output_get_settings(s->output); obs_data_release(settings); return props; } -static void mtl_output_terminate(struct mtl_tx_session* s) { +static void mtl_output_terminate(struct mtl_tx_session *s) { if (s->dev_handle) { mtl_stop(s->dev_handle); } @@ -113,17 +117,18 @@ static void mtl_output_terminate(struct mtl_tx_session* s) { } } -static void mtl_output_destroy(void* vptr) { +static void mtl_output_destroy(void *vptr) { MTL_TX_SESSION(vptr); - if (!s) return; + if (!s) + return; mtl_output_terminate(s); bfree(s); } -static void mtl_output_init(struct mtl_tx_session* s) { +static void mtl_output_init(struct mtl_tx_session *s) { struct mtl_init_params param; memset(¶m, 0, sizeof(param)); @@ -131,9 +136,9 @@ static void mtl_output_init(struct mtl_tx_session* s) { snprintf(param.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); inet_pton(AF_INET, s->sip, param.sip_addr[MTL_PORT_P]); param.pmd[MTL_PORT_P] = MTL_PMD_DPDK_USER; - param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa - param.log_level = s->log_level; // mtl lib log level - param.priv = s; // usr ctx pointer + param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa + param.log_level = s->log_level; // mtl lib log level + param.priv = s; // usr ctx pointer // user register ptp func, if not register, the internal ptp will be used param.ptp_get_time_fn = NULL; param.tx_queues_cnt[MTL_PORT_P] = 1; @@ -148,17 +153,17 @@ static void mtl_output_init(struct mtl_tx_session* s) { s->dev_handle = dev_handle; s->idx = 0; - video_t* video = obs_output_video(s->output); - const struct video_output_info* vo_info = video_output_get_info(video); + video_t *video = obs_output_video(s->output); + const struct video_output_info *vo_info = video_output_get_info(video); struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "mtl-input"; - ops_tx.priv = s; // app handle register to lib + ops_tx.priv = s; // app handle register to lib ops_tx.port.num_port = 1; inet_pton(AF_INET, s->ip, ops_tx.port.dip_addr[MTL_PORT_P]); snprintf(ops_tx.port.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); - ops_tx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. + ops_tx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. ops_tx.width = vo_info->width; ops_tx.height = vo_info->height; ops_tx.fps = obs_to_mtl_fps(vo_info->fps_num, vo_info->fps_den); @@ -181,13 +186,13 @@ static void mtl_output_init(struct mtl_tx_session* s) { mtl_output_terminate(s); } -static void mtl_output_update(void* vptr, obs_data_t* settings) { +static void mtl_output_update(void *vptr, obs_data_t *settings) { MTL_TX_SESSION(vptr); - s->port = (char*)obs_data_get_string(settings, "port"); - s->lcores = (char*)obs_data_get_string(settings, "lcores"); - s->sip = (char*)obs_data_get_string(settings, "sip"); - s->ip = (char*)obs_data_get_string(settings, "ip"); + s->port = (char *)obs_data_get_string(settings, "port"); + s->lcores = (char *)obs_data_get_string(settings, "lcores"); + s->sip = (char *)obs_data_get_string(settings, "sip"); + s->ip = (char *)obs_data_get_string(settings, "ip"); s->udp_port = obs_data_get_int(settings, "udp_port"); s->payload_type = obs_data_get_int(settings, "payload_type"); s->t_fmt = obs_data_get_int(settings, "t_fmt"); @@ -197,8 +202,8 @@ static void mtl_output_update(void* vptr, obs_data_t* settings) { mtl_output_init(s); } -static void* mtl_output_create(obs_data_t* settings, obs_output_t* output) { - struct mtl_tx_session* s = bzalloc(sizeof(struct mtl_tx_session)); +static void *mtl_output_create(obs_data_t *settings, obs_output_t *output) { + struct mtl_tx_session *s = bzalloc(sizeof(struct mtl_tx_session)); s->output = output; mtl_output_update(s, settings); @@ -206,18 +211,21 @@ static void* mtl_output_create(obs_data_t* settings, obs_output_t* output) { return s; } -static void mtl_output_video_frame(void* vptr, struct video_data* obs_frame) { +static void mtl_output_video_frame(void *vptr, struct video_data *obs_frame) { MTL_TX_SESSION(vptr); st20p_tx_handle handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; size_t data_size = 0; frame = st20p_tx_get_frame(handle); - if (!frame) return; + if (!frame) + return; uint8_t planes = st_frame_fmt_planes(frame->fmt); - for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; + plane++) { /* assume planes continuous */ size_t plane_size = - st_frame_least_linesize(frame->fmt, frame->width, plane) * frame->height; + st_frame_least_linesize(frame->fmt, frame->width, plane) * + frame->height; mtl_memcpy(frame->addr[plane], obs_frame->data[plane], plane_size); data_size += plane_size; } @@ -229,7 +237,7 @@ static void mtl_output_video_frame(void* vptr, struct video_data* obs_frame) { s->total_bytes += frame->data_size; } -static uint64_t mtl_output_total_bytes(void* vptr) { +static uint64_t mtl_output_total_bytes(void *vptr) { MTL_TX_SESSION(vptr); return s->total_bytes; } diff --git a/format-coding.sh b/format-coding.sh index 3a052404b..5bd835585 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -12,6 +12,6 @@ echo "clang-format check" find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' \ ! -name 'vmlinux.h' -exec clang-format --style=file ".github/linters/clang-format.yaml" --verbose -i {} + -CONFIG=".github/linters/.pyproject.toml" -black --config "$CONFIG" python/ -isort --settings-path "$CONFIG" python/ +# CONFIG=".github/linters/.pyproject.toml" +# black --config "$CONFIG" python/ +# isort --settings-path "$CONFIG" python/ diff --git a/include/experimental/st20_combined_api.h b/include/experimental/st20_combined_api.h index 0fd1b3b5f..0ba39564d 100644 --- a/include/experimental/st20_combined_api.h +++ b/include/experimental/st20_combined_api.h @@ -5,7 +5,8 @@ /** * @file st20_redundant_combined.h * - * Interfaces for st2110-20 combined redundant transport, experimental feature only. + * Interfaces for st2110-20 combined redundant transport, experimental feature + * only. * */ @@ -20,17 +21,19 @@ extern "C" { #endif /** Handle to rx st2110-22 pipeline session of lib */ -typedef struct st20rc_rx_ctx* st20rc_rx_handle; +typedef struct st20rc_rx_ctx *st20rc_rx_handle; /** * Flag bit in flags of struct st20rc_rx_ops, for non MTL_PMD_DPDK_USER. - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st20p_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st20p_rx_get_queue_meta to get the queue meta(queue number + * etc) info. */ #define ST20RC_RX_FLAG_DATA_PATH_ONLY (MTL_BIT32(0)) /** * Flag bit in flags of struct st20rc_rx_ops. - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ #define ST20RC_RX_FLAG_ENABLE_VSYNC (MTL_BIT32(1)) @@ -60,15 +63,16 @@ typedef struct st20rc_rx_ctx* st20rc_rx_handle; */ struct st20rc_rx_ops { /** name */ - const char* name; + const char *name; /** private data to the callback function */ - void* priv; + void *priv; union { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t + sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** num of ports this session attached to, must be 2 */ uint8_t num_port; @@ -94,8 +98,9 @@ struct st20rc_rx_ops { /** 7 bits payload type define in RFC3550. Zero means disable the * payload_type check on the RX pkt path */ uint8_t payload_type; - /** Optional. Synchronization source defined in RFC3550, RX session will check the - * incoming RTP packets match the ssrc. Leave to zero to disable the ssrc check */ + /** Optional. Synchronization source defined in RFC3550, RX session will check + * the incoming RTP packets match the ssrc. Leave to zero to disable the ssrc + * check */ uint32_t ssrc; /** Optional. source filter IP address of multicast */ uint8_t mcast_sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; @@ -112,21 +117,22 @@ struct st20rc_rx_ops { * frame: point to the address of the frame buf. * meta: point to the meta data. * return: - * - 0: if app consume the frame successful. App should call st20rc_rx_put_frame - * to return the frame when it finish the handling - * < 0: the error code if app can't handle, lib will call st20rc_rx_put_frame then. + * - 0: if app consume the frame successful. App should call + * st20rc_rx_put_frame to return the frame when it finish the handling < 0: + * the error code if app can't handle, lib will call st20rc_rx_put_frame then. * Only for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * And only non-block method can be used in this callback as it run from lcore + * tasklet routine. */ - int (*notify_frame_ready)(void* priv, void* frame, struct st20_rx_frame_meta* meta); + int (*notify_frame_ready)(void *priv, void *frame, + struct st20_rx_frame_meta *meta); /** * event callback, lib will call this when there is some event happened. - * Only non-block method can be used in this callback as it run from lcore routine. - * args point to the meta data of each event. - * Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. + * Only non-block method can be used in this callback as it run from lcore + * routine. args point to the meta data of each event. Ex, cast to struct + * st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); + int (*notify_event)(void *priv, enum st_event event, void *args); }; /** @@ -135,12 +141,13 @@ struct st20rc_rx_ops { * @param mt * The handle to the media transport device context. * @param ops - * The pointer to the structure describing how to create a rx st2110-20(video) session. + * The pointer to the structure describing how to create a rx st2110-20(video) + * session. * @return * - NULL on error. * - Otherwise, the handle to the rx st2110-20(redundant) session. */ -st20rc_rx_handle st20rc_rx_create(mtl_handle mt, struct st20rc_rx_ops* ops); +st20rc_rx_handle st20rc_rx_create(mtl_handle mt, struct st20rc_rx_ops *ops); /** * Free the rx st2110-20(redundant) session. @@ -164,7 +171,7 @@ int st20rc_rx_free(st20rc_rx_handle handle); * - 0: Success. * - <0: Error code. */ -int st20rc_rx_put_frame(st20rc_rx_handle handle, void* frame); +int st20rc_rx_put_frame(st20rc_rx_handle handle, void *frame); /** * Get the framebuffer size for the rx st2110-20(redundant) session. @@ -197,13 +204,14 @@ int st20rc_rx_get_framebuffer_count(st20rc_rx_handle handle); * synchronous or asynchronous, true means this func will return after dump * progress is finished. * @param meta - * The meta data returned, only for synchronous, leave to NULL if not need the meta. + * The meta data returned, only for synchronous, leave to NULL if not need the + * meta. * @return * - 0: Success, rx st2110-20(redundant) session pcapng dump succ. * - <0: Error code of the rx st2110-20(redundant) session pcapng dump. */ -int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta); +int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta); #if defined(__cplusplus) } diff --git a/include/mtl_api.h b/include/mtl_api.h index 6f216709b..4bc2eee2d 100644 --- a/include/mtl_api.h +++ b/include/mtl_api.h @@ -34,7 +34,7 @@ extern "C" { #endif #ifdef _MSC_VER -#define MTL_PACK(__Declaration__) \ +#define MTL_PACK(__Declaration__) \ __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop)) #endif @@ -45,7 +45,7 @@ extern "C" { /** * All version numbers in one to compare with ST_VERSION_NUM() */ -#define MTL_VERSION \ +#define MTL_VERSION \ MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR, MTL_VERSION_LAST) /** @@ -107,11 +107,11 @@ extern "C" { /** * Handle to MTL transport device context */ -typedef struct mtl_main_impl* mtl_handle; +typedef struct mtl_main_impl *mtl_handle; /** * Handle to st user dma device */ -typedef struct mtl_dma_lender_dev* mtl_udma_handle; +typedef struct mtl_dma_lender_dev *mtl_udma_handle; /** * IO virtual address type. @@ -126,7 +126,7 @@ typedef uint64_t mtl_cpuva_t; /** * Handle to dma mem */ -typedef struct mtl_dma_mem* mtl_dma_mem_handle; +typedef struct mtl_dma_mem *mtl_dma_mem_handle; /** * Bad IOVA address @@ -201,14 +201,15 @@ enum mtl_log_level { #define MTL_LOG_LEVEL_ERROR (MTL_LOG_LEVEL_ERR) /* log formatter */ -typedef void (*mtl_log_prefix_formatter_t)(char* buf, size_t buf_sz); +typedef void (*mtl_log_prefix_formatter_t)(char *buf, size_t buf_sz); /* log printer, similar to printf */ -typedef void (*mtl_log_printer_t)(enum mtl_log_level level, const char* format, ...); +typedef void (*mtl_log_printer_t)(enum mtl_log_level level, const char *format, + ...); /** - * Poll mode driver type, not change the enum value any more if one PMD type is marked as - * production quality. + * Poll mode driver type, not change the enum value any more if one PMD type is + * marked as production quality. */ enum mtl_pmd_type { /** DPDK user driver PMD */ @@ -239,7 +240,8 @@ enum mtl_rss_mode { MTL_RSS_MODE_NONE = 0, /** hash with both l3 src and dst, not use now */ MTL_RSS_MODE_L3, - /** hash with l3 src and dst address, l4 src port and dst port, used with shared rss */ + /** hash with l3 src and dst address, l4 src port and dst port, used with + shared rss */ MTL_RSS_MODE_L3_L4, /** max value of this enum */ MTL_RSS_MODE_MAX, @@ -325,15 +327,17 @@ enum mtl_init_flag { /** Separated lcore for RX video(st2110-20/st2110-22) sessions. */ MTL_FLAG_RX_SEPARATE_VIDEO_LCORE = (MTL_BIT64(2)), /** - * Enable migrate mode for rx video session if current LCORE is too busy to handle the - * rx video tasklet, the busy session may be migrated to a new LCORE. - * If not enable, rx video will always use static mapping based on quota. + * Enable migrate mode for rx video session if current LCORE is too busy to + * handle the rx video tasklet, the busy session may be migrated to a new + * LCORE. If not enable, rx video will always use static mapping based on + * quota. */ MTL_FLAG_TX_VIDEO_MIGRATE = (MTL_BIT64(3)), /** - * Enable migrate mode for rx video session if current LCORE is too busy to handle the - * rx video tasklet, the busy session may be migrated to a new LCORE. - * If not enable, rx video will always use static mapping based on quota. + * Enable migrate mode for rx video session if current LCORE is too busy to + * handle the rx video tasklet, the busy session may be migrated to a new + * LCORE. If not enable, rx video will always use static mapping based on + * quota. */ MTL_FLAG_RX_VIDEO_MIGRATE = (MTL_BIT64(4)), /** @@ -349,8 +353,8 @@ enum mtl_init_flag { */ MTL_FLAG_RXTX_SIMD_512 = (MTL_BIT64(7)), /** - * Enable HW offload timestamp for all RX packets target the compliance analyze. Only - * can work for PF on E810 now. + * Enable HW offload timestamp for all RX packets target the compliance + * analyze. Only can work for PF on E810 now. */ MTL_FLAG_ENABLE_HW_TIMESTAMP = (MTL_BIT64(8)), /** @@ -388,16 +392,18 @@ enum mtl_init_flag { */ MTL_FLAG_VIRTIO_USER = (MTL_BIT64(16)), /** - * Do mtl_start in mtl_init, mtl_stop in mtl_uninit, and skip the mtl_start/mtl_stop + * Do mtl_start in mtl_init, mtl_stop in mtl_uninit, and skip the + * mtl_start/mtl_stop */ MTL_FLAG_DEV_AUTO_START_STOP = (MTL_BIT64(17)), /** - * Enable the use of cores across NUMA nodes; by default, only cores within the same - * NUMA node as the NIC are used due to the high cost of cross-NUMA communication. + * Enable the use of cores across NUMA nodes; by default, only cores within + * the same NUMA node as the NIC are used due to the high cost of cross-NUMA + * communication. */ MTL_FLAG_ALLOW_ACROSS_NUMA_CORE = (MTL_BIT64(18)), - /** not send multicast join message, for the SDN switch case which deliver the stream - * directly + /** not send multicast join message, for the SDN switch case which deliver the + * stream directly */ MTL_FLAG_NO_MULTICAST = (MTL_BIT64(19)), /** Dedicated lcore for system CNI tasks. */ @@ -460,8 +466,8 @@ enum mtl_init_flag { */ MTL_FLAG_RX_USE_CNI = (MTL_BIT64(45)), /** - * To exclusively use port only for flow, the application must ensure that all RX - * streams have unique UDP port numbers. + * To exclusively use port only for flow, the application must ensure that all + * RX streams have unique UDP port numbers. */ MTL_FLAG_RX_UDP_PORT_ONLY = (MTL_BIT64(46)), /** not bind current process to NIC numa socket */ @@ -485,11 +491,12 @@ struct mtl_ptp_sync_notify_meta { * The structure describing how to init a mtl port device. */ struct mtl_port_init_params { - /** Optional. Flags to control MTL port. See MTL_PORT_FLAG_* for possible value */ + /** Optional. Flags to control MTL port. See MTL_PORT_FLAG_* for possible + * value */ uint64_t flags; /** Lib will force assign the numa for current port to this numa id if - * MTL_PORT_FLAG_FORCE_NUMA is set. Not set MTL_PORT_FLAG_FORCE_NUMA if you don't know - * the detail. + * MTL_PORT_FLAG_FORCE_NUMA is set. Not set MTL_PORT_FLAG_FORCE_NUMA if you + * don't know the detail. */ int socket_id; }; @@ -501,13 +508,15 @@ struct mtl_port_init_params { struct mtl_init_params { /** * Mandatory. PCIE BDF port, ex: 0000:af:01.0. - * MTL_PMD_NATIVE_AF_XDP, use native_af_xdp + ifname, ex: native_af_xdp:enp175s0f0. + * MTL_PMD_NATIVE_AF_XDP, use native_af_xdp + ifname, ex: + * native_af_xdp:enp175s0f0. * * Below PMDs are only for experimental usage, not for production usage. * MTL_PMD_KERNEL_SOCKET, use kernel + ifname, ex: kernel:enp175s0f0. - * MTL_PMD_RDMA_UD with ST2110 packing, use rdma_ud + ifname, ex: rdma_ud:enp175s0f0. - * MTL_PMD_DPDK_AF_XDP, use dpdk_af_xdp + ifname, ex: dpdk_af_xdp:enp175s0f0. - * MTL_PMD_DPDK_AF_PACKET, use dpdk_af_packet + ifname, ex: dpdk_af_packet:enp175s0f0. + * MTL_PMD_RDMA_UD with ST2110 packing, use rdma_ud + ifname, ex: + * rdma_ud:enp175s0f0. MTL_PMD_DPDK_AF_XDP, use dpdk_af_xdp + ifname, ex: + * dpdk_af_xdp:enp175s0f0. MTL_PMD_DPDK_AF_PACKET, use dpdk_af_packet + + * ifname, ex: dpdk_af_packet:enp175s0f0. */ char port[MTL_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. The element number in the port array, 1 to MTL_PORT_MAX_LEN */ @@ -517,19 +526,19 @@ struct mtl_init_params { * Static(default) or DHCP(please make sure you have a DHCP server inside LAN) */ enum mtl_net_proto net_proto[MTL_PORT_MAX]; - /** Mandatory. dpdk user pmd(default) or af_xdp. Use mtl_pmd_by_port_name helper to get - * PMD type */ + /** Mandatory. dpdk user pmd(default) or af_xdp. Use mtl_pmd_by_port_name + * helper to get PMD type */ enum mtl_pmd_type pmd[MTL_PORT_MAX]; /** * Mandatory. Max NIC tx queues requested the lib to support. - * for MTL_TRANSPORT_ST2110, you can use helper api: st_tx_sessions_queue_cnt to - * calculate. + * for MTL_TRANSPORT_ST2110, you can use helper api: st_tx_sessions_queue_cnt + * to calculate. */ uint16_t tx_queues_cnt[MTL_PORT_MAX]; /** * Mandatory. Max NIC rx queues requested the lib to support. - * for MTL_TRANSPORT_ST2110, you can use helper api: st_rx_sessions_queue_cnt to - * calculate. + * for MTL_TRANSPORT_ST2110, you can use helper api: st_rx_sessions_queue_cnt + * to calculate. */ uint16_t rx_queues_cnt[MTL_PORT_MAX]; @@ -551,31 +560,35 @@ struct mtl_init_params { */ uint8_t gateway[MTL_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Optional. Flags to control MTL behaviors. See MTL_FLAG_* for possible value */ + /** Optional. Flags to control MTL behaviors. See MTL_FLAG_* for possible + * value */ uint64_t flags; - /** Optional. Private data to the cb functions(ptp_get_time_fn and stat_dump_cb_fn) */ - void* priv; + /** Optional. Private data to the cb functions(ptp_get_time_fn and + * stat_dump_cb_fn) */ + void *priv; /** Optional. log level control */ enum mtl_log_level log_level; /** - * Optional. The logical cores list can be used in the MTL, e.g. "28,29,30,31". - * If not assigned, the core usage will be determined by MTL itself. + * Optional. The logical cores list can be used in the MTL, e.g. + * "28,29,30,31". If not assigned, the core usage will be determined by MTL + * itself. */ - char* lcores; + char *lcores; /** * Optional. Dma(CBDMA or DSA) device can be used in the MTL. - * DMA can be used to offload the CPU for copy the payload for video rx sessions. - * See more from ST20_RX_FLAG_DMA_OFFLOAD in st20_api.h. - * PCIE BDF path like 0000:80:04.0. + * DMA can be used to offload the CPU for copy the payload for video rx + * sessions. See more from ST20_RX_FLAG_DMA_OFFLOAD in st20_api.h. PCIE BDF + * path like 0000:80:04.0. */ char dma_dev_port[MTL_DMA_DEV_MAX][MTL_PORT_MAX_LEN]; - /** Optional. The element number in the dma_dev_port array, leave to zero if no DMA */ + /** Optional. The element number in the dma_dev_port array, leave to zero if + * no DMA */ uint8_t num_dma_dev_port; /** - * Optional. If using rss (L3 or L4) for the rx packets classification, default use RTE - * flow director. + * Optional. If using rss (L3 or L4) for the rx packets classification, + * default use RTE flow director. */ enum mtl_rss_mode rss_mode; /** @@ -583,58 +596,61 @@ struct mtl_init_params { */ enum mtl_iova_mode iova_mode; /** - * Optional. Number of transmit descriptors for each NIC TX queue, 0 means determined by - * lib. It will affect the memory usage and the performance. + * Optional. Number of transmit descriptors for each NIC TX queue, 0 means + * determined by lib. It will affect the memory usage and the performance. */ uint16_t nb_tx_desc; /** - * Optional. Number of receive descriptors for each NIC RX queue, 0 means determined by - * lib. It will affect the memory usage and the performance. + * Optional. Number of receive descriptors for each NIC RX queue, 0 means + * determined by lib. It will affect the memory usage and the performance. */ uint16_t nb_rx_desc; /** * Optional. Function to acquire current ptp time(in nanoseconds) from user. - * If NULL, MTL will get from built-in ptp source(NIC) if built-in ptp4l is enabled or - * system time if built-in ptp4l is not enabled. + * If NULL, MTL will get from built-in ptp source(NIC) if built-in ptp4l is + * enabled or system time if built-in ptp4l is not enabled. */ - uint64_t (*ptp_get_time_fn)(void* priv); - /** Optional for MTL_FLAG_PTP_ENABLE. The callback is notified every time the built-in - * PTP protocol receives a valid PTP_DELAY_RESP message from the PTP grandmaster. */ - void (*ptp_sync_notify)(void* priv, struct mtl_ptp_sync_notify_meta* meta); - - /** Optional. Stats dump period in seconds, zero means determined by lib(10s default) */ + uint64_t (*ptp_get_time_fn)(void *priv); + /** Optional for MTL_FLAG_PTP_ENABLE. The callback is notified every time the + * built-in PTP protocol receives a valid PTP_DELAY_RESP message from the PTP + * grandmaster. */ + void (*ptp_sync_notify)(void *priv, struct mtl_ptp_sync_notify_meta *meta); + + /** Optional. Stats dump period in seconds, zero means determined by lib(10s + * default) */ uint16_t dump_period_s; /** Optional. Stats dump callback for user in every dump_period_s */ - void (*stat_dump_cb_fn)(void* priv); + void (*stat_dump_cb_fn)(void *priv); /** - * Optional for MTL_TRANSPORT_ST2110. The st21 tx pacing way, leave to zero(auto) if you - * don't known the detail. + * Optional for MTL_TRANSPORT_ST2110. The st21 tx pacing way, leave to + * zero(auto) if you don't known the detail. */ enum st21_tx_pacing_way pacing; /** - * Optional for MTL_TRANSPORT_ST2110. The max data quota for the sessions of each lcore - * can handled, 0 means determined by lib. If exceed this limit, the new created - * sessions will be scheduled to a new lcore. + * Optional for MTL_TRANSPORT_ST2110. The max data quota for the sessions of + * each lcore can handled, 0 means determined by lib. If exceed this limit, + * the new created sessions will be scheduled to a new lcore. */ uint32_t data_quota_mbs_per_sch; /** - * Optional for MTL_TRANSPORT_ST2110. The number of max tx audio session for each lcore, - * 0 means determined by lib */ + * Optional for MTL_TRANSPORT_ST2110. The number of max tx audio session for + * each lcore, 0 means determined by lib */ uint32_t tx_audio_sessions_max_per_sch; /** - * Optional for MTL_TRANSPORT_ST2110. The number of max rx audio session for each lcore, - * 0 means determined by lib */ + * Optional for MTL_TRANSPORT_ST2110. The number of max rx audio session for + * each lcore, 0 means determined by lib */ uint32_t rx_audio_sessions_max_per_sch; /** - * Optional for MTL_TRANSPORT_ST2110. Suggest max allowed udp size for each network pkt, - * leave to zero if you don't known detail. + * Optional for MTL_TRANSPORT_ST2110. Suggest max allowed udp size for each + * network pkt, leave to zero if you don't known detail. */ uint16_t pkt_udp_suggest_max_size; /** - * Optional for MTL_TRANSPORT_ST2110. The number for hdr split queues of rx, should be - * smaller than rx_sessions_cnt_max. Experimental feature for header split. + * Optional for MTL_TRANSPORT_ST2110. The number for hdr split queues of rx, + * should be smaller than rx_sessions_cnt_max. Experimental feature for header + * split. */ uint16_t nb_rx_hdr_split_queues; /** @@ -643,22 +659,27 @@ struct mtl_init_params { * some NICs may need this to avoid mbuf split. */ uint16_t rx_pool_data_size; - /** Optional. the maximum number of memzones in DPDK, leave zero to use default 2560 */ + /** Optional. the maximum number of memzones in DPDK, leave zero to use + * default 2560 */ uint32_t memzone_max; - /** Optional. The number of tasklets for each lcore, 0 means determined by lib */ + /** Optional. The number of tasklets for each lcore, 0 means determined by lib + */ uint32_t tasklets_nb_per_sch; /** Optional. - * Set the ARP timeout value in seconds for ST2110 sessions when using a unicast - * address. Leave to zero to use the system's default timeout of 60 seconds. + * Set the ARP timeout value in seconds for ST2110 sessions when using a + * unicast address. Leave to zero to use the system's default timeout of 60 + * seconds. */ uint16_t arp_timeout_s; - /** Optional. Number of scheduler(lcore) used for rss dispatch, 0 means only 1 core */ + /** Optional. Number of scheduler(lcore) used for rss dispatch, 0 means only 1 + * core */ uint16_t rss_sch_nb[MTL_PORT_MAX]; - /** Optional for MTL_FLAG_PTP_ENABLE. The ptp pi controller proportional gain. */ + /** Optional for MTL_FLAG_PTP_ENABLE. The ptp pi controller proportional gain. + */ double kp; /** Optional for MTL_FLAG_PTP_ENABLE. The ptp pi controller integral gain. */ double ki; @@ -666,30 +687,35 @@ struct mtl_init_params { /** Optional, all future port params should be placed into this struct */ struct mtl_port_init_params port_params[MTL_PORT_MAX]; - /* The Core ID that is used as DPDK main thread, leave to zero is good for most case */ + /* The Core ID that is used as DPDK main thread, leave to zero is good for + * most case */ uint32_t main_lcore; /** * deprecated for MTL_TRANSPORT_ST2110. * max tx sessions(st20, st22, st30, st40) requested the lib to support, * use mtl_get_fix_info to query the actual count. - * dpdk context will allocate the hw resources(queues, memory) based on this number. + * dpdk context will allocate the hw resources(queues, memory) based on this + * number. */ #ifdef __MTL_LIB_BUILD__ uint16_t tx_sessions_cnt_max; #else - uint16_t tx_sessions_cnt_max __mtl_deprecated_msg("Use tx_queues_cnt instead"); + uint16_t + tx_sessions_cnt_max __mtl_deprecated_msg("Use tx_queues_cnt instead"); #endif /** * deprecated for MTL_TRANSPORT_ST2110. * max rx sessions(st20, st22, st30, st40) requested the lib to support, * use mtl_get_fix_info to query the actual count. - * dpdk context will allocate the hw resources(queues, memory) based on this number. + * dpdk context will allocate the hw resources(queues, memory) based on this + * number. */ #ifdef __MTL_LIB_BUILD__ uint16_t rx_sessions_cnt_max; #else - uint16_t rx_sessions_cnt_max __mtl_deprecated_msg("Use rx_queues_cnt instead"); + uint16_t + rx_sessions_cnt_max __mtl_deprecated_msg("Use rx_queues_cnt instead"); #endif }; @@ -733,7 +759,8 @@ struct mtl_port_status { uint64_t tx_bytes; /** Total number of failed received packets. */ uint64_t rx_err_packets; - /** Total number of received packets dropped by the HW. (i.e. Rx queues are full) */ + /** Total number of received packets dropped by the HW. (i.e. Rx queues are + * full) */ uint64_t rx_hw_dropped_packets; /** Total number of Rx mbuf allocation failures. */ uint64_t rx_nombuf_packets; @@ -752,7 +779,7 @@ struct mtl_port_status { * - 0 if successful. * - <0: Error code if fail. */ -int mtl_get_fix_info(mtl_handle mt, struct mtl_fix_info* info); +int mtl_get_fix_info(mtl_handle mt, struct mtl_fix_info *info); /** * Retrieve the varied information of an MTL instance. @@ -765,7 +792,7 @@ int mtl_get_fix_info(mtl_handle mt, struct mtl_fix_info* info); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_get_var_info(mtl_handle mt, struct mtl_var_info* info); +int mtl_get_var_info(mtl_handle mt, struct mtl_var_info *info); /** * Retrieve the general statistics(I/O) for a MTL port. @@ -780,7 +807,8 @@ int mtl_get_var_info(mtl_handle mt, struct mtl_var_info* info); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status* stats); +int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, + struct mtl_port_status *stats); /** * Reset the general statistics(I/O) for a MTL port. @@ -809,33 +837,40 @@ int mtl_reset_port_stats(mtl_handle mt, enum mtl_port port); int mtl_get_numa_id(mtl_handle mt, enum mtl_port port); /** Helper to set the port for struct mtl_init_params */ -int mtl_para_port_set(struct mtl_init_params* p, enum mtl_port port, char* name); +int mtl_para_port_set(struct mtl_init_params *p, enum mtl_port port, + char *name); /** Helper to set the sip for struct mtl_init_params */ -int mtl_para_sip_set(struct mtl_init_params* p, enum mtl_port port, char* ip); +int mtl_para_sip_set(struct mtl_init_params *p, enum mtl_port port, char *ip); /** Helper to set the gateway for struct mtl_init_params */ -int mtl_para_gateway_set(struct mtl_init_params* p, enum mtl_port port, char* gateway); +int mtl_para_gateway_set(struct mtl_init_params *p, enum mtl_port port, + char *gateway); /** Helper to set the netmask for struct mtl_init_params */ -int mtl_para_netmask_set(struct mtl_init_params* p, enum mtl_port port, char* netmask); +int mtl_para_netmask_set(struct mtl_init_params *p, enum mtl_port port, + char *netmask); /** Helper to set the dma dev port for struct mtl_init_params */ -int mtl_para_dma_port_set(struct mtl_init_params* p, enum mtl_port port, char* name); +int mtl_para_dma_port_set(struct mtl_init_params *p, enum mtl_port port, + char *name); /** Helper to set the tx queues number for struct mtl_init_params */ -static inline void mtl_para_tx_queues_cnt_set(struct mtl_init_params* p, - enum mtl_port port, uint16_t cnt) { +static inline void mtl_para_tx_queues_cnt_set(struct mtl_init_params *p, + enum mtl_port port, + uint16_t cnt) { p->tx_queues_cnt[port] = cnt; } /** Helper to set the rx queues number for struct mtl_init_params */ -static inline void mtl_para_rx_queues_cnt_set(struct mtl_init_params* p, - enum mtl_port port, uint16_t cnt) { +static inline void mtl_para_rx_queues_cnt_set(struct mtl_init_params *p, + enum mtl_port port, + uint16_t cnt) { p->rx_queues_cnt[port] = cnt; } /** Helper to set the PMD type for struct mtl_init_params */ -static inline void mtl_para_pmd_set(struct mtl_init_params* p, enum mtl_port port, - enum mtl_pmd_type pmd) { +static inline void mtl_para_pmd_set(struct mtl_init_params *p, + enum mtl_port port, enum mtl_pmd_type pmd) { p->pmd[port] = pmd; } /** Helper to get the port from struct mtl_init_params */ -static inline char* mtl_para_port_get(struct mtl_init_params* p, enum mtl_port port) { +static inline char *mtl_para_port_get(struct mtl_init_params *p, + enum mtl_port port) { return p->port[port]; } @@ -846,7 +881,7 @@ static inline char* mtl_para_port_get(struct mtl_init_params* p, enum mtl_port p * @return * Primary port name pointer */ -static inline char* mtl_p_port(struct mtl_init_params* p) { +static inline char *mtl_p_port(struct mtl_init_params *p) { return mtl_para_port_get(p, MTL_PORT_P); } @@ -857,7 +892,7 @@ static inline char* mtl_p_port(struct mtl_init_params* p) { * @return * Redundant port name pointer */ -static inline char* mtl_r_port(struct mtl_init_params* p) { +static inline char *mtl_r_port(struct mtl_init_params *p) { return mtl_para_port_get(p, MTL_PORT_R); } @@ -869,7 +904,7 @@ static inline char* mtl_r_port(struct mtl_init_params* p) { * @return * Primary port IP address pointer */ -static inline uint8_t* mtl_p_sip_addr(struct mtl_init_params* p) { +static inline uint8_t *mtl_p_sip_addr(struct mtl_init_params *p) { return p->sip_addr[MTL_PORT_P]; } @@ -881,7 +916,7 @@ static inline uint8_t* mtl_p_sip_addr(struct mtl_init_params* p) { * @return * Redundant port IP address pointer */ -static inline uint8_t* mtl_r_sip_addr(struct mtl_init_params* p) { +static inline uint8_t *mtl_r_sip_addr(struct mtl_init_params *p) { return p->sip_addr[MTL_PORT_R]; } @@ -890,7 +925,7 @@ static inline uint8_t* mtl_r_sip_addr(struct mtl_init_params* p) { * @return * ST version string */ -const char* mtl_version(void); +const char *mtl_version(void); /** * Initialize the MTL transport device context which based on DPDK. @@ -901,7 +936,7 @@ const char* mtl_version(void); * - NULL on error. * - Otherwise, the handle to the MTL transport device context. */ -mtl_handle mtl_init(struct mtl_init_params* p); +mtl_handle mtl_init(struct mtl_init_params *p); /** * Un-initialize the MTL transport device context. @@ -993,14 +1028,14 @@ enum mtl_log_level mtl_get_log_level(mtl_handle mt); int mtl_set_log_prefix_formatter(mtl_log_prefix_formatter_t f); /** - * Set up a custom log printer for the user. By default, MTL uses `RTE_LOG` for outputting - * logs. However, applications can register a customized log printer using this function. - * Whenever MTL needs to log anything, the registered log callback will be invoked. + * Set up a custom log printer for the user. By default, MTL uses `RTE_LOG` for + * outputting logs. However, applications can register a customized log printer + * using this function. Whenever MTL needs to log anything, the registered log + * callback will be invoked. * * A example printer is like below: - * static void log_user_printer(enum mtl_log_level level, const char* format, ...) { - * MTL_MAY_UNUSED(level); - * va_list args; + * static void log_user_printer(enum mtl_log_level level, const char* format, + * ...) { MTL_MAY_UNUSED(level); va_list args; * * // Init variadic argument list * va_start(args, format); @@ -1030,7 +1065,7 @@ int mtl_set_log_printer(mtl_log_printer_t f); * - 0: Success. * - <0: Error code. */ -int mtl_openlog_stream(FILE* f); +int mtl_openlog_stream(FILE *f); /** * Enable or disable sleep mode for sch. @@ -1072,7 +1107,7 @@ int mtl_sch_set_sleep_us(mtl_handle mt, uint64_t us); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_get_lcore(mtl_handle mt, unsigned int* lcore); +int mtl_get_lcore(mtl_handle mt, unsigned int *lcore); /** * Bind one thread to lcore. @@ -1090,7 +1125,8 @@ int mtl_get_lcore(mtl_handle mt, unsigned int* lcore); int mtl_bind_to_lcore(mtl_handle mt, pthread_t thread, unsigned int lcore); /** - * Put back the DPDK lcore which requested from the MTL transport device context. + * Put back the DPDK lcore which requested from the MTL transport device + * context. * * @param mt * The handle to the MTL transport device context. @@ -1114,7 +1150,7 @@ int mtl_put_lcore(mtl_handle mt, unsigned int lcore); * @return * - Pointer to the destination data. */ -void* mtl_memcpy(void* dest, const void* src, size_t n); +void *mtl_memcpy(void *dest, const void *src, size_t n); /** * Read cached time from ptp source. @@ -1139,7 +1175,8 @@ uint64_t mtl_ptp_read_time_raw(mtl_handle mt); /** * Allocate memory from the huge-page area of memory. The memory is not cleared. * In NUMA systems, the memory allocated from the same NUMA socket of the port. - * Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get the iova. + * Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get the + * iova. * * @param mt * The handle to the MTL transport device context. @@ -1151,13 +1188,14 @@ uint64_t mtl_ptp_read_time_raw(mtl_handle mt); * - NULL on error. Not enough memory, or invalid arguments * - Otherwise, the pointer to the allocated memory. */ -void* mtl_hp_malloc(mtl_handle mt, size_t size, enum mtl_port port); +void *mtl_hp_malloc(mtl_handle mt, size_t size, enum mtl_port port); /** * Allocate zero'ed memory from the huge-page area of memory. - * Equivalent to mtl_hp_malloc() except that the memory zone is cleared with zero. - * In NUMA systems, the memory allocated from the same NUMA socket of the port. - * Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get the iova. + * Equivalent to mtl_hp_malloc() except that the memory zone is cleared with + * zero. In NUMA systems, the memory allocated from the same NUMA socket of the + * port. Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get + * the iova. * * @param mt * The handle to the MTL transport device context. @@ -1169,7 +1207,7 @@ void* mtl_hp_malloc(mtl_handle mt, size_t size, enum mtl_port port); * - NULL on error. Not enough memory, or invalid arguments * - Otherwise, the virtual address pointer to the allocated memory. */ -void* mtl_hp_zmalloc(mtl_handle mt, size_t size, enum mtl_port port); +void *mtl_hp_zmalloc(mtl_handle mt, size_t size, enum mtl_port port); /** * Frees the memory pointed by the pointer. @@ -1183,7 +1221,7 @@ void* mtl_hp_zmalloc(mtl_handle mt, size_t size, enum mtl_port port); * @param ptr * The virtual address pointer to memory to be freed. */ -void mtl_hp_free(mtl_handle mt, void* ptr); +void mtl_hp_free(mtl_handle mt, void *ptr); /** * Return the IO address of a virtual address from mtl_hp_malloc/mtl_hp_zmalloc @@ -1196,7 +1234,7 @@ void mtl_hp_free(mtl_handle mt, void* ptr); * MTL_BAD_IOVA on error * otherwise return an address suitable for IO */ -mtl_iova_t mtl_hp_virt2iova(mtl_handle mt, const void* vaddr); +mtl_iova_t mtl_hp_virt2iova(mtl_handle mt, const void *vaddr); /** * Return the detected page size on the system. @@ -1239,7 +1277,7 @@ void mtl_delay_us(unsigned int us); * MTL_BAD_IOVA on error * otherwise return an address suitable for IO */ -mtl_iova_t mtl_dma_map(mtl_handle mt, const void* vaddr, size_t size); +mtl_iova_t mtl_dma_map(mtl_handle mt, const void *vaddr, size_t size); /** * Perform DMA unmapping on the mtl_dma_map @@ -1257,7 +1295,8 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void* vaddr, size_t size); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_dma_unmap(mtl_handle mt, const void* vaddr, mtl_iova_t iova, size_t size); +int mtl_dma_unmap(mtl_handle mt, const void *vaddr, mtl_iova_t iova, + size_t size); /** * Allocate memory block more than required and map valid data to IOVA. @@ -1303,7 +1342,7 @@ void mtl_dma_mem_free(mtl_handle mt, mtl_dma_mem_handle handle); * @return * - Begin address of dma mapped memory. */ -void* mtl_dma_mem_addr(mtl_dma_mem_handle handle); +void *mtl_dma_mem_addr(mtl_dma_mem_handle handle); /** * Get the begin IOVA of dma mapped memory. @@ -1329,7 +1368,8 @@ mtl_iova_t mtl_dma_mem_iova(mtl_dma_mem_handle handle); * - NULL on error. * - Otherwise, the handle to the st user dma dev. */ -mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, enum mtl_port port); +mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, + enum mtl_port port); /** * Free the st user dma dev. @@ -1473,8 +1513,10 @@ enum mtl_iova_mode mtl_iova_mode_get(mtl_handle mt); * - 0: Success. * - <0: Error code. */ -int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, uint8_t ip[MTL_IP_ADDR_LEN], - uint8_t netmask[MTL_IP_ADDR_LEN], uint8_t gateway[MTL_IP_ADDR_LEN]); +int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, + uint8_t ip[MTL_IP_ADDR_LEN], + uint8_t netmask[MTL_IP_ADDR_LEN], + uint8_t gateway[MTL_IP_ADDR_LEN]); /** * Check if the pmd of one mtl port is dpdk based or not. @@ -1485,7 +1527,8 @@ int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, uint8_t ip[MTL_IP_ADDR_L * The port. * @return * - true: a DPDK based PMD. - * - false: not a DPDK based PMD, MTL_PMD_KERNEL_SOCKET or MTL_PMD_NATIVE_AF_XDP. + * - false: not a DPDK based PMD, MTL_PMD_KERNEL_SOCKET or + * MTL_PMD_NATIVE_AF_XDP. */ bool mtl_pmd_is_dpdk_based(mtl_handle mt, enum mtl_port port); @@ -1505,7 +1548,7 @@ enum mtl_simd_level mtl_get_simd_level(void); * @return * simd level name */ -const char* mtl_get_simd_level_name(enum mtl_simd_level level); +const char *mtl_get_simd_level_name(enum mtl_simd_level level); /** * Helper function to get pmd type by port name. @@ -1515,7 +1558,7 @@ const char* mtl_get_simd_level_name(enum mtl_simd_level level); * @return * pmd type. */ -enum mtl_pmd_type mtl_pmd_by_port_name(const char* port); +enum mtl_pmd_type mtl_pmd_by_port_name(const char *port); /** * Helper function to check if it's a af_xdp based pmd. @@ -1543,7 +1586,7 @@ static inline bool mtl_pmd_is_af_xdp(enum mtl_pmd_type pmd) { * - 0: Success. * - <0: Error code. */ -int mtl_get_if_ip(char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], +int mtl_get_if_ip(char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]); /** @@ -1556,7 +1599,7 @@ int mtl_get_if_ip(char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], * - 0: Success. * - <0: Error code. */ -int mtl_thread_setname(pthread_t tid, const char* name); +int mtl_thread_setname(pthread_t tid, const char *name); /** * Helper function which align a size with pages @@ -1569,7 +1612,8 @@ int mtl_thread_setname(pthread_t tid, const char* name); * The aligned size. */ static inline size_t mtl_size_page_align(size_t sz, size_t pg_sz) { - if (sz % pg_sz) sz += pg_sz - (sz % pg_sz); + if (sz % pg_sz) + sz += pg_sz - (sz % pg_sz); return sz; } @@ -1580,8 +1624,8 @@ struct mtl_memcpy_ops { size_t sz; }; /** Helper function to perform mtl_memcpy with mtl_cpuva_t */ -static inline int mtl_memcpy_action(struct mtl_memcpy_ops* ops) { - mtl_memcpy((void*)ops->dst, (const void*)ops->src, ops->sz); +static inline int mtl_memcpy_action(struct mtl_memcpy_ops *ops) { + mtl_memcpy((void *)ops->dst, (const void *)ops->src, ops->sz); return 0; } diff --git a/include/mtl_lcore_shm_api.h b/include/mtl_lcore_shm_api.h index e1db99a5c..a7a2adbb4 100644 --- a/include/mtl_lcore_shm_api.h +++ b/include/mtl_lcore_shm_api.h @@ -56,7 +56,8 @@ int mtl_lcore_shm_print(void); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void* args, size_t args_sz); +int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void *args, + size_t args_sz); #if defined(__cplusplus) } diff --git a/include/mtl_sch_api.h b/include/mtl_sch_api.h index 151ec8911..6e86df85a 100644 --- a/include/mtl_sch_api.h +++ b/include/mtl_sch_api.h @@ -21,8 +21,8 @@ extern "C" { /** * Handle to mtl sch context */ -typedef struct mtl_sch_impl* mtl_sch_handle; -typedef struct mt_sch_tasklet_impl* mtl_tasklet_handle; +typedef struct mtl_sch_impl *mtl_sch_handle; +typedef struct mt_sch_tasklet_impl *mtl_tasklet_handle; /** the tasklet is likely has pending task */ #define MTL_TASKLET_HAS_PENDING (1) @@ -34,31 +34,33 @@ typedef struct mt_sch_tasklet_impl* mtl_tasklet_handle; */ struct mtl_sch_ops { /** name */ - const char* name; - /** the max number of tasklet in this sch, leave to zero to use the default value */ + const char *name; + /** the max number of tasklet in this sch, leave to zero to use the default + * value */ uint32_t nb_tasklets; }; /** - * The structure describing how to create a tasklet. Tasklet share the time slot on a - * sch, only non-block method can be used in handler routine. + * The structure describing how to create a tasklet. Tasklet share the time slot + * on a sch, only non-block method can be used in handler routine. */ struct mtl_tasklet_ops { /** name */ - const char* name; + const char *name; /** private data to the callback */ - void* priv; + void *priv; /** the callback at the time when the sch started */ - int (*start)(void* priv); + int (*start)(void *priv); /** the callback at the time when the sch stopped */ - int (*stop)(void* priv); + int (*stop)(void *priv); /** - * the callback for task routine, only non-block method can be used for this callback - * since all tasklets share the CPU time. Return MTL_TASKLET_ALL_DONE if no any pending - * task, all are done. Return MTL_TASKLET_HAS_PENDING if it has pending tasks. + * the callback for task routine, only non-block method can be used for this + * callback since all tasklets share the CPU time. Return MTL_TASKLET_ALL_DONE + * if no any pending task, all are done. Return MTL_TASKLET_HAS_PENDING if it + * has pending tasks. */ - int (*handler)(void* priv); + int (*handler)(void *priv); /** * the recommend sleep time(us) if all tasklet report MTL_TASKLET_ALL_DONE. * also this value can be set by mtl_tasklet_set_sleep at runtime. @@ -78,7 +80,7 @@ struct mtl_tasklet_ops { * - NULL on error. * - Otherwise, the handle to the sch. */ -mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops* ops); +mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops *ops); /** * Start the sch. @@ -114,8 +116,8 @@ int mtl_sch_stop(mtl_sch_handle sch); int mtl_sch_free(mtl_sch_handle sch); /** - * Register one tasklet into the sch. One tasklet can be registered at runtime after - * mtl_sch_start. + * Register one tasklet into the sch. One tasklet can be registered at runtime + * after mtl_sch_start. * * @param sch * The sch context. @@ -125,12 +127,13 @@ int mtl_sch_free(mtl_sch_handle sch); * - NULL on error. * - Otherwise, the handle to the tasklet. */ -mtl_tasklet_handle mtl_sch_register_tasklet(struct mtl_sch_impl* sch, - struct mtl_tasklet_ops* tasklet_ops); +mtl_tasklet_handle +mtl_sch_register_tasklet(struct mtl_sch_impl *sch, + struct mtl_tasklet_ops *tasklet_ops); /** - * Unregister the tasklet from the bind sch. One tasklet can be unregistered at runtime - * before mtl_sch_start. + * Unregister the tasklet from the bind sch. One tasklet can be unregistered at + * runtime before mtl_sch_start. * * @param sch * The handle to sch context. diff --git a/include/mudp_api.h b/include/mudp_api.h index fa650acda..0e22f97ec 100644 --- a/include/mudp_api.h +++ b/include/mudp_api.h @@ -27,7 +27,7 @@ extern "C" { /** * Handle to udp transport context */ -typedef struct mudp_impl* mudp_handle; +typedef struct mudp_impl *mudp_handle; /** * Create a udp transport socket. @@ -70,7 +70,7 @@ int mudp_close(mudp_handle ut); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mudp_bind(mudp_handle ut, const struct sockaddr* addr, socklen_t addrlen); +int mudp_bind(mudp_handle ut, const struct sockaddr *addr, socklen_t addrlen); /** * Send data on the udp transport socket. @@ -87,13 +87,14 @@ int mudp_bind(mudp_handle ut, const struct sockaddr* addr, socklen_t addrlen); * @param dest_addr * The address specified, only AF_INET now. * @param addrlen - * Specifies the size, in bytes, of the address structure pointed to by dest_addr. + * Specifies the size, in bytes, of the address structure pointed to by + * dest_addr. * @return * - >0: the number of bytes sent. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mudp_sendto(mudp_handle ut, const void* buf, size_t len, int flags, - const struct sockaddr* dest_addr, socklen_t addrlen); +ssize_t mudp_sendto(mudp_handle ut, const void *buf, size_t len, int flags, + const struct sockaddr *dest_addr, socklen_t addrlen); /** * Send data on the udp transport socket. @@ -108,7 +109,7 @@ ssize_t mudp_sendto(mudp_handle ut, const void* buf, size_t len, int flags, * - >0: the number of bytes sent. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr* msg, int flags); +ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr *msg, int flags); /** * The structure describing a polling request on mudp. @@ -143,7 +144,7 @@ typedef unsigned long int mudp_nfds_t; * - =0: Timeout. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mudp_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout); +int mudp_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout); /** * Receive data on the udp transport socket. @@ -159,13 +160,14 @@ int mudp_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout); * @param src_addr * The address specified, only AF_INET now. * @param addrlen - * Specifies the size, in bytes, of the address structure pointed to by src_addr. + * Specifies the size, in bytes, of the address structure pointed to by + * src_addr. * @return * - >0: the number of bytes received. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mudp_recvfrom(mudp_handle ut, void* buf, size_t len, int flags, - struct sockaddr* src_addr, socklen_t* addrlen); +ssize_t mudp_recvfrom(mudp_handle ut, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen); /** * Receive data on the udp transport socket. @@ -182,7 +184,8 @@ ssize_t mudp_recvfrom(mudp_handle ut, void* buf, size_t len, int flags, * - >0: the number of bytes received. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -static inline ssize_t mudp_recv(mudp_handle ut, void* buf, size_t len, int flags) { +static inline ssize_t mudp_recv(mudp_handle ut, void *buf, size_t len, + int flags) { return mudp_recvfrom(ut, buf, len, flags, NULL, NULL); } @@ -199,7 +202,7 @@ static inline ssize_t mudp_recv(mudp_handle ut, void* buf, size_t len, int flags * - >0: the number of bytes received. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mudp_recvmsg(mudp_handle ut, struct msghdr* msg, int flags); +ssize_t mudp_recvmsg(mudp_handle ut, struct msghdr *msg, int flags); /** * getsockopt on the udp transport socket. @@ -219,8 +222,8 @@ ssize_t mudp_recvmsg(mudp_handle ut, struct msghdr* msg, int flags); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mudp_getsockopt(mudp_handle ut, int level, int optname, void* optval, - socklen_t* optlen); +int mudp_getsockopt(mudp_handle ut, int level, int optname, void *optval, + socklen_t *optlen); /** * setsockopt on the udp transport socket. @@ -240,7 +243,7 @@ int mudp_getsockopt(mudp_handle ut, int level, int optname, void* optval, * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mudp_setsockopt(mudp_handle ut, int level, int optname, const void* optval, +int mudp_setsockopt(mudp_handle ut, int level, int optname, const void *optval, socklen_t optlen); /** @@ -257,8 +260,9 @@ int mudp_setsockopt(mudp_handle ut, int level, int optname, const void* optval, int mudp_ioctl(mudp_handle ut, unsigned long cmd, va_list args); /** - * Set the tx dst mac for the udp transport socket. MTL focus on data plane and only has - * ARP support. For the WAN transport, user can use this API to manual set the dst mac. + * Set the tx dst mac for the udp transport socket. MTL focus on data plane and + * only has ARP support. For the WAN transport, user can use this API to manual + * set the dst mac. * * @param ut * The handle to udp transport socket. @@ -466,7 +470,8 @@ int mudp_tx_valid_ip(mudp_handle ut, uint8_t dip[MTL_IP_ADDR_LEN]); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void* priv), void* priv); +int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void *priv), + void *priv); /** * Create a udp transport socket on a PCIE port. @@ -496,7 +501,8 @@ mudp_handle mudp_socket_port(mtl_handle mt, int domain, int type, int protocol, * @param port * UDP port. */ -static void inline mudp_init_sockaddr_any(struct sockaddr_in* saddr, uint16_t port) { +static void inline mudp_init_sockaddr_any(struct sockaddr_in *saddr, + uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; saddr->sin_addr.s_addr = INADDR_ANY; @@ -513,8 +519,9 @@ static void inline mudp_init_sockaddr_any(struct sockaddr_in* saddr, uint16_t po * @param port * UDP port. */ -static void inline mudp_init_sockaddr(struct sockaddr_in* saddr, - uint8_t ip[MTL_IP_ADDR_LEN], uint16_t port) { +static void inline mudp_init_sockaddr(struct sockaddr_in *saddr, + uint8_t ip[MTL_IP_ADDR_LEN], + uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; memcpy(&saddr->sin_addr.s_addr, ip, MTL_IP_ADDR_LEN); @@ -529,7 +536,7 @@ static void inline mudp_init_sockaddr(struct sockaddr_in* saddr, * @return * - multicast or not. */ -bool mudp_is_multicast(const struct sockaddr_in* saddr); +bool mudp_is_multicast(const struct sockaddr_in *saddr); #if defined(__cplusplus) } diff --git a/include/mudp_sockfd_api.h b/include/mudp_sockfd_api.h index 3ee3dbaa3..378613088 100644 --- a/include/mudp_sockfd_api.h +++ b/include/mudp_sockfd_api.h @@ -71,7 +71,7 @@ int mufd_close(int sockfd); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen); +int mufd_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); /** * Send data on the udp transport socket. @@ -88,13 +88,14 @@ int mufd_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen); * @param dest_addr * The address specified, only AF_INET now. * @param addrlen - * Specifies the size, in bytes, of the address structure pointed to by dest_addr. + * Specifies the size, in bytes, of the address structure pointed to by + * dest_addr. * @return * - >0: the number of bytes sent. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mufd_sendto(int sockfd, const void* buf, size_t len, int flags, - const struct sockaddr* dest_addr, socklen_t addrlen); +ssize_t mufd_sendto(int sockfd, const void *buf, size_t len, int flags, + const struct sockaddr *dest_addr, socklen_t addrlen); /** * Send data on the udp transport socket. @@ -109,7 +110,7 @@ ssize_t mufd_sendto(int sockfd, const void* buf, size_t len, int flags, * - >0: the number of bytes sent. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mufd_sendmsg(int sockfd, const struct msghdr* msg, int flags); +ssize_t mufd_sendmsg(int sockfd, const struct msghdr *msg, int flags); /** * Poll the udp transport socket, blocks until one of the events occurs. @@ -127,7 +128,7 @@ ssize_t mufd_sendmsg(int sockfd, const struct msghdr* msg, int flags); * - =0: Timeosockfd. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_poll(struct pollfd* fds, nfds_t nfds, int timeout); +int mufd_poll(struct pollfd *fds, nfds_t nfds, int timeout); /** * Receive data on the udp transport socket. @@ -143,13 +144,14 @@ int mufd_poll(struct pollfd* fds, nfds_t nfds, int timeout); * @param src_addr * The address specified, only AF_INET now. * @param addrlen - * Specifies the size, in bytes, of the address structure pointed to by src_addr. + * Specifies the size, in bytes, of the address structure pointed to by + * src_addr. * @return * - >0: the number of bytes received. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mufd_recvfrom(int sockfd, void* buf, size_t len, int flags, - struct sockaddr* src_addr, socklen_t* addrlen); +ssize_t mufd_recvfrom(int sockfd, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen); /** * Receive data on the udp transport socket. @@ -166,7 +168,7 @@ ssize_t mufd_recvfrom(int sockfd, void* buf, size_t len, int flags, * - >0: the number of bytes received. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -static inline ssize_t mufd_recv(int sockfd, void* buf, size_t len, int flags) { +static inline ssize_t mufd_recv(int sockfd, void *buf, size_t len, int flags) { return mufd_recvfrom(sockfd, buf, len, flags, NULL, NULL); } @@ -183,7 +185,7 @@ static inline ssize_t mufd_recv(int sockfd, void* buf, size_t len, int flags) { * - >0: the number of bytes received. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -ssize_t mufd_recvmsg(int sockfd, struct msghdr* msg, int flags); +ssize_t mufd_recvmsg(int sockfd, struct msghdr *msg, int flags); /** * getsockopt on the udp transport socket. @@ -203,7 +205,8 @@ ssize_t mufd_recvmsg(int sockfd, struct msghdr* msg, int flags); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_getsockopt(int sockfd, int level, int optname, void* optval, socklen_t* optlen); +int mufd_getsockopt(int sockfd, int level, int optname, void *optval, + socklen_t *optlen); /** * setsockopt on the udp transport socket. @@ -223,7 +226,7 @@ int mufd_getsockopt(int sockfd, int level, int optname, void* optval, socklen_t* * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_setsockopt(int sockfd, int level, int optname, const void* optval, +int mufd_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); /** @@ -274,8 +277,9 @@ int mufd_cleanup(void); int mufd_abort(void); /** - * Set the tx dst mac for the udp transport socket. MTL focus on data plane and only has - * ARP support. For the WAN transport, user can use this API to manual set the dst mac. + * Set the tx dst mac for the udp transport socket. MTL focus on data plane and + * only has ARP support. For the WAN transport, user can use this API to manual + * set the dst mac. * * @param sockfd * The handle to udp transport socket. @@ -324,7 +328,8 @@ uint64_t mufd_get_tx_rate(int sockfd); * - <0: Error code. */ int mufd_port_ip_info(enum mtl_port port, uint8_t ip[MTL_IP_ADDR_LEN], - uint8_t netmask[MTL_IP_ADDR_LEN], uint8_t gateway[MTL_IP_ADDR_LEN]); + uint8_t netmask[MTL_IP_ADDR_LEN], + uint8_t gateway[MTL_IP_ADDR_LEN]); /** * Create a sockfd udp transport socket on one PCIE port. @@ -351,7 +356,8 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port); * @param port * UDP port. */ -static void inline mufd_init_sockaddr_any(struct sockaddr_in* saddr, uint16_t port) { +static void inline mufd_init_sockaddr_any(struct sockaddr_in *saddr, + uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; saddr->sin_addr.s_addr = INADDR_ANY; @@ -368,8 +374,9 @@ static void inline mufd_init_sockaddr_any(struct sockaddr_in* saddr, uint16_t po * @param port * UDP port. */ -static void inline mufd_init_sockaddr(struct sockaddr_in* saddr, - uint8_t ip[MTL_IP_ADDR_LEN], uint16_t port) { +static void inline mufd_init_sockaddr(struct sockaddr_in *saddr, + uint8_t ip[MTL_IP_ADDR_LEN], + uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; memcpy(&saddr->sin_addr.s_addr, ip, MTL_IP_ADDR_LEN); diff --git a/include/mudp_sockfd_internal.h b/include/mudp_sockfd_internal.h index e6d3d7a65..990c776d3 100644 --- a/include/mudp_sockfd_internal.h +++ b/include/mudp_sockfd_internal.h @@ -48,7 +48,7 @@ struct mufd_override_params { * - >=0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_commit_override_params(struct mufd_override_params* p); +int mufd_commit_override_params(struct mufd_override_params *p); /** * All init params should be parsed from MUFD_CFG_ENV_NAME json config file. @@ -84,7 +84,7 @@ struct mufd_init_params { * - >=0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_commit_init_params(struct mufd_init_params* p); +int mufd_commit_init_params(struct mufd_init_params *p); /** * Get the session nb of mufd context. @@ -133,7 +133,7 @@ enum mtl_log_level mufd_log_level(void); * - >=0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_set_opaque(int sockfd, void* pri); +int mufd_set_opaque(int sockfd, void *pri); /** * Get private opaque data on the udp transport socket. @@ -144,7 +144,7 @@ int mufd_set_opaque(int sockfd, void* pri); * @return * - The opaque data pointer. */ -void* mufd_get_opaque(int sockfd); +void *mufd_get_opaque(int sockfd); /** * Get IP address of the udp transport socket. @@ -185,12 +185,13 @@ int mufd_tx_valid_ip(int sockfd, uint8_t dip[MTL_IP_ADDR_LEN]); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_register_stat_dump_cb(int sockfd, int (*dump)(void* priv), void* priv); +int mufd_register_stat_dump_cb(int sockfd, int (*dump)(void *priv), void *priv); /** * Allocate memory from the huge-page area of memory. The memory is not cleared. * In NUMA systems, the memory allocated from the same NUMA socket of the port. - * Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get the iova. + * Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get the + * iova. * * @param size * Size (in bytes) to be allocated. @@ -200,13 +201,14 @@ int mufd_register_stat_dump_cb(int sockfd, int (*dump)(void* priv), void* priv); * - NULL on error. Not enough memory, or invalid arguments * - Otherwise, the pointer to the allocated memory. */ -void* mufd_hp_malloc(size_t size, enum mtl_port port); +void *mufd_hp_malloc(size_t size, enum mtl_port port); /** * Allocate zero'ed memory from the huge-page area of memory. - * Equivalent to mufd_hp_malloc() except that the memory zone is cleared with zero. - * In NUMA systems, the memory allocated from the same NUMA socket of the port. - * Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get the iova. + * Equivalent to mufd_hp_malloc() except that the memory zone is cleared with + * zero. In NUMA systems, the memory allocated from the same NUMA socket of the + * port. Note the memory is mmap to IOVA already, use mtl_hp_virt2iova to get + * the iova. * * @param size * Size (in bytes) to be allocated. @@ -216,7 +218,7 @@ void* mufd_hp_malloc(size_t size, enum mtl_port port); * - NULL on error. Not enough memory, or invalid arguments * - Otherwise, the virtual address pointer to the allocated memory. */ -void* mufd_hp_zmalloc(size_t size, enum mtl_port port); +void *mufd_hp_zmalloc(size_t size, enum mtl_port port); /** * Frees the memory pointed by the pointer. @@ -228,7 +230,7 @@ void* mufd_hp_zmalloc(size_t size, enum mtl_port port); * @param ptr * The virtual address pointer to memory to be freed. */ -void mufd_hp_free(void* ptr); +void mufd_hp_free(void *ptr); /** * Check if the socket type is support or not by mufd. @@ -265,8 +267,8 @@ int mufd_socket_check(int domain, int type, int protocol); * - =0: Timeosockfd. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_poll_query(struct pollfd* fds, nfds_t nfds, int timeout, - int (*query)(void* priv), void* priv); +int mufd_poll_query(struct pollfd *fds, nfds_t nfds, int timeout, + int (*query)(void *priv), void *priv); #if defined(__cplusplus) } diff --git a/include/mudp_win.h b/include/mudp_win.h index 3e798914f..5655c47b6 100644 --- a/include/mudp_win.h +++ b/include/mudp_win.h @@ -23,23 +23,24 @@ extern "C" { /** Structure describing iovec for sendmsg and recvmsg */ struct iovec { /** Pointer to data. */ - void* iov_base; + void *iov_base; /** Length of data. */ size_t iov_len; }; -/** Structure describing messages sent by `sendmsg' and received by `recvmsg'. */ +/** Structure describing messages sent by `sendmsg' and received by `recvmsg'. + */ struct msghdr { /** Address to send to/receive from. */ - void* msg_name; + void *msg_name; /** Length of address data. */ socklen_t msg_namelen; /** Vector of data to send/receive into. */ - struct iovec* msg_iov; + struct iovec *msg_iov; /** Number of elements in the vector. */ size_t msg_iovlen; /** Ancillary data (eg BSD filedesc passing). */ - void* msg_control; + void *msg_control; /** Ancillary data buffer length. */ size_t msg_controllen; /** Flags on received message. */ @@ -56,18 +57,20 @@ struct cmsghdr { int cmsg_type; }; -#define CMSGDATA_ALIGN(length) \ +#define CMSGDATA_ALIGN(length) \ (((length) + MAX_NATURAL_ALIGNMENT - 1) & (~(MAX_NATURAL_ALIGNMENT - 1))) -#define CMSG_FIRSTHDR(msg) \ - (((msg)->msg_controllen >= sizeof(struct cmsghdr)) ? (msg)->msg_control : NULL) +#define CMSG_FIRSTHDR(msg) \ + (((msg)->msg_controllen >= sizeof(struct cmsghdr)) ? (msg)->msg_control \ + : NULL) #define CMSG_LEN(length) (CMSGDATA_ALIGN(sizeof(struct cmsghdr)) + length) #ifdef CMSG_DATA #undef CMSG_DATA #endif -#define CMSG_DATA(cmsg) ((PUCHAR)(cmsg) + CMSGDATA_ALIGN(sizeof(struct cmsghdr))) +#define CMSG_DATA(cmsg) \ + ((PUCHAR)(cmsg) + CMSGDATA_ALIGN(sizeof(struct cmsghdr))) #ifndef SOCK_NONBLOCK #define SOCK_NONBLOCK (0x800) diff --git a/include/st20_api.h b/include/st20_api.h index d97474773..a465ba798 100644 --- a/include/st20_api.h +++ b/include/st20_api.h @@ -57,7 +57,8 @@ extern "C" { #define ST20_TX_FLAG_USER_TIMESTAMP (MTL_BIT32(4)) /** * Flag bit in flags of struct st20_tx_ops. - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ #define ST20_TX_FLAG_ENABLE_VSYNC (MTL_BIT32(5)) /** @@ -72,8 +73,8 @@ extern "C" { #define ST20_TX_FLAG_ENABLE_RTCP (MTL_BIT32(7)) /** * Flag bit in flags of struct st20_tx_ops. - * Set this flag to set rtp timestamp at the time of the first packet egresses from the - * sender. + * Set this flag to set rtp timestamp at the time of the first packet egresses + * from the sender. */ #define ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT (MTL_BIT32(8)) /** @@ -83,8 +84,9 @@ extern "C" { #define ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH (MTL_BIT32(9)) /** * Flag bit in flags of struct st20_tx_ops. - * Set this flag to the bulk operation on all internal buffer rings. It may degrade the - * performance since the object enqueue/dequeue will be acted one by one. + * Set this flag to the bulk operation on all internal buffer rings. It may + * degrade the performance since the object enqueue/dequeue will be acted one by + * one. */ #define ST20_TX_FLAG_DISABLE_BULK (MTL_BIT32(10)) /** @@ -122,7 +124,8 @@ extern "C" { #define ST22_TX_FLAG_USER_TIMESTAMP (MTL_BIT32(4)) /** * Flag bit in flags of struct st22_tx_ops. - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ #define ST22_TX_FLAG_ENABLE_VSYNC (MTL_BIT32(5)) /** @@ -132,8 +135,9 @@ extern "C" { #define ST22_TX_FLAG_ENABLE_RTCP (MTL_BIT32(6)) /** * Flag bit in flags of struct st22_tx_ops. - * Set this flag to the bulk operation on all internal buffer rings. It may degrade the - * performance since the object enqueue/dequeue will be acted one by one. + * Set this flag to the bulk operation on all internal buffer rings. It may + * degrade the performance since the object enqueue/dequeue will be acted one by + * one. */ #define ST22_TX_FLAG_DISABLE_BULK (MTL_BIT32(7)) /** @@ -144,13 +148,15 @@ extern "C" { /** * Flag bit in flags of struct st20_rx_ops, for non MTL_PMD_DPDK_USER. - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st20_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st20_rx_get_queue_meta to get the queue meta(queue number etc) + * info. */ #define ST20_RX_FLAG_DATA_PATH_ONLY (MTL_BIT32(0)) /** * Flag bit in flags of struct st20_rx_ops. - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ #define ST20_RX_FLAG_ENABLE_VSYNC (MTL_BIT32(1)) /** @@ -200,9 +206,9 @@ extern "C" { #define ST20_RX_FLAG_HDR_SPLIT (MTL_BIT32(19)) /** * Flag bit in flags of struct st20_rx_ops. - * Only for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL and MTL_FLAG_RX_VIDEO_MIGRATE - * is enabled. - * Always disable MIGRATE for this session. + * Only for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL and + * MTL_FLAG_RX_VIDEO_MIGRATE is enabled. Always disable MIGRATE for this + * session. */ #define ST20_RX_FLAG_DISABLE_MIGRATE (MTL_BIT32(20)) /** @@ -224,13 +230,15 @@ extern "C" { /** * Flag bit in flags of struct st22_rx_ops, for non MTL_PMD_DPDK_USER. - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st22_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st22_rx_get_queue_meta to get the queue meta(queue number etc) + * info. */ #define ST22_RX_FLAG_DATA_PATH_ONLY (MTL_BIT32(0)) /** * Flag bit in flags of struct st22_rx_ops. - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ #define ST22_RX_FLAG_ENABLE_VSYNC (MTL_BIT32(1)) /** @@ -265,19 +273,19 @@ extern "C" { /** * Handle to tx st2110-20(video) session */ -typedef struct st_tx_video_session_handle_impl* st20_tx_handle; +typedef struct st_tx_video_session_handle_impl *st20_tx_handle; /** * Handle to tx st2110-22(compressed video) session */ -typedef struct st22_tx_video_session_handle_impl* st22_tx_handle; +typedef struct st22_tx_video_session_handle_impl *st22_tx_handle; /** * Handle to rx st2110-20(video) session */ -typedef struct st_rx_video_session_handle_impl* st20_rx_handle; +typedef struct st_rx_video_session_handle_impl *st20_rx_handle; /** * Handle to rx st2110-22(compressed video) session */ -typedef struct st22_rx_video_session_handle_impl* st22_rx_handle; +typedef struct st22_rx_video_session_handle_impl *st22_rx_handle; /** * Pacing type of st2110-20(video) sender @@ -311,11 +319,11 @@ enum st20_fmt { ST20_FMT_YUV_444_16BIT, /**< 16-bit YUV 4:4:4 */ /* * Below are the formats which not compatible with st2110 rfc4175. - * Ex, user want to transport ST_FRAME_FMT_YUV422PLANAR10LE directly with padding on the - * network and no color convert required. + * Ex, user want to transport ST_FRAME_FMT_YUV422PLANAR10LE directly with + * padding on the network and no color convert required. */ - ST20_FMT_YUV_422_PLANAR10LE, /**< 10-bit YUV 4:2:2 planar little endian. Experimental - now, how to support ext frame? */ + ST20_FMT_YUV_422_PLANAR10LE, /**< 10-bit YUV 4:2:2 planar little endian. + Experimental now, how to support ext frame? */ ST20_FMT_V210, /**< 10-bit YUV 422 V210 */ ST20_FMT_MAX, /**< max value of this enum */ }; @@ -331,8 +339,8 @@ enum st20_type { /** * similar to ST20_TYPE_FRAME_LEVEL but with slice control, * latency reduce to slice(lines) level. - * BTW, pls always enable ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME then app can get the - * notify for incomplete frame + * BTW, pls always enable ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME then app can + * get the notify for incomplete frame */ ST20_TYPE_SLICE_LEVEL, /** max value of this enum */ @@ -384,7 +392,7 @@ struct st20_pgroup { /** pixel group coverage(pixels), e.g. 2 for YUV422 10 bit */ uint32_t coverage; /** name */ - char* name; + char *name; }; /** @@ -411,10 +419,10 @@ struct st20_tx_frame_meta { uint32_t rtp_timestamp; /** * The user meta data buffer for current frame, the size must smaller than - * MTL_PKT_MAX_RTP_BYTES. This data will be transported to RX with video data and passed - * to user by user_meta in st20_rx_frame_meta. + * MTL_PKT_MAX_RTP_BYTES. This data will be transported to RX with video data + * and passed to user by user_meta in st20_rx_frame_meta. */ - const void* user_meta; + const void *user_meta; /** size for meta data buffer */ size_t user_meta_size; }; @@ -435,12 +443,12 @@ struct st20_tx_slice_meta { * cinst: Instantaneous value of the Retwork Compatibility model C. * vrx: Measured level of the Virtual Receive Buffer. * ipt: Inter-packet time, ns - * fpt: First Packet Time measured between frame/field reference time and the first - * captured packet of a frame/field. Unit: ns - * latency: TPA0(Actual measured arrival time of a packet) - RTP Timestamp. Unit: ns - * rtp_offset: RTP OFFSET = RTP Timestamp - N x Tframe, unit: timestamp ticks - * rtp_ts_delta: Delta between RTP timestamps of 2 consecutive frames/fields, - * unit: timestamp ticks. + * fpt: First Packet Time measured between frame/field reference time and the + * first captured packet of a frame/field. Unit: ns latency: TPA0(Actual + * measured arrival time of a packet) - RTP Timestamp. Unit: ns rtp_offset: RTP + * OFFSET = RTP Timestamp - N x Tframe, unit: timestamp ticks rtp_ts_delta: + * Delta between RTP timestamps of 2 consecutive frames/fields, unit: timestamp + * ticks. */ struct st20_rx_tp_meta { /** the max of cinst for current frame */ @@ -534,12 +542,13 @@ struct st20_rx_frame_meta { /** Second field type indicate, for interlaced mode */ bool second_field; /** - * The actual received size for current frame, user can inspect frame_recv_size - * against frame_total_size to check the signal integrity for incomplete frame. + * The actual received size for current frame, user can inspect + * frame_recv_size against frame_total_size to check the signal integrity for + * incomplete frame. */ size_t frame_recv_size; /** Private data for user, get from query_ext_frame callback */ - void* opaque; + void *opaque; /** timestamp(ST10_TIMESTAMP_FMT_TAI in ns, PTP) value for the first pkt */ uint64_t timestamp_first_pkt; /** timestamp(ST10_TIMESTAMP_FMT_TAI in ns, PTP) value for the first pkt */ @@ -551,17 +560,19 @@ struct st20_rx_frame_meta { /** * The received user meta data buffer for current frame. */ - const void* user_meta; + const void *user_meta; /** size for meta data buffer */ size_t user_meta_size; /** the total packets received, not include the redundant packets */ uint32_t pkts_total; - /** the valid packets received on each session port. For each session port, the validity - * of received packets can be assessed by comparing 'pkts_recv[s_port]' with - * 'pkts_total,' which serves as an indicator of signal quality. */ + /** the valid packets received on each session port. For each session port, + * the validity of received packets can be assessed by comparing + * 'pkts_recv[s_port]' with 'pkts_total,' which serves as an indicator of + * signal quality. */ uint32_t pkts_recv[MTL_SESSION_PORT_MAX]; - /** st20 rx timing parser meta, only active if ST20_RX_FLAG_TIMING_PARSER_META */ - struct st20_rx_tp_meta* tp[MTL_SESSION_PORT_MAX]; + /** st20 rx timing parser meta, only active if ST20_RX_FLAG_TIMING_PARSER_META + */ + struct st20_rx_tp_meta *tp[MTL_SESSION_PORT_MAX]; }; /** @@ -609,12 +620,13 @@ struct st20_rx_uframe_pg_meta { /** The total size for user frame */ size_t uframe_total_size; /** Point to current pixel groups data */ - void* payload; + void *payload; /** Number of octets of data included from current pixel groups data */ uint16_t row_length; /** Scan line number */ uint16_t row_number; - /** Offset of the first pixel of the payload data within current pixel groups data */ + /** Offset of the first pixel of the payload data within current pixel groups + * data */ uint16_t row_offset; /** How many pixel groups in current meta */ uint32_t pg_cnt; @@ -664,27 +676,29 @@ struct st22_rx_frame_meta { enum st_frame_status status; /** the total packets received, not include the redundant packets */ uint32_t pkts_total; - /** the valid packets received on each session port. For each session port, the validity - * of received packets can be assessed by comparing 'pkts_recv[s_port]' with - * 'pkts_total,' which serves as an indicator of signal quality. */ + /** the valid packets received on each session port. For each session port, + * the validity of received packets can be assessed by comparing + * 'pkts_recv[s_port]' with 'pkts_total,' which serves as an indicator of + * signal quality. */ uint32_t pkts_recv[MTL_SESSION_PORT_MAX]; }; /** - * The Continuation bit shall in row_offset be set to 1 if an additional Sample Row Data. - * Header follows the current Sample Row Data Header in the RTP Payload - * Header, which signals that the RTP packet is carrying data for more than one - * sample row. The Continuation bit shall be set to 0 otherwise. + * The Continuation bit shall in row_offset be set to 1 if an additional Sample + * Row Data. Header follows the current Sample Row Data Header in the RTP + * Payload Header, which signals that the RTP packet is carrying data for more + * than one sample row. The Continuation bit shall be set to 0 otherwise. */ #define ST20_SRD_OFFSET_CONTINUATION (0x1 << 15) /** - * The field identification bit in row_number shall be set to 1 if the payload comes from - * second field.The field identification bit shall be set to 0 otherwise. + * The field identification bit in row_number shall be set to 1 if the payload + * comes from second field.The field identification bit shall be set to 0 + * otherwise. */ #define ST20_SECOND_FIELD (0x1 << 15) /** - * The retransmit bit in row_length shall be set to 1 if it is a retransmit packet. - * Do not use it when row length can be larger than 16383. + * The retransmit bit in row_length shall be set to 1 if it is a retransmit + * packet. Do not use it when row length can be larger than 16383. */ #define ST20_RETRANSMIT (0x1 << 14) @@ -714,7 +728,8 @@ MTL_PACK(struct st22_rfc9134_rtp_hdr { struct st_rfc3550_rtp_hdr base; /** F counter high part */ uint8_t f_counter_hi : 3; - /** Interlaced information, 0b00: progressively, 0b10: first field, 0b11: second field. + /** Interlaced information, 0b00: progressively, 0b10: first field, 0b11: + * second field. */ uint8_t interlaced : 2; /** Last */ @@ -846,7 +861,8 @@ MTL_PACK(struct st20_rfc4175_444_12_pg2_le { }); #endif -/** Pixel Group describing four image pixels in YUV 4:4:4 or RGB 10-bit format */ +/** Pixel Group describing four image pixels in YUV 4:4:4 or RGB 10-bit format + */ #ifdef MTL_LITTLE_ENDIAN MTL_PACK(struct st20_rfc4175_444_10_pg4_be { uint8_t Cb_R00; /**< First 8 bits for Cb/Red 0 */ @@ -903,7 +919,8 @@ MTL_PACK(struct st20_rfc4175_444_10_pg4_be { }); #endif -/** Pixel Group describing four image pixels in YUV 4:4:4 or RGB 10-bit format */ +/** Pixel Group describing four image pixels in YUV 4:4:4 or RGB 10-bit format + */ #ifdef MTL_LITTLE_ENDIAN MTL_PACK(struct st20_rfc4175_444_10_pg4_le { uint8_t Cb_R00; /**< First 8 bits for Cb/Red 0 */ @@ -1072,13 +1089,14 @@ MTL_PACK(struct st20_rfc4175_422_8_pg2_le { /** External framebuffer */ struct st20_ext_frame { /** Virtual address of external framebuffer */ - void* buf_addr; + void *buf_addr; /** DMA mapped IOVA of external framebuffer */ mtl_iova_t buf_iova; /** Length of external framebuffer */ size_t buf_len; - /** Private data for user, will be retrieved with st_frame or st20_rx_frame_meta */ - void* opaque; + /** Private data for user, will be retrieved with st_frame or + * st20_rx_frame_meta */ + void *opaque; }; /** @@ -1101,7 +1119,8 @@ struct st_tx_rtcp_ops { struct st20_tx_ops { /** Mandatory. Destination IP address */ uint8_t dip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDFs of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDFs of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -1127,14 +1146,15 @@ struct st20_tx_ops { /** Mandatory. 7 bits payload type defined in RFC3550 */ uint8_t payload_type; - /** Optional. Synchronization source defined in RFC3550, if zero the session will assign - * a random value */ + /** Optional. Synchronization source defined in RFC3550, if zero the session + * will assign a random value */ uint32_t ssrc; /** Optional. Name */ - const char* name; + const char *name; /** Optional. Private data to the cb functions(get_next_frame and others) */ - void* priv; - /** Optional. Flags to control session behaviors. See ST20_TX_FLAG_* for possible value + void *priv; + /** Optional. Flags to control session behaviors. See ST20_TX_FLAG_* for + * possible value */ uint32_t flags; @@ -1146,51 +1166,55 @@ struct st20_tx_ops { uint16_t framebuff_cnt; /** * Mandatory for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL. - * The callback when lib require a new frame for sending, user should provide the next - * available frame index to next_frame_idx. It implicit means the frame ownership will - * be transferred to lib. And only non-block method can be used within this callback, as - * it run from lcore tasklet routine. + * The callback when lib require a new frame for sending, user should provide + * the next available frame index to next_frame_idx. It implicit means the + * frame ownership will be transferred to lib. And only non-block method can + * be used within this callback, as it run from lcore tasklet routine. */ - int (*get_next_frame)(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta); + int (*get_next_frame)(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta); /** * Optional for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL. - * The callback when lib finish the sending of one frame, frame_idx indicate the - * done frame. It implicit means the frame ownership is transferred to app. And only - * non-block method can be used within this callback as it run from lcore tasklet - * routine. + * The callback when lib finish the sending of one frame, frame_idx indicate + * the done frame. It implicit means the frame ownership is transferred to + * app. And only non-block method can be used within this callback as it run + * from lcore tasklet routine. */ - int (*notify_frame_done)(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta); + int (*notify_frame_done)(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta); /** - * Optional. The event callback when there is some event(vsync or others) happened for - * this session. Only non-block method can be used in this callback as it run from lcore - * routine. Args point to the meta data of each event. Ex, cast to struct - * st10_vsync_meta for ST_EVENT_VSYNC. + * Optional. The event callback when there is some event(vsync or others) + * happened for this session. Only non-block method can be used in this + * callback as it run from lcore routine. Args point to the meta data of each + * event. Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); + int (*notify_event)(void *priv, enum st_event event, void *args); /** Optional for ST20_TX_FLAG_ENABLE_RTCP. RTCP info */ struct st_tx_rtcp_ops rtcp; /** - * Optional. Session linesize(stride) in bytes, leave to zero if no padding for each - * line. Valid linesize should be wider than width size. + * Optional. Session linesize(stride) in bytes, leave to zero if no padding + * for each line. Valid linesize should be wider than width size. */ uint32_t linesize; - /** Optional. UDP source port number, leave as 0 to use same port as destination port */ + /** Optional. UDP source port number, leave as 0 to use same port as + * destination port */ uint16_t udp_src_port[MTL_SESSION_PORT_MAX]; - /** Optional. The tx destination mac address if ST20_TX_FLAG_USER_P(R)_MAC is enabled */ + /** Optional. The tx destination mac address if ST20_TX_FLAG_USER_P(R)_MAC is + * enabled */ uint8_t tx_dst_mac[MTL_SESSION_PORT_MAX][MTL_MAC_ADDR_LEN]; /** * Optional. The start vrx buffer. - * Leave to zero if not know detail, lib will assign a start value of vrx(narrow) based - * on resolution and timing. Refer to st21 spec for the possible vrx value and also fine - * tune is required since network setup difference and RL burst. + * Leave to zero if not know detail, lib will assign a start value of + * vrx(narrow) based on resolution and timing. Refer to st21 spec for the + * possible vrx value and also fine tune is required since network setup + * difference and RL burst. */ uint16_t start_vrx; /** * Optional. Manually assigned padding pkt interval(pkts level) for RL pacing. - * Leave to zero if not know detail, lib will train the interval in the initial routine. + * Leave to zero if not know detail, lib will train the interval in the + * initial routine. */ uint16_t pad_interval; /** @@ -1199,52 +1223,56 @@ struct st20_tx_ops { */ int32_t rtp_timestamp_delta_us; /** - * Optional. The time for lib to detect the hang on the tx queue and try to recovery - * Leave to zero system will use the default value(1s). + * Optional. The time for lib to detect the hang on the tx queue and try to + * recovery Leave to zero system will use the default value(1s). */ uint32_t tx_hang_detect_ms; /** * Mandatory for ST20_TYPE_SLICE_LEVEL. - * The callback when lib requires new ready lines, user should provide the ready lines - * number by the meta. + * The callback when lib requires new ready lines, user should provide the + * ready lines number by the meta. */ - int (*query_frame_lines_ready)(void* priv, uint16_t frame_idx, - struct st20_tx_slice_meta* meta); + int (*query_frame_lines_ready)(void *priv, uint16_t frame_idx, + struct st20_tx_slice_meta *meta); - /** Mandatory for ST20_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ + /** Mandatory for ST20_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 + */ uint32_t rtp_ring_size; /** - * Mandatory for ST20_TYPE_RTP_LEVEL. Total pkts in one frame, ex: 4320 for 1080p. + * Mandatory for ST20_TYPE_RTP_LEVEL. Total pkts in one frame, ex: 4320 for + * 1080p. */ uint32_t rtp_frame_total_pkts; /** * Mandatory for ST20_TYPE_RTP_LEVEL. - * Size for each rtp pkt, include both the payload data and rtp header, must small than - * MTL_PKT_MAX_RTP_BYTES. Used by MTL to calculate the total bandwidth of each frame. - * App still can customize the size of each pkt by the `len` parameter of - * `st20_tx_put_mbuf` + * Size for each rtp pkt, include both the payload data and rtp header, must + * small than MTL_PKT_MAX_RTP_BYTES. Used by MTL to calculate the total + * bandwidth of each frame. App still can customize the size of each pkt by + * the `len` parameter of `st20_tx_put_mbuf` */ uint16_t rtp_pkt_size; /** * Optional for ST20_TYPE_RTP_LEVEL. * The callback when lib finish the sending of one rtp packet. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_rtp_done)(void* priv); - /** Use this socket if ST20_TX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_rtp_done)(void *priv); + /** Use this socket if ST20_TX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; /** - * The structure describing how to create a tx st2110-22(compressed video) session. - * Include the PCIE port and other required info. + * The structure describing how to create a tx st2110-22(compressed video) + * session. Include the PCIE port and other required info. */ struct st22_tx_ops { /** Mandatory. Destination IP address */ uint8_t dip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDFs of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDFs of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -1270,14 +1298,15 @@ struct st22_tx_ops { /** Mandatory. 7 bits payload type define in RFC3550 */ uint8_t payload_type; - /** Optional. Synchronization source defined in RFC3550, if zero the session will assign - * a random value */ + /** Optional. Synchronization source defined in RFC3550, if zero the session + * will assign a random value */ uint32_t ssrc; /** Optional. Name */ - const char* name; + const char *name; /** Optional. Private data to the cb functions(get_next_frame and others) */ - void* priv; - /** Optional. Flags to control session behaviors. See ST22_TX_FLAG_* for possible value + void *priv; + /** Optional. Flags to control session behaviors. See ST22_TX_FLAG_* for + * possible value */ uint32_t flags; @@ -1296,60 +1325,65 @@ struct st22_tx_ops { */ size_t framebuff_max_size; /** - * Mandatory for ST22_TYPE_FRAME_LEVEL. The callback when lib require a new frame for - * sending. User should provide the next available frame index to next_frame_idx. It - * implicit means the frame ownership will be transferred to lib. And only non-block - * method can be used within this callback, as it run from lcore tasklet routine. + * Mandatory for ST22_TYPE_FRAME_LEVEL. The callback when lib require a new + * frame for sending. User should provide the next available frame index to + * next_frame_idx. It implicit means the frame ownership will be transferred + * to lib. And only non-block method can be used within this callback, as it + * run from lcore tasklet routine. */ - int (*get_next_frame)(void* priv, uint16_t* next_frame_idx, - struct st22_tx_frame_meta* meta); + int (*get_next_frame)(void *priv, uint16_t *next_frame_idx, + struct st22_tx_frame_meta *meta); /** * Optional for ST22_TYPE_FRAME_LEVEL. - * The callback when lib finish the sending of current frame, frame_idx indicate the - * done frame. It implicit means the frame ownership is transferred to app. And only - * non-block method can be used within this callback as it run from lcore tasklet - * routine. + * The callback when lib finish the sending of current frame, frame_idx + * indicate the done frame. It implicit means the frame ownership is + * transferred to app. And only non-block method can be used within this + * callback as it run from lcore tasklet routine. */ - int (*notify_frame_done)(void* priv, uint16_t frame_idx, - struct st22_tx_frame_meta* meta); + int (*notify_frame_done)(void *priv, uint16_t frame_idx, + struct st22_tx_frame_meta *meta); /** - * Optional. The event callback when there is some event(vsync or others) happened for - * this session. Only non-block method can be used in this callback as it run from lcore - * routine. Args point to the meta data of each event. Ex, cast to struct - * st10_vsync_meta for ST_EVENT_VSYNC. + * Optional. The event callback when there is some event(vsync or others) + * happened for this session. Only non-block method can be used in this + * callback as it run from lcore routine. Args point to the meta data of each + * event. Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); - /** Optional. UDP source port number, leave as 0 to use same port as destination port */ + int (*notify_event)(void *priv, enum st_event event, void *args); + /** Optional. UDP source port number, leave as 0 to use same port as + * destination port */ uint16_t udp_src_port[MTL_SESSION_PORT_MAX]; /** Optional for ST20_TX_FLAG_ENABLE_RTCP. RTCP info */ struct st_tx_rtcp_ops rtcp; - /** Optional. The tx destination mac address if ST20_TX_FLAG_USER_P(R)_MAC is enabled */ + /** Optional. The tx destination mac address if ST20_TX_FLAG_USER_P(R)_MAC is + * enabled */ uint8_t tx_dst_mac[MTL_SESSION_PORT_MAX][MTL_MAC_ADDR_LEN]; - /** Mandatory for ST22_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ + /** Mandatory for ST22_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 + */ uint32_t rtp_ring_size; /** - * Mandatory for ST22_TYPE_RTP_LEVEL. total pkts in one rtp frame. Used by MTL to - * calculate the total bandwidth of each frame, and user must build exactly the same - * number packets of each frame by `st20_tx_put_mbuf` */ + * Mandatory for ST22_TYPE_RTP_LEVEL. total pkts in one rtp frame. Used by MTL + * to calculate the total bandwidth of each frame, and user must build exactly + * the same number packets of each frame by `st20_tx_put_mbuf` */ uint32_t rtp_frame_total_pkts; /** * Mandatory for ST22_TYPE_RTP_LEVEL. - * Size for each rtp pkt, include both the payload data and rtp header, must small than - * MTL_PKT_MAX_RTP_BYTES. Used by MTL to calculate the total bandwidth of each frame. - * App still can customize the size of each pkt by the `len` parameter of - * `st20_tx_put_mbuf` + * Size for each rtp pkt, include both the payload data and rtp header, must + * small than MTL_PKT_MAX_RTP_BYTES. Used by MTL to calculate the total + * bandwidth of each frame. App still can customize the size of each pkt by + * the `len` parameter of `st20_tx_put_mbuf` */ uint16_t rtp_pkt_size; /** * Optional for ST22_TYPE_RTP_LEVEL. * The callback when lib finish the sending of one rtp packet. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_rtp_done)(void* priv); - /** Use this socket if ST22_TX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_rtp_done)(void *priv); + /** Use this socket if ST22_TX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -1425,12 +1459,14 @@ struct st20_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t + sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. UDP dest port number */ uint16_t udp_port[MTL_SESSION_PORT_MAX]; @@ -1453,23 +1489,28 @@ struct st20_rx_ops { /** Optional. source filter IP address of multicast */ uint8_t mcast_sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Optional. Synchronization source defined in RFC3550, RX session will check the - * incoming RTP packets match the ssrc. Leave to zero to disable the ssrc check */ + /** Optional. Synchronization source defined in RFC3550, RX session will check + * the incoming RTP packets match the ssrc. Leave to zero to disable the ssrc + * check */ uint32_t ssrc; - /** Optional. Not in use now as RX support all pacing type, reserved for future */ + /** Optional. Not in use now as RX support all pacing type, reserved for + * future */ enum st21_pacing pacing; - /** Optional. Not in use now as RX support all packing type, reserved for future */ + /** Optional. Not in use now as RX support all packing type, reserved for + * future */ enum st20_packing packing; /** Optional. Name */ - const char* name; - /** Optional. Private data to the cb functions(notify_frame_ready and others) */ - void* priv; - /** Optional. Flags to control session behaviors. See ST20_RX_FLAG_* for possible value + const char *name; + /** Optional. Private data to the cb functions(notify_frame_ready and others) + */ + void *priv; + /** Optional. Flags to control session behaviors. See ST20_RX_FLAG_* for + * possible value */ uint32_t flags; - /* Optional, the size for each mt_rxq_burst, leave to zero to let system select a - * default value */ + /* Optional, the size for each mt_rxq_burst, leave to zero to let system + * select a default value */ uint16_t rx_burst_size; /** @@ -1480,46 +1521,45 @@ struct st20_rx_ops { uint16_t framebuff_cnt; /** * Mandatory for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL. - * The callback when lib receive a new frame. It implicit means the frame ownership is - * transferred to app. - * frame: point to the address of the frame buf. - * meta: point to the meta data. - * return: - * - 0: if app consume the frame successful. App should call st20_rx_put_framebuff - * to return the frame when it finish the handling - * < 0: the error code if app can't handle, lib will call st20_rx_put_framebuff then. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * The callback when lib receive a new frame. It implicit means the frame + * ownership is transferred to app. frame: point to the address of the frame + * buf. meta: point to the meta data. return: + * - 0: if app consume the frame successful. App should call + * st20_rx_put_framebuff to return the frame when it finish the handling < 0: + * the error code if app can't handle, lib will call st20_rx_put_framebuff + * then. And only non-block method can be used in this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_ready)(void* priv, void* frame, struct st20_rx_frame_meta* meta); + int (*notify_frame_ready)(void *priv, void *frame, + struct st20_rx_frame_meta *meta); /** * Optional. the ST20_TYPE_FRAME_LEVEL external frame buffer info array, * Only for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL. */ - struct st20_ext_frame* ext_frames; + struct st20_ext_frame *ext_frames; /** - * Optional. The event callback when there is some event(vsync or others) happened for - * this session. Only non-block method can be used in this callback as it run from lcore - * routine. Args point to the meta data of each event. Ex, cast to struct - * st10_vsync_meta for ST_EVENT_VSYNC. + * Optional. The event callback when there is some event(vsync or others) + * happened for this session. Only non-block method can be used in this + * callback as it run from lcore routine. Args point to the meta data of each + * event. Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); + int (*notify_event)(void *priv, enum st_event event, void *args); /** Optional for ST20_RX_FLAG_ENABLE_RTCP. RTCP info */ struct st_rx_rtcp_ops rtcp; /** - * Optional. Session linesize(stride) in bytes, leave to zero if no padding for each - * line. Valid linesize should be wider than width size. + * Optional. Session linesize(stride) in bytes, leave to zero if no padding + * for each line. Valid linesize should be wider than width size. */ uint32_t linesize; /** * Optional for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL. - * Total size for user frame, lib will allocate frame with this value. When lib receive - * a payload from network, it will call uframe_pg_callback to let user to handle the - * pixel group data in the payload, the callback should convert the pixel group data to - * the data format app required. - * Zero means the user frame mode is disabled. + * Total size for user frame, lib will allocate frame with this value. When + * lib receive a payload from network, it will call uframe_pg_callback to let + * user to handle the pixel group data in the payload, the callback should + * convert the pixel group data to the data format app required. Zero means + * the user frame mode is disabled. */ size_t uframe_size; /** @@ -1530,62 +1570,69 @@ struct st20_rx_ops { * return: * - 0: if app consume the pixel group successfully. * < 0: the error code if app can't handle. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * And only non-block method can be used in this callback as it run from lcore + * tasklet routine. */ - int (*uframe_pg_callback)(void* priv, void* frame, struct st20_rx_uframe_pg_meta* meta); + int (*uframe_pg_callback)(void *priv, void *frame, + struct st20_rx_uframe_pg_meta *meta); /** * Optional for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL with - * ST20_RX_FLAG_AUTO_DETECT. The callback when lib detected video format. And only - * non-block method can be used in this callback as it run from lcore tasklet routine. + * ST20_RX_FLAG_AUTO_DETECT. The callback when lib detected video format. And + * only non-block method can be used in this callback as it run from lcore + * tasklet routine. */ - int (*notify_detected)(void* priv, const struct st20_detect_meta* meta, - struct st20_detect_reply* reply); + int (*notify_detected)(void *priv, const struct st20_detect_meta *meta, + struct st20_detect_reply *reply); /** - * Optional only for ST20_TYPE_FRAME_LEVEL with ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Optional only for ST20_TYPE_FRAME_LEVEL with + * ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME. And only non-block method can be + * used in this callback as it run from lcore tasklet routine. */ - int (*query_ext_frame)(void* priv, struct st20_ext_frame* ext_frame, - struct st20_rx_frame_meta* meta); + int (*query_ext_frame)(void *priv, struct st20_ext_frame *ext_frame, + struct st20_rx_frame_meta *meta); /** Mandatory for ST20_TYPE_SLICE_LEVEL, lines in one slice */ uint32_t slice_lines; /** * Mandatory for ST20_TYPE_SLICE_LEVEL. * the callback when lib received one more full slice info for a frame. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * And only non-block method can be used in this callback as it run from lcore + * tasklet routine. */ - int (*notify_slice_ready)(void* priv, void* frame, struct st20_rx_slice_meta* meta); + int (*notify_slice_ready)(void *priv, void *frame, + struct st20_rx_slice_meta *meta); - /** Mandatory for ST20_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ + /** Mandatory for ST20_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 + */ uint32_t rtp_ring_size; /** - * Optional for ST20_TYPE_RTP_LEVEL. The callback when lib receive one rtp packet. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Optional for ST20_TYPE_RTP_LEVEL. The callback when lib receive one rtp + * packet. And only non-block method can be used in this callback as it run + * from lcore tasklet routine. */ - int (*notify_rtp_ready)(void* priv); - /** Use this socket if ST20_RX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_rtp_ready)(void *priv); + /** Use this socket if ST20_RX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; /** - * The structure describing how to create a rx st2110-22(compressed video) session. - * Include the PCIE port and other required info. + * The structure describing how to create a rx st2110-22(compressed video) + * session. Include the PCIE port and other required info. */ struct st22_rx_ops { union { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t + sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. UDP dest port number */ uint16_t udp_port[MTL_SESSION_PORT_MAX]; @@ -1612,14 +1659,17 @@ struct st22_rx_ops { /** Optional. source filter IP address of multicast */ uint8_t mcast_sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Optional. Synchronization source defined in RFC3550, RX session will check the - * incoming RTP packets match the ssrc. Leave to zero to disable the ssrc check */ + /** Optional. Synchronization source defined in RFC3550, RX session will check + * the incoming RTP packets match the ssrc. Leave to zero to disable the ssrc + * check */ uint32_t ssrc; /** Optional. Name */ - const char* name; - /** Optional. Private data to the cb functions(notify_frame_ready and others) */ - void* priv; - /** Optional. Flags to control session behaviors. See ST22_RX_FLAG_* for possible value + const char *name; + /** Optional. Private data to the cb functions(notify_frame_ready and others) + */ + void *priv; + /** Optional. Flags to control session behaviors. See ST22_RX_FLAG_* for + * possible value */ uint32_t flags; @@ -1630,45 +1680,46 @@ struct st22_rx_ops { */ uint16_t framebuff_cnt; /** - * Mandatory for ST22_TYPE_FRAME_LEVEL. max framebuffer size for one st22 rx session, - * usually ST22 use constant bitrate (CBR) mode. - * lib will allocate all frame buffer with this size, - * app can get the real codestream size later in notify_frame_ready callback. + * Mandatory for ST22_TYPE_FRAME_LEVEL. max framebuffer size for one st22 rx + * session, usually ST22 use constant bitrate (CBR) mode. lib will allocate + * all frame buffer with this size, app can get the real codestream size later + * in notify_frame_ready callback. */ size_t framebuff_max_size; /** - * Mandatory for ST22_TYPE_FRAME_LEVEL. the callback when lib receive one frame. - * frame: point to the address of the frame buf. - * meta: point to the meta data. - * return: - * - 0: if app consume the frame successful. App should call st22_rx_put_framebuff - * to return the frame when it finish the handling - * < 0: the error code if app can't handle, lib will free the frame then. - * Only for ST22_TYPE_FRAME_LEVEL. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Mandatory for ST22_TYPE_FRAME_LEVEL. the callback when lib receive one + * frame. frame: point to the address of the frame buf. meta: point to the + * meta data. return: + * - 0: if app consume the frame successful. App should call + * st22_rx_put_framebuff to return the frame when it finish the handling < 0: + * the error code if app can't handle, lib will free the frame then. Only for + * ST22_TYPE_FRAME_LEVEL. And only non-block method can be used in this + * callback as it run from lcore tasklet routine. */ - int (*notify_frame_ready)(void* priv, void* frame, struct st22_rx_frame_meta* meta); + int (*notify_frame_ready)(void *priv, void *frame, + struct st22_rx_frame_meta *meta); /** - * Optional. The event callback when there is some event(vsync or others) happened for - * this session. Only non-block method can be used in this callback as it run from lcore - * routine. Args point to the meta data of each event. Ex, cast to struct - * st10_vsync_meta for ST_EVENT_VSYNC. + * Optional. The event callback when there is some event(vsync or others) + * happened for this session. Only non-block method can be used in this + * callback as it run from lcore routine. Args point to the meta data of each + * event. Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); + int (*notify_event)(void *priv, enum st_event event, void *args); /** Optional for ST22_RX_FLAG_ENABLE_RTCP, RTCP info */ struct st_rx_rtcp_ops rtcp; - /** Mandatory for ST22_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ + /** Mandatory for ST22_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 + */ uint32_t rtp_ring_size; /** - * Optional for ST22_TYPE_RTP_LEVEL. The callback when lib receive one rtp packet. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Optional for ST22_TYPE_RTP_LEVEL. The callback when lib receive one rtp + * packet. And only non-block method can be used in this callback as it run + * from lcore tasklet routine. */ - int (*notify_rtp_ready)(void* priv); - /** Use this socket if ST22_RX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_rtp_ready)(void *priv); + /** Use this socket if ST22_RX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -1706,12 +1757,13 @@ struct st20_rx_port_status { * @param mt * The handle to the media transport device context. * @param ops - * The pointer to the structure describing how to create a tx st2110-20(video) session. + * The pointer to the structure describing how to create a tx st2110-20(video) + * session. * @return * - NULL on error. * - Otherwise, the handle to the tx st2110-20(video) session. */ -st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops* ops); +st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops *ops); /** * Free the tx st2110-20(video) session. @@ -1735,16 +1787,18 @@ int st20_tx_free(st20_tx_handle handle); * - 0: Success, tx st2110-20(video) session destination update succ. * - <0: Error code of the rx st2110-20(video) session destination update. */ -int st20_tx_update_destination(st20_tx_handle handle, struct st_tx_dest_info* dst); +int st20_tx_update_destination(st20_tx_handle handle, + struct st_tx_dest_info *dst); /** - * Set the frame virtual address and iova from user for the tx st2110-20(video) session. - * For ST20_TYPE_FRAME_LEVEL. + * Set the frame virtual address and iova from user for the tx st2110-20(video) + * session. For ST20_TYPE_FRAME_LEVEL. * * @param handle * The handle to the tx st2110-20(video) session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st20_tx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st20_tx_ops]. * @param ext_frame * The pointer to the structure describing external framebuffer. * @return @@ -1752,7 +1806,7 @@ int st20_tx_update_destination(st20_tx_handle handle, struct st_tx_dest_info* ds * - <0: Error code if set fail. */ int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, - struct st20_ext_frame* ext_frame); + struct st20_ext_frame *ext_frame); /** * Get the framebuffer pointer from the tx st2110-20(video) session. @@ -1761,12 +1815,13 @@ int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, * @param handle * The handle to the tx st2110-20(video) session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st20_tx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st20_tx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st20_tx_get_framebuffer(st20_tx_handle handle, uint16_t idx); +void *st20_tx_get_framebuffer(st20_tx_handle handle, uint16_t idx); /** * Get the framebuffer size for the tx st2110-20(video) session. @@ -1789,9 +1844,9 @@ size_t st20_tx_get_framebuffer_size(st20_tx_handle handle); int st20_tx_get_framebuffer_count(st20_tx_handle handle); /** - * Get the mbuf pointer and usrptr of the mbuf from the tx st2110-20(video) session. - * For ST20_TYPE_RTP_LEVEL. - * Must call st20_tx_put_mbuf to return the mbuf after rtp pack done. + * Get the mbuf pointer and usrptr of the mbuf from the tx st2110-20(video) + * session. For ST20_TYPE_RTP_LEVEL. Must call st20_tx_put_mbuf to return the + * mbuf after rtp pack done. * * @param handle * The handle to the tx st2110-20(video) session. @@ -1801,11 +1856,11 @@ int st20_tx_get_framebuffer_count(st20_tx_handle handle); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st20_tx_get_mbuf(st20_tx_handle handle, void** usrptr); +void *st20_tx_get_mbuf(st20_tx_handle handle, void **usrptr); /** - * Put back the mbuf which get by st20_tx_get_mbuf to the tx st2110-20(video) session. - * For ST20_TYPE_RTP_LEVEL. + * Put back the mbuf which get by st20_tx_get_mbuf to the tx st2110-20(video) + * session. For ST20_TYPE_RTP_LEVEL. * * @param handle * The handle to the tx st2110-20(video) session. @@ -1817,7 +1872,7 @@ void* st20_tx_get_mbuf(st20_tx_handle handle, void** usrptr); * - 0 if successful. * - <0: Error code if put fail. */ -int st20_tx_put_mbuf(st20_tx_handle handle, void* mbuf, uint16_t len); +int st20_tx_put_mbuf(st20_tx_handle handle, void *mbuf, uint16_t len); /** * Get the scheduler index for the tx st2110-20(video) session. @@ -1831,7 +1886,8 @@ int st20_tx_put_mbuf(st20_tx_handle handle, void* mbuf, uint16_t len); int st20_tx_get_sch_idx(st20_tx_handle handle); /** - * Retrieve the general statistics(I/O) for one tx st2110-20(video) session port. + * Retrieve the general statistics(I/O) for one tx st2110-20(video) session + * port. * * @param handle * The handle to the tx st2110-20(video) session. @@ -1844,7 +1900,7 @@ int st20_tx_get_sch_idx(st20_tx_handle handle); * - <0: Error code. */ int st20_tx_get_port_stats(st20_tx_handle handle, enum mtl_session_port port, - struct st20_tx_port_status* stats); + struct st20_tx_port_status *stats); /** * Reset the general statistics(I/O) for one tx st2110-20(video) session port. @@ -1870,7 +1926,7 @@ int st20_tx_reset_port_stats(st20_tx_handle handle, enum mtl_session_port port); * - 0 if successful. * - <0: Error code if fail. */ -int st20_get_pgroup(enum st20_fmt fmt, struct st20_pgroup* pg); +int st20_get_pgroup(enum st20_fmt fmt, struct st20_pgroup *pg); /** * Retrieve the frame size from st2110-20(video) format. @@ -1905,17 +1961,19 @@ size_t st20_frame_size(enum st20_fmt fmt, uint32_t width, uint32_t height); * - 0 if successful. * - <0: Error code if fail. */ -int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, enum st_fps fps, - bool interlaced, uint64_t* bps); +int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, + enum st_fps fps, bool interlaced, uint64_t *bps); /** - * Inline function returning bandwidth(mega per second) for 1080 p59 yuv422 10bit + * Inline function returning bandwidth(mega per second) for 1080 p59 yuv422 + * 10bit * @return * Bandwidth(mega per second) */ static inline uint64_t st20_1080p59_yuv422_10bit_bandwidth_mps(void) { uint64_t bps; - st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, false, &bps); + st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, + false, &bps); return bps / 1000 / 1000; } @@ -1931,20 +1989,24 @@ static inline uint64_t st20_1080p59_yuv422_10bit_bandwidth_mps(void) { * - NULL on error. * - Otherwise, the handle to the tx st2110-22(compressed video) session. */ -st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops); +st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops); /** - * Online update the destination info for the tx st2110-22(compressed video) session. + * Online update the destination info for the tx st2110-22(compressed video) + * session. * * @param handle * The handle to the tx st2110-22(compressed video) session. * @param dst * The pointer to the tx st2110-22(compressed video) destination info. * @return - * - 0: Success, tx st2110-22(compressed video) session destination update succ. - * - <0: Error code of the rx st2110-22(compressed video) session destination update. + * - 0: Success, tx st2110-22(compressed video) session destination update + * succ. + * - <0: Error code of the rx st2110-22(compressed video) session destination + * update. */ -int st22_tx_update_destination(st22_tx_handle handle, struct st_tx_dest_info* dst); +int st22_tx_update_destination(st22_tx_handle handle, + struct st_tx_dest_info *dst); /** * Free the tx st2110-22(compressed video) session. @@ -1970,7 +2032,7 @@ int st22_tx_free(st22_tx_handle handle); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st22_tx_get_mbuf(st22_tx_handle handle, void** usrptr); +void *st22_tx_get_mbuf(st22_tx_handle handle, void **usrptr); /** * Put back the mbuf which get by st22_tx_get_mbuf to the tx @@ -1986,7 +2048,7 @@ void* st22_tx_get_mbuf(st22_tx_handle handle, void** usrptr); * - 0 if successful. * - <0: Error code if put fail. */ -int st22_tx_put_mbuf(st22_tx_handle handle, void* mbuf, uint16_t len); +int st22_tx_put_mbuf(st22_tx_handle handle, void *mbuf, uint16_t len); /** * Get the scheduler index for the tx st2110-22(compressed video) session. @@ -2006,12 +2068,13 @@ int st22_tx_get_sch_idx(st22_tx_handle handle); * @param handle * The handle to the tx st2110-22(video) session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st22_tx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st22_tx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st22_tx_get_fb_addr(st22_tx_handle handle, uint16_t idx); +void *st22_tx_get_fb_addr(st22_tx_handle handle, uint16_t idx); /** * Create one rx st2110-20(video) session. @@ -2019,12 +2082,13 @@ void* st22_tx_get_fb_addr(st22_tx_handle handle, uint16_t idx); * @param mt * The handle to the media transport device context. * @param ops - * The pointer to the structure describing how to create a rx st2110-20(video) session. + * The pointer to the structure describing how to create a rx st2110-20(video) + * session. * @return * - NULL on error. * - Otherwise, the handle to the rx st2110-20(video) session. */ -st20_rx_handle st20_rx_create(mtl_handle mt, struct st20_rx_ops* ops); +st20_rx_handle st20_rx_create(mtl_handle mt, struct st20_rx_ops *ops); /** * Online update the source info for the rx st2110-20(video) session. @@ -2037,7 +2101,7 @@ st20_rx_handle st20_rx_create(mtl_handle mt, struct st20_rx_ops* ops); * - 0: Success, rx st2110-20(video) session source update succ. * - <0: Error code of the rx st2110-20(video) session source update. */ -int st20_rx_update_source(st20_rx_handle handle, struct st_rx_source_info* src); +int st20_rx_update_source(st20_rx_handle handle, struct st_rx_source_info *src); /** * Get the scheduler index for the rx st2110-20(video) session. @@ -2061,13 +2125,14 @@ int st20_rx_get_sch_idx(st20_rx_handle handle); * synchronous or asynchronous, true means this func will return after dump * progress is finished. * @param meta - * The meta data returned, only for synchronous, leave to NULL if not need the meta. + * The meta data returned, only for synchronous, leave to NULL if not need the + * meta. * @return * - 0: Success, rx st2110-20(video) session pcapng dump succ. * - <0: Error code of the rx st2110-20(video) session pcapng dump. */ -int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta); +int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta); /** * Free the rx st2110-20(video) session. @@ -2112,12 +2177,12 @@ int st20_rx_get_framebuffer_count(st20_rx_handle handle); * - 0: Success. * - <0: Error code. */ -int st20_rx_put_framebuff(st20_rx_handle handle, void* frame); +int st20_rx_put_framebuff(st20_rx_handle handle, void *frame); /** - * Get the mbuf pointer and usrptr of the mbuf from the rx st2110-20(video) session. - * For ST20_TYPE_RTP_LEVEL. - * Must call st20_rx_put_mbuf to return the mbuf after consume it. + * Get the mbuf pointer and usrptr of the mbuf from the rx st2110-20(video) + * session. For ST20_TYPE_RTP_LEVEL. Must call st20_rx_put_mbuf to return the + * mbuf after consume it. * * @param handle * The handle to the tx st2110-20(video) session. @@ -2129,18 +2194,18 @@ int st20_rx_put_framebuff(st20_rx_handle handle, void* frame); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st20_rx_get_mbuf(st20_rx_handle handle, void** usrptr, uint16_t* len); +void *st20_rx_get_mbuf(st20_rx_handle handle, void **usrptr, uint16_t *len); /** - * Put back the mbuf which get by st20_rx_get_mbuf to the rx st2110-20(video) session. - * For ST20_TYPE_RTP_LEVEL. + * Put back the mbuf which get by st20_rx_get_mbuf to the rx st2110-20(video) + * session. For ST20_TYPE_RTP_LEVEL. * * @param handle * The handle to the rx st2110-20(video) session. * @param mbuf * the dpdk mbuf pointer by st20_rx_get_mbuf. */ -void st20_rx_put_mbuf(st20_rx_handle handle, void* mbuf); +void st20_rx_put_mbuf(st20_rx_handle handle, void *mbuf); /** * Get the queue meta attached to rx st2110-20(video) session. @@ -2153,7 +2218,7 @@ void st20_rx_put_mbuf(st20_rx_handle handle, void* mbuf); * - 0: Success. * - <0: Error code. */ -int st20_rx_get_queue_meta(st20_rx_handle handle, struct st_queue_meta* meta); +int st20_rx_get_queue_meta(st20_rx_handle handle, struct st_queue_meta *meta); /** * Check if dma is enabled or not. @@ -2178,10 +2243,12 @@ bool st20_rx_dma_enabled(st20_rx_handle handle); * - 0: Success. * - <0: Error code. */ -int st20_rx_timing_parser_critical(st20_rx_handle handle, struct st20_rx_tp_pass* pass); +int st20_rx_timing_parser_critical(st20_rx_handle handle, + struct st20_rx_tp_pass *pass); /** - * Retrieve the general statistics(I/O) for one rx st2110-20(video) session port. + * Retrieve the general statistics(I/O) for one rx st2110-20(video) session + * port. * * @param handle * The handle to the rx st2110-20(video) session. @@ -2194,7 +2261,7 @@ int st20_rx_timing_parser_critical(st20_rx_handle handle, struct st20_rx_tp_pass * - <0: Error code. */ int st20_rx_get_port_stats(st20_rx_handle handle, enum mtl_session_port port, - struct st20_rx_port_status* stats); + struct st20_rx_port_status *stats); /** * Reset the general statistics(I/O) for one rx st2110-20(video) session port. @@ -2221,7 +2288,7 @@ int st20_rx_reset_port_stats(st20_rx_handle handle, enum mtl_session_port port); * - NULL on error. * - Otherwise, the handle to the rx st2110-22(compressed video) session. */ -st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops); +st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops *ops); /** * Online update the source info for the rx st2110-22(compressed video) session. @@ -2232,9 +2299,10 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops); * The pointer to the rx st2110-22(compressed video) source info. * @return * - 0: Success, rx st2110-22(video) session source update succ. - * - <0: Error code of the rx st2110-22(compressed video) session source update. + * - <0: Error code of the rx st2110-22(compressed video) session source + * update. */ -int st22_rx_update_source(st22_rx_handle handle, struct st_rx_source_info* src); +int st22_rx_update_source(st22_rx_handle handle, struct st_rx_source_info *src); /** * Get the scheduler index for the rx st2110-22(compressed video) session. @@ -2258,13 +2326,14 @@ int st22_rx_get_sch_idx(st22_rx_handle handle); * synchronous or asynchronous, true means this func will return after dump * progress is finished. * @param meta - * The meta data returned, only for synchronous, leave to NULL if not need the meta. + * The meta data returned, only for synchronous, leave to NULL if not need the + * meta. * @return * - 0: Success, rx st2110-22 session pcapng dump succ. * - <0: Error code of the rx st2110-22 session pcapng dump. */ -int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta); +int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta); /** * Free the rx st2110-22(compressed video) session. @@ -2292,7 +2361,7 @@ int st22_rx_free(st22_rx_handle handle); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st22_rx_get_mbuf(st22_rx_handle handle, void** usrptr, uint16_t* len); +void *st22_rx_get_mbuf(st22_rx_handle handle, void **usrptr, uint16_t *len); /** * Put back the mbuf which get by st22_rx_get_mbuf to the rx @@ -2303,7 +2372,7 @@ void* st22_rx_get_mbuf(st22_rx_handle handle, void** usrptr, uint16_t* len); * @param mbuf * the dpdk mbuf pointer by st22_rx_get_mbuf. */ -void st22_rx_put_mbuf(st22_rx_handle handle, void* mbuf); +void st22_rx_put_mbuf(st22_rx_handle handle, void *mbuf); /** * Put back the received buff get from notify_frame_ready. @@ -2317,7 +2386,7 @@ void st22_rx_put_mbuf(st22_rx_handle handle, void* mbuf); * - 0: Success. * - <0: Error code. */ -int st22_rx_put_framebuff(st22_rx_handle handle, void* frame); +int st22_rx_put_framebuff(st22_rx_handle handle, void *frame); /** * Get the framebuffer pointer from the rx st2110-22(video) session. @@ -2326,12 +2395,13 @@ int st22_rx_put_framebuff(st22_rx_handle handle, void* frame); * @param handle * The handle to the rx st2110-22(video) session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st22_rx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st22_rx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st22_rx_get_fb_addr(st22_rx_handle handle, uint16_t idx); +void *st22_rx_get_fb_addr(st22_rx_handle handle, uint16_t idx); /** * Get the queue meta attached to rx st2110-22(video) session. @@ -2344,7 +2414,7 @@ void* st22_rx_get_fb_addr(st22_rx_handle handle, uint16_t idx); * - 0: Success. * - <0: Error code. */ -int st22_rx_get_queue_meta(st22_rx_handle handle, struct st_queue_meta* meta); +int st22_rx_get_queue_meta(st22_rx_handle handle, struct st_queue_meta *meta); /** * Get the name of st20_fmt @@ -2355,7 +2425,7 @@ int st22_rx_get_queue_meta(st22_rx_handle handle, struct st_queue_meta* meta); * The pointer to name. * NULL: Fail. */ -const char* st20_fmt_name(enum st20_fmt fmt); +const char *st20_fmt_name(enum st20_fmt fmt); /** * Get st20_fmt from name @@ -2366,7 +2436,7 @@ const char* st20_fmt_name(enum st20_fmt fmt); * The st20_fmt. * ST20_FMT_MAX: Fail. */ -enum st20_fmt st20_name_to_fmt(const char* name); +enum st20_fmt st20_name_to_fmt(const char *name); #if defined(__cplusplus) } diff --git a/include/st30_api.h b/include/st30_api.h index a74824c1e..3897f4b17 100644 --- a/include/st30_api.h +++ b/include/st30_api.h @@ -21,11 +21,11 @@ extern "C" { /** * Handle to tx st2110-30(audio) session */ -typedef struct st_tx_audio_session_handle_impl* st30_tx_handle; +typedef struct st_tx_audio_session_handle_impl *st30_tx_handle; /** * Handle to rx st2110-30(audio) session */ -typedef struct st_rx_audio_session_handle_impl* st30_rx_handle; +typedef struct st_rx_audio_session_handle_impl *st30_rx_handle; /** * Flag bit in flags of struct st30_tx_ops. @@ -70,8 +70,9 @@ typedef struct st_rx_audio_session_handle_impl* st30_rx_handle; /** * Flag bit in flags of struct st30_rx_ops, for non MTL_PMD_DPDK_USER. - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st30_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st30_rx_get_queue_meta to get the queue meta(queue number etc) + * info. */ #define ST30_RX_FLAG_DATA_PATH_ONLY (MTL_BIT32(0)) /** @@ -88,7 +89,8 @@ typedef struct st_rx_audio_session_handle_impl* st30_rx_handle; #define ST30_RX_FLAG_TIMING_PARSER_STAT (MTL_BIT32(16)) /** * Flag bit in flags of struct st30_rx_ops. - * Enable the timing analyze info by st30_rx_tp_meta of notify_timing_parser_result + * Enable the timing analyze info by st30_rx_tp_meta of + * notify_timing_parser_result */ #define ST30_RX_FLAG_TIMING_PARSER_META (MTL_BIT32(17)) @@ -322,7 +324,8 @@ struct st30_rx_tp_meta { struct st30_tx_ops { /** Mandatory. destination IP address */ uint8_t dip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -344,13 +347,13 @@ struct st30_tx_ops { /** Optional. The pacing engine */ enum st30_tx_pacing_way pacing_way; - /** Optional. Synchronization source defined in RFC3550, if zero the session will assign - * a random value */ + /** Optional. Synchronization source defined in RFC3550, if zero the session + * will assign a random value */ uint32_t ssrc; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; + void *priv; /** Optional. see ST30_TX_FLAG_* for possible flags */ uint32_t flags; @@ -361,30 +364,31 @@ struct st30_tx_ops { uint16_t framebuff_cnt; /** * Mandatory for ST30_TYPE_FRAME_LEVEL. - * size for each frame buffer, should be multiple of packet size(st30_get_packet_size), + * size for each frame buffer, should be multiple of packet + * size(st30_get_packet_size), */ uint32_t framebuff_size; /** - * Mandatory for ST30_TYPE_FRAME_LEVEL. the callback when lib require a new frame for - * sending. User should provide the next available frame index to next_frame_idx. It - * implicit means the frame ownership will be transferred to lib, And only non-block - * method can be used in this callback as it run from lcore tasklet routine. + * Mandatory for ST30_TYPE_FRAME_LEVEL. the callback when lib require a new + * frame for sending. User should provide the next available frame index to + * next_frame_idx. It implicit means the frame ownership will be transferred + * to lib, And only non-block method can be used in this callback as it run + * from lcore tasklet routine. */ - int (*get_next_frame)(void* priv, uint16_t* next_frame_idx, - struct st30_tx_frame_meta* meta); + int (*get_next_frame)(void *priv, uint16_t *next_frame_idx, + struct st30_tx_frame_meta *meta); /** - * Optional for ST30_TYPE_FRAME_LEVEL. The callback when lib finish sending a frame. - * frame_idx indicate the frame which finish the transmit. - * It implicit means the frame ownership is transferred to app. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Optional for ST30_TYPE_FRAME_LEVEL. The callback when lib finish sending a + * frame. frame_idx indicate the frame which finish the transmit. It implicit + * means the frame ownership is transferred to app. And only non-block method + * can be used in this callback as it run from lcore tasklet routine. */ - int (*notify_frame_done)(void* priv, uint16_t frame_idx, - struct st30_tx_frame_meta* meta); + int (*notify_frame_done)(void *priv, uint16_t frame_idx, + struct st30_tx_frame_meta *meta); /* - * Optional. The size of fifo ring which used between the packet builder and pacing. - * Leave to zero to use default value: the packet number within + * Optional. The size of fifo ring which used between the packet builder and + * pacing. Leave to zero to use default value: the packet number within * ST30_TX_FIFO_DEFAULT_TIME_MS. */ uint16_t fifo_size; @@ -396,19 +400,23 @@ struct st30_tx_ops { */ uint8_t tx_dst_mac[MTL_SESSION_PORT_MAX][MTL_MAC_ADDR_LEN]; - /** Mandatory for ST30_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ + /** Mandatory for ST30_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 + */ uint32_t rtp_ring_size; /** - * Optional for ST30_TYPE_RTP_LEVEL. the callback when lib finish the sending of one rtp - * packet. And only non-block method can be used in this callback as it run from lcore - * tasklet routine. + * Optional for ST30_TYPE_RTP_LEVEL. the callback when lib finish the sending + * of one rtp packet. And only non-block method can be used in this callback + * as it run from lcore tasklet routine. */ - int (*notify_rtp_done)(void* priv); - /** Optional for ST30_TX_PACING_WAY_RL, the required accuracy for warmup check point */ + int (*notify_rtp_done)(void *priv); + /** Optional for ST30_TX_PACING_WAY_RL, the required accuracy for warmup check + * point */ uint32_t rl_accuracy_ns; - /** Optional for ST30_TX_PACING_WAY_RL, the offset time(us) for warmup check point */ + /** Optional for ST30_TX_PACING_WAY_RL, the offset time(us) for warmup check + * point */ int32_t rl_offset_ns; - /** Use this socket if ST30_TX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + /** Use this socket if ST30_TX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; /** @@ -418,7 +426,8 @@ struct st30_tx_ops { uint16_t sample_size __mtl_deprecated_msg("Not use anymore, plan to remove"); /** * number of samples for single channel in packet, - * use st30_get_sample_num to get the number from different ptime and sampling rate. + * use st30_get_sample_num to get the number from different ptime and sampling + * rate. */ uint16_t sample_num __mtl_deprecated_msg("Not use anymore, plan to remove"); }; @@ -432,12 +441,14 @@ struct st30_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t + sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. UDP dest port number */ uint16_t udp_port[MTL_SESSION_PORT_MAX]; @@ -458,13 +469,14 @@ struct st30_rx_ops { /** Optional. source filter IP address of multicast */ uint8_t mcast_sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Optional. Synchronization source defined in RFC3550, RX session will check the - * incoming RTP packets match the ssrc. Leave to zero to disable the ssrc check */ + /** Optional. Synchronization source defined in RFC3550, RX session will check + * the incoming RTP packets match the ssrc. Leave to zero to disable the ssrc + * check */ uint32_t ssrc; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; + void *priv; /** Optional. see ST30_RX_FLAG_* for possible flags */ uint32_t flags; @@ -475,38 +487,41 @@ struct st30_rx_ops { uint16_t framebuff_cnt; /** * Mandatory for ST30_TYPE_FRAME_LEVEL. - * size for each frame buffer, should be multiple of packet size(st30_get_packet_size), + * size for each frame buffer, should be multiple of packet + * size(st30_get_packet_size), */ uint32_t framebuff_size; /** - * Mandatory for ST30_TYPE_FRAME_LEVEL. callback when lib receive one full frame. - * frame: point to the address of the frame buf. - * meta: point to the meta data. - * return: - * - 0: if app consume the frame successful. App should call st30_rx_put_framebuff - * to return the frame when it finish the handling - * < 0: the error code if app can't handle, lib will call st30_rx_put_framebuff then. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Mandatory for ST30_TYPE_FRAME_LEVEL. callback when lib receive one full + * frame. frame: point to the address of the frame buf. meta: point to the + * meta data. return: + * - 0: if app consume the frame successful. App should call + * st30_rx_put_framebuff to return the frame when it finish the handling < 0: + * the error code if app can't handle, lib will call st30_rx_put_framebuff + * then. And only non-block method can be used in this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_ready)(void* priv, void* frame, struct st30_rx_frame_meta* meta); + int (*notify_frame_ready)(void *priv, void *frame, + struct st30_rx_frame_meta *meta); - /** Mandatory for ST30_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ + /** Mandatory for ST30_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 + */ uint32_t rtp_ring_size; /** - * Optional for ST20_TYPE_RTP_LEVEL. The callback when lib receive one rtp packet. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Optional for ST20_TYPE_RTP_LEVEL. The callback when lib receive one rtp + * packet. And only non-block method can be used in this callback as it run + * from lcore tasklet routine. */ - int (*notify_rtp_ready)(void* priv); + int (*notify_rtp_ready)(void *priv); /** - * Mandatory for ST30_RX_FLAG_TIMING_PARSER_META. The callback to notify the rx timing - * parser result for every 200ms . And only non-block method can be used in this - * callback as it run from lcore tasklet routine. + * Mandatory for ST30_RX_FLAG_TIMING_PARSER_META. The callback to notify the + * rx timing parser result for every 200ms . And only non-block method can be + * used in this callback as it run from lcore tasklet routine. */ - int (*notify_timing_parser_result)(void* priv, enum mtl_session_port port, - struct st30_rx_tp_meta* tp); - /** Use this socket if ST30_RX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_timing_parser_result)(void *priv, enum mtl_session_port port, + struct st30_rx_tp_meta *tp); + /** Use this socket if ST30_RX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; /** @@ -516,7 +531,8 @@ struct st30_rx_ops { uint16_t sample_size __mtl_deprecated_msg("Not use anymore, plan to remove"); /** * number of samples for single channel in packet, - * use st30_get_sample_num to get the number from different ptime and sampling rate. + * use st30_get_sample_num to get the number from different ptime and sampling + * rate. */ uint16_t sample_num __mtl_deprecated_msg("Not use anymore, plan to remove"); }; @@ -527,12 +543,13 @@ struct st30_rx_ops { * @param mt * The handle to the media transport device context. * @param ops - * The pointer to the structure describing how to create a tx st2110-30(audio) session. + * The pointer to the structure describing how to create a tx st2110-30(audio) + * session. * @return * - NULL on error. * - Otherwise, the handle to the tx st2110-30(audio) session. */ -st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops* ops); +st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops *ops); /** * Free the tx st2110-30(audio) session. @@ -556,7 +573,8 @@ int st30_tx_free(st30_tx_handle handle); * - 0: Success, tx st2110-30(audio) session destination update succ. * - <0: Error code of the rx st2110-30(audio) session destination update. */ -int st30_tx_update_destination(st30_tx_handle handle, struct st_tx_dest_info* dst); +int st30_tx_update_destination(st30_tx_handle handle, + struct st_tx_dest_info *dst); /** * Get the framebuffer pointer from the tx st2110-30(audio) session. @@ -565,17 +583,18 @@ int st30_tx_update_destination(st30_tx_handle handle, struct st_tx_dest_info* ds * @param handle * The handle to the tx st2110-30(audio) session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st30_tx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st30_tx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st30_tx_get_framebuffer(st30_tx_handle handle, uint16_t idx); +void *st30_tx_get_framebuffer(st30_tx_handle handle, uint16_t idx); /** - * Get the mbuf pointer and usrptr of the mbuf from the tx st2110-30(audio) session. - * For ST30_TYPE_RTP_LEVEL. - * Must call st30_tx_put_mbuf to return the mbuf after rtp pack done. + * Get the mbuf pointer and usrptr of the mbuf from the tx st2110-30(audio) + * session. For ST30_TYPE_RTP_LEVEL. Must call st30_tx_put_mbuf to return the + * mbuf after rtp pack done. * * @param handle * The handle to the tx st2110-30(audio) session. @@ -585,11 +604,11 @@ void* st30_tx_get_framebuffer(st30_tx_handle handle, uint16_t idx); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st30_tx_get_mbuf(st30_tx_handle handle, void** usrptr); +void *st30_tx_get_mbuf(st30_tx_handle handle, void **usrptr); /** - * Put back the mbuf which get by st30_tx_get_mbuf to the tx st2110-30(audio) session. - * For ST30_TYPE_RTP_LEVEL. + * Put back the mbuf which get by st30_tx_get_mbuf to the tx st2110-30(audio) + * session. For ST30_TYPE_RTP_LEVEL. * * @param handle * The handle to the tx st2110-30(audio) session. @@ -601,7 +620,7 @@ void* st30_tx_get_mbuf(st30_tx_handle handle, void** usrptr); * - 0 if successful. * - <0: Error code if put fail. */ -int st30_tx_put_mbuf(st30_tx_handle handle, void* mbuf, uint16_t len); +int st30_tx_put_mbuf(st30_tx_handle handle, void *mbuf, uint16_t len); /** * Retrieve the packet time in nanoseconds from st2110-30(audio) ptime. @@ -682,15 +701,15 @@ int st30_get_packet_size(enum st30_fmt fmt, enum st30_ptime ptime, * @param desired_frame_time_ns * The desired frame time in ns. * @param fps - * The fps return for current frame rate based on desired_frame_time_ns. Leave to NULL - * if not want to know the fps. + * The fps return for current frame rate based on desired_frame_time_ns. Leave + * to NULL if not want to know the fps. * @return * - >0 the frame buffer size returned. * - <0: Error code if fail. */ int st30_calculate_framebuff_size(enum st30_fmt fmt, enum st30_ptime ptime, enum st30_sampling sampling, uint16_t channel, - uint64_t desired_frame_time_ns, double* fps); + uint64_t desired_frame_time_ns, double *fps); /** * Create one rx st2110-30(audio) session. @@ -698,12 +717,13 @@ int st30_calculate_framebuff_size(enum st30_fmt fmt, enum st30_ptime ptime, * @param mt * The handle to the media transport device context. * @param ops - * The pointer to the structure describing how to create a rx st2110-30(audio) session. + * The pointer to the structure describing how to create a rx st2110-30(audio) + * session. * @return * - NULL on error. * - Otherwise, the handle to the rx st2110-30(audio) session. */ -st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops* ops); +st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops *ops); /** * Online update the source info for the rx st2110-30(audio) session. @@ -716,7 +736,7 @@ st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops* ops); * - 0: Success, rx st2110-30(audio) session source update succ. * - <0: Error code of the rx st2110-30(audio) session source update. */ -int st30_rx_update_source(st30_rx_handle handle, struct st_rx_source_info* src); +int st30_rx_update_source(st30_rx_handle handle, struct st_rx_source_info *src); /** * Free the rx st2110-30(audio) session. @@ -741,12 +761,12 @@ int st30_rx_free(st30_rx_handle handle); * - 0: Success. * - <0: Error code. */ -int st30_rx_put_framebuff(st30_rx_handle handle, void* frame); +int st30_rx_put_framebuff(st30_rx_handle handle, void *frame); /** - * Get the mbuf pointer and usrptr of the mbuf from the rx st2110-30(audio) session. - * For ST30_TYPE_RTP_LEVEL. - * Must call st30_rx_put_mbuf to return the mbuf after consume it. + * Get the mbuf pointer and usrptr of the mbuf from the rx st2110-30(audio) + * session. For ST30_TYPE_RTP_LEVEL. Must call st30_rx_put_mbuf to return the + * mbuf after consume it. * * @param handle * The handle to the tx st2110-30(audio) session. @@ -758,18 +778,18 @@ int st30_rx_put_framebuff(st30_rx_handle handle, void* frame); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st30_rx_get_mbuf(st30_rx_handle handle, void** usrptr, uint16_t* len); +void *st30_rx_get_mbuf(st30_rx_handle handle, void **usrptr, uint16_t *len); /** - * Put back the mbuf which get by st30_rx_get_mbuf to the rx st2110-30(audio) session. - * For ST30_TYPE_RTP_LEVEL. + * Put back the mbuf which get by st30_rx_get_mbuf to the rx st2110-30(audio) + * session. For ST30_TYPE_RTP_LEVEL. * * @param handle * The handle to the rx st2110-30(audio) session. * @param mbuf * the dpdk mbuf pointer by st30_rx_get_mbuf. */ -void st30_rx_put_mbuf(st30_rx_handle handle, void* mbuf); +void st30_rx_put_mbuf(st30_rx_handle handle, void *mbuf); /** * Get the queue meta attached to rx st2110-30(audio) session. @@ -782,7 +802,7 @@ void st30_rx_put_mbuf(st30_rx_handle handle, void* mbuf); * - 0: Success. * - <0: Error code. */ -int st30_rx_get_queue_meta(st30_rx_handle handle, struct st_queue_meta* meta); +int st30_rx_get_queue_meta(st30_rx_handle handle, struct st_queue_meta *meta); #if defined(__cplusplus) } diff --git a/include/st30_pipeline_api.h b/include/st30_pipeline_api.h index 1b572508d..e7f734181 100644 --- a/include/st30_pipeline_api.h +++ b/include/st30_pipeline_api.h @@ -20,9 +20,9 @@ extern "C" { #endif /** Handle to tx st2110-30 pipeline session of lib */ -typedef struct st30p_tx_ctx* st30p_tx_handle; +typedef struct st30p_tx_ctx *st30p_tx_handle; /** Handle to rx st2110-30 pipeline session of lib */ -typedef struct st30p_rx_ctx* st30p_rx_handle; +typedef struct st30p_rx_ctx *st30p_rx_handle; /** Bit define for flags of struct st20p_tx_ops. */ enum st30p_tx_flag { @@ -45,14 +45,15 @@ enum st30p_tx_flag { ST30P_TX_FLAG_FORCE_NUMA = (MTL_BIT32(8)), /** Enable the st30p_tx_get_frame block behavior to wait until a frame becomes - available or timeout(default: 1s, use st30p_tx_set_block_timeout to customize)*/ + available or timeout(default: 1s, use st30p_tx_set_block_timeout to + customize)*/ ST30P_TX_FLAG_BLOCK_GET = (MTL_BIT32(15)), }; /** The structure info for st30 frame meta. */ struct st30_frame { /** frame buffer address */ - void* addr; + void *addr; /** frame format */ enum st30_fmt fmt; /** channels number */ @@ -75,18 +76,19 @@ struct st30_frame { uint32_t rtp_timestamp; /** the total packets received, not include the redundant packets */ uint32_t pkts_total; - /** the valid packets received on each session port. For each session port, the validity - * of received packets can be assessed by comparing 'pkts_recv[s_port]' with - * 'pkts_total,' which serves as an indicator of signal quality. */ + /** the valid packets received on each session port. For each session port, + * the validity of received packets can be assessed by comparing + * 'pkts_recv[s_port]' with 'pkts_total,' which serves as an indicator of + * signal quality. */ uint32_t pkts_recv[MTL_SESSION_PORT_MAX]; /** priv pointer for lib, do not touch this */ - void* priv; + void *priv; }; /** - * The structure describing how to create a tx st2110-30(audio) pipeline session. - * Include the PCIE port and other required info + * The structure describing how to create a tx st2110-30(audio) pipeline + * session. Include the PCIE port and other required info */ struct st30p_tx_ops { /** Mandatory. tx port info */ @@ -104,32 +106,33 @@ struct st30p_tx_ops { enum st30_tx_pacing_way pacing_way; /** Mandatory. the frame buffer count. */ uint16_t framebuff_cnt; - /** size for each frame buffer, must be multiple of packet size(st30_get_packet_size) */ + /** size for each frame buffer, must be multiple of packet + * size(st30_get_packet_size) */ uint32_t framebuff_size; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; + void *priv; /** Optional. see ST30P_TX_FLAG_* for possible flags */ uint32_t flags; /** * Optional. Callback when frame available. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_available)(void* priv); + int (*notify_frame_available)(void *priv); /** * Optional. Callback when frame done. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_done)(void* priv, struct st30_frame* frame); + int (*notify_frame_done)(void *priv, struct st30_frame *frame); /* - * Optional. The size of fifo ring which used between the packet builder and pacing. - * Leave to zero to use default value: the packet number within + * Optional. The size of fifo ring which used between the packet builder and + * pacing. Leave to zero to use default value: the packet number within * ST30_TX_FIFO_DEFAULT_TIME_MS. */ uint16_t fifo_size; @@ -139,11 +142,14 @@ struct st30p_tx_ops { */ uint8_t tx_dst_mac[MTL_SESSION_PORT_MAX][MTL_MAC_ADDR_LEN]; - /** Optional for ST30_TX_PACING_WAY_RL, the required accuracy for warmup check point */ + /** Optional for ST30_TX_PACING_WAY_RL, the required accuracy for warmup check + * point */ uint32_t rl_accuracy_ns; - /** Optional for ST30_TX_PACING_WAY_RL, the offset time(us) for warmup check point */ + /** Optional for ST30_TX_PACING_WAY_RL, the offset time(us) for warmup check + * point */ int32_t rl_offset_ns; - /** Use this socket if ST30P_TX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + /** Use this socket if ST30P_TX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -151,44 +157,49 @@ struct st30p_tx_ops { * Get one tx frame from the tx st2110-30 pipeline session. * Call st30p_tx_put_frame to return the frame to session. */ -struct st30_frame* st30p_tx_get_frame(st30p_tx_handle handle); +struct st30_frame *st30p_tx_get_frame(st30p_tx_handle handle); /** Put back the frame which get by st30p_tx_get_frame. */ -int st30p_tx_put_frame(st30p_tx_handle handle, struct st30_frame* frame); +int st30p_tx_put_frame(st30p_tx_handle handle, struct st30_frame *frame); /** Free the tx st2110-30 pipeline session. */ int st30p_tx_free(st30p_tx_handle handle); /** Create one tx st2110-30 pipeline session */ -st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops* ops); -/** Online update the destination info for the tx st2110-30(pipeline) session. */ -int st30p_tx_update_destination(st30p_tx_handle handle, struct st_tx_dest_info* dst); -/** Wake up the block wait on st30p_tx_get_frame if ST30P_TX_FLAG_BLOCK_GET is enabled.*/ +st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops *ops); +/** Online update the destination info for the tx st2110-30(pipeline) session. + */ +int st30p_tx_update_destination(st30p_tx_handle handle, + struct st_tx_dest_info *dst); +/** Wake up the block wait on st30p_tx_get_frame if ST30P_TX_FLAG_BLOCK_GET is + * enabled.*/ int st30p_tx_wake_block(st30p_tx_handle handle); /* get framebuff size */ size_t st30p_tx_frame_size(st30p_tx_handle handle); /* get framebuff pointer */ -void* st30p_tx_get_fb_addr(st30p_tx_handle handle, uint16_t idx); -/** Set the block timeout time on st30p_tx_get_frame if ST30P_TX_FLAG_BLOCK_GET is - * enabled. */ +void *st30p_tx_get_fb_addr(st30p_tx_handle handle, uint16_t idx); +/** Set the block timeout time on st30p_tx_get_frame if ST30P_TX_FLAG_BLOCK_GET + * is enabled. */ int st30p_tx_set_block_timeout(st30p_tx_handle handle, uint64_t timedwait_ns); /** Bit define for flags of struct st20p_rx_ops. */ enum st30p_rx_flag { /** * Flag bit in flags of struct st30p_rx_ops, for non MTL_PMD_DPDK_USER. - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st30_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st30_rx_get_queue_meta to get the queue meta(queue number + * etc) info. */ ST30P_RX_FLAG_DATA_PATH_ONLY = (MTL_BIT32(0)), /** Force the numa of the created session, both CPU and memory */ ST30P_RX_FLAG_FORCE_NUMA = (MTL_BIT32(2)), /** Enable the st30p_rx_get_frame block behavior to wait until a frame becomes - available or timeout(default: 1s, use st30p_rx_set_block_timeout to customize) */ + available or timeout(default: 1s, use st30p_rx_set_block_timeout to + customize) */ ST30P_RX_FLAG_BLOCK_GET = (MTL_BIT32(15)), }; /** - * The structure describing how to create a rx st2110-30(audio) pipeline session. - * Include the PCIE port and other required info + * The structure describing how to create a rx st2110-30(audio) pipeline + * session. Include the PCIE port and other required info */ struct st30p_rx_ops { /** Mandatory. rx port info */ @@ -204,23 +215,25 @@ struct st30p_rx_ops { enum st30_ptime ptime; /** Mandatory. the frame buffer count. */ uint16_t framebuff_cnt; - /** size for each frame buffer, must be multiple of packet size(st30_get_packet_size) */ + /** size for each frame buffer, must be multiple of packet + * size(st30_get_packet_size) */ uint32_t framebuff_size; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; + void *priv; /** Optional. see ST30P_RX_FLAG_* for possible flags */ uint32_t flags; /** * Optional. Callback when frame available in the lib. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_available)(void* priv); - /** Use this socket if ST30P_RX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_frame_available)(void *priv); + /** Use this socket if ST30P_RX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -228,17 +241,18 @@ struct st30p_rx_ops { * Get one rx frame from the rx st2110-30 pipeline session. * Call st30p_rx_put_frame to return the frame to session. */ -struct st30_frame* st30p_rx_get_frame(st30p_rx_handle handle); +struct st30_frame *st30p_rx_get_frame(st30p_rx_handle handle); /** Put back the frame which get by st30p_rx_get_frame. */ -int st30p_rx_put_frame(st30p_rx_handle handle, struct st30_frame* frame); +int st30p_rx_put_frame(st30p_rx_handle handle, struct st30_frame *frame); /** Free the rx st2110-30 pipeline session. */ int st30p_rx_free(st30p_rx_handle handle); /** Create one rx st2110-30 pipeline session */ -st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops* ops); -/** Wake up the block wait on st30p_rx_get_frame if ST30P_RX_FLAG_BLOCK_GET is enabled.*/ +st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops *ops); +/** Wake up the block wait on st30p_rx_get_frame if ST30P_RX_FLAG_BLOCK_GET is + * enabled.*/ int st30p_rx_wake_block(st30p_rx_handle handle); -/** Set the block timeout time on st30p_rx_get_frame if ST30P_RX_FLAG_BLOCK_GET is - * enabled. */ +/** Set the block timeout time on st30p_rx_get_frame if ST30P_RX_FLAG_BLOCK_GET + * is enabled. */ int st30p_rx_set_block_timeout(st30p_rx_handle handle, uint64_t timedwait_ns); /* get framebuff size */ size_t st30p_rx_frame_size(st30p_rx_handle handle); diff --git a/include/st40_api.h b/include/st40_api.h index 8b5c3eab6..381b23765 100644 --- a/include/st40_api.h +++ b/include/st40_api.h @@ -21,11 +21,11 @@ extern "C" { /** * Handle to tx st2110-40(ancillary) session */ -typedef struct st_tx_ancillary_session_handle_impl* st40_tx_handle; +typedef struct st_tx_ancillary_session_handle_impl *st40_tx_handle; /** * Handle to rx st2110-40(ancillary) session */ -typedef struct st_rx_ancillary_session_handle_impl* st40_rx_handle; +typedef struct st_rx_ancillary_session_handle_impl *st40_rx_handle; /** * Flag bit in flags of struct st40_tx_ops. @@ -62,8 +62,9 @@ typedef struct st_rx_ancillary_session_handle_impl* st40_rx_handle; /** * Flag bit in flags of struct st30_rx_ops, for non MTL_PMD_DPDK_USER. - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st40_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st40_rx_get_queue_meta to get the queue meta(queue number etc) + * info. */ #define ST40_RX_FLAG_DATA_PATH_ONLY (MTL_BIT32(0)) /** @@ -93,9 +94,11 @@ MTL_PACK(struct st40_rfc8331_rtp_hdr { uint16_t length; struct { - /** the count of the total number of ANC data packets carried in the RTP payload */ + /** the count of the total number of ANC data packets carried in the RTP + * payload */ uint32_t anc_count : 8; - /** signaling the field specified by the RTP timestamp in an interlaced SDI raster */ + /** signaling the field specified by the RTP timestamp in an interlaced SDI + * raster */ uint32_t f : 2; /** reserved */ uint32_t reserved : 22; @@ -115,7 +118,8 @@ MTL_PACK(struct st40_rfc8331_payload_hdr { uint32_t s : 1; /** the location of the ANC data packet in the SDI raster */ uint32_t horizontal_offset : 12; - /** line number corresponds to the location (vertical) of the ANC data packet */ + /** line number corresponds to the location (vertical) of the ANC data + * packet */ uint32_t line_number : 11; /** the ANC data uses luma (Y) data channel */ uint32_t c : 1; @@ -144,7 +148,8 @@ MTL_PACK(struct st40_rfc8331_payload_hdr { struct { /** the ANC data uses luma (Y) data channel */ uint32_t c : 1; - /** line number corresponds to the location (vertical) of the ANC data packet */ + /** line number corresponds to the location (vertical) of the ANC data + * packet */ uint32_t line_number : 11; /** the location of the ANC data packet in the SDI raster */ uint32_t horizontal_offset : 12; @@ -179,7 +184,8 @@ MTL_PACK(struct st40_rfc8331_payload_hdr { struct st40_meta { /** the ANC data uses luma (Y) data channel */ uint16_t c; - /** line number corresponds to the location (vertical) of the ANC data packet */ + /** line number corresponds to the location (vertical) of the ANC data packet + */ uint16_t line_number; /** the location of the ANC data packet in the SDI raster */ uint16_t hori_offset; @@ -207,7 +213,7 @@ struct st40_meta { */ struct st40_frame { struct st40_meta meta[ST40_MAX_META]; /**< Meta data */ - uint8_t* data; /**< Handle to data buffer */ + uint8_t *data; /**< Handle to data buffer */ uint32_t data_size; /**< Size of content data */ uint32_t meta_num; /**< number of meta data */ }; @@ -237,7 +243,8 @@ struct st40_tx_frame_meta { struct st40_tx_ops { /** Mandatory. destination IP address */ uint8_t dip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -253,13 +260,13 @@ struct st40_tx_ops { /** Mandatory. interlaced or not */ bool interlaced; - /** Optional. Synchronization source defined in RFC3550, if zero the session will assign - * a random value */ + /** Optional. Synchronization source defined in RFC3550, if zero the session + * will assign a random value */ uint32_t ssrc; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; + void *priv; /** Optional. see ST40_TX_FLAG_* for possible flags */ uint32_t flags; @@ -269,22 +276,22 @@ struct st40_tx_ops { */ uint16_t framebuff_cnt; /** - * Mandatory for ST40_TYPE_FRAME_LEVEL. callback when lib require a new frame for - * sending. User should provide the next available frame index to next_frame_idx. It - * implicit means the frame ownership will be transferred to lib, And only non-block - * method can be used in this callback as it run from lcore tasklet routine. + * Mandatory for ST40_TYPE_FRAME_LEVEL. callback when lib require a new frame + * for sending. User should provide the next available frame index to + * next_frame_idx. It implicit means the frame ownership will be transferred + * to lib, And only non-block method can be used in this callback as it run + * from lcore tasklet routine. */ - int (*get_next_frame)(void* priv, uint16_t* next_frame_idx, - struct st40_tx_frame_meta* meta); + int (*get_next_frame)(void *priv, uint16_t *next_frame_idx, + struct st40_tx_frame_meta *meta); /** - * Optional for ST40_TYPE_FRAME_LEVEL. callback when lib finish sending one frame. - * frame_idx indicate the frame which finish the transmit. - * It implicit means the frame ownership is transferred to app. - * And only non-block method can be used in this callback as it run from lcore tasklet - * routine. + * Optional for ST40_TYPE_FRAME_LEVEL. callback when lib finish sending one + * frame. frame_idx indicate the frame which finish the transmit. It implicit + * means the frame ownership is transferred to app. And only non-block method + * can be used in this callback as it run from lcore tasklet routine. */ - int (*notify_frame_done)(void* priv, uint16_t frame_idx, - struct st40_tx_frame_meta* meta); + int (*notify_frame_done)(void *priv, uint16_t frame_idx, + struct st40_tx_frame_meta *meta); /** Optional. UDP source port number, leave as 0 to use same port as dst */ uint16_t udp_src_port[MTL_SESSION_PORT_MAX]; @@ -294,14 +301,15 @@ struct st40_tx_ops { */ uint8_t tx_dst_mac[MTL_SESSION_PORT_MAX][MTL_MAC_ADDR_LEN]; - /** Mandatory for ST40_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ + /** Mandatory for ST40_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 + */ uint32_t rtp_ring_size; /** - * Optional for ST40_TYPE_RTP_LEVEL. callback when lib finish the sending of one rtp - * packet, And only non-block method can be used in this callback as it run from lcore - * tasklet routine. + * Optional for ST40_TYPE_RTP_LEVEL. callback when lib finish the sending of + * one rtp packet, And only non-block method can be used in this callback as + * it run from lcore tasklet routine. */ - int (*notify_rtp_done)(void* priv); + int (*notify_rtp_done)(void *priv); }; /** @@ -313,12 +321,14 @@ struct st40_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t + sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. UDP dest port number */ uint16_t udp_port[MTL_SESSION_PORT_MAX]; @@ -331,23 +341,25 @@ struct st40_rx_ops { /** Optional. source filter IP address of multicast */ uint8_t mcast_sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Optional. Synchronization source defined in RFC3550, RX session will check the - * incoming RTP packets match the ssrc. Leave to zero to disable the ssrc check */ + /** Optional. Synchronization source defined in RFC3550, RX session will check + * the incoming RTP packets match the ssrc. Leave to zero to disable the ssrc + * check */ uint32_t ssrc; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; + void *priv; /** Optional. see ST40_RX_FLAG_* for possible flags */ uint32_t flags; /** Mandatory. rtp ring queue size, must be power of 2 */ uint32_t rtp_ring_size; /** - * Optional. the callback when lib finish the sending of one rtp packet. And only - * non-block method can be used in this callback as it run from lcore tasklet routine. + * Optional. the callback when lib finish the sending of one rtp packet. And + * only non-block method can be used in this callback as it run from lcore + * tasklet routine. */ - int (*notify_rtp_ready)(void* priv); + int (*notify_rtp_ready)(void *priv); }; /** @@ -356,13 +368,13 @@ struct st40_rx_ops { * @param mt * The handle to the media transport device context. * @param ops - * The pointer to the structure describing how to create a tx st2110-40(ancillary) - * session. + * The pointer to the structure describing how to create a tx + * st2110-40(ancillary) session. * @return * - NULL on error. * - Otherwise, the handle to the tx st2110-40(ancillary) session. */ -st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops* ops); +st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops *ops); /** * Free the tx st2110-40(ancillary) session. @@ -386,7 +398,8 @@ int st40_tx_free(st40_tx_handle handle); * - 0: Success, tx st2110-40(ancillary) session destination update succ. * - <0: Error code of the rx st2110-40(ancillary) session destination update. */ -int st40_tx_update_destination(st40_tx_handle handle, struct st_tx_dest_info* dst); +int st40_tx_update_destination(st40_tx_handle handle, + struct st_tx_dest_info *dst); /** * Get the framebuffer pointer from the tx st2110-40(ancillary) session. @@ -395,17 +408,18 @@ int st40_tx_update_destination(st40_tx_handle handle, struct st_tx_dest_info* ds * @param handle * The handle to the tx st2110-40(ancillary) session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st40_tx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st40_tx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st40_tx_get_framebuffer(st40_tx_handle handle, uint16_t idx); +void *st40_tx_get_framebuffer(st40_tx_handle handle, uint16_t idx); /** - * Get the mbuf pointer and usrptr of the mbuf from the tx st2110-40(ancillary) session. - * For ST40_TYPE_RTP_LEVEL. - * Must call st40_tx_put_mbuf to return the mbuf after rtp pack done. + * Get the mbuf pointer and usrptr of the mbuf from the tx st2110-40(ancillary) + * session. For ST40_TYPE_RTP_LEVEL. Must call st40_tx_put_mbuf to return the + * mbuf after rtp pack done. * * @param handle * The handle to the tx st2110-40(ancillary) session. @@ -415,11 +429,11 @@ void* st40_tx_get_framebuffer(st40_tx_handle handle, uint16_t idx); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st40_tx_get_mbuf(st40_tx_handle handle, void** usrptr); +void *st40_tx_get_mbuf(st40_tx_handle handle, void **usrptr); /** - * Put back the mbuf which get by st40_tx_get_mbuf to the tx st2110-40(ancillary) session. - * For ST40_TYPE_RTP_LEVEL. + * Put back the mbuf which get by st40_tx_get_mbuf to the tx + * st2110-40(ancillary) session. For ST40_TYPE_RTP_LEVEL. * * @param handle * The handle to the tx st2110-40(ancillary) session. @@ -431,7 +445,7 @@ void* st40_tx_get_mbuf(st40_tx_handle handle, void** usrptr); * - 0 if successful. * - <0: Error code if put fail. */ -int st40_tx_put_mbuf(st40_tx_handle handle, void* mbuf, uint16_t len); +int st40_tx_put_mbuf(st40_tx_handle handle, void *mbuf, uint16_t len); /** * Create one rx st2110-40(ancillary) session. @@ -445,7 +459,7 @@ int st40_tx_put_mbuf(st40_tx_handle handle, void* mbuf, uint16_t len); * - NULL on error. * - Otherwise, the handle to the rx st2110-40(ancillary) session. */ -st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops* ops); +st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops *ops); /** * Online update the source info for the rx st2110-40(ancillary) session. @@ -458,7 +472,7 @@ st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops* ops); * - 0: Success, rx st2110-40(ancillary) session source update succ. * - <0: Error code of the rx st2110-40(ancillary) session source update. */ -int st40_rx_update_source(st40_rx_handle handle, struct st_rx_source_info* src); +int st40_rx_update_source(st40_rx_handle handle, struct st_rx_source_info *src); /** * Free the rx st2110-40(ancillary) session. @@ -472,9 +486,9 @@ int st40_rx_update_source(st40_rx_handle handle, struct st_rx_source_info* src); int st40_rx_free(st40_rx_handle handle); /** - * Get the mbuf pointer and usrptr of the mbuf from the rx st2110-40(ancillary) session. - * For ST40_TYPE_RTP_LEVEL. - * Must call st40_rx_put_mbuf to return the mbuf after consume it. + * Get the mbuf pointer and usrptr of the mbuf from the rx st2110-40(ancillary) + * session. For ST40_TYPE_RTP_LEVEL. Must call st40_rx_put_mbuf to return the + * mbuf after consume it. * * @param handle * The handle to the tx st2110-40(ancillary) session. @@ -486,18 +500,18 @@ int st40_rx_free(st40_rx_handle handle); * - NULL if no available mbuf in the ring. * - Otherwise, the dpdk mbuf pointer. */ -void* st40_rx_get_mbuf(st40_rx_handle handle, void** usrptr, uint16_t* len); +void *st40_rx_get_mbuf(st40_rx_handle handle, void **usrptr, uint16_t *len); /** - * Put back the mbuf which get by st40_rx_get_mbuf to the rx st2110-40(ancillary) session. - * For ST40_TYPE_RTP_LEVEL. + * Put back the mbuf which get by st40_rx_get_mbuf to the rx + * st2110-40(ancillary) session. For ST40_TYPE_RTP_LEVEL. * * @param handle * The handle to the rx st2110-40(ancillary) session. * @param mbuf * the dpdk mbuf pointer by st40_rx_get_mbuf. */ -void st40_rx_put_mbuf(st40_rx_handle handle, void* mbuf); +void st40_rx_put_mbuf(st40_rx_handle handle, void *mbuf); /** * Get the queue meta attached to rx st2110-40(ancillary) session. @@ -510,7 +524,7 @@ void st40_rx_put_mbuf(st40_rx_handle handle, void* mbuf); * - 0: Success. * - <0: Error code. */ -int st40_rx_get_queue_meta(st40_rx_handle handle, struct st_queue_meta* meta); +int st40_rx_get_queue_meta(st40_rx_handle handle, struct st_queue_meta *meta); /** * Get udw from from st2110-40(ancillary) payload. @@ -522,7 +536,7 @@ int st40_rx_get_queue_meta(st40_rx_handle handle, struct st_queue_meta* meta); * @return * - udw */ -uint16_t st40_get_udw(uint32_t idx, uint8_t* data); +uint16_t st40_get_udw(uint32_t idx, uint8_t *data); /** * Set udw from for st2110-40(ancillary) payload. @@ -534,7 +548,7 @@ uint16_t st40_get_udw(uint32_t idx, uint8_t* data); * @param data * The pointer to st2110-40 payload. */ -void st40_set_udw(uint32_t idx, uint16_t udw, uint8_t* data); +void st40_set_udw(uint32_t idx, uint16_t udw, uint8_t *data); /** * Calculate checksum from st2110-40(ancillary) payload. @@ -546,7 +560,7 @@ void st40_set_udw(uint32_t idx, uint16_t udw, uint8_t* data); * @return * - checksum */ -uint16_t st40_calc_checksum(uint32_t data_num, uint8_t* data); +uint16_t st40_calc_checksum(uint32_t data_num, uint8_t *data); /** * Add parity from st2110-40(ancillary) payload. diff --git a/include/st_api.h b/include/st_api.h index 0b93d6d64..a6488b4bf 100644 --- a/include/st_api.h +++ b/include/st_api.h @@ -79,8 +79,8 @@ enum st_frame_status { /** All pixels of the frame were received */ ST_FRAME_STATUS_COMPLETE = 0, /** - * There was some packet loss, but the complete frame was reconstructed using packets - * from primary and redundant streams + * There was some packet loss, but the complete frame was reconstructed using + * packets from primary and redundant streams */ ST_FRAME_STATUS_RECONSTRUCTED, /** Packets were lost */ @@ -140,8 +140,8 @@ MTL_PACK(struct st_rfc3550_rtp_hdr { #endif /** - * The structure describing the destination address(ip addr and port) info for TX. - * Leave redundant info to zero if the session only has primary port. + * The structure describing the destination address(ip addr and port) info for + * TX. Leave redundant info to zero if the session only has primary port. */ struct st_tx_dest_info { /** destination IP address of sender */ @@ -159,8 +159,9 @@ struct st_rx_source_info { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t + sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** UDP port number */ uint16_t udp_port[MTL_SESSION_PORT_MAX]; @@ -211,7 +212,8 @@ enum st_event { ST_EVENT_VSYNC = 0, /** the error occurred and session recovery successfully */ ST_EVENT_RECOVERY_ERROR, - /** fatal error and session can't recovery, app should free the session then */ + /** fatal error and session can't recovery, app should free the session then + */ ST_EVENT_FATAL_ERROR, /** max value of this enum */ ST_EVENT_MAX, @@ -250,7 +252,7 @@ struct st_var_info { * - 0 if successful. * - <0: Error code if fail. */ -int st_get_var_info(mtl_handle mt, struct st_var_info* info); +int st_get_var_info(mtl_handle mt, struct st_var_info *info); /** * Inline function to check the rx frame is a completed frame. @@ -260,7 +262,8 @@ int st_get_var_info(mtl_handle mt, struct st_var_info* info); * Complete or not. */ static inline bool st_is_frame_complete(enum st_frame_status status) { - if ((status == ST_FRAME_STATUS_COMPLETE) || (status == ST_FRAME_STATUS_RECONSTRUCTED)) + if ((status == ST_FRAME_STATUS_COMPLETE) || + (status == ST_FRAME_STATUS_RECONSTRUCTED)) return true; else return false; @@ -293,17 +296,19 @@ enum st_fps st_frame_rate_to_st_fps(double framerate); * @return * enum st_fps fps. */ -enum st_fps st_name_to_fps(const char* name); +enum st_fps st_name_to_fps(const char *name); /** - * Helper function to convert ST10_TIMESTAMP_FMT_TAI to ST10_TIMESTAMP_FMT_MEDIA_CLK. + * Helper function to convert ST10_TIMESTAMP_FMT_TAI to + * ST10_TIMESTAMP_FMT_MEDIA_CLK. * * @param tai_ns * time in nanoseconds since the TAI epoch. * @param sampling_rate * sampling rate(90k for video, 48K/96K for audio). * @return - * the raw media clock value defined in ST2110-10, whose units vary by sampling_rate + * the raw media clock value defined in ST2110-10, whose units vary by + * sampling_rate */ uint32_t st10_tai_to_media_clk(uint64_t tai_ns, uint32_t sampling_rate); @@ -311,7 +316,8 @@ uint32_t st10_tai_to_media_clk(uint64_t tai_ns, uint32_t sampling_rate); * Helper function to convert ST10_TIMESTAMP_FMT_MEDIA_CLK to nanoseconds. * * @param media_ts - * the raw media clock value defined in ST2110-10, whose units vary by sampling_rate. + * the raw media clock value defined in ST2110-10, whose units vary by + * sampling_rate. * @param sampling_rate * sampling rate(90k for video, 48K/96K for audio). * @return @@ -332,9 +338,11 @@ uint64_t st10_media_clk_to_ns(uint32_t media_ts, uint32_t sampling_rate); * @return * time in nanoseconds since the TAI epoch. */ -static inline uint64_t st10_get_tai(enum st10_timestamp_fmt tfmt, uint64_t timestamp, +static inline uint64_t st10_get_tai(enum st10_timestamp_fmt tfmt, + uint64_t timestamp, uint32_t sampling_rate) { - if (tfmt == ST10_TIMESTAMP_FMT_TAI) return timestamp; + if (tfmt == ST10_TIMESTAMP_FMT_TAI) + return timestamp; return st10_media_clk_to_ns((uint32_t)timestamp, sampling_rate); } @@ -349,11 +357,14 @@ static inline uint64_t st10_get_tai(enum st10_timestamp_fmt tfmt, uint64_t times * @param sampling_rate * sampling rate(90k for video, 48K/96K for audio). * @return - * the raw media clock value defined in ST2110-10, whose units vary by sampling_rate. + * the raw media clock value defined in ST2110-10, whose units vary by + * sampling_rate. */ static inline uint32_t st10_get_media_clk(enum st10_timestamp_fmt tfmt, - uint64_t timestamp, uint32_t sampling_rate) { - if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) return (uint32_t)timestamp; + uint64_t timestamp, + uint32_t sampling_rate) { + if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) + return (uint32_t)timestamp; return st10_tai_to_media_clk(timestamp, sampling_rate); } @@ -373,8 +384,10 @@ static inline uint16_t st_tx_sessions_queue_cnt(uint16_t st20_sessions, uint16_t st30_sessions, uint16_t st40_sessions) { uint16_t queues = st20_sessions; - if (st30_sessions) queues++; - if (st40_sessions) queues++; + if (st30_sessions) + queues++; + if (st40_sessions) + queues++; return queues; } diff --git a/include/st_convert_api.h b/include/st_convert_api.h index 10385efcd..9198b37d3 100644 --- a/include/st_convert_api.h +++ b/include/st_convert_api.h @@ -5,8 +5,8 @@ /** * @file st_convert_api.h * - * This header define the public interfaces of streaming(st2110) format conversion - * toolkit + * This header define the public interfaces of streaming(st2110) format + * conversion toolkit * */ @@ -38,22 +38,24 @@ extern "C" { * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_yuv422p10le( - struct st20_rfc4175_422_10_pg2_be* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p10le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p10le_simd(pg, y, b, r, w, h, + MTL_SIMD_LEVEL_MAX); } -/** helper to call st20_rfc4175_422be10_to_yuv422p10le with mtl_cpuva_t type for python - * binding +/** helper to call st20_rfc4175_422be10_to_yuv422p10le with mtl_cpuva_t type for + * python binding */ -static inline int st20_rfc4175_422be10_to_yuv422p10le_cpuva(mtl_cpuva_t pg_be, - mtl_cpuva_t y, mtl_cpuva_t b, - mtl_cpuva_t r, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p10le((struct st20_rfc4175_422_10_pg2_be*)pg_be, - (uint16_t*)y, (uint16_t*)b, (uint16_t*)r, w, - h); +static inline int +st20_rfc4175_422be10_to_yuv422p10le_cpuva(mtl_cpuva_t pg_be, mtl_cpuva_t y, + mtl_cpuva_t b, mtl_cpuva_t r, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p10le( + (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint16_t *)y, (uint16_t *)b, + (uint16_t *)r, w, h); } /** @@ -71,10 +73,12 @@ static inline int st20_rfc4175_422be10_to_yuv422p10le_cpuva(mtl_cpuva_t pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_422le10( - struct st20_rfc4175_422_10_pg2_be* pg_be, struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_422le10(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -93,23 +97,26 @@ static inline int st20_rfc4175_422be10_to_422le10( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_v210(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_v210_simd(pg_be, pg_v210, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_v210(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_v210_simd(pg_be, pg_v210, w, h, + MTL_SIMD_LEVEL_MAX); } -/** helper to call st20_rfc4175_422be10_to_v210 with mtl_cpuva_t type for python binding +/** helper to call st20_rfc4175_422be10_to_v210 with mtl_cpuva_t type for python + * binding */ static inline int st20_rfc4175_422be10_to_v210_cpuva(mtl_cpuva_t pg_be, - mtl_cpuva_t pg_v210, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_v210((struct st20_rfc4175_422_10_pg2_be*)pg_be, - (uint8_t*)pg_v210, w, h); + mtl_cpuva_t pg_v210, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_v210( + (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint8_t *)pg_v210, w, h); } /** - * Convert rfc4175_422be10 to rfc4175_422le8(packed UYVY) with the max optimized SIMD - * level. + * Convert rfc4175_422be10 to rfc4175_422le8(packed UYVY) with the max optimized + * SIMD level. * * @param pg_10 * Point to pg(rfc4175_422be10) data. @@ -123,10 +130,12 @@ static inline int st20_rfc4175_422be10_to_v210_cpuva(mtl_cpuva_t pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_422le8(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_422le8_simd(pg_10, pg_8, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_422le8(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_422le8_simd(pg_10, pg_8, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -148,10 +157,12 @@ static inline int st20_rfc4175_422be10_to_422le8(struct st20_rfc4175_422_10_pg2_ * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_yuv422p8(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p8_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_yuv422p8(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p8_simd(pg, y, b, r, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -173,10 +184,12 @@ static inline int st20_rfc4175_422be10_to_yuv422p8(struct st20_rfc4175_422_10_pg * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_yuv420p8(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_yuv420p8_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_yuv420p8(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_yuv420p8_simd(pg, y, b, r, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -198,10 +211,12 @@ static inline int st20_rfc4175_422be10_to_yuv420p8(struct st20_rfc4175_422_10_pg * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be12_to_yuv422p12le( - struct st20_rfc4175_422_12_pg2_be* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be12_to_yuv422p12le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be12_to_yuv422p12le_simd(pg, y, b, r, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -219,10 +234,12 @@ static inline int st20_rfc4175_422be12_to_yuv422p12le( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be12_to_422le12( - struct st20_rfc4175_422_12_pg2_be* pg_be, struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be12_to_422le12_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be12_to_422le12(struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be12_to_422le12_simd(pg_be, pg_le, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -244,10 +261,12 @@ static inline int st20_rfc4175_422be12_to_422le12( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444be10_to_yuv444p10le( - struct st20_rfc4175_444_10_pg4_be* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be10_to_444p10le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444be10_to_yuv444p10le(struct st20_rfc4175_444_10_pg4_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be10_to_444p10le_simd(pg, y, b, r, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -269,10 +288,12 @@ static inline int st20_rfc4175_444be10_to_yuv444p10le( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444be10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_be* pg, - uint16_t* g, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be10_to_444p10le_simd(pg, g, r, b, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444be10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_be *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be10_to_444p10le_simd(pg, g, r, b, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -290,10 +311,12 @@ static inline int st20_rfc4175_444be10_to_gbrp10le(struct st20_rfc4175_444_10_pg * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444be10_to_444le10( - struct st20_rfc4175_444_10_pg4_be* pg_be, struct st20_rfc4175_444_10_pg4_le* pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be10_to_444le10_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444be10_to_444le10(struct st20_rfc4175_444_10_pg4_be *pg_be, + struct st20_rfc4175_444_10_pg4_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be10_to_444le10_simd(pg_be, pg_le, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -315,10 +338,12 @@ static inline int st20_rfc4175_444be10_to_444le10( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444be12_to_yuv444p12le( - struct st20_rfc4175_444_12_pg2_be* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be12_to_444p12le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444be12_to_yuv444p12le(struct st20_rfc4175_444_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be12_to_444p12le_simd(pg, y, b, r, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -340,10 +365,12 @@ static inline int st20_rfc4175_444be12_to_yuv444p12le( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444be12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_be* pg, - uint16_t* g, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be12_to_444p12le_simd(pg, g, r, b, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444be12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_be *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be12_to_444p12le_simd(pg, g, r, b, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -361,10 +388,12 @@ static inline int st20_rfc4175_444be12_to_gbrp12le(struct st20_rfc4175_444_12_pg * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444be12_to_444le12( - struct st20_rfc4175_444_12_pg2_be* pg_be, struct st20_rfc4175_444_12_pg2_le* pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be12_to_444le12_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444be12_to_444le12(struct st20_rfc4175_444_12_pg2_be *pg_be, + struct st20_rfc4175_444_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be12_to_444le12_simd(pg_be, pg_le, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -386,10 +415,12 @@ static inline int st20_rfc4175_444be12_to_444le12( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_yuv422p10le_to_rfc4175_422be10( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h) { - return st20_yuv422p10le_to_rfc4175_422be10_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_yuv422p10le_to_rfc4175_422be10(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_yuv422p10le_to_rfc4175_422be10_simd(y, b, r, pg, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -408,10 +439,12 @@ static inline int st20_yuv422p10le_to_rfc4175_422be10( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_v210_to_rfc4175_422be10(uint8_t* pg_v210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - return st20_v210_to_rfc4175_422be10_simd(pg_v210, pg_be, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_v210_to_rfc4175_422be10(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_v210_to_rfc4175_422be10_simd(pg_v210, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -429,10 +462,12 @@ static inline int st20_v210_to_rfc4175_422be10(uint8_t* pg_v210, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422le10_to_422be10( - struct st20_rfc4175_422_10_pg2_le* pg_le, struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422le10_to_422be10(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -454,9 +489,9 @@ static inline int st20_rfc4175_422le10_to_422be10( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_yuv422p10le_to_rfc4175_422le10(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_le* pg, uint32_t w, - uint32_t h); +int st20_yuv422p10le_to_rfc4175_422le10(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_le *pg, + uint32_t w, uint32_t h); /** * Convert rfc4175_422le10 to yuv422p10le. @@ -477,9 +512,9 @@ int st20_yuv422p10le_to_rfc4175_422le10(uint16_t* y, uint16_t* b, uint16_t* r, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le* pg, - uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h); +int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h); /** * Convert rfc4175_422le10 to v210 with required SIMD level. @@ -497,9 +532,10 @@ int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le* pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422le10_to_v210(uint8_t* pg_le, uint8_t* pg_v210, +static inline int st20_rfc4175_422le10_to_v210(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, uint32_t h) { - return st20_rfc4175_422le10_to_v210_simd(pg_le, pg_v210, w, h, MTL_SIMD_LEVEL_MAX); + return st20_rfc4175_422le10_to_v210_simd(pg_le, pg_v210, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -518,10 +554,11 @@ static inline int st20_rfc4175_422le10_to_v210(uint8_t* pg_le, uint8_t* pg_v210, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_y210(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint16_t* pg_y210, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_y210_simd(pg_be, pg_y210, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_y210(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint16_t *pg_y210, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_y210_simd(pg_be, pg_y210, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -540,10 +577,12 @@ static inline int st20_rfc4175_422be10_to_y210(struct st20_rfc4175_422_10_pg2_be * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_y210_to_rfc4175_422be10(uint16_t* pg_y210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - return st20_y210_to_rfc4175_422be10_simd(pg_y210, pg_be, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_y210_to_rfc4175_422be10(uint16_t *pg_y210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_y210_to_rfc4175_422be10_simd(pg_y210, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -561,7 +600,7 @@ static inline int st20_y210_to_rfc4175_422be10(uint16_t* pg_y210, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_v210_to_rfc4175_422le10(uint8_t* pg_v210, uint8_t* pg_le, uint32_t w, +int st20_v210_to_rfc4175_422le10(uint8_t *pg_v210, uint8_t *pg_le, uint32_t w, uint32_t h); /** @@ -583,10 +622,12 @@ int st20_v210_to_rfc4175_422le10(uint8_t* pg_v210, uint8_t* pg_le, uint32_t w, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_yuv422p12le_to_rfc4175_422be12( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_422_12_pg2_be* pg, - uint32_t w, uint32_t h) { - return st20_yuv422p12le_to_rfc4175_422be12_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_yuv422p12le_to_rfc4175_422be12(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_yuv422p12le_to_rfc4175_422be12_simd(y, b, r, pg, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -604,10 +645,12 @@ static inline int st20_yuv422p12le_to_rfc4175_422be12( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422le12_to_422be12( - struct st20_rfc4175_422_12_pg2_le* pg_le, struct st20_rfc4175_422_12_pg2_be* pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422le12_to_422be12(struct st20_rfc4175_422_12_pg2_le *pg_le, + struct st20_rfc4175_422_12_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -629,9 +672,9 @@ static inline int st20_rfc4175_422le12_to_422be12( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_yuv422p12le_to_rfc4175_422le12(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_12_pg2_le* pg, uint32_t w, - uint32_t h); +int st20_yuv422p12le_to_rfc4175_422le12(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_le *pg, + uint32_t w, uint32_t h); /** * Convert rfc4175_422le12 to yuv422p12le. @@ -652,9 +695,9 @@ int st20_yuv422p12le_to_rfc4175_422le12(uint16_t* y, uint16_t* b, uint16_t* r, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le* pg, - uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h); +int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h); /** * Convert yuv444p10le to rfc4175_444be10. @@ -675,10 +718,12 @@ int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le* pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_yuv444p10le_to_rfc4175_444be10( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_444_10_pg4_be* pg, - uint32_t w, uint32_t h) { - return st20_444p10le_to_rfc4175_444be10_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_yuv444p10le_to_rfc4175_444be10(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_10_pg4_be *pg, + uint32_t w, uint32_t h) { + return st20_444p10le_to_rfc4175_444be10_simd(y, b, r, pg, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -696,10 +741,12 @@ static inline int st20_yuv444p10le_to_rfc4175_444be10( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444le10_to_444be10( - struct st20_rfc4175_444_10_pg4_le* pg_le, struct st20_rfc4175_444_10_pg4_be* pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444le10_to_444be10(struct st20_rfc4175_444_10_pg4_le *pg_le, + struct st20_rfc4175_444_10_pg4_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -721,9 +768,10 @@ static inline int st20_rfc4175_444le10_to_444be10( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_yuv444p10le_to_rfc4175_444le10( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_444_10_pg4_le* pg, - uint32_t w, uint32_t h) { +static inline int +st20_yuv444p10le_to_rfc4175_444le10(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_10_pg4_le *pg, + uint32_t w, uint32_t h) { return st20_444p10le_to_rfc4175_444le10(y, b, r, pg, w, h); } @@ -746,9 +794,10 @@ static inline int st20_yuv444p10le_to_rfc4175_444le10( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444le10_to_yuv444p10le( - struct st20_rfc4175_444_10_pg4_le* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { +static inline int +st20_rfc4175_444le10_to_yuv444p10le(struct st20_rfc4175_444_10_pg4_le *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le10_to_444p10le(pg, y, b, r, w, h); } @@ -771,10 +820,12 @@ static inline int st20_rfc4175_444le10_to_yuv444p10le( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_gbrp10le_to_rfc4175_444be10(uint16_t* g, uint16_t* b, uint16_t* r, - struct st20_rfc4175_444_10_pg4_be* pg, - uint32_t w, uint32_t h) { - return st20_444p10le_to_rfc4175_444be10_simd(g, r, b, pg, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_gbrp10le_to_rfc4175_444be10(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_10_pg4_be *pg, + uint32_t w, uint32_t h) { + return st20_444p10le_to_rfc4175_444be10_simd(g, r, b, pg, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -796,9 +847,10 @@ static inline int st20_gbrp10le_to_rfc4175_444be10(uint16_t* g, uint16_t* b, uin * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_gbrp10le_to_rfc4175_444le10(uint16_t* g, uint16_t* b, uint16_t* r, - struct st20_rfc4175_444_10_pg4_le* pg, - uint32_t w, uint32_t h) { +static inline int +st20_gbrp10le_to_rfc4175_444le10(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_10_pg4_le *pg, + uint32_t w, uint32_t h) { return st20_444p10le_to_rfc4175_444le10(g, r, b, pg, w, h); } @@ -821,9 +873,10 @@ static inline int st20_gbrp10le_to_rfc4175_444le10(uint16_t* g, uint16_t* b, uin * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444le10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_le* pg, - uint16_t* g, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { +static inline int +st20_rfc4175_444le10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_le *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le10_to_444p10le(pg, g, r, b, w, h); } @@ -846,10 +899,12 @@ static inline int st20_rfc4175_444le10_to_gbrp10le(struct st20_rfc4175_444_10_pg * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_yuv444p12le_to_rfc4175_444be12( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_444_12_pg2_be* pg, - uint32_t w, uint32_t h) { - return st20_444p12le_to_rfc4175_444be12_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_yuv444p12le_to_rfc4175_444be12(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_12_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_444p12le_to_rfc4175_444be12_simd(y, b, r, pg, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -867,10 +922,12 @@ static inline int st20_yuv444p12le_to_rfc4175_444be12( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444le12_to_444be12( - struct st20_rfc4175_444_12_pg2_le* pg_le, struct st20_rfc4175_444_12_pg2_be* pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_444le12_to_444be12(struct st20_rfc4175_444_12_pg2_le *pg_le, + struct st20_rfc4175_444_12_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -892,9 +949,10 @@ static inline int st20_rfc4175_444le12_to_444be12( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_yuv444p12le_to_rfc4175_444le12( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_444_12_pg2_le* pg, - uint32_t w, uint32_t h) { +static inline int +st20_yuv444p12le_to_rfc4175_444le12(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_12_pg2_le *pg, + uint32_t w, uint32_t h) { return st20_444p12le_to_rfc4175_444le12(y, b, r, pg, w, h); } @@ -917,9 +975,10 @@ static inline int st20_yuv444p12le_to_rfc4175_444le12( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444le12_to_yuv444p12le( - struct st20_rfc4175_444_12_pg2_le* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { +static inline int +st20_rfc4175_444le12_to_yuv444p12le(struct st20_rfc4175_444_12_pg2_le *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le12_to_444p12le(pg, y, b, r, w, h); } @@ -942,10 +1001,12 @@ static inline int st20_rfc4175_444le12_to_yuv444p12le( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_gbrp12le_to_rfc4175_444be12(uint16_t* g, uint16_t* b, uint16_t* r, - struct st20_rfc4175_444_12_pg2_be* pg, - uint32_t w, uint32_t h) { - return st20_444p12le_to_rfc4175_444be12_simd(g, r, b, pg, w, h, MTL_SIMD_LEVEL_MAX); +static inline int +st20_gbrp12le_to_rfc4175_444be12(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_12_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_444p12le_to_rfc4175_444be12_simd(g, r, b, pg, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -967,9 +1028,10 @@ static inline int st20_gbrp12le_to_rfc4175_444be12(uint16_t* g, uint16_t* b, uin * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_gbrp12le_to_rfc4175_444le12(uint16_t* g, uint16_t* b, uint16_t* r, - struct st20_rfc4175_444_12_pg2_le* pg, - uint32_t w, uint32_t h) { +static inline int +st20_gbrp12le_to_rfc4175_444le12(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_12_pg2_le *pg, + uint32_t w, uint32_t h) { return st20_444p12le_to_rfc4175_444le12(g, r, b, pg, w, h); } @@ -992,9 +1054,10 @@ static inline int st20_gbrp12le_to_rfc4175_444le12(uint16_t* g, uint16_t* b, uin * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_444le12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_le* pg, - uint16_t* g, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { +static inline int +st20_rfc4175_444le12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_le *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le12_to_444p12le(pg, g, r, b, w, h); } @@ -1011,7 +1074,7 @@ static inline int st20_rfc4175_444le12_to_gbrp12le(struct st20_rfc4175_444_12_pg * - 0 if successful. * - <0: Error code if convert fail. */ -int st31_am824_to_aes3(struct st31_am824* sf_am824, struct st31_aes3* sf_aes3, +int st31_am824_to_aes3(struct st31_am824 *sf_am824, struct st31_aes3 *sf_aes3, uint16_t subframes); /** @@ -1027,7 +1090,7 @@ int st31_am824_to_aes3(struct st31_am824* sf_am824, struct st31_aes3* sf_aes3, * - 0 if successful. * - <0: Error code if convert fail. */ -int st31_aes3_to_am824(struct st31_aes3* sf_aes3, struct st31_am824* sf_am824, +int st31_aes3_to_am824(struct st31_aes3 *sf_aes3, struct st31_am824 *sf_am824, uint16_t subframes); #if defined(__cplusplus) diff --git a/include/st_convert_internal.h b/include/st_convert_internal.h index 37237d313..8c649a9b4 100644 --- a/include/st_convert_internal.h +++ b/include/st_convert_internal.h @@ -5,8 +5,9 @@ /** * @file st_convert_internal.h * - * This header define the internal interfaces of streaming(st2110) format conversion - * toolkit. Please note the APIs below is for internal test usage only. + * This header define the internal interfaces of streaming(st2110) format + * conversion toolkit. Please note the APIs below is for internal test usage + * only. * */ @@ -42,16 +43,15 @@ extern "C" { * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_yuv422p10le_simd(struct st20_rfc4175_422_10_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_yuv422p10le_simd( + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level); /** - * Convert rfc4175_422be10 to yuv422p10le with required SIMD level and DMA helper. - * Note the level may downgrade to the SIMD which system really support. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422be10 to yuv422p10le with required SIMD level and DMA + * helper. Note the level may downgrade to the SIMD which system really support. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -75,18 +75,17 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd(struct st20_rfc4175_422_10_pg2_be* * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_yuv422p10le_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, - uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be10_to_yuv422p10le_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level); /* the SIMD level version of st20_rfc4175_422be10_to_yuv422p10le_2way */ int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( - struct st20_rfc4175_422_10_pg2_be* pg_be, uint16_t* y_full, uint16_t* b_full, - uint16_t* r_full, uint32_t w, uint32_t h, uint16_t* y_decimated, - uint16_t* b_decimated, uint16_t* r_decimated, int decimator, - enum mtl_simd_level level); + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, + uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, + uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, + int decimator, enum mtl_simd_level level); /** * Convert rfc4175_422be10 to rfc4175_422le10 with required SIMD level. @@ -106,16 +105,16 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le10_simd( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** - * Convert rfc4175_422be10 to rfc4175_422le10 with required SIMD level and DMA helper. - * Note the level may downgrade to the SIMD which system really support. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422be10 to rfc4175_422le10 with required SIMD level and DMA + * helper. Note the level may downgrade to the SIMD which system really support. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -135,12 +134,10 @@ int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be* pg_b * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le10_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le10_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be10 to v210 with required SIMD level. @@ -160,13 +157,14 @@ int st20_rfc4175_422be10_to_422le10_simd_dma(mtl_udma_handle udma, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210, uint32_t w, uint32_t h, +int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h, enum mtl_simd_level level); /** - * Convert rfc4175_422be10 to dual v210 streams(one full and one decimated) with required - * SIMD level. Note the level may downgrade to the SIMD which system really support. + * Convert rfc4175_422be10 to dual v210 streams(one full and one decimated) with + * required SIMD level. Note the level may downgrade to the SIMD which system + * really support. * * @param pg_be * Point to pg(rfc4175_422be10) data. @@ -184,16 +182,16 @@ int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_v210_simd_2way(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210_full, uint32_t w, uint32_t h, - uint8_t* pg_v210_decimated, int decimator, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_v210_simd_2way( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210_full, uint32_t w, + uint32_t h, uint8_t *pg_v210_decimated, int decimator, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to v210 with required SIMD level and DMA helper. * Note the level may downgrade to the SIMD which system really support. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -213,15 +211,14 @@ int st20_rfc4175_422be10_to_v210_simd_2way(struct st20_rfc4175_422_10_pg2_be* pg * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_v210_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint8_t* pg_v210, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_v210_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** - * Convert rfc4175_422be10 to rfc4175_422le8(packed UYVY) with required SIMD level. - * Note the level may downgrade to the SIMD which system really support. + * Convert rfc4175_422be10 to rfc4175_422le8(packed UYVY) with required SIMD + * level. Note the level may downgrade to the SIMD which system really support. * * @param pg_10 * Point to pg(rfc4175_422be10) data. @@ -237,15 +234,15 @@ int st20_rfc4175_422be10_to_v210_simd_dma(mtl_udma_handle udma, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le8_simd(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le8_simd( + struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** - * Convert rfc4175_422be10 to rfc4175_422le8 packed UYVY with required SIMD level and DMA - * helper. Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus - * pls only applied with 4k/8k. + * Convert rfc4175_422be10 to rfc4175_422le8 packed UYVY with required SIMD + * level and DMA helper. Profiling shows gain with 4k/8k solution due to LLC + * cache miss migration, thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -265,12 +262,10 @@ int st20_rfc4175_422be10_to_422le8_simd(struct st20_rfc4175_422_10_pg2_be* pg_10 * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le8_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_10, - mtl_iova_t pg_10_iova, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le8_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be10 to yuv422p8 with required SIMD level. @@ -294,9 +289,10 @@ int st20_rfc4175_422be10_to_422le8_simd_dma(mtl_udma_handle udma, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to yuv420p8 with required SIMD level. @@ -320,9 +316,10 @@ int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be12 to yuv422p12le with required SIMD level. @@ -346,16 +343,15 @@ int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_yuv422p12le_simd(struct st20_rfc4175_422_12_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be12_to_yuv422p12le_simd( + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level); /** - * Convert rfc4175_422be12 to yuv422p12le with required SIMD level and DMA helper. - * Note the level may downgrade to the SIMD which system really support. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422be12 to yuv422p12le with required SIMD level and DMA + * helper. Note the level may downgrade to the SIMD which system really support. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -379,11 +375,10 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd(struct st20_rfc4175_422_12_pg2_be* * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_yuv422p12le_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, - uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be12_to_yuv422p12le_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be12 to rfc4175_422le12 with required SIMD level. @@ -403,16 +398,16 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd_dma(mtl_udma_handle udma, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_422le12_simd(struct st20_rfc4175_422_12_pg2_be* pg_be, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be12_to_422le12_simd( + struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** - * Convert rfc4175_422be12 to rfc4175_422le12 with required SIMD level and DMA helper. - * Note the level may downgrade to the SIMD which system really support. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422be12 to rfc4175_422le12 with required SIMD level and DMA + * helper. Note the level may downgrade to the SIMD which system really support. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -432,12 +427,10 @@ int st20_rfc4175_422be12_to_422le12_simd(struct st20_rfc4175_422_12_pg2_be* pg_b * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_422le12_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be12_to_422le12_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_444be10 to yuv444p10le/gbrp10le with required SIMD level. @@ -461,9 +454,9 @@ int st20_rfc4175_422be12_to_422le12_simd_dma(mtl_udma_handle udma, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be* pg, - uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - uint32_t w, uint32_t h, +int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h, enum mtl_simd_level level); /** @@ -484,10 +477,10 @@ int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be* pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444be10_to_444le10_simd(struct st20_rfc4175_444_10_pg4_be* pg_be, - struct st20_rfc4175_444_10_pg4_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444be10_to_444le10_simd( + struct st20_rfc4175_444_10_pg4_be *pg_be, + struct st20_rfc4175_444_10_pg4_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_444be12 to yuv444p12le/gbrp12le with required SIMD level. @@ -511,9 +504,9 @@ int st20_rfc4175_444be10_to_444le10_simd(struct st20_rfc4175_444_10_pg4_be* pg_b * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be* pg, - uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - uint32_t w, uint32_t h, +int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h, enum mtl_simd_level level); /** @@ -534,10 +527,10 @@ int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be* pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444be12_to_444le12_simd(struct st20_rfc4175_444_12_pg2_be* pg_be, - struct st20_rfc4175_444_12_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444be12_to_444le12_simd( + struct st20_rfc4175_444_12_pg2_be *pg_be, + struct st20_rfc4175_444_12_pg2_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv422p10le to rfc4175_422be10 with required SIMD level. @@ -561,14 +554,14 @@ int st20_rfc4175_444be12_to_444le12_simd(struct st20_rfc4175_444_12_pg2_be* pg_b * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_yuv422p10le_to_rfc4175_422be10_simd(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_yuv422p10le_to_rfc4175_422be10_simd( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** - * Convert yuv422p10le to rfc4175_422be10 with required SIMD level and DMA helper. - * Note the level may downgrade to the SIMD which system really support. + * Convert yuv422p10le to rfc4175_422be10 with required SIMD level and DMA + * helper. Note the level may downgrade to the SIMD which system really support. * * @param udma * Point to dma engine. @@ -597,9 +590,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd(uint16_t* y, uint16_t* b, uint16_t* * - <0: Error code if convert fail. */ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint16_t* y, mtl_iova_t y_iova, uint16_t* b, mtl_iova_t b_iova, - uint16_t* r, mtl_iova_t r_iova, struct st20_rfc4175_422_10_pg2_be* pg, uint32_t w, - uint32_t h, enum mtl_simd_level level); + mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, + mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert v210 to rfc4175_422be10 with required SIMD level. @@ -619,9 +613,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_v210_to_rfc4175_422be10_simd(uint8_t* pg_v210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, enum mtl_simd_level level); +int st20_v210_to_rfc4175_422be10_simd(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert v210 to rfc4175_422be10 with required SIMD level and DMA helper. @@ -645,11 +640,10 @@ int st20_v210_to_rfc4175_422be10_simd(uint8_t* pg_v210, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_v210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint8_t* pg_v210, - mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_v210_to_rfc4175_422be10_simd_dma( + mtl_udma_handle udma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv422p12le to rfc4175_422be12 with required SIMD level. @@ -673,10 +667,10 @@ int st20_v210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint8_t* pg_v210 * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_yuv422p12le_to_rfc4175_422be12_simd(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_12_pg2_be* pg, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_yuv422p12le_to_rfc4175_422be12_simd( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_be *pg, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv444p10le or gbrp10le to rfc4175_444be10 with required SIMD level. @@ -700,8 +694,9 @@ int st20_yuv422p12le_to_rfc4175_422be12_simd(uint16_t* y, uint16_t* b, uint16_t* * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p10le_to_rfc4175_444be10_simd(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_10_pg4_be* pg, +int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level); @@ -727,8 +722,9 @@ int st20_444p10le_to_rfc4175_444be10_simd(uint16_t* y_g, uint16_t* b_r, uint16_t * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p12le_to_rfc4175_444be12_simd(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_12_pg2_be* pg, +int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level); @@ -750,16 +746,16 @@ int st20_444p12le_to_rfc4175_444be12_simd(uint16_t* y_g, uint16_t* b_r, uint16_t * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422le10_to_422be10_simd( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** - * Convert rfc4175_422le10 to rfc4175_422be10 with required SIMD level and DMA helper. - * Note the level may downgrade to the SIMD which system really support. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422le10 to rfc4175_422be10 with required SIMD level and DMA + * helper. Note the level may downgrade to the SIMD which system really support. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -779,12 +775,10 @@ int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le* pg_l * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le10_to_422be10_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_le* pg_le, - mtl_iova_t pg_le_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422le10_to_422be10_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422le10 to v210 with required SIMD level. @@ -804,8 +798,9 @@ int st20_rfc4175_422le10_to_422be10_simd_dma(mtl_udma_handle udma, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le10_to_v210_simd(uint8_t* pg_le, uint8_t* pg_v210, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422le10_to_v210_simd(uint8_t *pg_le, uint8_t *pg_v210, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to y210 with required SIMD level. @@ -825,15 +820,15 @@ int st20_rfc4175_422le10_to_v210_simd(uint8_t* pg_le, uint8_t* pg_v210, uint32_t * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint16_t* pg_y210, uint32_t w, uint32_t h, +int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint16_t *pg_y210, uint32_t w, uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be10 to y210 with required SIMD level and DMA helper. * Note the level may downgrade to the SIMD which system really support. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -853,11 +848,10 @@ int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_y210_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* pg_y210, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_y210_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert y210 to rfc4175_422be10 with required SIMD level. @@ -877,9 +871,10 @@ int st20_rfc4175_422be10_to_y210_simd_dma(mtl_udma_handle udma, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_y210_to_rfc4175_422be10_simd(uint16_t* pg_y210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, enum mtl_simd_level level); +int st20_y210_to_rfc4175_422be10_simd(uint16_t *pg_y210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert y210 to rfc4175_422be10 with required SIMD level and DMA helper. @@ -903,11 +898,10 @@ int st20_y210_to_rfc4175_422be10_simd(uint16_t* pg_y210, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_y210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint16_t* pg_y210, - mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_y210_to_rfc4175_422be10_simd_dma( + mtl_udma_handle udma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422le12 to rfc4175_422be12 with required SIMD level. @@ -927,10 +921,10 @@ int st20_y210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint16_t* pg_y21 * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le12_to_422be12_simd(struct st20_rfc4175_422_12_pg2_le* pg_le, - struct st20_rfc4175_422_12_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422le12_to_422be12_simd( + struct st20_rfc4175_422_12_pg2_le *pg_le, + struct st20_rfc4175_422_12_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_444le10 to rfc4175_444be10 with required SIMD level. @@ -950,10 +944,10 @@ int st20_rfc4175_422le12_to_422be12_simd(struct st20_rfc4175_422_12_pg2_le* pg_l * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le10_to_444be10_simd(struct st20_rfc4175_444_10_pg4_le* pg_le, - struct st20_rfc4175_444_10_pg4_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444le10_to_444be10_simd( + struct st20_rfc4175_444_10_pg4_le *pg_le, + struct st20_rfc4175_444_10_pg4_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv444p10le or gbrp10le to rfc4175_444le10. * @@ -973,9 +967,10 @@ int st20_rfc4175_444le10_to_444be10_simd(struct st20_rfc4175_444_10_pg4_le* pg_l * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p10le_to_rfc4175_444le10(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_10_pg4_le* pg, uint32_t w, - uint32_t h); +int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_le *pg, + uint32_t w, uint32_t h); /** * Convert rfc4175_444le10 to yuv444p10le or gbrp10le. @@ -996,9 +991,9 @@ int st20_444p10le_to_rfc4175_444le10(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le* pg, uint16_t* y_g, - uint16_t* b_r, uint16_t* r_b, uint32_t w, - uint32_t h); +int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h); /** * Convert rfc4175_444le12 to rfc4175_444be12 with required SIMD level. @@ -1018,10 +1013,10 @@ int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le* pg, uint * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le12_to_444be12_simd(struct st20_rfc4175_444_12_pg2_le* pg_le, - struct st20_rfc4175_444_12_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444le12_to_444be12_simd( + struct st20_rfc4175_444_12_pg2_le *pg_le, + struct st20_rfc4175_444_12_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv444p12le or gbrp12le to rfc4175_444le12. * @@ -1041,9 +1036,10 @@ int st20_rfc4175_444le12_to_444be12_simd(struct st20_rfc4175_444_12_pg2_le* pg_l * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p12le_to_rfc4175_444le12(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_12_pg2_le* pg, uint32_t w, - uint32_t h); +int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_le *pg, + uint32_t w, uint32_t h); /** * Convert rfc4175_444le12 to yuv444p12le or gbrp12le. @@ -1064,14 +1060,14 @@ int st20_444p12le_to_rfc4175_444le12(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le* pg, uint16_t* y_g, - uint16_t* b_r, uint16_t* r_b, uint32_t w, - uint32_t h); +int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h); /** - * Convert rfc4175_422be10 to yuv422p10le with the max optimized SIMD level and DMA - * helper. Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus - * pls only applied with 4k/8k. + * Convert rfc4175_422be10 to yuv422p10le with the max optimized SIMD level and + * DMA helper. Profiling shows gain with 4k/8k solution due to LLC cache miss + * migration, thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1094,16 +1090,17 @@ int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le* pg, uint * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_yuv422p10le_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be* pg_be, mtl_iova_t pg_be_iova, - uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p10le_simd_dma(udma, pg_be, pg_be_iova, y, b, r, w, - h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p10le_simd_dma( + udma, pg_be, pg_be_iova, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** - * Convert rfc4175_422be10 to rfc4175_422le10 with max SIMD level and DMA helper. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422be10 to rfc4175_422le10 with max SIMD level and DMA + * helper. Profiling shows gain with 4k/8k solution due to LLC cache miss + * migration, thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1122,16 +1119,17 @@ static inline int st20_rfc4175_422be10_to_yuv422p10le_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_422le10_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be* pg_be, mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_10_pg2_le* pg_le, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_422le10_simd_dma(udma, pg_be, pg_be_iova, pg_le, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_422le10_simd_dma( + udma, pg_be, pg_be_iova, pg_le, w, h, MTL_SIMD_LEVEL_MAX); } /** * Convert rfc4175_422be10 to v210 with max SIMD level and DMA helper. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1150,16 +1148,16 @@ static inline int st20_rfc4175_422be10_to_422le10_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_v210_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be* pg_be, mtl_iova_t pg_be_iova, - uint8_t* pg_v210, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_v210_simd_dma(udma, pg_be, pg_be_iova, pg_v210, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_v210_simd_dma(udma, pg_be, pg_be_iova, pg_v210, + w, h, MTL_SIMD_LEVEL_MAX); } /** - * Convert rfc4175_422be10 to rfc4175_422le8(packed UYVY) with max SIMD level and DMA - * helper. Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus - * pls only applied with 4k/8k. + * Convert rfc4175_422be10 to rfc4175_422le8(packed UYVY) with max SIMD level + * and DMA helper. Profiling shows gain with 4k/8k solution due to LLC cache + * miss migration, thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1178,16 +1176,17 @@ static inline int st20_rfc4175_422be10_to_v210_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_422le8_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be* pg_10, mtl_iova_t pg_10_iova, - struct st20_rfc4175_422_8_pg2_le* pg_8, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_422le8_simd_dma(udma, pg_10, pg_10_iova, pg_8, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_422le8_simd_dma(udma, pg_10, pg_10_iova, pg_8, + w, h, MTL_SIMD_LEVEL_MAX); } /** - * Convert rfc4175_422be12 to yuv422p12le with the max optimized SIMD level and DMA - * helper. Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus - * pls only applied with 4k/8k. + * Convert rfc4175_422be12 to yuv422p12le with the max optimized SIMD level and + * DMA helper. Profiling shows gain with 4k/8k solution due to LLC cache miss + * migration, thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1210,16 +1209,17 @@ static inline int st20_rfc4175_422be10_to_422le8_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be12_to_yuv422p12le_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be* pg_be, mtl_iova_t pg_be_iova, - uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, uint32_t h) { - return st20_rfc4175_422be12_to_yuv422p12le_simd_dma(udma, pg_be, pg_be_iova, y, b, r, w, - h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be12_to_yuv422p12le_simd_dma( + udma, pg_be, pg_be_iova, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** - * Convert rfc4175_422be12 to rfc4175_422le12 with max SIMD level and DMA helper. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422be12 to rfc4175_422le12 with max SIMD level and DMA + * helper. Profiling shows gain with 4k/8k solution due to LLC cache miss + * migration, thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1238,10 +1238,11 @@ static inline int st20_rfc4175_422be12_to_yuv422p12le_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be12_to_422le12_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be* pg_be, mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_12_pg2_le* pg_le, uint32_t w, uint32_t h) { - return st20_rfc4175_422be12_to_422le12_simd_dma(udma, pg_be, pg_be_iova, pg_le, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be12_to_422le12_simd_dma( + udma, pg_be, pg_be_iova, pg_le, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -1272,9 +1273,9 @@ static inline int st20_rfc4175_422be12_to_422le12_dma( * - <0: Error code if convert fail. */ static inline int st20_yuv422p10le_to_rfc4175_422be10_dma( - mtl_udma_handle udma, uint16_t* y, mtl_iova_t y_iova, uint16_t* b, mtl_iova_t b_iova, - uint16_t* r, mtl_iova_t r_iova, struct st20_rfc4175_422_10_pg2_be* pg, uint32_t w, - uint32_t h) { + mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, + mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { return st20_yuv422p10le_to_rfc4175_422be10_simd_dma( udma, y, y_iova, b, b_iova, r, r_iova, pg, w, h, MTL_SIMD_LEVEL_MAX); } @@ -1300,16 +1301,16 @@ static inline int st20_yuv422p10le_to_rfc4175_422be10_dma( * - <0: Error code if convert fail. */ static inline int st20_v210_to_rfc4175_422be10_dma( - mtl_udma_handle udma, uint8_t* pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, uint32_t w, uint32_t h) { - return st20_v210_to_rfc4175_422be10_simd_dma(udma, pg_v210, pg_v210_iova, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { + return st20_v210_to_rfc4175_422be10_simd_dma(udma, pg_v210, pg_v210_iova, + pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** - * Convert rfc4175_422le10 to rfc4175_422be10 with max SIMD level and DMA helper. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Convert rfc4175_422le10 to rfc4175_422be10 with max SIMD level and DMA + * helper. Profiling shows gain with 4k/8k solution due to LLC cache miss + * migration, thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1328,16 +1329,17 @@ static inline int st20_v210_to_rfc4175_422be10_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422le10_to_422be10_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le* pg_le, mtl_iova_t pg_le_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, uint32_t w, uint32_t h) { - return st20_rfc4175_422le10_to_422be10_simd_dma(udma, pg_le, pg_le_iova, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h) { + return st20_rfc4175_422le10_to_422be10_simd_dma( + udma, pg_le, pg_le_iova, pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** * Convert rfc4175_422be10 to y210 with max SIMD level and DMA helper. - * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, thus pls - * only applied with 4k/8k. + * Profiling shows gain with 4k/8k solution due to LLC cache miss migration, + * thus pls only applied with 4k/8k. * * @param udma * Point to dma engine. @@ -1356,10 +1358,10 @@ static inline int st20_rfc4175_422le10_to_422be10_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_y210_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be* pg_be, mtl_iova_t pg_be_iova, - uint16_t* pg_y210, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_y210_simd_dma(udma, pg_be, pg_be_iova, pg_y210, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_y210_simd_dma(udma, pg_be, pg_be_iova, pg_y210, + w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -1383,15 +1385,16 @@ static inline int st20_rfc4175_422be10_to_y210_dma( * - <0: Error code if convert fail. */ static inline int st20_y210_to_rfc4175_422be10_dma( - mtl_udma_handle udma, uint16_t* pg_y210, mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, uint32_t w, uint32_t h) { - return st20_y210_to_rfc4175_422be10_simd_dma(udma, pg_y210, pg_y210_iova, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { + return st20_y210_to_rfc4175_422be10_simd_dma(udma, pg_y210, pg_y210_iova, + pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** - * Convert rfc4175_422be10 to dual v210 streams(one full and one decimated) with required - * SIMD level. Note the level may downgrade to the SIMD which system really support. + * Convert rfc4175_422be10 to dual v210 streams(one full and one decimated) with + * required SIMD level. Note the level may downgrade to the SIMD which system + * really support. * * Todo: add SIMD implementation * @@ -1411,29 +1414,29 @@ static inline int st20_y210_to_rfc4175_422be10_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int st20_rfc4175_422be10_to_v210_2way( - struct st20_rfc4175_422_10_pg2_be* pg_be, uint8_t* pg_v210_full, uint32_t w, - uint32_t h, uint8_t* pg_v210_decimated, int decimator) { - return st20_rfc4175_422be10_to_v210_simd_2way( - pg_be, pg_v210_full, w, h, pg_v210_decimated, decimator, MTL_SIMD_LEVEL_MAX); +static inline int +st20_rfc4175_422be10_to_v210_2way(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210_full, uint32_t w, uint32_t h, + uint8_t *pg_v210_decimated, int decimator) { + return st20_rfc4175_422be10_to_v210_simd_2way(pg_be, pg_v210_full, w, h, + pg_v210_decimated, decimator, + MTL_SIMD_LEVEL_MAX); } -/** helper to call st20_rfc4175_422be10_to_v210_2way with mtl_cpuva_t type for python - * binding */ -static inline int st20_rfc4175_422be10_to_v210_2way_cpuva(mtl_cpuva_t pg_be, - mtl_cpuva_t pg_v210_full, - uint32_t w, uint32_t h, - mtl_cpuva_t pg_v210_decimated, - int decimator) { - return st20_rfc4175_422be10_to_v210_2way((struct st20_rfc4175_422_10_pg2_be*)pg_be, - (uint8_t*)pg_v210_full, w, h, - (uint8_t*)pg_v210_decimated, decimator); +/** helper to call st20_rfc4175_422be10_to_v210_2way with mtl_cpuva_t type for + * python binding */ +static inline int st20_rfc4175_422be10_to_v210_2way_cpuva( + mtl_cpuva_t pg_be, mtl_cpuva_t pg_v210_full, uint32_t w, uint32_t h, + mtl_cpuva_t pg_v210_decimated, int decimator) { + return st20_rfc4175_422be10_to_v210_2way( + (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint8_t *)pg_v210_full, w, h, + (uint8_t *)pg_v210_decimated, decimator); } /** - * Convert rfc4175_422be10 to dual yuv422p10le streams(one full and one decimated) with - * required SIMD level. Note the level may downgrade to the SIMD which system really - * support. + * Convert rfc4175_422be10 to dual yuv422p10le streams(one full and one + * decimated) with required SIMD level. Note the level may downgrade to the SIMD + * which system really support. * * Todo: add SIMD implementation * @@ -1462,24 +1465,25 @@ static inline int st20_rfc4175_422be10_to_v210_2way_cpuva(mtl_cpuva_t pg_be, * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_yuv422p10le_2way( - struct st20_rfc4175_422_10_pg2_be* pg_be, uint16_t* y_full, uint16_t* b_full, - uint16_t* r_full, uint32_t w, uint32_t h, uint16_t* y_decimated, - uint16_t* b_decimated, uint16_t* r_decimated, int decimator) { + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, + uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, + uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, + int decimator) { return st20_rfc4175_422be10_to_yuv422p10le_simd_2way( - pg_be, y_full, b_full, r_full, w, h, y_decimated, b_decimated, r_decimated, - decimator, MTL_SIMD_LEVEL_MAX); + pg_be, y_full, b_full, r_full, w, h, y_decimated, b_decimated, + r_decimated, decimator, MTL_SIMD_LEVEL_MAX); } -/** helper to call st20_rfc4175_422be10_to_yuv422p10le_2way with mtl_cpuva_t type for - * python binding */ +/** helper to call st20_rfc4175_422be10_to_yuv422p10le_2way with mtl_cpuva_t + * type for python binding */ static inline int st20_rfc4175_422be10_to_yuv422p10le_2way_cpuva( - mtl_cpuva_t pg_be, mtl_cpuva_t y_full, mtl_cpuva_t b_full, mtl_cpuva_t r_full, - uint32_t w, uint32_t h, mtl_cpuva_t y_decimated, mtl_cpuva_t b_decimated, - mtl_cpuva_t r_decimated, int decimator) { + mtl_cpuva_t pg_be, mtl_cpuva_t y_full, mtl_cpuva_t b_full, + mtl_cpuva_t r_full, uint32_t w, uint32_t h, mtl_cpuva_t y_decimated, + mtl_cpuva_t b_decimated, mtl_cpuva_t r_decimated, int decimator) { return st20_rfc4175_422be10_to_yuv422p10le_2way( - (struct st20_rfc4175_422_10_pg2_be*)pg_be, (uint16_t*)y_full, (uint16_t*)b_full, - (uint16_t*)r_full, w, h, (uint16_t*)y_decimated, (uint16_t*)b_decimated, - (uint16_t*)r_decimated, decimator); + (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint16_t *)y_full, + (uint16_t *)b_full, (uint16_t *)r_full, w, h, (uint16_t *)y_decimated, + (uint16_t *)b_decimated, (uint16_t *)r_decimated, decimator); } #if defined(__cplusplus) diff --git a/include/st_pipeline_api.h b/include/st_pipeline_api.h index 7e3becce2..f2cd2af2f 100644 --- a/include/st_pipeline_api.h +++ b/include/st_pipeline_api.h @@ -6,8 +6,8 @@ * @file st_pipeline_api.h * * Interfaces for st2110-20/22 pipeline transport. - * It include a plugin layer to hide the covert/encode detail that application can - * focus on the raw pixel handling. + * It include a plugin layer to hide the covert/encode detail that application + * can focus on the raw pixel handling. * */ @@ -21,41 +21,41 @@ extern "C" { #endif /** Handle to tx st2110-22 pipeline session of lib */ -typedef struct st22p_tx_ctx* st22p_tx_handle; +typedef struct st22p_tx_ctx *st22p_tx_handle; /** Handle to rx st2110-22 pipeline session of lib */ -typedef struct st22p_rx_ctx* st22p_rx_handle; +typedef struct st22p_rx_ctx *st22p_rx_handle; /** Handle to tx st2110-20 pipeline session of lib */ -typedef struct st20p_tx_ctx* st20p_tx_handle; +typedef struct st20p_tx_ctx *st20p_tx_handle; /** Handle to rx st2110-20 pipeline session of lib */ -typedef struct st20p_rx_ctx* st20p_rx_handle; +typedef struct st20p_rx_ctx *st20p_rx_handle; /** Handle to st2110-22 encode device of lib */ -typedef struct st22_encode_dev_impl* st22_encoder_dev_handle; +typedef struct st22_encode_dev_impl *st22_encoder_dev_handle; /** Handle to st2110-22 decode device of lib */ -typedef struct st22_decode_dev_impl* st22_decoder_dev_handle; +typedef struct st22_decode_dev_impl *st22_decoder_dev_handle; /** Handle to st2110-20 convert device of lib */ -typedef struct st20_convert_dev_impl* st20_converter_dev_handle; +typedef struct st20_convert_dev_impl *st20_converter_dev_handle; /** Handle to the st22 encode session private data */ -typedef void* st22_encode_priv; +typedef void *st22_encode_priv; /** Handle to the st2110-22 pipeline encode session of lib */ -typedef struct st22_encode_session_impl* st22p_encode_session; +typedef struct st22_encode_session_impl *st22p_encode_session; /** Handle to the st22 decode session private data */ -typedef void* st22_decode_priv; +typedef void *st22_decode_priv; /** Handle to the st2110-22 pipeline decode session of lib */ -typedef struct st22_decode_session_impl* st22p_decode_session; +typedef struct st22_decode_session_impl *st22p_decode_session; /** Handle to the st20 convert session private data */ -typedef void* st20_convert_priv; +typedef void *st20_convert_priv; /** Handle to the st2110-20 pipeline convert session of lib */ -typedef struct st20_convert_session_impl* st20p_convert_session; +typedef struct st20_convert_session_impl *st20p_convert_session; /** Handle to the private data of plugin */ -typedef void* st_plugin_priv; +typedef void *st_plugin_priv; /** Version type of st plugin */ enum st_plugin_version { @@ -82,7 +82,7 @@ struct st_plugin_meta { }; /** Get meta function prototype of plugin */ -typedef int (*st_plugin_get_meta_fn)(struct st_plugin_meta* meta); +typedef int (*st_plugin_get_meta_fn)(struct st_plugin_meta *meta); /** Get meta function name of plugin */ #define ST_PLUGIN_GET_META_API "st_plugin_get_meta" /** Create function prototype of plugin */ @@ -135,15 +135,17 @@ enum st_frame_fmt { */ ST_FRAME_FMT_YUV444RFC4175PG2BE12 = 11, /** Customized YUV 420 8bit, set transport format as ST20_FMT_YUV_420_8BIT. - * This is used when user wants to directly transport none-RFC4175 formats like - * I420/NV12. When this input/output format is set, the frame is identical to - * transport frame without conversion. The frame should not have lines padding. + * This is used when user wants to directly transport none-RFC4175 formats + * like I420/NV12. When this input/output format is set, the frame is + * identical to transport frame without conversion. The frame should not have + * lines padding. */ ST_FRAME_FMT_YUV420CUSTOM8 = 12, /** Customized YUV 422 8bit, set transport format as ST20_FMT_YUV_422_8BIT. - * This is used when user wants to directly transport none-RFC4175 formats like - * YUY2. When this input/output format is set, the frame is identical to - * transport frame without conversion. The frame should not have lines padding. + * This is used when user wants to directly transport none-RFC4175 formats + * like YUY2. When this input/output format is set, the frame is identical to + * transport frame without conversion. The frame should not have lines + * padding. */ ST_FRAME_FMT_YUV422CUSTOM8 = 13, /** YUV 420 planar 8bit */ @@ -207,7 +209,8 @@ enum st_frame_fmt { /** ST format cap of ST_FRAME_FMT_UYVY */ #define ST_FMT_CAP_UYVY (MTL_BIT64(ST_FRAME_FMT_UYVY)) /** ST format cap of ST_FRAME_FMT_YUV422RFC4175PG2BE10 */ -#define ST_FMT_CAP_YUV422RFC4175PG2BE10 (MTL_BIT64(ST_FRAME_FMT_YUV422RFC4175PG2BE10)) +#define ST_FMT_CAP_YUV422RFC4175PG2BE10 \ + (MTL_BIT64(ST_FRAME_FMT_YUV422RFC4175PG2BE10)) /** ST format cap of ST_FRAME_FMT_ARGB */ #define ST_FMT_CAP_ARGB (MTL_BIT64(ST_FRAME_FMT_ARGB)) @@ -216,15 +219,22 @@ enum st_frame_fmt { /** ST format cap of ST_FRAME_FMT_RGB8 */ #define ST_FMT_CAP_RGB8 (MTL_BIT64(ST_FRAME_FMT_RGB8)) -/** ST format cap of ST_FRAME_FMT_JPEGXS_CODESTREAM, used in the st22_plugin caps */ +/** ST format cap of ST_FRAME_FMT_JPEGXS_CODESTREAM, used in the st22_plugin + * caps */ #define ST_FMT_CAP_JPEGXS_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_JPEGXS_CODESTREAM)) -/** ST format cap of ST_FRAME_FMT_H264_CBR_CODESTREAM, used in the st22_plugin caps */ -#define ST_FMT_CAP_H264_CBR_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H264_CBR_CODESTREAM)) -/** ST format cap of ST_FRAME_FMT_H264_CODESTREAM, used in the st22_plugin caps */ +/** ST format cap of ST_FRAME_FMT_H264_CBR_CODESTREAM, used in the st22_plugin + * caps */ +#define ST_FMT_CAP_H264_CBR_CODESTREAM \ + (MTL_BIT64(ST_FRAME_FMT_H264_CBR_CODESTREAM)) +/** ST format cap of ST_FRAME_FMT_H264_CODESTREAM, used in the st22_plugin caps + */ #define ST_FMT_CAP_H264_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H264_CODESTREAM)) -/** ST format cap of ST_FRAME_FMT_H265_CBR_CODESTREAM, used in the st22_plugin caps */ -#define ST_FMT_CAP_H265_CBR_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H265_CBR_CODESTREAM)) -/** ST format cap of ST_FRAME_FMT_H265_CODESTREAM, used in the st22_plugin caps */ +/** ST format cap of ST_FRAME_FMT_H265_CBR_CODESTREAM, used in the st22_plugin + * caps */ +#define ST_FMT_CAP_H265_CBR_CODESTREAM \ + (MTL_BIT64(ST_FRAME_FMT_H265_CBR_CODESTREAM)) +/** ST format cap of ST_FRAME_FMT_H265_CODESTREAM, used in the st22_plugin caps + */ #define ST_FMT_CAP_H265_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H265_CODESTREAM)) /** Flag bit in flags of struct st_frame. */ @@ -242,7 +252,7 @@ enum st_frame_flag { /** The structure info for external frame */ struct st_ext_frame { /** Each plane's virtual address of external frame */ - void* addr[ST_MAX_PLANES]; + void *addr[ST_MAX_PLANES]; /** Each plane's IOVA of external frame */ mtl_iova_t iova[ST_MAX_PLANES]; /** Each plane's linesize of external frame, @@ -251,13 +261,13 @@ struct st_ext_frame { /** Each plane's virtual address of external frame */ /** Buffer size of external frame */ size_t size; /** Private data for user */ - void* opaque; + void *opaque; }; /** The structure info for frame meta. */ struct st_frame { /** frame buffer address of each plane */ - void* addr[ST_MAX_PLANES]; + void *addr[ST_MAX_PLANES]; /** frame buffer IOVA of each plane */ mtl_iova_t iova[ST_MAX_PLANES]; /** frame buffer linesize of each plane */ @@ -294,27 +304,28 @@ struct st_frame { enum st_frame_status status; /** - * The user meta data buffer for current frame of st20, the size must smaller than - * MTL_PKT_MAX_RTP_BYTES. This data will be transported to RX with video data and passed - * to user by user_meta also. + * The user meta data buffer for current frame of st20, the size must smaller + * than MTL_PKT_MAX_RTP_BYTES. This data will be transported to RX with video + * data and passed to user by user_meta also. */ - const void* user_meta; + const void *user_meta; /** size for meta data buffer */ size_t user_meta_size; /** the total packets received, not include the redundant packets */ uint32_t pkts_total; - /** the valid packets received on each session port. For each session port, the validity - * of received packets can be assessed by comparing 'pkts_recv[s_port]' with - * 'pkts_total,' which serves as an indicator of signal quality. */ + /** the valid packets received on each session port. For each session port, + * the validity of received packets can be assessed by comparing + * 'pkts_recv[s_port]' with 'pkts_total,' which serves as an indicator of + * signal quality. */ uint32_t pkts_recv[MTL_SESSION_PORT_MAX]; /** priv pointer for lib, do not touch this */ - void* priv; + void *priv; /** priv data for user */ - void* opaque; + void *opaque; /** timing parser meta for st20p_rx_get_frame, only active if * ST20P_RX_FLAG_TIMING_PARSER_META */ - struct st20_rx_tp_meta* tp[MTL_SESSION_PORT_MAX]; + struct st20_rx_tp_meta *tp[MTL_SESSION_PORT_MAX]; }; /** Device type of st plugin */ @@ -386,7 +397,8 @@ enum st22p_tx_flag { */ ST22P_TX_FLAG_USER_TIMESTAMP = (MTL_BIT32(4)), /** - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ ST22P_TX_FLAG_ENABLE_VSYNC = (MTL_BIT32(5)), /** @@ -394,8 +406,9 @@ enum st22p_tx_flag { */ ST22P_TX_FLAG_ENABLE_RTCP = (MTL_BIT32(6)), /** - * Set this flag to the bulk operation on all internal buffer rings. It may degrade the - * performance since the object enqueue/dequeue will be acted one by one. + * Set this flag to the bulk operation on all internal buffer rings. It may + * degrade the performance since the object enqueue/dequeue will be acted one + * by one. */ ST22P_TX_FLAG_DISABLE_BULK = (MTL_BIT32(7)), /** @@ -407,7 +420,8 @@ enum st22p_tx_flag { /** Force the numa of the created session, both CPU and memory */ ST22P_TX_FLAG_FORCE_NUMA = (MTL_BIT32(9)), /** Enable the st22p_tx_get_frame block behavior to wait until a frame becomes - available or timeout(default: 1s, use st22p_tx_set_block_timeout to customize) */ + available or timeout(default: 1s, use st22p_tx_set_block_timeout to + customize) */ ST22P_TX_FLAG_BLOCK_GET = (MTL_BIT32(15)), }; @@ -438,7 +452,8 @@ enum st20p_tx_flag { */ ST20P_TX_FLAG_USER_TIMESTAMP = (MTL_BIT32(4)), /** - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ ST20P_TX_FLAG_ENABLE_VSYNC = (MTL_BIT32(5)), /** @@ -450,8 +465,8 @@ enum st20p_tx_flag { */ ST20P_TX_FLAG_ENABLE_RTCP = (MTL_BIT32(7)), /** - * Set this flag to set rtp timestamp at the time of the first packet egresses from the - * sender. + * Set this flag to set rtp timestamp at the time of the first packet egresses + * from the sender. */ ST20P_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT = (MTL_BIT32(8)), /** @@ -459,8 +474,9 @@ enum st20p_tx_flag { */ ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH = (MTL_BIT32(9)), /** - * Set this flag to the bulk operation on all internal buffer rings. It may degrade the - * performance since the object enqueue/dequeue will be acted one by one. + * Set this flag to the bulk operation on all internal buffer rings. It may + * degrade the performance since the object enqueue/dequeue will be acted one + * by one. */ ST20P_TX_FLAG_DISABLE_BULK = (MTL_BIT32(10)), /** Force the numa of the created session, both CPU and memory */ @@ -473,12 +489,14 @@ enum st20p_tx_flag { /** Bit define for flags of struct st22p_rx_ops. */ enum st22p_rx_flag { /** - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st22p_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st22p_rx_get_queue_meta to get the queue meta(queue number + * etc) info. */ ST22P_RX_FLAG_DATA_PATH_ONLY = (MTL_BIT32(0)), /** - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ ST22P_RX_FLAG_ENABLE_VSYNC = (MTL_BIT32(1)), /** @@ -492,14 +510,16 @@ enum st22p_rx_flag { ST22P_RX_FLAG_SIMULATE_PKT_LOSS = (MTL_BIT32(3)), /** * Enable the dynamic external frame mode, and user must provide a query - * callback(query_ext_frame in st22p_rx_ops) to let MTL can get the frame when needed. + * callback(query_ext_frame in st22p_rx_ops) to let MTL can get the frame when + * needed. */ ST22P_RX_FLAG_EXT_FRAME = (MTL_BIT32(4)), /** Force the numa of the created session, both CPU and memory */ ST22P_RX_FLAG_FORCE_NUMA = MTL_BIT32(5), /** Enable the st22p_rx_get_frame block behavior to wait until a frame becomes - available or timeout(default: 1s, use st22p_rx_set_block_timeout to customize) */ + available or timeout(default: 1s, use st22p_rx_set_block_timeout to + customize) */ ST22P_RX_FLAG_BLOCK_GET = (MTL_BIT32(15)), /** * If set, lib will pass the incomplete frame to app also. @@ -512,18 +532,21 @@ enum st22p_rx_flag { enum st20p_rx_flag { /** * for non MTL_PMD_DPDK_USER. - * If set, it's application duty to set the rx flow(queue) and multicast join/drop. - * Use st20p_rx_get_queue_meta to get the queue meta(queue number etc) info. + * If set, it's application duty to set the rx flow(queue) and multicast + * join/drop. Use st20p_rx_get_queue_meta to get the queue meta(queue number + * etc) info. */ ST20P_RX_FLAG_DATA_PATH_ONLY = (MTL_BIT32(0)), /** - * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch start. + * If enabled, lib will pass ST_EVENT_VSYNC by the notify_event on every epoch + * start. */ ST20P_RX_FLAG_ENABLE_VSYNC = (MTL_BIT32(1)), /** * Enable the dynamic external frame mode, and user must provide a query - * callback(query_ext_frame in st20p_rx_ops) to let MTL can get the frame when needed. - * Note to enable ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME also for non-converter mode. + * callback(query_ext_frame in st20p_rx_ops) to let MTL can get the frame when + * needed. Note to enable ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME also for + * non-converter mode. */ ST20P_RX_FLAG_EXT_FRAME = (MTL_BIT32(2)), /** @@ -592,16 +615,18 @@ enum st20p_rx_flag { /** Bit define for flag_resp of struct st22_decoder_create_req. */ enum st22_decoder_resp_flag { - /** Enable the st22_decoder_get_frame block behavior to wait until a frame becomes - available or timeout(default: 1s, use st22_decoder_set_block_timeout to customize) + /** Enable the st22_decoder_get_frame block behavior to wait until a frame + becomes available or timeout(default: 1s, use + st22_decoder_set_block_timeout to customize) */ ST22_DECODER_RESP_FLAG_BLOCK_GET = (MTL_BIT32(0)), }; /** Bit define for flag_resp of struct st22_encoder_create_req. */ enum st22_encoder_resp_flag { - /** Enable the st22_encoder_get_frame block behavior to wait until a frame becomes - available or timeout(default: 1s, use st22_encoder_set_block_timeout to customize) + /** Enable the st22_encoder_get_frame block behavior to wait until a frame + becomes available or timeout(default: 1s, use + st22_encoder_set_block_timeout to customize) */ ST22_ENCODER_RESP_FLAG_BLOCK_GET = (MTL_BIT32(0)), }; @@ -639,9 +664,9 @@ struct st22_encoder_create_req { /** The structure info for st22 encoder dev. */ struct st22_encoder_dev { /** name */ - const char* name; + const char *name; /** private data to the callback function */ - void* priv; + void *priv; /** device, cpu/gpu/fpga/others */ enum st_plugin_device target_device; @@ -650,22 +675,22 @@ struct st22_encoder_dev { /** supported output format for encode, ST_FMT_CAP_* */ uint64_t output_fmt_caps; /** create session function */ - st22_encode_priv (*create_session)(void* priv, st22p_encode_session session_p, - struct st22_encoder_create_req* req); + st22_encode_priv (*create_session)(void *priv, st22p_encode_session session_p, + struct st22_encoder_create_req *req); /** Callback when frame available in the lib. */ int (*notify_frame_available)(st22_encode_priv encode_priv); /** free session function */ - int (*free_session)(void* priv, st22_encode_priv encode_priv); + int (*free_session)(void *priv, st22_encode_priv encode_priv); }; /** The structure info for st22 encode frame meta. */ struct st22_encode_frame_meta { /** Encode source frame */ - struct st_frame* src; + struct st_frame *src; /** Encode dst frame */ - struct st_frame* dst; + struct st_frame *dst; /** priv pointer for lib, do not touch this */ - void* priv; + void *priv; }; /** The structure info for st plugin decode session create request. */ @@ -695,9 +720,9 @@ struct st22_decoder_create_req { /** The structure info for st22 decoder dev. */ struct st22_decoder_dev { /** name */ - const char* name; + const char *name; /** private data to the callback function */ - void* priv; + void *priv; /** device, cpu/gpu/fpga/others */ enum st_plugin_device target_device; @@ -706,22 +731,22 @@ struct st22_decoder_dev { /** supported output format for decode, ST_FMT_CAP_* */ uint64_t output_fmt_caps; /** create session function */ - st22_decode_priv (*create_session)(void* priv, st22p_decode_session session_p, - struct st22_decoder_create_req* req); + st22_decode_priv (*create_session)(void *priv, st22p_decode_session session_p, + struct st22_decoder_create_req *req); /** Callback when frame available in the lib. */ int (*notify_frame_available)(st22_decode_priv decode_priv); /** free session function */ - int (*free_session)(void* priv, st22_decode_priv decode_priv); + int (*free_session)(void *priv, st22_decode_priv decode_priv); }; /** The structure info for st22 decode frame meta. */ struct st22_decode_frame_meta { /** Decode source frame */ - struct st_frame* src; + struct st_frame *src; /** Decode dst frame */ - struct st_frame* dst; + struct st_frame *dst; /** priv pointer for lib, do not touch this */ - void* priv; + void *priv; }; /** The structure info for st plugin convert session create request. */ @@ -745,9 +770,9 @@ struct st20_converter_create_req { /** The structure info for st20 converter dev. */ struct st20_converter_dev { /** name */ - const char* name; + const char *name; /** private data to the callback function */ - void* priv; + void *priv; /** device, cpu/gpu/fpga/others */ enum st_plugin_device target_device; @@ -756,29 +781,31 @@ struct st20_converter_dev { /** supported output format for convert, ST_FMT_CAP_* */ uint64_t output_fmt_caps; /** create session function */ - st20_convert_priv (*create_session)(void* priv, st20p_convert_session session_p, - struct st20_converter_create_req* req); + st20_convert_priv (*create_session)(void *priv, + st20p_convert_session session_p, + struct st20_converter_create_req *req); /** Callback when frame available in the lib. */ int (*notify_frame_available)(st20_convert_priv convert_priv); /** free session function */ - int (*free_session)(void* priv, st20_convert_priv convert_priv); + int (*free_session)(void *priv, st20_convert_priv convert_priv); }; /** The structure info for st20 convert frame meta. */ struct st20_convert_frame_meta { /** Encode source frame */ - struct st_frame* src; + struct st_frame *src; /** Encode dst frame */ - struct st_frame* dst; + struct st_frame *dst; /** priv pointer for lib, do not touch this */ - void* priv; + void *priv; }; /** The structure info for st tx port, used in creating session. */ struct st_tx_port { /** Mandatory. Destination IP address */ uint8_t dip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDFs of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDFs of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -788,8 +815,8 @@ struct st_tx_port { uint8_t payload_type; /** Optional. UDP source port number, leave as 0 to use same port as dst */ uint16_t udp_src_port[MTL_SESSION_PORT_MAX]; - /** Optional. Synchronization source defined in RFC3550, if zero the session will assign - * a random value */ + /** Optional. Synchronization source defined in RFC3550, if zero the session + * will assign a random value */ uint32_t ssrc; }; @@ -799,20 +826,23 @@ struct st_rx_port { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t + sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; - /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of mtl_init */ + /** Mandatory. Pcie BDF path like 0000:af:00.0, should align to BDF of + * mtl_init */ char port[MTL_SESSION_PORT_MAX][MTL_PORT_MAX_LEN]; /** Mandatory. UDP destination port number */ uint16_t udp_port[MTL_SESSION_PORT_MAX]; /** Mandatory. 7 bits payload type define in RFC3550. Zero means disable the * payload_type check on the RX pkt path */ uint8_t payload_type; - /** Optional. Synchronization source defined in RFC3550, RX session will check the - * incoming RTP packets match the ssrc. Leave to zero to disable the ssrc check */ + /** Optional. Synchronization source defined in RFC3550, RX session will check + * the incoming RTP packets match the ssrc. Leave to zero to disable the ssrc + * check */ uint32_t ssrc; /** Optional. source filter IP address of multicast */ uint8_t mcast_sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; @@ -842,30 +872,31 @@ struct st20p_tx_ops { /** Mandatory. Convert plugin device, auto or special */ enum st_plugin_device device; /** - * Mandatory. The frame buffer count requested for one st20 pipeline tx session, - * should be in range [2, ST20_FB_MAX_COUNT], + * Mandatory. The frame buffer count requested for one st20 pipeline tx + * session, should be in range [2, ST20_FB_MAX_COUNT], */ uint16_t framebuff_cnt; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; - /** Optional. Flags to control session behaviors. See ST20P_TX_FLAG_* for possible value + void *priv; + /** Optional. Flags to control session behaviors. See ST20P_TX_FLAG_* for + * possible value */ uint32_t flags; /** * Optional.Callback when frame available in the lib. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_available)(void* priv); + int (*notify_frame_available)(void *priv); /** * Optional. Callback when frame done in the lib. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_done)(void* priv, struct st_frame* frame); + int (*notify_frame_done)(void *priv, struct st_frame *frame); /** Optional. Linesize for transport frame, only for non-convert mode */ size_t transport_linesize; @@ -879,14 +910,16 @@ struct st20p_tx_ops { uint8_t tx_dst_mac[MTL_SESSION_PORT_MAX][MTL_MAC_ADDR_LEN]; /** * Optional. The start vrx buffer. - * Leave to zero if not know detail, lib will assign a start value of vrx(narrow) based - * on resolution and timing. Refer to st21 spec for the possible vrx value and also fine - * tune is required since network setup difference and RL burst. + * Leave to zero if not know detail, lib will assign a start value of + * vrx(narrow) based on resolution and timing. Refer to st21 spec for the + * possible vrx value and also fine tune is required since network setup + * difference and RL burst. */ uint16_t start_vrx; /** * Optional. Manually assigned padding pkt interval(pkts level) for RL pacing. - * Leave to zero if not know detail, lib will train the interval in the initial routine. + * Leave to zero if not know detail, lib will train the interval in the + * initial routine. */ uint16_t pad_interval; /** @@ -895,18 +928,19 @@ struct st20p_tx_ops { */ int32_t rtp_timestamp_delta_us; /** - * Optional. the time for lib to detect the hang on the tx queue and try to recovery - * Leave to zero system will use the default value(1s). + * Optional. the time for lib to detect the hang on the tx queue and try to + * recovery Leave to zero system will use the default value(1s). */ uint32_t tx_hang_detect_ms; /** * event callback, lib will call this when there is some event happened. - * Only non-block method can be used in this callback as it run from lcore routine. - * args point to the meta data of each event. - * Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. + * Only non-block method can be used in this callback as it run from lcore + * routine. args point to the meta data of each event. Ex, cast to struct + * st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); - /** Use this socket if ST20P_TX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_event)(void *priv, enum st_event event, void *args); + /** Use this socket if ST20P_TX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -929,56 +963,58 @@ struct st20p_rx_ops { /** Mandatory. Convert plugin device, auto or special */ enum st_plugin_device device; /** - * Mandatory. The frame buffer count requested for one st20 pipeline rx session, - * should be in range [2, ST20_FB_MAX_COUNT], + * Mandatory. The frame buffer count requested for one st20 pipeline rx + * session, should be in range [2, ST20_FB_MAX_COUNT], */ uint16_t framebuff_cnt; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; - /** Optional. Flags to control session behaviors. See ST20P_RX_FLAG_* for possible value + void *priv; + /** Optional. Flags to control session behaviors. See ST20P_RX_FLAG_* for + * possible value */ uint32_t flags; - /* Optional, the size for each mt_rxq_burst, leave to zero to let system select a - * default value */ + /* Optional, the size for each mt_rxq_burst, leave to zero to let system + * select a default value */ uint16_t rx_burst_size; /** * Optional. Callback when frame available in the lib. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_available)(void* priv); + int (*notify_frame_available)(void *priv); /** Optional. Linesize for transport frame, only for non-convert mode */ size_t transport_linesize; /** Optional. Array of external frames */ - struct st_ext_frame* ext_frames; + struct st_ext_frame *ext_frames; /** Optional for ST20_RX_FLAG_ENABLE_RTCP. RTCP info */ struct st_rx_rtcp_ops rtcp; /** * Optional. Callback when the lib query next external frame's data address. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*query_ext_frame)(void* priv, struct st_ext_frame* ext_frame, - struct st20_rx_frame_meta* meta); + int (*query_ext_frame)(void *priv, struct st_ext_frame *ext_frame, + struct st20_rx_frame_meta *meta); /** - * Optional. event callback, lib will call this when there is some event happened. - * Only non-block method can be used in this callback as it run from lcore routine. - * args point to the meta data of each event. - * Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. + * Optional. event callback, lib will call this when there is some event + * happened. Only non-block method can be used in this callback as it run from + * lcore routine. args point to the meta data of each event. Ex, cast to + * struct st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); + int (*notify_event)(void *priv, enum st_event event, void *args); /** - * Optional with ST20_RX_FLAG_AUTO_DETECT. The callback when lib detected video format. - * And only non-block method can be used in this callback as it run from lcore - * tasklet routine. + * Optional with ST20_RX_FLAG_AUTO_DETECT. The callback when lib detected + * video format. And only non-block method can be used in this callback as it + * run from lcore tasklet routine. */ - int (*notify_detected)(void* priv, const struct st20_detect_meta* meta, - struct st20_detect_reply* reply); - /** Use this socket if ST20P_RX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_detected)(void *priv, const struct st20_detect_meta *meta, + struct st20_detect_reply *reply); + /** Use this socket if ST20P_RX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -1004,36 +1040,37 @@ struct st22p_tx_ops { enum st_plugin_device device; /** Mandatory. speed or quality mode */ enum st22_quality_mode quality; - /** Mandatory. codestream size, calculate as compress ratio. For interlaced, it's the - * expected codestream size for each field */ + /** Mandatory. codestream size, calculate as compress ratio. For interlaced, + * it's the expected codestream size for each field */ size_t codestream_size; /** - * Mandatory. the frame buffer count requested for one st22 pipeline tx session, - * should be in range [2, ST22_FB_MAX_COUNT], + * Mandatory. the frame buffer count requested for one st22 pipeline tx + * session, should be in range [2, ST22_FB_MAX_COUNT], */ uint16_t framebuff_cnt; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; - /** Optional. Flags to control session behaviors. See ST22P_TX_FLAG_* for possible value + void *priv; + /** Optional. Flags to control session behaviors. See ST22P_TX_FLAG_* for + * possible value */ uint32_t flags; /** Optional. thread count for codec, leave to zero if not know */ uint32_t codec_thread_cnt; /** * Optional. Callback when frame available in the lib. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_available)(void* priv); + int (*notify_frame_available)(void *priv); /** * Optional. Callback when frame done in the lib. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_done)(void* priv, struct st_frame* frame); + int (*notify_frame_done)(void *priv, struct st_frame *frame); /** Optional for ST22P_TX_FLAG_ENABLE_RTCP. RTCP info */ struct st_tx_rtcp_ops rtcp; @@ -1043,13 +1080,14 @@ struct st22p_tx_ops { */ uint8_t tx_dst_mac[MTL_SESSION_PORT_MAX][MTL_MAC_ADDR_LEN]; /** - * Optional. event callback, lib will call this when there is some event happened. - * Only non-block method can be used in this callback as it run from lcore routine. - * args point to the meta data of each event. - * Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. + * Optional. event callback, lib will call this when there is some event + * happened. Only non-block method can be used in this callback as it run from + * lcore routine. args point to the meta data of each event. Ex, cast to + * struct st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); - /** Use this socket if ST22P_TX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*notify_event)(void *priv, enum st_event event, void *args); + /** Use this socket if ST22P_TX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -1074,46 +1112,48 @@ struct st22p_rx_ops { /** Mandatory. encode plugin device, auto or special */ enum st_plugin_device device; /** - * Mandatory. the frame buffer count requested for one st22 pipeline rx session, - * should be in range [2, ST22_FB_MAX_COUNT], + * Mandatory. the frame buffer count requested for one st22 pipeline rx + * session, should be in range [2, ST22_FB_MAX_COUNT], */ uint16_t framebuff_cnt; /** Optional. name */ - const char* name; + const char *name; /** Optional. private data to the callback function */ - void* priv; - /** Optional. Flags to control session behaviors. See ST22P_RX_FLAG_* for possible value + void *priv; + /** Optional. Flags to control session behaviors. See ST22P_RX_FLAG_* for + * possible value */ uint32_t flags; /** Optional. thread count for codec, leave to zero if not know */ uint32_t codec_thread_cnt; - /** Optional. max codestream size, lib will use output frame size if not set. For - * interlaced, it's the expected codestream size for each field */ + /** Optional. max codestream size, lib will use output frame size if not set. + * For interlaced, it's the expected codestream size for each field */ size_t max_codestream_size; /** Optional for ST22P_RX_FLAG_ENABLE_RTCP. RTCP info */ struct st_rx_rtcp_ops rtcp; /** * Optional. Callback when frame available in the lib. - * And only non-block method can be used within this callback as it run from lcore - * tasklet routine. + * And only non-block method can be used within this callback as it run from + * lcore tasklet routine. */ - int (*notify_frame_available)(void* priv); + int (*notify_frame_available)(void *priv); /** - * Optional. event callback, lib will call this when there is some event happened. - * Only non-block method can be used in this callback as it run from lcore routine. - * args point to the meta data of each event. - * Ex, cast to struct st10_vsync_meta for ST_EVENT_VSYNC. + * Optional. event callback, lib will call this when there is some event + * happened. Only non-block method can be used in this callback as it run from + * lcore routine. args point to the meta data of each event. Ex, cast to + * struct st10_vsync_meta for ST_EVENT_VSYNC. */ - int (*notify_event)(void* priv, enum st_event event, void* args); + int (*notify_event)(void *priv, enum st_event event, void *args); /** - * Mandatory for ST22P_RX_FLAG_EXT_FRAME. Callback when the lib query next external - * frame's data address. And only non-block method can be used within this callback as - * it run from lcore tasklet routine. + * Mandatory for ST22P_RX_FLAG_EXT_FRAME. Callback when the lib query next + * external frame's data address. And only non-block method can be used within + * this callback as it run from lcore tasklet routine. */ - int (*query_ext_frame)(void* priv, struct st_ext_frame* ext_frame, - struct st22_rx_frame_meta* meta); - /** Use this socket if ST22P_RX_FLAG_FORCE_NUMA is on, default use the NIC numa */ + int (*query_ext_frame)(void *priv, struct st_ext_frame *ext_frame, + struct st22_rx_frame_meta *meta); + /** Use this socket if ST22P_RX_FLAG_FORCE_NUMA is on, default use the NIC + * numa */ int socket_id; }; @@ -1129,7 +1169,7 @@ struct st22p_rx_ops { * - Others: the handle to the encode dev context. */ st22_encoder_dev_handle st22_encoder_register(mtl_handle mt, - struct st22_encoder_dev* dev); + struct st22_encoder_dev *dev); /** * Unregister one st22 encoder. @@ -1152,11 +1192,12 @@ int st22_encoder_unregister(st22_encoder_dev_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st22_encode_frame_meta* st22_encoder_get_frame(st22p_encode_session session); +struct st22_encode_frame_meta * +st22_encoder_get_frame(st22p_encode_session session); /** - * Wake up the block wait on st22_encoder_get_frame if ST22_ENCODER_RESP_FLAG_BLOCK_GET is - * enabled. + * Wake up the block wait on st22_encoder_get_frame if + * ST22_ENCODER_RESP_FLAG_BLOCK_GET is enabled. * * @param session * The handle to the st2110-22 encoder session. @@ -1178,7 +1219,8 @@ int st22_encoder_wake_block(st22p_encode_session session); * - 0: Success. * - <0: Error code. */ -int st22_encoder_set_block_timeout(st22p_encode_session session, uint64_t timedwait_ns); +int st22_encoder_set_block_timeout(st22p_encode_session session, + uint64_t timedwait_ns); /** * Put back the frame which get by st22_encoder_get_frame to the tx @@ -1195,7 +1237,7 @@ int st22_encoder_set_block_timeout(st22p_encode_session session, uint64_t timedw * - <0: Error code if put fail. */ int st22_encoder_put_frame(st22p_encode_session session, - struct st22_encode_frame_meta* frame, int result); + struct st22_encode_frame_meta *frame, int result); /** * Register one st22 decoder. @@ -1209,7 +1251,7 @@ int st22_encoder_put_frame(st22p_encode_session session, * - Others: the handle to the encode dev */ st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, - struct st22_decoder_dev* dev); + struct st22_decoder_dev *dev); /** * Unregister one st22 decoder. @@ -1232,11 +1274,12 @@ int st22_decoder_unregister(st22_decoder_dev_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st22_decode_frame_meta* st22_decoder_get_frame(st22p_decode_session session); +struct st22_decode_frame_meta * +st22_decoder_get_frame(st22p_decode_session session); /** - * Wake up the block wait on st22_decoder_get_frame if ST22_DECODER_RESP_FLAG_BLOCK_GET is - * enabled. + * Wake up the block wait on st22_decoder_get_frame if + * ST22_DECODER_RESP_FLAG_BLOCK_GET is enabled. * * @param session * The handle to the st2110-22 decode session. @@ -1258,7 +1301,8 @@ int st22_decoder_wake_block(st22p_decode_session session); * - 0: Success. * - <0: Error code. */ -int st22_decoder_set_block_timeout(st22p_decode_session session, uint64_t timedwait_ns); +int st22_decoder_set_block_timeout(st22p_decode_session session, + uint64_t timedwait_ns); /** * Put back the frame which get by st22_decoder_get_frame to the rx @@ -1275,7 +1319,7 @@ int st22_decoder_set_block_timeout(st22p_decode_session session, uint64_t timedw * - <0: Error code if put fail. */ int st22_decoder_put_frame(st22p_decode_session session, - struct st22_decode_frame_meta* frame, int result); + struct st22_decode_frame_meta *frame, int result); /** * Register one st20 converter. @@ -1288,8 +1332,8 @@ int st22_decoder_put_frame(st22p_decode_session session, * - NULL: fail. * - Others: the handle to the convert dev */ -st20_converter_dev_handle st20_converter_register(mtl_handle mt, - struct st20_converter_dev* dev); +st20_converter_dev_handle +st20_converter_register(mtl_handle mt, struct st20_converter_dev *dev); /** * Unregister one st20 converter. @@ -1312,7 +1356,8 @@ int st20_converter_unregister(st20_converter_dev_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st20_convert_frame_meta* st20_converter_get_frame(st20p_convert_session session); +struct st20_convert_frame_meta * +st20_converter_get_frame(st20p_convert_session session); /** * Put back the frame which get by st20_converter_get_frame to the rx @@ -1329,7 +1374,7 @@ struct st20_convert_frame_meta* st20_converter_get_frame(st20p_convert_session s * - <0: Error code if put fail. */ int st20_converter_put_frame(st20p_convert_session session, - struct st20_convert_frame_meta* frame, int result); + struct st20_convert_frame_meta *frame, int result); /** * Register one st plugin so. @@ -1343,7 +1388,7 @@ int st20_converter_put_frame(st20p_convert_session session, * - 0: Success. * - <0: Error code. */ -int st_plugin_register(mtl_handle mt, const char* path); +int st_plugin_register(mtl_handle mt, const char *path); /** * Unregister one st plugin so. @@ -1357,7 +1402,7 @@ int st_plugin_register(mtl_handle mt, const char* path); * - 0: Success. * - <0: Error code. */ -int st_plugin_unregister(mtl_handle mt, const char* path); +int st_plugin_unregister(mtl_handle mt, const char *path); /** * Get the number of registered plugins lib. @@ -1381,7 +1426,7 @@ int st_get_plugins_nb(mtl_handle mt); * - NULL on error. * - Otherwise, the handle to the tx st2110-22 pipeline session. */ -st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops* ops); +st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops *ops); /** * Free the tx st2110-22 pipeline session. @@ -1396,8 +1441,8 @@ int st22p_tx_free(st22p_tx_handle handle); /** * Get one tx frame from the tx st2110-22 pipeline session. - * Call st22p_tx_put_frame or st22p_tx_put_ext_frame(if ST22P_TX_FLAG_EXT_FRAME) to return - * the frame to session. + * Call st22p_tx_put_frame or st22p_tx_put_ext_frame(if ST22P_TX_FLAG_EXT_FRAME) + * to return the frame to session. * * @param handle * The handle to the tx st2110-22 pipeline session. @@ -1405,7 +1450,7 @@ int st22p_tx_free(st22p_tx_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame meta pointer. */ -struct st_frame* st22p_tx_get_frame(st22p_tx_handle handle); +struct st_frame *st22p_tx_get_frame(st22p_tx_handle handle); /** * Put back the frame which get by st22p_tx_get_frame to the tx @@ -1419,7 +1464,7 @@ struct st_frame* st22p_tx_get_frame(st22p_tx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame* frame); +int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame *frame); /** * Put back the frame which get by st22p_tx_get_frame to the tx @@ -1435,8 +1480,8 @@ int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame* frame); * - 0 if successful. * - <0: Error code if put fail. */ -int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame* frame, - struct st_ext_frame* ext_frame); +int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame *frame, + struct st_ext_frame *ext_frame); /** * Get the framebuffer pointer from the tx st2110-22 pipeline session. @@ -1444,12 +1489,13 @@ int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame* frame, * @param handle * The handle to the tx st2110-22 pipeline session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st22p_tx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st22p_tx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st22p_tx_get_fb_addr(st22p_tx_handle handle, uint16_t idx); +void *st22p_tx_get_fb_addr(st22p_tx_handle handle, uint16_t idx); /** * Get the framebuffer size from the tx st2110-22 pipeline session. @@ -1472,10 +1518,12 @@ size_t st22p_tx_frame_size(st22p_tx_handle handle); * - 0: Success. * - <0: Error code. */ -int st22p_tx_update_destination(st22p_tx_handle handle, struct st_tx_dest_info* dst); +int st22p_tx_update_destination(st22p_tx_handle handle, + struct st_tx_dest_info *dst); /** - * Wake up the block wait on st22p_tx_get_frame if ST22P_TX_FLAG_BLOCK_GET is enabled. + * Wake up the block wait on st22p_tx_get_frame if ST22P_TX_FLAG_BLOCK_GET is + * enabled. * * @param handle * The handle to the tx st2110-22(pipeline) session. @@ -1486,7 +1534,8 @@ int st22p_tx_update_destination(st22p_tx_handle handle, struct st_tx_dest_info* int st22p_tx_wake_block(st22p_tx_handle handle); /** - * Set the block timeout time on st22p_tx_get_frame if ST22P_TX_FLAG_BLOCK_GET is enabled. + * Set the block timeout time on st22p_tx_get_frame if ST22P_TX_FLAG_BLOCK_GET + * is enabled. * * @param handle * The handle to the tx st2110-22(pipeline) session. @@ -1510,7 +1559,7 @@ int st22p_tx_set_block_timeout(st22p_tx_handle handle, uint64_t timedwait_ns); * - NULL on error. * - Otherwise, the handle to the rx st2110-22 pipeline session. */ -st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops); +st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops); /** * Free the rx st2110-22 pipeline session. @@ -1533,7 +1582,7 @@ int st22p_rx_free(st22p_rx_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st_frame* st22p_rx_get_frame(st22p_rx_handle handle); +struct st_frame *st22p_rx_get_frame(st22p_rx_handle handle); /** * Put back the frame which get by st22p_rx_get_frame to the rx @@ -1547,7 +1596,7 @@ struct st_frame* st22p_rx_get_frame(st22p_rx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int st22p_rx_put_frame(st22p_rx_handle handle, struct st_frame* frame); +int st22p_rx_put_frame(st22p_rx_handle handle, struct st_frame *frame); /** * Get the framebuffer pointer from the rx st2110-22 pipeline session. @@ -1555,12 +1604,13 @@ int st22p_rx_put_frame(st22p_rx_handle handle, struct st_frame* frame); * @param handle * The handle to the rx st2110-22 pipeline session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st22p_rx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st22p_rx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st22p_rx_get_fb_addr(st22p_rx_handle handle, uint16_t idx); +void *st22p_rx_get_fb_addr(st22p_rx_handle handle, uint16_t idx); /** * Get the framebuffer size from the rx st2110-22 pipeline session. @@ -1583,13 +1633,14 @@ size_t st22p_rx_frame_size(st22p_rx_handle handle); * synchronous or asynchronous, true means this func will return after dump * progress is finished. * @param meta - * The meta data returned, only for synchronous, leave to NULL if not need the meta. + * The meta data returned, only for synchronous, leave to NULL if not need the + * meta. * @return * - 0: Success, rx st2110-22 pipeline session pcapng dump succ. * - <0: Error code of the rx st2110-22 pipeline session pcapng dump. */ -int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta); +int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta); /** * Get the queue meta attached to rx st2110-22 pipeline session. @@ -1602,7 +1653,7 @@ int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, bool * - 0: Success. * - <0: Error code. */ -int st22p_rx_get_queue_meta(st22p_rx_handle handle, struct st_queue_meta* meta); +int st22p_rx_get_queue_meta(st22p_rx_handle handle, struct st_queue_meta *meta); /** * Online update the source info for the rx st2110-22(pipeline) session. @@ -1615,10 +1666,12 @@ int st22p_rx_get_queue_meta(st22p_rx_handle handle, struct st_queue_meta* meta); * - 0: Success. * - <0: Error code. */ -int st22p_rx_update_source(st22p_rx_handle handle, struct st_rx_source_info* src); +int st22p_rx_update_source(st22p_rx_handle handle, + struct st_rx_source_info *src); /** - * Wake up the block wait on st22p_rx_get_frame if ST22P_RX_FLAG_BLOCK_GET is enabled. + * Wake up the block wait on st22p_rx_get_frame if ST22P_RX_FLAG_BLOCK_GET is + * enabled. * * @param handle * The handle to the rx st2110-22(pipeline) session. @@ -1629,7 +1682,8 @@ int st22p_rx_update_source(st22p_rx_handle handle, struct st_rx_source_info* src int st22p_rx_wake_block(st22p_rx_handle handle); /** - * Set the block timeout time on st22p_rx_get_frame if ST22P_RX_FLAG_BLOCK_GET is enabled. + * Set the block timeout time on st22p_rx_get_frame if ST22P_RX_FLAG_BLOCK_GET + * is enabled. * * @param handle * The handle to the rx st2110-22(pipeline) session. @@ -1653,7 +1707,7 @@ int st22p_rx_set_block_timeout(st22p_rx_handle handle, uint64_t timedwait_ns); * - NULL on error. * - Otherwise, the handle to the tx st2110-20 pipeline session. */ -st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops* ops); +st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops *ops); /** * Free the tx st2110-20 pipeline session. @@ -1668,8 +1722,8 @@ int st20p_tx_free(st20p_tx_handle handle); /** * Get one tx frame from the tx st2110-20 pipeline session. - * Call st20p_tx_put_frame/st20p_tx_put_ext_frame(if ST20P_TX_FLAG_EXT_FRAME) to return - * the frame to session. + * Call st20p_tx_put_frame/st20p_tx_put_ext_frame(if ST20P_TX_FLAG_EXT_FRAME) to + * return the frame to session. * * @param handle * The handle to the tx st2110-20 pipeline session. @@ -1677,7 +1731,7 @@ int st20p_tx_free(st20p_tx_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame meta pointer. */ -struct st_frame* st20p_tx_get_frame(st20p_tx_handle handle); +struct st_frame *st20p_tx_get_frame(st20p_tx_handle handle); /** * Put back the frame which get by st20p_tx_get_frame to the tx @@ -1691,7 +1745,7 @@ struct st_frame* st20p_tx_get_frame(st20p_tx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame* frame); +int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame *frame); /** * Put back the frame which get by st20p_tx_get_frame to the tx @@ -1707,8 +1761,8 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame* frame); * - 0 if successful. * - <0: Error code if put fail. */ -int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame* frame, - struct st_ext_frame* ext_frame); +int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame *frame, + struct st_ext_frame *ext_frame); /** * Get the framebuffer pointer from the tx st2110-20 pipeline session. @@ -1716,12 +1770,13 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame* frame, * @param handle * The handle to the tx st2110-20 pipeline session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st20p_tx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st20p_tx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st20p_tx_get_fb_addr(st20p_tx_handle handle, uint16_t idx); +void *st20p_tx_get_fb_addr(st20p_tx_handle handle, uint16_t idx); /** * Get the framebuffer size from the tx st2110-20 pipeline session. @@ -1745,7 +1800,8 @@ size_t st20p_tx_frame_size(st20p_tx_handle handle); int st20p_tx_get_sch_idx(st20p_tx_handle handle); /** - * Retrieve the general statistics(I/O) for one tx st2110-20(pipeline) session port. + * Retrieve the general statistics(I/O) for one tx st2110-20(pipeline) session + * port. * * @param handle * The handle to the tx st2110-20(pipeline) session. @@ -1758,10 +1814,11 @@ int st20p_tx_get_sch_idx(st20p_tx_handle handle); * - <0: Error code. */ int st20p_tx_get_port_stats(st20p_tx_handle handle, enum mtl_session_port port, - struct st20_tx_port_status* stats); + struct st20_tx_port_status *stats); /** - * Reset the general statistics(I/O) for one tx st2110-20(pipeline) session port. + * Reset the general statistics(I/O) for one tx st2110-20(pipeline) session + * port. * * @param handle * The handle to the tx st2110-20(pipeline) session. @@ -1771,7 +1828,8 @@ int st20p_tx_get_port_stats(st20p_tx_handle handle, enum mtl_session_port port, * - >=0 succ. * - <0: Error code. */ -int st20p_tx_reset_port_stats(st20p_tx_handle handle, enum mtl_session_port port); +int st20p_tx_reset_port_stats(st20p_tx_handle handle, + enum mtl_session_port port); /** * Online update the destination info for the tx st2110-20(pipeline) session. @@ -1784,10 +1842,12 @@ int st20p_tx_reset_port_stats(st20p_tx_handle handle, enum mtl_session_port port * - 0: Success. * - <0: Error code. */ -int st20p_tx_update_destination(st20p_tx_handle handle, struct st_tx_dest_info* dst); +int st20p_tx_update_destination(st20p_tx_handle handle, + struct st_tx_dest_info *dst); /** - * Wake up the block wait on st20p_tx_get_frame if ST20P_TX_FLAG_BLOCK_GET is enabled. + * Wake up the block wait on st20p_tx_get_frame if ST20P_TX_FLAG_BLOCK_GET is + * enabled. * * @param handle * The handle to the tx st2110-20(pipeline) session. @@ -1798,7 +1858,8 @@ int st20p_tx_update_destination(st20p_tx_handle handle, struct st_tx_dest_info* int st20p_tx_wake_block(st20p_tx_handle handle); /** - * Set the block timeout time on st20p_tx_get_frame if ST20P_TX_FLAG_BLOCK_GET is enabled. + * Set the block timeout time on st20p_tx_get_frame if ST20P_TX_FLAG_BLOCK_GET + * is enabled. * * @param handle * The handle to the tx st2110-20(pipeline) session. @@ -1822,7 +1883,7 @@ int st20p_tx_set_block_timeout(st20p_tx_handle handle, uint64_t timedwait_ns); * - NULL on error. * - Otherwise, the handle to the rx st2110-20 pipeline session. */ -st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops); +st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops *ops); /** * Free the rx st2110-20 pipeline session. @@ -1845,7 +1906,7 @@ int st20p_rx_free(st20p_rx_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st_frame* st20p_rx_get_frame(st20p_rx_handle handle); +struct st_frame *st20p_rx_get_frame(st20p_rx_handle handle); /** * Put back the frame which get by st20p_rx_get_frame to the rx @@ -1859,7 +1920,7 @@ struct st_frame* st20p_rx_get_frame(st20p_rx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int st20p_rx_put_frame(st20p_rx_handle handle, struct st_frame* frame); +int st20p_rx_put_frame(st20p_rx_handle handle, struct st_frame *frame); /** * Get the framebuffer pointer from the rx st2110-20 pipeline session. @@ -1867,12 +1928,13 @@ int st20p_rx_put_frame(st20p_rx_handle handle, struct st_frame* frame); * @param handle * The handle to the rx st2110-20 pipeline session. * @param idx - * The framebuffer index, should be in range [0, framebuff_cnt of st20p_rx_ops]. + * The framebuffer index, should be in range [0, framebuff_cnt of + * st20p_rx_ops]. * @return * - NULL on error. * - Otherwise, the framebuffer pointer. */ -void* st20p_rx_get_fb_addr(st20p_rx_handle handle, uint16_t idx); +void *st20p_rx_get_fb_addr(st20p_rx_handle handle, uint16_t idx); /** * Get the framebuffer size from the rx st2110-20 pipeline session. @@ -1895,13 +1957,14 @@ size_t st20p_rx_frame_size(st20p_rx_handle handle); * synchronous or asynchronous, true means this func will return after dump * progress is finished. * @param meta - * The meta data returned, only for synchronous, leave to NULL if not need the meta. + * The meta data returned, only for synchronous, leave to NULL if not need the + * meta. * @return * - 0: Success, rx st2110-20 pipeline session pcapng dump succ. * - <0: Error code of the rx st2110-20 pipeline session pcapng dump. */ -int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta); +int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta); /** * Get the queue meta attached to rx st2110-20 pipeline session. @@ -1914,7 +1977,7 @@ int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, bool * - 0: Success. * - <0: Error code. */ -int st20p_rx_get_queue_meta(st20p_rx_handle handle, struct st_queue_meta* meta); +int st20p_rx_get_queue_meta(st20p_rx_handle handle, struct st_queue_meta *meta); /** * Get the scheduler index for the rx st2110-20(pipeline) session. @@ -1928,7 +1991,8 @@ int st20p_rx_get_queue_meta(st20p_rx_handle handle, struct st_queue_meta* meta); int st20p_rx_get_sch_idx(st20p_rx_handle handle); /** - * Retrieve the general statistics(I/O) for one rx st2110-20(pipeline) session port. + * Retrieve the general statistics(I/O) for one rx st2110-20(pipeline) session + * port. * * @param handle * The handle to the rx st2110-20(pipeline) session. @@ -1941,10 +2005,11 @@ int st20p_rx_get_sch_idx(st20p_rx_handle handle); * - <0: Error code. */ int st20p_rx_get_port_stats(st20p_rx_handle handle, enum mtl_session_port port, - struct st20_rx_port_status* stats); + struct st20_rx_port_status *stats); /** - * Reset the general statistics(I/O) for one rx st2110-20(pipeline) session port. + * Reset the general statistics(I/O) for one rx st2110-20(pipeline) session + * port. * * @param handle * The handle to the rx st2110-20(pipeline) session. @@ -1954,7 +2019,8 @@ int st20p_rx_get_port_stats(st20p_rx_handle handle, enum mtl_session_port port, * - >=0 succ. * - <0: Error code. */ -int st20p_rx_reset_port_stats(st20p_rx_handle handle, enum mtl_session_port port); +int st20p_rx_reset_port_stats(st20p_rx_handle handle, + enum mtl_session_port port); /** * Online update the source info for the rx st2110-20(pipeline) session. @@ -1967,7 +2033,8 @@ int st20p_rx_reset_port_stats(st20p_rx_handle handle, enum mtl_session_port port * - 0: Success. * - <0: Error code. */ -int st20p_rx_update_source(st20p_rx_handle handle, struct st_rx_source_info* src); +int st20p_rx_update_source(st20p_rx_handle handle, + struct st_rx_source_info *src); /** * Get the timing parser pass critical to rx st2110-20(pipeline) session. @@ -1981,10 +2048,12 @@ int st20p_rx_update_source(st20p_rx_handle handle, struct st_rx_source_info* src * - 0: Success. * - <0: Error code. */ -int st20p_rx_timing_parser_critical(st20p_rx_handle handle, struct st20_rx_tp_pass* pass); +int st20p_rx_timing_parser_critical(st20p_rx_handle handle, + struct st20_rx_tp_pass *pass); /** - * Wake up the block wait on st20p_rx_get_frame if ST20P_RX_FLAG_BLOCK_GET is enabled. + * Wake up the block wait on st20p_rx_get_frame if ST20P_RX_FLAG_BLOCK_GET is + * enabled. * * @param handle * The handle to the rx st2110-20(pipeline) session. @@ -1995,7 +2064,8 @@ int st20p_rx_timing_parser_critical(st20p_rx_handle handle, struct st20_rx_tp_pa int st20p_rx_wake_block(st20p_rx_handle handle); /** - * Set the block timeout time on st20p_rx_get_frame if ST20P_RX_FLAG_BLOCK_GET is enabled. + * Set the block timeout time on st20p_rx_get_frame if ST20P_RX_FLAG_BLOCK_GET + * is enabled. * * @param handle * The handle to the rx st2110-20(pipeline) session. @@ -2018,7 +2088,7 @@ int st20p_rx_set_block_timeout(st20p_rx_handle handle, uint64_t timedwait_ns); * - 0: Success. * - <0: Error code. */ -int st_frame_convert(struct st_frame* src, struct st_frame* dst); +int st_frame_convert(struct st_frame *src, struct st_frame *dst); /** * Downsample frame size to destination frame. @@ -2033,7 +2103,7 @@ int st_frame_convert(struct st_frame* src, struct st_frame* dst); * - 0: Success. * - <0: Error code. */ -int st_frame_downsample(struct st_frame* src, struct st_frame* dst, int idx); +int st_frame_downsample(struct st_frame *src, struct st_frame *dst, int idx); /** * Calculate the least linesize per the format, w, plane @@ -2048,7 +2118,8 @@ int st_frame_downsample(struct st_frame* src, struct st_frame* dst, int idx); * > 0 if successful. * 0: Fail. */ -size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, uint8_t plane); +size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, + uint8_t plane); /** * Calculate the frame size per the format, w and h @@ -2077,7 +2148,7 @@ size_t st_frame_size(enum st_frame_fmt fmt, uint32_t width, uint32_t height, * 0 if successful. * < 0: Fail. */ -int st_frame_sanity_check(struct st_frame* frame); +int st_frame_sanity_check(struct st_frame *frame); /** * Get the name of st_frame_fmt @@ -2088,7 +2159,7 @@ int st_frame_sanity_check(struct st_frame* frame); * The pointer to name. * NULL: Fail. */ -const char* st_frame_fmt_name(enum st_frame_fmt fmt); +const char *st_frame_fmt_name(enum st_frame_fmt fmt); /** * Get st_frame_fmt from name @@ -2099,7 +2170,7 @@ const char* st_frame_fmt_name(enum st_frame_fmt fmt); * The frame fmt. * ST_FRAME_FMT_MAX: Fail. */ -enum st_frame_fmt st_frame_name_to_fmt(const char* name); +enum st_frame_fmt st_frame_name_to_fmt(const char *name); /** * Get number of planes of st_frame_fmt @@ -2114,7 +2185,8 @@ uint8_t st_frame_fmt_planes(enum st_frame_fmt fmt); /** helper to know if it's a codestream fmt */ static inline bool st_frame_fmt_is_codestream(enum st_frame_fmt fmt) { - if (fmt >= ST_FRAME_FMT_CODESTREAM_START && fmt <= ST_FRAME_FMT_CODESTREAM_END) + if (fmt >= ST_FRAME_FMT_CODESTREAM_START && + fmt <= ST_FRAME_FMT_CODESTREAM_END) return true; else return false; @@ -2170,7 +2242,8 @@ bool st_frame_fmt_equal_transport(enum st_frame_fmt fmt, enum st20_fmt tfmt); * - 0 if successful. * - <0: Error code if put fail. */ -int st_draw_logo(struct st_frame* frame, struct st_frame* logo, uint32_t x, uint32_t y); +int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, + uint32_t y); /** * Helper to get st frame plane size @@ -2182,86 +2255,95 @@ int st_draw_logo(struct st_frame* frame, struct st_frame* logo, uint32_t x, uint * @return * size */ -static inline size_t st_frame_plane_size(struct st_frame* frame, uint8_t plane) { +static inline size_t st_frame_plane_size(struct st_frame *frame, + uint8_t plane) { /* no line size for codestream */ - if (st_frame_fmt_is_codestream(frame->fmt)) return frame->data_size; + if (st_frame_fmt_is_codestream(frame->fmt)) + return frame->data_size; size_t sz = frame->linesize[plane] * frame->height; - if (frame->interlaced) sz /= 2; + if (frame->interlaced) + sz /= 2; return sz; } /** - * This helper function retrieves the actual data height in one st frame. Please note that - * for an interlaced frame, it will return half the height. + * This helper function retrieves the actual data height in one st frame. Please + * note that for an interlaced frame, it will return half the height. * * @param frame * The st_frame pointer. * @return * height */ -static inline uint32_t st_frame_data_height(struct st_frame* frame) { +static inline uint32_t st_frame_data_height(struct st_frame *frame) { uint32_t h = frame->height; - if (frame->interlaced) h /= 2; + if (frame->interlaced) + h /= 2; return h; } /** Helper to set the port for struct st_rx_port */ -int st_rxp_para_port_set(struct st_rx_port* p, enum mtl_session_port port, char* name); +int st_rxp_para_port_set(struct st_rx_port *p, enum mtl_session_port port, + char *name); /** Helper to set the ip for struct st_rx_port */ -int st_rxp_para_ip_set(struct st_rx_port* p, enum mtl_port port, char* ip); +int st_rxp_para_ip_set(struct st_rx_port *p, enum mtl_port port, char *ip); /** Helper to set the udp port number for struct st_rx_port */ -static inline void st_rxp_para_udp_port_set(struct st_rx_port* p, enum mtl_port port, +static inline void st_rxp_para_udp_port_set(struct st_rx_port *p, + enum mtl_port port, uint16_t udp_port) { p->udp_port[port] = udp_port; } /** Helper to set the port for struct st_tx_port */ -int st_txp_para_port_set(struct st_tx_port* p, enum mtl_session_port port, char* name); +int st_txp_para_port_set(struct st_tx_port *p, enum mtl_session_port port, + char *name); /** Helper to set the dip for struct st_tx_port */ -int st_txp_para_dip_set(struct st_tx_port* p, enum mtl_port port, char* ip); +int st_txp_para_dip_set(struct st_tx_port *p, enum mtl_port port, char *ip); /** Helper to set the udp port number for struct st_tx_port */ -static inline void st_txp_para_udp_port_set(struct st_tx_port* p, enum mtl_port port, +static inline void st_txp_para_udp_port_set(struct st_tx_port *p, + enum mtl_port port, uint16_t udp_port) { p->udp_port[port] = udp_port; } /** Helper to get the frame addr from struct st_frame */ -static inline void* st_frame_addr(struct st_frame* frame, uint8_t plane) { +static inline void *st_frame_addr(struct st_frame *frame, uint8_t plane) { return frame->addr[plane]; } /** Helper to get the frame addr(mtl_cpuva_t) from struct st_frame */ -static inline mtl_cpuva_t st_frame_addr_cpuva(struct st_frame* frame, uint8_t plane) { +static inline mtl_cpuva_t st_frame_addr_cpuva(struct st_frame *frame, + uint8_t plane) { return (mtl_cpuva_t)frame->addr[plane]; } /** Helper to get the frame iova from struct st_frame */ -static inline mtl_iova_t st_frame_iova(struct st_frame* frame, uint8_t plane) { +static inline mtl_iova_t st_frame_iova(struct st_frame *frame, uint8_t plane) { return frame->iova[plane]; } /** Helper to get the frame tp meta from struct st_frame */ -static inline struct st20_rx_tp_meta* st_frame_tp_meta(struct st_frame* frame, - enum mtl_session_port port) { +static inline struct st20_rx_tp_meta * +st_frame_tp_meta(struct st_frame *frame, enum mtl_session_port port) { return frame->tp[port]; } /** request to create a plain memory by rte malloc to hold the frame buffer */ -struct st_frame* st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, uint32_t w, - uint32_t h, bool interlaced); +struct st_frame *st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, + uint32_t w, uint32_t h, bool interlaced); /** free the frame created by st_frame_create */ -int st_frame_free(struct st_frame* frame); +int st_frame_free(struct st_frame *frame); /** request to create a plain memory by libc malloc */ -struct st_frame* st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, uint32_t h, - bool interlaced); +struct st_frame *st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, + uint32_t h, bool interlaced); /** merge two fields to one full frame */ -int st_field_merge(const struct st_frame* first, const struct st_frame* second, - struct st_frame* frame); +int st_field_merge(const struct st_frame *first, const struct st_frame *second, + struct st_frame *frame); /** split one full frame to two fields */ -int st_field_split(const struct st_frame* frame, struct st_frame* first, - struct st_frame* second); +int st_field_split(const struct st_frame *frame, struct st_frame *first, + struct st_frame *second); /** helper for name to codec */ -enum st22_codec st_name_to_codec(const char* name); +enum st22_codec st_name_to_codec(const char *name); #if defined(__cplusplus) } diff --git a/ld_preload/preload_platform.h b/ld_preload/preload_platform.h index 2950949bc..c6edfd6eb 100644 --- a/ld_preload/preload_platform.h +++ b/ld_preload/preload_platform.h @@ -19,9 +19,7 @@ #ifdef WINDOWSENV typedef unsigned long int nfds_t; -static inline pid_t getpid() { - return GetCurrentProcessId(); -} +static inline pid_t getpid() { return GetCurrentProcessId(); } #endif #endif diff --git a/ld_preload/udp/udp_preload.c b/ld_preload/udp/udp_preload.c index b01c0d2dc..7eadfc40c 100644 --- a/ld_preload/udp/udp_preload.c +++ b/ld_preload/udp/udp_preload.c @@ -7,29 +7,25 @@ #include /* call original libc function */ -#define LIBC_FN(__name, ...) \ - ({ \ - typeof(libc_fn.__name(__VA_ARGS__)) ret; \ - if (!libc_fn.__name) { \ - upl_resolve_libc_fn(&libc_fn); \ - } \ - ret = libc_fn.__name(__VA_ARGS__); \ - ret; \ +#define LIBC_FN(__name, ...) \ + ({ \ + typeof(libc_fn.__name(__VA_ARGS__)) ret; \ + if (!libc_fn.__name) { \ + upl_resolve_libc_fn(&libc_fn); \ + } \ + ret = libc_fn.__name(__VA_ARGS__); \ + ret; \ }) static struct upl_functions libc_fn; -static struct upl_ctx* g_upl_ctx; +static struct upl_ctx *g_upl_ctx; -static inline struct upl_ctx* upl_get_ctx(void) { - return g_upl_ctx; -} +static inline struct upl_ctx *upl_get_ctx(void) { return g_upl_ctx; } -static inline void upl_set_ctx(struct upl_ctx* ctx) { - g_upl_ctx = ctx; -} +static inline void upl_set_ctx(struct upl_ctx *ctx) { g_upl_ctx = ctx; } -static inline int upl_set_upl_entry(struct upl_ctx* ctx, int kfd, void* upl) { +static inline int upl_set_upl_entry(struct upl_ctx *ctx, int kfd, void *upl) { if (ctx->upl_entires[kfd]) { warn("%s(%d), already has upl %p\n", __func__, kfd, ctx->upl_entires[kfd]); } @@ -38,37 +34,41 @@ static inline int upl_set_upl_entry(struct upl_ctx* ctx, int kfd, void* upl) { return 0; } -static inline void* upl_get_upl_entry(struct upl_ctx* ctx, int kfd) { +static inline void *upl_get_upl_entry(struct upl_ctx *ctx, int kfd) { return ctx->upl_entires[kfd]; } -static inline int upl_clear_upl_entry(struct upl_ctx* ctx, int kfd) { +static inline int upl_clear_upl_entry(struct upl_ctx *ctx, int kfd) { ctx->upl_entires[kfd] = NULL; return 0; } -static inline struct upl_ufd_entry* upl_get_ufd_entry(struct upl_ctx* ctx, int kfd) { - struct upl_ufd_entry* entry = upl_get_upl_entry(ctx, kfd); +static inline struct upl_ufd_entry *upl_get_ufd_entry(struct upl_ctx *ctx, + int kfd) { + struct upl_ufd_entry *entry = upl_get_upl_entry(ctx, kfd); if (entry && entry->base.upl_type != UPL_ENTRY_UFD) { - dbg("%s(%d), entry %p error type %d\n", __func__, kfd, entry, entry->base.upl_type); + dbg("%s(%d), entry %p error type %d\n", __func__, kfd, entry, + entry->base.upl_type); return NULL; } dbg("%s(%d), ufd entry %p\n", __func__, kfd, entry); return entry; } -static inline struct upl_efd_entry* upl_get_efd_entry(struct upl_ctx* ctx, int kfd) { - struct upl_efd_entry* entry = upl_get_upl_entry(ctx, kfd); +static inline struct upl_efd_entry *upl_get_efd_entry(struct upl_ctx *ctx, + int kfd) { + struct upl_efd_entry *entry = upl_get_upl_entry(ctx, kfd); if (entry && entry->base.upl_type != UPL_ENTRY_EPOLL) { - err("%s(%d), entry %p error type %d\n", __func__, kfd, entry, entry->base.upl_type); + err("%s(%d), entry %p error type %d\n", __func__, kfd, entry, + entry->base.upl_type); return NULL; } dbg("%s(%d), efd entry %p\n", __func__, kfd, entry); return entry; } -static inline bool upl_is_ufd_entry(struct upl_ctx* ctx, int kfd) { - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, kfd); +static inline bool upl_is_ufd_entry(struct upl_ctx *ctx, int kfd) { + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, kfd); dbg("%s(%d), ufd entry %p\n", __func__, kfd, entry); if (!entry || entry->bind_kfd) return false; @@ -76,22 +76,23 @@ static inline bool upl_is_ufd_entry(struct upl_ctx* ctx, int kfd) { return true; } -static const char* upl_type_names[UPL_ENTRY_MAX] = { +static const char *upl_type_names[UPL_ENTRY_MAX] = { "unknown", "ufd", "efd", }; -static const char* upl_type_name(enum upl_entry_type type) { +static const char *upl_type_name(enum upl_entry_type type) { return upl_type_names[type]; } -static int upl_uinit_ctx(struct upl_ctx* ctx) { +static int upl_uinit_ctx(struct upl_ctx *ctx) { info("%s, %s pid %u\n", __func__, ctx->child ? "child" : "parent", ctx->pid); if (ctx->upl_entires) { for (int i = 0; i < ctx->upl_entires_nb; i++) { - struct upl_base_entry* entry = upl_get_upl_entry(ctx, i); - if (!entry) continue; + struct upl_base_entry *entry = upl_get_upl_entry(ctx, i); + if (!entry) + continue; if (ctx->child && !entry->child) continue; /* child only check the fd created by child */ warn("%s, upl still active on %d, upl type %s\n", __func__, i, @@ -107,14 +108,14 @@ static int upl_uinit_ctx(struct upl_ctx* ctx) { return 0; } -static int upl_resolve_libc_fn(struct upl_functions* fns) { -#define UPL_LIBC_FN(__name) \ - do { \ - fns->__name = dlsym(RTLD_NEXT, #__name); \ - if (!fns->__name) { \ - err("%s, dlsym %s fail\n", __func__, #__name); \ - UPL_ERR_RET(EIO); \ - } \ +static int upl_resolve_libc_fn(struct upl_functions *fns) { +#define UPL_LIBC_FN(__name) \ + do { \ + fns->__name = dlsym(RTLD_NEXT, #__name); \ + if (!fns->__name) { \ + err("%s, dlsym %s fail\n", __func__, #__name); \ + UPL_ERR_RET(EIO); \ + } \ } while (0) UPL_LIBC_FN(socket); @@ -145,8 +146,8 @@ static int upl_resolve_libc_fn(struct upl_functions* fns) { return 0; } -static struct upl_ctx* upl_create_ctx(bool child) { - struct upl_ctx* ctx = upl_zmalloc(sizeof(*ctx)); +static struct upl_ctx *upl_create_ctx(bool child) { + struct upl_ctx *ctx = upl_zmalloc(sizeof(*ctx)); if (!ctx) { err("%s, ctx malloc fail\n", __func__); return NULL; @@ -154,7 +155,8 @@ static struct upl_ctx* upl_create_ctx(bool child) { ctx->log_level = MTL_LOG_LEVEL_INFO; ctx->upl_entires_nb = 1024 * 10; /* max fd we support */ - ctx->upl_entires = upl_zmalloc(sizeof(*ctx->upl_entires) * ctx->upl_entires_nb); + ctx->upl_entires = + upl_zmalloc(sizeof(*ctx->upl_entires) * ctx->upl_entires_nb); if (!ctx->upl_entires) { err("%s, upl_entires malloc fail, nb %d\n", __func__, ctx->upl_entires_nb); upl_uinit_ctx(ctx); @@ -164,20 +166,20 @@ static struct upl_ctx* upl_create_ctx(bool child) { ctx->pid = getpid(); ctx->child = child; if (child) { - struct upl_ctx* parent = upl_get_ctx(); + struct upl_ctx *parent = upl_get_ctx(); /* copy the fd from master, todo: copy the only reuse fd */ memcpy(ctx->upl_entires, parent->upl_entires, sizeof(*ctx->upl_entires) * ctx->upl_entires_nb); } - info("%s, succ %s pid %u ctx %p\n", __func__, child ? "child" : "parent", ctx->pid, - ctx); + info("%s, succ %s pid %u ctx %p\n", __func__, child ? "child" : "parent", + ctx->pid, ctx); upl_set_ctx(ctx); return ctx; } static void upl_atfork_child(void) { - struct upl_ctx* ctx = upl_create_ctx(true); + struct upl_ctx *ctx = upl_create_ctx(true); if (!ctx) { err("%s, upl create ctx fail\n", __func__); return; @@ -193,7 +195,7 @@ static void __attribute__((constructor)) upl_init() { return; } - struct upl_ctx* ctx = upl_create_ctx(false); + struct upl_ctx *ctx = upl_create_ctx(false); if (!ctx) { err("%s, upl create ctx fail\n", __func__); return; @@ -208,35 +210,36 @@ static void __attribute__((constructor)) upl_init() { } static void __attribute__((destructor)) upl_uinit() { - struct upl_ctx* ctx = upl_get_ctx(); - if (ctx) upl_uinit_ctx(ctx); + struct upl_ctx *ctx = upl_get_ctx(); + if (ctx) + upl_uinit_ctx(ctx); } -static int upl_stat_dump(void* priv) { - struct upl_ufd_entry* entry = priv; +static int upl_stat_dump(void *priv) { + struct upl_ufd_entry *entry = priv; int kfd = entry->kfd; if (entry->stat_tx_ufd_cnt || entry->stat_rx_ufd_cnt) { - notice("%s(%d), ufd pkt tx %d rx %d\n", __func__, kfd, entry->stat_tx_ufd_cnt, - entry->stat_rx_ufd_cnt); + notice("%s(%d), ufd pkt tx %d rx %d\n", __func__, kfd, + entry->stat_tx_ufd_cnt, entry->stat_rx_ufd_cnt); entry->stat_tx_ufd_cnt = 0; entry->stat_rx_ufd_cnt = 0; } if (entry->stat_tx_kfd_cnt || entry->stat_rx_kfd_cnt) { - notice("%s(%d), kfd pkt tx %d rx %d\n", __func__, kfd, entry->stat_tx_kfd_cnt, - entry->stat_rx_kfd_cnt); + notice("%s(%d), kfd pkt tx %d rx %d\n", __func__, kfd, + entry->stat_tx_kfd_cnt, entry->stat_rx_kfd_cnt); entry->stat_tx_kfd_cnt = 0; entry->stat_rx_kfd_cnt = 0; } if (entry->stat_epoll_cnt || entry->stat_epoll_revents_cnt) { - notice("%s(%d), epoll %d revents %d\n", __func__, kfd, entry->stat_epoll_cnt, - entry->stat_epoll_revents_cnt); + notice("%s(%d), epoll %d revents %d\n", __func__, kfd, + entry->stat_epoll_cnt, entry->stat_epoll_revents_cnt); entry->stat_epoll_cnt = 0; entry->stat_epoll_revents_cnt = 0; } if (entry->stat_select_cnt || entry->stat_select_revents_cnt) { - notice("%s(%d), select %d revents %d\n", __func__, kfd, entry->stat_select_cnt, - entry->stat_select_revents_cnt); + notice("%s(%d), select %d revents %d\n", __func__, kfd, + entry->stat_select_cnt, entry->stat_select_revents_cnt); entry->stat_select_cnt = 0; entry->stat_select_revents_cnt = 0; } @@ -249,8 +252,8 @@ static int upl_stat_dump(void* priv) { return 0; } -static int upl_epoll_create(struct upl_ctx* ctx, int efd) { - struct upl_efd_entry* entry = upl_zmalloc(sizeof(*entry)); +static int upl_epoll_create(struct upl_ctx *ctx, int efd) { + struct upl_efd_entry *entry = upl_zmalloc(sizeof(*entry)); if (!entry) { err("%s, entry malloc fail for efd %d\n", __func__, efd); UPL_ERR_RET(ENOMEM); @@ -266,8 +269,8 @@ static int upl_epoll_create(struct upl_ctx* ctx, int efd) { return 0; } -static int upl_epoll_close(struct upl_efd_entry* entry) { - struct upl_efd_fd_item* item; +static int upl_epoll_close(struct upl_efd_entry *entry) { + struct upl_efd_fd_item *item; pthread_mutex_lock(&entry->mutex); /* check if any not removed */ @@ -284,24 +287,27 @@ static int upl_epoll_close(struct upl_efd_entry* entry) { return 0; } -static inline bool upl_epoll_has_ufd(struct upl_efd_entry* efd_entry) { +static inline bool upl_epoll_has_ufd(struct upl_efd_entry *efd_entry) { return TAILQ_EMPTY(&efd_entry->fds) ? false : true; } -static int upl_efd_ctl_add(struct upl_ctx* ctx, struct upl_efd_entry* efd, - struct upl_ufd_entry* ufd, struct epoll_event* event) { - struct upl_efd_fd_item* item = upl_zmalloc(sizeof(*item)); +static int upl_efd_ctl_add(struct upl_ctx *ctx, struct upl_efd_entry *efd, + struct upl_ufd_entry *ufd, + struct epoll_event *event) { + struct upl_efd_fd_item *item = upl_zmalloc(sizeof(*item)); if (!item) { err("%s, malloc fail\n", __func__); UPL_ERR_RET(ENOMEM); } - if (event) item->event = *event; + if (event) + item->event = *event; item->ufd = ufd; dbg("%s, efd %p ufd %p\n", __func__, efd, ufd); pthread_mutex_lock(&efd->mutex); /* todo: how to update ufd for child efd */ - if (!ctx->child) ufd->efd = efd->efd; + if (!ctx->child) + ufd->efd = efd->efd; TAILQ_INSERT_TAIL(&efd->fds, item, next); efd->fds_cnt++; pthread_mutex_unlock(&efd->mutex); @@ -310,8 +316,8 @@ static int upl_efd_ctl_add(struct upl_ctx* ctx, struct upl_efd_entry* efd, return 0; } -static int upl_efd_ctl_del(struct upl_ctx* ctx, struct upl_efd_entry* efd, - struct upl_ufd_entry* ufd) { +static int upl_efd_ctl_del(struct upl_ctx *ctx, struct upl_efd_entry *efd, + struct upl_ufd_entry *ufd) { struct upl_efd_fd_item *item, *tmp_item; pthread_mutex_lock(&efd->mutex); @@ -321,7 +327,8 @@ static int upl_efd_ctl_del(struct upl_ctx* ctx, struct upl_efd_entry* efd, /* found the matched item, remove it */ TAILQ_REMOVE(&efd->fds, item, next); /* todo: how to update ufd for child efd */ - if (!ctx->child) ufd->efd = -1; + if (!ctx->child) + ufd->efd = -1; efd->fds_cnt--; pthread_mutex_unlock(&efd->mutex); upl_free(item); @@ -335,8 +342,8 @@ static int upl_efd_ctl_del(struct upl_ctx* ctx, struct upl_efd_entry* efd, UPL_ERR_RET(EINVAL); } -static int upl_efd_ctl_mod(struct upl_efd_entry* efd, struct upl_ufd_entry* ufd, - struct epoll_event* event) { +static int upl_efd_ctl_mod(struct upl_efd_entry *efd, struct upl_ufd_entry *ufd, + struct epoll_event *event) { struct upl_efd_fd_item *item, *tmp_item; pthread_mutex_lock(&efd->mutex); @@ -356,15 +363,16 @@ static int upl_efd_ctl_mod(struct upl_efd_entry* efd, struct upl_ufd_entry* ufd, UPL_ERR_RET(EINVAL); } -static int upl_efd_epoll_query(void* priv) { - struct upl_efd_entry* entry = priv; +static int upl_efd_epoll_query(void *priv) { + struct upl_efd_entry *entry = priv; int efd = entry->efd; int ret; dbg("%s(%d), start\n", __func__, efd); /* timeout to zero for query */ if (entry->sigmask) - ret = LIBC_FN(epoll_pwait, efd, entry->events, entry->maxevents, 0, entry->sigmask); + ret = LIBC_FN(epoll_pwait, efd, entry->events, entry->maxevents, 0, + entry->sigmask); else ret = LIBC_FN(epoll_wait, efd, entry->events, entry->maxevents, 0); if (ret != 0) { /* event on kfd */ @@ -375,8 +383,8 @@ static int upl_efd_epoll_query(void* priv) { return ret; } -static int upl_select_query(void* priv) { - struct upl_select_ctx* select_ctx = priv; +static int upl_select_query(void *priv) { + struct upl_select_ctx *select_ctx = priv; int ret; struct timeval zero; @@ -388,17 +396,18 @@ static int upl_select_query(void* priv) { /* timeout to zero for query */ if (select_ctx->sigmask) - ret = LIBC_FN(pselect, select_ctx->nfds, select_ctx->readfds, select_ctx->writefds, - select_ctx->exceptfds, &zero_spec, select_ctx->sigmask); + ret = LIBC_FN(pselect, select_ctx->nfds, select_ctx->readfds, + select_ctx->writefds, select_ctx->exceptfds, &zero_spec, + select_ctx->sigmask); else - ret = LIBC_FN(select, select_ctx->nfds, select_ctx->readfds, select_ctx->writefds, - select_ctx->exceptfds, &zero); + ret = LIBC_FN(select, select_ctx->nfds, select_ctx->readfds, + select_ctx->writefds, select_ctx->exceptfds, &zero); dbg("%s, ret %d\n", __func__, ret); return ret; } -static int upl_poll_query(void* priv) { - struct upl_poll_ctx* poll_ctx = priv; +static int upl_poll_query(void *priv) { + struct upl_poll_ctx *poll_ctx = priv; int ret; /* use zero timeout as query */ @@ -406,7 +415,8 @@ static int upl_poll_query(void* priv) { struct timespec zero; zero.tv_sec = 0; zero.tv_nsec = 0; - ret = LIBC_FN(ppoll, poll_ctx->fds, poll_ctx->nfds, &zero, poll_ctx->sigmask); + ret = + LIBC_FN(ppoll, poll_ctx->fds, poll_ctx->nfds, &zero, poll_ctx->sigmask); } else { ret = LIBC_FN(poll, poll_ctx->fds, poll_ctx->nfds, 0); } @@ -415,23 +425,25 @@ static int upl_poll_query(void* priv) { } /* reuse mufd_poll now */ -static int upl_efd_epoll_pwait(struct upl_efd_entry* entry, struct epoll_event* events, - int maxevents, int timeout_ms, const sigset_t* sigmask) { +static int upl_efd_epoll_pwait(struct upl_efd_entry *entry, + struct epoll_event *events, int maxevents, + int timeout_ms, const sigset_t *sigmask) { int efd = entry->efd; const int fds_cnt = entry->fds_cnt; - struct upl_efd_fd_item* item; + struct upl_efd_fd_item *item; struct pollfd p_fds[fds_cnt]; - struct upl_efd_fd_item* efd_items[fds_cnt]; + struct upl_efd_fd_item *efd_items[fds_cnt]; int p_fds_cnt = 0; int kfd_cnt = atomic_load(&entry->kfd_cnt); int ret; - dbg("%s(%d), timeout_ms %d maxevents %d kfd_cnt %d\n", __func__, efd, timeout_ms, - maxevents, kfd_cnt); + dbg("%s(%d), timeout_ms %d maxevents %d kfd_cnt %d\n", __func__, efd, + timeout_ms, maxevents, kfd_cnt); pthread_mutex_lock(&entry->mutex); TAILQ_FOREACH(item, &entry->fds, next) { if (p_fds_cnt >= fds_cnt) { - err("%s(%d), wrong p_fds_cnt %d fds_cnt %d\n", __func__, efd, p_fds_cnt, fds_cnt); + err("%s(%d), wrong p_fds_cnt %d fds_cnt %d\n", __func__, efd, p_fds_cnt, + fds_cnt); pthread_mutex_unlock(&entry->mutex); UPL_ERR_RET(EIO); } @@ -448,20 +460,25 @@ static int upl_efd_epoll_pwait(struct upl_efd_entry* entry, struct epoll_event* entry->events = events; entry->maxevents = maxevents; entry->sigmask = sigmask; - ret = mufd_poll_query(p_fds, p_fds_cnt, timeout_ms, upl_efd_epoll_query, entry); + ret = mufd_poll_query(p_fds, p_fds_cnt, timeout_ms, upl_efd_epoll_query, + entry); } else { ret = mufd_poll(p_fds, p_fds_cnt, timeout_ms); } - if (ret <= 0) return ret; + if (ret <= 0) + return ret; /* event on the kfd */ - if (entry->kfd_ret > 0) return entry->kfd_ret; + if (entry->kfd_ret > 0) + return entry->kfd_ret; int ready = 0; for (int i = 0; i < p_fds_cnt; i++) { - if (!p_fds[i].revents) continue; + if (!p_fds[i].revents) + continue; item = efd_items[i]; - dbg("%s, revents on ufd %d kfd %d\n", __func__, p_fds[i].fd, item->ufd->kfd); + dbg("%s, revents on ufd %d kfd %d\n", __func__, p_fds[i].fd, + item->ufd->kfd); events[ready] = efd_items[i]->event; ready++; item->ufd->stat_epoll_revents_cnt++; @@ -470,9 +487,11 @@ static int upl_efd_epoll_pwait(struct upl_efd_entry* entry, struct epoll_event* return ready; } -static int upl_pselect(struct upl_ctx* ctx, int nfds, fd_set* readfds, fd_set* writefds, - fd_set* exceptfds, struct timeval* timeout, - const struct timespec* timeout_spec, const sigset_t* sigmask) { +static int upl_pselect(struct upl_ctx *ctx, int nfds, fd_set *readfds, + fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout, + const struct timespec *timeout_spec, + const sigset_t *sigmask) { dbg("%s, nfds %d\n", __func__, nfds); if (nfds <= 0 || nfds > FD_SETSIZE) { @@ -485,10 +504,11 @@ static int upl_pselect(struct upl_ctx* ctx, int nfds, fd_set* readfds, fd_set* w int poll_ufds_cnt = 0; /* split fd with kernel and mtl */ for (int i = 0; i < nfds; i++) { - if (!upl_is_ufd_entry(ctx, i)) continue; + if (!upl_is_ufd_entry(ctx, i)) + continue; if (readfds && FD_ISSET(i, readfds)) { FD_CLR(i, readfds); /* clear the readfds to kernel since it's a ufd */ - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, i); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, i); poll_ufds[poll_ufds_cnt].fd = entry->ufd; poll_ufds[poll_ufds_cnt].events = POLLIN; entry->stat_select_cnt++; @@ -508,7 +528,8 @@ static int upl_pselect(struct upl_ctx* ctx, int nfds, fd_set* readfds, fd_set* w if (!poll_ufds_cnt) { if (sigmask) - return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout_spec, sigmask); + return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout_spec, + sigmask); else return LIBC_FN(select, nfds, readfds, writefds, exceptfds, timeout); } @@ -529,15 +550,17 @@ static int upl_pselect(struct upl_ctx* ctx, int nfds, fd_set* readfds, fd_set* w timeout_ms = timeout_spec->tv_sec * 1000 + timeout_spec->tv_nsec / 1000000; } else timeout_ms = 1000 * 2; /* wa: when timeout is NULL */ - int ret = - mufd_poll_query(poll_ufds, poll_ufds_cnt, timeout_ms, upl_select_query, &priv); - if (ret < 0) return ret; + int ret = mufd_poll_query(poll_ufds, poll_ufds_cnt, timeout_ms, + upl_select_query, &priv); + if (ret < 0) + return ret; FD_ZERO(readfds); for (nfds_t i = 0; i < poll_ufds_cnt; i++) { - if (!poll_ufds[i].revents) continue; + if (!poll_ufds[i].revents) + continue; int kfd = poll_ufds_kfd[i]; - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, kfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, kfd); dbg("%s(%d), revents on ufd %d kfd %d\n", __func__, kfd, entry->ufd); entry->stat_select_revents_cnt++; FD_SET(kfd, readfds); @@ -545,8 +568,9 @@ static int upl_pselect(struct upl_ctx* ctx, int nfds, fd_set* readfds, fd_set* w return ret; } -static int upl_ppoll(struct upl_ctx* ctx, struct pollfd* fds, nfds_t nfds, int timeout, - const struct timespec* tmo_p, const sigset_t* sigmask) { +static int upl_ppoll(struct upl_ctx *ctx, struct pollfd *fds, nfds_t nfds, + int timeout, const struct timespec *tmo_p, + const sigset_t *sigmask) { if (nfds <= 0) { err("%s, invalid nfds %" PRIu64 "\n", __func__, nfds); UPL_ERR_RET(EIO); @@ -564,7 +588,7 @@ static int upl_ppoll(struct upl_ctx* ctx, struct pollfd* fds, nfds_t nfds, int t int kfd = fds[i].fd; fds[i].revents = 0; /* clear all revents */ if (upl_is_ufd_entry(ctx, kfd)) { - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, kfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, kfd); entry->stat_poll_cnt++; ufds[ufds_cnt].fd = entry->ufd; ufds[ufds_cnt].events = fds[i].events; @@ -595,7 +619,8 @@ static int upl_ppoll(struct upl_ctx* ctx, struct pollfd* fds, nfds_t nfds, int t priv.tmo_p = tmo_p; priv.sigmask = sigmask; /* wa to fix end loop in userspace issue */ - if (timeout < 0) timeout = 1000 * 2; + if (timeout < 0) + timeout = 1000 * 2; int ret; if (kfds_cnt) @@ -603,24 +628,27 @@ static int upl_ppoll(struct upl_ctx* ctx, struct pollfd* fds, nfds_t nfds, int t else ret = mufd_poll(ufds, ufds_cnt, timeout); dbg("%s, mufd_poll ret %d timeout %d\n", __func__, ret, timeout); - if (ret <= 0) return ret; + if (ret <= 0) + return ret; /* check if any ufd ready */ for (nfds_t i = 0; i < ufds_cnt; i++) { if (ufds[i].revents) { /* set revents on fds */ nfds_t pos = ufds_pos[i]; int kfd = fds[pos].fd; - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, kfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, kfd); entry->stat_poll_revents_cnt++; fds[pos].revents = ufds[i].revents; - dbg("%s(%d), revents %d on ufd %d\n", __func__, kfd, fds[pos].revents, entry->ufd); + dbg("%s(%d), revents %d on ufd %d\n", __func__, kfd, fds[pos].revents, + entry->ufd); if (entry->kfd != fds[pos].fd) { - err("%s(%d), not match with entry ufd %d kfd %d\n", __func__, kfd, entry->ufd, - entry->kfd); + err("%s(%d), not match with entry ufd %d kfd %d\n", __func__, kfd, + entry->ufd, entry->kfd); } } } - if (!kfds_cnt) return ret; + if (!kfds_cnt) + return ret; /* check if any kfd ready */ for (nfds_t i = 0; i < kfds_cnt; i++) { @@ -638,14 +666,14 @@ static int upl_ppoll(struct upl_ctx* ctx, struct pollfd* fds, nfds_t nfds, int t return ret; } -static int upl_ufd_close(struct upl_ufd_entry* ufd_entry) { +static int upl_ufd_close(struct upl_ufd_entry *ufd_entry) { int ufd = ufd_entry->ufd; int kfd = ufd_entry->kfd; int efd = ufd_entry->efd; if (efd > 0) { - struct upl_ctx* ctx = ufd_entry->base.parent; - struct upl_efd_entry* efd_entry = upl_get_efd_entry(ctx, efd); + struct upl_ctx *ctx = ufd_entry->base.parent; + struct upl_efd_entry *efd_entry = upl_get_efd_entry(ctx, efd); info("%s(%d), remove epoll ctl on efd %d\n", __func__, kfd, efd); upl_efd_ctl_del(ctx, efd_entry, ufd_entry); } @@ -656,44 +684,47 @@ static int upl_ufd_close(struct upl_ufd_entry* ufd_entry) { } int socket(int domain, int type, int protocol) { - struct upl_ctx* ctx = upl_get_ctx(); + struct upl_ctx *ctx = upl_get_ctx(); int kfd; int ret; - if (!ctx) return LIBC_FN(socket, domain, type, protocol); + if (!ctx) + return LIBC_FN(socket, domain, type, protocol); kfd = LIBC_FN(socket, domain, type, protocol); - dbg("%s, kfd %d for domain %d type %d protocol %d\n", __func__, kfd, domain, type, - protocol); + dbg("%s, kfd %d for domain %d type %d protocol %d\n", __func__, kfd, domain, + type, protocol); if (kfd < 0) { - err("%s, create kfd fail %d for domain %d type %d protocol %d\n", __func__, kfd, - domain, type, protocol); + err("%s, create kfd fail %d for domain %d type %d protocol %d\n", __func__, + kfd, domain, type, protocol); return kfd; } if (kfd > ctx->upl_entires_nb) { - err("%s, kfd %d too big, consider enlarge entires space %d\n", __func__, kfd, - ctx->upl_entires_nb); + err("%s, kfd %d too big, consider enlarge entires space %d\n", __func__, + kfd, ctx->upl_entires_nb); return kfd; } ret = mufd_socket_check(domain, type, protocol); - if (ret < 0) return kfd; /* not support by mufd */ + if (ret < 0) + return kfd; /* not support by mufd */ if (ctx->child) { - err("%s, kfd %d, child not allow to create a ufd, domain %d type %d protocol %d\n", + err("%s, kfd %d, child not allow to create a ufd, domain %d type %d " + "protocol %d\n", __func__, kfd, domain, type, protocol); return kfd; } int ufd = mufd_socket(domain, type, protocol); if (ufd < 0) { - err("%s, create ufd fail %d for domain %d type %d protocol %d\n", __func__, ufd, - domain, type, protocol); + err("%s, create ufd fail %d for domain %d type %d protocol %d\n", __func__, + ufd, domain, type, protocol); return kfd; /* return kfd for fallback path */ } /* use rte malloc as it will be shared by child */ - struct upl_ufd_entry* entry = mufd_hp_zmalloc(sizeof(*entry), MTL_PORT_P); + struct upl_ufd_entry *entry = mufd_hp_zmalloc(sizeof(*entry), MTL_PORT_P); if (!entry) { err("%s, entry malloc fail for ufd %d\n", __func__, ufd); mufd_close(ufd); @@ -715,21 +746,23 @@ int socket(int domain, int type, int protocol) { } upl_set_upl_entry(ctx, kfd, entry); - info("%s, ufd %d kfd %d for domain %d type %d protocol %d\n", __func__, ufd, kfd, - domain, type, protocol); + info("%s, ufd %d kfd %d for domain %d type %d protocol %d\n", __func__, ufd, + kfd, domain, type, protocol); return kfd; } int close(int fd) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(close, fd); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(close, fd); dbg("%s(%d), start\n", __func__, fd); - struct upl_base_entry* entry = upl_get_upl_entry(ctx, fd); - if (!entry) return LIBC_FN(close, fd); + struct upl_base_entry *entry = upl_get_upl_entry(ctx, fd); + if (!entry) + return LIBC_FN(close, fd); if (entry->upl_type == UPL_ENTRY_UFD) { - struct upl_ufd_entry* ufd_entry = (struct upl_ufd_entry*)entry; + struct upl_ufd_entry *ufd_entry = (struct upl_ufd_entry *)entry; if (ctx->child) { warn("%s(%d), skip ufd close for child\n", __func__, fd); } else { @@ -737,7 +770,7 @@ int close(int fd) { mufd_hp_free(entry); } } else if (entry->upl_type == UPL_ENTRY_EPOLL) { - struct upl_efd_entry* efd_entry = (struct upl_efd_entry*)entry; + struct upl_efd_entry *efd_entry = (struct upl_efd_entry *)entry; upl_epoll_close(efd_entry); upl_free(entry); } else { @@ -749,47 +782,53 @@ int close(int fd) { return LIBC_FN(close, fd); } -int bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { +int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { #if 0 const struct sockaddr_in* addr_in = (struct sockaddr_in*)addr; info("%s(%d), port %u\n", __func__, sockfd, htons(addr_in->sin_port)); #endif - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(bind, sockfd, addr, addrlen); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(bind, sockfd, addr, addrlen); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry) return LIBC_FN(bind, sockfd, addr, addrlen); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); + if (!entry) + return LIBC_FN(bind, sockfd, addr, addrlen); int ufd = entry->ufd; int ret = mufd_bind(ufd, addr, addrlen); - if (ret >= 0) return ret; /* mufd bind succ */ + if (ret >= 0) + return ret; /* mufd bind succ */ /* try kernel fallback path */ ret = LIBC_FN(bind, sockfd, addr, addrlen); - if (ret < 0) return ret; + if (ret < 0) + return ret; entry->bind_kfd = true; info("%s(%d), mufd bind fail, fall back to libc\n", __func__, sockfd); return 0; } -ssize_t sendto(int sockfd, const void* buf, size_t len, int flags, - const struct sockaddr* dest_addr, socklen_t addrlen) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); +ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, + const struct sockaddr *dest_addr, socklen_t addrlen) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); dbg("%s(%d), len %" PRIu64 "\n", __func__, sockfd, len); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry) return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); + if (!entry) + return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); /* ufd only support ipv4 now */ - const struct sockaddr_in* addr_in = (struct sockaddr_in*)dest_addr; - uint8_t* ip = (uint8_t*)&addr_in->sin_addr.s_addr; + const struct sockaddr_in *addr_in = (struct sockaddr_in *)dest_addr; + uint8_t *ip = (uint8_t *)&addr_in->sin_addr.s_addr; int ufd = entry->ufd; if (mufd_tx_valid_ip(ufd, ip) < 0) { /* fallback to kfd if it's not in ufd address scope */ - dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], - ip[2], ip[3]); + dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, + ip[0], ip[1], ip[2], ip[3]); entry->stat_tx_kfd_cnt++; return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); } else { @@ -798,13 +837,15 @@ ssize_t sendto(int sockfd, const void* buf, size_t len, int flags, } } -ssize_t sendmsg(int sockfd, const struct msghdr* msg, int flags) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(sendmsg, sockfd, msg, flags); +ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(sendmsg, sockfd, msg, flags); dbg("%s(%d), start\n", __func__, sockfd); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry || !msg->msg_name) return LIBC_FN(sendmsg, sockfd, msg, flags); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); + if (!entry || !msg->msg_name) + return LIBC_FN(sendmsg, sockfd, msg, flags); if (!msg->msg_name || msg->msg_namelen < sizeof(struct sockaddr_in)) { warn("%s(%d), no msg_name or msg_namelen not valid\n", __func__, sockfd); @@ -812,15 +853,16 @@ ssize_t sendmsg(int sockfd, const struct msghdr* msg, int flags) { } /* ufd only support ipv4 now */ - const struct sockaddr_in* addr_in = (struct sockaddr_in*)msg->msg_name; - uint8_t* ip = (uint8_t*)&addr_in->sin_addr.s_addr; - dbg("%s(%d), dst ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], ip[2], ip[3]); + const struct sockaddr_in *addr_in = (struct sockaddr_in *)msg->msg_name; + uint8_t *ip = (uint8_t *)&addr_in->sin_addr.s_addr; + dbg("%s(%d), dst ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], ip[2], + ip[3]); int ufd = entry->ufd; if (mufd_tx_valid_ip(ufd, ip) < 0) { /* fallback to kfd if it's not in ufd address scope */ - dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], - ip[2], ip[3]); + dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, + ip[0], ip[1], ip[2], ip[3]); entry->stat_tx_kfd_cnt++; return LIBC_FN(sendmsg, sockfd, msg, flags); } else { @@ -829,59 +871,71 @@ ssize_t sendmsg(int sockfd, const struct msghdr* msg, int flags) { } } -ssize_t send(int sockfd, const void* buf, size_t len, int flags) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(send, sockfd, buf, len, flags); +ssize_t send(int sockfd, const void *buf, size_t len, int flags) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(send, sockfd, buf, len, flags); dbg("%s(%d), len %" PRIu64 "\n", __func__, sockfd, len); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry) return LIBC_FN(send, sockfd, buf, len, flags); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); + if (!entry) + return LIBC_FN(send, sockfd, buf, len, flags); err("%s(%d), not support ufd now\n", __func__, sockfd); UPL_ERR_RET(ENOTSUP); } -int poll(struct pollfd* fds, nfds_t nfds, int timeout) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(poll, fds, nfds, timeout); +int poll(struct pollfd *fds, nfds_t nfds, int timeout) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(poll, fds, nfds, timeout); return upl_ppoll(ctx, fds, nfds, timeout, NULL, NULL); } -int ppoll(struct pollfd* fds, nfds_t nfds, const struct timespec* tmo_p, - const sigset_t* sigmask) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(ppoll, fds, nfds, tmo_p, sigmask); +int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, + const sigset_t *sigmask) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(ppoll, fds, nfds, tmo_p, sigmask); - int timeout = (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * 1000 + tmo_p->tv_nsec / 1000000); + int timeout = + (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * 1000 + tmo_p->tv_nsec / 1000000); return upl_ppoll(ctx, fds, nfds, timeout, tmo_p, sigmask); } -int select(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, - struct timeval* timeout) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(select, nfds, readfds, writefds, exceptfds, timeout); +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(select, nfds, readfds, writefds, exceptfds, timeout); - return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, timeout, NULL, NULL); + return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, timeout, NULL, + NULL); } -int pselect(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, - const struct timespec* timeout, const sigset_t* sigmask) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout, sigmask); +int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const sigset_t *sigmask) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout, + sigmask); - return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, NULL, timeout, sigmask); + return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, NULL, timeout, + sigmask); } -ssize_t recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* src_addr, - socklen_t* addrlen) { +ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen) { dbg("%s(%d), start\n", __func__, sockfd); - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(recvfrom, sockfd, buf, len, flags, src_addr, addrlen); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(recvfrom, sockfd, buf, len, flags, src_addr, addrlen); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) { - if (entry) entry->stat_rx_kfd_cnt++; + if (entry) + entry->stat_rx_kfd_cnt++; return LIBC_FN(recvfrom, sockfd, buf, len, flags, src_addr, addrlen); } else { entry->stat_rx_ufd_cnt++; @@ -889,13 +943,15 @@ ssize_t recvfrom(int sockfd, void* buf, size_t len, int flags, struct sockaddr* } } -ssize_t recv(int sockfd, void* buf, size_t len, int flags) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(recv, sockfd, buf, len, flags); +ssize_t recv(int sockfd, void *buf, size_t len, int flags) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(recv, sockfd, buf, len, flags); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) { - if (entry) entry->stat_rx_kfd_cnt++; + if (entry) + entry->stat_rx_kfd_cnt++; return LIBC_FN(recv, sockfd, buf, len, flags); } else { entry->stat_rx_ufd_cnt++; @@ -903,13 +959,15 @@ ssize_t recv(int sockfd, void* buf, size_t len, int flags) { } } -ssize_t recvmsg(int sockfd, struct msghdr* msg, int flags) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(recvmsg, sockfd, msg, flags); +ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(recvmsg, sockfd, msg, flags); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) { - if (entry) entry->stat_rx_kfd_cnt++; + if (entry) + entry->stat_rx_kfd_cnt++; return LIBC_FN(recvmsg, sockfd, msg, flags); } else { entry->stat_rx_ufd_cnt++; @@ -917,22 +975,26 @@ ssize_t recvmsg(int sockfd, struct msghdr* msg, int flags) { } } -int getsockopt(int sockfd, int level, int optname, void* optval, socklen_t* optlen) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(getsockopt, sockfd, level, optname, optval, optlen); +int getsockopt(int sockfd, int level, int optname, void *optval, + socklen_t *optlen) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(getsockopt, sockfd, level, optname, optval, optlen); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) return LIBC_FN(getsockopt, sockfd, level, optname, optval, optlen); else return mufd_getsockopt(entry->ufd, level, optname, optval, optlen); } -int setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t optlen) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(setsockopt, sockfd, level, optname, optval, optlen); +int setsockopt(int sockfd, int level, int optname, const void *optval, + socklen_t optlen) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(setsockopt, sockfd, level, optname, optval, optlen); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) return LIBC_FN(setsockopt, sockfd, level, optname, optval, optlen); else @@ -940,10 +1002,11 @@ int setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t } int fcntl(int sockfd, int cmd, va_list args) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(fcntl, sockfd, cmd, args); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(fcntl, sockfd, cmd, args); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) return LIBC_FN(fcntl, sockfd, cmd, args); else @@ -951,10 +1014,11 @@ int fcntl(int sockfd, int cmd, va_list args) { } int fcntl64(int sockfd, int cmd, va_list args) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(fcntl64, sockfd, cmd, args); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(fcntl64, sockfd, cmd, args); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) return LIBC_FN(fcntl64, sockfd, cmd, args); else @@ -962,10 +1026,11 @@ int fcntl64(int sockfd, int cmd, va_list args) { } int ioctl(int sockfd, unsigned long cmd, va_list args) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(ioctl, sockfd, cmd, args); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(ioctl, sockfd, cmd, args); - struct upl_ufd_entry* entry = upl_get_ufd_entry(ctx, sockfd); + struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) return LIBC_FN(ioctl, sockfd, cmd, args); else @@ -973,11 +1038,13 @@ int ioctl(int sockfd, unsigned long cmd, va_list args) { } int epoll_create(int size) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(epoll_create, size); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(epoll_create, size); int efd = LIBC_FN(epoll_create, size); - if (efd < 0) return efd; + if (efd < 0) + return efd; dbg("%s(%d), size %d\n", __func__, efd, size); upl_epoll_create(ctx, efd); @@ -985,30 +1052,35 @@ int epoll_create(int size) { } int epoll_create1(int flags) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(epoll_create1, flags); + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(epoll_create1, flags); int efd = LIBC_FN(epoll_create1, flags); - if (efd < 0) return efd; + if (efd < 0) + return efd; dbg("%s(%d), flags 0x%x\n", __func__, efd, flags); upl_epoll_create(ctx, efd); return efd; } -int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(epoll_ctl, epfd, op, fd, event); +int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(epoll_ctl, epfd, op, fd, event); dbg("%s(%d), op %d fd %d\n", __func__, epfd, op, fd); - struct upl_efd_entry* efd = upl_get_efd_entry(ctx, epfd); - if (!efd) return LIBC_FN(epoll_ctl, epfd, op, fd, event); + struct upl_efd_entry *efd = upl_get_efd_entry(ctx, epfd); + if (!efd) + return LIBC_FN(epoll_ctl, epfd, op, fd, event); /* if it's a ufd entry */ - struct upl_ufd_entry* ufd = upl_get_ufd_entry(ctx, fd); + struct upl_ufd_entry *ufd = upl_get_ufd_entry(ctx, fd); if (!ufd || ufd->bind_kfd) { int ret = LIBC_FN(epoll_ctl, epfd, op, fd, event); - if (ret < 0) return ret; + if (ret < 0) + return ret; dbg("%s(%d), op %d for fd %d succ with libc\n", __func__, epfd, op, fd); if (op == EPOLL_CTL_ADD) { atomic_fetch_add(&efd->kfd_cnt, 1); @@ -1031,38 +1103,43 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) { } } -int epoll_wait(int epfd, struct epoll_event* events, int maxevents, int timeout) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(epoll_wait, epfd, events, maxevents, timeout); +int epoll_wait(int epfd, struct epoll_event *events, int maxevents, + int timeout) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(epoll_wait, epfd, events, maxevents, timeout); - struct upl_efd_entry* efd = upl_get_efd_entry(ctx, epfd); + struct upl_efd_entry *efd = upl_get_efd_entry(ctx, epfd); if (!efd || !upl_epoll_has_ufd(efd)) return LIBC_FN(epoll_wait, epfd, events, maxevents, timeout); dbg("%s(%d), timeout %d maxevents %d\n", __func__, epfd, timeout, maxevents); /* wa to fix end loop in userspace issue */ - if (timeout < 0) timeout = 1000 * 2; + if (timeout < 0) + timeout = 1000 * 2; return upl_efd_epoll_pwait(efd, events, maxevents, timeout, NULL); } -int epoll_pwait(int epfd, struct epoll_event* events, int maxevents, int timeout, - const sigset_t* sigmask) { - struct upl_ctx* ctx = upl_get_ctx(); - if (!ctx) return LIBC_FN(epoll_pwait, epfd, events, maxevents, timeout, sigmask); +int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, + int timeout, const sigset_t *sigmask) { + struct upl_ctx *ctx = upl_get_ctx(); + if (!ctx) + return LIBC_FN(epoll_pwait, epfd, events, maxevents, timeout, sigmask); - struct upl_efd_entry* efd = upl_get_efd_entry(ctx, epfd); + struct upl_efd_entry *efd = upl_get_efd_entry(ctx, epfd); if (!efd || !upl_epoll_has_ufd(efd)) return LIBC_FN(epoll_pwait, epfd, events, maxevents, timeout, sigmask); int kfd_cnt = atomic_load(&efd->kfd_cnt); info("%s(%d), timeout %d, kfd_cnt %d\n", __func__, epfd, timeout, kfd_cnt); /* wa to fix end loop in userspace issue */ - if (timeout < 0) timeout = 1000 * 2; + if (timeout < 0) + timeout = 1000 * 2; return upl_efd_epoll_pwait(efd, events, maxevents, timeout, sigmask); } enum mtl_log_level upl_get_log_level(void) { - struct upl_ctx* ctx = upl_get_ctx(); + struct upl_ctx *ctx = upl_get_ctx(); if (ctx) return ctx->log_level; else diff --git a/ld_preload/udp/udp_preload.h b/ld_preload/udp/udp_preload.h index 97b4ca3de..3f5165fc2 100644 --- a/ld_preload/udp/udp_preload.h +++ b/ld_preload/udp/udp_preload.h @@ -29,75 +29,78 @@ enum mtl_log_level upl_get_log_level(void); /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_DEBUG) printf("UPL: " __VA_ARGS__); \ +#define dbg(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_DEBUG) \ + printf("UPL: " __VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_INFO) printf("UPL: " __VA_ARGS__); \ +#define info(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_INFO) \ + printf("UPL: " __VA_ARGS__); \ } while (0) -#define notice(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_NOTICE) printf("UPL: "__VA_ARGS__); \ +#define notice(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_NOTICE) \ + printf("UPL: "__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_WARNING) printf("UPL: Warn: "__VA_ARGS__); \ +#define warn(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_WARNING) \ + printf("UPL: Warn: "__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_ERR) printf("UPL: Error: "__VA_ARGS__); \ +#define err(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_ERR) \ + printf("UPL: Error: "__VA_ARGS__); \ } while (0) /* On error, -1 is returned, and errno is set appropriately. */ -#define UPL_ERR_RET(code) \ - do { \ - errno = code; \ - return -1; \ +#define UPL_ERR_RET(code) \ + do { \ + errno = code; \ + return -1; \ } while (0) /* child only can't use rte malloc */ -static inline void* upl_malloc(size_t sz) { - return malloc(sz); -} +static inline void *upl_malloc(size_t sz) { return malloc(sz); } -static inline void* upl_zmalloc(size_t sz) { - void* p = malloc(sz); - if (p) memset(p, 0x0, sz); +static inline void *upl_zmalloc(size_t sz) { + void *p = malloc(sz); + if (p) + memset(p, 0x0, sz); return p; } -static inline void upl_free(void* p) { - free(p); -} +static inline void upl_free(void *p) { free(p); } struct upl_functions { int (*socket)(int domain, int type, int protocol); int (*close)(int sockfd); - int (*bind)(int sockfd, const struct sockaddr* addr, socklen_t addrlen); - ssize_t (*send)(int sockfd, const void* buf, size_t len, int flags); - ssize_t (*sendto)(int sockfd, const void* buf, size_t len, int flags, - const struct sockaddr* dest_addr, socklen_t addrlen); - ssize_t (*sendmsg)(int sockfd, const struct msghdr* msg, int flags); - int (*poll)(struct pollfd* fds, nfds_t nfds, int timeout); - int (*ppoll)(struct pollfd* fds, nfds_t nfds, const struct timespec* tmo_p, - const sigset_t* sigmask); - int (*select)(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, - struct timeval* timeout); - int (*pselect)(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, - const struct timespec* timeout, const sigset_t* sigmask); - ssize_t (*recvfrom)(int sockfd, void* buf, size_t len, int flags, - struct sockaddr* src_addr, socklen_t* addrlen); - ssize_t (*recv)(int sockfd, void* buf, size_t len, int flags); - ssize_t (*recvmsg)(int sockfd, struct msghdr* msg, int flags); - int (*getsockopt)(int sockfd, int level, int optname, void* optval, socklen_t* optlen); - int (*setsockopt)(int sockfd, int level, int optname, const void* optval, + int (*bind)(int sockfd, const struct sockaddr *addr, socklen_t addrlen); + ssize_t (*send)(int sockfd, const void *buf, size_t len, int flags); + ssize_t (*sendto)(int sockfd, const void *buf, size_t len, int flags, + const struct sockaddr *dest_addr, socklen_t addrlen); + ssize_t (*sendmsg)(int sockfd, const struct msghdr *msg, int flags); + int (*poll)(struct pollfd *fds, nfds_t nfds, int timeout); + int (*ppoll)(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, + const sigset_t *sigmask); + int (*select)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + struct timeval *timeout); + int (*pselect)(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, + const struct timespec *timeout, const sigset_t *sigmask); + ssize_t (*recvfrom)(int sockfd, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen); + ssize_t (*recv)(int sockfd, void *buf, size_t len, int flags); + ssize_t (*recvmsg)(int sockfd, struct msghdr *msg, int flags); + int (*getsockopt)(int sockfd, int level, int optname, void *optval, + socklen_t *optlen); + int (*setsockopt)(int sockfd, int level, int optname, const void *optval, socklen_t optlen); int (*fcntl)(int sockfd, int cmd, va_list args); int (*fcntl64)(int sockfd, int cmd, va_list args); @@ -105,10 +108,11 @@ struct upl_functions { /* epoll */ int (*epoll_create)(int size); int (*epoll_create1)(int flags); - int (*epoll_ctl)(int epfd, int op, int fd, struct epoll_event* event); - int (*epoll_wait)(int epfd, struct epoll_event* events, int maxevents, int timeout); - int (*epoll_pwait)(int epfd, struct epoll_event* events, int maxevents, int timeout, - const sigset_t* sigmask); + int (*epoll_ctl)(int epfd, int op, int fd, struct epoll_event *event); + int (*epoll_wait)(int epfd, struct epoll_event *events, int maxevents, + int timeout); + int (*epoll_pwait)(int epfd, struct epoll_event *events, int maxevents, + int timeout, const sigset_t *sigmask); }; enum upl_entry_type { @@ -121,7 +125,7 @@ enum upl_entry_type { struct upl_ctx; /* forward declare */ struct upl_base_entry { - struct upl_ctx* parent; + struct upl_ctx *parent; enum upl_entry_type upl_type; /* if created by child */ bool child; @@ -152,7 +156,7 @@ struct upl_ufd_entry { struct upl_efd_fd_item { struct epoll_event event; - struct upl_ufd_entry* ufd; + struct upl_ufd_entry *ufd; /* linked list */ TAILQ_ENTRY(upl_efd_fd_item) next; }; @@ -169,46 +173,46 @@ struct upl_efd_entry { int fds_cnt; atomic_int kfd_cnt; /* for kfd query */ - struct epoll_event* events; + struct epoll_event *events; int maxevents; - const sigset_t* sigmask; + const sigset_t *sigmask; int kfd_ret; }; struct upl_ctx { enum mtl_log_level log_level; /* - * All rte_malloc memory is shared by processes as it's mapped with shared during DPDK - * memory init, and MTL always use DPDK memory. - * The easiest way for multi-process sharing is parent process to create/free the - * resource, child only access the data path */ + * All rte_malloc memory is shared by processes as it's mapped with shared + * during DPDK memory init, and MTL always use DPDK memory. The easiest way + * for multi-process sharing is parent process to create/free the resource, + * child only access the data path */ pid_t pid; bool child; /* if it's for child process */ int upl_entires_nb; /* the number of upl_entires */ - void** upl_entires; /* upl entries */ + void **upl_entires; /* upl entries */ }; struct upl_select_ctx { - struct upl_ctx* parent; + struct upl_ctx *parent; int nfds; - fd_set* readfds; - fd_set* writefds; - fd_set* exceptfds; - struct timeval* timeout; + fd_set *readfds; + fd_set *writefds; + fd_set *exceptfds; + struct timeval *timeout; /* for select */ - const struct timespec* timeout_spec; - const sigset_t* sigmask; + const struct timespec *timeout_spec; + const sigset_t *sigmask; }; struct upl_poll_ctx { - struct upl_ctx* parent; - struct pollfd* fds; + struct upl_ctx *parent; + struct pollfd *fds; nfds_t nfds; int timeout; /* for ppoll */ - const struct timespec* tmo_p; - const sigset_t* sigmask; + const struct timespec *tmo_p; + const sigset_t *sigmask; }; #endif diff --git a/lib/src/datapath/mt_dp_socket.c b/lib/src/datapath/mt_dp_socket.c index 8eef0f939..16c58640a 100644 --- a/lib/src/datapath/mt_dp_socket.c +++ b/lib/src/datapath/mt_dp_socket.c @@ -23,14 +23,14 @@ #ifndef WINDOWSENV -static inline int tx_socket_verify_mbuf(struct rte_mbuf* m) { +static inline int tx_socket_verify_mbuf(struct rte_mbuf *m) { if (m->nb_segs > 1) { err("%s, only support one nb_segs %u\n", __func__, m->nb_segs); return -ENOTSUP; } - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(m, struct mt_udp_hdr*); - struct rte_ether_hdr* eth = &hdr->eth; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(m, struct mt_udp_hdr *); + struct rte_ether_hdr *eth = &hdr->eth; uint16_t ether_type = ntohs(eth->ether_type); if (ether_type != RTE_ETHER_TYPE_IPV4) { @@ -41,12 +41,13 @@ static inline int tx_socket_verify_mbuf(struct rte_mbuf* m) { return 0; } -static int tx_socket_send_mbuf(struct mt_tx_socket_thread* t, struct rte_mbuf* m) { - struct mt_tx_socket_entry* entry = t->parent; +static int tx_socket_send_mbuf(struct mt_tx_socket_thread *t, + struct rte_mbuf *m) { + struct mt_tx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; int fd = t->fd, ret; struct sockaddr_in send_addr; - struct mtl_port_status* stats = mt_if(entry->parent, port)->dev_stats_sw; + struct mtl_port_status *stats = mt_if(entry->parent, port)->dev_stats_sw; /* check if suppoted */ ret = tx_socket_verify_mbuf(m); @@ -55,25 +56,26 @@ static int tx_socket_send_mbuf(struct mt_tx_socket_thread* t, struct rte_mbuf* m return ret; } - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(m, struct mt_udp_hdr*); + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(m, struct mt_udp_hdr *); // mt_mbuf_dump(port, 0, "socket_tx", m); - void* payload = rte_pktmbuf_mtod_offset(m, void*, sizeof(struct mt_udp_hdr)); + void *payload = rte_pktmbuf_mtod_offset(m, void *, sizeof(struct mt_udp_hdr)); ssize_t payload_len = m->data_len - sizeof(struct mt_udp_hdr); - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; - mudp_init_sockaddr(&send_addr, (uint8_t*)&ipv4->dst_addr, ntohs(udp->dst_port)); + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; + mudp_init_sockaddr(&send_addr, (uint8_t *)&ipv4->dst_addr, + ntohs(udp->dst_port)); t->stat_tx_try++; /* nonblocking */ ssize_t send = sendto(fd, payload, payload_len, MSG_DONTWAIT, - (const struct sockaddr*)&send_addr, sizeof(send_addr)); - dbg("%s(%d,%d), len %" PRId64 " send %" PRId64 "\n", __func__, port, fd, payload_len, - send); + (const struct sockaddr *)&send_addr, sizeof(send_addr)); + dbg("%s(%d,%d), len %" PRId64 " send %" PRId64 "\n", __func__, port, fd, + payload_len, send); if (send != payload_len) { - dbg("%s(%d,%d), sendto fail, len %" PRId64 " send %" PRId64 "\n", __func__, port, fd, - payload_len, send); + dbg("%s(%d,%d), sendto fail, len %" PRId64 " send %" PRId64 "\n", __func__, + port, fd, payload_len, send); return -EBUSY; } if (stats) { @@ -85,33 +87,37 @@ static int tx_socket_send_mbuf(struct mt_tx_socket_thread* t, struct rte_mbuf* m return 0; } -static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread* t, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { +static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread *t, + struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { uint16_t tx = 0; - struct mt_tx_socket_entry* entry = t->parent; + struct mt_tx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; int fd = t->fd, ret; uint16_t gso_sz = entry->gso_sz; struct iovec iovs[nb_pkts]; uint16_t gso_cnt = 0; - struct msghdr* msg = &t->msg; + struct msghdr *msg = &t->msg; ssize_t write; - struct mtl_port_status* stats = mt_if(entry->parent, port)->dev_stats_sw; + struct mtl_port_status *stats = mt_if(entry->parent, port)->dev_stats_sw; msg->msg_iov = iovs; for (uint16_t i = 0; i < nb_pkts; i++) { - struct rte_mbuf* m = tx_pkts[i]; + struct rte_mbuf *m = tx_pkts[i]; ret = tx_socket_verify_mbuf(m); if (ret < 0) { - err("%s(%d,%d), unsupported mbuf %p ret %d\n", __func__, port, fd, m, ret); + err("%s(%d,%d), unsupported mbuf %p ret %d\n", __func__, port, fd, m, + ret); return tx; } t->stat_tx_try++; uint16_t payload_len = m->data_len - sizeof(struct mt_udp_hdr); - void* payload = rte_pktmbuf_mtod_offset(m, void*, sizeof(struct mt_udp_hdr)); - dbg("%s(%d,%d), mbuf %u payload_len %u\n", __func__, port, fd, i, payload_len); + void *payload = + rte_pktmbuf_mtod_offset(m, void *, sizeof(struct mt_udp_hdr)); + dbg("%s(%d,%d), mbuf %u payload_len %u\n", __func__, port, fd, i, + payload_len); if (payload_len == gso_sz) { iovs[gso_cnt].iov_base = payload; @@ -122,8 +128,8 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread* t, msg->msg_iovlen = gso_cnt; write = sendmsg(fd, msg, MSG_DONTWAIT); if (write != (gso_sz * gso_cnt)) { - dbg("%s(%d,%d), sendmsg 1 fail, len %u send %" PRId64 "\n", __func__, port, fd, - gso_sz * gso_cnt, write); + dbg("%s(%d,%d), sendmsg 1 fail, len %u send %" PRId64 "\n", __func__, + port, fd, gso_sz * gso_cnt, write); return tx; } tx += gso_cnt; @@ -139,8 +145,8 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread* t, write = sendto(fd, payload, payload_len, MSG_DONTWAIT, &t->send_addr, sizeof(t->send_addr)); if (write != payload_len) { - dbg("%s(%d,%d), sendto fail, len %u send %" PRId64 "\n", __func__, port, fd, - payload_len, write); + dbg("%s(%d,%d), sendto fail, len %u send %" PRId64 "\n", __func__, port, + fd, payload_len, write); return tx; } tx++; @@ -156,12 +162,12 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread* t, msg->msg_iovlen = gso_cnt; write = sendmsg(fd, msg, MSG_DONTWAIT); if (write != (gso_sz * gso_cnt)) { - dbg("%s(%d,%d), sendmsg fail, len %u send %" PRId64 "\n", __func__, port, fd, - gso_sz * gso_cnt, write); + dbg("%s(%d,%d), sendmsg fail, len %u send %" PRId64 "\n", __func__, port, + fd, gso_sz * gso_cnt, write); return tx; } - dbg("%s(%d,%d), sendmsg succ, len %u send %" PRId64 "\n", __func__, port, fd, - gso_sz * gso_cnt, write); + dbg("%s(%d,%d), sendmsg succ, len %u send %" PRId64 "\n", __func__, port, + fd, gso_sz * gso_cnt, write); tx += gso_cnt; if (stats) { stats->tx_packets += gso_cnt; @@ -174,17 +180,18 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread* t, return tx; } -static void* tx_socket_thread_loop(void* arg) { - struct mt_tx_socket_thread* t = arg; - struct mt_tx_socket_entry* entry = t->parent; +static void *tx_socket_thread_loop(void *arg) { + struct mt_tx_socket_thread *t = arg; + struct mt_tx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; - struct rte_mbuf* m = NULL; + struct rte_mbuf *m = NULL; int ret; info("%s(%d,%d), start\n", __func__, port, t->fd); while (rte_atomic32_read(&t->stop_thread) == 0) { - ret = rte_ring_mc_dequeue(entry->ring, (void**)&m); - if (ret < 0) continue; + ret = rte_ring_mc_dequeue(entry->ring, (void **)&m); + if (ret < 0) + continue; do { ret = tx_socket_send_mbuf(t, m); } while ((ret < 0) && (rte_atomic32_read(&t->stop_thread) == 0)); @@ -195,9 +202,9 @@ static void* tx_socket_thread_loop(void* arg) { return NULL; } -static int tx_socket_init_thread_data(struct mt_tx_socket_thread* t) { +static int tx_socket_init_thread_data(struct mt_tx_socket_thread *t) { int ret; - struct mt_tx_socket_entry* entry = t->parent; + struct mt_tx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; int idx = t->idx; int fd = socket(AF_INET, SOCK_DGRAM, 0); @@ -216,55 +223,58 @@ static int tx_socket_init_thread_data(struct mt_tx_socket_thread* t) { } /* bind to device */ - const char* if_name = mt_kernel_if_name(entry->parent, port); + const char *if_name = mt_kernel_if_name(entry->parent, port); ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, if_name, strlen(if_name)); if (ret < 0) { - err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, idx, if_name, ret); + err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, idx, + if_name, ret); return ret; } if (entry->gso_sz) { - mudp_init_sockaddr(&t->send_addr, entry->flow.dip_addr, entry->flow.dst_port); + mudp_init_sockaddr(&t->send_addr, entry->flow.dip_addr, + entry->flow.dst_port); t->msg.msg_namelen = sizeof(t->send_addr); t->msg.msg_name = &t->send_addr; /* gso size for sendmsg */ t->msg.msg_control = t->msg_control; t->msg.msg_controllen = sizeof(t->msg_control); - struct cmsghdr* cmsg; + struct cmsghdr *cmsg; cmsg = CMSG_FIRSTHDR(&t->msg); cmsg->cmsg_level = SOL_UDP; cmsg->cmsg_type = UDP_SEGMENT; cmsg->cmsg_len = CMSG_LEN(sizeof(uint16_t)); - uint16_t* val_p; - val_p = (uint16_t*)CMSG_DATA(cmsg); + uint16_t *val_p; + val_p = (uint16_t *)CMSG_DATA(cmsg); *val_p = entry->gso_sz; } return 0; } -static int tx_socket_init_threads(struct mt_tx_socket_entry* entry) { +static int tx_socket_init_threads(struct mt_tx_socket_entry *entry) { int idx = entry->threads_data[0].fd; int ret; /* fds[0] already init */ for (int i = 1; i < entry->threads; i++) { - struct mt_tx_socket_thread* t = &entry->threads_data[i]; + struct mt_tx_socket_thread *t = &entry->threads_data[i]; ret = tx_socket_init_thread_data(t); - if (ret < 0) return ret; + if (ret < 0) + return ret; } /* create the ring, multi producer single consumer */ char ring_name[64]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count; snprintf(ring_name, sizeof(ring_name), "%sRP%dFD%d", MT_TX_DP_SOCKET_PREFIX, entry->port, idx); flags = RING_F_SC_DEQ; count = mt_if_nb_rx_desc(entry->parent, entry->port); - ring = - rte_ring_create(ring_name, count, mt_socket_id(entry->parent, entry->port), flags); + ring = rte_ring_create(ring_name, count, + mt_socket_id(entry->parent, entry->port), flags); if (!ring) { err("%s(%d), ring create fail\n", __func__, idx); return -EIO; @@ -273,12 +283,13 @@ static int tx_socket_init_threads(struct mt_tx_socket_entry* entry) { /* create the threads */ for (int i = 0; i < entry->threads; i++) { - struct mt_tx_socket_thread* t = &entry->threads_data[i]; + struct mt_tx_socket_thread *t = &entry->threads_data[i]; rte_atomic32_set(&t->stop_thread, 0); ret = pthread_create(&t->tid, NULL, tx_socket_thread_loop, t); if (ret < 0) { - err("%s(%d), thread create fail %d for thread %d\n", __func__, idx, ret, i); + err("%s(%d), thread create fail %d for thread %d\n", __func__, idx, ret, + i); return ret; } } @@ -286,16 +297,16 @@ static int tx_socket_init_threads(struct mt_tx_socket_entry* entry) { return 0; } -static int tx_socket_stat_dump(void* priv) { - struct mt_tx_socket_entry* entry = priv; +static int tx_socket_stat_dump(void *priv) { + struct mt_tx_socket_entry *entry = priv; enum mtl_port port = entry->port; for (int i = 0; i < entry->threads; i++) { - struct mt_tx_socket_thread* t = &entry->threads_data[i]; + struct mt_tx_socket_thread *t = &entry->threads_data[i]; int fd = t->fd; - info("%s(%d,%d), tx pkt %d gso %d try %d on thread %d\n", __func__, port, fd, - t->stat_tx_pkt, t->stat_tx_gso, t->stat_tx_try, i); + info("%s(%d,%d), tx pkt %d gso %d try %d on thread %d\n", __func__, port, + fd, t->stat_tx_pkt, t->stat_tx_gso, t->stat_tx_try, i); t->stat_tx_pkt = 0; t->stat_tx_gso = 0; t->stat_tx_try = 0; @@ -304,9 +315,9 @@ static int tx_socket_stat_dump(void* priv) { return 0; } -struct mt_tx_socket_entry* mt_tx_socket_get(struct mtl_main_impl* impl, +struct mt_tx_socket_entry *mt_tx_socket_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_txq_flow* flow) { + struct mt_txq_flow *flow) { int ret; if (!mt_drv_kernel_based(impl, port)) { @@ -314,7 +325,7 @@ struct mt_tx_socket_entry* mt_tx_socket_get(struct mtl_main_impl* impl, return NULL; } - struct mt_tx_socket_entry* entry = + struct mt_tx_socket_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -328,7 +339,7 @@ struct mt_tx_socket_entry* mt_tx_socket_get(struct mtl_main_impl* impl, rte_memcpy(&entry->flow, flow, sizeof(entry->flow)); for (int i = 0; i < MT_DP_SOCKET_THREADS_MAX; i++) { - struct mt_tx_socket_thread* t = &entry->threads_data[i]; + struct mt_tx_socket_thread *t = &entry->threads_data[i]; t->idx = i; t->fd = -1; t->parent = entry; @@ -346,7 +357,8 @@ struct mt_tx_socket_entry* mt_tx_socket_get(struct mtl_main_impl* impl, if (entry->threads > 1) { ret = tx_socket_init_threads(entry); if (ret < 0) { - err("%s(%d), init %d threads fail %d\n", __func__, port, entry->threads, ret); + err("%s(%d), init %d threads fail %d\n", __func__, port, entry->threads, + ret); mt_tx_socket_put(entry); return NULL; } @@ -360,14 +372,14 @@ struct mt_tx_socket_entry* mt_tx_socket_get(struct mtl_main_impl* impl, } entry->stat_registered = true; - uint8_t* ip = flow->dip_addr; - info("%s(%d), fd %d ip %u.%u.%u.%u, port %u, threads %u gso_sz %u\n", __func__, port, - entry->threads_data[0].fd, ip[0], ip[1], ip[2], ip[3], flow->dst_port, - entry->threads, entry->gso_sz); + uint8_t *ip = flow->dip_addr; + info("%s(%d), fd %d ip %u.%u.%u.%u, port %u, threads %u gso_sz %u\n", + __func__, port, entry->threads_data[0].fd, ip[0], ip[1], ip[2], ip[3], + flow->dst_port, entry->threads, entry->gso_sz); return entry; } -int mt_tx_socket_put(struct mt_tx_socket_entry* entry) { +int mt_tx_socket_put(struct mt_tx_socket_entry *entry) { int idx = entry->threads_data[0].fd; enum mtl_port port = entry->port; @@ -379,7 +391,7 @@ int mt_tx_socket_put(struct mt_tx_socket_entry* entry) { /* stop threads */ for (int i = 0; i < MT_DP_SOCKET_THREADS_MAX; i++) { - struct mt_tx_socket_thread* t = &entry->threads_data[i]; + struct mt_tx_socket_thread *t = &entry->threads_data[i]; rte_atomic32_set(&t->stop_thread, 1); if (t->tid) { @@ -396,7 +408,7 @@ int mt_tx_socket_put(struct mt_tx_socket_entry* entry) { /* close fd */ for (int i = 0; i < MT_DP_SOCKET_THREADS_MAX; i++) { - struct mt_tx_socket_thread* t = &entry->threads_data[i]; + struct mt_tx_socket_thread *t = &entry->threads_data[i]; if (t->fd >= 0) { close(t->fd); @@ -409,14 +421,14 @@ int mt_tx_socket_put(struct mt_tx_socket_entry* entry) { return 0; } -uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { uint16_t tx = 0; int ret; if (entry->ring) { - unsigned int n = - rte_ring_sp_enqueue_bulk(entry->ring, (void**)&tx_pkts[0], nb_pkts, NULL); + unsigned int n = rte_ring_sp_enqueue_bulk(entry->ring, (void **)&tx_pkts[0], + nb_pkts, NULL); // tx_socket_dequeue(&entry->threads_data[0]); return n; } @@ -425,9 +437,10 @@ uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry* entry, struct rte_mbuf** tx = tx_socket_send_mbuf_gso(&entry->threads_data[0], tx_pkts, nb_pkts); } else { for (tx = 0; tx < nb_pkts; tx++) { - struct rte_mbuf* m = tx_pkts[tx]; + struct rte_mbuf *m = tx_pkts[tx]; ret = tx_socket_send_mbuf(&entry->threads_data[0], m); - if (ret < 0) break; + if (ret < 0) + break; } } @@ -435,11 +448,12 @@ uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry* entry, struct rte_mbuf** return tx; } -static int rx_socket_init_fd(struct mt_rx_socket_entry* entry, int fd, bool reuse) { +static int rx_socket_init_fd(struct mt_rx_socket_entry *entry, int fd, + bool reuse) { int ret; enum mtl_port port = entry->port; - struct mtl_main_impl* impl = entry->parent; - struct mt_rxq_flow* flow = &entry->flow; + struct mtl_main_impl *impl = entry->parent; + struct mt_rxq_flow *flow = &entry->flow; if (reuse) { int optval = 1; @@ -458,11 +472,12 @@ static int rx_socket_init_fd(struct mt_rx_socket_entry* entry, int fd, bool reus } /* bind to device */ - const char* if_name = mt_kernel_if_name(impl, port); + const char *if_name = mt_kernel_if_name(impl, port); info("%s(%d,%d), SO_BINDTODEVICE to %s\n", __func__, port, fd, if_name); ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, if_name, strlen(if_name)); if (ret < 0) { - err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, fd, if_name, ret); + err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, fd, + if_name, ret); return ret; } @@ -472,9 +487,10 @@ static int rx_socket_init_fd(struct mt_rx_socket_entry* entry, int fd, bool reus mudp_init_sockaddr(&bind_addr, flow->dip_addr, flow->dst_port); else mudp_init_sockaddr(&bind_addr, mt_sip_addr(impl, port), flow->dst_port); - ret = bind(fd, (const struct sockaddr*)&bind_addr, sizeof(bind_addr)); + ret = bind(fd, (const struct sockaddr *)&bind_addr, sizeof(bind_addr)); if (ret < 0) { - err("%s(%d,%d), bind to port %u fail %d\n", __func__, port, fd, flow->dst_port, ret); + err("%s(%d,%d), bind to port %u fail %d\n", __func__, port, fd, + flow->dst_port, ret); return ret; } @@ -490,12 +506,12 @@ static int rx_socket_init_fd(struct mt_rx_socket_entry* entry, int fd, bool reus return 0; } -static struct rte_mbuf* rx_socket_recv_mbuf(struct mt_rx_socket_thread* t) { - struct mt_rx_socket_entry* entry = t->parent; +static struct rte_mbuf *rx_socket_recv_mbuf(struct mt_rx_socket_thread *t) { + struct mt_rx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; - struct mtl_port_status* stats = mt_if(entry->parent, port)->dev_stats_sw; + struct mtl_port_status *stats = mt_if(entry->parent, port)->dev_stats_sw; int fd = entry->fd; - struct rte_mbuf* pkt = t->mbuf; + struct rte_mbuf *pkt = t->mbuf; if (!pkt) { pkt = rte_pktmbuf_alloc(entry->pool); @@ -506,16 +522,16 @@ static struct rte_mbuf* rx_socket_recv_mbuf(struct mt_rx_socket_thread* t) { t->mbuf = pkt; } - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); - void* payload = &hdr[1]; - struct rte_udp_hdr* udp = &hdr->udp; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); + void *payload = &hdr[1]; + struct rte_udp_hdr *udp = &hdr->udp; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; struct sockaddr_in addr_in; socklen_t addr_in_len = sizeof(addr_in); t->stat_rx_try++; - ssize_t len = - recvfrom(fd, payload, entry->pool_element_sz, MSG_DONTWAIT, &addr_in, &addr_in_len); + ssize_t len = recvfrom(fd, payload, entry->pool_element_sz, MSG_DONTWAIT, + &addr_in, &addr_in_len); if (len <= 0) { return NULL; } @@ -539,21 +555,23 @@ static struct rte_mbuf* rx_socket_recv_mbuf(struct mt_rx_socket_thread* t) { return pkt; } -static void* rx_socket_thread_loop(void* arg) { - struct mt_rx_socket_thread* t = arg; - struct mt_rx_socket_entry* entry = t->parent; +static void *rx_socket_thread_loop(void *arg) { + struct mt_rx_socket_thread *t = arg; + struct mt_rx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; int idx = t->idx, fd = entry->fd; - struct rte_mbuf* m; + struct rte_mbuf *m; int ret; info("%s(%d,%d), start thread %d\n", __func__, port, fd, idx); while (rte_atomic32_read(&t->stop_thread) == 0) { m = rx_socket_recv_mbuf(t); - if (!m) continue; + if (!m) + continue; while (rte_atomic32_read(&t->stop_thread) == 0) { ret = rte_ring_mp_enqueue(entry->ring, m); - if (ret >= 0) break; /* succ */ + if (ret >= 0) + break; /* succ */ } } info("%s(%d,%d), stop thread %d\n", __func__, port, fd, idx); @@ -561,19 +579,21 @@ static void* rx_socket_thread_loop(void* arg) { return NULL; } -static int rx_socket_init_threads(struct mt_rx_socket_entry* entry) { +static int rx_socket_init_threads(struct mt_rx_socket_entry *entry) { int fd = entry->fd; enum mtl_port port = entry->port; int ret; /* create the ring, one producer multi consumer */ char ring_name[64]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count; - snprintf(ring_name, sizeof(ring_name), "%sRP%dFD%d", MT_RX_DP_SOCKET_PREFIX, port, fd); + snprintf(ring_name, sizeof(ring_name), "%sRP%dFD%d", MT_RX_DP_SOCKET_PREFIX, + port, fd); flags = RING_F_SP_ENQ; count = mt_if_nb_tx_desc(entry->parent, port); - ring = rte_ring_create(ring_name, count, mt_socket_id(entry->parent, port), flags); + ring = rte_ring_create(ring_name, count, mt_socket_id(entry->parent, port), + flags); if (!ring) { err("%s(%d,%d), ring create fail\n", __func__, port, fd); return -EIO; @@ -582,12 +602,13 @@ static int rx_socket_init_threads(struct mt_rx_socket_entry* entry) { /* create the threads except the base fd */ for (int i = 0; i < entry->threads; i++) { - struct mt_rx_socket_thread* t = &entry->threads_data[i]; + struct mt_rx_socket_thread *t = &entry->threads_data[i]; rte_atomic32_set(&t->stop_thread, 0); ret = pthread_create(&t->tid, NULL, rx_socket_thread_loop, t); if (ret < 0) { - err("%s(%d,%d), thread create fail %d for thread %d\n", __func__, port, fd, ret, i); + err("%s(%d,%d), thread create fail %d for thread %d\n", __func__, port, + fd, ret, i); return ret; } } @@ -595,16 +616,16 @@ static int rx_socket_init_threads(struct mt_rx_socket_entry* entry) { return 0; } -static int rx_socket_stat_dump(void* priv) { - struct mt_rx_socket_entry* entry = priv; +static int rx_socket_stat_dump(void *priv) { + struct mt_rx_socket_entry *entry = priv; enum mtl_port port = entry->port; int fd = entry->fd; for (int i = 0; i < entry->threads; i++) { - struct mt_rx_socket_thread* t = &entry->threads_data[i]; + struct mt_rx_socket_thread *t = &entry->threads_data[i]; - info("%s(%d,%d), rx pkt %d try %d on thread %d\n", __func__, port, fd, t->stat_rx_pkt, - t->stat_rx_try, i); + info("%s(%d,%d), rx pkt %d try %d on thread %d\n", __func__, port, fd, + t->stat_rx_pkt, t->stat_rx_try, i); t->stat_rx_pkt = 0; t->stat_rx_try = 0; } @@ -612,9 +633,9 @@ static int rx_socket_stat_dump(void* priv) { return 0; } -struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, +struct mt_rx_socket_entry *mt_rx_socket_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_rxq_flow* flow) { + struct mt_rxq_flow *flow) { int ret; if (!mt_drv_kernel_based(impl, port)) { @@ -637,7 +658,7 @@ struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, return NULL; } - struct mt_rx_socket_entry* entry = + struct mt_rx_socket_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -652,7 +673,7 @@ struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, entry->rate_limit_per_thread = (uint64_t)5 * 1000 * 1000 * 1000; for (int i = 0; i < MT_DP_SOCKET_THREADS_MAX; i++) { - struct mt_rx_socket_thread* t = &entry->threads_data[i]; + struct mt_rx_socket_thread *t = &entry->threads_data[i]; t->idx = i; t->parent = entry; } @@ -670,10 +691,12 @@ struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, /* Create mempool to hold the rx queue mbufs. */ unsigned int mbuf_elements = mt_if_nb_rx_desc(impl, port) + 1024; char pool_name[ST_MAX_NAME_LEN]; - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dF%d_MBUF", MT_RX_DP_SOCKET_PREFIX, port, fd); + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dF%d_MBUF", MT_RX_DP_SOCKET_PREFIX, + port, fd); /* no priv */ - entry->pool = mt_mempool_create(impl, port, pool_name, mbuf_elements, - MT_MBUF_CACHE_SIZE, 0, entry->pool_element_sz); + entry->pool = + mt_mempool_create(impl, port, pool_name, mbuf_elements, + MT_MBUF_CACHE_SIZE, 0, entry->pool_element_sz); if (!entry->pool) { err("%s(%d), mempool %s create fail\n", __func__, port, pool_name); mt_rx_socket_put(entry); @@ -683,8 +706,8 @@ struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, if (entry->threads > 1) { ret = rx_socket_init_threads(entry); if (ret < 0) { - err("%s(%d,%d), init %d threads fail %d\n", __func__, port, fd, entry->threads, - ret); + err("%s(%d,%d), init %d threads fail %d\n", __func__, port, fd, + entry->threads, ret); mt_rx_socket_put(entry); return NULL; } @@ -698,16 +721,16 @@ struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, } entry->stat_registered = true; - uint8_t* ip = flow->dip_addr; - info("%s(%d), fd %d ip %u.%u.%u.%u port %u threads %d\n", __func__, port, fd, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, entry->threads); + uint8_t *ip = flow->dip_addr; + info("%s(%d), fd %d ip %u.%u.%u.%u port %u threads %d\n", __func__, port, fd, + ip[0], ip[1], ip[2], ip[3], flow->dst_port, entry->threads); return entry; } -int mt_rx_socket_put(struct mt_rx_socket_entry* entry) { +int mt_rx_socket_put(struct mt_rx_socket_entry *entry) { int fd = entry->fd; enum mtl_port port = entry->port; - struct mt_rx_socket_thread* t; + struct mt_rx_socket_thread *t; if (entry->stat_registered) { rx_socket_stat_dump(entry); @@ -750,18 +773,20 @@ int mt_rx_socket_put(struct mt_rx_socket_entry* entry) { return 0; } -uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry* entry, struct rte_mbuf** rx_pkts, - const uint16_t nb_pkts) { +uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { uint16_t rx = 0; - struct mt_rx_socket_thread* t = &entry->threads_data[0]; + struct mt_rx_socket_thread *t = &entry->threads_data[0]; if (entry->ring) { - return rte_ring_sc_dequeue_burst(entry->ring, (void**)rx_pkts, nb_pkts, NULL); + return rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, + NULL); } for (rx = 0; rx < nb_pkts; rx++) { - struct rte_mbuf* pkt = rx_socket_recv_mbuf(t); - if (!pkt) break; + struct rte_mbuf *pkt = rx_socket_recv_mbuf(t); + if (!pkt) + break; rx_pkts[rx] = pkt; } @@ -769,44 +794,44 @@ uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry* entry, struct rte_mbuf** } #else -struct mt_tx_socket_entry* mt_tx_socket_get(struct mtl_main_impl* impl, +struct mt_tx_socket_entry *mt_tx_socket_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_txq_flow* flow) { + struct mt_txq_flow *flow) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(flow); err("%s(%d), not support on this platform\n", __func__, port); return NULL; } -int mt_tx_socket_put(struct mt_tx_socket_entry* entry) { +int mt_tx_socket_put(struct mt_tx_socket_entry *entry) { err("%s(%d), not support on this platform\n", __func__, entry->port); return 0; } -uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); err("%s(%d), not support on this platform\n", __func__, entry->port); rte_pktmbuf_free_bulk(tx_pkts, nb_pkts); return 0; } -struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, +struct mt_rx_socket_entry *mt_rx_socket_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_rxq_flow* flow) { + struct mt_rxq_flow *flow) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(flow); err("%s(%d), not support on this platform\n", __func__, port); return NULL; } -int mt_rx_socket_put(struct mt_rx_socket_entry* entry) { +int mt_rx_socket_put(struct mt_rx_socket_entry *entry) { err("%s(%d), not support on this platform\n", __func__, entry->port); return 0; } -uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry* entry, struct rte_mbuf** rx_pkts, - const uint16_t nb_pkts) { +uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(rx_pkts); MTL_MAY_UNUSED(nb_pkts); diff --git a/lib/src/datapath/mt_dp_socket.h b/lib/src/datapath/mt_dp_socket.h index 17491e5e9..495a651f3 100644 --- a/lib/src/datapath/mt_dp_socket.h +++ b/lib/src/datapath/mt_dp_socket.h @@ -7,22 +7,24 @@ #include "../mt_main.h" -struct mt_tx_socket_entry* mt_tx_socket_get(struct mtl_main_impl* impl, - enum mtl_port port, struct mt_txq_flow* flow); -int mt_tx_socket_put(struct mt_tx_socket_entry* entry); -static inline uint16_t mt_tx_socket_queue_id(struct mt_tx_socket_entry* entry) { +struct mt_tx_socket_entry *mt_tx_socket_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow); +int mt_tx_socket_put(struct mt_tx_socket_entry *entry); +static inline uint16_t mt_tx_socket_queue_id(struct mt_tx_socket_entry *entry) { return entry->threads_data[0].fd; } -uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts); +uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -struct mt_rx_socket_entry* mt_rx_socket_get(struct mtl_main_impl* impl, - enum mtl_port port, struct mt_rxq_flow* flow); -int mt_rx_socket_put(struct mt_rx_socket_entry* entry); -static inline uint16_t mt_rx_socket_queue_id(struct mt_rx_socket_entry* entry) { +struct mt_rx_socket_entry *mt_rx_socket_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow); +int mt_rx_socket_put(struct mt_rx_socket_entry *entry); +static inline uint16_t mt_rx_socket_queue_id(struct mt_rx_socket_entry *entry) { return entry->fd; } -uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry* entry, struct rte_mbuf** rx_pkts, - const uint16_t nb_pkts); +uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); #endif diff --git a/lib/src/datapath/mt_queue.c b/lib/src/datapath/mt_queue.c index 7cdf61bff..9e9d35a3a 100644 --- a/lib/src/datapath/mt_queue.c +++ b/lib/src/datapath/mt_queue.c @@ -13,44 +13,51 @@ #include "mt_shared_queue.h" #include "mt_shared_rss.h" -static uint16_t rx_socket_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t rx_socket_burst(struct mt_rxq_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rx_socket_burst(entry->rx_socket_q, rx_pkts, nb_pkts); } -static uint16_t rx_xdp_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t rx_xdp_burst(struct mt_rxq_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rx_xdp_burst(entry->rx_xdp_q, rx_pkts, nb_pkts); } -static uint16_t rx_rdma_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t rx_rdma_burst(struct mt_rxq_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rx_rdma_burst(entry->rx_rdma_q, rx_pkts, nb_pkts); } -static uint16_t rx_srss_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t rx_srss_burst(struct mt_rxq_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_srss_burst(entry->srss, rx_pkts, nb_pkts); } -static uint16_t rx_rsq_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t rx_rsq_burst(struct mt_rxq_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rsq_burst(entry->rsq, rx_pkts, nb_pkts); } -static uint16_t rx_csq_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t rx_csq_burst(struct mt_rxq_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_csq_burst(entry->csq, rx_pkts, nb_pkts); } -static uint16_t rx_dpdk_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t rx_dpdk_burst(struct mt_rxq_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_dpdk_rx_burst(entry->rxq, rx_pkts, nb_pkts); } -struct mt_rxq_entry* mt_rxq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow) { - struct mt_rxq_entry* entry = +struct mt_rxq_entry *mt_rxq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow) { + struct mt_rxq_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -59,39 +66,47 @@ struct mt_rxq_entry* mt_rxq_get(struct mtl_main_impl* impl, enum mtl_port port, entry->parent = impl; dbg("%s(%d), flags 0x%x\n", __func__, port, flow->flags); - if (mt_pmd_is_kernel_socket(impl, port) || (flow->flags & MT_RXQ_FLOW_F_FORCE_SOCKET)) { + if (mt_pmd_is_kernel_socket(impl, port) || + (flow->flags & MT_RXQ_FLOW_F_FORCE_SOCKET)) { entry->rx_socket_q = mt_rx_socket_get(impl, port, flow); - if (!entry->rx_socket_q) goto fail; + if (!entry->rx_socket_q) + goto fail; entry->queue_id = mt_rx_socket_queue_id(entry->rx_socket_q); entry->burst = rx_socket_burst; } else if (mt_has_srss(impl, port)) { entry->srss = mt_srss_get(impl, port, flow); - if (!entry->srss) goto fail; + if (!entry->srss) + goto fail; entry->queue_id = mt_srss_queue_id(entry->srss); entry->burst = rx_srss_burst; } else if (mt_user_shared_rxq(impl, port)) { entry->rsq = mt_rsq_get(impl, port, flow); - if (!entry->rsq) goto fail; + if (!entry->rsq) + goto fail; entry->queue_id = mt_rsq_queue_id(entry->rsq); entry->burst = rx_rsq_burst; } else if (mt_pmd_is_native_af_xdp(impl, port)) { entry->rx_xdp_q = mt_rx_xdp_get(impl, port, flow, NULL); - if (!entry->rx_xdp_q) goto fail; + if (!entry->rx_xdp_q) + goto fail; entry->queue_id = mt_rx_xdp_queue_id(entry->rx_xdp_q); entry->burst = rx_xdp_burst; } else if (mt_pmd_is_rdma_ud(impl, port)) { entry->rx_rdma_q = mt_rx_rdma_get(impl, port, flow, NULL); - if (!entry->rx_rdma_q) goto fail; + if (!entry->rx_rdma_q) + goto fail; entry->queue_id = mt_rx_rdma_queue_id(entry->rx_rdma_q); entry->burst = rx_rdma_burst; } else if (flow->flags & MT_RXQ_FLOW_F_FORCE_CNI) { entry->csq = mt_csq_get(impl, port, flow); - if (!entry->csq) goto fail; + if (!entry->csq) + goto fail; entry->queue_id = mt_csq_queue_id(entry->csq); entry->burst = rx_csq_burst; } else { entry->rxq = mt_dev_get_rx_queue(impl, port, flow); - if (!entry->rxq) goto fail; + if (!entry->rxq) + goto fail; entry->queue_id = mt_dev_rx_queue_id(entry->rxq); entry->burst = rx_dpdk_burst; } @@ -103,7 +118,7 @@ struct mt_rxq_entry* mt_rxq_get(struct mtl_main_impl* impl, enum mtl_port port, return NULL; } -int mt_rxq_put(struct mt_rxq_entry* entry) { +int mt_rxq_put(struct mt_rxq_entry *entry) { if (entry->rxq) { mt_dev_put_rx_queue(entry->parent, entry->rxq); entry->rxq = NULL; @@ -136,39 +151,39 @@ int mt_rxq_put(struct mt_rxq_entry* entry) { return 0; } -uint16_t mt_rxq_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +uint16_t mt_rxq_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return entry->burst(entry, rx_pkts, nb_pkts); } -static uint16_t tx_socket_burst(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +static uint16_t tx_socket_burst(struct mt_txq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return mt_tx_socket_burst(entry->tx_socket_q, tx_pkts, nb_pkts); } -static uint16_t tx_xdp_burst(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +static uint16_t tx_xdp_burst(struct mt_txq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return mt_tx_xdp_burst(entry->tx_xdp_q, tx_pkts, nb_pkts); } -static uint16_t tx_rdma_burst(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +static uint16_t tx_rdma_burst(struct mt_txq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return mt_tx_rdma_burst(entry->tx_rdma_q, tx_pkts, nb_pkts); } -static uint16_t tx_tsq_burst(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +static uint16_t tx_tsq_burst(struct mt_txq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return mt_tsq_burst(entry->tsq, tx_pkts, nb_pkts); } -static uint16_t tx_dpdk_burst(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +static uint16_t tx_dpdk_burst(struct mt_txq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return mt_dpdk_tx_burst(entry->txq, tx_pkts, nb_pkts); } -struct mt_txq_entry* mt_txq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow) { - struct mt_txq_entry* entry = +struct mt_txq_entry *mt_txq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_txq_flow *flow) { + struct mt_txq_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -177,29 +192,35 @@ struct mt_txq_entry* mt_txq_get(struct mtl_main_impl* impl, enum mtl_port port, entry->parent = impl; dbg("%s(%d), flags 0x%x\n", __func__, port, flow->flags); - if (mt_pmd_is_kernel_socket(impl, port) || (flow->flags & MT_TXQ_FLOW_F_FORCE_SOCKET)) { + if (mt_pmd_is_kernel_socket(impl, port) || + (flow->flags & MT_TXQ_FLOW_F_FORCE_SOCKET)) { entry->tx_socket_q = mt_tx_socket_get(impl, port, flow); - if (!entry->tx_socket_q) goto fail; + if (!entry->tx_socket_q) + goto fail; entry->queue_id = mt_tx_socket_queue_id(entry->tx_socket_q); entry->burst = tx_socket_burst; } else if (mt_user_shared_txq(impl, port)) { entry->tsq = mt_tsq_get(impl, port, flow); - if (!entry->tsq) goto fail; + if (!entry->tsq) + goto fail; entry->queue_id = mt_tsq_queue_id(entry->tsq); entry->burst = tx_tsq_burst; } else if (mt_pmd_is_native_af_xdp(impl, port)) { entry->tx_xdp_q = mt_tx_xdp_get(impl, port, flow, NULL); - if (!entry->tx_xdp_q) goto fail; + if (!entry->tx_xdp_q) + goto fail; entry->queue_id = mt_tx_xdp_queue_id(entry->tx_xdp_q); entry->burst = tx_xdp_burst; } else if (mt_pmd_is_rdma_ud(impl, port)) { entry->tx_rdma_q = mt_tx_rdma_get(impl, port, flow, NULL); - if (!entry->tx_rdma_q) goto fail; + if (!entry->tx_rdma_q) + goto fail; entry->queue_id = mt_tx_rdma_queue_id(entry->tx_rdma_q); entry->burst = tx_rdma_burst; } else { entry->txq = mt_dev_get_tx_queue(impl, port, flow); - if (!entry->txq) goto fail; + if (!entry->txq) + goto fail; entry->queue_id = mt_dev_tx_queue_id(entry->txq); entry->burst = tx_dpdk_burst; } @@ -211,7 +232,7 @@ struct mt_txq_entry* mt_txq_get(struct mtl_main_impl* impl, enum mtl_port port, return NULL; } -int mt_txq_put(struct mt_txq_entry* entry) { +int mt_txq_put(struct mt_txq_entry *entry) { if (entry->txq) { mt_dev_put_tx_queue(entry->parent, entry->txq); entry->txq = NULL; @@ -236,19 +257,23 @@ int mt_txq_put(struct mt_txq_entry* entry) { return 0; } -int mt_txq_fatal_error(struct mt_txq_entry* entry) { - if (entry->txq) mt_dev_tx_queue_fatal_error(entry->parent, entry->txq); - if (entry->tsq) mt_tsq_fatal_error(entry->tsq); +int mt_txq_fatal_error(struct mt_txq_entry *entry) { + if (entry->txq) + mt_dev_tx_queue_fatal_error(entry->parent, entry->txq); + if (entry->tsq) + mt_tsq_fatal_error(entry->tsq); return 0; } -int mt_txq_done_cleanup(struct mt_txq_entry* entry) { - if (entry->txq) mt_dev_tx_done_cleanup(entry->parent, entry->txq); - if (entry->tsq) mt_tsq_done_cleanup(entry->tsq); +int mt_txq_done_cleanup(struct mt_txq_entry *entry) { + if (entry->txq) + mt_dev_tx_done_cleanup(entry->parent, entry->txq); + if (entry->tsq) + mt_tsq_done_cleanup(entry->tsq); return 0; } -int mt_txq_set_tx_bps(struct mt_txq_entry* entry, uint64_t bytes_per_sec) { +int mt_txq_set_tx_bps(struct mt_txq_entry *entry, uint64_t bytes_per_sec) { if (!entry->txq) { err("%s(%u), not txq\n", __func__, entry->queue_id); return -ENOTSUP; @@ -257,7 +282,7 @@ int mt_txq_set_tx_bps(struct mt_txq_entry* entry, uint64_t bytes_per_sec) { return mt_dev_set_tx_bps(entry->parent, entry->txq, bytes_per_sec); } -int mt_txq_flush(struct mt_txq_entry* entry, struct rte_mbuf* pad) { +int mt_txq_flush(struct mt_txq_entry *entry, struct rte_mbuf *pad) { if (entry->tsq) return mt_tsq_flush(entry->parent, entry->tsq, pad); else if (entry->txq) @@ -266,15 +291,16 @@ int mt_txq_flush(struct mt_txq_entry* entry, struct rte_mbuf* pad) { return 0; } -uint16_t mt_txq_burst(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, +uint16_t mt_txq_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return entry->burst(entry, tx_pkts, nb_pkts); } -uint16_t mt_txq_burst_busy(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts, int timeout_ms) { +uint16_t mt_txq_burst_busy(struct mt_txq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, + int timeout_ms) { uint16_t sent = 0; - struct mtl_main_impl* impl = entry->parent; + struct mtl_main_impl *impl = entry->parent; uint64_t start_ts = mt_get_tsc(impl); /* Send this vector with busy looping */ @@ -282,7 +308,8 @@ uint16_t mt_txq_burst_busy(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts if (timeout_ms > 0) { int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (ms > timeout_ms) { - warn("%s(%u), fail as timeout to %d ms\n", __func__, entry->queue_id, timeout_ms); + warn("%s(%u), fail as timeout to %d ms\n", __func__, entry->queue_id, + timeout_ms); return sent; } } @@ -292,9 +319,9 @@ uint16_t mt_txq_burst_busy(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts return sent; } -int mt_dp_queue_init(struct mtl_main_impl* impl) { +int mt_dp_queue_init(struct mtl_main_impl *impl) { int ret; - struct mt_dp_impl* dp; + struct mt_dp_impl *dp; int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { @@ -330,7 +357,8 @@ int mt_dp_queue_init(struct mtl_main_impl* impl) { for (int i = 0; i < num_ports; i++) { dp = impl->dp[i]; /* no sys tx queue */ - if (mt_drv_no_sys_txq(impl, i)) continue; + if (mt_drv_no_sys_txq(impl, i)) + continue; struct mt_txq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -349,12 +377,13 @@ int mt_dp_queue_init(struct mtl_main_impl* impl) { return 0; } -int mt_dp_queue_uinit(struct mtl_main_impl* impl) { +int mt_dp_queue_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { - struct mt_dp_impl* dp = impl->dp[i]; - if (!dp) continue; + struct mt_dp_impl *dp = impl->dp[i]; + if (!dp) + continue; if (dp->txq_sys_entry) { mt_txq_flush(dp->txq_sys_entry, mt_get_pad(impl, i)); @@ -370,8 +399,9 @@ int mt_dp_queue_uinit(struct mtl_main_impl* impl) { mt_tsq_uinit(impl); for (int i = 0; i < num_ports; i++) { - struct mt_dp_impl* dp = impl->dp[i]; - if (!dp) continue; + struct mt_dp_impl *dp = impl->dp[i]; + if (!dp) + continue; mt_rte_free(dp); impl->dp[i] = NULL; @@ -380,9 +410,9 @@ int mt_dp_queue_uinit(struct mtl_main_impl* impl) { return 0; } -uint16_t mt_sys_queue_tx_burst(struct mtl_main_impl* impl, enum mtl_port port, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { - struct mt_dp_impl* dp = impl->dp[port]; +uint16_t mt_sys_queue_tx_burst(struct mtl_main_impl *impl, enum mtl_port port, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { + struct mt_dp_impl *dp = impl->dp[port]; if (!dp->txq_sys_entry) { err("%s(%d), txq sys queue not active\n", __func__, port); diff --git a/lib/src/datapath/mt_queue.h b/lib/src/datapath/mt_queue.h index 8869ef85e..d468ca34d 100644 --- a/lib/src/datapath/mt_queue.h +++ b/lib/src/datapath/mt_queue.h @@ -7,68 +7,69 @@ #ifndef _MT_LIB_DP_QUEUE_HEAD_H_ #define _MT_LIB_DP_QUEUE_HEAD_H_ -int mt_dp_queue_init(struct mtl_main_impl* impl); -int mt_dp_queue_uinit(struct mtl_main_impl* impl); +int mt_dp_queue_init(struct mtl_main_impl *impl); +int mt_dp_queue_uinit(struct mtl_main_impl *impl); struct mt_rxq_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; uint16_t queue_id; - struct mt_rx_queue* rxq; - struct mt_rsq_entry* rsq; - struct mt_srss_entry* srss; - struct mt_csq_entry* csq; - struct mt_rx_socket_entry* rx_socket_q; - struct mt_rx_xdp_entry* rx_xdp_q; - struct mt_rx_rdma_entry* rx_rdma_q; + struct mt_rx_queue *rxq; + struct mt_rsq_entry *rsq; + struct mt_srss_entry *srss; + struct mt_csq_entry *csq; + struct mt_rx_socket_entry *rx_socket_q; + struct mt_rx_xdp_entry *rx_xdp_q; + struct mt_rx_rdma_entry *rx_rdma_q; - uint16_t (*burst)(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, + uint16_t (*burst)(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); }; -struct mt_rxq_entry* mt_rxq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow); -static inline uint16_t mt_rxq_queue_id(struct mt_rxq_entry* entry) { +struct mt_rxq_entry *mt_rxq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow); +static inline uint16_t mt_rxq_queue_id(struct mt_rxq_entry *entry) { return entry->queue_id; } -uint16_t mt_rxq_burst(struct mt_rxq_entry* entry, struct rte_mbuf** rx_pkts, +uint16_t mt_rxq_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); -int mt_rxq_put(struct mt_rxq_entry* entry); +int mt_rxq_put(struct mt_rxq_entry *entry); struct mt_txq_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; uint16_t queue_id; - struct mt_tx_queue* txq; - struct mt_tsq_entry* tsq; - struct mt_tx_socket_entry* tx_socket_q; - struct mt_tx_xdp_entry* tx_xdp_q; - struct mt_tx_rdma_entry* tx_rdma_q; // TODO: remove this when rdma is ready + struct mt_tx_queue *txq; + struct mt_tsq_entry *tsq; + struct mt_tx_socket_entry *tx_socket_q; + struct mt_tx_xdp_entry *tx_xdp_q; + struct mt_tx_rdma_entry *tx_rdma_q; // TODO: remove this when rdma is ready - uint16_t (*burst)(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, + uint16_t (*burst)(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); }; -struct mt_txq_entry* mt_txq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow); -static inline uint16_t mt_txq_queue_id(struct mt_txq_entry* entry) { +struct mt_txq_entry *mt_txq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_txq_flow *flow); +static inline uint16_t mt_txq_queue_id(struct mt_txq_entry *entry) { return entry->queue_id; } -static inline struct rte_mempool* mt_txq_mempool(struct mt_txq_entry* entry) { +static inline struct rte_mempool *mt_txq_mempool(struct mt_txq_entry *entry) { if (entry->tsq) return entry->tsq->tx_pool; else return NULL; /* only for shared queue */ } -uint16_t mt_txq_burst(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, +uint16_t mt_txq_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -uint16_t mt_txq_burst_busy(struct mt_txq_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts, int timeout_ms); -int mt_txq_flush(struct mt_txq_entry* entry, struct rte_mbuf* pad); -int mt_txq_put(struct mt_txq_entry* entry); -int mt_txq_fatal_error(struct mt_txq_entry* entry); -int mt_txq_done_cleanup(struct mt_txq_entry* entry); -int mt_txq_set_tx_bps(struct mt_txq_entry* entry, uint64_t bytes_per_sec); +uint16_t mt_txq_burst_busy(struct mt_txq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, + int timeout_ms); +int mt_txq_flush(struct mt_txq_entry *entry, struct rte_mbuf *pad); +int mt_txq_put(struct mt_txq_entry *entry); +int mt_txq_fatal_error(struct mt_txq_entry *entry); +int mt_txq_done_cleanup(struct mt_txq_entry *entry); +int mt_txq_set_tx_bps(struct mt_txq_entry *entry, uint64_t bytes_per_sec); -uint16_t mt_sys_queue_tx_burst(struct mtl_main_impl* impl, enum mtl_port port, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts); +uint16_t mt_sys_queue_tx_burst(struct mtl_main_impl *impl, enum mtl_port port, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts); #endif diff --git a/lib/src/datapath/mt_shared_queue.c b/lib/src/datapath/mt_shared_queue.c index 30e25bcc4..41e45b5e0 100644 --- a/lib/src/datapath/mt_shared_queue.c +++ b/lib/src/datapath/mt_shared_queue.c @@ -15,38 +15,40 @@ #define MT_SQ_RING_PREFIX "SQ_" #define MT_SQ_BURST_SIZE (128) -static inline struct mt_rsq_impl* rsq_ctx_get(struct mtl_main_impl* impl, +static inline struct mt_rsq_impl *rsq_ctx_get(struct mtl_main_impl *impl, enum mtl_port port) { return impl->rsq[port]; } -static inline void rsq_lock(struct mt_rsq_queue* s) { +static inline void rsq_lock(struct mt_rsq_queue *s) { rte_spinlock_lock(&s->mutex); } /* return true if try lock succ */ -static inline bool rsq_try_lock(struct mt_rsq_queue* s) { +static inline bool rsq_try_lock(struct mt_rsq_queue *s) { int ret = rte_spinlock_trylock(&s->mutex); return ret ? true : false; } -static inline void rsq_unlock(struct mt_rsq_queue* s) { +static inline void rsq_unlock(struct mt_rsq_queue *s) { rte_spinlock_unlock(&s->mutex); } -static int rsq_stat_dump(void* priv) { - struct mt_rsq_impl* rsq = priv; +static int rsq_stat_dump(void *priv) { + struct mt_rsq_impl *rsq = priv; enum mtl_port port = rsq->port; - struct mt_rsq_queue* s; - struct mt_rsq_entry* entry; + struct mt_rsq_queue *s; + struct mt_rsq_entry *entry; int idx; for (uint16_t q = 0; q < rsq->nb_rsq_queues; q++) { s = &rsq->rsq_queues[q]; - if (!rsq_try_lock(s)) continue; + if (!rsq_try_lock(s)) + continue; if (s->stat_pkts_recv) { - notice("%s(%d,%u), entries %d, pkt recv %d deliver %d\n", __func__, port, q, - rte_atomic32_read(&s->entry_cnt), s->stat_pkts_recv, s->stat_pkts_deliver); + notice("%s(%d,%u), entries %d, pkt recv %d deliver %d\n", __func__, port, + q, rte_atomic32_read(&s->entry_cnt), s->stat_pkts_recv, + s->stat_pkts_deliver); s->stat_pkts_recv = 0; s->stat_pkts_deliver = 0; @@ -69,8 +71,8 @@ static int rsq_stat_dump(void* priv) { return 0; } -static int rsq_entry_free(struct mt_rsq_entry* entry) { - struct mt_rsq_impl* rsqm = entry->parent; +static int rsq_entry_free(struct mt_rsq_entry *entry) { + struct mt_rsq_impl *rsqm = entry->parent; if (entry->flow_rsp) { mt_rx_flow_free(rsqm->parent, rsqm->port, entry->flow_rsp); @@ -90,9 +92,9 @@ static int rsq_entry_free(struct mt_rsq_entry* entry) { return 0; } -static int rsq_uinit(struct mt_rsq_impl* rsq) { - struct mt_rsq_queue* rsq_queue; - struct mt_rsq_entry* entry; +static int rsq_uinit(struct mt_rsq_impl *rsq) { + struct mt_rsq_queue *rsq_queue; + struct mt_rsq_entry *entry; if (rsq->rsq_queues) { for (uint16_t q = 0; q < rsq->nb_rsq_queues; q++) { @@ -119,13 +121,13 @@ static int rsq_uinit(struct mt_rsq_impl* rsq) { return 0; } -static int rsq_init(struct mtl_main_impl* impl, struct mt_rsq_impl* rsq) { +static int rsq_init(struct mtl_main_impl *impl, struct mt_rsq_impl *rsq) { enum mtl_port port = rsq->port; int soc_id = mt_socket_id(impl, port); - struct mt_rsq_queue* rsq_queue; + struct mt_rsq_queue *rsq_queue; - rsq->rsq_queues = - mt_rte_zmalloc_socket(sizeof(*rsq->rsq_queues) * rsq->nb_rsq_queues, soc_id); + rsq->rsq_queues = mt_rte_zmalloc_socket( + sizeof(*rsq->rsq_queues) * rsq->nb_rsq_queues, soc_id); if (!rsq->rsq_queues) { err("%s(%d), rsq_queues alloc fail\n", __func__, port); return -ENOMEM; @@ -149,35 +151,36 @@ static int rsq_init(struct mtl_main_impl* impl, struct mt_rsq_impl* rsq) { return 0; } -static uint32_t rsq_flow_hash(struct mt_rxq_flow* flow) { +static uint32_t rsq_flow_hash(struct mt_rxq_flow *flow) { struct rte_ipv4_tuple tuple; uint32_t len; - if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) return 0; + if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) + return 0; len = RTE_THASH_V4_L4_LEN; - tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], - flow->dip_addr[3]); - tuple.dst_addr = RTE_IPV4(flow->sip_addr[0], flow->sip_addr[1], flow->sip_addr[2], - flow->sip_addr[3]); + tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], + flow->dip_addr[2], flow->dip_addr[3]); + tuple.dst_addr = RTE_IPV4(flow->sip_addr[0], flow->sip_addr[1], + flow->sip_addr[2], flow->sip_addr[3]); tuple.dport = flow->dst_port; tuple.sport = tuple.dport; - return mt_softrss((uint32_t*)&tuple, len); + return mt_softrss((uint32_t *)&tuple, len); } -struct mt_rsq_entry* mt_rsq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow) { +struct mt_rsq_entry *mt_rsq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow) { if (!mt_user_shared_rxq(impl, port)) { err("%s(%d), shared queue not enabled\n", __func__, port); return NULL; } - struct mt_rsq_impl* rsqm = rsq_ctx_get(impl, port); + struct mt_rsq_impl *rsqm = rsq_ctx_get(impl, port); uint32_t hash = rsq_flow_hash(flow); uint16_t q = (hash % RTE_ETH_RETA_GROUP_SIZE) % rsqm->nb_rsq_queues; - struct mt_rsq_queue* rsq_queue = &rsqm->rsq_queues[q]; + struct mt_rsq_queue *rsq_queue = &rsqm->rsq_queues[q]; int idx = rsq_queue->entry_idx; - struct mt_rsq_entry* entry = + struct mt_rsq_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%u), entry malloc fail\n", __func__, q); @@ -230,7 +233,8 @@ struct mt_rsq_entry* mt_rsq_get(struct mtl_main_impl* impl, enum mtl_port port, return NULL; } - if (mt_pmd_is_dpdk_af_packet(impl, port) && mt_is_multicast_ip(flow->dip_addr)) { + if (mt_pmd_is_dpdk_af_packet(impl, port) && + mt_is_multicast_ip(flow->dip_addr)) { /* join multicast group, will drop automatically when socket fd closed */ entry->mcast_fd = mt_socket_get_multicast_fd(impl, port, flow); if (entry->mcast_fd < 0) { @@ -245,18 +249,19 @@ struct mt_rsq_entry* mt_rsq_get(struct mtl_main_impl* impl, enum mtl_port port, MT_TAILQ_INSERT_HEAD(&rsq_queue->head, entry, next); rte_atomic32_inc(&rsq_queue->entry_cnt); rsq_queue->entry_idx++; - if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) rsq_queue->cni_entry = entry; + if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) + rsq_queue->cni_entry = entry; rsq_unlock(rsq_queue); - uint8_t* ip = flow->dip_addr; - info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u, on %d\n", __func__, port, q, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, hash, idx); + uint8_t *ip = flow->dip_addr; + info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u, on %d\n", __func__, port, + q, ip[0], ip[1], ip[2], ip[3], flow->dst_port, hash, idx); return entry; } -int mt_rsq_put(struct mt_rsq_entry* entry) { - struct mt_rsq_impl* rsqm = entry->parent; - struct mt_rsq_queue* rsq_queue = &rsqm->rsq_queues[entry->queue_id]; +int mt_rsq_put(struct mt_rsq_entry *entry) { + struct mt_rsq_impl *rsqm = entry->parent; + struct mt_rsq_queue *rsq_queue = &rsqm->rsq_queues[entry->queue_id]; rsq_lock(rsq_queue); MT_TAILQ_REMOVE(&rsq_queue->head, entry, next); @@ -267,11 +272,12 @@ int mt_rsq_put(struct mt_rsq_entry* entry) { return 0; } -static inline void rsq_entry_pkts_enqueue(struct mt_rsq_entry* entry, - struct rte_mbuf** pkts, +static inline void rsq_entry_pkts_enqueue(struct mt_rsq_entry *entry, + struct rte_mbuf **pkts, const uint16_t nb_pkts) { /* use bulk version */ - unsigned int n = rte_ring_sp_enqueue_bulk(entry->ring, (void**)pkts, nb_pkts, NULL); + unsigned int n = + rte_ring_sp_enqueue_bulk(entry->ring, (void **)pkts, nb_pkts, NULL); entry->stat_enqueue_cnt += n; if (n == 0) { rte_pktmbuf_free_bulk(pkts, nb_pkts); @@ -279,49 +285,53 @@ static inline void rsq_entry_pkts_enqueue(struct mt_rsq_entry* entry, } } -#define UPDATE_ENTRY() \ - do { \ - if (matched_pkts_nb) \ - rsq_entry_pkts_enqueue(last_rsq_entry, &matched_pkts[0], matched_pkts_nb); \ - last_rsq_entry = rsq_entry; \ - matched_pkts_nb = 0; \ +#define UPDATE_ENTRY() \ + do { \ + if (matched_pkts_nb) \ + rsq_entry_pkts_enqueue(last_rsq_entry, &matched_pkts[0], \ + matched_pkts_nb); \ + last_rsq_entry = rsq_entry; \ + matched_pkts_nb = 0; \ } while (0) -static int rsq_rx(struct mt_rsq_queue* rsq_queue) { +static int rsq_rx(struct mt_rsq_queue *rsq_queue) { uint16_t q = rsq_queue->queue_id; - struct rte_mbuf* pkts[MT_SQ_BURST_SIZE]; - struct rte_mbuf* matched_pkts[MT_SQ_BURST_SIZE]; + struct rte_mbuf *pkts[MT_SQ_BURST_SIZE]; + struct rte_mbuf *matched_pkts[MT_SQ_BURST_SIZE]; uint16_t rx; - struct mt_rsq_entry* rsq_entry = NULL; - struct mt_rsq_entry* last_rsq_entry = NULL; + struct mt_rsq_entry *rsq_entry = NULL; + struct mt_rsq_entry *last_rsq_entry = NULL; uint16_t matched_pkts_nb = 0; - struct mt_udp_hdr* hdr; + struct mt_udp_hdr *hdr; if (rsq_queue->xdp) rx = mt_rx_xdp_burst(rsq_queue->xdp, pkts, MT_SQ_BURST_SIZE); else rx = rte_eth_rx_burst(rsq_queue->port_id, q, pkts, MT_SQ_BURST_SIZE); - if (rx) dbg("%s(%u), rx pkts %u\n", __func__, q, rx); + if (rx) + dbg("%s(%u), rx pkts %u\n", __func__, q, rx); rsq_queue->stat_pkts_recv += rx; for (uint16_t i = 0; i < rx; i++) { rsq_entry = NULL; - hdr = rte_pktmbuf_mtod(pkts[i], struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkts[i], struct mt_udp_hdr *); dbg("%s(%u), pkt %u ip %u.%u.%u.%u, port dst %u src %u\n", __func__, q, i, ntohs(hdr->udp.dst_port), ntohs(hdr->udp.src_port)); MT_TAILQ_FOREACH(rsq_entry, &rsq_queue->head, next) { bool matched = mt_udp_matched(&rsq_entry->flow, hdr); if (matched) { - if (rsq_entry != last_rsq_entry) UPDATE_ENTRY(); + if (rsq_entry != last_rsq_entry) + UPDATE_ENTRY(); matched_pkts[matched_pkts_nb++] = pkts[i]; break; } } if (!rsq_entry) { /* no match, redirect to cni */ UPDATE_ENTRY(); - if (rsq_queue->cni_entry) rsq_entry_pkts_enqueue(rsq_queue->cni_entry, &pkts[i], 1); + if (rsq_queue->cni_entry) + rsq_entry_pkts_enqueue(rsq_queue->cni_entry, &pkts[i], 1); } } if (matched_pkts_nb) @@ -330,28 +340,32 @@ static int rsq_rx(struct mt_rsq_queue* rsq_queue) { return rx; } -uint16_t mt_rsq_burst(struct mt_rsq_entry* entry, struct rte_mbuf** rx_pkts, +uint16_t mt_rsq_burst(struct mt_rsq_entry *entry, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) { - struct mt_rsq_impl* rsqm = entry->parent; + struct mt_rsq_impl *rsqm = entry->parent; uint16_t q = entry->queue_id; - struct mt_rsq_queue* rsq_queue = &rsqm->rsq_queues[q]; + struct mt_rsq_queue *rsq_queue = &rsqm->rsq_queues[q]; - if (!rsq_try_lock(rsq_queue)) return 0; + if (!rsq_try_lock(rsq_queue)) + return 0; rsq_rx(rsq_queue); rsq_unlock(rsq_queue); - uint16_t n = rte_ring_sc_dequeue_burst(entry->ring, (void**)rx_pkts, nb_pkts, NULL); + uint16_t n = + rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); entry->stat_dequeue_cnt += n; return n; } -int mt_rsq_init(struct mtl_main_impl* impl) { +int mt_rsq_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); int ret; for (int i = 0; i < num_ports; i++) { - if (!mt_user_shared_rxq(impl, i)) continue; - impl->rsq[i] = mt_rte_zmalloc_socket(sizeof(*impl->rsq[i]), mt_socket_id(impl, i)); + if (!mt_user_shared_rxq(impl, i)) + continue; + impl->rsq[i] = + mt_rte_zmalloc_socket(sizeof(*impl->rsq[i]), mt_socket_id(impl, i)); if (!impl->rsq[i]) { err("%s(%d), rsq malloc fail\n", __func__, i); mt_rsq_uinit(impl); @@ -360,8 +374,9 @@ int mt_rsq_init(struct mtl_main_impl* impl) { impl->rsq[i]->parent = impl; impl->rsq[i]->port = i; impl->rsq[i]->nb_rsq_queues = mt_if(impl, i)->nb_rx_q; - impl->rsq[i]->queue_mode = - mt_pmd_is_native_af_xdp(impl, i) ? MT_QUEUE_MODE_XDP : MT_QUEUE_MODE_DPDK; + impl->rsq[i]->queue_mode = mt_pmd_is_native_af_xdp(impl, i) + ? MT_QUEUE_MODE_XDP + : MT_QUEUE_MODE_DPDK; ret = rsq_init(impl, impl->rsq[i]); if (ret < 0) { err("%s(%d), rsq init fail\n", __func__, i); @@ -374,7 +389,7 @@ int mt_rsq_init(struct mtl_main_impl* impl) { return 0; } -int mt_rsq_uinit(struct mtl_main_impl* impl) { +int mt_rsq_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < MTL_PORT_MAX; i++) { if (impl->rsq[i]) { rsq_uinit(impl->rsq[i]); @@ -386,32 +401,33 @@ int mt_rsq_uinit(struct mtl_main_impl* impl) { return 0; } -static inline struct mt_tsq_impl* tsq_ctx_get(struct mtl_main_impl* impl, +static inline struct mt_tsq_impl *tsq_ctx_get(struct mtl_main_impl *impl, enum mtl_port port) { return impl->tsq[port]; } -static inline void tsq_lock(struct mt_tsq_queue* s) { +static inline void tsq_lock(struct mt_tsq_queue *s) { mt_pthread_mutex_lock(&s->mutex); } /* return true if try lock succ */ -static inline bool tsq_try_lock(struct mt_tsq_queue* s) { +static inline bool tsq_try_lock(struct mt_tsq_queue *s) { int ret = mt_pthread_mutex_try_lock(&s->mutex); return ret == 0 ? true : false; } -static inline void tsq_unlock(struct mt_tsq_queue* s) { +static inline void tsq_unlock(struct mt_tsq_queue *s) { mt_pthread_mutex_unlock(&s->mutex); } -static int tsq_stat_dump(void* priv) { - struct mt_tsq_impl* tsq = priv; - struct mt_tsq_queue* s; +static int tsq_stat_dump(void *priv) { + struct mt_tsq_impl *tsq = priv; + struct mt_tsq_queue *s; for (uint16_t q = 0; q < tsq->nb_tsq_queues; q++) { s = &tsq->tsq_queues[q]; - if (!tsq_try_lock(s)) continue; + if (!tsq_try_lock(s)) + continue; if (s->stat_pkts_send) { notice("%s(%d,%u), entries %d, pkt send %d\n", __func__, tsq->port, q, rte_atomic32_read(&s->entry_cnt), s->stat_pkts_send); @@ -423,14 +439,14 @@ static int tsq_stat_dump(void* priv) { return 0; } -static int tsq_entry_free(struct mt_tsq_entry* entry) { +static int tsq_entry_free(struct mt_tsq_entry *entry) { mt_rte_free(entry); return 0; } -static int tsq_uinit(struct mt_tsq_impl* tsq) { - struct mt_tsq_queue* tsq_queue; - struct mt_tsq_entry* entry; +static int tsq_uinit(struct mt_tsq_impl *tsq) { + struct mt_tsq_queue *tsq_queue; + struct mt_tsq_entry *entry; if (tsq->tsq_queues) { for (uint16_t q = 0; q < tsq->nb_tsq_queues; q++) { @@ -461,13 +477,13 @@ static int tsq_uinit(struct mt_tsq_impl* tsq) { return 0; } -static int tsq_init(struct mtl_main_impl* impl, struct mt_tsq_impl* tsq) { +static int tsq_init(struct mtl_main_impl *impl, struct mt_tsq_impl *tsq) { enum mtl_port port = tsq->port; int soc_id = mt_socket_id(impl, port); - struct mt_tsq_queue* tsq_queue; + struct mt_tsq_queue *tsq_queue; - tsq->tsq_queues = - mt_rte_zmalloc_socket(sizeof(*tsq->tsq_queues) * tsq->nb_tsq_queues, soc_id); + tsq->tsq_queues = mt_rte_zmalloc_socket( + sizeof(*tsq->tsq_queues) * tsq->nb_tsq_queues, soc_id); if (!tsq->tsq_queues) { err("%s(%d), tsq_queues alloc fail\n", __func__, port); return -ENOMEM; @@ -491,36 +507,37 @@ static int tsq_init(struct mtl_main_impl* impl, struct mt_tsq_impl* tsq) { return 0; } -static uint32_t tsq_flow_hash(struct mt_txq_flow* flow) { +static uint32_t tsq_flow_hash(struct mt_txq_flow *flow) { struct rte_ipv4_tuple tuple; uint32_t len; - if (flow->flags & MT_TXQ_FLOW_F_SYS_QUEUE) return 0; + if (flow->flags & MT_TXQ_FLOW_F_SYS_QUEUE) + return 0; len = RTE_THASH_V4_L4_LEN; - tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], - flow->dip_addr[3]); + tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], + flow->dip_addr[2], flow->dip_addr[3]); tuple.dst_addr = tuple.src_addr; tuple.sport = flow->dst_port; tuple.dport = flow->dst_port; - return mt_softrss((uint32_t*)&tuple, len); + return mt_softrss((uint32_t *)&tuple, len); } -struct mt_tsq_entry* mt_tsq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow) { +struct mt_tsq_entry *mt_tsq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_txq_flow *flow) { if (!mt_user_shared_txq(impl, port)) { err("%s(%d), shared queue not enabled\n", __func__, port); return NULL; } - struct mt_tsq_impl* tsqm = tsq_ctx_get(impl, port); + struct mt_tsq_impl *tsqm = tsq_ctx_get(impl, port); uint32_t hash = tsq_flow_hash(flow); uint16_t q = 0; /* queue zero is reserved for system queue */ if (!(flow->flags & MT_TXQ_FLOW_F_SYS_QUEUE)) { q = (hash % RTE_ETH_RETA_GROUP_SIZE) % (tsqm->nb_tsq_queues - 1) + 1; } - struct mt_tsq_queue* tsq_queue = &tsqm->tsq_queues[q]; + struct mt_tsq_queue *tsq_queue = &tsqm->tsq_queues[q]; if (tsq_queue->fatal_error) { /* try to find one valid queue */ @@ -530,7 +547,8 @@ struct mt_tsq_entry* mt_tsq_get(struct mtl_main_impl* impl, enum mtl_port port, if (tsq_queue->fatal_error) { /* loop to find a valid queue*/ for (q_b = 1; q_b < tsqm->nb_tsq_queues; q_b++) { tsq_queue = &tsqm->tsq_queues[q_b]; - if (!tsq_queue->fatal_error) break; + if (!tsq_queue->fatal_error) + break; } } @@ -539,11 +557,12 @@ struct mt_tsq_entry* mt_tsq_get(struct mtl_main_impl* impl, enum mtl_port port, return NULL; } - warn("%s(%d), q %u is fatal error, use %u instead\n", __func__, port, q, q_b); + warn("%s(%d), q %u is fatal error, use %u instead\n", __func__, port, q, + q_b); q = q_b; tsq_queue = &tsqm->tsq_queues[q]; } - struct mt_tsq_entry* entry = + struct mt_tsq_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d:%u), entry malloc fail\n", __func__, port, q); @@ -557,9 +576,9 @@ struct mt_tsq_entry* mt_tsq_get(struct mtl_main_impl* impl, enum mtl_port port, if (!tsq_queue->tx_pool) { char pool_name[32]; snprintf(pool_name, 32, "TSQ_P%dQ%u", port, q); - struct rte_mempool* pool = - mt_mempool_create(impl, port, pool_name, mt_if_nb_tx_desc(impl, port) + 512, - MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); + struct rte_mempool *pool = mt_mempool_create( + impl, port, pool_name, mt_if_nb_tx_desc(impl, port) + 512, + MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); if (!pool) { err("%s(%d:%u), mempool create fail\n", __func__, port, q); tsq_unlock(tsq_queue); @@ -591,15 +610,15 @@ struct mt_tsq_entry* mt_tsq_get(struct mtl_main_impl* impl, enum mtl_port port, entry->tx_pool = tsq_queue->tx_pool; - uint8_t* ip = flow->dip_addr; - info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u\n", __func__, port, q, ip[0], ip[1], - ip[2], ip[3], flow->dst_port, hash); + uint8_t *ip = flow->dip_addr; + info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u\n", __func__, port, q, + ip[0], ip[1], ip[2], ip[3], flow->dst_port, hash); return entry; } -int mt_tsq_put(struct mt_tsq_entry* entry) { - struct mt_tsq_impl* tsqm = entry->parent; - struct mt_tsq_queue* tsq_queue = &tsqm->tsq_queues[entry->queue_id]; +int mt_tsq_put(struct mt_tsq_entry *entry) { + struct mt_tsq_impl *tsqm = entry->parent; + struct mt_tsq_queue *tsq_queue = &tsqm->tsq_queues[entry->queue_id]; tsq_lock(tsq_queue); MT_TAILQ_REMOVE(&tsq_queue->head, entry, next); @@ -610,21 +629,22 @@ int mt_tsq_put(struct mt_tsq_entry* entry) { return 0; } -int mt_tsq_fatal_error(struct mt_tsq_entry* entry) { - struct mt_tsq_impl* tsqm = entry->parent; - struct mt_tsq_queue* tsq_queue = &tsqm->tsq_queues[entry->queue_id]; +int mt_tsq_fatal_error(struct mt_tsq_entry *entry) { + struct mt_tsq_impl *tsqm = entry->parent; + struct mt_tsq_queue *tsq_queue = &tsqm->tsq_queues[entry->queue_id]; tsq_lock(tsq_queue); tsq_queue->fatal_error = true; tsq_unlock(tsq_queue); - err("%s(%d), q %d masked as fatal error\n", __func__, tsqm->port, tsq_queue->queue_id); + err("%s(%d), q %d masked as fatal error\n", __func__, tsqm->port, + tsq_queue->queue_id); return 0; } -int mt_tsq_done_cleanup(struct mt_tsq_entry* entry) { - struct mt_tsq_impl* tsqm = entry->parent; - struct mt_tsq_queue* tsq_queue = &tsqm->tsq_queues[entry->queue_id]; +int mt_tsq_done_cleanup(struct mt_tsq_entry *entry) { + struct mt_tsq_impl *tsqm = entry->parent; + struct mt_tsq_queue *tsq_queue = &tsqm->tsq_queues[entry->queue_id]; tsq_lock(tsq_queue); rte_eth_tx_done_cleanup(tsq_queue->port_id, tsq_queue->queue_id, 0); @@ -633,25 +653,28 @@ int mt_tsq_done_cleanup(struct mt_tsq_entry* entry) { return 0; } -uint16_t mt_tsq_burst(struct mt_tsq_entry* entry, struct rte_mbuf** tx_pkts, +uint16_t mt_tsq_burst(struct mt_tsq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { - struct mt_tsq_impl* tsqm = entry->parent; - struct mt_tsq_queue* tsq_queue = &tsqm->tsq_queues[entry->queue_id]; + struct mt_tsq_impl *tsqm = entry->parent; + struct mt_tsq_queue *tsq_queue = &tsqm->tsq_queues[entry->queue_id]; uint16_t tx; rte_spinlock_lock(&tsq_queue->tx_mutex); if (tsq_queue->xdp) tx = mt_tx_xdp_burst(tsq_queue->xdp, tx_pkts, nb_pkts); else - tx = rte_eth_tx_burst(tsq_queue->port_id, tsq_queue->queue_id, tx_pkts, nb_pkts); + tx = rte_eth_tx_burst(tsq_queue->port_id, tsq_queue->queue_id, tx_pkts, + nb_pkts); tsq_queue->stat_pkts_send += tx; rte_spinlock_unlock(&tsq_queue->tx_mutex); return tx; } -uint16_t mt_tsq_burst_busy(struct mtl_main_impl* impl, struct mt_tsq_entry* entry, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts, int timeout_ms) { +uint16_t mt_tsq_burst_busy(struct mtl_main_impl *impl, + struct mt_tsq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, + int timeout_ms) { uint16_t sent = 0; uint64_t start_ts = mt_get_tsc(impl); @@ -660,8 +683,8 @@ uint16_t mt_tsq_burst_busy(struct mtl_main_impl* impl, struct mt_tsq_entry* entr if (timeout_ms > 0) { int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (ms > timeout_ms) { - warn("%s(%u), fail as timeout to %d ms\n", __func__, mt_tsq_queue_id(entry), - timeout_ms); + warn("%s(%u), fail as timeout to %d ms\n", __func__, + mt_tsq_queue_id(entry), timeout_ms); return sent; } } @@ -671,18 +694,20 @@ uint16_t mt_tsq_burst_busy(struct mtl_main_impl* impl, struct mt_tsq_entry* entr return sent; } -int mt_tsq_flush(struct mtl_main_impl* impl, struct mt_tsq_entry* entry, - struct rte_mbuf* pad) { - struct mt_tsq_impl* tsqm = entry->parent; +int mt_tsq_flush(struct mtl_main_impl *impl, struct mt_tsq_entry *entry, + struct rte_mbuf *pad) { + struct mt_tsq_impl *tsqm = entry->parent; enum mtl_port port = tsqm->port; uint16_t queue_id = entry->queue_id; - /* use double to make sure all the fifo are burst out to clean all mbufs in the pool */ + /* use double to make sure all the fifo are burst out to clean all mbufs in + * the pool */ int burst_pkts = mt_if_nb_tx_burst(impl, port) * 2; - struct rte_mbuf* pads[1]; + struct rte_mbuf *pads[1]; pads[0] = pad; - info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, burst_pkts); + info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, + burst_pkts); for (int i = 0; i < burst_pkts; i++) { rte_mbuf_refcnt_update(pad, 1); mt_tsq_burst_busy(impl, entry, &pads[0], 1, 10); @@ -691,13 +716,15 @@ int mt_tsq_flush(struct mtl_main_impl* impl, struct mt_tsq_entry* entry, return 0; } -int mt_tsq_init(struct mtl_main_impl* impl) { +int mt_tsq_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); int ret; for (int i = 0; i < num_ports; i++) { - if (!mt_user_shared_txq(impl, i)) continue; - impl->tsq[i] = mt_rte_zmalloc_socket(sizeof(*impl->tsq[i]), mt_socket_id(impl, i)); + if (!mt_user_shared_txq(impl, i)) + continue; + impl->tsq[i] = + mt_rte_zmalloc_socket(sizeof(*impl->tsq[i]), mt_socket_id(impl, i)); if (!impl->tsq[i]) { err("%s(%d), tsq malloc fail\n", __func__, i); mt_tsq_uinit(impl); @@ -706,8 +733,9 @@ int mt_tsq_init(struct mtl_main_impl* impl) { impl->tsq[i]->parent = impl; impl->tsq[i]->port = i; impl->tsq[i]->nb_tsq_queues = mt_if(impl, i)->nb_tx_q; - impl->tsq[i]->queue_mode = - mt_pmd_is_native_af_xdp(impl, i) ? MT_QUEUE_MODE_XDP : MT_QUEUE_MODE_DPDK; + impl->tsq[i]->queue_mode = mt_pmd_is_native_af_xdp(impl, i) + ? MT_QUEUE_MODE_XDP + : MT_QUEUE_MODE_DPDK; ret = tsq_init(impl, impl->tsq[i]); if (ret < 0) { err("%s(%d), tsq init fail\n", __func__, i); @@ -720,7 +748,7 @@ int mt_tsq_init(struct mtl_main_impl* impl) { return 0; } -int mt_tsq_uinit(struct mtl_main_impl* impl) { +int mt_tsq_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < MTL_PORT_MAX; i++) { if (impl->tsq[i]) { tsq_uinit(impl->tsq[i]); diff --git a/lib/src/datapath/mt_shared_queue.h b/lib/src/datapath/mt_shared_queue.h index fd8556796..5d5ceca4b 100644 --- a/lib/src/datapath/mt_shared_queue.h +++ b/lib/src/datapath/mt_shared_queue.h @@ -7,37 +7,39 @@ #include "../mt_main.h" -int mt_rsq_init(struct mtl_main_impl* impl); -int mt_rsq_uinit(struct mtl_main_impl* impl); +int mt_rsq_init(struct mtl_main_impl *impl); +int mt_rsq_uinit(struct mtl_main_impl *impl); -struct mt_rsq_entry* mt_rsq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow); -static inline uint16_t mt_rsq_queue_id(struct mt_rsq_entry* entry) { +struct mt_rsq_entry *mt_rsq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow); +static inline uint16_t mt_rsq_queue_id(struct mt_rsq_entry *entry) { return entry->queue_id; } -uint16_t mt_rsq_burst(struct mt_rsq_entry* entry, struct rte_mbuf** rx_pkts, +uint16_t mt_rsq_burst(struct mt_rsq_entry *entry, struct rte_mbuf **rx_pkts, uint16_t nb_pkts); -int mt_rsq_put(struct mt_rsq_entry* entry); +int mt_rsq_put(struct mt_rsq_entry *entry); -int mt_tsq_init(struct mtl_main_impl* impl); -int mt_tsq_uinit(struct mtl_main_impl* impl); +int mt_tsq_init(struct mtl_main_impl *impl); +int mt_tsq_uinit(struct mtl_main_impl *impl); -struct mt_tsq_entry* mt_tsq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow); -static inline uint16_t mt_tsq_queue_id(struct mt_tsq_entry* entry) { +struct mt_tsq_entry *mt_tsq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_txq_flow *flow); +static inline uint16_t mt_tsq_queue_id(struct mt_tsq_entry *entry) { return entry->queue_id; } -static inline struct rte_mempool* mt_tsq_mempool(struct mt_tsq_entry* entry) { +static inline struct rte_mempool *mt_tsq_mempool(struct mt_tsq_entry *entry) { return entry->tx_pool; } -uint16_t mt_tsq_burst(struct mt_tsq_entry* entry, struct rte_mbuf** tx_pkts, +uint16_t mt_tsq_burst(struct mt_tsq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -uint16_t mt_tsq_burst_busy(struct mtl_main_impl* impl, struct mt_tsq_entry* entry, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts, int timeout_ms); -int mt_tsq_flush(struct mtl_main_impl* impl, struct mt_tsq_entry* entry, - struct rte_mbuf* pad); -int mt_tsq_put(struct mt_tsq_entry* entry); -int mt_tsq_fatal_error(struct mt_tsq_entry* entry); -int mt_tsq_done_cleanup(struct mt_tsq_entry* entry); +uint16_t mt_tsq_burst_busy(struct mtl_main_impl *impl, + struct mt_tsq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, + int timeout_ms); +int mt_tsq_flush(struct mtl_main_impl *impl, struct mt_tsq_entry *entry, + struct rte_mbuf *pad); +int mt_tsq_put(struct mt_tsq_entry *entry); +int mt_tsq_fatal_error(struct mt_tsq_entry *entry); +int mt_tsq_done_cleanup(struct mt_tsq_entry *entry); #endif diff --git a/lib/src/datapath/mt_shared_rss.c b/lib/src/datapath/mt_shared_rss.c index 7543f5f5b..e113ffa3a 100644 --- a/lib/src/datapath/mt_shared_rss.c +++ b/lib/src/datapath/mt_shared_rss.c @@ -13,31 +13,32 @@ #define MT_SRSS_BURST_SIZE (128) #define MT_SRSS_RING_PREFIX "SR_" -static inline struct mt_srss_list* srss_list_by_udp_port(struct mt_srss_impl* srss, - uint16_t port) { +static inline struct mt_srss_list * +srss_list_by_udp_port(struct mt_srss_impl *srss, uint16_t port) { int l_idx = port % srss->lists_sz; return &srss->lists[l_idx]; } -static inline void srss_list_lock(struct mt_srss_list* list) { +static inline void srss_list_lock(struct mt_srss_list *list) { rte_spinlock_lock(&list->mutex); } /* return true if try lock succ */ -static inline bool srss_list_try_lock(struct mt_srss_list* list) { +static inline bool srss_list_try_lock(struct mt_srss_list *list) { int ret = rte_spinlock_trylock(&list->mutex); return ret ? true : false; } -static inline void srss_list_unlock(struct mt_srss_list* list) { +static inline void srss_list_unlock(struct mt_srss_list *list) { rte_spinlock_unlock(&list->mutex); } -static inline void srss_entry_pkts_enqueue(struct mt_srss_entry* entry, - struct rte_mbuf** pkts, +static inline void srss_entry_pkts_enqueue(struct mt_srss_entry *entry, + struct rte_mbuf **pkts, const uint16_t nb_pkts) { /* use bulk version */ - unsigned int n = rte_ring_mp_enqueue_bulk(entry->ring, (void**)pkts, nb_pkts, NULL); + unsigned int n = + rte_ring_mp_enqueue_bulk(entry->ring, (void **)pkts, nb_pkts, NULL); entry->stat_enqueue_cnt += n; if (n == 0) { rte_pktmbuf_free_bulk(pkts, nb_pkts); @@ -45,38 +46,40 @@ static inline void srss_entry_pkts_enqueue(struct mt_srss_entry* entry, } } -#define UPDATE_ENTRY() \ - do { \ - if (matched_pkts_nb) \ - srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], matched_pkts_nb); \ - last_srss_entry = srss_entry; \ - matched_pkts_nb = 0; \ +#define UPDATE_ENTRY() \ + do { \ + if (matched_pkts_nb) \ + srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], \ + matched_pkts_nb); \ + last_srss_entry = srss_entry; \ + matched_pkts_nb = 0; \ } while (0) -#define CNI_ENQUEUE() \ - do { \ - if (srss->cni_entry) \ - srss_entry_pkts_enqueue(srss->cni_entry, &pkts[i], 1); \ - else \ - rte_pktmbuf_free(pkts[i]); \ +#define CNI_ENQUEUE() \ + do { \ + if (srss->cni_entry) \ + srss_entry_pkts_enqueue(srss->cni_entry, &pkts[i], 1); \ + else \ + rte_pktmbuf_free(pkts[i]); \ } while (0) -#define UPDATE_LIST() \ - do { \ - if (last_list) srss_list_unlock(last_list); \ - srss_list_lock(list); \ - last_list = list; \ +#define UPDATE_LIST() \ + do { \ + if (last_list) \ + srss_list_unlock(last_list); \ + srss_list_lock(list); \ + last_list = list; \ } while (0) -static int srss_sch_tasklet_handler(void* priv) { - struct mt_srss_sch* srss_sch = priv; - struct mt_srss_impl* srss = srss_sch->parent; - struct mtl_main_impl* impl = srss->parent; +static int srss_sch_tasklet_handler(void *priv) { + struct mt_srss_sch *srss_sch = priv; + struct mt_srss_impl *srss = srss_sch->parent; + struct mtl_main_impl *impl = srss->parent; struct rte_mbuf *pkts[MT_SRSS_BURST_SIZE], *matched_pkts[MT_SRSS_BURST_SIZE]; struct mt_srss_entry *srss_entry, *last_srss_entry; struct mt_srss_list *list = NULL, *last_list = NULL; - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; for (uint16_t queue = srss_sch->q_start; queue < srss_sch->q_end; queue++) { uint16_t matched_pkts_nb = 0; @@ -85,16 +88,17 @@ static int srss_sch_tasklet_handler(void* priv) { if (srss->xdps) { rx = mt_rx_xdp_burst(srss->xdps[queue], pkts, MT_SRSS_BURST_SIZE); } else { - rx = - rte_eth_rx_burst(mt_port_id(impl, srss->port), queue, pkts, MT_SRSS_BURST_SIZE); + rx = rte_eth_rx_burst(mt_port_id(impl, srss->port), queue, pkts, + MT_SRSS_BURST_SIZE); } - if (!rx) continue; + if (!rx) + continue; srss_sch->stat_pkts_rx += rx; last_srss_entry = NULL; for (uint16_t i = 0; i < rx; i++) { srss_entry = NULL; - hdr = rte_pktmbuf_mtod(pkts[i], struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkts[i], struct mt_udp_hdr *); if (hdr->eth.ether_type != htons(RTE_ETHER_TYPE_IPV4)) { /* non ip, redirect to cni */ UPDATE_ENTRY(); @@ -114,11 +118,12 @@ static int srss_sch_tasklet_handler(void* priv) { UPDATE_LIST(); } /* check if match any entry in current list */ - struct mt_srss_entrys_list* head = &list->entrys_list; + struct mt_srss_entrys_list *head = &list->entrys_list; MT_TAILQ_FOREACH(srss_entry, head, next) { bool matched = mt_udp_matched(&srss_entry->flow, hdr); if (matched) { - if (srss_entry != last_srss_entry) UPDATE_ENTRY(); + if (srss_entry != last_srss_entry) + UPDATE_ENTRY(); matched_pkts[matched_pkts_nb++] = pkts[i]; break; } @@ -130,21 +135,23 @@ static int srss_sch_tasklet_handler(void* priv) { } } if (matched_pkts_nb) - srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], matched_pkts_nb); + srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], + matched_pkts_nb); } - if (last_list) srss_list_unlock(last_list); + if (last_list) + srss_list_unlock(last_list); return 0; } -static void* srss_traffic_thread(void* arg) { - struct mt_srss_impl* srss = arg; +static void *srss_traffic_thread(void *arg) { + struct mt_srss_impl *srss = arg; info("%s, start\n", __func__); while (rte_atomic32_read(&srss->stop_thread) == 0) { for (int s_idx = 0; s_idx < srss->schs_cnt; s_idx++) { - struct mt_srss_sch* srss_sch = &srss->schs[s_idx]; + struct mt_srss_sch *srss_sch = &srss->schs[s_idx]; srss_sch_tasklet_handler(srss_sch); } @@ -155,7 +162,7 @@ static void* srss_traffic_thread(void* arg) { return NULL; } -static int srss_traffic_thread_start(struct mt_srss_impl* srss) { +static int srss_traffic_thread_start(struct mt_srss_impl *srss) { int ret; if (srss->tid) { @@ -173,7 +180,7 @@ static int srss_traffic_thread_start(struct mt_srss_impl* srss) { return 0; } -static int srss_traffic_thread_stop(struct mt_srss_impl* srss) { +static int srss_traffic_thread_stop(struct mt_srss_impl *srss) { rte_atomic32_set(&srss->stop_thread, 1); if (srss->tid) { pthread_join(srss->tid, NULL); @@ -183,8 +190,8 @@ static int srss_traffic_thread_stop(struct mt_srss_impl* srss) { return 0; } -static int srss_sch_tasklet_start(void* priv) { - struct mt_srss_sch* srss_sch = priv; +static int srss_sch_tasklet_start(void *priv) { + struct mt_srss_sch *srss_sch = priv; if (srss_sch->idx == 0) { /* tasklet will take over the srss thread */ @@ -194,8 +201,8 @@ static int srss_sch_tasklet_start(void* priv) { return 0; } -static int srss_sch_tasklet_stop(void* priv) { - struct mt_srss_sch* srss_sch = priv; +static int srss_sch_tasklet_stop(void *priv) { + struct mt_srss_sch *srss_sch = priv; if (srss_sch->idx == 0) { srss_traffic_thread_start(srss_sch->parent); @@ -204,23 +211,23 @@ static int srss_sch_tasklet_stop(void* priv) { return 0; } -static int srss_stat(void* priv) { - struct mt_srss_impl* srss = priv; +static int srss_stat(void *priv) { + struct mt_srss_impl *srss = priv; enum mtl_port port = srss->port; - struct mt_srss_entry* entry; + struct mt_srss_entry *entry; int idx; for (int l_idx = 0; l_idx < srss->lists_sz; l_idx++) { - struct mt_srss_list* list = &srss->lists[l_idx]; + struct mt_srss_list *list = &srss->lists[l_idx]; if (!srss_list_try_lock(list)) { continue; } - struct mt_srss_entrys_list* head = &list->entrys_list; + struct mt_srss_entrys_list *head = &list->entrys_list; MT_TAILQ_FOREACH(entry, head, next) { idx = entry->idx; - notice("%s(%d,%d,%d), enqueue %u dequeue %u\n", __func__, port, l_idx, idx, - entry->stat_enqueue_cnt, entry->stat_dequeue_cnt); + notice("%s(%d,%d,%d), enqueue %u dequeue %u\n", __func__, port, l_idx, + idx, entry->stat_enqueue_cnt, entry->stat_dequeue_cnt); entry->stat_enqueue_cnt = 0; entry->stat_dequeue_cnt = 0; if (entry->stat_enqueue_fail_cnt) { @@ -233,18 +240,20 @@ static int srss_stat(void* priv) { } for (int s_idx = 0; s_idx < srss->schs_cnt; s_idx++) { - struct mt_srss_sch* srss_sch = &srss->schs[s_idx]; + struct mt_srss_sch *srss_sch = &srss->schs[s_idx]; - notice("%s(%d,%d), pkts rx %u\n", __func__, port, s_idx, srss_sch->stat_pkts_rx); + notice("%s(%d,%d), pkts rx %u\n", __func__, port, s_idx, + srss_sch->stat_pkts_rx); srss_sch->stat_pkts_rx = 0; } return 0; } -static int srss_uinit_xdp(struct mt_srss_impl* srss) { - struct mt_rx_xdp_entry** xdps = srss->xdps; - if (!xdps) return 0; +static int srss_uinit_xdp(struct mt_srss_impl *srss) { + struct mt_rx_xdp_entry **xdps = srss->xdps; + if (!xdps) + return 0; for (uint16_t queue = 0; queue < srss->nb_rx_q; queue++) { if (xdps[queue]) { @@ -258,8 +267,8 @@ static int srss_uinit_xdp(struct mt_srss_impl* srss) { return 0; } -static int srss_init_xdp(struct mt_srss_impl* srss) { - struct mtl_main_impl* impl = srss->parent; +static int srss_init_xdp(struct mt_srss_impl *srss) { + struct mtl_main_impl *impl = srss->parent; enum mtl_port port = srss->port; srss->xdps = mt_rte_zmalloc_socket(sizeof(*srss->xdps) * srss->nb_rx_q, @@ -291,13 +300,14 @@ static int srss_init_xdp(struct mt_srss_impl* srss) { return 0; } -struct mt_srss_entry* mt_srss_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow) { - struct mt_srss_impl* srss = impl->srss[port]; +struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow) { + struct mt_srss_impl *srss = impl->srss[port]; int idx = srss->entry_idx; - struct mt_srss_entry* entry; - struct mt_srss_list* list; - struct mt_srss_entrys_list* head; + struct mt_srss_entry *entry; + struct mt_srss_list *list; + struct mt_srss_entrys_list *head; if (!mt_has_srss(impl, port)) { err("%s(%d,%d), shared rss not enabled\n", __func__, port, idx); @@ -311,10 +321,10 @@ struct mt_srss_entry* mt_srss_get(struct mtl_main_impl* impl, enum mtl_port port MT_TAILQ_FOREACH(entry, head, next) { /* todo: check with flow flags */ if (entry->flow.dst_port == flow->dst_port && - *(uint32_t*)entry->flow.dip_addr == *(uint32_t*)flow->dip_addr) { + *(uint32_t *)entry->flow.dip_addr == *(uint32_t *)flow->dip_addr) { err("%s(%d,%d), already has entry %u.%u.%u.%u:%u\n", __func__, port, idx, - flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], flow->dip_addr[3], - flow->dst_port); + flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], + flow->dip_addr[3], flow->dst_port); srss_list_unlock(list); return NULL; } @@ -330,8 +340,8 @@ struct mt_srss_entry* mt_srss_get(struct mtl_main_impl* impl, enum mtl_port port /* ring create */ char ring_name[32]; snprintf(ring_name, 32, "%sP%d_%d", MT_SRSS_RING_PREFIX, port, idx); - entry->ring = - rte_ring_create(ring_name, 512, mt_socket_id(impl, MTL_PORT_P), RING_F_SC_DEQ); + entry->ring = rte_ring_create(ring_name, 512, mt_socket_id(impl, MTL_PORT_P), + RING_F_SC_DEQ); if (!entry->ring) { err("%s(%d,%d), ring create fail\n", __func__, port, idx); mt_rte_free(entry); @@ -344,24 +354,25 @@ struct mt_srss_entry* mt_srss_get(struct mtl_main_impl* impl, enum mtl_port port srss_list_lock(list); MT_TAILQ_INSERT_TAIL(head, entry, next); - if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) srss->cni_entry = entry; + if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) + srss->cni_entry = entry; srss->entry_idx++; srss_list_unlock(list); info("%s(%d), entry %u.%u.%u.%u:(dst)%u on %d of list %d\n", __func__, port, - flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], flow->dip_addr[3], - flow->dst_port, idx, list->idx); + flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], + flow->dip_addr[3], flow->dst_port, idx, list->idx); return entry; } -int mt_srss_put(struct mt_srss_entry* entry) { - struct mt_srss_impl* srss = entry->srss; +int mt_srss_put(struct mt_srss_entry *entry) { + struct mt_srss_impl *srss = entry->srss; enum mtl_port port = srss->port; - struct mt_srss_list* list = srss_list_by_udp_port(srss, entry->flow.dst_port); - struct mt_srss_entrys_list* head = &list->entrys_list; + struct mt_srss_list *list = srss_list_by_udp_port(srss, entry->flow.dst_port); + struct mt_srss_entrys_list *head = &list->entrys_list; /* check if it's a known entry in the list */ - struct mt_srss_entry* temp_entry; + struct mt_srss_entry *temp_entry; bool found = false; srss_list_lock(list); MT_TAILQ_FOREACH(temp_entry, head, next) { @@ -396,27 +407,28 @@ int mt_srss_put(struct mt_srss_entry* entry) { return 0; } -int mt_srss_init(struct mtl_main_impl* impl) { +int mt_srss_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mtl_init_params* p = mt_get_user_params(impl); + struct mtl_init_params *p = mt_get_user_params(impl); int ret; for (int port = 0; port < num_ports; port++) { - if (!mt_has_srss(impl, port)) continue; + if (!mt_has_srss(impl, port)) + continue; - impl->srss[port] = - mt_rte_zmalloc_socket(sizeof(*impl->srss[port]), mt_socket_id(impl, port)); + impl->srss[port] = mt_rte_zmalloc_socket(sizeof(*impl->srss[port]), + mt_socket_id(impl, port)); if (!impl->srss[port]) { err("%s(%d), srss malloc fail\n", __func__, port); mt_srss_uinit(impl); return -ENOMEM; } - struct mt_srss_impl* srss = impl->srss[port]; + struct mt_srss_impl *srss = impl->srss[port]; srss->port = port; srss->parent = impl; - srss->queue_mode = - mt_pmd_is_native_af_xdp(impl, port) ? MT_QUEUE_MODE_XDP : MT_QUEUE_MODE_DPDK; + srss->queue_mode = mt_pmd_is_native_af_xdp(impl, port) ? MT_QUEUE_MODE_XDP + : MT_QUEUE_MODE_DPDK; srss->nb_rx_q = mt_if(impl, port)->nb_rx_q; srss->lists_sz = 64 - 1; /* use odd count for better distribution */ @@ -428,7 +440,7 @@ int mt_srss_init(struct mtl_main_impl* impl) { return -ENOMEM; } for (int l_idx = 0; l_idx < srss->lists_sz; l_idx++) { - struct mt_srss_list* list = &srss->lists[l_idx]; + struct mt_srss_list *list = &srss->lists[l_idx]; list->idx = l_idx; MT_TAILQ_INIT(&list->entrys_list); @@ -445,8 +457,10 @@ int mt_srss_init(struct mtl_main_impl* impl) { } srss->schs_cnt = p->rss_sch_nb[port]; - if (!srss->schs_cnt) srss->schs_cnt = 1; - if (srss->schs_cnt > srss->nb_rx_q) srss->schs_cnt = srss->nb_rx_q; + if (!srss->schs_cnt) + srss->schs_cnt = 1; + if (srss->schs_cnt > srss->nb_rx_q) + srss->schs_cnt = srss->nb_rx_q; srss->schs = mt_rte_zmalloc_socket(sizeof(*srss->schs) * srss->schs_cnt, mt_socket_id(impl, port)); if (!srss->schs) { @@ -459,17 +473,18 @@ int mt_srss_init(struct mtl_main_impl* impl) { uint16_t q_per_sch = srss->nb_rx_q / srss->schs_cnt; uint16_t q_remaining = srss->nb_rx_q % srss->schs_cnt; for (int s_idx = 0; s_idx < srss->schs_cnt; s_idx++) { - struct mt_srss_sch* srss_sch = &srss->schs[s_idx]; + struct mt_srss_sch *srss_sch = &srss->schs[s_idx]; srss_sch->parent = srss; srss_sch->idx = s_idx; srss_sch->quota_mps = 0; srss_sch->q_start = q_idx; uint16_t q_end = srss_sch->q_start + q_per_sch; - if (s_idx < q_remaining) q_end++; + if (s_idx < q_remaining) + q_end++; srss_sch->q_end = q_end; q_idx = q_end; - struct mtl_sch_impl* sch = + struct mtl_sch_impl *sch = mt_sch_get(impl, srss_sch->quota_mps, MT_SCH_TYPE_DEFAULT, sch_mask); if (!sch) { err("%s(%d), get sch fail on %d\n", __func__, port, s_idx); @@ -493,8 +508,8 @@ int mt_srss_init(struct mtl_main_impl* impl) { } sch_mask &= ~(MTL_BIT64(sch->idx)); - info("%s(%d), sch %d with queues start %u end %u\n", __func__, port, s_idx, - srss_sch->q_start, srss_sch->q_end); + info("%s(%d), sch %d with queues start %u end %u\n", __func__, port, + s_idx, srss_sch->q_start, srss_sch->q_end); } rte_atomic32_set(&srss->stop_thread, 0); @@ -513,19 +528,20 @@ int mt_srss_init(struct mtl_main_impl* impl) { return 0; } -int mt_srss_uinit(struct mtl_main_impl* impl) { +int mt_srss_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { - struct mt_srss_impl* srss = impl->srss[i]; - if (!srss) continue; + struct mt_srss_impl *srss = impl->srss[i]; + if (!srss) + continue; mt_stat_unregister(impl, srss_stat, srss); srss_traffic_thread_stop(srss); if (srss->schs) { for (int s_idx = 0; s_idx < srss->schs_cnt; s_idx++) { - struct mt_srss_sch* srss_sch = &srss->schs[s_idx]; + struct mt_srss_sch *srss_sch = &srss->schs[s_idx]; if (srss_sch->tasklet) { mtl_sch_unregister_tasklet(srss_sch->tasklet); srss_sch->tasklet = NULL; @@ -542,13 +558,13 @@ int mt_srss_uinit(struct mtl_main_impl* impl) { if (srss->lists) { for (int l_idx = 0; l_idx < srss->lists_sz; l_idx++) { - struct mt_srss_list* list = &srss->lists[l_idx]; + struct mt_srss_list *list = &srss->lists[l_idx]; - struct mt_srss_entrys_list* head = &list->entrys_list; - struct mt_srss_entry* entry; + struct mt_srss_entrys_list *head = &list->entrys_list; + struct mt_srss_entry *entry; while ((entry = MT_TAILQ_FIRST(head))) { - warn("%s(%d), still has entry %p on list_heads %d\n", __func__, i, entry, - l_idx); + warn("%s(%d), still has entry %p on list_heads %d\n", __func__, i, + entry, l_idx); MT_TAILQ_REMOVE(head, entry, next); mt_rte_free(entry); } diff --git a/lib/src/datapath/mt_shared_rss.h b/lib/src/datapath/mt_shared_rss.h index 4d695bc8f..b4026457b 100644 --- a/lib/src/datapath/mt_shared_rss.h +++ b/lib/src/datapath/mt_shared_rss.h @@ -7,21 +7,23 @@ #include "../mt_main.h" -int mt_srss_init(struct mtl_main_impl* impl); +int mt_srss_init(struct mtl_main_impl *impl); -int mt_srss_uinit(struct mtl_main_impl* impl); +int mt_srss_uinit(struct mtl_main_impl *impl); -struct mt_srss_entry* mt_srss_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow); -static inline uint16_t mt_srss_queue_id(struct mt_srss_entry* entry) { +struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, + enum mtl_port port, struct mt_rxq_flow *flow); +static inline uint16_t mt_srss_queue_id(struct mt_srss_entry *entry) { return entry->idx; /* use dummy id*/ } -static inline uint16_t mt_srss_burst(struct mt_srss_entry* entry, - struct rte_mbuf** rx_pkts, const uint16_t nb_pkts) { - uint16_t n = rte_ring_sc_dequeue_burst(entry->ring, (void**)rx_pkts, nb_pkts, NULL); +static inline uint16_t mt_srss_burst(struct mt_srss_entry *entry, + struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts) { + uint16_t n = + rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); entry->stat_dequeue_cnt += n; return n; } -int mt_srss_put(struct mt_srss_entry* entry); +int mt_srss_put(struct mt_srss_entry *entry); #endif \ No newline at end of file diff --git a/lib/src/dev/mt_af_xdp.c b/lib/src/dev/mt_af_xdp.c index 3807f9cf7..fda82e0e5 100644 --- a/lib/src/dev/mt_af_xdp.c +++ b/lib/src/dev/mt_af_xdp.c @@ -26,30 +26,32 @@ struct mt_xdp_queue { enum mtl_port port; - struct rte_mempool* mbuf_pool; + struct rte_mempool *mbuf_pool; uint16_t q; uint32_t umem_ring_size; - struct xsk_umem* umem; - void* umem_buffer; + struct xsk_umem *umem; + void *umem_buffer; - struct xsk_socket* socket; + struct xsk_socket *socket; int socket_fd; /* rx pkt send on this producer ring, filled by kernel */ struct xsk_ring_prod rx_prod; - /* rx pkt done on this consumer ring, pulled from userspace on the RX data path */ + /* rx pkt done on this consumer ring, pulled from userspace on the RX data + * path */ struct xsk_ring_cons rx_cons; /* tx pkt done on this consumer ring, filled by kernel */ struct xsk_ring_cons tx_cons; - /* tx pkt send on this producer ring, filled from userspace on the TX data path */ + /* tx pkt send on this producer ring, filled from userspace on the TX data + * path */ struct xsk_ring_prod tx_prod; uint32_t tx_free_thresh; uint32_t tx_full_thresh; - struct mt_tx_xdp_entry* tx_entry; - struct mt_rx_xdp_entry* rx_entry; + struct mt_tx_xdp_entry *tx_entry; + struct mt_rx_xdp_entry *rx_entry; uint64_t stat_tx_pkts; uint64_t stat_tx_bytes; @@ -73,7 +75,7 @@ struct mt_xdp_queue { }; struct mt_xdp_priv { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; char drv[32]; uint32_t flags; /* XDP_F_* */ @@ -81,48 +83,49 @@ struct mt_xdp_priv { uint16_t queues_cnt; - struct mt_xdp_queue* queues_info; + struct mt_xdp_queue *queues_info; pthread_mutex_t queues_lock; bool has_ctrl; }; -static int xdp_queue_tx_max_rate(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq, - uint32_t rate_kbps) { +static int xdp_queue_tx_max_rate(struct mt_xdp_priv *xdp, + struct mt_xdp_queue *xq, uint32_t rate_kbps) { enum mtl_port port = xq->port; - const char* if_name = mt_kernel_if_name(xdp->parent, port); + const char *if_name = mt_kernel_if_name(xdp->parent, port); char path[128]; - snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", if_name, - xq->q); + snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", + if_name, xq->q); int ret = mt_sysfs_write_uint32(path, rate_kbps | MTL_BIT32(31)); info("%s(%d), write %u to %s ret %d\n", __func__, port, rate_kbps, path, ret); return ret; } -static int xdp_queue_tx_stat(struct mt_xdp_queue* xq) { +static int xdp_queue_tx_stat(struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 " free %" PRIu64 - " wakeup %" PRIu64 "\n", - __func__, port, q, xq->stat_tx_pkts, xq->stat_tx_bytes, xq->stat_tx_submit, - xq->stat_tx_free, xq->stat_tx_wakeup); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 + " free %" PRIu64 " wakeup %" PRIu64 "\n", + __func__, port, q, xq->stat_tx_pkts, xq->stat_tx_bytes, + xq->stat_tx_submit, xq->stat_tx_free, xq->stat_tx_wakeup); xq->stat_tx_pkts = 0; xq->stat_tx_bytes = 0; xq->stat_tx_submit = 0; xq->stat_tx_free = 0; xq->stat_tx_wakeup = 0; if (xq->stat_tx_copy) { - notice("%s(%d,%u), pkts copy %" PRIu64 "\n", __func__, port, q, xq->stat_tx_copy); + notice("%s(%d,%u), pkts copy %" PRIu64 "\n", __func__, port, q, + xq->stat_tx_copy); xq->stat_tx_copy = 0; } uint32_t ring_sz = xq->umem_ring_size; uint32_t cons_avail = xsk_cons_nb_avail(&xq->tx_cons, ring_sz); uint32_t prod_free = xsk_prod_nb_free(&xq->tx_prod, ring_sz); - notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, cons_avail, - prod_free); + notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, + cons_avail, prod_free); if (xq->stat_tx_mbuf_alloc_fail) { warn("%s(%d,%u), mbuf alloc fail %" PRIu64 "\n", __func__, port, q, @@ -147,12 +150,13 @@ static int xdp_queue_tx_stat(struct mt_xdp_queue* xq) { return 0; } -static int xdp_queue_rx_stat(struct mt_xdp_queue* xq) { +static int xdp_queue_rx_stat(struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", __func__, - port, q, xq->stat_rx_pkts, xq->stat_rx_bytes, xq->stat_rx_burst); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", + __func__, port, q, xq->stat_rx_pkts, xq->stat_rx_bytes, + xq->stat_rx_burst); xq->stat_rx_pkts = 0; xq->stat_rx_bytes = 0; xq->stat_rx_burst = 0; @@ -160,8 +164,8 @@ static int xdp_queue_rx_stat(struct mt_xdp_queue* xq) { uint32_t ring_sz = xq->umem_ring_size; uint32_t cons_avail = xsk_cons_nb_avail(&xq->rx_cons, ring_sz); uint32_t prod_free = xsk_prod_nb_free(&xq->rx_prod, ring_sz); - notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, cons_avail, - prod_free); + notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, + cons_avail, prod_free); if (xq->stat_rx_mbuf_alloc_fail) { warn("%s(%d,%u), mbuf alloc fail %" PRIu64 "\n", __func__, port, q, @@ -183,24 +187,26 @@ static int xdp_queue_rx_stat(struct mt_xdp_queue* xq) { return 0; } -static int xdp_stat_dump(void* priv) { - struct mt_xdp_priv* xdp = priv; +static int xdp_stat_dump(void *priv) { + struct mt_xdp_priv *xdp = priv; for (uint16_t i = 0; i < xdp->queues_cnt; i++) { - struct mt_xdp_queue* xq = &xdp->queues_info[i]; - if (xq->tx_entry) xdp_queue_tx_stat(xq); - if (xq->rx_entry) xdp_queue_rx_stat(xq); + struct mt_xdp_queue *xq = &xdp->queues_info[i]; + if (xq->tx_entry) + xdp_queue_tx_stat(xq); + if (xq->rx_entry) + xdp_queue_rx_stat(xq); } return 0; } -static void xdp_queue_clean_mbuf(struct mt_xdp_queue* xq) { +static void xdp_queue_clean_mbuf(struct mt_xdp_queue *xq) { /* todo: find a way to safe free the mbuf in xsk_ring_prod__fill_addr */ MTL_MAY_UNUSED(xq); } -static int xdp_queue_uinit(struct mt_xdp_queue* xq) { +static int xdp_queue_uinit(struct mt_xdp_queue *xq) { xdp_queue_clean_mbuf(xq); if (xq->socket) { @@ -216,12 +222,12 @@ static int xdp_queue_uinit(struct mt_xdp_queue* xq) { return 0; } -static int xdp_free(struct mt_xdp_priv* xdp) { +static int xdp_free(struct mt_xdp_priv *xdp) { enum mtl_port port = xdp->port; if (xdp->queues_info) { for (uint16_t i = 0; i < xdp->queues_cnt; i++) { - struct mt_xdp_queue* xq = &xdp->queues_info[i]; + struct mt_xdp_queue *xq = &xdp->queues_info[i]; xdp_queue_uinit(xq); @@ -245,21 +251,22 @@ static int xdp_free(struct mt_xdp_priv* xdp) { return 0; } -static int xdp_parse_drv_name(struct mt_xdp_priv* xdp) { - struct mtl_main_impl* impl = xdp->parent; +static int xdp_parse_drv_name(struct mt_xdp_priv *xdp) { + struct mtl_main_impl *impl = xdp->parent; enum mtl_port port = xdp->port; - const char* if_name = mt_kernel_if_name(impl, port); + const char *if_name = mt_kernel_if_name(impl, port); char drv_path[128]; char link_path[128]; - snprintf(drv_path, sizeof(drv_path), "/sys/class/net/%s/device/driver", if_name); + snprintf(drv_path, sizeof(drv_path), "/sys/class/net/%s/device/driver", + if_name); ssize_t len = readlink(drv_path, link_path, sizeof(link_path)); if (len < 0) { warn("%s(%d), readlink fail for %s\n", __func__, port, if_name); goto unknown; } link_path[len] = '\0'; - char* driver_name = basename(link_path); + char *driver_name = basename(link_path); if (!driver_name) { warn("%s(%d), basename fail for %s\n", __func__, port, if_name); goto unknown; @@ -274,14 +281,15 @@ static int xdp_parse_drv_name(struct mt_xdp_priv* xdp) { return -EIO; } -static int xdp_parse_pacing_ice(struct mt_xdp_priv* xdp) { - struct mtl_main_impl* impl = xdp->parent; +static int xdp_parse_pacing_ice(struct mt_xdp_priv *xdp) { + struct mtl_main_impl *impl = xdp->parent; enum mtl_port port = xdp->port; - const char* if_name = mt_kernel_if_name(impl, port); + const char *if_name = mt_kernel_if_name(impl, port); uint32_t rate = MTL_BIT32(31); char path[128]; - snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", if_name, 1); + snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", + if_name, 1); int ret = mt_sysfs_write_uint32(path, rate); info("%s(%d), rl feature %s\n", __func__, port, ret < 0 ? "no" : "yes"); if (ret >= 0) { @@ -291,14 +299,14 @@ static int xdp_parse_pacing_ice(struct mt_xdp_priv* xdp) { return ret; } -static int xdp_umem_init(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq) { +static int xdp_umem_init(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; int ret; struct xsk_umem_config cfg; - void* base_addr = NULL; - void* aligned_base_addr = NULL; - struct rte_mempool* pool = xq->mbuf_pool; + void *base_addr = NULL; + void *aligned_base_addr = NULL; + struct rte_mempool *pool = xq->mbuf_pool; uint64_t umem_size; memset(&cfg, 0, sizeof(cfg)); @@ -311,33 +319,36 @@ static int xdp_umem_init(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq) { rte_pktmbuf_priv_size(pool) + RTE_PKTMBUF_HEADROOM; base_addr = mt_mempool_mem_addr(pool); - aligned_base_addr = (void*)((uint64_t)base_addr & ~(mtl_page_size(xdp->parent) - 1)); + aligned_base_addr = + (void *)((uint64_t)base_addr & ~(mtl_page_size(xdp->parent) - 1)); umem_size = mt_mempool_mem_size(pool) + base_addr - aligned_base_addr; - dbg("%s(%d), base_addr %p umem_size %" PRIu64 "\n", __func__, port, aligned_base_addr, - umem_size); + dbg("%s(%d), base_addr %p umem_size %" PRIu64 "\n", __func__, port, + aligned_base_addr, umem_size); ret = xsk_umem__create(&xq->umem, aligned_base_addr, umem_size, &xq->rx_prod, &xq->tx_cons, &cfg); if (ret < 0) { - err("%s(%d,%u), umem create fail %d %s\n", __func__, port, q, ret, strerror(errno)); + err("%s(%d,%u), umem create fail %d %s\n", __func__, port, q, ret, + strerror(errno)); if (ret == -EPERM) - err("%s(%d,%u), please add capability for the app: sudo setcap 'cap_net_raw+ep' " + err("%s(%d,%u), please add capability for the app: sudo setcap " + "'cap_net_raw+ep' " "\n", __func__, port, q); return ret; } xq->umem_buffer = aligned_base_addr; - info("%s(%d,%u), umem %p buffer %p size %" PRIu64 "\n", __func__, port, q, xq->umem, - xq->umem_buffer, umem_size); + info("%s(%d,%u), umem %p buffer %p size %" PRIu64 "\n", __func__, port, q, + xq->umem, xq->umem_buffer, umem_size); return 0; } -static inline int xdp_rx_prod_reserve(struct mt_xdp_queue* xq, struct rte_mbuf** mbufs, - uint16_t sz) { +static inline int xdp_rx_prod_reserve(struct mt_xdp_queue *xq, + struct rte_mbuf **mbufs, uint16_t sz) { enum mtl_port port = xq->port; uint16_t q = xq->q; uint32_t idx = 0; - struct xsk_ring_prod* pq = &xq->rx_prod; + struct xsk_ring_prod *pq = &xq->rx_prod; int ret; ret = xsk_ring_prod__reserve(pq, sz, &idx); @@ -347,11 +358,12 @@ static inline int xdp_rx_prod_reserve(struct mt_xdp_queue* xq, struct rte_mbuf** } for (uint32_t i = 0; i < sz; i++) { - __u64* fq_addr; + __u64 *fq_addr; uint64_t addr; fq_addr = xsk_ring_prod__fill_addr(pq, idx++); - addr = (uint64_t)mbufs[i] - (uint64_t)xq->umem_buffer - xq->mbuf_pool->header_size; + addr = (uint64_t)mbufs[i] - (uint64_t)xq->umem_buffer - + xq->mbuf_pool->header_size; *fq_addr = addr; } @@ -359,13 +371,13 @@ static inline int xdp_rx_prod_reserve(struct mt_xdp_queue* xq, struct rte_mbuf** return 0; } -static int xdp_rx_prod_init(struct mt_xdp_queue* xq) { +static int xdp_rx_prod_init(struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; uint32_t ring_sz = xq->umem_ring_size; int ret; - struct rte_mbuf* mbufs[ring_sz]; + struct rte_mbuf *mbufs[ring_sz]; ret = rte_pktmbuf_alloc_bulk(xq->mbuf_pool, mbufs, ring_sz); if (ret < 0) { err("%s(%d,%u), mbufs alloc fail %d\n", __func__, port, q, ret); @@ -381,13 +393,15 @@ static int xdp_rx_prod_init(struct mt_xdp_queue* xq) { return 0; } -static int xdp_socket_update_xskmap(struct mtl_main_impl* impl, struct mt_xdp_queue* xq, - const char* ifname) { +static int xdp_socket_update_xskmap(struct mtl_main_impl *impl, + struct mt_xdp_queue *xq, + const char *ifname) { enum mtl_port port = xq->port; uint16_t q = xq->q; int ret; - int xsks_map_fd = mt_instance_request_xsks_map_fd(impl, if_nametoindex(ifname)); + int xsks_map_fd = + mt_instance_request_xsks_map_fd(impl, if_nametoindex(ifname)); if (xsks_map_fd < 0) { err("%s(%d,%u), get xsks_map_fd fail\n", __func__, port, q); @@ -403,11 +417,11 @@ static int xdp_socket_update_xskmap(struct mtl_main_impl* impl, struct mt_xdp_qu return 0; } -static int xdp_socket_init(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq) { +static int xdp_socket_init(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; - struct mtl_main_impl* impl = xdp->parent; - const char* if_name = mt_kernel_if_name(impl, port); + struct mtl_main_impl *impl = xdp->parent; + const char *if_name = mt_kernel_if_name(impl, port); struct xsk_socket_config cfg; int ret; @@ -427,15 +441,16 @@ static int xdp_socket_init(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq) { /* first try zero copy mode */ cfg.bind_flags |= XDP_ZEROCOPY; /* force zero copy mode */ - ret = xsk_socket__create(&xq->socket, if_name, q, xq->umem, &xq->rx_cons, &xq->tx_prod, - &cfg); + ret = xsk_socket__create(&xq->socket, if_name, q, xq->umem, &xq->rx_cons, + &xq->tx_prod, &cfg); if (ret < 0) { if (ret == -EPERM) { - err("%s(%d,%u), please run with mtl manager or root user\n", __func__, port, q); + err("%s(%d,%u), please run with mtl manager or root user\n", __func__, + port, q); return ret; } - warn("%s(%d,%u), xsk create with zero copy fail %d(%s), try copy mode\n", __func__, - port, q, ret, strerror(ret)); + warn("%s(%d,%u), xsk create with zero copy fail %d(%s), try copy mode\n", + __func__, port, q, ret, strerror(ret)); } else { xdp->flags |= XDP_F_ZERO_COPY; } @@ -448,21 +463,24 @@ static int xdp_socket_init(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq) { &xq->tx_prod, &cfg); if (ret < 0) { if (ret == -EPERM) { - err("%s(%d,%u), please run with mtl manager or root user\n", __func__, port, q); + err("%s(%d,%u), please run with mtl manager or root user\n", __func__, + port, q); } - err("%s(%d,%u), xsk create fail %d(%s)\n", __func__, port, q, ret, strerror(ret)); + err("%s(%d,%u), xsk create fail %d(%s)\n", __func__, port, q, ret, + strerror(ret)); return ret; } } xq->socket_fd = xsk_socket__fd(xq->socket); - if (xdp->has_ctrl) return xdp_socket_update_xskmap(impl, xq, if_name); + if (xdp->has_ctrl) + return xdp_socket_update_xskmap(impl, xq, if_name); return 0; } -static int xdp_queue_init(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq) { +static int xdp_queue_init(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; int ret; @@ -491,8 +509,8 @@ static int xdp_queue_init(struct mt_xdp_priv* xdp, struct mt_xdp_queue* xq) { return 0; } -static void xdp_tx_poll_done(struct mt_xdp_queue* xq) { - struct xsk_ring_cons* cq = &xq->tx_cons; +static void xdp_tx_poll_done(struct mt_xdp_queue *xq) { + struct xsk_ring_cons *cq = &xq->tx_cons; uint32_t idx = 0; uint32_t size = xq->umem_ring_size; uint32_t n = xsk_ring_cons__peek(cq, size, &idx); @@ -500,10 +518,10 @@ static void xdp_tx_poll_done(struct mt_xdp_queue* xq) { for (uint32_t i = 0; i < n; i++) { uint64_t addr = *xsk_ring_cons__comp_addr(cq, idx++); addr = xsk_umem__extract_addr(addr); - struct rte_mbuf* m = (struct rte_mbuf*)xsk_umem__get_data( + struct rte_mbuf *m = (struct rte_mbuf *)xsk_umem__get_data( xq->umem_buffer, addr + xq->mbuf_pool->header_size); - dbg("%s(%d, %u), free mbuf %p addr 0x%" PRIu64 "\n", __func__, xq->port, xq->q, m, - addr); + dbg("%s(%d, %u), free mbuf %p addr 0x%" PRIu64 "\n", __func__, xq->port, + xq->q, m, addr); rte_pktmbuf_free(m); } xq->stat_tx_free += n; @@ -511,8 +529,8 @@ static void xdp_tx_poll_done(struct mt_xdp_queue* xq) { xsk_ring_cons__release(cq, n); } -static inline void xdp_tx_check_free(struct mt_xdp_queue* xq) { - struct xsk_ring_cons* cq = &xq->tx_cons; +static inline void xdp_tx_check_free(struct mt_xdp_queue *xq) { + struct xsk_ring_cons *cq = &xq->tx_cons; uint32_t cq_avail = xsk_cons_nb_avail(cq, xq->umem_ring_size); dbg("%s(%d, %u), cq_avail %u\n", __func__, port, q, cq_avail); if (cq_avail >= xq->tx_free_thresh) { @@ -520,7 +538,7 @@ static inline void xdp_tx_check_free(struct mt_xdp_queue* xq) { } } -static void xdp_tx_wakeup(struct mt_xdp_queue* xq) { +static void xdp_tx_wakeup(struct mt_xdp_queue *xq) { if (xsk_ring_prod__needs_wakeup(&xq->tx_prod)) { int ret = send(xq->socket_fd, NULL, 0, MSG_DONTWAIT); xq->stat_tx_wakeup++; @@ -533,17 +551,18 @@ static void xdp_tx_wakeup(struct mt_xdp_queue* xq) { } } -static uint16_t xdp_tx(struct mtl_main_impl* impl, struct mt_xdp_queue* xq, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { +static uint16_t xdp_tx(struct mtl_main_impl *impl, struct mt_xdp_queue *xq, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { enum mtl_port port = xq->port; // uint16_t q = xq->q; - struct rte_mempool* mbuf_pool = xq->mbuf_pool; + struct rte_mempool *mbuf_pool = xq->mbuf_pool; uint16_t tx = 0; - struct xsk_ring_prod* pd = &xq->tx_prod; - struct mtl_port_status* stats = mt_if(impl, port)->dev_stats_sw; + struct xsk_ring_prod *pd = &xq->tx_prod; + struct mtl_port_status *stats = mt_if(impl, port)->dev_stats_sw; uint64_t tx_bytes = 0; - xdp_tx_check_free(xq); /* do we need check free threshold for every tx burst */ + xdp_tx_check_free( + xq); /* do we need check free threshold for every tx burst */ uint32_t prod_free = xsk_prod_nb_free(&xq->tx_prod, xq->umem_ring_size); if (prod_free < xq->tx_full_thresh) { /* tx_prod is full */ @@ -552,8 +571,8 @@ static uint16_t xdp_tx(struct mtl_main_impl* impl, struct mt_xdp_queue* xq, } for (uint16_t i = 0; i < nb_pkts; i++) { - struct rte_mbuf* m = tx_pkts[i]; - struct rte_mbuf* local = rte_pktmbuf_alloc(mbuf_pool); + struct rte_mbuf *m = tx_pkts[i]; + struct rte_mbuf *local = rte_pktmbuf_alloc(mbuf_pool); if (!local) { dbg("%s(%d, %u), local mbuf alloc fail\n", __func__, port, q); xq->stat_tx_mbuf_alloc_fail++; @@ -568,20 +587,20 @@ static uint16_t xdp_tx(struct mtl_main_impl* impl, struct mt_xdp_queue* xq, xdp_tx_wakeup(xq); goto exit; } - struct xdp_desc* desc = xsk_ring_prod__tx_desc(pd, idx); + struct xdp_desc *desc = xsk_ring_prod__tx_desc(pd, idx); desc->len = m->pkt_len; - uint64_t addr = - (uint64_t)local - (uint64_t)xq->umem_buffer - xq->mbuf_pool->header_size; - uint64_t offset = - rte_pktmbuf_mtod(local, uint64_t) - (uint64_t)local + xq->mbuf_pool->header_size; - void* pkt = xsk_umem__get_data(xq->umem_buffer, addr + offset); + uint64_t addr = (uint64_t)local - (uint64_t)xq->umem_buffer - + xq->mbuf_pool->header_size; + uint64_t offset = rte_pktmbuf_mtod(local, uint64_t) - (uint64_t)local + + xq->mbuf_pool->header_size; + void *pkt = xsk_umem__get_data(xq->umem_buffer, addr + offset); offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; desc->addr = addr | offset; - struct rte_mbuf* n = m; + struct rte_mbuf *n = m; uint16_t nb_segs = m->nb_segs; for (uint16_t seg = 0; seg < nb_segs; seg++) { - rte_memcpy(pkt, rte_pktmbuf_mtod(n, void*), n->data_len); + rte_memcpy(pkt, rte_pktmbuf_mtod(n, void *), n->data_len); pkt += n->data_len; /* point to next */ n = n->next; @@ -589,8 +608,8 @@ static uint16_t xdp_tx(struct mtl_main_impl* impl, struct mt_xdp_queue* xq, tx_bytes += desc->len; rte_pktmbuf_free(m); - dbg("%s(%d, %u), tx local mbuf %p umem pkt %p addr 0x%" PRIu64 "\n", __func__, port, - q, local, pkt, addr); + dbg("%s(%d, %u), tx local mbuf %p umem pkt %p addr 0x%" PRIu64 "\n", + __func__, port, q, local, pkt, addr); xq->stat_tx_copy++; tx++; } @@ -613,14 +632,15 @@ static uint16_t xdp_tx(struct mtl_main_impl* impl, struct mt_xdp_queue* xq, return tx; } -static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry* entry, struct rte_mbuf* pkt) { +static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry *entry, + struct rte_mbuf *pkt) { enum mtl_port port = entry->port; - struct mt_xdp_queue* xq = entry->xq; + struct mt_xdp_queue *xq = entry->xq; uint16_t q = entry->queue_id; - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); - struct rte_ether_hdr* eth = &hdr->eth; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); + struct rte_ether_hdr *eth = &hdr->eth; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(q); @@ -632,7 +652,8 @@ static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry* entry, struct rte_mbuf* pkt } if (ipv4->next_proto_id != IPPROTO_UDP) { - dbg("%s(%d, %u), wrong next_proto_id %u\n", __func__, port, q, ipv4->next_proto_id); + dbg("%s(%d, %u), wrong next_proto_id %u\n", __func__, port, q, + ipv4->next_proto_id); return false; } @@ -640,8 +661,8 @@ static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry* entry, struct rte_mbuf* pkt uint16_t dst_port = ntohs(udp->dst_port); if (dst_port != entry->flow.dst_port) { xq->stat_rx_pkt_err_udp_port++; - dbg("%s(%d, %u), wrong dst_port %u expect %u\n", __func__, port, q, dst_port, - entry->flow.dst_port); + dbg("%s(%d, %u), wrong dst_port %u expect %u\n", __func__, port, q, + dst_port, entry->flow.dst_port); return false; } } @@ -649,22 +670,23 @@ static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry* entry, struct rte_mbuf* pkt return true; } -static uint16_t xdp_rx(struct mt_rx_xdp_entry* entry, struct rte_mbuf** rx_pkts, +static uint16_t xdp_rx(struct mt_rx_xdp_entry *entry, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) { - struct mt_xdp_queue* xq = entry->xq; + struct mt_xdp_queue *xq = entry->xq; enum mtl_port port = entry->port; uint16_t q = xq->q; - struct xsk_ring_cons* rx_cons = &xq->rx_cons; - struct rte_mempool* mp = xq->mbuf_pool; - struct mtl_port_status* stats = mt_if(entry->parent, port)->dev_stats_sw; + struct xsk_ring_cons *rx_cons = &xq->rx_cons; + struct rte_mempool *mp = xq->mbuf_pool; + struct mtl_port_status *stats = mt_if(entry->parent, port)->dev_stats_sw; uint64_t rx_bytes = 0; uint32_t idx = 0; uint32_t rx = xsk_ring_cons__peek(rx_cons, nb_pkts, &idx); - if (!rx) return 0; + if (!rx) + return 0; xq->stat_rx_burst++; - struct rte_mbuf* fill[rx]; + struct rte_mbuf *fill[rx]; int ret = rte_pktmbuf_alloc_bulk(xq->mbuf_pool, fill, rx); if (ret < 0) { dbg("%s(%d, %u), mbuf alloc bulk %u fail\n", __func__, port, q, rx); @@ -675,7 +697,7 @@ static uint16_t xdp_rx(struct mt_rx_xdp_entry* entry, struct rte_mbuf** rx_pkts, uint32_t valid_rx = 0; for (uint32_t i = 0; i < rx; i++) { - const struct xdp_desc* desc; + const struct xdp_desc *desc; uint64_t addr; uint32_t len; uint64_t offset; @@ -685,9 +707,10 @@ static uint16_t xdp_rx(struct mt_rx_xdp_entry* entry, struct rte_mbuf** rx_pkts, len = desc->len; offset = xsk_umem__extract_offset(addr); addr = xsk_umem__extract_addr(addr); - struct rte_mbuf* pkt = xsk_umem__get_data(xq->umem_buffer, addr + mp->header_size); - pkt->data_off = - offset - sizeof(struct rte_mbuf) - rte_pktmbuf_priv_size(mp) - mp->header_size; + struct rte_mbuf *pkt = + xsk_umem__get_data(xq->umem_buffer, addr + mp->header_size); + pkt->data_off = offset - sizeof(struct rte_mbuf) - + rte_pktmbuf_priv_size(mp) - mp->header_size; rte_pktmbuf_pkt_len(pkt) = len; rte_pktmbuf_data_len(pkt) = len; if (entry->skip_all_check || xdp_rx_check_pkt(entry, pkt)) { @@ -717,8 +740,8 @@ static uint16_t xdp_rx(struct mt_rx_xdp_entry* entry, struct rte_mbuf** rx_pkts, return valid_rx; } -int mt_dev_xdp_init(struct mt_interface* inf) { - struct mtl_main_impl* impl = inf->parent; +int mt_dev_xdp_init(struct mt_interface *inf) { + struct mtl_main_impl *impl = inf->parent; enum mtl_port port = inf->port; int ret; @@ -732,7 +755,8 @@ int mt_dev_xdp_init(struct mt_interface* inf) { return -EIO; } - struct mt_xdp_priv* xdp = mt_rte_zmalloc_socket(sizeof(*xdp), mt_socket_id(impl, port)); + struct mt_xdp_priv *xdp = + mt_rte_zmalloc_socket(sizeof(*xdp), mt_socket_id(impl, port)); if (!xdp) { err("%s(%d), xdp malloc fail\n", __func__, port); return -ENOMEM; @@ -746,8 +770,8 @@ int mt_dev_xdp_init(struct mt_interface* inf) { xdp_parse_drv_name(xdp); - xdp->queues_info = mt_rte_zmalloc_socket(sizeof(*xdp->queues_info) * xdp->queues_cnt, - mt_socket_id(impl, port)); + xdp->queues_info = mt_rte_zmalloc_socket( + sizeof(*xdp->queues_info) * xdp->queues_cnt, mt_socket_id(impl, port)); if (!xdp->queues_info) { err("%s(%d), xdp queues_info malloc fail\n", __func__, port); xdp_free(xdp); @@ -761,7 +785,7 @@ int mt_dev_xdp_init(struct mt_interface* inf) { return -EIO; } - struct mt_xdp_queue* xq = &xdp->queues_info[i]; + struct mt_xdp_queue *xq = &xdp->queues_info[i]; xq->port = port; xq->q = q; xq->umem_ring_size = XSK_RING_CONS__DEFAULT_NUM_DESCS; @@ -789,7 +813,8 @@ int mt_dev_xdp_init(struct mt_interface* inf) { return ret; } - if (0 == strncmp(xdp->drv, "ice", sizeof("ice"))) xdp_parse_pacing_ice(xdp); + if (0 == strncmp(xdp->drv, "ice", sizeof("ice"))) + xdp_parse_pacing_ice(xdp); inf->port_id = inf->port; inf->xdp = xdp; @@ -798,10 +823,11 @@ int mt_dev_xdp_init(struct mt_interface* inf) { return 0; } -int mt_dev_xdp_uinit(struct mt_interface* inf) { - struct mt_xdp_priv* xdp = inf->xdp; - if (!xdp) return 0; - struct mtl_main_impl* impl = inf->parent; +int mt_dev_xdp_uinit(struct mt_interface *inf) { + struct mt_xdp_priv *xdp = inf->xdp; + if (!xdp) + return 0; + struct mtl_main_impl *impl = inf->parent; mt_stat_unregister(impl, xdp_stat_dump, xdp); @@ -811,15 +837,16 @@ int mt_dev_xdp_uinit(struct mt_interface* inf) { return 0; } -struct mt_tx_xdp_entry* mt_tx_xdp_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow, - struct mt_tx_xdp_get_args* args) { +struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow, + struct mt_tx_xdp_get_args *args) { if (!mt_pmd_is_native_af_xdp(impl, port)) { err("%s(%d), this pmd is not native xdp\n", __func__, port); return NULL; } - struct mt_tx_xdp_entry* entry = + struct mt_tx_xdp_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -829,8 +856,8 @@ struct mt_tx_xdp_entry* mt_tx_xdp_get(struct mtl_main_impl* impl, enum mtl_port entry->port = port; rte_memcpy(&entry->flow, flow, sizeof(entry->flow)); - struct mt_xdp_priv* xdp = mt_if(impl, port)->xdp; - struct mt_xdp_queue* xq = NULL; + struct mt_xdp_priv *xdp = mt_if(impl, port)->xdp; + struct mt_xdp_queue *xq = NULL; if (args && args->queue_match) { mt_pthread_mutex_lock(&xdp->queues_lock); @@ -873,18 +900,18 @@ struct mt_tx_xdp_entry* mt_tx_xdp_get(struct mtl_main_impl* impl, enum mtl_port xdp_queue_tx_max_rate(xdp, xq, rate_kbps); } - uint8_t* ip = flow->dip_addr; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], - ip[3], flow->dst_port, entry->queue_id); + uint8_t *ip = flow->dip_addr; + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); return entry; } -int mt_tx_xdp_put(struct mt_tx_xdp_entry* entry) { +int mt_tx_xdp_put(struct mt_tx_xdp_entry *entry) { enum mtl_port port = entry->port; - struct mt_txq_flow* flow = &entry->flow; - uint8_t* ip = flow->dip_addr; - struct mt_xdp_queue* xq = entry->xq; - struct mt_xdp_priv* xdp = mt_if(entry->parent, port)->xdp; + struct mt_txq_flow *flow = &entry->flow; + uint8_t *ip = flow->dip_addr; + struct mt_xdp_queue *xq = entry->xq; + struct mt_xdp_priv *xdp = mt_if(entry->parent, port)->xdp; /* rl settings clear */ if (xdp->flags & XDP_F_RATE_LIMIT) { @@ -897,27 +924,28 @@ int mt_tx_xdp_put(struct mt_tx_xdp_entry* entry) { xdp_queue_tx_stat(xq); xq->tx_entry = NULL; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], - ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); } mt_rte_free(entry); return 0; } -uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return xdp_tx(entry->parent, entry->xq, tx_pkts, nb_pkts); } -static inline int xdp_socket_update_dp(struct mtl_main_impl* impl, int ifindex, +static inline int xdp_socket_update_dp(struct mtl_main_impl *impl, int ifindex, uint16_t dp, bool add) { return mt_instance_update_udp_dp_filter(impl, ifindex, dp, add); } -struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow, - struct mt_rx_xdp_get_args* args) { +struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow, + struct mt_rx_xdp_get_args *args) { if (!mt_pmd_is_native_af_xdp(impl, port)) { err("%s(%d), this pmd is not native xdp\n", __func__, port); return NULL; @@ -925,7 +953,7 @@ struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, enum mtl_port MTL_MAY_UNUSED(args); - struct mt_rx_xdp_entry* entry = + struct mt_rx_xdp_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -936,8 +964,8 @@ struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, enum mtl_port entry->mcast_fd = -1; rte_memcpy(&entry->flow, flow, sizeof(entry->flow)); - struct mt_xdp_priv* xdp = mt_if(impl, port)->xdp; - struct mt_xdp_queue* xq = NULL; + struct mt_xdp_priv *xdp = mt_if(impl, port)->xdp; + struct mt_xdp_queue *xq = NULL; if (args && args->queue_match) { mt_pthread_mutex_lock(&xdp->queues_lock); @@ -982,7 +1010,8 @@ struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, enum mtl_port mt_rx_xdp_put(entry); return NULL; } - if (xdp->has_ctrl && !xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, true)) + if (xdp->has_ctrl && + !xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, true)) entry->skip_all_check = true; else entry->skip_all_check = false; @@ -1000,19 +1029,19 @@ struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, enum mtl_port } entry->mcast_fd = mcast_fd; - uint8_t* ip = flow->dip_addr; - info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], ip[2], - ip[3], flow->dst_port); + uint8_t *ip = flow->dip_addr; + info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], + ip[2], ip[3], flow->dst_port); return entry; } -int mt_rx_xdp_put(struct mt_rx_xdp_entry* entry) { - struct mtl_main_impl* impl = entry->parent; +int mt_rx_xdp_put(struct mt_rx_xdp_entry *entry) { + struct mtl_main_impl *impl = entry->parent; enum mtl_port port = entry->port; - struct mt_rxq_flow* flow = &entry->flow; - uint8_t* ip = flow->dip_addr; - struct mt_xdp_queue* xq = entry->xq; - struct mt_xdp_priv* xdp = mt_if(impl, port)->xdp; + struct mt_rxq_flow *flow = &entry->flow; + uint8_t *ip = flow->dip_addr; + struct mt_xdp_queue *xq = entry->xq; + struct mt_xdp_priv *xdp = mt_if(impl, port)->xdp; if (entry->mcast_fd > 0) { close(entry->mcast_fd); @@ -1022,19 +1051,20 @@ int mt_rx_xdp_put(struct mt_rx_xdp_entry* entry) { if (entry->flow_rsp) { mt_rx_flow_free(impl, port, entry->flow_rsp); entry->flow_rsp = NULL; - if (xdp->has_ctrl) xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, false); + if (xdp->has_ctrl) + xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, false); } if (xq) { xdp_queue_rx_stat(xq); xq->rx_entry = NULL; } - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], - ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); mt_rte_free(entry); return 0; } -uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry* entry, struct rte_mbuf** rx_pkts, - const uint16_t nb_pkts) { +uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return xdp_rx(entry, rx_pkts, nb_pkts); } diff --git a/lib/src/dev/mt_af_xdp.h b/lib/src/dev/mt_af_xdp.h index 914217d42..05dc8581e 100644 --- a/lib/src/dev/mt_af_xdp.h +++ b/lib/src/dev/mt_af_xdp.h @@ -21,40 +21,41 @@ struct mt_rx_xdp_get_args { #ifdef MTL_HAS_XDP_BACKEND -int mt_dev_xdp_init(struct mt_interface* inf); -int mt_dev_xdp_uinit(struct mt_interface* inf); - -struct mt_tx_xdp_entry* mt_tx_xdp_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow, - struct mt_tx_xdp_get_args* args); -int mt_tx_xdp_put(struct mt_tx_xdp_entry* entry); -uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts); - -struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow, - struct mt_rx_xdp_get_args* args); -int mt_rx_xdp_put(struct mt_rx_xdp_entry* entry); -uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry* entry, struct rte_mbuf** rx_pkts, - const uint16_t nb_pkts); +int mt_dev_xdp_init(struct mt_interface *inf); +int mt_dev_xdp_uinit(struct mt_interface *inf); + +struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow, + struct mt_tx_xdp_get_args *args); +int mt_tx_xdp_put(struct mt_tx_xdp_entry *entry); +uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts); + +struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow, + struct mt_rx_xdp_get_args *args); +int mt_rx_xdp_put(struct mt_rx_xdp_entry *entry); +uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); #else #include "../mt_log.h" -static inline int mt_dev_xdp_init(struct mt_interface* inf) { +static inline int mt_dev_xdp_init(struct mt_interface *inf) { err("%s(%d), no xdp support for this build\n", __func__, inf->port); return -ENOTSUP; } -static inline int mt_dev_xdp_uinit(struct mt_interface* inf) { +static inline int mt_dev_xdp_uinit(struct mt_interface *inf) { MTL_MAY_UNUSED(inf); return -ENOTSUP; } -static inline struct mt_tx_xdp_entry* mt_tx_xdp_get(struct mtl_main_impl* impl, - enum mtl_port port, - struct mt_txq_flow* flow, - struct mt_tx_xdp_get_args* args) { +static inline struct mt_tx_xdp_entry * +mt_tx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_txq_flow *flow, struct mt_tx_xdp_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); @@ -62,23 +63,23 @@ static inline struct mt_tx_xdp_entry* mt_tx_xdp_get(struct mtl_main_impl* impl, return NULL; } -static inline int mt_tx_xdp_put(struct mt_tx_xdp_entry* entry) { +static inline int mt_tx_xdp_put(struct mt_tx_xdp_entry *entry) { MTL_MAY_UNUSED(entry); return -ENOTSUP; } -static inline uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry* entry, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { +static inline uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, + struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(tx_pkts); MTL_MAY_UNUSED(nb_pkts); return 0; } -static inline struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, - enum mtl_port port, - struct mt_rxq_flow* flow, - struct mt_rx_xdp_get_args* args) { +static inline struct mt_rx_xdp_entry * +mt_rx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow, struct mt_rx_xdp_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); @@ -86,13 +87,13 @@ static inline struct mt_rx_xdp_entry* mt_rx_xdp_get(struct mtl_main_impl* impl, return NULL; } -static inline int mt_rx_xdp_put(struct mt_rx_xdp_entry* entry) { +static inline int mt_rx_xdp_put(struct mt_rx_xdp_entry *entry) { MTL_MAY_UNUSED(entry); return -ENOTSUP; } -static inline uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry* entry, - struct rte_mbuf** rx_pkts, +static inline uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(rx_pkts); @@ -101,11 +102,11 @@ static inline uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry* entry, } #endif -static inline uint16_t mt_tx_xdp_queue_id(struct mt_tx_xdp_entry* entry) { +static inline uint16_t mt_tx_xdp_queue_id(struct mt_tx_xdp_entry *entry) { return entry->queue_id; } -static inline uint16_t mt_rx_xdp_queue_id(struct mt_rx_xdp_entry* entry) { +static inline uint16_t mt_rx_xdp_queue_id(struct mt_rx_xdp_entry *entry) { return entry->queue_id; } diff --git a/lib/src/dev/mt_dev.c b/lib/src/dev/mt_dev.c index a3434f9e6..8cf9cd384 100644 --- a/lib/src/dev/mt_dev.c +++ b/lib/src/dev/mt_dev.c @@ -79,45 +79,50 @@ static const struct mt_dev_driver_info dev_drvs[] = { .port_type = MT_PORT_DPDK_AF_XDP, .drv_type = MT_DRV_DPDK_AF_XDP, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | - MT_DRV_F_KERNEL_BASED, + .flags = MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | + MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_KERNEL_BASED, }, { .name = "net_af_packet", .port_type = MT_PORT_DPDK_AF_PKT, .drv_type = MT_DRV_DPDK_AF_PKT, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_RX_NO_FLOW | - MT_DRV_F_KERNEL_BASED | MT_DRV_F_MCAST_IN_DP, + .flags = MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | + MT_DRV_F_RX_NO_FLOW | MT_DRV_F_KERNEL_BASED | + MT_DRV_F_MCAST_IN_DP, }, { .name = "kernel_socket", .port_type = MT_PORT_KERNEL_SOCKET, .drv_type = MT_DRV_KERNEL_SOCKET, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | - MT_DRV_F_RX_NO_FLOW | MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, + .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | + MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_NO_FLOW | + MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, }, { .name = "native_af_xdp", .port_type = MT_PORT_NATIVE_AF_XDP, .drv_type = MT_DRV_NATIVE_AF_XDP, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | - MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, + .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | + MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | + MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, }, { .name = "rdma", .port_type = MT_PORT_RDMA_UD, .drv_type = MT_DRV_IRDMA, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | - MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED | + .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | + MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | + MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED | MT_DRV_F_NO_SYS_TX_QUEUE, }, }; -static int parse_driver_info(const char* driver, struct mt_dev_driver_info* drv_info) { +static int parse_driver_info(const char *driver, + struct mt_dev_driver_info *drv_info) { for (int i = 0; i < MTL_ARRAY_SIZE(dev_drvs); i++) { if (!strcmp(dev_drvs[i].name, driver)) { *drv_info = dev_drvs[i]; @@ -125,9 +130,12 @@ static int parse_driver_info(const char* driver, struct mt_dev_driver_info* drv_ } } - warn("%s, unknown nic driver %s, use the default drv info\n", __func__, driver); - warn("%s, use the default drv info, please add one item in dev_drvs array\n", __func__); - *drv_info = dev_drvs[0]; /* the default is always the first one in the arrays */ + warn("%s, unknown nic driver %s, use the default drv info\n", __func__, + driver); + warn("%s, use the default drv info, please add one item in dev_drvs array\n", + __func__); + *drv_info = + dev_drvs[0]; /* the default is always the first one in the arrays */ return 0; } @@ -163,13 +171,14 @@ static void dev_eth_xstat(uint16_t port_id) { } } -static inline void diff_and_update(uint64_t* new, uint64_t* old) { +static inline void diff_and_update(uint64_t *new, uint64_t *old) { uint64_t temp = *new; *new -= *old; *old = temp; } -static void stat_update_dpdk(struct mtl_port_status* sum, struct rte_eth_stats* update, +static void stat_update_dpdk(struct mtl_port_status *sum, + struct rte_eth_stats *update, enum mt_driver_type drv_type) { sum->rx_packets += update->ipackets; sum->tx_packets += update->opackets; @@ -177,12 +186,13 @@ static void stat_update_dpdk(struct mtl_port_status* sum, struct rte_eth_stats* sum->tx_bytes += update->obytes; sum->rx_err_packets += update->ierrors; /* iavf wrong report the tx error */ - if (drv_type != MT_DRV_IAVF) sum->tx_err_packets += update->oerrors; + if (drv_type != MT_DRV_IAVF) + sum->tx_err_packets += update->oerrors; sum->rx_hw_dropped_packets += update->imissed; sum->rx_nombuf_packets += update->rx_nombuf; } -static int dev_inf_get_stat_dpdk(struct mt_interface* inf) { +static int dev_inf_get_stat_dpdk(struct mt_interface *inf) { enum mtl_port port = inf->port; uint16_t port_id = inf->port_id; enum mt_driver_type drv_type = inf->drv_info.drv_type; @@ -198,7 +208,7 @@ static int dev_inf_get_stat_dpdk(struct mt_interface* inf) { return ret; } - struct mtl_port_status* dev_stats_not_reset = inf->dev_stats_not_reset; + struct mtl_port_status *dev_stats_not_reset = inf->dev_stats_not_reset; if (dev_stats_not_reset) { dbg("%s(%d), diff_and_update\n", __func__, port); diff_and_update(&stats.ipackets, &dev_stats_not_reset->rx_packets); @@ -207,15 +217,16 @@ static int dev_inf_get_stat_dpdk(struct mt_interface* inf) { diff_and_update(&stats.obytes, &dev_stats_not_reset->tx_bytes); diff_and_update(&stats.ierrors, &dev_stats_not_reset->rx_err_packets); diff_and_update(&stats.oerrors, &dev_stats_not_reset->tx_err_packets); - diff_and_update(&stats.imissed, &dev_stats_not_reset->rx_hw_dropped_packets); + diff_and_update(&stats.imissed, + &dev_stats_not_reset->rx_hw_dropped_packets); diff_and_update(&stats.rx_nombuf, &dev_stats_not_reset->rx_nombuf_packets); } - struct mtl_port_status* stats_sum = &inf->stats_sum; + struct mtl_port_status *stats_sum = &inf->stats_sum; stat_update_dpdk(stats_sum, &stats, drv_type); - struct mtl_port_status* port_stats = &inf->user_stats_port; + struct mtl_port_status *port_stats = &inf->user_stats_port; stat_update_dpdk(port_stats, &stats, drv_type); - struct mtl_port_status* stats_admin = &inf->stats_admin; + struct mtl_port_status *stats_admin = &inf->stats_admin; stat_update_dpdk(stats_admin, &stats, drv_type); if (!dev_stats_not_reset) { @@ -227,7 +238,8 @@ static int dev_inf_get_stat_dpdk(struct mt_interface* inf) { return 0; } -static void stat_update_sw(struct mtl_port_status* sum, struct mtl_port_status* update) { +static void stat_update_sw(struct mtl_port_status *sum, + struct mtl_port_status *update) { sum->rx_packets += update->rx_packets; sum->tx_packets += update->tx_packets; sum->rx_bytes += update->rx_bytes; @@ -238,16 +250,16 @@ static void stat_update_sw(struct mtl_port_status* sum, struct mtl_port_status* sum->rx_nombuf_packets += update->rx_nombuf_packets; } -static int dev_inf_get_stat_sw(struct mt_interface* inf) { - struct mtl_port_status* stats = inf->dev_stats_sw; +static int dev_inf_get_stat_sw(struct mt_interface *inf) { + struct mtl_port_status *stats = inf->dev_stats_sw; rte_spinlock_lock(&inf->stats_lock); - struct mtl_port_status* stats_sum = &inf->stats_sum; + struct mtl_port_status *stats_sum = &inf->stats_sum; stat_update_sw(stats_sum, stats); - struct mtl_port_status* port_stats = &inf->user_stats_port; + struct mtl_port_status *port_stats = &inf->user_stats_port; stat_update_sw(port_stats, stats); - struct mtl_port_status* stats_admin = &inf->stats_admin; + struct mtl_port_status *stats_admin = &inf->stats_admin; stat_update_sw(stats_admin, stats); memset(stats, 0, sizeof(*stats)); @@ -256,34 +268,37 @@ static int dev_inf_get_stat_sw(struct mt_interface* inf) { return 0; } -static int dev_inf_get_stat(struct mt_interface* inf) { +static int dev_inf_get_stat(struct mt_interface *inf) { if (inf->dev_stats_sw) return dev_inf_get_stat_sw(inf); else return dev_inf_get_stat_dpdk(inf); } -static int dev_inf_stat(void* pri) { - struct mt_interface* inf = pri; - struct mtl_main_impl* impl = inf->parent; +static int dev_inf_stat(void *pri) { + struct mt_interface *inf = pri; + struct mtl_main_impl *impl = inf->parent; enum mtl_port port = inf->port; uint16_t port_id = inf->port_id; - struct mtl_port_status* stats_sum; + struct mtl_port_status *stats_sum; dev_inf_get_stat(inf); stats_sum = &inf->stats_sum; double dump_period_s = mt_stat_dump_period_s(impl); - double orate_m = (double)stats_sum->tx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; - double irate_m = (double)stats_sum->rx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; + double orate_m = + (double)stats_sum->tx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; + double irate_m = + (double)stats_sum->rx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; notice("DEV(%d): Avr rate, tx: %f Mb/s, rx: %f Mb/s, pkts, tx: %" PRIu64 ", rx: %" PRIu64 "\n", port, orate_m, irate_m, stats_sum->tx_packets, stats_sum->rx_packets); if (stats_sum->rx_hw_dropped_packets || stats_sum->rx_err_packets || stats_sum->rx_nombuf_packets || stats_sum->tx_err_packets) { - err("DEV(%d): Status: rx_hw_dropped_packets %" PRIu64 " rx_err_packets %" PRIu64 - " rx_nombuf_packets %" PRIu64 " tx_err_packets %" PRIu64 "\n", + err("DEV(%d): Status: rx_hw_dropped_packets %" PRIu64 + " rx_err_packets %" PRIu64 " rx_nombuf_packets %" PRIu64 + " tx_err_packets %" PRIu64 "\n", port, stats_sum->rx_hw_dropped_packets, stats_sum->rx_err_packets, stats_sum->rx_nombuf_packets, stats_sum->tx_err_packets); dev_eth_xstat(port_id); @@ -301,27 +316,28 @@ static int dev_inf_stat(void* pri) { struct dev_eal_init_args { int argc; - char** argv; + char **argv; int result; }; -static void* dev_eal_init_thread(void* arg) { - struct dev_eal_init_args* init = arg; +static void *dev_eal_init_thread(void *arg) { + struct dev_eal_init_args *init = arg; dbg("%s, start\n", __func__); init->result = rte_eal_init(init->argc, init->argv); return NULL; } -static int dev_eal_init(struct mtl_init_params* p, struct mt_kport_info* kport_info) { - char* argv[MT_EAL_MAX_ARGS]; +static int dev_eal_init(struct mtl_init_params *p, + struct mt_kport_info *kport_info) { + char *argv[MT_EAL_MAX_ARGS]; int argc, ret; int num_ports = RTE_MIN(p->num_ports, MTL_PORT_MAX); static bool eal_initted = false; /* eal cann't re-enter in one process */ bool has_afxdp = false; bool has_afpkt = false; char port_params[MTL_PORT_MAX][2 * MTL_PORT_MAX_LEN]; - char* port_param; + char *port_param; int pci_ports = 0; enum mtl_pmd_type pmd; @@ -343,20 +359,25 @@ static int dev_eal_init(struct mtl_init_params* p, struct mt_kport_info* kport_i for (int i = 0; i < num_ports; i++) { pmd = p->pmd[i]; if (pmd == MTL_PMD_KERNEL_SOCKET) { - const char* if_name = mt_kernel_port2if(p->port[i]); - if (!if_name) return -EINVAL; - snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "kernel_socket_%d", i); + const char *if_name = mt_kernel_port2if(p->port[i]); + if (!if_name) + return -EINVAL; + snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "kernel_socket_%d", + i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); continue; } else if (pmd == MTL_PMD_NATIVE_AF_XDP) { - const char* if_name = mt_native_afxdp_port2if(p->port[i]); - if (!if_name) return -EINVAL; - snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "native_af_xdp_%d", i); + const char *if_name = mt_native_afxdp_port2if(p->port[i]); + if (!if_name) + return -EINVAL; + snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "native_af_xdp_%d", + i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); continue; } else if (pmd == MTL_PMD_RDMA_UD) { - const char* if_name = mt_rdma_ud_port2if(p->port[i]); - if (!if_name) return -EINVAL; + const char *if_name = mt_rdma_ud_port2if(p->port[i]); + if (!if_name) + return -EINVAL; snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "rdma_%d", i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); continue; @@ -379,22 +400,25 @@ static int dev_eal_init(struct mtl_init_params* p, struct mt_kport_info* kport_i uint16_t queue_pair_cnt = RTE_MAX(p->tx_queues_cnt[i], p->rx_queues_cnt[i]); if (p->pmd[i] == MTL_PMD_DPDK_AF_XDP) { - const char* if_name = mt_dpdk_afxdp_port2if(p->port[i]); - if (!if_name) return -EINVAL; + const char *if_name = mt_dpdk_afxdp_port2if(p->port[i]); + if (!if_name) + return -EINVAL; snprintf(port_param, 2 * MTL_PORT_MAX_LEN, - "net_af_xdp%d,iface=%s,start_queue=%u,queue_count=%u", i, if_name, - MT_DPDK_AF_XDP_START_QUEUE, queue_pair_cnt); + "net_af_xdp%d,iface=%s,start_queue=%u,queue_count=%u", i, + if_name, MT_DPDK_AF_XDP_START_QUEUE, queue_pair_cnt); /* save kport info */ snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "net_af_xdp%d", i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); } else if (p->pmd[i] == MTL_PMD_DPDK_AF_PACKET) { - const char* if_name = mt_dpdk_afpkt_port2if(p->port[i]); - if (!if_name) return -EINVAL; + const char *if_name = mt_dpdk_afpkt_port2if(p->port[i]); + if (!if_name) + return -EINVAL; snprintf(port_param, 2 * MTL_PORT_MAX_LEN, - "eth_af_packet%d,iface=%s,framesz=2048,blocksz=4096,qpairs=%u", i, if_name, - queue_pair_cnt + 1); + "eth_af_packet%d,iface=%s,framesz=2048,blocksz=4096,qpairs=%u", + i, if_name, queue_pair_cnt + 1); /* save kport info */ - snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "eth_af_packet%d", i); + snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "eth_af_packet%d", + i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); } else { snprintf(port_param, 2 * MTL_PORT_MAX_LEN, "%s", p->port[i]); @@ -504,24 +528,26 @@ static int dev_eal_init(struct mtl_init_params* p, struct mt_kport_info* kport_i info("%s, wait eal_init_thread done\n", __func__); pthread_join(eal_init_thread, NULL); ret = i_args.result; - if (ret < 0) return ret; + if (ret < 0) + return ret; eal_initted = true; return 0; } -int dev_rx_runtime_queue_start(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_interface* inf = mt_if(impl, port); +int dev_rx_runtime_queue_start(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_interface *inf = mt_if(impl, port); int ret; - struct mt_rx_queue* rx_queue; + struct mt_rx_queue *rx_queue; for (uint16_t q = 0; q < inf->nb_rx_q; q++) { rx_queue = &inf->rx_queues[q]; if (rx_queue->active) { ret = rte_eth_dev_rx_queue_start(inf->port_id, q); if (ret < 0) - err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, ret); + err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, + ret); } } @@ -529,15 +555,17 @@ int dev_rx_runtime_queue_start(struct mtl_main_impl* impl, enum mtl_port port) { } /* flush all the old bufs in the rx queue already */ -static int dev_flush_rx_queue(struct mt_interface* inf, struct mt_rx_queue* queue) { +static int dev_flush_rx_queue(struct mt_interface *inf, + struct mt_rx_queue *queue) { int mbuf_size = 128; int loop = inf->nb_rx_desc / mbuf_size; - struct rte_mbuf* mbuf[mbuf_size]; + struct rte_mbuf *mbuf[mbuf_size]; uint16_t rv; for (int i = 0; i < loop; i++) { rv = mt_dpdk_rx_burst(queue, &mbuf[0], mbuf_size); - if (!rv) break; + if (!rv) + break; rte_pktmbuf_free_bulk(&mbuf[0], rv); } @@ -549,14 +577,16 @@ static int dev_flush_rx_queue(struct mt_interface* inf, struct mt_rx_queue* queu #define ST_DEFAULT_NODE_ID 246 #define ST_DEFAULT_RL_BPS (1024 * 1024 * 1024 / 8) /* 1g bit per second */ -static int dev_rl_init_root(struct mt_interface* inf, uint32_t shaper_profile_id) { +static int dev_rl_init_root(struct mt_interface *inf, + uint32_t shaper_profile_id) { uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; int ret; struct rte_tm_error error; struct rte_tm_node_params np; - if (inf->tx_rl_root_active) return 0; + if (inf->tx_rl_root_active) + return 0; memset(&error, 0, sizeof(error)); memset(&np, 0, sizeof(np)); @@ -572,8 +602,8 @@ static int dev_rl_init_root(struct mt_interface* inf, uint32_t shaper_profile_id } /* nonleaf node based on root */ - ret = - rte_tm_node_add(port_id, ST_DEFAULT_NODE_ID, ST_ROOT_NODE_ID, 0, 1, 1, &np, &error); + ret = rte_tm_node_add(port_id, ST_DEFAULT_NODE_ID, ST_ROOT_NODE_ID, 0, 1, 1, + &np, &error); if (ret < 0) { err("%s(%d), node add error: (%d)%s\n", __func__, port, ret, mt_string_safe(error.message)); @@ -584,8 +614,9 @@ static int dev_rl_init_root(struct mt_interface* inf, uint32_t shaper_profile_id return 0; } -static struct mt_rl_shaper* dev_rl_shaper_add(struct mt_interface* inf, uint64_t bps) { - struct mt_rl_shaper* shapers = &inf->tx_rl_shapers[0]; +static struct mt_rl_shaper *dev_rl_shaper_add(struct mt_interface *inf, + uint64_t bps) { + struct mt_rl_shaper *shapers = &inf->tx_rl_shapers[0]; uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; int ret; @@ -596,7 +627,8 @@ static struct mt_rl_shaper* dev_rl_shaper_add(struct mt_interface* inf, uint64_t memset(&error, 0, sizeof(error)); for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (shapers[i].rl_bps) continue; + if (shapers[i].rl_bps) + continue; shaper_profile_id = ST_SHAPER_PROFILE_ID + i; @@ -629,28 +661,30 @@ static struct mt_rl_shaper* dev_rl_shaper_add(struct mt_interface* inf, uint64_t return NULL; } -static struct mt_rl_shaper* dev_rl_shaper_get(struct mt_interface* inf, uint64_t bps) { - struct mt_rl_shaper* shapers = &inf->tx_rl_shapers[0]; +static struct mt_rl_shaper *dev_rl_shaper_get(struct mt_interface *inf, + uint64_t bps) { + struct mt_rl_shaper *shapers = &inf->tx_rl_shapers[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (bps == shapers[i].rl_bps) return &shapers[i]; + if (bps == shapers[i].rl_bps) + return &shapers[i]; } return dev_rl_shaper_add(inf, bps); } -static int dev_init_ratelimit_all(struct mt_interface* inf) { +static int dev_init_ratelimit_all(struct mt_interface *inf) { uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; int ret; struct rte_tm_error error; struct rte_tm_node_params qp; - struct mt_rl_shaper* shaper; + struct mt_rl_shaper *shaper; uint64_t bps = ST_DEFAULT_RL_BPS; memset(&error, 0, sizeof(error)); - struct mt_tx_queue* tx_queue; + struct mt_tx_queue *tx_queue; for (uint16_t q = 0; q < inf->nb_tx_q; q++) { tx_queue = &inf->tx_queues[q]; @@ -684,16 +718,16 @@ static int dev_init_ratelimit_all(struct mt_interface* inf) { return ret; } -static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue, +static int dev_tx_queue_set_rl_rate(struct mt_interface *inf, uint16_t queue, uint64_t bytes_per_sec) { uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; - struct mt_tx_queue* tx_queue = &inf->tx_queues[queue]; + struct mt_tx_queue *tx_queue = &inf->tx_queues[queue]; uint64_t bps = bytes_per_sec; int ret; struct rte_tm_error error; struct rte_tm_node_params qp; - struct mt_rl_shaper* shaper; + struct mt_rl_shaper *shaper; memset(&error, 0, sizeof(error)); @@ -702,7 +736,8 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue, } /* not changed */ - if (bps == tx_queue->bps) return 0; + if (bps == tx_queue->bps) + return 0; /* delete old queue node */ if (tx_queue->rl_shapers_mapping >= 0) { @@ -725,15 +760,16 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue, qp.shaper_profile_id = shaper->shaper_profile_id; qp.leaf.cman = RTE_TM_CMAN_TAIL_DROP; qp.leaf.wred.wred_profile_id = RTE_TM_WRED_PROFILE_ID_NONE; - ret = rte_tm_node_add(port_id, queue, ST_DEFAULT_NODE_ID, 0, 1, 2, &qp, &error); + ret = rte_tm_node_add(port_id, queue, ST_DEFAULT_NODE_ID, 0, 1, 2, &qp, + &error); if (ret < 0) { err("%s(%d), q %d add fail %d(%s)\n", __func__, port, queue, ret, mt_string_safe(error.message)); return ret; } tx_queue->rl_shapers_mapping = shaper->idx; - info("%s(%d), q %d link to shaper id %d(%" PRIu64 ")\n", __func__, port, queue, - shaper->shaper_profile_id, shaper->rl_bps); + info("%s(%d), q %d link to shaper id %d(%" PRIu64 ")\n", __func__, port, + queue, shaper->shaper_profile_id, shaper->rl_bps); } mt_pthread_mutex_lock(&inf->vf_cmd_mutex); @@ -750,7 +786,7 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface* inf, uint16_t queue, return 0; } -static int dev_stop_port(struct mt_interface* inf) { +static int dev_stop_port(struct mt_interface *inf) { int ret; uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; @@ -762,7 +798,8 @@ static int dev_stop_port(struct mt_interface* inf) { if (!(inf->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD)) { ret = rte_eth_dev_stop(port_id); - if (ret < 0) err("%s(%d), rte_eth_dev_stop fail %d\n", __func__, port, ret); + if (ret < 0) + err("%s(%d), rte_eth_dev_stop fail %d\n", __func__, port, ret); } inf->status &= ~MT_IF_STAT_PORT_STARTED; @@ -770,7 +807,7 @@ static int dev_stop_port(struct mt_interface* inf) { return 0; } -static int dev_close_port(struct mt_interface* inf) { +static int dev_close_port(struct mt_interface *inf) { int ret; uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; @@ -782,7 +819,8 @@ static int dev_close_port(struct mt_interface* inf) { if (!(inf->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD)) { ret = rte_eth_dev_close(port_id); - if (ret < 0) err("%s(%d), rte_eth_dev_close fail %d\n", __func__, port, ret); + if (ret < 0) + err("%s(%d), rte_eth_dev_close fail %d\n", __func__, port, ret); } inf->status &= ~MT_IF_STAT_PORT_CONFIGURED; @@ -790,7 +828,7 @@ static int dev_close_port(struct mt_interface* inf) { return 0; } -static int dev_detect_link(struct mt_interface* inf) { +static int dev_detect_link(struct mt_interface *inf) { /* get link speed for the port */ struct rte_eth_link eth_link; uint16_t port_id = inf->port_id; @@ -819,7 +857,7 @@ static int dev_detect_link(struct mt_interface* inf) { return -EIO; } -static int dev_start_timesync(struct mt_interface* inf) { +static int dev_start_timesync(struct mt_interface *inf) { int ret, i = 0, max_retry = 10; uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; @@ -848,8 +886,8 @@ static int dev_start_timesync(struct mt_interface* inf) { info("%s(%d), init ptp time %s, i %d\n", __func__, port, date_time, i); break; } - dbg("%s(%d), tv_sec %" PRIu64 " tv_nsec %" PRIu64 ", i %d\n", __func__, port, - spec.tv_sec, spec.tv_nsec, i); + dbg("%s(%d), tv_sec %" PRIu64 " tv_nsec %" PRIu64 ", i %d\n", __func__, + port, spec.tv_sec, spec.tv_nsec, i); mt_sleep_ms(10); } if (i >= max_retry) { @@ -865,7 +903,7 @@ static const struct rte_eth_conf dev_port_conf = {.txmode = { }}; /* 1:1 map with hash % reta_size % nb_rx_q */ -static int dev_config_rss_reta(struct mt_interface* inf) { +static int dev_config_rss_reta(struct mt_interface *inf) { enum mtl_port port = inf->port; uint16_t reta_size = inf->dev_info.reta_size; int reta_group_size = reta_size / RTE_ETH_RETA_GROUP_SIZE; @@ -889,13 +927,13 @@ static int dev_config_rss_reta(struct mt_interface* inf) { return 0; } -static int dev_config_port(struct mt_interface* inf) { - struct mtl_main_impl* impl = inf->parent; +static int dev_config_port(struct mt_interface *inf) { + struct mtl_main_impl *impl = inf->parent; uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; uint16_t nb_rx_desc = MT_DEV_RX_DESC, nb_tx_desc = MT_DEV_TX_DESC; int ret; - struct mtl_init_params* p = mt_get_user_params(impl); + struct mtl_init_params *p = mt_get_user_params(impl); uint16_t nb_rx_q = inf->nb_rx_q, nb_tx_q = inf->nb_tx_q; struct rte_eth_conf port_conf = dev_port_conf; @@ -903,8 +941,9 @@ static int dev_config_port(struct mt_interface* inf) { inf->nb_tx_desc = nb_tx_desc; inf->nb_rx_desc = nb_rx_desc; inf->status |= MT_IF_STAT_PORT_CONFIGURED; - info("%s(%d), not dpdk based tx_q(%d with %d desc) rx_q (%d with %d desc)\n", - __func__, port, nb_tx_q, nb_tx_desc, nb_rx_q, nb_rx_desc); + info( + "%s(%d), not dpdk based tx_q(%d with %d desc) rx_q (%d with %d desc)\n", + __func__, port, nb_tx_q, nb_tx_desc, nb_rx_q, nb_rx_desc); return 0; } @@ -934,7 +973,7 @@ static int dev_config_port(struct mt_interface* inf) { dbg("%s(%d), rss mode %d\n", __func__, port, inf->rss_mode); if (mt_has_srss(impl, port)) { - struct rte_eth_rss_conf* rss_conf; + struct rte_eth_rss_conf *rss_conf; rss_conf = &port_conf.rx_adv_conf.rss_conf; rss_conf->rss_key = NULL; @@ -946,9 +985,10 @@ static int dev_config_port(struct mt_interface* inf) { err("%s(%d), not support rss_mode %d\n", __func__, port, inf->rss_mode); return -EIO; } - if (rss_conf->rss_hf != (inf->dev_info.flow_type_rss_offloads & rss_conf->rss_hf)) { - err("%s(%d), not support rss offload %" PRIx64 ", mode %d\n", __func__, port, - rss_conf->rss_hf, inf->rss_mode); + if (rss_conf->rss_hf != + (inf->dev_info.flow_type_rss_offloads & rss_conf->rss_hf)) { + err("%s(%d), not support rss offload %" PRIx64 ", mode %d\n", __func__, + port, rss_conf->rss_hf, inf->rss_mode); return -EIO; } port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_RSS; @@ -964,18 +1004,22 @@ static int dev_config_port(struct mt_interface* inf) { port_conf = dev_port_conf; ret = rte_eth_dev_configure(inf->virtio_port_id, 1, 1, &port_conf); if (ret < 0) { - err("%s(%d), rte_eth_dev_configure virtio port fail %d\n", __func__, port, ret); + err("%s(%d), rte_eth_dev_configure virtio port fail %d\n", __func__, port, + ret); return ret; } } /* apply if user has rx_tx_desc config */ - if (p->nb_tx_desc) nb_tx_desc = p->nb_tx_desc; - if (p->nb_rx_desc) nb_rx_desc = p->nb_rx_desc; + if (p->nb_tx_desc) + nb_tx_desc = p->nb_tx_desc; + if (p->nb_rx_desc) + nb_rx_desc = p->nb_rx_desc; ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_id, &nb_rx_desc, &nb_tx_desc); if (ret < 0) { - err("%s(%d), rte_eth_dev_adjust_nb_rx_tx_desc fail %d\n", __func__, port, ret); + err("%s(%d), rte_eth_dev_adjust_nb_rx_tx_desc fail %d\n", __func__, port, + ret); return ret; } inf->nb_tx_desc = nb_tx_desc; @@ -986,10 +1030,10 @@ static int dev_config_port(struct mt_interface* inf) { uint32_t set_ptypes[16]; uint32_t ptype_mask = RTE_PTYPE_L2_ETHER_TIMESYNC | RTE_PTYPE_L2_ETHER_ARP | RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L2_ETHER_QINQ | - RTE_PTYPE_L4_ICMP | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP | - RTE_PTYPE_L4_FRAG; - int num_ptypes = - rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, ptypes, RTE_DIM(ptypes)); + RTE_PTYPE_L4_ICMP | RTE_PTYPE_L3_IPV4 | + RTE_PTYPE_L4_UDP | RTE_PTYPE_L4_FRAG; + int num_ptypes = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, ptypes, + RTE_DIM(ptypes)); for (int i = 0; i < num_ptypes; i++) { set_ptypes[i] = ptypes[i]; } @@ -1000,29 +1044,30 @@ static int dev_config_port(struct mt_interface* inf) { return ret; } } else { - warn("%s(%d), failed to setup all ptype, only %d supported\n", __func__, port, - num_ptypes); + warn("%s(%d), failed to setup all ptype, only %d supported\n", __func__, + port, num_ptypes); } inf->status |= MT_IF_STAT_PORT_CONFIGURED; - info("%s(%d), tx_q(%d with %d desc) rx_q (%d with %d desc)\n", __func__, port, nb_tx_q, - nb_tx_desc, nb_rx_q, nb_rx_desc); + info("%s(%d), tx_q(%d with %d desc) rx_q (%d with %d desc)\n", __func__, port, + nb_tx_q, nb_tx_desc, nb_rx_q, nb_rx_desc); return 0; } #if !MT_DEV_SIMULATE_MALICIOUS_PKT -static bool dev_pkt_valid(struct mt_interface* inf, uint16_t queue, - struct rte_mbuf* pkt) { +static bool dev_pkt_valid(struct mt_interface *inf, uint16_t queue, + struct rte_mbuf *pkt) { uint32_t pkt_len = pkt->pkt_len; enum mtl_port port = inf->port; if ((pkt_len <= 16) || (pkt_len > MTL_MTU_MAX_BYTES)) { - err("%s(%d:%u), invalid pkt_len %u at %p\n", __func__, port, queue, pkt_len, pkt); + err("%s(%d:%u), invalid pkt_len %u at %p\n", __func__, port, queue, pkt_len, + pkt); return false; } if (pkt->nb_segs > 2) { - err("%s(%d:%u), invalid nb_segs %u at %p\n", __func__, port, queue, pkt->nb_segs, - pkt); + err("%s(%d:%u), invalid nb_segs %u at %p\n", __func__, port, queue, + pkt->nb_segs, pkt); return false; } @@ -1030,9 +1075,10 @@ static bool dev_pkt_valid(struct mt_interface* inf, uint16_t queue, } #endif -static uint16_t dev_tx_pkt_check(uint16_t port, uint16_t queue, struct rte_mbuf** pkts, - uint16_t nb_pkts, void* priv) { - struct mt_interface* inf = priv; +static uint16_t dev_tx_pkt_check(uint16_t port, uint16_t queue, + struct rte_mbuf **pkts, uint16_t nb_pkts, + void *priv) { + struct mt_interface *inf = priv; MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(nb_pkts); @@ -1062,9 +1108,9 @@ static uint16_t dev_tx_pkt_check(uint16_t port, uint16_t queue, struct rte_mbuf* return nb_pkts; } -static int dev_start_port(struct mt_interface* inf) { +static int dev_start_port(struct mt_interface *inf) { int ret; - struct mtl_main_impl* impl = inf->parent; + struct mtl_main_impl *impl = inf->parent; uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; int socket_id = inf->socket_id; @@ -1081,10 +1127,11 @@ static int dev_start_port(struct mt_interface* inf) { return 0; } - if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) rx_deferred_start = 1; + if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) + rx_deferred_start = 1; rx_port_conf.rx_deferred_start = rx_deferred_start; - struct rte_mempool* mbuf_pool; + struct rte_mempool *mbuf_pool; for (uint16_t q = 0; q < nb_rx_q; q++) { mbuf_pool = inf->rx_queues[q].mbuf_pool ? inf->rx_queues[q].mbuf_pool : mt_sys_rx_mempool(impl, port); @@ -1104,7 +1151,7 @@ static int dev_start_port(struct mt_interface* inf) { info("%s(%d), enable hdr split for queue %d\n", __func__, port, q); /* two segments */ union rte_eth_rxseg rx_usegs[2] = {}; - struct rte_eth_rxseg_split* rx_seg; + struct rte_eth_rxseg_split *rx_seg; rx_seg = &rx_usegs[0].split; #if RTE_VERSION >= RTE_VERSION_NUM(22, 11, 0, 0) @@ -1127,29 +1174,30 @@ static int dev_start_port(struct mt_interface* inf) { rx_port_conf.rx_nseg = 2; rx_port_conf.rx_seg = rx_usegs; - ret = - rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, &rx_port_conf, NULL); + ret = rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, + &rx_port_conf, NULL); #else err("%s, no hdr split support for this dpdk build\n", __func__); return -ENOTSUP; #endif } else { - ret = rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, &rx_port_conf, - mbuf_pool); + ret = rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, + &rx_port_conf, mbuf_pool); } if (ret < 0) { - err("%s(%d), rte_eth_rx_queue_setup fail %d for queue %d\n", __func__, port, ret, - q); + err("%s(%d), rte_eth_rx_queue_setup fail %d for queue %d\n", __func__, + port, ret, q); return ret; } } for (uint16_t q = 0; q < nb_tx_q; q++) { tx_port_conf = inf->dev_info.default_txconf; - ret = rte_eth_tx_queue_setup(port_id, q, nb_tx_desc, socket_id, &tx_port_conf); + ret = rte_eth_tx_queue_setup(port_id, q, nb_tx_desc, socket_id, + &tx_port_conf); if (ret < 0) { - err("%s(%d), rte_eth_tx_queue_setup fail %d for queue %d\n", __func__, port, ret, - q); + err("%s(%d), rte_eth_tx_queue_setup fail %d for queue %d\n", __func__, + port, ret, q); return ret; } } @@ -1169,21 +1217,23 @@ static int dev_start_port(struct mt_interface* inf) { if (mt_has_virtio_user(impl, port)) { mbuf_pool = inf->rx_queues[0].mbuf_pool ? inf->rx_queues[0].mbuf_pool : mt_sys_rx_mempool(impl, port); - ret = rte_eth_rx_queue_setup(inf->virtio_port_id, 0, 0, socket_id, NULL, mbuf_pool); + ret = rte_eth_rx_queue_setup(inf->virtio_port_id, 0, 0, socket_id, NULL, + mbuf_pool); if (ret < 0) { - err("%s(%d), rte_eth_rx_queue_setup fail %d for virtio port\n", __func__, port, - ret); + err("%s(%d), rte_eth_rx_queue_setup fail %d for virtio port\n", __func__, + port, ret); return ret; } ret = rte_eth_tx_queue_setup(inf->virtio_port_id, 0, 0, socket_id, NULL); if (ret < 0) { - err("%s(%d), rte_eth_tx_queue_setup fail %d for virtio port\n", __func__, port, - ret); + err("%s(%d), rte_eth_tx_queue_setup fail %d for virtio port\n", __func__, + port, ret); return ret; } ret = rte_eth_dev_start(inf->virtio_port_id); if (ret < 0) { - err("%s(%d), rte_eth_dev_start virtio port fail %d\n", __func__, port, ret); + err("%s(%d), rte_eth_dev_start virtio port fail %d\n", __func__, port, + ret); return ret; } } @@ -1209,11 +1259,12 @@ static int dev_start_port(struct mt_interface* inf) { return 0; } -static int dev_if_uinit_rx_queues(struct mt_interface* inf) { +static int dev_if_uinit_rx_queues(struct mt_interface *inf) { enum mtl_port port = inf->port; - struct mt_rx_queue* rx_queue; + struct mt_rx_queue *rx_queue; - if (!inf->rx_queues) return 0; + if (!inf->rx_queues) + return 0; for (uint16_t q = 0; q < inf->nb_rx_q; q++) { rx_queue = &inf->rx_queues[q]; @@ -1242,13 +1293,16 @@ static int dev_if_uinit_rx_queues(struct mt_interface* inf) { return 0; } -static int dev_if_init_rx_queues(struct mtl_main_impl* impl, struct mt_interface* inf) { - if (!inf->nb_rx_q) return 0; +static int dev_if_init_rx_queues(struct mtl_main_impl *impl, + struct mt_interface *inf) { + if (!inf->nb_rx_q) + return 0; - struct mt_rx_queue* rx_queues = + struct mt_rx_queue *rx_queues = mt_rte_zmalloc_socket(sizeof(*rx_queues) * inf->nb_rx_q, inf->socket_id); if (!rx_queues) { - err("%s(%d), rx_queues zmalloc fail, queues %u\n", __func__, inf->port, inf->nb_rx_q); + err("%s(%d), rx_queues zmalloc fail, queues %u\n", __func__, inf->port, + inf->nb_rx_q); return -ENOMEM; } @@ -1261,9 +1315,9 @@ static int dev_if_init_rx_queues(struct mtl_main_impl* impl, struct mt_interface /* Create mempool to hold the rx queue mbufs. */ unsigned int mbuf_elements = inf->nb_rx_desc + 1024; char pool_name[ST_MAX_NAME_LEN]; - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_MBUF", MT_RX_MEMPOOL_PREFIX, - inf->port, q); - struct rte_mempool* mbuf_pool = NULL; + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_MBUF", + MT_RX_MEMPOOL_PREFIX, inf->port, q); + struct rte_mempool *mbuf_pool = NULL; if (inf->drv_info.flags & MT_DRV_F_RX_POOL_COMMON) { /* no priv for af_xdp/af_packet/rdma_ud */ @@ -1271,7 +1325,8 @@ static int dev_if_init_rx_queues(struct mtl_main_impl* impl, struct mt_interface MT_MBUF_CACHE_SIZE, 0, 2048); } else { if (q < inf->system_rx_queues_end) - mbuf_pool = mt_mempool_create_common(impl, inf->port, pool_name, mbuf_elements); + mbuf_pool = mt_mempool_create_common(impl, inf->port, pool_name, + mbuf_elements); else { uint16_t data_room_sz = ST_PKT_MAX_ETHER_BYTES; /* to avoid igc/igxbe nic split mbuf */ @@ -1280,9 +1335,9 @@ static int dev_if_init_rx_queues(struct mtl_main_impl* impl, struct mt_interface data_room_sz = MT_MBUF_DEFAULT_DATA_SIZE; if (impl->rx_pool_data_size) /* user suggested data room size */ data_room_sz = impl->rx_pool_data_size; - mbuf_pool = mt_mempool_create(impl, inf->port, pool_name, mbuf_elements, - MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), data_room_sz); + mbuf_pool = mt_mempool_create( + impl, inf->port, pool_name, mbuf_elements, MT_MBUF_CACHE_SIZE, + sizeof(struct mt_muf_priv_data), data_room_sz); } } if (!mbuf_pool) { @@ -1293,17 +1348,18 @@ static int dev_if_init_rx_queues(struct mtl_main_impl* impl, struct mt_interface rx_queues[q].mbuf_elements = mbuf_elements; /* hdr split payload mbuf */ - if ((q >= inf->system_rx_queues_end) && (q < inf->hdr_split_rx_queues_end)) { + if ((q >= inf->system_rx_queues_end) && + (q < inf->hdr_split_rx_queues_end)) { if (!mt_if_has_hdr_split(impl, inf->port)) { err("%s(%d), no hdr split feature\n", __func__, inf->port); dev_if_uinit_rx_queues(inf); return -EIO; } - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_PAYLOAD", MT_RX_MEMPOOL_PREFIX, - inf->port, q); - mbuf_pool = mt_mempool_create(impl, inf->port, pool_name, mbuf_elements, - MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), - ST_PKT_MAX_ETHER_BYTES); + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_PAYLOAD", + MT_RX_MEMPOOL_PREFIX, inf->port, q); + mbuf_pool = mt_mempool_create( + impl, inf->port, pool_name, mbuf_elements, MT_MBUF_CACHE_SIZE, + sizeof(struct mt_muf_priv_data), ST_PKT_MAX_ETHER_BYTES); if (!mbuf_pool) { dev_if_uinit_rx_queues(inf); return -ENOMEM; @@ -1318,11 +1374,12 @@ static int dev_if_init_rx_queues(struct mtl_main_impl* impl, struct mt_interface return 0; } -static int dev_if_uinit_tx_queues(struct mt_interface* inf) { +static int dev_if_uinit_tx_queues(struct mt_interface *inf) { enum mtl_port port = inf->port; - struct mt_tx_queue* tx_queue; + struct mt_tx_queue *tx_queue; - if (!inf->tx_queues) return 0; + if (!inf->tx_queues) + return 0; for (uint16_t q = 0; q < inf->nb_tx_q; q++) { tx_queue = &inf->tx_queues[q]; @@ -1337,13 +1394,15 @@ static int dev_if_uinit_tx_queues(struct mt_interface* inf) { return 0; } -static int dev_if_init_tx_queues(struct mt_interface* inf) { - if (!inf->nb_tx_q) return 0; +static int dev_if_init_tx_queues(struct mt_interface *inf) { + if (!inf->nb_tx_q) + return 0; - struct mt_tx_queue* tx_queues = + struct mt_tx_queue *tx_queues = mt_rte_zmalloc_socket(sizeof(*tx_queues) * inf->nb_tx_q, inf->socket_id); if (!tx_queues) { - err("%s(%d), tx_queues %u malloc alloc\n", __func__, inf->port, inf->nb_tx_q); + err("%s(%d), tx_queues %u malloc alloc\n", __func__, inf->port, + inf->nb_tx_q); return -ENOMEM; } @@ -1360,7 +1419,7 @@ static int dev_if_init_tx_queues(struct mt_interface* inf) { } /* detect pacing */ -static int dev_if_init_pacing(struct mt_interface* inf) { +static int dev_if_init_pacing(struct mt_interface *inf) { enum mtl_port port = inf->port; int ret; bool auto_detect = false; @@ -1398,7 +1457,8 @@ static int dev_if_init_pacing(struct mt_interface* inf) { ret = dev_init_ratelimit_all(inf); } else { ret = dev_tx_queue_set_rl_rate(inf, 0, ST_DEFAULT_RL_BPS); - if (ret >= 0) dev_tx_queue_set_rl_rate(inf, 0, 0); + if (ret >= 0) + dev_tx_queue_set_rl_rate(inf, 0, 0); } if (ret < 0) { /* fallback to tsc if no rl */ if (auto_detect) { @@ -1414,10 +1474,10 @@ static int dev_if_init_pacing(struct mt_interface* inf) { return 0; } -static int dev_if_init_virtio_user(struct mt_interface* inf) { +static int dev_if_init_virtio_user(struct mt_interface *inf) { #ifndef WINDOWSENV enum mtl_port port = inf->port; - struct mtl_main_impl* impl = inf->parent; + struct mtl_main_impl *impl = inf->parent; uint16_t port_id = inf->port_id; int ret; char name[IF_NAMESIZE]; @@ -1430,7 +1490,8 @@ static int dev_if_init_virtio_user(struct mt_interface* inf) { (uint8_t)port_id); /* to limit name length, assume port_id < 255 */ snprintf( args, sizeof(args), - "path=/dev/vhost-net,queues=1,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, + "path=/dev/" + "vhost-net,queues=1,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, 1024, name, RTE_ETHER_ADDR_BYTES(&addr)); ret = rte_eal_hotplug_add("vdev", name, args); @@ -1447,7 +1508,8 @@ static int dev_if_init_virtio_user(struct mt_interface* inf) { } inf->virtio_port_id = virtio_port_id; - ret = mt_socket_set_if_ip(name, mt_sip_addr(impl, port), mt_sip_netmask(impl, port)); + ret = mt_socket_set_if_ip(name, mt_sip_addr(impl, port), + mt_sip_netmask(impl, port)); if (ret < 0) { err("%s(%d), cannot set interface ip\n", __func__, port); return ret; @@ -1472,35 +1534,37 @@ static int dev_if_init_virtio_user(struct mt_interface* inf) { #endif } -static uint64_t ptp_from_real_time(struct mtl_main_impl* impl, enum mtl_port port) { +static uint64_t ptp_from_real_time(struct mtl_main_impl *impl, + enum mtl_port port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); return mt_get_real_time(); } -static uint64_t ptp_from_user(struct mtl_main_impl* impl, enum mtl_port port) { - struct mtl_init_params* p = mt_get_user_params(impl); +static uint64_t ptp_from_user(struct mtl_main_impl *impl, enum mtl_port port) { + struct mtl_init_params *p = mt_get_user_params(impl); MTL_MAY_UNUSED(port); return p->ptp_get_time_fn(p->priv); } -static uint64_t ptp_from_tsc(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_interface* inf = mt_if(impl, port); +static uint64_t ptp_from_tsc(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_interface *inf = mt_if(impl, port); uint64_t tsc = mt_get_tsc(impl); return inf->real_time_base + tsc - inf->tsc_time_base; } -struct mt_tx_queue* mt_dev_get_tx_queue(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow) { - struct mt_interface* inf = mt_if(impl, port); +struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow) { + struct mt_interface *inf = mt_if(impl, port); uint64_t bytes_per_sec = flow->bytes_per_sec; - struct mt_tx_queue* tx_queue; + struct mt_tx_queue *tx_queue; int ret; if (mt_user_shared_txq(impl, port)) { - err("%s(%d), conflict with shared tx queue mode, use tsq api instead\n", __func__, - port); + err("%s(%d), conflict with shared tx queue mode, use tsq api instead\n", + __func__, port); return NULL; } @@ -1509,21 +1573,24 @@ struct mt_tx_queue* mt_dev_get_tx_queue(struct mtl_main_impl* impl, enum mtl_por if ((ST21_TX_PACING_WAY_TSN == inf->tx_pacing_way) && (MT_DRV_IGC == inf->drv_info.drv_type)) { /* - * igc corresponding network card i225/i226, implements TSN pacing based on - * LaunchTime Tx feature. Currently, igc driver enables LaunchTime Tx feature - * of queue 0 by hard coding static configuration. So, traffic requires - * LaunchTime based pacing must be transmitted over queue 0. + * igc corresponding network card i225/i226, implements TSN pacing based + * on LaunchTime Tx feature. Currently, igc driver enables LaunchTime Tx + * feature of queue 0 by hard coding static configuration. So, traffic + * requires LaunchTime based pacing must be transmitted over queue 0. */ if (flow->flags & MT_TXQ_FLOW_F_LAUNCH_TIME) { /* If require LaunchTime based pacing, queue 0 is the only choice. */ - if (q != 0) break; + if (q != 0) + break; } else { /* If not require LaunchTime based pacing, queue 0 is invisible. */ - if (q == 0) continue; + if (q == 0) + continue; } } tx_queue = &inf->tx_queues[q]; - if (tx_queue->active || tx_queue->fatal_error) continue; + if (tx_queue->active || tx_queue->fatal_error) + continue; if (inf->tx_pacing_way == ST21_TX_PACING_WAY_RL) { ret = dev_tx_queue_set_rl_rate(inf, q, bytes_per_sec); @@ -1548,43 +1615,50 @@ struct mt_tx_queue* mt_dev_get_tx_queue(struct mtl_main_impl* impl, enum mtl_por return NULL; } -struct mt_rx_queue* mt_dev_get_rx_queue(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow) { - struct mt_interface* inf = mt_if(impl, port); +struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow) { + struct mt_interface *inf = mt_if(impl, port); int ret; - struct mt_rx_queue* rx_queue; + struct mt_rx_queue *rx_queue; if (mt_has_srss(impl, port)) { - err("%s(%d), conflict with srss mode, use srss api instead\n", __func__, port); + err("%s(%d), conflict with srss mode, use srss api instead\n", __func__, + port); return NULL; } if (mt_user_shared_rxq(impl, port)) { - err("%s(%d), conflict with shared rx queue mode, use rsq api instead\n", __func__, - port); + err("%s(%d), conflict with shared rx queue mode, use rsq api instead\n", + __func__, port); return NULL; } mt_pthread_mutex_lock(&inf->rx_queues_mutex); for (uint16_t q = 0; q < inf->nb_rx_q; q++) { rx_queue = &inf->rx_queues[q]; - if (rx_queue->active) continue; + if (rx_queue->active) + continue; if (flow && (flow->flags & MT_RXQ_FLOW_F_HDR_SPLIT)) { /* continue if not hdr split queue */ - if (!mt_if_hdr_split_pool(inf, q)) continue; + if (!mt_if_hdr_split_pool(inf, q)) + continue; #ifdef ST_HAS_DPDK_HDR_SPLIT if (flow->hdr_split_mbuf_cb) { - ret = rte_eth_hdrs_set_mbuf_callback( - inf->port_id, q, flow->hdr_split_mbuf_cb_priv, flow->hdr_split_mbuf_cb); + ret = rte_eth_hdrs_set_mbuf_callback(inf->port_id, q, + flow->hdr_split_mbuf_cb_priv, + flow->hdr_split_mbuf_cb); if (ret < 0) { - err("%s(%d), hdrs callback fail %d for queue %d\n", __func__, port, ret, q); + err("%s(%d), hdrs callback fail %d for queue %d\n", __func__, port, + ret, q); mt_pthread_mutex_unlock(&inf->rx_queues_mutex); return NULL; } } #endif } else { /* continue if hdr split queue */ - if (mt_if_hdr_split_pool(inf, q)) continue; + if (mt_if_hdr_split_pool(inf, q)) + continue; } /* free the dummy flow if any */ @@ -1607,7 +1681,8 @@ struct mt_rx_queue* mt_dev_get_rx_queue(struct mtl_main_impl* impl, enum mtl_por if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) { ret = rte_eth_dev_rx_queue_start(inf->port_id, q); if (ret < 0) { - err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, ret); + err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, + ret); if (rx_queue->flow_rsp) { mt_rx_flow_free(impl, port, rx_queue->flow_rsp); rx_queue->flow_rsp = NULL; @@ -1621,9 +1696,9 @@ struct mt_rx_queue* mt_dev_get_rx_queue(struct mtl_main_impl* impl, enum mtl_por dev_flush_rx_queue(inf, rx_queue); if (flow) { - uint8_t* ip = flow->dip_addr; - info("%s(%d), q %u ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], - ip[2], ip[3], flow->dst_port); + uint8_t *ip = flow->dip_addr; + info("%s(%d), q %u ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], + ip[1], ip[2], ip[3], flow->dst_port); } else { info("%s(%d), q %u\n", __func__, port, q); } @@ -1635,8 +1710,9 @@ struct mt_rx_queue* mt_dev_get_rx_queue(struct mtl_main_impl* impl, enum mtl_por return NULL; } -uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl* impl, struct mt_tx_queue* queue, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts, +uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, + struct mt_tx_queue *queue, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, int timeout_ms) { uint16_t sent = 0; uint64_t start_ts = mt_get_tsc(impl); @@ -1646,8 +1722,8 @@ uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl* impl, struct mt_tx_queue* q if (timeout_ms > 0) { int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (ms > timeout_ms) { - warn("%s(%u), fail as timeout to %d ms\n", __func__, mt_dev_tx_queue_id(queue), - timeout_ms); + warn("%s(%u), fail as timeout to %d ms\n", __func__, + mt_dev_tx_queue_id(queue), timeout_ms); return sent; } } @@ -1657,17 +1733,19 @@ uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl* impl, struct mt_tx_queue* q return sent; } -int mt_dpdk_flush_tx_queue(struct mtl_main_impl* impl, struct mt_tx_queue* queue, - struct rte_mbuf* pad) { +int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, + struct mt_tx_queue *queue, struct rte_mbuf *pad) { enum mtl_port port = queue->port; uint16_t queue_id = queue->queue_id; - /* use double to make sure all the fifo are burst out to clean all mbufs in the pool */ + /* use double to make sure all the fifo are burst out to clean all mbufs in + * the pool */ int burst_pkts = mt_if_nb_tx_burst(impl, port) * 2; - struct rte_mbuf* pads[1]; + struct rte_mbuf *pads[1]; pads[0] = pad; - info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, burst_pkts); + info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, + burst_pkts); for (int i = 0; i < burst_pkts; i++) { rte_mbuf_refcnt_update(pad, 1); mt_dpdk_tx_burst_busy(impl, queue, &pads[0], 1, 1); @@ -1676,7 +1754,8 @@ int mt_dpdk_flush_tx_queue(struct mtl_main_impl* impl, struct mt_tx_queue* queue return 0; } -int mt_dev_tx_done_cleanup(struct mtl_main_impl* impl, struct mt_tx_queue* queue) { +int mt_dev_tx_done_cleanup(struct mtl_main_impl *impl, + struct mt_tx_queue *queue) { uint16_t port_id = queue->port_id; uint16_t queue_id = queue->queue_id; MTL_MAY_UNUSED(impl); @@ -1684,10 +1763,10 @@ int mt_dev_tx_done_cleanup(struct mtl_main_impl* impl, struct mt_tx_queue* queue return rte_eth_tx_done_cleanup(port_id, queue_id, 0); } -int mt_dev_put_tx_queue(struct mtl_main_impl* impl, struct mt_tx_queue* queue) { +int mt_dev_put_tx_queue(struct mtl_main_impl *impl, struct mt_tx_queue *queue) { enum mtl_port port = queue->port; - struct mt_interface* inf = mt_if(impl, port); - struct mt_tx_queue* tx_queue; + struct mt_interface *inf = mt_if(impl, port); + struct mt_tx_queue *tx_queue; uint16_t queue_id = queue->queue_id; if (queue_id >= inf->nb_tx_q) { @@ -1710,10 +1789,11 @@ int mt_dev_put_tx_queue(struct mtl_main_impl* impl, struct mt_tx_queue* queue) { return 0; } -int mt_dev_tx_queue_fatal_error(struct mtl_main_impl* impl, struct mt_tx_queue* queue) { +int mt_dev_tx_queue_fatal_error(struct mtl_main_impl *impl, + struct mt_tx_queue *queue) { enum mtl_port port = queue->port; - struct mt_interface* inf = mt_if(impl, port); - struct mt_tx_queue* tx_queue; + struct mt_interface *inf = mt_if(impl, port); + struct mt_tx_queue *tx_queue; uint16_t queue_id = queue->queue_id; if (queue_id >= inf->nb_tx_q) { @@ -1736,10 +1816,10 @@ int mt_dev_tx_queue_fatal_error(struct mtl_main_impl* impl, struct mt_tx_queue* return 0; } -int mt_dev_set_tx_bps(struct mtl_main_impl* impl, struct mt_tx_queue* queue, +int mt_dev_set_tx_bps(struct mtl_main_impl *impl, struct mt_tx_queue *queue, uint64_t bytes_per_sec) { enum mtl_port port = queue->port; - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); uint16_t queue_id = queue->queue_id; if (queue_id >= inf->nb_tx_q) { @@ -1748,7 +1828,8 @@ int mt_dev_set_tx_bps(struct mtl_main_impl* impl, struct mt_tx_queue* queue, } if (inf->tx_pacing_way != ST21_TX_PACING_WAY_RL) { - err("%s(%d,%u), pacing %d is not rl\n", __func__, port, queue_id, inf->tx_pacing_way); + err("%s(%d,%u), pacing %d is not rl\n", __func__, port, queue_id, + inf->tx_pacing_way); return -ENOTSUP; } @@ -1757,12 +1838,12 @@ int mt_dev_set_tx_bps(struct mtl_main_impl* impl, struct mt_tx_queue* queue, return 0; } -int mt_dev_put_rx_queue(struct mtl_main_impl* impl, struct mt_rx_queue* queue) { +int mt_dev_put_rx_queue(struct mtl_main_impl *impl, struct mt_rx_queue *queue) { enum mtl_port port = queue->port; - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); uint16_t queue_id = queue->queue_id; int ret; - struct mt_rx_queue* rx_queue; + struct mt_rx_queue *rx_queue; if (queue_id >= inf->nb_rx_q) { err("%s(%d), invalid queue %d\n", __func__, port, queue_id); @@ -1790,7 +1871,8 @@ int mt_dev_put_rx_queue(struct mtl_main_impl* impl, struct mt_rx_queue* queue) { if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) { ret = rte_eth_dev_rx_queue_stop(inf->port_id, queue_id); if (ret < 0) - err("%s(%d), stop runtime rx queue %d fail %d\n", __func__, port, queue_id, ret); + err("%s(%d), stop runtime rx queue %d fail %d\n", __func__, port, + queue_id, ret); } rx_queue->active = false; @@ -1798,10 +1880,10 @@ int mt_dev_put_rx_queue(struct mtl_main_impl* impl, struct mt_rx_queue* queue) { return 0; } -int mt_dev_create(struct mtl_main_impl* impl) { +int mt_dev_create(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); int ret; - struct mt_interface* inf; + struct mt_interface *inf; enum mt_port_type port_type; for (int i = 0; i < num_ports; i++) { @@ -1815,7 +1897,8 @@ int mt_dev_create(struct mtl_main_impl* impl) { if ((mt_user_ptp_service(impl) || mt_user_hw_timestamp(impl)) && (port_type == MT_PORT_PF)) { ret = dev_start_timesync(inf); - if (ret >= 0) inf->feature |= MT_IF_FEATURE_TIMESYNC; + if (ret >= 0) + inf->feature |= MT_IF_FEATURE_TIMESYNC; } #endif @@ -1832,7 +1915,8 @@ int mt_dev_create(struct mtl_main_impl* impl) { } ret = dev_detect_link(inf); /* some port can only detect link after start */ if (ret < 0) { - err("%s(%d), dev_detect_link fail %d retry %d\n", __func__, i, ret, detect_retry); + err("%s(%d), dev_detect_link fail %d retry %d\n", __func__, i, ret, + detect_retry); if (detect_retry < 3) { detect_retry++; rte_eth_dev_reset(inf->port_id); @@ -1850,7 +1934,8 @@ int mt_dev_create(struct mtl_main_impl* impl) { if ((mt_user_ptp_service(impl) || mt_user_hw_timestamp(impl)) && (port_type == MT_PORT_PF) && !(inf->feature & MT_IF_FEATURE_TIMESYNC)) { ret = dev_start_timesync(inf); - if (ret >= 0) inf->feature |= MT_IF_FEATURE_TIMESYNC; + if (ret >= 0) + inf->feature |= MT_IF_FEATURE_TIMESYNC; } ret = dev_if_init_pacing(inf); @@ -1860,8 +1945,8 @@ int mt_dev_create(struct mtl_main_impl* impl) { } if (inf->drv_info.flags & MT_DRV_F_NO_STATUS_RESET) { - inf->dev_stats_not_reset = - mt_rte_zmalloc_socket(sizeof(*inf->dev_stats_not_reset), inf->socket_id); + inf->dev_stats_not_reset = mt_rte_zmalloc_socket( + sizeof(*inf->dev_stats_not_reset), inf->socket_id); if (!inf->dev_stats_not_reset) { err("%s(%d), malloc dev_stats_not_reset fail\n", __func__, i); ret = -ENOMEM; @@ -1900,8 +1985,9 @@ int mt_dev_create(struct mtl_main_impl* impl) { } /* create system sch */ - enum mt_sch_type type = - mt_user_dedicated_sys_lcore(impl) ? MT_SCH_TYPE_SYSTEM : MT_SCH_TYPE_DEFAULT; + enum mt_sch_type type = mt_user_dedicated_sys_lcore(impl) + ? MT_SCH_TYPE_SYSTEM + : MT_SCH_TYPE_DEFAULT; impl->main_sch = mt_sch_get(impl, 0, type, MT_SCH_MASK_ALL); if (!impl->main_sch) { err("%s, get sch fail\n", __func__); @@ -1912,7 +1998,8 @@ int mt_dev_create(struct mtl_main_impl* impl) { return 0; err_exit: - if (impl->main_sch) mt_sch_put(impl->main_sch, 0); + if (impl->main_sch) + mt_sch_put(impl->main_sch, 0); for (int i = num_ports - 1; i >= 0; i--) { inf = mt_if(impl, i); @@ -1921,9 +2008,9 @@ int mt_dev_create(struct mtl_main_impl* impl) { return ret; } -int mt_dev_free(struct mtl_main_impl* impl) { +int mt_dev_free(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_interface* inf; + struct mt_interface *inf; mt_sch_mrg_uinit(impl); @@ -1946,7 +2033,7 @@ int mt_dev_free(struct mtl_main_impl* impl) { return 0; } -int mt_dev_start(struct mtl_main_impl* impl) { +int mt_dev_start(struct mtl_main_impl *impl) { int ret = 0; /* start active sch */ @@ -1960,17 +2047,18 @@ int mt_dev_start(struct mtl_main_impl* impl) { return 0; } -int mt_dev_stop(struct mtl_main_impl* impl) { +int mt_dev_stop(struct mtl_main_impl *impl) { mt_sch_stop_all(impl); return 0; } -int mt_dev_get_socket_id(const char* port) { +int mt_dev_get_socket_id(const char *port) { uint16_t port_id = 0; int ret = rte_eth_dev_get_port_by_name(port, &port_id); if (ret < 0) { err("%s, failed to get port for %s\n", __func__, port); - err("%s, please make sure the driver of %s is configured rightly\n", __func__, port); + err("%s, please make sure the driver of %s is configured rightly\n", + __func__, port); return ret; } int soc_id; @@ -1982,14 +2070,14 @@ int mt_dev_get_socket_id(const char* port) { return soc_id; } -int mt_dev_init(struct mtl_init_params* p, struct mt_kport_info* kport_info) { +int mt_dev_init(struct mtl_init_params *p, struct mt_kport_info *kport_info) { int ret; #if RTE_VERSION >= RTE_VERSION_NUM(23, 7, 0, 0) /* introduce from 23.07 */ if (p->memzone_max) { rte_memzone_max_set(p->memzone_max); - info("%s, user preferred memzone_max %u, now %" PRIu64 "\n", __func__, p->memzone_max, - rte_memzone_max_get()); + info("%s, user preferred memzone_max %u, now %" PRIu64 "\n", __func__, + p->memzone_max, rte_memzone_max_get()); } #endif @@ -2002,7 +2090,7 @@ int mt_dev_init(struct mtl_init_params* p, struct mt_kport_info* kport_info) { return 0; } -int mt_dev_uinit(struct mtl_init_params* p) { +int mt_dev_uinit(struct mtl_init_params *p) { MTL_MAY_UNUSED(p); rte_eal_cleanup(); @@ -2011,9 +2099,9 @@ int mt_dev_uinit(struct mtl_init_params* p) { return 0; } -int mt_dev_if_uinit(struct mtl_main_impl* impl) { +int mt_dev_if_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl), ret; - struct mt_interface* inf; + struct mt_interface *inf; for (int i = 0; i < num_ports; i++) { inf = mt_if(impl, i); @@ -2042,11 +2130,13 @@ int mt_dev_if_uinit(struct mtl_main_impl* impl) { if (inf->tx_mbuf_pool) { ret = mt_mempool_free(inf->tx_mbuf_pool); - if (ret >= 0) inf->tx_mbuf_pool = NULL; + if (ret >= 0) + inf->tx_mbuf_pool = NULL; } if (inf->rx_mbuf_pool) { ret = mt_mempool_free(inf->rx_mbuf_pool); - if (ret >= 0) inf->rx_mbuf_pool = NULL; + if (ret >= 0) + inf->rx_mbuf_pool = NULL; } mt_pthread_mutex_destroy(&inf->tx_queues_mutex); @@ -2059,13 +2149,13 @@ int mt_dev_if_uinit(struct mtl_main_impl* impl) { return 0; } -int mt_dev_if_init(struct mtl_main_impl* impl) { +int mt_dev_if_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mtl_init_params* p = mt_get_user_params(impl); + struct mtl_init_params *p = mt_get_user_params(impl); uint16_t port_id; - char* port; - struct rte_eth_dev_info* dev_info; - struct mt_interface* inf; + char *port; + struct rte_eth_dev_info *dev_info; + struct mt_interface *inf; int ret; for (int i = 0; i < num_ports; i++) { @@ -2135,14 +2225,16 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { inf->net_proto = p->net_proto[i]; inf->rss_mode = p->rss_mode; /* enable rss if no flow support */ - if (inf->drv_info.flow_type == MT_FLOW_NONE && inf->rss_mode == MTL_RSS_MODE_NONE) { + if (inf->drv_info.flow_type == MT_FLOW_NONE && + inf->rss_mode == MTL_RSS_MODE_NONE) { inf->rss_mode = MTL_RSS_MODE_L3_L4; /* default l3_l4 */ } - info("%s(%d), user request queues tx %u rx %u\n", __func__, i, p->tx_queues_cnt[i], - p->rx_queues_cnt[i]); + info("%s(%d), user request queues tx %u rx %u\n", __func__, i, + p->tx_queues_cnt[i], p->rx_queues_cnt[i]); uint16_t queue_pair_cnt = RTE_MAX(p->tx_queues_cnt[i], p->rx_queues_cnt[i]); - if (!queue_pair_cnt) queue_pair_cnt = 1; /* at least 1 queue pair */ + if (!queue_pair_cnt) + queue_pair_cnt = 1; /* at least 1 queue pair */ /* set max tx/rx queues */ if (mt_pmd_is_kernel_socket(impl, i)) { inf->nb_tx_q = p->tx_queues_cnt[i]; @@ -2195,8 +2287,8 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { inf->hdr_split_rx_queues_end = inf->system_rx_queues_end + p->nb_rx_hdr_split_queues; } - dbg("%s(%d), tx_queues %u dev max tx queues %u\n", __func__, i, inf->nb_tx_q, - dev_info->max_tx_queues); + dbg("%s(%d), tx_queues %u dev max tx queues %u\n", __func__, i, + inf->nb_tx_q, dev_info->max_tx_queues); if (!(inf->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD)) { /* max tx/rx queues don't exceed dev limit */ inf->nb_tx_q = RTE_MIN(inf->nb_tx_q, dev_info->max_tx_queues); @@ -2207,7 +2299,8 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { inf->nb_tx_q = RTE_MAX(inf->nb_tx_q, inf->nb_rx_q); inf->nb_rx_q = inf->nb_tx_q; } - dbg("%s(%d), tx_queues %u rx queues %u\n", __func__, i, inf->nb_tx_q, inf->nb_rx_q); + dbg("%s(%d), tx_queues %u rx queues %u\n", __func__, i, inf->nb_tx_q, + inf->nb_rx_q); /* feature detect */ if (dev_info->dev_capa & RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP) @@ -2230,7 +2323,8 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { #endif /* Disable checksum calculation for RDMA UD backend */ - if (mt_pmd_is_rdma_ud(impl, i)) inf->feature |= MT_IF_FEATURE_TX_OFFLOAD_IPV4_CKSUM; + if (mt_pmd_is_rdma_ud(impl, i)) + inf->feature |= MT_IF_FEATURE_TX_OFFLOAD_IPV4_CKSUM; #if RTE_VERSION >= RTE_VERSION_NUM(23, 3, 0, 0) /* Detect LaunchTime capability */ @@ -2238,22 +2332,25 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { ST21_TX_PACING_WAY_TSN == inf->tx_pacing_way) { inf->feature |= MT_IF_FEATURE_TX_OFFLOAD_SEND_ON_TIMESTAMP; - int* dev_tx_timestamp_dynfield_offset_ptr = + int *dev_tx_timestamp_dynfield_offset_ptr = dev_info->default_txconf.reserved_ptrs[1]; - uint64_t* dev_tx_timestamp_dynflag_ptr = dev_info->default_txconf.reserved_ptrs[0]; - ret = rte_mbuf_dyn_tx_timestamp_register(dev_tx_timestamp_dynfield_offset_ptr, - dev_tx_timestamp_dynflag_ptr); + uint64_t *dev_tx_timestamp_dynflag_ptr = + dev_info->default_txconf.reserved_ptrs[0]; + ret = rte_mbuf_dyn_tx_timestamp_register( + dev_tx_timestamp_dynfield_offset_ptr, dev_tx_timestamp_dynflag_ptr); if (ret < 0) { err("%s, rte_mbuf_dyn_tx_timestamp_register fail\n", __func__); return ret; } ret = rte_mbuf_dynflag_lookup(RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME, NULL); - if (ret < 0) return ret; + if (ret < 0) + return ret; inf->tx_launch_time_flag = 1ULL << ret; ret = rte_mbuf_dynfield_lookup(RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL); - if (ret < 0) return ret; + if (ret < 0) + return ret; inf->tx_dynfield_offset = ret; } #endif @@ -2271,7 +2368,8 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { err("%s, rte_mbuf_dyn_rx_timestamp_register fail\n", __func__); return ret; } - info("%s, rte_mbuf_dyn_rx_timestamp_register: mbuf dynfield offset: %d\n", + info("%s, rte_mbuf_dyn_rx_timestamp_register: mbuf dynfield offset: " + "%d\n", __func__, impl->dynfield_offset); } inf->feature |= MT_IF_FEATURE_RX_OFFLOAD_TIMESTAMP; @@ -2289,7 +2387,8 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { if (ret < 0) { err("%s(%d), init virtio_user fail\n", __func__, i); if (ret == -EPERM) - err("%s(%d), you need additional capability: sudo setcap 'cap_net_admin+ep' " + err("%s(%d), you need additional capability: sudo setcap " + "'cap_net_admin+ep' " "\n", __func__, i); return ret; @@ -2305,13 +2404,14 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { unsigned int mbuf_elements = 1024; char pool_name[ST_MAX_NAME_LEN]; - struct rte_mempool* mbuf_pool; + struct rte_mempool *mbuf_pool; /* Create mempool in memory to hold the system rx mbufs if mono */ if (mt_user_rx_mono_pool(impl)) { mbuf_elements = 1024; /* append as rx queues */ mbuf_elements += inf->nb_rx_q * inf->nb_rx_desc; - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%d_SYS", MT_RX_MEMPOOL_PREFIX, i); + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%d_SYS", MT_RX_MEMPOOL_PREFIX, + i); mbuf_pool = mt_mempool_create_common(impl, i, pool_name, mbuf_elements); if (!mbuf_pool) { mt_dev_if_uinit(impl); @@ -2345,8 +2445,8 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { return -ENOMEM; } - inf->pad = - mt_build_pad(impl, mt_sys_tx_mempool(impl, i), i, RTE_ETHER_TYPE_IPV4, 1024); + inf->pad = mt_build_pad(impl, mt_sys_tx_mempool(impl, i), i, + RTE_ETHER_TYPE_IPV4, 1024); if (!inf->pad) { err("%s(%d), pad alloc fail\n", __func__, i); mt_dev_if_uinit(impl); @@ -2383,27 +2483,29 @@ int mt_dev_if_init(struct mtl_main_impl* impl) { __func__, i, dev_info->dev_capa, dev_info->tx_offload_capa, dev_info->rx_offload_capa, dev_info->tx_queue_offload_capa, dev_info->rx_queue_offload_capa, dev_info->flow_type_rss_offloads); - info("%s(%d), system_rx_queues_end %d hdr_split_rx_queues_end %d\n", __func__, i, - inf->system_rx_queues_end, inf->hdr_split_rx_queues_end); - uint8_t* ip = p->sip_addr[i]; + info("%s(%d), system_rx_queues_end %d hdr_split_rx_queues_end %d\n", + __func__, i, inf->system_rx_queues_end, inf->hdr_split_rx_queues_end); + uint8_t *ip = p->sip_addr[i]; info("%s(%d), sip: %u.%u.%u.%u\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); - uint8_t* nm = p->netmask[i]; - info("%s(%d), netmask: %u.%u.%u.%u\n", __func__, i, nm[0], nm[1], nm[2], nm[3]); - uint8_t* gw = p->gateway[i]; - info("%s(%d), gateway: %u.%u.%u.%u\n", __func__, i, gw[0], gw[1], gw[2], gw[3]); + uint8_t *nm = p->netmask[i]; + info("%s(%d), netmask: %u.%u.%u.%u\n", __func__, i, nm[0], nm[1], nm[2], + nm[3]); + uint8_t *gw = p->gateway[i]; + info("%s(%d), gateway: %u.%u.%u.%u\n", __func__, i, gw[0], gw[1], gw[2], + gw[3]); struct rte_ether_addr mac; mt_macaddr_get(impl, i, &mac); - info("%s(%d), mac: %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, i, mac.addr_bytes[0], - mac.addr_bytes[1], mac.addr_bytes[2], mac.addr_bytes[3], mac.addr_bytes[4], - mac.addr_bytes[5]); + info("%s(%d), mac: %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, i, + mac.addr_bytes[0], mac.addr_bytes[1], mac.addr_bytes[2], + mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]); } return 0; } -int mt_dev_if_pre_uinit(struct mtl_main_impl* impl) { +int mt_dev_if_pre_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_interface* inf; + struct mt_interface *inf; if (impl->main_sch) { mt_sch_put(impl->main_sch, 0); @@ -2416,9 +2518,11 @@ int mt_dev_if_pre_uinit(struct mtl_main_impl* impl) { if (mt_has_virtio_user(impl, i)) { inf->virtio_port_active = false; int ret = rte_eth_dev_stop(inf->virtio_port_id); - if (ret < 0) warn("%s(%d), stop virtio port fail %d\n", __func__, i, ret); + if (ret < 0) + warn("%s(%d), stop virtio port fail %d\n", __func__, i, ret); ret = rte_eth_dev_close(inf->virtio_port_id); - if (ret < 0) warn("%s(%d), close virtio port fail %d\n", __func__, i, ret); + if (ret < 0) + warn("%s(%d), close virtio port fail %d\n", __func__, i, ret); } } @@ -2426,15 +2530,15 @@ int mt_dev_if_pre_uinit(struct mtl_main_impl* impl) { } /* map with dev_config_rss_reta */ -uint16_t mt_dev_rss_hash_queue(struct mtl_main_impl* impl, enum mtl_port port, +uint16_t mt_dev_rss_hash_queue(struct mtl_main_impl *impl, enum mtl_port port, uint32_t hash) { - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); return (hash % inf->dev_info.reta_size) % inf->nb_rx_q; } -int mt_dev_tsc_done_action(struct mtl_main_impl* impl) { +int mt_dev_tsc_done_action(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_interface* inf; + struct mt_interface *inf; for (int i = 0; i < num_ports; i++) { inf = mt_if(impl, i); @@ -2447,40 +2551,41 @@ int mt_dev_tsc_done_action(struct mtl_main_impl* impl) { return 0; } -int mt_update_admin_port_stats(struct mtl_main_impl* impl) { +int mt_update_admin_port_stats(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); for (int port = 0; port < num_ports; port++) { - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); dev_inf_get_stat(inf); } return 0; } -int mt_reset_admin_port_stats(struct mtl_main_impl* impl) { +int mt_reset_admin_port_stats(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); for (int port = 0; port < num_ports; port++) { - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); memset(&inf->stats_admin, 0, sizeof(inf->stats_admin)); } return 0; } -int mt_read_admin_port_stats(struct mtl_main_impl* impl, enum mtl_port port, - struct mtl_port_status* stats) { +int mt_read_admin_port_stats(struct mtl_main_impl *impl, enum mtl_port port, + struct mtl_port_status *stats) { if (port >= mt_num_ports(impl)) { err("%s, invalid port %d\n", __func__, port); return -EIO; } - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); memcpy(stats, &inf->stats_admin, sizeof(*stats)); return 0; } -int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status* stats) { - struct mtl_main_impl* impl = mt; +int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, + struct mtl_port_status *stats) { + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -2491,7 +2596,7 @@ int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status return -EIO; } - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); dev_inf_get_stat(inf); memcpy(stats, &inf->user_stats_port, sizeof(*stats)); @@ -2499,7 +2604,7 @@ int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status } int mtl_reset_port_stats(mtl_handle mt, enum mtl_port port) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -2510,7 +2615,7 @@ int mtl_reset_port_stats(mtl_handle mt, enum mtl_port port) { return -EIO; } - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); memset(&inf->user_stats_port, 0, sizeof(inf->user_stats_port)); return 0; diff --git a/lib/src/dev/mt_dev.h b/lib/src/dev/mt_dev.h index 2db8b88f4..5b9453ebe 100644 --- a/lib/src/dev/mt_dev.h +++ b/lib/src/dev/mt_dev.h @@ -19,61 +19,67 @@ /* set to 1 to enable the simulated test */ #define MT_DEV_SIMULATE_MALICIOUS_PKT (0) -int mt_dev_get_socket_id(const char* port); +int mt_dev_get_socket_id(const char *port); -int mt_dev_init(struct mtl_init_params* p, struct mt_kport_info* kport_info); -int mt_dev_uinit(struct mtl_init_params* p); +int mt_dev_init(struct mtl_init_params *p, struct mt_kport_info *kport_info); +int mt_dev_uinit(struct mtl_init_params *p); -int mt_dev_create(struct mtl_main_impl* impl); -int mt_dev_free(struct mtl_main_impl* impl); +int mt_dev_create(struct mtl_main_impl *impl); +int mt_dev_free(struct mtl_main_impl *impl); -int mt_dev_start(struct mtl_main_impl* impl); -int mt_dev_stop(struct mtl_main_impl* impl); +int mt_dev_start(struct mtl_main_impl *impl); +int mt_dev_stop(struct mtl_main_impl *impl); -struct mt_tx_queue* mt_dev_get_tx_queue(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow); -int mt_dev_put_tx_queue(struct mtl_main_impl* impl, struct mt_tx_queue* queue); -static inline uint16_t mt_dev_tx_queue_id(struct mt_tx_queue* queue) { +struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow); +int mt_dev_put_tx_queue(struct mtl_main_impl *impl, struct mt_tx_queue *queue); +static inline uint16_t mt_dev_tx_queue_id(struct mt_tx_queue *queue) { return queue->queue_id; } -int mt_dev_tx_queue_fatal_error(struct mtl_main_impl* impl, struct mt_tx_queue* queue); -int mt_dev_set_tx_bps(struct mtl_main_impl* impl, struct mt_tx_queue* queue, +int mt_dev_tx_queue_fatal_error(struct mtl_main_impl *impl, + struct mt_tx_queue *queue); +int mt_dev_set_tx_bps(struct mtl_main_impl *impl, struct mt_tx_queue *queue, uint64_t bytes_per_sec); -int mt_dpdk_flush_tx_queue(struct mtl_main_impl* impl, struct mt_tx_queue* queue, - struct rte_mbuf* pad); -int mt_dev_tx_done_cleanup(struct mtl_main_impl* impl, struct mt_tx_queue* queue); -static inline uint16_t mt_dpdk_tx_burst(struct mt_tx_queue* queue, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { +int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, + struct mt_tx_queue *queue, struct rte_mbuf *pad); +int mt_dev_tx_done_cleanup(struct mtl_main_impl *impl, + struct mt_tx_queue *queue); +static inline uint16_t mt_dpdk_tx_burst(struct mt_tx_queue *queue, + struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return rte_eth_tx_burst(queue->port_id, queue->queue_id, tx_pkts, nb_pkts); } -uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl* impl, struct mt_tx_queue* queue, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts, +uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, + struct mt_tx_queue *queue, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, int timeout_ms); -struct mt_rx_queue* mt_dev_get_rx_queue(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow); -int mt_dev_put_rx_queue(struct mtl_main_impl* impl, struct mt_rx_queue* queue); -static inline uint16_t mt_dev_rx_queue_id(struct mt_rx_queue* queue) { +struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow); +int mt_dev_put_rx_queue(struct mtl_main_impl *impl, struct mt_rx_queue *queue); +static inline uint16_t mt_dev_rx_queue_id(struct mt_rx_queue *queue) { return queue->queue_id; } -static inline uint16_t mt_dpdk_rx_burst(struct mt_rx_queue* queue, - struct rte_mbuf** rx_pkts, +static inline uint16_t mt_dpdk_rx_burst(struct mt_rx_queue *queue, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return rte_eth_rx_burst(queue->port_id, queue->queue_id, rx_pkts, nb_pkts); } -int mt_dev_if_init(struct mtl_main_impl* impl); -int mt_dev_if_uinit(struct mtl_main_impl* impl); -int mt_dev_if_pre_uinit(struct mtl_main_impl* impl); +int mt_dev_if_init(struct mtl_main_impl *impl); +int mt_dev_if_uinit(struct mtl_main_impl *impl); +int mt_dev_if_pre_uinit(struct mtl_main_impl *impl); -int mt_dev_tsc_done_action(struct mtl_main_impl* impl); +int mt_dev_tsc_done_action(struct mtl_main_impl *impl); -uint16_t mt_dev_rss_hash_queue(struct mtl_main_impl* impl, enum mtl_port port, +uint16_t mt_dev_rss_hash_queue(struct mtl_main_impl *impl, enum mtl_port port, uint32_t hash); -int mt_update_admin_port_stats(struct mtl_main_impl* impl); -int mt_read_admin_port_stats(struct mtl_main_impl* impl, enum mtl_port port, - struct mtl_port_status* stats); -int mt_reset_admin_port_stats(struct mtl_main_impl* impl); +int mt_update_admin_port_stats(struct mtl_main_impl *impl); +int mt_read_admin_port_stats(struct mtl_main_impl *impl, enum mtl_port port, + struct mtl_port_status *stats); +int mt_reset_admin_port_stats(struct mtl_main_impl *impl); #endif diff --git a/lib/src/dev/mt_rdma_ud.c b/lib/src/dev/mt_rdma_ud.c index f9ccb95a1..8756988f2 100644 --- a/lib/src/dev/mt_rdma_ud.c +++ b/lib/src/dev/mt_rdma_ud.c @@ -17,21 +17,21 @@ struct mt_rdma_tx_queue { enum mtl_port port; uint16_t q; - uint8_t* sip; + uint8_t *sip; uint32_t flow_hash; bool multicast; - struct rdma_event_channel* ec; - struct rdma_cm_id* cma_id; - struct ibv_pd* pd; - struct ibv_cq* cq; - struct ibv_ah* ah; + struct rdma_event_channel *ec; + struct rdma_cm_id *cma_id; + struct ibv_pd *pd; + struct ibv_cq *cq; + struct ibv_ah *ah; uint32_t remote_qpn; uint32_t remote_qkey; - struct rdma_addrinfo* rai; - struct ibv_mr** send_mrs; - void** send_mrs_buffers; - size_t* send_mrs_sizes; + struct rdma_addrinfo *rai; + struct ibv_mr **send_mrs; + void **send_mrs_buffers; + size_t *send_mrs_sizes; int num_mrs; bool connected; @@ -39,7 +39,7 @@ struct mt_rdma_tx_queue { pthread_t connect_thread; uint16_t outstanding_wr; - struct mt_tx_rdma_entry* tx_entry; + struct mt_tx_rdma_entry *tx_entry; uint64_t stat_tx_pkts; uint64_t stat_tx_bytes; @@ -53,28 +53,28 @@ struct mt_rdma_tx_queue { struct mt_rdma_rx_queue { enum mtl_port port; - struct rte_mempool* mbuf_pool; + struct rte_mempool *mbuf_pool; uint16_t q; - uint8_t* sip; + uint8_t *sip; uint32_t flow_hash; bool multicast; - struct rdma_event_channel* ec; - struct rdma_cm_id* listen_id; - struct rdma_cm_id* cma_id; - struct ibv_pd* pd; - struct ibv_cq* cq; - struct ibv_qp* qp; - struct ibv_mr* recv_mr; - struct rdma_addrinfo* rai; - void* recv_buffer; + struct rdma_event_channel *ec; + struct rdma_cm_id *listen_id; + struct rdma_cm_id *cma_id; + struct ibv_pd *pd; + struct ibv_cq *cq; + struct ibv_qp *qp; + struct ibv_mr *recv_mr; + struct rdma_addrinfo *rai; + void *recv_buffer; size_t recv_len; size_t recv_buffer_size; bool connected; bool stop; pthread_t connect_thread; - struct mt_rx_rdma_entry* rx_entry; + struct mt_rx_rdma_entry *rx_entry; uint64_t stat_rx_pkts; uint64_t stat_rx_bytes; uint64_t stat_rx_burst; @@ -85,35 +85,37 @@ struct mt_rdma_rx_queue { }; struct mt_rdma_priv { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; uint16_t tx_queues_cnt; uint16_t rx_queues_cnt; - struct mt_rdma_tx_queue* tx_queues; - struct mt_rdma_rx_queue* rx_queues; + struct mt_rdma_tx_queue *tx_queues; + struct mt_rdma_rx_queue *rx_queues; pthread_mutex_t queues_lock; }; -static inline uint32_t rdma_flow_hash(uint8_t* sip, uint8_t* dip, uint16_t sport, - uint16_t dport) { +static inline uint32_t rdma_flow_hash(uint8_t *sip, uint8_t *dip, + uint16_t sport, uint16_t dport) { struct rte_ipv4_tuple tuple = {}; - if (sip) tuple.src_addr = RTE_IPV4(sip[0], sip[1], sip[2], sip[3]); - if (dip) tuple.dst_addr = RTE_IPV4(dip[0], dip[1], dip[2], dip[3]); + if (sip) + tuple.src_addr = RTE_IPV4(sip[0], sip[1], sip[2], sip[3]); + if (dip) + tuple.dst_addr = RTE_IPV4(dip[0], dip[1], dip[2], dip[3]); tuple.sport = sport; tuple.dport = dport; - return mt_softrss((uint32_t*)&tuple, RTE_THASH_V4_L4_LEN); + return mt_softrss((uint32_t *)&tuple, RTE_THASH_V4_L4_LEN); } -static int rdma_tx_queue_stat(struct mt_rdma_tx_queue* txq) { +static int rdma_tx_queue_stat(struct mt_rdma_tx_queue *txq) { enum mtl_port port = txq->port; uint16_t q = txq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 " free %" PRIu64 - "\n", - __func__, port, q, txq->stat_tx_pkts, txq->stat_tx_bytes, txq->stat_tx_submit, - txq->stat_tx_free); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 + " free %" PRIu64 "\n", + __func__, port, q, txq->stat_tx_pkts, txq->stat_tx_bytes, + txq->stat_tx_submit, txq->stat_tx_free); txq->stat_tx_pkts = 0; txq->stat_tx_bytes = 0; txq->stat_tx_submit = 0; @@ -142,12 +144,13 @@ static int rdma_tx_queue_stat(struct mt_rdma_tx_queue* txq) { return 0; } -static int rdma_rx_queue_stat(struct mt_rdma_rx_queue* rxq) { +static int rdma_rx_queue_stat(struct mt_rdma_rx_queue *rxq) { enum mtl_port port = rxq->port; uint16_t q = rxq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", __func__, - port, q, rxq->stat_rx_pkts, rxq->stat_rx_bytes, rxq->stat_rx_burst); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", + __func__, port, q, rxq->stat_rx_pkts, rxq->stat_rx_bytes, + rxq->stat_rx_burst); rxq->stat_rx_pkts = 0; rxq->stat_rx_bytes = 0; rxq->stat_rx_burst = 0; @@ -163,35 +166,38 @@ static int rdma_rx_queue_stat(struct mt_rdma_rx_queue* rxq) { rxq->stat_rx_post_recv_fail = 0; } if (rxq->stat_rx_pkt_invalid) { - err("%s(%d,%u), invalid pkt %u\n", __func__, port, q, rxq->stat_rx_pkt_invalid); + err("%s(%d,%u), invalid pkt %u\n", __func__, port, q, + rxq->stat_rx_pkt_invalid); rxq->stat_rx_pkt_invalid = 0; } return 0; } -static int rdma_stat_dump(void* priv) { - struct mt_rdma_priv* rdma = priv; +static int rdma_stat_dump(void *priv) { + struct mt_rdma_priv *rdma = priv; for (uint16_t i = 0; i < rdma->tx_queues_cnt; i++) { - struct mt_rdma_tx_queue* txq = &rdma->tx_queues[i]; - if (txq->tx_entry) rdma_tx_queue_stat(txq); + struct mt_rdma_tx_queue *txq = &rdma->tx_queues[i]; + if (txq->tx_entry) + rdma_tx_queue_stat(txq); } for (uint16_t i = 0; i < rdma->rx_queues_cnt; i++) { - struct mt_rdma_rx_queue* rxq = &rdma->rx_queues[i]; - if (rxq->rx_entry) rdma_rx_queue_stat(rxq); + struct mt_rdma_rx_queue *rxq = &rdma->rx_queues[i]; + if (rxq->rx_entry) + rdma_rx_queue_stat(rxq); } return 0; } -static int rdma_free(struct mt_rdma_priv* rdma) { +static int rdma_free(struct mt_rdma_priv *rdma) { enum mtl_port port = rdma->port; if (rdma->tx_queues) { for (uint16_t i = 0; i < rdma->tx_queues_cnt; i++) { - struct mt_rdma_tx_queue* txq = &rdma->tx_queues[i]; + struct mt_rdma_tx_queue *txq = &rdma->tx_queues[i]; if (txq->tx_entry) { warn("%s(%d,%u), tx_entry still active\n", __func__, port, txq->q); @@ -203,7 +209,7 @@ static int rdma_free(struct mt_rdma_priv* rdma) { if (rdma->rx_queues) { for (uint16_t i = 0; i < rdma->rx_queues_cnt; i++) { - struct mt_rdma_rx_queue* rxq = &rdma->rx_queues[i]; + struct mt_rdma_rx_queue *rxq = &rdma->rx_queues[i]; if (rxq->rx_entry) { warn("%s(%d,%u), rx_entry still active\n", __func__, port, rxq->q); @@ -218,23 +224,23 @@ static int rdma_free(struct mt_rdma_priv* rdma) { return 0; } -static int rdma_rx_post_recv(struct mt_rdma_rx_queue* rxq, struct rte_mbuf** mbufs, - uint16_t sz) { +static int rdma_rx_post_recv(struct mt_rdma_rx_queue *rxq, + struct rte_mbuf **mbufs, uint16_t sz) { enum mtl_port port = rxq->port; uint16_t q = rxq->q; int ret; - struct rte_mbuf* m = NULL; + struct rte_mbuf *m = NULL; for (int i = 0; i < sz; i++) { m = mbufs[i]; /* skip l2/l3/l4 headers, leave space for ibv_grh */ - void* addr = rte_pktmbuf_mtod_offset(m, void*, sizeof(struct mt_udp_hdr)) - + void *addr = rte_pktmbuf_mtod_offset(m, void *, sizeof(struct mt_udp_hdr)) - sizeof(struct ibv_grh); ret = rdma_post_recv(rxq->cma_id, m, addr, rxq->recv_len, rxq->recv_mr); if (ret) { rxq->stat_rx_post_recv_fail++; - err("%s(%d,%u), rdma_post_recv %u fail %d, addr %p, len %" PRIu64 "\n", __func__, - port, q, i, ret, addr, rxq->recv_len); + err("%s(%d,%u), rdma_post_recv %u fail %d, addr %p, len %" PRIu64 "\n", + __func__, port, q, i, ret, addr, rxq->recv_len); return ret; } } @@ -242,9 +248,10 @@ static int rdma_rx_post_recv(struct mt_rdma_rx_queue* rxq, struct rte_mbuf** mbu return 0; } -static void rdma_tx_poll_done(struct mt_rdma_tx_queue* txq) { - if (!txq->connected) return; - struct ibv_cq* cq = txq->cq; +static void rdma_tx_poll_done(struct mt_rdma_tx_queue *txq) { + if (!txq->connected) + return; + struct ibv_cq *cq = txq->cq; struct ibv_wc wc[128]; int n = 0; @@ -258,21 +265,23 @@ static void rdma_tx_poll_done(struct mt_rdma_tx_queue* txq) { err("%s, poll fail, wc status %d\n", __func__, wc[i].status); txq->stat_tx_completion_fail++; } - rte_pktmbuf_free((struct rte_mbuf*)wc[i].wr_id); + rte_pktmbuf_free((struct rte_mbuf *)wc[i].wr_id); } txq->outstanding_wr -= n; txq->stat_tx_free += n; } while (n > 0); } -static uint16_t rdma_tx(struct mtl_main_impl* impl, struct mt_rdma_tx_queue* txq, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { - if (!txq->connected) return 0; +static uint16_t rdma_tx(struct mtl_main_impl *impl, + struct mt_rdma_tx_queue *txq, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { + if (!txq->connected) + return 0; int ret = 0; enum mtl_port port = txq->port; uint16_t q = txq->q; uint16_t tx = 0; - struct mtl_port_status* stats = mt_if(impl, port)->dev_stats_sw; + struct mtl_port_status *stats = mt_if(impl, port)->dev_stats_sw; uint64_t tx_bytes = 0; rdma_tx_poll_done(txq); @@ -285,24 +294,25 @@ static uint16_t rdma_tx(struct mtl_main_impl* impl, struct mt_rdma_tx_queue* txq struct ibv_send_wr wr, *bad; struct ibv_sge sge[2]; - struct rte_mbuf* m = NULL; + struct rte_mbuf *m = NULL; for (uint16_t i = 0; i < nb_pkts; i++) { m = tx_pkts[i]; /* l2/l3/l4 headers are not used in data path */ - sge[0].addr = rte_pktmbuf_mtod_offset(m, uint64_t, sizeof(struct mt_udp_hdr)); + sge[0].addr = + rte_pktmbuf_mtod_offset(m, uint64_t, sizeof(struct mt_udp_hdr)); sge[0].length = m->data_len - sizeof(struct mt_udp_hdr); sge[0].lkey = txq->send_mrs[0]->lkey; uint16_t nb_segs = m->nb_segs; if (nb_segs > 1) { - struct st_frame_trans* frame = st_tx_mbuf_get_priv(m); - struct rte_mbuf* n = m->next; + struct st_frame_trans *frame = st_tx_mbuf_get_priv(m); + struct rte_mbuf *n = m->next; int mr_idx = frame->idx + 1; sge[1].addr = (uint64_t)n->buf_addr; sge[1].length = n->buf_len; sge[1].lkey = txq->send_mrs[mr_idx]->lkey; - dbg("%s(%d, %u), ext buffer %p len %u mr_lkey %u\n", __func__, port, q, n->buf_addr, - n->buf_len, sge[1].lkey); + dbg("%s(%d, %u), ext buffer %p len %u mr_lkey %u\n", __func__, port, q, + n->buf_addr, n->buf_len, sge[1].lkey); } wr.wr_id = (uintptr_t)m; @@ -346,22 +356,24 @@ static uint16_t rdma_tx(struct mtl_main_impl* impl, struct mt_rdma_tx_queue* txq return tx; } -static uint16_t rdma_rx(struct mt_rx_rdma_entry* entry, struct rte_mbuf** rx_pkts, - uint16_t nb_pkts) { - if (!entry->rxq->connected) return 0; - struct mt_rdma_rx_queue* rxq = entry->rxq; +static uint16_t rdma_rx(struct mt_rx_rdma_entry *entry, + struct rte_mbuf **rx_pkts, uint16_t nb_pkts) { + if (!entry->rxq->connected) + return 0; + struct mt_rdma_rx_queue *rxq = entry->rxq; enum mtl_port port = entry->port; // uint16_t q = rxq->q; - struct mtl_port_status* stats = mt_if(entry->parent, port)->dev_stats_sw; + struct mtl_port_status *stats = mt_if(entry->parent, port)->dev_stats_sw; uint64_t rx_bytes = 0; struct ibv_wc wc[nb_pkts]; int rx = ibv_poll_cq(rxq->cq, nb_pkts, wc); - if (rx <= 0) return 0; + if (rx <= 0) + return 0; rxq->stat_rx_burst++; - struct rte_mbuf* fill[rx]; + struct rte_mbuf *fill[rx]; int ret = rte_pktmbuf_alloc_bulk(rxq->mbuf_pool, fill, rx); if (ret < 0) { dbg("%s(%d, %u), mbuf alloc bulk %u fail\n", __func__, port, q, rx); @@ -370,9 +382,9 @@ static uint16_t rdma_rx(struct mt_rx_rdma_entry* entry, struct rte_mbuf** rx_pkt } int rx_valid = 0; - struct rte_mbuf* pkt = NULL; + struct rte_mbuf *pkt = NULL; for (int i = 0; i < rx; i++) { - pkt = (struct rte_mbuf*)wc[i].wr_id; + pkt = (struct rte_mbuf *)wc[i].wr_id; if (wc[i].status != IBV_WC_SUCCESS) { rxq->stat_rx_pkt_invalid++; rte_pktmbuf_free(pkt); @@ -380,8 +392,8 @@ static uint16_t rdma_rx(struct mt_rx_rdma_entry* entry, struct rte_mbuf** rx_pkt } uint32_t flow_hash = ntohl(wc[i].imm_data); if (flow_hash != rxq->flow_hash) { - dbg("%s(%d, %u), flow_hash mismatch %u %u\n", __func__, port, q, flow_hash, - rxq->flow_hash); + dbg("%s(%d, %u), flow_hash mismatch %u %u\n", __func__, port, q, + flow_hash, rxq->flow_hash); rxq->stat_rx_pkt_invalid++; rte_pktmbuf_free(pkt); continue; @@ -407,8 +419,8 @@ static uint16_t rdma_rx(struct mt_rx_rdma_entry* entry, struct rte_mbuf** rx_pkt return rx_valid; } -int mt_dev_rdma_init(struct mt_interface* inf) { - struct mtl_main_impl* impl = inf->parent; +int mt_dev_rdma_init(struct mt_interface *inf) { + struct mtl_main_impl *impl = inf->parent; enum mtl_port port = inf->port; int ret; @@ -417,7 +429,7 @@ int mt_dev_rdma_init(struct mt_interface* inf) { return -EIO; } - struct mt_rdma_priv* rdma = + struct mt_rdma_priv *rdma = mt_rte_zmalloc_socket(sizeof(*rdma), mt_socket_id(impl, port)); if (!rdma) { err("%s(%d), rdma malloc fail\n", __func__, port); @@ -429,8 +441,9 @@ int mt_dev_rdma_init(struct mt_interface* inf) { rdma->rx_queues_cnt = inf->nb_rx_q; mt_pthread_mutex_init(&rdma->queues_lock, NULL); if (rdma->tx_queues_cnt) { - rdma->tx_queues = mt_rte_zmalloc_socket( - sizeof(*rdma->tx_queues) * rdma->tx_queues_cnt, mt_socket_id(impl, port)); + rdma->tx_queues = + mt_rte_zmalloc_socket(sizeof(*rdma->tx_queues) * rdma->tx_queues_cnt, + mt_socket_id(impl, port)); if (!rdma->tx_queues) { err("%s(%d), rdma tx_queues malloc fail\n", __func__, port); rdma_free(rdma); @@ -438,8 +451,9 @@ int mt_dev_rdma_init(struct mt_interface* inf) { } } if (rdma->rx_queues_cnt) { - rdma->rx_queues = mt_rte_zmalloc_socket( - sizeof(*rdma->rx_queues) * rdma->rx_queues_cnt, mt_socket_id(impl, port)); + rdma->rx_queues = + mt_rte_zmalloc_socket(sizeof(*rdma->rx_queues) * rdma->rx_queues_cnt, + mt_socket_id(impl, port)); if (!rdma->rx_queues) { err("%s(%d), rdma rx_queues malloc fail\n", __func__, port); rdma_free(rdma); @@ -448,14 +462,14 @@ int mt_dev_rdma_init(struct mt_interface* inf) { } for (uint16_t i = 0; i < rdma->tx_queues_cnt; i++) { - struct mt_rdma_tx_queue* txq = &rdma->tx_queues[i]; + struct mt_rdma_tx_queue *txq = &rdma->tx_queues[i]; txq->sip = mt_sip_addr(impl, port); txq->port = port; txq->q = i; } for (uint16_t i = 0; i < rdma->rx_queues_cnt; i++) { - struct mt_rdma_rx_queue* rxq = &rdma->rx_queues[i]; + struct mt_rdma_rx_queue *rxq = &rdma->rx_queues[i]; rxq->sip = mt_sip_addr(impl, port); rxq->port = port; rxq->q = i; @@ -481,10 +495,11 @@ int mt_dev_rdma_init(struct mt_interface* inf) { return 0; } -int mt_dev_rdma_uinit(struct mt_interface* inf) { - struct mt_rdma_priv* rdma = inf->rdma; - if (!rdma) return 0; - struct mtl_main_impl* impl = inf->parent; +int mt_dev_rdma_uinit(struct mt_interface *inf) { + struct mt_rdma_priv *rdma = inf->rdma; + if (!rdma) + return 0; + struct mtl_main_impl *impl = inf->parent; mt_stat_unregister(impl, rdma_stat_dump, rdma); @@ -494,20 +509,20 @@ int mt_dev_rdma_uinit(struct mt_interface* inf) { return 0; } -static int rdma_tx_mrs_pre_init(struct mt_rdma_tx_queue* txq, void** buffers, - size_t* sizes, int num_mrs) { - struct mtl_main_impl* impl = txq->tx_entry->parent; +static int rdma_tx_mrs_pre_init(struct mt_rdma_tx_queue *txq, void **buffers, + size_t *sizes, int num_mrs) { + struct mtl_main_impl *impl = txq->tx_entry->parent; enum mtl_port port = txq->port; uint16_t q = txq->q; - void** mrs_buffers = - mt_rte_zmalloc_socket(num_mrs * sizeof(void*), mt_socket_id(impl, port)); + void **mrs_buffers = + mt_rte_zmalloc_socket(num_mrs * sizeof(void *), mt_socket_id(impl, port)); if (!mrs_buffers) { err("%s(%d, %u), %d mrs_buffers malloc fail\n", __func__, port, q, num_mrs); return -ENOMEM; } - size_t* mrs_sizes = + size_t *mrs_sizes = mt_rte_zmalloc_socket(num_mrs * sizeof(size_t), mt_socket_id(impl, port)); if (!mrs_sizes) { err("%s(%d, %u), mrs_sizes malloc fail\n", __func__, port, q); @@ -527,7 +542,7 @@ static int rdma_tx_mrs_pre_init(struct mt_rdma_tx_queue* txq, void** buffers, return 0; } -static int rdma_tx_mrs_uinit(struct mt_rdma_tx_queue* txq) { +static int rdma_tx_mrs_uinit(struct mt_rdma_tx_queue *txq) { if (txq->send_mrs) { for (int i = 0; i < txq->num_mrs; ++i) { MT_SAFE_FREE(txq->send_mrs[i], ibv_dereg_mr); @@ -541,8 +556,8 @@ static int rdma_tx_mrs_uinit(struct mt_rdma_tx_queue* txq) { return 0; } -static int rdma_tx_mrs_init(struct mt_rdma_tx_queue* txq) { - struct mtl_main_impl* impl = txq->tx_entry->parent; +static int rdma_tx_mrs_init(struct mt_rdma_tx_queue *txq) { + struct mtl_main_impl *impl = txq->tx_entry->parent; enum mtl_port port = txq->port; uint16_t q = txq->q; int num_mrs = txq->num_mrs; @@ -557,27 +572,27 @@ static int rdma_tx_mrs_init(struct mt_rdma_tx_queue* txq) { return -EIO; } - struct ibv_mr** mrs = - mt_rte_zmalloc_socket(num_mrs * sizeof(struct ibv_mr*), mt_socket_id(impl, port)); + struct ibv_mr **mrs = mt_rte_zmalloc_socket(num_mrs * sizeof(struct ibv_mr *), + mt_socket_id(impl, port)); if (!mrs) { err("%s(%d, %u), mrs malloc fail\n", __func__, port, q); return -ENOMEM; } for (int i = 0; i < num_mrs; ++i) { - void* buffer = txq->send_mrs_buffers[i]; + void *buffer = txq->send_mrs_buffers[i]; size_t sz = txq->send_mrs_sizes[i]; - struct ibv_mr* mr = ibv_reg_mr(txq->pd, buffer, sz, IBV_ACCESS_LOCAL_WRITE); + struct ibv_mr *mr = ibv_reg_mr(txq->pd, buffer, sz, IBV_ACCESS_LOCAL_WRITE); if (!mr) { - err("%s(%d, %u), ibv_reg_mr fail, buffer %p size %" PRIu64 "\n", __func__, port, q, - buffer, sz); + err("%s(%d, %u), ibv_reg_mr fail, buffer %p size %" PRIu64 "\n", __func__, + port, q, buffer, sz); txq->num_mrs = i; rdma_tx_mrs_uinit(txq); return -EIO; } mrs[i] = mr; - dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", __func__, - port, q, buffers[i], sizes[i], mr->lkey); + dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", + __func__, port, q, buffers[i], sizes[i], mr->lkey); } txq->send_mrs = mrs; @@ -585,15 +600,17 @@ static int rdma_tx_mrs_init(struct mt_rdma_tx_queue* txq) { return 0; } -static int rdma_tx_queue_uinit(struct mt_rdma_tx_queue* txq) { +static int rdma_tx_queue_uinit(struct mt_rdma_tx_queue *txq) { txq->stop = true; pthread_join(txq->connect_thread, NULL); if (txq->multicast && txq->cma_id && txq->rai) rdma_leave_multicast(txq->cma_id, txq->rai->ai_dst_addr); MT_SAFE_FREE(txq->ah, ibv_destroy_ah); - if (txq->cma_id && txq->cma_id->qp) rdma_destroy_qp(txq->cma_id); + if (txq->cma_id && txq->cma_id->qp) + rdma_destroy_qp(txq->cma_id); MT_SAFE_FREE(txq->cq, ibv_destroy_cq); - if (txq->cma_id && !txq->cma_id->pd) MT_SAFE_FREE(txq->pd, ibv_dealloc_pd); + if (txq->cma_id && !txq->cma_id->pd) + MT_SAFE_FREE(txq->pd, ibv_dealloc_pd); MT_SAFE_FREE(txq->rai, rdma_freeaddrinfo); MT_SAFE_FREE(txq->cma_id, rdma_destroy_id); MT_SAFE_FREE(txq->ec, rdma_destroy_event_channel); @@ -601,7 +618,7 @@ static int rdma_tx_queue_uinit(struct mt_rdma_tx_queue* txq) { return 0; } -static int rdma_tx_queue_post_init(struct mt_rdma_tx_queue* txq) { +static int rdma_tx_queue_post_init(struct mt_rdma_tx_queue *txq) { int ret = 0; enum mtl_port port = txq->port; uint16_t q = txq->q; @@ -649,11 +666,11 @@ static int rdma_tx_queue_post_init(struct mt_rdma_tx_queue* txq) { return 0; } -static void* rdma_tx_connect_thread(void* arg) { - struct mt_rdma_tx_queue* txq = arg; +static void *rdma_tx_connect_thread(void *arg) { + struct mt_rdma_tx_queue *txq = arg; enum mtl_port port = txq->port; uint16_t q = txq->q; - struct rdma_cm_event* event; + struct rdma_cm_event *event; struct pollfd pfd; pfd.fd = txq->ec->fd; pfd.events = POLLIN; @@ -665,67 +682,69 @@ static void* rdma_tx_connect_thread(void* arg) { ret = rdma_get_cm_event(txq->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_ADDR_RESOLVED: - if (!txq->multicast) { - ret = rdma_resolve_route(txq->cma_id, 2000); - if (ret) { - err("%s(%d, %u), rdma_resolve_route fail\n", __func__, port, q); - goto connect_err; - } - } else { - ret = rdma_tx_queue_post_init(txq); - if (ret) { - err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, q); - goto connect_err; - } - struct rdma_cm_join_mc_attr_ex attr = { - .addr = txq->rai->ai_dst_addr, - .comp_mask = - RDMA_CM_JOIN_MC_ATTR_ADDRESS | RDMA_CM_JOIN_MC_ATTR_JOIN_FLAGS, - .join_flags = RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER, - }; - ret = rdma_join_multicast_ex(txq->cma_id, &attr, NULL); - if (ret) { - err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); - goto connect_err; - } + case RDMA_CM_EVENT_ADDR_RESOLVED: + if (!txq->multicast) { + ret = rdma_resolve_route(txq->cma_id, 2000); + if (ret) { + err("%s(%d, %u), rdma_resolve_route fail\n", __func__, port, q); + goto connect_err; } - break; - case RDMA_CM_EVENT_ROUTE_RESOLVED: + } else { ret = rdma_tx_queue_post_init(txq); if (ret) { - err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, q); + err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, + q); goto connect_err; } - struct rdma_conn_param conn_param = { - .private_data = txq->rai->ai_connect, - .private_data_len = txq->rai->ai_connect_len, + struct rdma_cm_join_mc_attr_ex attr = { + .addr = txq->rai->ai_dst_addr, + .comp_mask = RDMA_CM_JOIN_MC_ATTR_ADDRESS | + RDMA_CM_JOIN_MC_ATTR_JOIN_FLAGS, + .join_flags = RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER, }; - ret = rdma_connect(txq->cma_id, &conn_param); + ret = rdma_join_multicast_ex(txq->cma_id, &attr, NULL); if (ret) { - err("%s(%d, %u), rdma connect fail %d\n", __func__, port, q, ret); - goto connect_err; - } - break; - case RDMA_CM_EVENT_ESTABLISHED: - case RDMA_CM_EVENT_MULTICAST_JOIN: - txq->remote_qpn = event->param.ud.qp_num; - txq->remote_qkey = event->param.ud.qkey; - txq->ah = ibv_create_ah(txq->pd, &event->param.ud.ah_attr); - if (!txq->ah) { - err("%s(%d, %u), ibv_create_ah fail\n", __func__, port, q); + err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); goto connect_err; } - if (txq->multicast) - info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); - else - info("%s(%d, %u), rdma connected\n", __func__, port, q); - txq->connected = true; - break; - default: - err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, q, - rdma_event_str(event->event), event->status); + } + break; + case RDMA_CM_EVENT_ROUTE_RESOLVED: + ret = rdma_tx_queue_post_init(txq); + if (ret) { + err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, + q); + goto connect_err; + } + struct rdma_conn_param conn_param = { + .private_data = txq->rai->ai_connect, + .private_data_len = txq->rai->ai_connect_len, + }; + ret = rdma_connect(txq->cma_id, &conn_param); + if (ret) { + err("%s(%d, %u), rdma connect fail %d\n", __func__, port, q, ret); + goto connect_err; + } + break; + case RDMA_CM_EVENT_ESTABLISHED: + case RDMA_CM_EVENT_MULTICAST_JOIN: + txq->remote_qpn = event->param.ud.qp_num; + txq->remote_qkey = event->param.ud.qkey; + txq->ah = ibv_create_ah(txq->pd, &event->param.ud.ah_attr); + if (!txq->ah) { + err("%s(%d, %u), ibv_create_ah fail\n", __func__, port, q); goto connect_err; + } + if (txq->multicast) + info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); + else + info("%s(%d, %u), rdma connected\n", __func__, port, q); + txq->connected = true; + break; + default: + err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, + q, rdma_event_str(event->event), event->status); + goto connect_err; } rdma_ack_cm_event(event); } @@ -746,7 +765,7 @@ static void* rdma_tx_connect_thread(void* arg) { return NULL; } -static int rdma_tx_queue_init(struct mt_rdma_tx_queue* txq) { +static int rdma_tx_queue_init(struct mt_rdma_tx_queue *txq) { int ret = 0; enum mtl_port port = txq->port; uint16_t q = txq->q; @@ -769,7 +788,8 @@ static int rdma_tx_queue_init(struct mt_rdma_tx_queue* txq) { hints.ai_port_space = RDMA_PS_UDP; hints.ai_flags = RAI_PASSIVE; char ip[16]; - snprintf(ip, 16, "%d.%d.%d.%d", txq->sip[0], txq->sip[1], txq->sip[2], txq->sip[3]); + snprintf(ip, 16, "%d.%d.%d.%d", txq->sip[0], txq->sip[1], txq->sip[2], + txq->sip[3]); ret = rdma_getaddrinfo(ip, NULL, &hints, &local_rai); if (ret) { err("%s(%d, %u), rdma_getaddrinfo fail %d\n", __func__, port, q, ret); @@ -789,7 +809,7 @@ static int rdma_tx_queue_init(struct mt_rdma_tx_queue* txq) { hints.ai_src_addr = local_rai->ai_src_addr; hints.ai_src_len = local_rai->ai_src_len; hints.ai_flags &= ~RAI_PASSIVE; - uint8_t* dip = txq->tx_entry->flow.dip_addr; + uint8_t *dip = txq->tx_entry->flow.dip_addr; txq->multicast = mt_is_multicast_ip(dip) ? true : false; snprintf(ip, 16, "%d.%d.%d.%d", dip[0], dip[1], dip[2], dip[3]); char dport[6]; @@ -808,8 +828,8 @@ static int rdma_tx_queue_init(struct mt_rdma_tx_queue* txq) { info("%s(%d, %u), flow hash %u\n", __func__, port, q, txq->flow_hash); /* resolve rx/multicast addr */ - ret = rdma_resolve_addr(txq->cma_id, remote_rai->ai_src_addr, remote_rai->ai_dst_addr, - 2000); + ret = rdma_resolve_addr(txq->cma_id, remote_rai->ai_src_addr, + remote_rai->ai_dst_addr, 2000); if (ret) { err("%s(%d, %u), rdma_resolve_addr fail %d\n", __func__, port, q, ret); rdma_tx_queue_uinit(txq); @@ -828,9 +848,9 @@ static int rdma_tx_queue_init(struct mt_rdma_tx_queue* txq) { return 0; } -static int rdma_rx_mr_init(struct mt_rdma_rx_queue* rxq) { - void* base_addr = NULL; - struct rte_mempool* pool = rxq->mbuf_pool; +static int rdma_rx_mr_init(struct mt_rdma_rx_queue *rxq) { + void *base_addr = NULL; + struct rte_mempool *pool = rxq->mbuf_pool; size_t mr_size; /* l2/l3/l4 headers are not used in data path */ @@ -838,25 +858,28 @@ static int rdma_rx_mr_init(struct mt_rdma_rx_queue* rxq) { RTE_PKTMBUF_HEADROOM - sizeof(struct mt_udp_hdr); base_addr = mt_mempool_mem_addr(pool); mr_size = mt_mempool_mem_size(pool); - rxq->recv_mr = ibv_reg_mr(rxq->pd, base_addr, mr_size, IBV_ACCESS_LOCAL_WRITE); + rxq->recv_mr = + ibv_reg_mr(rxq->pd, base_addr, mr_size, IBV_ACCESS_LOCAL_WRITE); if (!rxq->recv_mr) { err("%s(%d, %u), ibv_reg_mr fail\n", __func__, rxq->port, rxq->q); return -ENOMEM; } - dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", __func__, - rxq->port, rxq->q, base_addr, mr_size, rxq->recv_mr->lkey); + dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", + __func__, rxq->port, rxq->q, base_addr, mr_size, rxq->recv_mr->lkey); return 0; } -static int rdma_rx_queue_uinit(struct mt_rdma_rx_queue* rxq) { +static int rdma_rx_queue_uinit(struct mt_rdma_rx_queue *rxq) { rxq->stop = true; pthread_join(rxq->connect_thread, NULL); if (rxq->multicast && rxq->cma_id && rxq->rai) rdma_leave_multicast(rxq->cma_id, rxq->rai->ai_dst_addr); MT_SAFE_FREE(rxq->recv_mr, ibv_dereg_mr); - if (rxq->cma_id && rxq->cma_id->qp) rdma_destroy_qp(rxq->cma_id); + if (rxq->cma_id && rxq->cma_id->qp) + rdma_destroy_qp(rxq->cma_id); MT_SAFE_FREE(rxq->cq, ibv_destroy_cq); - if (!rxq->multicast) MT_SAFE_FREE(rxq->pd, ibv_dealloc_pd); + if (!rxq->multicast) + MT_SAFE_FREE(rxq->pd, ibv_dealloc_pd); MT_SAFE_FREE(rxq->rai, rdma_freeaddrinfo); MT_SAFE_FREE(rxq->listen_id, rdma_destroy_id); MT_SAFE_FREE(rxq->ec, rdma_destroy_event_channel); @@ -864,7 +887,7 @@ static int rdma_rx_queue_uinit(struct mt_rdma_rx_queue* rxq) { return 0; } -static int rdma_rx_queue_post_init(struct mt_rdma_rx_queue* rxq) { +static int rdma_rx_queue_post_init(struct mt_rdma_rx_queue *rxq) { int ret = 0; enum mtl_port port = rxq->port; uint16_t q = rxq->q; @@ -910,7 +933,7 @@ static int rdma_rx_queue_post_init(struct mt_rdma_rx_queue* rxq) { return ret; } - struct rte_mbuf* mbufs[MT_RDMA_MAX_WR / 2]; + struct rte_mbuf *mbufs[MT_RDMA_MAX_WR / 2]; ret = rte_pktmbuf_alloc_bulk(rxq->mbuf_pool, mbufs, MT_RDMA_MAX_WR / 2); if (ret) { err("%s(%d, %u), mbuf alloc fail %d\n", __func__, port, q, ret); @@ -928,11 +951,11 @@ static int rdma_rx_queue_post_init(struct mt_rdma_rx_queue* rxq) { return 0; } -static void* rdma_rx_connect_thread(void* arg) { - struct mt_rdma_rx_queue* rxq = arg; +static void *rdma_rx_connect_thread(void *arg) { + struct mt_rdma_rx_queue *rxq = arg; enum mtl_port port = rxq->port; uint16_t q = rxq->q; - struct rdma_cm_event* event; + struct rdma_cm_event *event; struct pollfd pfd; pfd.fd = rxq->ec->fd; pfd.events = POLLIN; @@ -944,45 +967,47 @@ static void* rdma_rx_connect_thread(void* arg) { ret = rdma_get_cm_event(rxq->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_CONNECT_REQUEST: - rxq->cma_id = event->id; - ret = rdma_rx_queue_post_init(rxq); - if (ret) { - err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, q); - goto connect_err; - } - struct rdma_conn_param conn_param = { - .qp_num = event->id->qp->qp_num, - }; - ret = rdma_accept(event->id, &conn_param); - if (ret) { - err("%s(%d, %u), rdma_accept fail %d\n", __func__, port, q, ret); - goto connect_err; - } - info("%s(%d, %u), rdma connected\n", __func__, port, q); - rxq->connected = true; - break; - case RDMA_CM_EVENT_ADDR_RESOLVED: - rxq->cma_id = event->id; - ret = rdma_rx_queue_post_init(rxq); - if (ret) { - err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, q); - goto connect_err; - } - ret = rdma_join_multicast(rxq->cma_id, rxq->rai->ai_dst_addr, NULL); - if (ret) { - err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); - goto connect_err; - } - break; - case RDMA_CM_EVENT_MULTICAST_JOIN: - info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); - rxq->connected = true; - break; - default: - err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, q, - rdma_event_str(event->event), event->status); + case RDMA_CM_EVENT_CONNECT_REQUEST: + rxq->cma_id = event->id; + ret = rdma_rx_queue_post_init(rxq); + if (ret) { + err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, + q); + goto connect_err; + } + struct rdma_conn_param conn_param = { + .qp_num = event->id->qp->qp_num, + }; + ret = rdma_accept(event->id, &conn_param); + if (ret) { + err("%s(%d, %u), rdma_accept fail %d\n", __func__, port, q, ret); + goto connect_err; + } + info("%s(%d, %u), rdma connected\n", __func__, port, q); + rxq->connected = true; + break; + case RDMA_CM_EVENT_ADDR_RESOLVED: + rxq->cma_id = event->id; + ret = rdma_rx_queue_post_init(rxq); + if (ret) { + err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, + q); + goto connect_err; + } + ret = rdma_join_multicast(rxq->cma_id, rxq->rai->ai_dst_addr, NULL); + if (ret) { + err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); goto connect_err; + } + break; + case RDMA_CM_EVENT_MULTICAST_JOIN: + info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); + rxq->connected = true; + break; + default: + err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, + q, rdma_event_str(event->event), event->status); + goto connect_err; } rdma_ack_cm_event(event); } @@ -1002,7 +1027,7 @@ static void* rdma_rx_connect_thread(void* arg) { return NULL; } -static int rdma_rx_queue_init(struct mt_rdma_rx_queue* rxq) { +static int rdma_rx_queue_init(struct mt_rdma_rx_queue *rxq) { int ret = 0; enum mtl_port port = rxq->port; uint16_t q = rxq->q; @@ -1024,10 +1049,11 @@ static int rdma_rx_queue_init(struct mt_rdma_rx_queue* rxq) { .ai_flags = RAI_PASSIVE, }; char ip[16]; - snprintf(ip, 16, "%d.%d.%d.%d", rxq->sip[0], rxq->sip[1], rxq->sip[2], rxq->sip[3]); + snprintf(ip, 16, "%d.%d.%d.%d", rxq->sip[0], rxq->sip[1], rxq->sip[2], + rxq->sip[3]); char dport[6]; snprintf(dport, 6, "%d", rxq->rx_entry->flow.dst_port); - struct rdma_addrinfo* local_rai; + struct rdma_addrinfo *local_rai; ret = rdma_getaddrinfo(ip, dport, &hints, &local_rai); if (ret) { err("%s(%d, %u), rdma_getaddrinfo fail %d\n", __func__, port, q, ret); @@ -1043,12 +1069,12 @@ static int rdma_rx_queue_init(struct mt_rdma_rx_queue* rxq) { return ret; } - uint8_t* dip = rxq->rx_entry->flow.dip_addr; + uint8_t *dip = rxq->rx_entry->flow.dip_addr; rxq->multicast = mt_is_multicast_ip(dip) ? true : false; if (rxq->multicast) { rxq->pd = rxq->listen_id->pd; hints.ai_flags = 0; - struct rdma_addrinfo* mcast_rai; + struct rdma_addrinfo *mcast_rai; snprintf(ip, 16, "%d.%d.%d.%d", dip[0], dip[1], dip[2], dip[3]); ret = rdma_getaddrinfo(ip, dport, &hints, &mcast_rai); if (ret) { @@ -1094,16 +1120,17 @@ static int rdma_rx_queue_init(struct mt_rdma_rx_queue* rxq) { return 0; } -struct mt_tx_rdma_entry* mt_tx_rdma_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow, - struct mt_tx_rdma_get_args* args) { +struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow, + struct mt_tx_rdma_get_args *args) { MTL_MAY_UNUSED(args); if (!mt_pmd_is_rdma_ud(impl, port)) { err("%s(%d), this pmd is not rdma ud\n", __func__, port); return NULL; } - struct mt_tx_rdma_entry* entry = + struct mt_tx_rdma_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -1113,8 +1140,8 @@ struct mt_tx_rdma_entry* mt_tx_rdma_get(struct mtl_main_impl* impl, enum mtl_por entry->port = port; rte_memcpy(&entry->flow, flow, sizeof(entry->flow)); - struct mt_rdma_priv* rdma = mt_if(impl, port)->rdma; - struct mt_rdma_tx_queue* txq = NULL; + struct mt_rdma_priv *rdma = mt_if(impl, port)->rdma; + struct mt_rdma_tx_queue *txq = NULL; /* find a null slot */ mt_pthread_mutex_lock(&rdma->queues_lock); @@ -1135,7 +1162,8 @@ struct mt_tx_rdma_entry* mt_tx_rdma_get(struct mtl_main_impl* impl, enum mtl_por entry->txq = txq; entry->queue_id = txq->q; - if (rdma_tx_mrs_pre_init(txq, flow->mrs_bufs, flow->mrs_sizes, flow->num_mrs)) { + if (rdma_tx_mrs_pre_init(txq, flow->mrs_bufs, flow->mrs_sizes, + flow->num_mrs)) { err("%s(%d), rdma_tx_mrs_init fail\n", __func__, port); mt_tx_rdma_put(entry); return NULL; @@ -1147,24 +1175,25 @@ struct mt_tx_rdma_entry* mt_tx_rdma_get(struct mtl_main_impl* impl, enum mtl_por return NULL; } - uint8_t* ip = flow->dip_addr; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], - ip[3], flow->dst_port, entry->queue_id); + uint8_t *ip = flow->dip_addr; + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); return entry; } -static void rdma_tx_queue_flush(struct mt_rdma_tx_queue* txq) { - if (!txq->cma_id || !txq->cma_id->qp) return; +static void rdma_tx_queue_flush(struct mt_rdma_tx_queue *txq) { + if (!txq->cma_id || !txq->cma_id->qp) + return; struct ibv_qp_attr qp_attr = {.qp_state = IBV_QPS_ERR}; ibv_modify_qp(txq->cma_id->qp, &qp_attr, IBV_QP_STATE); rdma_tx_poll_done(txq); } -int mt_tx_rdma_put(struct mt_tx_rdma_entry* entry) { +int mt_tx_rdma_put(struct mt_tx_rdma_entry *entry) { enum mtl_port port = entry->port; - struct mt_txq_flow* flow = &entry->flow; - uint8_t* ip = flow->dip_addr; - struct mt_rdma_tx_queue* txq = entry->txq; + struct mt_txq_flow *flow = &entry->flow; + uint8_t *ip = flow->dip_addr; + struct mt_rdma_tx_queue *txq = entry->txq; if (txq) { rdma_tx_queue_stat(txq); @@ -1174,22 +1203,23 @@ int mt_tx_rdma_put(struct mt_tx_rdma_entry* entry) { rdma_tx_queue_uinit(txq); txq->tx_entry = NULL; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], - ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); } mt_rte_free(entry); return 0; } -uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { +uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return rdma_tx(entry->parent, entry->txq, tx_pkts, nb_pkts); } -struct mt_rx_rdma_entry* mt_rx_rdma_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow, - struct mt_rx_rdma_get_args* args) { +struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow, + struct mt_rx_rdma_get_args *args) { if (!mt_pmd_is_rdma_ud(impl, port)) { err("%s(%d), this pmd is not rdma\n", __func__, port); return NULL; @@ -1197,7 +1227,7 @@ struct mt_rx_rdma_entry* mt_rx_rdma_get(struct mtl_main_impl* impl, enum mtl_por MTL_MAY_UNUSED(args); - struct mt_rx_rdma_entry* entry = + struct mt_rx_rdma_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d), entry malloc fail\n", __func__, port); @@ -1207,8 +1237,8 @@ struct mt_rx_rdma_entry* mt_rx_rdma_get(struct mtl_main_impl* impl, enum mtl_por entry->port = port; rte_memcpy(&entry->flow, flow, sizeof(entry->flow)); - struct mt_rdma_priv* rdma = mt_if(impl, port)->rdma; - struct mt_rdma_rx_queue* rxq = NULL; + struct mt_rdma_priv *rdma = mt_if(impl, port)->rdma; + struct mt_rdma_rx_queue *rxq = NULL; /* find a null slot */ mt_pthread_mutex_lock(&rdma->queues_lock); @@ -1236,33 +1266,34 @@ struct mt_rx_rdma_entry* mt_rx_rdma_get(struct mtl_main_impl* impl, enum mtl_por return NULL; } - uint8_t* ip = flow->dip_addr; - info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], ip[2], - ip[3], flow->dst_port); + uint8_t *ip = flow->dip_addr; + info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], + ip[2], ip[3], flow->dst_port); return entry; } -static void rdma_queue_rx_flush(struct mt_rdma_rx_queue* rxq) { - if (!rxq->qp) return; +static void rdma_queue_rx_flush(struct mt_rdma_rx_queue *rxq) { + if (!rxq->qp) + return; struct ibv_qp_attr qp_attr = {.qp_state = IBV_QPS_ERR}; ibv_modify_qp(rxq->qp, &qp_attr, IBV_QP_STATE); struct ibv_wc wc[32]; int rx = 0; do { rx = ibv_poll_cq(rxq->cq, 32, wc); - struct rte_mbuf* m = NULL; + struct rte_mbuf *m = NULL; for (int i = 0; i < rx; i++) { - m = (struct rte_mbuf*)wc[i].wr_id; + m = (struct rte_mbuf *)wc[i].wr_id; rte_pktmbuf_free(m); } } while (rx > 0); } -int mt_rx_rdma_put(struct mt_rx_rdma_entry* entry) { +int mt_rx_rdma_put(struct mt_rx_rdma_entry *entry) { enum mtl_port port = entry->port; - struct mt_rxq_flow* flow = &entry->flow; - uint8_t* ip = flow->dip_addr; - struct mt_rdma_rx_queue* rxq = entry->rxq; + struct mt_rxq_flow *flow = &entry->flow; + uint8_t *ip = flow->dip_addr; + struct mt_rdma_rx_queue *rxq = entry->rxq; if (rxq) { rdma_rx_queue_stat(rxq); @@ -1271,13 +1302,13 @@ int mt_rx_rdma_put(struct mt_rx_rdma_entry* entry) { rdma_rx_queue_uinit(rxq); rxq->rx_entry = NULL; } - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], - ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); mt_rte_free(entry); return 0; } -uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry* entry, struct rte_mbuf** rx_pkts, - const uint16_t nb_pkts) { +uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return rdma_rx(entry, rx_pkts, nb_pkts); } diff --git a/lib/src/dev/mt_rdma_ud.h b/lib/src/dev/mt_rdma_ud.h index 043565228..a39870809 100644 --- a/lib/src/dev/mt_rdma_ud.h +++ b/lib/src/dev/mt_rdma_ud.h @@ -17,40 +17,41 @@ struct mt_rx_rdma_get_args { #ifdef MTL_HAS_RDMA_BACKEND -int mt_dev_rdma_init(struct mt_interface* inf); -int mt_dev_rdma_uinit(struct mt_interface* inf); - -struct mt_tx_rdma_entry* mt_tx_rdma_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_txq_flow* flow, - struct mt_tx_rdma_get_args* args); -int mt_tx_rdma_put(struct mt_tx_rdma_entry* entry); -uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry* entry, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts); - -struct mt_rx_rdma_entry* mt_rx_rdma_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow, - struct mt_rx_rdma_get_args* args); -int mt_rx_rdma_put(struct mt_rx_rdma_entry* entry); -uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry* entry, struct rte_mbuf** rx_pkts, - const uint16_t nb_pkts); +int mt_dev_rdma_init(struct mt_interface *inf); +int mt_dev_rdma_uinit(struct mt_interface *inf); + +struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow, + struct mt_tx_rdma_get_args *args); +int mt_tx_rdma_put(struct mt_tx_rdma_entry *entry); +uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts); + +struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow, + struct mt_rx_rdma_get_args *args); +int mt_rx_rdma_put(struct mt_rx_rdma_entry *entry); +uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); #else #include "../mt_log.h" -static inline int mt_dev_rdma_init(struct mt_interface* inf) { +static inline int mt_dev_rdma_init(struct mt_interface *inf) { err("%s(%d), no rdma support for this build\n", __func__, inf->port); return -ENOTSUP; } -static inline int mt_dev_rdma_uinit(struct mt_interface* inf) { +static inline int mt_dev_rdma_uinit(struct mt_interface *inf) { MTL_MAY_UNUSED(inf); return -ENOTSUP; } -static inline struct mt_tx_rdma_entry* mt_tx_rdma_get(struct mtl_main_impl* impl, - enum mtl_port port, - struct mt_txq_flow* flow, - struct mt_tx_rdma_get_args* args) { +static inline struct mt_tx_rdma_entry * +mt_tx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_txq_flow *flow, struct mt_tx_rdma_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); @@ -58,23 +59,23 @@ static inline struct mt_tx_rdma_entry* mt_tx_rdma_get(struct mtl_main_impl* impl return NULL; } -static inline int mt_tx_rdma_put(struct mt_tx_rdma_entry* entry) { +static inline int mt_tx_rdma_put(struct mt_tx_rdma_entry *entry) { MTL_MAY_UNUSED(entry); return -ENOTSUP; } -static inline uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry* entry, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { +static inline uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, + struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(tx_pkts); MTL_MAY_UNUSED(nb_pkts); return 0; } -static inline struct mt_rx_rdma_entry* mt_rx_rdma_get(struct mtl_main_impl* impl, - enum mtl_port port, - struct mt_rxq_flow* flow, - struct mt_rx_rdma_get_args* args) { +static inline struct mt_rx_rdma_entry * +mt_rx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow, struct mt_rx_rdma_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); @@ -82,13 +83,13 @@ static inline struct mt_rx_rdma_entry* mt_rx_rdma_get(struct mtl_main_impl* impl return NULL; } -static inline int mt_rx_rdma_put(struct mt_rx_rdma_entry* entry) { +static inline int mt_rx_rdma_put(struct mt_rx_rdma_entry *entry) { MTL_MAY_UNUSED(entry); return -ENOTSUP; } -static inline uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry* entry, - struct rte_mbuf** rx_pkts, +static inline uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry *entry, + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(rx_pkts); @@ -97,11 +98,11 @@ static inline uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry* entry, } #endif -static inline uint16_t mt_tx_rdma_queue_id(struct mt_tx_rdma_entry* entry) { +static inline uint16_t mt_tx_rdma_queue_id(struct mt_tx_rdma_entry *entry) { return entry->queue_id; } -static inline uint16_t mt_rx_rdma_queue_id(struct mt_rx_rdma_entry* entry) { +static inline uint16_t mt_rx_rdma_queue_id(struct mt_rx_rdma_entry *entry) { return entry->queue_id; } diff --git a/lib/src/mt_admin.c b/lib/src/mt_admin.c index bb1cabeb3..8f6ea53ff 100644 --- a/lib/src/mt_admin.c +++ b/lib/src/mt_admin.c @@ -9,20 +9,21 @@ #include "st2110/st_rx_video_session.h" #include "st2110/st_tx_video_session.h" -static inline struct mt_admin* mt_get_admin(struct mtl_main_impl* impl) { +static inline struct mt_admin *mt_get_admin(struct mtl_main_impl *impl) { return &impl->admin; } -static int admin_cal_cpu_busy(struct mtl_main_impl* impl) { - struct mtl_sch_impl* sch; - struct st_tx_video_sessions_mgr* tx_mgr; - struct st_tx_video_session_impl* tx_s; - struct st_rx_video_sessions_mgr* rx_mgr; - struct st_rx_video_session_impl* rx_s; +static int admin_cal_cpu_busy(struct mtl_main_impl *impl) { + struct mtl_sch_impl *sch; + struct st_tx_video_sessions_mgr *tx_mgr; + struct st_tx_video_session_impl *tx_s; + struct st_rx_video_sessions_mgr *rx_mgr; + struct st_rx_video_session_impl *rx_s; for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) continue; + if (!mt_sch_started(sch)) + continue; /* cal tx video cpu */ tx_mgr = &sch->tx_video_mgr; @@ -48,16 +49,17 @@ static int admin_cal_cpu_busy(struct mtl_main_impl* impl) { return 0; } -static int admin_clear_cpu_busy(struct mtl_main_impl* impl) { - struct mtl_sch_impl* sch; - struct st_tx_video_sessions_mgr* tx_mgr; - struct st_tx_video_session_impl* tx_s; - struct st_rx_video_sessions_mgr* rx_mgr; - struct st_rx_video_session_impl* rx_s; +static int admin_clear_cpu_busy(struct mtl_main_impl *impl) { + struct mtl_sch_impl *sch; + struct st_tx_video_sessions_mgr *tx_mgr; + struct st_tx_video_session_impl *tx_s; + struct st_rx_video_sessions_mgr *rx_mgr; + struct st_rx_video_session_impl *rx_s; for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) continue; + if (!mt_sch_started(sch)) + continue; /* cal tx video cpu */ tx_mgr = &sch->tx_video_mgr; @@ -83,27 +85,27 @@ static int admin_clear_cpu_busy(struct mtl_main_impl* impl) { return 0; } -static inline int tx_video_quota_mbs(struct st_tx_video_session_impl* s) { +static inline int tx_video_quota_mbs(struct st_tx_video_session_impl *s) { if (s->st22_handle) return s->st22_handle->quota_mbs; else return s->st20_handle->quota_mbs; } -static inline void tx_video_set_sch(struct st_tx_video_session_impl* s, - struct mtl_sch_impl* sch) { +static inline void tx_video_set_sch(struct st_tx_video_session_impl *s, + struct mtl_sch_impl *sch) { if (s->st22_handle) s->st22_handle->sch = sch; else s->st20_handle->sch = sch; } -static int tx_video_migrate_to(struct st_tx_video_session_impl* s, - struct mtl_sch_impl* from_sch, - struct mtl_sch_impl* to_sch) { - struct st_tx_video_sessions_mgr* to_tx_mgr = &to_sch->tx_video_mgr; +static int tx_video_migrate_to(struct st_tx_video_session_impl *s, + struct mtl_sch_impl *from_sch, + struct mtl_sch_impl *to_sch) { + struct st_tx_video_sessions_mgr *to_tx_mgr = &to_sch->tx_video_mgr; int to_midx = to_tx_mgr->idx; - struct st_tx_video_sessions_mgr* from_tx_mgr = &from_sch->tx_video_mgr; + struct st_tx_video_sessions_mgr *from_tx_mgr = &from_sch->tx_video_mgr; int from_midx = from_tx_mgr->idx; int from_idx = s->idx; @@ -118,7 +120,8 @@ static int tx_video_migrate_to(struct st_tx_video_session_impl* s, int i; /* find one empty slot in the new sch */ for (i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { - if (!tx_video_session_get_empty(to_tx_mgr, i)) continue; + if (!tx_video_session_get_empty(to_tx_mgr, i)) + continue; /* remove from old sch */ from_tx_mgr->sessions[from_idx] = NULL; /* migrate resource */ @@ -140,22 +143,25 @@ static int tx_video_migrate_to(struct st_tx_video_session_impl* s, return 0; } -static int admin_tx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { - struct st_tx_video_session_impl* busy_s = NULL; - struct mtl_sch_impl* from_sch = NULL; +static int admin_tx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { + struct st_tx_video_session_impl *busy_s = NULL; + struct mtl_sch_impl *from_sch = NULL; int ret; for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { - struct mtl_sch_impl* sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) continue; - if (!mt_sch_has_busy(sch)) continue; + struct mtl_sch_impl *sch = mt_sch_instance(impl, sch_idx); + if (!mt_sch_started(sch)) + continue; + if (!mt_sch_has_busy(sch)) + continue; /* check if any busy session in this cpu */ - struct st_tx_video_session_impl* busy_s_in_sch = NULL; - struct st_tx_video_sessions_mgr* tx_mgr = &sch->tx_video_mgr; + struct st_tx_video_session_impl *busy_s_in_sch = NULL; + struct st_tx_video_sessions_mgr *tx_mgr = &sch->tx_video_mgr; for (int j = 0; j < tx_mgr->max_idx; j++) { - struct st_tx_video_session_impl* tx_s = tx_video_session_get(tx_mgr, j); - if (!tx_s) continue; + struct st_tx_video_session_impl *tx_s = tx_video_session_get(tx_mgr, j); + if (!tx_s) + continue; if (tx_video_session_is_cpu_busy(tx_s)) { busy_s_in_sch = tx_s; /* last one as the busy one */ } @@ -169,18 +175,22 @@ static int admin_tx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { } } - if (!busy_s) return 0; /* no busy session */ + if (!busy_s) + return 0; /* no busy session */ int quota_mbs = tx_video_quota_mbs(busy_s); if (quota_mbs >= from_sch->data_quota_mbs_total) { return 0; /* only one video session in this sch */ } - dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); - struct mtl_sch_impl* to_sch = mt_sch_get_by_socket( - impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, mt_sch_socket_id(from_sch)); + dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, + busy_s->idx); + struct mtl_sch_impl *to_sch = + mt_sch_get_by_socket(impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, + mt_sch_socket_id(from_sch)); if (!to_sch) { - err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); + err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, + busy_s->idx); return -EIO; } @@ -190,7 +200,8 @@ static int admin_tx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { ret = tx_video_migrate_to(busy_s, from_sch, to_sch); if (ret < 0) { - err("%s, session(%d,%d) migrate to fail\n", __func__, from_sch->idx, busy_s->idx); + err("%s, session(%d,%d) migrate to fail\n", __func__, from_sch->idx, + busy_s->idx); mt_sch_put(to_sch, quota_mbs); /* put back new sch */ return ret; } @@ -199,28 +210,28 @@ static int admin_tx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { return 0; } -static inline int rx_video_quota_mbs(struct st_rx_video_session_impl* s) { +static inline int rx_video_quota_mbs(struct st_rx_video_session_impl *s) { if (s->st22_handle) return s->st22_handle->quota_mbs; else return s->st20_handle->quota_mbs; } -static inline void rx_video_set_sch(struct st_rx_video_session_impl* s, - struct mtl_sch_impl* sch) { +static inline void rx_video_set_sch(struct st_rx_video_session_impl *s, + struct mtl_sch_impl *sch) { if (s->st22_handle) s->st22_handle->sch = sch; else s->st20_handle->sch = sch; } -static int rx_video_migrate_to(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s, - struct mtl_sch_impl* from_sch, - struct mtl_sch_impl* to_sch) { - struct st_rx_video_sessions_mgr* to_rx_mgr = &to_sch->rx_video_mgr; +static int rx_video_migrate_to(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s, + struct mtl_sch_impl *from_sch, + struct mtl_sch_impl *to_sch) { + struct st_rx_video_sessions_mgr *to_rx_mgr = &to_sch->rx_video_mgr; int to_midx = to_rx_mgr->idx; - struct st_rx_video_sessions_mgr* from_rx_mgr = &from_sch->rx_video_mgr; + struct st_rx_video_sessions_mgr *from_rx_mgr = &from_sch->rx_video_mgr; int from_midx = from_rx_mgr->idx; int from_idx = s->idx; @@ -235,7 +246,8 @@ static int rx_video_migrate_to(struct mtl_main_impl* impl, int i; /* find one empty slot in the new sch */ for (i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { - if (!rx_video_session_get_empty(to_rx_mgr, i)) continue; + if (!rx_video_session_get_empty(to_rx_mgr, i)) + continue; /* remove from old sch */ from_rx_mgr->sessions[from_idx] = NULL; /* migrate resource */ @@ -257,23 +269,27 @@ static int rx_video_migrate_to(struct mtl_main_impl* impl, return 0; } -static int admin_rx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { - struct st_rx_video_session_impl* busy_s = NULL; - struct mtl_sch_impl* from_sch = NULL; +static int admin_rx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { + struct st_rx_video_session_impl *busy_s = NULL; + struct mtl_sch_impl *from_sch = NULL; int ret; for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { - struct mtl_sch_impl* sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) continue; - if (!mt_sch_has_busy(sch)) continue; + struct mtl_sch_impl *sch = mt_sch_instance(impl, sch_idx); + if (!mt_sch_started(sch)) + continue; + if (!mt_sch_has_busy(sch)) + continue; /* check if any busy session in this cpu */ - struct st_rx_video_session_impl* busy_s_in_sch = NULL; - struct st_rx_video_sessions_mgr* rx_mgr = &sch->rx_video_mgr; + struct st_rx_video_session_impl *busy_s_in_sch = NULL; + struct st_rx_video_sessions_mgr *rx_mgr = &sch->rx_video_mgr; for (int j = 0; j < rx_mgr->max_idx; j++) { - struct st_rx_video_session_impl* rx_s = rx_video_session_get(rx_mgr, j); - if (!rx_s) continue; - if (rx_video_session_can_migrate(rx_s) && rx_video_session_is_cpu_busy(rx_s)) { + struct st_rx_video_session_impl *rx_s = rx_video_session_get(rx_mgr, j); + if (!rx_s) + continue; + if (rx_video_session_can_migrate(rx_s) && + rx_video_session_is_cpu_busy(rx_s)) { busy_s_in_sch = rx_s; /* last one as the busy one */ } rx_video_session_put(rx_mgr, j); @@ -286,18 +302,22 @@ static int admin_rx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { } } - if (!busy_s) return 0; /* no busy session */ + if (!busy_s) + return 0; /* no busy session */ int quota_mbs = rx_video_quota_mbs(busy_s); if (quota_mbs >= from_sch->data_quota_mbs_total) { return 0; /* only one video session in this sch */ } - dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); - struct mtl_sch_impl* to_sch = mt_sch_get_by_socket( - impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, mt_sch_socket_id(from_sch)); + dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, + busy_s->idx); + struct mtl_sch_impl *to_sch = + mt_sch_get_by_socket(impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, + mt_sch_socket_id(from_sch)); if (!to_sch) { - err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); + err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, + busy_s->idx); return -EIO; } @@ -307,7 +327,8 @@ static int admin_rx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { ret = rx_video_migrate_to(impl, busy_s, from_sch, to_sch); if (ret < 0) { - err("%s, session(%d,%d) migrate fail\n", __func__, from_sch->idx, busy_s->idx); + err("%s, session(%d,%d) migrate fail\n", __func__, from_sch->idx, + busy_s->idx); mt_sch_put(to_sch, quota_mbs); /* put back new sch */ return ret; } @@ -316,21 +337,21 @@ static int admin_rx_video_migrate(struct mtl_main_impl* impl, bool* migrated) { return 0; } -static void admin_wakeup_thread(struct mt_admin* admin) { +static void admin_wakeup_thread(struct mt_admin *admin) { mt_pthread_mutex_lock(&admin->admin_wake_mutex); mt_pthread_cond_signal(&admin->admin_wake_cond); mt_pthread_mutex_unlock(&admin->admin_wake_mutex); } -static void admin_alarm_handler(void* param) { - struct mtl_main_impl* impl = param; - struct mt_admin* admin = mt_get_admin(impl); +static void admin_alarm_handler(void *param) { + struct mtl_main_impl *impl = param; + struct mt_admin *admin = mt_get_admin(impl); admin_wakeup_thread(admin); } -static int admin_func(struct mtl_main_impl* impl) { - struct mt_admin* admin = mt_get_admin(impl); +static int admin_func(struct mtl_main_impl *impl) { + struct mt_admin *admin = mt_get_admin(impl); dbg("%s, start\n", __func__); mt_update_admin_port_stats(impl); @@ -346,7 +367,8 @@ static int admin_func(struct mtl_main_impl* impl) { admin_rx_video_migrate(impl, &migrated); } - if (migrated) admin_clear_cpu_busy(impl); + if (migrated) + admin_clear_cpu_busy(impl); rte_eal_alarm_set(admin->period_us, admin_alarm_handler, impl); @@ -355,9 +377,9 @@ static int admin_func(struct mtl_main_impl* impl) { return 0; } -static void* admin_thread(void* arg) { - struct mtl_main_impl* impl = arg; - struct mt_admin* admin = mt_get_admin(impl); +static void *admin_thread(void *arg) { + struct mtl_main_impl *impl = arg; + struct mt_admin *admin = mt_get_admin(impl); info("%s, start\n", __func__); while (rte_atomic32_read(&admin->admin_stop) == 0) { @@ -366,15 +388,16 @@ static void* admin_thread(void* arg) { mt_pthread_cond_wait(&admin->admin_wake_cond, &admin->admin_wake_mutex); mt_pthread_mutex_unlock(&admin->admin_wake_mutex); - if (!rte_atomic32_read(&admin->admin_stop)) admin_func(impl); + if (!rte_atomic32_read(&admin->admin_stop)) + admin_func(impl); } info("%s, stop\n", __func__); return NULL; } -int mt_admin_init(struct mtl_main_impl* impl) { - struct mt_admin* admin = mt_get_admin(impl); +int mt_admin_init(struct mtl_main_impl *impl) { + struct mt_admin *admin = mt_get_admin(impl); admin->period_us = 6 * US_PER_S; /* 6s */ mt_pthread_mutex_init(&admin->admin_wake_mutex, NULL); @@ -382,7 +405,8 @@ int mt_admin_init(struct mtl_main_impl* impl) { rte_atomic32_set(&admin->admin_stop, 0); int ret = pthread_create(&admin->admin_tid, NULL, admin_thread, impl); - if (ret < 0) return ret; + if (ret < 0) + return ret; mtl_thread_setname(admin->admin_tid, "mtl_admin"); rte_eal_alarm_set(admin->period_us, admin_alarm_handler, impl); @@ -390,8 +414,8 @@ int mt_admin_init(struct mtl_main_impl* impl) { return 0; } -int mt_admin_uinit(struct mtl_main_impl* impl) { - struct mt_admin* admin = mt_get_admin(impl); +int mt_admin_uinit(struct mtl_main_impl *impl) { + struct mt_admin *admin = mt_get_admin(impl); if (admin->admin_tid) { rte_atomic32_set(&admin->admin_stop, 1); diff --git a/lib/src/mt_admin.h b/lib/src/mt_admin.h index 686916b8b..07118b4c9 100644 --- a/lib/src/mt_admin.h +++ b/lib/src/mt_admin.h @@ -7,7 +7,7 @@ #include "mt_main.h" -int mt_admin_init(struct mtl_main_impl* impl); -int mt_admin_uinit(struct mtl_main_impl* impl); +int mt_admin_init(struct mtl_main_impl *impl); +int mt_admin_uinit(struct mtl_main_impl *impl); #endif diff --git a/lib/src/mt_arp.c b/lib/src/mt_arp.c index 7db26da7f..99504bc2d 100644 --- a/lib/src/mt_arp.c +++ b/lib/src/mt_arp.c @@ -13,15 +13,15 @@ #define ARP_REQ_PERIOD_MS (500) #define ARP_REQ_PERIOD_US (ARP_REQ_PERIOD_MS * 1000) -static int arp_start_arp_timer(struct mt_arp_impl* arp_impl); +static int arp_start_arp_timer(struct mt_arp_impl *arp_impl); -static inline struct mt_arp_impl* get_arp(struct mtl_main_impl* impl, +static inline struct mt_arp_impl *get_arp(struct mtl_main_impl *impl, enum mtl_port port) { return impl->arp[port]; } -static void arp_reset(struct mt_arp_impl* arp) { - struct mt_arp_entry* entry = NULL; +static void arp_reset(struct mt_arp_impl *arp) { + struct mt_arp_entry *entry = NULL; for (int i = 0; i < MT_ARP_ENTRY_MAX; i++) { entry = &arp->entries[i]; @@ -32,7 +32,7 @@ static void arp_reset(struct mt_arp_impl* arp) { } } -static bool arp_is_valid_hdr(struct rte_arp_hdr* hdr) { +static bool arp_is_valid_hdr(struct rte_arp_hdr *hdr) { if ((ntohs(hdr->arp_hardware) != RTE_ARP_HRD_ETHER) && (ntohs(hdr->arp_protocol) != RTE_ETHER_TYPE_IPV4) && (hdr->arp_hlen != RTE_ETHER_ADDR_LEN) && (hdr->arp_plen != 4)) { @@ -43,16 +43,18 @@ static bool arp_is_valid_hdr(struct rte_arp_hdr* hdr) { return true; } -static int arp_receive_request(struct mtl_main_impl* impl, struct rte_arp_hdr* request, +static int arp_receive_request(struct mtl_main_impl *impl, + struct rte_arp_hdr *request, enum mtl_port port) { - if (!arp_is_valid_hdr(request)) return -EINVAL; + if (!arp_is_valid_hdr(request)) + return -EINVAL; - if (request->arp_data.arp_tip != *(uint32_t*)mt_sip_addr(impl, port)) { + if (request->arp_data.arp_tip != *(uint32_t *)mt_sip_addr(impl, port)) { dbg("%s(%d), not our arp\n", __func__, port); return -EINVAL; } - struct rte_mbuf* rpl_pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); + struct rte_mbuf *rpl_pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); if (!rpl_pkt) { err("%s(%d), rpl_pkt alloc fail\n", __func__, port); return -ENOMEM; @@ -61,22 +63,22 @@ static int arp_receive_request(struct mtl_main_impl* impl, struct rte_arp_hdr* r rpl_pkt->pkt_len = rpl_pkt->data_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_arp_hdr); - struct rte_ether_hdr* eth = rte_pktmbuf_mtod(rpl_pkt, struct rte_ether_hdr*); + struct rte_ether_hdr *eth = rte_pktmbuf_mtod(rpl_pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); rte_ether_addr_copy(&request->arp_data.arp_sha, mt_eth_d_addr(eth)); - eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL + eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL - struct rte_arp_hdr* arp = - rte_pktmbuf_mtod_offset(rpl_pkt, struct rte_arp_hdr*, sizeof(struct rte_ether_hdr)); + struct rte_arp_hdr *arp = rte_pktmbuf_mtod_offset( + rpl_pkt, struct rte_arp_hdr *, sizeof(struct rte_ether_hdr)); arp->arp_hardware = htons(RTE_ARP_HRD_ETHER); - arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol - arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC - arp->arp_plen = 4; // size of fo IP + arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol + arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC + arp->arp_plen = 4; // size of fo IP arp->arp_opcode = htons(RTE_ARP_OP_REPLY); rte_ether_addr_copy(&request->arp_data.arp_sha, &arp->arp_data.arp_tha); arp->arp_data.arp_tip = request->arp_data.arp_sip; mt_macaddr_get(impl, port, &arp->arp_data.arp_sha); - arp->arp_data.arp_sip = *(uint32_t*)mt_sip_addr(impl, port); + arp->arp_data.arp_sip = *(uint32_t *)mt_sip_addr(impl, port); /* send arp reply packet */ uint16_t send = mt_sys_queue_tx_burst(impl, port, &rpl_pkt, 1); @@ -85,28 +87,32 @@ static int arp_receive_request(struct mtl_main_impl* impl, struct rte_arp_hdr* r rte_pktmbuf_free(rpl_pkt); } - uint8_t* ip = (uint8_t*)&request->arp_data.arp_sip; - info_once("%s(%d), send to %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); + uint8_t *ip = (uint8_t *)&request->arp_data.arp_sip; + info_once("%s(%d), send to %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3]); return 0; } -static int arp_receive_reply(struct mtl_main_impl* impl, struct rte_arp_hdr* reply, - enum mtl_port port) { - if (!arp_is_valid_hdr(reply)) return -EINVAL; +static int arp_receive_reply(struct mtl_main_impl *impl, + struct rte_arp_hdr *reply, enum mtl_port port) { + if (!arp_is_valid_hdr(reply)) + return -EINVAL; - if (reply->arp_data.arp_tip != *(uint32_t*)mt_sip_addr(impl, port)) { + if (reply->arp_data.arp_tip != *(uint32_t *)mt_sip_addr(impl, port)) { dbg("%s(%d), not our arp\n", __func__, port); return -EINVAL; } - uint8_t* ip = (uint8_t*)&reply->arp_data.arp_sip; - uint8_t* addr_bytes = reply->arp_data.arp_sha.addr_bytes; - info_once("%s(%d), from %d.%d.%d.%d, mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", - __func__, port, ip[0], ip[1], ip[2], ip[3], addr_bytes[0], addr_bytes[1], - addr_bytes[2], addr_bytes[3], addr_bytes[4], addr_bytes[5]); + uint8_t *ip = (uint8_t *)&reply->arp_data.arp_sip; + uint8_t *addr_bytes = reply->arp_data.arp_sha.addr_bytes; + info_once("%s(%d), from %d.%d.%d.%d, mac: " + "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", + __func__, port, ip[0], ip[1], ip[2], ip[3], addr_bytes[0], + addr_bytes[1], addr_bytes[2], addr_bytes[3], addr_bytes[4], + addr_bytes[5]); - struct mt_arp_impl* arp_impl = get_arp(impl, port); - struct mt_arp_entry* entry = NULL; + struct mt_arp_impl *arp_impl = get_arp(impl, port); + struct mt_arp_entry *entry = NULL; /* check if our request */ mt_pthread_mutex_lock(&arp_impl->mutex); @@ -114,25 +120,28 @@ static int arp_receive_reply(struct mtl_main_impl* impl, struct rte_arp_hdr* rep for (i = 0; i < MT_ARP_ENTRY_MAX; i++) { entry = &arp_impl->entries[i]; - if (entry->ip == reply->arp_data.arp_sip) break; + if (entry->ip == reply->arp_data.arp_sip) + break; } if (i >= MT_ARP_ENTRY_MAX) { - err_once("%s(%d), not our arp request, from %d.%d.%d.%d\n", __func__, port, ip[0], - ip[1], ip[2], ip[3]); + err_once("%s(%d), not our arp request, from %d.%d.%d.%d\n", __func__, port, + ip[0], ip[1], ip[2], ip[3]); mt_pthread_mutex_unlock(&arp_impl->mutex); return -EINVAL; } /* save to arp table */ - memcpy(entry->ea.addr_bytes, reply->arp_data.arp_sha.addr_bytes, RTE_ETHER_ADDR_LEN); + memcpy(entry->ea.addr_bytes, reply->arp_data.arp_sha.addr_bytes, + RTE_ETHER_ADDR_LEN); rte_atomic32_set(&entry->mac_ready, 1); mt_pthread_mutex_unlock(&arp_impl->mutex); return 0; } -static int arp_send_req(struct mtl_main_impl* impl, enum mtl_port port, uint32_t ip) { - struct rte_mbuf* req_pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); +static int arp_send_req(struct mtl_main_impl *impl, enum mtl_port port, + uint32_t ip) { + struct rte_mbuf *req_pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); if (!req_pkt) { err("%s(%d), req_pkt malloc fail\n", __func__, port); return -ENOMEM; @@ -141,19 +150,19 @@ static int arp_send_req(struct mtl_main_impl* impl, enum mtl_port port, uint32_t req_pkt->pkt_len = req_pkt->data_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_arp_hdr); - struct rte_ether_hdr* eth = rte_pktmbuf_mtod(req_pkt, struct rte_ether_hdr*); + struct rte_ether_hdr *eth = rte_pktmbuf_mtod(req_pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); memset(mt_eth_d_addr(eth), 0xFF, RTE_ETHER_ADDR_LEN); - eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL - struct rte_arp_hdr* arp = - rte_pktmbuf_mtod_offset(req_pkt, struct rte_arp_hdr*, sizeof(struct rte_ether_hdr)); + eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL + struct rte_arp_hdr *arp = rte_pktmbuf_mtod_offset( + req_pkt, struct rte_arp_hdr *, sizeof(struct rte_ether_hdr)); arp->arp_hardware = htons(RTE_ARP_HRD_ETHER); - arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol - arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC - arp->arp_plen = 4; // size of fo IP + arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol + arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC + arp->arp_plen = 4; // size of fo IP arp->arp_opcode = htons(RTE_ARP_OP_REQUEST); arp->arp_data.arp_tip = ip; - arp->arp_data.arp_sip = *(uint32_t*)mt_sip_addr(impl, port); + arp->arp_data.arp_sip = *(uint32_t *)mt_sip_addr(impl, port); mt_macaddr_get(impl, port, &arp->arp_data.arp_sha); memset(&arp->arp_data.arp_tha, 0, RTE_ETHER_ADDR_LEN); @@ -168,14 +177,15 @@ static int arp_send_req(struct mtl_main_impl* impl, enum mtl_port port, uint32_t return 0; } -static int arp_get_result(struct mt_arp_impl* arp_impl, struct mt_arp_entry* entry, - int timeout_ms) { +static int arp_get_result(struct mt_arp_impl *arp_impl, + struct mt_arp_entry *entry, int timeout_ms) { enum mtl_port port = arp_impl->port; int retry = 0; int max_retry = 0; int sleep_interval_ms = 500; - if (timeout_ms) max_retry = (timeout_ms / sleep_interval_ms) + 1; + if (timeout_ms) + max_retry = (timeout_ms / sleep_interval_ms) + 1; /* wait the arp result */ while (!rte_atomic32_read(&entry->mac_ready)) { @@ -185,7 +195,8 @@ static int arp_get_result(struct mt_arp_impl* arp_impl, struct mt_arp_entry* ent } if (retry >= max_retry) { if (max_retry) /* log only if not zero timeout */ - err("%s(%d), cache fail as timeout to %d ms\n", __func__, port, timeout_ms); + err("%s(%d), cache fail as timeout to %d ms\n", __func__, port, + timeout_ms); return -EIO; } mt_sleep_ms(sleep_interval_ms); @@ -193,8 +204,8 @@ static int arp_get_result(struct mt_arp_impl* arp_impl, struct mt_arp_entry* ent if (0 == (retry % 10)) { uint8_t ip[MTL_IP_ADDR_LEN]; mt_u32_to_ip(entry->ip, ip); - info("%s(%d), cache waiting arp from %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3]); + info("%s(%d), cache waiting arp from %d.%d.%d.%d\n", __func__, port, + ip[0], ip[1], ip[2], ip[3]); } } @@ -202,11 +213,11 @@ static int arp_get_result(struct mt_arp_impl* arp_impl, struct mt_arp_entry* ent return 0; } -static void arp_timer_cb(void* param) { - struct mt_arp_impl* arp_impl = param; - struct mt_arp_entry* entry = NULL; +static void arp_timer_cb(void *param) { + struct mt_arp_impl *arp_impl = param; + struct mt_arp_entry *entry = NULL; enum mtl_port port = arp_impl->port; - struct mtl_main_impl* impl = arp_impl->parent; + struct mtl_main_impl *impl = arp_impl->parent; int pending = 0; dbg("%s(%d), start\n", __func__, port); @@ -229,7 +240,7 @@ static void arp_timer_cb(void* param) { } } -static int arp_start_arp_timer(struct mt_arp_impl* arp_impl) { +static int arp_start_arp_timer(struct mt_arp_impl *arp_impl) { int ret = 0; mt_pthread_mutex_lock(&arp_impl->mutex); @@ -247,23 +258,25 @@ static int arp_start_arp_timer(struct mt_arp_impl* arp_impl) { return ret; } -int mt_arp_parse(struct mtl_main_impl* impl, struct rte_arp_hdr* hdr, +int mt_arp_parse(struct mtl_main_impl *impl, struct rte_arp_hdr *hdr, enum mtl_port port) { switch (ntohs(hdr->arp_opcode)) { - case RTE_ARP_OP_REQUEST: - return arp_receive_request(impl, hdr, port); - case RTE_ARP_OP_REPLY: - return arp_receive_reply(impl, hdr, port); - default: - err("%s, mt_arp_parse %04x unimplemented\n", __func__, ntohs(hdr->arp_opcode)); - return -EINVAL; + case RTE_ARP_OP_REQUEST: + return arp_receive_request(impl, hdr, port); + case RTE_ARP_OP_REPLY: + return arp_receive_reply(impl, hdr, port); + default: + err("%s, mt_arp_parse %04x unimplemented\n", __func__, + ntohs(hdr->arp_opcode)); + return -EINVAL; } } -static int mt_arp_cni_get_mac(struct mtl_main_impl* impl, struct rte_ether_addr* ea, - enum mtl_port port, uint32_t ip, int timeout_ms) { - struct mt_arp_impl* arp_impl = get_arp(impl, port); - struct mt_arp_entry* entry = NULL; +static int mt_arp_cni_get_mac(struct mtl_main_impl *impl, + struct rte_ether_addr *ea, enum mtl_port port, + uint32_t ip, int timeout_ms) { + struct mt_arp_impl *arp_impl = get_arp(impl, port); + struct mt_arp_entry *entry = NULL; int ret; mt_pthread_mutex_lock(&arp_impl->mutex); @@ -282,7 +295,8 @@ static int mt_arp_cni_get_mac(struct mtl_main_impl* impl, struct rte_ether_addr* entry = &arp_impl->entries[i]; /* find a empty slot */ - if (entry->ip == 0) break; + if (entry->ip == 0) + break; } if (i >= MT_ARP_ENTRY_MAX) { warn("%s(%d), reset arp\n", __func__, port); @@ -297,12 +311,13 @@ static int mt_arp_cni_get_mac(struct mtl_main_impl* impl, struct rte_ether_addr* uint8_t addr[MTL_IP_ADDR_LEN]; mt_u32_to_ip(ip, addr); - info("%s(%d), %d.%d.%d.%d alloc at %d\n", __func__, port, addr[0], addr[1], addr[2], - addr[3], i); + info("%s(%d), %d.%d.%d.%d alloc at %d\n", __func__, port, addr[0], addr[1], + addr[2], addr[3], i); /* arp and wait the reply */ - arp_send_req(impl, port, ip); /* send the first arp request packet */ - arp_start_arp_timer(arp_impl); /* start the timer to monitor if send arp again */ + arp_send_req(impl, port, ip); /* send the first arp request packet */ + arp_start_arp_timer( + arp_impl); /* start the timer to monitor if send arp again */ get_result: /* wait the arp result */ @@ -314,13 +329,14 @@ static int mt_arp_cni_get_mac(struct mtl_main_impl* impl, struct rte_ether_addr* return ret; } -int mt_arp_init(struct mtl_main_impl* impl) { +int mt_arp_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); int socket = mt_socket_id(impl, MTL_PORT_P); for (int i = 0; i < num_ports; i++) { - if (mt_has_virtio_user(impl, i)) continue; /* use kernel path */ - struct mt_arp_impl* arp = mt_rte_zmalloc_socket(sizeof(*arp), socket); + if (mt_has_virtio_user(impl, i)) + continue; /* use kernel path */ + struct mt_arp_impl *arp = mt_rte_zmalloc_socket(sizeof(*arp), socket); if (!arp) { err("%s(%d), arp malloc fail\n", __func__, i); mt_arp_uinit(impl); @@ -338,12 +354,13 @@ int mt_arp_init(struct mtl_main_impl* impl) { return 0; } -int mt_arp_uinit(struct mtl_main_impl* impl) { +int mt_arp_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { - struct mt_arp_impl* arp = get_arp(impl, i); - if (!arp) continue; + struct mt_arp_impl *arp = get_arp(impl, i); + if (!arp) + continue; mt_pthread_mutex_destroy(&arp->mutex); @@ -355,14 +372,16 @@ int mt_arp_uinit(struct mtl_main_impl* impl) { return 0; } -int mt_arp_get_mac(struct mtl_main_impl* impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr* ea, enum mtl_port port, int timeout_ms) { +int mt_arp_get_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], + struct rte_ether_addr *ea, enum mtl_port port, + int timeout_ms) { int ret; - dbg("%s(%d), start to get mac for ip %d.%d.%d.%d\n", __func__, port, dip[0], dip[1], - dip[2], dip[3]); + dbg("%s(%d), start to get mac for ip %d.%d.%d.%d\n", __func__, port, dip[0], + dip[1], dip[2], dip[3]); if (mt_drv_use_kernel_ctl(impl, port) || mt_has_virtio_user(impl, port)) { - ret = mt_socket_get_mac(impl, mt_kernel_if_name(impl, port), dip, ea, timeout_ms); + ret = mt_socket_get_mac(impl, mt_kernel_if_name(impl, port), dip, ea, + timeout_ms); if (ret < 0) { dbg("%s(%d), failed to get mac from socket %d\n", __func__, port, ret); return ret; diff --git a/lib/src/mt_arp.h b/lib/src/mt_arp.h index e96577fb0..e51c592d6 100644 --- a/lib/src/mt_arp.h +++ b/lib/src/mt_arp.h @@ -7,12 +7,14 @@ #include "mt_main.h" -int mt_arp_parse(struct mtl_main_impl* impl, struct rte_arp_hdr* hdr, enum mtl_port port); +int mt_arp_parse(struct mtl_main_impl *impl, struct rte_arp_hdr *hdr, + enum mtl_port port); -int mt_arp_init(struct mtl_main_impl* impl); -int mt_arp_uinit(struct mtl_main_impl* impl); +int mt_arp_init(struct mtl_main_impl *impl); +int mt_arp_uinit(struct mtl_main_impl *impl); -int mt_arp_get_mac(struct mtl_main_impl* impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr* ea, enum mtl_port port, int timeout_ms); +int mt_arp_get_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], + struct rte_ether_addr *ea, enum mtl_port port, + int timeout_ms); #endif diff --git a/lib/src/mt_cni.c b/lib/src/mt_cni.c index f2841ff98..039721700 100644 --- a/lib/src/mt_cni.c +++ b/lib/src/mt_cni.c @@ -20,26 +20,26 @@ #define MT_CSQ_RING_PREFIX "CSQ_" -static inline struct mt_cni_entry* cni_get_entry(struct mtl_main_impl* impl, +static inline struct mt_cni_entry *cni_get_entry(struct mtl_main_impl *impl, enum mtl_port port) { return &mt_get_cni(impl)->entries[port]; } /* return true if try lock succ */ -static inline bool csq_try_lock(struct mt_cni_entry* cni) { +static inline bool csq_try_lock(struct mt_cni_entry *cni) { int ret = rte_spinlock_trylock(&cni->csq_lock); return ret ? true : false; } -static inline void csq_lock(struct mt_cni_entry* cni) { +static inline void csq_lock(struct mt_cni_entry *cni) { rte_spinlock_lock(&cni->csq_lock); } -static inline void csq_unlock(struct mt_cni_entry* cni) { +static inline void csq_unlock(struct mt_cni_entry *cni) { rte_spinlock_unlock(&cni->csq_lock); } -static int csq_entry_free(struct mt_csq_entry* entry) { +static int csq_entry_free(struct mt_csq_entry *entry) { if (entry->ring) { mt_ring_dequeue_clean(entry->ring); rte_ring_free(entry->ring); @@ -49,29 +49,31 @@ static int csq_entry_free(struct mt_csq_entry* entry) { return 0; } -static void cni_udp_detect_dump(struct mt_cni_entry* cni, - struct mt_cni_udp_detect_entry* entry) { - uint8_t* sip = (uint8_t*)&entry->tuple[0]; - uint8_t* dip = (uint8_t*)&entry->tuple[1]; +static void cni_udp_detect_dump(struct mt_cni_entry *cni, + struct mt_cni_udp_detect_entry *entry) { + uint8_t *sip = (uint8_t *)&entry->tuple[0]; + uint8_t *dip = (uint8_t *)&entry->tuple[1]; uint32_t udp_port = entry->tuple[2]; uint16_t src_port = ntohs((uint16_t)udp_port); uint16_t dst_port = ntohs((uint16_t)(udp_port >> 16)); - info("%s(%d), sip: %d.%d.%d.%d, dip: %d.%d.%d.%d, src_port %u dst_port %d, pkt %d\n", - __func__, cni->port, sip[0], sip[1], sip[2], sip[3], dip[0], dip[1], dip[2], - dip[3], src_port, dst_port, entry->pkt_cnt); + info("%s(%d), sip: %d.%d.%d.%d, dip: %d.%d.%d.%d, src_port %u dst_port %d, " + "pkt %d\n", + __func__, cni->port, sip[0], sip[1], sip[2], sip[3], dip[0], dip[1], + dip[2], dip[3], src_port, dst_port, entry->pkt_cnt); } -static int cni_udp_detect_analyses(struct mt_cni_entry* cni, struct mt_udp_hdr* hdr) { +static int cni_udp_detect_analyses(struct mt_cni_entry *cni, + struct mt_udp_hdr *hdr) { enum mtl_port port = cni->port; uint32_t tuple[3]; - struct mt_cni_udp_detect_entry* entry; - struct mt_cni_udp_detect_list* list = &cni->udp_detect; - uint8_t* dip = (uint8_t*)&hdr->ipv4.dst_addr; + struct mt_cni_udp_detect_entry *entry; + struct mt_cni_udp_detect_list *list = &cni->udp_detect; + uint8_t *dip = (uint8_t *)&hdr->ipv4.dst_addr; if (!mt_is_multicast_ip(dip) && memcmp(mt_sip_addr(cni->impl, port), dip, MTL_IP_ADDR_LEN)) { - dbg("%s(%d), not our ip %u.%u.%u.%u\n", __func__, port, dip[0], dip[1], dip[2], - dip[3]); + dbg("%s(%d), not our ip %u.%u.%u.%u\n", __func__, port, dip[0], dip[1], + dip[2], dip[3]); return -EINVAL; } @@ -99,9 +101,9 @@ static int cni_udp_detect_analyses(struct mt_cni_entry* cni, struct mt_udp_hdr* return 0; } -static int csq_stat(struct mt_cni_entry* cni) { +static int csq_stat(struct mt_cni_entry *cni) { enum mtl_port port = cni->port; - struct mt_csq_entry* csq = NULL; + struct mt_csq_entry *csq = NULL; int idx; if (!csq_try_lock(cni)) { @@ -125,11 +127,12 @@ static int csq_stat(struct mt_cni_entry* cni) { return 0; } -static int cni_burst_to_kernel(struct mt_cni_entry* cni, struct rte_mbuf* m) { - struct mtl_main_impl* impl = cni->impl; +static int cni_burst_to_kernel(struct mt_cni_entry *cni, struct rte_mbuf *m) { + struct mtl_main_impl *impl = cni->impl; enum mtl_port port = cni->port; - struct mt_interface* inf = mt_if(impl, port); - if (!inf->virtio_port_active) return 0; + struct mt_interface *inf = mt_if(impl, port); + if (!inf->virtio_port_active) + return 0; cni->virtio_rx_cnt++; int ret = rte_eth_tx_burst(inf->virtio_port_id, 0, &m, 1); @@ -142,15 +145,17 @@ static int cni_burst_to_kernel(struct mt_cni_entry* cni, struct rte_mbuf* m) { return 0; } -static int cni_burst_from_kernel(struct mt_cni_entry* cni) { - struct mtl_main_impl* impl = cni->impl; +static int cni_burst_from_kernel(struct mt_cni_entry *cni) { + struct mtl_main_impl *impl = cni->impl; enum mtl_port port = cni->port; - struct mt_interface* inf = mt_if(impl, port); - if (!inf->virtio_port_active) return 0; + struct mt_interface *inf = mt_if(impl, port); + if (!inf->virtio_port_active) + return 0; - struct rte_mbuf* pkts[ST_CNI_RX_BURST_SIZE]; + struct rte_mbuf *pkts[ST_CNI_RX_BURST_SIZE]; - uint16_t revd = rte_eth_rx_burst(inf->virtio_port_id, 0, pkts, ST_CNI_RX_BURST_SIZE); + uint16_t revd = + rte_eth_rx_burst(inf->virtio_port_id, 0, pkts, ST_CNI_RX_BURST_SIZE); if (revd > 0) { cni->virtio_tx_cnt += revd; uint16_t sent = mt_sys_queue_tx_burst(impl, port, pkts, revd); @@ -163,12 +168,12 @@ static int cni_burst_from_kernel(struct mt_cni_entry* cni) { return 0; } -static int cni_udp_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) { - struct mt_udp_hdr* hdr; - struct mt_csq_entry* csq = NULL; +static int cni_udp_handle(struct mt_cni_entry *cni, struct rte_mbuf *m) { + struct mt_udp_hdr *hdr; + struct mt_csq_entry *csq = NULL; int ret; - hdr = rte_pktmbuf_mtod(m, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(m, struct mt_udp_hdr *); csq_lock(cni); MT_TAILQ_FOREACH(csq, &cni->csq_queues, next) { @@ -195,20 +200,20 @@ static int cni_udp_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) { return 0; } -static int cni_rx_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) { - struct mtl_main_impl* impl = cni->impl; +static int cni_rx_handle(struct mt_cni_entry *cni, struct rte_mbuf *m) { + struct mtl_main_impl *impl = cni->impl; enum mtl_port port = cni->port; - struct mt_ptp_impl* ptp = mt_get_ptp(impl, port); - struct mt_dhcp_impl* dhcp = mt_get_dhcp(impl, port); - struct rte_ether_hdr* eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr*); + struct mt_ptp_impl *ptp = mt_get_ptp(impl, port); + struct mt_dhcp_impl *dhcp = mt_get_dhcp(impl, port); + struct rte_ether_hdr *eth_hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); uint16_t ether_type, src_port; - struct rte_vlan_hdr* vlan_header; + struct rte_vlan_hdr *vlan_header; bool vlan = false; - struct mt_ptp_header* ptp_hdr; - struct rte_arp_hdr* arp_hdr; - struct mt_dhcp_hdr* dhcp_hdr; - struct rte_ipv4_hdr* ipv4_hdr; - struct rte_udp_hdr* udp_hdr; + struct mt_ptp_header *ptp_hdr; + struct rte_arp_hdr *arp_hdr; + struct mt_dhcp_hdr *dhcp_hdr; + struct rte_ipv4_hdr *ipv4_hdr; + struct rte_udp_hdr *udp_hdr; size_t hdr_offset = sizeof(struct rte_ether_hdr); // mt_mbuf_dump_hdr(port, 0, "cni_rx", m); @@ -216,7 +221,7 @@ static int cni_rx_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) { /* vlan check */ ether_type = ntohs(eth_hdr->ether_type); if (ether_type == RTE_ETHER_TYPE_VLAN) { - vlan_header = (struct rte_vlan_hdr*)((void*)ð_hdr->ether_type + 2); + vlan_header = (struct rte_vlan_hdr *)((void *)ð_hdr->ether_type + 2); ether_type = ntohs(vlan_header->eth_proto); vlan = true; hdr_offset += sizeof(struct rte_vlan_hdr); @@ -225,64 +230,66 @@ static int cni_rx_handle(struct mt_cni_entry* cni, struct rte_mbuf* m) { dbg("%s(%d), ether_type 0x%x\n", __func__, port, ether_type); switch (ether_type) { - case RTE_ETHER_TYPE_1588: - ptp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header*, hdr_offset); - mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L2, m->timesync, NULL); - break; - case RTE_ETHER_TYPE_ARP: - if (mt_has_virtio_user(impl, port)) { - /* use kernel implementation */ - cni_burst_to_kernel(cni, m); - } else { - /* use internal implementation */ - arp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_arp_hdr*, hdr_offset); - mt_arp_parse(impl, arp_hdr, port); - } - break; - case RTE_ETHER_TYPE_IPV4: - ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr*, hdr_offset); - hdr_offset += ipv4_hdr->ihl * 4; /* may have ip option field */ - if (ipv4_hdr->next_proto_id == IPPROTO_UDP) { - udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr*, hdr_offset); - hdr_offset += sizeof(struct rte_udp_hdr); - src_port = ntohs(udp_hdr->src_port); - if (ptp && (src_port == MT_PTP_UDP_EVENT_PORT || - src_port == MT_PTP_UDP_GEN_PORT)) { /* ptp pkt*/ - dbg("%s(%d), ptp msg src_port %u\n", __func__, port, src_port); - ptp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header*, hdr_offset); - mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L4, m->timesync, - (struct mt_ipv4_udp*)ipv4_hdr); - } else if (dhcp && src_port == MT_DHCP_UDP_SERVER_PORT) { /* dhcp pkt */ - dhcp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_dhcp_hdr*, hdr_offset); - mt_dhcp_parse(impl, dhcp_hdr, port); - } else { - cni_udp_handle(cni, m); - } - } else if (ipv4_hdr->next_proto_id == IPPROTO_IGMP) { - struct mcast_mb_query_v3* mb_query = - rte_pktmbuf_mtod_offset(m, struct mcast_mb_query_v3*, hdr_offset); - mt_mcast_parse(impl, mb_query, port); + case RTE_ETHER_TYPE_1588: + ptp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, hdr_offset); + mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L2, m->timesync, NULL); + break; + case RTE_ETHER_TYPE_ARP: + if (mt_has_virtio_user(impl, port)) { + /* use kernel implementation */ + cni_burst_to_kernel(cni, m); + } else { + /* use internal implementation */ + arp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_arp_hdr *, hdr_offset); + mt_arp_parse(impl, arp_hdr, port); + } + break; + case RTE_ETHER_TYPE_IPV4: + ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, hdr_offset); + hdr_offset += ipv4_hdr->ihl * 4; /* may have ip option field */ + if (ipv4_hdr->next_proto_id == IPPROTO_UDP) { + udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *, hdr_offset); + hdr_offset += sizeof(struct rte_udp_hdr); + src_port = ntohs(udp_hdr->src_port); + if (ptp && (src_port == MT_PTP_UDP_EVENT_PORT || + src_port == MT_PTP_UDP_GEN_PORT)) { /* ptp pkt*/ + dbg("%s(%d), ptp msg src_port %u\n", __func__, port, src_port); + ptp_hdr = + rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, hdr_offset); + mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L4, m->timesync, + (struct mt_ipv4_udp *)ipv4_hdr); + } else if (dhcp && src_port == MT_DHCP_UDP_SERVER_PORT) { /* dhcp pkt */ + dhcp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_dhcp_hdr *, hdr_offset); + mt_dhcp_parse(impl, dhcp_hdr, port); } else { - /* ipv4 packets other than UDP/IGMP fallback to kernel */ - cni_burst_to_kernel(cni, m); + cni_udp_handle(cni, m); } - break; - default: - // dbg("%s(%d), unknown ether_type %d\n", __func__, port, ether_type); - /* unknown eth packets fallback to kernel */ + } else if (ipv4_hdr->next_proto_id == IPPROTO_IGMP) { + struct mcast_mb_query_v3 *mb_query = + rte_pktmbuf_mtod_offset(m, struct mcast_mb_query_v3 *, hdr_offset); + mt_mcast_parse(impl, mb_query, port); + } else { + /* ipv4 packets other than UDP/IGMP fallback to kernel */ cni_burst_to_kernel(cni, m); - break; + } + break; + default: + // dbg("%s(%d), unknown ether_type %d\n", __func__, port, ether_type); + /* unknown eth packets fallback to kernel */ + cni_burst_to_kernel(cni, m); + break; } cni->eth_rx_bytes += m->pkt_len; return 0; } -static int cni_stop_pcap(struct mt_cni_entry* cni) { +static int cni_stop_pcap(struct mt_cni_entry *cni) { enum mtl_port port = cni->port; - struct mt_rx_pcap* pcap = &cni->pcap; + struct mt_rx_pcap *pcap = &cni->pcap; - if (!pcap->pcap) return 0; + if (!pcap->pcap) + return 0; info("%s(%d), dumped %u packets to %s, dropped %u packets\n", __func__, port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); @@ -293,25 +300,27 @@ static int cni_stop_pcap(struct mt_cni_entry* cni) { return 0; } -static int cni_start_pcap(struct mt_cni_entry* cni, uint32_t max_dump_packets) { +static int cni_start_pcap(struct mt_cni_entry *cni, uint32_t max_dump_packets) { enum mtl_port port = cni->port; - struct mt_rx_pcap* pcap = &cni->pcap; + struct mt_rx_pcap *pcap = &cni->pcap; if (pcap->pcap) { err("%s(%d), pcap dump already started\n", __func__, port); return -EIO; } - snprintf(pcap->file_name, sizeof(pcap->file_name), "cni_p%d_%u_XXXXXX.pcapng", port, - max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), "cni_p%d_%u_XXXXXX.pcapng", + port, max_dump_packets); int fd = mt_mkstemps(pcap->file_name, strlen(".pcapng")); if (fd < 0) { - err("%s(%d), failed to create pcap file %s\n", __func__, port, pcap->file_name); + err("%s(%d), failed to create pcap file %s\n", __func__, port, + pcap->file_name); return -EIO; } pcap->pcap = mt_pcap_open(cni->impl, port, fd); if (!pcap->pcap) { - err("%s(%d), failed to open pcap file %s\n", __func__, port, pcap->file_name); + err("%s(%d), failed to open pcap file %s\n", __func__, port, + pcap->file_name); close(fd); return -EIO; } @@ -324,27 +333,29 @@ static int cni_start_pcap(struct mt_cni_entry* cni, uint32_t max_dump_packets) { return 0; } -static int cni_dump_pcap(struct mt_cni_entry* cni, struct rte_mbuf** mbufs, uint16_t nb) { +static int cni_dump_pcap(struct mt_cni_entry *cni, struct rte_mbuf **mbufs, + uint16_t nb) { enum mtl_port port = cni->port; - struct mt_rx_pcap* pcap = &cni->pcap; + struct mt_rx_pcap *pcap = &cni->pcap; uint16_t dump = mt_pcap_dump(cni->impl, port, pcap->pcap, mbufs, nb); pcap->dumped_pkts += dump; pcap->dropped_pkts += nb - dump; return 0; } -static int cni_traffic(struct mtl_main_impl* impl) { - struct mt_cni_entry* cni; +static int cni_traffic(struct mtl_main_impl *impl) { + struct mt_cni_entry *cni; int num_ports = mt_num_ports(impl); - struct rte_mbuf* pkts_rx[ST_CNI_RX_BURST_SIZE]; + struct rte_mbuf *pkts_rx[ST_CNI_RX_BURST_SIZE]; uint16_t rx; bool done = true; for (int i = 0; i < num_ports; i++) { cni = cni_get_entry(impl, i); - if (!cni->rxq) continue; + if (!cni->rxq) + continue; - struct mt_rx_pcap* pcap = &cni->pcap; + struct mt_rx_pcap *pcap = &cni->pcap; /* if any pcap progress */ if (MT_USDT_CNI_PCAP_DUMP_ENABLED()) { if (!pcap->usdt_dump) { @@ -375,7 +386,8 @@ static int cni_traffic(struct mtl_main_impl* impl) { } } - for (uint16_t ri = 0; ri < rx; ri++) cni_rx_handle(cni, pkts_rx[ri]); + for (uint16_t ri = 0; ri < rx; ri++) + cni_rx_handle(cni, pkts_rx[ri]); mt_free_mbufs(&pkts_rx[0], rx); done = false; } @@ -386,22 +398,24 @@ static int cni_traffic(struct mtl_main_impl* impl) { return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static void* cni_traffic_thread(void* arg) { - struct mtl_main_impl* impl = arg; - struct mt_cni_impl* cni = mt_get_cni(impl); +static void *cni_traffic_thread(void *arg) { + struct mtl_main_impl *impl = arg; + struct mt_cni_impl *cni = mt_get_cni(impl); int ret; info("%s, start\n", __func__); while (rte_atomic32_read(&cni->stop_thread) == 0) { ret = cni_traffic(impl); - if (MTL_TASKLET_ALL_DONE == ret) mt_sleep_ms(cni->thread_sleep_ms); + if (MTL_TASKLET_ALL_DONE == ret) + mt_sleep_ms(cni->thread_sleep_ms); } info("%s, stop\n", __func__); return NULL; } -static int cni_traffic_thread_start(struct mtl_main_impl* impl, struct mt_cni_impl* cni) { +static int cni_traffic_thread_start(struct mtl_main_impl *impl, + struct mt_cni_impl *cni) { int ret; if (cni->tid) { @@ -419,7 +433,7 @@ static int cni_traffic_thread_start(struct mtl_main_impl* impl, struct mt_cni_im return 0; } -static int cni_traffic_thread_stop(struct mt_cni_impl* cni) { +static int cni_traffic_thread_stop(struct mt_cni_impl *cni) { rte_atomic32_set(&cni->stop_thread, 1); if (cni->tid) { pthread_join(cni->tid, NULL); @@ -429,34 +443,36 @@ static int cni_traffic_thread_stop(struct mt_cni_impl* cni) { return 0; } -static int cni_tasklet_start(void* priv) { - struct mtl_main_impl* impl = priv; - struct mt_cni_impl* cni = mt_get_cni(impl); +static int cni_tasklet_start(void *priv) { + struct mtl_main_impl *impl = priv; + struct mt_cni_impl *cni = mt_get_cni(impl); /* tasklet will take over the cni thread */ - if (cni->lcore_tasklet) cni_traffic_thread_stop(cni); + if (cni->lcore_tasklet) + cni_traffic_thread_stop(cni); return 0; } -static int cni_tasklet_stop(void* priv) { - struct mtl_main_impl* impl = priv; - struct mt_cni_impl* cni = mt_get_cni(impl); +static int cni_tasklet_stop(void *priv) { + struct mtl_main_impl *impl = priv; + struct mt_cni_impl *cni = mt_get_cni(impl); - if (cni->lcore_tasklet) cni_traffic_thread_start(impl, cni); + if (cni->lcore_tasklet) + cni_traffic_thread_start(impl, cni); return 0; } -static int cni_tasklet_handler(void* priv) { - struct mtl_main_impl* impl = priv; +static int cni_tasklet_handler(void *priv) { + struct mtl_main_impl *impl = priv; return cni_traffic(impl); } -static int cni_queues_uinit(struct mtl_main_impl* impl) { +static int cni_queues_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_cni_entry* cni; + struct mt_cni_entry *cni; for (int i = 0; i < num_ports; i++) { cni = cni_get_entry(impl, i); @@ -470,10 +486,10 @@ static int cni_queues_uinit(struct mtl_main_impl* impl) { return 0; } -static int cni_queues_init(struct mtl_main_impl* impl) { +static int cni_queues_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_cni_entry* cni; - struct mt_interface* inf; + struct mt_cni_entry *cni; + struct mt_interface *inf; if (mt_user_no_system_rxq(impl)) { warn("%s, disabled as no system rx queues\n", __func__); @@ -485,7 +501,8 @@ static int cni_queues_init(struct mtl_main_impl* impl) { inf = mt_if(impl, i); /* continue if no cni */ - if (inf->drv_info.flags & MT_DRV_F_NO_CNI) continue; + if (inf->drv_info.flags & MT_DRV_F_NO_CNI) + continue; struct mt_rxq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -502,31 +519,34 @@ static int cni_queues_init(struct mtl_main_impl* impl) { return 0; } -static bool cni_need_tasklet(struct mt_cni_impl* cni_impl) { - struct mtl_main_impl* impl = cni_impl->parent; - if (!impl) return false; - struct mt_cni_entry* cni; +static bool cni_need_tasklet(struct mt_cni_impl *cni_impl) { + struct mtl_main_impl *impl = cni_impl->parent; + if (!impl) + return false; + struct mt_cni_entry *cni; int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { cni = &cni_impl->entries[i]; - if (cni->rxq) return true; + if (cni->rxq) + return true; } /* no cni in all ports */ return false; } -static int cni_stat(void* priv) { - struct mt_cni_impl* cni_impl = priv; - struct mtl_main_impl* impl = cni_impl->parent; - struct mt_cni_entry* cni; +static int cni_stat(void *priv) { + struct mt_cni_impl *cni_impl = priv; + struct mtl_main_impl *impl = cni_impl->parent; + struct mt_cni_entry *cni; int num_ports = mt_num_ports(impl); double dump_period_s = mt_stat_dump_period_s(impl); for (int i = 0; i < num_ports; i++) { cni = &cni_impl->entries[i]; - if (!cni->rxq) continue; /* no cni */ + if (!cni->rxq) + continue; /* no cni */ notice("CNI(%d): eth_rx_rate %f Mb/s, eth_rx_cnt %u\n", i, (double)cni->eth_rx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT, @@ -535,8 +555,9 @@ static int cni_stat(void* priv) { cni->eth_rx_bytes = 0; if (cni->virtio_rx_cnt || cni->virtio_tx_cnt) { - notice("CNI(%d): virtio pkts(all:fail) rx %u:%u, tx %u:%u\n", i, cni->virtio_rx_cnt, - cni->virtio_rx_fail_cnt, cni->virtio_tx_cnt, cni->virtio_tx_fail_cnt); + notice("CNI(%d): virtio pkts(all:fail) rx %u:%u, tx %u:%u\n", i, + cni->virtio_rx_cnt, cni->virtio_rx_fail_cnt, cni->virtio_tx_cnt, + cni->virtio_tx_fail_cnt); cni->virtio_rx_cnt = 0; cni->virtio_rx_fail_cnt = 0; cni->virtio_tx_cnt = 0; @@ -545,7 +566,7 @@ static int cni_stat(void* priv) { csq_stat(cni); - struct mt_rx_pcap* pcap = &cni->pcap; + struct mt_rx_pcap *pcap = &cni->pcap; if (pcap->pcap) { MT_USDT_CNI_PCAP_DUMP(i, pcap->file_name, pcap->dumped_pkts); } @@ -554,10 +575,10 @@ static int cni_stat(void* priv) { return 0; } -int mt_cni_init(struct mtl_main_impl* impl) { +int mt_cni_init(struct mtl_main_impl *impl) { int ret; - struct mt_cni_impl* cni_impl = mt_get_cni(impl); - struct mtl_init_params* p = mt_get_user_params(impl); + struct mt_cni_impl *cni_impl = mt_get_cni(impl); + struct mtl_init_params *p = mt_get_user_params(impl); int num_ports = mt_num_ports(impl); cni_impl->parent = impl; @@ -581,7 +602,7 @@ int mt_cni_init(struct mtl_main_impl* impl) { cni_impl->thread_sleep_ms = 1; for (int i = 0; i < num_ports; i++) { - struct mt_cni_entry* cni = cni_get_entry(impl, i); + struct mt_cni_entry *cni = cni_get_entry(impl, i); cni->port = i; cni->impl = impl; MT_TAILQ_INIT(&cni->csq_queues); @@ -601,7 +622,8 @@ int mt_cni_init(struct mtl_main_impl* impl) { } ret = mt_tap_init(impl); - if (ret < 0) return ret; + if (ret < 0) + return ret; if (cni_impl->lcore_tasklet) { struct mtl_tasklet_ops ops; @@ -632,14 +654,14 @@ int mt_cni_init(struct mtl_main_impl* impl) { return 0; } -int mt_cni_uinit(struct mtl_main_impl* impl) { - struct mt_cni_impl* cni_impl = mt_get_cni(impl); +int mt_cni_uinit(struct mtl_main_impl *impl) { + struct mt_cni_impl *cni_impl = mt_get_cni(impl); int num_ports = mt_num_ports(impl); - struct mt_cni_udp_detect_entry* udp_detect; - struct mt_csq_entry* csq; + struct mt_cni_udp_detect_entry *udp_detect; + struct mt_csq_entry *csq; for (int i = 0; i < num_ports; i++) { - struct mt_cni_entry* cni = cni_get_entry(impl, i); + struct mt_cni_entry *cni = cni_get_entry(impl, i); cni_stop_pcap(cni); @@ -679,29 +701,31 @@ int mt_cni_uinit(struct mtl_main_impl* impl) { return 0; } -int mt_cni_start(struct mtl_main_impl* impl) { - struct mt_cni_impl* cni = mt_get_cni(impl); +int mt_cni_start(struct mtl_main_impl *impl) { + struct mt_cni_impl *cni = mt_get_cni(impl); int ret; - if (!cni_need_tasklet(cni)) return 0; + if (!cni_need_tasklet(cni)) + return 0; ret = cni_traffic_thread_start(impl, cni); - if (ret < 0) return ret; + if (ret < 0) + return ret; return 0; } -int mt_cni_stop(struct mtl_main_impl* impl) { - struct mt_cni_impl* cni = mt_get_cni(impl); +int mt_cni_stop(struct mtl_main_impl *impl) { + struct mt_cni_impl *cni = mt_get_cni(impl); cni_traffic_thread_stop(cni); return 0; } -struct mt_csq_entry* mt_csq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow) { - struct mt_cni_entry* cni = cni_get_entry(impl, port); +struct mt_csq_entry *mt_csq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow) { + struct mt_cni_entry *cni = cni_get_entry(impl, port); int idx = cni->csq_idx; if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) { @@ -709,7 +733,7 @@ struct mt_csq_entry* mt_csq_get(struct mtl_main_impl* impl, enum mtl_port port, return NULL; } - struct mt_csq_entry* entry = + struct mt_csq_entry *entry = mt_rte_zmalloc_socket(sizeof(*entry), mt_socket_id(impl, port)); if (!entry) { err("%s(%d,%d), entry malloc fail\n", __func__, port, idx); @@ -738,14 +762,14 @@ struct mt_csq_entry* mt_csq_get(struct mtl_main_impl* impl, enum mtl_port port, /* csq enabled, disable the sleep */ mt_get_cni(impl)->thread_sleep_ms = 0; - uint8_t* ip = flow->dip_addr; - info("%s(%d), ip %u.%u.%u.%u port %u on %d\n", __func__, port, ip[0], ip[1], ip[2], - ip[3], flow->dst_port, idx); + uint8_t *ip = flow->dip_addr; + info("%s(%d), ip %u.%u.%u.%u port %u on %d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3], flow->dst_port, idx); return entry; } -int mt_csq_put(struct mt_csq_entry* entry) { - struct mt_cni_entry* cni = entry->parent; +int mt_csq_put(struct mt_csq_entry *entry) { + struct mt_cni_entry *cni = entry->parent; csq_lock(cni); MT_TAILQ_REMOVE(&cni->csq_queues, entry, next); @@ -755,9 +779,10 @@ int mt_csq_put(struct mt_csq_entry* entry) { return 0; } -uint16_t mt_csq_burst(struct mt_csq_entry* entry, struct rte_mbuf** rx_pkts, +uint16_t mt_csq_burst(struct mt_csq_entry *entry, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) { - uint16_t n = rte_ring_sc_dequeue_burst(entry->ring, (void**)rx_pkts, nb_pkts, NULL); + uint16_t n = + rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); entry->stat_dequeue_cnt += n; return n; } diff --git a/lib/src/mt_cni.h b/lib/src/mt_cni.h index c0773af64..4a58d50f6 100644 --- a/lib/src/mt_cni.h +++ b/lib/src/mt_cni.h @@ -9,22 +9,22 @@ #define ST_CNI_RX_BURST_SIZE (32) -int mt_cni_init(struct mtl_main_impl* impl); -int mt_cni_uinit(struct mtl_main_impl* impl); -int mt_cni_start(struct mtl_main_impl* impl); -int mt_cni_stop(struct mtl_main_impl* impl); +int mt_cni_init(struct mtl_main_impl *impl); +int mt_cni_uinit(struct mtl_main_impl *impl); +int mt_cni_start(struct mtl_main_impl *impl); +int mt_cni_stop(struct mtl_main_impl *impl); -static inline struct mt_cni_impl* mt_get_cni(struct mtl_main_impl* impl) { +static inline struct mt_cni_impl *mt_get_cni(struct mtl_main_impl *impl) { return &impl->cni; } -struct mt_csq_entry* mt_csq_get(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow); -static inline uint16_t mt_csq_queue_id(struct mt_csq_entry* entry) { +struct mt_csq_entry *mt_csq_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow); +static inline uint16_t mt_csq_queue_id(struct mt_csq_entry *entry) { return entry->idx; } -uint16_t mt_csq_burst(struct mt_csq_entry* entry, struct rte_mbuf** rx_pkts, +uint16_t mt_csq_burst(struct mt_csq_entry *entry, struct rte_mbuf **rx_pkts, uint16_t nb_pkts); -int mt_csq_put(struct mt_csq_entry* entry); +int mt_csq_put(struct mt_csq_entry *entry); #endif diff --git a/lib/src/mt_config.c b/lib/src/mt_config.c index 52f4a8967..b6cb9d10e 100644 --- a/lib/src/mt_config.c +++ b/lib/src/mt_config.c @@ -6,7 +6,8 @@ #include "mt_log.h" -static int config_parse_plugins(struct mtl_main_impl* impl, json_object* plugins_array) { +static int config_parse_plugins(struct mtl_main_impl *impl, + json_object *plugins_array) { if (json_object_get_type(plugins_array) != json_type_array) { err("%s, type not array\n", __func__); return -EIO; @@ -15,42 +16,49 @@ static int config_parse_plugins(struct mtl_main_impl* impl, json_object* plugins int num_plugins = json_object_array_length(plugins_array); dbg("%s, num_plugins %d\n", __func__, num_plugins); for (int i = 0; i < num_plugins; i++) { - json_object* plugin_obj = json_object_array_get_idx(plugins_array, i); - if (!plugin_obj) continue; - json_object* obj; + json_object *plugin_obj = json_object_array_get_idx(plugins_array, i); + if (!plugin_obj) + continue; + json_object *obj; obj = mt_json_object_get(plugin_obj, "enabled"); - if (obj && !json_object_get_boolean(obj)) continue; - const char* name = NULL; + if (obj && !json_object_get_boolean(obj)) + continue; + const char *name = NULL; obj = mt_json_object_get(plugin_obj, "name"); - if (obj) name = json_object_get_string(obj); - const char* path = NULL; + if (obj) + name = json_object_get_string(obj); + const char *path = NULL; obj = mt_json_object_get(plugin_obj, "path"); - if (obj) path = json_object_get_string(obj); - if (!name || !path) continue; + if (obj) + path = json_object_get_string(obj); + if (!name || !path) + continue; st_plugin_register(impl, path); } return 0; } -static int config_parse_json(struct mtl_main_impl* impl, const char* filename) { - json_object* root_object = json_object_from_file(filename); +static int config_parse_json(struct mtl_main_impl *impl, const char *filename) { + json_object *root_object = json_object_from_file(filename); if (root_object == NULL) { warn("%s, open json file %s fail\n", __func__, filename); return -EIO; } - info("%s, parse %s with json-c version: %s\n", __func__, filename, json_c_version()); + info("%s, parse %s with json-c version: %s\n", __func__, filename, + json_c_version()); /* parse plugins for system */ - json_object* plugins_array = mt_json_object_get(root_object, "plugins"); - if (plugins_array) config_parse_plugins(impl, plugins_array); + json_object *plugins_array = mt_json_object_get(root_object, "plugins"); + if (plugins_array) + config_parse_plugins(impl, plugins_array); json_object_put(root_object); return 0; } -int mt_config_init(struct mtl_main_impl* impl) { - const char* cfg_path = getenv("KAHAWAI_CFG_PATH"); +int mt_config_init(struct mtl_main_impl *impl) { + const char *cfg_path = getenv("KAHAWAI_CFG_PATH"); if (cfg_path) { info("%s, KAHAWAI_CFG_PATH: %s\n", __func__, cfg_path); @@ -62,7 +70,7 @@ int mt_config_init(struct mtl_main_impl* impl) { return 0; } -int mt_config_uinit(struct mtl_main_impl* impl) { +int mt_config_uinit(struct mtl_main_impl *impl) { MTL_MAY_UNUSED(impl); return 0; } diff --git a/lib/src/mt_config.h b/lib/src/mt_config.h index 17f8b7088..88e812151 100644 --- a/lib/src/mt_config.h +++ b/lib/src/mt_config.h @@ -7,7 +7,7 @@ #include "mt_main.h" -int mt_config_init(struct mtl_main_impl* impl); -int mt_config_uinit(struct mtl_main_impl* impl); +int mt_config_init(struct mtl_main_impl *impl); +int mt_config_uinit(struct mtl_main_impl *impl); #endif diff --git a/lib/src/mt_dhcp.c b/lib/src/mt_dhcp.c index f8ed0221c..832c74a2b 100644 --- a/lib/src/mt_dhcp.c +++ b/lib/src/mt_dhcp.c @@ -31,21 +31,21 @@ #define DHCP_MESSAGE_TYPE_NAK (6) #define DHCP_MESSAGE_TYPE_RELEASE (7) -static inline void dhcp_set_status(struct mt_dhcp_impl* dhcp, +static inline void dhcp_set_status(struct mt_dhcp_impl *dhcp, enum mt_dhcp_status status) { mt_pthread_mutex_lock(&dhcp->mutex); dhcp->status = status; mt_pthread_mutex_unlock(&dhcp->mutex); } -static int dhcp_send_discover(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); - struct rte_mbuf* pkt; - struct mt_dhcp_hdr* dhcp; - struct rte_ether_hdr* eth; - struct rte_ipv4_hdr* ip; - struct rte_udp_hdr* udp; - uint8_t* options; +static int dhcp_send_discover(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); + struct rte_mbuf *pkt; + struct mt_dhcp_hdr *dhcp; + struct rte_ether_hdr *eth; + struct rte_ipv4_hdr *ip; + struct rte_udp_hdr *udp; + uint8_t *options; size_t hdr_offset = 0; pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); @@ -54,13 +54,13 @@ static int dhcp_send_discover(struct mtl_main_impl* impl, enum mtl_port port) { return -ENOMEM; } - eth = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr*); + eth = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); memset(mt_eth_d_addr(eth), 0xFF, RTE_ETHER_ADDR_LEN); /* send to broadcast */ eth->ether_type = htons(RTE_ETHER_TYPE_IPV4); hdr_offset += sizeof(*eth); - ip = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr*, hdr_offset); + ip = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, hdr_offset); ip->version_ihl = (4 << 4) | (sizeof(struct rte_ipv4_hdr) / 4); ip->time_to_live = 128; ip->type_of_service = 0; @@ -71,19 +71,20 @@ static int dhcp_send_discover(struct mtl_main_impl* impl, enum mtl_port port) { ip->dst_addr = 0xFFFFFFFF; /* send to broadcast */ hdr_offset += sizeof(*ip); - udp = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr*, hdr_offset); + udp = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr *, hdr_offset); udp->src_port = htons(MT_DHCP_UDP_CLIENT_PORT); udp->dst_port = htons(MT_DHCP_UDP_SERVER_PORT); hdr_offset += sizeof(*udp); - dhcp = rte_pktmbuf_mtod_offset(pkt, struct mt_dhcp_hdr*, hdr_offset); + dhcp = rte_pktmbuf_mtod_offset(pkt, struct mt_dhcp_hdr *, hdr_offset); memset(dhcp, 0, sizeof(*dhcp)); dhcp->op = DHCP_OP_BOOTREQUEST; dhcp->htype = DHCP_HTYPE_ETHERNET; dhcp->hlen = DHCP_HLEN_ETHERNET; dhcp->xid = htonl(dhcp_impl->xid); dhcp->magic_cookie = htonl(DHCP_MAGIC_COOKIE); - rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, sizeof(eth->src_addr.addr_bytes)); + rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, + sizeof(eth->src_addr.addr_bytes)); options = dhcp->options; *options++ = DHCP_OPTION_MESSAGE_TYPE; *options++ = 1; @@ -118,14 +119,14 @@ static int dhcp_send_discover(struct mtl_main_impl* impl, enum mtl_port port) { return 0; } -static int dhcp_send_request(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); - struct rte_mbuf* pkt; - struct mt_dhcp_hdr* dhcp; - struct rte_ether_hdr* eth; - struct rte_ipv4_hdr* ip; - struct rte_udp_hdr* udp; - uint8_t* options; +static int dhcp_send_request(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); + struct rte_mbuf *pkt; + struct mt_dhcp_hdr *dhcp; + struct rte_ether_hdr *eth; + struct rte_ipv4_hdr *ip; + struct rte_udp_hdr *udp; + uint8_t *options; size_t hdr_offset = 0; pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); @@ -134,13 +135,13 @@ static int dhcp_send_request(struct mtl_main_impl* impl, enum mtl_port port) { return -ENOMEM; } - eth = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr*); + eth = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); memset(mt_eth_d_addr(eth), 0xFF, RTE_ETHER_ADDR_LEN); eth->ether_type = htons(RTE_ETHER_TYPE_IPV4); hdr_offset += sizeof(*eth); - ip = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr*, hdr_offset); + ip = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, hdr_offset); ip->version_ihl = (4 << 4) | (sizeof(struct rte_ipv4_hdr) / 4); ip->time_to_live = 128; ip->type_of_service = 0; @@ -150,18 +151,18 @@ static int dhcp_send_request(struct mtl_main_impl* impl, enum mtl_port port) { ip->src_addr = 0; mt_pthread_mutex_lock(&dhcp_impl->mutex); if (dhcp_impl->status == MT_DHCP_STATUS_RENEWING) - ip->dst_addr = htonl(*(uint32_t*)dhcp_impl->server_ip); + ip->dst_addr = htonl(*(uint32_t *)dhcp_impl->server_ip); else ip->dst_addr = 0xFFFFFFFF; mt_pthread_mutex_unlock(&dhcp_impl->mutex); hdr_offset += sizeof(*ip); - udp = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr*, hdr_offset); + udp = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr *, hdr_offset); udp->src_port = htons(MT_DHCP_UDP_CLIENT_PORT); udp->dst_port = htons(MT_DHCP_UDP_SERVER_PORT); hdr_offset += sizeof(*udp); - dhcp = rte_pktmbuf_mtod_offset(pkt, struct mt_dhcp_hdr*, hdr_offset); + dhcp = rte_pktmbuf_mtod_offset(pkt, struct mt_dhcp_hdr *, hdr_offset); memset(dhcp, 0, sizeof(*dhcp)); dhcp->op = DHCP_OP_BOOTREQUEST; dhcp->htype = DHCP_HTYPE_ETHERNET; @@ -170,8 +171,9 @@ static int dhcp_send_request(struct mtl_main_impl* impl, enum mtl_port port) { dhcp->magic_cookie = htonl(DHCP_MAGIC_COOKIE); if (dhcp_impl->status == MT_DHCP_STATUS_RENEWING || dhcp_impl->status == MT_DHCP_STATUS_REBINDING) - dhcp->ciaddr = htonl(*(uint32_t*)dhcp_impl->ip); - rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, sizeof(eth->src_addr.addr_bytes)); + dhcp->ciaddr = htonl(*(uint32_t *)dhcp_impl->ip); + rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, + sizeof(eth->src_addr.addr_bytes)); options = dhcp->options; *options++ = DHCP_OPTION_MESSAGE_TYPE; *options++ = 1; @@ -223,9 +225,9 @@ static int dhcp_send_request(struct mtl_main_impl* impl, enum mtl_port port) { return 0; } -static int dhcp_recv_offer(struct mtl_main_impl* impl, struct mt_dhcp_hdr* offer, - enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); +static int dhcp_recv_offer(struct mtl_main_impl *impl, + struct mt_dhcp_hdr *offer, enum mtl_port port) { + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); mt_pthread_mutex_lock(&dhcp_impl->mutex); if (dhcp_impl->status != MT_DHCP_STATUS_DISCOVERING) { dbg("%s(%d), not in discovering status\n", __func__, port); @@ -236,19 +238,19 @@ static int dhcp_recv_offer(struct mtl_main_impl* impl, struct mt_dhcp_hdr* offer mt_pthread_mutex_unlock(&dhcp_impl->mutex); info("%s(%d), received dhcp offer\n", __func__, port); info("%s(%d), ip address: %s\n", __func__, dhcp_impl->port, - inet_ntoa(*(struct in_addr*)dhcp_impl->ip)); - uint8_t* options = offer->options; + inet_ntoa(*(struct in_addr *)dhcp_impl->ip)); + uint8_t *options = offer->options; while (*options != DHCP_OPTION_END) { if (*options == DHCP_OPTION_SUBNET_MASK) dbg("%s(%d), subnet mask: %s\n", __func__, port, - inet_ntoa(*(struct in_addr*)(options + 2))); + inet_ntoa(*(struct in_addr *)(options + 2))); if (*options == DHCP_OPTION_ROUTER) dbg("%s(%d), default gateway: %s\n", __func__, port, - inet_ntoa(*(struct in_addr*)(options + 2))); + inet_ntoa(*(struct in_addr *)(options + 2))); if (*options == DHCP_OPTION_DNS_SERVER) { for (int i = 0; i < options[1] / 4; ++i) dbg("%s(%d), dns server %d: %s\n", __func__, port, i, - inet_ntoa(*(struct in_addr*)(options + 2 + i * 4))); + inet_ntoa(*(struct in_addr *)(options + 2 + i * 4))); } if (*options == DHCP_OPTION_SERVER_IDENTIFIER) rte_memcpy(dhcp_impl->server_ip, &options[2], MTL_IP_ADDR_LEN); @@ -262,15 +264,15 @@ static int dhcp_recv_offer(struct mtl_main_impl* impl, struct mt_dhcp_hdr* offer } /* renew at t1 after ack */ -static void dhcp_renew_handler(void* param) { - struct mt_dhcp_impl* dhcp_impl = param; +static void dhcp_renew_handler(void *param) { + struct mt_dhcp_impl *dhcp_impl = param; dhcp_set_status(dhcp_impl, MT_DHCP_STATUS_RENEWING); dhcp_send_request(dhcp_impl->parent, dhcp_impl->port); } /* rebind at t2 after ack if not renewed */ -static void dhcp_rebind_handler(void* param) { - struct mt_dhcp_impl* dhcp_impl = param; +static void dhcp_rebind_handler(void *param) { + struct mt_dhcp_impl *dhcp_impl = param; mt_pthread_mutex_lock(&dhcp_impl->mutex); if (dhcp_impl->status != MT_DHCP_STATUS_BOUND) { dhcp_impl->status = MT_DHCP_STATUS_REBINDING; @@ -281,8 +283,8 @@ static void dhcp_rebind_handler(void* param) { } /* exceeds lease time */ -static void dhcp_lease_handler(void* param) { - struct mt_dhcp_impl* dhcp_impl = param; +static void dhcp_lease_handler(void *param) { + struct mt_dhcp_impl *dhcp_impl = param; mt_pthread_mutex_lock(&dhcp_impl->mutex); if (dhcp_impl->status != MT_DHCP_STATUS_BOUND) { dhcp_impl->status = MT_DHCP_STATUS_INIT; @@ -292,12 +294,12 @@ static void dhcp_lease_handler(void* param) { mt_pthread_mutex_unlock(&dhcp_impl->mutex); } -static int dhcp_recv_ack(struct mtl_main_impl* impl, struct mt_dhcp_hdr* ack, +static int dhcp_recv_ack(struct mtl_main_impl *impl, struct mt_dhcp_hdr *ack, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); int ret; double t = 0.0, t1 = 0.0, t2 = 0.0; - uint8_t* options = ack->options; + uint8_t *options = ack->options; mt_pthread_mutex_lock(&dhcp_impl->mutex); rte_memcpy(dhcp_impl->ip, &ack->yiaddr, MTL_IP_ADDR_LEN); while (*options != DHCP_OPTION_END) { @@ -306,7 +308,7 @@ static int dhcp_recv_ack(struct mtl_main_impl* impl, struct mt_dhcp_hdr* ack, if (*options == DHCP_OPTION_ROUTER) rte_memcpy(dhcp_impl->gateway, &options[2], MTL_IP_ADDR_LEN); if (*options == DHCP_OPTION_LEASE_TIME) { - t = ntohl(*(uint32_t*)(options + 2)); + t = ntohl(*(uint32_t *)(options + 2)); t1 = t * 0.5; t2 = t * 0.875; } @@ -318,21 +320,22 @@ static int dhcp_recv_ack(struct mtl_main_impl* impl, struct mt_dhcp_hdr* ack, ret = rte_eal_alarm_set(t1 * US_PER_S, dhcp_renew_handler, dhcp_impl); if (ret < 0) { - err("%s(%d), start renew timer fail %d, t1 %lf\n", __func__, dhcp_impl->port, ret, - t1); + err("%s(%d), start renew timer fail %d, t1 %lf\n", __func__, + dhcp_impl->port, ret, t1); return ret; } ret = rte_eal_alarm_set(t2 * US_PER_S, dhcp_rebind_handler, dhcp_impl); if (ret < 0) { - err("%s(%d), start rebind timer fail %d, t2 %lf\n", __func__, dhcp_impl->port, ret, - t2); + err("%s(%d), start rebind timer fail %d, t2 %lf\n", __func__, + dhcp_impl->port, ret, t2); return ret; } ret = rte_eal_alarm_set(t * US_PER_S, dhcp_lease_handler, dhcp_impl); if (ret < 0) { - err("%s(%d), start lease timer fail %d, t %lf\n", __func__, dhcp_impl->port, ret, t); + err("%s(%d), start lease timer fail %d, t %lf\n", __func__, dhcp_impl->port, + ret, t); return ret; } @@ -340,24 +343,24 @@ static int dhcp_recv_ack(struct mtl_main_impl* impl, struct mt_dhcp_hdr* ack, info("%s(%d), dhcp configuration done\n", __func__, dhcp_impl->port); info("%s(%d), ip address: %s\n", __func__, dhcp_impl->port, - inet_ntoa(*(struct in_addr*)dhcp_impl->ip)); + inet_ntoa(*(struct in_addr *)dhcp_impl->ip)); info("%s(%d), subnet mask: %s\n", __func__, dhcp_impl->port, - inet_ntoa(*(struct in_addr*)dhcp_impl->netmask)); + inet_ntoa(*(struct in_addr *)dhcp_impl->netmask)); info("%s(%d), default gateway: %s\n", __func__, dhcp_impl->port, - inet_ntoa(*(struct in_addr*)dhcp_impl->gateway)); + inet_ntoa(*(struct in_addr *)dhcp_impl->gateway)); info("%s(%d), lease time: %u s\n", __func__, dhcp_impl->port, (uint32_t)t); return 0; } -static int dhcp_send_release(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); - struct rte_mbuf* pkt; - struct mt_dhcp_hdr* dhcp; - struct rte_ether_hdr* eth; - struct rte_ipv4_hdr* ip; - struct rte_udp_hdr* udp; - uint8_t* options; +static int dhcp_send_release(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); + struct rte_mbuf *pkt; + struct mt_dhcp_hdr *dhcp; + struct rte_ether_hdr *eth; + struct rte_ipv4_hdr *ip; + struct rte_udp_hdr *udp; + uint8_t *options; size_t hdr_offset = 0; pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); @@ -366,13 +369,13 @@ static int dhcp_send_release(struct mtl_main_impl* impl, enum mtl_port port) { return -ENOMEM; } - eth = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr*); + eth = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); memset(mt_eth_d_addr(eth), 0xFF, RTE_ETHER_ADDR_LEN); eth->ether_type = htons(RTE_ETHER_TYPE_IPV4); hdr_offset += sizeof(*eth); - ip = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr*, hdr_offset); + ip = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, hdr_offset); ip->version_ihl = (4 << 4) | (sizeof(struct rte_ipv4_hdr) / 4); ip->time_to_live = 128; ip->type_of_service = 0; @@ -380,23 +383,24 @@ static int dhcp_send_release(struct mtl_main_impl* impl, enum mtl_port port) { ip->hdr_checksum = 0; ip->next_proto_id = IPPROTO_UDP; ip->src_addr = 0; - ip->dst_addr = htonl(*(uint32_t*)dhcp_impl->server_ip); + ip->dst_addr = htonl(*(uint32_t *)dhcp_impl->server_ip); hdr_offset += sizeof(*ip); - udp = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr*, hdr_offset); + udp = rte_pktmbuf_mtod_offset(pkt, struct rte_udp_hdr *, hdr_offset); udp->src_port = htons(MT_DHCP_UDP_CLIENT_PORT); udp->dst_port = htons(MT_DHCP_UDP_SERVER_PORT); hdr_offset += sizeof(*udp); - dhcp = rte_pktmbuf_mtod_offset(pkt, struct mt_dhcp_hdr*, hdr_offset); + dhcp = rte_pktmbuf_mtod_offset(pkt, struct mt_dhcp_hdr *, hdr_offset); memset(dhcp, 0, sizeof(*dhcp)); dhcp->op = DHCP_OP_BOOTREQUEST; dhcp->htype = DHCP_HTYPE_ETHERNET; dhcp->hlen = DHCP_HLEN_ETHERNET; dhcp->xid = rand(); dhcp->magic_cookie = htonl(DHCP_MAGIC_COOKIE); - dhcp->ciaddr = htonl(*(uint32_t*)dhcp_impl->ip); - rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, sizeof(eth->src_addr.addr_bytes)); + dhcp->ciaddr = htonl(*(uint32_t *)dhcp_impl->ip); + rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, + sizeof(eth->src_addr.addr_bytes)); options = dhcp->options; *options++ = DHCP_OPTION_MESSAGE_TYPE; *options++ = 1; @@ -436,9 +440,9 @@ static int dhcp_send_release(struct mtl_main_impl* impl, enum mtl_port port) { return 0; } -int mt_dhcp_parse(struct mtl_main_impl* impl, struct mt_dhcp_hdr* hdr, +int mt_dhcp_parse(struct mtl_main_impl *impl, struct mt_dhcp_hdr *hdr, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); if (rte_be_to_cpu_32(hdr->magic_cookie) != DHCP_MAGIC_COOKIE) { err("%s(%d), invalid magic cookie 0x%" PRIx32 "\n", __func__, port, rte_be_to_cpu_32(hdr->magic_cookie)); @@ -456,33 +460,33 @@ int mt_dhcp_parse(struct mtl_main_impl* impl, struct mt_dhcp_hdr* hdr, return -EINVAL; } - uint8_t* options = hdr->options; + uint8_t *options = hdr->options; if (*options != DHCP_OPTION_MESSAGE_TYPE) { err("%s(%d), invalid option field %u\n", __func__, port, *options); return -EINVAL; } switch (options[2]) { - case DHCP_MESSAGE_TYPE_OFFER: - dhcp_recv_offer(impl, hdr, port); - break; - case DHCP_MESSAGE_TYPE_ACK: - dhcp_recv_ack(impl, hdr, port); - break; - case DHCP_MESSAGE_TYPE_NAK: - /* restart the cycle */ - dhcp_send_discover(impl, port); - break; - default: - err("%s(%d), invalid dhcp message type %u\n", __func__, port, options[2]); - return -EINVAL; + case DHCP_MESSAGE_TYPE_OFFER: + dhcp_recv_offer(impl, hdr, port); + break; + case DHCP_MESSAGE_TYPE_ACK: + dhcp_recv_ack(impl, hdr, port); + break; + case DHCP_MESSAGE_TYPE_NAK: + /* restart the cycle */ + dhcp_send_discover(impl, port); + break; + default: + err("%s(%d), invalid dhcp message type %u\n", __func__, port, options[2]); + return -EINVAL; } return 0; } -uint8_t* mt_dhcp_get_ip(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); +uint8_t *mt_dhcp_get_ip(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); if (dhcp_impl->status != MT_DHCP_STATUS_BOUND && dhcp_impl->status != MT_DHCP_STATUS_RENEWING && @@ -493,8 +497,8 @@ uint8_t* mt_dhcp_get_ip(struct mtl_main_impl* impl, enum mtl_port port) { return dhcp_impl->ip; } -uint8_t* mt_dhcp_get_netmask(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); +uint8_t *mt_dhcp_get_netmask(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); if (dhcp_impl->status != MT_DHCP_STATUS_BOUND && dhcp_impl->status != MT_DHCP_STATUS_RENEWING && @@ -505,8 +509,8 @@ uint8_t* mt_dhcp_get_netmask(struct mtl_main_impl* impl, enum mtl_port port) { return dhcp_impl->netmask; } -uint8_t* mt_dhcp_get_gateway(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_dhcp_impl* dhcp_impl = mt_get_dhcp(impl, port); +uint8_t *mt_dhcp_get_gateway(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); if (dhcp_impl->status != MT_DHCP_STATUS_BOUND && dhcp_impl->status != MT_DHCP_STATUS_RENEWING && @@ -517,14 +521,15 @@ uint8_t* mt_dhcp_get_gateway(struct mtl_main_impl* impl, enum mtl_port port) { return dhcp_impl->gateway; } -int mt_dhcp_init(struct mtl_main_impl* impl) { +int mt_dhcp_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); int socket = mt_socket_id(impl, MTL_PORT_P); int num_dhcp = 0; for (int i = 0; i < num_ports; i++) { - if (mt_if(impl, i)->net_proto != MTL_PROTO_DHCP) continue; - struct mt_dhcp_impl* dhcp = mt_rte_zmalloc_socket(sizeof(*dhcp), socket); + if (mt_if(impl, i)->net_proto != MTL_PROTO_DHCP) + continue; + struct mt_dhcp_impl *dhcp = mt_rte_zmalloc_socket(sizeof(*dhcp), socket); if (!dhcp) { err("%s(%d), dhcp malloc fail\n", __func__, i); mt_dhcp_uinit(impl); @@ -551,8 +556,10 @@ int mt_dhcp_init(struct mtl_main_impl* impl) { while (--max_retry) { done = 0; for (int i = 0; i < num_ports; i++) - if (impl->dhcp[i] && impl->dhcp[i]->status == MT_DHCP_STATUS_BOUND) done++; - if (done == num_dhcp) break; + if (impl->dhcp[i] && impl->dhcp[i]->status == MT_DHCP_STATUS_BOUND) + done++; + if (done == num_dhcp) + break; mt_sleep_ms(100); } if (done != num_dhcp) { @@ -568,12 +575,13 @@ int mt_dhcp_init(struct mtl_main_impl* impl) { return 0; } -int mt_dhcp_uinit(struct mtl_main_impl* impl) { +int mt_dhcp_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { - struct mt_dhcp_impl* dhcp = mt_get_dhcp(impl, i); - if (!dhcp) continue; + struct mt_dhcp_impl *dhcp = mt_get_dhcp(impl, i); + if (!dhcp) + continue; /* send release to server */ dhcp_send_release(impl, i); diff --git a/lib/src/mt_dhcp.h b/lib/src/mt_dhcp.h index 22b5834e5..d5f84eb1d 100644 --- a/lib/src/mt_dhcp.h +++ b/lib/src/mt_dhcp.h @@ -32,22 +32,22 @@ struct mt_dhcp_hdr { uint8_t options[0]; } __attribute__((packed)); -static inline struct mt_dhcp_impl* mt_get_dhcp(struct mtl_main_impl* impl, +static inline struct mt_dhcp_impl *mt_get_dhcp(struct mtl_main_impl *impl, enum mtl_port port) { return impl->dhcp[port]; } -int mt_dhcp_init(struct mtl_main_impl* impl); +int mt_dhcp_init(struct mtl_main_impl *impl); -int mt_dhcp_uinit(struct mtl_main_impl* impl); +int mt_dhcp_uinit(struct mtl_main_impl *impl); -int mt_dhcp_parse(struct mtl_main_impl* impl, struct mt_dhcp_hdr* hdr, +int mt_dhcp_parse(struct mtl_main_impl *impl, struct mt_dhcp_hdr *hdr, enum mtl_port port); -uint8_t* mt_dhcp_get_ip(struct mtl_main_impl* impl, enum mtl_port port); +uint8_t *mt_dhcp_get_ip(struct mtl_main_impl *impl, enum mtl_port port); -uint8_t* mt_dhcp_get_netmask(struct mtl_main_impl* impl, enum mtl_port port); +uint8_t *mt_dhcp_get_netmask(struct mtl_main_impl *impl, enum mtl_port port); -uint8_t* mt_dhcp_get_gateway(struct mtl_main_impl* impl, enum mtl_port port); +uint8_t *mt_dhcp_get_gateway(struct mtl_main_impl *impl, enum mtl_port port); #endif \ No newline at end of file diff --git a/lib/src/mt_dma.c b/lib/src/mt_dma.c index dd0b2d4be..5810a7333 100644 --- a/lib/src/mt_dma.c +++ b/lib/src/mt_dma.c @@ -7,17 +7,17 @@ #include "mt_log.h" #include "mt_stat.h" -static inline struct mt_map_mgr* mt_get_map_mgr(struct mtl_main_impl* impl) { +static inline struct mt_map_mgr *mt_get_map_mgr(struct mtl_main_impl *impl) { return &impl->map_mgr; } -int mt_map_add(struct mtl_main_impl* impl, struct mt_map_item* item) { - struct mt_map_mgr* mgr = mt_get_map_mgr(impl); - void* start = item->vaddr; - void* end = start + item->size; - struct mt_map_item* i_item; - void* i_start; - void* i_end; +int mt_map_add(struct mtl_main_impl *impl, struct mt_map_item *item) { + struct mt_map_mgr *mgr = mt_get_map_mgr(impl); + void *start = item->vaddr; + void *end = start + item->size; + struct mt_map_item *i_item; + void *i_start; + void *i_end; mtl_iova_t iova_base = 0x10000; /* assume user IOVA start from 1M */ mtl_iova_t iova_end; @@ -26,30 +26,36 @@ int mt_map_add(struct mtl_main_impl* impl, struct mt_map_item* item) { /* first check if any conflict with exist mapping */ for (int i = 0; i < MT_MAP_MAX_ITEMS; i++) { i_item = mgr->items[i]; - if (!i_item) continue; + if (!i_item) + continue; i_start = i_item->vaddr; i_end = i_start + i_item->size; if ((start >= i_start) && (start < i_end)) { - err("%s, invalid start %p i_start %p i_end %p\n", __func__, start, i_start, i_end); + err("%s, invalid start %p i_start %p i_end %p\n", __func__, start, + i_start, i_end); mt_pthread_mutex_unlock(&mgr->mutex); return -EINVAL; } if ((end > i_start) && (end <= i_end)) { - err("%s, invalid end %p i_start %p i_end %p\n", __func__, end, i_start, i_end); + err("%s, invalid end %p i_start %p i_end %p\n", __func__, end, i_start, + i_end); mt_pthread_mutex_unlock(&mgr->mutex); return -EINVAL; } /* simply set iova_base to max iova in previous item */ iova_end = i_item->iova + i_item->size; - if (iova_end > iova_base) iova_base = iova_end; + if (iova_end > iova_base) + iova_base = iova_end; } item->iova = iova_base; /* find empty slot and insert */ for (int i = 0; i < MT_MAP_MAX_ITEMS; i++) { i_item = mgr->items[i]; - if (i_item) continue; - i_item = mt_rte_zmalloc_socket(sizeof(*i_item), mt_socket_id(impl, MTL_PORT_P)); + if (i_item) + continue; + i_item = + mt_rte_zmalloc_socket(sizeof(*i_item), mt_socket_id(impl, MTL_PORT_P)); if (!i_item) { err("%s, i_item malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->mutex); @@ -58,8 +64,8 @@ int mt_map_add(struct mtl_main_impl* impl, struct mt_map_item* item) { *i_item = *item; mgr->items[i] = i_item; mt_pthread_mutex_unlock(&mgr->mutex); - info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, end, - i_item->iova); + info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, + end, i_item->iova); return 0; } @@ -68,25 +74,26 @@ int mt_map_add(struct mtl_main_impl* impl, struct mt_map_item* item) { return -EIO; } -int mt_map_remove(struct mtl_main_impl* impl, struct mt_map_item* item) { - struct mt_map_mgr* mgr = mt_get_map_mgr(impl); - void* start = item->vaddr; - void* end = start + item->size; - struct mt_map_item* i_item; - void* i_start; - void* i_end; +int mt_map_remove(struct mtl_main_impl *impl, struct mt_map_item *item) { + struct mt_map_mgr *mgr = mt_get_map_mgr(impl); + void *start = item->vaddr; + void *end = start + item->size; + struct mt_map_item *i_item; + void *i_start; + void *i_end; mt_pthread_mutex_lock(&mgr->mutex); /* find slot and delete */ for (int i = 0; i < MT_MAP_MAX_ITEMS; i++) { i_item = mgr->items[i]; - if (!i_item) continue; + if (!i_item) + continue; i_start = i_item->vaddr; i_end = i_start + i_item->size; if ((start == i_start) && (end == i_end) && (item->iova == i_item->iova)) { - info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, end, - i_item->iova); + info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, + end, i_item->iova); mt_rte_free(i_item); mgr->items[i] = NULL; mt_pthread_mutex_unlock(&mgr->mutex); @@ -94,23 +101,23 @@ int mt_map_remove(struct mtl_main_impl* impl, struct mt_map_item* item) { } } - err("%s, unknown items start %p end %p iova %" PRIx64 "\n", __func__, start, end, - item->iova); + err("%s, unknown items start %p end %p iova %" PRIx64 "\n", __func__, start, + end, item->iova); mt_pthread_mutex_unlock(&mgr->mutex); return -EIO; } -int mt_map_init(struct mtl_main_impl* impl) { - struct mt_map_mgr* mgr = mt_get_map_mgr(impl); +int mt_map_init(struct mtl_main_impl *impl) { + struct mt_map_mgr *mgr = mt_get_map_mgr(impl); mt_pthread_mutex_init(&mgr->mutex, NULL); return 0; } -int mt_map_uinit(struct mtl_main_impl* impl) { - struct mt_map_mgr* mgr = mt_get_map_mgr(impl); - struct mt_map_item* item; +int mt_map_uinit(struct mtl_main_impl *impl) { + struct mt_map_mgr *mgr = mt_get_map_mgr(impl); + struct mt_map_item *item; for (int i = 0; i < MT_MAP_MAX_ITEMS; i++) { item = mgr->items[i]; @@ -130,8 +137,9 @@ int mt_map_uinit(struct mtl_main_impl* impl) { #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0) #include -static int dma_copy_test(struct mtl_main_impl* impl, struct mtl_dma_lender_dev* dev, - uint32_t off, uint32_t len) { +static int dma_copy_test(struct mtl_main_impl *impl, + struct mtl_dma_lender_dev *dev, uint32_t off, + uint32_t len) { void *dst = NULL, *src = NULL; int idx = mt_dma_dev_id(dev); int ret = -EIO; @@ -179,19 +187,21 @@ static int dma_copy_test(struct mtl_main_impl* impl, struct mtl_dma_lender_dev* } exit: - if (dst) mt_rte_free(dst); - if (src) mt_rte_free(src); + if (dst) + mt_rte_free(dst); + if (src) + mt_rte_free(src); return ret; } -static int dma_drop_mbuf(struct mt_dma_dev* dma_dev, uint16_t nb_mbuf) { - struct rte_mbuf* mbuf = NULL; - struct mtl_dma_lender_dev* mbuf_dev; +static int dma_drop_mbuf(struct mt_dma_dev *dma_dev, uint16_t nb_mbuf) { + struct rte_mbuf *mbuf = NULL; + struct mtl_dma_lender_dev *mbuf_dev; for (uint16_t i = 0; i < nb_mbuf; i++) { #if MT_DMA_RTE_RING - int ret = rte_ring_sc_dequeue(dma_dev->borrow_queue, (void**)&mbuf); + int ret = rte_ring_sc_dequeue(dma_dev->borrow_queue, (void **)&mbuf); if (ret < 0) { err("%s(%d), no item to dequeue\n", __func__, dma_dev->idx); break; @@ -214,7 +224,7 @@ static int dma_drop_mbuf(struct mt_dma_dev* dma_dev, uint16_t nb_mbuf) { return 0; } -static int dma_hw_start(struct mtl_main_impl* impl, struct mt_dma_dev* dev, +static int dma_hw_start(struct mtl_main_impl *impl, struct mt_dma_dev *dev, uint16_t nb_desc) { struct rte_dma_info info; struct rte_dma_conf dev_config = {.nb_vchans = 1}; @@ -257,18 +267,19 @@ static int dma_hw_start(struct mtl_main_impl* impl, struct mt_dma_dev* dev, return dma_copy_test(impl, &dev->lenders[0], 0, 32); } -static int dma_hw_stop(struct mt_dma_dev* dev) { +static int dma_hw_stop(struct mt_dma_dev *dev) { int16_t dev_id = dev->dev_id; int ret, idx = dev->idx; ret = rte_dma_stop(dev_id); - if (ret < 0) err("%s(%d), rte_dma_stop fail %d\n", __func__, idx, ret); + if (ret < 0) + err("%s(%d), rte_dma_stop fail %d\n", __func__, idx, ret); return 0; } -static int dma_stat(void* priv) { - struct mt_dma_dev* dev = priv; +static int dma_stat(void *priv) { + struct mt_dma_dev *dev = priv; int16_t dev_id = dev->dev_id; int idx = dev->idx; struct rte_dma_stats stats; @@ -280,24 +291,26 @@ static int dma_stat(void* priv) { avg_nb_inflight = dev->stat_inflight_sum / dev->stat_commit_sum; dev->stat_inflight_sum = 0; dev->stat_commit_sum = 0; - notice("DMA(%d), s %" PRIu64 " c %" PRIu64 " e %" PRIu64 " avg q %" PRIu64 "\n", idx, - stats.submitted, stats.completed, stats.errors, avg_nb_inflight); + notice("DMA(%d), s %" PRIu64 " c %" PRIu64 " e %" PRIu64 " avg q %" PRIu64 + "\n", + idx, stats.submitted, stats.completed, stats.errors, avg_nb_inflight); return 0; } -static int dma_sw_init(struct mtl_main_impl* impl, struct mt_dma_dev* dev) { +static int dma_sw_init(struct mtl_main_impl *impl, struct mt_dma_dev *dev) { int idx = dev->idx; #if MT_DMA_RTE_RING char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count; snprintf(ring_name, 32, "%sD%d", MT_DMA_BORROW_RING_PREFIX, idx); flags = RING_F_SP_ENQ | RING_F_SC_DEQ; count = dev->nb_desc; - ring = rte_ring_create(ring_name, count, mt_socket_id(impl, MTL_PORT_P), flags); + ring = + rte_ring_create(ring_name, count, mt_socket_id(impl, MTL_PORT_P), flags); if (!ring) { err("%s(%d), rte_ring_create fail\n", __func__, idx); return -ENOMEM; @@ -306,8 +319,9 @@ static int dma_sw_init(struct mtl_main_impl* impl, struct mt_dma_dev* dev) { #else dev->inflight_enqueue_idx = 0; dev->inflight_dequeue_idx = 0; - dev->inflight_mbufs = mt_rte_zmalloc_socket(sizeof(*dev->inflight_mbufs) * dev->nb_desc, - mt_socket_id(impl, MTL_PORT_P)); + dev->inflight_mbufs = + mt_rte_zmalloc_socket(sizeof(*dev->inflight_mbufs) * dev->nb_desc, + mt_socket_id(impl, MTL_PORT_P)); if (!dev->inflight_mbufs) { err("%s(%d), inflight_mbufs alloc fail\n", __func__, idx); return -ENOMEM; @@ -320,7 +334,7 @@ static int dma_sw_init(struct mtl_main_impl* impl, struct mt_dma_dev* dev) { return 0; } -static int dma_sw_uinit(struct mtl_main_impl* impl, struct mt_dma_dev* dev) { +static int dma_sw_uinit(struct mtl_main_impl *impl, struct mt_dma_dev *dev) { uint16_t nb_inflight = 0; mt_stat_unregister(impl, dma_stat, dev); @@ -350,7 +364,7 @@ static int dma_sw_uinit(struct mtl_main_impl* impl, struct mt_dma_dev* dev) { return 0; } -static int dma_free(struct mtl_main_impl* impl, struct mt_dma_dev* dev) { +static int dma_free(struct mtl_main_impl *impl, struct mt_dma_dev *dev) { if (!dev->active) { err("%s(%d), not active\n", __func__, dev->idx); return -EIO; @@ -363,24 +377,27 @@ static int dma_free(struct mtl_main_impl* impl, struct mt_dma_dev* dev) { return 0; } -struct mtl_dma_lender_dev* mt_dma_request_dev(struct mtl_main_impl* impl, - struct mt_dma_request_req* req) { - struct mt_dma_mgr* mgr = mt_get_dma_mgr(impl); - struct mt_dma_dev* dev; - struct mtl_dma_lender_dev* lender_dev; +struct mtl_dma_lender_dev *mt_dma_request_dev(struct mtl_main_impl *impl, + struct mt_dma_request_req *req) { + struct mt_dma_mgr *mgr = mt_get_dma_mgr(impl); + struct mt_dma_dev *dev; + struct mtl_dma_lender_dev *lender_dev; int idx, ret; - if (!mgr->num_dma_dev) return NULL; + if (!mgr->num_dma_dev) + return NULL; uint16_t nb_desc = req->nb_desc; - if (!nb_desc) nb_desc = 128; + if (!nb_desc) + nb_desc = 128; mt_pthread_mutex_lock(&mgr->mutex); /* first try to find a shared dma */ for (idx = 0; idx < MTL_DMA_DEV_MAX; idx++) { dev = &mgr->devs[idx]; if (dev->active && (dev->sch_idx == req->sch_idx) && - (dev->soc_id == req->socket_id) && (dev->nb_session < dev->max_shared)) { + (dev->soc_id == req->socket_id) && + (dev->nb_session < dev->max_shared)) { for (int render = 0; render < dev->max_shared; render++) { lender_dev = &dev->lenders[render]; if (!lender_dev->active) { @@ -435,11 +452,12 @@ struct mtl_dma_lender_dev* mt_dma_request_dev(struct mtl_main_impl* impl, return NULL; } -int mt_dma_free_dev(struct mtl_main_impl* impl, struct mtl_dma_lender_dev* dev) { - struct mt_dma_dev* dma_dev = dev->parent; +int mt_dma_free_dev(struct mtl_main_impl *impl, + struct mtl_dma_lender_dev *dev) { + struct mt_dma_dev *dma_dev = dev->parent; int idx = dev->lender_id; int dma_idx = dma_dev->idx; - struct mt_dma_mgr* mgr = mt_get_dma_mgr(impl); + struct mt_dma_mgr *mgr = mt_get_dma_mgr(impl); if (!dev->active) { err("%s(%d,%d), not active\n", __func__, dma_idx, idx); @@ -455,41 +473,42 @@ int mt_dma_free_dev(struct mtl_main_impl* impl, struct mtl_dma_lender_dev* dev) rte_atomic32_dec(&mgr->num_dma_dev_active); } - info("%s(%d,%d), nb_session now %u\n", __func__, dma_idx, idx, dma_dev->nb_session); + info("%s(%d,%d), nb_session now %u\n", __func__, dma_idx, idx, + dma_dev->nb_session); return 0; } -int mt_dma_copy(struct mtl_dma_lender_dev* dev, rte_iova_t dst, rte_iova_t src, +int mt_dma_copy(struct mtl_dma_lender_dev *dev, rte_iova_t dst, rte_iova_t src, uint32_t length) { - struct mt_dma_dev* dma_dev = dev->parent; + struct mt_dma_dev *dma_dev = dev->parent; return rte_dma_copy(dma_dev->dev_id, 0, src, dst, length, 0); } -int mt_dma_fill(struct mtl_dma_lender_dev* dev, rte_iova_t dst, uint64_t pattern, - uint32_t length) { - struct mt_dma_dev* dma_dev = dev->parent; +int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, + uint64_t pattern, uint32_t length) { + struct mt_dma_dev *dma_dev = dev->parent; return rte_dma_fill(dma_dev->dev_id, 0, pattern, dst, length, 0); } -int mt_dma_submit(struct mtl_dma_lender_dev* dev) { - struct mt_dma_dev* dma_dev = dev->parent; +int mt_dma_submit(struct mtl_dma_lender_dev *dev) { + struct mt_dma_dev *dma_dev = dev->parent; dma_dev->stat_commit_sum++; dma_dev->stat_inflight_sum += dma_dev->nb_inflight; return rte_dma_submit(dma_dev->dev_id, 0); } -uint16_t mt_dma_completed(struct mtl_dma_lender_dev* dev, uint16_t nb_cpls, - uint16_t* last_idx, bool* has_error) { - struct mt_dma_dev* dma_dev = dev->parent; +uint16_t mt_dma_completed(struct mtl_dma_lender_dev *dev, uint16_t nb_cpls, + uint16_t *last_idx, bool *has_error) { + struct mt_dma_dev *dma_dev = dev->parent; return rte_dma_completed(dma_dev->dev_id, 0, nb_cpls, last_idx, has_error); } -int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev* dev, struct rte_mbuf* mbuf) { - struct mt_dma_dev* dma_dev = dev->parent; +int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev *dev, struct rte_mbuf *mbuf) { + struct mt_dma_dev *dma_dev = dev->parent; st_rx_mbuf_set_lender(mbuf, dev->lender_id); #if MT_DMA_RTE_RING - int ret = rte_ring_sp_enqueue(dma_dev->borrow_queue, (void*)mbuf); + int ret = rte_ring_sp_enqueue(dma_dev->borrow_queue, (void *)mbuf); if (ret) { err("%s, no space for queue\n", __func__); return ret; @@ -508,12 +527,12 @@ int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev* dev, struct rte_mbuf* mbuf) { return 0; } -int mt_dma_drop_mbuf(struct mtl_dma_lender_dev* dev, uint16_t nb_mbuf) { +int mt_dma_drop_mbuf(struct mtl_dma_lender_dev *dev, uint16_t nb_mbuf) { return dma_drop_mbuf(dev->parent, nb_mbuf); } -bool mt_dma_full(struct mtl_dma_lender_dev* dev) { - struct mt_dma_dev* dma_dev = dev->parent; +bool mt_dma_full(struct mtl_dma_lender_dev *dev) { + struct mt_dma_dev *dma_dev = dev->parent; #if MT_DMA_RTE_RING return rte_ring_full(dma_dev->borrow_queue) ? true : false; #else @@ -521,13 +540,13 @@ bool mt_dma_full(struct mtl_dma_lender_dev* dev) { #endif } -int mt_dma_init(struct mtl_main_impl* impl) { - struct mt_dma_mgr* mgr = mt_get_dma_mgr(impl); +int mt_dma_init(struct mtl_main_impl *impl) { + struct mt_dma_mgr *mgr = mt_get_dma_mgr(impl); int16_t dev_id; int idx; - struct mt_dma_dev* dev; + struct mt_dma_dev *dev; struct rte_dma_info dev_info; - struct mtl_dma_lender_dev* lender_dev; + struct mtl_dma_lender_dev *lender_dev; mt_pthread_mutex_init(&mgr->mutex, NULL); @@ -540,15 +559,17 @@ int mt_dma_init(struct mtl_main_impl* impl) { idx = 0; RTE_DMA_FOREACH_DEV(dev_id) { rte_dma_info_get(dev_id, &dev_info); - if (!mt_is_valid_socket(impl, dev_info.numa_node)) continue; + if (!mt_is_valid_socket(impl, dev_info.numa_node)) + continue; dev = &mgr->devs[idx]; dev->dev_id = dev_id; dev->soc_id = dev_info.numa_node; dev->usable = true; dev->nb_session = 0; - info("%s(%d), dma dev id %u name %s capa 0x%" PRIx64 " numa %d desc %u:%u\n", - __func__, idx, dev_id, dev_info.dev_name, dev_info.dev_capa, dev_info.numa_node, - dev_info.min_desc, dev_info.max_desc); + info("%s(%d), dma dev id %u name %s capa 0x%" PRIx64 + " numa %d desc %u:%u\n", + __func__, idx, dev_id, dev_info.dev_name, dev_info.dev_capa, + dev_info.numa_node, dev_info.min_desc, dev_info.max_desc); for (int render = 0; render < MT_DMA_MAX_SESSIONS; render++) { lender_dev = &dev->lenders[render]; lender_dev->parent = dev; @@ -562,10 +583,10 @@ int mt_dma_init(struct mtl_main_impl* impl) { return 0; } -int mt_dma_uinit(struct mtl_main_impl* impl) { - struct mt_dma_mgr* mgr = mt_get_dma_mgr(impl); +int mt_dma_uinit(struct mtl_main_impl *impl) { + struct mt_dma_mgr *mgr = mt_get_dma_mgr(impl); int idx; - struct mt_dma_dev* dev; + struct mt_dma_dev *dev; for (idx = 0; idx < MTL_DMA_DEV_MAX; idx++) { dev = &mgr->devs[idx]; @@ -579,51 +600,47 @@ int mt_dma_uinit(struct mtl_main_impl* impl) { } #else -int mt_dma_init(struct mtl_main_impl* impl) { - struct mtl_init_params* p = mt_get_user_params(impl); +int mt_dma_init(struct mtl_main_impl *impl) { + struct mtl_init_params *p = mt_get_user_params(impl); if (p->num_dma_dev_port) { - err("%s, total dma dev %d requested, but the lib build without dma dev support\n", + err("%s, total dma dev %d requested, but the lib build without dma dev " + "support\n", __func__, p->num_dma_dev_port); } return -EINVAL; } -int mt_dma_uinit(struct mtl_main_impl* impl) { - return -EINVAL; -} +int mt_dma_uinit(struct mtl_main_impl *impl) { return -EINVAL; } -struct mtl_dma_lender_dev* mt_dma_request_dev(struct mtl_main_impl* impl, - struct mt_dma_request_req* req) { +struct mtl_dma_lender_dev *mt_dma_request_dev(struct mtl_main_impl *impl, + struct mt_dma_request_req *req) { return NULL; } -int mt_dma_free_dev(struct mtl_main_impl* impl, struct mtl_dma_lender_dev* dev) { +int mt_dma_free_dev(struct mtl_main_impl *impl, + struct mtl_dma_lender_dev *dev) { return -EINVAL; } -int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev* dev, struct rte_mbuf* mbuf) { +int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev *dev, struct rte_mbuf *mbuf) { return -EINVAL; } -int mt_dma_drop_mbuf(struct mtl_dma_lender_dev* dev, uint16_t nb_mbuf) { +int mt_dma_drop_mbuf(struct mtl_dma_lender_dev *dev, uint16_t nb_mbuf) { return -EINVAL; } -int mt_dma_copy(struct mtl_dma_lender_dev* dev, rte_iova_t dst, rte_iova_t src, +int mt_dma_copy(struct mtl_dma_lender_dev *dev, rte_iova_t dst, rte_iova_t src, uint32_t length) { return -EINVAL; } -int mt_dma_fill(struct mtl_dma_lender_dev* dev, rte_iova_t dst, uint64_t pattern, - uint32_t length) { +int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, + uint64_t pattern, uint32_t length) { return -EINVAL; } -int mt_dma_submit(struct mtl_dma_lender_dev* dev) { - return -EINVAL; -} -uint16_t mt_dma_completed(struct mtl_dma_lender_dev* dev, uint16_t nb_cpls, - uint16_t* last_idx, bool* has_error) { +int mt_dma_submit(struct mtl_dma_lender_dev *dev) { return -EINVAL; } +uint16_t mt_dma_completed(struct mtl_dma_lender_dev *dev, uint16_t nb_cpls, + uint16_t *last_idx, bool *has_error) { return 0; } -bool mt_dma_full(struct mtl_dma_lender_dev* dev) { - return true; -} +bool mt_dma_full(struct mtl_dma_lender_dev *dev) { return true; } #endif diff --git a/lib/src/mt_dma.h b/lib/src/mt_dma.h index ed2f2c31e..921f27db1 100644 --- a/lib/src/mt_dma.h +++ b/lib/src/mt_dma.h @@ -9,70 +9,71 @@ #define MT_DMA_BORROW_RING_PREFIX "DB_" -int mt_dma_init(struct mtl_main_impl* impl); -int mt_dma_uinit(struct mtl_main_impl* impl); +int mt_dma_init(struct mtl_main_impl *impl); +int mt_dma_uinit(struct mtl_main_impl *impl); struct mt_dma_request_req { uint16_t nb_desc; uint16_t max_shared; int sch_idx; int socket_id; - void* priv; + void *priv; mt_dma_drop_mbuf_cb drop_mbuf_cb; }; -struct mtl_dma_lender_dev* mt_dma_request_dev(struct mtl_main_impl* impl, - struct mt_dma_request_req* req); -int mt_dma_free_dev(struct mtl_main_impl* impl, struct mtl_dma_lender_dev* dev); +struct mtl_dma_lender_dev *mt_dma_request_dev(struct mtl_main_impl *impl, + struct mt_dma_request_req *req); +int mt_dma_free_dev(struct mtl_main_impl *impl, struct mtl_dma_lender_dev *dev); /* enqueue mbuf for later free, also mark the lender session */ -int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev* dev, struct rte_mbuf* mbuf); +int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev *dev, struct rte_mbuf *mbuf); /* dequeue and free mbufs */ -int mt_dma_drop_mbuf(struct mtl_dma_lender_dev* dev, uint16_t nb_mbuf); +int mt_dma_drop_mbuf(struct mtl_dma_lender_dev *dev, uint16_t nb_mbuf); -bool mt_dma_full(struct mtl_dma_lender_dev* dev); +bool mt_dma_full(struct mtl_dma_lender_dev *dev); -int mt_dma_copy(struct mtl_dma_lender_dev* dev, rte_iova_t dst, rte_iova_t src, +int mt_dma_copy(struct mtl_dma_lender_dev *dev, rte_iova_t dst, rte_iova_t src, uint32_t length); -int mt_dma_fill(struct mtl_dma_lender_dev* dev, rte_iova_t dst, uint64_t pattern, - uint32_t length); -int mt_dma_submit(struct mtl_dma_lender_dev* dev); -uint16_t mt_dma_completed(struct mtl_dma_lender_dev* dev, uint16_t nb_cpls, - uint16_t* last_idx, bool* has_error); - -static inline void mt_dma_copy_busy(struct mtl_dma_lender_dev* dev, rte_iova_t dst, - rte_iova_t src, uint32_t length) { +int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, + uint64_t pattern, uint32_t length); +int mt_dma_submit(struct mtl_dma_lender_dev *dev); +uint16_t mt_dma_completed(struct mtl_dma_lender_dev *dev, uint16_t nb_cpls, + uint16_t *last_idx, bool *has_error); + +static inline void mt_dma_copy_busy(struct mtl_dma_lender_dev *dev, + rte_iova_t dst, rte_iova_t src, + uint32_t length) { int ret; do { ret = mt_dma_copy(dev, dst, src, length); } while (ret < 0); } -static inline void mt_dma_submit_busy(struct mtl_dma_lender_dev* dev) { +static inline void mt_dma_submit_busy(struct mtl_dma_lender_dev *dev) { int ret; do { ret = mt_dma_submit(dev); } while (ret < 0); } -static inline bool mt_dma_empty(struct mtl_dma_lender_dev* dev) { +static inline bool mt_dma_empty(struct mtl_dma_lender_dev *dev) { if (dev->nb_borrowed) return false; else return true; } -static inline int mt_dma_lender_id(struct mtl_dma_lender_dev* dev) { +static inline int mt_dma_lender_id(struct mtl_dma_lender_dev *dev) { return dev->lender_id; } -static inline int mt_dma_dev_id(struct mtl_dma_lender_dev* dev) { +static inline int mt_dma_dev_id(struct mtl_dma_lender_dev *dev) { return dev->parent->idx; } -int mt_map_init(struct mtl_main_impl* impl); -int mt_map_uinit(struct mtl_main_impl* impl); -int mt_map_add(struct mtl_main_impl* impl, struct mt_map_item* item); -int mt_map_remove(struct mtl_main_impl* impl, struct mt_map_item* item); +int mt_map_init(struct mtl_main_impl *impl); +int mt_map_uinit(struct mtl_main_impl *impl); +int mt_map_add(struct mtl_main_impl *impl, struct mt_map_item *item); +int mt_map_remove(struct mtl_main_impl *impl, struct mt_map_item *item); #endif diff --git a/lib/src/mt_flow.c b/lib/src/mt_flow.c index eb4463ded..7017d0370 100644 --- a/lib/src/mt_flow.c +++ b/lib/src/mt_flow.c @@ -8,18 +8,19 @@ #include "mt_socket.h" #include "mt_util.h" -static inline void rx_flow_lock(struct mt_flow_impl* flow) { +static inline void rx_flow_lock(struct mt_flow_impl *flow) { mt_pthread_mutex_lock(&flow->mutex); } -static inline void rx_flow_unlock(struct mt_flow_impl* flow) { +static inline void rx_flow_unlock(struct mt_flow_impl *flow) { mt_pthread_mutex_unlock(&flow->mutex); } -static struct rte_flow* rte_rx_flow_create_raw(struct mt_interface* inf, uint16_t q, - struct mt_rxq_flow* flow) { +static struct rte_flow *rte_rx_flow_create_raw(struct mt_interface *inf, + uint16_t q, + struct mt_rxq_flow *flow) { struct rte_flow_error error; - struct rte_flow* r_flow; + struct rte_flow *r_flow; struct rte_flow_attr attr = {0}; struct rte_flow_item pattern[2]; @@ -29,12 +30,12 @@ static struct rte_flow* rte_rx_flow_create_raw(struct mt_interface* inf, uint16_ struct rte_flow_action_queue to_queue = {0}; uint16_t port_id = inf->port_id; - char pkt_buf[] = - "0000000000010000000000020800450000300000000000110000010101010202020200001B3A001C00" - "008000000000000000000000000000000000000000"; - char msk_buf[] = - "000000000000000000000000000000000000000000000000000000000000000000000000FFFF000000" - "000000000000000000000000000000000000000000"; + char pkt_buf[] = "00000000000100000000000208004500003000000000001100000101010" + "10202020200001B3A001C00" + "008000000000000000000000000000000000000000"; + char msk_buf[] = "00000000000000000000000000000000000000000000000000000000000" + "0000000000000FFFF000000" + "000000000000000000000000000000000000000000"; MTL_MAY_UNUSED(flow); attr.ingress = 1; @@ -43,9 +44,9 @@ static struct rte_flow* rte_rx_flow_create_raw(struct mt_interface* inf, uint16_ memset(pattern, 0, sizeof(pattern)); memset(action, 0, sizeof(action)); - spec.pattern = (const void*)pkt_buf; + spec.pattern = (const void *)pkt_buf; spec.length = 62; - mask.pattern = (const void*)msk_buf; + mask.pattern = (const void *)msk_buf; mask.length = 62; pattern[0].type = RTE_FLOW_ITEM_TYPE_RAW; @@ -71,8 +72,8 @@ static struct rte_flow* rte_rx_flow_create_raw(struct mt_interface* inf, uint16_ return r_flow; } -static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q, - struct mt_rxq_flow* flow) { +static struct rte_flow *rte_rx_flow_create(struct mt_interface *inf, uint16_t q, + struct mt_rxq_flow *flow) { struct rte_flow_attr attr; struct rte_flow_item pattern[4]; struct rte_flow_action action[2]; @@ -84,7 +85,7 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q, struct rte_flow_item_udp udp_spec; struct rte_flow_item_udp udp_mask; struct rte_flow_error error; - struct rte_flow* r_flow; + struct rte_flow *r_flow; int ret; bool has_ip_flow = true; bool has_port_flow = true; @@ -95,15 +96,19 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q, memset(&error, 0, sizeof(error)); /* drv not support ip flow */ - if (inf->drv_info.flow_type == MT_FLOW_NO_IP) has_ip_flow = false; + if (inf->drv_info.flow_type == MT_FLOW_NO_IP) + has_ip_flow = false; /* no ip flow requested */ - if (flow->flags & MT_RXQ_FLOW_F_NO_IP) has_ip_flow = false; + if (flow->flags & MT_RXQ_FLOW_F_NO_IP) + has_ip_flow = false; /* no port flow requested */ - if (flow->flags & MT_RXQ_FLOW_F_NO_PORT) has_port_flow = false; + if (flow->flags & MT_RXQ_FLOW_F_NO_PORT) + has_port_flow = false; if (mt_get_user_params(inf->parent)->flags & MTL_FLAG_RX_UDP_PORT_ONLY) { if (has_ip_flow) { - info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, port); + info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, + port); has_ip_flow = false; } } @@ -170,8 +175,8 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q, ret = rte_flow_validate(port_id, &attr, pattern, action, &error); if (ret < 0) { - err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port, ret, q, - mt_string_safe(error.message)); + err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port, + ret, q, mt_string_safe(error.message)); return NULL; } @@ -185,34 +190,36 @@ static struct rte_flow* rte_rx_flow_create(struct mt_interface* inf, uint16_t q, } if (has_ip_flow) { - uint8_t* ip = flow->dip_addr; - info("%s(%d), queue %u succ, ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], - ip[1], ip[2], ip[3], flow->dst_port); + uint8_t *ip = flow->dip_addr; + info("%s(%d), queue %u succ, ip %u.%u.%u.%u port %u\n", __func__, port, q, + ip[0], ip[1], ip[2], ip[3], flow->dst_port); } else { info("%s(%d), queue %u succ, port %u\n", __func__, port, q, flow->dst_port); } return r_flow; } -static struct mt_rx_flow_rsp* rx_flow_create(struct mt_interface* inf, uint16_t q, - struct mt_rxq_flow* flow) { +static struct mt_rx_flow_rsp * +rx_flow_create(struct mt_interface *inf, uint16_t q, struct mt_rxq_flow *flow) { int ret; enum mtl_port port = inf->port; - struct mtl_main_impl* impl = inf->parent; - uint8_t* ip = flow->dip_addr; + struct mtl_main_impl *impl = inf->parent; + uint8_t *ip = flow->dip_addr; if (!mt_drv_kernel_based(impl, port) && q >= inf->nb_rx_q) { err("%s(%d), invalid q %u\n", __func__, port, q); return NULL; } - struct mt_rx_flow_rsp* rsp = mt_rte_zmalloc_socket(sizeof(*rsp), inf->socket_id); + struct mt_rx_flow_rsp *rsp = + mt_rte_zmalloc_socket(sizeof(*rsp), inf->socket_id); rsp->flow_id = -1; rsp->queue_id = q; rsp->dst_port = flow->dst_port; /* no flow if MT_DRV_F_RX_NO_FLOW */ - if (inf->drv_info.flags & MT_DRV_F_RX_NO_FLOW) return rsp; + if (inf->drv_info.flags & MT_DRV_F_RX_NO_FLOW) + return rsp; if (mt_drv_use_kernel_ctl(impl, port)) { ret = mt_socket_add_flow(impl, port, q, flow); @@ -223,25 +230,26 @@ static struct mt_rx_flow_rsp* rx_flow_create(struct mt_interface* inf, uint16_t } rsp->flow_id = ret; } else { - struct rte_flow* r_flow; + struct rte_flow *r_flow; r_flow = rte_rx_flow_create(inf, q, flow); if (!r_flow) { - err("%s(%d), create flow fail for queue %d, ip %u.%u.%u.%u port %u\n", __func__, - port, q, ip[0], ip[1], ip[2], ip[3], flow->dst_port); + err("%s(%d), create flow fail for queue %d, ip %u.%u.%u.%u port %u\n", + __func__, port, q, ip[0], ip[1], ip[2], ip[3], flow->dst_port); mt_rte_free(rsp); return NULL; } rsp->flow = r_flow; /* WA to avoid iavf_flow_create fail in 1000+ mudp close at same time */ - if (inf->drv_info.drv_type == MT_DRV_IAVF) mt_sleep_ms(5); + if (inf->drv_info.drv_type == MT_DRV_IAVF) + mt_sleep_ms(5); } return rsp; } -static int rx_flow_free(struct mt_interface* inf, struct mt_rx_flow_rsp* rsp) { +static int rx_flow_free(struct mt_interface *inf, struct mt_rx_flow_rsp *rsp) { enum mtl_port port = inf->port; struct rte_flow_error error; int ret; @@ -270,18 +278,21 @@ static int rx_flow_free(struct mt_interface* inf, struct mt_rx_flow_rsp* rsp) { } mt_rte_free(rsp); /* WA to avoid iavf_flow_destroy fail in 1000+ mudp close at same time */ - if (inf->drv_info.drv_type == MT_DRV_IAVF) mt_sleep_ms(1); + if (inf->drv_info.drv_type == MT_DRV_IAVF) + mt_sleep_ms(1); return 0; } -struct mt_rx_flow_rsp* mt_rx_flow_create(struct mtl_main_impl* impl, enum mtl_port port, - uint16_t q, struct mt_rxq_flow* flow) { - struct mt_interface* inf = mt_if(impl, port); - struct mt_rx_flow_rsp* rsp; - struct mt_flow_impl* flow_impl = impl->flow[port]; +struct mt_rx_flow_rsp *mt_rx_flow_create(struct mtl_main_impl *impl, + enum mtl_port port, uint16_t q, + struct mt_rxq_flow *flow) { + struct mt_interface *inf = mt_if(impl, port); + struct mt_rx_flow_rsp *rsp; + struct mt_flow_impl *flow_impl = impl->flow[port]; if (!mt_drv_kernel_based(impl, port) && q >= inf->nb_rx_q) { - err("%s(%d), invalid q %u max allowed %u\n", __func__, port, q, inf->nb_rx_q); + err("%s(%d), invalid q %u max allowed %u\n", __func__, port, q, + inf->nb_rx_q); return NULL; } @@ -292,19 +303,20 @@ struct mt_rx_flow_rsp* mt_rx_flow_create(struct mtl_main_impl* impl, enum mtl_po return rsp; } -int mt_rx_flow_free(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rx_flow_rsp* rsp) { - struct mt_interface* inf = mt_if(impl, port); +int mt_rx_flow_free(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rx_flow_rsp *rsp) { + struct mt_interface *inf = mt_if(impl, port); /* no lock need */ return rx_flow_free(inf, rsp); } -int mt_flow_uinit(struct mtl_main_impl* impl) { +int mt_flow_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { - struct mt_flow_impl* flow = impl->flow[i]; - if (!flow) continue; + struct mt_flow_impl *flow = impl->flow[i]; + if (!flow) + continue; mt_pthread_mutex_destroy(&flow->mutex); mt_rte_free(flow); @@ -314,9 +326,9 @@ int mt_flow_uinit(struct mtl_main_impl* impl) { return 0; } -int mt_flow_init(struct mtl_main_impl* impl) { +int mt_flow_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_flow_impl* flow; + struct mt_flow_impl *flow; for (int i = 0; i < num_ports; i++) { flow = mt_rte_zmalloc_socket(sizeof(*flow), mt_socket_id(impl, i)); diff --git a/lib/src/mt_flow.h b/lib/src/mt_flow.h index 29ca564b0..9d36e6499 100644 --- a/lib/src/mt_flow.h +++ b/lib/src/mt_flow.h @@ -7,12 +7,13 @@ #include "mt_main.h" -int mt_flow_init(struct mtl_main_impl* impl); -int mt_flow_uinit(struct mtl_main_impl* impl); +int mt_flow_init(struct mtl_main_impl *impl); +int mt_flow_uinit(struct mtl_main_impl *impl); -struct mt_rx_flow_rsp* mt_rx_flow_create(struct mtl_main_impl* impl, enum mtl_port port, - uint16_t q, struct mt_rxq_flow* flow); -int mt_rx_flow_free(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rx_flow_rsp* rsp); +struct mt_rx_flow_rsp *mt_rx_flow_create(struct mtl_main_impl *impl, + enum mtl_port port, uint16_t q, + struct mt_rxq_flow *flow); +int mt_rx_flow_free(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rx_flow_rsp *rsp); #endif diff --git a/lib/src/mt_header.h b/lib/src/mt_header.h index 7030a526e..6ea7ffdb1 100644 --- a/lib/src/mt_header.h +++ b/lib/src/mt_header.h @@ -52,7 +52,7 @@ struct mt_stat_u64 { }; struct mt_rx_pcap { - struct mt_pcap* pcap; + struct mt_pcap *pcap; uint32_t dumped_pkts; uint32_t dropped_pkts; uint32_t required_pkts; diff --git a/lib/src/mt_instance.c b/lib/src/mt_instance.c index 33a57140e..f791a93d7 100644 --- a/lib/src/mt_instance.c +++ b/lib/src/mt_instance.c @@ -12,7 +12,7 @@ #include "mt_log.h" #include "mt_util.h" -static int instance_send_and_receive_message(int sock, mtl_message_t* msg, +static int instance_send_and_receive_message(int sock, mtl_message_t *msg, mtl_message_type_t response_type) { ssize_t ret = send(sock, msg, sizeof(*msg), 0); if (ret < 0) { @@ -31,7 +31,7 @@ static int instance_send_and_receive_message(int sock, mtl_message_t* msg, return ntohl(msg->body.response_msg.response); } -int mt_instance_put_lcore(struct mtl_main_impl* impl, uint16_t lcore_id) { +int mt_instance_put_lcore(struct mtl_main_impl *impl, uint16_t lcore_id) { int sock = impl->instance_fd; mtl_message_t msg; @@ -43,7 +43,7 @@ int mt_instance_put_lcore(struct mtl_main_impl* impl, uint16_t lcore_id) { return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); } -int mt_instance_get_lcore(struct mtl_main_impl* impl, uint16_t lcore_id) { +int mt_instance_get_lcore(struct mtl_main_impl *impl, uint16_t lcore_id) { int sock = impl->instance_fd; mtl_message_t msg; @@ -55,7 +55,8 @@ int mt_instance_get_lcore(struct mtl_main_impl* impl, uint16_t lcore_id) { return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); } -int mt_instance_request_xsks_map_fd(struct mtl_main_impl* impl, unsigned int ifindex) { +int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, + unsigned int ifindex) { int ret; int xsks_map_fd = -1; int sock = impl->instance_fd; @@ -73,7 +74,7 @@ int mt_instance_request_xsks_map_fd(struct mtl_main_impl* impl, unsigned int ifi } char cms[CMSG_SPACE(sizeof(int))]; - struct cmsghdr* cmsg; + struct cmsghdr *cmsg; struct msghdr msg; struct iovec iov; int value; @@ -101,23 +102,25 @@ int mt_instance_request_xsks_map_fd(struct mtl_main_impl* impl, unsigned int ifi return -EINVAL; } - xsks_map_fd = *(int*)CMSG_DATA(cmsg); + xsks_map_fd = *(int *)CMSG_DATA(cmsg); if (xsks_map_fd < 0) { - err("%s(%u), get xsks_map_fd fail, %s\n", __func__, ifindex, strerror(errno)); + err("%s(%u), get xsks_map_fd fail, %s\n", __func__, ifindex, + strerror(errno)); return errno; } return xsks_map_fd; } -int mt_instance_update_udp_dp_filter(struct mtl_main_impl* impl, unsigned int ifindex, - uint16_t dst_port, bool add) { +int mt_instance_update_udp_dp_filter(struct mtl_main_impl *impl, + unsigned int ifindex, uint16_t dst_port, + bool add) { int sock = impl->instance_fd; mtl_message_t msg; msg.header.magic = htonl(MTL_MANAGER_MAGIC); - msg.header.type = - add ? htonl(MTL_MSG_TYPE_ADD_UDP_DP_FILTER) : htonl(MTL_MSG_TYPE_DEL_UDP_DP_FILTER); + msg.header.type = add ? htonl(MTL_MSG_TYPE_ADD_UDP_DP_FILTER) + : htonl(MTL_MSG_TYPE_DEL_UDP_DP_FILTER); msg.body.udp_dp_filter_msg.ifindex = htonl(ifindex); msg.body.udp_dp_filter_msg.port = htons(dst_port); msg.header.body_len = htonl(sizeof(mtl_udp_dp_filter_message_t)); @@ -125,7 +128,7 @@ int mt_instance_update_udp_dp_filter(struct mtl_main_impl* impl, unsigned int if return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); } -int mt_instance_get_queue(struct mtl_main_impl* impl, unsigned int ifindex) { +int mt_instance_get_queue(struct mtl_main_impl *impl, unsigned int ifindex) { int sock = impl->instance_fd; mtl_message_t msg; @@ -134,10 +137,11 @@ int mt_instance_get_queue(struct mtl_main_impl* impl, unsigned int ifindex) { msg.body.if_msg.ifindex = htonl(ifindex); msg.header.body_len = htonl(sizeof(mtl_if_message_t)); - return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_IF_QUEUE_ID); + return instance_send_and_receive_message(sock, &msg, + MTL_MSG_TYPE_IF_QUEUE_ID); } -int mt_instance_put_queue(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_put_queue(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id) { int sock = impl->instance_fd; @@ -151,9 +155,10 @@ int mt_instance_put_queue(struct mtl_main_impl* impl, unsigned int ifindex, return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); } -int mt_instance_add_flow(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_add_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, - uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) { + uint32_t dst_ip, uint16_t src_port, + uint16_t dst_port) { int sock = impl->instance_fd; mtl_message_t msg; @@ -171,7 +176,7 @@ int mt_instance_add_flow(struct mtl_main_impl* impl, unsigned int ifindex, return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_IF_FLOW_ID); } -int mt_instance_del_flow(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_del_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint32_t flow_id) { int sock = impl->instance_fd; @@ -185,7 +190,7 @@ int mt_instance_del_flow(struct mtl_main_impl* impl, unsigned int ifindex, return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); } -int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p) { +int mt_instance_init(struct mtl_main_impl *impl, struct mtl_init_params *p) { impl->instance_fd = -1; int sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { @@ -196,21 +201,22 @@ int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p) { struct sockaddr_un addr; addr.sun_family = AF_UNIX; strncpy(addr.sun_path, MTL_MANAGER_SOCK_PATH, sizeof(addr.sun_path) - 1); - int ret = connect(sock, (struct sockaddr*)&addr, sizeof(addr)); + int ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { - warn("%s, connect to manager fail, assume single instance mode\n", __func__); + warn("%s, connect to manager fail, assume single instance mode\n", + __func__); close(sock); return ret; } - struct mt_user_info* u_info = &impl->u_info; + struct mt_user_info *u_info = &impl->u_info; mtl_message_t msg; msg.header.magic = htonl(MTL_MANAGER_MAGIC); msg.header.type = htonl(MTL_MSG_TYPE_REGISTER); msg.header.body_len = sizeof(mtl_register_message_t); - mtl_register_message_t* reg_msg = &msg.body.register_msg; + mtl_register_message_t *reg_msg = &msg.body.register_msg; reg_msg->pid = htonl(u_info->pid); reg_msg->uid = htonl(getuid()); strncpy(reg_msg->hostname, u_info->hostname, sizeof(reg_msg->hostname) - 1); @@ -220,7 +226,7 @@ int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p) { uint16_t num_xdp_if = 0; for (int i = 0; i < p->num_ports; i++) { if (mtl_pmd_is_af_xdp(p->pmd[i])) { - const char* if_name; + const char *if_name; if (p->pmd[i] == MTL_PMD_NATIVE_AF_XDP) if_name = mt_native_afxdp_port2if(p->port[i]); else @@ -231,7 +237,8 @@ int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p) { } reg_msg->num_if = htons(num_xdp_if); - int response = instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); + int response = + instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); if (response != 0) { err("%s, register fail\n", __func__); close(sock); @@ -245,9 +252,10 @@ int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p) { return 0; } -int mt_instance_uinit(struct mtl_main_impl* impl) { +int mt_instance_uinit(struct mtl_main_impl *impl) { int sock = impl->instance_fd; - if (sock <= 0) return -EIO; + if (sock <= 0) + return -EIO; return close(sock); } @@ -261,7 +269,7 @@ bool mtl_is_manager_alive(void) { struct sockaddr_un addr; addr.sun_family = AF_UNIX; strncpy(addr.sun_path, MTL_MANAGER_SOCK_PATH, sizeof(addr.sun_path) - 1); - int ret = connect(sock, (struct sockaddr*)&addr, sizeof(addr)); + int ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { err("%s, MTL manager is not alive\n", __func__); close(sock); @@ -274,42 +282,43 @@ bool mtl_is_manager_alive(void) { #else /* not supported on Windows */ -int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p) { +int mt_instance_init(struct mtl_main_impl *impl, struct mtl_init_params *p) { impl->instance_fd = -1; MTL_MAY_UNUSED(p); return -ENOTSUP; } -int mt_instance_uinit(struct mtl_main_impl* impl) { +int mt_instance_uinit(struct mtl_main_impl *impl) { MTL_MAY_UNUSED(impl); return -ENOTSUP; } -int mt_instance_get_lcore(struct mtl_main_impl* impl, uint16_t lcore_id) { +int mt_instance_get_lcore(struct mtl_main_impl *impl, uint16_t lcore_id) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(lcore_id); return -ENOTSUP; } -int mt_instance_put_lcore(struct mtl_main_impl* impl, uint16_t lcore_id) { +int mt_instance_put_lcore(struct mtl_main_impl *impl, uint16_t lcore_id) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(lcore_id); return -ENOTSUP; } -int mt_instance_request_xsks_map_fd(struct mtl_main_impl* impl, unsigned int ifindex) { +int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, + unsigned int ifindex) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(ifindex); return -ENOTSUP; } -int mt_instance_get_queue(struct mtl_main_impl* impl, unsigned int ifindex) { +int mt_instance_get_queue(struct mtl_main_impl *impl, unsigned int ifindex) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(ifindex); return -ENOTSUP; } -int mt_instance_put_queue(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_put_queue(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(ifindex); @@ -317,9 +326,10 @@ int mt_instance_put_queue(struct mtl_main_impl* impl, unsigned int ifindex, return -ENOTSUP; } -int mt_instance_add_flow(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_add_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, - uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) { + uint32_t dst_ip, uint16_t src_port, + uint16_t dst_port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(ifindex); MTL_MAY_UNUSED(queue_id); @@ -331,7 +341,7 @@ int mt_instance_add_flow(struct mtl_main_impl* impl, unsigned int ifindex, return -ENOTSUP; } -int mt_instance_del_flow(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_del_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint32_t flow_id) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(ifindex); @@ -339,8 +349,6 @@ int mt_instance_del_flow(struct mtl_main_impl* impl, unsigned int ifindex, return -ENOTSUP; } -bool mtl_is_manager_alive(void) { - return false; -} +bool mtl_is_manager_alive(void) { return false; } #endif \ No newline at end of file diff --git a/lib/src/mt_instance.h b/lib/src/mt_instance.h index 314564b20..ff8b0c5cd 100644 --- a/lib/src/mt_instance.h +++ b/lib/src/mt_instance.h @@ -7,21 +7,23 @@ #include "mt_main.h" -int mt_instance_init(struct mtl_main_impl* impl, struct mtl_init_params* p); -int mt_instance_uinit(struct mtl_main_impl* impl); +int mt_instance_init(struct mtl_main_impl *impl, struct mtl_init_params *p); +int mt_instance_uinit(struct mtl_main_impl *impl); -int mt_instance_get_lcore(struct mtl_main_impl* impl, uint16_t lcore_id); -int mt_instance_put_lcore(struct mtl_main_impl* impl, uint16_t lcore_id); -int mt_instance_request_xsks_map_fd(struct mtl_main_impl* impl, unsigned int ifindex); -int mt_instance_update_udp_dp_filter(struct mtl_main_impl* impl, unsigned int ifindex, - uint16_t dst_port, bool add); -int mt_instance_get_queue(struct mtl_main_impl* impl, unsigned int ifindex); -int mt_instance_put_queue(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_get_lcore(struct mtl_main_impl *impl, uint16_t lcore_id); +int mt_instance_put_lcore(struct mtl_main_impl *impl, uint16_t lcore_id); +int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, + unsigned int ifindex); +int mt_instance_update_udp_dp_filter(struct mtl_main_impl *impl, + unsigned int ifindex, uint16_t dst_port, + bool add); +int mt_instance_get_queue(struct mtl_main_impl *impl, unsigned int ifindex); +int mt_instance_put_queue(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id); -int mt_instance_add_flow(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_add_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); -int mt_instance_del_flow(struct mtl_main_impl* impl, unsigned int ifindex, +int mt_instance_del_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint32_t flow_id); #endif \ No newline at end of file diff --git a/lib/src/mt_log.c b/lib/src/mt_log.c index 6bbc62b24..08de0109a 100644 --- a/lib/src/mt_log.c +++ b/lib/src/mt_log.c @@ -6,7 +6,7 @@ #include "mt_main.h" -static void log_default_prefix(char* buf, size_t sz) { +static void log_default_prefix(char *buf, size_t sz) { time_t now; struct tm tm; @@ -41,11 +41,10 @@ int mtl_set_log_printer(mtl_log_printer_t f) { return 0; } -mtl_log_printer_t mt_get_log_printer(void) { - return g_mt_log_printer; -} +mtl_log_printer_t mt_get_log_printer(void) { return g_mt_log_printer; } -static void log_usdt_printer(enum mtl_log_level level, const char* format, ...) { +static void log_usdt_printer(enum mtl_log_level level, const char *format, + ...) { char msg[256]; va_list args; MTL_MAY_UNUSED(level); @@ -57,9 +56,7 @@ static void log_usdt_printer(enum mtl_log_level level, const char* format, ...) MT_USDT_SYS_LOG_MSG(level, msg); } -mtl_log_printer_t mt_get_usdt_log_printer(void) { - return log_usdt_printer; -} +mtl_log_printer_t mt_get_usdt_log_printer(void) { return log_usdt_printer; } static enum mtl_log_level g_mt_log_level = MTL_LOG_LEVEL_INFO; @@ -68,12 +65,10 @@ int mt_set_log_global_level(enum mtl_log_level level) { return 0; } -enum mtl_log_level mt_get_log_global_level(void) { - return g_mt_log_level; -} +enum mtl_log_level mt_get_log_global_level(void) { return g_mt_log_level; } int mtl_set_log_level(mtl_handle mt, enum mtl_log_level level) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; uint32_t rte_level; if (impl->type != MT_HANDLE_MAIN) { @@ -82,30 +77,31 @@ int mtl_set_log_level(mtl_handle mt, enum mtl_log_level level) { } dbg("%s, set log level %d\n", __func__, level); - if (level == mtl_get_log_level(mt)) return 0; + if (level == mtl_get_log_level(mt)) + return 0; switch (level) { - case MTL_LOG_LEVEL_DEBUG: - rte_level = RTE_LOG_DEBUG; - break; - case MTL_LOG_LEVEL_INFO: - rte_level = RTE_LOG_INFO; - break; - case MTL_LOG_LEVEL_NOTICE: - rte_level = RTE_LOG_NOTICE; - break; - case MTL_LOG_LEVEL_WARNING: - rte_level = RTE_LOG_WARNING; - break; - case MTL_LOG_LEVEL_ERR: - rte_level = RTE_LOG_ERR; - break; - case MTL_LOG_LEVEL_CRIT: - rte_level = RTE_LOG_CRIT; - break; - default: - err("%s, invalid level %d\n", __func__, level); - return -EINVAL; + case MTL_LOG_LEVEL_DEBUG: + rte_level = RTE_LOG_DEBUG; + break; + case MTL_LOG_LEVEL_INFO: + rte_level = RTE_LOG_INFO; + break; + case MTL_LOG_LEVEL_NOTICE: + rte_level = RTE_LOG_NOTICE; + break; + case MTL_LOG_LEVEL_WARNING: + rte_level = RTE_LOG_WARNING; + break; + case MTL_LOG_LEVEL_ERR: + rte_level = RTE_LOG_ERR; + break; + case MTL_LOG_LEVEL_CRIT: + rte_level = RTE_LOG_CRIT; + break; + default: + err("%s, invalid level %d\n", __func__, level); + return -EINVAL; } rte_log_set_global_level(rte_level); @@ -117,7 +113,7 @@ int mtl_set_log_level(mtl_handle mt, enum mtl_log_level level) { } enum mtl_log_level mtl_get_log_level(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -127,6 +123,4 @@ enum mtl_log_level mtl_get_log_level(mtl_handle mt) { return mt_get_user_params(impl)->log_level; } -int mtl_openlog_stream(FILE* f) { - return rte_openlog_stream(f); -} +int mtl_openlog_stream(FILE *f) { return rte_openlog_stream(f); } diff --git a/lib/src/mt_log.h b/lib/src/mt_log.h index 800238ff0..cd25aeb43 100644 --- a/lib/src/mt_log.h +++ b/lib/src/mt_log.h @@ -41,84 +41,84 @@ mtl_log_printer_t mt_get_usdt_log_printer(void); /* Debug-level messages */ #ifdef DEBUG -#define dbg(...) \ - do { \ - MT_LOG(DEBUG, MT, __VA_ARGS__); \ +#define dbg(...) \ + do { \ + MT_LOG(DEBUG, MT, __VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif /* Informational */ -#define info(...) \ - do { \ - MT_LOG(INFO, MTL, __VA_ARGS__); \ +#define info(...) \ + do { \ + MT_LOG(INFO, MTL, __VA_ARGS__); \ } while (0) -#define info_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(INFO, MTL, __VA_ARGS__); \ - once = false; \ - } \ +#define info_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(INFO, MTL, __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Normal but significant condition. */ -#define notice(...) \ - do { \ - MT_LOG(NOTICE, MTL, __VA_ARGS__); \ +#define notice(...) \ + do { \ + MT_LOG(NOTICE, MTL, __VA_ARGS__); \ } while (0) -#define notice_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(NOTICE, MTL, __VA_ARGS__); \ - once = false; \ - } \ +#define notice_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(NOTICE, MTL, __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Warning conditions. */ -#define warn(...) \ - do { \ - MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ +#define warn(...) \ + do { \ + MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ } while (0) -#define warn_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ - once = false; \ - } \ +#define warn_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Error conditions. */ -#define err(...) \ - do { \ - MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ +#define err(...) \ + do { \ + MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ } while (0) -#define err_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ - once = false; \ - } \ +#define err_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Critical conditions */ -#define critical(...) \ - do { \ - MT_LOG(CRIT, MTL, __VA_ARGS__); \ +#define critical(...) \ + do { \ + MT_LOG(CRIT, MTL, __VA_ARGS__); \ } while (0) -#define critical_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(CRIT, MTL, __VA_ARGS__); \ - once = false; \ - } \ +#define critical_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(CRIT, MTL, __VA_ARGS__); \ + once = false; \ + } \ } while (0) #endif diff --git a/lib/src/mt_main.c b/lib/src/mt_main.c index f09160323..02847a4a1 100644 --- a/lib/src/mt_main.c +++ b/lib/src/mt_main.c @@ -24,75 +24,83 @@ #include "st2110/pipeline/st_plugin.h" #include "udp/udp_rxq.h" -enum mtl_port mt_port_by_id(struct mtl_main_impl* impl, uint16_t port_id) { +enum mtl_port mt_port_by_id(struct mtl_main_impl *impl, uint16_t port_id) { int num_ports = mt_num_ports(impl); int i; for (i = 0; i < num_ports; i++) { - if (port_id == mt_port_id(impl, i)) return i; + if (port_id == mt_port_id(impl, i)) + return i; } err("%s, invalid port_id %d\n", __func__, port_id); return MTL_PORT_MAX; } -int mt_dst_ip_mac(struct mtl_main_impl* impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr* ea, enum mtl_port port, int timeout_ms) { +int mt_dst_ip_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], + struct rte_ether_addr *ea, enum mtl_port port, + int timeout_ms) { int ret; if (mt_is_multicast_ip(dip)) { mt_mcast_ip_to_mac(dip, ea); ret = 0; - } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), mt_sip_netmask(impl, port))) { + } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), + mt_sip_netmask(impl, port))) { ret = mt_arp_get_mac(impl, dip, ea, port, timeout_ms); } else { - uint8_t* gateway = mt_sip_gateway(impl, port); + uint8_t *gateway = mt_sip_gateway(impl, port); if (mt_ip_to_u32(gateway)) { ret = mt_arp_get_mac(impl, gateway, ea, port, timeout_ms); } else { - err("%s(%d), ip %d.%d.%d.%d is wan but no gateway support\n", __func__, port, - dip[0], dip[1], dip[2], dip[3]); + err("%s(%d), ip %d.%d.%d.%d is wan but no gateway support\n", __func__, + port, dip[0], dip[1], dip[2], dip[3]); return -EIO; } } - dbg("%s(%d), ip: %d.%d.%d.%d, mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", + dbg("%s(%d), ip: %d.%d.%d.%d, mac: " + "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", __func__, port, dip[0], dip[1], dip[2], dip[3], ea->addr_bytes[0], - ea->addr_bytes[1], ea->addr_bytes[2], ea->addr_bytes[3], ea->addr_bytes[4], - ea->addr_bytes[5]); + ea->addr_bytes[1], ea->addr_bytes[2], ea->addr_bytes[3], + ea->addr_bytes[4], ea->addr_bytes[5]); return ret; } -uint8_t* mt_sip_addr(struct mtl_main_impl* impl, enum mtl_port port) { - if (mt_dhcp_service_active(impl, port)) return mt_dhcp_get_ip(impl, port); +uint8_t *mt_sip_addr(struct mtl_main_impl *impl, enum mtl_port port) { + if (mt_dhcp_service_active(impl, port)) + return mt_dhcp_get_ip(impl, port); return mt_get_user_params(impl)->sip_addr[port]; } -uint8_t* mt_sip_netmask(struct mtl_main_impl* impl, enum mtl_port port) { - if (mt_dhcp_service_active(impl, port)) return mt_dhcp_get_netmask(impl, port); +uint8_t *mt_sip_netmask(struct mtl_main_impl *impl, enum mtl_port port) { + if (mt_dhcp_service_active(impl, port)) + return mt_dhcp_get_netmask(impl, port); return mt_get_user_params(impl)->netmask[port]; } -uint8_t* mt_sip_gateway(struct mtl_main_impl* impl, enum mtl_port port) { - if (mt_dhcp_service_active(impl, port)) return mt_dhcp_get_gateway(impl, port); +uint8_t *mt_sip_gateway(struct mtl_main_impl *impl, enum mtl_port port) { + if (mt_dhcp_service_active(impl, port)) + return mt_dhcp_get_gateway(impl, port); return mt_get_user_params(impl)->gateway[port]; } -bool mt_is_valid_socket(struct mtl_main_impl* impl, int soc_id) { +bool mt_is_valid_socket(struct mtl_main_impl *impl, int soc_id) { int num_ports = mt_num_ports(impl); int i; for (i = 0; i < num_ports; i++) { - if (soc_id == mt_socket_id(impl, i)) return true; + if (soc_id == mt_socket_id(impl, i)) + return true; } err("%s, invalid soc_id %d\n", __func__, soc_id); return false; } -static int u64_cmp(const void* a, const void* b) { - const uint64_t* ai = a; - const uint64_t* bi = b; +static int u64_cmp(const void *a, const void *b) { + const uint64_t *ai = a; + const uint64_t *bi = b; if (*ai < *bi) { return -1; @@ -102,8 +110,8 @@ static int u64_cmp(const void* a, const void* b) { return 0; } -static void* mt_calibrate_tsc(void* arg) { - struct mtl_main_impl* impl = arg; +static void *mt_calibrate_tsc(void *arg) { + struct mtl_main_impl *impl = arg; int loop = 100; int trim = 10; uint64_t array[loop]; @@ -133,7 +141,7 @@ static void* mt_calibrate_tsc(void* arg) { return NULL; } -static int mt_main_create(struct mtl_main_impl* impl) { +static int mt_main_create(struct mtl_main_impl *impl) { int ret; ret = mt_flow_init(impl); @@ -226,7 +234,7 @@ static int mt_main_create(struct mtl_main_impl* impl) { return 0; } -static int mt_main_free(struct mtl_main_impl* impl) { +static int mt_main_free(struct mtl_main_impl *impl) { if (impl->tsc_cal_tid) { pthread_join(impl->tsc_cal_tid, NULL); impl->tsc_cal_tid = 0; @@ -253,15 +261,16 @@ static int mt_main_free(struct mtl_main_impl* impl) { return 0; } -bool mt_sessions_time_measure(struct mtl_main_impl* impl) { +bool mt_sessions_time_measure(struct mtl_main_impl *impl) { bool enabled = mt_user_tasklet_time_measure(impl); - if (MT_USDT_SESSIONS_TIME_MEASURE_ENABLED()) enabled = true; + if (MT_USDT_SESSIONS_TIME_MEASURE_ENABLED()) + enabled = true; return enabled; } -static int mt_user_params_check(struct mtl_init_params* p) { +static int mt_user_params_check(struct mtl_init_params *p) { int num_ports = p->num_ports, ret; - uint8_t* ip = NULL; + uint8_t *ip = NULL; uint8_t if_ip[MTL_IP_ADDR_LEN]; uint8_t if_netmask[MTL_IP_ADDR_LEN]; @@ -273,7 +282,7 @@ static int mt_user_params_check(struct mtl_init_params* p) { /* info check for each port */ for (int i = 0; i < num_ports; i++) { enum mtl_pmd_type pmd = p->pmd[i]; - const char* if_name = NULL; + const char *if_name = NULL; /* type check */ if (pmd >= MTL_PMD_TYPE_MAX) { @@ -288,7 +297,8 @@ static int mt_user_params_check(struct mtl_init_params* p) { else if_name = mt_dpdk_afxdp_port2if(p->port[i]); if (!if_name) { - err("%s(%d), get afxdp if name fail from %s\n", __func__, i, p->port[i]); + err("%s(%d), get afxdp if name fail from %s\n", __func__, i, + p->port[i]); return -EINVAL; } } @@ -296,7 +306,8 @@ static int mt_user_params_check(struct mtl_init_params* p) { if (pmd == MTL_PMD_DPDK_AF_PACKET) { if_name = mt_dpdk_afpkt_port2if(p->port[i]); if (!if_name) { - err("%s(%d), get afpkt if name fail from %s\n", __func__, i, p->port[i]); + err("%s(%d), get afpkt if name fail from %s\n", __func__, i, + p->port[i]); return -EINVAL; } } @@ -304,7 +315,8 @@ static int mt_user_params_check(struct mtl_init_params* p) { if (pmd == MTL_PMD_KERNEL_SOCKET) { if_name = mt_kernel_port2if(p->port[i]); if (!if_name) { - err("%s(%d), get kernel socket if name fail from %s\n", __func__, i, p->port[i]); + err("%s(%d), get kernel socket if name fail from %s\n", __func__, i, + p->port[i]); return -EINVAL; } } @@ -319,7 +331,8 @@ static int mt_user_params_check(struct mtl_init_params* p) { ip = p->sip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], + ip[2], ip[3]); return -EINVAL; } } @@ -330,19 +343,22 @@ static int mt_user_params_check(struct mtl_init_params* p) { if (0 == strncmp(p->port[i], p->port[j], MTL_PORT_MAX_LEN)) { if (!strncmp(p->port[i], "kernel:lo", MTL_PORT_MAX_LEN)) { /* duplicated kernel:lo for test purpose */ - warn("%s, same name %s for port %d and %d\n", __func__, p->port[i], i, j); + warn("%s, same name %s for port %d and %d\n", __func__, p->port[i], + i, j); } else { - err("%s, same name %s for port %d and %d\n", __func__, p->port[i], i, j); + err("%s, same name %s for port %d and %d\n", __func__, p->port[i], + i, j); return -EINVAL; } } /* check if duplicate ip */ - if ((p->net_proto[i] == MTL_PROTO_STATIC) && (p->pmd[i] == MTL_PMD_DPDK_USER) && + if ((p->net_proto[i] == MTL_PROTO_STATIC) && + (p->pmd[i] == MTL_PMD_DPDK_USER) && (p->pmd[j] == MTL_PMD_DPDK_USER)) { if (0 == memcmp(p->sip_addr[i], p->sip_addr[j], MTL_IP_ADDR_LEN)) { ip = p->sip_addr[j]; - err("%s, same ip %d.%d.%d.%d for port %d and %d\n", __func__, ip[0], ip[1], - ip[2], ip[3], i, j); + err("%s, same ip %d.%d.%d.%d for port %d and %d\n", __func__, ip[0], + ip[1], ip[2], ip[3], i, j); return -EINVAL; } } @@ -353,7 +369,7 @@ static int mt_user_params_check(struct mtl_init_params* p) { return 0; } -static int _mt_start(struct mtl_main_impl* impl) { +static int _mt_start(struct mtl_main_impl *impl) { int ret; if (mt_started(impl)) { @@ -376,7 +392,7 @@ static int _mt_start(struct mtl_main_impl* impl) { return 0; } -static int _mt_stop(struct mtl_main_impl* impl) { +static int _mt_stop(struct mtl_main_impl *impl) { if (!mt_started(impl)) { dbg("%s, not started\n", __func__); return 0; @@ -388,12 +404,12 @@ static int _mt_stop(struct mtl_main_impl* impl) { return 0; } -mtl_handle mtl_init(struct mtl_init_params* p) { - struct mtl_main_impl* impl = NULL; +mtl_handle mtl_init(struct mtl_init_params *p) { + struct mtl_main_impl *impl = NULL; int socket[MTL_PORT_MAX], ret; int num_ports = p->num_ports; struct mt_kport_info kport_info; - struct mt_interface* inf; + struct mt_interface *inf; enum mtl_pmd_type pmd; RTE_BUILD_BUG_ON(MTL_SESSION_PORT_MAX > (int)MTL_PORT_MAX); @@ -431,10 +447,12 @@ mtl_handle mtl_init(struct mtl_init_params* p) { socket[i] = mt_dev_get_socket_id(p->port[i]); } if (socket[i] < 0) { - err("%s(%d), get socket fail %d for pmd %d\n", __func__, i, socket[i], p->pmd[i]); + err("%s(%d), get socket fail %d for pmd %d\n", __func__, i, socket[i], + p->pmd[i]); #ifndef WINDOWSENV if (pmd == MTL_PMD_DPDK_USER) { - err("Run \"dpdk-devbind.py -s | grep Ethernet\" to check if other port driver is " + err("Run \"dpdk-devbind.py -s | grep Ethernet\" to check if other port " + "driver is " "ready as vfio-pci mode\n"); } #endif @@ -449,10 +467,11 @@ mtl_handle mtl_init(struct mtl_init_params* p) { #ifndef WINDOWSENV int numa_nodes = 0; - if (numa_available() >= 0) numa_nodes = numa_max_node() + 1; + if (numa_available() >= 0) + numa_nodes = numa_max_node() + 1; if (!(p->flags & MTL_FLAG_NOT_BIND_PROCESS_NUMA) && (numa_nodes > 1)) { /* bind current thread and its children to socket node */ - struct bitmask* mask = numa_bitmask_alloc(numa_nodes); + struct bitmask *mask = numa_bitmask_alloc(numa_nodes); info("%s, bind to socket %d, numa_nodes %d\n", __func__, socket[MTL_PORT_P], numa_nodes); @@ -500,7 +519,7 @@ mtl_handle mtl_init(struct mtl_init_params* p) { uint8_t if_ip[MTL_IP_ADDR_LEN]; uint8_t if_netmask[MTL_IP_ADDR_LEN]; uint8_t if_gateway[MTL_IP_ADDR_LEN]; - const char* if_name = kport_info.kernel_if[i]; + const char *if_name = kport_info.kernel_if[i]; ret = mt_socket_get_if_ip(if_name, if_ip, if_netmask); if (ret < 0) { @@ -567,10 +586,12 @@ mtl_handle mtl_init(struct mtl_init_params* p) { impl->rx_pool_data_size = p->rx_pool_data_size; info("%s, new rx_pool_data_size %u\n", __func__, impl->rx_pool_data_size); } else { - warn("%s, invalid rx_pool_data_size %u\n", __func__, p->rx_pool_data_size); + warn("%s, invalid rx_pool_data_size %u\n", __func__, + p->rx_pool_data_size); } } - impl->sch_schedule_ns = 200 * NS_PER_US; /* max schedule ns for mt_sleep_ms(0) */ + impl->sch_schedule_ns = + 200 * NS_PER_US; /* max schedule ns for mt_sleep_ms(0) */ if (p->arp_timeout_s) impl->arp_timeout_ms = p->arp_timeout_s * MS_PER_S; @@ -614,7 +635,8 @@ mtl_handle mtl_init(struct mtl_init_params* p) { } if (p->flags & MTL_FLAG_NOT_BIND_NUMA) { - warn("%s, performance may limited as possible across numa access\n", __func__); + warn("%s, performance may limited as possible across numa access\n", + __func__); } info("%s, succ, tsc_hz %" PRIu64 "\n", __func__, impl->tsc_hz); @@ -623,13 +645,14 @@ mtl_handle mtl_init(struct mtl_init_params* p) { return impl; err_exit: - if (impl) mtl_uninit(impl); + if (impl) + mtl_uninit(impl); return NULL; } int mtl_uninit(mtl_handle mt) { - struct mtl_main_impl* impl = mt; - struct mtl_init_params* p = mt_get_user_params(impl); + struct mtl_main_impl *impl = mt; + struct mtl_init_params *p = mt_get_user_params(impl); if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -659,7 +682,7 @@ int mtl_uninit(mtl_handle mt) { } int mtl_start(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -670,20 +693,21 @@ int mtl_start(mtl_handle mt) { } int mtl_stop(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); return -EIO; } - if (mt_user_auto_start_stop(impl)) return 0; + if (mt_user_auto_start_stop(impl)) + return 0; return _mt_stop(impl); } -int mtl_get_lcore(mtl_handle mt, unsigned int* lcore) { - struct mtl_main_impl* impl = mt; +int mtl_get_lcore(mtl_handle mt, unsigned int *lcore) { + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -695,7 +719,7 @@ int mtl_get_lcore(mtl_handle mt, unsigned int* lcore) { } int mtl_put_lcore(mtl_handle mt, unsigned int lcore) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -706,7 +730,7 @@ int mtl_put_lcore(mtl_handle mt, unsigned int lcore) { } int mtl_bind_to_lcore(mtl_handle mt, pthread_t thread, unsigned int lcore) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -727,7 +751,7 @@ int mtl_bind_to_lcore(mtl_handle mt, pthread_t thread, unsigned int lcore) { } int mtl_abort(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -739,12 +763,12 @@ int mtl_abort(mtl_handle mt) { return 0; } -void* mtl_memcpy(void* dest, const void* src, size_t n) { +void *mtl_memcpy(void *dest, const void *src, size_t n) { return rte_memcpy(dest, src, n); } -void* mtl_hp_malloc(mtl_handle mt, size_t size, enum mtl_port port) { - struct mtl_main_impl* impl = mt; +void *mtl_hp_malloc(mtl_handle mt, size_t size, enum mtl_port port) { + struct mtl_main_impl *impl = mt; int num_ports = mt_num_ports(impl); if (impl->type != MT_HANDLE_MAIN) { @@ -760,8 +784,8 @@ void* mtl_hp_malloc(mtl_handle mt, size_t size, enum mtl_port port) { return mt_rte_malloc_socket(size, mt_socket_id(impl, port)); } -void* mtl_hp_zmalloc(mtl_handle mt, size_t size, enum mtl_port port) { - struct mtl_main_impl* impl = mt; +void *mtl_hp_zmalloc(mtl_handle mt, size_t size, enum mtl_port port) { + struct mtl_main_impl *impl = mt; int num_ports = mt_num_ports(impl); if (impl->type != MT_HANDLE_MAIN) { @@ -777,18 +801,18 @@ void* mtl_hp_zmalloc(mtl_handle mt, size_t size, enum mtl_port port) { return mt_rte_zmalloc_socket(size, mt_socket_id(impl, port)); } -void mtl_hp_free(mtl_handle mt, void* ptr) { +void mtl_hp_free(mtl_handle mt, void *ptr) { MTL_MAY_UNUSED(mt); return mt_rte_free(ptr); } -mtl_iova_t mtl_hp_virt2iova(mtl_handle mt, const void* vaddr) { +mtl_iova_t mtl_hp_virt2iova(mtl_handle mt, const void *vaddr) { MTL_MAY_UNUSED(mt); return rte_malloc_virt2iova(vaddr); } size_t mtl_page_size(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -798,8 +822,8 @@ size_t mtl_page_size(mtl_handle mt) { return impl->page_size; } -mtl_iova_t mtl_dma_map(mtl_handle mt, const void* vaddr, size_t size) { - struct mtl_main_impl* impl = mt; +mtl_iova_t mtl_dma_map(mtl_handle mt, const void *vaddr, size_t size) { + struct mtl_main_impl *impl = mt; int ret; mtl_iova_t iova; size_t page_size = mtl_page_size(impl); @@ -809,7 +833,7 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void* vaddr, size_t size) { return MTL_BAD_IOVA; } - if (!rte_is_aligned((void*)vaddr, page_size)) { + if (!rte_is_aligned((void *)vaddr, page_size)) { err("%s, vaddr %p not align to page size\n", __func__, vaddr); return MTL_BAD_IOVA; } @@ -825,26 +849,28 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void* vaddr, size_t size) { } struct mt_map_item item; - item.vaddr = (void*)vaddr; + item.vaddr = (void *)vaddr; item.size = size; item.iova = MTL_BAD_IOVA; /* let map to find one suitable iova for us */ ret = mt_map_add(impl, &item); - if (ret < 0) return MTL_BAD_IOVA; + if (ret < 0) + return MTL_BAD_IOVA; iova = item.iova; if (!mt_drv_dpdk_based(impl, MTL_PORT_P)) { return iova; } - ret = rte_extmem_register((void*)vaddr, size, NULL, 0, page_size); + ret = rte_extmem_register((void *)vaddr, size, NULL, 0, page_size); if (ret < 0) { - err("%s, fail(%d,%s) to register extmem %p\n", __func__, ret, rte_strerror(rte_errno), - vaddr); + err("%s, fail(%d,%s) to register extmem %p\n", __func__, ret, + rte_strerror(rte_errno), vaddr); goto fail_extmem; } /* only map for MTL_PORT_P now */ - ret = rte_dev_dma_map(mt_port_device(impl, MTL_PORT_P), (void*)vaddr, iova, size); + ret = rte_dev_dma_map(mt_port_device(impl, MTL_PORT_P), (void *)vaddr, iova, + size); if (ret < 0) { err("%s, dma map fail(%d,%s) for add(%p,%" PRIu64 ")\n", __func__, ret, rte_strerror(rte_errno), vaddr, size); @@ -854,14 +880,15 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void* vaddr, size_t size) { return iova; fail_map: - rte_extmem_unregister((void*)vaddr, size); + rte_extmem_unregister((void *)vaddr, size); fail_extmem: mt_map_remove(impl, &item); return MTL_BAD_IOVA; } -int mtl_dma_unmap(mtl_handle mt, const void* vaddr, mtl_iova_t iova, size_t size) { - struct mtl_main_impl* impl = mt; +int mtl_dma_unmap(mtl_handle mt, const void *vaddr, mtl_iova_t iova, + size_t size) { + struct mtl_main_impl *impl = mt; int ret; size_t page_size = mtl_page_size(impl); @@ -870,7 +897,7 @@ int mtl_dma_unmap(mtl_handle mt, const void* vaddr, mtl_iova_t iova, size_t size return -EIO; } - if (!rte_is_aligned((void*)vaddr, page_size)) { + if (!rte_is_aligned((void *)vaddr, page_size)) { err("%s, vaddr %p not align to page size\n", __func__, vaddr); return -EINVAL; } @@ -886,31 +913,33 @@ int mtl_dma_unmap(mtl_handle mt, const void* vaddr, mtl_iova_t iova, size_t size } struct mt_map_item item; - item.vaddr = (void*)vaddr; + item.vaddr = (void *)vaddr; item.size = size; item.iova = iova; ret = mt_map_remove(impl, &item); - if (ret < 0) return ret; + if (ret < 0) + return ret; if (!mt_drv_dpdk_based(impl, MTL_PORT_P)) { return 0; } /* only unmap for MTL_PORT_P now */ - ret = rte_dev_dma_unmap(mt_port_device(impl, MTL_PORT_P), (void*)vaddr, iova, size); + ret = rte_dev_dma_unmap(mt_port_device(impl, MTL_PORT_P), (void *)vaddr, iova, + size); if (ret < 0) { err("%s, dma unmap fail(%d,%s) for add(%p,%" PRIu64 ")\n", __func__, ret, rte_strerror(rte_errno), vaddr, size); } - rte_extmem_unregister((void*)vaddr, size); + rte_extmem_unregister((void *)vaddr, size); return 0; } mtl_dma_mem_handle mtl_dma_mem_alloc(mtl_handle mt, size_t size) { - struct mtl_main_impl* impl = mt; - struct mtl_dma_mem* mem; + struct mtl_main_impl *impl = mt; + struct mtl_dma_mem *mem; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -926,14 +955,14 @@ mtl_dma_mem_handle mtl_dma_mem_alloc(mtl_handle mt, size_t size) { size_t page_size = mtl_page_size(impl); size_t iova_size = mtl_size_page_align(size, page_size); size_t alloc_size = iova_size + page_size; - void* alloc_addr = mt_zmalloc(alloc_size); + void *alloc_addr = mt_zmalloc(alloc_size); if (!alloc_addr) { err("%s, dma mem alloc fail\n", __func__); mt_rte_free(mem); return NULL; } - void* addr = (void*)MTL_ALIGN((uint64_t)alloc_addr, page_size); + void *addr = (void *)MTL_ALIGN((uint64_t)alloc_addr, page_size); mtl_iova_t iova = mtl_dma_map(impl, addr, iova_size); if (iova == MTL_BAD_IOVA) { err("%s, dma mem %p map fail\n", __func__, addr); @@ -954,37 +983,38 @@ mtl_dma_mem_handle mtl_dma_mem_alloc(mtl_handle mt, size_t size) { } void mtl_dma_mem_free(mtl_handle mt, mtl_dma_mem_handle handle) { - struct mtl_dma_mem* mem = handle; + struct mtl_dma_mem *mem = handle; mtl_dma_unmap(mt, mem->addr, mem->iova, mem->iova_size); mt_free(mem->alloc_addr); mt_rte_free(mem); } -void* mtl_dma_mem_addr(mtl_dma_mem_handle handle) { - struct mtl_dma_mem* mem = handle; +void *mtl_dma_mem_addr(mtl_dma_mem_handle handle) { + struct mtl_dma_mem *mem = handle; return mem->addr; } mtl_iova_t mtl_dma_mem_iova(mtl_dma_mem_handle handle) { - struct mtl_dma_mem* mem = handle; + struct mtl_dma_mem *mem = handle; return mem->iova; } -const char* mtl_version(void) { +const char *mtl_version(void) { static char version[128]; - if (version[0] != 0) return version; + if (version[0] != 0) + return version; snprintf(version, sizeof(version), "%d.%d.%d.%s %s %s %s", MTL_VERSION_MAJOR, - MTL_VERSION_MINOR, MTL_VERSION_LAST, MTL_VERSION_EXTRA, __TIMESTAMP__, - __MTL_GIT__, MTL_COMPILER); + MTL_VERSION_MINOR, MTL_VERSION_LAST, MTL_VERSION_EXTRA, + __TIMESTAMP__, __MTL_GIT__, MTL_COMPILER); return version; } -int mtl_get_fix_info(mtl_handle mt, struct mtl_fix_info* info) { - struct mtl_main_impl* impl = mt; +int mtl_get_fix_info(mtl_handle mt, struct mtl_fix_info *info) { + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -998,9 +1028,9 @@ int mtl_get_fix_info(mtl_handle mt, struct mtl_fix_info* info) { return 0; } -int mtl_get_var_info(mtl_handle mt, struct mtl_var_info* info) { - struct mtl_main_impl* impl = mt; - struct mt_dma_mgr* mgr = mt_get_dma_mgr(impl); +int mtl_get_var_info(mtl_handle mt, struct mtl_var_info *info) { + struct mtl_main_impl *impl = mt; + struct mt_dma_mgr *mgr = mt_get_dma_mgr(impl); if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1016,8 +1046,8 @@ int mtl_get_var_info(mtl_handle mt, struct mtl_var_info* info) { return 0; } -int st_get_var_info(mtl_handle mt, struct st_var_info* info) { - struct mtl_main_impl* impl = mt; +int st_get_var_info(mtl_handle mt, struct st_var_info *info) { + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1038,7 +1068,7 @@ int st_get_var_info(mtl_handle mt, struct st_var_info* info) { } int mtl_sch_enable_sleep(mtl_handle mt, int sch_idx, bool enable) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (sch_idx > MT_MAX_SCH_NUM) { err("%s, invalid sch_idx %d\n", __func__, sch_idx); @@ -1049,7 +1079,7 @@ int mtl_sch_enable_sleep(mtl_handle mt, int sch_idx, bool enable) { return -EIO; } - struct mtl_sch_impl* sch = mt_sch_instance(impl, sch_idx); + struct mtl_sch_impl *sch = mt_sch_instance(impl, sch_idx); if (!sch) { err("%s(%d), sch instance null\n", __func__, sch_idx); return -EIO; @@ -1060,12 +1090,13 @@ int mtl_sch_enable_sleep(mtl_handle mt, int sch_idx, bool enable) { } mt_sch_enable_allow_sleep(sch, enable); - info("%s(%d), %s allow sleep\n", __func__, sch_idx, enable ? "enable" : "disable"); + info("%s(%d), %s allow sleep\n", __func__, sch_idx, + enable ? "enable" : "disable"); return 0; } int mtl_sch_set_sleep_us(mtl_handle mt, uint64_t us) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1078,7 +1109,7 @@ int mtl_sch_set_sleep_us(mtl_handle mt, uint64_t us) { } uint64_t mtl_ptp_read_time(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; enum mtl_port port = MTL_PORT_P; if (impl->type != MT_HANDLE_MAIN) { @@ -1103,7 +1134,7 @@ uint64_t mtl_ptp_read_time(mtl_handle mt) { } uint64_t mtl_ptp_read_time_raw(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; enum mtl_port port = MTL_PORT_P; if (impl->type != MT_HANDLE_MAIN) { @@ -1114,8 +1145,9 @@ uint64_t mtl_ptp_read_time_raw(mtl_handle mt) { return mt_get_ptp_time(impl, port); } -mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, enum mtl_port port) { - struct mtl_main_impl* impl = mt; +mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, + enum mtl_port port) { + struct mtl_main_impl *impl = mt; struct mt_dma_request_req req; if (impl->type != MT_HANDLE_MAIN) { @@ -1134,14 +1166,15 @@ mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, enum mtl_port p req.socket_id = mt_socket_id(impl, port); req.priv = impl; req.drop_mbuf_cb = NULL; - struct mtl_dma_lender_dev* dev = mt_dma_request_dev(impl, &req); - if (dev) dev->type = MT_HANDLE_UDMA; + struct mtl_dma_lender_dev *dev = mt_dma_request_dev(impl, &req); + if (dev) + dev->type = MT_HANDLE_UDMA; return dev; } int mtl_udma_free(mtl_udma_handle handle) { - struct mtl_dma_lender_dev* dev = handle; - struct mtl_main_impl* impl = dev->priv; + struct mtl_dma_lender_dev *dev = handle; + struct mtl_main_impl *impl = dev->priv; if (dev->type != MT_HANDLE_UDMA) { err("%s, invalid type %d\n", __func__, dev->type); @@ -1153,7 +1186,7 @@ int mtl_udma_free(mtl_udma_handle handle) { int mtl_udma_copy(mtl_udma_handle handle, mtl_iova_t dst, mtl_iova_t src, uint32_t length) { - struct mtl_dma_lender_dev* dev = handle; + struct mtl_dma_lender_dev *dev = handle; if (dev->type != MT_HANDLE_UDMA) { err("%s, invalid type %d\n", __func__, dev->type); @@ -1165,7 +1198,7 @@ int mtl_udma_copy(mtl_udma_handle handle, mtl_iova_t dst, mtl_iova_t src, int mtl_udma_fill(mtl_udma_handle handle, mtl_iova_t dst, uint64_t pattern, uint32_t length) { - struct mtl_dma_lender_dev* dev = handle; + struct mtl_dma_lender_dev *dev = handle; if (dev->type != MT_HANDLE_UDMA) { err("%s, invalid type %d\n", __func__, dev->type); @@ -1176,7 +1209,7 @@ int mtl_udma_fill(mtl_udma_handle handle, mtl_iova_t dst, uint64_t pattern, } int mtl_udma_submit(mtl_udma_handle handle) { - struct mtl_dma_lender_dev* dev = handle; + struct mtl_dma_lender_dev *dev = handle; if (dev->type != MT_HANDLE_UDMA) { err("%s, invalid type %d\n", __func__, dev->type); @@ -1187,7 +1220,7 @@ int mtl_udma_submit(mtl_udma_handle handle) { } uint16_t mtl_udma_completed(mtl_udma_handle handle, const uint16_t nb_cpls) { - struct mtl_dma_lender_dev* dev = handle; + struct mtl_dma_lender_dev *dev = handle; if (dev->type != MT_HANDLE_UDMA) { err("%s, invalid type %d\n", __func__, dev->type); @@ -1198,7 +1231,7 @@ uint16_t mtl_udma_completed(mtl_udma_handle handle, const uint16_t nb_cpls) { } enum mtl_rss_mode mtl_rss_mode_get(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1209,7 +1242,7 @@ enum mtl_rss_mode mtl_rss_mode_get(mtl_handle mt) { } enum mtl_iova_mode mtl_iova_mode_get(mtl_handle mt) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1217,19 +1250,21 @@ enum mtl_iova_mode mtl_iova_mode_get(mtl_handle mt) { } switch (impl->iova_mode) { - case RTE_IOVA_PA: - return MTL_IOVA_MODE_PA; - case RTE_IOVA_VA: - return MTL_IOVA_MODE_VA; - default: - err("%s, invalid iova_mode %d\n", __func__, impl->iova_mode); - return MTL_IOVA_MODE_MAX; + case RTE_IOVA_PA: + return MTL_IOVA_MODE_PA; + case RTE_IOVA_VA: + return MTL_IOVA_MODE_VA; + default: + err("%s, invalid iova_mode %d\n", __func__, impl->iova_mode); + return MTL_IOVA_MODE_MAX; } } -int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, uint8_t ip[MTL_IP_ADDR_LEN], - uint8_t netmask[MTL_IP_ADDR_LEN], uint8_t gateway[MTL_IP_ADDR_LEN]) { - struct mtl_main_impl* impl = mt; +int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, + uint8_t ip[MTL_IP_ADDR_LEN], + uint8_t netmask[MTL_IP_ADDR_LEN], + uint8_t gateway[MTL_IP_ADDR_LEN]) { + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1240,29 +1275,34 @@ int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, uint8_t ip[MTL_IP_ADDR_L return -EINVAL; } - if (ip) rte_memcpy(ip, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); - if (netmask) rte_memcpy(netmask, mt_sip_netmask(impl, port), MTL_IP_ADDR_LEN); - if (gateway) rte_memcpy(gateway, mt_sip_gateway(impl, port), MTL_IP_ADDR_LEN); + if (ip) + rte_memcpy(ip, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); + if (netmask) + rte_memcpy(netmask, mt_sip_netmask(impl, port), MTL_IP_ADDR_LEN); + if (gateway) + rte_memcpy(gateway, mt_sip_gateway(impl, port), MTL_IP_ADDR_LEN); return 0; } enum mtl_simd_level mtl_get_simd_level(void) { if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VBMI2)) return MTL_SIMD_LEVEL_AVX512_VBMI2; - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL)) return MTL_SIMD_LEVEL_AVX512; - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2)) return MTL_SIMD_LEVEL_AVX2; + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL)) + return MTL_SIMD_LEVEL_AVX512; + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2)) + return MTL_SIMD_LEVEL_AVX2; /* no simd */ return MTL_SIMD_LEVEL_NONE; } -static const char* mt_simd_level_names[MTL_SIMD_LEVEL_MAX] = { +static const char *mt_simd_level_names[MTL_SIMD_LEVEL_MAX] = { "none", "avx2", "avx512", "avx512_vbmi", }; -const char* mtl_get_simd_level_name(enum mtl_simd_level level) { +const char *mtl_get_simd_level_name(enum mtl_simd_level level) { if (level >= MTL_SIMD_LEVEL_MAX) { err("%s, invalid level %d\n", __func__, level); return "unknown"; @@ -1272,7 +1312,7 @@ const char* mtl_get_simd_level_name(enum mtl_simd_level level) { } bool mtl_pmd_is_dpdk_based(mtl_handle mt, enum mtl_port port) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1285,7 +1325,7 @@ bool mtl_pmd_is_dpdk_based(mtl_handle mt, enum mtl_port port) { return mt_drv_dpdk_based(impl, port); } -int mtl_thread_setname(pthread_t tid, const char* name) { +int mtl_thread_setname(pthread_t tid, const char *name) { #if RTE_VERSION >= RTE_VERSION_NUM(23, 11, 0, 0) rte_thread_t thread_id = {.opaque_id = tid}; rte_thread_set_name(thread_id, name); @@ -1299,45 +1339,48 @@ int mtl_thread_setname(pthread_t tid, const char* name) { #endif } -void mtl_sleep_us(unsigned int us) { - return mt_sleep_us(us); -} +void mtl_sleep_us(unsigned int us) { return mt_sleep_us(us); } -void mtl_delay_us(unsigned int us) { - return mt_delay_us(us); -} +void mtl_delay_us(unsigned int us) { return mt_delay_us(us); } -int mtl_para_sip_set(struct mtl_init_params* p, enum mtl_port port, char* ip) { +int mtl_para_sip_set(struct mtl_init_params *p, enum mtl_port port, char *ip) { int ret = inet_pton(AF_INET, ip, p->sip_addr[port]); - if (ret == 1) return 0; + if (ret == 1) + return 0; err("%s, fail to inet_pton for %s\n", __func__, ip); return -EIO; } -int mtl_para_gateway_set(struct mtl_init_params* p, enum mtl_port port, char* gateway) { +int mtl_para_gateway_set(struct mtl_init_params *p, enum mtl_port port, + char *gateway) { int ret = inet_pton(AF_INET, gateway, p->gateway[port]); - if (ret == 1) return 0; + if (ret == 1) + return 0; err("%s, fail to inet_pton for %s\n", __func__, gateway); return -EIO; } -int mtl_para_netmask_set(struct mtl_init_params* p, enum mtl_port port, char* netmask) { +int mtl_para_netmask_set(struct mtl_init_params *p, enum mtl_port port, + char *netmask) { int ret = inet_pton(AF_INET, netmask, p->netmask[port]); - if (ret == 1) return 0; + if (ret == 1) + return 0; err("%s, fail to inet_pton for %s\n", __func__, netmask); return -EIO; } -int mtl_para_port_set(struct mtl_init_params* p, enum mtl_port port, char* name) { +int mtl_para_port_set(struct mtl_init_params *p, enum mtl_port port, + char *name) { return snprintf(p->port[port], MTL_PORT_MAX_LEN, "%s", name); } -int mtl_para_dma_port_set(struct mtl_init_params* p, enum mtl_port port, char* name) { +int mtl_para_dma_port_set(struct mtl_init_params *p, enum mtl_port port, + char *name) { return snprintf(p->dma_dev_port[port], MTL_PORT_MAX_LEN, "%s", name); } int mtl_get_numa_id(mtl_handle mt, enum mtl_port port) { - struct mtl_main_impl* impl = mt; + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1348,6 +1391,6 @@ int mtl_get_numa_id(mtl_handle mt, enum mtl_port port) { return -EIO; } - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); return inf->socket_id; } diff --git a/lib/src/mt_main.h b/lib/src/mt_main.h index 5be810e89..ecca72aa7 100644 --- a/lib/src/mt_main.h +++ b/lib/src/mt_main.h @@ -33,8 +33,10 @@ #define MT_TAILQ_FIRST(head) RTE_TAILQ_FIRST(head) #define MT_TAILQ_NEXT(elem, field) RTE_TAILQ_NEXT(elem, field) -#define MT_TAILQ_INSERT_TAIL(head, elem, filed) TAILQ_INSERT_TAIL(head, elem, filed) -#define MT_TAILQ_INSERT_HEAD(head, elem, filed) TAILQ_INSERT_HEAD(head, elem, filed) +#define MT_TAILQ_INSERT_TAIL(head, elem, filed) \ + TAILQ_INSERT_TAIL(head, elem, filed) +#define MT_TAILQ_INSERT_HEAD(head, elem, filed) \ + TAILQ_INSERT_HEAD(head, elem, filed) #define MT_TAILQ_REMOVE(head, elem, filed) TAILQ_REMOVE(head, elem, filed) #define MT_TAILQ_INIT(head) TAILQ_INIT(head) @@ -89,12 +91,12 @@ #define MT_TIMEOUT_INFINITE (INT_MAX) #define MT_TIMEOUT_ZERO (0) -#define MT_SAFE_FREE(obj, free_fn) \ - do { \ - if (obj) { \ - free_fn(obj); \ - obj = NULL; \ - } \ +#define MT_SAFE_FREE(obj, free_fn) \ + do { \ + if (obj) { \ + free_fn(obj); \ + obj = NULL; \ + } \ } while (0) struct mtl_main_impl; /* forward declare */ @@ -196,7 +198,7 @@ struct mt_phc2sys_impl { }; struct mt_ptp_impl { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; enum mtl_port port; uint16_t port_id; bool active; /* if the ptp stack is running */ @@ -213,15 +215,15 @@ struct mt_ptp_impl { int64_t no_timesync_delta; /* for no cni case */ - struct mt_rxq_entry* gen_rxq; /* for MT_PTP_UDP_GEN_PORT */ - struct mt_rxq_entry* event_rxq; /* for MT_PTP_UDP_EVENT_PORT */ - struct mt_sch_tasklet_impl* rxq_tasklet; + struct mt_rxq_entry *gen_rxq; /* for MT_PTP_UDP_GEN_PORT */ + struct mt_rxq_entry *event_rxq; /* for MT_PTP_UDP_EVENT_PORT */ + struct mt_sch_tasklet_impl *rxq_tasklet; struct mt_phc2sys_impl phc2sys; bool phc2sys_active; struct mt_pi_servo servo; /* PI for PTP */ - struct rte_mempool* mbuf_pool; + struct rte_mempool *mbuf_pool; uint8_t mcast_group_addr[MTL_IP_ADDR_LEN]; /* 224.0.1.129 */ bool master_initialized; @@ -244,7 +246,8 @@ struct mt_ptp_impl { uint16_t t3_sequence_id; uint64_t t4; - bool calibrate_t2_t3; /* for no_timesync case which the t2 and t3 get from tsc */ + bool calibrate_t2_t3; /* for no_timesync case which the t2 and t3 get from tsc + */ bool locked; bool connected; @@ -333,8 +336,9 @@ struct mt_rxq_flow { uint64_t bytes_per_sec; /* optional for hdr split */ - void* hdr_split_mbuf_cb_priv; -#ifdef ST_HAS_DPDK_HDR_SPLIT /* rte_eth_hdrs_mbuf_callback_fn define with this marco */ + void *hdr_split_mbuf_cb_priv; +#ifdef ST_HAS_DPDK_HDR_SPLIT /* rte_eth_hdrs_mbuf_callback_fn define with this \ + marco */ rte_eth_hdrs_mbuf_callback_fn hdr_split_mbuf_cb; #endif }; @@ -350,9 +354,9 @@ MT_TAILQ_HEAD(mt_cni_udp_detect_list, mt_cni_udp_detect_entry); struct mt_csq_entry { int idx; - struct mt_cni_entry* parent; + struct mt_cni_entry *parent; struct mt_rxq_flow flow; - struct rte_ring* ring; + struct rte_ring *ring; uint32_t stat_enqueue_cnt; uint32_t stat_dequeue_cnt; uint32_t stat_enqueue_fail_cnt; @@ -363,9 +367,9 @@ struct mt_csq_entry { MT_TAILQ_HEAD(mt_csq_queue, mt_csq_entry); struct mt_cni_entry { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; enum mtl_port port; - struct mt_rxq_entry* rxq; + struct mt_rxq_entry *rxq; struct mt_csq_queue csq_queues; /* for cni udp queue */ int csq_idx; @@ -384,12 +388,12 @@ struct mt_cni_entry { }; struct mt_cni_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; pthread_t tid; /* thread id for rx */ rte_atomic32_t stop_thread; bool lcore_tasklet; - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; int thread_sleep_ms; struct mt_cni_entry entries[MTL_PORT_MAX]; @@ -397,11 +401,11 @@ struct mt_cni_impl { #ifdef MTL_HAS_TAP pthread_t tap_bkg_tid; /* bkg thread id for tap */ rte_atomic32_t stop_tap; - struct mt_txq_entry* tap_tx_q[MTL_PORT_MAX]; /* tap tx queue */ - struct mt_rxq_entry* tap_rx_q[MTL_PORT_MAX]; /* tap rx queue */ + struct mt_txq_entry *tap_tx_q[MTL_PORT_MAX]; /* tap tx queue */ + struct mt_rxq_entry *tap_rx_q[MTL_PORT_MAX]; /* tap rx queue */ int tap_rx_cnt[MTL_PORT_MAX]; rte_atomic32_t tap_if_up[MTL_PORT_MAX]; - void* tap_context; + void *tap_context; #endif }; @@ -416,7 +420,7 @@ struct mt_arp_impl { struct mt_arp_entry entries[MT_ARP_ENTRY_MAX]; bool timer_active; enum mtl_port port; - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; }; struct mt_mcast_src_entry { @@ -446,7 +450,8 @@ struct mt_mcast_impl { enum mt_dhcp_status { MT_DHCP_STATUS_INIT = 0, - MT_DHCP_STATUS_DISCOVERING, /* no selecting as we always choose the first offer */ + MT_DHCP_STATUS_DISCOVERING, /* no selecting as we always choose the first + offer */ MT_DHCP_STATUS_REQUESTING, MT_DHCP_STATUS_BOUND, MT_DHCP_STATUS_RENEWING, @@ -460,7 +465,7 @@ struct mt_dhcp_impl { uint32_t xid; uint8_t server_ip[MTL_IP_ADDR_LEN]; enum mtl_port port; - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; /* cached configuration */ uint8_t ip[MTL_IP_ADDR_LEN]; @@ -472,7 +477,7 @@ struct mt_dhcp_impl { struct mt_sch_tasklet_impl { struct mtl_tasklet_ops ops; char name[ST_MAX_NAME_LEN]; - struct mtl_sch_impl* sch; + struct mtl_sch_impl *sch; int idx; bool request_exit; @@ -499,14 +504,15 @@ typedef uint64_t mt_sch_mask_t; struct mtl_sch_impl { char name[32]; pthread_mutex_t mutex; /* protect sch context */ - struct mt_sch_tasklet_impl** tasklet; + struct mt_sch_tasklet_impl **tasklet; uint32_t nb_tasklets; /* the number of tasklet in current sch */ /* max tasklet index */ volatile int max_tasklet_idx; unsigned int lcore; /* the socket id this sch attached to */ int socket_id; - bool run_in_thread; /* Run the tasklet inside one thread instead of a pinned lcore. */ + bool run_in_thread; /* Run the tasklet inside one thread instead of a pinned + lcore. */ pthread_t tid; /* thread id for run_in_thread */ int t_pid; /* gettid */ @@ -514,7 +520,7 @@ struct mtl_sch_impl { int data_quota_mbs_limit; /* limit data quota(mb/s) for current sch */ bool cpu_busy; - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; /* index for current sch */ rte_atomic32_t started; rte_atomic32_t request_stop; @@ -577,7 +583,7 @@ struct mtl_sch_impl { }; struct mt_lcore_mgr { - struct mt_lcore_shm* lcore_shm; + struct mt_lcore_shm *lcore_shm; int lcore_shm_id; }; @@ -623,7 +629,7 @@ struct mt_rl_shaper { struct mt_rx_flow_rsp { int flow_id; /* flow id for socket based flow */ - struct rte_flow* flow; + struct rte_flow *flow; uint16_t queue_id; uint16_t dst_port; }; @@ -634,11 +640,11 @@ struct mt_rx_queue { uint16_t queue_id; bool active; struct mt_rxq_flow flow; - struct mt_rx_flow_rsp* flow_rsp; - struct rte_mempool* mbuf_pool; + struct mt_rx_flow_rsp *flow_rsp; + struct rte_mempool *mbuf_pool; unsigned int mbuf_elements; /* pool for hdr split payload */ - struct rte_mempool* mbuf_payload_pool; + struct rte_mempool *mbuf_payload_pool; }; struct mt_tx_queue { @@ -652,7 +658,8 @@ struct mt_tx_queue { uint64_t bps; /* bytes per sec for rate limit */ }; -/* use rte_eth_dev_set_mc_addr_list instead of rte_eth_dev_mac_addr_add for multicast */ +/* use rte_eth_dev_set_mc_addr_list instead of rte_eth_dev_mac_addr_add for + * multicast */ #define MT_DRV_F_USE_MC_ADDR_LIST (MTL_BIT64(0)) /* no rte_eth_stats_reset support */ #define MT_DRV_F_NO_STATUS_RESET (MTL_BIT64(1)) @@ -674,7 +681,7 @@ struct mt_tx_queue { #define MT_DRV_F_KERNEL_BASED (MTL_BIT64(9)) struct mt_dev_driver_info { - char* name; + char *name; enum mt_port_type port_type; enum mt_driver_type drv_type; @@ -684,7 +691,7 @@ struct mt_dev_driver_info { }; struct mt_interface { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; uint16_t port_id; struct rte_eth_dev_info dev_info; @@ -694,18 +701,18 @@ struct mt_interface { int socket_id; /* socket id for the port */ uint32_t feature; /* MT_IF_FEATURE_* */ uint32_t link_speed; /* ETH_SPEED_NUM_ */ - struct rte_ether_addr* mcast_mac_lists; /* pool of multicast mac addrs */ + struct rte_ether_addr *mcast_mac_lists; /* pool of multicast mac addrs */ uint32_t mcast_nb; /* number of address */ uint32_t status; /* MT_IF_STAT_* */ /* default tx mbuf_pool */ - struct rte_mempool* tx_mbuf_pool; + struct rte_mempool *tx_mbuf_pool; /* default rx mbuf_pool */ - struct rte_mempool* rx_mbuf_pool; + struct rte_mempool *rx_mbuf_pool; uint16_t nb_tx_desc; uint16_t nb_rx_desc; - struct rte_mbuf* pad; + struct rte_mbuf *pad; /* * protect rl and fdir for vf. * _atomic_set_cmd(): There is incomplete cmd 112 @@ -714,14 +721,14 @@ struct mt_interface { /* tx queue resources */ uint16_t nb_tx_q; - struct mt_tx_queue* tx_queues; + struct mt_tx_queue *tx_queues; pthread_mutex_t tx_queues_mutex; /* protect tx_queues */ /* rx queue resources */ uint16_t nb_rx_q; uint16_t system_rx_queues_end; uint16_t hdr_split_rx_queues_end; - struct mt_rx_queue* rx_queues; + struct mt_rx_queue *rx_queues; pthread_mutex_t rx_queues_mutex; /* protect rx_queues */ /* tx rl info */ @@ -733,7 +740,7 @@ struct mt_interface { struct mt_audio_pacing_train_result audio_pt_results[MT_MAX_RL_ITEMS]; /* function ops per interface(pf/vf) */ - uint64_t (*ptp_get_time_fn)(struct mtl_main_impl* impl, enum mtl_port port); + uint64_t (*ptp_get_time_fn)(struct mtl_main_impl *impl, enum mtl_port port); enum st21_tx_pacing_way tx_pacing_way; @@ -747,8 +754,8 @@ struct mt_interface { uint64_t real_time_base; rte_spinlock_t stats_lock; - struct mtl_port_status* dev_stats_not_reset; /* for nic without reset func */ - struct mtl_port_status* dev_stats_sw; /* for MT_DRV_F_NOT_DPDK_PMD */ + struct mtl_port_status *dev_stats_not_reset; /* for nic without reset func */ + struct mtl_port_status *dev_stats_sw; /* for MT_DRV_F_NOT_DPDK_PMD */ struct mtl_port_status stats_sum; /* for dev_inf_stat dump */ struct mtl_port_status user_stats_port; /* for mtl_get_port_stats */ struct mtl_port_status stats_admin; /* stats used in admin task */ @@ -761,8 +768,8 @@ struct mt_interface { /* the mac for kernel socket based transport */ struct rte_ether_addr k_mac_addr; - void* xdp; - void* rdma; + void *xdp; + void *rdma; }; struct mt_user_info { @@ -787,16 +794,16 @@ struct mt_lcore_shm { struct mt_lcore_shm_entry lcores_info[RTE_MAX_LCORE]; }; -typedef int (*mt_dma_drop_mbuf_cb)(void* priv, struct rte_mbuf* mbuf); +typedef int (*mt_dma_drop_mbuf_cb)(void *priv, struct rte_mbuf *mbuf); struct mtl_dma_lender_dev { enum mt_handle_type type; /* for sanity check */ - struct mt_dma_dev* parent; + struct mt_dma_dev *parent; int lender_id; bool active; - void* priv; + void *priv; uint16_t nb_borrowed; mt_dma_drop_mbuf_cb cb; }; @@ -815,11 +822,11 @@ struct mt_dma_dev { struct mtl_dma_lender_dev lenders[MT_DMA_MAX_SESSIONS]; uint16_t nb_inflight; /* not atomic since it's in single thread only */ #if MT_DMA_RTE_RING - struct rte_ring* borrow_queue; /* borrowed mbufs from rx sessions */ + struct rte_ring *borrow_queue; /* borrowed mbufs from rx sessions */ #else uint16_t inflight_enqueue_idx; uint16_t inflight_dequeue_idx; - struct rte_mbuf** inflight_mbufs; + struct rte_mbuf **inflight_mbufs; #endif uint64_t stat_inflight_sum; uint64_t stat_commit_sum; @@ -833,9 +840,9 @@ struct mt_dma_mgr { }; struct mtl_dma_mem { - void* alloc_addr; /* the address return from malloc */ + void *alloc_addr; /* the address return from malloc */ size_t alloc_size; /* the malloc size */ - void* addr; /* the first page aligned address after alloc_addr */ + void *addr; /* the first page aligned address after alloc_addr */ size_t valid_size; /* the valid data size from user */ mtl_iova_t iova; /* the dma mapped address of addr */ size_t iova_size; /* the iova mapped size */ @@ -857,14 +864,14 @@ struct mt_kport_info { }; struct mt_map_item { - void* vaddr; + void *vaddr; size_t size; mtl_iova_t iova; /* iova address */ }; struct mt_map_mgr { pthread_mutex_t mutex; - struct mt_map_item* items[MT_MAP_MAX_ITEMS]; + struct mt_map_item *items[MT_MAP_MAX_ITEMS]; }; struct mt_var_params { @@ -876,12 +883,12 @@ struct mt_var_params { uint64_t sch_zero_sleep_threshold_us; }; -typedef int (*mt_stat_cb_t)(void* priv); +typedef int (*mt_stat_cb_t)(void *priv); struct mt_stat_item { /* stat dump callback func */ mt_stat_cb_t cb_func; /* stat dump callback private data */ - void* cb_priv; + void *cb_priv; /* name */ char name[ST_MAX_NAME_LEN]; /* linked list */ @@ -891,7 +898,7 @@ struct mt_stat_item { MT_TAILQ_HEAD(mt_stat_items_list, mt_stat_item); struct mt_stat_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; uint64_t dump_period_us; rte_spinlock_t lock; @@ -915,9 +922,9 @@ struct mt_rsq_entry { uint16_t queue_id; int idx; struct mt_rxq_flow flow; - struct mt_rx_flow_rsp* flow_rsp; - struct mt_rsq_impl* parent; - struct rte_ring* ring; + struct mt_rx_flow_rsp *flow_rsp; + struct mt_rsq_impl *parent; + struct rte_ring *ring; /* wa for MTL_PMD_DPDK_AF_PACKET */ int mcast_fd; uint32_t stat_enqueue_cnt; @@ -932,24 +939,24 @@ struct mt_rsq_queue { uint16_t port_id; uint16_t queue_id; /* for native xdp based shared queue */ - struct mt_rx_xdp_entry* xdp; + struct mt_rx_xdp_entry *xdp; /* List of rsq entry */ struct mt_rsq_entrys_list head; rte_spinlock_t mutex; rte_atomic32_t entry_cnt; int entry_idx; - struct mt_rsq_entry* cni_entry; + struct mt_rsq_entry *cni_entry; /* stat */ int stat_pkts_recv; int stat_pkts_deliver; }; struct mt_rsq_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; /* sq rx queue resources */ uint16_t nb_rsq_queues; - struct mt_rsq_queue* rsq_queues; + struct mt_rsq_queue *rsq_queues; enum mt_queue_mode queue_mode; }; @@ -972,8 +979,8 @@ struct mt_txq_flow { uint16_t gso_sz; /* only for rdma ud */ - void** mrs_bufs; - size_t* mrs_sizes; + void **mrs_bufs; + size_t *mrs_sizes; int num_mrs; }; @@ -982,8 +989,8 @@ struct mt_tsq_impl; /* forward delcare */ struct mt_tsq_entry { uint16_t queue_id; struct mt_txq_flow flow; - struct mt_tsq_impl* parent; - struct rte_mempool* tx_pool; + struct mt_tsq_impl *parent; + struct rte_mempool *tx_pool; /* linked list */ MT_TAILQ_ENTRY(mt_tsq_entry) next; }; @@ -993,9 +1000,9 @@ struct mt_tsq_queue { uint16_t port_id; uint16_t queue_id; /* shared tx mempool */ - struct rte_mempool* tx_pool; + struct rte_mempool *tx_pool; /* for native xdp based shared queue */ - struct mt_tx_xdp_entry* xdp; + struct mt_tx_xdp_entry *xdp; /* List of rsq entry */ struct mt_tsq_entrys_list head; @@ -1008,19 +1015,19 @@ struct mt_tsq_queue { }; struct mt_tsq_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; /* sq tx queue resources */ uint16_t nb_tsq_queues; - struct mt_tsq_queue* tsq_queues; + struct mt_tsq_queue *tsq_queues; enum mt_queue_mode queue_mode; }; struct mt_srss_entry { struct mt_rxq_flow flow; - struct mt_srss_impl* srss; + struct mt_srss_impl *srss; int idx; - struct rte_ring* ring; + struct rte_ring *ring; uint32_t stat_enqueue_cnt; uint32_t stat_dequeue_cnt; uint32_t stat_enqueue_fail_cnt; @@ -1036,46 +1043,46 @@ struct mt_srss_list { }; struct mt_srss_sch { - struct mt_srss_impl* parent; + struct mt_srss_impl *parent; int idx; uint16_t q_start; uint16_t q_end; - struct mtl_sch_impl* sch; - struct mt_sch_tasklet_impl* tasklet; + struct mtl_sch_impl *sch; + struct mt_sch_tasklet_impl *tasklet; int quota_mps; uint32_t stat_pkts_rx; }; struct mt_srss_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; enum mt_queue_mode queue_mode; uint16_t nb_rx_q; /* map entry to different heads as the UDP port number */ - struct mt_srss_list* lists; + struct mt_srss_list *lists; int lists_sz; /* sch threads */ - struct mt_srss_sch* schs; + struct mt_srss_sch *schs; int schs_cnt; pthread_t tid; rte_atomic32_t stop_thread; - struct mt_srss_entry* cni_entry; + struct mt_srss_entry *cni_entry; int entry_idx; /* for native xdp based srss */ - struct mt_rx_xdp_entry** xdps; + struct mt_rx_xdp_entry **xdps; }; #define MT_DP_SOCKET_THREADS_MAX (4) struct mt_tx_socket_thread { - struct mt_tx_socket_entry* parent; + struct mt_tx_socket_entry *parent; int idx; int fd; pthread_t tid; @@ -1093,22 +1100,22 @@ struct mt_tx_socket_thread { }; struct mt_tx_socket_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; struct mt_txq_flow flow; uint64_t rate_limit_per_thread; uint16_t gso_sz; int threads; - struct rte_ring* ring; + struct rte_ring *ring; struct mt_tx_socket_thread threads_data[MT_DP_SOCKET_THREADS_MAX]; bool stat_registered; }; struct mt_rx_socket_thread { - struct mt_rx_socket_entry* parent; + struct mt_rx_socket_entry *parent; int idx; - struct rte_mbuf* mbuf; + struct rte_mbuf *mbuf; pthread_t tid; rte_atomic32_t stop_thread; @@ -1117,55 +1124,55 @@ struct mt_rx_socket_thread { }; struct mt_rx_socket_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; struct mt_rxq_flow flow; - struct rte_mempool* pool; + struct rte_mempool *pool; uint16_t pool_element_sz; int fd; uint64_t rate_limit_per_thread; int threads; - struct rte_ring* ring; + struct rte_ring *ring; struct mt_rx_socket_thread threads_data[MT_DP_SOCKET_THREADS_MAX]; bool stat_registered; }; struct mt_tx_xdp_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; struct mt_txq_flow flow; uint16_t queue_id; - struct mt_xdp_queue* xq; + struct mt_xdp_queue *xq; }; struct mt_rx_xdp_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; struct mt_rxq_flow flow; uint16_t queue_id; - struct mt_xdp_queue* xq; - struct mt_rx_flow_rsp* flow_rsp; + struct mt_xdp_queue *xq; + struct mt_rx_flow_rsp *flow_rsp; bool skip_udp_port_check; bool skip_all_check; int mcast_fd; }; struct mt_tx_rdma_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; struct mt_txq_flow flow; uint16_t queue_id; - struct mt_rdma_tx_queue* txq; + struct mt_rdma_tx_queue *txq; }; struct mt_rx_rdma_entry { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; struct mt_rxq_flow flow; uint16_t queue_id; - struct mt_rdma_rx_queue* rxq; + struct mt_rdma_rx_queue *rxq; }; struct mt_flow_impl { @@ -1174,7 +1181,7 @@ struct mt_flow_impl { struct mt_dp_impl { /* the shared tx sys queue */ - struct mt_txq_entry* txq_sys_entry; + struct mt_txq_entry *txq_sys_entry; rte_spinlock_t txq_sys_entry_lock; /* protect txq_sys_entry */ }; @@ -1192,15 +1199,15 @@ struct mtl_main_impl { size_t page_size; /* flow */ - struct mt_flow_impl* flow[MTL_PORT_MAX]; + struct mt_flow_impl *flow[MTL_PORT_MAX]; /* data path queue mgr */ - struct mt_dp_impl* dp[MTL_PORT_MAX]; + struct mt_dp_impl *dp[MTL_PORT_MAX]; /* rss */ - struct mt_rss_impl* rss[MTL_PORT_MAX]; - struct mt_srss_impl* srss[MTL_PORT_MAX]; + struct mt_rss_impl *rss[MTL_PORT_MAX]; + struct mt_srss_impl *srss[MTL_PORT_MAX]; /* shared rx queue mgr */ - struct mt_rsq_impl* rsq[MTL_PORT_MAX]; - struct mt_tsq_impl* tsq[MTL_PORT_MAX]; + struct mt_rsq_impl *rsq[MTL_PORT_MAX]; + struct mt_tsq_impl *tsq[MTL_PORT_MAX]; /* stat */ struct mt_stat_mgr stat_mgr; @@ -1210,7 +1217,7 @@ struct mtl_main_impl { rte_atomic32_t instance_in_reset; /* if mt instance is in reset */ /* if mt instance is aborted, in case for ctrl-c from app */ rte_atomic32_t instance_aborted; - struct mtl_sch_impl* main_sch; /* system sch */ + struct mtl_sch_impl *main_sch; /* system sch */ /* admin context */ struct mt_admin admin; @@ -1219,15 +1226,15 @@ struct mtl_main_impl { struct mt_cni_impl cni; /* ptp context */ - struct mt_ptp_impl* ptp[MTL_PORT_MAX]; + struct mt_ptp_impl *ptp[MTL_PORT_MAX]; uint64_t ptp_usync; uint64_t ptp_usync_tsc; /* arp context */ - struct mt_arp_impl* arp[MTL_PORT_MAX]; + struct mt_arp_impl *arp[MTL_PORT_MAX]; /* mcast context */ - struct mt_mcast_impl* mcast[MTL_PORT_MAX]; + struct mt_mcast_impl *mcast[MTL_PORT_MAX]; /* dhcp context */ - struct mt_dhcp_impl* dhcp[MTL_PORT_MAX]; + struct mt_dhcp_impl *dhcp[MTL_PORT_MAX]; /* sch context */ struct mt_sch_mgr sch_mgr; @@ -1241,7 +1248,7 @@ struct mtl_main_impl { struct mt_user_info u_info; - void* mudp_rxq_mgr[MTL_PORT_MAX]; + void *mudp_rxq_mgr[MTL_PORT_MAX]; /* cnt for open sessions */ rte_atomic32_t st20_tx_sessions_cnt; @@ -1273,56 +1280,61 @@ struct mtl_main_impl { int instance_fd; }; -static inline struct mtl_init_params* mt_get_user_params(struct mtl_main_impl* impl) { +static inline struct mtl_init_params * +mt_get_user_params(struct mtl_main_impl *impl) { return &impl->user_para; } -static inline bool mt_is_privileged(struct mtl_main_impl* impl) { +static inline bool mt_is_privileged(struct mtl_main_impl *impl) { return impl->privileged; } -static inline bool mt_is_manager_connected(struct mtl_main_impl* impl) { +static inline bool mt_is_manager_connected(struct mtl_main_impl *impl) { return impl->instance_fd > 0; } -static inline struct mt_interface* mt_if(struct mtl_main_impl* impl, enum mtl_port port) { +static inline struct mt_interface *mt_if(struct mtl_main_impl *impl, + enum mtl_port port) { return &impl->inf[port]; } -static inline uint16_t mt_port_id(struct mtl_main_impl* impl, enum mtl_port port) { +static inline uint16_t mt_port_id(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_if(impl, port)->port_id; } -static inline struct rte_device* mt_port_device(struct mtl_main_impl* impl, +static inline struct rte_device *mt_port_device(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->dev_info.device; } -static inline enum mt_port_type mt_port_type(struct mtl_main_impl* impl, +static inline enum mt_port_type mt_port_type(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->drv_info.port_type; } -enum mtl_port mt_port_by_id(struct mtl_main_impl* impl, uint16_t port_id); -uint8_t* mt_sip_addr(struct mtl_main_impl* impl, enum mtl_port port); -uint8_t* mt_sip_netmask(struct mtl_main_impl* impl, enum mtl_port port); -uint8_t* mt_sip_gateway(struct mtl_main_impl* impl, enum mtl_port port); -int mt_dst_ip_mac(struct mtl_main_impl* impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr* ea, enum mtl_port port, int timeout_ms); +enum mtl_port mt_port_by_id(struct mtl_main_impl *impl, uint16_t port_id); +uint8_t *mt_sip_addr(struct mtl_main_impl *impl, enum mtl_port port); +uint8_t *mt_sip_netmask(struct mtl_main_impl *impl, enum mtl_port port); +uint8_t *mt_sip_gateway(struct mtl_main_impl *impl, enum mtl_port port); +int mt_dst_ip_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], + struct rte_ether_addr *ea, enum mtl_port port, + int timeout_ms); -static inline enum mtl_pmd_type mt_pmd_type(struct mtl_main_impl* impl, +static inline enum mtl_pmd_type mt_pmd_type(struct mtl_main_impl *impl, enum mtl_port port) { return mt_get_user_params(impl)->pmd[port]; } -static inline bool mt_pmd_is_dpdk_user(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_pmd_is_dpdk_user(struct mtl_main_impl *impl, + enum mtl_port port) { if (MTL_PMD_DPDK_USER == mt_get_user_params(impl)->pmd[port]) return true; else return false; } -static inline bool mt_pmd_is_kernel_based(struct mtl_main_impl* impl, +static inline bool mt_pmd_is_kernel_based(struct mtl_main_impl *impl, enum mtl_port port) { if (MTL_PMD_DPDK_USER == mt_get_user_params(impl)->pmd[port]) return false; @@ -1330,61 +1342,68 @@ static inline bool mt_pmd_is_kernel_based(struct mtl_main_impl* impl, return true; } -static inline bool mt_drv_use_kernel_ctl(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_drv_use_kernel_ctl(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_USE_KERNEL_CTL) return true; else return false; } -static inline bool mt_drv_dpdk_based(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_drv_dpdk_based(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD) return false; else return true; } -static inline bool mt_drv_mcast_in_dp(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_drv_mcast_in_dp(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_MCAST_IN_DP) return true; else return false; } -static inline const char* mt_kernel_if_name(struct mtl_main_impl* impl, +static inline const char *mt_kernel_if_name(struct mtl_main_impl *impl, enum mtl_port port) { return impl->kport_info.kernel_if[port]; } -static inline bool mt_drv_no_cni(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_drv_no_cni(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_NO_CNI) return true; else return false; } -static inline bool mt_drv_no_sys_txq(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_drv_no_sys_txq(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_NO_SYS_TX_QUEUE) return true; else return false; } -static inline bool mt_drv_kernel_based(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_drv_kernel_based(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_KERNEL_BASED) return true; else return false; } -static inline bool mt_pmd_is_dpdk_af_xdp(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_pmd_is_dpdk_af_xdp(struct mtl_main_impl *impl, + enum mtl_port port) { if (MTL_PMD_DPDK_AF_XDP == mt_get_user_params(impl)->pmd[port]) return true; else return false; } -static inline bool mt_pmd_is_dpdk_af_packet(struct mtl_main_impl* impl, +static inline bool mt_pmd_is_dpdk_af_packet(struct mtl_main_impl *impl, enum mtl_port port) { if (MTL_PMD_DPDK_AF_PACKET == mt_get_user_params(impl)->pmd[port]) return true; @@ -1392,7 +1411,7 @@ static inline bool mt_pmd_is_dpdk_af_packet(struct mtl_main_impl* impl, return false; } -static inline bool mt_pmd_is_kernel_socket(struct mtl_main_impl* impl, +static inline bool mt_pmd_is_kernel_socket(struct mtl_main_impl *impl, enum mtl_port port) { if (MTL_PMD_KERNEL_SOCKET == mt_get_user_params(impl)->pmd[port]) return true; @@ -1400,7 +1419,7 @@ static inline bool mt_pmd_is_kernel_socket(struct mtl_main_impl* impl, return false; } -static inline bool mt_pmd_is_native_af_xdp(struct mtl_main_impl* impl, +static inline bool mt_pmd_is_native_af_xdp(struct mtl_main_impl *impl, enum mtl_port port) { if (MTL_PMD_NATIVE_AF_XDP == mt_get_user_params(impl)->pmd[port]) return true; @@ -1408,21 +1427,22 @@ static inline bool mt_pmd_is_native_af_xdp(struct mtl_main_impl* impl, return false; } -static inline bool mt_pmd_is_rdma_ud(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_pmd_is_rdma_ud(struct mtl_main_impl *impl, + enum mtl_port port) { if (MTL_PMD_RDMA_UD == mt_get_user_params(impl)->pmd[port]) return true; else return false; } -static inline int mt_num_ports(struct mtl_main_impl* impl) { +static inline int mt_num_ports(struct mtl_main_impl *impl) { return RTE_MIN(mt_get_user_params(impl)->num_ports, MTL_PORT_MAX); } -bool mt_is_valid_socket(struct mtl_main_impl* impl, int soc_id); +bool mt_is_valid_socket(struct mtl_main_impl *impl, int soc_id); /* if user enable the phc2sys service */ -static inline bool mt_user_phc2sys_service(struct mtl_main_impl* impl) { +static inline bool mt_user_phc2sys_service(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_PHC2SYS_ENABLE) return true; else @@ -1430,7 +1450,7 @@ static inline bool mt_user_phc2sys_service(struct mtl_main_impl* impl) { } /* if user enable the ptp service */ -static inline bool mt_user_ptp_service(struct mtl_main_impl* impl) { +static inline bool mt_user_ptp_service(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_PTP_ENABLE) return true; else @@ -1438,7 +1458,7 @@ static inline bool mt_user_ptp_service(struct mtl_main_impl* impl) { } /* if user enable the not numa bind for lcore thread */ -static inline bool mt_user_not_bind_numa(struct mtl_main_impl* impl) { +static inline bool mt_user_not_bind_numa(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_NOT_BIND_NUMA) return true; else @@ -1446,7 +1466,7 @@ static inline bool mt_user_not_bind_numa(struct mtl_main_impl* impl) { } /* if user enable the auto start/stop */ -static inline bool mt_user_auto_start_stop(struct mtl_main_impl* impl) { +static inline bool mt_user_auto_start_stop(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_DEV_AUTO_START_STOP) return true; else @@ -1454,7 +1474,7 @@ static inline bool mt_user_auto_start_stop(struct mtl_main_impl* impl) { } /* if user enable the auto start/stop */ -static inline bool mt_user_across_numa_core(struct mtl_main_impl* impl) { +static inline bool mt_user_across_numa_core(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_ALLOW_ACROSS_NUMA_CORE) return true; else @@ -1462,7 +1482,7 @@ static inline bool mt_user_across_numa_core(struct mtl_main_impl* impl) { } /* if user enable the MTL_FLAG_NO_MULTICAST */ -static inline bool mt_user_no_multicast(struct mtl_main_impl* impl) { +static inline bool mt_user_no_multicast(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_NO_MULTICAST) return true; else @@ -1470,7 +1490,7 @@ static inline bool mt_user_no_multicast(struct mtl_main_impl* impl) { } /* if user disable the af xdp zc */ -static inline bool mt_user_af_xdp_zc(struct mtl_main_impl* impl) { +static inline bool mt_user_af_xdp_zc(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_AF_XDP_ZC_DISABLE) return false; else @@ -1478,7 +1498,7 @@ static inline bool mt_user_af_xdp_zc(struct mtl_main_impl* impl) { } /* if user enable the ptp time source func */ -static inline bool mt_user_ptp_time_fn(struct mtl_main_impl* impl) { +static inline bool mt_user_ptp_time_fn(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->ptp_get_time_fn) return true; else @@ -1486,7 +1506,7 @@ static inline bool mt_user_ptp_time_fn(struct mtl_main_impl* impl) { } /* if user has customized sch quota */ -static inline bool mt_user_quota_active(struct mtl_main_impl* impl) { +static inline bool mt_user_quota_active(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->data_quota_mbs_per_sch) return true; else @@ -1494,7 +1514,7 @@ static inline bool mt_user_quota_active(struct mtl_main_impl* impl) { } /* if user enable hw offload timestamp */ -static inline bool mt_user_hw_timestamp(struct mtl_main_impl* impl) { +static inline bool mt_user_hw_timestamp(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_ENABLE_HW_TIMESTAMP) return true; else @@ -1502,7 +1522,7 @@ static inline bool mt_user_hw_timestamp(struct mtl_main_impl* impl) { } /* if user enable separate sch for rx video session */ -static inline bool mt_user_rxv_separate_sch(struct mtl_main_impl* impl) { +static inline bool mt_user_rxv_separate_sch(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_RX_SEPARATE_VIDEO_LCORE) return true; else @@ -1510,7 +1530,7 @@ static inline bool mt_user_rxv_separate_sch(struct mtl_main_impl* impl) { } /* if user enable dedicated lcore for system tasks(CNI, PTP, etc...) */ -static inline bool mt_user_dedicated_sys_lcore(struct mtl_main_impl* impl) { +static inline bool mt_user_dedicated_sys_lcore(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_DEDICATED_SYS_LCORE) return true; else @@ -1518,7 +1538,7 @@ static inline bool mt_user_dedicated_sys_lcore(struct mtl_main_impl* impl) { } /* if user enable tx video migrate feature */ -static inline bool mt_user_tx_video_migrate(struct mtl_main_impl* impl) { +static inline bool mt_user_tx_video_migrate(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_TX_VIDEO_MIGRATE) return true; else @@ -1526,7 +1546,7 @@ static inline bool mt_user_tx_video_migrate(struct mtl_main_impl* impl) { } /* if user enable rx video migrate feature */ -static inline bool mt_user_rx_video_migrate(struct mtl_main_impl* impl) { +static inline bool mt_user_rx_video_migrate(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_RX_VIDEO_MIGRATE) return true; else @@ -1534,17 +1554,17 @@ static inline bool mt_user_rx_video_migrate(struct mtl_main_impl* impl) { } /* if user enable tasklet time measure */ -static inline bool mt_user_tasklet_time_measure(struct mtl_main_impl* impl) { +static inline bool mt_user_tasklet_time_measure(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_TASKLET_TIME_MEASURE) return true; else return false; } -bool mt_sessions_time_measure(struct mtl_main_impl* impl); +bool mt_sessions_time_measure(struct mtl_main_impl *impl); /* if user enable rx mono pool */ -static inline bool mt_user_rx_mono_pool(struct mtl_main_impl* impl) { +static inline bool mt_user_rx_mono_pool(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_RX_MONO_POOL) return true; else @@ -1552,7 +1572,7 @@ static inline bool mt_user_rx_mono_pool(struct mtl_main_impl* impl) { } /* if user enable tx mono pool */ -static inline bool mt_user_tx_mono_pool(struct mtl_main_impl* impl) { +static inline bool mt_user_tx_mono_pool(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_TX_MONO_POOL) return true; else @@ -1560,28 +1580,31 @@ static inline bool mt_user_tx_mono_pool(struct mtl_main_impl* impl) { } /* if user force tx to no chain mode */ -static inline bool mt_user_tx_no_chain(struct mtl_main_impl* impl) { +static inline bool mt_user_tx_no_chain(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_TX_NO_CHAIN) return true; else return false; } -static inline bool mt_has_cni(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_has_cni(struct mtl_main_impl *impl, enum mtl_port port) { if (impl->cni.entries[port].rxq) return true; else return false; } -static inline bool mt_has_cni_rx(struct mtl_main_impl* impl, enum mtl_port port) { - if ((mt_get_user_params(impl)->flags & MTL_FLAG_RX_USE_CNI) && mt_has_cni(impl, port)) +static inline bool mt_has_cni_rx(struct mtl_main_impl *impl, + enum mtl_port port) { + if ((mt_get_user_params(impl)->flags & MTL_FLAG_RX_USE_CNI) && + mt_has_cni(impl, port)) return true; else return false; } -static inline bool mt_has_virtio_user(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_has_virtio_user(struct mtl_main_impl *impl, + enum mtl_port port) { if ((mt_get_user_params(impl)->flags & MTL_FLAG_VIRTIO_USER) && mt_pmd_is_dpdk_user(impl, port)) return true; @@ -1589,7 +1612,7 @@ static inline bool mt_has_virtio_user(struct mtl_main_impl* impl, enum mtl_port return false; } -static inline bool mt_dhcp_service_active(struct mtl_main_impl* impl, +static inline bool mt_dhcp_service_active(struct mtl_main_impl *impl, enum mtl_port port) { if ((mt_if(impl, port)->net_proto == MTL_PROTO_DHCP) && impl->dhcp[port]) return true; @@ -1597,17 +1620,18 @@ static inline bool mt_dhcp_service_active(struct mtl_main_impl* impl, return false; } -static inline enum mtl_rss_mode mt_if_rss_mode(struct mtl_main_impl* impl, +static inline enum mtl_rss_mode mt_if_rss_mode(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->rss_mode; } -static inline bool mt_has_srss(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_has_srss(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if_rss_mode(impl, port) != MTL_RSS_MODE_NONE; } /* if user enable udp lcore mode */ -static inline bool mt_user_udp_lcore(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_user_udp_lcore(struct mtl_main_impl *impl, + enum mtl_port port) { MTL_MAY_UNUSED(port); if (mt_get_user_params(impl)->flags & MTL_FLAG_UDP_LCORE) return true; @@ -1616,7 +1640,7 @@ static inline bool mt_user_udp_lcore(struct mtl_main_impl* impl, enum mtl_port p } /* if user enable random src port */ -static inline bool mt_user_random_src_port(struct mtl_main_impl* impl) { +static inline bool mt_user_random_src_port(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_RANDOM_SRC_PORT) return true; else @@ -1624,7 +1648,7 @@ static inline bool mt_user_random_src_port(struct mtl_main_impl* impl) { } /* if user enable multi src port */ -static inline bool mt_user_multi_src_port(struct mtl_main_impl* impl) { +static inline bool mt_user_multi_src_port(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_MULTI_SRC_PORT) return true; else @@ -1632,7 +1656,8 @@ static inline bool mt_user_multi_src_port(struct mtl_main_impl* impl) { } /* if user enable shared tx queue */ -static inline bool mt_user_shared_txq(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_user_shared_txq(struct mtl_main_impl *impl, + enum mtl_port port) { MTL_MAY_UNUSED(port); if (mt_get_user_params(impl)->flags & MTL_FLAG_SHARED_TX_QUEUE) return true; @@ -1641,7 +1666,8 @@ static inline bool mt_user_shared_txq(struct mtl_main_impl* impl, enum mtl_port } /* if user enable shared rx queue */ -static inline bool mt_user_shared_rxq(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_user_shared_rxq(struct mtl_main_impl *impl, + enum mtl_port port) { MTL_MAY_UNUSED(port); if (mt_get_user_params(impl)->flags & MTL_FLAG_SHARED_RX_QUEUE) return true; @@ -1650,7 +1676,7 @@ static inline bool mt_user_shared_rxq(struct mtl_main_impl* impl, enum mtl_port } /* if user disable system rx queue */ -static inline bool mt_user_no_system_rxq(struct mtl_main_impl* impl) { +static inline bool mt_user_no_system_rxq(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_DISABLE_SYSTEM_RX_QUEUES) return true; else @@ -1658,7 +1684,7 @@ static inline bool mt_user_no_system_rxq(struct mtl_main_impl* impl) { } /* if user enable ptp tsc source */ -static inline bool mt_user_ptp_tsc_source(struct mtl_main_impl* impl) { +static inline bool mt_user_ptp_tsc_source(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_PTP_SOURCE_TSC) return true; else @@ -1666,7 +1692,7 @@ static inline bool mt_user_ptp_tsc_source(struct mtl_main_impl* impl) { } /* if user enable tasklet thread */ -static inline bool mt_user_tasklet_thread(struct mtl_main_impl* impl) { +static inline bool mt_user_tasklet_thread(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_TASKLET_THREAD) return true; else @@ -1674,21 +1700,22 @@ static inline bool mt_user_tasklet_thread(struct mtl_main_impl* impl) { } /* if user enable tasklet sleep */ -static inline bool mt_user_tasklet_sleep(struct mtl_main_impl* impl) { +static inline bool mt_user_tasklet_sleep(struct mtl_main_impl *impl) { if (mt_get_user_params(impl)->flags & MTL_FLAG_TASKLET_SLEEP) return true; else return false; } -static inline bool mt_if_has_timesync(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_if_has_timesync(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_TIMESYNC) return true; else return false; } -static inline bool mt_if_has_offload_timestamp(struct mtl_main_impl* impl, +static inline bool mt_if_has_offload_timestamp(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_RX_OFFLOAD_TIMESTAMP) return true; @@ -1696,7 +1723,7 @@ static inline bool mt_if_has_offload_timestamp(struct mtl_main_impl* impl, return false; } -static inline bool mt_if_has_offload_ipv4_cksum(struct mtl_main_impl* impl, +static inline bool mt_if_has_offload_ipv4_cksum(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_TX_OFFLOAD_IPV4_CKSUM) return true; @@ -1704,39 +1731,45 @@ static inline bool mt_if_has_offload_ipv4_cksum(struct mtl_main_impl* impl, return false; } -static inline bool mt_if_has_multi_seg(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_if_has_multi_seg(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_TX_MULTI_SEGS) return true; else return false; } -static inline bool mt_if_has_hdr_split(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_if_has_hdr_split(struct mtl_main_impl *impl, + enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_RXQ_OFFLOAD_BUFFER_SPLIT) return true; else return false; } -static inline struct rte_mempool* mt_if_hdr_split_pool(struct mt_interface* inf, +static inline struct rte_mempool *mt_if_hdr_split_pool(struct mt_interface *inf, uint16_t q) { return inf->rx_queues[q].mbuf_payload_pool; } -static inline uint16_t mt_if_nb_tx_desc(struct mtl_main_impl* impl, enum mtl_port port) { +static inline uint16_t mt_if_nb_tx_desc(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_if(impl, port)->nb_tx_desc; } -static inline uint16_t mt_if_nb_rx_desc(struct mtl_main_impl* impl, enum mtl_port port) { +static inline uint16_t mt_if_nb_rx_desc(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_if(impl, port)->nb_rx_desc; } -static inline uint16_t mt_if_nb_tx_burst(struct mtl_main_impl* impl, enum mtl_port port) { +static inline uint16_t mt_if_nb_tx_burst(struct mtl_main_impl *impl, + enum mtl_port port) { uint16_t burst_pkts; if (mt_pmd_is_dpdk_af_xdp(impl, port)) { /* same umem for both tx and rx */ - burst_pkts = RTE_MAX(mt_if_nb_rx_desc(impl, port), mt_if_nb_tx_desc(impl, port)); + burst_pkts = + RTE_MAX(mt_if_nb_rx_desc(impl, port), mt_if_nb_tx_desc(impl, port)); } else { burst_pkts = mt_if_nb_tx_desc(impl, port); } @@ -1744,63 +1777,63 @@ static inline uint16_t mt_if_nb_tx_burst(struct mtl_main_impl* impl, enum mtl_po return burst_pkts; } -static inline int mt_socket_id(struct mtl_main_impl* impl, enum mtl_port port) { +static inline int mt_socket_id(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->socket_id; } -static inline bool mt_started(struct mtl_main_impl* impl) { +static inline bool mt_started(struct mtl_main_impl *impl) { if (rte_atomic32_read(&impl->instance_started)) return true; else return false; } -static inline bool mt_in_reset(struct mtl_main_impl* impl) { +static inline bool mt_in_reset(struct mtl_main_impl *impl) { if (rte_atomic32_read(&impl->instance_in_reset)) return true; else return false; } -static inline bool mt_aborted(struct mtl_main_impl* impl) { +static inline bool mt_aborted(struct mtl_main_impl *impl) { if (rte_atomic32_read(&impl->instance_aborted)) return true; else return false; } -static inline uint32_t mt_sch_schedule_ns(struct mtl_main_impl* impl) { +static inline uint32_t mt_sch_schedule_ns(struct mtl_main_impl *impl) { return impl->sch_schedule_ns; } -static inline struct rte_mempool* mt_sys_tx_mempool(struct mtl_main_impl* impl, +static inline struct rte_mempool *mt_sys_tx_mempool(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->tx_mbuf_pool; } -static inline struct rte_mempool* mt_sys_rx_mempool(struct mtl_main_impl* impl, +static inline struct rte_mempool *mt_sys_rx_mempool(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->rx_mbuf_pool; } -static inline struct rte_mbuf* mt_get_pad(struct mtl_main_impl* impl, +static inline struct rte_mbuf *mt_get_pad(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->pad; } -static inline struct mt_dma_mgr* mt_get_dma_mgr(struct mtl_main_impl* impl) { +static inline struct mt_dma_mgr *mt_get_dma_mgr(struct mtl_main_impl *impl) { return &impl->dma_mgr; } -static inline uint64_t mt_sch_default_sleep_us(struct mtl_main_impl* impl) { +static inline uint64_t mt_sch_default_sleep_us(struct mtl_main_impl *impl) { return impl->var_para.sch_default_sleep_us; } -static inline uint64_t mt_sch_force_sleep_us(struct mtl_main_impl* impl) { +static inline uint64_t mt_sch_force_sleep_us(struct mtl_main_impl *impl) { return impl->var_para.sch_force_sleep_us; } -static inline uint64_t mt_sch_zero_sleep_thresh_us(struct mtl_main_impl* impl) { +static inline uint64_t mt_sch_zero_sleep_thresh_us(struct mtl_main_impl *impl) { return impl->var_para.sch_zero_sleep_threshold_us; } @@ -1816,14 +1849,14 @@ static inline void mt_delay_us(unsigned int us) { return rte_delay_us_block(us); } -static inline void mt_free_mbufs(struct rte_mbuf** pkts, int num) { +static inline void mt_free_mbufs(struct rte_mbuf **pkts, int num) { for (int i = 0; i < num; i++) { rte_pktmbuf_free(pkts[i]); pkts[i] = NULL; } } -static inline void mt_mbuf_init_ipv4(struct rte_mbuf* pkt) { +static inline void mt_mbuf_init_ipv4(struct rte_mbuf *pkt) { pkt->l2_len = sizeof(struct rte_ether_hdr); /* 14 */ pkt->l3_len = sizeof(struct rte_ipv4_hdr); /* 20 */ #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0) @@ -1833,16 +1866,16 @@ static inline void mt_mbuf_init_ipv4(struct rte_mbuf* pkt) { #endif } -static inline uint64_t mt_timespec_to_ns(const struct timespec* ts) { +static inline uint64_t mt_timespec_to_ns(const struct timespec *ts) { return ((uint64_t)ts->tv_sec * NS_PER_S) + ts->tv_nsec; } -static inline void mt_ns_to_timespec(uint64_t ns, struct timespec* ts) { +static inline void mt_ns_to_timespec(uint64_t ns, struct timespec *ts) { ts->tv_sec = ns / NS_PER_S; ts->tv_nsec = ns % NS_PER_S; } -static inline int mt_wait_tsc_stable(struct mtl_main_impl* impl) { +static inline int mt_wait_tsc_stable(struct mtl_main_impl *impl) { if (impl->tsc_cal_tid) { pthread_join(impl->tsc_cal_tid, NULL); impl->tsc_cal_tid = 0; @@ -1852,7 +1885,7 @@ static inline int mt_wait_tsc_stable(struct mtl_main_impl* impl) { } /* Return relative TSC time in nanoseconds */ -static inline uint64_t mt_get_tsc(struct mtl_main_impl* impl) { +static inline uint64_t mt_get_tsc(struct mtl_main_impl *impl) { double tsc = rte_get_tsc_cycles(); double tsc_hz = impl->tsc_hz; double time_nano = tsc / (tsc_hz / ((double)NS_PER_S)); @@ -1860,7 +1893,8 @@ static inline uint64_t mt_get_tsc(struct mtl_main_impl* impl) { } /* busy loop until target time reach */ -static inline void mt_tsc_delay_to(struct mtl_main_impl* impl, uint64_t target) { +static inline void mt_tsc_delay_to(struct mtl_main_impl *impl, + uint64_t target) { while (mt_get_tsc(impl) < target) { } } @@ -1880,125 +1914,136 @@ static inline uint64_t mt_get_real_time(void) { return mt_timespec_to_ns(&ts); } -static inline void st_tx_mbuf_set_tsc(struct rte_mbuf* mbuf, uint64_t time_stamp) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void st_tx_mbuf_set_tsc(struct rte_mbuf *mbuf, + uint64_t time_stamp) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->tx_priv.tsc_time_stamp = time_stamp; } -static inline uint64_t st_tx_mbuf_get_tsc(struct rte_mbuf* mbuf) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline uint64_t st_tx_mbuf_get_tsc(struct rte_mbuf *mbuf) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); return priv->tx_priv.tsc_time_stamp; } -static inline void st_tx_mbuf_set_ptp(struct rte_mbuf* mbuf, uint64_t time_stamp) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void st_tx_mbuf_set_ptp(struct rte_mbuf *mbuf, + uint64_t time_stamp) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->tx_priv.ptp_time_stamp = time_stamp; } -static inline uint64_t st_tx_mbuf_get_ptp(struct rte_mbuf* mbuf) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline uint64_t st_tx_mbuf_get_ptp(struct rte_mbuf *mbuf) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); return priv->tx_priv.ptp_time_stamp; } -static inline void st_tx_mbuf_set_idx(struct rte_mbuf* mbuf, uint32_t idx) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void st_tx_mbuf_set_idx(struct rte_mbuf *mbuf, uint32_t idx) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->tx_priv.idx = idx; } -static inline uint32_t st_tx_mbuf_get_idx(struct rte_mbuf* mbuf) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline uint32_t st_tx_mbuf_get_idx(struct rte_mbuf *mbuf) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); return priv->tx_priv.idx; } -static inline void st_tx_mbuf_set_priv(struct rte_mbuf* mbuf, void* p) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void st_tx_mbuf_set_priv(struct rte_mbuf *mbuf, void *p) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->tx_priv.priv = p; } -static inline void* st_tx_mbuf_get_priv(struct rte_mbuf* mbuf) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void *st_tx_mbuf_get_priv(struct rte_mbuf *mbuf) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); return priv->tx_priv.priv; } -static inline void st_rx_mbuf_set_lender(struct rte_mbuf* mbuf, uint32_t lender) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void st_rx_mbuf_set_lender(struct rte_mbuf *mbuf, + uint32_t lender) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->rx_priv.lender = lender; } -static inline uint32_t st_rx_mbuf_get_lender(struct rte_mbuf* mbuf) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline uint32_t st_rx_mbuf_get_lender(struct rte_mbuf *mbuf) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); return priv->rx_priv.lender; } -static inline void st_rx_mbuf_set_offset(struct rte_mbuf* mbuf, uint32_t offset) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void st_rx_mbuf_set_offset(struct rte_mbuf *mbuf, + uint32_t offset) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->rx_priv.offset = offset; } -static inline uint32_t st_rx_mbuf_get_offset(struct rte_mbuf* mbuf) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline uint32_t st_rx_mbuf_get_offset(struct rte_mbuf *mbuf) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); return priv->rx_priv.offset; } -static inline void st_rx_mbuf_set_len(struct rte_mbuf* mbuf, uint32_t len) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline void st_rx_mbuf_set_len(struct rte_mbuf *mbuf, uint32_t len) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->rx_priv.len = len; } -static inline uint32_t st_rx_mbuf_get_len(struct rte_mbuf* mbuf) { - struct mt_muf_priv_data* priv = rte_mbuf_to_priv(mbuf); +static inline uint32_t st_rx_mbuf_get_len(struct rte_mbuf *mbuf) { + struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); return priv->rx_priv.len; } -uint64_t mt_mbuf_time_stamp(struct mtl_main_impl* impl, struct rte_mbuf* mbuf, +uint64_t mt_mbuf_time_stamp(struct mtl_main_impl *impl, struct rte_mbuf *mbuf, enum mtl_port port); -static inline uint64_t mt_get_ptp_time(struct mtl_main_impl* impl, enum mtl_port port) { +static inline uint64_t mt_get_ptp_time(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_if(impl, port)->ptp_get_time_fn(impl, port); } -int mt_ptp_wait_stable(struct mtl_main_impl* impl, enum mtl_port port, int timeout_ms); +int mt_ptp_wait_stable(struct mtl_main_impl *impl, enum mtl_port port, + int timeout_ms); -uint64_t mt_get_raw_ptp_time(struct mtl_main_impl* impl, enum mtl_port port); +uint64_t mt_get_raw_ptp_time(struct mtl_main_impl *impl, enum mtl_port port); #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0) -static inline struct rte_ether_addr* mt_eth_s_addr(struct rte_ether_hdr* eth) { +static inline struct rte_ether_addr *mt_eth_s_addr(struct rte_ether_hdr *eth) { return ð->src_addr; } -static inline struct rte_ether_addr* mt_eth_d_addr(struct rte_ether_hdr* eth) { +static inline struct rte_ether_addr *mt_eth_d_addr(struct rte_ether_hdr *eth) { return ð->dst_addr; } #else -static inline struct rte_ether_addr* mt_eth_s_addr(struct rte_ether_hdr* eth) { +static inline struct rte_ether_addr *mt_eth_s_addr(struct rte_ether_hdr *eth) { return ð->s_addr; } -static inline struct rte_ether_addr* mt_eth_d_addr(struct rte_ether_hdr* eth) { +static inline struct rte_ether_addr *mt_eth_d_addr(struct rte_ether_hdr *eth) { return ð->d_addr; } #endif -#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ +#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ (JSON_C_VERSION_NUM < ((0 << 16) | (10 << 8) | 0)) -static inline json_object* mt_json_object_get(json_object* obj, const char* key) { +static inline json_object *mt_json_object_get(json_object *obj, + const char *key) { return json_object_object_get(obj, key); } #else -static inline json_object* mt_json_object_get(json_object* obj, const char* key) { - json_object* value; +static inline json_object *mt_json_object_get(json_object *obj, + const char *key) { + json_object *value; int ret = json_object_object_get_ex(obj, key, &value); - if (ret) return value; + if (ret) + return value; return NULL; } #endif -static inline bool mt_spinlock_lock_timeout(struct mtl_main_impl* impl, - rte_spinlock_t* lock, int timeout_us) { +static inline bool mt_spinlock_lock_timeout(struct mtl_main_impl *impl, + rte_spinlock_t *lock, + int timeout_us) { uint64_t time = mt_get_tsc(impl); uint64_t end = time + timeout_us * NS_PER_US; while (time < end) { - if (rte_spinlock_trylock(lock)) return true; + if (rte_spinlock_trylock(lock)) + return true; time = mt_get_tsc(impl); } return false; /* timeout */ diff --git a/lib/src/mt_mcast.c b/lib/src/mt_mcast.c index 7dbd9208f..759883fe4 100644 --- a/lib/src/mt_mcast.c +++ b/lib/src/mt_mcast.c @@ -10,37 +10,38 @@ #define MT_MCAST_POOL_INC (32) -static inline struct mt_mcast_impl* get_mcast(struct mtl_main_impl* impl, +static inline struct mt_mcast_impl *get_mcast(struct mtl_main_impl *impl, enum mtl_port port) { return impl->mcast[port]; } /* Computing the Internet Checksum based on rfc1071 */ -static uint16_t mcast_msg_checksum(enum mcast_msg_type type, void* msg, +static uint16_t mcast_msg_checksum(enum mcast_msg_type type, void *msg, size_t mb_report_len) { size_t size = 0; switch (type) { - case MEMBERSHIP_QUERY: - size = sizeof(struct mcast_mb_query_v3); - break; - case MEMBERSHIP_REPORT_V3: - size = mb_report_len; - break; - default: - err("%s, wrong mcast msg type: %d\n", __func__, type); - break; + case MEMBERSHIP_QUERY: + size = sizeof(struct mcast_mb_query_v3); + break; + case MEMBERSHIP_REPORT_V3: + size = mb_report_len; + break; + default: + err("%s, wrong mcast msg type: %d\n", __func__, type); + break; } return mt_rf1071_check_sum(msg, size, true); } /* group record shaping, return record length, refer to RFC3376 - 4.2.4 */ -static inline size_t mcast_create_group_record_on_query( - uint32_t group_addr, struct mt_mcast_src_list* src_list, - struct mcast_group_record* group_record) { +static inline size_t +mcast_create_group_record_on_query(uint32_t group_addr, + struct mt_mcast_src_list *src_list, + struct mcast_group_record *group_record) { uint16_t num_sources = 0; - struct mt_mcast_src_entry* src; + struct mt_mcast_src_entry *src; TAILQ_FOREACH(src, src_list, entries) { group_record->source_addr[num_sources++] = src->src_ip; } @@ -54,13 +55,15 @@ static inline size_t mcast_create_group_record_on_query( group_record->num_sources = htons(num_sources); group_record->multicast_addr = group_addr; - size_t record_len = sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); + size_t record_len = + sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); return record_len; } -static inline size_t mcast_create_group_record_join( - uint32_t group_addr, uint32_t src_addr, struct mcast_group_record* group_record) { +static inline size_t +mcast_create_group_record_join(uint32_t group_addr, uint32_t src_addr, + struct mcast_group_record *group_record) { uint16_t num_sources = 0; group_record->aux_data_len = 0; group_record->multicast_addr = group_addr; @@ -74,12 +77,14 @@ static inline size_t mcast_create_group_record_join( } group_record->num_sources = htons(num_sources); - size_t record_len = sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); + size_t record_len = + sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); return record_len; } -static inline size_t mcast_create_group_record_leave( - uint32_t group_addr, uint32_t src_addr, struct mcast_group_record* group_record) { +static inline size_t +mcast_create_group_record_leave(uint32_t group_addr, uint32_t src_addr, + struct mcast_group_record *group_record) { uint16_t num_sources = 0; group_record->aux_data_len = 0; group_record->multicast_addr = group_addr; @@ -93,24 +98,28 @@ static inline size_t mcast_create_group_record_leave( } group_record->num_sources = htons(num_sources); - size_t record_len = sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); + size_t record_len = + sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); return record_len; } /* 224.0.0.22 */ -static struct rte_ether_addr const mcast_mac_dst = {{0x01, 0x00, 0x5e, 0x00, 0x00, 0x16}}; +static struct rte_ether_addr const mcast_mac_dst = { + {0x01, 0x00, 0x5e, 0x00, 0x00, 0x16}}; -static struct rte_ipv4_hdr* mcast_fill_ipv4(struct mtl_main_impl* impl, - enum mtl_port port, struct rte_mbuf* pkt) { - struct rte_ether_hdr* eth_hdr; - struct rte_ipv4_hdr* ip_hdr; +static struct rte_ipv4_hdr *mcast_fill_ipv4(struct mtl_main_impl *impl, + enum mtl_port port, + struct rte_mbuf *pkt) { + struct rte_ether_hdr *eth_hdr; + struct rte_ipv4_hdr *ip_hdr; - eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr*); + eth_hdr = rte_pktmbuf_mtod(pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth_hdr)); rte_ether_addr_copy(&mcast_mac_dst, mt_eth_d_addr(eth_hdr)); eth_hdr->ether_type = htons(RTE_ETHER_TYPE_IPV4); - ip_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr*, sizeof(*eth_hdr)); + ip_hdr = + rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, sizeof(*eth_hdr)); ip_hdr->version_ihl = (4 << 4) | (sizeof(struct rte_ipv4_hdr) / 4); ip_hdr->time_to_live = 1; ip_hdr->type_of_service = IP_IGMP_DSCP_VALUE; @@ -118,7 +127,7 @@ static struct rte_ipv4_hdr* mcast_fill_ipv4(struct mtl_main_impl* impl, ip_hdr->hdr_checksum = 0; ip_hdr->total_length = 0; ip_hdr->next_proto_id = IPPROTO_IGMP; - ip_hdr->src_addr = *(uint32_t*)mt_sip_addr(impl, port); + ip_hdr->src_addr = *(uint32_t *)mt_sip_addr(impl, port); inet_pton(AF_INET, IGMP_REPORT_IP, &ip_hdr->dst_addr); return ip_hdr; @@ -129,10 +138,11 @@ static struct rte_ipv4_hdr* mcast_fill_ipv4(struct mtl_main_impl* impl, static struct rte_ether_addr const mcast_mac_query = { {0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}}; -int mcast_membership_general_query(struct mtl_main_impl* impl, enum mtl_port port) { - struct rte_mbuf* pkt; - struct rte_ipv4_hdr* ip_hdr; - struct mcast_mb_query_v3* mb_query; +int mcast_membership_general_query(struct mtl_main_impl *impl, + enum mtl_port port) { + struct rte_mbuf *pkt; + struct rte_ipv4_hdr *ip_hdr; + struct mcast_mb_query_v3 *mb_query; size_t hdr_offset = 0; size_t mb_query_len = sizeof(struct mcast_mb_query_v3); @@ -145,7 +155,8 @@ int mcast_membership_general_query(struct mtl_main_impl* impl, enum mtl_port por ip_hdr = mcast_fill_ipv4(impl, port, pkt); hdr_offset += sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr); - mb_query = rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_query_v3*, hdr_offset); + mb_query = + rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_query_v3 *, hdr_offset); mb_query->type = MEMBERSHIP_QUERY; mb_query->max_resp_code = 100; mb_query->checksum = 0x00; @@ -180,13 +191,13 @@ int mcast_membership_general_query(struct mtl_main_impl* impl, enum mtl_port por #endif /* membership report shaping, refer to RFC3376 - 4.2 */ -static int mcast_membership_report_on_query(struct mtl_main_impl* impl, +static int mcast_membership_report_on_query(struct mtl_main_impl *impl, enum mtl_port port) { - struct mt_mcast_impl* mcast = get_mcast(impl, port); + struct mt_mcast_impl *mcast = get_mcast(impl, port); uint16_t group_num = mcast->group_num; - struct rte_mbuf* pkt; - struct rte_ipv4_hdr* ip_hdr; - struct mcast_mb_report_v3* mb_report; + struct rte_mbuf *pkt; + struct rte_ipv4_hdr *ip_hdr; + struct mcast_mb_report_v3 *mb_report; size_t hdr_offset = 0; size_t mb_report_len = sizeof(struct mcast_mb_report_v3); @@ -206,24 +217,28 @@ static int mcast_membership_report_on_query(struct mtl_main_impl* impl, ip_hdr = mcast_fill_ipv4(impl, port, pkt); hdr_offset += sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr); - mb_report = rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3*, hdr_offset); + mb_report = + rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3 *, hdr_offset); mb_report->type = MEMBERSHIP_REPORT_V3; mb_report->reserved_1 = 0x00; mb_report->checksum = 0x00; mb_report->reserved_2 = 0x00; mb_report->num_group_records = htons(group_num); hdr_offset += sizeof(struct mcast_mb_report_v3); - uint8_t* group_record_addr = rte_pktmbuf_mtod_offset(pkt, uint8_t*, hdr_offset); + uint8_t *group_record_addr = + rte_pktmbuf_mtod_offset(pkt, uint8_t *, hdr_offset); - struct mt_mcast_group_entry* group; + struct mt_mcast_group_entry *group; TAILQ_FOREACH(group, &mcast->group_list, entries) { size_t record_len = mcast_create_group_record_on_query( - group->group_ip, &group->src_list, (struct mcast_group_record*)group_record_addr); + group->group_ip, &group->src_list, + (struct mcast_group_record *)group_record_addr); group_record_addr += record_len; mb_report_len += record_len; } - uint16_t checksum = mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); + uint16_t checksum = + mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); if (checksum <= 0) { err("%s(%d), err checksum %d\n", __func__, port, checksum); return -EIO; @@ -239,8 +254,9 @@ static int mcast_membership_report_on_query(struct mtl_main_impl* impl, #ifdef MCAST_DEBUG /* send packet to kernel for capturing */ if (mt_has_virtio_user(impl, port)) { - struct mt_interface* inf = mt_if(impl, port); - rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf**)&report_pkt, 1); + struct mt_interface *inf = mt_if(impl, port); + rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf **)&report_pkt, + 1); } #endif @@ -251,19 +267,21 @@ static int mcast_membership_report_on_query(struct mtl_main_impl* impl, return -EIO; } - dbg("%s(%d), send pkt, mb_report_len %" PRIu64 "\n", __func__, port, mb_report_len); + dbg("%s(%d), send pkt, mb_report_len %" PRIu64 "\n", __func__, port, + mb_report_len); return 0; } -static int mcast_membership_report_on_action(struct mtl_main_impl* impl, - enum mtl_port port, uint32_t group_addr, +static int mcast_membership_report_on_action(struct mtl_main_impl *impl, + enum mtl_port port, + uint32_t group_addr, uint32_t src_addr, enum mcast_action_type action) { - struct rte_mbuf* pkt; - struct rte_ipv4_hdr* ip_hdr; - struct mcast_mb_report_v3* mb_report; - struct mcast_group_record* group_record; + struct rte_mbuf *pkt; + struct rte_ipv4_hdr *ip_hdr; + struct mcast_mb_report_v3 *mb_report; + struct mcast_group_record *group_record; size_t hdr_offset = 0; size_t mb_report_len = sizeof(struct mcast_mb_report_v3); @@ -276,20 +294,25 @@ static int mcast_membership_report_on_action(struct mtl_main_impl* impl, ip_hdr = mcast_fill_ipv4(impl, port, pkt); hdr_offset += sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr); - mb_report = rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3*, hdr_offset); + mb_report = + rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3 *, hdr_offset); mb_report->type = MEMBERSHIP_REPORT_V3; mb_report->reserved_1 = 0x00; mb_report->checksum = 0x00; mb_report->reserved_2 = 0x00; mb_report->num_group_records = htons(1); hdr_offset += sizeof(struct mcast_mb_report_v3); - group_record = rte_pktmbuf_mtod_offset(pkt, struct mcast_group_record*, hdr_offset); + group_record = + rte_pktmbuf_mtod_offset(pkt, struct mcast_group_record *, hdr_offset); if (action == MCAST_JOIN) - mb_report_len += mcast_create_group_record_join(group_addr, src_addr, group_record); + mb_report_len += + mcast_create_group_record_join(group_addr, src_addr, group_record); else - mb_report_len += mcast_create_group_record_leave(group_addr, src_addr, group_record); + mb_report_len += + mcast_create_group_record_leave(group_addr, src_addr, group_record); - uint16_t checksum = mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); + uint16_t checksum = + mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); if (checksum <= 0) { err("%s(%d), err checksum %d\n", __func__, checksum, port); return -EIO; @@ -305,12 +328,13 @@ static int mcast_membership_report_on_action(struct mtl_main_impl* impl, #ifdef MCAST_DEBUG /* send packet to kernel for capturing */ if (mt_has_virtio_user(impl, port)) { - struct mt_interface* inf = mt_if(impl, port); - rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf**)&report_pkt, 1); + struct mt_interface *inf = mt_if(impl, port); + rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf **)&report_pkt, + 1); } #endif /* send membership report twice */ - struct rte_mbuf* pkt_copy = rte_pktmbuf_copy(pkt, pkt->pool, 0, UINT32_MAX); + struct rte_mbuf *pkt_copy = rte_pktmbuf_copy(pkt, pkt->pool, 0, UINT32_MAX); uint16_t tx = mt_sys_queue_tx_burst(impl, port, &pkt, 1); if (tx < 1) { @@ -332,15 +356,16 @@ static int mcast_membership_report_on_action(struct mtl_main_impl* impl, return 0; } -static void mcast_membership_report_cb(void* param) { - struct mtl_main_impl* impl = (struct mtl_main_impl*)param; +static void mcast_membership_report_cb(void *param) { + struct mtl_main_impl *impl = (struct mtl_main_impl *)param; int num_ports = mt_num_ports(impl); int ret; for (int port = 0; port < num_ports; port++) { - struct mt_mcast_impl* mcast = get_mcast(impl, port); - if (!mcast) continue; + struct mt_mcast_impl *mcast = get_mcast(impl, port); + if (!mcast) + continue; if (!mcast->has_external_query) { ret = mcast_membership_report_on_query(impl, port); if (ret < 0) { @@ -349,12 +374,14 @@ static void mcast_membership_report_cb(void* param) { } } - ret = rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, mcast_membership_report_cb, impl); - if (ret < 0) err("%s, set igmp alarm fail %d\n", __func__, ret); + ret = rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, mcast_membership_report_cb, + impl); + if (ret < 0) + err("%s, set igmp alarm fail %d\n", __func__, ret); } -static int mcast_addr_pool_extend(struct mt_interface* inf) { - struct rte_ether_addr* mc_list; +static int mcast_addr_pool_extend(struct mt_interface *inf) { + struct rte_ether_addr *mc_list; size_t mc_list_size; if ((inf->mcast_nb % MT_MCAST_POOL_INC) != 0) { @@ -367,8 +394,10 @@ static int mcast_addr_pool_extend(struct mt_interface* inf) { * The previous test guarantees that port->mc_addr_nb is a multiple * of MCAST_POOL_INC. */ - mc_list_size = sizeof(struct rte_ether_addr) * (inf->mcast_nb + MT_MCAST_POOL_INC); - mc_list = (struct rte_ether_addr*)realloc(inf->mcast_mac_lists, mc_list_size); + mc_list_size = + sizeof(struct rte_ether_addr) * (inf->mcast_nb + MT_MCAST_POOL_INC); + mc_list = + (struct rte_ether_addr *)realloc(inf->mcast_mac_lists, mc_list_size); if (mc_list == NULL) { return -ENOMEM; } @@ -378,14 +407,16 @@ static int mcast_addr_pool_extend(struct mt_interface* inf) { return 0; } -static int mcast_addr_pool_append(struct mt_interface* inf, - struct rte_ether_addr* mc_addr) { - if (mcast_addr_pool_extend(inf) != 0) return -1; +static int mcast_addr_pool_append(struct mt_interface *inf, + struct rte_ether_addr *mc_addr) { + if (mcast_addr_pool_extend(inf) != 0) + return -1; rte_ether_addr_copy(mc_addr, &inf->mcast_mac_lists[inf->mcast_nb - 1]); return 0; } -static void mcast_addr_pool_remove(struct mt_interface* inf, uint32_t addr_idx) { +static void mcast_addr_pool_remove(struct mt_interface *inf, + uint32_t addr_idx) { inf->mcast_nb--; if (addr_idx == inf->mcast_nb) { /* No need to recompose the set of multicast address. */ @@ -400,7 +431,8 @@ static void mcast_addr_pool_remove(struct mt_interface* inf, uint32_t addr_idx) sizeof(struct rte_ether_addr) * (inf->mcast_nb - addr_idx)); } -static int mcast_inf_add_mac(struct mt_interface* inf, struct rte_ether_addr* mcast_mac) { +static int mcast_inf_add_mac(struct mt_interface *inf, + struct rte_ether_addr *mcast_mac) { uint16_t port_id = inf->port_id; uint32_t i; @@ -416,13 +448,14 @@ static int mcast_inf_add_mac(struct mt_interface* inf, struct rte_ether_addr* mc mcast_addr_pool_append(inf, mcast_mac); if (inf->drv_info.flags & MT_DRV_F_USE_MC_ADDR_LIST) - return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, inf->mcast_nb); + return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, + inf->mcast_nb); else return rte_eth_dev_mac_addr_add(port_id, mcast_mac, 0); } -static int mcast_inf_remove_mac(struct mt_interface* inf, - struct rte_ether_addr* mcast_mac) { +static int mcast_inf_remove_mac(struct mt_interface *inf, + struct rte_ether_addr *mcast_mac) { uint32_t i; uint16_t port_id = inf->port_id; @@ -430,7 +463,8 @@ static int mcast_inf_remove_mac(struct mt_interface* inf, * Search the pool of multicast MAC addresses for the removed address. */ for (i = 0; i < inf->mcast_nb; i++) { - if (rte_is_same_ether_addr(mcast_mac, &inf->mcast_mac_lists[i])) break; + if (rte_is_same_ether_addr(mcast_mac, &inf->mcast_mac_lists[i])) + break; } if (i == inf->mcast_nb) { return 0; @@ -438,15 +472,17 @@ static int mcast_inf_remove_mac(struct mt_interface* inf, mcast_addr_pool_remove(inf, i); if (inf->drv_info.flags & MT_DRV_F_USE_MC_ADDR_LIST) - return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, inf->mcast_nb); + return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, + inf->mcast_nb); else return rte_eth_dev_mac_addr_remove(port_id, mcast_mac); } /* 224.0.0.1 */ -static struct rte_ether_addr mcast_mac_all = {{0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}}; +static struct rte_ether_addr mcast_mac_all = { + {0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}}; -int mt_mcast_init(struct mtl_main_impl* impl) { +int mt_mcast_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); int socket = mt_socket_id(impl, MTL_PORT_P); bool has_mcast = false; @@ -457,8 +493,9 @@ int mt_mcast_init(struct mtl_main_impl* impl) { } for (int i = 0; i < num_ports; i++) { - if (mt_drv_mcast_in_dp(impl, i)) continue; - struct mt_mcast_impl* mcast = mt_rte_zmalloc_socket(sizeof(*mcast), socket); + if (mt_drv_mcast_in_dp(impl, i)) + continue; + struct mt_mcast_impl *mcast = mt_rte_zmalloc_socket(sizeof(*mcast), socket); if (!mcast) { err("%s(%d), mcast malloc fail\n", __func__, i); mt_mcast_uinit(impl); @@ -480,8 +517,8 @@ int mt_mcast_init(struct mtl_main_impl* impl) { } if (has_mcast) { - int ret = - rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, mcast_membership_report_cb, impl); + int ret = rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, + mcast_membership_report_cb, impl); if (ret < 0) err("%s, set igmp alarm fail %d\n", __func__, ret); else @@ -492,7 +529,7 @@ int mt_mcast_init(struct mtl_main_impl* impl) { return 0; } -static void mcast_group_clear(struct mt_mcast_group_list* group_list) { +static void mcast_group_clear(struct mt_mcast_group_list *group_list) { struct mt_mcast_group_entry *group, *temp_group; struct mt_mcast_src_entry *src, *temp_src; @@ -517,14 +554,15 @@ static void mcast_group_clear(struct mt_mcast_group_list* group_list) { } } -int mt_mcast_uinit(struct mtl_main_impl* impl) { +int mt_mcast_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); bool has_mcast = false; for (int i = 0; i < num_ports; i++) { - struct mt_mcast_impl* mcast = get_mcast(impl, i); - if (!mcast) continue; + struct mt_mcast_impl *mcast = get_mcast(impl, i); + if (!mcast) + continue; if (!mt_drv_use_kernel_ctl(impl, i)) mcast_inf_remove_mac(mt_if(impl, i), &mcast_mac_all); @@ -543,7 +581,8 @@ int mt_mcast_uinit(struct mtl_main_impl* impl) { if (has_mcast) { int ret = rte_eal_alarm_cancel(mcast_membership_report_cb, impl); - if (ret < 0) err("%s, alarm cancel fail %d\n", __func__, ret); + if (ret < 0) + err("%s, alarm cancel fail %d\n", __func__, ret); } dbg("%s, succ\n", __func__); @@ -551,18 +590,19 @@ int mt_mcast_uinit(struct mtl_main_impl* impl) { } /* add a group address with/without source address to the group ip list */ -int mt_mcast_join(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t source_addr, - enum mtl_port port) { - struct mt_mcast_impl* mcast = get_mcast(impl, port); +int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, + uint32_t source_addr, enum mtl_port port) { + struct mt_mcast_impl *mcast = get_mcast(impl, port); struct rte_ether_addr mcast_mac; - struct mt_interface* inf = mt_if(impl, port); - uint8_t* ip = (uint8_t*)&group_addr; + struct mt_interface *inf = mt_if(impl, port); + uint8_t *ip = (uint8_t *)&group_addr; if (mt_user_no_multicast(impl)) { return 0; } - if (mt_drv_mcast_in_dp(impl, port)) return 0; + if (mt_drv_mcast_in_dp(impl, port)) + return 0; if (mcast->group_num >= MT_MCAST_GROUP_MAX) { err("%s(%d), reach max multicast group number!\n", __func__, port); @@ -573,7 +613,7 @@ int mt_mcast_join(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t sour /* find existing group */ bool found = false; - struct mt_mcast_group_entry* group; + struct mt_mcast_group_entry *group; TAILQ_FOREACH(group, &mcast->group_list, entries) { if (group->group_ip == group_addr) { group->group_ref_cnt++; @@ -607,10 +647,11 @@ int mt_mcast_join(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t sour /* add source address to group's source list */ if (source_addr != 0) { found = false; - struct mt_mcast_src_entry* src; + struct mt_mcast_src_entry *src; TAILQ_FOREACH(src, &group->src_list, entries) { if (src->src_ip == source_addr) { - dbg("%s(%d), already has source ip in the source list\n", __func__, port); + dbg("%s(%d), already has source ip in the source list\n", __func__, + port); src->src_ref_cnt++; found = true; break; @@ -634,21 +675,22 @@ int mt_mcast_join(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t sour /* * send mcast report msg if joined new group/source and dpdk based. - * one thing should notice is that if we have joined a group with source specified, - * then join it again with any source is not allowed. + * one thing should notice is that if we have joined a group with source + * specified, then join it again with any source is not allowed. */ if (!found) { - int ret = mcast_membership_report_on_action(impl, port, group_addr, source_addr, - MCAST_JOIN); + int ret = mcast_membership_report_on_action(impl, port, group_addr, + source_addr, MCAST_JOIN); if (ret < 0) { err("%s(%d), send membership report fail\n", __func__, port); return ret; } - info("%s(%d), join group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); + info("%s(%d), join group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3]); if (source_addr != 0) { - ip = (uint8_t*)&source_addr; - info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], - ip[3]); + ip = (uint8_t *)&source_addr; + info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3]); } } @@ -656,27 +698,29 @@ int mt_mcast_join(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t sour } /* delete a group address with/without source address from the group ip list */ -int mt_mcast_leave(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t source_addr, - enum mtl_port port) { +int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, + uint32_t source_addr, enum mtl_port port) { if (mt_user_no_multicast(impl)) { return 0; } - if (mt_drv_mcast_in_dp(impl, port)) return 0; + if (mt_drv_mcast_in_dp(impl, port)) + return 0; - struct mt_mcast_impl* mcast = get_mcast(impl, port); + struct mt_mcast_impl *mcast = get_mcast(impl, port); int group_num = mcast->group_num; - struct mt_interface* inf = mt_if(impl, port); - uint8_t* ip = (uint8_t*)&group_addr; + struct mt_interface *inf = mt_if(impl, port); + uint8_t *ip = (uint8_t *)&group_addr; struct rte_ether_addr mcast_mac; - if (group_num == 0) return 0; + if (group_num == 0) + return 0; mt_pthread_mutex_lock(&mcast->group_mutex); /* find existing group */ bool found = false; bool gdelete = false; - struct mt_mcast_group_entry* group; + struct mt_mcast_group_entry *group; TAILQ_FOREACH(group, &mcast->group_list, entries) { if (group->group_ip == group_addr) { found = true; @@ -694,7 +738,7 @@ int mt_mcast_leave(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t sou bool sdelete = false; if (source_addr != 0) { found = false; - struct mt_mcast_src_entry* src; + struct mt_mcast_src_entry *src; TAILQ_FOREACH(src, &group->src_list, entries) { if (src->src_ip == source_addr) { found = true; @@ -732,39 +776,42 @@ int mt_mcast_leave(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t sou /* send leave report */ if (gdelete || sdelete) { - int ret = mcast_membership_report_on_action(impl, port, group_addr, source_addr, - MCAST_LEAVE); + int ret = mcast_membership_report_on_action(impl, port, group_addr, + source_addr, MCAST_LEAVE); if (ret < 0) { err("%s(%d), send leave report failed\n", __func__, port); return ret; } - info("%s(%d), leave group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); + info("%s(%d), leave group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3]); if (source_addr != 0) { - ip = (uint8_t*)&source_addr; - info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], - ip[3]); + ip = (uint8_t *)&source_addr; + info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3]); } } return 0; } -int mt_mcast_l2_join(struct mtl_main_impl* impl, struct rte_ether_addr* addr, +int mt_mcast_l2_join(struct mtl_main_impl *impl, struct rte_ether_addr *addr, enum mtl_port port) { - struct mt_interface* inf = mt_if(impl, port); - if (mt_drv_use_kernel_ctl(impl, port)) return 0; + struct mt_interface *inf = mt_if(impl, port); + if (mt_drv_use_kernel_ctl(impl, port)) + return 0; return mcast_inf_add_mac(inf, addr); } -int mt_mcast_l2_leave(struct mtl_main_impl* impl, struct rte_ether_addr* addr, +int mt_mcast_l2_leave(struct mtl_main_impl *impl, struct rte_ether_addr *addr, enum mtl_port port) { - struct mt_interface* inf = mt_if(impl, port); - if (mt_drv_use_kernel_ctl(impl, port)) return 0; + struct mt_interface *inf = mt_if(impl, port); + if (mt_drv_use_kernel_ctl(impl, port)) + return 0; return mcast_inf_remove_mac(inf, addr); } -int mt_mcast_restore(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_interface* inf = mt_if(impl, port); +int mt_mcast_restore(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_interface *inf = mt_if(impl, port); uint16_t port_id = inf->port_id; if (inf->drv_info.flags & MT_DRV_F_USE_MC_ADDR_LIST) { @@ -777,11 +824,11 @@ int mt_mcast_restore(struct mtl_main_impl* impl, enum mtl_port port) { return 0; } -int mt_mcast_parse(struct mtl_main_impl* impl, struct mcast_mb_query_v3* query, +int mt_mcast_parse(struct mtl_main_impl *impl, struct mcast_mb_query_v3 *query, enum mtl_port port) { if (query->type != MEMBERSHIP_QUERY) { - err("%s(%d), invalid type %u, only allow igmp query packet\n", __func__, port, - query->type); + err("%s(%d), invalid type %u, only allow igmp query packet\n", __func__, + port, query->type); return -EIO; } @@ -789,11 +836,12 @@ int mt_mcast_parse(struct mtl_main_impl* impl, struct mcast_mb_query_v3* query, query->checksum = 0; uint16_t checksum = mcast_msg_checksum(MEMBERSHIP_QUERY, query, 0); if (checksum != query_checksum) { - err("%s(%d), err checksum %d:%d\n", __func__, port, query_checksum, checksum); + err("%s(%d), err checksum %d:%d\n", __func__, port, query_checksum, + checksum); return -EIO; } - struct mt_mcast_impl* mcast = get_mcast(impl, port); + struct mt_mcast_impl *mcast = get_mcast(impl, port); if (!mcast->has_external_query) { info("%s(%d), received igmp query, stop auto-join\n", __func__, port); mcast->has_external_query = true; diff --git a/lib/src/mt_mcast.h b/lib/src/mt_mcast.h index 51b6e39af..5e709f02b 100644 --- a/lib/src/mt_mcast.h +++ b/lib/src/mt_mcast.h @@ -67,21 +67,21 @@ struct mcast_mb_query_v3 { uint32_t source_addr[0]; } __attribute__((__packed__)) __rte_aligned(2); -int mt_mcast_init(struct mtl_main_impl* impl); -int mt_mcast_uinit(struct mtl_main_impl* impl); -int mt_mcast_join(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t source_addr, - enum mtl_port port); -int mt_mcast_leave(struct mtl_main_impl* impl, uint32_t group_addr, uint32_t source_addr, - enum mtl_port port); -int mt_mcast_l2_join(struct mtl_main_impl* impl, struct rte_ether_addr* addr, +int mt_mcast_init(struct mtl_main_impl *impl); +int mt_mcast_uinit(struct mtl_main_impl *impl); +int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, + uint32_t source_addr, enum mtl_port port); +int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, + uint32_t source_addr, enum mtl_port port); +int mt_mcast_l2_join(struct mtl_main_impl *impl, struct rte_ether_addr *addr, enum mtl_port port); -int mt_mcast_l2_leave(struct mtl_main_impl* impl, struct rte_ether_addr* addr, +int mt_mcast_l2_leave(struct mtl_main_impl *impl, struct rte_ether_addr *addr, enum mtl_port port); -int mt_mcast_parse(struct mtl_main_impl* impl, struct mcast_mb_query_v3* query, +int mt_mcast_parse(struct mtl_main_impl *impl, struct mcast_mb_query_v3 *query, enum mtl_port port); -static inline void mt_mcast_ip_to_mac(uint8_t* mcast_ip4_addr, - struct rte_ether_addr* mcast_mac) { +static inline void mt_mcast_ip_to_mac(uint8_t *mcast_ip4_addr, + struct rte_ether_addr *mcast_mac) { /* Fixed multicast area */ mcast_mac->addr_bytes[0] = 0x01; mcast_mac->addr_bytes[1] = 0x00; diff --git a/lib/src/mt_mem.h b/lib/src/mt_mem.h index de49527dd..517c53ff4 100644 --- a/lib/src/mt_mem.h +++ b/lib/src/mt_mem.h @@ -10,38 +10,33 @@ #define MT_DPDK_LIB_NAME "MT_DPDK" -static inline void* mt_malloc(size_t sz) { - return malloc(sz); -} +static inline void *mt_malloc(size_t sz) { return malloc(sz); } -static inline void* mt_zmalloc(size_t sz) { - void* p = malloc(sz); - if (p) memset(p, 0x0, sz); +static inline void *mt_zmalloc(size_t sz) { + void *p = malloc(sz); + if (p) + memset(p, 0x0, sz); return p; } -static inline void mt_free(void* p) { - free(p); -} +static inline void mt_free(void *p) { free(p); } #ifdef MTL_HAS_ASAN int mt_asan_init(void); int mt_asan_check(void); -void* mt_rte_malloc_socket(size_t sz, int socket); -void* mt_rte_zmalloc_socket(size_t sz, int socket); -void mt_rte_free(void* p); +void *mt_rte_malloc_socket(size_t sz, int socket); +void *mt_rte_zmalloc_socket(size_t sz, int socket); +void mt_rte_free(void *p); #else -static inline void* mt_rte_malloc_socket(size_t sz, int socket) { +static inline void *mt_rte_malloc_socket(size_t sz, int socket) { return rte_malloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); } -static inline void* mt_rte_zmalloc_socket(size_t sz, int socket) { +static inline void *mt_rte_zmalloc_socket(size_t sz, int socket) { return rte_zmalloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); } -static inline void mt_rte_free(void* p) { - rte_free(p); -} +static inline void mt_rte_free(void *p) { rte_free(p); } #endif #endif diff --git a/lib/src/mt_pcap.c b/lib/src/mt_pcap.c index 499f00d5d..494525f21 100644 --- a/lib/src/mt_pcap.c +++ b/lib/src/mt_pcap.c @@ -9,7 +9,7 @@ #ifdef MT_HAS_PCAPNG_TS -int mt_pcap_close(struct mt_pcap* pcap) { +int mt_pcap_close(struct mt_pcap *pcap) { if (pcap->pcapng) { rte_pcapng_close(pcap->pcapng); pcap->pcapng = NULL; @@ -22,9 +22,10 @@ int mt_pcap_close(struct mt_pcap* pcap) { return 0; } -struct mt_pcap* mt_pcap_open(struct mtl_main_impl* impl, enum mtl_port port, int fd) { +struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, + int fd) { int ret; - struct mt_pcap* pcap = mt_zmalloc(sizeof(*pcap)); + struct mt_pcap *pcap = mt_zmalloc(sizeof(*pcap)); if (!pcap) { err("%s(%d,%d), malloc pcap fail\n", __func__, port, fd); return NULL; @@ -35,8 +36,8 @@ struct mt_pcap* mt_pcap_open(struct mtl_main_impl* impl, enum mtl_port port, int char pool_name[ST_MAX_NAME_LEN]; snprintf(pool_name, sizeof(pool_name), "mt_pcap_p%di%d", port, fd); - pcap->mp = mt_mempool_create(impl, port, pool_name, 512, MT_MBUF_CACHE_SIZE, 0, - rte_pcapng_mbuf_size(pcap->max_len)); + pcap->mp = mt_mempool_create(impl, port, pool_name, 512, MT_MBUF_CACHE_SIZE, + 0, rte_pcapng_mbuf_size(pcap->max_len)); if (!pcap->mp) { err("%s(%d,%d), failed to create mempool\n", __func__, port, fd); mt_pcap_close(pcap); @@ -52,7 +53,8 @@ struct mt_pcap* mt_pcap_open(struct mtl_main_impl* impl, enum mtl_port port, int #if RTE_VERSION >= RTE_VERSION_NUM(23, 3, 0, 0) /* add all port interfaces */ for (int i = 0; i < mt_num_ports(impl); i++) { - ret = rte_pcapng_add_interface(pcap->pcapng, mt_port_id(impl, i), NULL, NULL, NULL); + ret = rte_pcapng_add_interface(pcap->pcapng, mt_port_id(impl, i), NULL, + NULL, NULL); if (ret < 0) { warn("%s(%d), add interface fail %d on port %d\n", __func__, fd, ret, i); } @@ -63,13 +65,14 @@ struct mt_pcap* mt_pcap_open(struct mtl_main_impl* impl, enum mtl_port port, int return pcap; } -uint16_t mt_pcap_dump(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_pcap* pcap, struct rte_mbuf** mbufs, uint16_t nb) { - struct rte_mbuf* pcapng_mbuf[nb]; +uint16_t mt_pcap_dump(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_pcap *pcap, struct rte_mbuf **mbufs, + uint16_t nb) { + struct rte_mbuf *pcapng_mbuf[nb]; int pcapng_mbuf_cnt = 0; uint16_t port_id = mt_port_id(impl, port); - struct rte_mbuf* pkt; - struct rte_mbuf* mc; + struct rte_mbuf *pkt; + struct rte_mbuf *mc; for (uint16_t i = 0; i < nb; i++) { pkt = mbufs[i]; @@ -83,7 +86,8 @@ uint16_t mt_pcap_dump(struct mtl_main_impl* impl, enum mtl_port port, pcapng_mbuf[pcapng_mbuf_cnt++] = mc; } - ssize_t len = rte_pcapng_write_packets(pcap->pcapng, pcapng_mbuf, pcapng_mbuf_cnt); + ssize_t len = + rte_pcapng_write_packets(pcap->pcapng, pcapng_mbuf, pcapng_mbuf_cnt); if (len <= 0) { warn("%s(%d,%d), write packet fail\n", __func__, port, pcap->fd); } diff --git a/lib/src/mt_pcap.h b/lib/src/mt_pcap.h index 0e0f940bb..57e3e0c10 100644 --- a/lib/src/mt_pcap.h +++ b/lib/src/mt_pcap.h @@ -18,31 +18,33 @@ struct mt_pcap { enum mtl_port port; int fd; uint32_t max_len; - struct rte_mempool* mp; - struct rte_pcapng* pcapng; + struct rte_mempool *mp; + struct rte_pcapng *pcapng; }; /* note: fd will be be closed in mt_pcap_close if the open succ */ -struct mt_pcap* mt_pcap_open(struct mtl_main_impl* impl, enum mtl_port port, int fd); -int mt_pcap_close(struct mt_pcap* pcap); -uint16_t mt_pcap_dump(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_pcap* pcap, struct rte_mbuf** mbufs, uint16_t nb); +struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, + int fd); +int mt_pcap_close(struct mt_pcap *pcap); +uint16_t mt_pcap_dump(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_pcap *pcap, struct rte_mbuf **mbufs, + uint16_t nb); #else -static inline struct mt_pcap* mt_pcap_open(struct mtl_main_impl* impl, enum mtl_port port, - int fd) { +static inline struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, + enum mtl_port port, int fd) { MTL_MAY_UNUSED(impl); err("%s(%d,%d), no pcap support for this build\n", __func__, port, fd); return NULL; } -static inline int mt_pcap_close(struct mt_pcap* pcap) { +static inline int mt_pcap_close(struct mt_pcap *pcap) { MTL_MAY_UNUSED(pcap); return -ENOTSUP; } -static inline uint16_t mt_pcap_dump(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_pcap* pcap, struct rte_mbuf** mbufs, - uint16_t nb) { +static inline uint16_t mt_pcap_dump(struct mtl_main_impl *impl, + enum mtl_port port, struct mt_pcap *pcap, + struct rte_mbuf **mbufs, uint16_t nb) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(pcap); diff --git a/lib/src/mt_platform.h b/lib/src/mt_platform.h index e0061bc51..017b3167d 100644 --- a/lib/src/mt_platform.h +++ b/lib/src/mt_platform.h @@ -61,8 +61,8 @@ typedef unsigned long int nfds_t; #define MT_ENABLE_P_SHARED /* default enable PTHREAD_PROCESS_SHARED */ #endif -static inline int mt_pthread_mutex_init(pthread_mutex_t* mutex, - pthread_mutexattr_t* p_attr) { +static inline int mt_pthread_mutex_init(pthread_mutex_t *mutex, + pthread_mutexattr_t *p_attr) { #ifdef MT_ENABLE_P_SHARED pthread_mutexattr_t attr; if (p_attr) { @@ -77,41 +77,43 @@ static inline int mt_pthread_mutex_init(pthread_mutex_t* mutex, return pthread_mutex_init(mutex, p_attr); } -static inline int mt_pthread_mutex_lock(pthread_mutex_t* mutex) { +static inline int mt_pthread_mutex_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); } -static inline int mt_pthread_mutex_try_lock(pthread_mutex_t* mutex) { +static inline int mt_pthread_mutex_try_lock(pthread_mutex_t *mutex) { return pthread_mutex_trylock(mutex); } -static inline int mt_pthread_mutex_unlock(pthread_mutex_t* mutex) { +static inline int mt_pthread_mutex_unlock(pthread_mutex_t *mutex) { return pthread_mutex_unlock(mutex); } -static inline int mt_pthread_mutex_destroy(pthread_mutex_t* mutex) { +static inline int mt_pthread_mutex_destroy(pthread_mutex_t *mutex) { return pthread_mutex_destroy(mutex); } -static inline int mt_pthread_cond_init(pthread_cond_t* cond, - pthread_condattr_t* cond_attr) { +static inline int mt_pthread_cond_init(pthread_cond_t *cond, + pthread_condattr_t *cond_attr) { return pthread_cond_init(cond, cond_attr); } -static inline int mt_pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) { +static inline int mt_pthread_cond_wait(pthread_cond_t *cond, + pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } -static inline int mt_pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, - const struct timespec* time) { +static inline int mt_pthread_cond_timedwait(pthread_cond_t *cond, + pthread_mutex_t *mutex, + const struct timespec *time) { return pthread_cond_timedwait(cond, mutex, time); } -static inline int mt_pthread_cond_destroy(pthread_cond_t* cond) { +static inline int mt_pthread_cond_destroy(pthread_cond_t *cond) { return pthread_cond_destroy(cond); } -static inline int mt_pthread_cond_wait_init(pthread_cond_t* cond) { +static inline int mt_pthread_cond_wait_init(pthread_cond_t *cond) { #if MT_THREAD_TIMEDWAIT_CLOCK_ID != CLOCK_REALTIME pthread_condattr_t attr; pthread_condattr_init(&attr); @@ -122,7 +124,7 @@ static inline int mt_pthread_cond_wait_init(pthread_cond_t* cond) { #endif } -static inline void timespec_add_ns(struct timespec* time, uint64_t ns) { +static inline void timespec_add_ns(struct timespec *time, uint64_t ns) { time->tv_nsec += ns; while (time->tv_nsec >= 1000000000L) { time->tv_nsec -= 1000000000L; @@ -130,8 +132,8 @@ static inline void timespec_add_ns(struct timespec* time, uint64_t ns) { } } -static inline int mt_pthread_cond_timedwait_ns(pthread_cond_t* cond, - pthread_mutex_t* mutex, +static inline int mt_pthread_cond_timedwait_ns(pthread_cond_t *cond, + pthread_mutex_t *mutex, uint64_t timedwait_ns) { struct timespec time; clock_gettime(MT_THREAD_TIMEDWAIT_CLOCK_ID, &time); @@ -139,7 +141,7 @@ static inline int mt_pthread_cond_timedwait_ns(pthread_cond_t* cond, return mt_pthread_cond_timedwait(cond, mutex, &time); } -static inline int mt_pthread_cond_signal(pthread_cond_t* cond) { +static inline int mt_pthread_cond_signal(pthread_cond_t *cond) { return pthread_cond_signal(cond); } @@ -147,7 +149,7 @@ static inline bool mt_socket_match(int cpu_socket, int dev_socket) { #ifdef WINDOWSENV MTL_MAY_UNUSED(cpu_socket); MTL_MAY_UNUSED(dev_socket); - return true; // windows cpu socket always 0 + return true; // windows cpu socket always 0 #else return (cpu_socket == dev_socket); #endif diff --git a/lib/src/mt_ptp.c b/lib/src/mt_ptp.c index cc3d04a85..7cc71901c 100644 --- a/lib/src/mt_ptp.c +++ b/lib/src/mt_ptp.c @@ -31,15 +31,17 @@ ((1 == ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) // clang-format on -typedef BOOL(WINAPI* PGSTAP)(PDWORD64 lpTimeAdjustment, PDWORD64 lpTimeIncrement, +typedef BOOL(WINAPI *PGSTAP)(PDWORD64 lpTimeAdjustment, + PDWORD64 lpTimeIncrement, PBOOL lpTimeAdjustmentDisabled); static PGSTAP win_get_systime_adj; -typedef BOOL(WINAPI* PSSTAP)(DWORD64 dwTimeAdjustment, BOOL bTimeAdjustmentDisabled); +typedef BOOL(WINAPI *PSSTAP)(DWORD64 dwTimeAdjustment, + BOOL bTimeAdjustmentDisabled); static PSSTAP win_set_systime_adj; #endif -static char* ptp_mode_strs[MT_PTP_MAX_MODE] = { +static char *ptp_mode_strs[MT_PTP_MAX_MODE] = { "l2", "l4", }; @@ -50,45 +52,48 @@ enum servo_state { LOCKED, }; -static inline char* ptp_mode_str(enum mt_ptp_l_mode mode) { +static inline char *ptp_mode_str(enum mt_ptp_l_mode mode) { return ptp_mode_strs[mode]; } -static inline uint64_t ptp_net_tmstamp_to_ns(struct mt_ptp_tmstamp* ts) { - uint64_t sec = (uint64_t)ntohl(ts->sec_lsb) + ((uint64_t)ntohs(ts->sec_msb) << 32); +static inline uint64_t ptp_net_tmstamp_to_ns(struct mt_ptp_tmstamp *ts) { + uint64_t sec = + (uint64_t)ntohl(ts->sec_lsb) + ((uint64_t)ntohs(ts->sec_msb) << 32); return (sec * NS_PER_S) + ntohl(ts->ns); } -static inline void ptp_timesync_lock(struct mt_ptp_impl* ptp) { /* todo */ +static inline void ptp_timesync_lock(struct mt_ptp_impl *ptp) { /* todo */ MTL_MAY_UNUSED(ptp); } -static inline void ptp_timesync_unlock(struct mt_ptp_impl* ptp) { /* todo */ +static inline void ptp_timesync_unlock(struct mt_ptp_impl *ptp) { /* todo */ MTL_MAY_UNUSED(ptp); } -static inline uint64_t ptp_correct_ts(struct mt_ptp_impl* ptp, uint64_t ts) { +static inline uint64_t ptp_correct_ts(struct mt_ptp_impl *ptp, uint64_t ts) { int64_t ts_local_advanced = ts - ptp->last_sync_ts; int64_t ts_ptp_advanced = ptp->coefficient * ts_local_advanced; return ptp->last_sync_ts + ts_ptp_advanced; } -static inline uint64_t ptp_no_timesync_time(struct mt_ptp_impl* ptp) { +static inline uint64_t ptp_no_timesync_time(struct mt_ptp_impl *ptp) { uint64_t tsc = mt_get_tsc(ptp->impl); return tsc + ptp->no_timesync_delta; } -static inline void ptp_no_timesync_adjust(struct mt_ptp_impl* ptp, int64_t delta) { +static inline void ptp_no_timesync_adjust(struct mt_ptp_impl *ptp, + int64_t delta) { ptp->no_timesync_delta += delta; } -static inline uint64_t ptp_timesync_read_time_no_lock(struct mt_ptp_impl* ptp) { +static inline uint64_t ptp_timesync_read_time_no_lock(struct mt_ptp_impl *ptp) { enum mtl_port port = ptp->port; uint16_t port_id = ptp->port_id; int ret; struct timespec spec; - if (ptp->no_timesync) return ptp_no_timesync_time(ptp); + if (ptp->no_timesync) + return ptp_no_timesync_time(ptp); memset(&spec, 0, sizeof(spec)); @@ -101,13 +106,14 @@ static inline uint64_t ptp_timesync_read_time_no_lock(struct mt_ptp_impl* ptp) { return mt_timespec_to_ns(&spec); } -static inline uint64_t ptp_timesync_read_time(struct mt_ptp_impl* ptp) { +static inline uint64_t ptp_timesync_read_time(struct mt_ptp_impl *ptp) { enum mtl_port port = ptp->port; uint16_t port_id = ptp->port_id; int ret; struct timespec spec; - if (ptp->no_timesync) return ptp_no_timesync_time(ptp); + if (ptp->no_timesync) + return ptp_no_timesync_time(ptp); memset(&spec, 0, sizeof(spec)); @@ -122,45 +128,45 @@ static inline uint64_t ptp_timesync_read_time(struct mt_ptp_impl* ptp) { return mt_timespec_to_ns(&spec); } -static inline double pi_sample(struct mt_pi_servo* s, double offset, double local_ts, - enum servo_state* state) { +static inline double pi_sample(struct mt_pi_servo *s, double offset, + double local_ts, enum servo_state *state) { double ppb = 0.0; switch (s->count) { - case 0: - s->offset[0] = offset; - s->local[0] = local_ts; - *state = UNLOCKED; - s->count = 1; - break; - case 1: - s->offset[1] = offset; - s->local[1] = local_ts; - *state = UNLOCKED; - s->count = 2; - break; - case 2: - s->drift += (s->offset[1] - s->offset[0]) / (s->local[1] - s->local[0]); - *state = UNLOCKED; - s->count = 3; - break; - case 3: - *state = JUMP; + case 0: + s->offset[0] = offset; + s->local[0] = local_ts; + *state = UNLOCKED; + s->count = 1; + break; + case 1: + s->offset[1] = offset; + s->local[1] = local_ts; + *state = UNLOCKED; + s->count = 2; + break; + case 2: + s->drift += (s->offset[1] - s->offset[0]) / (s->local[1] - s->local[0]); + *state = UNLOCKED; + s->count = 3; + break; + case 3: + *state = JUMP; #ifndef WINDOWSENV /* windows always adj offset since adj freq not ready */ - s->count = 4; + s->count = 4; #endif - break; - case 4: - s->drift += 0.7 * offset; - ppb = 0.3 * offset + s->drift; - *state = LOCKED; - break; + break; + case 4: + s->drift += 0.7 * offset; + ppb = 0.3 * offset + s->drift; + *state = LOCKED; + break; } return ppb; } -static void ptp_adj_system_clock_time(struct mt_ptp_impl* ptp, int64_t delta) { +static void ptp_adj_system_clock_time(struct mt_ptp_impl *ptp, int64_t delta) { int ret; #ifndef WINDOWSENV struct timex adjtime; @@ -198,13 +204,14 @@ static void ptp_adj_system_clock_time(struct mt_ptp_impl* ptp, int64_t delta) { if (ret < 0) { err("%s(%d), adj system time offset fail %d\n", __func__, ptp->port, ret); if (ret == -EPERM) - err("%s(%d), please add capability to the app: sudo setcap 'cap_sys_time+ep' " + err("%s(%d), please add capability to the app: sudo setcap " + "'cap_sys_time+ep' " "\n", __func__, ptp->port); } } -static void ptp_adj_system_clock_freq(struct mt_ptp_impl* ptp, double ppb) { +static void ptp_adj_system_clock_freq(struct mt_ptp_impl *ptp, double ppb) { int ret = -1; #ifndef WINDOWSENV struct timex adjfreq; @@ -212,8 +219,8 @@ static void ptp_adj_system_clock_freq(struct mt_ptp_impl* ptp, double ppb) { if (ptp->phc2sys.realtime_nominal_tick) { adjfreq.modes |= ADJ_TICK; - adjfreq.tick = - round(ppb / 1e3 / ptp->phc2sys.realtime_hz) + ptp->phc2sys.realtime_nominal_tick; + adjfreq.tick = round(ppb / 1e3 / ptp->phc2sys.realtime_hz) + + ptp->phc2sys.realtime_nominal_tick; ppb -= 1e3 * ptp->phc2sys.realtime_hz * (adjfreq.tick - ptp->phc2sys.realtime_nominal_tick); } @@ -233,13 +240,14 @@ static void ptp_adj_system_clock_freq(struct mt_ptp_impl* ptp, double ppb) { if (ret < 0) { err("%s(%d), adj system time freq fail %d\n", __func__, ptp->port, ret); if (ret == -EPERM) - err("%s(%d), please add capability to the app: sudo setcap 'cap_sys_time+ep' " + err("%s(%d), please add capability to the app: sudo setcap " + "'cap_sys_time+ep' " "\n", __func__, ptp->port); } } -static void phc2sys_adjust(struct mt_ptp_impl* ptp) { +static void phc2sys_adjust(struct mt_ptp_impl *ptp) { enum servo_state state = UNLOCKED; double ppb; struct timespec ts1_sys, ts2_sys; @@ -275,29 +283,32 @@ static void phc2sys_adjust(struct mt_ptp_impl* ptp) { dbg("%s(%d), state %d\n", __func__, ptp->port, state); switch (state) { - case UNLOCKED: - break; - case JUMP: - ptp_adj_system_clock_time(ptp, -offset); - dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 " adjust time.\n", - __func__, ptp->port_id, offset, shortest_delay); - break; - case LOCKED: - ptp_adj_system_clock_freq(ptp, -ppb); - dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 - " adjust freq %lf ppb.\n", - __func__, ptp->port_id, offset, shortest_delay, ppb); - break; + case UNLOCKED: + break; + case JUMP: + ptp_adj_system_clock_time(ptp, -offset); + dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 + " adjust time.\n", + __func__, ptp->port_id, offset, shortest_delay); + break; + case LOCKED: + ptp_adj_system_clock_freq(ptp, -ppb); + dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 + " adjust freq %lf ppb.\n", + __func__, ptp->port_id, offset, shortest_delay, ppb); + break; } - ptp->phc2sys.stat_delta_max = RTE_MAX(labs(offset), ptp->phc2sys.stat_delta_max); + ptp->phc2sys.stat_delta_max = + RTE_MAX(labs(offset), ptp->phc2sys.stat_delta_max); if (!ptp->phc2sys.locked) { /* * Be considered as synchronized while the max delta is continuously below * 300ns. */ - if (ptp->phc2sys.stat_delta_max < 300 && ptp->phc2sys.stat_delta_max > 0) { + if (ptp->phc2sys.stat_delta_max < 300 && + ptp->phc2sys.stat_delta_max > 0) { if (ptp->phc2sys.stat_sync_keep > 100) ptp->phc2sys.locked = true; else @@ -307,17 +318,20 @@ static void phc2sys_adjust(struct mt_ptp_impl* ptp) { } } } else { - err("%s(%d), PHC or system time retrieving failed.\n", __func__, ptp->port_id); + err("%s(%d), PHC or system time retrieving failed.\n", __func__, + ptp->port_id); } } -static inline int ptp_timesync_read_tx_time(struct mt_ptp_impl* ptp, uint64_t* tai) { +static inline int ptp_timesync_read_tx_time(struct mt_ptp_impl *ptp, + uint64_t *tai) { uint16_t port_id = ptp->port_id; int ret; struct timespec spec; if (ptp->no_timesync) { - if (tai) *tai = ptp_no_timesync_time(ptp); + if (tai) + *tai = ptp_no_timesync_time(ptp); return 0; } @@ -327,20 +341,23 @@ static inline int ptp_timesync_read_tx_time(struct mt_ptp_impl* ptp, uint64_t* t ret = rte_eth_timesync_read_tx_timestamp(port_id, &spec); ptp_timesync_unlock(ptp); - if (ret < 0) dbg("%s(%d), err %d\n", __func__, port, ret); - if (tai) *tai = mt_timespec_to_ns(&spec); + if (ret < 0) + dbg("%s(%d), err %d\n", __func__, port, ret); + if (tai) + *tai = mt_timespec_to_ns(&spec); return ret; } -static inline int ptp_timesync_read_rx_time(struct mt_ptp_impl* ptp, uint32_t flags, - uint64_t* tai) { +static inline int ptp_timesync_read_rx_time(struct mt_ptp_impl *ptp, + uint32_t flags, uint64_t *tai) { enum mtl_port port = ptp->port; uint16_t port_id = ptp->port_id; int ret; struct timespec spec; if (ptp->no_timesync) { - if (tai) *tai = ptp_no_timesync_time(ptp); + if (tai) + *tai = ptp_no_timesync_time(ptp); return 0; } @@ -350,12 +367,15 @@ static inline int ptp_timesync_read_rx_time(struct mt_ptp_impl* ptp, uint32_t fl ret = rte_eth_timesync_read_rx_timestamp(port_id, &spec, flags); ptp_timesync_unlock(ptp); - if (ret < 0) err("%s(%d), err %d\n", __func__, port, ret); - if (tai) *tai = mt_timespec_to_ns(&spec); + if (ret < 0) + err("%s(%d), err %d\n", __func__, port, ret); + if (tai) + *tai = mt_timespec_to_ns(&spec); return ret; } -static inline int ptp_timesync_adjust_time(struct mt_ptp_impl* ptp, int64_t delta) { +static inline int ptp_timesync_adjust_time(struct mt_ptp_impl *ptp, + int64_t delta) { int ret; if (ptp->no_timesync) { @@ -371,7 +391,7 @@ static inline int ptp_timesync_adjust_time(struct mt_ptp_impl* ptp, int64_t delt } #ifdef MTL_HAS_DPDK_TIMESYNC_ADJUST_FREQ -static inline int ptp_timesync_adjust_freq(struct mt_ptp_impl* ptp, int64_t ppm, +static inline int ptp_timesync_adjust_freq(struct mt_ptp_impl *ptp, int64_t ppm, int64_t delta) { int ret; @@ -384,33 +404,35 @@ static inline int ptp_timesync_adjust_freq(struct mt_ptp_impl* ptp, int64_t ppm, ret = rte_eth_timesync_adjust_freq(ptp->port_id, ppm); ptp_timesync_unlock(ptp); - if (ret) ptp_timesync_adjust_time(ptp, delta); + if (ret) + ptp_timesync_adjust_time(ptp, delta); return ret; } #endif -static inline uint64_t ptp_get_raw_time(struct mt_ptp_impl* ptp) { +static inline uint64_t ptp_get_raw_time(struct mt_ptp_impl *ptp) { return ptp_timesync_read_time(ptp); } -static inline uint64_t ptp_get_correct_time(struct mt_ptp_impl* ptp) { +static inline uint64_t ptp_get_correct_time(struct mt_ptp_impl *ptp) { return ptp_correct_ts(ptp, ptp_get_raw_time(ptp)); } -static uint64_t ptp_from_eth(struct mtl_main_impl* impl, enum mtl_port port) { +static uint64_t ptp_from_eth(struct mtl_main_impl *impl, enum mtl_port port) { return ptp_get_correct_time(mt_get_ptp(impl, port)); } -static void ptp_print_port_id(enum mtl_port port, struct mt_ptp_port_id* pid) { - uint8_t* id = &pid->clock_identity.id[0]; - info( - "mt_ptp_port_id(%d), port_number: %04x, clk_id: " - "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - port, pid->port_number, id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]); +static void ptp_print_port_id(enum mtl_port port, struct mt_ptp_port_id *pid) { + uint8_t *id = &pid->clock_identity.id[0]; + info("mt_ptp_port_id(%d), port_number: %04x, clk_id: " + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + port, pid->port_number, id[0], id[1], id[2], id[3], id[4], id[5], id[6], + id[7]); } -static inline bool ptp_port_id_equal(struct mt_ptp_port_id* s, struct mt_ptp_port_id* t) { +static inline bool ptp_port_id_equal(struct mt_ptp_port_id *s, + struct mt_ptp_port_id *t) { if (!memcmp(s, t, sizeof(struct mt_ptp_port_id))) return true; else @@ -423,8 +445,8 @@ static struct rte_ether_addr ptp_l4_multicast_eaddr = { static struct rte_ether_addr ptp_l2_multicast_eaddr = { {0x01, 0x1b, 0x19, 0x00, 0x00, 0x00}}; -static inline void ptp_set_master_addr(struct mt_ptp_impl* ptp, - struct rte_ether_addr* d_addr) { +static inline void ptp_set_master_addr(struct mt_ptp_impl *ptp, + struct rte_ether_addr *d_addr) { if (ptp->master_addr_mode == MT_PTP_MULTICAST_ADDR) { if (ptp->t2_mode == MT_PTP_L4) rte_ether_addr_copy(&ptp_l4_multicast_eaddr, d_addr); @@ -435,30 +457,36 @@ static inline void ptp_set_master_addr(struct mt_ptp_impl* ptp, } } -static void ptp_coefficient_result_reset(struct mt_ptp_impl* ptp) { +static void ptp_coefficient_result_reset(struct mt_ptp_impl *ptp) { ptp->coefficient_result_sum = 0.0; ptp->coefficient_result_min = 2.0; ptp->coefficient_result_max = 0.0; ptp->coefficient_result_cnt = 0; } -static void ptp_update_coefficient(struct mt_ptp_impl* ptp, int64_t error) { +static void ptp_update_coefficient(struct mt_ptp_impl *ptp, int64_t error) { ptp->integral += (error + ptp->prev_error) / 2; ptp->prev_error = error; double offset = ptp->kp * error + ptp->ki * ptp->integral; - if (ptp->t2_mode == MT_PTP_L4) offset /= 4; /* where sync interval is 0.25s for l4 */ + if (ptp->t2_mode == MT_PTP_L4) + offset /= 4; /* where sync interval is 0.25s for l4 */ ptp->coefficient += RTE_MIN(RTE_MAX(offset, -1e-7), 1e-7); - dbg("%s(%d), error %" PRId64 ", offset %.15lf\n", __func__, ptp->port, error, offset); + dbg("%s(%d), error %" PRId64 ", offset %.15lf\n", __func__, ptp->port, error, + offset); } -static void ptp_calculate_coefficient(struct mt_ptp_impl* ptp, int64_t delta) { - if (delta > 1000 * 1000) return; +static void ptp_calculate_coefficient(struct mt_ptp_impl *ptp, int64_t delta) { + if (delta > 1000 * 1000) + return; uint64_t ts_s = ptp_get_raw_time(ptp); uint64_t ts_m = ts_s + delta; - double coefficient = (double)(ts_m - ptp->last_sync_ts) / (ts_s - ptp->last_sync_ts); + double coefficient = + (double)(ts_m - ptp->last_sync_ts) / (ts_s - ptp->last_sync_ts); ptp->coefficient_result_sum += coefficient; - ptp->coefficient_result_min = RTE_MIN(coefficient, ptp->coefficient_result_min); - ptp->coefficient_result_max = RTE_MAX(coefficient, ptp->coefficient_result_max); + ptp->coefficient_result_min = + RTE_MIN(coefficient, ptp->coefficient_result_min); + ptp->coefficient_result_max = + RTE_MAX(coefficient, ptp->coefficient_result_max); ptp->coefficient_result_cnt++; if (ptp->coefficient - 1.0 < 1e-15) /* store first result */ ptp->coefficient = coefficient; @@ -470,11 +498,12 @@ static void ptp_calculate_coefficient(struct mt_ptp_impl* ptp, int64_t delta) { ptp_coefficient_result_reset(ptp); } ptp->last_sync_ts = ts_m; - dbg("%s(%d), delta %" PRId64 ", co %.15lf, ptp %" PRIu64 "\n", __func__, ptp->port, - delta, ptp->coefficient, ts_m); + dbg("%s(%d), delta %" PRId64 ", co %.15lf, ptp %" PRIu64 "\n", __func__, + ptp->port, delta, ptp->coefficient, ts_m); } -static void ptp_adjust_delta(struct mt_ptp_impl* ptp, int64_t delta, bool error_correct) { +static void ptp_adjust_delta(struct mt_ptp_impl *ptp, int64_t delta, + bool error_correct) { MTL_MAY_UNUSED(error_correct); #ifdef MTL_HAS_DPDK_TIMESYNC_ADJUST_FREQ @@ -486,44 +515,47 @@ static void ptp_adjust_delta(struct mt_ptp_impl* ptp, int64_t delta, bool error_ ppb = pi_sample(&ptp->servo, -1 * delta, ptp->t2, &state); switch (state) { - case UNLOCKED: - break; - case JUMP: - if (!ptp_timesync_adjust_time(ptp, delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 - " adjust time.\n", - __func__, ptp->port_id, delta, ptp->path_delay); - else - err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); - break; - case LOCKED: - if (!ptp_timesync_adjust_freq(ptp, -1 * (long)(ppb * 65.536), delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 - " adjust freq.\n", - __func__, ptp->port_id, delta, ptp->path_delay); - else - err("%s(%d), PHC freqency adjust failed.\n", __func__, ptp->port_id); - break; + case UNLOCKED: + break; + case JUMP: + if (!ptp_timesync_adjust_time(ptp, delta)) + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 + " adjust time.\n", + __func__, ptp->port_id, delta, ptp->path_delay); + else + err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); + break; + case LOCKED: + if (!ptp_timesync_adjust_freq(ptp, -1 * (long)(ppb * 65.536), delta)) + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 + " adjust freq.\n", + __func__, ptp->port_id, delta, ptp->path_delay); + else + err("%s(%d), PHC freqency adjust failed.\n", __func__, ptp->port_id); + break; } phc2sys_adjust(ptp); } } else { if (!ptp_timesync_adjust_time(ptp, delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 " adjust time.\n", + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 + " adjust time.\n", __func__, ptp->port_id, delta, ptp->path_delay); else err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); } #else if (!ptp_timesync_adjust_time(ptp, delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 " adjust time.\n", + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 + " adjust time.\n", __func__, ptp->port_id, delta, ptp->path_delay); else err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); - if (ptp->phc2sys_active) phc2sys_adjust(ptp); + if (ptp->phc2sys_active) + phc2sys_adjust(ptp); #endif - dbg("%s(%d), delta %" PRId64 ", ptp %" PRIu64 "\n", __func__, ptp->port, delta, - ptp_get_raw_time(ptp)); + dbg("%s(%d), delta %" PRId64 ", ptp %" PRIu64 "\n", __func__, ptp->port, + delta, ptp_get_raw_time(ptp)); ptp->ptp_delta += delta; if (5 == ptp->delta_result_cnt) /* clear the first 5 results */ @@ -554,8 +586,8 @@ static void ptp_adjust_delta(struct mt_ptp_impl* ptp, int64_t delta, bool error_ } } -static void ptp_delay_req_read_tx_time_handler(void* param) { - struct mt_ptp_impl* ptp = param; +static void ptp_delay_req_read_tx_time_handler(void *param) { + struct mt_ptp_impl *ptp = param; uint64_t tx_ns = 0; int ret; @@ -563,11 +595,12 @@ static void ptp_delay_req_read_tx_time_handler(void* param) { if (ret >= 0) { ptp->t3 = tx_ns; } else { - if (!ptp->t4) rte_eal_alarm_set(5, ptp_delay_req_read_tx_time_handler, ptp); + if (!ptp->t4) + rte_eal_alarm_set(5, ptp_delay_req_read_tx_time_handler, ptp); } } -static void ptp_expect_result_clear(struct mt_ptp_impl* ptp) { +static void ptp_expect_result_clear(struct mt_ptp_impl *ptp) { ptp->expect_result_cnt = 0; ptp->expect_result_sum = 0; ptp->expect_correct_result_sum = 0; @@ -576,14 +609,14 @@ static void ptp_expect_result_clear(struct mt_ptp_impl* ptp) { ptp->expect_result_start_ns = 0; } -static void ptp_t_result_clear(struct mt_ptp_impl* ptp) { +static void ptp_t_result_clear(struct mt_ptp_impl *ptp) { ptp->t1 = 0; ptp->t2 = 0; ptp->t3 = 0; ptp->t4 = 0; } -static void ptp_result_reset(struct mt_ptp_impl* ptp) { +static void ptp_result_reset(struct mt_ptp_impl *ptp) { ptp->delta_result_err = 0; ptp->delta_result_cnt = 0; ptp->delta_result_sum = 0; @@ -593,7 +626,7 @@ static void ptp_result_reset(struct mt_ptp_impl* ptp) { ptp->expect_t2_t1_delta_avg = 0; } -static int ptp_sync_expect_result(struct mt_ptp_impl* ptp) { +static int ptp_sync_expect_result(struct mt_ptp_impl *ptp) { if (ptp->expect_correct_result_avg) { if (ptp->use_pi) { /* fine tune coefficient */ @@ -605,25 +638,27 @@ static int ptp_sync_expect_result(struct mt_ptp_impl* ptp) { ptp_calculate_coefficient(ptp, ptp->expect_result_avg); } } - if (ptp->expect_result_avg) ptp_adjust_delta(ptp, ptp->expect_result_avg, true); + if (ptp->expect_result_avg) + ptp_adjust_delta(ptp, ptp->expect_result_avg, true); return 0; } -static void ptp_monitor_handler(void* param) { - struct mt_ptp_impl* ptp = param; +static void ptp_monitor_handler(void *param) { + struct mt_ptp_impl *ptp = param; uint64_t expect_result_period_us = ptp->expect_result_period_ns / 1000; ptp->stat_sync_timeout_err++; ptp_sync_expect_result(ptp); if (expect_result_period_us) { - dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, expect_result_period_us); + dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, + expect_result_period_us); rte_eal_alarm_set(expect_result_period_us, ptp_monitor_handler, ptp); } } -static void ptp_sync_timeout_handler(void* param) { - struct mt_ptp_impl* ptp = param; +static void ptp_sync_timeout_handler(void *param) { + struct mt_ptp_impl *ptp = param; uint64_t expect_result_period_us = ptp->expect_result_period_ns / 1000; ptp_expect_result_clear(ptp); @@ -632,20 +667,21 @@ static void ptp_sync_timeout_handler(void* param) { ptp_sync_expect_result(ptp); if (expect_result_period_us) { - dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, expect_result_period_us); + dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, + expect_result_period_us); rte_eal_alarm_set(expect_result_period_us, ptp_monitor_handler, ptp); } } -static int ptp_parse_result(struct mt_ptp_impl* ptp) { - struct mtl_main_impl* impl = ptp->impl; +static int ptp_parse_result(struct mt_ptp_impl *ptp) { + struct mtl_main_impl *impl = ptp->impl; int64_t t2_t1_delta = ((int64_t)ptp->t2 - ptp->t1); int64_t t4_t3_delta = ((int64_t)ptp->t4 - ptp->t3); - dbg("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 "\n", __func__, - ptp->port, ptp->t1, ptp->t2, ptp->t3, ptp->t4); - dbg("%s(%d), t2-t1 delta %" PRId64 " t4-t3 delta %" PRIu64 "\n", __func__, ptp->port, - t2_t1_delta, t4_t3_delta); + dbg("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 "\n", + __func__, ptp->port, ptp->t1, ptp->t2, ptp->t3, ptp->t4); + dbg("%s(%d), t2-t1 delta %" PRId64 " t4-t3 delta %" PRIu64 "\n", __func__, + ptp->port, t2_t1_delta, t4_t3_delta); if (ptp->calibrate_t2_t3) { /* max 1us delta */ int32_t max_diff = 1000; @@ -654,7 +690,8 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { t2_t1_delta > (ptp->expect_t2_t1_delta_avg + max_diff)) { ptp->t2_t1_delta_continuous_err++; if (ptp->t2_t1_delta_continuous_err > 20) { - err("%s(%d), t2_t1_delta %" PRId64 ", reset as too many continuous errors\n", + err("%s(%d), t2_t1_delta %" PRId64 + ", reset as too many continuous errors\n", __func__, ptp->port, t2_t1_delta); } t2_t1_delta = ptp->expect_t2_t1_delta_avg; @@ -675,7 +712,8 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { t4_t3_delta > (ptp->expect_t4_t3_delta_avg + max_diff)) { ptp->t4_t3_delta_continuous_err++; if (ptp->t4_t3_delta_continuous_err > 20) { - err("%s(%d), t4_t3_delta %" PRId64 ", reset as too many continuous errors\n", + err("%s(%d), t4_t3_delta %" PRId64 + ", reset as too many continuous errors\n", __func__, ptp->port, t4_t3_delta); } t4_t3_delta = ptp->expect_t4_t3_delta_avg; @@ -706,15 +744,18 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { rte_eal_alarm_cancel(ptp_sync_timeout_handler, ptp); rte_eal_alarm_cancel(ptp_monitor_handler, ptp); if (ptp->delta_result_cnt) { - expect_delta = abs(ptp->expect_result_avg) * (RTE_MIN(ptp->delta_result_err + 2, 5)); + expect_delta = + abs(ptp->expect_result_avg) * (RTE_MIN(ptp->delta_result_err + 2, 5)); if (!expect_delta) { expect_delta = ptp->delta_result_sum / ptp->delta_result_cnt * 2; expect_delta = RTE_MAX(expect_delta, 100 * 1000); /* min 100us */ } if (abs_delta > expect_delta) { #if MT_PTP_PRINT_ERR_RESULT - err("%s(%d), error abs_delta %" PRIu64 "\n", __func__, ptp->port, abs_delta); - err("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 "\n", + err("%s(%d), error abs_delta %" PRIu64 "\n", __func__, ptp->port, + abs_delta); + err("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 + "\n", __func__, ptp->port, ptp->t1, ptp->t2, ptp->t3, ptp->t4); #endif ptp_t_result_clear(ptp); @@ -722,12 +763,14 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { ptp->delta_result_err++; ptp->stat_result_err++; if (ptp->delta_result_err > 10) { - dbg("%s(%d), reset the result as too many errors\n", __func__, ptp->port); + dbg("%s(%d), reset the result as too many errors\n", __func__, + ptp->port); ptp_result_reset(ptp); } ptp_sync_expect_result(ptp); #ifdef MTL_HAS_DPDK_TIMESYNC_ADJUST_FREQ - if (!ptp->phc2sys_active) return -EIO; + if (!ptp->phc2sys_active) + return -EIO; #else return -EIO; #endif @@ -739,10 +782,13 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { int64_t correct_delta = ((int64_t)ptp->t4 - ptp_correct_ts(ptp, ptp->t3)) - ((int64_t)ptp_correct_ts(ptp, ptp->t2) - ptp->t1); correct_delta /= 2; - dbg("%s(%d), correct_delta %" PRId64 "\n", __func__, ptp->port, correct_delta); + dbg("%s(%d), correct_delta %" PRId64 "\n", __func__, ptp->port, + correct_delta); /* update correct delta and path delay result */ - ptp->stat_correct_delta_min = RTE_MIN(correct_delta, ptp->stat_correct_delta_min); - ptp->stat_correct_delta_max = RTE_MAX(correct_delta, ptp->stat_correct_delta_max); + ptp->stat_correct_delta_min = + RTE_MIN(correct_delta, ptp->stat_correct_delta_min); + ptp->stat_correct_delta_max = + RTE_MAX(correct_delta, ptp->stat_correct_delta_max); ptp->stat_correct_delta_cnt++; ptp->stat_correct_delta_sum += labs(correct_delta); ptp->stat_path_delay_min = RTE_MIN(path_delay, ptp->stat_path_delay_min); @@ -765,7 +811,7 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { ptp->connected = true; /* notify the sync event if ptp_sync_notify is enabled */ - struct mtl_init_params* p = mt_get_user_params(impl); + struct mtl_init_params *p = mt_get_user_params(impl); if (p->ptp_sync_notify && (MTL_PORT_P == ptp->port)) { struct mtl_ptp_sync_notify_meta meta; meta.master_utc_offset = ptp->master_utc_offset; @@ -784,7 +830,8 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { ptp->expect_t4_t3_delta_sum += t4_t3_delta; ptp->expect_result_sum += delta; if (ptp->expect_result_cnt >= 10) { - ptp->expect_result_avg = ptp->expect_result_sum / ptp->expect_result_cnt; + ptp->expect_result_avg = + ptp->expect_result_sum / ptp->expect_result_cnt; ptp->expect_correct_result_avg = ptp->expect_correct_result_sum / ptp->expect_result_cnt; ptp->expect_t2_t1_delta_avg = @@ -794,10 +841,12 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { ptp->expect_result_period_ns = (mt_get_monotonic_time() - ptp->expect_result_start_ns) / (ptp->expect_result_cnt - 1); - dbg("%s(%d), expect result avg %d(correct: %d), t2_t1_delta %d, t4_t3_delta %d, " + dbg("%s(%d), expect result avg %d(correct: %d), t2_t1_delta %d, " + "t4_t3_delta %d, " "period %fs\n", - __func__, ptp->port, ptp->expect_result_avg, ptp->expect_correct_result_avg, - ptp->expect_t2_t1_delta_avg, ptp->expect_t4_t3_delta_avg, + __func__, ptp->port, ptp->expect_result_avg, + ptp->expect_correct_result_avg, ptp->expect_t2_t1_delta_avg, + ptp->expect_t4_t3_delta_avg, (float)ptp->expect_result_period_ns / NS_PER_S); ptp_expect_result_clear(ptp); } @@ -809,15 +858,16 @@ static int ptp_parse_result(struct mt_ptp_impl* ptp) { return 0; } -static void ptp_delay_req_task(struct mt_ptp_impl* ptp) { +static void ptp_delay_req_task(struct mt_ptp_impl *ptp) { enum mtl_port port = ptp->port; size_t hdr_offset; - struct mt_ptp_sync_msg* msg; + struct mt_ptp_sync_msg *msg; uint64_t tx_ns = 0; - if (ptp->t3) return; /* t3 already sent */ + if (ptp->t3) + return; /* t3 already sent */ - struct rte_mbuf* m = rte_pktmbuf_alloc(ptp->mbuf_pool); + struct rte_mbuf *m = rte_pktmbuf_alloc(ptp->mbuf_pool); if (!m) { err("%s(%d), rte_pktmbuf_alloc fail\n", __func__, port); return; @@ -833,12 +883,12 @@ static void ptp_delay_req_task(struct mt_ptp_impl* ptp) { #endif } - struct rte_ether_hdr* hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr*); + struct rte_ether_hdr *hdr = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); hdr_offset = sizeof(struct rte_ether_hdr); if (ptp->t2_mode == MT_PTP_L4) { - struct mt_ipv4_udp* ipv4_hdr = - rte_pktmbuf_mtod_offset(m, struct mt_ipv4_udp*, hdr_offset); + struct mt_ipv4_udp *ipv4_hdr = + rte_pktmbuf_mtod_offset(m, struct mt_ipv4_udp *, hdr_offset); hdr_offset += sizeof(struct mt_ipv4_udp); rte_memcpy(ipv4_hdr, &ptp->dst_udp, sizeof(*ipv4_hdr)); ipv4_hdr->udp.src_port = htons(MT_PTP_UDP_EVENT_PORT); @@ -854,7 +904,7 @@ static void ptp_delay_req_task(struct mt_ptp_impl* ptp) { hdr->ether_type = htons(RTE_ETHER_TYPE_1588); } - msg = rte_pktmbuf_mtod_offset(m, struct mt_ptp_sync_msg*, hdr_offset); + msg = rte_pktmbuf_mtod_offset(m, struct mt_ptp_sync_msg *, hdr_offset); memset(msg, 0x0, sizeof(*msg)); msg->hdr.message_type = PTP_DELAY_REQ; msg->hdr.version = 2; @@ -922,8 +972,8 @@ static void ptp_delay_req_task(struct mt_ptp_impl* ptp) { uint64_t delta = ptp_ns - tx_ns; #define TX_MAX_DELTA (1 * 1000 * 1000) /* 1ms */ if (unlikely(delta > TX_MAX_DELTA)) { - err("%s(%d), tx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, tx_ns, - delta); + err("%s(%d), tx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, + tx_ns, delta); ptp->stat_tx_sync_err++; } #endif @@ -932,8 +982,9 @@ static void ptp_delay_req_task(struct mt_ptp_impl* ptp) { #else ptp->t3 = ptp_get_raw_time(ptp); #endif - dbg("%s(%d), t3 %" PRIu64 ", seq %d, max_retry %d, ptp %" PRIu64 "\n", __func__, port, - ptp->t3, ptp->t3_sequence_id, max_retry, ptp_get_raw_time(ptp)); + dbg("%s(%d), t3 %" PRIu64 ", seq %d, max_retry %d, ptp %" PRIu64 "\n", + __func__, port, ptp->t3, ptp->t3_sequence_id, max_retry, + ptp_get_raw_time(ptp)); MT_USDT_PTP_MSG(ptp->port, 3, ptp->t3); /* all time get */ @@ -944,14 +995,15 @@ static void ptp_delay_req_task(struct mt_ptp_impl* ptp) { } #if MT_PTP_USE_TX_TIMER -static void ptp_delay_req_handler(void* param) { - struct mt_ptp_impl* ptp = param; +static void ptp_delay_req_handler(void *param) { + struct mt_ptp_impl *ptp = param; return ptp_delay_req_task(ptp); } #endif -static int ptp_parse_sync(struct mt_ptp_impl* ptp, struct mt_ptp_sync_msg* msg, bool vlan, - enum mt_ptp_l_mode mode, uint16_t timesync) { +static int ptp_parse_sync(struct mt_ptp_impl *ptp, struct mt_ptp_sync_msg *msg, + bool vlan, enum mt_ptp_l_mode mode, + uint16_t timesync) { uint64_t rx_ns = 0; #define RX_MAX_DELTA (1 * 1000 * 1000) /* 1ms */ @@ -959,7 +1011,8 @@ static int ptp_parse_sync(struct mt_ptp_impl* ptp, struct mt_ptp_sync_msg* msg, uint64_t monitor_period_us = ptp->expect_result_period_ns / 1000 / 2; if (monitor_period_us) { - monitor_period_us = RTE_MAX(monitor_period_us, 100 * 1000 * 1000); /* min 100ms */ + monitor_period_us = + RTE_MAX(monitor_period_us, 100 * 1000 * 1000); /* min 100ms */ if (ptp->t2) { /* already has a pending t2 */ ptp_expect_result_clear(ptp); ptp_t_result_clear(ptp); @@ -982,8 +1035,8 @@ static int ptp_parse_sync(struct mt_ptp_impl* ptp, struct mt_ptp_sync_msg* msg, ptp_ns = ptp_timesync_read_time(ptp); delta = ptp_ns - rx_ns; if (unlikely(delta > RX_MAX_DELTA)) { - err("%s(%d), rx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, rx_ns, - delta); + err("%s(%d), rx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, + rx_ns, delta); ptp->stat_rx_sync_err++; } #endif @@ -996,18 +1049,18 @@ static int ptp_parse_sync(struct mt_ptp_impl* ptp, struct mt_ptp_sync_msg* msg, ptp->t2_sequence_id = msg->hdr.sequence_id; ptp->t2_vlan = vlan; ptp->t2_mode = mode; - dbg("%s(%d), t2 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, ptp->t2, - ptp->t2_sequence_id, ptp_get_raw_time(ptp)); + dbg("%s(%d), t2 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, + ptp->t2, ptp->t2_sequence_id, ptp_get_raw_time(ptp)); MT_USDT_PTP_MSG(ptp->port, 2, ptp->t2); return 0; } -static int ptp_parse_follow_up(struct mt_ptp_impl* ptp, - struct mt_ptp_follow_up_msg* msg) { +static int ptp_parse_follow_up(struct mt_ptp_impl *ptp, + struct mt_ptp_follow_up_msg *msg) { if (msg->hdr.sequence_id != ptp->t2_sequence_id) { - dbg("%s(%d), error sequence id %d %d\n", __func__, ptp->port, msg->hdr.sequence_id, - ptp->t2_sequence_id); + dbg("%s(%d), error sequence id %d %d\n", __func__, ptp->port, + msg->hdr.sequence_id, ptp->t2_sequence_id); return -EINVAL; } ptp->t1 = ptp_net_tmstamp_to_ns(&msg->precise_origin_timestamp) + @@ -1027,8 +1080,10 @@ static int ptp_parse_follow_up(struct mt_ptp_impl* ptp, return 0; } -static int ptp_parse_announce(struct mt_ptp_impl* ptp, struct mt_ptp_announce_msg* msg, - enum mt_ptp_l_mode mode, struct mt_ipv4_udp* ipv4_hdr) { +static int ptp_parse_announce(struct mt_ptp_impl *ptp, + struct mt_ptp_announce_msg *msg, + enum mt_ptp_l_mode mode, + struct mt_ipv4_udp *ipv4_hdr) { enum mtl_port port = ptp->port; if (!ptp->master_initialized) { @@ -1036,19 +1091,21 @@ static int ptp_parse_announce(struct mt_ptp_impl* ptp, struct mt_ptp_announce_ms ptp->master_utc_offset = ntohs(msg->current_utc_offset); rte_memcpy(&ptp->master_port_id, &msg->hdr.source_port_identity, sizeof(ptp->master_port_id)); - rte_memcpy(&ptp->master_addr.addr_bytes[0], &ptp->master_port_id.clock_identity.id[0], - 3); - rte_memcpy(&ptp->master_addr.addr_bytes[3], &ptp->master_port_id.clock_identity.id[5], - 3); - info("%s(%d), master initialized, mode %s utc_offset %d domain_number %d\n", __func__, - port, ptp_mode_str(mode), ptp->master_utc_offset, msg->hdr.domain_number); + rte_memcpy(&ptp->master_addr.addr_bytes[0], + &ptp->master_port_id.clock_identity.id[0], 3); + rte_memcpy(&ptp->master_addr.addr_bytes[3], + &ptp->master_port_id.clock_identity.id[5], 3); + info("%s(%d), master initialized, mode %s utc_offset %d domain_number %d\n", + __func__, port, ptp_mode_str(mode), ptp->master_utc_offset, + msg->hdr.domain_number); ptp_print_port_id(port, &ptp->master_port_id); if (mode == MT_PTP_L4) { - struct mt_ipv4_udp* dst_udp = &ptp->dst_udp; + struct mt_ipv4_udp *dst_udp = &ptp->dst_udp; rte_memcpy(dst_udp, ipv4_hdr, sizeof(*dst_udp)); rte_memcpy(&dst_udp->ip.src_addr, &ptp->sip_addr[0], MTL_IP_ADDR_LEN); - rte_memcpy(&dst_udp->ip.dst_addr, &ptp->mcast_group_addr[0], MTL_IP_ADDR_LEN); + rte_memcpy(&dst_udp->ip.dst_addr, &ptp->mcast_group_addr[0], + MTL_IP_ADDR_LEN); dst_udp->ip.total_length = htons(sizeof(struct mt_ipv4_udp) + sizeof(struct mt_ptp_sync_msg)); dst_udp->ip.hdr_checksum = 0; @@ -1068,8 +1125,8 @@ static int ptp_parse_announce(struct mt_ptp_impl* ptp, struct mt_ptp_announce_ms return 0; } -static int ptp_parse_delay_resp(struct mt_ptp_impl* ptp, - struct mt_ptp_delay_resp_msg* msg) { +static int ptp_parse_delay_resp(struct mt_ptp_impl *ptp, + struct mt_ptp_delay_resp_msg *msg) { if (!ptp_port_id_equal(&msg->requesting_port_identity, &ptp->our_port_id)) { /* not our request resp */ return 0; @@ -1088,8 +1145,8 @@ static int ptp_parse_delay_resp(struct mt_ptp_impl* ptp, } ptp->t4 = ptp_net_tmstamp_to_ns(&msg->receive_timestamp) - (be64toh(msg->hdr.correction_field) >> 16); - dbg("%s(%d), t4 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, ptp->t4, - ptp->t3_sequence_id, ptp_get_raw_time(ptp)); + dbg("%s(%d), t4 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, + ptp->t4, ptp->t3_sequence_id, ptp_get_raw_time(ptp)); MT_USDT_PTP_MSG(ptp->port, 4, ptp->t4); /* all time get */ @@ -1100,7 +1157,7 @@ static int ptp_parse_delay_resp(struct mt_ptp_impl* ptp, return 0; } -static void ptp_stat_clear(struct mt_ptp_impl* ptp) { +static void ptp_stat_clear(struct mt_ptp_impl *ptp) { ptp->stat_delta_cnt = 0; ptp->stat_delta_sum = 0; ptp->stat_delta_min = INT_MAX; @@ -1118,10 +1175,12 @@ static void ptp_stat_clear(struct mt_ptp_impl* ptp) { ptp->stat_result_err = 0; ptp->stat_sync_timeout_err = 0; ptp->stat_sync_cnt = 0; - if (ptp->phc2sys_active) ptp->phc2sys.stat_delta_max = 0; + if (ptp->phc2sys_active) + ptp->phc2sys.stat_delta_max = 0; } -static void ptp_sync_from_user(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp) { +static void ptp_sync_from_user(struct mtl_main_impl *impl, + struct mt_ptp_impl *ptp) { enum mtl_port port = ptp->port; uint64_t target_ns = mt_get_ptp_time(impl, port); uint64_t raw_ns = ptp_get_raw_time(ptp); @@ -1130,15 +1189,17 @@ static void ptp_sync_from_user(struct mtl_main_impl* impl, struct mt_ptp_impl* p uint64_t expect_abs_delta = abs(ptp->expect_result_avg) * 2; if (expect_abs_delta) { - if (abs_delta > expect_abs_delta) delta = ptp->expect_result_avg; + if (abs_delta > expect_abs_delta) + delta = ptp->expect_result_avg; } else { if (abs_delta < 10000) { ptp->expect_result_sum += delta; ptp->expect_result_cnt++; if (ptp->expect_result_cnt > 1000) { - ptp->expect_result_avg = ptp->expect_result_sum / ptp->expect_result_cnt; - info("%s(%d), expect delta %d, sum %d\n", __func__, port, ptp->expect_result_avg, - ptp->expect_result_sum); + ptp->expect_result_avg = + ptp->expect_result_sum / ptp->expect_result_cnt; + info("%s(%d), expect delta %d, sum %d\n", __func__, port, + ptp->expect_result_avg, ptp->expect_result_sum); } } } @@ -1156,8 +1217,8 @@ static void ptp_sync_from_user(struct mtl_main_impl* impl, struct mt_ptp_impl* p ptp->stat_delta_sum += labs(delta); } -static void ptp_sync_from_user_handler(void* param) { - struct mt_ptp_impl* ptp = param; +static void ptp_sync_from_user_handler(void *param) { + struct mt_ptp_impl *ptp = param; ptp_sync_from_user(ptp->impl, ptp); rte_eal_alarm_set(MT_PTP_TP_SYNC_MS * 1000, ptp_sync_from_user_handler, ptp); @@ -1175,8 +1236,8 @@ int obtain_systime_privileges() { return -1; } - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, - &hProcToken)) { + if (!OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hProcToken)) { err("%s, failed to open process token. hr=0x%08lx\n", __func__, HRESULT_FROM_WIN32(GetLastError())); return -1; @@ -1192,14 +1253,15 @@ int obtain_systime_privileges() { return -1; } - if (hProcToken) CloseHandle(hProcToken); + if (hProcToken) + CloseHandle(hProcToken); info("%s, succ\n", __func__); return 0; } #endif -static void phc2sys_init(struct mt_ptp_impl* ptp) { +static void phc2sys_init(struct mt_ptp_impl *ptp) { memset(&ptp->phc2sys.servo, 0, sizeof(struct mt_pi_servo)); memset(&ptp->servo, 0, sizeof(struct mt_pi_servo)); #ifndef WINDOWSENV @@ -1209,10 +1271,13 @@ static void phc2sys_init(struct mt_ptp_impl* ptp) { HANDLE hDll; hDll = LoadLibrary("api-ms-win-core-sysinfo-l1-2-4.dll"); - win_get_systime_adj = (PGSTAP)GetProcAddress(hDll, "GetSystemTimeAdjustmentPrecise"); - win_set_systime_adj = (PSSTAP)GetProcAddress(hDll, "SetSystemTimeAdjustmentPrecise"); + win_get_systime_adj = + (PGSTAP)GetProcAddress(hDll, "GetSystemTimeAdjustmentPrecise"); + win_set_systime_adj = + (PSSTAP)GetProcAddress(hDll, "SetSystemTimeAdjustmentPrecise"); - if (obtain_systime_privileges()) return; + if (obtain_systime_privileges()) + return; /* set system internal adj */ if (!(*win_set_systime_adj)(0, TRUE)) { @@ -1232,24 +1297,25 @@ static void phc2sys_init(struct mt_ptp_impl* ptp) { info("%s(%d), succ\n", __func__, ptp->port); } -static int ptp_rxq_mbuf_handle(struct mt_ptp_impl* ptp, struct rte_mbuf* m) { - struct mt_ipv4_udp* ipv4_hdr; - struct mt_ptp_header* hdr; +static int ptp_rxq_mbuf_handle(struct mt_ptp_impl *ptp, struct rte_mbuf *m) { + struct mt_ipv4_udp *ipv4_hdr; + struct mt_ptp_header *hdr; size_t hdr_offset; hdr_offset = sizeof(struct rte_ether_hdr); - ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ipv4_udp*, hdr_offset); + ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ipv4_udp *, hdr_offset); hdr_offset += sizeof(*ipv4_hdr); - hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header*, sizeof(struct mt_udp_hdr)); + hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, + sizeof(struct mt_udp_hdr)); mt_ptp_parse(ptp, hdr, false, MT_PTP_L4, m->timesync, ipv4_hdr); return 0; } -static int ptp_rxq_tasklet_handler(void* priv) { - struct mt_ptp_impl* ptp = priv; +static int ptp_rxq_tasklet_handler(void *priv) { + struct mt_ptp_impl *ptp = priv; uint16_t rx; - struct rte_mbuf* pkt[MT_PTP_RX_BURST_SIZE]; + struct rte_mbuf *pkt[MT_PTP_RX_BURST_SIZE]; /* MT_PTP_UDP_GEN_PORT */ rx = mt_rxq_burst(ptp->gen_rxq, &pkt[0], MT_PTP_RX_BURST_SIZE); @@ -1268,13 +1334,13 @@ static int ptp_rxq_tasklet_handler(void* priv) { return 0; } -static int ptp_init(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp, +static int ptp_init(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp, enum mtl_port port) { uint16_t port_id = mt_port_id(impl, port); struct rte_ether_addr mac; int ret; - uint8_t* ip = &ptp->sip_addr[0]; - struct mt_interface* inf = mt_if(impl, port); + uint8_t *ip = &ptp->sip_addr[0]; + struct mt_interface *inf = mt_if(impl, port); ret = mt_macaddr_get(impl, port, &mac); if (ret < 0) { @@ -1283,12 +1349,12 @@ static int ptp_init(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp, } uint16_t magic = MT_PTP_CLOCK_IDENTITY_MAGIC; - struct mt_ptp_port_id* our_port_id = &ptp->our_port_id; - uint8_t* id = &our_port_id->clock_identity.id[0]; + struct mt_ptp_port_id *our_port_id = &ptp->our_port_id; + uint8_t *id = &our_port_id->clock_identity.id[0]; memcpy(&id[0], &mac.addr_bytes[0], 3); memcpy(&id[3], &magic, 2); memcpy(&id[5], &mac.addr_bytes[3], 3); - our_port_id->port_number = htons(port_id); // now always + our_port_id->port_number = htons(port_id); // now always ptp_print_port_id(port_id, our_port_id); rte_memcpy(ip, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); @@ -1304,18 +1370,20 @@ static int ptp_init(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp, ptp->ki = impl->user_para.ki < 1e-15 ? MT_PTP_DEFAULT_KI : impl->user_para.ki; ptp->use_pi = (impl->user_para.flags & MTL_FLAG_PTP_PI); if (ptp->use_pi) - info("%s(%d), use pi controller, kp %e, ki %e\n", __func__, port, ptp->kp, ptp->ki); - if (mt_user_phc2sys_service(impl) && (MTL_PORT_P == port)) phc2sys_init(ptp); + info("%s(%d), use pi controller, kp %e, ki %e\n", __func__, port, ptp->kp, + ptp->ki); + if (mt_user_phc2sys_service(impl) && (MTL_PORT_P == port)) + phc2sys_init(ptp); - struct mtl_init_params* p = mt_get_user_params(impl); + struct mtl_init_params *p = mt_get_user_params(impl); if (p->flags & MTL_FLAG_PTP_UNICAST_ADDR) { ptp->master_addr_mode = MT_PTP_UNICAST_ADDR; info("%s(%d), MT_PTP_UNICAST_ADDR\n", __func__, port); } else { ptp->master_addr_mode = MT_PTP_MULTICAST_ADDR; } - ptp->qbv_enabled = - ((ST21_TX_PACING_WAY_TSN == p->pacing) && (MT_DRV_IGC == inf->drv_info.drv_type)); + ptp->qbv_enabled = ((ST21_TX_PACING_WAY_TSN == p->pacing) && + (MT_DRV_IGC == inf->drv_info.drv_type)); ptp->locked = false; ptp->stat_sync_keep = 0; @@ -1328,9 +1396,11 @@ static int ptp_init(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp, ptp->no_timesync = true; warn("%s(%d), ptp running without timesync support\n", __func__, port); } - info("%s(%d), ptp sync from user for hw offload timestamp\n", __func__, port); + info("%s(%d), ptp sync from user for hw offload timestamp\n", __func__, + port); ptp_sync_from_user(impl, ptp); - rte_eal_alarm_set(MT_PTP_TP_SYNC_MS * 1000, ptp_sync_from_user_handler, ptp); + rte_eal_alarm_set(MT_PTP_TP_SYNC_MS * 1000, ptp_sync_from_user_handler, + ptp); ptp->connected = true; ptp->locked = true; ptp->active = true; @@ -1346,7 +1416,8 @@ static int ptp_init(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp, inet_pton(AF_INET, "224.0.1.129", ptp->mcast_group_addr); if (mt_has_cni(impl, port) && !mt_drv_mcast_in_dp(impl, port)) { - /* join mcast only if cni path, no cni use socket which has mcast in the data path */ + /* join mcast only if cni path, no cni use socket which has mcast in the + * data path */ ret = mt_mcast_join(impl, mt_ip_to_u32(ptp->mcast_group_addr), 0, port); if (ret < 0) { err("%s(%d), join ptp multicast group fail\n", __func__, port); @@ -1394,11 +1465,12 @@ static int ptp_init(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp, ptp->calibrate_t2_t3 = true; warn("%s(%d), ptp running without timesync support\n", __func__, port); } - info("%s(%d), sip: %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); + info("%s(%d), sip: %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], + ip[3]); return 0; } -static int ptp_uinit(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp) { +static int ptp_uinit(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp) { enum mtl_port port = ptp->port; rte_eal_alarm_cancel(ptp_sync_from_user_handler, ptp); @@ -1408,10 +1480,12 @@ static int ptp_uinit(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp) { rte_eal_alarm_cancel(ptp_sync_timeout_handler, ptp); rte_eal_alarm_cancel(ptp_monitor_handler, ptp); #ifdef MT_PTP_USE_TX_TIME_STAMP - if (ptp->qbv_enabled) rte_eal_alarm_cancel(ptp_delay_req_read_tx_time_handler, ptp); + if (ptp->qbv_enabled) + rte_eal_alarm_cancel(ptp_delay_req_read_tx_time_handler, ptp); #endif - if (!ptp->active) return 0; + if (!ptp->active) + return 0; if (mt_has_cni(impl, port) && !mt_drv_mcast_in_dp(impl, port)) { mt_mcast_l2_leave(impl, &ptp_l2_multicast_eaddr, port); @@ -1435,24 +1509,26 @@ static int ptp_uinit(struct mtl_main_impl* impl, struct mt_ptp_impl* ptp) { return 0; } -int mt_ptp_parse(struct mt_ptp_impl* ptp, struct mt_ptp_header* hdr, bool vlan, +int mt_ptp_parse(struct mt_ptp_impl *ptp, struct mt_ptp_header *hdr, bool vlan, enum mt_ptp_l_mode mode, uint16_t timesync, - struct mt_ipv4_udp* ipv4_hdr) { + struct mt_ipv4_udp *ipv4_hdr) { enum mtl_port port = ptp->port; - if (!ptp->active) return 0; + if (!ptp->active) + return 0; dbg("%s(%d), message_type %d\n", __func__, port, hdr->message_type); // mt_ptp_print_port_id(port, &hdr->source_port_identity); if (hdr->message_type != PTP_ANNOUNCE) { if (!ptp->master_initialized) { - dbg("%s(%d), master not initialized, message_type %d, mode %s\n", __func__, port, - hdr->message_type, ptp_mode_str(mode)); + dbg("%s(%d), master not initialized, message_type %d, mode %s\n", + __func__, port, hdr->message_type, ptp_mode_str(mode)); return -EINVAL; } if (!ptp_port_id_equal(&hdr->source_port_identity, &ptp->master_port_id)) { - dbg("%s(%d), source_port_identity not our master, message_type %d, mode %s\n", + dbg("%s(%d), source_port_identity not our master, message_type %d, mode " + "%s\n", __func__, port, hdr->message_type, ptp_mode_str(mode)); #ifdef DEBUG ptp_print_port_id(port, &hdr->source_port_identity); @@ -1462,25 +1538,25 @@ int mt_ptp_parse(struct mt_ptp_impl* ptp, struct mt_ptp_header* hdr, bool vlan, } switch (hdr->message_type) { - case PTP_SYNC: - ptp_parse_sync(ptp, (struct mt_ptp_sync_msg*)hdr, vlan, mode, timesync); - break; - case PTP_FOLLOW_UP: - ptp_parse_follow_up(ptp, (struct mt_ptp_follow_up_msg*)hdr); - break; - case PTP_DELAY_RESP: - ptp_parse_delay_resp(ptp, (struct mt_ptp_delay_resp_msg*)hdr); - break; - case PTP_ANNOUNCE: - ptp_parse_announce(ptp, (struct mt_ptp_announce_msg*)hdr, mode, ipv4_hdr); - break; - case PTP_DELAY_REQ: - break; - case PTP_PDELAY_REQ: - break; - default: - err("%s(%d), unknown message_type %d\n", __func__, port, hdr->message_type); - return -EINVAL; + case PTP_SYNC: + ptp_parse_sync(ptp, (struct mt_ptp_sync_msg *)hdr, vlan, mode, timesync); + break; + case PTP_FOLLOW_UP: + ptp_parse_follow_up(ptp, (struct mt_ptp_follow_up_msg *)hdr); + break; + case PTP_DELAY_RESP: + ptp_parse_delay_resp(ptp, (struct mt_ptp_delay_resp_msg *)hdr); + break; + case PTP_ANNOUNCE: + ptp_parse_announce(ptp, (struct mt_ptp_announce_msg *)hdr, mode, ipv4_hdr); + break; + case PTP_DELAY_REQ: + break; + case PTP_PDELAY_REQ: + break; + default: + err("%s(%d), unknown message_type %d\n", __func__, port, hdr->message_type); + return -EINVAL; } /* read to clear rx timesync status */ @@ -1489,8 +1565,8 @@ int mt_ptp_parse(struct mt_ptp_impl* ptp, struct mt_ptp_header* hdr, bool vlan, return 0; } -static int ptp_stat(void* priv) { - struct mt_ptp_impl* ptp = priv; +static int ptp_stat(void *priv) { + struct mt_ptp_impl *ptp = priv; enum mtl_port port = ptp->port; char date_time[64]; struct timespec spec; @@ -1504,22 +1580,25 @@ static int ptp_stat(void* priv) { strftime(date_time, sizeof(date_time), "%Y-%m-%d %H:%M:%S", &t); notice("PTP(%d): time %" PRIu64 ", %s\n", port, ns, date_time); - if (!ptp->active) return 0; + if (!ptp->active) + return 0; if (ptp->stat_delta_cnt) { if (ptp->phc2sys_active) { notice("PTP(%d): system clock offset max %" PRId64 ", %s\n", port, - ptp->phc2sys.stat_delta_max, ptp->phc2sys.locked ? "locked" : "not locked"); + ptp->phc2sys.stat_delta_max, + ptp->phc2sys.locked ? "locked" : "not locked"); } - notice("PTP(%d): delta avg %" PRId64 ", min %" PRId64 ", max %" PRId64 ", cnt %d\n", + notice("PTP(%d): delta avg %" PRId64 ", min %" PRId64 ", max %" PRId64 + ", cnt %d\n", port, ptp->stat_delta_sum / ptp->stat_delta_cnt, ptp->stat_delta_min, ptp->stat_delta_max, ptp->stat_delta_cnt); } else { notice("PTP(%d): not connected\n", port); } if (ptp->stat_correct_delta_cnt) - notice("PTP(%d): correct_delta avg %" PRId64 ", min %" PRId64 ", max %" PRId64 - ", cnt %d\n", + notice("PTP(%d): correct_delta avg %" PRId64 ", min %" PRId64 + ", max %" PRId64 ", cnt %d\n", port, ptp->stat_correct_delta_sum / ptp->stat_correct_delta_cnt, ptp->stat_correct_delta_min, ptp->stat_correct_delta_max, ptp->stat_correct_delta_cnt); @@ -1527,16 +1606,20 @@ static int ptp_stat(void* priv) { notice("PTP(%d): path_delay avg %" PRId64 ", min %" PRId64 ", max %" PRId64 ", cnt %d\n", port, ptp->stat_path_delay_sum / ptp->stat_path_delay_cnt, - ptp->stat_path_delay_min, ptp->stat_path_delay_max, ptp->stat_path_delay_cnt); - notice( - "PTP(%d): mode %s, sync cnt %d, expect avg %d:%d@%fs t2_t1_delta %d t4_t3_delta " - "%d\n", - port, ptp_mode_str(ptp->t2_mode), ptp->stat_sync_cnt, ptp->expect_result_avg, - ptp->expect_correct_result_avg, (float)ptp->expect_result_period_ns / NS_PER_S, - ptp->expect_t2_t1_delta_avg, ptp->expect_t4_t3_delta_avg); + ptp->stat_path_delay_min, ptp->stat_path_delay_max, + ptp->stat_path_delay_cnt); + notice("PTP(%d): mode %s, sync cnt %d, expect avg %d:%d@%fs t2_t1_delta %d " + "t4_t3_delta " + "%d\n", + port, ptp_mode_str(ptp->t2_mode), ptp->stat_sync_cnt, + ptp->expect_result_avg, ptp->expect_correct_result_avg, + (float)ptp->expect_result_period_ns / NS_PER_S, + ptp->expect_t2_t1_delta_avg, ptp->expect_t4_t3_delta_avg); if (ptp->stat_rx_sync_err || ptp->stat_result_err || ptp->stat_tx_sync_err) - notice("PTP(%d): rx time error %d, tx time error %d, delta result error %d\n", port, - ptp->stat_rx_sync_err, ptp->stat_tx_sync_err, ptp->stat_result_err); + notice( + "PTP(%d): rx time error %d, tx time error %d, delta result error %d\n", + port, ptp->stat_rx_sync_err, ptp->stat_tx_sync_err, + ptp->stat_result_err); if (ptp->stat_sync_timeout_err) err("PTP(%d): sync timeout %d\n", port, ptp->stat_sync_timeout_err); @@ -1547,7 +1630,8 @@ static int ptp_stat(void* priv) { ptp->stat_t4_t3_delta_calibrate = 0; } if (ptp->stat_t3_sequence_id_mismatch) { - err("PTP(%d): t3 sequence id mismatch %d\n", port, ptp->stat_t3_sequence_id_mismatch); + err("PTP(%d): t3 sequence id mismatch %d\n", port, + ptp->stat_t3_sequence_id_mismatch); ptp->stat_t3_sequence_id_mismatch = 0; } @@ -1556,16 +1640,17 @@ static int ptp_stat(void* priv) { return 0; } -int mt_ptp_init(struct mtl_main_impl* impl) { +int mt_ptp_init(struct mtl_main_impl *impl) { int socket = mt_socket_id(impl, MTL_PORT_P); int ret; int num_port = mt_num_ports(impl); for (int i = 0; i < num_port; i++) { /* only probe on the MTL_PORT_P */ - if ((i != MTL_PORT_P) && !mt_if_has_offload_timestamp(impl, i)) continue; + if ((i != MTL_PORT_P) && !mt_if_has_offload_timestamp(impl, i)) + continue; - struct mt_ptp_impl* ptp = mt_rte_zmalloc_socket(sizeof(*ptp), socket); + struct mt_ptp_impl *ptp = mt_rte_zmalloc_socket(sizeof(*ptp), socket); if (!ptp) { err("%s(%d), ptp malloc fail\n", __func__, i); mt_ptp_uinit(impl); @@ -1589,13 +1674,14 @@ int mt_ptp_init(struct mtl_main_impl* impl) { return 0; } -int mt_ptp_uinit(struct mtl_main_impl* impl) { +int mt_ptp_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_ptp_impl* ptp; + struct mt_ptp_impl *ptp; for (int i = 0; i < num_ports; i++) { ptp = mt_get_ptp(impl, i); - if (!ptp) continue; + if (!ptp) + continue; mt_stat_unregister(impl, ptp_stat, ptp); @@ -1609,20 +1695,20 @@ int mt_ptp_uinit(struct mtl_main_impl* impl) { return 0; } -uint64_t mt_get_raw_ptp_time(struct mtl_main_impl* impl, enum mtl_port port) { +uint64_t mt_get_raw_ptp_time(struct mtl_main_impl *impl, enum mtl_port port) { return ptp_get_raw_time(mt_get_ptp(impl, port)); } -static uint64_t mbuf_hw_time_stamp(struct mtl_main_impl* impl, struct rte_mbuf* mbuf, - enum mtl_port port) { - struct mt_ptp_impl* ptp = mt_get_ptp(impl, port); +static uint64_t mbuf_hw_time_stamp(struct mtl_main_impl *impl, + struct rte_mbuf *mbuf, enum mtl_port port) { + struct mt_ptp_impl *ptp = mt_get_ptp(impl, port); uint64_t time_stamp = - *RTE_MBUF_DYNFIELD(mbuf, impl->dynfield_offset, rte_mbuf_timestamp_t*); + *RTE_MBUF_DYNFIELD(mbuf, impl->dynfield_offset, rte_mbuf_timestamp_t *); time_stamp += ptp->ptp_delta; return ptp_correct_ts(ptp, time_stamp); } -uint64_t mt_mbuf_time_stamp(struct mtl_main_impl* impl, struct rte_mbuf* mbuf, +uint64_t mt_mbuf_time_stamp(struct mtl_main_impl *impl, struct rte_mbuf *mbuf, enum mtl_port port) { if (mt_if_has_offload_timestamp(impl, port)) return mbuf_hw_time_stamp(impl, mbuf, port); @@ -1630,12 +1716,14 @@ uint64_t mt_mbuf_time_stamp(struct mtl_main_impl* impl, struct rte_mbuf* mbuf, return mtl_ptp_read_time(impl); } -int mt_ptp_wait_stable(struct mtl_main_impl* impl, enum mtl_port port, int timeout_ms) { - struct mt_ptp_impl* ptp = mt_get_ptp(impl, port); +int mt_ptp_wait_stable(struct mtl_main_impl *impl, enum mtl_port port, + int timeout_ms) { + struct mt_ptp_impl *ptp = mt_get_ptp(impl, port); uint64_t start_ts = mt_get_tsc(impl); int retry = 0; - if (!ptp->active) return 0; + if (!ptp->active) + return 0; while (ptp->delta_result_cnt <= 5) { if (mt_aborted(impl)) { @@ -1652,15 +1740,16 @@ int mt_ptp_wait_stable(struct mtl_main_impl* impl, enum mtl_port port, int timeo } retry++; if (0 == (retry % 500)) - info("%s(%d), wait PTP stable, timeout %d ms\n", __func__, port, timeout_ms); + info("%s(%d), wait PTP stable, timeout %d ms\n", __func__, port, + timeout_ms); mt_sleep_ms(10); } return 0; } -uint64_t mt_ptp_internal_time(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_ptp_impl* ptp = mt_get_ptp(impl, port); +uint64_t mt_ptp_internal_time(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_ptp_impl *ptp = mt_get_ptp(impl, port); if (!ptp->active) { err("%s(%d), ptp not active\n", __func__, port); diff --git a/lib/src/mt_ptp.h b/lib/src/mt_ptp.h index d985b5d81..6ff44cff5 100644 --- a/lib/src/mt_ptp.h +++ b/lib/src/mt_ptp.h @@ -102,30 +102,33 @@ struct mt_ptp_delay_resp_msg { uint8_t suffix[0]; } __attribute__((packed)); -static inline struct mt_ptp_impl* mt_get_ptp(struct mtl_main_impl* impl, +static inline struct mt_ptp_impl *mt_get_ptp(struct mtl_main_impl *impl, enum mtl_port port) { return impl->ptp[port]; } -int mt_ptp_init(struct mtl_main_impl* impl); -int mt_ptp_uinit(struct mtl_main_impl* impl); +int mt_ptp_init(struct mtl_main_impl *impl); +int mt_ptp_uinit(struct mtl_main_impl *impl); -int mt_ptp_parse(struct mt_ptp_impl* ptp, struct mt_ptp_header* hdr, bool vlan, +int mt_ptp_parse(struct mt_ptp_impl *ptp, struct mt_ptp_header *hdr, bool vlan, enum mt_ptp_l_mode mode, uint16_t timesync, - struct mt_ipv4_udp* ipv4_hdr); + struct mt_ipv4_udp *ipv4_hdr); -static inline bool mt_ptp_is_active(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_ptp_is_active(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_get_ptp(impl, port)->active; } -static inline bool mt_ptp_is_locked(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_ptp_is_locked(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_get_ptp(impl, port)->locked; } -static inline bool mt_ptp_is_connected(struct mtl_main_impl* impl, enum mtl_port port) { +static inline bool mt_ptp_is_connected(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_get_ptp(impl, port)->connected; } -uint64_t mt_ptp_internal_time(struct mtl_main_impl* impl, enum mtl_port port); +uint64_t mt_ptp_internal_time(struct mtl_main_impl *impl, enum mtl_port port); #endif diff --git a/lib/src/mt_quirk.h b/lib/src/mt_quirk.h index caba1dd0a..f9ed1698e 100644 --- a/lib/src/mt_quirk.h +++ b/lib/src/mt_quirk.h @@ -5,11 +5,12 @@ #ifndef _MT_LIB_QUIRK_HEAD_H_ #define _MT_LIB_QUIRK_HEAD_H_ -static inline unsigned int mt_rte_ring_sc_dequeue_bulk(struct rte_ring* r, - void** obj_table, unsigned int n, - unsigned int* available) { +static inline unsigned int +mt_rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, + unsigned int n, unsigned int *available) { #if defined(__clang__) /* fix for clang release build */ - /* not sure why clang has issue with variable n, probably optimized code sequence */ + /* not sure why clang has issue with variable n, probably optimized code + * sequence */ if (n == 4) return rte_ring_sc_dequeue_bulk(r, obj_table, 4, available); else if (n == 1) diff --git a/lib/src/mt_rtcp.c b/lib/src/mt_rtcp.c index 826f01940..4628aafc7 100644 --- a/lib/src/mt_rtcp.c +++ b/lib/src/mt_rtcp.c @@ -25,38 +25,43 @@ static int rtp_seq_num_cmp(uint16_t seq0, uint16_t seq1) { } } -int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx* tx, struct rte_mbuf** mbufs, - unsigned int bulk) { - if (!tx->active) return 0; +int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx *tx, + struct rte_mbuf **mbufs, unsigned int bulk) { + if (!tx->active) + return 0; if (mt_u64_fifo_free_count(tx->mbuf_ring) < bulk) { - struct rte_mbuf* clean_mbufs[bulk]; - if (mt_u64_fifo_get_bulk(tx->mbuf_ring, (uint64_t*)clean_mbufs, bulk) < 0) { + struct rte_mbuf *clean_mbufs[bulk]; + if (mt_u64_fifo_get_bulk(tx->mbuf_ring, (uint64_t *)clean_mbufs, bulk) < + 0) { err("%s(%s), failed to dequeue mbuf from ring\n", __func__, tx->name); return -EIO; } rte_pktmbuf_free_bulk(clean_mbufs, bulk); } - /* check the seq num in order, if err happens user should check the enqueue logic */ - struct st_rfc3550_rtp_hdr* rtp = rte_pktmbuf_mtod_offset( - mbufs[0], struct st_rfc3550_rtp_hdr*, sizeof(struct mt_udp_hdr)); + /* check the seq num in order, if err happens user should check the enqueue + * logic */ + struct st_rfc3550_rtp_hdr *rtp = rte_pktmbuf_mtod_offset( + mbufs[0], struct st_rfc3550_rtp_hdr *, sizeof(struct mt_udp_hdr)); uint16_t seq = ntohs(rtp->seq_number); - uint16_t diff = seq - tx->last_seq_num; /* uint16_t wrap-around should be ok */ + uint16_t diff = + seq - tx->last_seq_num; /* uint16_t wrap-around should be ok */ if (diff != 1 && mt_u64_fifo_count(tx->mbuf_ring) != 0) { uint32_t ts = ntohl(rtp->tmstamp); - err("%s(%s), ts 0x%x seq %u out of order, last seq %u\n", __func__, tx->name, ts, seq, - tx->last_seq_num); + err("%s(%s), ts 0x%x seq %u out of order, last seq %u\n", __func__, + tx->name, ts, seq, tx->last_seq_num); return -EIO; } - if (mt_u64_fifo_put_bulk(tx->mbuf_ring, (uint64_t*)mbufs, bulk) < 0) { - err("%s(%s), failed to enqueue %u mbuf to ring\n", __func__, tx->name, bulk); + if (mt_u64_fifo_put_bulk(tx->mbuf_ring, (uint64_t *)mbufs, bulk) < 0) { + err("%s(%s), failed to enqueue %u mbuf to ring\n", __func__, tx->name, + bulk); return -EIO; } mt_mbuf_refcnt_inc_bulk(mbufs, bulk); /* save the last rtp seq num */ - rtp = rte_pktmbuf_mtod_offset(mbufs[bulk - 1], struct st_rfc3550_rtp_hdr*, + rtp = rte_pktmbuf_mtod_offset(mbufs[bulk - 1], struct st_rfc3550_rtp_hdr *, sizeof(struct mt_udp_hdr)); tx->last_seq_num = ntohs(rtp->seq_number); @@ -65,7 +70,7 @@ int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx* tx, struct rte_mbuf** mbufs return 0; } -static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx* tx, uint16_t seq, +static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx *tx, uint16_t seq, uint16_t bulk) { int ret = 0; uint16_t nb_rt = bulk, send = 0; @@ -74,30 +79,33 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx* tx, uint16_t seq, uint32_t ts = 0; MTL_MAY_UNUSED(ts); - struct rte_mbuf* head_mbuf = NULL; - if (mt_u64_fifo_read_front(tx->mbuf_ring, (uint64_t*)&head_mbuf) < 0 || !head_mbuf) { + struct rte_mbuf *head_mbuf = NULL; + if (mt_u64_fifo_read_front(tx->mbuf_ring, (uint64_t *)&head_mbuf) < 0 || + !head_mbuf) { err("%s(%s), empty ring\n", __func__, tx->name); ret = -EIO; goto rt_exit; } - struct st_rfc3550_rtp_hdr* rtp = rte_pktmbuf_mtod_offset( - head_mbuf, struct st_rfc3550_rtp_hdr*, sizeof(struct mt_udp_hdr)); + struct st_rfc3550_rtp_hdr *rtp = rte_pktmbuf_mtod_offset( + head_mbuf, struct st_rfc3550_rtp_hdr *, sizeof(struct mt_udp_hdr)); ring_head_seq = ntohs(rtp->seq_number); ts = ntohl(rtp->tmstamp); int cmp_result = rtp_seq_num_cmp(ring_head_seq, seq); if (cmp_result > 0) { - dbg("%s(%s), ts 0x%x seq %u out of date, ring head %u, you ask late\n", __func__, - tx->name, ts, seq, ring_head_seq); + dbg("%s(%s), ts 0x%x seq %u out of date, ring head %u, you ask late\n", + __func__, tx->name, ts, seq, ring_head_seq); tx->stat_rtp_retransmit_fail_obsolete += bulk; ret = -EIO; goto rt_exit; } uint16_t diff = seq - ring_head_seq; - if (mt_u64_fifo_read_any_bulk(tx->mbuf_ring, (uint64_t*)mbufs, bulk, diff) < 0) { - dbg("%s(%s), failed to read retransmit mbufs from ring\n", __func__, tx->name); + if (mt_u64_fifo_read_any_bulk(tx->mbuf_ring, (uint64_t *)mbufs, bulk, diff) < + 0) { + dbg("%s(%s), failed to read retransmit mbufs from ring\n", __func__, + tx->name); tx->stat_rtp_retransmit_fail_read += bulk; ret = -EIO; goto rt_exit; @@ -105,7 +113,8 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx* tx, uint16_t seq, /* deep copy the mbuf then send */ for (int i = 0; i < bulk; i++) { - struct rte_mbuf* copied = rte_pktmbuf_copy(mbufs[i], tx->mbuf_pool, 0, UINT32_MAX); + struct rte_mbuf *copied = + rte_pktmbuf_copy(mbufs[i], tx->mbuf_pool, 0, UINT32_MAX); if (!copied) { dbg("%s(%s), failed to copy mbuf\n", __func__, tx->name); tx->stat_rtp_retransmit_fail_nobuf += bulk - i; @@ -115,8 +124,8 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx* tx, uint16_t seq, copy_mbufs[i] = copied; if (tx->payload_format == MT_RTP_PAYLOAD_FORMAT_RFC4175) { /* set the retransmit bit */ - struct st20_rfc4175_rtp_hdr* rtp = rte_pktmbuf_mtod_offset( - copied, struct st20_rfc4175_rtp_hdr*, sizeof(struct mt_udp_hdr)); + struct st20_rfc4175_rtp_hdr *rtp = rte_pktmbuf_mtod_offset( + copied, struct st20_rfc4175_rtp_hdr *, sizeof(struct mt_udp_hdr)); uint16_t line1_length = ntohs(rtp->row_length); rtp->row_length = htons(line1_length | ST20_RETRANSMIT); } @@ -129,7 +138,8 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx* tx, uint16_t seq, } ret = send; - dbg("%s(%s), ts 0x%x seq %u retransmit %u pkt(s)\n", __func__, tx->name, ts, seq, send); + dbg("%s(%s), ts 0x%x seq %u retransmit %u pkt(s)\n", __func__, tx->name, ts, + seq, send); rt_exit: tx->stat_rtp_retransmit_succ += send; @@ -138,8 +148,10 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx* tx, uint16_t seq, return ret; } -int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx* tx, struct mt_rtcp_hdr* rtcp) { - if (!tx->active) return 0; +int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx *tx, + struct mt_rtcp_hdr *rtcp) { + if (!tx->active) + return 0; if (rtcp->flags != 0x80) { err("%s(%s), wrong rtcp flags %u\n", __func__, tx->name, rtcp->flags); return -EIO; @@ -153,15 +165,15 @@ int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx* tx, struct mt_rtcp_hdr* rtcp tx->stat_nack_received++; uint16_t num_fcis = ntohs(rtcp->len) + 1 - sizeof(struct mt_rtcp_hdr) / 4; - struct mt_rtcp_fci* fci = rtcp->fci; + struct mt_rtcp_fci *fci = rtcp->fci; for (uint16_t i = 0; i < num_fcis; i++) { uint16_t start = ntohs(fci->start); uint16_t follow = ntohs(fci->follow); dbg("%s(%s), nack %u,%u\n", __func__, tx->name, start, follow); if (rtcp_tx_retransmit_rtp_packets(tx, start, follow + 1) < 0) { - dbg("%s(%s), failed to retransmit rtp packets %u,%u\n", __func__, tx->name, start, - follow); + dbg("%s(%s), failed to retransmit rtp packets %u,%u\n", __func__, + tx->name, start, follow); } fci++; @@ -171,20 +183,23 @@ int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx* tx, struct mt_rtcp_hdr* rtcp return 0; } -static int rtcp_rx_update_last_cont(struct mt_rtcp_rx* rx) { +static int rtcp_rx_update_last_cont(struct mt_rtcp_rx *rx) { uint16_t last_cont = rx->last_cont; uint16_t last_seq = rx->last_seq; /* find the last continuous seq */ for (uint16_t i = last_cont + 1; rtp_seq_num_cmp(i, last_seq) <= 0; i++) { - if (!mt_bitmap_test(rx->seq_bitmap, i % rx->seq_window_size)) break; + if (!mt_bitmap_test(rx->seq_bitmap, i % rx->seq_window_size)) + break; rx->last_cont = i; } return 0; } -int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx* rx, struct st_rfc3550_rtp_hdr* rtp) { - if (!rx->active) return 0; +int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx *rx, + struct st_rfc3550_rtp_hdr *rtp) { + if (!rx->active) + return 0; uint16_t seq = ntohs(rtp->seq_number); if (rx->ssrc == 0) { /* first received */ @@ -226,17 +241,19 @@ int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx* rx, struct st_rfc3550_rtp_hdr return 0; } -int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx) { - if (!rx->active) return 0; - struct mtl_main_impl* impl = rx->parent; +int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx) { + if (!rx->active) + return 0; + struct mtl_main_impl *impl = rx->parent; enum mtl_port port = rx->port; - struct rte_mbuf* pkt; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; + struct rte_mbuf *pkt; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; uint16_t num_fci = 0; uint64_t now = mt_get_tsc(impl); - if (now < rx->nacks_send_time) return 0; + if (now < rx->nacks_send_time) + return 0; rx->nacks_send_time = now + rx->nacks_send_interval; pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); @@ -245,7 +262,7 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx) { return -ENOMEM; } - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; @@ -253,16 +270,17 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx) { mt_mbuf_init_ipv4(pkt); pkt->data_len = sizeof(*hdr); - struct mt_rtcp_hdr* rtcp = - rte_pktmbuf_mtod_offset(pkt, struct mt_rtcp_hdr*, sizeof(*hdr)); - struct mt_rtcp_fci* fcis = &rtcp->fci[0]; + struct mt_rtcp_hdr *rtcp = + rte_pktmbuf_mtod_offset(pkt, struct mt_rtcp_hdr *, sizeof(*hdr)); + struct mt_rtcp_fci *fcis = &rtcp->fci[0]; /* check missing pkts with bitmap, update fci fields */ uint16_t seq = rx->last_cont + 1; uint16_t start = seq; uint16_t end = rx->last_seq - rx->seq_skip_window; uint16_t miss = 0; - bool end_state = mt_bitmap_test_and_set(rx->seq_bitmap, end % rx->seq_window_size); + bool end_state = + mt_bitmap_test_and_set(rx->seq_bitmap, end % rx->seq_window_size); while (rtp_seq_num_cmp(seq, end) <= 0) { if (!mt_bitmap_test(rx->seq_bitmap, seq % rx->seq_window_size)) { miss++; @@ -285,7 +303,8 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx) { } seq++; } - if (!end_state) mt_bitmap_test_and_unset(rx->seq_bitmap, end % rx->seq_window_size); + if (!end_state) + mt_bitmap_test_and_unset(rx->seq_bitmap, end % rx->seq_window_size); if (num_fci == 0) { rte_pktmbuf_free(pkt); return 0; @@ -298,12 +317,14 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx) { rtcp->ssrc = htonl(rx->ssrc); rte_memcpy(rtcp->name, "IMTL", 4); - pkt->data_len += sizeof(struct mt_rtcp_hdr) + num_fci * sizeof(struct mt_rtcp_fci); + pkt->data_len += + sizeof(struct mt_rtcp_hdr) + num_fci * sizeof(struct mt_rtcp_fci); pkt->pkt_len = pkt->data_len; /* update length */ ipv4->total_length = htons(pkt->pkt_len - sizeof(struct rte_ether_hdr)); - udp->dgram_len = htons(pkt->pkt_len - sizeof(struct rte_ether_hdr) - sizeof(*ipv4)); + udp->dgram_len = + htons(pkt->pkt_len - sizeof(struct rte_ether_hdr) - sizeof(*ipv4)); uint16_t send = mt_sys_queue_tx_burst(impl, port, &pkt, 1); if (send != 1) { @@ -317,19 +338,22 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx) { return 0; } -static int rtcp_tx_stat(void* priv) { - struct mt_rtcp_tx* tx = priv; +static int rtcp_tx_stat(void *priv) { + struct mt_rtcp_tx *tx = priv; - notice("%s(%s), rtp sent %u nack recv %u rtp retransmit succ %u\n", __func__, tx->name, - tx->stat_rtp_sent, tx->stat_nack_received, tx->stat_rtp_retransmit_succ); + notice("%s(%s), rtp sent %u nack recv %u rtp retransmit succ %u\n", __func__, + tx->name, tx->stat_rtp_sent, tx->stat_nack_received, + tx->stat_rtp_retransmit_succ); tx->stat_rtp_sent = 0; tx->stat_nack_received = 0; tx->stat_rtp_retransmit_succ = 0; if (tx->stat_rtp_retransmit_fail) { - notice("%s(%s), retransmit fail %u no mbuf %u read %u obsolete %u burst %u\n", - __func__, tx->name, tx->stat_rtp_retransmit_fail, - tx->stat_rtp_retransmit_fail_nobuf, tx->stat_rtp_retransmit_fail_read, - tx->stat_rtp_retransmit_fail_obsolete, tx->stat_rtp_retransmit_fail_burst); + notice( + "%s(%s), retransmit fail %u no mbuf %u read %u obsolete %u burst %u\n", + __func__, tx->name, tx->stat_rtp_retransmit_fail, + tx->stat_rtp_retransmit_fail_nobuf, tx->stat_rtp_retransmit_fail_read, + tx->stat_rtp_retransmit_fail_obsolete, + tx->stat_rtp_retransmit_fail_burst); tx->stat_rtp_retransmit_fail_nobuf = 0; tx->stat_rtp_retransmit_fail_read = 0; tx->stat_rtp_retransmit_fail_obsolete = 0; @@ -340,8 +364,8 @@ static int rtcp_tx_stat(void* priv) { return 0; } -static int rtcp_rx_stat(void* priv) { - struct mt_rtcp_rx* rx = priv; +static int rtcp_rx_stat(void *priv) { + struct mt_rtcp_rx *rx = priv; notice("%s(%s), rtp recv %u lost %u nack sent %u\n", __func__, rx->name, rx->stat_rtp_received, rx->stat_rtp_lost_detected, rx->stat_nack_sent); @@ -357,12 +381,12 @@ static int rtcp_rx_stat(void* priv) { return 0; } -struct mt_rtcp_tx* mt_rtcp_tx_create(struct mtl_main_impl* impl, - struct mt_rtcp_tx_ops* ops) { +struct mt_rtcp_tx *mt_rtcp_tx_create(struct mtl_main_impl *impl, + struct mt_rtcp_tx_ops *ops) { const enum mtl_port port = ops->port; - const char* name = ops->name; - struct mt_rtcp_tx* tx = - mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_tx), mt_socket_id(impl, port)); + const char *name = ops->name; + struct mt_rtcp_tx *tx = mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_tx), + mt_socket_id(impl, port)); if (!tx) { err("%s(%s), failed to allocate memory for mt_rtcp_tx\n", __func__, name); return NULL; @@ -372,14 +396,14 @@ struct mt_rtcp_tx* mt_rtcp_tx_create(struct mtl_main_impl* impl, tx->payload_format = ops->payload_format; if (ops->buffer_size < mt_if_nb_tx_desc(impl, port)) { - warn("%s(%s), buffer_size(%u) is small, adjust to nb_tx_desc(%u)\n", __func__, name, - ops->buffer_size, mt_if_nb_tx_desc(impl, port)); + warn("%s(%s), buffer_size(%u) is small, adjust to nb_tx_desc(%u)\n", + __func__, name, ops->buffer_size, mt_if_nb_tx_desc(impl, port)); ops->buffer_size = mt_if_nb_tx_desc(impl, port); } uint32_t n = ops->buffer_size + mt_if_nb_tx_desc(impl, port); - struct rte_mempool* pool = - mt_mempool_create(impl, port, name, n, MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); + struct rte_mempool *pool = mt_mempool_create( + impl, port, name, n, MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); if (!pool) { err("%s(%s), failed to create mempool for mt_rtcp_tx\n", __func__, name); mt_rtcp_tx_free(tx); @@ -391,7 +415,7 @@ struct mt_rtcp_tx* mt_rtcp_tx_create(struct mtl_main_impl* impl, memset(&flow, 0, sizeof(flow)); mtl_memcpy(&flow.dip_addr, &ops->udp_hdr->ipv4.dst_addr, MTL_IP_ADDR_LEN); flow.dst_port = ntohs(ops->udp_hdr->udp.dst_port) - 1; /* rtp port */ - struct mt_txq_entry* q = mt_txq_get(impl, port, &flow); + struct mt_txq_entry *q = mt_txq_get(impl, port, &flow); if (!q) { err("%s(%s), failed to create queue for mt_rtcp_tx\n", __func__, name); mt_rtcp_tx_free(tx); @@ -399,7 +423,8 @@ struct mt_rtcp_tx* mt_rtcp_tx_create(struct mtl_main_impl* impl, } tx->mbuf_queue = q; - struct mt_u64_fifo* ring = mt_u64_fifo_init(ops->buffer_size, mt_socket_id(impl, port)); + struct mt_u64_fifo *ring = + mt_u64_fifo_init(ops->buffer_size, mt_socket_id(impl, port)); if (!ring) { err("%s(%s), failed to create ring for mt_rtcp_tx\n", __func__, name); mt_rtcp_tx_free(tx); @@ -419,8 +444,8 @@ struct mt_rtcp_tx* mt_rtcp_tx_create(struct mtl_main_impl* impl, return tx; } -void mt_rtcp_tx_free(struct mt_rtcp_tx* tx) { - struct mtl_main_impl* impl = tx->parent; +void mt_rtcp_tx_free(struct mt_rtcp_tx *tx) { + struct mtl_main_impl *impl = tx->parent; enum mtl_port port = tx->port; mt_stat_unregister(impl, rtcp_tx_stat, tx); @@ -449,12 +474,12 @@ void mt_rtcp_tx_free(struct mt_rtcp_tx* tx) { mt_rte_free(tx); } -struct mt_rtcp_rx* mt_rtcp_rx_create(struct mtl_main_impl* impl, - struct mt_rtcp_rx_ops* ops) { +struct mt_rtcp_rx *mt_rtcp_rx_create(struct mtl_main_impl *impl, + struct mt_rtcp_rx_ops *ops) { const enum mtl_port port = ops->port; - const char* name = ops->name; - struct mt_rtcp_rx* rx = - mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_rx), mt_socket_id(impl, port)); + const char *name = ops->name; + struct mt_rtcp_rx *rx = mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_rx), + mt_socket_id(impl, port)); if (!rx) { err("%s(%s), failed to allocate memory for mt_rtcp_rx\n", __func__, name); return NULL; @@ -468,8 +493,8 @@ struct mt_rtcp_rx* mt_rtcp_rx_create(struct mtl_main_impl* impl, snprintf(rx->name, sizeof(rx->name) - 1, "%s", name); rte_memcpy(&rx->udp_hdr, ops->udp_hdr, sizeof(rx->udp_hdr)); - uint8_t* seq_bitmap = mt_rte_zmalloc_socket(sizeof(uint8_t) * ops->seq_bitmap_size, - mt_socket_id(impl, port)); + uint8_t *seq_bitmap = mt_rte_zmalloc_socket( + sizeof(uint8_t) * ops->seq_bitmap_size, mt_socket_id(impl, port)); if (!seq_bitmap) { err("%s(%s), failed to allocate memory for seq_bitmap\n", __func__, name); mt_rtcp_rx_free(rx); @@ -486,14 +511,15 @@ struct mt_rtcp_rx* mt_rtcp_rx_create(struct mtl_main_impl* impl, return rx; } -void mt_rtcp_rx_free(struct mt_rtcp_rx* rx) { +void mt_rtcp_rx_free(struct mt_rtcp_rx *rx) { mt_stat_unregister(rx->parent, rtcp_rx_stat, rx); rx->active = false; rtcp_rx_stat(rx); - if (rx->seq_bitmap) mt_rte_free(rx->seq_bitmap); + if (rx->seq_bitmap) + mt_rte_free(rx->seq_bitmap); mt_rte_free(rx); } \ No newline at end of file diff --git a/lib/src/mt_rtcp.h b/lib/src/mt_rtcp.h index c1081bc9d..a3da8e84a 100644 --- a/lib/src/mt_rtcp.h +++ b/lib/src/mt_rtcp.h @@ -34,29 +34,31 @@ enum mt_rtp_payload_format { }; struct mt_rtcp_tx_ops { - const char* name; /* short and unique name for each session */ - struct mt_udp_hdr* udp_hdr; /* headers including eth, ipv4 and udp */ - uint32_t ssrc; /* ssrc of rtp session */ - uint16_t buffer_size; /* max number of buffered rtp packets */ - enum mtl_port port; /* port of rtp session */ + const char *name; /* short and unique name for each session */ + struct mt_udp_hdr *udp_hdr; /* headers including eth, ipv4 and udp */ + uint32_t ssrc; /* ssrc of rtp session */ + uint16_t buffer_size; /* max number of buffered rtp packets */ + enum mtl_port port; /* port of rtp session */ enum mt_rtp_payload_format payload_format; /* payload format */ }; struct mt_rtcp_rx_ops { - const char* name; /* short and unique name for each session */ - struct mt_udp_hdr* udp_hdr; /* headers including eth, ipv4 and udp */ + const char *name; /* short and unique name for each session */ + struct mt_udp_hdr *udp_hdr; /* headers including eth, ipv4 and udp */ uint64_t nacks_send_interval; /* nack sending interval */ enum mtl_port port; /* port of rtp session */ - uint16_t seq_bitmap_size; /* bitmap size of detecting window, can hold n * 8 seq */ - uint16_t seq_skip_window; /* skip some seq to handle out of order while detecting */ + uint16_t + seq_bitmap_size; /* bitmap size of detecting window, can hold n * 8 seq */ + uint16_t seq_skip_window; /* skip some seq to handle out of order while + detecting */ }; struct mt_rtcp_tx { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; - struct mt_u64_fifo* mbuf_ring; - struct rte_mempool* mbuf_pool; - struct mt_txq_entry* mbuf_queue; + struct mt_u64_fifo *mbuf_ring; + struct rte_mempool *mbuf_pool; + struct mt_txq_entry *mbuf_queue; struct mt_udp_hdr udp_hdr; char name[MT_RTCP_MAX_NAME_LEN]; uint32_t ssrc; @@ -77,7 +79,7 @@ struct mt_rtcp_tx { }; struct mt_rtcp_rx { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; struct mt_udp_hdr udp_hdr; char name[MT_RTCP_MAX_NAME_LEN]; @@ -89,7 +91,7 @@ struct mt_rtcp_rx { uint16_t last_seq; uint16_t last_cont; - uint8_t* seq_bitmap; + uint8_t *seq_bitmap; uint16_t seq_window_size; uint16_t seq_skip_window; @@ -100,19 +102,21 @@ struct mt_rtcp_rx { uint32_t stat_nack_drop_exceed; }; -struct mt_rtcp_tx* mt_rtcp_tx_create(struct mtl_main_impl* mtl, - struct mt_rtcp_tx_ops* ops); -void mt_rtcp_tx_free(struct mt_rtcp_tx* tx); +struct mt_rtcp_tx *mt_rtcp_tx_create(struct mtl_main_impl *mtl, + struct mt_rtcp_tx_ops *ops); +void mt_rtcp_tx_free(struct mt_rtcp_tx *tx); -struct mt_rtcp_rx* mt_rtcp_rx_create(struct mtl_main_impl* mtl, - struct mt_rtcp_rx_ops* ops); -void mt_rtcp_rx_free(struct mt_rtcp_rx* rx); +struct mt_rtcp_rx *mt_rtcp_rx_create(struct mtl_main_impl *mtl, + struct mt_rtcp_rx_ops *ops); +void mt_rtcp_rx_free(struct mt_rtcp_rx *rx); -int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx* tx, struct rte_mbuf** mbufs, - unsigned int bulk); -int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx* tx, struct mt_rtcp_hdr* rtcp); +int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx *tx, + struct rte_mbuf **mbufs, unsigned int bulk); +int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx *tx, + struct mt_rtcp_hdr *rtcp); -int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx* rx, struct st_rfc3550_rtp_hdr* rtp); -int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx* rx); +int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx *rx, + struct st_rfc3550_rtp_hdr *rtp); +int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx); #endif \ No newline at end of file diff --git a/lib/src/mt_sch.c b/lib/src/mt_sch.c index 55c4fde32..7b684f2b8 100644 --- a/lib/src/mt_sch.c +++ b/lib/src/mt_sch.c @@ -17,51 +17,52 @@ #include "st2110/st_tx_audio_session.h" #include "st2110/st_tx_video_session.h" -static inline void sch_mgr_lock(struct mt_sch_mgr* mgr) { +static inline void sch_mgr_lock(struct mt_sch_mgr *mgr) { mt_pthread_mutex_lock(&mgr->mgr_mutex); } -static inline void sch_mgr_unlock(struct mt_sch_mgr* mgr) { +static inline void sch_mgr_unlock(struct mt_sch_mgr *mgr) { mt_pthread_mutex_unlock(&mgr->mgr_mutex); } -static inline void sch_lock(struct mtl_sch_impl* sch) { +static inline void sch_lock(struct mtl_sch_impl *sch) { mt_pthread_mutex_lock(&sch->mutex); } -static inline void sch_unlock(struct mtl_sch_impl* sch) { +static inline void sch_unlock(struct mtl_sch_impl *sch) { mt_pthread_mutex_unlock(&sch->mutex); } -static const char* lcore_type_names[MT_LCORE_TYPE_MAX] = { +static const char *lcore_type_names[MT_LCORE_TYPE_MAX] = { "lib_sch", "lib_tap", "lib_rxv_ring", "app_allocated", "lib_app_sch", }; -static const char* lcore_type_name(enum mt_lcore_type type) { +static const char *lcore_type_name(enum mt_lcore_type type) { if (type >= MT_LCORE_TYPE_SCH && type < MT_LCORE_TYPE_MAX) return lcore_type_names[type]; else return "unknown"; } -static void sch_sleep_wakeup(struct mtl_sch_impl* sch) { +static void sch_sleep_wakeup(struct mtl_sch_impl *sch) { mt_pthread_mutex_lock(&sch->sleep_wake_mutex); mt_pthread_cond_signal(&sch->sleep_wake_cond); mt_pthread_mutex_unlock(&sch->sleep_wake_mutex); } -static void sch_sleep_alarm_handler(void* param) { - struct mtl_sch_impl* sch = param; +static void sch_sleep_alarm_handler(void *param) { + struct mtl_sch_impl *sch = param; sch_sleep_wakeup(sch); } -static int sch_tasklet_sleep(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { +static int sch_tasklet_sleep(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { /* get sleep us */ uint64_t sleep_us = mt_sch_default_sleep_us(impl); uint64_t force_sleep_us = mt_sch_force_sleep_us(impl); int num_tasklet = sch->max_tasklet_idx; - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; uint64_t advice_sleep_us; if (force_sleep_us) { @@ -69,9 +70,11 @@ static int sch_tasklet_sleep(struct mtl_main_impl* impl, struct mtl_sch_impl* sc } else { for (int i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) continue; + if (!tasklet) + continue; advice_sleep_us = tasklet->ops.advice_sleep_us; - if (advice_sleep_us && (advice_sleep_us < sleep_us)) sleep_us = advice_sleep_us; + if (advice_sleep_us && (advice_sleep_us < sleep_us)) + sleep_us = advice_sleep_us; } } dbg("%s(%d), sleep_us %" PRIu64 "\n", __func__, sch->idx, sleep_us); @@ -84,7 +87,8 @@ static int sch_tasklet_sleep(struct mtl_main_impl* impl, struct mtl_sch_impl* sc rte_eal_alarm_set(sleep_us, sch_sleep_alarm_handler, sch); mt_pthread_mutex_lock(&sch->sleep_wake_mutex); /* timeout 1s */ - mt_pthread_cond_timedwait_ns(&sch->sleep_wake_cond, &sch->sleep_wake_mutex, NS_PER_S); + mt_pthread_cond_timedwait_ns(&sch->sleep_wake_cond, &sch->sleep_wake_mutex, + NS_PER_S); mt_pthread_mutex_unlock(&sch->sleep_wake_mutex); } uint64_t end = mt_get_tsc(impl); @@ -110,18 +114,19 @@ static int sch_tasklet_sleep(struct mtl_main_impl* impl, struct mtl_sch_impl* sc return 0; } -static bool sch_tasklet_time_measure(struct mtl_main_impl* impl) { +static bool sch_tasklet_time_measure(struct mtl_main_impl *impl) { bool enabled = mt_user_tasklet_time_measure(impl); - if (MT_USDT_TASKLET_TIME_MEASURE_ENABLED()) enabled = true; + if (MT_USDT_TASKLET_TIME_MEASURE_ENABLED()) + enabled = true; return enabled; } -static int sch_tasklet_func(struct mtl_sch_impl* sch) { - struct mtl_main_impl* impl = sch->parent; +static int sch_tasklet_func(struct mtl_sch_impl *sch) { + struct mtl_main_impl *impl = sch->parent; int idx = sch->idx; int num_tasklet, i; - struct mtl_tasklet_ops* ops; - struct mt_sch_tasklet_impl* tasklet; + struct mtl_tasklet_ops *ops; + struct mt_sch_tasklet_impl *tasklet; uint64_t loop_cal_start_ns; uint64_t loop_cnt = 0; @@ -135,9 +140,11 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { for (i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) continue; + if (!tasklet) + continue; ops = &tasklet->ops; - if (ops->start) ops->start(ops->priv); + if (ops->start) + ops->start(ops->priv); } sch->sleep_ratio_start_ns = mt_get_tsc(impl); @@ -148,12 +155,14 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { bool time_measure = sch_tasklet_time_measure(impl); uint64_t tm_sch_tsc_s = 0; /* for sch time_measure */ - if (time_measure) tm_sch_tsc_s = mt_get_tsc(impl); + if (time_measure) + tm_sch_tsc_s = mt_get_tsc(impl); num_tasklet = sch->max_tasklet_idx; for (i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) continue; + if (!tasklet) + continue; if (tasklet->request_exit) { tasklet->ack_exit = true; sch->tasklet[i] = NULL; @@ -163,7 +172,8 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { ops = &tasklet->ops; uint64_t tm_tasklet_tsc_s = 0; /* for tasklet time_measure */ - if (time_measure) tm_tasklet_tsc_s = mt_get_tsc(impl); + if (time_measure) + tm_tasklet_tsc_s = mt_get_tsc(impl); pending += ops->handler(ops->priv); if (time_measure) { uint64_t delta_ns = mt_get_tsc(impl) - tm_tasklet_tsc_s; @@ -192,9 +202,11 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { num_tasklet = sch->max_tasklet_idx; for (i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) continue; + if (!tasklet) + continue; ops = &tasklet->ops; - if (ops->stop) ops->stop(ops->priv); + if (ops->stop) + ops->stop(ops->priv); } rte_atomic32_set(&sch->stopped, 1); @@ -202,22 +214,22 @@ static int sch_tasklet_func(struct mtl_sch_impl* sch) { return 0; } -static int sch_tasklet_lcore(void* arg) { - struct mtl_sch_impl* sch = arg; +static int sch_tasklet_lcore(void *arg) { + struct mtl_sch_impl *sch = arg; sch->tid = pthread_self(); sch->t_pid = rte_sys_gettid(); sch_tasklet_func(sch); return 0; } -static void* sch_tasklet_thread(void* arg) { - struct mtl_sch_impl* sch = arg; +static void *sch_tasklet_thread(void *arg) { + struct mtl_sch_impl *sch = arg; sch->t_pid = rte_sys_gettid(); sch_tasklet_func(sch); return NULL; } -static int sch_start(struct mtl_sch_impl* sch) { +static int sch_start(struct mtl_sch_impl *sch) { int idx = sch->idx; int ret; @@ -234,10 +246,11 @@ static int sch_start(struct mtl_sch_impl* sch) { rte_atomic32_set(&sch->stopped, 0); if (!sch->run_in_thread) { - ret = mt_sch_get_lcore( - sch->parent, &sch->lcore, - (sch->type == MT_SCH_TYPE_APP) ? MT_LCORE_TYPE_SCH_USER : MT_LCORE_TYPE_SCH, - mt_sch_socket_id(sch)); + ret = + mt_sch_get_lcore(sch->parent, &sch->lcore, + (sch->type == MT_SCH_TYPE_APP) ? MT_LCORE_TYPE_SCH_USER + : MT_LCORE_TYPE_SCH, + mt_sch_socket_id(sch)); if (ret < 0) { err("%s(%d), get lcore fail %d\n", __func__, idx, ret); sch_unlock(sch); @@ -263,7 +276,7 @@ static int sch_start(struct mtl_sch_impl* sch) { return 0; } -static int sch_stop(struct mtl_sch_impl* sch) { +static int sch_stop(struct mtl_sch_impl *sch) { int idx = sch->idx; sch_lock(sch); @@ -293,14 +306,16 @@ static int sch_stop(struct mtl_sch_impl* sch) { return 0; } -static struct mtl_sch_impl* sch_request(struct mtl_main_impl* impl, enum mt_sch_type type, - mt_sch_mask_t mask, struct mtl_sch_ops* ops, - int socket) { - struct mtl_sch_impl* sch; +static struct mtl_sch_impl *sch_request(struct mtl_main_impl *impl, + enum mt_sch_type type, + mt_sch_mask_t mask, + struct mtl_sch_ops *ops, int socket) { + struct mtl_sch_impl *sch; for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { /* mask check */ - if (!(mask & MTL_BIT64(sch_idx))) continue; + if (!(mask & MTL_BIT64(sch_idx))) + continue; sch = mt_sch_instance(impl, sch_idx); @@ -316,10 +331,11 @@ static struct mtl_sch_impl* sch_request(struct mtl_main_impl* impl, enum mt_sch_ sch->nb_tasklets = ops->nb_tasklets; else sch->nb_tasklets = impl->tasklets_nb_per_sch; - sch->tasklet = - mt_rte_zmalloc_socket(sizeof(*sch->tasklet) * sch->nb_tasklets, socket); + sch->tasklet = mt_rte_zmalloc_socket( + sizeof(*sch->tasklet) * sch->nb_tasklets, socket); if (!sch->tasklet) { - err("%s(%d), %u tasklet malloc fail\n", __func__, sch_idx, sch->nb_tasklets); + err("%s(%d), %u tasklet malloc fail\n", __func__, sch_idx, + sch->nb_tasklets); sch_unlock(sch); return NULL; } @@ -329,8 +345,8 @@ static struct mtl_sch_impl* sch_request(struct mtl_main_impl* impl, enum mt_sch_ /* set the socket id */ sch->socket_id = socket; - info("%s(%d), name %s with %u tasklets, type %d socket %d\n", __func__, sch_idx, - sch->name, sch->nb_tasklets, type, sch->socket_id); + info("%s(%d), name %s with %u tasklets, type %d socket %d\n", __func__, + sch_idx, sch->name, sch->nb_tasklets, type, sch->socket_id); return sch; } sch_unlock(sch); @@ -340,7 +356,7 @@ static struct mtl_sch_impl* sch_request(struct mtl_main_impl* impl, enum mt_sch_ return NULL; } -static int sch_free(struct mtl_sch_impl* sch) { +static int sch_free(struct mtl_sch_impl *sch) { int idx = sch->idx; if (!mt_sch_is_active(sch)) { @@ -369,7 +385,7 @@ static int sch_free(struct mtl_sch_impl* sch) { return 0; } -static int sch_free_quota(struct mtl_sch_impl* sch, int quota_mbs) { +static int sch_free_quota(struct mtl_sch_impl *sch, int quota_mbs) { int idx = sch->idx; if (!mt_sch_is_active(sch)) { @@ -389,12 +405,13 @@ static int sch_free_quota(struct mtl_sch_impl* sch, int quota_mbs) { return 0; } -static bool sch_is_capable(struct mtl_sch_impl* sch, int quota_mbs, +static bool sch_is_capable(struct mtl_sch_impl *sch, int quota_mbs, enum mt_sch_type type) { if (!quota_mbs) { /* zero quota_mbs can be applied to any type */ return true; } - if ((type == MT_SCH_TYPE_RX_VIDEO_ONLY) && (sch->type == MT_SCH_TYPE_DEFAULT)) { + if ((type == MT_SCH_TYPE_RX_VIDEO_ONLY) && + (sch->type == MT_SCH_TYPE_DEFAULT)) { sch_lock(sch); if (!sch->data_quota_mbs_total) { /* change type to rx video only since no quota on this */ @@ -410,19 +427,22 @@ static bool sch_is_capable(struct mtl_sch_impl* sch, int quota_mbs, return true; } -static int sch_stat(void* priv) { - struct mtl_sch_impl* sch = priv; +static int sch_stat(void *priv) { + struct mtl_sch_impl *sch = priv; int num_tasklet = sch->max_tasklet_idx; - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; int idx = sch->idx; - if (!mt_sch_is_active(sch)) return 0; + if (!mt_sch_is_active(sch)) + return 0; - notice("SCH(%d:%s): tasklets %d, lcore %u(t_pid: %d), avg loop %" PRIu64 " ns\n", idx, - sch->name, num_tasklet, sch->lcore, sch->t_pid, mt_sch_avg_ns_loop(sch)); + notice("SCH(%d:%s): tasklets %d, lcore %u(t_pid: %d), avg loop %" PRIu64 + " ns\n", + idx, sch->name, num_tasklet, sch->lcore, sch->t_pid, + mt_sch_avg_ns_loop(sch)); /* print the stat time info */ - struct mt_stat_u64* stat_time = &sch->stat_time; + struct mt_stat_u64 *stat_time = &sch->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; notice("SCH(%d): time avg %.2fus max %.2fus min %.2fus\n", idx, @@ -432,22 +452,24 @@ static int sch_stat(void* priv) { } for (int i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) continue; + if (!tasklet) + continue; dbg("SCH(%d): tasklet %s at %d\n", idx, tasklet->name, i); stat_time = &tasklet->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("SCH(%d,%d): tasklet %s, avg %.2fus max %.2fus min %.2fus\n", idx, i, - tasklet->name, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + notice("SCH(%d,%d): tasklet %s, avg %.2fus max %.2fus min %.2fus\n", idx, + i, tasklet->name, (float)avg_ns / NS_PER_US, + (float)stat_time->max / NS_PER_US, (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } } if (sch->allow_sleep) { - notice("SCH(%d): sleep %fms(ratio:%f), cnt %u, min %" PRIu64 "us, max %" PRIu64 - "us\n", + notice("SCH(%d): sleep %fms(ratio:%f), cnt %u, min %" PRIu64 + "us, max %" PRIu64 "us\n", idx, (double)sch->stat_sleep_ns / NS_PER_MS, sch->sleep_ratio_score, sch->stat_sleep_cnt, sch->stat_sleep_ns_min / NS_PER_US, sch->stat_sleep_ns_max / NS_PER_US); @@ -463,13 +485,14 @@ static int sch_stat(void* priv) { return 0; } -static int sch_filelock_lock(struct mt_sch_mgr* mgr) { +static int sch_filelock_lock(struct mt_sch_mgr *mgr) { int fd = open(MT_FLOCK_PATH, O_RDONLY | O_CREAT, 0666); if (fd < 0) { /* sometimes may fail due to user permission, try open read-only */ fd = open(MT_FLOCK_PATH, O_RDONLY); if (fd < 0) { - err("%s, failed to open %s, %s\n", __func__, MT_FLOCK_PATH, strerror(errno)); + err("%s, failed to open %s, %s\n", __func__, MT_FLOCK_PATH, + strerror(errno)); return -EIO; } } @@ -485,7 +508,7 @@ static int sch_filelock_lock(struct mt_sch_mgr* mgr) { return 0; } -static int sch_filelock_unlock(struct mt_sch_mgr* mgr) { +static int sch_filelock_unlock(struct mt_sch_mgr *mgr) { int fd = mgr->lcore_lock_fd; if (fd < 0) { @@ -502,8 +525,8 @@ static int sch_filelock_unlock(struct mt_sch_mgr* mgr) { return 0; } -static int sch_lcore_shm_init(struct mt_lcore_mgr* mgr, bool clear_on_first) { - struct mt_lcore_shm* lcore_shm = NULL; +static int sch_lcore_shm_init(struct mt_lcore_mgr *mgr, bool clear_on_first) { + struct mt_lcore_shm *lcore_shm = NULL; int ret; mgr->lcore_shm_id = -1; @@ -515,14 +538,16 @@ static int sch_lcore_shm_init(struct mt_lcore_mgr* mgr, bool clear_on_first) { } int shm_id = shmget(key, sizeof(*lcore_shm), 0666 | IPC_CREAT); if (shm_id < 0) { - err("%s, can not get shared memory for lcore, %s\n", __func__, strerror(errno)); + err("%s, can not get shared memory for lcore, %s\n", __func__, + strerror(errno)); return -EIO; } mgr->lcore_shm_id = shm_id; lcore_shm = shmat(shm_id, NULL, 0); - if (lcore_shm == (void*)-1) { - err("%s, can not attach shared memory for lcore, %s\n", __func__, strerror(errno)); + if (lcore_shm == (void *)-1) { + err("%s, can not attach shared memory for lcore, %s\n", __func__, + strerror(errno)); return -EIO; } @@ -540,17 +565,18 @@ static int sch_lcore_shm_init(struct mt_lcore_mgr* mgr, bool clear_on_first) { } mgr->lcore_shm = lcore_shm; - info("%s, shared memory attached at %p nattch %d shm_id %d key 0x%x\n", __func__, - mgr->lcore_shm, (int)stat.shm_nattch, shm_id, (int)key); + info("%s, shared memory attached at %p nattch %d shm_id %d key 0x%x\n", + __func__, mgr->lcore_shm, (int)stat.shm_nattch, shm_id, (int)key); return 0; } -static int sch_lcore_shm_uinit(struct mt_lcore_mgr* mgr) { +static int sch_lcore_shm_uinit(struct mt_lcore_mgr *mgr) { int ret; if (mgr->lcore_shm) { ret = shmdt(mgr->lcore_shm); - if (ret < 0) err("%s, shared memory detach failed, %s\n", __func__, strerror(errno)); + if (ret < 0) + err("%s, shared memory detach failed, %s\n", __func__, strerror(errno)); mgr->lcore_shm = NULL; } @@ -564,7 +590,8 @@ static int sch_lcore_shm_uinit(struct mt_lcore_mgr* mgr) { notice("%s, remove shared memory as we are the last user\n", __func__); ret = shmctl(mgr->lcore_shm_id, IPC_RMID, NULL); if (ret < 0) { - warn("%s, can not remove shared memory, %s\n", __func__, strerror(errno)); + warn("%s, can not remove shared memory, %s\n", __func__, + strerror(errno)); } } } @@ -574,7 +601,8 @@ static int sch_lcore_shm_uinit(struct mt_lcore_mgr* mgr) { return 0; } -static int sch_uinit_lcores(struct mtl_main_impl* impl, struct mt_sch_mgr* mgr) { +static int sch_uinit_lcores(struct mtl_main_impl *impl, + struct mt_sch_mgr *mgr) { int ret; for (unsigned int lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { @@ -604,7 +632,7 @@ static int sch_uinit_lcores(struct mtl_main_impl* impl, struct mt_sch_mgr* mgr) return 0; } -static int sch_init_lcores(struct mt_sch_mgr* mgr) { +static int sch_init_lcores(struct mt_sch_mgr *mgr) { int ret; if (mgr->lcore_mgr.lcore_shm) { @@ -635,19 +663,21 @@ static int sch_init_lcores(struct mt_sch_mgr* mgr) { static inline bool sch_socket_match(int cpu_socket, int dev_socket, bool skip_numa_check) { - if (skip_numa_check) return true; + if (skip_numa_check) + return true; return mt_socket_match(cpu_socket, dev_socket); } -int mt_sch_get_lcore(struct mtl_main_impl* impl, unsigned int* lcore, +int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, enum mt_lcore_type type, int socket) { unsigned int cur_lcore; int ret; bool skip_numa_check = false; - struct mt_sch_mgr* mgr = mt_sch_get_mgr(impl); + struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); int tried = 0; - if (mt_user_not_bind_numa(impl)) skip_numa_check = true; + if (mt_user_not_bind_numa(impl)) + skip_numa_check = true; again: cur_lcore = 0; @@ -655,7 +685,8 @@ int mt_sch_get_lcore(struct mtl_main_impl* impl, unsigned int* lcore, do { cur_lcore = rte_get_next_lcore(cur_lcore, 1, 0); if ((cur_lcore < RTE_MAX_LCORE) && - sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, skip_numa_check)) { + sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, + skip_numa_check)) { ret = mt_instance_get_lcore(impl, cur_lcore); if (ret == 0) { *lcore = cur_lcore; @@ -663,18 +694,18 @@ int mt_sch_get_lcore(struct mtl_main_impl* impl, unsigned int* lcore, /* set local lcores info */ mgr->local_lcores_active[cur_lcore] = true; mgr->local_lcores_type[cur_lcore] = type; - info("%s, succ on manager lcore %d for %s socket %d\n", __func__, cur_lcore, - lcore_type_name(type), socket); + info("%s, succ on manager lcore %d for %s socket %d\n", __func__, + cur_lcore, lcore_type_name(type), socket); return 0; } } tried++; } while (cur_lcore < RTE_MAX_LCORE); } else { - struct mt_user_info* info = &impl->u_info; + struct mt_user_info *info = &impl->u_info; - struct mt_lcore_shm* lcore_shm = mgr->lcore_mgr.lcore_shm; - struct mt_lcore_shm_entry* shm_entry; + struct mt_lcore_shm *lcore_shm = mgr->lcore_mgr.lcore_shm; + struct mt_lcore_shm_entry *shm_entry; ret = sch_filelock_lock(mgr); if (ret < 0) { @@ -687,11 +718,12 @@ int mt_sch_get_lcore(struct mtl_main_impl* impl, unsigned int* lcore, shm_entry = &lcore_shm->lcores_info[cur_lcore]; if ((cur_lcore < RTE_MAX_LCORE) && - sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, skip_numa_check)) { + sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, + skip_numa_check)) { if (!shm_entry->active) { *lcore = cur_lcore; shm_entry->active = true; - struct mt_user_info* u_info = &shm_entry->u_info; + struct mt_user_info *u_info = &shm_entry->u_info; strncpy(u_info->hostname, info->hostname, sizeof(u_info->hostname)); strncpy(u_info->user, info->user, sizeof(u_info->user)); strncpy(u_info->comm, info->comm, sizeof(u_info->comm)); @@ -703,8 +735,8 @@ int mt_sch_get_lcore(struct mtl_main_impl* impl, unsigned int* lcore, mgr->local_lcores_active[cur_lcore] = true; mgr->local_lcores_type[cur_lcore] = type; ret = sch_filelock_unlock(mgr); - info("%s, succ on shm lcore %d for %s socket %d\n", __func__, cur_lcore, - lcore_type_name(type), socket); + info("%s, succ on shm lcore %d for %s socket %d\n", __func__, + cur_lcore, lcore_type_name(type), socket); if (ret < 0) { err("%s, sch_filelock_unlock fail\n", __func__); return ret; @@ -719,20 +751,21 @@ int mt_sch_get_lcore(struct mtl_main_impl* impl, unsigned int* lcore, } if (!skip_numa_check && mt_user_across_numa_core(impl)) { - warn("%s, can't find available lcore from socket %d, try with other numa cpu\n", + warn("%s, can't find available lcore from socket %d, try with other numa " + "cpu\n", __func__, socket); skip_numa_check = true; goto again; } - err("%s, no available lcore, type %s tried %d\n", __func__, lcore_type_name(type), - tried); + err("%s, no available lcore, type %s tried %d\n", __func__, + lcore_type_name(type), tried); return -EIO; } -int mt_sch_put_lcore(struct mtl_main_impl* impl, unsigned int lcore) { +int mt_sch_put_lcore(struct mtl_main_impl *impl, unsigned int lcore) { int ret; - struct mt_sch_mgr* mgr = mt_sch_get_mgr(impl); + struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); if (mt_is_manager_connected(impl)) { ret = mt_instance_put_lcore(impl, lcore); @@ -751,7 +784,7 @@ int mt_sch_put_lcore(struct mtl_main_impl* impl, unsigned int lcore) { return ret; } } else { - struct mt_lcore_shm* lcore_shm = mgr->lcore_mgr.lcore_shm; + struct mt_lcore_shm *lcore_shm = mgr->lcore_mgr.lcore_shm; if (lcore >= RTE_MAX_LCORE) { err("%s, invalid lcore %d\n", __func__, lcore); @@ -791,16 +824,17 @@ int mt_sch_put_lcore(struct mtl_main_impl* impl, unsigned int lcore) { return ret; } -bool mt_sch_lcore_valid(struct mtl_main_impl* impl, unsigned int lcore) { - struct mt_sch_mgr* mgr = mt_sch_get_mgr(impl); - struct mt_lcore_shm* lcore_shm = mgr->lcore_mgr.lcore_shm; +bool mt_sch_lcore_valid(struct mtl_main_impl *impl, unsigned int lcore) { + struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); + struct mt_lcore_shm *lcore_shm = mgr->lcore_mgr.lcore_shm; if (lcore >= RTE_MAX_LCORE) { err("%s, invalid lcore %d\n", __func__, lcore); return -EIO; } - if (mt_is_manager_connected(impl)) return true; + if (mt_is_manager_connected(impl)) + return true; if (!lcore_shm) { err("%s, no lcore shm attached\n", __func__); @@ -811,7 +845,7 @@ bool mt_sch_lcore_valid(struct mtl_main_impl* impl, unsigned int lcore) { } int mtl_sch_unregister_tasklet(mtl_tasklet_handle tasklet) { - struct mtl_sch_impl* sch = tasklet->sch; + struct mtl_sch_impl *sch = tasklet->sch; int sch_idx = sch->idx; int idx = tasklet->idx; @@ -826,16 +860,16 @@ int mtl_sch_unregister_tasklet(mtl_tasklet_handle tasklet) { if (mt_sch_started(sch)) { int retry = 0; /* wait sch ack this exit */ - dbg("%s(%d), tasklet %s(%d) runtime unregistered\n", __func__, sch_idx, tasklet->name, - idx); + dbg("%s(%d), tasklet %s(%d) runtime unregistered\n", __func__, sch_idx, + tasklet->name, idx); tasklet->ack_exit = false; tasklet->request_exit = true; do { mt_sleep_ms(1); retry++; if (retry > 1000) { - err("%s(%d), tasklet %s(%d) runtime unregistered timeout\n", __func__, sch_idx, - tasklet->name, idx); + err("%s(%d), tasklet %s(%d) runtime unregistered timeout\n", __func__, + sch_idx, tasklet->name, idx); sch_unlock(sch); return -EIO; } @@ -843,18 +877,21 @@ int mtl_sch_unregister_tasklet(mtl_tasklet_handle tasklet) { info("%s(%d), tasklet %s(%d) unregistered, retry %d\n", __func__, sch_idx, tasklet->name, idx, retry); /* call the stop for runtime path */ - if (tasklet->ops.stop) tasklet->ops.stop(tasklet->ops.priv); + if (tasklet->ops.stop) + tasklet->ops.stop(tasklet->ops.priv); } else { /* safe to directly remove */ sch->tasklet[idx] = NULL; - info("%s(%d), tasklet %s(%d) unregistered\n", __func__, sch_idx, tasklet->name, idx); + info("%s(%d), tasklet %s(%d) unregistered\n", __func__, sch_idx, + tasklet->name, idx); } mt_rte_free(tasklet); int max_idx = 0; for (int i = 0; i < sch->nb_tasklets; i++) { - if (sch->tasklet[i]) max_idx = i + 1; + if (sch->tasklet[i]) + max_idx = i + 1; } sch->max_tasklet_idx = max_idx; @@ -862,16 +899,18 @@ int mtl_sch_unregister_tasklet(mtl_tasklet_handle tasklet) { return 0; } -mtl_tasklet_handle mtl_sch_register_tasklet(struct mtl_sch_impl* sch, - struct mtl_tasklet_ops* tasklet_ops) { +mtl_tasklet_handle +mtl_sch_register_tasklet(struct mtl_sch_impl *sch, + struct mtl_tasklet_ops *tasklet_ops) { int idx = sch->idx; - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; sch_lock(sch); /* find one empty slot in the mgr */ for (int i = 0; i < sch->nb_tasklets; i++) { - if (sch->tasklet[i]) continue; + if (sch->tasklet[i]) + continue; /* find one empty tasklet slot */ tasklet = mt_rte_zmalloc_socket(sizeof(*tasklet), mt_sch_socket_id(sch)); @@ -891,23 +930,25 @@ mtl_tasklet_handle mtl_sch_register_tasklet(struct mtl_sch_impl* sch, sch->max_tasklet_idx = RTE_MAX(sch->max_tasklet_idx, i + 1); if (mt_sch_started(sch)) { - if (tasklet_ops->start) tasklet_ops->start(tasklet_ops->priv); + if (tasklet_ops->start) + tasklet_ops->start(tasklet_ops->priv); } sch_unlock(sch); - info("%s(%d), tasklet %s registered into slot %d\n", __func__, idx, tasklet_ops->name, - i); + info("%s(%d), tasklet %s registered into slot %d\n", __func__, idx, + tasklet_ops->name, i); return tasklet; } - err("%s(%d), no space on this sch, max %d\n", __func__, idx, sch->nb_tasklets); + err("%s(%d), no space on this sch, max %d\n", __func__, idx, + sch->nb_tasklets); sch_unlock(sch); return NULL; } -int mt_sch_mrg_init(struct mtl_main_impl* impl, int data_quota_mbs_limit) { - struct mtl_sch_impl* sch; - struct mt_sch_mgr* mgr = mt_sch_get_mgr(impl); +int mt_sch_mrg_init(struct mtl_main_impl *impl, int data_quota_mbs_limit) { + struct mtl_sch_impl *sch; + struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); int ret; mt_pthread_mutex_init(&mgr->mgr_mutex, NULL); @@ -916,7 +957,8 @@ int mt_sch_mrg_init(struct mtl_main_impl* impl, int data_quota_mbs_limit) { if (!mt_is_manager_connected(impl)) { ret = sch_init_lcores(mgr); - if (ret < 0) return ret; + if (ret < 0) + return ret; } for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { @@ -956,11 +998,12 @@ int mt_sch_mrg_init(struct mtl_main_impl* impl, int data_quota_mbs_limit) { return 0; } -int mt_sch_mrg_uinit(struct mtl_main_impl* impl) { - struct mtl_sch_impl* sch; - struct mt_sch_mgr* mgr = mt_sch_get_mgr(impl); +int mt_sch_mrg_uinit(struct mtl_main_impl *impl) { + struct mtl_sch_impl *sch; + struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); - if (!mt_is_manager_connected(impl)) sch_uinit_lcores(impl, mgr); + if (!mt_is_manager_connected(impl)) + sch_uinit_lcores(impl, mgr); for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); @@ -991,7 +1034,7 @@ int mt_sch_mrg_uinit(struct mtl_main_impl* impl) { return 0; }; -int mt_sch_add_quota(struct mtl_sch_impl* sch, int quota_mbs) { +int mt_sch_add_quota(struct mtl_sch_impl *sch, int quota_mbs) { int idx = sch->idx; if (!mt_sch_is_active(sch)) { @@ -1005,8 +1048,8 @@ int mt_sch_add_quota(struct mtl_sch_impl* sch, int quota_mbs) { ((sch->data_quota_mbs_total + quota_mbs) <= sch->data_quota_mbs_limit)) { /* find one sch capable with quota */ sch->data_quota_mbs_total += quota_mbs; - info("%s(%d:%d), quota %d total now %d\n", __func__, idx, sch->type, quota_mbs, - sch->data_quota_mbs_total); + info("%s(%d:%d), quota %d total now %d\n", __func__, idx, sch->type, + quota_mbs, sch->data_quota_mbs_total); sch_unlock(sch); return 0; } @@ -1015,9 +1058,9 @@ int mt_sch_add_quota(struct mtl_sch_impl* sch, int quota_mbs) { return -ENOMEM; } -int mt_sch_put(struct mtl_sch_impl* sch, int quota_mbs) { +int mt_sch_put(struct mtl_sch_impl *sch, int quota_mbs) { int sidx = sch->idx, ret; - struct mtl_main_impl* impl = sch->parent; + struct mtl_main_impl *impl = sch->parent; sch_free_quota(sch, quota_mbs); @@ -1062,29 +1105,33 @@ int mt_sch_put(struct mtl_sch_impl* sch, int quota_mbs) { return 0; } -struct mtl_sch_impl* mt_sch_get_by_socket(struct mtl_main_impl* impl, int quota_mbs, - enum mt_sch_type type, mt_sch_mask_t mask, - int socket) { +struct mtl_sch_impl *mt_sch_get_by_socket(struct mtl_main_impl *impl, + int quota_mbs, enum mt_sch_type type, + mt_sch_mask_t mask, int socket) { int ret, idx; - struct mtl_sch_impl* sch; - struct mt_sch_mgr* mgr = mt_sch_get_mgr(impl); + struct mtl_sch_impl *sch; + struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); sch_mgr_lock(mgr); /* first try to find one sch capable with quota */ for (idx = 0; idx < MT_MAX_SCH_NUM; idx++) { sch = mt_sch_instance(impl, idx); - if (socket != mt_sch_socket_id(sch)) continue; + if (socket != mt_sch_socket_id(sch)) + continue; /* mask check */ - if (!(mask & MTL_BIT64(idx))) continue; + if (!(mask & MTL_BIT64(idx))) + continue; /* active and busy check */ - if (!mt_sch_is_active(sch) || sch->cpu_busy) continue; + if (!mt_sch_is_active(sch) || sch->cpu_busy) + continue; /* quota check */ - if (!sch_is_capable(sch, quota_mbs, type)) continue; + if (!sch_is_capable(sch, quota_mbs, type)) + continue; ret = mt_sch_add_quota(sch, quota_mbs); if (ret >= 0) { - info("%s(%d), succ with quota_mbs %d socket %d\n", __func__, idx, quota_mbs, - socket); + info("%s(%d), succ with quota_mbs %d socket %d\n", __func__, idx, + quota_mbs, socket); rte_atomic32_inc(&sch->ref_cnt); sch_mgr_unlock(mgr); return sch; @@ -1124,15 +1171,16 @@ struct mtl_sch_impl* mt_sch_get_by_socket(struct mtl_main_impl* impl, int quota_ return sch; } -int mt_sch_start_all(struct mtl_main_impl* impl) { +int mt_sch_start_all(struct mtl_main_impl *impl) { int ret = 0; - struct mtl_sch_impl* sch; + struct mtl_sch_impl *sch; /* start active sch */ for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); /* not start the app created sch, app should do the mtl_sch_start */ - if (sch->type == MT_SCH_TYPE_APP) continue; + if (sch->type == MT_SCH_TYPE_APP) + continue; if (mt_sch_is_active(sch) && !mt_sch_started(sch)) { ret = sch_start(sch); @@ -1147,15 +1195,16 @@ int mt_sch_start_all(struct mtl_main_impl* impl) { return 0; } -int mt_sch_stop_all(struct mtl_main_impl* impl) { +int mt_sch_stop_all(struct mtl_main_impl *impl) { int ret; - struct mtl_sch_impl* sch; + struct mtl_sch_impl *sch; /* stop active sch */ for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); /* not stop the app created sch, app should do the mtl_sch_stop */ - if (sch->type == MT_SCH_TYPE_APP) continue; + if (sch->type == MT_SCH_TYPE_APP) + continue; if (mt_sch_is_active(sch) && mt_sch_started(sch)) { ret = sch_stop(sch); @@ -1171,12 +1220,13 @@ int mt_sch_stop_all(struct mtl_main_impl* impl) { int mtl_lcore_shm_print(void) { struct mt_lcore_mgr lcore_mgr; - struct mt_lcore_shm_entry* shm_entry; + struct mt_lcore_shm_entry *shm_entry; int ret = sch_lcore_shm_init(&lcore_mgr, false); - if (ret < 0) return ret; + if (ret < 0) + return ret; - struct mt_lcore_shm* lcore_shm = lcore_mgr.lcore_shm; + struct mt_lcore_shm *lcore_shm = lcore_mgr.lcore_shm; info("%s, MTL used lcores %d\n", __func__, lcore_shm->used); int cpu_ids[RTE_MAX_LCORE]; @@ -1185,10 +1235,11 @@ int mtl_lcore_shm_print(void) { for (int i = 0; i < RTE_MAX_LCORE; i++) { shm_entry = &lcore_shm->lcores_info[i]; - if (!shm_entry->active) continue; - struct mt_user_info* u_info = &shm_entry->u_info; - info("%s, lcore %d active by %s@%s, pid: %d(comm: %s) type: %s\n", __func__, i, - u_info->user, u_info->hostname, (int)shm_entry->pid, u_info->comm, + if (!shm_entry->active) + continue; + struct mt_user_info *u_info = &shm_entry->u_info; + info("%s, lcore %d active by %s@%s, pid: %d(comm: %s) type: %s\n", __func__, + i, u_info->user, u_info->hostname, (int)shm_entry->pid, u_info->comm, lcore_type_name(shm_entry->type)); cpu_ids[found] = i; found++; @@ -1201,14 +1252,14 @@ int mtl_lcore_shm_print(void) { info("%s, collecting cpu usage...\n", __func__); ret = mt_read_cpu_usage(prev, cpu_ids, found); if (ret != found) { - err("%s, read cpu prev usage fail, expect %d but only %d get\n", __func__, found, - ret); + err("%s, read cpu prev usage fail, expect %d but only %d get\n", __func__, + found, ret); } else { mt_sleep_ms(1000 * 1); ret = mt_read_cpu_usage(cur, cpu_ids, found); if (ret != found) { - err("%s, read cpu curr usage fail, expect %d but only %d get\n", __func__, found, - ret); + err("%s, read cpu curr usage fail, expect %d but only %d get\n", + __func__, found, ret); } else { /* print the result */ for (int i = 0; i < found; i++) { @@ -1224,44 +1275,48 @@ int mtl_lcore_shm_print(void) { } #ifdef WINDOWSENV -static int lcore_shm_clean_auto_pid(struct mt_lcore_mgr* lcore_mgr) { +static int lcore_shm_clean_auto_pid(struct mt_lcore_mgr *lcore_mgr) { MTL_MAY_UNUSED(lcore_mgr); err("%s, not support on windows\n", __func__); return -EINVAL; } #else -static int lcore_shm_clean_auto_pid(struct mt_lcore_mgr* lcore_mgr) { +static int lcore_shm_clean_auto_pid(struct mt_lcore_mgr *lcore_mgr) { struct mt_user_info info; int clean = 0; memset(&info, 0, sizeof(info)); mt_user_info_init(&info); - struct mt_lcore_shm* lcore_shm = lcore_mgr->lcore_shm; - struct mt_lcore_shm_entry* shm_entry; + struct mt_lcore_shm *lcore_shm = lcore_mgr->lcore_shm; + struct mt_lcore_shm_entry *shm_entry; for (int i = 0; i < RTE_MAX_LCORE; i++) { shm_entry = &lcore_shm->lcores_info[i]; - if (!shm_entry->active) continue; - struct mt_user_info* u_info = &shm_entry->u_info; - if (0 != strncmp(u_info->hostname, info.hostname, sizeof(u_info->hostname))) continue; - if (0 != strncmp(u_info->user, info.user, sizeof(u_info->user))) continue; + if (!shm_entry->active) + continue; + struct mt_user_info *u_info = &shm_entry->u_info; + if (0 != strncmp(u_info->hostname, info.hostname, sizeof(u_info->hostname))) + continue; + if (0 != strncmp(u_info->user, info.user, sizeof(u_info->user))) + continue; /* now check if PID is active with zero signal */ int result = kill(shm_entry->pid, 0); - if (0 == result) continue; + if (0 == result) + continue; clean++; - notice("%s, delete dead lcore %d from the shared mem, PID %d\n", __func__, i, - (int)shm_entry->pid); + notice("%s, delete dead lcore %d from the shared mem, PID %d\n", __func__, + i, (int)shm_entry->pid); } return clean; } #endif -static int lcore_shm_clean_id(struct mt_lcore_mgr* lcore_mgr, void* args, +static int lcore_shm_clean_id(struct mt_lcore_mgr *lcore_mgr, void *args, size_t args_sz) { - struct mtl_lcore_clean_pid_info* info = args; + struct mtl_lcore_clean_pid_info *info = args; if (!args) { err("%s, NULL args\n", __func__); @@ -1277,8 +1332,8 @@ static int lcore_shm_clean_id(struct mt_lcore_mgr* lcore_mgr, void* args, return -EINVAL; } - struct mt_lcore_shm* lcore_shm = lcore_mgr->lcore_shm; - struct mt_lcore_shm_entry* shm_entry = &lcore_shm->lcores_info[lcore]; + struct mt_lcore_shm *lcore_shm = lcore_mgr->lcore_shm; + struct mt_lcore_shm_entry *shm_entry = &lcore_shm->lcores_info[lcore]; if (!shm_entry->active) { err("%s, lcore %u is inactive\n", __func__, lcore); return -EINVAL; @@ -1290,25 +1345,27 @@ static int lcore_shm_clean_id(struct mt_lcore_mgr* lcore_mgr, void* args, return 0; } -int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void* args, size_t args_sz) { +int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void *args, + size_t args_sz) { struct mt_lcore_mgr lcore_mgr; int ret = sch_lcore_shm_init(&lcore_mgr, false); - if (ret < 0) return ret; + if (ret < 0) + return ret; MTL_MAY_UNUSED(args); MTL_MAY_UNUSED(args_sz); switch (action) { - case MTL_LCORE_CLEAN_PID_AUTO_CHECK: - ret = lcore_shm_clean_auto_pid(&lcore_mgr); - break; - case MTL_LCORE_CLEAN_LCORE: - ret = lcore_shm_clean_id(&lcore_mgr, args, args_sz); - break; - default: - err("%s, unknown action %d\n", __func__, action); - ret = -EINVAL; - break; + case MTL_LCORE_CLEAN_PID_AUTO_CHECK: + ret = lcore_shm_clean_auto_pid(&lcore_mgr); + break; + case MTL_LCORE_CLEAN_LCORE: + ret = lcore_shm_clean_id(&lcore_mgr, args, args_sz); + break; + default: + err("%s, unknown action %d\n", __func__, action); + ret = -EINVAL; + break; } sch_lcore_shm_uinit(&lcore_mgr); @@ -1317,8 +1374,8 @@ int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void* args, size_t a /* below for public interface for application */ -mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops* ops) { - struct mtl_main_impl* impl = mt; +mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops *ops) { + struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -1331,8 +1388,8 @@ mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops* ops) { } /* request sch on the MTL_PORT_P socket */ - struct mtl_sch_impl* sch = sch_request(impl, MT_SCH_TYPE_APP, MT_SCH_MASK_ALL, ops, - mt_socket_id(impl, MTL_PORT_P)); + struct mtl_sch_impl *sch = sch_request(impl, MT_SCH_TYPE_APP, MT_SCH_MASK_ALL, + ops, mt_socket_id(impl, MTL_PORT_P)); if (!sch) { err("%s, sch request fail\n", __func__); return NULL; @@ -1345,7 +1402,8 @@ mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops* ops) { int mtl_sch_free(mtl_sch_handle sch) { int idx = sch->idx; /* stop incase user not dp the mtl_sch_stop */ - if (mt_sch_started(sch)) sch_stop(sch); + if (mt_sch_started(sch)) + sch_stop(sch); int ret = sch_free(sch); if (ret < 0) { err("%s(%d), sch free fail %d\n", __func__, idx, ret); diff --git a/lib/src/mt_sch.h b/lib/src/mt_sch.h index b5b08e040..1913c84bd 100644 --- a/lib/src/mt_sch.h +++ b/lib/src/mt_sch.h @@ -7,78 +7,82 @@ #include "mt_main.h" -static inline struct mt_sch_mgr* mt_sch_get_mgr(struct mtl_main_impl* impl) { +static inline struct mt_sch_mgr *mt_sch_get_mgr(struct mtl_main_impl *impl) { return &impl->sch_mgr; } -static inline struct mtl_sch_impl* mt_sch_instance(struct mtl_main_impl* impl, int i) { +static inline struct mtl_sch_impl *mt_sch_instance(struct mtl_main_impl *impl, + int i) { return &mt_sch_get_mgr(impl)->sch[i]; } -static inline bool mt_sch_is_active(struct mtl_sch_impl* sch) { +static inline bool mt_sch_is_active(struct mtl_sch_impl *sch) { if (rte_atomic32_read(&sch->active)) return true; else return false; } -static inline bool mt_sch_started(struct mtl_sch_impl* sch) { +static inline bool mt_sch_started(struct mtl_sch_impl *sch) { if (rte_atomic32_read(&sch->started)) return true; else return false; } -static inline int mt_sch_socket_id(struct mtl_sch_impl* sch) { +static inline int mt_sch_socket_id(struct mtl_sch_impl *sch) { return sch->socket_id; } -static inline void mt_sch_enable_allow_sleep(struct mtl_sch_impl* sch, bool enable) { +static inline void mt_sch_enable_allow_sleep(struct mtl_sch_impl *sch, + bool enable) { sch->allow_sleep = enable; } -static inline bool mt_sch_has_busy(struct mtl_sch_impl* sch) { +static inline bool mt_sch_has_busy(struct mtl_sch_impl *sch) { if (!sch->allow_sleep || sch->sleep_ratio_score > 70.0) return true; else return false; } -int mt_sch_mrg_init(struct mtl_main_impl* impl, int data_quota_mbs_limit); -int mt_sch_mrg_uinit(struct mtl_main_impl* impl); +int mt_sch_mrg_init(struct mtl_main_impl *impl, int data_quota_mbs_limit); +int mt_sch_mrg_uinit(struct mtl_main_impl *impl); -static inline void mt_tasklet_set_sleep(struct mt_sch_tasklet_impl* tasklet, +static inline void mt_tasklet_set_sleep(struct mt_sch_tasklet_impl *tasklet, uint64_t advice_sleep_us) { tasklet->ops.advice_sleep_us = advice_sleep_us; } -int mt_sch_add_quota(struct mtl_sch_impl* sch, int quota_mbs); +int mt_sch_add_quota(struct mtl_sch_impl *sch, int quota_mbs); -struct mtl_sch_impl* mt_sch_get_by_socket(struct mtl_main_impl* impl, int quota_mbs, - enum mt_sch_type type, mt_sch_mask_t mask, - int socket); -static inline struct mtl_sch_impl* mt_sch_get(struct mtl_main_impl* impl, int quota_mbs, - enum mt_sch_type type, mt_sch_mask_t mask) { +struct mtl_sch_impl *mt_sch_get_by_socket(struct mtl_main_impl *impl, + int quota_mbs, enum mt_sch_type type, + mt_sch_mask_t mask, int socket); +static inline struct mtl_sch_impl *mt_sch_get(struct mtl_main_impl *impl, + int quota_mbs, + enum mt_sch_type type, + mt_sch_mask_t mask) { /* use the default socket of MTL_PORT_P */ return mt_sch_get_by_socket(impl, quota_mbs, type, mask, mt_socket_id(impl, MTL_PORT_P)); } -int mt_sch_put(struct mtl_sch_impl* sch, int quota_mbs); +int mt_sch_put(struct mtl_sch_impl *sch, int quota_mbs); -int mt_sch_start_all(struct mtl_main_impl* impl); -int mt_sch_stop_all(struct mtl_main_impl* impl); +int mt_sch_start_all(struct mtl_main_impl *impl); +int mt_sch_stop_all(struct mtl_main_impl *impl); -static inline void mt_sch_set_cpu_busy(struct mtl_sch_impl* sch, bool busy) { +static inline void mt_sch_set_cpu_busy(struct mtl_sch_impl *sch, bool busy) { sch->cpu_busy = busy; } -static inline uint64_t mt_sch_avg_ns_loop(struct mtl_sch_impl* sch) { +static inline uint64_t mt_sch_avg_ns_loop(struct mtl_sch_impl *sch) { return sch->avg_ns_per_loop; } -int mt_sch_put_lcore(struct mtl_main_impl* impl, unsigned int lcore); -int mt_sch_get_lcore(struct mtl_main_impl* impl, unsigned int* lcore, +int mt_sch_put_lcore(struct mtl_main_impl *impl, unsigned int lcore); +int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, enum mt_lcore_type type, int socket); -bool mt_sch_lcore_valid(struct mtl_main_impl* impl, unsigned int lcore); +bool mt_sch_lcore_valid(struct mtl_main_impl *impl, unsigned int lcore); #endif diff --git a/lib/src/mt_simd.h b/lib/src/mt_simd.h index fd8bbabed..48b731a07 100644 --- a/lib/src/mt_simd.h +++ b/lib/src/mt_simd.h @@ -10,12 +10,12 @@ // Push the SIMD compiler flag online to build the code path #if defined(__clang__) /* "clang attribute push" support from clang 9.0 */ -#define MT_TARGET_CODE_START(Target) \ - _Pragma(STRINGIFY( \ - clang attribute push(__attribute__((target(Target))), apply_to = function))) +#define MT_TARGET_CODE_START(Target) \ + _Pragma(STRINGIFY(clang attribute push(__attribute__((target(Target))), \ + apply_to = function))) #define MT_TARGET_CODE_STOP _Pragma("clang attribute pop") #elif defined(__GNUC__) -#define MT_TARGET_CODE_START(Target) \ +#define MT_TARGET_CODE_START(Target) \ _Pragma("GCC push_options") _Pragma(STRINGIFY(GCC target(Target))) #define MT_TARGET_CODE_STOP _Pragma("GCC pop_options") #else @@ -31,13 +31,13 @@ #endif #ifdef MTL_HAS_AVX512 -#define MT_TARGET_CODE_START_AVX512 \ +#define MT_TARGET_CODE_START_AVX512 \ MT_TARGET_CODE_START("avx512f,avx512cd,avx512vl,avx512dq,avx512bw") #endif #ifdef MTL_HAS_AVX512_VBMI2 -#define MT_TARGET_CODE_START_AVX512_VBMI2 \ - MT_TARGET_CODE_START( \ +#define MT_TARGET_CODE_START_AVX512_VBMI2 \ + MT_TARGET_CODE_START( \ "avx512f,avx512cd,avx512vl,avx512dq,avx512bw,avx512vbmi,avx512vbmi2") #endif diff --git a/lib/src/mt_socket.c b/lib/src/mt_socket.c index 3783fcf34..7f56af619 100644 --- a/lib/src/mt_socket.c +++ b/lib/src/mt_socket.c @@ -9,7 +9,7 @@ #include "mt_util.h" #ifndef WINDOWSENV -int mt_socket_get_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], +int mt_socket_get_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]) { int sock, ret; struct ifreq ifr; @@ -28,8 +28,9 @@ int mt_socket_get_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], close(sock); return ret; } - struct sockaddr_in* ipaddr = (struct sockaddr_in*)&ifr.ifr_addr; - if (ip) memcpy(ip, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); + struct sockaddr_in *ipaddr = (struct sockaddr_in *)&ifr.ifr_addr; + if (ip) + memcpy(ip, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); ret = ioctl(sock, SIOCGIFNETMASK, &ifr); if (ret < 0) { @@ -37,14 +38,15 @@ int mt_socket_get_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], close(sock); return ret; } - ipaddr = (struct sockaddr_in*)&ifr.ifr_addr; - if (netmask) memcpy(netmask, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); + ipaddr = (struct sockaddr_in *)&ifr.ifr_addr; + if (netmask) + memcpy(netmask, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); close(sock); return 0; } -int mt_socket_set_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], +int mt_socket_set_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]) { struct ifreq ifr; int sock; @@ -60,7 +62,8 @@ int mt_socket_set_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", if_name); ifr.ifr_addr.sa_family = AF_INET; - memcpy(&((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr.s_addr, ip, MTL_IP_ADDR_LEN); + memcpy(&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr, ip, + MTL_IP_ADDR_LEN); ret = ioctl(sock, SIOCSIFADDR, &ifr); if (ret < 0) { err("%s, SIOCSIFADDR fail %d for if %s\n", __func__, ret, if_name); @@ -69,7 +72,7 @@ int mt_socket_set_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], } ifr.ifr_addr.sa_family = AF_INET; - memcpy(&((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr.s_addr, netmask, + memcpy(&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr, netmask, MTL_IP_ADDR_LEN); ret = ioctl(sock, SIOCSIFNETMASK, &ifr); if (ret < 0) { @@ -83,8 +86,9 @@ int mt_socket_set_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], return 0; } -int mt_socket_get_if_gateway(const char* if_name, uint8_t gateway[MTL_IP_ADDR_LEN]) { - FILE* fp = fopen("/proc/net/route", "r"); +int mt_socket_get_if_gateway(const char *if_name, + uint8_t gateway[MTL_IP_ADDR_LEN]) { + FILE *fp = fopen("/proc/net/route", "r"); char line[100], iface[IF_NAMESIZE], dest[9], gway[9]; if (fp == NULL) { @@ -116,7 +120,7 @@ int mt_socket_get_if_gateway(const char* if_name, uint8_t gateway[MTL_IP_ADDR_LE return -EIO; } -int mt_socket_get_if_mac(const char* if_name, struct rte_ether_addr* ea) { +int mt_socket_get_if_mac(const char *if_name, struct rte_ether_addr *ea) { int sock, ret; struct ifreq ifr; @@ -140,7 +144,7 @@ int mt_socket_get_if_mac(const char* if_name, struct rte_ether_addr* ea) { return 0; } -int mt_socket_set_if_up(const char* if_name) { +int mt_socket_set_if_up(const char *if_name) { int sock, ret; struct ifreq ifr; @@ -171,11 +175,11 @@ int mt_socket_set_if_up(const char* if_name) { return 0; } -int mt_socket_get_numa(const char* if_name) { +int mt_socket_get_numa(const char *if_name) { char path[256]; snprintf(path, sizeof(path), "/sys/class/net/%s/device/numa_node", if_name); - FILE* file = fopen(path, "r"); + FILE *file = fopen(path, "r"); if (!file) { err("%s, open %s fail\n", __func__, path); return 0; @@ -192,25 +196,26 @@ int mt_socket_get_numa(const char* if_name) { dbg("%s, numa_node %d for %s\n", __func__, numa_node, if_name); if (SOCKET_ID_ANY == numa_node) { numa_node = 0; - info("%s, direct soc_id from SOCKET_ID_ANY to 0 for %s\n", __func__, if_name); + info("%s, direct soc_id from SOCKET_ID_ANY to 0 for %s\n", __func__, + if_name); } return numa_node; } -static int socket_arp_get(int sfd, in_addr_t ip, struct rte_ether_addr* ea, - const char* if_name) { +static int socket_arp_get(int sfd, in_addr_t ip, struct rte_ether_addr *ea, + const char *if_name) { struct arpreq arp; - struct sockaddr_in* sin; + struct sockaddr_in *sin; struct in_addr ina; - unsigned char* hw_addr; + unsigned char *hw_addr; memset(&arp, 0, sizeof(arp)); - sin = (struct sockaddr_in*)&arp.arp_pa; + sin = (struct sockaddr_in *)&arp.arp_pa; memset(sin, 0, sizeof(struct sockaddr_in)); sin->sin_family = AF_INET; ina.s_addr = ip; - memcpy(&sin->sin_addr, (char*)&ina, sizeof(struct in_addr)); + memcpy(&sin->sin_addr, (char *)&ina, sizeof(struct in_addr)); snprintf(arp.arp_dev, sizeof(arp.arp_dev) - 1, "%s", if_name); int ret = ioctl(sfd, SIOCGARP, &arp); @@ -225,19 +230,19 @@ static int socket_arp_get(int sfd, in_addr_t ip, struct rte_ether_addr* ea, } dbg("%s, entry has been successfully retrieved\n", __func__); - hw_addr = (unsigned char*)arp.arp_ha.sa_data; + hw_addr = (unsigned char *)arp.arp_ha.sa_data; memcpy(ea->addr_bytes, hw_addr, RTE_ETHER_ADDR_LEN); - dbg("%s, mac addr found : %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, hw_addr[0], - hw_addr[1], hw_addr[2], hw_addr[3], hw_addr[4], hw_addr[5]); + dbg("%s, mac addr found : %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, + hw_addr[0], hw_addr[1], hw_addr[2], hw_addr[3], hw_addr[4], hw_addr[5]); return 0; } static int socket_query_local_mac(uint8_t ip[MTL_IP_ADDR_LEN], - struct rte_ether_addr* ea) { + struct rte_ether_addr *ea) { int sock; struct ifconf conf; - struct ifreq* ifr = NULL; + struct ifreq *ifr = NULL; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { @@ -274,8 +279,8 @@ static int socket_query_local_mac(uint8_t ip[MTL_IP_ADDR_LEN], int numif = conf.ifc_len / sizeof(*ifr); for (int i = 0; i < numif; i++) { - struct ifreq* r = &ifr[i]; - struct sockaddr_in* sin = (struct sockaddr_in*)&r->ifr_addr; + struct ifreq *r = &ifr[i]; + struct sockaddr_in *sin = (struct sockaddr_in *)&r->ifr_addr; dbg("%s: %s\n", r->ifr_name, inet_ntoa(sin->sin_addr)); if (0 == memcmp(ip, &sin->sin_addr.s_addr, MTL_IP_ADDR_LEN)) { dbg("%s: %s match the input\n", r->ifr_name, inet_ntoa(sin->sin_addr)); @@ -291,8 +296,8 @@ static int socket_query_local_mac(uint8_t ip[MTL_IP_ADDR_LEN], return -EIO; } -int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, - uint8_t dip[MTL_IP_ADDR_LEN], struct rte_ether_addr* ea, +int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, + uint8_t dip[MTL_IP_ADDR_LEN], struct rte_ether_addr *ea, int timeout_ms) { int sock, ret; struct sockaddr_in addr; @@ -300,11 +305,13 @@ int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, int max_retry = 0; int sleep_interval_ms = 100; - if (timeout_ms) max_retry = (timeout_ms / sleep_interval_ms) + 1; + if (timeout_ms) + max_retry = (timeout_ms / sleep_interval_ms) + 1; ret = socket_query_local_mac(dip, ea); if (ret >= 0) { - dbg("%s: %u.%u.%u.%u is a local ip\n", __func__, dip[0], dip[1], dip[2], dip[3]); + dbg("%s: %u.%u.%u.%u is a local ip\n", __func__, dip[0], dip[1], dip[2], + dip[3]); return 0; } @@ -323,7 +330,7 @@ int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, while (socket_arp_get(sock, addr.sin_addr.s_addr, ea, if_name) < 0) { memset(dummy_buf, 0, sizeof(dummy_buf)); /* tx one dummy pkt to send arp request */ - if (sendto(sock, dummy_buf, 0, 0, (struct sockaddr*)&addr, + if (sendto(sock, dummy_buf, 0, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) continue; @@ -340,8 +347,8 @@ int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, } retry++; if (0 == (retry % 50)) { - info("%s(%s), waiting arp from %d.%d.%d.%d\n", __func__, if_name, dip[0], dip[1], - dip[2], dip[3]); + info("%s(%s), waiting arp from %d.%d.%d.%d\n", __func__, if_name, dip[0], + dip[1], dip[2], dip[3]); } mt_sleep_ms(sleep_interval_ms); } @@ -350,9 +357,9 @@ int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, return 0; } -int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t queue_id, - struct mt_rxq_flow* flow) { - const char* if_name = mt_kernel_if_name(impl, port); +int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, + uint16_t queue_id, struct mt_rxq_flow *flow) { + const char *if_name = mt_kernel_if_name(impl, port); bool has_ip_flow = true; if (!mt_is_manager_connected(impl)) { @@ -370,11 +377,13 @@ int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t } /* no ip flow requested */ - if (flow->flags & MT_RXQ_FLOW_F_NO_IP) has_ip_flow = false; + if (flow->flags & MT_RXQ_FLOW_F_NO_IP) + has_ip_flow = false; if (mt_get_user_params(impl)->flags & MTL_FLAG_RX_UDP_PORT_ONLY) { if (has_ip_flow) { - info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, port); + info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, + port); has_ip_flow = false; } } @@ -383,18 +392,18 @@ int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t uint16_t dport = flow->dst_port; if (has_ip_flow) { if (mt_is_multicast_ip(flow->dip_addr)) { - dip = *(uint32_t*)flow->dip_addr; + dip = *(uint32_t *)flow->dip_addr; } else { - sip = *(uint32_t*)flow->dip_addr; - dip = *(uint32_t*)flow->sip_addr; + sip = *(uint32_t *)flow->dip_addr; + dip = *(uint32_t *)flow->sip_addr; } } if (mt_pmd_is_dpdk_af_xdp(impl, port)) { /* workaround now */ queue_id += MT_DPDK_AF_XDP_START_QUEUE; - int ret = - mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), dport, true); + int ret = mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), + dport, true); if (ret < 0) { err("%s(%d), udp_dp_filter fail %d\n", __func__, port, ret); return ret; @@ -404,9 +413,9 @@ int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t 0x02 /*UDP_V4_FLOW*/, sip, dip, 0, dport); } -int mt_socket_remove_flow(struct mtl_main_impl* impl, enum mtl_port port, int flow_id, - uint16_t dst_port) { - const char* if_name = mt_kernel_if_name(impl, port); +int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, + int flow_id, uint16_t dst_port) { + const char *if_name = mt_kernel_if_name(impl, port); if (!mt_is_manager_connected(impl)) { err("%s(%d), manager not connected\n", __func__, port); @@ -415,15 +424,16 @@ int mt_socket_remove_flow(struct mtl_main_impl* impl, enum mtl_port port, int fl if (mt_pmd_is_dpdk_af_xdp(impl, port)) { /* workaround now */ - mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), dst_port, false); + mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), dst_port, + false); } return mt_instance_del_flow(impl, if_nametoindex(if_name), flow_id); } -int mt_socket_fd_join_multicast(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow, int fd) { - uint32_t source = *(uint32_t*)flow->sip_addr; +int mt_socket_fd_join_multicast(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow, int fd) { + uint32_t source = *(uint32_t *)flow->sip_addr; int ret; if (!mt_is_multicast_ip(flow->dip_addr)) { @@ -435,22 +445,25 @@ int mt_socket_fd_join_multicast(struct mtl_main_impl* impl, enum mtl_port port, struct ip_mreq mreq; memset(&mreq, 0, sizeof(mreq)); memcpy(&mreq.imr_multiaddr.s_addr, flow->dip_addr, MTL_IP_ADDR_LEN); - memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); + memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), + MTL_IP_ADDR_LEN); ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); } else { struct ip_mreq_source mreq; memset(&mreq, 0, sizeof(mreq)); memcpy(&mreq.imr_multiaddr.s_addr, flow->dip_addr, MTL_IP_ADDR_LEN); - memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); + memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), + MTL_IP_ADDR_LEN); memcpy(&mreq.imr_sourceaddr.s_addr, flow->sip_addr, MTL_IP_ADDR_LEN); - ret = setsockopt(fd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, &mreq, sizeof(mreq)); + ret = setsockopt(fd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, &mreq, + sizeof(mreq)); } return ret; } -int mt_socket_get_multicast_fd(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow) { +int mt_socket_get_multicast_fd(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow) { int ret; int mcast_fd = socket(AF_INET, SOCK_DGRAM, 0); if (mcast_fd < 0) { @@ -465,14 +478,15 @@ int mt_socket_get_multicast_fd(struct mtl_main_impl* impl, enum mtl_port port, return ret; } else { /* return the fd */ - uint8_t* ip = flow->dip_addr; - info("%s(%d), join %u.%u.%u.%u succ\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); + uint8_t *ip = flow->dip_addr; + info("%s(%d), join %u.%u.%u.%u succ\n", __func__, port, ip[0], ip[1], ip[2], + ip[3]); return mcast_fd; } } #else -int mt_socket_get_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], +int mt_socket_get_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]) { MTL_MAY_UNUSED(if_name); MTL_MAY_UNUSED(ip); @@ -480,25 +494,26 @@ int mt_socket_get_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], return -ENOTSUP; } -int mt_socket_get_if_gateway(const char* if_name, uint8_t gateway[MTL_IP_ADDR_LEN]) { +int mt_socket_get_if_gateway(const char *if_name, + uint8_t gateway[MTL_IP_ADDR_LEN]) { MTL_MAY_UNUSED(if_name); MTL_MAY_UNUSED(gateway); return -ENOTSUP; } -int mt_socket_get_if_mac(const char* if_name, struct rte_ether_addr* ea) { +int mt_socket_get_if_mac(const char *if_name, struct rte_ether_addr *ea) { MTL_MAY_UNUSED(if_name); MTL_MAY_UNUSED(ea); return -ENOTSUP; } -int mt_socket_get_numa(const char* if_name) { +int mt_socket_get_numa(const char *if_name) { MTL_MAY_UNUSED(if_name); return 0; } -int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, - uint8_t dip[MTL_IP_ADDR_LEN], struct rte_ether_addr* ea, +int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, + uint8_t dip[MTL_IP_ADDR_LEN], struct rte_ether_addr *ea, int timeout_ms) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(if_name); @@ -508,8 +523,8 @@ int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, return -ENOTSUP; } -int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t queue_id, - struct mt_rxq_flow* flow) { +int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, + uint16_t queue_id, struct mt_rxq_flow *flow) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(queue_id); @@ -517,8 +532,8 @@ int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t return -ENOTSUP; } -int mt_socket_remove_flow(struct mtl_main_impl* impl, enum mtl_port port, int flow_id, - uint16_t dst_port) { +int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, + int flow_id, uint16_t dst_port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow_id); @@ -526,16 +541,16 @@ int mt_socket_remove_flow(struct mtl_main_impl* impl, enum mtl_port port, int fl return -ENOTSUP; } -int mt_socket_get_multicast_fd(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow) { +int mt_socket_get_multicast_fd(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); return -ENOTSUP; } -int mt_socket_fd_join_multicast(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow, int fd) { +int mt_socket_fd_join_multicast(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow, int fd) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); @@ -544,7 +559,7 @@ int mt_socket_fd_join_multicast(struct mtl_main_impl* impl, enum mtl_port port, } #endif -int mtl_get_if_ip(char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], +int mtl_get_if_ip(char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]) { return mt_socket_get_if_ip(if_name, ip, netmask); } diff --git a/lib/src/mt_socket.h b/lib/src/mt_socket.h index 136e9a7e2..6f4ffbcdd 100644 --- a/lib/src/mt_socket.h +++ b/lib/src/mt_socket.h @@ -7,34 +7,35 @@ #include "mt_main.h" -int mt_socket_get_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], +int mt_socket_get_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]); -int mt_socket_set_if_ip(const char* if_name, uint8_t ip[MTL_IP_ADDR_LEN], +int mt_socket_set_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]); -int mt_socket_get_if_gateway(const char* if_name, uint8_t gateway[MTL_IP_ADDR_LEN]); +int mt_socket_get_if_gateway(const char *if_name, + uint8_t gateway[MTL_IP_ADDR_LEN]); -int mt_socket_get_if_mac(const char* if_name, struct rte_ether_addr* ea); +int mt_socket_get_if_mac(const char *if_name, struct rte_ether_addr *ea); -int mt_socket_set_if_up(const char* if_name); +int mt_socket_set_if_up(const char *if_name); -int mt_socket_get_numa(const char* if_name); +int mt_socket_get_numa(const char *if_name); -int mt_socket_get_mac(struct mtl_main_impl* impl, const char* if_name, - uint8_t dip[MTL_IP_ADDR_LEN], struct rte_ether_addr* ea, +int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, + uint8_t dip[MTL_IP_ADDR_LEN], struct rte_ether_addr *ea, int timeout_ms); -int mt_socket_add_flow(struct mtl_main_impl* impl, enum mtl_port port, uint16_t queue_id, - struct mt_rxq_flow* flow); +int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, + uint16_t queue_id, struct mt_rxq_flow *flow); -int mt_socket_remove_flow(struct mtl_main_impl* impl, enum mtl_port port, int flow_id, - uint16_t dst_port); +int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, + int flow_id, uint16_t dst_port); -int mt_socket_fd_join_multicast(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow, int fd); +int mt_socket_fd_join_multicast(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow, int fd); -int mt_socket_get_multicast_fd(struct mtl_main_impl* impl, enum mtl_port port, - struct mt_rxq_flow* flow); +int mt_socket_get_multicast_fd(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow); #endif diff --git a/lib/src/mt_stat.c b/lib/src/mt_stat.c index adfb95951..abce72733 100644 --- a/lib/src/mt_stat.c +++ b/lib/src/mt_stat.c @@ -9,42 +9,40 @@ #define MT_STAT_INTERVAL_S_DEFAULT (10) /* 10s */ -static inline struct mt_stat_mgr* get_stat_mgr(struct mtl_main_impl* impl) { +static inline struct mt_stat_mgr *get_stat_mgr(struct mtl_main_impl *impl) { return &impl->stat_mgr; } -static inline void stat_lock(struct mt_stat_mgr* mgr) { +static inline void stat_lock(struct mt_stat_mgr *mgr) { rte_spinlock_lock(&mgr->lock); } /* return true if try lock succ */ -static inline bool stat_try_lock(struct mt_stat_mgr* mgr) { +static inline bool stat_try_lock(struct mt_stat_mgr *mgr) { int ret = rte_spinlock_trylock(&mgr->lock); return ret ? true : false; } -static inline void stat_unlock(struct mt_stat_mgr* mgr) { +static inline void stat_unlock(struct mt_stat_mgr *mgr) { rte_spinlock_unlock(&mgr->lock); } -static int _stat_dump(struct mt_stat_mgr* mgr) { - struct mt_stat_item* item; +static int _stat_dump(struct mt_stat_mgr *mgr) { + struct mt_stat_item *item; if (!stat_try_lock(mgr)) { notice("STAT: failed to get lock\n"); return -EIO; } - MT_TAILQ_FOREACH(item, &mgr->head, next) { - item->cb_func(item->cb_priv); - } + MT_TAILQ_FOREACH(item, &mgr->head, next) { item->cb_func(item->cb_priv); } stat_unlock(mgr); return 0; } -static void stat_dump(struct mt_stat_mgr* mgr) { - struct mtl_main_impl* impl = mgr->parent; - struct mtl_init_params* p = mt_get_user_params(impl); +static void stat_dump(struct mt_stat_mgr *mgr) { + struct mtl_main_impl *impl = mgr->parent; + struct mtl_init_params *p = mt_get_user_params(impl); if (mt_in_reset(impl)) { notice("* * M T D E V I N R E S E T * * \n"); @@ -60,8 +58,8 @@ static void stat_dump(struct mt_stat_mgr* mgr) { notice("* * E N D S T A T E * * \n\n"); } -static void* stat_thread(void* arg) { - struct mt_stat_mgr* mgr = arg; +static void *stat_thread(void *arg) { + struct mt_stat_mgr *mgr = arg; info("%s, start\n", __func__); while (rte_atomic32_read(&mgr->stat_stop) == 0) { @@ -80,14 +78,14 @@ static void* stat_thread(void* arg) { return NULL; } -static void stat_wakeup_thread(struct mt_stat_mgr* mgr) { +static void stat_wakeup_thread(struct mt_stat_mgr *mgr) { mt_pthread_mutex_lock(&mgr->stat_wake_mutex); mt_pthread_cond_signal(&mgr->stat_wake_cond); mt_pthread_mutex_unlock(&mgr->stat_wake_mutex); } -static void stat_alarm_handler(void* param) { - struct mt_stat_mgr* mgr = param; +static void stat_alarm_handler(void *param) { + struct mt_stat_mgr *mgr = param; if (mgr->stat_tid) stat_wakeup_thread(mgr); @@ -97,10 +95,10 @@ static void stat_alarm_handler(void* param) { rte_eal_alarm_set(mgr->dump_period_us, stat_alarm_handler, mgr); } -int mt_stat_register(struct mtl_main_impl* impl, mt_stat_cb_t cb, void* priv, - char* name) { - struct mt_stat_mgr* mgr = get_stat_mgr(impl); - struct mt_stat_item* item = +int mt_stat_register(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv, + char *name) { + struct mt_stat_mgr *mgr = get_stat_mgr(impl); + struct mt_stat_item *item = mt_rte_zmalloc_socket(sizeof(*item), mt_socket_id(impl, MTL_PORT_P)); if (!item) { err("%s, malloc fail\n", __func__); @@ -108,7 +106,8 @@ int mt_stat_register(struct mtl_main_impl* impl, mt_stat_cb_t cb, void* priv, } item->cb_func = cb; item->cb_priv = priv; - if (name) snprintf(item->name, ST_MAX_NAME_LEN - 1, "%s", name); + if (name) + snprintf(item->name, ST_MAX_NAME_LEN - 1, "%s", name); stat_lock(mgr); MT_TAILQ_INSERT_TAIL(&mgr->head, item, next); @@ -118,8 +117,9 @@ int mt_stat_register(struct mtl_main_impl* impl, mt_stat_cb_t cb, void* priv, return 0; } -int mt_stat_unregister(struct mtl_main_impl* impl, mt_stat_cb_t cb, void* priv) { - struct mt_stat_mgr* mgr = get_stat_mgr(impl); +int mt_stat_unregister(struct mtl_main_impl *impl, mt_stat_cb_t cb, + void *priv) { + struct mt_stat_mgr *mgr = get_stat_mgr(impl); struct mt_stat_item *item, *tmp_item; stat_lock(mgr); @@ -140,9 +140,9 @@ int mt_stat_unregister(struct mtl_main_impl* impl, mt_stat_cb_t cb, void* priv) return -EIO; } -int mt_stat_init(struct mtl_main_impl* impl) { - struct mt_stat_mgr* mgr = get_stat_mgr(impl); - struct mtl_init_params* p = mt_get_user_params(impl); +int mt_stat_init(struct mtl_main_impl *impl) { + struct mt_stat_mgr *mgr = get_stat_mgr(impl); + struct mtl_init_params *p = mt_get_user_params(impl); int ret; mgr->parent = impl; @@ -160,7 +160,8 @@ int mt_stat_init(struct mtl_main_impl* impl) { } mtl_thread_setname(mgr->stat_tid, "mtl_stat"); - if (!p->dump_period_s) p->dump_period_s = MT_STAT_INTERVAL_S_DEFAULT; + if (!p->dump_period_s) + p->dump_period_s = MT_STAT_INTERVAL_S_DEFAULT; mgr->dump_period_us = (uint64_t)p->dump_period_s * US_PER_S; rte_eal_alarm_set(mgr->dump_period_us, stat_alarm_handler, mgr); @@ -168,9 +169,9 @@ int mt_stat_init(struct mtl_main_impl* impl) { return 0; } -int mt_stat_uinit(struct mtl_main_impl* impl) { - struct mt_stat_mgr* mgr = get_stat_mgr(impl); - struct mt_stat_item* item; +int mt_stat_uinit(struct mtl_main_impl *impl) { + struct mt_stat_mgr *mgr = get_stat_mgr(impl); + struct mt_stat_item *item; int ret; /* check if any not unregister */ @@ -181,7 +182,8 @@ int mt_stat_uinit(struct mtl_main_impl* impl) { } ret = rte_eal_alarm_cancel(stat_alarm_handler, impl); - if (ret < 0) err("%s, alarm cancel fail %d\n", __func__, ret); + if (ret < 0) + err("%s, alarm cancel fail %d\n", __func__, ret); if (mgr->stat_tid) { rte_atomic32_set(&mgr->stat_stop, 1); stat_wakeup_thread(mgr); diff --git a/lib/src/mt_stat.h b/lib/src/mt_stat.h index 0bd5c1486..03f74ba2c 100644 --- a/lib/src/mt_stat.h +++ b/lib/src/mt_stat.h @@ -7,17 +7,18 @@ #include "mt_main.h" -int mt_stat_init(struct mtl_main_impl* impl); -int mt_stat_uinit(struct mtl_main_impl* impl); +int mt_stat_init(struct mtl_main_impl *impl); +int mt_stat_uinit(struct mtl_main_impl *impl); -int mt_stat_register(struct mtl_main_impl* impl, mt_stat_cb_t cb, void* priv, char* name); -int mt_stat_unregister(struct mtl_main_impl* impl, mt_stat_cb_t cb, void* priv); +int mt_stat_register(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv, + char *name); +int mt_stat_unregister(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv); -static inline uint64_t mt_stat_dump_period_us(struct mtl_main_impl* impl) { +static inline uint64_t mt_stat_dump_period_us(struct mtl_main_impl *impl) { return impl->stat_mgr.dump_period_us; } -static inline double mt_stat_dump_period_s(struct mtl_main_impl* impl) { +static inline double mt_stat_dump_period_s(struct mtl_main_impl *impl) { return (double)mt_stat_dump_period_us(impl) / US_PER_S; } diff --git a/lib/src/mt_tap.c b/lib/src/mt_tap.c index 5502c9a4b..e9ec5e3ee 100644 --- a/lib/src/mt_tap.c +++ b/lib/src/mt_tap.c @@ -14,32 +14,36 @@ #include "mt_sch.h" #include "mt_util.h" -static struct mtl_main_impl* tap_main_impl; -static struct rte_ring* tap_tx_ring; +static struct mtl_main_impl *tap_main_impl; +static struct rte_ring *tap_tx_ring; -typedef ULONG (*GetAdaptersInfo_type)(PIP_ADAPTER_INFO AdapterInfo, PULONG SizePointer); +typedef ULONG (*GetAdaptersInfo_type)(PIP_ADAPTER_INFO AdapterInfo, + PULONG SizePointer); static GetAdaptersInfo_type GetAdaptersInfo_ptr = NULL; -static inline void tap_set_global_impl(struct mtl_main_impl* impl) { +static inline void tap_set_global_impl(struct mtl_main_impl *impl) { tap_main_impl = impl; } -static inline bool io_active(struct overlapped_io* io) { - return io->iostate == IOSTATE_QUEUED || io->iostate == IOSTATE_IMMEDIATE_RETURN; +static inline bool io_active(struct overlapped_io *io) { + return io->iostate == IOSTATE_QUEUED || + io->iostate == IOSTATE_IMMEDIATE_RETURN; } -static struct mtl_main_impl* tap_get_global_impl(void) { - struct mtl_main_impl* impl = tap_main_impl; - if (!impl) err("%s, global impl not init\n", __func__); +static struct mtl_main_impl *tap_get_global_impl(void) { + struct mtl_main_impl *impl = tap_main_impl; + if (!impl) + err("%s, global impl not init\n", __func__); return impl; } -static void tap_rxq_pool_free(struct rte_mbuf* pool) { - struct rte_mbuf* mbuf = pool; +static void tap_rxq_pool_free(struct rte_mbuf *pool) { + struct rte_mbuf *mbuf = pool; uint16_t nb_segs = 1; - if (mbuf == NULL) return; + if (mbuf == NULL) + return; while (mbuf->next) { mbuf = mbuf->next; @@ -49,8 +53,8 @@ static void tap_rxq_pool_free(struct rte_mbuf* pool) { rte_pktmbuf_free(pool); } -static int tap_put_mbuf(struct rte_ring* packet_ring, void* mbuf) { - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; +static int tap_put_mbuf(struct rte_ring *packet_ring, void *mbuf) { + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; int ret; if (!packet_ring) { err("%s, tap ring is not created\n", __func__); @@ -62,7 +66,7 @@ static int tap_put_mbuf(struct rte_ring* packet_ring, void* mbuf) { return -EIO; } pkt->data_len = pkt->pkt_len; - ret = rte_ring_sp_enqueue(packet_ring, (void*)pkt); + ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); if (ret < 0) { err("%s, can not enqueue to the tap ring\n", __func__); @@ -72,74 +76,78 @@ static int tap_put_mbuf(struct rte_ring* packet_ring, void* mbuf) { return 0; } -static void* tap_get_mbuf(struct rte_ring* packet_ring, void** usrptr, uint16_t* len) { - struct rte_mbuf* pkt; +static void *tap_get_mbuf(struct rte_ring *packet_ring, void **usrptr, + uint16_t *len) { + struct rte_mbuf *pkt; int ret; if (!packet_ring) { err("%s, tap ring is not created\n", __func__); return NULL; } - ret = rte_ring_sc_dequeue(packet_ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(packet_ring, (void **)&pkt); if (ret < 0) { info("%s, tap ring is empty\n", __func__); return NULL; } - if (len) *len = pkt->data_len; - if (usrptr) *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, 0); + if (len) + *len = pkt->data_len; + if (usrptr) + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, 0); return pkt; } -static int overlapped_result(struct mt_cni_impl* cni, struct overlapped_io* io) { +static int overlapped_result(struct mt_cni_impl *cni, + struct overlapped_io *io) { int ret = -1; BOOL status; - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; switch (io->iostate) { - case IOSTATE_QUEUED: - status = - GetOverlappedResult(tap_ctx->tap_handle, &io->overlapped, &io->size, FALSE); - if (status) { - ret = io->size; - io->status = 0; - io->iostate = IOSTATE_IMMEDIATE_RETURN; - assert(ResetEvent(io->overlapped.hEvent)); - } else { - ret = -1; - if (GetLastError() != ERROR_IO_INCOMPLETE) { - io->iostate = IOSTATE_INITIAL; - io->status = -1; - assert(ResetEvent(io->overlapped.hEvent)); - } - } - break; - - case IOSTATE_IMMEDIATE_RETURN: - io->iostate = IOSTATE_INITIAL; + case IOSTATE_QUEUED: + status = GetOverlappedResult(tap_ctx->tap_handle, &io->overlapped, + &io->size, FALSE); + if (status) { + ret = io->size; + io->status = 0; + io->iostate = IOSTATE_IMMEDIATE_RETURN; assert(ResetEvent(io->overlapped.hEvent)); - if (io->status) { - SetLastError(io->status); - ret = -1; - } else { - ret = io->size; + } else { + ret = -1; + if (GetLastError() != ERROR_IO_INCOMPLETE) { + io->iostate = IOSTATE_INITIAL; + io->status = -1; + assert(ResetEvent(io->overlapped.hEvent)); } - break; + } + break; - case IOSTATE_INITIAL: - SetLastError(ERROR_INVALID_FUNCTION); + case IOSTATE_IMMEDIATE_RETURN: + io->iostate = IOSTATE_INITIAL; + assert(ResetEvent(io->overlapped.hEvent)); + if (io->status) { + SetLastError(io->status); ret = -1; - err("%s : Overlapped result wrong state\n", __func__); - break; + } else { + ret = io->size; + } + break; + + case IOSTATE_INITIAL: + SetLastError(ERROR_INVALID_FUNCTION); + ret = -1; + err("%s : Overlapped result wrong state\n", __func__); + break; - default: - assert(0); + default: + assert(0); } return ret; } -static long readv(struct mt_cni_impl* cni, struct iovec* iov, int count) { - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; +static long readv(struct mt_cni_impl *cni, struct iovec *iov, int count) { + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; long rlen = -1, total = 0; BOOL status; int err; @@ -167,7 +175,8 @@ static long readv(struct mt_cni_impl* cni, struct iovec* iov, int count) { rlen = 0; } } - if (rlen <= 0) return rlen; + if (rlen <= 0) + return rlen; total += rlen; iov++; count--; @@ -175,16 +184,17 @@ static long readv(struct mt_cni_impl* cni, struct iovec* iov, int count) { return total; } -static long writev(struct mt_cni_impl* cni, struct iovec* iov, int count) { +static long writev(struct mt_cni_impl *cni, struct iovec *iov, int count) { long totallen = 0, wlen = -1; BOOL status; int err; - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; while (count) { wlen = 0; assert(ResetEvent(tap_ctx->writes.overlapped.hEvent)); - status = WriteFile(tap_ctx->tap_handle, (const char*)iov->iov_base, iov->iov_len, - &tap_ctx->writes.size, &tap_ctx->writes.overlapped); + status = WriteFile(tap_ctx->tap_handle, (const char *)iov->iov_base, + iov->iov_len, &tap_ctx->writes.size, + &tap_ctx->writes.overlapped); if (status) { tap_ctx->writes.iostate = IOSTATE_IMMEDIATE_RETURN; assert(SetEvent(tap_ctx->writes.overlapped.hEvent)); @@ -201,7 +211,8 @@ static long writev(struct mt_cni_impl* cni, struct iovec* iov, int count) { tap_ctx->writes.status = err; } } - if (wlen <= 0) return totallen; + if (wlen <= 0) + return totallen; totallen += wlen; iov++; count--; @@ -209,20 +220,22 @@ static long writev(struct mt_cni_impl* cni, struct iovec* iov, int count) { return totallen; } -static uint16_t tap_tx_packet(struct mt_cni_impl* cni, struct rte_mbuf** bufs, +static uint16_t tap_tx_packet(struct mt_cni_impl *cni, struct rte_mbuf **bufs, uint16_t nb_pkts) { int ret = 0; - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; - if (unlikely(nb_pkts == 0)) return 0; - if (io_active(&tap_ctx->writes)) ret = overlapped_result(cni, &tap_ctx->writes); + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; + if (unlikely(nb_pkts == 0)) + return 0; + if (io_active(&tap_ctx->writes)) + ret = overlapped_result(cni, &tap_ctx->writes); if (tap_ctx->writes.iostate == IOSTATE_INITIAL) { - struct rte_mbuf* mbuf = bufs[0]; + struct rte_mbuf *mbuf = bufs[0]; static struct iovec iovecs[2]; - struct rte_mbuf* seg = mbuf; + struct rte_mbuf *seg = mbuf; iovecs[0].iov_len = rte_pktmbuf_data_len(seg); - iovecs[0].iov_base = rte_pktmbuf_mtod(seg, void*); + iovecs[0].iov_base = rte_pktmbuf_mtod(seg, void *); ret = writev(cni, iovecs, 1); if (ret == -1) { err("%s write buffer error\n", __func__); @@ -234,47 +247,55 @@ static uint16_t tap_tx_packet(struct mt_cni_impl* cni, struct rte_mbuf** bufs, return 0; } -static uint16_t tap_rx_packet(struct mt_cni_impl* cni, struct rte_mbuf** bufs, +static uint16_t tap_rx_packet(struct mt_cni_impl *cni, struct rte_mbuf **bufs, uint16_t nb_pkts) { int len; uint16_t num_rx = 0; unsigned long num_rx_bytes = 0; - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; - if (!nb_pkts) return 0; - if (io_active(&tap_ctx->reads)) overlapped_result(cni, &tap_ctx->reads); + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; + if (!nb_pkts) + return 0; + if (io_active(&tap_ctx->reads)) + overlapped_result(cni, &tap_ctx->reads); - if (tap_ctx->reads.iostate == IOSTATE_INITIAL) readv(cni, *tap_ctx->iovecs, 1); + if (tap_ctx->reads.iostate == IOSTATE_INITIAL) + readv(cni, *tap_ctx->iovecs, 1); len = tap_ctx->reads.size; if (len > 0) { - struct rte_mbuf* mbuf = tap_ctx->pool; - struct rte_mbuf* seg = NULL; - struct rte_mbuf* new_tail = NULL; + struct rte_mbuf *mbuf = tap_ctx->pool; + struct rte_mbuf *seg = NULL; + struct rte_mbuf *new_tail = NULL; uint16_t data_off = rte_pktmbuf_headroom(mbuf); mbuf->pkt_len = len; mbuf->nb_segs = 0; while (1) { - struct rte_mbuf* buf = rte_pktmbuf_alloc(tap_ctx->mp); + struct rte_mbuf *buf = rte_pktmbuf_alloc(tap_ctx->mp); if (unlikely(!buf)) { - if (!new_tail || !seg) goto end; + if (!new_tail || !seg) + goto end; seg->next = NULL; tap_rxq_pool_free(mbuf); goto end; } seg = seg ? seg->next : mbuf; - if (tap_ctx->pool == mbuf) tap_ctx->pool = buf; - if (new_tail) new_tail->next = buf; + if (tap_ctx->pool == mbuf) + tap_ctx->pool = buf; + if (new_tail) + new_tail->next = buf; new_tail = buf; new_tail->next = seg->next; (*tap_ctx->iovecs)[mbuf->nb_segs].iov_len = buf->buf_len - data_off; - (*tap_ctx->iovecs)[mbuf->nb_segs].iov_base = (char*)buf->buf_addr + data_off; + (*tap_ctx->iovecs)[mbuf->nb_segs].iov_base = + (char *)buf->buf_addr + data_off; seg->data_len = RTE_MIN(seg->buf_len - data_off, len); seg->data_off = data_off; len -= seg->data_len; - if (len <= 0) break; + if (len <= 0) + break; mbuf->nb_segs++; /* First segment has headroom, not the others */ data_off = 0; @@ -287,8 +308,8 @@ static uint16_t tap_rx_packet(struct mt_cni_impl* cni, struct rte_mbuf** bufs, return num_rx; } -static struct rte_flow* tap_create_flow(struct mt_cni_impl* cni, uint16_t port_id, - uint16_t q) { +static struct rte_flow *tap_create_flow(struct mt_cni_impl *cni, + uint16_t port_id, uint16_t q) { struct rte_flow_attr attr; struct rte_flow_item pattern[4]; struct rte_flow_action action[2]; @@ -302,9 +323,9 @@ static struct rte_flow* tap_create_flow(struct mt_cni_impl* cni, uint16_t port_i char pkt_buf[90]; char msk_buf[90]; struct rte_flow_error error; - struct rte_flow* r_flow; + struct rte_flow *r_flow; int ret; - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; memset(&error, 0, sizeof(error)); @@ -321,8 +342,9 @@ static struct rte_flow* tap_create_flow(struct mt_cni_impl* cni, uint16_t port_i memset(&ipv4_mask.hdr.dst_addr, 0xFF, MTL_IP_ADDR_LEN); rte_memcpy(&ipv4_spec.hdr.dst_addr, tap_ctx->ip_addr, MTL_IP_ADDR_LEN); - info("Flow bind to ip address inet %02x %02x %02x %02x \n", tap_ctx->ip_addr[0], - tap_ctx->ip_addr[1], tap_ctx->ip_addr[2], tap_ctx->ip_addr[3]); + info("Flow bind to ip address inet %02x %02x %02x %02x \n", + tap_ctx->ip_addr[0], tap_ctx->ip_addr[1], tap_ctx->ip_addr[2], + tap_ctx->ip_addr[3]); memset(&attr, 0, sizeof(attr)); attr.ingress = 1; @@ -344,8 +366,8 @@ static struct rte_flow* tap_create_flow(struct mt_cni_impl* cni, uint16_t port_i ret = rte_flow_validate(port_id, &attr, pattern, action, &error); if (ret < 0) { - err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port_id, ret, q, - mt_string_safe(error.message)); + err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, + port_id, ret, q, mt_string_safe(error.message)); return NULL; } @@ -367,21 +389,23 @@ static struct rte_flow* tap_create_flow(struct mt_cni_impl* cni, uint16_t port_i memset(pkt_buf, 0, sizeof(pkt_buf)); memset(msk_buf, 0, sizeof(msk_buf)); snprintf(pkt_buf, 84, "%s", - "00000000000100000000000208060001080006040000000000000001010101010000000000020" + "0000000000010000000000020806000108000604000000000000000101010101000" + "0000000020" "2020202"); - snprintf(pkt_buf, 12, "%02x%02x%02x%02x%02x%02x", tap_ctx->mac_addr.addr_bytes[0], - tap_ctx->mac_addr.addr_bytes[1], tap_ctx->mac_addr.addr_bytes[2], - tap_ctx->mac_addr.addr_bytes[3], tap_ctx->mac_addr.addr_bytes[4], - tap_ctx->mac_addr.addr_bytes[5]); + snprintf(pkt_buf, 12, "%02x%02x%02x%02x%02x%02x", + tap_ctx->mac_addr.addr_bytes[0], tap_ctx->mac_addr.addr_bytes[1], + tap_ctx->mac_addr.addr_bytes[2], tap_ctx->mac_addr.addr_bytes[3], + tap_ctx->mac_addr.addr_bytes[4], tap_ctx->mac_addr.addr_bytes[5]); info("Flow bind to mac address %12.12s \n", pkt_buf); snprintf(msk_buf, 84, "%s", - "FFFFFFFFFFFF000000000000FFFF0000000000000000000000000000000000000000000000000" + "FFFFFFFFFFFF000000000000FFFF000000000000000000000000000000000000000" + "0000000000" "0000000"); memset(pattern, 0, sizeof(pattern)); - spec.pattern = (void*)pkt_buf; + spec.pattern = (void *)pkt_buf; spec.length = 42; - mask.pattern = (void*)msk_buf; + mask.pattern = (void *)msk_buf; mask.length = 42; memset(pattern, 0, sizeof(pattern)); @@ -392,21 +416,21 @@ static struct rte_flow* tap_create_flow(struct mt_cni_impl* cni, uint16_t port_i r_flow = rte_flow_create(port_id, &attr, pattern, action, &error); if (!r_flow) { - err("%s(%d), rte_flow_create 2 fail for queue %d, %s\n", __func__, port_id, q, - mt_string_safe(error.message)); + err("%s(%d), rte_flow_create 2 fail for queue %d, %s\n", __func__, port_id, + q, mt_string_safe(error.message)); return NULL; } return r_flow; } -static int tap_get_ipaddress(struct mt_cni_impl* cni) { +static int tap_get_ipaddress(struct mt_cni_impl *cni) { PIP_ADAPTER_INFO pAdapterInfo; PIP_ADAPTER_INFO pAdapter = NULL; DWORD dwRetVal = 0; static const char library_name[] = "IPHLPAPI.dll"; static const char function[] = "GetAdaptersInfo"; ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO); - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; HMODULE library = NULL; library = LoadLibraryA(library_name); @@ -415,34 +439,38 @@ static int tap_get_ipaddress(struct mt_cni_impl* cni) { return 1; } - GetAdaptersInfo_ptr = (GetAdaptersInfo_type)((void*)GetProcAddress(library, function)); + GetAdaptersInfo_ptr = + (GetAdaptersInfo_type)((void *)GetProcAddress(library, function)); if (GetAdaptersInfo_ptr == NULL) { err("GetProcAddress(\"%s\", \"%s\")\n", library_name, function); return 1; } - pAdapterInfo = (IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO)); + pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO)); if (pAdapterInfo == NULL) { err("Error allocating memory needed to call GetAdaptersinfo\n"); return 1; } - if (GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { + if (GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen) == + ERROR_BUFFER_OVERFLOW) { free(pAdapterInfo); - pAdapterInfo = (IP_ADAPTER_INFO*)malloc(ulOutBufLen); + pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); if (pAdapterInfo == NULL) { err("Error allocating memory needed to call GetAdaptersinfo\n"); return 1; } } - if ((dwRetVal = GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) { + if ((dwRetVal = GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen)) == + NO_ERROR) { pAdapter = pAdapterInfo; while (pAdapter) { dbg("\tAdapter Name: \t%s\n", pAdapter->AdapterName); if (strcmpi(tap_ctx->tap_name, pAdapter->AdapterName) == 0) { dbg("Found ip address %s\n", pAdapter->IpAddressList.IpAddress.String); - inet_pton(AF_INET, pAdapter->IpAddressList.IpAddress.String, tap_ctx->ip_addr); + inet_pton(AF_INET, pAdapter->IpAddressList.IpAddress.String, + tap_ctx->ip_addr); } dbg("\tAdapter Desc: \t%s\n", pAdapter->Description); dbg("\tIP Address: \t%s\n", pAdapter->IpAddressList.IpAddress.String); @@ -452,9 +480,9 @@ static int tap_get_ipaddress(struct mt_cni_impl* cni) { return 0; } -static int tap_uninit_lcore(struct mtl_main_impl* impl) { - struct mt_cni_impl* cni = mt_get_cni(impl); - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; +static int tap_uninit_lcore(struct mtl_main_impl *impl) { + struct mt_cni_impl *cni = mt_get_cni(impl); + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; while (rte_atomic32_read(&cni->stop_tap) == 0) { mt_sleep_ms(10); @@ -469,15 +497,15 @@ static int tap_uninit_lcore(struct mtl_main_impl* impl) { // Thread to handle rx packets in ring buffer from NIC card // Write packet to TAP from ring buffer // Read packets from TAP driver and directly transfer to NIC card -static int tap_bkg_thread(void* arg) { - struct mtl_main_impl* impl = arg; - struct mt_cni_impl* cni = mt_get_cni(impl); +static int tap_bkg_thread(void *arg) { + struct mtl_main_impl *impl = arg; + struct mt_cni_impl *cni = mt_get_cni(impl); int num_ports = mt_num_ports(impl); int i; - void* data = NULL; + void *data = NULL; uint16_t rx, tx, count; - struct rte_mbuf* pkts_rx[1]; - struct rte_mbuf* pkts_tx[1]; + struct rte_mbuf *pkts_rx[1]; + struct rte_mbuf *pkts_tx[1]; pkts_tx[0] = NULL; pkts_rx[0] = NULL; @@ -487,7 +515,8 @@ static int tap_bkg_thread(void* arg) { for (i = 0; i < num_ports; i++) { count = rte_ring_count(tap_tx_ring); while (count) { - if (!pkts_tx[0]) pkts_tx[0] = tap_get_mbuf(tap_tx_ring, &data, &tx); + if (!pkts_tx[0]) + pkts_tx[0] = tap_get_mbuf(tap_tx_ring, &data, &tx); if (pkts_tx[0]) { tx = tap_tx_packet(cni, pkts_tx, 1); if (tx > 0) { @@ -515,14 +544,15 @@ static int tap_bkg_thread(void* arg) { return 0; } -static int tap_queues_uinit(struct mtl_main_impl* impl) { +static int tap_queues_uinit(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); - struct mt_cni_impl* cni = mt_get_cni(impl); - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; + struct mt_cni_impl *cni = mt_get_cni(impl); + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; for (int i = 0; i < num_ports; i++) { if (cni->tap_tx_q[i]) { - struct rte_mbuf* pad = mt_get_pad(impl, i); - if (pad) mt_txq_flush(cni->tap_tx_q[i], pad); + struct rte_mbuf *pad = mt_get_pad(impl, i); + if (pad) + mt_txq_flush(cni->tap_tx_q[i], pad); mt_txq_put(cni->tap_tx_q[i]); cni->tap_tx_q[i] = NULL; } @@ -531,9 +561,12 @@ static int tap_queues_uinit(struct mtl_main_impl* impl) { cni->tap_rx_q[i] = NULL; } } - if (tap_ctx->iovecs) rte_free(tap_ctx->iovecs); - if (tap_ctx->pool) tap_rxq_pool_free(tap_ctx->pool); - if (tap_ctx->mp) mt_mempool_free(tap_ctx->mp); + if (tap_ctx->iovecs) + rte_free(tap_ctx->iovecs); + if (tap_ctx->pool) + tap_rxq_pool_free(tap_ctx->pool); + if (tap_ctx->mp) + mt_mempool_free(tap_ctx->mp); return 0; } @@ -541,16 +574,17 @@ static int configure_tap() { int ret, i; char ring_name[32]; unsigned int flags, count; - struct mtl_main_impl* impl = tap_get_global_impl(); - struct mt_cni_impl* cni = mt_get_cni(impl); - struct mt_interface* inf = mt_if(impl, 0); + struct mtl_main_impl *impl = tap_get_global_impl(); + struct mt_cni_impl *cni = mt_get_cni(impl); + struct mt_interface *inf = mt_if(impl, 0); struct iovec(*iovecs)[inf->nb_rx_desc + 1]; int data_off = RTE_PKTMBUF_HEADROOM; - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; - struct rte_mbuf** tmp = &tap_ctx->pool; - struct rte_mempool* mbuf_pool = mt_mempool_create( + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; + struct rte_mbuf **tmp = &tap_ctx->pool; + struct rte_mempool *mbuf_pool = mt_mempool_create( impl, 0, "tap", inf->nb_rx_desc + ST_TX_VIDEO_SESSIONS_RING_SIZE, - MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), ST_PKT_MAX_ETHER_BYTES); + MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), + ST_PKT_MAX_ETHER_BYTES); if (!mbuf_pool) { err("%s tap mempool create fail\n", __func__); return -ENOMEM; @@ -572,7 +606,7 @@ static int configure_tap() { return ret; } (*tap_ctx->iovecs)[i].iov_len = (*tmp)->buf_len - data_off; - (*tap_ctx->iovecs)[i].iov_base = (char*)(*tmp)->buf_addr + data_off; + (*tap_ctx->iovecs)[i].iov_base = (char *)(*tmp)->buf_addr + data_off; data_off = 0; tmp = &(*tmp)->next; } @@ -587,48 +621,49 @@ static int configure_tap() { return 0; } -static bool tap_open_device(struct mt_cni_impl* cni, +static bool tap_open_device(struct mt_cni_impl *cni, PSP_DEVICE_INTERFACE_DETAIL_DATA dev_ifx_detail) { - struct mtl_main_impl* impl = tap_get_global_impl(); - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; - char* path; + struct mtl_main_impl *impl = tap_get_global_impl(); + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; + char *path; char tap_device_path[MAX_PATH]; - path = strrchr(dev_ifx_detail->DevicePath, '\\'); // find the last character '\' - if (path) // remove the character '\' + path = + strrchr(dev_ifx_detail->DevicePath, '\\'); // find the last character '\' + if (path) // remove the character '\' path++; else return false; snprintf(tap_ctx->tap_name, sizeof(tap_ctx->tap_name), "%s", path); - snprintf(tap_device_path, sizeof(tap_device_path), "%s%s%s", USERMODEDEVICEDIR, path, - TAP_WIN_SUFFIX); + snprintf(tap_device_path, sizeof(tap_device_path), "%s%s%s", + USERMODEDEVICEDIR, path, TAP_WIN_SUFFIX); info("%s create file path %s\n", __func__, tap_device_path); - tap_ctx->tap_handle = - CreateFile(tap_device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, - FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); + tap_ctx->tap_handle = CreateFile( + tap_device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, + FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); if (tap_ctx->tap_handle == NULL) { err("CreateFile failed on device: %s\n", tap_device_path); return false; } ULONG mtu = 0; DWORD len; - if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMTU, &mtu, sizeof(mtu), &mtu, - sizeof(mtu), &len, NULL)) { + if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMTU, &mtu, + sizeof(mtu), &mtu, sizeof(mtu), &len, NULL)) { info("TAP-Windows MTU=%d\n", (int)mtu); } ULONG info[3]; memset(info, 0, sizeof(info)); - if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPVER, &info, sizeof(info), - &info, sizeof(info), &len, NULL)) { + if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPVER, &info, + sizeof(info), &info, sizeof(info), &len, NULL)) { info("TAP-Windows Driver Version %d.%d %s\n", (int)info[0], (int)info[1], (info[2] ? "(DEBUG)" : "")); } unsigned char mac[6]; memset(mac, 0, sizeof(mac)); - if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMAC, &mac, sizeof(mac), &mac, - sizeof(mac), &len, NULL)) { + if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMAC, &mac, + sizeof(mac), &mac, sizeof(mac), &len, NULL)) { rte_memcpy(tap_ctx->mac_addr.addr_bytes, mac, 6); info("TAP-Windows Mac address %02x-%02x-%02x-%02x-%02x-%02x\n", tap_ctx->mac_addr.addr_bytes[0], tap_ctx->mac_addr.addr_bytes[1], @@ -639,9 +674,9 @@ static bool tap_open_device(struct mt_cni_impl* cni, ULONG status = TRUE; if (!DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_SET_TAPSTATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL)) { - info( - "WARNING: The TAP-Windows driver rejected a TAP_WIN_IOCTL_SET_MEDIA_STATUS " - "DeviceIoControl call.\n"); + info("WARNING: The TAP-Windows driver rejected a " + "TAP_WIN_IOCTL_SET_MEDIA_STATUS " + "DeviceIoControl call.\n"); } memset(&tap_ctx->writes, 0, sizeof(tap_ctx->writes)); @@ -660,7 +695,8 @@ static bool tap_open_device(struct mt_cni_impl* cni, for (int i = 0; i < num_ports; i++) { if (rte_eth_dev_mac_addr_add(mt_port_id(impl, i), &tap_ctx->mac_addr, 0)) err("%s bind to mac failed \n", __func__); - tap_create_flow(cni, mt_port_id(impl, i), mt_rxq_queue_id(cni->tap_rx_q[i])); + tap_create_flow(cni, mt_port_id(impl, i), + mt_rxq_queue_id(cni->tap_rx_q[i])); } } return true; @@ -674,7 +710,8 @@ static HDEVINFO get_tap_device_information_set(HDEVINFO tapinfo, HDEVINFO tapset; /* obtain the driver interface for this device */ - ret = SetupDiGetDeviceInstanceId(tapinfo, tapdata, tap_id, sizeof(tap_id), &size); + ret = SetupDiGetDeviceInstanceId(tapinfo, tapdata, tap_id, sizeof(tap_id), + &size); if (ret) { dbg("%s tap device id %s\n", __func__, tap_id); tapset = SetupDiGetClassDevs(&GUID_NDIS_LAN_CLASS, tap_id, NULL, @@ -690,7 +727,8 @@ static HDEVINFO get_tap_device_information_set(HDEVINFO tapinfo, } } -static PSP_DEVICE_INTERFACE_DETAIL_DATA get_tap_device_interface_detail(HDEVINFO tapset) { +static PSP_DEVICE_INTERFACE_DETAIL_DATA +get_tap_device_interface_detail(HDEVINFO tapset) { BOOL ret; DWORD size = 0; SP_DEVICE_INTERFACE_DATA tap_interface_data; @@ -703,15 +741,17 @@ static PSP_DEVICE_INTERFACE_DETAIL_DATA get_tap_device_interface_detail(HDEVINFO &tap_interface_data); if (ret) { size = 0; - ret = SetupDiGetDeviceInterfaceDetail(tapset, &tap_interface_data, NULL, 0, &size, - NULL); + ret = SetupDiGetDeviceInterfaceDetail(tapset, &tap_interface_data, NULL, 0, + &size, NULL); if (!ret) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { tap_interface_detail = calloc(size, sizeof(char)); if (tap_interface_detail) { - tap_interface_detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + tap_interface_detail->cbSize = + sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); ret = SetupDiGetDeviceInterfaceDetail(tapset, &tap_interface_data, - tap_interface_detail, size, NULL, NULL); + tap_interface_detail, size, + NULL, NULL); if (!ret) { err("Error get tap interface detail"); free(tap_interface_detail); @@ -732,14 +772,14 @@ static PSP_DEVICE_INTERFACE_DETAIL_DATA get_tap_device_interface_detail(HDEVINFO return NULL; } -static int tap_device_init(struct mt_cni_impl* cni) { +static int tap_device_init(struct mt_cni_impl *cni) { DWORD device_index = 0; HDEVINFO dev_info; SP_DEVINFO_DATA device_info_data; char sz_buffer[MAX_PATH]; HDEVINFO di_set = INVALID_HANDLE_VALUE; PSP_DEVICE_INTERFACE_DETAIL_DATA dev_ifx_detail = NULL; - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; dev_info = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL, DIGCF_PRESENT); if (dev_info == INVALID_HANDLE_VALUE) { @@ -753,21 +793,27 @@ static int tap_device_init(struct mt_cni_impl* cni) { device_index++; /* we only want to enumerate net class devices */ memset(sz_buffer, 0, sizeof(sz_buffer)); - SetupDiGetDeviceRegistryProperty(dev_info, &device_info_data, SPDRP_DEVICEDESC, NULL, - (PBYTE)&sz_buffer, sizeof(sz_buffer), NULL); + SetupDiGetDeviceRegistryProperty(dev_info, &device_info_data, + SPDRP_DEVICEDESC, NULL, (PBYTE)&sz_buffer, + sizeof(sz_buffer), NULL); if (strstr(sz_buffer, TAP_WIN_DRIVERNAME) != NULL) { di_set = get_tap_device_information_set(dev_info, &device_info_data); - if (di_set == INVALID_HANDLE_VALUE) continue; + if (di_set == INVALID_HANDLE_VALUE) + continue; dev_ifx_detail = get_tap_device_interface_detail(di_set); if (!dev_ifx_detail) { - if (di_set != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(di_set); + if (di_set != INVALID_HANDLE_VALUE) + SetupDiDestroyDeviceInfoList(di_set); continue; } else { if (tap_open_device(cni, dev_ifx_detail)) { - if (dev_ifx_detail) free(dev_ifx_detail); - if (di_set != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(di_set); + if (dev_ifx_detail) + free(dev_ifx_detail); + if (di_set != INVALID_HANDLE_VALUE) + SetupDiDestroyDeviceInfoList(di_set); - if (dev_info != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(dev_info); + if (dev_info != INVALID_HANDLE_VALUE) + SetupDiDestroyDeviceInfoList(dev_info); break; } @@ -776,33 +822,36 @@ static int tap_device_init(struct mt_cni_impl* cni) { memset(&device_info_data, 0, sizeof(SP_DEVINFO_DATA)); device_info_data.cbSize = sizeof(SP_DEVINFO_DATA); } - if (dev_info != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(dev_info); + if (dev_info != INVALID_HANDLE_VALUE) + SetupDiDestroyDeviceInfoList(dev_info); if (tap_ctx->tap_handle) return 0; else return -EIO; } -static int tap_device_uninit(struct mtl_main_impl* impl) { - struct rte_mbuf* pkts_rx; - void* data = NULL; +static int tap_device_uninit(struct mtl_main_impl *impl) { + struct rte_mbuf *pkts_rx; + void *data = NULL; uint16_t tx; - struct mt_cni_impl* cni = mt_get_cni(impl); - struct tap_rt_context* tap_ctx = (struct tap_rt_context*)cni->tap_context; + struct mt_cni_impl *cni = mt_get_cni(impl); + struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; pkts_rx = tap_get_mbuf(tap_tx_ring, &data, &tx); while (pkts_rx) { mt_free_mbufs(&pkts_rx, 1); pkts_rx = tap_get_mbuf(tap_tx_ring, &data, &tx); } - if (tap_ctx->tap_handle) CloseHandle(tap_ctx->tap_handle); + if (tap_ctx->tap_handle) + CloseHandle(tap_ctx->tap_handle); return 0; } static const struct rte_eth_txconf dev_tx_port_conf = {.tx_rs_thresh = 1, .tx_free_thresh = 1}; -static int tap_queues_init(struct mtl_main_impl* impl, struct mt_cni_impl* cni) { +static int tap_queues_init(struct mtl_main_impl *impl, + struct mt_cni_impl *cni) { int num_ports = mt_num_ports(impl); uint16_t nb_tx_desc; @@ -830,8 +879,9 @@ static int tap_queues_init(struct mtl_main_impl* impl, struct mt_cni_impl* cni) } nb_tx_desc = mt_if_nb_tx_desc(impl, i); socket_id = rte_eth_dev_socket_id(mt_port_id(impl, i)); - ret = rte_eth_tx_queue_setup(mt_port_id(impl, i), mt_txq_queue_id(cni->tap_tx_q[i]), - nb_tx_desc, socket_id, &dev_tx_port_conf); + ret = rte_eth_tx_queue_setup(mt_port_id(impl, i), + mt_txq_queue_id(cni->tap_tx_q[i]), nb_tx_desc, + socket_id, &dev_tx_port_conf); if (ret < 0) { err("%s(%d), rte_eth_tx_queue_setup fail %d\n", __func__, i, ret); return ret; @@ -858,9 +908,9 @@ static int tap_queues_init(struct mtl_main_impl* impl, struct mt_cni_impl* cni) return 0; } -int mt_tap_handle(struct mtl_main_impl* impl, enum mtl_port port) { - struct mt_cni_impl* cni = mt_get_cni(impl); - struct rte_mbuf* pkts_rx[ST_CNI_RX_BURST_SIZE]; +int mt_tap_handle(struct mtl_main_impl *impl, enum mtl_port port) { + struct mt_cni_impl *cni = mt_get_cni(impl); + struct rte_mbuf *pkts_rx[ST_CNI_RX_BURST_SIZE]; uint16_t rx; if (rte_atomic32_read(&cni->stop_tap)) { @@ -880,27 +930,30 @@ int mt_tap_handle(struct mtl_main_impl* impl, enum mtl_port port) { return 0; } -int mt_tap_init(struct mtl_main_impl* impl) { +int mt_tap_init(struct mtl_main_impl *impl) { int ret; - struct mt_cni_impl* cni = mt_get_cni(impl); + struct mt_cni_impl *cni = mt_get_cni(impl); unsigned int lcore; - struct tap_rt_context* tap_ctx; + struct tap_rt_context *tap_ctx; tap_set_global_impl(impl); cni->tap_context = calloc(sizeof(struct tap_rt_context), sizeof(char)); - tap_ctx = (struct tap_rt_context*)cni->tap_context; + tap_ctx = (struct tap_rt_context *)cni->tap_context; tap_ctx->flow_control = - true; // if do not need flow control, should set NIC to promiscuous mode + true; // if do not need flow control, should set NIC to promiscuous mode ret = tap_queues_init(impl, cni); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = tap_device_init(cni); - if (ret < 0) return ret; + if (ret < 0) + return ret; rte_atomic32_set(&cni->stop_tap, 0); tap_ctx->has_lcore = false; - ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_TAP, mt_socket_id(impl, MTL_PORT_P)); + ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_TAP, + mt_socket_id(impl, MTL_PORT_P)); if (ret < 0) { err("%s, get lcore fail %d\n", __func__, ret); mt_tap_uinit(impl); @@ -918,8 +971,8 @@ int mt_tap_init(struct mtl_main_impl* impl) { return 0; } -int mt_tap_uinit(struct mtl_main_impl* impl) { - struct mt_cni_impl* cni = mt_get_cni(impl); +int mt_tap_uinit(struct mtl_main_impl *impl) { + struct mt_cni_impl *cni = mt_get_cni(impl); rte_atomic32_set(&cni->stop_tap, 1); if (cni->tap_bkg_tid) { @@ -930,7 +983,8 @@ int mt_tap_uinit(struct mtl_main_impl* impl) { tap_queues_uinit(impl); tap_device_uninit(impl); tap_set_global_impl(NULL); - if (cni->tap_context) free(cni->tap_context); + if (cni->tap_context) + free(cni->tap_context); info("%s, succ\n", __func__); return 0; } diff --git a/lib/src/mt_tap.h b/lib/src/mt_tap.h index e7f98ced0..c61d71ef8 100644 --- a/lib/src/mt_tap.h +++ b/lib/src/mt_tap.h @@ -16,7 +16,7 @@ #define TAP_IOV_DEFAULT_MAX 1024 -#define ST_TAP_CTL_CODE(code) \ +#define ST_TAP_CTL_CODE(code) \ CTL_CODE(FILE_DEVICE_UNKNOWN, code, METHOD_BUFFERED, FILE_ANY_ACCESS) #define ST_IOCTL_GET_TAPMAC ST_TAP_CTL_CODE(1) @@ -44,7 +44,7 @@ enum windows_driver_type { #define IOSTATE_INITIAL 0 #define IOSTATE_QUEUED 1 /* overlapped I/O has been queued */ -#define IOSTATE_IMMEDIATE_RETURN \ +#define IOSTATE_IMMEDIATE_RETURN \ 2 /* I/O function returned immediately without queueing */ struct overlapped_io { @@ -56,13 +56,13 @@ struct overlapped_io { }; struct iovec { - void* iov_base; /* Pointer to data. */ + void *iov_base; /* Pointer to data. */ size_t iov_len; /* Length of data. */ }; struct tap_rt_context { - struct rte_mempool* mp; - struct rte_mbuf* pool; + struct rte_mempool *mp; + struct rte_mbuf *pool; struct iovec (*iovecs)[]; HANDLE tap_handle; struct overlapped_io reads; @@ -75,20 +75,21 @@ struct tap_rt_context { bool flow_control; }; -int mt_tap_init(struct mtl_main_impl* impl); -int mt_tap_uinit(struct mtl_main_impl* impl); -int mt_tap_handle(struct mtl_main_impl* impl, enum mtl_port port); +int mt_tap_init(struct mtl_main_impl *impl); +int mt_tap_uinit(struct mtl_main_impl *impl); +int mt_tap_handle(struct mtl_main_impl *impl, enum mtl_port port); #else -static inline int mt_tap_init(struct mtl_main_impl* impl) { +static inline int mt_tap_init(struct mtl_main_impl *impl) { MTL_MAY_UNUSED(impl); return 0; } -static inline int mt_tap_uinit(struct mtl_main_impl* impl) { +static inline int mt_tap_uinit(struct mtl_main_impl *impl) { MTL_MAY_UNUSED(impl); return 0; } -static inline int mt_tap_handle(struct mtl_main_impl* impl, enum mtl_port port) { +static inline int mt_tap_handle(struct mtl_main_impl *impl, + enum mtl_port port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); return -EIO; diff --git a/lib/src/mt_usdt.h b/lib/src/mt_usdt.h index a59e3da41..168e75b4f 100644 --- a/lib/src/mt_usdt.h +++ b/lib/src/mt_usdt.h @@ -7,50 +7,55 @@ #ifdef MTL_HAS_USDT -/* mt_usdt_provider.h auto generated by the dtrace tool from mt_usdt_provider.d */ +/* mt_usdt_provider.h auto generated by the dtrace tool from mt_usdt_provider.d + */ #include "mt_usdt_provider.h" #define MT_DTRACE_PROBE(provider, probe) DTRACE_PROBE(provider, probe) -#define MT_DTRACE_PROBE1(provider, probe, parm1) DTRACE_PROBE1(provider, probe, parm1) -#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ +#define MT_DTRACE_PROBE1(provider, probe, parm1) \ + DTRACE_PROBE1(provider, probe, parm1) +#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ DTRACE_PROBE2(provider, probe, parm1, parm2) -#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ +#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) -#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ +#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) -#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ +#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) -#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6) \ +#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, \ + parm6) \ DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6) -#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, \ - parm7) \ - DTRACE_PROBE7(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, parm7) +#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, \ + parm6, parm7) \ + DTRACE_PROBE7(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, \ + parm7) #else -#define MT_DTRACE_PROBE(provider, probe) \ - do { \ +#define MT_DTRACE_PROBE(provider, probe) \ + do { \ } while (0) -#define MT_DTRACE_PROBE1(provider, probe, parm1) \ - do { \ +#define MT_DTRACE_PROBE1(provider, probe, parm1) \ + do { \ } while (0) -#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ - do { \ +#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ + do { \ } while (0) -#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ - do { \ +#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ + do { \ } while (0) -#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ - do { \ +#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ + do { \ } while (0) -#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ - do { \ +#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ + do { \ } while (0) -#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6) \ - do { \ +#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, \ + parm6) \ + do { \ } while (0) -#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, \ - parm7) \ - do { \ +#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, \ + parm6, parm7) \ + do { \ } while (0) #define SYS_LOG_MSG_ENABLED() (0) @@ -80,172 +85,189 @@ #endif -#define MT_USDT_PTP_MSG(port, stage, value) \ +#define MT_USDT_PTP_MSG(port, stage, value) \ MT_DTRACE_PROBE3(ptp, ptp_msg, port, stage, value) -#define MT_USDT_PTP_RESULT(port, delta, correct) \ +#define MT_USDT_PTP_RESULT(port, delta, correct) \ MT_DTRACE_PROBE3(ptp, ptp_result, port, delta, correct) -#define MT_USDT_SYS_LOG_MSG(level, msg) MT_DTRACE_PROBE2(sys, log_msg, level, msg) +#define MT_USDT_SYS_LOG_MSG(level, msg) \ + MT_DTRACE_PROBE2(sys, log_msg, level, msg) #define MT_USDT_SYS_LOG_MSG_ENABLED() SYS_LOG_MSG_ENABLED() #define MT_SYS_TASKLET_TIME_MEASURE() MT_DTRACE_PROBE(sys, tasklet_time_measure) -#define MT_USDT_TASKLET_TIME_MEASURE_ENABLED() SYS_TASKLET_TIME_MEASURE_ENABLED() +#define MT_USDT_TASKLET_TIME_MEASURE_ENABLED() \ + SYS_TASKLET_TIME_MEASURE_ENABLED() -#define MT_SYS_SESSIONS_TIME_MEASURE() MT_DTRACE_PROBE(sys, sessions_time_measure) -#define MT_USDT_SESSIONS_TIME_MEASURE_ENABLED() SYS_SESSIONS_TIME_MEASURE_ENABLED() +#define MT_SYS_SESSIONS_TIME_MEASURE() \ + MT_DTRACE_PROBE(sys, sessions_time_measure) +#define MT_USDT_SESSIONS_TIME_MEASURE_ENABLED() \ + SYS_SESSIONS_TIME_MEASURE_ENABLED() -#define MT_USDT_CNI_PCAP_DUMP(port, file, pkts) \ +#define MT_USDT_CNI_PCAP_DUMP(port, file, pkts) \ MT_DTRACE_PROBE3(sys, cni_pcap_dump, port, file, pkts) #define MT_USDT_CNI_PCAP_DUMP_ENABLED() SYS_CNI_PCAP_DUMP_ENABLED() -#define MT_USDT_ST20P_TX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST20P_TX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st20p, tx_frame_get, idx, f_idx, va) -#define MT_USDT_ST20P_TX_FRAME_PUT(idx, f_idx, va, stat) \ +#define MT_USDT_ST20P_TX_FRAME_PUT(idx, f_idx, va, stat) \ MT_DTRACE_PROBE4(st20p, tx_frame_put, idx, f_idx, va, stat) -#define MT_USDT_ST20P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ +#define MT_USDT_ST20P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ MT_DTRACE_PROBE3(st20p, tx_frame_done, idx, f_idx, tmstamp) -#define MT_USDT_ST20P_TX_FRAME_NEXT(idx, f_idx) \ +#define MT_USDT_ST20P_TX_FRAME_NEXT(idx, f_idx) \ MT_DTRACE_PROBE2(st20p, tx_frame_next, idx, f_idx) -#define MT_USDT_ST20P_TX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST20P_TX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st20p, tx_frame_dump, idx, file, va, sz) #define MT_USDT_ST20P_TX_FRAME_DUMP_ENABLED() ST20P_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20P_RX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST20P_RX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st20p, rx_frame_get, idx, f_idx, va) -#define MT_USDT_ST20P_RX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST20P_RX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st20p, rx_frame_put, idx, f_idx, va) -#define MT_USDT_ST20P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st20p, rx_frame_available, idx, f_idx, va, tmstamp, data_size) -#define MT_USDT_ST20P_RX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST20P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE5(st20p, rx_frame_available, idx, f_idx, va, tmstamp, \ + data_size) +#define MT_USDT_ST20P_RX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st20p, rx_frame_dump, idx, file, va, sz) #define MT_USDT_ST20P_RX_FRAME_DUMP_ENABLED() ST20P_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30P_TX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST30P_TX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, tx_frame_get, idx, f_idx, va) -#define MT_USDT_ST30P_TX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST30P_TX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, tx_frame_put, idx, f_idx, va) -#define MT_USDT_ST30P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ +#define MT_USDT_ST30P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ MT_DTRACE_PROBE3(st30p, tx_frame_done, idx, f_idx, tmstamp) -#define MT_USDT_ST30P_TX_FRAME_NEXT(idx, f_idx) \ +#define MT_USDT_ST30P_TX_FRAME_NEXT(idx, f_idx) \ MT_DTRACE_PROBE2(st30p, tx_frame_next, idx, f_idx) -#define MT_USDT_ST30P_TX_FRAME_DUMP(idx, file, frames) \ +#define MT_USDT_ST30P_TX_FRAME_DUMP(idx, file, frames) \ MT_DTRACE_PROBE3(st30p, tx_frame_dump, idx, file, frames) #define MT_USDT_ST30P_TX_FRAME_DUMP_ENABLED() ST30P_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30P_RX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST30P_RX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, rx_frame_get, idx, f_idx, va) -#define MT_USDT_ST30P_RX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST30P_RX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, rx_frame_put, idx, f_idx, va) -#define MT_USDT_ST30P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st30p, rx_frame_available, idx, f_idx, va, tmstamp, data_size) -#define MT_USDT_ST30P_RX_FRAME_DUMP(idx, file, frames) \ +#define MT_USDT_ST30P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE5(st30p, rx_frame_available, idx, f_idx, va, tmstamp, \ + data_size) +#define MT_USDT_ST30P_RX_FRAME_DUMP(idx, file, frames) \ MT_DTRACE_PROBE3(st30p, rx_frame_dump, idx, file, frames) #define MT_USDT_ST30P_RX_FRAME_DUMP_ENABLED() ST30P_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp) \ +#define MT_USDT_ST20_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp) \ MT_DTRACE_PROBE5(st20, tx_frame_next, m_idx, s_idx, f_idx, va, tmstamp) -#define MT_USDT_ST20_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST20_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st20, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) -#define MT_USDT_ST20_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST20_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st20, tx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST20_TX_FRAME_DUMP_ENABLED() ST20_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE6(st20, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, data_size) -#define MT_USDT_ST20_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST20_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, \ + data_size) \ + MT_DTRACE_PROBE6(st20, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, \ + data_size) +#define MT_USDT_ST20_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st20, rx_frame_put, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST20_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ +#define MT_USDT_ST20_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ MT_DTRACE_PROBE3(st20, rx_no_framebuffer, m_idx, s_idx, tmstamp) -#define MT_USDT_ST20_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST20_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st20, rx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST20_RX_FRAME_DUMP_ENABLED() ST20_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ +#define MT_USDT_ST20_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ MT_DTRACE_PROBE5(st20, rx_pcap_dump, m_idx, s_idx, s_port, file, pkts) #define MT_USDT_ST20_RX_PCAP_DUMP_ENABLED() ST20_RX_PCAP_DUMP_ENABLED() -#define MT_USDT_ST20_RX_FRAME_INCOMPLETE(m_idx, s_idx, f_idx, tmstamp, data_size, \ - expect_size) \ - MT_DTRACE_PROBE6(st20, rx_frame_incomplete, m_idx, s_idx, f_idx, tmstamp, data_size, \ - expect_size) +#define MT_USDT_ST20_RX_FRAME_INCOMPLETE(m_idx, s_idx, f_idx, tmstamp, \ + data_size, expect_size) \ + MT_DTRACE_PROBE6(st20, rx_frame_incomplete, m_idx, s_idx, f_idx, tmstamp, \ + data_size, expect_size) -#define MT_USDT_ST30_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST30_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st30, tx_frame_next, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST30_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST30_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st30, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) -#define MT_USDT_ST30_TX_FRAME_DUMP(m_idx, s_idx, file, frames) \ +#define MT_USDT_ST30_TX_FRAME_DUMP(m_idx, s_idx, file, frames) \ MT_DTRACE_PROBE4(st30, tx_frame_dump, m_idx, s_idx, file, frames) #define MT_USDT_ST30_TX_FRAME_DUMP_ENABLED() ST30_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE6(st30, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, data_size) -#define MT_USDT_ST30_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST30_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, \ + data_size) \ + MT_DTRACE_PROBE6(st30, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, \ + data_size) +#define MT_USDT_ST30_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st30, rx_frame_put, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST30_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ +#define MT_USDT_ST30_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ MT_DTRACE_PROBE3(st30, rx_no_framebuffer, m_idx, s_idx, tmstamp) -#define MT_USDT_ST30_RX_FRAME_DUMP(m_idx, s_idx, file, frames) \ +#define MT_USDT_ST30_RX_FRAME_DUMP(m_idx, s_idx, file, frames) \ MT_DTRACE_PROBE4(st30, rx_frame_dump, m_idx, s_idx, file, frames) #define MT_USDT_ST30_RX_FRAME_DUMP_ENABLED() ST30_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ +#define MT_USDT_ST30_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ MT_DTRACE_PROBE5(st30, rx_pcap_dump, m_idx, s_idx, s_port, file, pkts) #define MT_USDT_ST30_RX_PCAP_DUMP_ENABLED() ST30_RX_PCAP_DUMP_ENABLED() -#define MT_USDT_ST40_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, meta_num, total_udw) \ - MT_DTRACE_PROBE6(st40, tx_frame_next, m_idx, s_idx, f_idx, va, meta_num, total_udw) -#define MT_USDT_ST40_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST40_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, meta_num, \ + total_udw) \ + MT_DTRACE_PROBE6(st40, tx_frame_next, m_idx, s_idx, f_idx, va, meta_num, \ + total_udw) +#define MT_USDT_ST40_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st40, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) #define MT_USDT_ST40_RX_MBUF_AVAILABLE(m_idx, s_idx, mbuf, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st40, rx_mbuf_available, m_idx, s_idx, mbuf, tmstamp, data_size) -#define MT_USDT_ST40_RX_MBUF_PUT(m_idx, s_idx, mbuf) \ + MT_DTRACE_PROBE5(st40, rx_mbuf_available, m_idx, s_idx, mbuf, tmstamp, \ + data_size) +#define MT_USDT_ST40_RX_MBUF_PUT(m_idx, s_idx, mbuf) \ MT_DTRACE_PROBE3(st40, rx_mbuf_put, m_idx, s_idx, mbuf) -#define MT_USDT_ST40_RX_MBUF_ENQUEUE_FAIL(m_idx, s_idx, mbuf, tmstamp) \ +#define MT_USDT_ST40_RX_MBUF_ENQUEUE_FAIL(m_idx, s_idx, mbuf, tmstamp) \ MT_DTRACE_PROBE4(st40, rx_mbuf_enqueue_fail, m_idx, s_idx, mbuf, tmstamp) -#define MT_USDT_ST22_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp, sz) \ +#define MT_USDT_ST22_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp, sz) \ MT_DTRACE_PROBE6(st22, tx_frame_next, m_idx, s_idx, f_idx, va, tmstamp, sz) -#define MT_USDT_ST22_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST22_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st22, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) -#define MT_USDT_ST22_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST22_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st22, tx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST22_TX_FRAME_DUMP_ENABLED() ST22_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE6(st22, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, data_size) -#define MT_USDT_ST22_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST22_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, \ + data_size) \ + MT_DTRACE_PROBE6(st22, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, \ + data_size) +#define MT_USDT_ST22_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st22, rx_frame_put, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST22_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ +#define MT_USDT_ST22_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ MT_DTRACE_PROBE3(st22, rx_no_framebuffer, m_idx, s_idx, tmstamp) -#define MT_USDT_ST22_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST22_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st22, rx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST22_RX_FRAME_DUMP_ENABLED() ST22_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22P_TX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST22P_TX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st22p, tx_frame_get, idx, f_idx, va) -#define MT_USDT_ST22P_TX_FRAME_PUT(idx, f_idx, va, stat, size) \ +#define MT_USDT_ST22P_TX_FRAME_PUT(idx, f_idx, va, stat, size) \ MT_DTRACE_PROBE5(st22p, tx_frame_put, idx, f_idx, va, stat, size) -#define MT_USDT_ST22P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ +#define MT_USDT_ST22P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ MT_DTRACE_PROBE3(st22p, tx_frame_done, idx, f_idx, tmstamp) -#define MT_USDT_ST22P_TX_FRAME_NEXT(idx, f_idx) \ +#define MT_USDT_ST22P_TX_FRAME_NEXT(idx, f_idx) \ MT_DTRACE_PROBE2(st22p, tx_frame_next, idx, f_idx) -#define MT_USDT_ST22P_TX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST22P_TX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st22p, tx_frame_dump, idx, file, va, sz) #define MT_USDT_ST22P_TX_FRAME_DUMP_ENABLED() ST22P_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22P_RX_FRAME_GET(idx, f_idx, va, sz) \ +#define MT_USDT_ST22P_RX_FRAME_GET(idx, f_idx, va, sz) \ MT_DTRACE_PROBE4(st22p, rx_frame_get, idx, f_idx, va, sz) -#define MT_USDT_ST22P_RX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST22P_RX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st22p, rx_frame_put, idx, f_idx, va) -#define MT_USDT_ST22P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st22p, rx_frame_available, idx, f_idx, va, tmstamp, data_size) -#define MT_USDT_ST22P_RX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST22P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE5(st22p, rx_frame_available, idx, f_idx, va, tmstamp, \ + data_size) +#define MT_USDT_ST22P_RX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st22p, rx_frame_dump, idx, file, va, sz) #define MT_USDT_ST22P_RX_FRAME_DUMP_ENABLED() ST22P_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22P_TX_ENCODE_GET(idx, f_idx, src, dst) \ +#define MT_USDT_ST22P_TX_ENCODE_GET(idx, f_idx, src, dst) \ MT_DTRACE_PROBE4(st22p, tx_encode_get, idx, f_idx, src, dst) -#define MT_USDT_ST22P_TX_ENCODE_PUT(idx, f_idx, src, dst, result, data_size) \ - MT_DTRACE_PROBE6(st22p, tx_encode_put, idx, f_idx, src, dst, result, data_size) -#define MT_USDT_ST22P_RX_DECODE_GET(idx, f_idx, src, dst, data_size) \ +#define MT_USDT_ST22P_TX_ENCODE_PUT(idx, f_idx, src, dst, result, data_size) \ + MT_DTRACE_PROBE6(st22p, tx_encode_put, idx, f_idx, src, dst, result, \ + data_size) +#define MT_USDT_ST22P_RX_DECODE_GET(idx, f_idx, src, dst, data_size) \ MT_DTRACE_PROBE5(st22p, rx_decode_get, idx, f_idx, src, dst, data_size) -#define MT_USDT_ST22P_RX_DECODE_PUT(idx, f_idx, src, dst, result) \ +#define MT_USDT_ST22P_RX_DECODE_PUT(idx, f_idx, src, dst, result) \ MT_DTRACE_PROBE5(st22p, rx_decode_put, idx, f_idx, src, dst, result) #endif diff --git a/lib/src/mt_util.c b/lib/src/mt_util.c index 5252656e9..b2b44c618 100644 --- a/lib/src/mt_util.c +++ b/lib/src/mt_util.c @@ -18,9 +18,9 @@ #define MAX_BT_SIZE 32 /* backtrace info */ struct mt_backtrace_info { - void* pointer; + void *pointer; size_t size; - char** bt_strings; + char **bt_strings; int bt_size; MT_TAILQ_ENTRY(mt_backtrace_info) next; }; @@ -30,7 +30,8 @@ MT_TAILQ_HEAD(mt_backtrace_info_list, mt_backtrace_info); static struct mt_backtrace_info_list g_bt_head; static pthread_mutex_t g_bt_mutex; -/* additional memleak check for mempool_create since dpdk asan not support this */ +/* additional memleak check for mempool_create since dpdk asan not support this + */ static int g_mt_mempool_create_cnt; int mt_asan_init(void) { @@ -42,7 +43,7 @@ int mt_asan_init(void) { int mt_asan_check(void) { /* check if any not freed */ int leak_cnt = 0; - struct mt_backtrace_info* bt_info = NULL; + struct mt_backtrace_info *bt_info = NULL; while ((bt_info = MT_TAILQ_FIRST(&g_bt_head))) { info("%s, \033[31mleak of %" PRIu64 " byte(s) at %p\033[0m\n", __func__, bt_info->size, bt_info->pointer); @@ -60,26 +61,29 @@ int mt_asan_check(void) { leak_cnt++; } if (leak_cnt) - info("%s, \033[33mfound %d rte_malloc leak(s) in total\033[0m\n", __func__, leak_cnt); + info("%s, \033[33mfound %d rte_malloc leak(s) in total\033[0m\n", __func__, + leak_cnt); mt_pthread_mutex_destroy(&g_bt_mutex); if (g_mt_mempool_create_cnt != 0) { - err("%s, detect not free mempool, leak cnt %d\n", __func__, g_mt_mempool_create_cnt); + err("%s, detect not free mempool, leak cnt %d\n", __func__, + g_mt_mempool_create_cnt); } return 0; } -void* mt_rte_malloc_socket(size_t sz, int socket) { - void* p = rte_malloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); +void *mt_rte_malloc_socket(size_t sz, int socket) { + void *p = + rte_malloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); if (p) { /* insert bt_info to list */ - struct mt_backtrace_info* bt_info = mt_zmalloc(sizeof(*bt_info)); + struct mt_backtrace_info *bt_info = mt_zmalloc(sizeof(*bt_info)); if (bt_info) { bt_info->pointer = p; bt_info->size = sz; - void* buffer[MAX_BT_SIZE]; + void *buffer[MAX_BT_SIZE]; bt_info->bt_size = backtrace(buffer, MAX_BT_SIZE); bt_info->bt_strings = backtrace_symbols(buffer, bt_info->bt_size); mt_pthread_mutex_lock(&g_bt_mutex); @@ -90,15 +94,16 @@ void* mt_rte_malloc_socket(size_t sz, int socket) { return p; } -void* mt_rte_zmalloc_socket(size_t sz, int socket) { - void* p = rte_zmalloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); +void *mt_rte_zmalloc_socket(size_t sz, int socket) { + void *p = + rte_zmalloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); if (p) { /* insert bt_info to list */ - struct mt_backtrace_info* bt_info = mt_zmalloc(sizeof(*bt_info)); + struct mt_backtrace_info *bt_info = mt_zmalloc(sizeof(*bt_info)); if (bt_info) { bt_info->pointer = p; bt_info->size = sz; - void* buffer[MAX_BT_SIZE]; + void *buffer[MAX_BT_SIZE]; bt_info->bt_size = backtrace(buffer, MAX_BT_SIZE); bt_info->bt_strings = backtrace_symbols(buffer, bt_info->bt_size); mt_pthread_mutex_lock(&g_bt_mutex); @@ -109,15 +114,17 @@ void* mt_rte_zmalloc_socket(size_t sz, int socket) { return p; } -void mt_rte_free(void* p) { +void mt_rte_free(void *p) { /* remove bt_info from list */ struct mt_backtrace_info *bt_info, *tmp_bt_info; mt_pthread_mutex_lock(&g_bt_mutex); - for (bt_info = MT_TAILQ_FIRST(&g_bt_head); bt_info != NULL; bt_info = tmp_bt_info) { + for (bt_info = MT_TAILQ_FIRST(&g_bt_head); bt_info != NULL; + bt_info = tmp_bt_info) { tmp_bt_info = MT_TAILQ_NEXT(bt_info, next); if (bt_info->pointer == p) { MT_TAILQ_REMOVE(&g_bt_head, bt_info, next); - if (bt_info->bt_strings) mt_free(bt_info->bt_strings); + if (bt_info->bt_strings) + mt_free(bt_info->bt_strings); mt_free(bt_info); break; } @@ -130,7 +137,7 @@ void mt_rte_free(void* p) { } #endif -bool mt_bitmap_test(uint8_t* bitmap, int idx) { +bool mt_bitmap_test(uint8_t *bitmap, int idx) { int pos = idx / 8; int off = idx % 8; uint8_t bits = bitmap[pos]; @@ -138,42 +145,46 @@ bool mt_bitmap_test(uint8_t* bitmap, int idx) { return (bits & (0x1 << off)) ? true : false; } -bool mt_bitmap_test_and_set(uint8_t* bitmap, int idx) { +bool mt_bitmap_test_and_set(uint8_t *bitmap, int idx) { int pos = idx / 8; int off = idx % 8; uint8_t bits = bitmap[pos]; /* already set */ - if (bits & (0x1 << off)) return true; + if (bits & (0x1 << off)) + return true; /* set the bit */ bitmap[pos] = bits | (0x1 << off); return false; } -bool mt_bitmap_test_and_unset(uint8_t* bitmap, int idx) { +bool mt_bitmap_test_and_unset(uint8_t *bitmap, int idx) { int pos = idx / 8; int off = idx % 8; uint8_t bits = bitmap[pos]; /* already unset */ - if (!(bits & (0x1 << off))) return true; + if (!(bits & (0x1 << off))) + return true; /* unset the bit */ bitmap[pos] = bits & (UINT8_MAX ^ (0x1 << off)); return false; } -int mt_ring_dequeue_clean(struct rte_ring* ring) { +int mt_ring_dequeue_clean(struct rte_ring *ring) { int ret; - struct rte_mbuf* pkt; + struct rte_mbuf *pkt; unsigned int count = rte_ring_count(ring); - if (count) info("%s, count %d for ring %s\n", __func__, count, ring->name); + if (count) + info("%s, count %d for ring %s\n", __func__, count, ring->name); /* dequeue and free all mbufs in the ring */ do { - ret = rte_ring_sc_dequeue(ring, (void**)&pkt); - if (ret < 0) break; + ret = rte_ring_sc_dequeue(ring, (void **)&pkt); + if (ret < 0) + break; rte_pktmbuf_free(pkt); } while (1); @@ -181,8 +192,8 @@ int mt_ring_dequeue_clean(struct rte_ring* ring) { return 0; } -void mt_mbuf_sanity_check(struct rte_mbuf** mbufs, uint16_t nb, char* tag) { - struct rte_mbuf* mbuf; +void mt_mbuf_sanity_check(struct rte_mbuf **mbufs, uint16_t nb, char *tag) { + struct rte_mbuf *mbuf; for (int i = 0; i < nb; i++) { mbuf = mbufs[i]; @@ -193,8 +204,8 @@ void mt_mbuf_sanity_check(struct rte_mbuf** mbufs, uint16_t nb, char* tag) { } } -enum mtl_port mt_port_by_name(struct mtl_main_impl* impl, const char* name) { - struct mtl_init_params* p = mt_get_user_params(impl); +enum mtl_port mt_port_by_name(struct mtl_main_impl *impl, const char *name) { + struct mtl_init_params *p = mt_get_user_params(impl); int main_num_ports = p->num_ports; if (!name) { @@ -212,9 +223,9 @@ enum mtl_port mt_port_by_name(struct mtl_main_impl* impl, const char* name) { return MTL_PORT_MAX; } -int mt_build_port_map(struct mtl_main_impl* impl, char** ports, enum mtl_port* maps, - int num_ports) { - struct mtl_init_params* p = mt_get_user_params(impl); +int mt_build_port_map(struct mtl_main_impl *impl, char **ports, + enum mtl_port *maps, int num_ports) { + struct mtl_init_params *p = mt_get_user_params(impl); int main_num_ports = p->num_ports; if (num_ports > main_num_ports) { @@ -247,12 +258,13 @@ int mt_build_port_map(struct mtl_main_impl* impl, char** ports, enum mtl_port* m return 0; } -int mt_pacing_train_result_add(struct mtl_main_impl* impl, enum mtl_port port, +int mt_pacing_train_result_add(struct mtl_main_impl *impl, enum mtl_port port, uint64_t rl_bps, float pad_interval) { - struct mt_pacing_train_result* ptr = &mt_if(impl, port)->pt_results[0]; + struct mt_pacing_train_result *ptr = &mt_if(impl, port)->pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (ptr[i].rl_bps) continue; + if (ptr[i].rl_bps) + continue; ptr[i].rl_bps = rl_bps; ptr[i].pacing_pad_interval = pad_interval; return 0; @@ -262,9 +274,10 @@ int mt_pacing_train_result_add(struct mtl_main_impl* impl, enum mtl_port port, return -ENOMEM; } -int mt_pacing_train_result_search(struct mtl_main_impl* impl, enum mtl_port port, - uint64_t rl_bps, float* pad_interval) { - struct mt_pacing_train_result* ptr = &mt_if(impl, port)->pt_results[0]; +int mt_pacing_train_result_search(struct mtl_main_impl *impl, + enum mtl_port port, uint64_t rl_bps, + float *pad_interval) { + struct mt_pacing_train_result *ptr = &mt_if(impl, port)->pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { if (rl_bps == ptr[i].rl_bps) { @@ -277,12 +290,15 @@ int mt_pacing_train_result_search(struct mtl_main_impl* impl, enum mtl_port port return -EINVAL; } -int mt_audio_pacing_train_result_add(struct mtl_main_impl* impl, enum mtl_port port, - uint64_t input_bps, uint64_t profiled_bps) { - struct mt_audio_pacing_train_result* ptr = &mt_if(impl, port)->audio_pt_results[0]; +int mt_audio_pacing_train_result_add(struct mtl_main_impl *impl, + enum mtl_port port, uint64_t input_bps, + uint64_t profiled_bps) { + struct mt_audio_pacing_train_result *ptr = + &mt_if(impl, port)->audio_pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (ptr[i].input_bps) continue; + if (ptr[i].input_bps) + continue; ptr[i].input_bps = input_bps; ptr[i].profiled_bps = profiled_bps; return 0; @@ -292,9 +308,11 @@ int mt_audio_pacing_train_result_add(struct mtl_main_impl* impl, enum mtl_port p return -ENOMEM; } -int mt_audio_pacing_train_result_search(struct mtl_main_impl* impl, enum mtl_port port, - uint64_t input_bps, uint64_t* profiled_bps) { - struct mt_audio_pacing_train_result* ptr = &mt_if(impl, port)->audio_pt_results[0]; +int mt_audio_pacing_train_result_search(struct mtl_main_impl *impl, + enum mtl_port port, uint64_t input_bps, + uint64_t *profiled_bps) { + struct mt_audio_pacing_train_result *ptr = + &mt_if(impl, port)->audio_pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { if (input_bps == ptr[i].input_bps) { @@ -307,24 +325,26 @@ int mt_audio_pacing_train_result_search(struct mtl_main_impl* impl, enum mtl_por return -EINVAL; } -void st_video_rtp_dump(enum mtl_port port, int idx, char* tag, - struct st20_rfc4175_rtp_hdr* rtp) { +void st_video_rtp_dump(enum mtl_port port, int idx, char *tag, + struct st20_rfc4175_rtp_hdr *rtp) { uint16_t line1_number = ntohs(rtp->row_number); uint16_t line1_offset = ntohs(rtp->row_offset); uint16_t line1_length = ntohs(rtp->row_length); uint32_t tmstamp = ntohl(rtp->base.tmstamp); uint32_t seq_id = (uint32_t)ntohs(rtp->base.seq_number) | (((uint32_t)ntohs(rtp->seq_number_ext)) << 16); - struct st20_rfc4175_extra_rtp_hdr* extra_rtp = NULL; + struct st20_rfc4175_extra_rtp_hdr *extra_rtp = NULL; if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { line1_offset &= ~ST20_SRD_OFFSET_CONTINUATION; - extra_rtp = (struct st20_rfc4175_extra_rtp_hdr*)&rtp[1]; + extra_rtp = (struct st20_rfc4175_extra_rtp_hdr *)&rtp[1]; } - if (tag) info("%s(%d,%d), %s\n", __func__, port, idx, tag); + if (tag) + info("%s(%d,%d), %s\n", __func__, port, idx, tag); info("tmstamp: 0x%x, seq_id: %u\n", tmstamp, seq_id); - info("line: no %d offset %d len %d\n", line1_number, line1_offset, line1_length); + info("line: no %d offset %d len %d\n", line1_number, line1_offset, + line1_length); if (extra_rtp) { uint16_t line2_number = ntohs(extra_rtp->row_number); uint16_t line2_offset = ntohs(extra_rtp->row_offset); @@ -335,74 +355,79 @@ void st_video_rtp_dump(enum mtl_port port, int idx, char* tag, } } -void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char* tag, struct rte_mbuf* m) { - struct rte_ether_hdr* eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr*); +void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, + struct rte_mbuf *m) { + struct rte_ether_hdr *eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); size_t hdr_offset = sizeof(struct rte_ether_hdr); - struct rte_ipv4_hdr* ipv4 = NULL; - struct rte_udp_hdr* udp = NULL; + struct rte_ipv4_hdr *ipv4 = NULL; + struct rte_udp_hdr *udp = NULL; uint16_t ether_type = ntohs(eth->ether_type); - uint8_t* mac; - uint8_t* ip; + uint8_t *mac; + uint8_t *ip; - if (tag) info("%s(%d,%d), %s\n", __func__, port, idx, tag); + if (tag) + info("%s(%d,%d), %s\n", __func__, port, idx, tag); info("ether_type 0x%x\n", ether_type); mac = &mt_eth_d_addr(eth)->addr_bytes[0]; - info("d_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], - mac[5]); + info("d_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], + mac[4], mac[5]); mac = &mt_eth_s_addr(eth)->addr_bytes[0]; - info("s_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], - mac[5]); + info("s_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], + mac[4], mac[5]); if (ether_type == RTE_ETHER_TYPE_IPV4) { - ipv4 = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr*, hdr_offset); + ipv4 = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, hdr_offset); hdr_offset += sizeof(*ipv4); - udp = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr*, hdr_offset); + udp = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *, hdr_offset); hdr_offset += sizeof(*udp); } if (ipv4) { - ip = (uint8_t*)&ipv4->dst_addr; + ip = (uint8_t *)&ipv4->dst_addr; info("d_ip %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); - ip = (uint8_t*)&ipv4->src_addr; + ip = (uint8_t *)&ipv4->src_addr; info("s_ip %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); } if (udp) { - info("dst_port %d src_port %d\n", ntohs(udp->dst_port), ntohs(udp->src_port)); + info("dst_port %d src_port %d\n", ntohs(udp->dst_port), + ntohs(udp->src_port)); } } -void mt_mbuf_dump(enum mtl_port port, int idx, char* tag, struct rte_mbuf* m) { +void mt_mbuf_dump(enum mtl_port port, int idx, char *tag, struct rte_mbuf *m) { mt_mbuf_dump_hdr(port, idx, tag, m); rte_pktmbuf_dump(stdout, m, m->data_len); } -void mt_lcore_dump() { - rte_lcore_dump(stdout); -} +void mt_lcore_dump() { rte_lcore_dump(stdout); } void mt_eth_link_dump(uint16_t port_id) { struct rte_eth_link eth_link; rte_eth_link_get_nowait(port_id, ð_link); - critical("%s(%d), link_speed %dg link_status %d link_duplex %d link_autoneg %d\n", - __func__, port_id, eth_link.link_speed / 1000, eth_link.link_status, - eth_link.link_duplex, eth_link.link_autoneg); + critical( + "%s(%d), link_speed %dg link_status %d link_duplex %d link_autoneg %d\n", + __func__, port_id, eth_link.link_speed / 1000, eth_link.link_status, + eth_link.link_duplex, eth_link.link_autoneg); } -void mt_eth_macaddr_dump(enum mtl_port port, char* tag, struct rte_ether_addr* mac_addr) { - if (tag) info("%s(%d), %s\n", __func__, port, tag); +void mt_eth_macaddr_dump(enum mtl_port port, char *tag, + struct rte_ether_addr *mac_addr) { + if (tag) + info("%s(%d), %s\n", __func__, port, tag); - uint8_t* addr = &mac_addr->addr_bytes[0]; - info("%02x:%02x:%02x:%02x:%02x:%02x\n", addr[0], addr[1], addr[2], addr[3], addr[4], - addr[5]); + uint8_t *addr = &mac_addr->addr_bytes[0]; + info("%02x:%02x:%02x:%02x:%02x:%02x\n", addr[0], addr[1], addr[2], addr[3], + addr[4], addr[5]); } -struct rte_mbuf* mt_build_pad(struct mtl_main_impl* impl, struct rte_mempool* mempool, - enum mtl_port port, uint16_t ether_type, uint16_t len) { +struct rte_mbuf *mt_build_pad(struct mtl_main_impl *impl, + struct rte_mempool *mempool, enum mtl_port port, + uint16_t ether_type, uint16_t len) { struct rte_ether_addr src_mac; - struct rte_mbuf* pad; - struct rte_ether_hdr* eth_hdr; + struct rte_mbuf *pad; + struct rte_ether_hdr *eth_hdr; pad = rte_pktmbuf_alloc(mempool); if (unlikely(pad == NULL)) { @@ -415,8 +440,8 @@ struct rte_mbuf* mt_build_pad(struct mtl_main_impl* impl, struct rte_mempool* me pad->data_len = len; pad->pkt_len = len; - eth_hdr = rte_pktmbuf_mtod(pad, struct rte_ether_hdr*); - memset((char*)eth_hdr, 0, len); + eth_hdr = rte_pktmbuf_mtod(pad, struct rte_ether_hdr *); + memset((char *)eth_hdr, 0, len); eth_hdr->ether_type = htons(ether_type); mt_eth_d_addr(eth_hdr)->addr_bytes[0] = 0x01; mt_eth_d_addr(eth_hdr)->addr_bytes[1] = 0x80; @@ -427,9 +452,9 @@ struct rte_mbuf* mt_build_pad(struct mtl_main_impl* impl, struct rte_mempool* me return pad; } -int mt_macaddr_get(struct mtl_main_impl* impl, enum mtl_port port, - struct rte_ether_addr* mac_addr) { - struct mt_interface* inf = mt_if(impl, port); +int mt_macaddr_get(struct mtl_main_impl *impl, enum mtl_port port, + struct rte_ether_addr *mac_addr) { + struct mt_interface *inf = mt_if(impl, port); if (inf->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD) { mtl_memcpy(mac_addr, &inf->k_mac_addr, sizeof(*mac_addr)); @@ -440,41 +465,44 @@ int mt_macaddr_get(struct mtl_main_impl* impl, enum mtl_port port, return rte_eth_macaddr_get(port_id, mac_addr); } -void* mt_mempool_mem_addr(struct rte_mempool* mp) { - struct rte_mempool_memhdr* hdr = STAILQ_FIRST(&mp->mem_list); +void *mt_mempool_mem_addr(struct rte_mempool *mp) { + struct rte_mempool_memhdr *hdr = STAILQ_FIRST(&mp->mem_list); if (mp->nb_mem_chunks != 1) - err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, mp->nb_mem_chunks); + err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, + mp->nb_mem_chunks); return hdr->addr; } -size_t mt_mempool_mem_size(struct rte_mempool* mp) { - struct rte_mempool_memhdr* hdr = STAILQ_FIRST(&mp->mem_list); +size_t mt_mempool_mem_size(struct rte_mempool *mp) { + struct rte_mempool_memhdr *hdr = STAILQ_FIRST(&mp->mem_list); if (mp->nb_mem_chunks != 1) - err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, mp->nb_mem_chunks); + err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, + mp->nb_mem_chunks); return hdr->len; } -uint32_t mt_mempool_obj_size(struct rte_mempool* mp) { +uint32_t mt_mempool_obj_size(struct rte_mempool *mp) { return rte_mempool_calc_obj_size(mp->elt_size, mp->flags, NULL); } -int mt_mempool_dump(struct rte_mempool* mp) { +int mt_mempool_dump(struct rte_mempool *mp) { uint32_t populated_size = mp->populated_size; - struct rte_mbuf* mbufs[populated_size]; + struct rte_mbuf *mbufs[populated_size]; uint32_t mbufs_alloced = 0; - void* base_addr = mt_mempool_mem_addr(mp); - void* end_addr = base_addr + mt_mempool_mem_size(mp); - void* last_hdr = NULL; + void *base_addr = mt_mempool_mem_addr(mp); + void *end_addr = base_addr + mt_mempool_mem_size(mp); + void *last_hdr = NULL; - info("%s(%s), %u mbufs object size %u, memory range: %p to %p\n", __func__, mp->name, - populated_size, mt_mempool_obj_size(mp), base_addr, end_addr); + info("%s(%s), %u mbufs object size %u, memory range: %p to %p\n", __func__, + mp->name, populated_size, mt_mempool_obj_size(mp), base_addr, end_addr); for (uint32_t i = 0; i < populated_size; i++) { mbufs[i] = rte_pktmbuf_alloc(mp); - if (!mbufs[i]) break; + if (!mbufs[i]) + break; mbufs_alloced++; - void* hdr = rte_pktmbuf_mtod(mbufs[i], void*); - info("%s(%s), mbuf %u hdr %p step %" PRId64 "\n", __func__, mp->name, i, hdr, - hdr - last_hdr); + void *hdr = rte_pktmbuf_mtod(mbufs[i], void *); + info("%s(%s), mbuf %u hdr %p step %" PRId64 "\n", __func__, mp->name, i, + hdr, hdr - last_hdr); last_hdr = hdr; } @@ -482,13 +510,15 @@ int mt_mempool_dump(struct rte_mempool* mp) { return 0; } -struct rte_mempool* mt_mempool_create_by_ops(struct mtl_main_impl* impl, const char* name, - unsigned int n, unsigned int cache_size, - uint16_t priv_size, uint16_t element_size, - const char* ops_name, int socket_id) { - char name_with_idx[32]; /* 32 is the max length allowed by mempool api, in our lib we - use concise names so it won't exceed this length */ - struct rte_mempool* mbuf_pool; +struct rte_mempool * +mt_mempool_create_by_ops(struct mtl_main_impl *impl, const char *name, + unsigned int n, unsigned int cache_size, + uint16_t priv_size, uint16_t element_size, + const char *ops_name, int socket_id) { + char name_with_idx[32]; /* 32 is the max length allowed by mempool api, in our + lib we use concise names so it won't exceed this + length */ + struct rte_mempool *mbuf_pool; uint16_t data_room_size; unsigned int ret = 1; float size_m; @@ -499,27 +529,30 @@ struct rte_mempool* mt_mempool_create_by_ops(struct mtl_main_impl* impl, const c * optimum size (in terms of memory usage) for a mempool * is when n is a power of two minus one: n = (2^q - 1). */ - while (ret - 1 <= n && ret) ret <<= 1; + while (ret - 1 <= n && ret) + ret <<= 1; - dbg("%s(%d), optimize number of elements in the mbuf pool from %d to %d\n ", __func__, - socket_id, n, ret - 1); + dbg("%s(%d), optimize number of elements in the mbuf pool from %d to %d\n ", + __func__, socket_id, n, ret - 1); n = ret - 1; if (cache_size && (element_size % cache_size)) /* align to cache size */ element_size = (element_size / cache_size + 1) * cache_size; - snprintf(name_with_idx, sizeof(name_with_idx), "%s_%d", name, impl->mempool_idx++); + snprintf(name_with_idx, sizeof(name_with_idx), "%s_%d", name, + impl->mempool_idx++); data_room_size = element_size + MT_MBUF_HEADROOM_SIZE; /* include head room */ - mbuf_pool = rte_pktmbuf_pool_create_by_ops(name_with_idx, n, cache_size, priv_size, - data_room_size, socket_id, ops_name); + mbuf_pool = + rte_pktmbuf_pool_create_by_ops(name_with_idx, n, cache_size, priv_size, + data_room_size, socket_id, ops_name); if (!mbuf_pool) { - err("%s(%d), fail(%s) for %s, n %u\n", __func__, socket_id, rte_strerror(rte_errno), - name, n); + err("%s(%d), fail(%s) for %s, n %u\n", __func__, socket_id, + rte_strerror(rte_errno), name, n); } else { size_m = (float)n * (data_room_size + priv_size) / (1024 * 1024); - info("%s(%d), succ at %p size %fm n %u d %u for %s\n", __func__, socket_id, mbuf_pool, - size_m, n, element_size, name_with_idx); + info("%s(%d), succ at %p size %fm n %u d %u for %s\n", __func__, socket_id, + mbuf_pool, size_m, n, element_size, name_with_idx); #ifdef MTL_HAS_ASAN g_mt_mempool_create_cnt++; #endif @@ -528,11 +561,13 @@ struct rte_mempool* mt_mempool_create_by_ops(struct mtl_main_impl* impl, const c return mbuf_pool; } -int mt_mempool_free(struct rte_mempool* mp) { +int mt_mempool_free(struct rte_mempool *mp) { unsigned int in_use_count = rte_mempool_in_use_count(mp); if (in_use_count) { - /* failed to free the mempool, caused by the mbuf is still in nix tx queues? */ - warn("%s, still has %d mbuf in mempool %s\n", __func__, in_use_count, mp->name); + /* failed to free the mempool, caused by the mbuf is still in nix tx queues? + */ + warn("%s, still has %d mbuf in mempool %s\n", __func__, in_use_count, + mp->name); return 0; } @@ -547,8 +582,8 @@ int mt_mempool_free(struct rte_mempool* mp) { } /* Computing the Internet Checksum based on rfc1071 */ -uint16_t mt_rf1071_check_sum(uint8_t* p, size_t len, bool convert) { - uint16_t* u16_in = (uint16_t*)p; +uint16_t mt_rf1071_check_sum(uint8_t *p, size_t len, bool convert) { + uint16_t *u16_in = (uint16_t *)p; uint16_t check_sum = 0; uint32_t sum = 0; @@ -566,7 +601,7 @@ uint16_t mt_rf1071_check_sum(uint8_t* p, size_t len, bool convert) { if (len == 1) { uint16_t left = 0; - *(uint8_t*)&left = *(uint8_t*)u16_in; + *(uint8_t *)&left = *(uint8_t *)u16_in; sum += left; } @@ -578,10 +613,11 @@ uint16_t mt_rf1071_check_sum(uint8_t* p, size_t len, bool convert) { return check_sum; } -struct mt_u64_fifo* mt_u64_fifo_init(int size, int soc_id) { - struct mt_u64_fifo* fifo = mt_rte_zmalloc_socket(sizeof(*fifo), soc_id); - if (!fifo) return NULL; - uint64_t* data = mt_rte_zmalloc_socket(sizeof(*data) * size, soc_id); +struct mt_u64_fifo *mt_u64_fifo_init(int size, int soc_id) { + struct mt_u64_fifo *fifo = mt_rte_zmalloc_socket(sizeof(*fifo), soc_id); + if (!fifo) + return NULL; + uint64_t *data = mt_rte_zmalloc_socket(sizeof(*data) * size, soc_id); if (!data) { mt_rte_free(fifo); return NULL; @@ -592,7 +628,7 @@ struct mt_u64_fifo* mt_u64_fifo_init(int size, int soc_id) { return fifo; } -int mt_u64_fifo_uinit(struct mt_u64_fifo* fifo) { +int mt_u64_fifo_uinit(struct mt_u64_fifo *fifo) { if (fifo->used > 0) { err("%s, still has %d items\n", __func__, fifo->used); return -EIO; @@ -603,32 +639,35 @@ int mt_u64_fifo_uinit(struct mt_u64_fifo* fifo) { } /* todo: add overflow check */ -int mt_u64_fifo_put(struct mt_u64_fifo* fifo, const uint64_t item) { +int mt_u64_fifo_put(struct mt_u64_fifo *fifo, const uint64_t item) { if (fifo->used >= fifo->size) { dbg("%s, fail as fifo is full(%d)\n", __func__, fifo->size); return -EIO; } fifo->data[fifo->write_idx] = item; fifo->write_idx++; - if (fifo->write_idx >= fifo->size) fifo->write_idx = 0; + if (fifo->write_idx >= fifo->size) + fifo->write_idx = 0; fifo->used++; return 0; } /* todo: add overflow check */ -int mt_u64_fifo_get(struct mt_u64_fifo* fifo, uint64_t* item) { +int mt_u64_fifo_get(struct mt_u64_fifo *fifo, uint64_t *item) { if (fifo->used <= 0) { dbg("%s, fail as empty\n", __func__); return -EIO; } *item = fifo->data[fifo->read_idx]; fifo->read_idx++; - if (fifo->read_idx >= fifo->size) fifo->read_idx = 0; + if (fifo->read_idx >= fifo->size) + fifo->read_idx = 0; fifo->used--; return 0; } -int mt_u64_fifo_put_bulk(struct mt_u64_fifo* fifo, const uint64_t* items, uint32_t n) { +int mt_u64_fifo_put_bulk(struct mt_u64_fifo *fifo, const uint64_t *items, + uint32_t n) { if (fifo->used + n > fifo->size) { dbg("%s, fail as fifo is full(%d)\n", __func__, fifo->size); return -EIO; @@ -637,13 +676,15 @@ int mt_u64_fifo_put_bulk(struct mt_u64_fifo* fifo, const uint64_t* items, uint32 for (i = 0; i < n; i++) { fifo->data[fifo->write_idx] = items[i]; fifo->write_idx++; - if (fifo->write_idx >= fifo->size) fifo->write_idx = 0; + if (fifo->write_idx >= fifo->size) + fifo->write_idx = 0; } fifo->used += n; return 0; } -int mt_u64_fifo_get_bulk(struct mt_u64_fifo* fifo, uint64_t* items, uint32_t n) { +int mt_u64_fifo_get_bulk(struct mt_u64_fifo *fifo, uint64_t *items, + uint32_t n) { if (fifo->used < n) { dbg("%s, fail as no enough item\n", __func__); return -EIO; @@ -652,24 +693,26 @@ int mt_u64_fifo_get_bulk(struct mt_u64_fifo* fifo, uint64_t* items, uint32_t n) for (i = 0; i < n; i++) { items[i] = fifo->data[fifo->read_idx]; fifo->read_idx++; - if (fifo->read_idx >= fifo->size) fifo->read_idx = 0; + if (fifo->read_idx >= fifo->size) + fifo->read_idx = 0; } fifo->used -= n; return 0; } -int mt_u64_fifo_read_back(struct mt_u64_fifo* fifo, uint64_t* item) { +int mt_u64_fifo_read_back(struct mt_u64_fifo *fifo, uint64_t *item) { if (fifo->used <= 0) { dbg("%s, fail as empty\n", __func__); return -EIO; } int idx = fifo->write_idx - 1; - if (idx < 0) idx = fifo->size - 1; + if (idx < 0) + idx = fifo->size - 1; *item = fifo->data[idx]; return 0; } -int mt_u64_fifo_read_front(struct mt_u64_fifo* fifo, uint64_t* item) { +int mt_u64_fifo_read_front(struct mt_u64_fifo *fifo, uint64_t *item) { if (fifo->used <= 0) { dbg("%s, fail as empty\n", __func__); return -EIO; @@ -678,7 +721,7 @@ int mt_u64_fifo_read_front(struct mt_u64_fifo* fifo, uint64_t* item) { return 0; } -int mt_u64_fifo_read_any(struct mt_u64_fifo* fifo, uint64_t* item, int skip) { +int mt_u64_fifo_read_any(struct mt_u64_fifo *fifo, uint64_t *item, int skip) { if (fifo->used <= 0) { dbg("%s, fail as empty\n", __func__); return -EIO; @@ -688,13 +731,14 @@ int mt_u64_fifo_read_any(struct mt_u64_fifo* fifo, uint64_t* item, int skip) { return -EIO; } int read_idx = fifo->read_idx + skip; - if (read_idx >= fifo->size) read_idx -= fifo->size; + if (read_idx >= fifo->size) + read_idx -= fifo->size; *item = fifo->data[read_idx]; return 0; } -int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo* fifo, uint64_t* items, uint32_t n, - int skip) { +int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo *fifo, uint64_t *items, + uint32_t n, int skip) { if (fifo->used < n) { dbg("%s, fail as no enough item\n", __func__); return -EIO; @@ -704,51 +748,61 @@ int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo* fifo, uint64_t* items, uint32_ return -EIO; } int read_idx = fifo->read_idx + skip; - if (read_idx >= fifo->size) read_idx -= fifo->size; + if (read_idx >= fifo->size) + read_idx -= fifo->size; uint32_t i = 0; for (i = 0; i < n; i++) { items[i] = fifo->data[read_idx]; read_idx++; - if (read_idx >= fifo->size) read_idx = 0; + if (read_idx >= fifo->size) + read_idx = 0; } return 0; } /* only for the mbuf fifo */ -int mt_fifo_mbuf_clean(struct mt_u64_fifo* fifo) { - struct rte_mbuf* mbuf; +int mt_fifo_mbuf_clean(struct mt_u64_fifo *fifo) { + struct rte_mbuf *mbuf; while (mt_u64_fifo_count(fifo) > 0) { - mt_u64_fifo_get(fifo, (uint64_t*)&mbuf); + mt_u64_fifo_get(fifo, (uint64_t *)&mbuf); rte_pktmbuf_free(mbuf); } return 0; } -struct mt_cvt_dma_ctx* mt_cvt_dma_ctx_init(int fifo_size, int soc_id, int type_num) { - struct mt_cvt_dma_ctx* ctx = mt_rte_zmalloc_socket(sizeof(*ctx), soc_id); - if (!ctx) return NULL; +struct mt_cvt_dma_ctx *mt_cvt_dma_ctx_init(int fifo_size, int soc_id, + int type_num) { + struct mt_cvt_dma_ctx *ctx = mt_rte_zmalloc_socket(sizeof(*ctx), soc_id); + if (!ctx) + return NULL; ctx->fifo = mt_u64_fifo_init(fifo_size, soc_id); - if (!ctx->fifo) goto fail; + if (!ctx->fifo) + goto fail; ctx->tran = mt_rte_zmalloc_socket(sizeof(*ctx->tran) * type_num, soc_id); - if (!ctx->tran) goto fail; + if (!ctx->tran) + goto fail; ctx->done = mt_rte_zmalloc_socket(sizeof(*ctx->done) * type_num, soc_id); - if (!ctx->done) goto fail; + if (!ctx->done) + goto fail; return ctx; fail: - if (ctx->fifo) mt_u64_fifo_uinit(ctx->fifo); - if (ctx->tran) mt_rte_free(ctx->tran); - if (ctx->done) mt_rte_free(ctx->done); + if (ctx->fifo) + mt_u64_fifo_uinit(ctx->fifo); + if (ctx->tran) + mt_rte_free(ctx->tran); + if (ctx->done) + mt_rte_free(ctx->done); mt_rte_free(ctx); return NULL; } -int mt_cvt_dma_ctx_uinit(struct mt_cvt_dma_ctx* ctx) { +int mt_cvt_dma_ctx_uinit(struct mt_cvt_dma_ctx *ctx) { mt_u64_fifo_uinit(ctx->fifo); mt_rte_free(ctx->tran); mt_rte_free(ctx->done); @@ -756,26 +810,28 @@ int mt_cvt_dma_ctx_uinit(struct mt_cvt_dma_ctx* ctx) { return 0; } -int mt_cvt_dma_ctx_push(struct mt_cvt_dma_ctx* ctx, int type) { +int mt_cvt_dma_ctx_push(struct mt_cvt_dma_ctx *ctx, int type) { int ret = mt_u64_fifo_put(ctx->fifo, type); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx->tran[type]++; dbg("%s, tran %d for type %d\n", __func__, ctx->tran[type], type); return 0; } -int mt_cvt_dma_ctx_pop(struct mt_cvt_dma_ctx* ctx) { +int mt_cvt_dma_ctx_pop(struct mt_cvt_dma_ctx *ctx) { uint64_t type = 0; int ret = mt_u64_fifo_get(ctx->fifo, &type); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx->done[type]++; dbg("%s, done %d for type %" PRIu64 "\n", __func__, ctx->done[type], type); return 0; } -int mt_run_cmd(const char* cmd, char* out, size_t out_len) { - FILE* fp; - char* ret; +int mt_run_cmd(const char *cmd, char *out, size_t out_len) { + FILE *fp; + char *ret; fp = popen(cmd, "r"); if (!fp) { @@ -797,30 +853,33 @@ int mt_run_cmd(const char* cmd, char* out, size_t out_len) { return 0; } -int mt_ip_addr_check(uint8_t* ip) { +int mt_ip_addr_check(uint8_t *ip) { for (int i = 0; i < MTL_IP_ADDR_LEN; i++) { - if (ip[i]) return 0; + if (ip[i]) + return 0; } return -EINVAL; } -int st_tx_dest_info_check(struct st_tx_dest_info* dst, int num_ports) { - uint8_t* ip; +int st_tx_dest_info_check(struct st_tx_dest_info *dst, int num_ports) { + uint8_t *ip; int ret; for (int i = 0; i < num_ports; i++) { ip = dst->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(dst->dip_addr[0], dst->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -828,22 +887,24 @@ int st_tx_dest_info_check(struct st_tx_dest_info* dst, int num_ports) { return 0; } -int st_rx_source_info_check(struct st_rx_source_info* src, int num_ports) { - uint8_t* ip; +int st_rx_source_info_check(struct st_rx_source_info *src, int num_ports) { + uint8_t *ip; int ret; for (int i = 0; i < num_ports; i++) { ip = src->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(src->ip_addr[0], src->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -851,16 +912,18 @@ int st_rx_source_info_check(struct st_rx_source_info* src, int num_ports) { return 0; } -int st_frame_trans_uinit(struct st_frame_trans* frame) { +int st_frame_trans_uinit(struct st_frame_trans *frame) { int idx = frame->idx; /* check if it's still shared */ uint16_t sh_info_refcnt = rte_mbuf_ext_refcnt_read(&frame->sh_info); if (sh_info_refcnt) - warn("%s(%d), sh_info still active, refcnt %d\n", __func__, idx, sh_info_refcnt); + warn("%s(%d), sh_info still active, refcnt %d\n", __func__, idx, + sh_info_refcnt); int refcnt = rte_atomic32_read(&frame->refcnt); - if (refcnt) warn("%s(%d), refcnt not zero %d\n", __func__, idx, refcnt); + if (refcnt) + warn("%s(%d), refcnt not zero %d\n", __func__, idx, refcnt); if (frame->addr) { if (frame->flags & ST_FT_FLAG_RTE_MALLOC) { @@ -886,7 +949,8 @@ int st_frame_trans_uinit(struct st_frame_trans* frame) { return 0; } -int st_vsync_calculate(struct mtl_main_impl* impl, struct st_vsync_info* vsync) { +int st_vsync_calculate(struct mtl_main_impl *impl, + struct st_vsync_info *vsync) { uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); uint64_t next_epoch; uint64_t to_next_epochs; @@ -921,21 +985,24 @@ uint16_t mt_random_port(uint16_t base_port) { return port; } -static const char* dpdk_afxdp_port_prefix = "dpdk_af_xdp:"; -static const char* dpdk_afpkt_port_prefix = "dpdk_af_packet:"; -static const char* kernel_port_prefix = "kernel:"; -static const char* native_afxdp_port_prefix = "native_af_xdp:"; -static const char* rdma_ud_port_prefix = "rdma_ud:"; +static const char *dpdk_afxdp_port_prefix = "dpdk_af_xdp:"; +static const char *dpdk_afpkt_port_prefix = "dpdk_af_packet:"; +static const char *kernel_port_prefix = "kernel:"; +static const char *native_afxdp_port_prefix = "native_af_xdp:"; +static const char *rdma_ud_port_prefix = "rdma_ud:"; -enum mtl_pmd_type mtl_pmd_by_port_name(const char* port) { +enum mtl_pmd_type mtl_pmd_by_port_name(const char *port) { dbg("%s, port %s\n", __func__, port); - if (strncmp(port, dpdk_afxdp_port_prefix, strlen(dpdk_afxdp_port_prefix)) == 0) + if (strncmp(port, dpdk_afxdp_port_prefix, strlen(dpdk_afxdp_port_prefix)) == + 0) return MTL_PMD_DPDK_AF_XDP; - else if (strncmp(port, dpdk_afpkt_port_prefix, strlen(dpdk_afpkt_port_prefix)) == 0) + else if (strncmp(port, dpdk_afpkt_port_prefix, + strlen(dpdk_afpkt_port_prefix)) == 0) return MTL_PMD_DPDK_AF_PACKET; else if (strncmp(port, kernel_port_prefix, strlen(kernel_port_prefix)) == 0) return MTL_PMD_KERNEL_SOCKET; - else if (strncmp(port, native_afxdp_port_prefix, strlen(native_afxdp_port_prefix)) == 0) + else if (strncmp(port, native_afxdp_port_prefix, + strlen(native_afxdp_port_prefix)) == 0) return MTL_PMD_NATIVE_AF_XDP; else if (strncmp(port, rdma_ud_port_prefix, strlen(rdma_ud_port_prefix)) == 0) return MTL_PMD_RDMA_UD; @@ -943,7 +1010,7 @@ enum mtl_pmd_type mtl_pmd_by_port_name(const char* port) { return MTL_PMD_DPDK_USER; /* default */ } -const char* mt_kernel_port2if(const char* port) { +const char *mt_kernel_port2if(const char *port) { if (mtl_pmd_by_port_name(port) != MTL_PMD_KERNEL_SOCKET) { err("%s, port %s is not a kernel based\n", __func__, port); return NULL; @@ -951,7 +1018,7 @@ const char* mt_kernel_port2if(const char* port) { return port + strlen(kernel_port_prefix); } -const char* mt_dpdk_afxdp_port2if(const char* port) { +const char *mt_dpdk_afxdp_port2if(const char *port) { if (mtl_pmd_by_port_name(port) != MTL_PMD_DPDK_AF_XDP) { err("%s, port %s is not dpdk_af_xdp\n", __func__, port); return NULL; @@ -959,7 +1026,7 @@ const char* mt_dpdk_afxdp_port2if(const char* port) { return port + strlen(dpdk_afxdp_port_prefix); } -const char* mt_dpdk_afpkt_port2if(const char* port) { +const char *mt_dpdk_afpkt_port2if(const char *port) { if (mtl_pmd_by_port_name(port) != MTL_PMD_DPDK_AF_PACKET) { err("%s, port %s is not a dpdk_af_pkt\n", __func__, port); return NULL; @@ -967,7 +1034,7 @@ const char* mt_dpdk_afpkt_port2if(const char* port) { return port + strlen(dpdk_afpkt_port_prefix); } -const char* mt_native_afxdp_port2if(const char* port) { +const char *mt_native_afxdp_port2if(const char *port) { if (mtl_pmd_by_port_name(port) != MTL_PMD_NATIVE_AF_XDP) { err("%s, port %s is not native_af_xdp\n", __func__, port); return NULL; @@ -975,7 +1042,7 @@ const char* mt_native_afxdp_port2if(const char* port) { return port + strlen(native_afxdp_port_prefix); } -const char* mt_rdma_ud_port2if(const char* port) { +const char *mt_rdma_ud_port2if(const char *port) { if (mtl_pmd_by_port_name(port) != MTL_PMD_RDMA_UD) { err("%s, port %s is not a rdma based\n", __func__, port); return NULL; @@ -983,7 +1050,7 @@ const char* mt_rdma_ud_port2if(const char* port) { return port + strlen(rdma_ud_port_prefix); } -int mt_user_info_init(struct mt_user_info* info) { +int mt_user_info_init(struct mt_user_info *info) { int ret = -EIO; info->pid = getpid(); @@ -1000,7 +1067,7 @@ int mt_user_info_init(struct mt_user_info* info) { snprintf(info->hostname, sizeof(info->hostname), "%s", "unknow"); } uid_t uid = getuid(); - struct passwd* user_info = getpwuid(uid); + struct passwd *user_info = getpwuid(uid); snprintf(info->user, sizeof(info->user), "%s", user_info ? user_info->pw_name : "unknow"); char comm_path[128]; @@ -1022,7 +1089,7 @@ int mt_user_info_init(struct mt_user_info* info) { return 0; } -int mt_read_cpu_usage(struct mt_cpu_usage* usages, int* cpu_ids, int num_cpus) { +int mt_read_cpu_usage(struct mt_cpu_usage *usages, int *cpu_ids, int num_cpus) { #ifdef WINDOWSENV /* todo */ MTL_MAY_UNUSED(usages); MTL_MAY_UNUSED(cpu_ids); @@ -1030,7 +1097,7 @@ int mt_read_cpu_usage(struct mt_cpu_usage* usages, int* cpu_ids, int num_cpus) { err("%s, not support on windows\n", __func__); return -ENOTSUP; #else - FILE* file; + FILE *file; char line[256]; int found = 0; @@ -1044,11 +1111,12 @@ int mt_read_cpu_usage(struct mt_cpu_usage* usages, int* cpu_ids, int num_cpus) { struct mt_cpu_usage cur; int cpu; int parsed = sscanf(line, - "cpu%d %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 - " %" PRIu64 " %" PRIu64 " %" PRIu64 "", - &cpu, &cur.user, &cur.nice, &cur.system, &cur.idle, &cur.iowait, - &cur.irq, &cur.softirq, &cur.steal); - if (parsed != 9) continue; + "cpu%d %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 + " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "", + &cpu, &cur.user, &cur.nice, &cur.system, &cur.idle, + &cur.iowait, &cur.irq, &cur.softirq, &cur.steal); + if (parsed != 9) + continue; /* check if match with any input cpus */ for (int i = 0; i < num_cpus; i++) { if (cpu == cpu_ids[i]) { @@ -1065,7 +1133,8 @@ int mt_read_cpu_usage(struct mt_cpu_usage* usages, int* cpu_ids, int num_cpus) { #endif } -double mt_calculate_cpu_usage(struct mt_cpu_usage* prev, struct mt_cpu_usage* curr) { +double mt_calculate_cpu_usage(struct mt_cpu_usage *prev, + struct mt_cpu_usage *curr) { uint64_t prev_idle = prev->idle + prev->iowait; uint64_t curr_idle = curr->idle + curr->iowait; uint64_t prev_total = prev->user + prev->nice + prev->system + prev->idle + @@ -1078,8 +1147,8 @@ double mt_calculate_cpu_usage(struct mt_cpu_usage* prev, struct mt_cpu_usage* cu return 100.0 * (totald - idled) / totald; } -bool mt_file_exists(const char* filename) { - FILE* file = fopen(filename, "r"); +bool mt_file_exists(const char *filename) { + FILE *file = fopen(filename, "r"); if (file) { fclose(file); return true; @@ -1087,7 +1156,7 @@ bool mt_file_exists(const char* filename) { return false; } -int mt_sysfs_write_uint32(const char* path, uint32_t value) { +int mt_sysfs_write_uint32(const char *path, uint32_t value) { int fd = open(path, O_WRONLY); if (fd < 0) { err("%s, open %s fail %d\n", __func__, path, fd); @@ -1121,6 +1190,6 @@ static uint8_t mt_rss_hash_key[MT_HASH_KEY_LENGTH] = { }; // clang-format on -uint32_t mt_softrss(uint32_t* input_tuple, uint32_t input_len) { +uint32_t mt_softrss(uint32_t *input_tuple, uint32_t input_len) { return rte_softrss(input_tuple, input_len, mt_rss_hash_key); } \ No newline at end of file diff --git a/lib/src/mt_util.h b/lib/src/mt_util.h index 28fe045a5..303bb35b8 100644 --- a/lib/src/mt_util.h +++ b/lib/src/mt_util.h @@ -23,10 +23,12 @@ static inline bool mt_is_multicast_ip(const uint8_t ip[MTL_IP_ADDR_LEN]) { } /* if it is a local address area */ -static inline bool mt_is_lan_ip(uint8_t ip[MTL_IP_ADDR_LEN], uint8_t sip[MTL_IP_ADDR_LEN], +static inline bool mt_is_lan_ip(uint8_t ip[MTL_IP_ADDR_LEN], + uint8_t sip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]) { for (int i = 0; i < MTL_IP_ADDR_LEN; i++) { - if ((ip[i] & netmask[i]) != (sip[i] & netmask[i])) return false; + if ((ip[i] & netmask[i]) != (sip[i] & netmask[i])) + return false; } return true; @@ -47,40 +49,44 @@ static inline void mt_u32_to_ip(uint32_t group, uint8_t ip[MTL_IP_ADDR_LEN]) { ip[3] = group >> 24; } -bool mt_bitmap_test_and_set(uint8_t* bitmap, int idx); -bool mt_bitmap_test(uint8_t* bitmap, int idx); -bool mt_bitmap_test_and_unset(uint8_t* bitmap, int idx); +bool mt_bitmap_test_and_set(uint8_t *bitmap, int idx); +bool mt_bitmap_test(uint8_t *bitmap, int idx); +bool mt_bitmap_test_and_unset(uint8_t *bitmap, int idx); /* only for mbuf ring with RING_F_SP_ENQ | RING_F_SC_DEQ */ -int mt_ring_dequeue_clean(struct rte_ring* ring); +int mt_ring_dequeue_clean(struct rte_ring *ring); -void mt_mbuf_sanity_check(struct rte_mbuf** mbufs, uint16_t nb, char* tag); +void mt_mbuf_sanity_check(struct rte_mbuf **mbufs, uint16_t nb, char *tag); -int mt_pacing_train_result_add(struct mtl_main_impl* impl, enum mtl_port port, +int mt_pacing_train_result_add(struct mtl_main_impl *impl, enum mtl_port port, uint64_t rl_bps, float pad_interval); -int mt_pacing_train_result_search(struct mtl_main_impl* impl, enum mtl_port port, - uint64_t rl_bps, float* pad_interval); +int mt_pacing_train_result_search(struct mtl_main_impl *impl, + enum mtl_port port, uint64_t rl_bps, + float *pad_interval); -int mt_audio_pacing_train_result_add(struct mtl_main_impl* impl, enum mtl_port port, - uint64_t input_bps, uint64_t profiled_bps); -int mt_audio_pacing_train_result_search(struct mtl_main_impl* impl, enum mtl_port port, - uint64_t input_bps, uint64_t* profiled_bps); +int mt_audio_pacing_train_result_add(struct mtl_main_impl *impl, + enum mtl_port port, uint64_t input_bps, + uint64_t profiled_bps); +int mt_audio_pacing_train_result_search(struct mtl_main_impl *impl, + enum mtl_port port, uint64_t input_bps, + uint64_t *profiled_bps); -enum mtl_port mt_port_by_name(struct mtl_main_impl* impl, const char* name); -int mt_build_port_map(struct mtl_main_impl* impl, char** ports, enum mtl_port* maps, - int num_ports); +enum mtl_port mt_port_by_name(struct mtl_main_impl *impl, const char *name); +int mt_build_port_map(struct mtl_main_impl *impl, char **ports, + enum mtl_port *maps, int num_ports); /* logical session port to main(physical) port */ -static inline enum mtl_port mt_port_logic2phy(enum mtl_port* maps, +static inline enum mtl_port mt_port_logic2phy(enum mtl_port *maps, enum mtl_session_port logic) { return maps[logic]; } -void st_video_rtp_dump(enum mtl_port port, int idx, char* tag, - struct st20_rfc4175_rtp_hdr* rtp); +void st_video_rtp_dump(enum mtl_port port, int idx, char *tag, + struct st20_rfc4175_rtp_hdr *rtp); -void mt_mbuf_dump(enum mtl_port port, int idx, char* tag, struct rte_mbuf* m); -void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char* tag, struct rte_mbuf* m); +void mt_mbuf_dump(enum mtl_port port, int idx, char *tag, struct rte_mbuf *m); +void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, + struct rte_mbuf *m); void mt_lcore_dump(); @@ -95,133 +101,147 @@ static inline bool st_is_valid_payload_type(int payload_type) { return false; } -void mt_eth_macaddr_dump(enum mtl_port port, char* tag, struct rte_ether_addr* mac_addr); +void mt_eth_macaddr_dump(enum mtl_port port, char *tag, + struct rte_ether_addr *mac_addr); -static inline bool st_rx_seq_drop(uint16_t new_id, uint16_t old_id, uint16_t delta) { +static inline bool st_rx_seq_drop(uint16_t new_id, uint16_t old_id, + uint16_t delta) { if ((new_id <= old_id) && ((old_id - new_id) < delta)) return true; else return false; } -struct rte_mbuf* mt_build_pad(struct mtl_main_impl* impl, struct rte_mempool* mempool, - enum mtl_port port, uint16_t ether_type, uint16_t len); +struct rte_mbuf *mt_build_pad(struct mtl_main_impl *impl, + struct rte_mempool *mempool, enum mtl_port port, + uint16_t ether_type, uint16_t len); -int mt_macaddr_get(struct mtl_main_impl* impl, enum mtl_port port, - struct rte_ether_addr* mac_addr); +int mt_macaddr_get(struct mtl_main_impl *impl, enum mtl_port port, + struct rte_ether_addr *mac_addr); /* default with stack */ #define MT_MEMPOOL_OPS_DEFAULT ("stack") -struct rte_mempool* mt_mempool_create_by_ops(struct mtl_main_impl* impl, const char* name, - unsigned int n, unsigned int cache_size, - uint16_t priv_size, uint16_t element_size, - const char* ops_name, int socket_id); - -static inline struct rte_mempool* mt_mempool_create( - struct mtl_main_impl* impl, enum mtl_port port, const char* name, unsigned int n, - unsigned int cache_size, uint16_t priv_size, uint16_t element_size) { - return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, element_size, - MT_MEMPOOL_OPS_DEFAULT, mt_socket_id(impl, port)); +struct rte_mempool * +mt_mempool_create_by_ops(struct mtl_main_impl *impl, const char *name, + unsigned int n, unsigned int cache_size, + uint16_t priv_size, uint16_t element_size, + const char *ops_name, int socket_id); + +static inline struct rte_mempool * +mt_mempool_create(struct mtl_main_impl *impl, enum mtl_port port, + const char *name, unsigned int n, unsigned int cache_size, + uint16_t priv_size, uint16_t element_size) { + return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, + element_size, MT_MEMPOOL_OPS_DEFAULT, + mt_socket_id(impl, port)); } -static inline struct rte_mempool* mt_mempool_create_by_socket( - struct mtl_main_impl* impl, const char* name, unsigned int n, unsigned int cache_size, - uint16_t priv_size, uint16_t element_size, int socket_id) { - return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, element_size, - MT_MEMPOOL_OPS_DEFAULT, socket_id); +static inline struct rte_mempool * +mt_mempool_create_by_socket(struct mtl_main_impl *impl, const char *name, + unsigned int n, unsigned int cache_size, + uint16_t priv_size, uint16_t element_size, + int socket_id) { + return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, + element_size, MT_MEMPOOL_OPS_DEFAULT, + socket_id); } -static inline struct rte_mempool* mt_mempool_create_common(struct mtl_main_impl* impl, - enum mtl_port port, - const char* name, - unsigned int n) { +static inline struct rte_mempool * +mt_mempool_create_common(struct mtl_main_impl *impl, enum mtl_port port, + const char *name, unsigned int n) { return mt_mempool_create(impl, port, name, n, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), MT_MBUF_DEFAULT_DATA_SIZE); + sizeof(struct mt_muf_priv_data), + MT_MBUF_DEFAULT_DATA_SIZE); } -int mt_mempool_free(struct rte_mempool* mp); +int mt_mempool_free(struct rte_mempool *mp); -void* mt_mempool_mem_addr(struct rte_mempool* mp); -size_t mt_mempool_mem_size(struct rte_mempool* mp); -uint32_t mt_mempool_obj_size(struct rte_mempool* mp); -int mt_mempool_dump(struct rte_mempool* mp); +void *mt_mempool_mem_addr(struct rte_mempool *mp); +size_t mt_mempool_mem_size(struct rte_mempool *mp); +uint32_t mt_mempool_obj_size(struct rte_mempool *mp); +int mt_mempool_dump(struct rte_mempool *mp); -uint16_t mt_rf1071_check_sum(uint8_t* p, size_t len, bool convert); +uint16_t mt_rf1071_check_sum(uint8_t *p, size_t len, bool convert); struct mt_u64_fifo { - uint64_t* data; + uint64_t *data; int write_idx; int read_idx; int size; int used; }; -struct mt_u64_fifo* mt_u64_fifo_init(int size, int soc_id); -int mt_u64_fifo_uinit(struct mt_u64_fifo* fifo); -int mt_u64_fifo_put(struct mt_u64_fifo* fifo, const uint64_t item); -int mt_u64_fifo_get(struct mt_u64_fifo* fifo, uint64_t* item); -int mt_u64_fifo_put_bulk(struct mt_u64_fifo* fifo, const uint64_t* items, uint32_t n); -int mt_u64_fifo_get_bulk(struct mt_u64_fifo* fifo, uint64_t* items, uint32_t n); -int mt_u64_fifo_read_back(struct mt_u64_fifo* fifo, uint64_t* item); -int mt_u64_fifo_read_front(struct mt_u64_fifo* fifo, uint64_t* item); -int mt_u64_fifo_read_any(struct mt_u64_fifo* fifo, uint64_t* item, int skip); -int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo* fifo, uint64_t* items, uint32_t n, - int skip); - -static inline int mt_u64_fifo_full(struct mt_u64_fifo* fifo) { +struct mt_u64_fifo *mt_u64_fifo_init(int size, int soc_id); +int mt_u64_fifo_uinit(struct mt_u64_fifo *fifo); +int mt_u64_fifo_put(struct mt_u64_fifo *fifo, const uint64_t item); +int mt_u64_fifo_get(struct mt_u64_fifo *fifo, uint64_t *item); +int mt_u64_fifo_put_bulk(struct mt_u64_fifo *fifo, const uint64_t *items, + uint32_t n); +int mt_u64_fifo_get_bulk(struct mt_u64_fifo *fifo, uint64_t *items, uint32_t n); +int mt_u64_fifo_read_back(struct mt_u64_fifo *fifo, uint64_t *item); +int mt_u64_fifo_read_front(struct mt_u64_fifo *fifo, uint64_t *item); +int mt_u64_fifo_read_any(struct mt_u64_fifo *fifo, uint64_t *item, int skip); +int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo *fifo, uint64_t *items, + uint32_t n, int skip); + +static inline int mt_u64_fifo_full(struct mt_u64_fifo *fifo) { return fifo->used == fifo->size; } -static inline int mt_u64_fifo_count(struct mt_u64_fifo* fifo) { +static inline int mt_u64_fifo_count(struct mt_u64_fifo *fifo) { return fifo->used; } -static inline int mt_u64_fifo_free_count(struct mt_u64_fifo* fifo) { +static inline int mt_u64_fifo_free_count(struct mt_u64_fifo *fifo) { return fifo->size - fifo->used; } /* only for the mbuf fifo */ -int mt_fifo_mbuf_clean(struct mt_u64_fifo* fifo); +int mt_fifo_mbuf_clean(struct mt_u64_fifo *fifo); struct mt_cvt_dma_ctx { - struct mt_u64_fifo* fifo; - int* tran; - int* done; + struct mt_u64_fifo *fifo; + int *tran; + int *done; }; -struct mt_cvt_dma_ctx* mt_cvt_dma_ctx_init(int fifo_size, int soc_id, int type_num); -int mt_cvt_dma_ctx_uinit(struct mt_cvt_dma_ctx* ctx); -int mt_cvt_dma_ctx_push(struct mt_cvt_dma_ctx* ctx, int type); -int mt_cvt_dma_ctx_pop(struct mt_cvt_dma_ctx* ctx); -static inline int mt_cvt_dma_ctx_get_done(struct mt_cvt_dma_ctx* ctx, int type) { +struct mt_cvt_dma_ctx *mt_cvt_dma_ctx_init(int fifo_size, int soc_id, + int type_num); +int mt_cvt_dma_ctx_uinit(struct mt_cvt_dma_ctx *ctx); +int mt_cvt_dma_ctx_push(struct mt_cvt_dma_ctx *ctx, int type); +int mt_cvt_dma_ctx_pop(struct mt_cvt_dma_ctx *ctx); +static inline int mt_cvt_dma_ctx_get_done(struct mt_cvt_dma_ctx *ctx, + int type) { return ctx->done[type]; } -static inline int mt_cvt_dma_ctx_get_tran(struct mt_cvt_dma_ctx* ctx, int type) { +static inline int mt_cvt_dma_ctx_get_tran(struct mt_cvt_dma_ctx *ctx, + int type) { return ctx->tran[type]; } -int mt_run_cmd(const char* cmd, char* out, size_t out_len); +int mt_run_cmd(const char *cmd, char *out, size_t out_len); -int mt_ip_addr_check(uint8_t* ip); +int mt_ip_addr_check(uint8_t *ip); -int st_tx_dest_info_check(struct st_tx_dest_info* src, int num_ports); +int st_tx_dest_info_check(struct st_tx_dest_info *src, int num_ports); -int st_rx_source_info_check(struct st_rx_source_info* src, int num_ports); +int st_rx_source_info_check(struct st_rx_source_info *src, int num_ports); -int st_frame_trans_uinit(struct st_frame_trans* frame); +int st_frame_trans_uinit(struct st_frame_trans *frame); -int st_vsync_calculate(struct mtl_main_impl* impl, struct st_vsync_info* vsync); +int st_vsync_calculate(struct mtl_main_impl *impl, struct st_vsync_info *vsync); uint16_t mt_random_port(uint16_t base_port); -static inline const char* mt_string_safe(const char* msg) { +static inline const char *mt_string_safe(const char *msg) { return msg ? msg : "null"; } -static inline void mt_mbuf_refcnt_inc_bulk(struct rte_mbuf** mbufs, uint16_t nb) { - struct rte_mbuf* m = NULL; +static inline void mt_mbuf_refcnt_inc_bulk(struct rte_mbuf **mbufs, + uint16_t nb) { + struct rte_mbuf *m = NULL; for (uint16_t i = 0; i < nb; i++) { m = mbufs[i]; while (m) { @@ -231,18 +251,18 @@ static inline void mt_mbuf_refcnt_inc_bulk(struct rte_mbuf** mbufs, uint16_t nb) } } -static inline bool mt_udp_matched(const struct mt_rxq_flow* flow, - const struct mt_udp_hdr* hdr) { - const struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - const struct rte_udp_hdr* udp = &hdr->udp; +static inline bool mt_udp_matched(const struct mt_rxq_flow *flow, + const struct mt_udp_hdr *hdr) { + const struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + const struct rte_udp_hdr *udp = &hdr->udp; bool ip_matched, port_matched; if (flow->flags & MT_RXQ_FLOW_F_NO_IP) { ip_matched = true; } else { ip_matched = mt_is_multicast_ip(flow->dip_addr) - ? (ipv4->dst_addr == *(uint32_t*)flow->dip_addr) - : (ipv4->src_addr == *(uint32_t*)flow->dip_addr); + ? (ipv4->dst_addr == *(uint32_t *)flow->dip_addr) + : (ipv4->src_addr == *(uint32_t *)flow->dip_addr); } if (flow->flags & MT_RXQ_FLOW_F_NO_PORT) { port_matched = true; @@ -269,7 +289,7 @@ static inline int mt_fd_set_nonbolck(int fd) { } #endif -static inline int mt_mkstemps(char* template, int suffix_len) { +static inline int mt_mkstemps(char *template, int suffix_len) { #ifdef WINDOWSENV template[strlen(template) - suffix_len] = '\0'; return mkstemp(template); @@ -278,13 +298,13 @@ static inline int mt_mkstemps(char* template, int suffix_len) { #endif } -const char* mt_dpdk_afxdp_port2if(const char* port); -const char* mt_dpdk_afpkt_port2if(const char* port); -const char* mt_kernel_port2if(const char* port); -const char* mt_native_afxdp_port2if(const char* port); -const char* mt_rdma_ud_port2if(const char* port); +const char *mt_dpdk_afxdp_port2if(const char *port); +const char *mt_dpdk_afpkt_port2if(const char *port); +const char *mt_kernel_port2if(const char *port); +const char *mt_native_afxdp_port2if(const char *port); +const char *mt_rdma_ud_port2if(const char *port); -int mt_user_info_init(struct mt_user_info* info); +int mt_user_info_init(struct mt_user_info *info); struct mt_cpu_usage { uint64_t user; @@ -297,24 +317,25 @@ struct mt_cpu_usage { uint64_t steal; }; -int mt_read_cpu_usage(struct mt_cpu_usage* usages, int* cpu_ids, int num_cpus); +int mt_read_cpu_usage(struct mt_cpu_usage *usages, int *cpu_ids, int num_cpus); -double mt_calculate_cpu_usage(struct mt_cpu_usage* prev, struct mt_cpu_usage* curr); +double mt_calculate_cpu_usage(struct mt_cpu_usage *prev, + struct mt_cpu_usage *curr); -bool mt_file_exists(const char* filename); +bool mt_file_exists(const char *filename); -int mt_sysfs_write_uint32(const char* path, uint32_t value); +int mt_sysfs_write_uint32(const char *path, uint32_t value); -uint32_t mt_softrss(uint32_t* input_tuple, uint32_t input_len); +uint32_t mt_softrss(uint32_t *input_tuple, uint32_t input_len); -static inline void mt_stat_u64_init(struct mt_stat_u64* stat) { +static inline void mt_stat_u64_init(struct mt_stat_u64 *stat) { stat->max = 0; stat->min = (uint64_t)-1; stat->sum = 0; stat->cnt = 0; } -static inline void mt_stat_u64_update(struct mt_stat_u64* stat, uint64_t new) { +static inline void mt_stat_u64_update(struct mt_stat_u64 *stat, uint64_t new) { stat->max = RTE_MAX(stat->max, new); stat->min = RTE_MIN(stat->min, new); stat->sum += new; diff --git a/lib/src/st2110/experimental/st20_redundant_combined_rx.c b/lib/src/st2110/experimental/st20_redundant_combined_rx.c index 8b87f3108..2d27c0307 100644 --- a/lib/src/st2110/experimental/st20_redundant_combined_rx.c +++ b/lib/src/st2110/experimental/st20_redundant_combined_rx.c @@ -9,12 +9,13 @@ #include "../../mt_log.h" #include "../st_rx_video_session.h" -static int rx_st20rc_frame_pop(struct st20rc_rx_ctx* ctx, void* frame) { - struct st20rc_rx_frame* rx_frame; +static int rx_st20rc_frame_pop(struct st20rc_rx_ctx *ctx, void *frame) { + struct st20rc_rx_frame *rx_frame; for (int i = 0; i < ctx->frames_cnt; i++) { rx_frame = &ctx->frames[i]; - if (rx_frame->frame != frame) continue; + if (rx_frame->frame != frame) + continue; /* find the slot */ rx_frame->frame = NULL; return st20_rx_put_framebuff(ctx->transport[rx_frame->port]->handle, frame); @@ -24,22 +25,23 @@ static int rx_st20rc_frame_pop(struct st20rc_rx_ctx* ctx, void* frame) { return -EIO; } -static int rx_st20rc_frame_push(struct st20rc_rx_ctx* ctx, void* frame, +static int rx_st20rc_frame_push(struct st20rc_rx_ctx *ctx, void *frame, enum mtl_session_port port, - struct st20_rx_frame_meta* meta) { - struct st20rc_rx_frame* rx_frame; + struct st20_rx_frame_meta *meta) { + struct st20rc_rx_frame *rx_frame; int ret; for (int i = 0; i < ctx->frames_cnt; i++) { rx_frame = &ctx->frames[i]; - if (rx_frame->frame) continue; + if (rx_frame->frame) + continue; /* find a empty slot, notify user */ rx_frame->frame = frame; rx_frame->port = port; rx_frame->meta = *meta; ret = ctx->ops.notify_frame_ready(ctx->ops.priv, frame, meta); - dbg("%s(%d), notify frame %p(%d:%u) to user, ret %d\n", __func__, ctx->idx, frame, - port, i, ret); + dbg("%s(%d), notify frame %p(%d:%u) to user, ret %d\n", __func__, ctx->idx, + frame, port, i, ret); if (ret < 0) { /* clear the frame */ rx_frame->frame = NULL; @@ -51,15 +53,16 @@ static int rx_st20rc_frame_push(struct st20rc_rx_ctx* ctx, void* frame, return -EIO; } -static int rx_st20rc_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - struct st20rc_rx_transport* transport = priv; - struct st20rc_rx_ctx* ctx = transport->parent; +static int rx_st20rc_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct st20rc_rx_transport *transport = priv; + struct st20rc_rx_ctx *ctx = transport->parent; int idx = ctx->idx; enum mtl_session_port port = transport->port; int ret = -EIO; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ dbg("%s(%d), get frame %p at port %d\n", __func__, idx, frame, port); @@ -86,7 +89,8 @@ static int rx_st20rc_frame_ready(void* priv, void* frame, ret = rx_st20rc_frame_push(ctx, frame, port, meta); if (ret >= 0) { ctx->cur_frame_complete = true; - info("%s(%d), push frame %p at r_port %d\n", __func__, idx, frame, port); + info("%s(%d), push frame %p at r_port %d\n", __func__, idx, frame, + port); } } else { ret = -EIO; /* simply drop as frame get already */ @@ -98,12 +102,13 @@ static int rx_st20rc_frame_ready(void* priv, void* frame, mt_pthread_mutex_unlock(&ctx->lock); /* always return 0 to suppress the error log */ - if (ret < 0) st20_rx_put_framebuff(ctx->transport[port]->handle, frame); + if (ret < 0) + st20_rx_put_framebuff(ctx->transport[port]->handle, frame); return 0; } -static int rx_st20rc_notify_event(void* priv, enum st_event event, void* args) { - struct st20rc_rx_ctx* ctx = priv; +static int rx_st20rc_notify_event(void *priv, enum st_event event, void *args) { + struct st20rc_rx_ctx *ctx = priv; if (ctx->ops.notify_event) { ctx->ops.notify_event(ctx->ops.priv, event, args); @@ -112,7 +117,7 @@ static int rx_st20rc_notify_event(void* priv, enum st_event event, void* args) { return 0; } -static int rx_st20rc_free_transport(struct st20rc_rx_transport* transport) { +static int rx_st20rc_free_transport(struct st20rc_rx_transport *transport) { if (transport->handle) { st20_rx_free(transport->handle); transport->handle = NULL; @@ -122,12 +127,12 @@ static int rx_st20rc_free_transport(struct st20rc_rx_transport* transport) { return 0; } -static int rx_st20rc_create_transport(struct st20rc_rx_ctx* ctx, - struct st20rc_rx_ops* ops, +static int rx_st20rc_create_transport(struct st20rc_rx_ctx *ctx, + struct st20rc_rx_ops *ops, enum mtl_session_port port) { int idx = ctx->idx; - struct mtl_main_impl* impl = ctx->impl; - struct st20rc_rx_transport* transport; + struct mtl_main_impl *impl = ctx->impl; + struct st20rc_rx_transport *transport; struct st20_rx_ops ops_rx; if (ctx->transport[port]) { @@ -135,7 +140,8 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx* ctx, return -EIO; } - transport = mt_rte_zmalloc_socket(sizeof(*transport), mt_socket_id(impl, MTL_PORT_P)); + transport = + mt_rte_zmalloc_socket(sizeof(*transport), mt_socket_id(impl, MTL_PORT_P)); if (!transport) { err("%s, transport malloc fail\n", __func__); return -ENOMEM; @@ -148,10 +154,12 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx* ctx, ops_rx.name = ops->name; ops_rx.priv = transport; ops_rx.num_port = 1; - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ops->ip_addr[port], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ops->ip_addr[port], + MTL_IP_ADDR_LEN); memcpy(ops_rx.mcast_sip_addr[MTL_SESSION_PORT_P], ops->mcast_sip_addr[port], MTL_IP_ADDR_LEN); - snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ops->port[port]); + snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + ops->port[port]); ops_rx.udp_port[MTL_SESSION_PORT_P] = ops->udp_port[port]; if (ops->flags & ST20RC_RX_FLAG_DATA_PATH_ONLY) @@ -160,9 +168,12 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx* ctx, ops_rx.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; /* disable migrate since it may migrate the two sessions into one sch */ ops_rx.flags |= ST20_RX_FLAG_DISABLE_MIGRATE; - if (ops->flags & ST20RC_RX_FLAG_DMA_OFFLOAD) ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; - if (ops->flags & ST20RC_RX_FLAG_HDR_SPLIT) ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; - if (ops->flags & ST20RC_RX_FLAG_ENABLE_VSYNC) ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST20RC_RX_FLAG_DMA_OFFLOAD) + ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; + if (ops->flags & ST20RC_RX_FLAG_HDR_SPLIT) + ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (ops->flags & ST20RC_RX_FLAG_ENABLE_VSYNC) + ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; ops_rx.pacing = ops->pacing; ops_rx.width = ops->width; @@ -181,7 +192,8 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx* ctx, mt_sch_mask_t sch_mask = MT_SCH_MASK_ALL; if (port == MTL_SESSION_PORT_R) { /* let R port select a different sch */ - int sch_idx = st20_rx_get_sch_idx(ctx->transport[MTL_SESSION_PORT_P]->handle); + int sch_idx = + st20_rx_get_sch_idx(ctx->transport[MTL_SESSION_PORT_P]->handle); if (sch_idx < 0) { err("%s(%d), st20_rx_get_sch_idx fail \n", __func__, idx); rx_st20rc_free_transport(transport); @@ -204,7 +216,7 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx* ctx, } int st20rc_rx_free(st20rc_rx_handle handle) { - struct st20rc_rx_ctx* ctx = handle; + struct st20rc_rx_ctx *ctx = handle; if (ctx->type != MT_HANDLE_RX_VIDEO_R) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); @@ -230,9 +242,9 @@ int st20rc_rx_free(st20rc_rx_handle handle) { return 0; } -st20rc_rx_handle st20rc_rx_create(mtl_handle mt, struct st20rc_rx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct st20rc_rx_ctx* ctx; +st20rc_rx_handle st20rc_rx_create(mtl_handle mt, struct st20rc_rx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct st20rc_rx_ctx *ctx; int ret; int idx = 0; /* todo */ int num_port = ops->num_port; @@ -245,10 +257,11 @@ st20rc_rx_handle st20rc_rx_create(mtl_handle mt, struct st20rc_rx_ops* ops) { err("%s, invalid num_port %u\n", __func__, num_port); return NULL; } - if (0 == memcmp(ops->ip_addr[MTL_SESSION_PORT_P], ops->ip_addr[MTL_SESSION_PORT_R], - MTL_IP_ADDR_LEN)) { - uint8_t* ip = ops->ip_addr[MTL_SESSION_PORT_P]; - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + if (0 == memcmp(ops->ip_addr[MTL_SESSION_PORT_P], + ops->ip_addr[MTL_SESSION_PORT_R], MTL_IP_ADDR_LEN)) { + uint8_t *ip = ops->ip_addr[MTL_SESSION_PORT_P]; + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return NULL; } if (!ops->notify_frame_ready) { @@ -298,8 +311,8 @@ st20rc_rx_handle st20rc_rx_create(mtl_handle mt, struct st20rc_rx_ops* ops) { return ctx; } -int st20rc_rx_put_frame(st20rc_rx_handle handle, void* frame) { - struct st20rc_rx_ctx* ctx = handle; +int st20rc_rx_put_frame(st20rc_rx_handle handle, void *frame) { + struct st20rc_rx_ctx *ctx = handle; if (ctx->type != MT_HANDLE_RX_VIDEO_R) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); @@ -310,30 +323,32 @@ int st20rc_rx_put_frame(st20rc_rx_handle handle, void* frame) { } size_t st20rc_rx_get_framebuffer_size(st20rc_rx_handle handle) { - struct st20rc_rx_ctx* ctx = handle; + struct st20rc_rx_ctx *ctx = handle; if (ctx->type != MT_HANDLE_RX_VIDEO_R) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); return -EIO; } - return st20_rx_get_framebuffer_size(ctx->transport[MTL_SESSION_PORT_P]->handle); + return st20_rx_get_framebuffer_size( + ctx->transport[MTL_SESSION_PORT_P]->handle); } int st20rc_rx_get_framebuffer_count(st20rc_rx_handle handle) { - struct st20rc_rx_ctx* ctx = handle; + struct st20rc_rx_ctx *ctx = handle; if (ctx->type != MT_HANDLE_RX_VIDEO_R) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); return -EIO; } - return st20_rx_get_framebuffer_count(ctx->transport[MTL_SESSION_PORT_P]->handle); + return st20_rx_get_framebuffer_count( + ctx->transport[MTL_SESSION_PORT_P]->handle); } -int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta) { - struct st20rc_rx_ctx* ctx = handle; +int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta) { + struct st20rc_rx_ctx *ctx = handle; int ret = 0; if (ctx->type != MT_HANDLE_RX_VIDEO_R) { @@ -341,9 +356,9 @@ int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, bo return -EIO; } - ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_P]->handle, max_dump_packets, - sync, meta); - ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_R]->handle, max_dump_packets, - sync, meta); + ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_P]->handle, + max_dump_packets, sync, meta); + ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_R]->handle, + max_dump_packets, sync, meta); return ret; } diff --git a/lib/src/st2110/experimental/st20_redundant_combined_rx.h b/lib/src/st2110/experimental/st20_redundant_combined_rx.h index b1eda3848..74321d5e7 100644 --- a/lib/src/st2110/experimental/st20_redundant_combined_rx.h +++ b/lib/src/st2110/experimental/st20_redundant_combined_rx.h @@ -16,17 +16,17 @@ struct st20rc_rx_ctx; struct st20rc_rx_transport { st20_rx_handle handle; enum mtl_session_port port; /* port this handle attached */ - struct st20rc_rx_ctx* parent; + struct st20rc_rx_ctx *parent; }; struct st20rc_rx_frame { - void* frame; + void *frame; enum mtl_session_port port; struct st20_rx_frame_meta meta; }; struct st20rc_rx_ctx { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; enum mt_handle_type type; /* for sanity check, must be MT_HANDLE_RX_VIDEO_R */ @@ -35,14 +35,14 @@ struct st20rc_rx_ctx { pthread_mutex_t lock; bool ready; - struct st20rc_rx_transport* transport[MTL_SESSION_PORT_MAX]; + struct st20rc_rx_transport *transport[MTL_SESSION_PORT_MAX]; /* global status for current frame */ - void* cur_frame; + void *cur_frame; uint64_t cur_timestamp; bool cur_frame_complete; /* the frames passed to user */ - struct st20rc_rx_frame* frames; + struct st20rc_rx_frame *frames; int frames_cnt; }; diff --git a/lib/src/st2110/pipeline/st20_pipeline_rx.c b/lib/src/st2110/pipeline/st20_pipeline_rx.c index ac544bd66..c6264252a 100644 --- a/lib/src/st2110/pipeline/st20_pipeline_rx.c +++ b/lib/src/st2110/pipeline/st20_pipeline_rx.c @@ -7,32 +7,33 @@ #include "../../mt_log.h" #include "../../mt_stat.h" -static int rx_st20p_uinit_dst_fbs(struct st20p_rx_ctx* ctx); +static int rx_st20p_uinit_dst_fbs(struct st20p_rx_ctx *ctx); -static const char* st20p_rx_frame_stat_name[ST20P_RX_FRAME_STATUS_MAX] = { +static const char *st20p_rx_frame_stat_name[ST20P_RX_FRAME_STATUS_MAX] = { "free", "ready", "in_converting", "converted", "in_user", }; -static const char* rx_st20p_stat_name(enum st20p_rx_frame_status stat) { +static const char *rx_st20p_stat_name(enum st20p_rx_frame_status stat) { return st20p_rx_frame_stat_name[stat]; } -static uint16_t rx_st20p_next_idx(struct st20p_rx_ctx* ctx, uint16_t idx) { +static uint16_t rx_st20p_next_idx(struct st20p_rx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) + next_idx = 0; return next_idx; } -static void rx_st20p_block_wake(struct st20p_rx_ctx* ctx) { +static void rx_st20p_block_wake(struct st20p_rx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); mt_pthread_cond_signal(&ctx->block_wake_cond); mt_pthread_mutex_unlock(&ctx->block_wake_mutex); } -static void rx_st20p_notify_frame_available(struct st20p_rx_ctx* ctx) { +static void rx_st20p_notify_frame_available(struct st20p_rx_ctx *ctx) { if (ctx->ops.notify_frame_available) { /* notify app */ ctx->ops.notify_frame_available(ctx->ops.priv); } @@ -43,10 +44,11 @@ static void rx_st20p_notify_frame_available(struct st20p_rx_ctx* ctx) { } } -static struct st20p_rx_frame* rx_st20p_next_available( - struct st20p_rx_ctx* ctx, uint16_t idx_start, enum st20p_rx_frame_status desired) { +static struct st20p_rx_frame * +rx_st20p_next_available(struct st20p_rx_ctx *ctx, uint16_t idx_start, + enum st20p_rx_frame_status desired) { uint16_t idx = idx_start; - struct st20p_rx_frame* framebuff; + struct st20p_rx_frame *framebuff; /* check ready frame from idx_start */ while (1) { @@ -66,19 +68,19 @@ static struct st20p_rx_frame* rx_st20p_next_available( return NULL; } -static int rx_st20p_packet_convert(void* priv, void* frame, - struct st20_rx_uframe_pg_meta* meta) { - struct st20p_rx_ctx* ctx = priv; - struct st20p_rx_frame* framebuff; +static int rx_st20p_packet_convert(void *priv, void *frame, + struct st20_rx_uframe_pg_meta *meta) { + struct st20p_rx_ctx *ctx = priv; + struct st20p_rx_frame *framebuff; int ret = 0; - struct st20_rfc4175_422_10_pg2_be* src = meta->payload; + struct st20_rfc4175_422_10_pg2_be *src = meta->payload; MTL_MAY_UNUSED(frame); mt_pthread_mutex_lock(&ctx->lock); if (meta->row_number == 0 && meta->row_offset == 0) { /* first packet of frame */ - framebuff = - rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_RX_FRAME_FREE); + framebuff = rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, + ST20P_RX_FRAME_FREE); if (framebuff) { framebuff->stat = ST20P_RX_FRAME_IN_CONVERTING; framebuff->dst.timestamp = meta->timestamp; @@ -88,8 +90,8 @@ static int rx_st20p_packet_convert(void* priv, void* frame, ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { dbg("%s(%d), not this frame, find next one\n", __func__, ctx->idx); - framebuff = - rx_st20p_next_available(ctx, framebuff->idx, ST20P_RX_FRAME_IN_CONVERTING); + framebuff = rx_st20p_next_available(ctx, framebuff->idx, + ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { /* should never happen */ err_once("%s(%d), wrong frame timestamp\n", __func__, ctx->idx); @@ -105,50 +107,62 @@ static int rx_st20p_packet_convert(void* priv, void* frame, } mt_pthread_mutex_unlock(&ctx->lock); if (ctx->ops.output_fmt == ST_FRAME_FMT_YUV422PLANAR10LE) { - uint8_t* y = (uint8_t*)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; - uint8_t* b = (uint8_t*)framebuff->dst.addr[1] + - framebuff->dst.linesize[1] * meta->row_number + meta->row_offset; - uint8_t* r = (uint8_t*)framebuff->dst.addr[2] + - framebuff->dst.linesize[2] * meta->row_number + meta->row_offset; - ret = st20_rfc4175_422be10_to_yuv422p10le(src, (uint16_t*)y, (uint16_t*)b, - (uint16_t*)r, meta->pg_cnt, 2); + uint8_t *y = (uint8_t *)framebuff->dst.addr[0] + + framebuff->dst.linesize[0] * meta->row_number + + meta->row_offset * 2; + uint8_t *b = (uint8_t *)framebuff->dst.addr[1] + + framebuff->dst.linesize[1] * meta->row_number + + meta->row_offset; + uint8_t *r = (uint8_t *)framebuff->dst.addr[2] + + framebuff->dst.linesize[2] * meta->row_number + + meta->row_offset; + ret = st20_rfc4175_422be10_to_yuv422p10le(src, (uint16_t *)y, (uint16_t *)b, + (uint16_t *)r, meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_Y210) { - uint8_t* dst = (uint8_t*)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 4; - ret = st20_rfc4175_422be10_to_y210(src, (uint16_t*)dst, meta->pg_cnt, 2); + uint8_t *dst = (uint8_t *)framebuff->dst.addr[0] + + framebuff->dst.linesize[0] * meta->row_number + + meta->row_offset * 4; + ret = st20_rfc4175_422be10_to_y210(src, (uint16_t *)dst, meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_UYVY) { - uint8_t* dst = (uint8_t*)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; - ret = st20_rfc4175_422be10_to_422le8(src, (struct st20_rfc4175_422_8_pg2_le*)dst, - meta->pg_cnt, 2); + uint8_t *dst = (uint8_t *)framebuff->dst.addr[0] + + framebuff->dst.linesize[0] * meta->row_number + + meta->row_offset * 2; + ret = st20_rfc4175_422be10_to_422le8( + src, (struct st20_rfc4175_422_8_pg2_le *)dst, meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_YUV422PLANAR8) { - uint8_t* y = (uint8_t*)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; - uint8_t* b = (uint8_t*)framebuff->dst.addr[1] + - framebuff->dst.linesize[1] * meta->row_number + meta->row_offset; - uint8_t* r = (uint8_t*)framebuff->dst.addr[2] + - framebuff->dst.linesize[2] * meta->row_number + meta->row_offset; + uint8_t *y = (uint8_t *)framebuff->dst.addr[0] + + framebuff->dst.linesize[0] * meta->row_number + + meta->row_offset * 2; + uint8_t *b = (uint8_t *)framebuff->dst.addr[1] + + framebuff->dst.linesize[1] * meta->row_number + + meta->row_offset; + uint8_t *r = (uint8_t *)framebuff->dst.addr[2] + + framebuff->dst.linesize[2] * meta->row_number + + meta->row_offset; ret = st20_rfc4175_422be10_to_yuv422p8(src, y, b, r, meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_YUV420PLANAR8) { - uint8_t* y = (uint8_t*)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; - uint8_t* b = (uint8_t*)framebuff->dst.addr[1] + - framebuff->dst.linesize[1] * meta->row_number + meta->row_offset; - uint8_t* r = (uint8_t*)framebuff->dst.addr[2] + - framebuff->dst.linesize[2] * meta->row_number + meta->row_offset; + uint8_t *y = (uint8_t *)framebuff->dst.addr[0] + + framebuff->dst.linesize[0] * meta->row_number + + meta->row_offset * 2; + uint8_t *b = (uint8_t *)framebuff->dst.addr[1] + + framebuff->dst.linesize[1] * meta->row_number + + meta->row_offset; + uint8_t *r = (uint8_t *)framebuff->dst.addr[2] + + framebuff->dst.linesize[2] * meta->row_number + + meta->row_offset; ret = st20_rfc4175_422be10_to_yuv420p8(src, y, b, r, meta->pg_cnt, 2); } return ret; } -static int rx_st20p_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - struct st20p_rx_ctx* ctx = priv; - struct st20p_rx_frame* framebuff; +static int rx_st20p_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + struct st20p_rx_ctx *ctx = priv; + struct st20p_rx_frame *framebuff; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); if (ctx->ops.flags & ST20P_RX_FLAG_PKT_CONVERT) { @@ -156,8 +170,8 @@ static int rx_st20p_frame_ready(void* priv, void* frame, ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { dbg("%s(%d), not this frame, find next one\n", __func__, ctx->idx); - framebuff = - rx_st20p_next_available(ctx, framebuff->idx, ST20P_RX_FRAME_IN_CONVERTING); + framebuff = rx_st20p_next_available(ctx, framebuff->idx, + ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { /* should never happen */ mt_pthread_mutex_unlock(&ctx->lock); @@ -166,8 +180,8 @@ static int rx_st20p_frame_ready(void* priv, void* frame, } } } else { - framebuff = - rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_RX_FRAME_FREE); + framebuff = rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, + ST20P_RX_FRAME_FREE); } /* not any free frame */ @@ -177,8 +191,8 @@ static int rx_st20p_frame_ready(void* priv, void* frame, return -EBUSY; } - MT_USDT_ST20P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, meta->rtp_timestamp, - meta->frame_recv_size); + MT_USDT_ST20P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, + meta->rtp_timestamp, meta->frame_recv_size); /* query the ext frame for no convert mode */ if (ctx->dynamic_ext_frame && !ctx->derive) { @@ -212,27 +226,35 @@ static int rx_st20p_frame_ready(void* priv, void* frame, framebuff->src.addr[0] = frame; framebuff->src.data_size = meta->frame_total_size; - framebuff->src.second_field = framebuff->dst.second_field = meta->second_field; + framebuff->src.second_field = framebuff->dst.second_field = + meta->second_field; framebuff->src.tfmt = framebuff->dst.tfmt = meta->tfmt; framebuff->src.timestamp = framebuff->dst.timestamp = meta->timestamp; - framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp; + framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = + meta->rtp_timestamp; framebuff->src.status = framebuff->dst.status = meta->status; framebuff->src.pkts_total = framebuff->dst.pkts_total = meta->pkts_total; - for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; s_port++) { + for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; + s_port++) { framebuff->src.pkts_recv[s_port] = framebuff->dst.pkts_recv[s_port] = meta->pkts_recv[s_port]; } /* copy timing parser meta */ - for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; s_port++) { + for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; + s_port++) { framebuff->src.tp[s_port] = framebuff->dst.tp[s_port] = NULL; } - for (enum mtl_session_port s_port = 0; s_port < ctx->ops.port.num_port; s_port++) { - if (!meta->tp[s_port]) continue; - mtl_memcpy(&framebuff->tp[s_port], meta->tp[s_port], sizeof(framebuff->tp[s_port])); - framebuff->src.tp[s_port] = framebuff->dst.tp[s_port] = &framebuff->tp[s_port]; + for (enum mtl_session_port s_port = 0; s_port < ctx->ops.port.num_port; + s_port++) { + if (!meta->tp[s_port]) + continue; + mtl_memcpy(&framebuff->tp[s_port], meta->tp[s_port], + sizeof(framebuff->tp[s_port])); + framebuff->src.tp[s_port] = framebuff->dst.tp[s_port] = + &framebuff->tp[s_port]; } /* check user meta */ @@ -248,7 +270,8 @@ static int rx_st20p_frame_ready(void* priv, void* frame, /* ask app to consume src frame directly */ if (ctx->derive || (ctx->ops.flags & ST20P_RX_FLAG_PKT_CONVERT)) { - if (ctx->derive) framebuff->dst = framebuff->src; + if (ctx->derive) + framebuff->dst = framebuff->src; framebuff->stat = ST20P_RX_FRAME_CONVERTED; /* point to next */ ctx->framebuff_producer_idx = rx_st20p_next_idx(ctx, framebuff->idx); @@ -265,7 +288,8 @@ static int rx_st20p_frame_ready(void* priv, void* frame, dbg("%s(%d), frame %u succ\n", __func__, ctx->idx, framebuff->idx); /* ask convert plugin to consume */ - if (ctx->convert_impl) st20_convert_notify_frame_ready(ctx->convert_impl); + if (ctx->convert_impl) + st20_convert_notify_frame_ready(ctx->convert_impl); /* or ask app to consume with internal converter */ if (ctx->internal_converter) { @@ -275,17 +299,19 @@ static int rx_st20p_frame_ready(void* priv, void* frame, return 0; } -static int rx_st20p_query_ext_frame(void* priv, struct st20_ext_frame* ext_frame, - struct st20_rx_frame_meta* meta) { - struct st20p_rx_ctx* ctx = priv; - struct st20p_rx_frame* framebuff; +static int rx_st20p_query_ext_frame(void *priv, + struct st20_ext_frame *ext_frame, + struct st20_rx_frame_meta *meta) { + struct st20p_rx_ctx *ctx = priv; + struct st20p_rx_frame *framebuff; int ret; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_RX_FRAME_FREE); + framebuff = rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, + ST20P_RX_FRAME_FREE); /* not any free frame */ if (!framebuff) { rte_atomic32_inc(&ctx->stat_busy); @@ -311,8 +337,8 @@ static int rx_st20p_query_ext_frame(void* priv, struct st20_ext_frame* ext_frame return 0; } -static int rx_st20p_notify_event(void* priv, enum st_event event, void* args) { - struct st20p_rx_ctx* ctx = priv; +static int rx_st20p_notify_event(void *priv, enum st_event event, void *args) { + struct st20p_rx_ctx *ctx = priv; if (ctx->ops.notify_event) { ctx->ops.notify_event(ctx->ops.priv, event, args); @@ -321,20 +347,22 @@ static int rx_st20p_notify_event(void* priv, enum st_event event, void* args) { return 0; } -static int rx_st20p_notify_detected(void* priv, const struct st20_detect_meta* meta, - struct st20_detect_reply* reply) { - struct st20p_rx_ctx* ctx = priv; +static int rx_st20p_notify_detected(void *priv, + const struct st20_detect_meta *meta, + struct st20_detect_reply *reply) { + struct st20p_rx_ctx *ctx = priv; int idx = ctx->idx; - void* dst = NULL; - struct st20p_rx_frame* frames = ctx->framebuffs; + void *dst = NULL; + struct st20p_rx_frame *frames = ctx->framebuffs; bool no_dst_malloc = false; int soc_id = ctx->socket_id; info("%s(%d), init dst buffer now, w %d h %d\n", __func__, idx, meta->width, meta->height); - ctx->dst_size = - st_frame_size(ctx->ops.output_fmt, meta->width, meta->height, meta->interlaced); - if (ctx->derive || ctx->ops.ext_frames || ctx->ops.flags & ST20P_RX_FLAG_EXT_FRAME) { + ctx->dst_size = st_frame_size(ctx->ops.output_fmt, meta->width, meta->height, + meta->interlaced); + if (ctx->derive || ctx->ops.ext_frames || + ctx->ops.flags & ST20P_RX_FLAG_EXT_FRAME) { no_dst_malloc = true; } @@ -348,26 +376,28 @@ static int rx_st20p_notify_detected(void* priv, const struct st20_detect_meta* m frames[i].src.height = meta->height; frames[i].src.buffer_size = - st_frame_size(frames[i].src.fmt, frames[i].src.width, frames[i].src.height, - frames[i].src.interlaced); + st_frame_size(frames[i].src.fmt, frames[i].src.width, + frames[i].src.height, frames[i].src.interlaced); frames[i].src.data_size = frames[i].src.buffer_size; /* rfc4175 uses packed format */ - frames[i].src.linesize[0] = - RTE_MAX(ctx->ops.transport_linesize, - st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); + frames[i].src.linesize[0] = RTE_MAX( + ctx->ops.transport_linesize, + st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); - if (no_dst_malloc) continue; + if (no_dst_malloc) + continue; dst = mt_rte_zmalloc_socket(ctx->dst_size, soc_id); if (!dst) { - err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", __func__, idx, i, - ctx->dst_size); + err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", __func__, + idx, i, ctx->dst_size); rx_st20p_uinit_dst_fbs(ctx); return -ENOMEM; } frames[i].dst.buffer_size = ctx->dst_size; frames[i].dst.data_size = ctx->dst_size; /* init plane */ - st_frame_init_plane_single_src(&frames[i].dst, dst, mtl_hp_virt2iova(ctx->impl, dst)); + st_frame_init_plane_single_src(&frames[i].dst, dst, + mtl_hp_virt2iova(ctx->impl, dst)); } if (ctx->ops.notify_detected) { @@ -377,21 +407,22 @@ static int rx_st20p_notify_detected(void* priv, const struct st20_detect_meta* m return 0; } -static struct st20_convert_frame_meta* rx_st20p_convert_get_frame(void* priv) { - struct st20p_rx_ctx* ctx = priv; +static struct st20_convert_frame_meta *rx_st20p_convert_get_frame(void *priv) { + struct st20p_rx_ctx *ctx = priv; int idx = ctx->idx; - struct st20p_rx_frame* framebuff; + struct st20p_rx_frame *framebuff; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st20p_next_available(ctx, ctx->framebuff_convert_idx, ST20P_RX_FRAME_READY); + framebuff = rx_st20p_next_available(ctx, ctx->framebuff_convert_idx, + ST20P_RX_FRAME_READY); /* not any ready frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -407,11 +438,12 @@ static struct st20_convert_frame_meta* rx_st20p_convert_get_frame(void* priv) { return &framebuff->convert_frame; } -static int rx_st20p_convert_put_frame(void* priv, struct st20_convert_frame_meta* frame, +static int rx_st20p_convert_put_frame(void *priv, + struct st20_convert_frame_meta *frame, int result) { - struct st20p_rx_ctx* ctx = priv; + struct st20p_rx_ctx *ctx = priv; int idx = ctx->idx; - struct st20p_rx_frame* framebuff = frame->priv; + struct st20p_rx_frame *framebuff = frame->priv; uint16_t convert_idx = framebuff->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -439,11 +471,12 @@ static int rx_st20p_convert_put_frame(void* priv, struct st20_convert_frame_meta return 0; } -static int rx_st20p_convert_dump(void* priv) { - struct st20p_rx_ctx* ctx = priv; - struct st20p_rx_frame* framebuff = ctx->framebuffs; +static int rx_st20p_convert_dump(void *priv) { + struct st20p_rx_ctx *ctx = priv; + struct st20p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t convert_idx = ctx->framebuff_convert_idx; notice("RX_st20p(%s), cv(%d:%s)\n", ctx->ops_name, convert_idx, @@ -464,12 +497,13 @@ static int rx_st20p_convert_dump(void* priv) { return 0; } -static int rx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_rx_ctx* ctx, - struct st20p_rx_ops* ops) { +static int rx_st20p_create_transport(struct mtl_main_impl *impl, + struct st20p_rx_ctx *ctx, + struct st20p_rx_ops *ops) { int idx = ctx->idx; struct st20_rx_ops ops_rx; st20_rx_handle transport; - struct st20_ext_frame* trans_ext_frames = NULL; + struct st20_ext_frame *trans_ext_frames = NULL; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = ops->name; @@ -477,18 +511,23 @@ static int rx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_rx ops_rx.num_port = RTE_MIN(ops->port.num_port, MTL_SESSION_PORT_MAX); for (int i = 0; i < ops_rx.num_port; i++) { memcpy(ops_rx.ip_addr[i], ops->port.ip_addr[i], MTL_IP_ADDR_LEN); - memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], MTL_IP_ADDR_LEN); + memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[i], MTL_PORT_MAX_LEN, "%s", ops->port.port[i]); ops_rx.udp_port[i] = ops->port.udp_port[i]; } if (ops->flags & ST20P_RX_FLAG_DATA_PATH_ONLY) ops_rx.flags |= ST20_RX_FLAG_DATA_PATH_ONLY; - if (ops->flags & ST20P_RX_FLAG_ENABLE_VSYNC) ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST20P_RX_FLAG_ENABLE_VSYNC) + ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; if (ops->flags & ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME) ops_rx.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; - if (ops->flags & ST20P_RX_FLAG_DMA_OFFLOAD) ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; - if (ops->flags & ST20P_RX_FLAG_AUTO_DETECT) ops_rx.flags |= ST20_RX_FLAG_AUTO_DETECT; - if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (ops->flags & ST20P_RX_FLAG_DMA_OFFLOAD) + ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; + if (ops->flags & ST20P_RX_FLAG_AUTO_DETECT) + ops_rx.flags |= ST20_RX_FLAG_AUTO_DETECT; + if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) + ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; if (ops->flags & ST20P_RX_FLAG_DISABLE_MIGRATE) ops_rx.flags |= ST20_RX_FLAG_DISABLE_MIGRATE; if (ops->flags & ST20P_RX_FLAG_TIMING_PARSER_STAT) @@ -510,7 +549,8 @@ static int rx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_rx return -EIO; } ops_rx.uframe_pg_callback = rx_st20p_packet_convert; - ops_rx.uframe_size = st20_frame_size(ops->transport_fmt, ops->width, ops->height); + ops_rx.uframe_size = + st20_frame_size(ops->transport_fmt, ops->width, ops->height); } if (ops->flags & ST20P_RX_FLAG_ENABLE_RTCP) { ops_rx.flags |= ST20_RX_FLAG_ENABLE_RTCP; @@ -543,9 +583,10 @@ static int rx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_rx if (ops->ext_frames) { uint16_t framebuff_cnt = ctx->framebuff_cnt; /* hdr split use continuous frame */ - if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) framebuff_cnt = 1; - trans_ext_frames = mt_rte_zmalloc_socket(sizeof(*trans_ext_frames) * framebuff_cnt, - ctx->socket_id); + if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) + framebuff_cnt = 1; + trans_ext_frames = mt_rte_zmalloc_socket( + sizeof(*trans_ext_frames) * framebuff_cnt, ctx->socket_id); if (!trans_ext_frames) { err("%s, trans_ext_frames malloc fail\n", __func__); return -ENOMEM; @@ -559,8 +600,10 @@ static int rx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_rx } if (ops->query_ext_frame) { if (!(ops->flags & ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME)) { - err("%s, pls enable incomplete frame flag for derive query ext mode\n", __func__); - if (trans_ext_frames) mt_rte_free(trans_ext_frames); + err("%s, pls enable incomplete frame flag for derive query ext mode\n", + __func__); + if (trans_ext_frames) + mt_rte_free(trans_ext_frames); return -EINVAL; } ops_rx.query_ext_frame = rx_st20p_query_ext_frame; @@ -570,23 +613,25 @@ static int rx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_rx transport = st20_rx_create(impl, &ops_rx); if (!transport) { err("%s(%d), transport create fail\n", __func__, idx); - if (trans_ext_frames) mt_rte_free(trans_ext_frames); + if (trans_ext_frames) + mt_rte_free(trans_ext_frames); return -EIO; } ctx->transport = transport; - struct st20p_rx_frame* frames = ctx->framebuffs; + struct st20p_rx_frame *frames = ctx->framebuffs; for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { frames[i].src.fmt = st_frame_fmt_from_transport(ctx->ops.transport_fmt); frames[i].src.interlaced = ops->interlaced; - frames[i].src.buffer_size = - st_frame_size(frames[i].src.fmt, ops->width, ops->height, ops->interlaced); + frames[i].src.buffer_size = st_frame_size(frames[i].src.fmt, ops->width, + ops->height, ops->interlaced); frames[i].src.data_size = frames[i].src.buffer_size; frames[i].src.width = ops->width; frames[i].src.height = ops->height; frames[i].src.linesize[0] = /* rfc4175 uses packed format */ - RTE_MAX(ops->transport_linesize, - st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); + RTE_MAX( + ops->transport_linesize, + st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); frames[i].src.priv = &frames[i]; frames[i].convert_frame.src = &frames[i].src; @@ -594,12 +639,13 @@ static int rx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_rx frames[i].convert_frame.priv = &frames[i]; } - if (trans_ext_frames) mt_rte_free(trans_ext_frames); + if (trans_ext_frames) + mt_rte_free(trans_ext_frames); return 0; } -static int rx_st20p_uinit_dst_fbs(struct st20p_rx_ctx* ctx) { +static int rx_st20p_uinit_dst_fbs(struct st20p_rx_ctx *ctx) { if (ctx->framebuffs) { if (!ctx->derive && !ctx->ops.ext_frames && !(ctx->ops.flags & ST20P_RX_FLAG_EXT_FRAME)) { @@ -624,16 +670,18 @@ static int rx_st20p_uinit_dst_fbs(struct st20p_rx_ctx* ctx) { return 0; } -static int rx_st20p_init_dst_fbs(struct mtl_main_impl* impl, struct st20p_rx_ctx* ctx, - struct st20p_rx_ops* ops) { +static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, + struct st20p_rx_ctx *ctx, + struct st20p_rx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; - struct st20p_rx_frame* frames; - void* dst = NULL; + struct st20p_rx_frame *frames; + void *dst = NULL; size_t dst_size = ctx->dst_size; bool no_dst_malloc = false; - if (ops->flags & ST20P_RX_FLAG_EXT_FRAME || ops->flags & ST20P_RX_FLAG_AUTO_DETECT) { + if (ops->flags & ST20P_RX_FLAG_EXT_FRAME || + ops->flags & ST20P_RX_FLAG_AUTO_DETECT) { no_dst_malloc = true; } @@ -661,7 +709,8 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl* impl, struct st20p_rx_ctx frames[i].dst.iova[plane] = ops->ext_frames[i].iova[plane]; frames[i].dst.linesize[plane] = ops->ext_frames[i].linesize[plane]; } - frames[i].dst.buffer_size = frames[i].dst.data_size = ops->ext_frames[i].size; + frames[i].dst.buffer_size = frames[i].dst.data_size = + ops->ext_frames[i].size; frames[i].dst.opaque = ops->ext_frames[i].opaque; } else if (no_dst_malloc) { for (uint8_t plane = 0; plane < planes; plane++) { @@ -671,8 +720,8 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl* impl, struct st20p_rx_ctx } else { dst = mt_rte_zmalloc_socket(dst_size, soc_id); if (!dst) { - err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", __func__, idx, i, - dst_size); + err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", + __func__, idx, i, dst_size); rx_st20p_uinit_dst_fbs(ctx); return -ENOMEM; } @@ -693,7 +742,8 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl* impl, struct st20p_rx_ctx /* init user meta */ frames[i].user_meta_buffer_size = impl->pkt_udp_suggest_max_size - sizeof(struct st20_rfc4175_rtp_hdr); - frames[i].user_meta = mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); + frames[i].user_meta = + mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); if (!frames[i].user_meta) { err("%s(%d), user_meta malloc %" PRIu64 " fail at %d\n", __func__, idx, frames[i].user_meta_buffer_size, i); @@ -701,13 +751,14 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl* impl, struct st20p_rx_ctx return -ENOMEM; } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, dst_size, - ops->output_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, + dst_size, ops->output_fmt, ctx->framebuff_cnt); return 0; } -static int rx_st20p_get_converter(struct mtl_main_impl* impl, struct st20p_rx_ctx* ctx, - struct st20p_rx_ops* ops) { +static int rx_st20p_get_converter(struct mtl_main_impl *impl, + struct st20p_rx_ctx *ctx, + struct st20p_rx_ops *ops) { int idx = ctx->idx; struct st20_get_converter_request req; @@ -725,16 +776,18 @@ static int rx_st20p_get_converter(struct mtl_main_impl* impl, struct st20p_rx_ct req.put_frame = rx_st20p_convert_put_frame; req.dump = rx_st20p_convert_dump; - struct st20_convert_session_impl* convert_impl = st20_get_converter(impl, &req); + struct st20_convert_session_impl *convert_impl = + st20_get_converter(impl, &req); if (req.device == ST_PLUGIN_DEVICE_TEST_INTERNAL || !convert_impl) { - struct st_frame_converter* converter = NULL; + struct st_frame_converter *converter = NULL; converter = mt_rte_zmalloc_socket(sizeof(*converter), ctx->socket_id); if (!converter) { err("%s, converter malloc fail\n", __func__); return -ENOMEM; } memset(converter, 0, sizeof(*converter)); - if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, converter) < 0) { + if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, + converter) < 0) { err("%s, get converter fail\n", __func__); mt_rte_free(converter); return -EIO; @@ -748,20 +801,22 @@ static int rx_st20p_get_converter(struct mtl_main_impl* impl, struct st20p_rx_ct return 0; } -static int rx_st20p_stat(void* priv) { - struct st20p_rx_ctx* ctx = priv; - struct st20p_rx_frame* framebuff = ctx->framebuffs; +static int rx_st20p_stat(void *priv) { + struct st20p_rx_ctx *ctx = priv; + struct st20p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("RX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, - rx_st20p_stat_name(framebuff[producer_idx].stat), consumer_idx, - rx_st20p_stat_name(framebuff[consumer_idx].stat)); + notice("RX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, + producer_idx, rx_st20p_stat_name(framebuff[producer_idx].stat), + consumer_idx, rx_st20p_stat_name(framebuff[consumer_idx].stat)); notice("RX_st20p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, + ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -769,16 +824,18 @@ static int rx_st20p_stat(void* priv) { return 0; } -static int rx_st20p_usdt_dump_frame(struct st20p_rx_ctx* ctx, struct st_frame* frame) { +static int rx_st20p_usdt_dump_frame(struct st20p_rx_ctx *ctx, + struct st_frame *frame) { int idx = ctx->idx; - struct mtl_main_impl* impl = ctx->impl; + struct mtl_main_impl *impl = ctx->impl; int fd; char usdt_dump_path[64]; - struct st20p_rx_ops* ops = &ctx->ops; + struct st20p_rx_ops *ops = &ctx->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); + "imtl_usdt_st20prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -800,7 +857,7 @@ static int rx_st20p_usdt_dump_frame(struct st20p_rx_ctx* ctx, struct st_frame* f return 0; } -static int st20p_rx_get_block_wait(struct st20p_rx_ctx* ctx) { +static int st20p_rx_get_block_wait(struct st20p_rx_ctx *ctx) { dbg("%s(%d), start\n", __func__, ctx->idx); /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); @@ -811,33 +868,34 @@ static int st20p_rx_get_block_wait(struct st20p_rx_ctx* ctx) { return 0; } -struct st_frame* st20p_rx_get_frame(st20p_rx_handle handle) { - struct st20p_rx_ctx* ctx = handle; +struct st_frame *st20p_rx_get_frame(st20p_rx_handle handle) { + struct st20p_rx_ctx *ctx = handle; int idx = ctx->idx; - struct st20p_rx_frame* framebuff; - struct st_frame* frame; + struct st20p_rx_frame *framebuff; + struct st_frame *frame; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); if (ctx->internal_converter) { /* convert internal */ - framebuff = - rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, ST20P_RX_FRAME_READY); + framebuff = rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, + ST20P_RX_FRAME_READY); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); st20p_rx_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, ST20P_RX_FRAME_READY); + framebuff = rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, + ST20P_RX_FRAME_READY); } /* not any ready frame */ if (!framebuff) { @@ -893,10 +951,10 @@ struct st_frame* st20p_rx_get_frame(st20p_rx_handle handle) { return frame; } -int st20p_rx_put_frame(st20p_rx_handle handle, struct st_frame* frame) { - struct st20p_rx_ctx* ctx = handle; +int st20p_rx_put_frame(st20p_rx_handle handle, struct st_frame *frame) { + struct st20p_rx_ctx *ctx = handle; int idx = ctx->idx; - struct st20p_rx_frame* framebuff = frame->priv; + struct st20p_rx_frame *framebuff = frame->priv; uint16_t consumer_idx = framebuff->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -921,10 +979,10 @@ int st20p_rx_put_frame(st20p_rx_handle handle, struct st_frame* frame) { return 0; } -st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) { +st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops *ops) { static int st20p_rx_idx; - struct mtl_main_impl* impl = mt; - struct st20p_rx_ctx* ctx; + struct mtl_main_impl *impl = mt; + struct st20p_rx_ctx *ctx; int ret; int idx = st20p_rx_idx; size_t dst_size = 0; @@ -939,7 +997,8 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) { if (ops->flags & ST20P_RX_FLAG_EXT_FRAME) { if (!ops->query_ext_frame) { - err("%s, no query_ext_frame query callback for dynamic ext frame mode\n", __func__); + err("%s, no query_ext_frame query callback for dynamic ext frame mode\n", + __func__); return NULL; } } @@ -947,15 +1006,18 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) { if (auto_detect) { info("%s(%d), auto_detect enabled\n", __func__, idx); } else { - dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, ops->interlaced); + dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, + ops->interlaced); if (!dst_size) { err("%s(%d), get dst size fail\n", __func__, idx); return NULL; } } - enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + enum mtl_port port = + mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20P_RX_FLAG_FORCE_NUMA) { @@ -972,8 +1034,10 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) { ctx->idx = idx; ctx->socket_id = socket; ctx->ready = false; - ctx->derive = st_frame_fmt_equal_transport(ops->output_fmt, ops->transport_fmt); - ctx->dynamic_ext_frame = (ops->flags & ST20P_RX_FLAG_EXT_FRAME) ? true : false; + ctx->derive = + st_frame_fmt_equal_transport(ops->output_fmt, ops->transport_fmt); + ctx->dynamic_ext_frame = + (ops->flags & ST20P_RX_FLAG_EXT_FRAME) ? true : false; ctx->impl = impl; ctx->type = MT_ST20_HANDLE_PIPELINE_RX; ctx->dst_size = dst_size; @@ -984,7 +1048,8 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; - if (ops->flags & ST20P_RX_FLAG_BLOCK_GET) ctx->block_get = true; + if (ops->flags & ST20P_RX_FLAG_BLOCK_GET) + ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -1027,7 +1092,8 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) { ops->flags); st20p_rx_idx++; - if (!ctx->block_get) rx_st20p_notify_frame_available(ctx); + if (!ctx->block_get) + rx_st20p_notify_frame_available(ctx); mt_stat_register(impl, rx_st20p_stat, ctx, ctx->ops_name); @@ -1035,8 +1101,8 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops* ops) { } int st20p_rx_free(st20p_rx_handle handle) { - struct st20p_rx_ctx* ctx = handle; - struct mtl_main_impl* impl = ctx->impl; + struct st20p_rx_ctx *ctx = handle; + struct mtl_main_impl *impl = ctx->impl; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); @@ -1074,8 +1140,8 @@ int st20p_rx_free(st20p_rx_handle handle) { return 0; } -void* st20p_rx_get_fb_addr(st20p_rx_handle handle, uint16_t idx) { - struct st20p_rx_ctx* ctx = handle; +void *st20p_rx_get_fb_addr(st20p_rx_handle handle, uint16_t idx) { + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1088,12 +1154,13 @@ void* st20p_rx_get_fb_addr(st20p_rx_handle handle, uint16_t idx) { ctx->framebuff_cnt); return NULL; } - if (ctx->derive) return ctx->framebuffs[idx].src.addr; + if (ctx->derive) + return ctx->framebuffs[idx].src.addr; return ctx->framebuffs[idx].dst.addr; } size_t st20p_rx_frame_size(st20p_rx_handle handle) { - struct st20p_rx_ctx* ctx = handle; + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1104,9 +1171,9 @@ size_t st20p_rx_frame_size(st20p_rx_handle handle) { return ctx->dst_size; } -int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta) { - struct st20p_rx_ctx* ctx = handle; +int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta) { + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1117,8 +1184,9 @@ int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, bool return st20_rx_pcapng_dump(ctx->transport, max_dump_packets, sync, meta); } -int st20p_rx_get_queue_meta(st20p_rx_handle handle, struct st_queue_meta* meta) { - struct st20p_rx_ctx* ctx = handle; +int st20p_rx_get_queue_meta(st20p_rx_handle handle, + struct st_queue_meta *meta) { + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1130,7 +1198,7 @@ int st20p_rx_get_queue_meta(st20p_rx_handle handle, struct st_queue_meta* meta) } int st20p_rx_get_sch_idx(st20p_rx_handle handle) { - struct st20p_rx_ctx* ctx = handle; + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1142,8 +1210,8 @@ int st20p_rx_get_sch_idx(st20p_rx_handle handle) { } int st20p_rx_get_port_stats(st20p_rx_handle handle, enum mtl_session_port port, - struct st20_rx_port_status* stats) { - struct st20p_rx_ctx* ctx = handle; + struct st20_rx_port_status *stats) { + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1154,8 +1222,9 @@ int st20p_rx_get_port_stats(st20p_rx_handle handle, enum mtl_session_port port, return st20_rx_get_port_stats(ctx->transport, port, stats); } -int st20p_rx_reset_port_stats(st20p_rx_handle handle, enum mtl_session_port port) { - struct st20p_rx_ctx* ctx = handle; +int st20p_rx_reset_port_stats(st20p_rx_handle handle, + enum mtl_session_port port) { + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1166,8 +1235,9 @@ int st20p_rx_reset_port_stats(st20p_rx_handle handle, enum mtl_session_port port return st20_rx_reset_port_stats(ctx->transport, port); } -int st20p_rx_update_source(st20p_rx_handle handle, struct st_rx_source_info* src) { - struct st20p_rx_ctx* ctx = handle; +int st20p_rx_update_source(st20p_rx_handle handle, + struct st_rx_source_info *src) { + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1179,8 +1249,8 @@ int st20p_rx_update_source(st20p_rx_handle handle, struct st_rx_source_info* src } int st20p_rx_timing_parser_critical(st20p_rx_handle handle, - struct st20_rx_tp_pass* pass) { - struct st20p_rx_ctx* ctx = handle; + struct st20_rx_tp_pass *pass) { + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1192,7 +1262,7 @@ int st20p_rx_timing_parser_critical(st20p_rx_handle handle, } int st20p_rx_wake_block(st20p_rx_handle handle) { - struct st20p_rx_ctx* ctx = handle; + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { @@ -1200,13 +1270,14 @@ int st20p_rx_wake_block(st20p_rx_handle handle) { return 0; } - if (ctx->block_get) rx_st20p_block_wake(ctx); + if (ctx->block_get) + rx_st20p_block_wake(ctx); return 0; } int st20p_rx_set_block_timeout(st20p_rx_handle handle, uint64_t timedwait_ns) { - struct st20p_rx_ctx* ctx = handle; + struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_RX) { diff --git a/lib/src/st2110/pipeline/st20_pipeline_rx.h b/lib/src/st2110/pipeline/st20_pipeline_rx.h index a691ef7bc..bd21eb806 100644 --- a/lib/src/st2110/pipeline/st20_pipeline_rx.h +++ b/lib/src/st2110/pipeline/st20_pipeline_rx.h @@ -23,14 +23,14 @@ struct st20p_rx_frame { struct st_frame dst; /* converted */ struct st20_convert_frame_meta convert_frame; uint16_t idx; - void* user_meta; /* the user meta data */ + void *user_meta; /* the user meta data */ size_t user_meta_buffer_size; size_t user_meta_data_size; struct st20_rx_tp_meta tp[MTL_SESSION_PORT_MAX]; }; struct st20p_rx_ctx { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; int socket_id; enum mt_handle_type type; /* for sanity check */ @@ -43,7 +43,7 @@ struct st20p_rx_ctx { uint16_t framebuff_producer_idx; uint16_t framebuff_convert_idx; uint16_t framebuff_consumer_idx; - struct st20p_rx_frame* framebuffs; + struct st20p_rx_frame *framebuffs; pthread_mutex_t lock; int usdt_frame_cnt; @@ -53,8 +53,8 @@ struct st20p_rx_ctx { pthread_mutex_t block_wake_mutex; uint64_t block_timeout_ns; - struct st20_convert_session_impl* convert_impl; - struct st_frame_converter* internal_converter; + struct st20_convert_session_impl *convert_impl; + struct st_frame_converter *internal_converter; bool ready; bool derive; bool dynamic_ext_frame; diff --git a/lib/src/st2110/pipeline/st20_pipeline_tx.c b/lib/src/st2110/pipeline/st20_pipeline_tx.c index d14728536..8b30b7a8b 100644 --- a/lib/src/st2110/pipeline/st20_pipeline_tx.c +++ b/lib/src/st2110/pipeline/st20_pipeline_tx.c @@ -7,35 +7,37 @@ #include "../../mt_log.h" #include "../../mt_stat.h" -static const char* st20p_tx_frame_stat_name[ST20P_TX_FRAME_STATUS_MAX] = { +static const char *st20p_tx_frame_stat_name[ST20P_TX_FRAME_STATUS_MAX] = { "free", "ready", "in_converting", "converted", "in_user", "in_transmitting", }; -static const char* tx_st20p_stat_name(enum st20p_tx_frame_status stat) { +static const char *tx_st20p_stat_name(enum st20p_tx_frame_status stat) { return st20p_tx_frame_stat_name[stat]; } -static uint16_t tx_st20p_next_idx(struct st20p_tx_ctx* ctx, uint16_t idx) { +static uint16_t tx_st20p_next_idx(struct st20p_tx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) + next_idx = 0; return next_idx; } -static inline struct st_frame* tx_st20p_user_frame(struct st20p_tx_ctx* ctx, - struct st20p_tx_frame* framebuff) { +static inline struct st_frame * +tx_st20p_user_frame(struct st20p_tx_ctx *ctx, + struct st20p_tx_frame *framebuff) { return ctx->derive ? &framebuff->dst : &framebuff->src; } -static void tx_st20p_block_wake(struct st20p_tx_ctx* ctx) { +static void tx_st20p_block_wake(struct st20p_tx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); mt_pthread_cond_signal(&ctx->block_wake_cond); mt_pthread_mutex_unlock(&ctx->block_wake_mutex); } -static void tx_st20p_notify_frame_available(struct st20p_tx_ctx* ctx) { +static void tx_st20p_notify_frame_available(struct st20p_tx_ctx *ctx) { if (ctx->ops.notify_frame_available) { /* notify app */ ctx->ops.notify_frame_available(ctx->ops.priv); } @@ -46,10 +48,11 @@ static void tx_st20p_notify_frame_available(struct st20p_tx_ctx* ctx) { } } -static struct st20p_tx_frame* tx_st20p_next_available( - struct st20p_tx_ctx* ctx, uint16_t idx_start, enum st20p_tx_frame_status desired) { +static struct st20p_tx_frame * +tx_st20p_next_available(struct st20p_tx_ctx *ctx, uint16_t idx_start, + enum st20p_tx_frame_status desired) { uint16_t idx = idx_start; - struct st20p_tx_frame* framebuff; + struct st20p_tx_frame *framebuff; /* check ready frame from idx_start */ while (1) { @@ -69,16 +72,17 @@ static struct st20p_tx_frame* tx_st20p_next_available( return NULL; } -static int tx_st20p_next_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - struct st20p_tx_ctx* ctx = priv; - struct st20p_tx_frame* framebuff; +static int tx_st20p_next_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + struct st20p_tx_ctx *ctx = priv; + struct st20p_tx_frame *framebuff; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, ST20P_TX_FRAME_CONVERTED); + framebuff = tx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, + ST20P_TX_FRAME_CONVERTED); /* not any converted frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -88,9 +92,10 @@ static int tx_st20p_next_frame(void* priv, uint16_t* next_frame_idx, framebuff->stat = ST20P_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = framebuff->idx; - struct st_frame* frame = tx_st20p_user_frame(ctx, framebuff); + struct st_frame *frame = tx_st20p_user_frame(ctx, framebuff); meta->second_field = frame->second_field; - if (ctx->ops.flags & (ST20P_TX_FLAG_USER_PACING | ST20P_TX_FLAG_USER_TIMESTAMP)) { + if (ctx->ops.flags & + (ST20P_TX_FLAG_USER_PACING | ST20P_TX_FLAG_USER_TIMESTAMP)) { meta->tfmt = frame->tfmt; meta->timestamp = frame->timestamp; } @@ -106,11 +111,11 @@ static int tx_st20p_next_frame(void* priv, uint16_t* next_frame_idx, return 0; } -static int tx_st20p_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - struct st20p_tx_ctx* ctx = priv; +static int tx_st20p_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + struct st20p_tx_ctx *ctx = priv; int ret; - struct st20p_tx_frame* framebuff = &ctx->framebuffs[frame_idx]; + struct st20p_tx_frame *framebuff = &ctx->framebuffs[frame_idx]; mt_pthread_mutex_lock(&ctx->lock); if (ST20P_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { @@ -119,12 +124,12 @@ static int tx_st20p_frame_done(void* priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, ctx->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, + framebuff->stat, frame_idx); } mt_pthread_mutex_unlock(&ctx->lock); - struct st_frame* frame = tx_st20p_user_frame(ctx, framebuff); + struct st_frame *frame = tx_st20p_user_frame(ctx, framebuff); frame->tfmt = meta->tfmt; frame->timestamp = meta->timestamp; frame->epoch = meta->epoch; @@ -142,8 +147,8 @@ static int tx_st20p_frame_done(void* priv, uint16_t frame_idx, return ret; } -static int tx_st20p_notify_event(void* priv, enum st_event event, void* args) { - struct st20p_tx_ctx* ctx = priv; +static int tx_st20p_notify_event(void *priv, enum st_event event, void *args) { + struct st20p_tx_ctx *ctx = priv; if (ctx->ops.notify_event) { ctx->ops.notify_event(ctx->ops.priv, event, args); @@ -152,21 +157,22 @@ static int tx_st20p_notify_event(void* priv, enum st_event event, void* args) { return 0; } -static struct st20_convert_frame_meta* tx_st20p_convert_get_frame(void* priv) { - struct st20p_tx_ctx* ctx = priv; +static struct st20_convert_frame_meta *tx_st20p_convert_get_frame(void *priv) { + struct st20p_tx_ctx *ctx = priv; int idx = ctx->idx; - struct st20p_tx_frame* framebuff; + struct st20p_tx_frame *framebuff; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st20p_next_available(ctx, ctx->framebuff_convert_idx, ST20P_TX_FRAME_READY); + framebuff = tx_st20p_next_available(ctx, ctx->framebuff_convert_idx, + ST20P_TX_FRAME_READY); /* not any free frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -182,11 +188,12 @@ static struct st20_convert_frame_meta* tx_st20p_convert_get_frame(void* priv) { return &framebuff->convert_frame; } -static int tx_st20p_convert_put_frame(void* priv, struct st20_convert_frame_meta* frame, +static int tx_st20p_convert_put_frame(void *priv, + struct st20_convert_frame_meta *frame, int result) { - struct st20p_tx_ctx* ctx = priv; + struct st20p_tx_ctx *ctx = priv; int idx = ctx->idx; - struct st20p_tx_frame* framebuff = frame->priv; + struct st20p_tx_frame *framebuff = frame->priv; uint16_t convert_idx = framebuff->idx; size_t data_size = frame->dst->data_size; @@ -202,8 +209,8 @@ static int tx_st20p_convert_put_frame(void* priv, struct st20_convert_frame_meta } if ((result < 0) || (data_size <= 0)) { - dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, convert_idx, - result, data_size); + dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, + convert_idx, result, data_size); framebuff->stat = ST20P_TX_FRAME_FREE; /* notify app can get frame */ tx_st20p_notify_frame_available(ctx); @@ -215,11 +222,12 @@ static int tx_st20p_convert_put_frame(void* priv, struct st20_convert_frame_meta return 0; } -static int tx_st20p_convert_dump(void* priv) { - struct st20p_tx_ctx* ctx = priv; - struct st20p_tx_frame* framebuff = ctx->framebuffs; +static int tx_st20p_convert_dump(void *priv) { + struct st20p_tx_ctx *ctx = priv; + struct st20p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t convert_idx = ctx->framebuff_convert_idx; notice("TX_st20p(%s), cv(%d:%s)\n", ctx->ops_name, convert_idx, @@ -240,8 +248,9 @@ static int tx_st20p_convert_dump(void* priv) { return 0; } -static int tx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_tx_ctx* ctx, - struct st20p_tx_ops* ops) { +static int tx_st20p_create_transport(struct mtl_main_impl *impl, + struct st20p_tx_ctx *ctx, + struct st20p_tx_ops *ops) { int idx = ctx->idx; struct st20_tx_ops ops_tx; st20_tx_handle transport; @@ -288,10 +297,12 @@ static int tx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_tx ops_tx.notify_event = tx_st20p_notify_event; if (ctx->derive && ops->flags & ST20P_TX_FLAG_EXT_FRAME) ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; - if (ops->flags & ST20P_TX_FLAG_USER_PACING) ops_tx.flags |= ST20_TX_FLAG_USER_PACING; + if (ops->flags & ST20P_TX_FLAG_USER_PACING) + ops_tx.flags |= ST20_TX_FLAG_USER_PACING; if (ops->flags & ST20P_TX_FLAG_USER_TIMESTAMP) ops_tx.flags |= ST20_TX_FLAG_USER_TIMESTAMP; - if (ops->flags & ST20P_TX_FLAG_ENABLE_VSYNC) ops_tx.flags |= ST20_TX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST20P_TX_FLAG_ENABLE_VSYNC) + ops_tx.flags |= ST20_TX_FLAG_ENABLE_VSYNC; if (ops->flags & ST20P_TX_FLAG_DISABLE_STATIC_PAD_P) ops_tx.flags |= ST20_TX_FLAG_DISABLE_STATIC_PAD_P; if (ops->flags & ST20P_TX_FLAG_ENABLE_RTCP) { @@ -302,7 +313,8 @@ static int tx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_tx ops_tx.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; if (ops->flags & ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH) ops_tx.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH; - if (ops->flags & ST20P_TX_FLAG_DISABLE_BULK) ops_tx.flags |= ST20_TX_FLAG_DISABLE_BULK; + if (ops->flags & ST20P_TX_FLAG_DISABLE_BULK) + ops_tx.flags |= ST20_TX_FLAG_DISABLE_BULK; if (ops->flags & ST20P_TX_FLAG_FORCE_NUMA) { ops_tx.socket_id = ops->socket_id; ops_tx.flags |= ST20_TX_FLAG_FORCE_NUMA; @@ -315,7 +327,7 @@ static int tx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_tx } ctx->transport = transport; - struct st20p_tx_frame* frames = ctx->framebuffs; + struct st20p_tx_frame *frames = ctx->framebuffs; for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { if (ctx->derive && ops->flags & ST20P_TX_FLAG_EXT_FRAME) { frames[i].dst.addr[0] = NULL; @@ -324,14 +336,15 @@ static int tx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_tx } frames[i].dst.fmt = st_frame_fmt_from_transport(ctx->ops.transport_fmt); frames[i].dst.interlaced = ops->interlaced; - frames[i].dst.buffer_size = - st_frame_size(frames[i].dst.fmt, ops->width, ops->height, ops->interlaced); + frames[i].dst.buffer_size = st_frame_size(frames[i].dst.fmt, ops->width, + ops->height, ops->interlaced); frames[i].dst.data_size = frames[i].dst.buffer_size; frames[i].dst.width = ops->width; frames[i].dst.height = ops->height; frames[i].dst.linesize[0] = /* rfc4175 uses packed format */ - RTE_MAX(ops->transport_linesize, - st_frame_least_linesize(frames[i].dst.fmt, frames[i].dst.width, 0)); + RTE_MAX( + ops->transport_linesize, + st_frame_least_linesize(frames[i].dst.fmt, frames[i].dst.width, 0)); frames[i].dst.priv = &frames[i]; frames[i].convert_frame.src = &frames[i].src; @@ -342,7 +355,7 @@ static int tx_st20p_create_transport(struct mtl_main_impl* impl, struct st20p_tx return 0; } -static int tx_st20p_uinit_src_fbs(struct st20p_tx_ctx* ctx) { +static int tx_st20p_uinit_src_fbs(struct st20p_tx_ctx *ctx) { if (ctx->framebuffs) { if (!ctx->derive && !(ctx->ops.flags & ST20P_TX_FLAG_EXT_FRAME)) { /* do not free derived/ext frames */ @@ -370,12 +383,13 @@ static int tx_st20p_uinit_src_fbs(struct st20p_tx_ctx* ctx) { return 0; } -static int tx_st20p_init_src_fbs(struct mtl_main_impl* impl, struct st20p_tx_ctx* ctx, - struct st20p_tx_ops* ops) { +static int tx_st20p_init_src_fbs(struct mtl_main_impl *impl, + struct st20p_tx_ctx *ctx, + struct st20p_tx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; - struct st20p_tx_frame* frames; - void* src = NULL; + struct st20p_tx_frame *frames; + void *src = NULL; size_t src_size = ctx->src_size; ctx->framebuff_cnt = ops->framebuff_cnt; @@ -424,7 +438,8 @@ static int tx_st20p_init_src_fbs(struct mtl_main_impl* impl, struct st20p_tx_ctx /* init user meta */ frames[i].user_meta_buffer_size = impl->pkt_udp_suggest_max_size - sizeof(struct st20_rfc4175_rtp_hdr); - frames[i].user_meta = mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); + frames[i].user_meta = + mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); if (!frames[i].user_meta) { err("%s(%d), user_meta malloc %" PRIu64 " fail at %d\n", __func__, idx, frames[i].user_meta_buffer_size, i); @@ -432,13 +447,14 @@ static int tx_st20p_init_src_fbs(struct mtl_main_impl* impl, struct st20p_tx_ctx return -ENOMEM; } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, src_size, - ops->transport_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, + src_size, ops->transport_fmt, ctx->framebuff_cnt); return 0; } -static int tx_st20p_get_converter(struct mtl_main_impl* impl, struct st20p_tx_ctx* ctx, - struct st20p_tx_ops* ops) { +static int tx_st20p_get_converter(struct mtl_main_impl *impl, + struct st20p_tx_ctx *ctx, + struct st20p_tx_ops *ops) { int idx = ctx->idx; struct st20_get_converter_request req; @@ -456,16 +472,18 @@ static int tx_st20p_get_converter(struct mtl_main_impl* impl, struct st20p_tx_ct req.put_frame = tx_st20p_convert_put_frame; req.dump = tx_st20p_convert_dump; - struct st20_convert_session_impl* convert_impl = st20_get_converter(impl, &req); + struct st20_convert_session_impl *convert_impl = + st20_get_converter(impl, &req); if (req.device == ST_PLUGIN_DEVICE_TEST_INTERNAL || !convert_impl) { - struct st_frame_converter* converter = NULL; + struct st_frame_converter *converter = NULL; converter = mt_rte_zmalloc_socket(sizeof(*converter), ctx->socket_id); if (!converter) { err("%s, converter malloc fail\n", __func__); return -ENOMEM; } memset(converter, 0, sizeof(*converter)); - if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, converter) < 0) { + if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, + converter) < 0) { err("%s, get converter fail\n", __func__); mt_rte_free(converter); return -EIO; @@ -479,20 +497,22 @@ static int tx_st20p_get_converter(struct mtl_main_impl* impl, struct st20p_tx_ct return 0; } -static int tx_st20p_stat(void* priv) { - struct st20p_tx_ctx* ctx = priv; - struct st20p_tx_frame* framebuff = ctx->framebuffs; +static int tx_st20p_stat(void *priv) { + struct st20p_tx_ctx *ctx = priv; + struct st20p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("TX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, - tx_st20p_stat_name(framebuff[producer_idx].stat), consumer_idx, - tx_st20p_stat_name(framebuff[consumer_idx].stat)); + notice("TX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, + producer_idx, tx_st20p_stat_name(framebuff[producer_idx].stat), + consumer_idx, tx_st20p_stat_name(framebuff[consumer_idx].stat)); notice("TX_st20p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, + ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -500,16 +520,18 @@ static int tx_st20p_stat(void* priv) { return 0; } -static int tx_st20p_usdt_dump_frame(struct st20p_tx_ctx* ctx, struct st_frame* frame) { +static int tx_st20p_usdt_dump_frame(struct st20p_tx_ctx *ctx, + struct st_frame *frame) { int idx = ctx->idx; - struct mtl_main_impl* impl = ctx->impl; + struct mtl_main_impl *impl = ctx->impl; int fd; char usdt_dump_path[64]; - struct st20p_tx_ops* ops = &ctx->ops; + struct st20p_tx_ops *ops = &ctx->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); + "imtl_usdt_st20ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -531,14 +553,15 @@ static int tx_st20p_usdt_dump_frame(struct st20p_tx_ctx* ctx, struct st_frame* f return 0; } -static void tx_st20p_framebuffs_flush(struct st20p_tx_ctx* ctx) { +static void tx_st20p_framebuffs_flush(struct st20p_tx_ctx *ctx) { /* wait all frame are in free or in transmitting(flushed by transport) */ for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { - struct st20p_tx_frame* framebuff = &ctx->framebuffs[i]; + struct st20p_tx_frame *framebuff = &ctx->framebuffs[i]; int retry = 0; while (1) { - if (framebuff->stat == ST20P_TX_FRAME_FREE) break; + if (framebuff->stat == ST20P_TX_FRAME_FREE) + break; if (framebuff->stat == ST20P_TX_FRAME_IN_TRANSMITTING) { /* make sure transport to finish the transmit */ /* WA to use sleep here, todo: add a transport API to query the stat */ @@ -550,8 +573,8 @@ static void tx_st20p_framebuffs_flush(struct st20p_tx_ctx* ctx) { tx_st20p_stat_name(framebuff->stat), retry); retry++; if (retry > 100) { - info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, i, - tx_st20p_stat_name(framebuff->stat), retry); + info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, + i, tx_st20p_stat_name(framebuff->stat), retry); break; } mt_sleep_ms(10); @@ -559,7 +582,7 @@ static void tx_st20p_framebuffs_flush(struct st20p_tx_ctx* ctx) { } } -static int st20p_tx_get_block_wait(struct st20p_tx_ctx* ctx) { +static int st20p_tx_get_block_wait(struct st20p_tx_ctx *ctx) { dbg("%s(%d), start\n", __func__, ctx->idx); /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); @@ -570,30 +593,31 @@ static int st20p_tx_get_block_wait(struct st20p_tx_ctx* ctx) { return 0; } -struct st_frame* st20p_tx_get_frame(st20p_tx_handle handle) { - struct st20p_tx_ctx* ctx = handle; +struct st_frame *st20p_tx_get_frame(st20p_tx_handle handle) { + struct st20p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st20p_tx_frame* framebuff; + struct st20p_tx_frame *framebuff; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_TX_FRAME_FREE); + framebuff = tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, + ST20P_TX_FRAME_FREE); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); st20p_tx_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_TX_FRAME_FREE); + framebuff = tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, + ST20P_TX_FRAME_FREE); } /* not any free frame */ if (!framebuff) { @@ -607,8 +631,9 @@ struct st_frame* st20p_tx_get_frame(st20p_tx_handle handle) { mt_pthread_mutex_unlock(&ctx->lock); dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); - struct st_frame* frame = tx_st20p_user_frame(ctx, framebuff); - if (ctx->ops.interlaced) { /* init second_field but user still can customize */ + struct st_frame *frame = tx_st20p_user_frame(ctx, framebuff); + if (ctx->ops + .interlaced) { /* init second_field but user still can customize */ frame->second_field = ctx->second_field; ctx->second_field = ctx->second_field ? false : true; } @@ -619,10 +644,10 @@ struct st_frame* st20p_tx_get_frame(st20p_tx_handle handle) { return frame; } -int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame* frame) { - struct st20p_tx_ctx* ctx = handle; +int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame *frame) { + struct st20p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st20p_tx_frame* framebuff = frame->priv; + struct st20p_tx_frame *framebuff = frame->priv; uint16_t producer_idx = framebuff->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -637,16 +662,16 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame* frame) { } if (ctx->ops.flags & ST20P_TX_FLAG_EXT_FRAME) { - err("%s(%d), EXT_FRAME flag enabled, use st20p_tx_put_ext_frame instead\n", __func__, - idx); + err("%s(%d), EXT_FRAME flag enabled, use st20p_tx_put_ext_frame instead\n", + __func__, idx); return -EIO; } framebuff->user_meta_data_size = 0; if (frame->user_meta) { if (frame->user_meta_size > framebuff->user_meta_buffer_size) { - err("%s(%d), frame %u user meta size %" PRId64 " too large\n", __func__, idx, - producer_idx, frame->user_meta_size); + err("%s(%d), frame %u user meta size %" PRId64 " too large\n", __func__, + idx, producer_idx, frame->user_meta_size); framebuff->stat = ST20P_TX_FRAME_FREE; return -EIO; } @@ -657,7 +682,8 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame* frame) { } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = + frame->second_field; } if (ctx->internal_converter) { /* convert internal */ @@ -671,7 +697,8 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame* frame) { } ctx->stat_put_frame++; - MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], framebuff->stat); + MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], + framebuff->stat); /* check if dump USDT enabled */ if (MT_USDT_ST20P_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -686,11 +713,11 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame* frame) { return 0; } -int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame* frame, - struct st_ext_frame* ext_frame) { - struct st20p_tx_ctx* ctx = handle; +int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame *frame, + struct st_ext_frame *ext_frame) { + struct st20p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st20p_tx_frame* framebuff = frame->priv; + struct st20p_tx_frame *framebuff = frame->priv; uint16_t producer_idx = framebuff->idx; int ret = 0; @@ -711,7 +738,8 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame* frame, } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = + frame->second_field; } uint8_t planes = st_frame_fmt_planes(framebuff->src.fmt); @@ -722,7 +750,8 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame* frame, trans_ext_frame.buf_len = ext_frame->size; ret = st20_tx_set_ext_frame(ctx->transport, producer_idx, &trans_ext_frame); if (ret < 0) { - err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, producer_idx); + err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, + producer_idx); return -EIO; } framebuff->dst.addr[0] = ext_frame->addr[0]; @@ -757,7 +786,8 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame* frame, } ctx->stat_put_frame++; - MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], framebuff->stat); + MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], + framebuff->stat); /* check if dump USDT enabled */ if (MT_USDT_ST20P_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -773,10 +803,10 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame* frame, return 0; } -st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops* ops) { +st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops *ops) { static int st20p_tx_idx; - struct mtl_main_impl* impl = mt; - struct st20p_tx_ctx* ctx; + struct mtl_main_impl *impl = mt; + struct st20p_tx_ctx *ctx; int ret; int idx = st20p_tx_idx; size_t src_size; @@ -788,14 +818,17 @@ st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops* ops) { return NULL; } - src_size = st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); + src_size = + st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); if (!src_size) { err("%s(%d), get src size fail\n", __func__, idx); return NULL; } - enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + enum mtl_port port = + mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20P_TX_FLAG_FORCE_NUMA) { @@ -812,7 +845,8 @@ st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops* ops) { ctx->idx = idx; ctx->socket_id = socket; ctx->ready = false; - ctx->derive = st_frame_fmt_equal_transport(ops->input_fmt, ops->transport_fmt); + ctx->derive = + st_frame_fmt_equal_transport(ops->input_fmt, ops->transport_fmt); ctx->impl = impl; ctx->type = MT_ST20_HANDLE_PIPELINE_TX; ctx->src_size = src_size; @@ -869,7 +903,8 @@ st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops* ops) { st20p_tx_idx++; /* notify app can get frame */ - if (!ctx->block_get) tx_st20p_notify_frame_available(ctx); + if (!ctx->block_get) + tx_st20p_notify_frame_available(ctx); mt_stat_register(impl, tx_st20p_stat, ctx, ctx->ops_name); @@ -877,8 +912,8 @@ st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops* ops) { } int st20p_tx_free(st20p_tx_handle handle) { - struct st20p_tx_ctx* ctx = handle; - struct mtl_main_impl* impl = ctx->impl; + struct st20p_tx_ctx *ctx = handle; + struct mtl_main_impl *impl = ctx->impl; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); @@ -921,8 +956,8 @@ int st20p_tx_free(st20p_tx_handle handle) { return 0; } -void* st20p_tx_get_fb_addr(st20p_tx_handle handle, uint16_t idx) { - struct st20p_tx_ctx* ctx = handle; +void *st20p_tx_get_fb_addr(st20p_tx_handle handle, uint16_t idx) { + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -945,7 +980,7 @@ void* st20p_tx_get_fb_addr(st20p_tx_handle handle, uint16_t idx) { } size_t st20p_tx_frame_size(st20p_tx_handle handle) { - struct st20p_tx_ctx* ctx = handle; + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -957,7 +992,7 @@ size_t st20p_tx_frame_size(st20p_tx_handle handle) { } int st20p_tx_get_sch_idx(st20p_tx_handle handle) { - struct st20p_tx_ctx* ctx = handle; + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -969,8 +1004,8 @@ int st20p_tx_get_sch_idx(st20p_tx_handle handle) { } int st20p_tx_get_port_stats(st20p_tx_handle handle, enum mtl_session_port port, - struct st20_tx_port_status* stats) { - struct st20p_tx_ctx* ctx = handle; + struct st20_tx_port_status *stats) { + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -981,8 +1016,9 @@ int st20p_tx_get_port_stats(st20p_tx_handle handle, enum mtl_session_port port, return st20_tx_get_port_stats(ctx->transport, port, stats); } -int st20p_tx_reset_port_stats(st20p_tx_handle handle, enum mtl_session_port port) { - struct st20p_tx_ctx* ctx = handle; +int st20p_tx_reset_port_stats(st20p_tx_handle handle, + enum mtl_session_port port) { + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -993,8 +1029,9 @@ int st20p_tx_reset_port_stats(st20p_tx_handle handle, enum mtl_session_port port return st20_tx_reset_port_stats(ctx->transport, port); } -int st20p_tx_update_destination(st20p_tx_handle handle, struct st_tx_dest_info* dst) { - struct st20p_tx_ctx* ctx = handle; +int st20p_tx_update_destination(st20p_tx_handle handle, + struct st_tx_dest_info *dst) { + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -1006,7 +1043,7 @@ int st20p_tx_update_destination(st20p_tx_handle handle, struct st_tx_dest_info* } int st20p_tx_wake_block(st20p_tx_handle handle) { - struct st20p_tx_ctx* ctx = handle; + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { @@ -1014,13 +1051,14 @@ int st20p_tx_wake_block(st20p_tx_handle handle) { return 0; } - if (ctx->block_get) tx_st20p_block_wake(ctx); + if (ctx->block_get) + tx_st20p_block_wake(ctx); return 0; } int st20p_tx_set_block_timeout(st20p_tx_handle handle, uint64_t timedwait_ns) { - struct st20p_tx_ctx* ctx = handle; + struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST20_HANDLE_PIPELINE_TX) { diff --git a/lib/src/st2110/pipeline/st20_pipeline_tx.h b/lib/src/st2110/pipeline/st20_pipeline_tx.h index a55ef8497..cd9591e60 100644 --- a/lib/src/st2110/pipeline/st20_pipeline_tx.h +++ b/lib/src/st2110/pipeline/st20_pipeline_tx.h @@ -24,13 +24,13 @@ struct st20p_tx_frame { struct st_frame dst; /* converted */ struct st20_convert_frame_meta convert_frame; uint16_t idx; - void* user_meta; /* the meta data from user */ + void *user_meta; /* the meta data from user */ size_t user_meta_buffer_size; size_t user_meta_data_size; }; struct st20p_tx_ctx { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; int socket_id; enum mt_handle_type type; /* for sanity check */ @@ -43,12 +43,12 @@ struct st20p_tx_ctx { uint16_t framebuff_producer_idx; uint16_t framebuff_convert_idx; uint16_t framebuff_consumer_idx; - struct st20p_tx_frame* framebuffs; + struct st20p_tx_frame *framebuffs; pthread_mutex_t lock; int usdt_frame_cnt; - struct st20_convert_session_impl* convert_impl; - struct st_frame_converter* internal_converter; + struct st20_convert_session_impl *convert_impl; + struct st_frame_converter *internal_converter; bool ready; bool derive; /* input_fmt == transport_fmt */ diff --git a/lib/src/st2110/pipeline/st22_pipeline_rx.c b/lib/src/st2110/pipeline/st22_pipeline_rx.c index 0c7a9237e..d96aef5b7 100644 --- a/lib/src/st2110/pipeline/st22_pipeline_rx.c +++ b/lib/src/st2110/pipeline/st22_pipeline_rx.c @@ -6,45 +6,48 @@ #include "../../mt_log.h" -static const char* st22p_rx_frame_stat_name[ST22P_RX_FRAME_STATUS_MAX] = { +static const char *st22p_rx_frame_stat_name[ST22P_RX_FRAME_STATUS_MAX] = { "free", "ready", "in_decoding", "decoded", "in_user", }; -static const char* rx_st22p_stat_name(enum st22p_rx_frame_status stat) { +static const char *rx_st22p_stat_name(enum st22p_rx_frame_status stat) { return st22p_rx_frame_stat_name[stat]; } -static uint16_t rx_st22p_next_idx(struct st22p_rx_ctx* ctx, uint16_t idx) { +static uint16_t rx_st22p_next_idx(struct st22p_rx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) + next_idx = 0; return next_idx; } -static void rx_st22p_block_wake(struct st22p_rx_ctx* ctx) { +static void rx_st22p_block_wake(struct st22p_rx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); mt_pthread_cond_signal(&ctx->block_wake_cond); mt_pthread_mutex_unlock(&ctx->block_wake_mutex); } -static void rx_st22p_decode_block_wake(struct st22p_rx_ctx* ctx) { +static void rx_st22p_decode_block_wake(struct st22p_rx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->decode_block_wake_mutex); mt_pthread_cond_signal(&ctx->decode_block_wake_cond); mt_pthread_mutex_unlock(&ctx->decode_block_wake_mutex); } -static void rx_st22p_decode_notify_frame_ready(struct st22p_rx_ctx* ctx) { - if (ctx->derive) return; /* no decoder for derive mode */ +static void rx_st22p_decode_notify_frame_ready(struct st22p_rx_ctx *ctx) { + if (ctx->derive) + return; /* no decoder for derive mode */ - struct st22_decode_session_impl* decoder = ctx->decode_impl; - struct st22_decode_dev_impl* dev_impl = decoder->parent; - struct st22_decoder_dev* dev = &dev_impl->dev; + struct st22_decode_session_impl *decoder = ctx->decode_impl; + struct st22_decode_dev_impl *dev_impl = decoder->parent; + struct st22_decoder_dev *dev = &dev_impl->dev; st22_decode_priv session = decoder->session; - if (dev->notify_frame_available) dev->notify_frame_available(session); + if (dev->notify_frame_available) + dev->notify_frame_available(session); if (ctx->decode_block_get) { /* notify block */ @@ -52,7 +55,7 @@ static void rx_st22p_decode_notify_frame_ready(struct st22p_rx_ctx* ctx) { } } -static void rx_st22p_notify_frame_available(struct st22p_rx_ctx* ctx) { +static void rx_st22p_notify_frame_available(struct st22p_rx_ctx *ctx) { if (ctx->ops.notify_frame_available) { /* notify app */ ctx->ops.notify_frame_available(ctx->ops.priv); } @@ -63,10 +66,11 @@ static void rx_st22p_notify_frame_available(struct st22p_rx_ctx* ctx) { } } -static struct st22p_rx_frame* rx_st22p_next_available( - struct st22p_rx_ctx* ctx, uint16_t idx_start, enum st22p_rx_frame_status desired) { +static struct st22p_rx_frame * +rx_st22p_next_available(struct st22p_rx_ctx *ctx, uint16_t idx_start, + enum st22p_rx_frame_status desired) { uint16_t idx = idx_start; - struct st22p_rx_frame* framebuff; + struct st22p_rx_frame *framebuff; /* check ready frame from idx_start */ while (1) { @@ -86,17 +90,18 @@ static struct st22p_rx_frame* rx_st22p_next_available( return NULL; } -static int rx_st22p_frame_ready(void* priv, void* frame, - struct st22_rx_frame_meta* meta) { - struct st22p_rx_ctx* ctx = priv; - struct st22p_rx_frame* framebuff; +static int rx_st22p_frame_ready(void *priv, void *frame, + struct st22_rx_frame_meta *meta) { + struct st22p_rx_ctx *ctx = priv; + struct st22p_rx_frame *framebuff; int ret; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st22p_next_available(ctx, ctx->framebuff_producer_idx, ST22P_RX_FRAME_FREE); + framebuff = rx_st22p_next_available(ctx, ctx->framebuff_producer_idx, + ST22P_RX_FRAME_FREE); /* not any free frame */ if (!framebuff) { rte_atomic32_inc(&ctx->stat_busy); @@ -104,8 +109,8 @@ static int rx_st22p_frame_ready(void* priv, void* frame, return -EBUSY; } - MT_USDT_ST22P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, meta->rtp_timestamp, - meta->frame_total_size); + MT_USDT_ST22P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, + meta->rtp_timestamp, meta->frame_total_size); if (ctx->ext_frame) { struct st_ext_frame ext_frame; @@ -143,14 +148,16 @@ static int rx_st22p_frame_ready(void* priv, void* frame, framebuff->dst.tfmt = meta->tfmt; /* set dst timestamp to same as src? */ framebuff->dst.timestamp = meta->timestamp; - framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp; + framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = + meta->rtp_timestamp; /* if second field */ - framebuff->dst.second_field = framebuff->src.second_field = meta->second_field; + framebuff->dst.second_field = framebuff->src.second_field = + meta->second_field; framebuff->src.pkts_total = framebuff->dst.pkts_total = meta->pkts_total; - for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; s_port < MTL_SESSION_PORT_MAX; - s_port++) { + for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; + s_port < MTL_SESSION_PORT_MAX; s_port++) { framebuff->src.pkts_recv[s_port] = framebuff->dst.pkts_recv[s_port] = meta->pkts_recv[s_port]; } @@ -176,8 +183,8 @@ static int rx_st22p_frame_ready(void* priv, void* frame, return 0; } -static int rx_st22p_notify_event(void* priv, enum st_event event, void* args) { - struct st22p_rx_ctx* ctx = priv; +static int rx_st22p_notify_event(void *priv, enum st_event event, void *args) { + struct st22p_rx_ctx *ctx = priv; if (ctx->ops.notify_event) { ctx->ops.notify_event(ctx->ops.priv, event, args); @@ -186,7 +193,7 @@ static int rx_st22p_notify_event(void* priv, enum st_event event, void* args) { return 0; } -static int rx_st22p_decode_get_block_wait(struct st22p_rx_ctx* ctx) { +static int rx_st22p_decode_get_block_wait(struct st22p_rx_ctx *ctx) { /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->decode_block_wake_mutex); mt_pthread_cond_timedwait_ns(&ctx->decode_block_wake_cond, @@ -196,23 +203,23 @@ static int rx_st22p_decode_get_block_wait(struct st22p_rx_ctx* ctx) { return 0; } -static int rx_st22p_decode_wake_block(void* priv) { - struct st22p_rx_ctx* ctx = priv; +static int rx_st22p_decode_wake_block(void *priv) { + struct st22p_rx_ctx *ctx = priv; rx_st22p_decode_block_wake(ctx); return 0; } -static int rx_st22p_decode_set_timeout(void* priv, uint64_t timedwait_ns) { - struct st22p_rx_ctx* ctx = priv; +static int rx_st22p_decode_set_timeout(void *priv, uint64_t timedwait_ns) { + struct st22p_rx_ctx *ctx = priv; ctx->decode_block_timeout_ns = timedwait_ns; return 0; } -static struct st22_decode_frame_meta* rx_st22p_decode_get_frame(void* priv) { - struct st22p_rx_ctx* ctx = priv; +static struct st22_decode_frame_meta *rx_st22p_decode_get_frame(void *priv) { + struct st22p_rx_ctx *ctx = priv; int idx = ctx->idx; - struct st22p_rx_frame* framebuff; + struct st22p_rx_frame *framebuff; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); @@ -223,7 +230,8 @@ static struct st22_decode_frame_meta* rx_st22p_decode_get_frame(void* priv) { dbg("%s(%d), not ready %d\n", __func__, idx, ctx->type); if (ctx->decode_block_get) { rx_st22p_decode_get_block_wait(ctx); - if (!ctx->ready) return NULL; + if (!ctx->ready) + return NULL; } return NULL; /* not ready */ } @@ -231,15 +239,15 @@ static struct st22_decode_frame_meta* rx_st22p_decode_get_frame(void* priv) { ctx->stat_decode_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, ST22P_RX_FRAME_READY); + framebuff = rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, + ST22P_RX_FRAME_READY); if (!framebuff && ctx->decode_block_get) { /* wait here for block mode */ mt_pthread_mutex_unlock(&ctx->lock); rx_st22p_decode_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, ST22P_RX_FRAME_READY); + framebuff = rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, + ST22P_RX_FRAME_READY); } /* not any ready frame */ if (!framebuff) { @@ -254,18 +262,19 @@ static struct st22_decode_frame_meta* rx_st22p_decode_get_frame(void* priv) { mt_pthread_mutex_unlock(&ctx->lock); ctx->stat_decode_get_frame_succ++; - struct st22_decode_frame_meta* frame = &framebuff->decode_frame; + struct st22_decode_frame_meta *frame = &framebuff->decode_frame; MT_USDT_ST22P_RX_DECODE_GET(idx, framebuff->idx, frame->src->addr[0], frame->dst->addr[0], frame->src->data_size); dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); return frame; } -static int rx_st22p_decode_put_frame(void* priv, struct st22_decode_frame_meta* frame, +static int rx_st22p_decode_put_frame(void *priv, + struct st22_decode_frame_meta *frame, int result) { - struct st22p_rx_ctx* ctx = priv; + struct st22p_rx_ctx *ctx = priv; int idx = ctx->idx; - struct st22p_rx_frame* framebuff = frame->priv; + struct st22p_rx_frame *framebuff = frame->priv; uint16_t decode_idx = framebuff->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -296,19 +305,20 @@ static int rx_st22p_decode_put_frame(void* priv, struct st22_decode_frame_meta* return 0; } -static int rx_st22p_decode_dump(void* priv) { - struct st22p_rx_ctx* ctx = priv; - struct st22p_rx_frame* framebuff = ctx->framebuffs; +static int rx_st22p_decode_dump(void *priv) { + struct st22p_rx_ctx *ctx = priv; + struct st22p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t decode_idx = ctx->framebuff_decode_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("RX_ST22P(%s), p(%d:%s) d(%d:%s) c(%d:%s)\n", ctx->ops_name, producer_idx, - rx_st22p_stat_name(framebuff[producer_idx].stat), decode_idx, - rx_st22p_stat_name(framebuff[decode_idx].stat), consumer_idx, - rx_st22p_stat_name(framebuff[consumer_idx].stat)); + notice("RX_ST22P(%s), p(%d:%s) d(%d:%s) c(%d:%s)\n", ctx->ops_name, + producer_idx, rx_st22p_stat_name(framebuff[producer_idx].stat), + decode_idx, rx_st22p_stat_name(framebuff[decode_idx].stat), + consumer_idx, rx_st22p_stat_name(framebuff[consumer_idx].stat)); int decode_fail = rte_atomic32_read(&ctx->stat_decode_fail); rte_atomic32_set(&ctx->stat_decode_fail, 0); @@ -323,7 +333,8 @@ static int rx_st22p_decode_dump(void* priv) { } notice("RX_ST22P(%s), frame get try %d succ %d, put %d\n", ctx->ops_name, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, + ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -338,8 +349,9 @@ static int rx_st22p_decode_dump(void* priv) { return 0; } -static int rx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_rx_ctx* ctx, - struct st22p_rx_ops* ops) { +static int rx_st22p_create_transport(struct mtl_main_impl *impl, + struct st22p_rx_ctx *ctx, + struct st22p_rx_ops *ops) { int idx = ctx->idx; struct st22_rx_ops ops_rx; st22_rx_handle transport; @@ -350,13 +362,15 @@ static int rx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_rx ops_rx.num_port = RTE_MIN(ops->port.num_port, MTL_SESSION_PORT_MAX); for (int i = 0; i < ops_rx.num_port; i++) { memcpy(ops_rx.ip_addr[i], ops->port.ip_addr[i], MTL_IP_ADDR_LEN); - memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], MTL_IP_ADDR_LEN); + memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[i], MTL_PORT_MAX_LEN, "%s", ops->port.port[i]); ops_rx.udp_port[i] = ops->port.udp_port[i]; } if (ops->flags & ST22P_RX_FLAG_DATA_PATH_ONLY) ops_rx.flags |= ST22_RX_FLAG_DATA_PATH_ONLY; - if (ops->flags & ST22P_RX_FLAG_ENABLE_VSYNC) ops_rx.flags |= ST22_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22P_RX_FLAG_ENABLE_VSYNC) + ops_rx.flags |= ST22_RX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22P_RX_FLAG_ENABLE_RTCP) { ops_rx.flags |= ST22_RX_FLAG_ENABLE_RTCP; ops_rx.rtcp = ops->rtcp; @@ -390,7 +404,7 @@ static int rx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_rx } ctx->transport = transport; - struct st22p_rx_frame* frames = ctx->framebuffs; + struct st22p_rx_frame *frames = ctx->framebuffs; for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { frames[i].src.fmt = ctx->codestream_fmt; frames[i].src.buffer_size = ops_rx.framebuff_max_size; @@ -408,7 +422,7 @@ static int rx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_rx return 0; } -static int rx_st22p_uinit_dst_fbs(struct st22p_rx_ctx* ctx) { +static int rx_st22p_uinit_dst_fbs(struct st22p_rx_ctx *ctx) { if (ctx->framebuffs) { if (!ctx->derive && !ctx->ext_frame) { for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { @@ -425,11 +439,12 @@ static int rx_st22p_uinit_dst_fbs(struct st22p_rx_ctx* ctx) { return 0; } -static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx* ctx, struct st22p_rx_ops* ops) { +static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx *ctx, + struct st22p_rx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; - struct st22p_rx_frame* frames; - void* dst; + struct st22p_rx_frame *frames; + void *dst; size_t dst_size = ctx->dst_size; ctx->framebuff_cnt = ops->framebuff_cnt; @@ -451,7 +466,8 @@ static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx* ctx, struct st22p_rx_ops* frames[i].dst.height = ops->height; frames[i].dst.priv = &frames[i]; - if (ctx->derive) continue; /* skip the plane init */ + if (ctx->derive) + continue; /* skip the plane init */ if (ctx->ext_frame) { /* will use ext frame from user */ uint8_t planes = st_frame_fmt_planes(frames[i].dst.fmt); @@ -480,13 +496,14 @@ static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx* ctx, struct st22p_rx_ops* } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, dst_size, - ops->output_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, + dst_size, ops->output_fmt, ctx->framebuff_cnt); return 0; } -static int rx_st22p_get_decoder(struct mtl_main_impl* impl, struct st22p_rx_ctx* ctx, - struct st22p_rx_ops* ops) { +static int rx_st22p_get_decoder(struct mtl_main_impl *impl, + struct st22p_rx_ctx *ctx, + struct st22p_rx_ops *ops) { int idx = ctx->idx; struct st22_get_decoder_request req; @@ -508,7 +525,7 @@ static int rx_st22p_get_decoder(struct mtl_main_impl* impl, struct st22p_rx_ctx* req.put_frame = rx_st22p_decode_put_frame; req.dump = rx_st22p_decode_dump; - struct st22_decode_session_impl* decode_impl = st22_get_decoder(impl, &req); + struct st22_decode_session_impl *decode_impl = st22_get_decoder(impl, &req); if (!decode_impl) { err("%s(%d), get decoder fail\n", __func__, idx); return -EINVAL; @@ -524,7 +541,7 @@ static int rx_st22p_get_decoder(struct mtl_main_impl* impl, struct st22p_rx_ctx* return 0; } -static int rx_st22p_get_block_wait(struct st22p_rx_ctx* ctx) { +static int rx_st22p_get_block_wait(struct st22p_rx_ctx *ctx) { dbg("%s(%d), start\n", __func__, ctx->idx); /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); @@ -535,16 +552,18 @@ static int rx_st22p_get_block_wait(struct st22p_rx_ctx* ctx) { return 0; } -static int rx_st22p_usdt_dump_frame(struct st22p_rx_ctx* ctx, struct st_frame* frame) { +static int rx_st22p_usdt_dump_frame(struct st22p_rx_ctx *ctx, + struct st_frame *frame) { int idx = ctx->idx; - struct mtl_main_impl* impl = ctx->impl; + struct mtl_main_impl *impl = ctx->impl; int fd; char usdt_dump_path[64]; - struct st22p_rx_ops* ops = &ctx->ops; + struct st22p_rx_ops *ops = &ctx->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); + "imtl_usdt_st22prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -566,30 +585,31 @@ static int rx_st22p_usdt_dump_frame(struct st22p_rx_ctx* ctx, struct st_frame* f return 0; } -struct st_frame* st22p_rx_get_frame(st22p_rx_handle handle) { - struct st22p_rx_ctx* ctx = handle; +struct st_frame *st22p_rx_get_frame(st22p_rx_handle handle) { + struct st22p_rx_ctx *ctx = handle; int idx = ctx->idx; - struct st22p_rx_frame* framebuff; + struct st22p_rx_frame *framebuff; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, ST22P_RX_FRAME_DECODED); + framebuff = rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, + ST22P_RX_FRAME_DECODED); if (!framebuff && ctx->block_get) { mt_pthread_mutex_unlock(&ctx->lock); rx_st22p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, ST22P_RX_FRAME_DECODED); + framebuff = rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, + ST22P_RX_FRAME_DECODED); } /* not any decoded frame */ if (!framebuff) { @@ -604,8 +624,9 @@ struct st_frame* st22p_rx_get_frame(st22p_rx_handle handle) { dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); ctx->stat_get_frame_succ++; - struct st_frame* frame = &framebuff->dst; - MT_USDT_ST22P_RX_FRAME_GET(idx, framebuff->idx, frame->addr[0], frame->data_size); + struct st_frame *frame = &framebuff->dst; + MT_USDT_ST22P_RX_FRAME_GET(idx, framebuff->idx, frame->addr[0], + frame->data_size); /* check if dump USDT enabled */ if (!ctx->derive && MT_USDT_ST22P_RX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -619,10 +640,10 @@ struct st_frame* st22p_rx_get_frame(st22p_rx_handle handle) { return frame; } -int st22p_rx_put_frame(st22p_rx_handle handle, struct st_frame* frame) { - struct st22p_rx_ctx* ctx = handle; +int st22p_rx_put_frame(st22p_rx_handle handle, struct st_frame *frame) { + struct st22p_rx_ctx *ctx = handle; int idx = ctx->idx; - struct st22p_rx_frame* framebuff = frame->priv; + struct st22p_rx_frame *framebuff = frame->priv; uint16_t consumer_idx = framebuff->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -646,10 +667,10 @@ int st22p_rx_put_frame(st22p_rx_handle handle, struct st_frame* frame) { return 0; } -st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops) { +st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops) { static int st22p_rx_idx; - struct mtl_main_impl* impl = mt; - struct st22p_rx_ctx* ctx; + struct mtl_main_impl *impl = mt; + struct st22p_rx_ctx *ctx; int ret; int idx = st22p_rx_idx; size_t dst_size; @@ -664,7 +685,8 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops) { if (ops->flags & ST22P_RX_FLAG_EXT_FRAME) { if (!ops->query_ext_frame) { - err("%s, no query_ext_frame query callback for ext frame mode\n", __func__); + err("%s, no query_ext_frame query callback for ext frame mode\n", + __func__); return NULL; } } @@ -675,8 +697,10 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops) { return NULL; } - enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + enum mtl_port port = + mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22P_RX_FLAG_FORCE_NUMA) { @@ -698,7 +722,8 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops) { if (ctx->derive) { dst_size = 0; } else { - dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, ops->interlaced); + dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, + ops->interlaced); if (!dst_size) { err("%s(%d), get dst size fail\n", __func__, idx); return NULL; @@ -714,9 +739,11 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops) { ctx->dst_size = dst_size; /* use the possible max size */ ctx->max_codestream_size = ops->max_codestream_size; - if (!ctx->max_codestream_size) ctx->max_codestream_size = dst_size; + if (!ctx->max_codestream_size) + ctx->max_codestream_size = dst_size; if (ctx->derive && !ctx->max_codestream_size) { - warn("%s(%d), codestream_size is not set by user in derive mode, use default 1M\n", + warn("%s(%d), codestream_size is not set by user in derive mode, use " + "default 1M\n", __func__, idx); ctx->max_codestream_size = 0x100000; } @@ -731,7 +758,8 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; - if (ops->flags & ST22P_RX_FLAG_BLOCK_GET) ctx->block_get = true; + if (ops->flags & ST22P_RX_FLAG_BLOCK_GET) + ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -769,19 +797,20 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops* ops) { /* all ready now */ ctx->ready = true; - notice("%s(%d), codestream fmt %s, output fmt: %s, flags 0x%x\n", __func__, idx, - st_frame_fmt_name(ctx->codestream_fmt), st_frame_fmt_name(ops->output_fmt), - ops->flags); + notice("%s(%d), codestream fmt %s, output fmt: %s, flags 0x%x\n", __func__, + idx, st_frame_fmt_name(ctx->codestream_fmt), + st_frame_fmt_name(ops->output_fmt), ops->flags); st22p_rx_idx++; - if (!ctx->block_get) rx_st22p_notify_frame_available(ctx); + if (!ctx->block_get) + rx_st22p_notify_frame_available(ctx); return ctx; } int st22p_rx_free(st22p_rx_handle handle) { - struct st22p_rx_ctx* ctx = handle; - struct mtl_main_impl* impl = ctx->impl; + struct st22p_rx_ctx *ctx = handle; + struct mtl_main_impl *impl = ctx->impl; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); @@ -809,8 +838,8 @@ int st22p_rx_free(st22p_rx_handle handle) { return 0; } -void* st22p_rx_get_fb_addr(st22p_rx_handle handle, uint16_t idx) { - struct st22p_rx_ctx* ctx = handle; +void *st22p_rx_get_fb_addr(st22p_rx_handle handle, uint16_t idx) { + struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -833,7 +862,7 @@ void* st22p_rx_get_fb_addr(st22p_rx_handle handle, uint16_t idx) { } size_t st22p_rx_frame_size(st22p_rx_handle handle) { - struct st22p_rx_ctx* ctx = handle; + struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -847,8 +876,9 @@ size_t st22p_rx_frame_size(st22p_rx_handle handle) { return ctx->dst_size; } -int st22p_rx_get_queue_meta(st22p_rx_handle handle, struct st_queue_meta* meta) { - struct st22p_rx_ctx* ctx = handle; +int st22p_rx_get_queue_meta(st22p_rx_handle handle, + struct st_queue_meta *meta) { + struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -859,9 +889,9 @@ int st22p_rx_get_queue_meta(st22p_rx_handle handle, struct st_queue_meta* meta) return st22_rx_get_queue_meta(ctx->transport, meta); } -int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta) { - struct st22p_rx_ctx* ctx = handle; +int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta) { + struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -872,8 +902,9 @@ int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, bool return st22_rx_pcapng_dump(ctx->transport, max_dump_packets, sync, meta); } -int st22p_rx_update_source(st22p_rx_handle handle, struct st_rx_source_info* src) { - struct st22p_rx_ctx* ctx = handle; +int st22p_rx_update_source(st22p_rx_handle handle, + struct st_rx_source_info *src) { + struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -885,7 +916,7 @@ int st22p_rx_update_source(st22p_rx_handle handle, struct st_rx_source_info* src } int st22p_rx_wake_block(st22p_rx_handle handle) { - struct st22p_rx_ctx* ctx = handle; + struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { @@ -893,13 +924,14 @@ int st22p_rx_wake_block(st22p_rx_handle handle) { return 0; } - if (ctx->block_get) rx_st22p_block_wake(ctx); + if (ctx->block_get) + rx_st22p_block_wake(ctx); return 0; } int st22p_rx_set_block_timeout(st22p_rx_handle handle, uint64_t timedwait_ns) { - struct st22p_rx_ctx* ctx = handle; + struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_RX) { diff --git a/lib/src/st2110/pipeline/st22_pipeline_rx.h b/lib/src/st2110/pipeline/st22_pipeline_rx.h index a248ce4f1..b64867653 100644 --- a/lib/src/st2110/pipeline/st22_pipeline_rx.h +++ b/lib/src/st2110/pipeline/st22_pipeline_rx.h @@ -26,7 +26,7 @@ struct st22p_rx_frame { }; struct st22p_rx_ctx { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; int socket_id; enum mt_handle_type type; /* for sanity check */ @@ -40,7 +40,7 @@ struct st22p_rx_ctx { uint16_t framebuff_producer_idx; uint16_t framebuff_decode_idx; uint16_t framebuff_consumer_idx; - struct st22p_rx_frame* framebuffs; + struct st22p_rx_frame *framebuffs; pthread_mutex_t lock; /* for ST22P_RX_FLAG_BLOCK_GET */ @@ -49,7 +49,7 @@ struct st22p_rx_ctx { pthread_mutex_t block_wake_mutex; uint64_t block_timeout_ns; - struct st22_decode_session_impl* decode_impl; + struct st22_decode_session_impl *decode_impl; /* for ST22_DECODER_RESP_FLAG_BLOCK_GET */ bool decode_block_get; pthread_cond_t decode_block_wake_cond; diff --git a/lib/src/st2110/pipeline/st22_pipeline_tx.c b/lib/src/st2110/pipeline/st22_pipeline_tx.c index 866bfad7d..8840d5482 100644 --- a/lib/src/st2110/pipeline/st22_pipeline_tx.c +++ b/lib/src/st2110/pipeline/st22_pipeline_tx.c @@ -6,35 +6,37 @@ #include "../../mt_log.h" -static const char* st22p_tx_frame_stat_name[ST22P_TX_FRAME_STATUS_MAX] = { +static const char *st22p_tx_frame_stat_name[ST22P_TX_FRAME_STATUS_MAX] = { "free", "in_user", "ready", "in_encoding", "encoded", "in_trans", }; -static const char* tx_st22p_stat_name(enum st22p_tx_frame_status stat) { +static const char *tx_st22p_stat_name(enum st22p_tx_frame_status stat) { return st22p_tx_frame_stat_name[stat]; } -static inline struct st_frame* tx_st22p_user_frame(struct st22p_tx_ctx* ctx, - struct st22p_tx_frame* framebuff) { +static inline struct st_frame * +tx_st22p_user_frame(struct st22p_tx_ctx *ctx, + struct st22p_tx_frame *framebuff) { return ctx->derive ? &framebuff->dst : &framebuff->src; } -static uint16_t tx_st22p_next_idx(struct st22p_tx_ctx* ctx, uint16_t idx) { +static uint16_t tx_st22p_next_idx(struct st22p_tx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) + next_idx = 0; return next_idx; } -static void tx_st22p_block_wake(struct st22p_tx_ctx* ctx) { +static void tx_st22p_block_wake(struct st22p_tx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); mt_pthread_cond_signal(&ctx->block_wake_cond); mt_pthread_mutex_unlock(&ctx->block_wake_mutex); } -static void tx_st22p_notify_frame_available(struct st22p_tx_ctx* ctx) { +static void tx_st22p_notify_frame_available(struct st22p_tx_ctx *ctx) { if (ctx->ops.notify_frame_available) { /* notify app */ ctx->ops.notify_frame_available(ctx->ops.priv); } @@ -45,22 +47,24 @@ static void tx_st22p_notify_frame_available(struct st22p_tx_ctx* ctx) { } } -static void tx_st22p_encode_block_wake(struct st22p_tx_ctx* ctx) { +static void tx_st22p_encode_block_wake(struct st22p_tx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->encode_block_wake_mutex); mt_pthread_cond_signal(&ctx->encode_block_wake_cond); mt_pthread_mutex_unlock(&ctx->encode_block_wake_mutex); } -static void tx_st22p_encode_notify_frame_ready(struct st22p_tx_ctx* ctx) { - if (ctx->derive) return; /* no encoder for derive mode */ +static void tx_st22p_encode_notify_frame_ready(struct st22p_tx_ctx *ctx) { + if (ctx->derive) + return; /* no encoder for derive mode */ - struct st22_encode_session_impl* encoder = ctx->encode_impl; - struct st22_encode_dev_impl* dev_impl = encoder->parent; - struct st22_encoder_dev* dev = &dev_impl->dev; + struct st22_encode_session_impl *encoder = ctx->encode_impl; + struct st22_encode_dev_impl *dev_impl = encoder->parent; + struct st22_encoder_dev *dev = &dev_impl->dev; st22_encode_priv session = encoder->session; - if (dev->notify_frame_available) dev->notify_frame_available(session); + if (dev->notify_frame_available) + dev->notify_frame_available(session); if (ctx->encode_block_get) { /* notify block */ @@ -68,10 +72,11 @@ static void tx_st22p_encode_notify_frame_ready(struct st22p_tx_ctx* ctx) { } } -static struct st22p_tx_frame* tx_st22p_next_available( - struct st22p_tx_ctx* ctx, uint16_t idx_start, enum st22p_tx_frame_status desired) { +static struct st22p_tx_frame * +tx_st22p_next_available(struct st22p_tx_ctx *ctx, uint16_t idx_start, + enum st22p_tx_frame_status desired) { uint16_t idx = idx_start; - struct st22p_tx_frame* framebuff; + struct st22p_tx_frame *framebuff; /* check ready frame from idx_start */ while (1) { @@ -91,16 +96,17 @@ static struct st22p_tx_frame* tx_st22p_next_available( return NULL; } -static int tx_st22p_next_frame(void* priv, uint16_t* next_frame_idx, - struct st22_tx_frame_meta* meta) { - struct st22p_tx_ctx* ctx = priv; - struct st22p_tx_frame* framebuff; +static int tx_st22p_next_frame(void *priv, uint16_t *next_frame_idx, + struct st22_tx_frame_meta *meta) { + struct st22p_tx_ctx *ctx = priv; + struct st22p_tx_frame *framebuff; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, ST22P_TX_FRAME_ENCODED); + framebuff = tx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, + ST22P_TX_FRAME_ENCODED); /* not any encoded frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -110,9 +116,10 @@ static int tx_st22p_next_frame(void* priv, uint16_t* next_frame_idx, framebuff->stat = ST22P_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = framebuff->idx; - struct st_frame* frame = tx_st22p_user_frame(ctx, framebuff); + struct st_frame *frame = tx_st22p_user_frame(ctx, framebuff); meta->second_field = frame->second_field; - if (ctx->ops.flags & (ST22P_TX_FLAG_USER_PACING | ST22P_TX_FLAG_USER_TIMESTAMP)) { + if (ctx->ops.flags & + (ST22P_TX_FLAG_USER_PACING | ST22P_TX_FLAG_USER_TIMESTAMP)) { meta->tfmt = frame->tfmt; meta->timestamp = frame->timestamp; dbg("%s(%d), frame %u succ timestamp %" PRIu64 "\n", __func__, ctx->idx, @@ -127,11 +134,11 @@ static int tx_st22p_next_frame(void* priv, uint16_t* next_frame_idx, return 0; } -static int tx_st22p_frame_done(void* priv, uint16_t frame_idx, - struct st22_tx_frame_meta* meta) { - struct st22p_tx_ctx* ctx = priv; +static int tx_st22p_frame_done(void *priv, uint16_t frame_idx, + struct st22_tx_frame_meta *meta) { + struct st22p_tx_ctx *ctx = priv; int ret; - struct st22p_tx_frame* framebuff = &ctx->framebuffs[frame_idx]; + struct st22p_tx_frame *framebuff = &ctx->framebuffs[frame_idx]; mt_pthread_mutex_lock(&ctx->lock); if (ST22P_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { @@ -140,8 +147,8 @@ static int tx_st22p_frame_done(void* priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, ctx->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, + framebuff->stat, frame_idx); } mt_pthread_mutex_unlock(&ctx->lock); @@ -149,10 +156,11 @@ static int tx_st22p_frame_done(void* priv, uint16_t frame_idx, framebuff->dst.tfmt = meta->tfmt; framebuff->src.timestamp = meta->timestamp; framebuff->dst.timestamp = meta->timestamp; - framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp; + framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = + meta->rtp_timestamp; if (ctx->ops.notify_frame_done) { /* notify app which frame done */ - struct st_frame* frame = tx_st22p_user_frame(ctx, framebuff); + struct st_frame *frame = tx_st22p_user_frame(ctx, framebuff); ctx->ops.notify_frame_done(ctx->ops.priv, frame); } @@ -163,8 +171,8 @@ static int tx_st22p_frame_done(void* priv, uint16_t frame_idx, return ret; } -static int tx_st22p_notify_event(void* priv, enum st_event event, void* args) { - struct st22p_tx_ctx* ctx = priv; +static int tx_st22p_notify_event(void *priv, enum st_event event, void *args) { + struct st22p_tx_ctx *ctx = priv; if (ctx->ops.notify_event) { ctx->ops.notify_event(ctx->ops.priv, event, args); @@ -173,7 +181,7 @@ static int tx_st22p_notify_event(void* priv, enum st_event event, void* args) { return 0; } -static int tx_st22p_encode_get_block_wait(struct st22p_tx_ctx* ctx) { +static int tx_st22p_encode_get_block_wait(struct st22p_tx_ctx *ctx) { /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->encode_block_wake_mutex); mt_pthread_cond_timedwait_ns(&ctx->encode_block_wake_cond, @@ -183,23 +191,23 @@ static int tx_st22p_encode_get_block_wait(struct st22p_tx_ctx* ctx) { return 0; } -static int tx_st22p_encode_wake_block(void* priv) { - struct st22p_tx_ctx* ctx = priv; +static int tx_st22p_encode_wake_block(void *priv) { + struct st22p_tx_ctx *ctx = priv; tx_st22p_encode_block_wake(ctx); return 0; } -static int tx_st22p_encode_set_timeout(void* priv, uint64_t timedwait_ns) { - struct st22p_tx_ctx* ctx = priv; +static int tx_st22p_encode_set_timeout(void *priv, uint64_t timedwait_ns) { + struct st22p_tx_ctx *ctx = priv; ctx->encode_block_timeout_ns = timedwait_ns; return 0; } -static struct st22_encode_frame_meta* tx_st22p_encode_get_frame(void* priv) { - struct st22p_tx_ctx* ctx = priv; +static struct st22_encode_frame_meta *tx_st22p_encode_get_frame(void *priv) { + struct st22p_tx_ctx *ctx = priv; int idx = ctx->idx; - struct st22p_tx_frame* framebuff; + struct st22p_tx_frame *framebuff; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); @@ -210,7 +218,8 @@ static struct st22_encode_frame_meta* tx_st22p_encode_get_frame(void* priv) { dbg("%s(%d), not ready %d\n", __func__, idx, ctx->type); if (ctx->encode_block_get) { tx_st22p_encode_get_block_wait(ctx); - if (!ctx->ready) return NULL; + if (!ctx->ready) + return NULL; } return NULL; /* not ready */ } @@ -218,15 +227,15 @@ static struct st22_encode_frame_meta* tx_st22p_encode_get_frame(void* priv) { ctx->stat_encode_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, ST22P_TX_FRAME_READY); + framebuff = tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, + ST22P_TX_FRAME_READY); if (!framebuff && ctx->encode_block_get) { /* wait here for block mode */ mt_pthread_mutex_unlock(&ctx->lock); tx_st22p_encode_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, ST22P_TX_FRAME_READY); + framebuff = tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, + ST22P_TX_FRAME_READY); } /* not any free frame */ if (!framebuff) { @@ -242,20 +251,22 @@ static struct st22_encode_frame_meta* tx_st22p_encode_get_frame(void* priv) { ctx->stat_encode_get_frame_succ++; dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); - struct st22_encode_frame_meta* frame = &framebuff->encode_frame; + struct st22_encode_frame_meta *frame = &framebuff->encode_frame; MT_USDT_ST22P_TX_ENCODE_GET(idx, framebuff->idx, frame->src->addr[0], frame->dst->addr[0]); return frame; } /* min frame size should be capable of bulk pkts */ -#define ST22_ENCODE_MIN_FRAME_SZ ((ST_SESSION_MAX_BULK + 1) * MTL_PKT_MAX_RTP_BYTES) +#define ST22_ENCODE_MIN_FRAME_SZ \ + ((ST_SESSION_MAX_BULK + 1) * MTL_PKT_MAX_RTP_BYTES) -static int tx_st22p_encode_put_frame(void* priv, struct st22_encode_frame_meta* frame, +static int tx_st22p_encode_put_frame(void *priv, + struct st22_encode_frame_meta *frame, int result) { - struct st22p_tx_ctx* ctx = priv; + struct st22p_tx_ctx *ctx = priv; int idx = ctx->idx; - struct st22p_tx_frame* framebuff = frame->priv; + struct st22p_tx_frame *framebuff = frame->priv; uint16_t encode_idx = framebuff->idx; size_t data_size = frame->dst->data_size; size_t max_size = ctx->encode_impl->codestream_max_size; @@ -272,9 +283,10 @@ static int tx_st22p_encode_put_frame(void* priv, struct st22_encode_frame_meta* } ctx->stat_encode_put_frame++; - dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, encode_idx, - result, data_size); - if ((result < 0) || (data_size <= ST22_ENCODE_MIN_FRAME_SZ) || (data_size > max_size)) { + dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, + encode_idx, result, data_size); + if ((result < 0) || (data_size <= ST22_ENCODE_MIN_FRAME_SZ) || + (data_size > max_size)) { warn("%s(%d), invalid frame %u result %d data_size %" PRIu64 ", allowed min %u max %" PRIu64 "\n", __func__, idx, encode_idx, result, data_size, ST22_ENCODE_MIN_FRAME_SZ, @@ -291,19 +303,20 @@ static int tx_st22p_encode_put_frame(void* priv, struct st22_encode_frame_meta* return 0; } -static int tx_st22p_encode_dump(void* priv) { - struct st22p_tx_ctx* ctx = priv; - struct st22p_tx_frame* framebuff = ctx->framebuffs; +static int tx_st22p_encode_dump(void *priv) { + struct st22p_tx_ctx *ctx = priv; + struct st22p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t encode_idx = ctx->framebuff_encode_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("TX_ST22P(%s), p(%d:%s) e(%d:%s) c(%d:%s)\n", ctx->ops_name, producer_idx, - tx_st22p_stat_name(framebuff[producer_idx].stat), encode_idx, - tx_st22p_stat_name(framebuff[encode_idx].stat), consumer_idx, - tx_st22p_stat_name(framebuff[consumer_idx].stat)); + notice("TX_ST22P(%s), p(%d:%s) e(%d:%s) c(%d:%s)\n", ctx->ops_name, + producer_idx, tx_st22p_stat_name(framebuff[producer_idx].stat), + encode_idx, tx_st22p_stat_name(framebuff[encode_idx].stat), + consumer_idx, tx_st22p_stat_name(framebuff[consumer_idx].stat)); int encode_fail = rte_atomic32_read(&ctx->stat_encode_fail); rte_atomic32_set(&ctx->stat_encode_fail, 0); @@ -312,7 +325,8 @@ static int tx_st22p_encode_dump(void* priv) { } notice("TX_ST22P(%s), frame get try %d succ %d, put %d\n", ctx->ops_name, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, + ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -327,8 +341,9 @@ static int tx_st22p_encode_dump(void* priv) { return 0; } -static int tx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_tx_ctx* ctx, - struct st22p_tx_ops* ops) { +static int tx_st22p_create_transport(struct mtl_main_impl *impl, + struct st22p_tx_ctx *ctx, + struct st22p_tx_ops *ops) { int idx = ctx->idx; struct st22_tx_ops ops_tx; st22_tx_handle transport; @@ -344,26 +359,29 @@ static int tx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_tx ops_tx.udp_port[i] = ops->port.udp_port[i]; } if (ops->flags & ST22P_TX_FLAG_USER_P_MAC) { - memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_P][0], &ops->tx_dst_mac[MTL_PORT_P][0], - MTL_MAC_ADDR_LEN); + memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_P][0], + &ops->tx_dst_mac[MTL_PORT_P][0], MTL_MAC_ADDR_LEN); ops_tx.flags |= ST22_TX_FLAG_USER_P_MAC; } if (ops->flags & ST22P_TX_FLAG_USER_R_MAC) { - memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_R][0], &ops->tx_dst_mac[MTL_PORT_R][0], - MTL_MAC_ADDR_LEN); + memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_R][0], + &ops->tx_dst_mac[MTL_PORT_R][0], MTL_MAC_ADDR_LEN); ops_tx.flags |= ST22_TX_FLAG_USER_R_MAC; } if (ops->flags & ST22P_TX_FLAG_DISABLE_BOXES) ops_tx.flags |= ST22_TX_FLAG_DISABLE_BOXES; - if (ops->flags & ST22P_TX_FLAG_USER_PACING) ops_tx.flags |= ST22_TX_FLAG_USER_PACING; + if (ops->flags & ST22P_TX_FLAG_USER_PACING) + ops_tx.flags |= ST22_TX_FLAG_USER_PACING; if (ops->flags & ST22P_TX_FLAG_USER_TIMESTAMP) ops_tx.flags |= ST22_TX_FLAG_USER_TIMESTAMP; - if (ops->flags & ST22P_TX_FLAG_ENABLE_VSYNC) ops_tx.flags |= ST22_TX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22P_TX_FLAG_ENABLE_VSYNC) + ops_tx.flags |= ST22_TX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22P_TX_FLAG_ENABLE_RTCP) { ops_tx.flags |= ST22_TX_FLAG_ENABLE_RTCP; ops_tx.rtcp = ops->rtcp; } - if (ops->flags & ST22P_TX_FLAG_DISABLE_BULK) ops_tx.flags |= ST22_TX_FLAG_DISABLE_BULK; + if (ops->flags & ST22P_TX_FLAG_DISABLE_BULK) + ops_tx.flags |= ST22_TX_FLAG_DISABLE_BULK; if (ops->flags & ST22P_TX_FLAG_FORCE_NUMA) { ops_tx.socket_id = ops->socket_id; ops_tx.flags |= ST22_TX_FLAG_FORCE_NUMA; @@ -396,7 +414,7 @@ static int tx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_tx } ctx->transport = transport; - struct st22p_tx_frame* frames = ctx->framebuffs; + struct st22p_tx_frame *frames = ctx->framebuffs; for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { frames[i].dst.addr[0] = st22_tx_get_fb_addr(transport, i); frames[i].dst.fmt = ctx->codestream_fmt; @@ -415,7 +433,7 @@ static int tx_st22p_create_transport(struct mtl_main_impl* impl, struct st22p_tx return 0; } -static int tx_st22p_uinit_src_fbs(struct st22p_tx_ctx* ctx) { +static int tx_st22p_uinit_src_fbs(struct st22p_tx_ctx *ctx) { if (ctx->framebuffs) { if (!ctx->ext_frame) { for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { @@ -438,11 +456,12 @@ static int tx_st22p_uinit_src_fbs(struct st22p_tx_ctx* ctx) { return 0; } -static int tx_st22p_init_src_fbs(struct st22p_tx_ctx* ctx, struct st22p_tx_ops* ops) { +static int tx_st22p_init_src_fbs(struct st22p_tx_ctx *ctx, + struct st22p_tx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; - struct st22p_tx_frame* frames; - void* src; + struct st22p_tx_frame *frames; + void *src; size_t src_size = ctx->src_size; ctx->framebuff_cnt = ops->framebuff_cnt; @@ -464,7 +483,8 @@ static int tx_st22p_init_src_fbs(struct st22p_tx_ctx* ctx, struct st22p_tx_ops* frames[i].src.height = ops->height; frames[i].src.priv = &frames[i]; - if (ctx->derive) continue; /* skip the plane init */ + if (ctx->derive) + continue; /* skip the plane init */ if (ctx->ext_frame) { /* will use ext frame from user */ uint8_t planes = st_frame_fmt_planes(frames[i].src.fmt); @@ -493,13 +513,14 @@ static int tx_st22p_init_src_fbs(struct st22p_tx_ctx* ctx, struct st22p_tx_ops* } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, src_size, - ops->input_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, + src_size, ops->input_fmt, ctx->framebuff_cnt); return 0; } -static int tx_st22p_get_encoder(struct mtl_main_impl* impl, struct st22p_tx_ctx* ctx, - struct st22p_tx_ops* ops) { +static int tx_st22p_get_encoder(struct mtl_main_impl *impl, + struct st22p_tx_ctx *ctx, + struct st22p_tx_ops *ops) { int idx = ctx->idx; struct st22_get_encoder_request req; @@ -524,7 +545,7 @@ static int tx_st22p_get_encoder(struct mtl_main_impl* impl, struct st22p_tx_ctx* req.put_frame = tx_st22p_encode_put_frame; req.dump = tx_st22p_encode_dump; - struct st22_encode_session_impl* encode_impl = st22_get_encoder(impl, &req); + struct st22_encode_session_impl *encode_impl = st22_get_encoder(impl, &req); if (!encode_impl) { err("%s(%d), get encoder fail\n", __func__, idx); return -EINVAL; @@ -545,7 +566,7 @@ static int tx_st22p_get_encoder(struct mtl_main_impl* impl, struct st22p_tx_ctx* return 0; } -static int tx_st22p_get_block_wait(struct st22p_tx_ctx* ctx) { +static int tx_st22p_get_block_wait(struct st22p_tx_ctx *ctx) { /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); mt_pthread_cond_timedwait_ns(&ctx->block_wake_cond, &ctx->block_wake_mutex, @@ -554,16 +575,18 @@ static int tx_st22p_get_block_wait(struct st22p_tx_ctx* ctx) { return 0; } -static int tx_st22p_usdt_dump_frame(struct st22p_tx_ctx* ctx, struct st_frame* frame) { +static int tx_st22p_usdt_dump_frame(struct st22p_tx_ctx *ctx, + struct st_frame *frame) { int idx = ctx->idx; - struct mtl_main_impl* impl = ctx->impl; + struct mtl_main_impl *impl = ctx->impl; int fd; char usdt_dump_path[64]; - struct st22p_tx_ops* ops = &ctx->ops; + struct st22p_tx_ops *ops = &ctx->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); + "imtl_usdt_st22ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -585,14 +608,15 @@ static int tx_st22p_usdt_dump_frame(struct st22p_tx_ctx* ctx, struct st_frame* f return 0; } -static void tx_st22p_framebuffs_flush(struct st22p_tx_ctx* ctx) { +static void tx_st22p_framebuffs_flush(struct st22p_tx_ctx *ctx) { /* wait all frame are in free or in transmitting(flushed by transport) */ for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { - struct st22p_tx_frame* framebuff = &ctx->framebuffs[i]; + struct st22p_tx_frame *framebuff = &ctx->framebuffs[i]; int retry = 0; while (1) { - if (framebuff->stat == ST22P_TX_FRAME_FREE) break; + if (framebuff->stat == ST22P_TX_FRAME_FREE) + break; if (framebuff->stat == ST22P_TX_FRAME_IN_TRANSMITTING) { /* * make sure to wait when the frame is in transmit @@ -606,8 +630,8 @@ static void tx_st22p_framebuffs_flush(struct st22p_tx_ctx* ctx) { tx_st22p_stat_name(framebuff->stat), retry); retry++; if (retry > 100) { - info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, i, - tx_st22p_stat_name(framebuff->stat), retry); + info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, + i, tx_st22p_stat_name(framebuff->stat), retry); break; } mt_sleep_ms(10); @@ -615,30 +639,31 @@ static void tx_st22p_framebuffs_flush(struct st22p_tx_ctx* ctx) { } } -struct st_frame* st22p_tx_get_frame(st22p_tx_handle handle) { - struct st22p_tx_ctx* ctx = handle; +struct st_frame *st22p_tx_get_frame(st22p_tx_handle handle) { + struct st22p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st22p_tx_frame* framebuff; + struct st22p_tx_frame *framebuff; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, ST22P_TX_FRAME_FREE); + framebuff = tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, + ST22P_TX_FRAME_FREE); if (!framebuff && ctx->block_get) { mt_pthread_mutex_unlock(&ctx->lock); tx_st22p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, ST22P_TX_FRAME_FREE); + framebuff = tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, + ST22P_TX_FRAME_FREE); } /* not any free frame */ if (!framebuff) { @@ -652,21 +677,24 @@ struct st_frame* st22p_tx_get_frame(st22p_tx_handle handle) { mt_pthread_mutex_unlock(&ctx->lock); dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); - if (ctx->ops.interlaced) { /* init second_field but user still can customize */ - framebuff->dst.second_field = framebuff->src.second_field = ctx->second_field; + if (ctx->ops + .interlaced) { /* init second_field but user still can customize */ + framebuff->dst.second_field = framebuff->src.second_field = + ctx->second_field; ctx->second_field = ctx->second_field ? false : true; } ctx->stat_get_frame_succ++; - struct st_frame* frame = tx_st22p_user_frame(ctx, framebuff); - dbg("%s(%d), frame %u addr %p\n", __func__, idx, framebuff->idx, frame->addr[0]); + struct st_frame *frame = tx_st22p_user_frame(ctx, framebuff); + dbg("%s(%d), frame %u addr %p\n", __func__, idx, framebuff->idx, + frame->addr[0]); MT_USDT_ST22P_TX_FRAME_GET(idx, framebuff->idx, frame->addr[0]); return frame; } -int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame* frame) { - struct st22p_tx_ctx* ctx = handle; +int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame *frame) { + struct st22p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st22p_tx_frame* framebuff = frame->priv; + struct st22p_tx_frame *framebuff = frame->priv; uint16_t producer_idx = framebuff->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { @@ -681,12 +709,14 @@ int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame* frame) { } if (ctx->ext_frame) { - err("%s(%d), EXT_FRAME enabled, use st22p_tx_put_ext_frame instead\n", __func__, idx); + err("%s(%d), EXT_FRAME enabled, use st22p_tx_put_ext_frame instead\n", + __func__, idx); return -EIO; } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = + frame->second_field; } if (ctx->derive) { @@ -697,8 +727,8 @@ int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame* frame) { } ctx->stat_put_frame++; - MT_USDT_ST22P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], framebuff->stat, - frame->data_size); + MT_USDT_ST22P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], + framebuff->stat, frame->data_size); /* check if dump USDT enabled */ if (!ctx->derive && MT_USDT_ST22P_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -714,11 +744,11 @@ int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame* frame) { return 0; } -int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame* frame, - struct st_ext_frame* ext_frame) { - struct st22p_tx_ctx* ctx = handle; +int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame *frame, + struct st_ext_frame *ext_frame) { + struct st22p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st22p_tx_frame* framebuff = frame->priv; + struct st22p_tx_frame *framebuff = frame->priv; uint16_t producer_idx = framebuff->idx; int ret = 0; @@ -761,7 +791,8 @@ int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame* frame, } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = + frame->second_field; } framebuff->stat = ST22P_TX_FRAME_READY; @@ -772,10 +803,10 @@ int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame* frame, return 0; } -st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops* ops) { +st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops *ops) { static int st22p_tx_idx; - struct mtl_main_impl* impl = mt; - struct st22p_tx_ctx* ctx; + struct mtl_main_impl *impl = mt; + struct st22p_tx_ctx *ctx; int ret; int idx = st22p_tx_idx; size_t src_size; @@ -794,8 +825,10 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops* ops) { return NULL; } - enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + enum mtl_port port = + mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22P_TX_FLAG_FORCE_NUMA) { @@ -818,12 +851,14 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops* ops) { if (ctx->derive) { src_size = ops->codestream_size; if (!src_size) { - warn("%s(%d), codestream_size is not set by user in derive mode, use default 1M\n", + warn("%s(%d), codestream_size is not set by user in derive mode, use " + "default 1M\n", __func__, idx); src_size = 0x100000; } } else { - src_size = st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); + src_size = + st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); if (!src_size) { err("%s(%d), get source size fail\n", __func__, idx); return NULL; @@ -847,7 +882,8 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops* ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; /* default to 1s */ - if (ops->flags & ST22P_TX_FLAG_BLOCK_GET) ctx->block_get = true; + if (ops->flags & ST22P_TX_FLAG_BLOCK_GET) + ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -885,19 +921,20 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops* ops) { /* all ready now */ ctx->ready = true; - notice("%s(%d), codestream fmt %s, input fmt: %s, flags 0x%x\n", __func__, idx, - st_frame_fmt_name(ctx->codestream_fmt), st_frame_fmt_name(ops->input_fmt), - ops->flags); + notice("%s(%d), codestream fmt %s, input fmt: %s, flags 0x%x\n", __func__, + idx, st_frame_fmt_name(ctx->codestream_fmt), + st_frame_fmt_name(ops->input_fmt), ops->flags); st22p_tx_idx++; - if (!ctx->block_get) tx_st22p_notify_frame_available(ctx); + if (!ctx->block_get) + tx_st22p_notify_frame_available(ctx); return ctx; } int st22p_tx_free(st22p_tx_handle handle) { - struct st22p_tx_ctx* ctx = handle; - struct mtl_main_impl* impl = ctx->impl; + struct st22p_tx_ctx *ctx = handle; + struct mtl_main_impl *impl = ctx->impl; notice("%s(%d), start\n", __func__, ctx->idx); @@ -932,8 +969,8 @@ int st22p_tx_free(st22p_tx_handle handle) { return 0; } -void* st22p_tx_get_fb_addr(st22p_tx_handle handle, uint16_t idx) { - struct st22p_tx_ctx* ctx = handle; +void *st22p_tx_get_fb_addr(st22p_tx_handle handle, uint16_t idx) { + struct st22p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { @@ -956,7 +993,7 @@ void* st22p_tx_get_fb_addr(st22p_tx_handle handle, uint16_t idx) { } size_t st22p_tx_frame_size(st22p_tx_handle handle) { - struct st22p_tx_ctx* ctx = handle; + struct st22p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { @@ -967,8 +1004,9 @@ size_t st22p_tx_frame_size(st22p_tx_handle handle) { return ctx->src_size; } -int st22p_tx_update_destination(st22p_tx_handle handle, struct st_tx_dest_info* dst) { - struct st22p_tx_ctx* ctx = handle; +int st22p_tx_update_destination(st22p_tx_handle handle, + struct st_tx_dest_info *dst) { + struct st22p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { @@ -980,7 +1018,7 @@ int st22p_tx_update_destination(st22p_tx_handle handle, struct st_tx_dest_info* } int st22p_tx_wake_block(st22p_tx_handle handle) { - struct st22p_tx_ctx* ctx = handle; + struct st22p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { @@ -988,13 +1026,14 @@ int st22p_tx_wake_block(st22p_tx_handle handle) { return 0; } - if (ctx->block_get) tx_st22p_block_wake(ctx); + if (ctx->block_get) + tx_st22p_block_wake(ctx); return 0; } int st22p_tx_set_block_timeout(st22p_tx_handle handle, uint64_t timedwait_ns) { - struct st22p_tx_ctx* ctx = handle; + struct st22p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST22_HANDLE_PIPELINE_TX) { diff --git a/lib/src/st2110/pipeline/st22_pipeline_tx.h b/lib/src/st2110/pipeline/st22_pipeline_tx.h index 58342e692..9b5933b18 100644 --- a/lib/src/st2110/pipeline/st22_pipeline_tx.h +++ b/lib/src/st2110/pipeline/st22_pipeline_tx.h @@ -27,7 +27,7 @@ struct st22p_tx_frame { }; struct st22p_tx_ctx { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; int socket_id; enum mt_handle_type type; /* for sanity check */ @@ -41,7 +41,7 @@ struct st22p_tx_ctx { uint16_t framebuff_producer_idx; uint16_t framebuff_encode_idx; uint16_t framebuff_consumer_idx; - struct st22p_tx_frame* framebuffs; + struct st22p_tx_frame *framebuffs; pthread_mutex_t lock; /* protect framebuffs */ /* for ST22P_TX_FLAG_BLOCK_GET */ @@ -50,7 +50,7 @@ struct st22p_tx_ctx { pthread_mutex_t block_wake_mutex; uint64_t block_timeout_ns; - struct st22_encode_session_impl* encode_impl; + struct st22_encode_session_impl *encode_impl; /* for ST22_ENCODER_RESP_FLAG_BLOCK_GET */ bool encode_block_get; pthread_cond_t encode_block_wake_cond; diff --git a/lib/src/st2110/pipeline/st30_pipeline_rx.c b/lib/src/st2110/pipeline/st30_pipeline_rx.c index b9b828777..3f1f8fc23 100644 --- a/lib/src/st2110/pipeline/st30_pipeline_rx.c +++ b/lib/src/st2110/pipeline/st30_pipeline_rx.c @@ -7,32 +7,33 @@ #include "../../mt_log.h" #include "../../mt_stat.h" -static const char* st30p_rx_frame_stat_name[ST30P_RX_FRAME_STATUS_MAX] = { +static const char *st30p_rx_frame_stat_name[ST30P_RX_FRAME_STATUS_MAX] = { "free", "ready", "in_user", }; -static const char* rx_st30p_stat_name(enum st30p_rx_frame_status stat) { +static const char *rx_st30p_stat_name(enum st30p_rx_frame_status stat) { return st30p_rx_frame_stat_name[stat]; } -static uint16_t rx_st30p_next_idx(struct st30p_rx_ctx* ctx, uint16_t idx) { +static uint16_t rx_st30p_next_idx(struct st30p_rx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) + next_idx = 0; return next_idx; } -static void rx_st30p_block_wake(struct st30p_rx_ctx* ctx) { +static void rx_st30p_block_wake(struct st30p_rx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); mt_pthread_cond_signal(&ctx->block_wake_cond); mt_pthread_mutex_unlock(&ctx->block_wake_mutex); } -static void rx_st30p_notify_frame_available(struct st30p_rx_ctx* ctx) { +static void rx_st30p_notify_frame_available(struct st30p_rx_ctx *ctx) { if (ctx->ops.notify_frame_available) { /* notify app */ ctx->ops.notify_frame_available(ctx->ops.priv); } @@ -43,10 +44,11 @@ static void rx_st30p_notify_frame_available(struct st30p_rx_ctx* ctx) { } } -static struct st30p_rx_frame* rx_st30p_next_available( - struct st30p_rx_ctx* ctx, uint16_t idx_start, enum st30p_rx_frame_status desired) { +static struct st30p_rx_frame * +rx_st30p_next_available(struct st30p_rx_ctx *ctx, uint16_t idx_start, + enum st30p_rx_frame_status desired) { uint16_t idx = idx_start; - struct st30p_rx_frame* framebuff; + struct st30p_rx_frame *framebuff; /* check ready frame from idx_start */ while (1) { @@ -66,15 +68,17 @@ static struct st30p_rx_frame* rx_st30p_next_available( return NULL; } -static int rx_st30p_frame_ready(void* priv, void* addr, struct st30_rx_frame_meta* meta) { - struct st30p_rx_ctx* ctx = priv; - struct st30p_rx_frame* framebuff; +static int rx_st30p_frame_ready(void *priv, void *addr, + struct st30_rx_frame_meta *meta) { + struct st30p_rx_ctx *ctx = priv; + struct st30p_rx_frame *framebuff; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st30p_next_available(ctx, ctx->framebuff_producer_idx, ST30P_RX_FRAME_FREE); + framebuff = rx_st30p_next_available(ctx, ctx->framebuff_producer_idx, + ST30P_RX_FRAME_FREE); /* not any free frame */ if (!framebuff) { @@ -83,7 +87,7 @@ static int rx_st30p_frame_ready(void* priv, void* addr, struct st30_rx_frame_met return -EBUSY; } - struct st30_frame* frame = &framebuff->frame; + struct st30_frame *frame = &framebuff->frame; frame->addr = addr; frame->data_size = meta->frame_recv_size; frame->tfmt = meta->tfmt; @@ -94,7 +98,8 @@ static int rx_st30p_frame_ready(void* priv, void* addr, struct st30_rx_frame_met ctx->framebuff_producer_idx = rx_st30p_next_idx(ctx, framebuff->idx); mt_pthread_mutex_unlock(&ctx->lock); - dbg("%s(%d), frame %u(%p) succ\n", __func__, ctx->idx, framebuff->idx, frame->addr); + dbg("%s(%d), frame %u(%p) succ\n", __func__, ctx->idx, framebuff->idx, + frame->addr); /* notify app to a ready frame */ rx_st30p_notify_frame_available(ctx); @@ -103,8 +108,9 @@ static int rx_st30p_frame_ready(void* priv, void* addr, struct st30_rx_frame_met return 0; } -static int rx_st30p_create_transport(struct mtl_main_impl* impl, struct st30p_rx_ctx* ctx, - struct st30p_rx_ops* ops) { +static int rx_st30p_create_transport(struct mtl_main_impl *impl, + struct st30p_rx_ctx *ctx, + struct st30p_rx_ops *ops) { int idx = ctx->idx; struct st30_rx_ops ops_rx; st30_rx_handle transport; @@ -117,7 +123,8 @@ static int rx_st30p_create_transport(struct mtl_main_impl* impl, struct st30p_rx ops_rx.ssrc = ops->port.ssrc; for (int i = 0; i < ops_rx.num_port; i++) { memcpy(ops_rx.ip_addr[i], ops->port.ip_addr[i], MTL_IP_ADDR_LEN); - memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], MTL_IP_ADDR_LEN); + memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[i], MTL_PORT_MAX_LEN, "%s", ops->port.port[i]); ops_rx.udp_port[i] = ops->port.udp_port[i]; } @@ -149,7 +156,7 @@ static int rx_st30p_create_transport(struct mtl_main_impl* impl, struct st30p_rx return 0; } -static int rx_st30p_uinit_fbs(struct st30p_rx_ctx* ctx) { +static int rx_st30p_uinit_fbs(struct st30p_rx_ctx *ctx) { if (ctx->framebuffs) { mt_rte_free(ctx->framebuffs); ctx->framebuffs = NULL; @@ -158,10 +165,11 @@ static int rx_st30p_uinit_fbs(struct st30p_rx_ctx* ctx) { return 0; } -static int rx_st30p_init_fbs(struct st30p_rx_ctx* ctx, struct st30p_rx_ops* ops) { +static int rx_st30p_init_fbs(struct st30p_rx_ctx *ctx, + struct st30p_rx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; - struct st30p_rx_frame* frames; + struct st30p_rx_frame *frames; frames = mt_rte_zmalloc_socket(sizeof(*frames) * ctx->framebuff_cnt, soc_id); if (!frames) { @@ -171,8 +179,8 @@ static int rx_st30p_init_fbs(struct st30p_rx_ctx* ctx, struct st30p_rx_ops* ops) ctx->framebuffs = frames; for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { - struct st30p_rx_frame* framebuff = &frames[i]; - struct st30_frame* frame = &framebuff->frame; + struct st30p_rx_frame *framebuff = &frames[i]; + struct st30_frame *frame = &framebuff->frame; framebuff->stat = ST30P_RX_FRAME_FREE; framebuff->idx = i; @@ -191,33 +199,36 @@ static int rx_st30p_init_fbs(struct st30p_rx_ctx* ctx, struct st30p_rx_ops* ops) return 0; } -static int rx_st30p_stat(void* priv) { - struct st30p_rx_ctx* ctx = priv; - struct st30p_rx_frame* framebuff = ctx->framebuffs; +static int rx_st30p_stat(void *priv) { + struct st30p_rx_ctx *ctx = priv; + struct st30p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("RX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, - rx_st30p_stat_name(framebuff[producer_idx].stat), consumer_idx, - rx_st30p_stat_name(framebuff[consumer_idx].stat)); + notice("RX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, + producer_idx, rx_st30p_stat_name(framebuff[producer_idx].stat), + consumer_idx, rx_st30p_stat_name(framebuff[consumer_idx].stat)); notice("RX_st30p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, + ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; if (ctx->stat_busy) { - warn("RX_st30p(%d), stat_busy %d in rx frame ready\n", ctx->idx, ctx->stat_busy); + warn("RX_st30p(%d), stat_busy %d in rx frame ready\n", ctx->idx, + ctx->stat_busy); ctx->stat_busy = 0; } return 0; } -static int rx_st30p_get_block_wait(struct st30p_rx_ctx* ctx) { +static int rx_st30p_get_block_wait(struct st30p_rx_ctx *ctx) { dbg("%s(%d), start\n", __func__, ctx->idx); /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); @@ -228,36 +239,38 @@ static int rx_st30p_get_block_wait(struct st30p_rx_ctx* ctx) { return 0; } -static int rx_st30p_usdt_dump_close(struct st30p_rx_ctx* ctx) { +static int rx_st30p_usdt_dump_close(struct st30p_rx_ctx *ctx) { int idx = ctx->idx; if (ctx->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, ctx->usdt_dump_fd, - ctx->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, + ctx->usdt_dump_fd, ctx->usdt_dumped_frames); close(ctx->usdt_dump_fd); ctx->usdt_dump_fd = -1; } return 0; } -static int rx_st30p_usdt_dump_frame(struct st30p_rx_ctx* ctx, struct st30_frame* frame) { +static int rx_st30p_usdt_dump_frame(struct st30p_rx_ctx *ctx, + struct st30_frame *frame) { int idx = ctx->idx; int ret; if (ctx->usdt_dump_fd < 0) { - struct st30p_rx_ops* ops = &ctx->ops; + struct st30p_rx_ops *ops = &ctx->ops; snprintf(ctx->usdt_dump_path, sizeof(ctx->usdt_dump_path), "imtl_usdt_st30prx_s%d_%d_%d_c%u_XXXXXX.pcm", idx, - st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, - ops->channel); + st30_get_sample_rate(ops->sampling), + st30_get_sample_size(ops->fmt) * 8, ops->channel); ret = mt_mkstemps(ctx->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, + ret); return ret; } ctx->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, ctx->usdt_dump_path, - ctx->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, + ctx->usdt_dump_path, ctx->usdt_dump_fd); } /* write frame to dump file */ @@ -268,39 +281,41 @@ static int rx_st30p_usdt_dump_frame(struct st30p_rx_ctx* ctx, struct st30_frame* ctx->usdt_dumped_frames++; /* logging every 1 sec */ if ((ctx->usdt_dumped_frames % (ctx->frames_per_sec * 1)) == 0) { - MT_USDT_ST30P_RX_FRAME_DUMP(idx, ctx->usdt_dump_path, ctx->usdt_dumped_frames); + MT_USDT_ST30P_RX_FRAME_DUMP(idx, ctx->usdt_dump_path, + ctx->usdt_dumped_frames); } } return 0; } -struct st30_frame* st30p_rx_get_frame(st30p_rx_handle handle) { - struct st30p_rx_ctx* ctx = handle; +struct st30_frame *st30p_rx_get_frame(st30p_rx_handle handle) { + struct st30p_rx_ctx *ctx = handle; int idx = ctx->idx; - struct st30p_rx_frame* framebuff; - struct st30_frame* frame; + struct st30p_rx_frame *framebuff; + struct st30_frame *frame; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, ST30P_RX_FRAME_READY); + framebuff = rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, + ST30P_RX_FRAME_READY); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); rx_st30p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, ST30P_RX_FRAME_READY); + framebuff = rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, + ST30P_RX_FRAME_READY); } /* not any converted frame */ if (!framebuff) { @@ -316,7 +331,8 @@ struct st30_frame* st30p_rx_get_frame(st30p_rx_handle handle) { frame = &framebuff->frame; ctx->stat_get_frame_succ++; MT_USDT_ST30P_RX_FRAME_GET(idx, framebuff->idx, frame->addr); - dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, frame->addr); + dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, + frame->addr); /* check if dump USDT enabled */ if (MT_USDT_ST30P_RX_FRAME_DUMP_ENABLED()) { rx_st30p_usdt_dump_frame(ctx, frame); @@ -326,10 +342,10 @@ struct st30_frame* st30p_rx_get_frame(st30p_rx_handle handle) { return frame; } -int st30p_rx_put_frame(st30p_rx_handle handle, struct st30_frame* frame) { - struct st30p_rx_ctx* ctx = handle; +int st30p_rx_put_frame(st30p_rx_handle handle, struct st30_frame *frame) { + struct st30p_rx_ctx *ctx = handle; int idx = ctx->idx; - struct st30p_rx_frame* framebuff = frame->priv; + struct st30p_rx_frame *framebuff = frame->priv; uint16_t consumer_idx = framebuff->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { @@ -354,8 +370,8 @@ int st30p_rx_put_frame(st30p_rx_handle handle, struct st30_frame* frame) { } int st30p_rx_free(st30p_rx_handle handle) { - struct st30p_rx_ctx* ctx = handle; - struct mtl_main_impl* impl = ctx->impl; + struct st30p_rx_ctx *ctx = handle; + struct mtl_main_impl *impl = ctx->impl; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); @@ -384,10 +400,10 @@ int st30p_rx_free(st30p_rx_handle handle) { return 0; } -st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops* ops) { +st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops *ops) { static int st30p_rx_idx; - struct mtl_main_impl* impl = mt; - struct st30p_rx_ctx* ctx; + struct mtl_main_impl *impl = mt; + struct st30p_rx_ctx *ctx; int ret; int idx = st30p_rx_idx; @@ -398,8 +414,10 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops* ops) { return NULL; } - enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + enum mtl_port port = + mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30P_RX_FLAG_FORCE_NUMA) { @@ -424,7 +442,8 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops* ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; - if (ops->flags & ST30P_RX_FLAG_BLOCK_GET) ctx->block_get = true; + if (ops->flags & ST30P_RX_FLAG_BLOCK_GET) + ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -456,7 +475,8 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops* ops) { notice("%s(%d), flags 0x%x\n", __func__, idx, ops->flags); st30p_rx_idx++; - if (!ctx->block_get) rx_st30p_notify_frame_available(ctx); + if (!ctx->block_get) + rx_st30p_notify_frame_available(ctx); mt_stat_register(impl, rx_st30p_stat, ctx, ctx->ops_name); @@ -464,7 +484,7 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops* ops) { } size_t st30p_rx_frame_size(st30p_rx_handle handle) { - struct st30p_rx_ctx* ctx = handle; + struct st30p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { @@ -475,8 +495,9 @@ size_t st30p_rx_frame_size(st30p_rx_handle handle) { return ctx->ops.framebuff_size; } -int st30p_rx_get_queue_meta(st30p_rx_handle handle, struct st_queue_meta* meta) { - struct st30p_rx_ctx* ctx = handle; +int st30p_rx_get_queue_meta(st30p_rx_handle handle, + struct st_queue_meta *meta) { + struct st30p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { @@ -487,8 +508,9 @@ int st30p_rx_get_queue_meta(st30p_rx_handle handle, struct st_queue_meta* meta) return st30_rx_get_queue_meta(ctx->transport, meta); } -int st30p_rx_update_source(st30p_rx_handle handle, struct st_rx_source_info* src) { - struct st30p_rx_ctx* ctx = handle; +int st30p_rx_update_source(st30p_rx_handle handle, + struct st_rx_source_info *src) { + struct st30p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { @@ -500,7 +522,7 @@ int st30p_rx_update_source(st30p_rx_handle handle, struct st_rx_source_info* src } int st30p_rx_wake_block(st30p_rx_handle handle) { - struct st30p_rx_ctx* ctx = handle; + struct st30p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { @@ -508,13 +530,14 @@ int st30p_rx_wake_block(st30p_rx_handle handle) { return 0; } - if (ctx->block_get) rx_st30p_block_wake(ctx); + if (ctx->block_get) + rx_st30p_block_wake(ctx); return 0; } int st30p_rx_set_block_timeout(st30p_rx_handle handle, uint64_t timedwait_ns) { - struct st30p_rx_ctx* ctx = handle; + struct st30p_rx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_RX) { diff --git a/lib/src/st2110/pipeline/st30_pipeline_rx.h b/lib/src/st2110/pipeline/st30_pipeline_rx.h index 5163f9bc1..d0694ba8e 100644 --- a/lib/src/st2110/pipeline/st30_pipeline_rx.h +++ b/lib/src/st2110/pipeline/st30_pipeline_rx.h @@ -22,7 +22,7 @@ struct st30p_rx_frame { }; struct st30p_rx_ctx { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; int socket_id; enum mt_handle_type type; /* for sanity check */ @@ -34,7 +34,7 @@ struct st30p_rx_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st30p_rx_frame* framebuffs; + struct st30p_rx_frame *framebuffs; pthread_mutex_t lock; bool ready; diff --git a/lib/src/st2110/pipeline/st30_pipeline_tx.c b/lib/src/st2110/pipeline/st30_pipeline_tx.c index abd1ef56b..4fe0e2041 100644 --- a/lib/src/st2110/pipeline/st30_pipeline_tx.c +++ b/lib/src/st2110/pipeline/st30_pipeline_tx.c @@ -7,33 +7,34 @@ #include "../../mt_log.h" #include "../../mt_stat.h" -static const char* st30p_tx_frame_stat_name[ST30P_TX_FRAME_STATUS_MAX] = { +static const char *st30p_tx_frame_stat_name[ST30P_TX_FRAME_STATUS_MAX] = { "free", "in_user", "ready", "in_transmitting", }; -static const char* tx_st30p_stat_name(enum st30p_tx_frame_status stat) { +static const char *tx_st30p_stat_name(enum st30p_tx_frame_status stat) { return st30p_tx_frame_stat_name[stat]; } -static uint16_t tx_st30p_next_idx(struct st30p_tx_ctx* ctx, uint16_t idx) { +static uint16_t tx_st30p_next_idx(struct st30p_tx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) + next_idx = 0; return next_idx; } -static void tx_st30p_block_wake(struct st30p_tx_ctx* ctx) { +static void tx_st30p_block_wake(struct st30p_tx_ctx *ctx) { /* notify block */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); mt_pthread_cond_signal(&ctx->block_wake_cond); mt_pthread_mutex_unlock(&ctx->block_wake_mutex); } -static void tx_st30p_notify_frame_available(struct st30p_tx_ctx* ctx) { +static void tx_st30p_notify_frame_available(struct st30p_tx_ctx *ctx) { if (ctx->ops.notify_frame_available) { /* notify app */ ctx->ops.notify_frame_available(ctx->ops.priv); } @@ -44,10 +45,11 @@ static void tx_st30p_notify_frame_available(struct st30p_tx_ctx* ctx) { } } -static struct st30p_tx_frame* tx_st30p_next_available( - struct st30p_tx_ctx* ctx, uint16_t idx_start, enum st30p_tx_frame_status desired) { +static struct st30p_tx_frame * +tx_st30p_next_available(struct st30p_tx_ctx *ctx, uint16_t idx_start, + enum st30p_tx_frame_status desired) { uint16_t idx = idx_start; - struct st30p_tx_frame* framebuff; + struct st30p_tx_frame *framebuff; /* check ready frame from idx_start */ while (1) { @@ -67,17 +69,18 @@ static struct st30p_tx_frame* tx_st30p_next_available( return NULL; } -static int tx_st30p_next_frame(void* priv, uint16_t* next_frame_idx, - struct st30_tx_frame_meta* meta) { - struct st30p_tx_ctx* ctx = priv; - struct st30p_tx_frame* framebuff; +static int tx_st30p_next_frame(void *priv, uint16_t *next_frame_idx, + struct st30_tx_frame_meta *meta) { + struct st30p_tx_ctx *ctx = priv; + struct st30p_tx_frame *framebuff; MTL_MAY_UNUSED(meta); - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, ST30P_TX_FRAME_READY); + framebuff = tx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, + ST30P_TX_FRAME_READY); /* not any converted frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -94,11 +97,11 @@ static int tx_st30p_next_frame(void* priv, uint16_t* next_frame_idx, return 0; } -static int tx_st30p_frame_done(void* priv, uint16_t frame_idx, - struct st30_tx_frame_meta* meta) { - struct st30p_tx_ctx* ctx = priv; +static int tx_st30p_frame_done(void *priv, uint16_t frame_idx, + struct st30_tx_frame_meta *meta) { + struct st30p_tx_ctx *ctx = priv; int ret; - struct st30p_tx_frame* framebuff = &ctx->framebuffs[frame_idx]; + struct st30p_tx_frame *framebuff = &ctx->framebuffs[frame_idx]; mt_pthread_mutex_lock(&ctx->lock); if (ST30P_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { @@ -107,12 +110,12 @@ static int tx_st30p_frame_done(void* priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, ctx->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, framebuff->stat, - frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, + framebuff->stat, frame_idx); } mt_pthread_mutex_unlock(&ctx->lock); - struct st30_frame* frame = &framebuff->frame; + struct st30_frame *frame = &framebuff->frame; frame->tfmt = meta->tfmt; frame->timestamp = meta->timestamp; frame->epoch = meta->epoch; @@ -129,8 +132,9 @@ static int tx_st30p_frame_done(void* priv, uint16_t frame_idx, return ret; } -static int tx_st30p_create_transport(struct mtl_main_impl* impl, struct st30p_tx_ctx* ctx, - struct st30p_tx_ops* ops) { +static int tx_st30p_create_transport(struct mtl_main_impl *impl, + struct st30p_tx_ctx *ctx, + struct st30p_tx_ops *ops) { int idx = ctx->idx; struct st30_tx_ops ops_tx; st30_tx_handle transport; @@ -186,9 +190,9 @@ static int tx_st30p_create_transport(struct mtl_main_impl* impl, struct st30p_tx ctx->transport = transport; ctx->frames_per_sec = transport->impl->frames_per_sec; - struct st30p_tx_frame* frames = ctx->framebuffs; + struct st30p_tx_frame *frames = ctx->framebuffs; for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { - struct st30_frame* frame = &frames[i].frame; + struct st30_frame *frame = &frames[i].frame; frame->addr = st30_tx_get_framebuffer(transport, i); dbg("%s(%d), fb %p on %u\n", __func__, idx, frame->addr); @@ -197,7 +201,7 @@ static int tx_st30p_create_transport(struct mtl_main_impl* impl, struct st30p_tx return 0; } -static int tx_st30p_uinit_fbs(struct st30p_tx_ctx* ctx) { +static int tx_st30p_uinit_fbs(struct st30p_tx_ctx *ctx) { if (ctx->framebuffs) { for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { if (ctx->framebuffs[i].stat != ST30P_TX_FRAME_FREE) { @@ -212,10 +216,11 @@ static int tx_st30p_uinit_fbs(struct st30p_tx_ctx* ctx) { return 0; } -static int tx_st30p_init_fbs(struct st30p_tx_ctx* ctx, struct st30p_tx_ops* ops) { +static int tx_st30p_init_fbs(struct st30p_tx_ctx *ctx, + struct st30p_tx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; - struct st30p_tx_frame* frames; + struct st30p_tx_frame *frames; frames = mt_rte_zmalloc_socket(sizeof(*frames) * ctx->framebuff_cnt, soc_id); if (!frames) { @@ -225,8 +230,8 @@ static int tx_st30p_init_fbs(struct st30p_tx_ctx* ctx, struct st30p_tx_ops* ops) ctx->framebuffs = frames; for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { - struct st30p_tx_frame* framebuff = &frames[i]; - struct st30_frame* frame = &framebuff->frame; + struct st30p_tx_frame *framebuff = &frames[i]; + struct st30_frame *frame = &framebuff->frame; framebuff->stat = ST30P_TX_FRAME_FREE; framebuff->idx = i; @@ -245,20 +250,22 @@ static int tx_st30p_init_fbs(struct st30p_tx_ctx* ctx, struct st30p_tx_ops* ops) return 0; } -static int tx_st30p_stat(void* priv) { - struct st30p_tx_ctx* ctx = priv; - struct st30p_tx_frame* framebuff = ctx->framebuffs; +static int tx_st30p_stat(void *priv) { + struct st30p_tx_ctx *ctx = priv; + struct st30p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) return -EBUSY; /* not ready */ + if (!ctx->ready) + return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("TX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, - tx_st30p_stat_name(framebuff[producer_idx].stat), consumer_idx, - tx_st30p_stat_name(framebuff[consumer_idx].stat)); + notice("TX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, + producer_idx, tx_st30p_stat_name(framebuff[producer_idx].stat), + consumer_idx, tx_st30p_stat_name(framebuff[consumer_idx].stat)); notice("TX_st30p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, + ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -266,7 +273,7 @@ static int tx_st30p_stat(void* priv) { return 0; } -static int tx_st30p_get_block_wait(struct st30p_tx_ctx* ctx) { +static int tx_st30p_get_block_wait(struct st30p_tx_ctx *ctx) { dbg("%s(%d), start\n", __func__, ctx->idx); /* wait on the block cond */ mt_pthread_mutex_lock(&ctx->block_wake_mutex); @@ -277,36 +284,38 @@ static int tx_st30p_get_block_wait(struct st30p_tx_ctx* ctx) { return 0; } -static int tx_st30p_usdt_dump_close(struct st30p_tx_ctx* ctx) { +static int tx_st30p_usdt_dump_close(struct st30p_tx_ctx *ctx) { int idx = ctx->idx; if (ctx->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, ctx->usdt_dump_fd, - ctx->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, + ctx->usdt_dump_fd, ctx->usdt_dumped_frames); close(ctx->usdt_dump_fd); ctx->usdt_dump_fd = -1; } return 0; } -static int tx_st30p_usdt_dump_frame(struct st30p_tx_ctx* ctx, struct st30_frame* frame) { +static int tx_st30p_usdt_dump_frame(struct st30p_tx_ctx *ctx, + struct st30_frame *frame) { int idx = ctx->idx; int ret; if (ctx->usdt_dump_fd < 0) { - struct st30p_tx_ops* ops = &ctx->ops; + struct st30p_tx_ops *ops = &ctx->ops; snprintf(ctx->usdt_dump_path, sizeof(ctx->usdt_dump_path), "imtl_usdt_st30ptx_s%d_%d_%d_c%u_XXXXXX.pcm", idx, - st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, - ops->channel); + st30_get_sample_rate(ops->sampling), + st30_get_sample_size(ops->fmt) * 8, ops->channel); ret = mt_mkstemps(ctx->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, + ret); return ret; } ctx->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, ctx->usdt_dump_path, - ctx->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, + ctx->usdt_dump_path, ctx->usdt_dump_fd); } /* write frame to dump file */ @@ -317,21 +326,23 @@ static int tx_st30p_usdt_dump_frame(struct st30p_tx_ctx* ctx, struct st30_frame* ctx->usdt_dumped_frames++; /* logging every 1 sec */ if ((ctx->usdt_dumped_frames % (ctx->frames_per_sec * 1)) == 0) { - MT_USDT_ST30P_TX_FRAME_DUMP(idx, ctx->usdt_dump_path, ctx->usdt_dumped_frames); + MT_USDT_ST30P_TX_FRAME_DUMP(idx, ctx->usdt_dump_path, + ctx->usdt_dumped_frames); } } return 0; } -static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx* ctx) { +static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx *ctx) { /* wait all frame are in free or in transmitting(flushed by transport) */ for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { - struct st30p_tx_frame* framebuff = &ctx->framebuffs[i]; + struct st30p_tx_frame *framebuff = &ctx->framebuffs[i]; int retry = 0; while (1) { - if (framebuff->stat == ST30P_TX_FRAME_FREE) break; + if (framebuff->stat == ST30P_TX_FRAME_FREE) + break; if (framebuff->stat == ST30P_TX_FRAME_IN_TRANSMITTING) { /* make sure transport to finish the transmit */ /* WA to use sleep here, todo: add a transport API to query the stat */ @@ -343,8 +354,8 @@ static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx* ctx) { tx_st30p_stat_name(framebuff->stat), retry); retry++; if (retry > 100) { - info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, i, - tx_st30p_stat_name(framebuff->stat), retry); + info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, + i, tx_st30p_stat_name(framebuff->stat), retry); break; } mt_sleep_ms(10); @@ -352,30 +363,31 @@ static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx* ctx) { } } -struct st30_frame* st30p_tx_get_frame(st30p_tx_handle handle) { - struct st30p_tx_ctx* ctx = handle; +struct st30_frame *st30p_tx_get_frame(st30p_tx_handle handle) { + struct st30p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st30p_tx_frame* framebuff; + struct st30p_tx_frame *framebuff; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { err("%s(%d), invalid type %d\n", __func__, idx, ctx->type); return NULL; } - if (!ctx->ready) return NULL; /* not ready */ + if (!ctx->ready) + return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, ST30P_TX_FRAME_FREE); + framebuff = tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, + ST30P_TX_FRAME_FREE); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); tx_st30p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = - tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, ST30P_TX_FRAME_FREE); + framebuff = tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, + ST30P_TX_FRAME_FREE); } /* not any free frame */ if (!framebuff) { @@ -388,10 +400,11 @@ struct st30_frame* st30p_tx_get_frame(st30p_tx_handle handle) { ctx->framebuff_producer_idx = tx_st30p_next_idx(ctx, framebuff->idx); mt_pthread_mutex_unlock(&ctx->lock); - struct st30_frame* frame = &framebuff->frame; + struct st30_frame *frame = &framebuff->frame; ctx->stat_get_frame_succ++; MT_USDT_ST30P_TX_FRAME_GET(idx, framebuff->idx, frame->addr); - dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, frame->addr); + dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, + frame->addr); /* check if dump USDT enabled */ if (MT_USDT_ST30P_TX_FRAME_DUMP_ENABLED()) { tx_st30p_usdt_dump_frame(ctx, frame); @@ -401,10 +414,10 @@ struct st30_frame* st30p_tx_get_frame(st30p_tx_handle handle) { return frame; } -int st30p_tx_put_frame(st30p_tx_handle handle, struct st30_frame* frame) { - struct st30p_tx_ctx* ctx = handle; +int st30p_tx_put_frame(st30p_tx_handle handle, struct st30_frame *frame) { + struct st30p_tx_ctx *ctx = handle; int idx = ctx->idx; - struct st30p_tx_frame* framebuff = frame->priv; + struct st30p_tx_frame *framebuff = frame->priv; uint16_t producer_idx = framebuff->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { @@ -426,8 +439,8 @@ int st30p_tx_put_frame(st30p_tx_handle handle, struct st30_frame* frame) { } int st30p_tx_free(st30p_tx_handle handle) { - struct st30p_tx_ctx* ctx = handle; - struct mtl_main_impl* impl = ctx->impl; + struct st30p_tx_ctx *ctx = handle; + struct mtl_main_impl *impl = ctx->impl; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { err("%s(%d), invalid type %d\n", __func__, ctx->idx, ctx->type); @@ -461,10 +474,10 @@ int st30p_tx_free(st30p_tx_handle handle) { return 0; } -st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops* ops) { +st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops *ops) { static int st30p_tx_idx; - struct mtl_main_impl* impl = mt; - struct st30p_tx_ctx* ctx; + struct mtl_main_impl *impl = mt; + struct st30p_tx_ctx *ctx; int ret; int idx = st30p_tx_idx; @@ -475,8 +488,10 @@ st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops* ops) { return NULL; } - enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + enum mtl_port port = + mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30P_RX_FLAG_FORCE_NUMA) { @@ -536,15 +551,17 @@ st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops* ops) { st30p_tx_idx++; /* notify app can get frame */ - if (!ctx->block_get) tx_st30p_notify_frame_available(ctx); + if (!ctx->block_get) + tx_st30p_notify_frame_available(ctx); mt_stat_register(impl, tx_st30p_stat, ctx, ctx->ops_name); return ctx; } -int st30p_tx_update_destination(st30p_tx_handle handle, struct st_tx_dest_info* dst) { - struct st30p_tx_ctx* ctx = handle; +int st30p_tx_update_destination(st30p_tx_handle handle, + struct st_tx_dest_info *dst) { + struct st30p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { @@ -556,7 +573,7 @@ int st30p_tx_update_destination(st30p_tx_handle handle, struct st_tx_dest_info* } int st30p_tx_wake_block(st30p_tx_handle handle) { - struct st30p_tx_ctx* ctx = handle; + struct st30p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { @@ -564,13 +581,14 @@ int st30p_tx_wake_block(st30p_tx_handle handle) { return 0; } - if (ctx->block_get) tx_st30p_block_wake(ctx); + if (ctx->block_get) + tx_st30p_block_wake(ctx); return 0; } int st30p_tx_set_block_timeout(st30p_tx_handle handle, uint64_t timedwait_ns) { - struct st30p_tx_ctx* ctx = handle; + struct st30p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { @@ -583,7 +601,7 @@ int st30p_tx_set_block_timeout(st30p_tx_handle handle, uint64_t timedwait_ns) { } size_t st30p_tx_frame_size(st30p_tx_handle handle) { - struct st30p_tx_ctx* ctx = handle; + struct st30p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { @@ -594,8 +612,8 @@ size_t st30p_tx_frame_size(st30p_tx_handle handle) { return ctx->ops.framebuff_size; } -void* st30p_tx_get_fb_addr(st30p_tx_handle handle, uint16_t idx) { - struct st30p_tx_ctx* ctx = handle; +void *st30p_tx_get_fb_addr(st30p_tx_handle handle, uint16_t idx) { + struct st30p_tx_ctx *ctx = handle; int cidx = ctx->idx; if (ctx->type != MT_ST30_HANDLE_PIPELINE_TX) { diff --git a/lib/src/st2110/pipeline/st30_pipeline_tx.h b/lib/src/st2110/pipeline/st30_pipeline_tx.h index 1ff92b2af..fef72975b 100644 --- a/lib/src/st2110/pipeline/st30_pipeline_tx.h +++ b/lib/src/st2110/pipeline/st30_pipeline_tx.h @@ -23,7 +23,7 @@ struct st30p_tx_frame { }; struct st30p_tx_ctx { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; int socket_id; enum mt_handle_type type; /* for sanity check */ @@ -35,7 +35,7 @@ struct st30p_tx_ctx { uint16_t framebuff_cnt; uint16_t framebuff_producer_idx; uint16_t framebuff_consumer_idx; - struct st30p_tx_frame* framebuffs; + struct st30p_tx_frame *framebuffs; pthread_mutex_t lock; bool ready; diff --git a/lib/src/st2110/pipeline/st_plugin.c b/lib/src/st2110/pipeline/st_plugin.c index b1177e9c2..5c29f2240 100644 --- a/lib/src/st2110/pipeline/st_plugin.c +++ b/lib/src/st2110/pipeline/st_plugin.c @@ -9,14 +9,16 @@ #include "../../mt_log.h" #include "../../mt_stat.h" -static int st_plugins_dump(void* priv); +static int st_plugins_dump(void *priv); -static inline struct st_plugin_mgr* st_get_plugins_mgr(struct mtl_main_impl* impl) { +static inline struct st_plugin_mgr * +st_get_plugins_mgr(struct mtl_main_impl *impl) { return &impl->plugin_mgr; } -static int st_plugin_free(struct st_dl_plugin_impl* plugin) { - if (plugin->free) plugin->free(plugin->handle); +static int st_plugin_free(struct st_dl_plugin_impl *plugin) { + if (plugin->free) + plugin->free(plugin->handle); if (plugin->dl_handle) { dlclose(plugin->dl_handle); plugin->dl_handle = NULL; @@ -26,8 +28,8 @@ static int st_plugin_free(struct st_dl_plugin_impl* plugin) { return 0; } -int st_plugins_init(struct mtl_main_impl* impl) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); +int st_plugins_init(struct mtl_main_impl *impl) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); mt_pthread_mutex_init(&mgr->lock, NULL); mt_pthread_mutex_init(&mgr->plugins_lock, NULL); @@ -37,8 +39,8 @@ int st_plugins_init(struct mtl_main_impl* impl) { return 0; } -int st_plugins_uinit(struct mtl_main_impl* impl) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); +int st_plugins_uinit(struct mtl_main_impl *impl) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); mt_stat_unregister(impl, st_plugins_dump, impl); for (int i = 0; i < ST_MAX_DL_PLUGINS; i++) { @@ -75,11 +77,11 @@ int st_plugins_uinit(struct mtl_main_impl* impl) { return 0; } -int st22_put_encoder(struct mtl_main_impl* impl, - struct st22_encode_session_impl* encoder) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st22_encode_dev_impl* dev_impl = encoder->parent; - struct st22_encoder_dev* dev = &dev_impl->dev; +int st22_put_encoder(struct mtl_main_impl *impl, + struct st22_encode_session_impl *encoder) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st22_encode_dev_impl *dev_impl = encoder->parent; + struct st22_encoder_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; st22_encode_priv session = encoder->session; @@ -93,17 +95,19 @@ int st22_put_encoder(struct mtl_main_impl* impl, return 0; } -static struct st22_encode_session_impl* st22_get_encoder_session( - struct st22_encode_dev_impl* dev_impl, struct st22_get_encoder_request* req) { - struct st22_encoder_dev* dev = &dev_impl->dev; +static struct st22_encode_session_impl * +st22_get_encoder_session(struct st22_encode_dev_impl *dev_impl, + struct st22_get_encoder_request *req) { + struct st22_encoder_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; - struct st22_encoder_create_req* create_req = &req->req; - struct st22_encode_session_impl* session_impl; + struct st22_encoder_create_req *create_req = &req->req; + struct st22_encode_session_impl *session_impl; st22_encode_priv session; for (int i = 0; i < ST_MAX_SESSIONS_PER_ENCODER; i++) { session_impl = &dev_impl->sessions[i]; - if (session_impl->session) continue; + if (session_impl->session) + continue; session = dev->create_session(dev->priv, session_impl, create_req); if (session) { @@ -111,14 +115,16 @@ static struct st22_encode_session_impl* st22_get_encoder_session( session_impl->codestream_max_size = create_req->max_codestream_size; session_impl->req = *req; session_impl->type = MT_ST22_HANDLE_PIPELINE_ENCODE; - info("%s(%d), get one session at %d on dev %s, max codestream size %" PRIu64 "\n", + info("%s(%d), get one session at %d on dev %s, max codestream size " + "%" PRIu64 "\n", __func__, idx, i, dev->name, session_impl->codestream_max_size); info("%s(%d), input fmt: %s, output fmt: %s\n", __func__, idx, - st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), + st_frame_fmt_name(req->req.output_fmt)); return session_impl; } else { - err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, i, - dev->name); + err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, + i, dev->name); return NULL; } } @@ -126,31 +132,36 @@ static struct st22_encode_session_impl* st22_get_encoder_session( return NULL; } -static bool st22_encoder_is_capable(struct st22_encoder_dev* dev, - struct st22_get_encoder_request* req) { +static bool st22_encoder_is_capable(struct st22_encoder_dev *dev, + struct st22_get_encoder_request *req) { enum st_plugin_device plugin_dev = req->device; - if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && (plugin_dev != dev->target_device)) + if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && + (plugin_dev != dev->target_device)) return false; - if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) return false; + if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) + return false; - if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) return false; + if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) + return false; return true; } -struct st22_encode_session_impl* st22_get_encoder(struct mtl_main_impl* impl, - struct st22_get_encoder_request* req) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st22_encoder_dev* dev; - struct st22_encode_dev_impl* dev_impl; - struct st22_encode_session_impl* session_impl; +struct st22_encode_session_impl * +st22_get_encoder(struct mtl_main_impl *impl, + struct st22_get_encoder_request *req) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st22_encoder_dev *dev; + struct st22_encode_dev_impl *dev_impl; + struct st22_encode_session_impl *session_impl; mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_ENCODER_DEV; i++) { dev_impl = mgr->encode_devs[i]; - if (!dev_impl) continue; + if (!dev_impl) + continue; dbg("%s(%d), try to find one dev\n", __func__, i); dev = &mgr->encode_devs[i]->dev; if (!st22_encoder_is_capable(dev, req)) { @@ -169,15 +180,16 @@ struct st22_encode_session_impl* st22_get_encoder(struct mtl_main_impl* impl, mt_pthread_mutex_unlock(&mgr->lock); err("%s, fail to get, input fmt: %s, output fmt: %s\n", __func__, - st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), + st_frame_fmt_name(req->req.output_fmt)); return NULL; } -int st22_put_decoder(struct mtl_main_impl* impl, - struct st22_decode_session_impl* decoder) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st22_decode_dev_impl* dev_impl = decoder->parent; - struct st22_decoder_dev* dev = &dev_impl->dev; +int st22_put_decoder(struct mtl_main_impl *impl, + struct st22_decode_session_impl *decoder) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st22_decode_dev_impl *dev_impl = decoder->parent; + struct st22_decoder_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; st22_decode_priv session = decoder->session; @@ -191,30 +203,34 @@ int st22_put_decoder(struct mtl_main_impl* impl, return 0; } -static struct st22_decode_session_impl* st22_get_decoder_session( - struct st22_decode_dev_impl* dev_impl, struct st22_get_decoder_request* req) { - struct st22_decoder_dev* dev = &dev_impl->dev; +static struct st22_decode_session_impl * +st22_get_decoder_session(struct st22_decode_dev_impl *dev_impl, + struct st22_get_decoder_request *req) { + struct st22_decoder_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; - struct st22_decoder_create_req* create_req = &req->req; - struct st22_decode_session_impl* session_impl; + struct st22_decoder_create_req *create_req = &req->req; + struct st22_decode_session_impl *session_impl; st22_decode_priv session; for (int i = 0; i < ST_MAX_SESSIONS_PER_DECODER; i++) { session_impl = &dev_impl->sessions[i]; - if (session_impl->session) continue; + if (session_impl->session) + continue; session = dev->create_session(dev->priv, session_impl, create_req); if (session) { session_impl->session = session; session_impl->req = *req; session_impl->type = MT_ST22_HANDLE_PIPELINE_DECODE; - info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, dev->name); + info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, + dev->name); info("%s(%d), input fmt: %s, output fmt: %s\n", __func__, idx, - st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), + st_frame_fmt_name(req->req.output_fmt)); return session_impl; } else { - err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, i, - dev->name); + err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, + i, dev->name); return NULL; } } @@ -222,34 +238,40 @@ static struct st22_decode_session_impl* st22_get_decoder_session( return NULL; } -static bool st22_decoder_is_capable(struct st22_decoder_dev* dev, - struct st22_get_decoder_request* req) { +static bool st22_decoder_is_capable(struct st22_decoder_dev *dev, + struct st22_get_decoder_request *req) { enum st_plugin_device plugin_dev = req->device; - if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && (plugin_dev != dev->target_device)) + if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && + (plugin_dev != dev->target_device)) return false; - if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) return false; + if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) + return false; - if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) return false; + if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) + return false; return true; } -struct st22_decode_session_impl* st22_get_decoder(struct mtl_main_impl* impl, - struct st22_get_decoder_request* req) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st22_decoder_dev* dev; - struct st22_decode_dev_impl* dev_impl; - struct st22_decode_session_impl* session_impl; +struct st22_decode_session_impl * +st22_get_decoder(struct mtl_main_impl *impl, + struct st22_get_decoder_request *req) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st22_decoder_dev *dev; + struct st22_decode_dev_impl *dev_impl; + struct st22_decode_session_impl *session_impl; mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_DECODER_DEV; i++) { dev_impl = mgr->decode_devs[i]; - if (!dev_impl) continue; + if (!dev_impl) + continue; dbg("%s(%d), try to find one dev\n", __func__, i); dev = &mgr->decode_devs[i]->dev; - if (!st22_decoder_is_capable(dev, req)) continue; + if (!st22_decoder_is_capable(dev, req)) + continue; dbg("%s(%d), try to find one session\n", __func__, i); session_impl = st22_get_decoder_session(dev_impl, req); @@ -262,23 +284,25 @@ struct st22_decode_session_impl* st22_get_decoder(struct mtl_main_impl* impl, mt_pthread_mutex_unlock(&mgr->lock); err("%s, fail to get, input fmt: %s, output fmt: %s\n", __func__, - st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), + st_frame_fmt_name(req->req.output_fmt)); return NULL; } -int st20_convert_notify_frame_ready(struct st20_convert_session_impl* converter) { - struct st20_convert_dev_impl* dev_impl = converter->parent; - struct st20_converter_dev* dev = &dev_impl->dev; +int st20_convert_notify_frame_ready( + struct st20_convert_session_impl *converter) { + struct st20_convert_dev_impl *dev_impl = converter->parent; + struct st20_converter_dev *dev = &dev_impl->dev; st20_convert_priv session = converter->session; return dev->notify_frame_available(session); } -int st20_put_converter(struct mtl_main_impl* impl, - struct st20_convert_session_impl* converter) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st20_convert_dev_impl* dev_impl = converter->parent; - struct st20_converter_dev* dev = &dev_impl->dev; +int st20_put_converter(struct mtl_main_impl *impl, + struct st20_convert_session_impl *converter) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st20_convert_dev_impl *dev_impl = converter->parent; + struct st20_converter_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; st20_convert_priv session = converter->session; @@ -292,30 +316,34 @@ int st20_put_converter(struct mtl_main_impl* impl, return 0; } -static struct st20_convert_session_impl* st20_get_converter_session( - struct st20_convert_dev_impl* dev_impl, struct st20_get_converter_request* req) { - struct st20_converter_dev* dev = &dev_impl->dev; +static struct st20_convert_session_impl * +st20_get_converter_session(struct st20_convert_dev_impl *dev_impl, + struct st20_get_converter_request *req) { + struct st20_converter_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; - struct st20_converter_create_req* create_req = &req->req; - struct st20_convert_session_impl* session_impl; + struct st20_converter_create_req *create_req = &req->req; + struct st20_convert_session_impl *session_impl; st20_convert_priv session; for (int i = 0; i < ST_MAX_SESSIONS_PER_CONVERTER; i++) { session_impl = &dev_impl->sessions[i]; - if (session_impl->session) continue; + if (session_impl->session) + continue; session = dev->create_session(dev->priv, session_impl, create_req); if (session) { session_impl->session = session; session_impl->req = *req; session_impl->type = MT_ST20_HANDLE_PIPELINE_CONVERT; - info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, dev->name); + info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, + dev->name); info("%s(%d), input fmt: %s, output fmt: %s\n", __func__, idx, - st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), + st_frame_fmt_name(req->req.output_fmt)); return session_impl; } else { - err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, i, - dev->name); + err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, + i, dev->name); return NULL; } } @@ -323,34 +351,40 @@ static struct st20_convert_session_impl* st20_get_converter_session( return NULL; } -static bool st20_converter_is_capable(struct st20_converter_dev* dev, - struct st20_get_converter_request* req) { +static bool st20_converter_is_capable(struct st20_converter_dev *dev, + struct st20_get_converter_request *req) { enum st_plugin_device plugin_dev = req->device; - if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && (plugin_dev != dev->target_device)) + if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && + (plugin_dev != dev->target_device)) return false; - if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) return false; + if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) + return false; - if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) return false; + if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) + return false; return true; } -struct st20_convert_session_impl* st20_get_converter( - struct mtl_main_impl* impl, struct st20_get_converter_request* req) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st20_converter_dev* dev; - struct st20_convert_dev_impl* dev_impl; - struct st20_convert_session_impl* session_impl; +struct st20_convert_session_impl * +st20_get_converter(struct mtl_main_impl *impl, + struct st20_get_converter_request *req) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st20_converter_dev *dev; + struct st20_convert_dev_impl *dev_impl; + struct st20_convert_session_impl *session_impl; mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_CONVERTER_DEV; i++) { dev_impl = mgr->convert_devs[i]; - if (!dev_impl) continue; + if (!dev_impl) + continue; dbg("%s(%d), try to find one dev\n", __func__, i); dev = &mgr->convert_devs[i]->dev; - if (!st20_converter_is_capable(dev, req)) continue; + if (!st20_converter_is_capable(dev, req)) + continue; dbg("%s(%d), try to find one session\n", __func__, i); session_impl = st20_get_converter_session(dev_impl, req); @@ -363,73 +397,86 @@ struct st20_convert_session_impl* st20_get_converter( mt_pthread_mutex_unlock(&mgr->lock); info("%s, plugin not found, input fmt: %s, output fmt: %s\n", __func__, - st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), + st_frame_fmt_name(req->req.output_fmt)); return NULL; } -static int st22_encode_dev_dump(struct st22_encode_dev_impl* encode) { - struct st22_encode_session_impl* session; +static int st22_encode_dev_dump(struct st22_encode_dev_impl *encode) { + struct st22_encode_session_impl *session; int ref_cnt = rte_atomic32_read(&encode->ref_cnt); - if (ref_cnt) notice("ST22 encoder dev: %s with %d sessions\n", encode->name, ref_cnt); + if (ref_cnt) + notice("ST22 encoder dev: %s with %d sessions\n", encode->name, ref_cnt); for (int i = 0; i < ST_MAX_SESSIONS_PER_ENCODER; i++) { session = &encode->sessions[i]; - if (!session->session) continue; - if (session->req.dump) session->req.dump(session->req.priv); + if (!session->session) + continue; + if (session->req.dump) + session->req.dump(session->req.priv); } return 0; } -static int st22_decode_dev_dump(struct st22_decode_dev_impl* decode) { - struct st22_decode_session_impl* session; +static int st22_decode_dev_dump(struct st22_decode_dev_impl *decode) { + struct st22_decode_session_impl *session; int ref_cnt = rte_atomic32_read(&decode->ref_cnt); - if (ref_cnt) notice("ST22 encoder dev: %s with %d sessions\n", decode->name, ref_cnt); + if (ref_cnt) + notice("ST22 encoder dev: %s with %d sessions\n", decode->name, ref_cnt); for (int i = 0; i < ST_MAX_SESSIONS_PER_DECODER; i++) { session = &decode->sessions[i]; - if (!session->session) continue; - if (session->req.dump) session->req.dump(session->req.priv); + if (!session->session) + continue; + if (session->req.dump) + session->req.dump(session->req.priv); } return 0; } -static int st20_convert_dev_dump(struct st20_convert_dev_impl* convert) { - struct st20_convert_session_impl* session; +static int st20_convert_dev_dump(struct st20_convert_dev_impl *convert) { + struct st20_convert_session_impl *session; int ref_cnt = rte_atomic32_read(&convert->ref_cnt); - if (ref_cnt) notice("ST20 convert dev: %s with %d sessions\n", convert->name, ref_cnt); + if (ref_cnt) + notice("ST20 convert dev: %s with %d sessions\n", convert->name, ref_cnt); for (int i = 0; i < ST_MAX_SESSIONS_PER_CONVERTER; i++) { session = &convert->sessions[i]; - if (!session->session) continue; - if (session->req.dump) session->req.dump(session->req.priv); + if (!session->session) + continue; + if (session->req.dump) + session->req.dump(session->req.priv); } return 0; } -static int st_plugins_dump(void* priv) { - struct mtl_main_impl* impl = priv; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st22_encode_dev_impl* encode; - struct st22_decode_dev_impl* decode; - struct st20_convert_dev_impl* convert; +static int st_plugins_dump(void *priv) { + struct mtl_main_impl *impl = priv; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st22_encode_dev_impl *encode; + struct st22_decode_dev_impl *decode; + struct st20_convert_dev_impl *convert; mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_ENCODER_DEV; i++) { encode = mgr->encode_devs[i]; - if (!encode) continue; + if (!encode) + continue; st22_encode_dev_dump(encode); } for (int i = 0; i < ST_MAX_DECODER_DEV; i++) { decode = mgr->decode_devs[i]; - if (!decode) continue; + if (!decode) + continue; st22_decode_dev_dump(decode); } for (int i = 0; i < ST_MAX_CONVERTER_DEV; i++) { convert = mgr->convert_devs[i]; - if (!convert) continue; + if (!convert) + continue; st20_convert_dev_dump(convert); } mt_pthread_mutex_unlock(&mgr->lock); @@ -438,15 +485,15 @@ static int st_plugins_dump(void* priv) { } int st22_encoder_unregister(st22_encoder_dev_handle handle) { - struct st22_encode_dev_impl* dev = handle; + struct st22_encode_dev_impl *dev = handle; if (dev->type != MT_ST22_HANDLE_DEV_ENCODE) { err("%s, invalid type %d\n", __func__, dev->type); return -EIO; } - struct mtl_main_impl* impl = dev->parent; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); + struct mtl_main_impl *impl = dev->parent; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); int idx = dev->idx; if (mgr->encode_devs[idx] != dev) { @@ -459,7 +506,8 @@ int st22_encoder_unregister(st22_encoder_dev_handle handle) { int ref_cnt = rte_atomic32_read(&dev->ref_cnt); if (ref_cnt) { mt_pthread_mutex_unlock(&mgr->lock); - err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, ref_cnt); + err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, + ref_cnt); return -EBUSY; } mt_rte_free(dev); @@ -470,15 +518,15 @@ int st22_encoder_unregister(st22_encoder_dev_handle handle) { } int st22_decoder_unregister(st22_decoder_dev_handle handle) { - struct st22_decode_dev_impl* dev = handle; + struct st22_decode_dev_impl *dev = handle; if (dev->type != MT_ST22_HANDLE_DEV_DECODE) { err("%s, invalid type %d\n", __func__, dev->type); return -EIO; } - struct mtl_main_impl* impl = dev->parent; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); + struct mtl_main_impl *impl = dev->parent; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); int idx = dev->idx; if (mgr->decode_devs[idx] != dev) { @@ -491,7 +539,8 @@ int st22_decoder_unregister(st22_decoder_dev_handle handle) { int ref_cnt = rte_atomic32_read(&dev->ref_cnt); if (ref_cnt) { mt_pthread_mutex_unlock(&mgr->lock); - err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, ref_cnt); + err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, + ref_cnt); return -EBUSY; } mt_rte_free(dev); @@ -502,15 +551,15 @@ int st22_decoder_unregister(st22_decoder_dev_handle handle) { } int st20_converter_unregister(st20_converter_dev_handle handle) { - struct st20_convert_dev_impl* dev = handle; + struct st20_convert_dev_impl *dev = handle; if (dev->type != MT_ST20_HANDLE_DEV_CONVERT) { err("%s, invalid type %d\n", __func__, dev->type); return -EIO; } - struct mtl_main_impl* impl = dev->parent; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); + struct mtl_main_impl *impl = dev->parent; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); int idx = dev->idx; if (mgr->convert_devs[idx] != dev) { @@ -523,7 +572,8 @@ int st20_converter_unregister(st20_converter_dev_handle handle) { int ref_cnt = rte_atomic32_read(&dev->ref_cnt); if (ref_cnt) { mt_pthread_mutex_unlock(&mgr->lock); - err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, ref_cnt); + err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, + ref_cnt); return -EBUSY; } mt_rte_free(dev); @@ -534,10 +584,10 @@ int st20_converter_unregister(st20_converter_dev_handle handle) { } st22_encoder_dev_handle st22_encoder_register(mtl_handle mt, - struct st22_encoder_dev* dev) { - struct mtl_main_impl* impl = mt; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st22_encode_dev_impl* encode_dev; + struct st22_encoder_dev *dev) { + struct mtl_main_impl *impl = mt; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st22_encode_dev_impl *encode_dev; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -555,9 +605,10 @@ st22_encoder_dev_handle st22_encoder_register(mtl_handle mt, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_ENCODER_DEV; i++) { - if (mgr->encode_devs[i]) continue; - encode_dev = - mt_rte_zmalloc_socket(sizeof(*encode_dev), mt_socket_id(impl, MTL_PORT_P)); + if (mgr->encode_devs[i]) + continue; + encode_dev = mt_rte_zmalloc_socket(sizeof(*encode_dev), + mt_socket_id(impl, MTL_PORT_P)); if (!encode_dev) { err("%s, encode_dev malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->lock); @@ -575,8 +626,8 @@ st22_encoder_dev_handle st22_encoder_register(mtl_handle mt, } mgr->encode_devs[i] = encode_dev; mt_pthread_mutex_unlock(&mgr->lock); - info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", __func__, - i, encode_dev->name, dev->target_device, dev->input_fmt_caps, + info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", + __func__, i, encode_dev->name, dev->target_device, dev->input_fmt_caps, dev->output_fmt_caps); return encode_dev; } @@ -587,10 +638,10 @@ st22_encoder_dev_handle st22_encoder_register(mtl_handle mt, } st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, - struct st22_decoder_dev* dev) { - struct mtl_main_impl* impl = mt; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st22_decode_dev_impl* decode_dev; + struct st22_decoder_dev *dev) { + struct mtl_main_impl *impl = mt; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st22_decode_dev_impl *decode_dev; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -608,9 +659,10 @@ st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_DECODER_DEV; i++) { - if (mgr->decode_devs[i]) continue; - decode_dev = - mt_rte_zmalloc_socket(sizeof(*decode_dev), mt_socket_id(impl, MTL_PORT_P)); + if (mgr->decode_devs[i]) + continue; + decode_dev = mt_rte_zmalloc_socket(sizeof(*decode_dev), + mt_socket_id(impl, MTL_PORT_P)); if (!decode_dev) { err("%s, decode_dev malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->lock); @@ -628,8 +680,8 @@ st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, } mgr->decode_devs[i] = decode_dev; mt_pthread_mutex_unlock(&mgr->lock); - info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", __func__, - i, decode_dev->name, dev->target_device, dev->input_fmt_caps, + info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", + __func__, i, decode_dev->name, dev->target_device, dev->input_fmt_caps, dev->output_fmt_caps); return decode_dev; } @@ -639,11 +691,11 @@ st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, return NULL; } -st20_converter_dev_handle st20_converter_register(mtl_handle mt, - struct st20_converter_dev* dev) { - struct mtl_main_impl* impl = mt; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st20_convert_dev_impl* convert_dev; +st20_converter_dev_handle +st20_converter_register(mtl_handle mt, struct st20_converter_dev *dev) { + struct mtl_main_impl *impl = mt; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st20_convert_dev_impl *convert_dev; if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -665,9 +717,10 @@ st20_converter_dev_handle st20_converter_register(mtl_handle mt, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_CONVERTER_DEV; i++) { - if (mgr->convert_devs[i]) continue; - convert_dev = - mt_rte_zmalloc_socket(sizeof(*convert_dev), mt_socket_id(impl, MTL_PORT_P)); + if (mgr->convert_devs[i]) + continue; + convert_dev = mt_rte_zmalloc_socket(sizeof(*convert_dev), + mt_socket_id(impl, MTL_PORT_P)); if (!convert_dev) { err("%s, convert_dev malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->lock); @@ -685,9 +738,9 @@ st20_converter_dev_handle st20_converter_register(mtl_handle mt, } mgr->convert_devs[i] = convert_dev; mt_pthread_mutex_unlock(&mgr->lock); - info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", __func__, - i, convert_dev->name, dev->target_device, dev->input_fmt_caps, - dev->output_fmt_caps); + info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", + __func__, i, convert_dev->name, dev->target_device, + dev->input_fmt_caps, dev->output_fmt_caps); return convert_dev; } mt_pthread_mutex_unlock(&mgr->lock); @@ -696,11 +749,13 @@ st20_converter_dev_handle st20_converter_register(mtl_handle mt, return NULL; } -struct st22_encode_frame_meta* st22_encoder_get_frame(st22p_encode_session session) { - struct st22_encode_session_impl* session_impl = session; +struct st22_encode_frame_meta * +st22_encoder_get_frame(st22p_encode_session session) { + struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return NULL; } @@ -708,44 +763,51 @@ struct st22_encode_frame_meta* st22_encoder_get_frame(st22p_encode_session sessi } int st22_encoder_wake_block(st22p_encode_session session) { - struct st22_encode_session_impl* session_impl = session; + struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return -EIO; } return session_impl->req.wake_block(session_impl->req.priv); } -int st22_encoder_set_block_timeout(st22p_encode_session session, uint64_t timedwait_ns) { - struct st22_encode_session_impl* session_impl = session; +int st22_encoder_set_block_timeout(st22p_encode_session session, + uint64_t timedwait_ns) { + struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return -EIO; } - return session_impl->req.set_block_timeout(session_impl->req.priv, timedwait_ns); + return session_impl->req.set_block_timeout(session_impl->req.priv, + timedwait_ns); } int st22_encoder_put_frame(st22p_encode_session session, - struct st22_encode_frame_meta* frame, int result) { - struct st22_encode_session_impl* session_impl = session; + struct st22_encode_frame_meta *frame, int result) { + struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return -EIO; } return session_impl->req.put_frame(session_impl->req.priv, frame, result); } -struct st22_decode_frame_meta* st22_decoder_get_frame(st22p_decode_session session) { - struct st22_decode_session_impl* session_impl = session; +struct st22_decode_frame_meta * +st22_decoder_get_frame(st22p_decode_session session) { + struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return NULL; } @@ -753,44 +815,51 @@ struct st22_decode_frame_meta* st22_decoder_get_frame(st22p_decode_session sessi } int st22_decoder_wake_block(st22p_decode_session session) { - struct st22_decode_session_impl* session_impl = session; + struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return -EIO; } return session_impl->req.wake_block(session_impl->req.priv); } -int st22_decoder_set_block_timeout(st22p_decode_session session, uint64_t timedwait_ns) { - struct st22_decode_session_impl* session_impl = session; +int st22_decoder_set_block_timeout(st22p_decode_session session, + uint64_t timedwait_ns) { + struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return -EIO; } - return session_impl->req.set_block_timeout(session_impl->req.priv, timedwait_ns); + return session_impl->req.set_block_timeout(session_impl->req.priv, + timedwait_ns); } int st22_decoder_put_frame(st22p_decode_session session, - struct st22_decode_frame_meta* frame, int result) { - struct st22_decode_session_impl* session_impl = session; + struct st22_decode_frame_meta *frame, int result) { + struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return -EIO; } return session_impl->req.put_frame(session_impl->req.priv, frame, result); } -struct st20_convert_frame_meta* st20_converter_get_frame(st20p_convert_session session) { - struct st20_convert_session_impl* session_impl = session; +struct st20_convert_frame_meta * +st20_converter_get_frame(st20p_convert_session session) { + struct st20_convert_session_impl *session_impl = session; if (session_impl->type != MT_ST20_HANDLE_PIPELINE_CONVERT) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return NULL; } @@ -798,21 +867,23 @@ struct st20_convert_frame_meta* st20_converter_get_frame(st20p_convert_session s } int st20_converter_put_frame(st20p_convert_session session, - struct st20_convert_frame_meta* frame, int result) { - struct st20_convert_session_impl* session_impl = session; + struct st20_convert_frame_meta *frame, + int result) { + struct st20_convert_session_impl *session_impl = session; if (session_impl->type != MT_ST20_HANDLE_PIPELINE_CONVERT) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, + session_impl->type); return -EIO; } return session_impl->req.put_frame(session_impl->req.priv, frame, result); } -static struct st_dl_plugin_impl* st_plugin_by_path(struct mtl_main_impl* impl, - const char* path) { - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st_dl_plugin_impl* plugin; +static struct st_dl_plugin_impl *st_plugin_by_path(struct mtl_main_impl *impl, + const char *path) { + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st_dl_plugin_impl *plugin; mt_pthread_mutex_lock(&mgr->plugins_lock); for (int i = 0; i < ST_MAX_DL_PLUGINS; i++) { @@ -831,8 +902,8 @@ static struct st_dl_plugin_impl* st_plugin_by_path(struct mtl_main_impl* impl, } int st_get_plugins_nb(mtl_handle mt) { - struct mtl_main_impl* impl = mt; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); + struct mtl_main_impl *impl = mt; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); if (impl->type != MT_HANDLE_MAIN) { err("%s, invalid type %d\n", __func__, impl->type); @@ -842,10 +913,10 @@ int st_get_plugins_nb(mtl_handle mt) { return mgr->plugins_nb; } -int st_plugin_register(mtl_handle mt, const char* path) { - struct mtl_main_impl* impl = mt; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - void* dl_handle; +int st_plugin_register(mtl_handle mt, const char *path) { + struct mtl_main_impl *impl = mt; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + void *dl_handle; st_plugin_get_meta_fn get_meta_fn; st_plugin_create_fn create_fn; st_plugin_free_fn free_fn; @@ -915,12 +986,14 @@ int st_plugin_register(mtl_handle mt, const char* path) { return -EIO; } - struct st_dl_plugin_impl* plugin; + struct st_dl_plugin_impl *plugin; /* add to the plugins */ mt_pthread_mutex_lock(&mgr->plugins_lock); for (int i = 0; i < ST_MAX_DL_PLUGINS; i++) { - if (mgr->plugins[i]) continue; - plugin = mt_rte_zmalloc_socket(sizeof(*plugin), mt_socket_id(impl, MTL_PORT_P)); + if (mgr->plugins[i]) + continue; + plugin = + mt_rte_zmalloc_socket(sizeof(*plugin), mt_socket_id(impl, MTL_PORT_P)); if (!plugin) { mt_pthread_mutex_unlock(&mgr->plugins_lock); dlclose(dl_handle); @@ -936,7 +1009,8 @@ int st_plugin_register(mtl_handle mt, const char* path) { mgr->plugins_nb++; mgr->plugins[i] = plugin; mt_pthread_mutex_unlock(&mgr->plugins_lock); - info("%s(%d), %s registered, version %d\n", __func__, i, path, meta.version); + info("%s(%d), %s registered, version %d\n", __func__, i, path, + meta.version); return 0; } mt_pthread_mutex_unlock(&mgr->plugins_lock); @@ -946,10 +1020,10 @@ int st_plugin_register(mtl_handle mt, const char* path) { return -EIO; } -int st_plugin_unregister(mtl_handle mt, const char* path) { - struct mtl_main_impl* impl = mt; - struct st_plugin_mgr* mgr = st_get_plugins_mgr(impl); - struct st_dl_plugin_impl* plugin; +int st_plugin_unregister(mtl_handle mt, const char *path) { + struct mtl_main_impl *impl = mt; + struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); + struct st_dl_plugin_impl *plugin; mt_pthread_mutex_lock(&mgr->plugins_lock); for (int i = 0; i < ST_MAX_DL_PLUGINS; i++) { diff --git a/lib/src/st2110/pipeline/st_plugin.h b/lib/src/st2110/pipeline/st_plugin.h index e705274ca..175187b4a 100644 --- a/lib/src/st2110/pipeline/st_plugin.h +++ b/lib/src/st2110/pipeline/st_plugin.h @@ -7,23 +7,27 @@ #include "../st_main.h" -struct st22_encode_session_impl* st22_get_encoder(struct mtl_main_impl* impl, - struct st22_get_encoder_request* req); -int st22_put_encoder(struct mtl_main_impl* impl, - struct st22_encode_session_impl* encoder); +struct st22_encode_session_impl * +st22_get_encoder(struct mtl_main_impl *impl, + struct st22_get_encoder_request *req); +int st22_put_encoder(struct mtl_main_impl *impl, + struct st22_encode_session_impl *encoder); -struct st22_decode_session_impl* st22_get_decoder(struct mtl_main_impl* impl, - struct st22_get_decoder_request* req); -int st22_put_decoder(struct mtl_main_impl* impl, - struct st22_decode_session_impl* encoder); +struct st22_decode_session_impl * +st22_get_decoder(struct mtl_main_impl *impl, + struct st22_get_decoder_request *req); +int st22_put_decoder(struct mtl_main_impl *impl, + struct st22_decode_session_impl *encoder); -struct st20_convert_session_impl* st20_get_converter( - struct mtl_main_impl* impl, struct st20_get_converter_request* req); -int st20_convert_notify_frame_ready(struct st20_convert_session_impl* converter); -int st20_put_converter(struct mtl_main_impl* impl, - struct st20_convert_session_impl* converter); +struct st20_convert_session_impl * +st20_get_converter(struct mtl_main_impl *impl, + struct st20_get_converter_request *req); +int st20_convert_notify_frame_ready( + struct st20_convert_session_impl *converter); +int st20_put_converter(struct mtl_main_impl *impl, + struct st20_convert_session_impl *converter); -int st_plugins_init(struct mtl_main_impl* impl); -int st_plugins_uinit(struct mtl_main_impl* impl); +int st_plugins_init(struct mtl_main_impl *impl); +int st_plugins_uinit(struct mtl_main_impl *impl); #endif diff --git a/lib/src/st2110/st_ancillary.c b/lib/src/st2110/st_ancillary.c index 6ae7eccd9..808b03656 100644 --- a/lib/src/st2110/st_ancillary.c +++ b/lib/src/st2110/st_ancillary.c @@ -39,51 +39,66 @@ typedef union anc_udw_6e_10 { } __attribute__((__packed__)) anc_udw_6e_10_t; static uint16_t parity_tab[] = { - // 0 1 2 3 4 5 6 7 8 9 A + // 0 1 2 3 4 5 6 7 8 + // 9 A // B C D E F - /* 0 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - /* 1 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* 2 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* 3 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - /* 4 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* 5 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - /* 6 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - /* 7 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* 8 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* 9 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - /* A */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - /* B */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* C */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - /* D */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* E */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - /* F */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* 0 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, + /* 1 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* 2 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* 3 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, + /* 4 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* 5 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, + /* 6 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, + /* 7 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* 8 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* 9 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, + /* A */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, + /* B */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* C */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, + /* D */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* E */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0100, 0x0200, 0x0200, 0x0100, + /* F */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0200, 0x0100, 0x0100, 0x0200, }; static inline uint16_t get_parity_bits(uint16_t val) { return parity_tab[val & 0xFF]; } -static uint16_t st_ntohs(uint8_t* data) { - return ((data[0] << 8) | (data[1])); -} +static uint16_t st_ntohs(uint8_t *data) { return ((data[0] << 8) | (data[1])); } -static uint16_t get_10bit_udw(int idx, uint8_t* data) { +static uint16_t get_10bit_udw(int idx, uint8_t *data) { int byte_offset, bit_offset; int total_bits_offset = idx * 10; /*10 bit per field */ byte_offset = total_bits_offset / 8; @@ -94,35 +109,35 @@ static uint16_t get_10bit_udw(int idx, uint8_t* data) { uint16_t udw = 0; switch (bit_offset) { - case 0: { - anc_udw_10_6e_t val10; - val10.val = val; - udw = val10.udw; - break; - } - case 2: { - anc_udw_2e_10_4e_t val10; - val10.val = val; - udw = val10.udw; - break; - } - case 4: { - anc_udw_4e_10_2e_t val10; - val10.val = val; - udw = val10.udw; - break; - } - case 6: { - anc_udw_6e_10_t val10; - val10.val = val; - udw = val10.udw; - break; - } + case 0: { + anc_udw_10_6e_t val10; + val10.val = val; + udw = val10.udw; + break; + } + case 2: { + anc_udw_2e_10_4e_t val10; + val10.val = val; + udw = val10.udw; + break; + } + case 4: { + anc_udw_4e_10_2e_t val10; + val10.val = val; + udw = val10.udw; + break; + } + case 6: { + anc_udw_6e_10_t val10; + val10.val = val; + udw = val10.udw; + break; + } } return udw; } -static void set_10bit_udw(int idx, uint16_t udw, uint8_t* data) { +static void set_10bit_udw(int idx, uint16_t udw, uint8_t *data) { int byte_offset, bit_offset; int total_bits_offset = idx * 10; /*10 bit per field */ byte_offset = total_bits_offset / 8; @@ -131,49 +146,49 @@ static void set_10bit_udw(int idx, uint16_t udw, uint8_t* data) { // host to network conversion without load from misaligned address uint16_t val = st_ntohs(data); switch (bit_offset) { - case 0: { - anc_udw_10_6e_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } - case 2: { - anc_udw_2e_10_4e_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } - case 4: { - anc_udw_4e_10_2e_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } - case 6: { - anc_udw_6e_10_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } + case 0: { + anc_udw_10_6e_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } + case 2: { + anc_udw_2e_10_4e_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } + case 4: { + anc_udw_4e_10_2e_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } + case 6: { + anc_udw_6e_10_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } } // host to network conversion without store to misaligned address data[0] = (uint8_t)((val & 0xFF00) >> 8); data[1] = (uint8_t)(val & 0xFF); } -uint16_t st40_get_udw(uint32_t idx, uint8_t* data) { +uint16_t st40_get_udw(uint32_t idx, uint8_t *data) { return get_10bit_udw(idx, data); } -void st40_set_udw(uint32_t idx, uint16_t udw, uint8_t* data) { +void st40_set_udw(uint32_t idx, uint16_t udw, uint8_t *data) { set_10bit_udw(idx, udw, data); } -uint16_t st40_calc_checksum(uint32_t data_num, uint8_t* data) { +uint16_t st40_calc_checksum(uint32_t data_num, uint8_t *data) { uint16_t chks = 0, udw; for (uint32_t i = 0; i < data_num; i++) { udw = get_10bit_udw(i, data); diff --git a/lib/src/st2110/st_ancillary_transmitter.c b/lib/src/st2110/st_ancillary_transmitter.c index 2ea78f6aa..67db12e84 100644 --- a/lib/src/st2110/st_ancillary_transmitter.c +++ b/lib/src/st2110/st_ancillary_transmitter.c @@ -9,10 +9,10 @@ #include "st_err.h" #include "st_tx_ancillary_session.h" -static int st_ancillary_trs_tasklet_start(void* priv) { - struct st_ancillary_transmitter_impl* trs = priv; +static int st_ancillary_trs_tasklet_start(void *priv) { + struct st_ancillary_transmitter_impl *trs = priv; int idx = trs->idx; - struct st_tx_ancillary_sessions_mgr* mgr = trs->mgr; + struct st_tx_ancillary_sessions_mgr *mgr = trs->mgr; rte_atomic32_set(&mgr->transmitter_started, 1); @@ -20,17 +20,18 @@ static int st_ancillary_trs_tasklet_start(void* priv) { return 0; } -static int st_ancillary_trs_tasklet_stop(void* priv) { - struct st_ancillary_transmitter_impl* trs = priv; - struct mtl_main_impl* impl = trs->parent; - struct st_tx_ancillary_sessions_mgr* mgr = trs->mgr; +static int st_ancillary_trs_tasklet_stop(void *priv) { + struct st_ancillary_transmitter_impl *trs = priv; + struct mtl_main_impl *impl = trs->parent; + struct st_tx_ancillary_sessions_mgr *mgr = trs->mgr; int idx = trs->idx, port; rte_atomic32_set(&mgr->transmitter_started, 0); for (port = 0; port < mt_num_ports(impl); port++) { /* flush all the pkts in the tx ring desc */ - if (mgr->queue[port]) mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); + if (mgr->queue[port]) + mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); if (mgr->ring[port]) { mt_ring_dequeue_clean(mgr->ring[port]); info("%s(%d), port %d, remaining entries %d\n", __func__, idx, port, @@ -48,15 +49,17 @@ static int st_ancillary_trs_tasklet_stop(void* priv) { } /* pacing handled by session itself */ -static int st_ancillary_trs_session_tasklet(struct st_ancillary_transmitter_impl* trs, - struct st_tx_ancillary_sessions_mgr* mgr, - enum mtl_port port) { - struct rte_ring* ring = mgr->ring[port]; +static int +st_ancillary_trs_session_tasklet(struct st_ancillary_transmitter_impl *trs, + struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { + struct rte_ring *ring = mgr->ring[port]; int ret; uint16_t n; - struct rte_mbuf* pkt; + struct rte_mbuf *pkt; - if (!ring) return 0; + if (!ring) + return 0; /* check if any inflight pkts in transmitter */ pkt = trs->inflight[port]; @@ -74,7 +77,7 @@ static int st_ancillary_trs_session_tasklet(struct st_ancillary_transmitter_impl /* try to dequeue */ for (int i = 0; i < mgr->max_idx; i++) { /* try to dequeue */ - ret = rte_ring_sc_dequeue(ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(ring, (void **)&pkt); if (ret < 0) { mgr->stat_trs_ret_code[port] = -STI_TSCTRS_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; /* all done */ @@ -94,10 +97,10 @@ static int st_ancillary_trs_session_tasklet(struct st_ancillary_transmitter_impl return MTL_TASKLET_HAS_PENDING; /* may has pending pkt in the ring */ } -static int st_ancillary_trs_tasklet_handler(void* priv) { - struct st_ancillary_transmitter_impl* trs = priv; - struct mtl_main_impl* impl = trs->parent; - struct st_tx_ancillary_sessions_mgr* mgr = trs->mgr; +static int st_ancillary_trs_tasklet_handler(void *priv) { + struct st_ancillary_transmitter_impl *trs = priv; + struct mtl_main_impl *impl = trs->parent; + struct st_tx_ancillary_sessions_mgr *mgr = trs->mgr; int port; int pending = MTL_TASKLET_ALL_DONE; @@ -108,9 +111,10 @@ static int st_ancillary_trs_tasklet_handler(void* priv) { return pending; } -int st_ancillary_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_ancillary_transmitter_impl* trs) { +int st_ancillary_transmitter_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_ancillary_transmitter_impl *trs) { int idx = sch->idx; struct mtl_tasklet_ops ops; @@ -137,7 +141,7 @@ int st_ancillary_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_imp return 0; } -int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl* trs) { +int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl *trs) { int idx = trs->idx; if (trs->tasklet) { @@ -146,7 +150,8 @@ int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl* trs) { } for (int i = 0; i < mt_num_ports(trs->parent); i++) { - info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, trs->inflight_cnt[i]); + info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, + trs->inflight_cnt[i]); } return 0; } diff --git a/lib/src/st2110/st_ancillary_transmitter.h b/lib/src/st2110/st_ancillary_transmitter.h index 6628317df..54da8d70e 100644 --- a/lib/src/st2110/st_ancillary_transmitter.h +++ b/lib/src/st2110/st_ancillary_transmitter.h @@ -7,9 +7,10 @@ #include "st_main.h" -int st_ancillary_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_ancillary_transmitter_impl* trs); -int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl* trs); +int st_ancillary_transmitter_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_ancillary_transmitter_impl *trs); +int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl *trs); #endif diff --git a/lib/src/st2110/st_audio_transmitter.c b/lib/src/st2110/st_audio_transmitter.c index c37777ab7..b7a6cd1f2 100644 --- a/lib/src/st2110/st_audio_transmitter.c +++ b/lib/src/st2110/st_audio_transmitter.c @@ -9,10 +9,10 @@ #include "st_err.h" #include "st_tx_audio_session.h" -static int st_audio_trs_tasklet_start(void* priv) { - struct st_audio_transmitter_impl* trs = priv; +static int st_audio_trs_tasklet_start(void *priv) { + struct st_audio_transmitter_impl *trs = priv; int idx = trs->idx; - struct st_tx_audio_sessions_mgr* mgr = trs->mgr; + struct st_tx_audio_sessions_mgr *mgr = trs->mgr; rte_atomic32_set(&mgr->transmitter_started, 1); @@ -20,17 +20,18 @@ static int st_audio_trs_tasklet_start(void* priv) { return 0; } -static int st_audio_trs_tasklet_stop(void* priv) { - struct st_audio_transmitter_impl* trs = priv; - struct mtl_main_impl* impl = trs->parent; - struct st_tx_audio_sessions_mgr* mgr = trs->mgr; +static int st_audio_trs_tasklet_stop(void *priv) { + struct st_audio_transmitter_impl *trs = priv; + struct mtl_main_impl *impl = trs->parent; + struct st_tx_audio_sessions_mgr *mgr = trs->mgr; int idx = trs->idx, port; rte_atomic32_set(&mgr->transmitter_started, 0); for (port = 0; port < mt_num_ports(impl); port++) { /* flush all the pkts in the tx ring desc */ - if (mgr->queue[port]) mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); + if (mgr->queue[port]) + mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); if (mgr->ring[port]) { mt_ring_dequeue_clean(mgr->ring[port]); info("%s(%d), port %d, remaining entries %d\n", __func__, idx, port, @@ -47,8 +48,8 @@ static int st_audio_trs_tasklet_stop(void* priv) { return 0; } -static uint16_t st_audio_trs_burst_fail(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, +static uint16_t st_audio_trs_burst_fail(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port) { uint64_t cur_tsc = mt_get_tsc(impl); uint64_t fail_duration = cur_tsc - mgr->last_burst_succ_time_tsc[port]; @@ -63,27 +64,30 @@ static uint16_t st_audio_trs_burst_fail(struct mtl_main_impl* impl, return 0; } -static uint16_t st_audio_trs_burst(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, - enum mtl_port port, struct rte_mbuf* pkt) { - if (!mgr->queue[port]) return 0; +static uint16_t st_audio_trs_burst(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + enum mtl_port port, struct rte_mbuf *pkt) { + if (!mgr->queue[port]) + return 0; uint16_t tx = mt_txq_burst(mgr->queue[port], &pkt, 1); - if (!tx) return st_audio_trs_burst_fail(impl, mgr, port); + if (!tx) + return st_audio_trs_burst_fail(impl, mgr, port); mgr->last_burst_succ_time_tsc[port] = mt_get_tsc(impl); return tx; } /* pacing handled by session itself */ -static int st_audio_trs_session_tasklet(struct mtl_main_impl* impl, - struct st_audio_transmitter_impl* trs, - struct st_tx_audio_sessions_mgr* mgr, +static int st_audio_trs_session_tasklet(struct mtl_main_impl *impl, + struct st_audio_transmitter_impl *trs, + struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port) { - struct rte_ring* ring = mgr->ring[port]; + struct rte_ring *ring = mgr->ring[port]; int ret; uint16_t n; - struct rte_mbuf* pkt; + struct rte_mbuf *pkt; - if (!ring) return 0; + if (!ring) + return 0; /* check if any inflight pkts in transmitter */ pkt = trs->inflight[port]; @@ -100,7 +104,7 @@ static int st_audio_trs_session_tasklet(struct mtl_main_impl* impl, for (int i = 0; i < mgr->max_idx; i++) { /* try to dequeue */ - ret = rte_ring_sc_dequeue(ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(ring, (void **)&pkt); if (ret < 0) { mgr->stat_trs_ret_code[port] = -STI_TSCTRS_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; /* all done */ @@ -120,10 +124,10 @@ static int st_audio_trs_session_tasklet(struct mtl_main_impl* impl, return MTL_TASKLET_HAS_PENDING; /* may has pending pkt in the ring */ } -static int st_audio_trs_tasklet_handler(void* priv) { - struct st_audio_transmitter_impl* trs = priv; - struct mtl_main_impl* impl = trs->parent; - struct st_tx_audio_sessions_mgr* mgr = trs->mgr; +static int st_audio_trs_tasklet_handler(void *priv) { + struct st_audio_transmitter_impl *trs = priv; + struct mtl_main_impl *impl = trs->parent; + struct st_tx_audio_sessions_mgr *mgr = trs->mgr; int pending = MTL_TASKLET_ALL_DONE; for (int port = 0; port < mt_num_ports(impl); port++) { @@ -133,9 +137,10 @@ static int st_audio_trs_tasklet_handler(void* priv) { return pending; } -int st_audio_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_tx_audio_sessions_mgr* mgr, - struct st_audio_transmitter_impl* trs) { +int st_audio_transmitter_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_audio_sessions_mgr *mgr, + struct st_audio_transmitter_impl *trs) { int idx = sch->idx; struct mtl_tasklet_ops ops; @@ -163,7 +168,7 @@ int st_audio_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* s return 0; } -int st_audio_transmitter_uinit(struct st_audio_transmitter_impl* trs) { +int st_audio_transmitter_uinit(struct st_audio_transmitter_impl *trs) { int idx = trs->idx; if (trs->tasklet) { @@ -172,7 +177,8 @@ int st_audio_transmitter_uinit(struct st_audio_transmitter_impl* trs) { } for (int i = 0; i < mt_num_ports(trs->parent); i++) { - info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, trs->inflight_cnt[i]); + info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, + trs->inflight_cnt[i]); } return 0; } diff --git a/lib/src/st2110/st_audio_transmitter.h b/lib/src/st2110/st_audio_transmitter.h index 8962d15ef..b2347d10b 100644 --- a/lib/src/st2110/st_audio_transmitter.h +++ b/lib/src/st2110/st_audio_transmitter.h @@ -7,12 +7,14 @@ #include "st_main.h" -int st_audio_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_tx_audio_sessions_mgr* mgr, - struct st_audio_transmitter_impl* trs); -int st_audio_transmitter_uinit(struct st_audio_transmitter_impl* trs); +int st_audio_transmitter_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_audio_sessions_mgr *mgr, + struct st_audio_transmitter_impl *trs); +int st_audio_transmitter_uinit(struct st_audio_transmitter_impl *trs); -int st_audio_queue_fatal_error(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, enum mtl_port port); +int st_audio_queue_fatal_error(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + enum mtl_port port); #endif diff --git a/lib/src/st2110/st_avx2.c b/lib/src/st2110/st_avx2.c index 232fba7b2..fbae90ccf 100644 --- a/lib/src/st2110/st_avx2.c +++ b/lib/src/st2110/st_avx2.c @@ -48,38 +48,42 @@ static uint8_t rfc4175_b2l_shuffle_r1_tbl[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422be10_to_422le10_avx2(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h) { - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)rfc4175_b2l_shuffle_l0_tbl); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)rfc4175_b2l_shuffle_r0_tbl); - __m128i and_l0 = _mm_loadu_si128((__m128i*)rfc4175_b2l_and_l0_tbl); - __m128i and_r0 = _mm_loadu_si128((__m128i*)rfc4175_b2l_and_r0_tbl); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)rfc4175_b2l_shuffle_l1_tbl); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)rfc4175_b2l_shuffle_r1_tbl); +int st20_rfc4175_422be10_to_422le10_avx2( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)rfc4175_b2l_shuffle_l0_tbl); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)rfc4175_b2l_shuffle_r0_tbl); + __m128i and_l0 = _mm_loadu_si128((__m128i *)rfc4175_b2l_and_l0_tbl); + __m128i and_r0 = _mm_loadu_si128((__m128i *)rfc4175_b2l_and_r0_tbl); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)rfc4175_b2l_shuffle_l1_tbl); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)rfc4175_b2l_shuffle_r1_tbl); int pg_cnt = w * h / 2; int batch = pg_cnt / 3; int left = pg_cnt % 3; dbg("%s, pg_cnt %d batch %d left %d\n", __func__, pg_cnt, batch, left); - /* jump the last batch, for the Xmm may access invalid memory in the last byte */ + /* jump the last batch, for the Xmm may access invalid memory in the last byte + */ if (batch != 0 && left == 0) { left = 3; batch -= 1; } - /* jump the last batch, for the Xmm may access invalid memory in the last byte */ + /* jump the last batch, for the Xmm may access invalid memory in the last byte + */ for (int i = 0; i < batch; i++) { - __m128i input = _mm_loadu_si128((__m128i*)pg_be); + __m128i input = _mm_loadu_si128((__m128i *)pg_be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i sl_result = _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); - __m128i sr_result = _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); + __m128i sl_result = + _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); + __m128i sr_result = + _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); __m128i sl_result_shuffle = _mm_shuffle_epi8(sl_result, shuffle_l1); __m128i sr_result_shuffle = _mm_shuffle_epi8(sr_result, shuffle_r1); __m128i result = _mm_or_si128(sl_result_shuffle, sr_result_shuffle); - _mm_storeu_si128((__m128i*)pg_le, result); + _mm_storeu_si128((__m128i *)pg_le, result); pg_be += 3; pg_le += 3; @@ -153,38 +157,42 @@ static uint8_t rfc4175_l2b_shuffle_r1_tbl[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422le10_to_422be10_avx2(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)rfc4175_l2b_shuffle_l0_tbl); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)rfc4175_l2b_shuffle_r0_tbl); - __m128i and_l0 = _mm_loadu_si128((__m128i*)rfc4175_l2b_and_l0_tbl); - __m128i and_r0 = _mm_loadu_si128((__m128i*)rfc4175_l2b_and_r0_tbl); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)rfc4175_l2b_shuffle_l1_tbl); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)rfc4175_l2b_shuffle_r1_tbl); +int st20_rfc4175_422le10_to_422be10_avx2( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)rfc4175_l2b_shuffle_l0_tbl); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)rfc4175_l2b_shuffle_r0_tbl); + __m128i and_l0 = _mm_loadu_si128((__m128i *)rfc4175_l2b_and_l0_tbl); + __m128i and_r0 = _mm_loadu_si128((__m128i *)rfc4175_l2b_and_r0_tbl); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)rfc4175_l2b_shuffle_l1_tbl); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)rfc4175_l2b_shuffle_r1_tbl); int pg_cnt = w * h / 2; int batch = pg_cnt / 3; int left = pg_cnt % 3; dbg("%s, pg_cnt %d batch %d left %d\n", __func__, pg_cnt, batch, left); - /* jump the last batch, for the Xmm may access invalid memory in the last byte */ + /* jump the last batch, for the Xmm may access invalid memory in the last byte + */ if (batch != 0 && left == 0) { left = 3; batch -= 1; } - /* jump the last batch, for the Xmm may access invalid memory in the last byte */ + /* jump the last batch, for the Xmm may access invalid memory in the last byte + */ for (int i = 0; i < batch; i++) { - __m128i input = _mm_loadu_si128((__m128i*)pg_le); + __m128i input = _mm_loadu_si128((__m128i *)pg_le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i sl_result = _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); - __m128i sr_result = _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); + __m128i sl_result = + _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); + __m128i sr_result = + _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); __m128i sl_result_shuffle = _mm_shuffle_epi8(sl_result, shuffle_l1); __m128i sr_result_shuffle = _mm_shuffle_epi8(sr_result, shuffle_r1); __m128i result = _mm_or_si128(sl_result_shuffle, sr_result_shuffle); - _mm_storeu_si128((__m128i*)pg_be, result); + _mm_storeu_si128((__m128i *)pg_be, result); pg_be += 3; pg_le += 3; diff --git a/lib/src/st2110/st_avx2.h b/lib/src/st2110/st_avx2.h index 459708ca2..f792c1c7f 100644 --- a/lib/src/st2110/st_avx2.h +++ b/lib/src/st2110/st_avx2.h @@ -7,12 +7,12 @@ #include "st_main.h" -int st20_rfc4175_422be10_to_422le10_avx2(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx2( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h); -int st20_rfc4175_422le10_to_422be10_avx2(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); +int st20_rfc4175_422le10_to_422be10_avx2( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); #endif \ No newline at end of file diff --git a/lib/src/st2110/st_avx512.c b/lib/src/st2110/st_avx512.c index 5856ee2db..43249ed0d 100644 --- a/lib/src/st2110/st_avx512.c +++ b/lib/src/st2110/st_avx512.c @@ -33,23 +33,27 @@ static uint32_t be10_to_ple_permute_tbl_512[16] = { 0, 4, 8, 12, 1, 5, 9, 13, 2, 3, 6, 7, 10, 11, 14, 15, }; -int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = _mm_loadu_si128((__m128i*)be10_to_ple_shuffle_tbl_128); - __m128i srlv_le_mask = _mm_loadu_si128((__m128i*)be10_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = _mm_loadu_si128((__m128i*)be10_to_ple_and_mask_tbl_128); - __m512i permute_mask = _mm512_loadu_si512((__m512i*)be10_to_ple_permute_tbl_512); +int st20_rfc4175_422be10_to_yuv422p10le_avx512( + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h) { + __m128i shuffle_le_mask = + _mm_loadu_si128((__m128i *)be10_to_ple_shuffle_tbl_128); + __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be10_to_ple_srlv_tbl_128); + __m128i srlv_and_mask = + _mm_loadu_si128((__m128i *)be10_to_ple_and_mask_tbl_128); + __m512i permute_mask = + _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); - /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group */ + /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group + */ while (pg_cnt >= 32) { /* cvt the result to __m128i(2 pg group) */ __m128i stage_m128i[16]; for (int j = 0; j < 16; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); @@ -58,33 +62,39 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be /* shift result to m128i */ __m512i stage_m512i[4]; for (int j = 0; j < 4; j++) { - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ - __m512i input_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[j * 4]); - /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} + */ + __m512i input_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} + */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); } /* shift m128i to m512i */ /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[1]); + result_m512i[1] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[3]); + result_m512i[3] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b10001000); - _mm512_storeu_si512((__m512i*)b, b_result_m512i); + _mm512_storeu_si512((__m512i *)b, b_result_m512i); b += 32; __m512i r_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b11011101); - _mm512_storeu_si512((__m512i*)r, r_result_m512i); + _mm512_storeu_si512((__m512i *)r, r_result_m512i); r += 32; pg_cnt -= 32; @@ -94,14 +104,14 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be while (pg_cnt >= 8) { __m128i stage_m128i[4]; for (int j = 0; j < 4; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg += 2; } // {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} - __m512i stage_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[0]); + __m512i stage_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[0]); /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ __m512i permute = _mm512_permutexvar_epi32(permute_mask, stage_m512i); @@ -110,13 +120,13 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be __m128i result_Y0 = _mm512_extracti32x4_epi32(permute, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(permute, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; pg_cnt -= 8; @@ -137,13 +147,16 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be } int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = _mm_loadu_si128((__m128i*)be10_to_ple_shuffle_tbl_128); - __m128i srlv_le_mask = _mm_loadu_si128((__m128i*)be10_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = _mm_loadu_si128((__m128i*)be10_to_ple_and_mask_tbl_128); - __m512i permute_mask = _mm512_loadu_si512((__m512i*)be10_to_ple_permute_tbl_512); + __m128i shuffle_le_mask = + _mm_loadu_si128((__m128i *)be10_to_ple_shuffle_tbl_128); + __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be10_to_ple_srlv_tbl_128); + __m128i srlv_and_mask = + _mm_loadu_si128((__m128i *)be10_to_ple_and_mask_tbl_128); + __m512i permute_mask = + _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; @@ -154,24 +167,26 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_yuv422p10le_avx512(pg_be, y, b, r, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -180,7 +195,8 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -192,51 +208,61 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* pg = be_cache; + struct st20_rfc4175_422_10_pg2_be *pg = be_cache; int batch = cache_pg_cnt / 32; for (int j = 0; j < batch; j++) { /* cvt the result to __m128i(2 pg group) */ __m128i stage_m128i[16]; for (int j = 0; j < 16; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); - __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); + __m128i srlv_le_result = + _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg += 2; } /* shift result to m128i */ __m512i stage_m512i[4]; for (int j = 0; j < 4; j++) { - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ - __m512i input_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[j * 4]); - /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, + * Y7} */ + __m512i input_m512i = + _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, + * Y7} */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); } /* shift m128i to m512i */ - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} + */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[1]); + result_m512i[1] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[3]); + result_m512i[3] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b10001000); - _mm512_storeu_si512((__m512i*)b, b_result_m512i); + _mm512_storeu_si512((__m512i *)b, b_result_m512i); b += 32; __m512i r_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b11011101); - _mm512_storeu_si512((__m512i*)r, r_result_m512i); + _mm512_storeu_si512((__m512i *)r, r_result_m512i); r += 32; } } @@ -247,12 +273,13 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( /* remaining simd batch */ int batch = pg_cnt / 32; - /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group */ + /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group + */ for (int i = 0; i < batch; i++) { /* cvt the result to __m128i(2 pg group) */ __m128i stage_m128i[16]; for (int j = 0; j < 16; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); @@ -261,33 +288,39 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( /* shift result to m128i */ __m512i stage_m512i[4]; for (int j = 0; j < 4; j++) { - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ - __m512i input_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[j * 4]); - /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} + */ + __m512i input_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} + */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); } /* shift m128i to m512i */ /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[1]); + result_m512i[1] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[3]); + result_m512i[3] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b10001000); - _mm512_storeu_si512((__m512i*)b, b_result_m512i); + _mm512_storeu_si512((__m512i *)b, b_result_m512i); b += 32; __m512i r_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b11011101); - _mm512_storeu_si512((__m512i*)r, r_result_m512i); + _mm512_storeu_si512((__m512i *)r, r_result_m512i); r += 32; } pg_cnt = pg_cnt % 32; @@ -297,14 +330,14 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( for (int i = 0; i < batch; i++) { __m128i stage_m128i[4]; for (int j = 0; j < 4; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg_be += 2; } // {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} - __m512i stage_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[0]); + __m512i stage_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[0]); /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ __m512i permute = _mm512_permutexvar_epi32(permute_mask, stage_m512i); @@ -313,13 +346,13 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( __m128i result_Y0 = _mm512_extracti32x4_epi32(permute, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(permute, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; } pg_cnt = pg_cnt % 8; @@ -378,15 +411,19 @@ static uint8_t be10_to_le_shuffle_r1_tbl_128[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422be10_to_422le10_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h) { - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_l0_tbl_128); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_r0_tbl_128); - __m128i and_l0 = _mm_loadu_si128((__m128i*)be10_to_and_l0_tbl_128); - __m128i and_r0 = _mm_loadu_si128((__m128i*)be10_to_le_and_r0_tbl_128); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_l1_tbl_128); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_r1_tbl_128); +int st20_rfc4175_422be10_to_422le10_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { + __m128i shuffle_l0 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l0_tbl_128); + __m128i shuffle_r0 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r0_tbl_128); + __m128i and_l0 = _mm_loadu_si128((__m128i *)be10_to_and_l0_tbl_128); + __m128i and_r0 = _mm_loadu_si128((__m128i *)be10_to_le_and_r0_tbl_128); + __m128i shuffle_l1 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l1_tbl_128); + __m128i shuffle_r1 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r1_tbl_128); __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; @@ -394,17 +431,19 @@ int st20_rfc4175_422be10_to_422le10_avx512(struct st20_rfc4175_422_10_pg2_be* pg int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = + _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = + _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_le, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_le, k, result); pg_be += 3; pg_le += 3; @@ -435,17 +474,20 @@ int st20_rfc4175_422be10_to_422le10_avx512(struct st20_rfc4175_422_10_pg2_be* pg return 0; } -int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h) { - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_l0_tbl_128); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_r0_tbl_128); - __m128i and_l0 = _mm_loadu_si128((__m128i*)be10_to_and_l0_tbl_128); - __m128i and_r0 = _mm_loadu_si128((__m128i*)be10_to_le_and_r0_tbl_128); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_l1_tbl_128); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)be10_to_le_shuffle_r1_tbl_128); +int st20_rfc4175_422be10_to_422le10_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, + uint32_t h) { + __m128i shuffle_l0 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l0_tbl_128); + __m128i shuffle_r0 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r0_tbl_128); + __m128i and_l0 = _mm_loadu_si128((__m128i *)be10_to_and_l0_tbl_128); + __m128i and_r0 = _mm_loadu_si128((__m128i *)be10_to_le_and_r0_tbl_128); + __m128i shuffle_l1 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l1_tbl_128); + __m128i shuffle_r1 = + _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r1_tbl_128); __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; @@ -456,24 +498,26 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le10_avx512(pg_be, pg_le, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -482,7 +526,8 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev* dma, int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -494,23 +539,26 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* be = be_cache; + struct st20_rfc4175_422_10_pg2_be *be = be_cache; int batch = cache_pg_cnt / 3; for (int j = 0; j < batch; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = + _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = + _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_le, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_le, k, result); be += 3; pg_le += 3; @@ -524,17 +572,19 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = + _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = + _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_le, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_le, k, result); pg_be += 3; pg_le += 3; @@ -580,23 +630,25 @@ static uint8_t be10_to_le8_shuffle1_tbl_128[16] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, /* zeros */ }; -int st20_rfc4175_422be10_to_422le8_avx512(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h) { - __m128i shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle0_tbl_128); - __m128i sllv_mask = _mm_loadu_si128((__m128i*)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle1_tbl_128); +int st20_rfc4175_422be10_to_422le8_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { + __m128i shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); + __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); + __m128i sllv_shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); while (pg_cnt >= 2) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_10); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_10); __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); __m128i result = _mm_shuffle_epi8(sllv_result, sllv_shuffle_mask); - _mm_storel_epi64((__m128i*)pg_8, result); + _mm_storel_epi64((__m128i *)pg_8, result); pg_10 += 2; pg_8 += 2; @@ -618,14 +670,15 @@ int st20_rfc4175_422be10_to_422le8_avx512(struct st20_rfc4175_422_10_pg2_be* pg_ return 0; } -int st20_rfc4175_422be10_to_422le8_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_10, - mtl_iova_t pg_10_iova, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h) { - __m128i shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle0_tbl_128); - __m128i sllv_mask = _mm_loadu_si128((__m128i*)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle1_tbl_128); +int st20_rfc4175_422be10_to_422le8_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, + uint32_t h) { + __m128i shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); + __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); + __m128i sllv_shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); @@ -637,25 +690,27 @@ int st20_rfc4175_422be10_to_422le8_avx512_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sizeof(*pg_10); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be10_caches = + struct st20_rfc4175_422_10_pg2_be *be10_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); /* two type be(0) or le(1) */ - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be10_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be10_caches); - if (be10_caches) mt_rte_free(be10_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be10_caches); + if (be10_caches) + mt_rte_free(be10_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le8_avx512(pg_10, pg_8, w, h); } rte_iova_t be10_caches_iova = rte_malloc_virt2iova(be10_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be10_cache = + struct st20_rfc4175_422_10_pg2_be *be10_cache = be10_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -677,17 +732,18 @@ int st20_rfc4175_422be10_to_422le8_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* be_10 = be10_cache; + struct st20_rfc4175_422_10_pg2_be *be_10 = be10_cache; int batch = cache_pg_cnt / 2; for (int j = 0; j < batch; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)be_10); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)be_10); __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); __m128i result = _mm_shuffle_epi8(sllv_result, sllv_shuffle_mask); - _mm_storel_epi64((__m128i*)pg_8, result); + _mm_storel_epi64((__m128i *)pg_8, result); be_10 += 2; pg_8 += 2; @@ -701,12 +757,12 @@ int st20_rfc4175_422be10_to_422le8_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 2; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_10); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_10); __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); __m128i result = _mm_shuffle_epi8(sllv_result, sllv_shuffle_mask); - _mm_storel_epi64((__m128i*)pg_8, result); + _mm_storel_epi64((__m128i *)pg_8, result); pg_10 += 2; pg_8 += 2; @@ -737,13 +793,15 @@ static uint8_t p8_uyvy2uvyy_mask[16] = { 9, 11, 13, 15, /* y1 */ }; -int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h) { - __m128i shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle0_tbl_128); - __m128i sllv_mask = _mm_loadu_si128((__m128i*)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle1_tbl_128); - __m128i uyvy2uvyy_mask = _mm_loadu_si128((__m128i*)p8_uyvy2uvyy_mask); +int st20_rfc4175_422be10_to_yuv422p8_avx512( + struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { + __m128i shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); + __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); + __m128i sllv_shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); + __m128i uyvy2uvyy_mask = _mm_loadu_si128((__m128i *)p8_uyvy2uvyy_mask); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); @@ -752,14 +810,14 @@ int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be* p __m128i uvyy[4]; for (int step = 0; step < 4; step++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); pg += 2; __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); /* uyvy uyvy .... .... */ __m128i uyvy_t1 = _mm_shuffle_epi8(sllv_result, sllv_shuffle_mask); - input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); pg += 2; shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); @@ -775,10 +833,10 @@ int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be* p /* merge all u v y from u0v0y0y1, u1v1y2y3, u2v2y4y5, u3v3y6y7*/ /* merge y */ __m128i y0y1y2y3 = _mm_unpackhi_epi64(uvyy[0], uvyy[1]); - _mm_storeu_si128((__m128i*)y, y0y1y2y3); + _mm_storeu_si128((__m128i *)y, y0y1y2y3); y += 16; __m128i y4y5y6y7 = _mm_unpackhi_epi64(uvyy[2], uvyy[3]); - _mm_storeu_si128((__m128i*)y, y4y5y6y7); + _mm_storeu_si128((__m128i *)y, y4y5y6y7); y += 16; /* merge b and r */ __m128i u0v0u1v1 = _mm_unpacklo_epi64(uvyy[0], uvyy[1]); @@ -786,10 +844,10 @@ int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be* p __m128i u0u2v0v2 = _mm_unpacklo_epi32(u0v0u1v1, u2v2u3v3); __m128i u1u3v1v3 = _mm_unpackhi_epi32(u0v0u1v1, u2v2u3v3); __m128i u0u1u2u3 = _mm_unpacklo_epi32(u0u2v0v2, u1u3v1v3); - _mm_storeu_si128((__m128i*)b, u0u1u2u3); + _mm_storeu_si128((__m128i *)b, u0u1u2u3); b += 16; __m128i v0v1v2v3 = _mm_unpackhi_epi32(u0u2v0v2, u1u3v1v3); - _mm_storeu_si128((__m128i*)r, v0v1v2v3); + _mm_storeu_si128((__m128i *)r, v0v1v2v3); r += 16; pg_cnt -= 16; @@ -808,13 +866,15 @@ int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be* p return 0; } -int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h) { - __m128i shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle0_tbl_128); - __m128i sllv_mask = _mm_loadu_si128((__m128i*)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_le8_shuffle1_tbl_128); - __m128i uyvy2uvyy_mask = _mm_loadu_si128((__m128i*)p8_uyvy2uvyy_mask); +int st20_rfc4175_422be10_to_yuv420p8_avx512( + struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { + __m128i shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); + __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); + __m128i sllv_shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); + __m128i uyvy2uvyy_mask = _mm_loadu_si128((__m128i *)p8_uyvy2uvyy_mask); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ uint32_t line_pg_cnt = w / 2; /* two pgs in one convert */ @@ -827,14 +887,14 @@ int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be* p __m128i uvyy[4]; for (int step = 0; step < 4; step++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); pg += 2; __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); /* uyvy uyvy .... .... */ __m128i uyvy_t1 = _mm_shuffle_epi8(sllv_result, sllv_shuffle_mask); - input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); pg += 2; shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); @@ -850,10 +910,10 @@ int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be* p /* merge all u v y from u0v0y0y1, u1v1y2y3, u2v2y4y5, u3v3y6y7*/ /* merge y */ __m128i y0y1y2y3 = _mm_unpackhi_epi64(uvyy[0], uvyy[1]); - _mm_storeu_si128((__m128i*)y, y0y1y2y3); + _mm_storeu_si128((__m128i *)y, y0y1y2y3); y += 16; __m128i y4y5y6y7 = _mm_unpackhi_epi64(uvyy[2], uvyy[3]); - _mm_storeu_si128((__m128i*)y, y4y5y6y7); + _mm_storeu_si128((__m128i *)y, y4y5y6y7); y += 16; /* merge b and r */ __m128i u0v0u1v1 = _mm_unpacklo_epi64(uvyy[0], uvyy[1]); @@ -861,10 +921,10 @@ int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be* p __m128i u0u2v0v2 = _mm_unpacklo_epi32(u0v0u1v1, u2v2u3v3); __m128i u1u3v1v3 = _mm_unpackhi_epi32(u0v0u1v1, u2v2u3v3); __m128i u0u1u2u3 = _mm_unpacklo_epi32(u0u2v0v2, u1u3v1v3); - _mm_storeu_si128((__m128i*)b, u0u1u2u3); + _mm_storeu_si128((__m128i *)b, u0u1u2u3); b += 16; __m128i v0v1v2v3 = _mm_unpackhi_epi32(u0u2v0v2, u1u3v1v3); - _mm_storeu_si128((__m128i*)r, v0v1v2v3); + _mm_storeu_si128((__m128i *)r, v0v1v2v3); r += 16; pg_cnt -= 16; @@ -885,14 +945,14 @@ int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be* p __m128i uvyy[4]; for (int step = 0; step < 4; step++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); pg += 2; __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); /* uyvy uyvy .... .... */ __m128i uyvy_t1 = _mm_shuffle_epi8(sllv_result, sllv_shuffle_mask); - input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); pg += 2; shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); @@ -908,10 +968,10 @@ int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be* p /* merge all u v y from u0v0y0y1, u1v1y2y3, u2v2y4y5, u3v3y6y7*/ /* merge y */ __m128i y0y1y2y3 = _mm_unpackhi_epi64(uvyy[0], uvyy[1]); - _mm_storeu_si128((__m128i*)y, y0y1y2y3); + _mm_storeu_si128((__m128i *)y, y0y1y2y3); y += 16; __m128i y4y5y6y7 = _mm_unpackhi_epi64(uvyy[2], uvyy[3]); - _mm_storeu_si128((__m128i*)y, y4y5y6y7); + _mm_storeu_si128((__m128i *)y, y4y5y6y7); y += 16; pg_cnt -= 16; @@ -949,32 +1009,34 @@ static uint8_t le10_to_v210_and_tbl_128[16] = { 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, }; -int st20_rfc4175_422le10_to_v210_avx512(uint8_t* pg_le, uint8_t* pg_v210, uint32_t w, - uint32_t h) { - __m128i shuffle_r_mask = _mm_loadu_si128((__m128i*)le10_to_v210_shuffle_r_tbl_128); - __m128i srlv_mask = _mm_loadu_si128((__m128i*)le10_to_v210_srlv_tbl_128); - __m128i sllv_mask = _mm_loadu_si128((__m128i*)le10_to_v210_sllv_tbl_128); - __m128i padding_mask = _mm_loadu_si128((__m128i*)le10_to_v210_and_tbl_128); +int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, + uint32_t w, uint32_t h) { + __m128i shuffle_r_mask = + _mm_loadu_si128((__m128i *)le10_to_v210_shuffle_r_tbl_128); + __m128i srlv_mask = _mm_loadu_si128((__m128i *)le10_to_v210_srlv_tbl_128); + __m128i sllv_mask = _mm_loadu_si128((__m128i *)le10_to_v210_sllv_tbl_128); + __m128i padding_mask = _mm_loadu_si128((__m128i *)le10_to_v210_and_tbl_128); __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ __mmask16 k_mov = 0x0880; int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", + __func__, pg_cnt); return -EINVAL; } int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_le); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_le); __m128i shuffle_l_result = _mm_maskz_mov_epi8(k_mov, input); __m128i shuffle_r_result = _mm_shuffle_epi8(input, shuffle_r_mask); __m128i sllv_result = _mm_sllv_epi32(shuffle_l_result, sllv_mask); __m128i srlv_result = _mm_srlv_epi32(shuffle_r_result, srlv_mask); - __m128i result = _mm_and_si128(_mm_or_si128(sllv_result, srlv_result), padding_mask); + __m128i result = + _mm_and_si128(_mm_or_si128(sllv_result, srlv_result), padding_mask); - _mm_store_si128((__m128i*)pg_v210, result); + _mm_store_si128((__m128i *)pg_v210, result); pg_le += 15; pg_v210 += 16; @@ -1017,28 +1079,31 @@ static uint8_t be10_to_v210_and1_tbl_128[16] = { 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, }; -int st20_rfc4175_422be10_to_v210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210, uint32_t w, uint32_t h) { - __m128i shuffle0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_shuffle0_tbl_128); - __m128i sllv0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_sllv0_tbl_128); - __m128i srlv0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_srlv0_tbl_128); - __m128i and0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_and0_tbl_128); - __m128i shuffle1_mask = _mm_loadu_si128((__m128i*)be10_to_v210_shuffle1_tbl_128); - __m128i srlv1_mask = _mm_loadu_si128((__m128i*)be10_to_v210_srlv1_tbl_128); - __m128i and1_mask = _mm_loadu_si128((__m128i*)be10_to_v210_and1_tbl_128); +int st20_rfc4175_422be10_to_v210_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, + uint32_t h) { + __m128i shuffle0_mask = + _mm_loadu_si128((__m128i *)be10_to_v210_shuffle0_tbl_128); + __m128i sllv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_sllv0_tbl_128); + __m128i srlv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv0_tbl_128); + __m128i and0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and0_tbl_128); + __m128i shuffle1_mask = + _mm_loadu_si128((__m128i *)be10_to_v210_shuffle1_tbl_128); + __m128i srlv1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv1_tbl_128); + __m128i and1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and1_tbl_128); __mmask16 k_load = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", + __func__, pg_cnt); return -EINVAL; } int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i *)pg_be); __m128i shuffle0_result = _mm_shuffle_epi8(input, shuffle0_mask); __m128i sllv0_result = _mm_sllv_epi16(shuffle0_result, sllv0_mask); __m128i srlv0_result = _mm_srlv_epi16(sllv0_result, srlv0_mask); @@ -1048,7 +1113,7 @@ int st20_rfc4175_422be10_to_v210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be __m128i and1_result = _mm_and_si128(srlv1_result, and1_mask); __m128i result = _mm_or_si128(and0_result, and1_result); - _mm_store_si128((__m128i*)pg_v210, result); + _mm_store_si128((__m128i *)pg_v210, result); pg_be += 3; pg_v210 += 16; @@ -1057,24 +1122,25 @@ int st20_rfc4175_422be10_to_v210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be return 0; } -int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint8_t* pg_v210, - uint32_t w, uint32_t h) { - __m128i shuffle0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_shuffle0_tbl_128); - __m128i sllv0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_sllv0_tbl_128); - __m128i srlv0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_srlv0_tbl_128); - __m128i and0_mask = _mm_loadu_si128((__m128i*)be10_to_v210_and0_tbl_128); - __m128i shuffle1_mask = _mm_loadu_si128((__m128i*)be10_to_v210_shuffle1_tbl_128); - __m128i srlv1_mask = _mm_loadu_si128((__m128i*)be10_to_v210_srlv1_tbl_128); - __m128i and1_mask = _mm_loadu_si128((__m128i*)be10_to_v210_and1_tbl_128); +int st20_rfc4175_422be10_to_v210_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h) { + __m128i shuffle0_mask = + _mm_loadu_si128((__m128i *)be10_to_v210_shuffle0_tbl_128); + __m128i sllv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_sllv0_tbl_128); + __m128i srlv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv0_tbl_128); + __m128i and0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and0_tbl_128); + __m128i shuffle1_mask = + _mm_loadu_si128((__m128i *)be10_to_v210_shuffle1_tbl_128); + __m128i srlv1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv1_tbl_128); + __m128i and1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and1_tbl_128); __mmask16 k_load = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", + __func__, pg_cnt); return -EINVAL; } @@ -1085,24 +1151,26 @@ int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_v210_avx512(pg_be, pg_v210, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -1111,7 +1179,8 @@ int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -1123,13 +1192,14 @@ int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* be = be_cache; + struct st20_rfc4175_422_10_pg2_be *be = be_cache; int batch = cache_pg_cnt / 3; for (int j = 0; j < batch; j++) { - __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i*)be); + __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i *)be); __m128i shuffle0_result = _mm_shuffle_epi8(input, shuffle0_mask); __m128i sllv0_result = _mm_sllv_epi16(shuffle0_result, sllv0_mask); __m128i srlv0_result = _mm_srlv_epi16(sllv0_result, srlv0_mask); @@ -1139,7 +1209,7 @@ int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, __m128i and1_result = _mm_and_si128(srlv1_result, and1_mask); __m128i result = _mm_or_si128(and0_result, and1_result); - _mm_store_si128((__m128i*)pg_v210, result); + _mm_store_si128((__m128i *)pg_v210, result); be += 3; pg_v210 += 16; @@ -1153,7 +1223,7 @@ int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i *)pg_be); __m128i shuffle0_result = _mm_shuffle_epi8(input, shuffle0_mask); __m128i sllv0_result = _mm_sllv_epi16(shuffle0_result, sllv0_mask); __m128i srlv0_result = _mm_srlv_epi16(sllv0_result, srlv0_mask); @@ -1163,7 +1233,7 @@ int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, __m128i and1_result = _mm_and_si128(srlv1_result, and1_mask); __m128i result = _mm_or_si128(and0_result, and1_result); - _mm_store_si128((__m128i*)pg_v210, result); + _mm_store_si128((__m128i *)pg_v210, result); pg_be += 3; pg_v210 += 16; @@ -1191,25 +1261,27 @@ static uint8_t ple_to_be10_shuffle_lo_tbl_128[16] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, }; -int st20_yuv422p10le_to_rfc4175_422be10_avx512(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h) { +int st20_yuv422p10le_to_rfc4175_422be10_avx512( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { uint32_t pg_cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; - __m128i sllv_le_mask = _mm_loadu_si128((__m128i*)ple_to_be10_sllv_tbl_128); - __m128i shuffle_hi_mask = _mm_loadu_si128((__m128i*)ple_to_be10_shuffle_hi_tbl_128); - __m128i shuffle_lo_mask = _mm_loadu_si128((__m128i*)ple_to_be10_shuffle_lo_tbl_128); + __m128i sllv_le_mask = _mm_loadu_si128((__m128i *)ple_to_be10_sllv_tbl_128); + __m128i shuffle_hi_mask = + _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_hi_tbl_128); + __m128i shuffle_lo_mask = + _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_lo_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ /* each __m128i batch handle 4 __m128i, each __m128i with 2 pg group */ while (pg_cnt >= 8) { - __m128i src_y0 = _mm_loadu_si128((__m128i*)y); /* y0-y7 */ + __m128i src_y0 = _mm_loadu_si128((__m128i *)y); /* y0-y7 */ y += 8; - __m128i src_y8 = _mm_loadu_si128((__m128i*)y); /* y8-y15 */ + __m128i src_y8 = _mm_loadu_si128((__m128i *)y); /* y8-y15 */ y += 8; - __m128i src_b = _mm_loadu_si128((__m128i*)b); /* b0-b7 */ + __m128i src_b = _mm_loadu_si128((__m128i *)b); /* b0-b7 */ b += 8; - __m128i src_r = _mm_loadu_si128((__m128i*)r); /* r0-r7 */ + __m128i src_r = _mm_loadu_si128((__m128i *)r); /* r0-r7 */ r += 8; __m128i src_br_lo = @@ -1228,8 +1300,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512(uint16_t* y, uint16_t* b, uint16_ for (int j = 0; j < 4; j++) { /* convert to PGs in __m128i */ __m128i srlv_le_result = _mm_sllv_epi16(src[j], sllv_le_mask); - __m128i shuffle_hi_result = _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); - __m128i shuffle_lo_result = _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); + __m128i shuffle_hi_result = + _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); + __m128i shuffle_lo_result = + _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); __m128i result = _mm_or_si128(shuffle_hi_result, shuffle_lo_result); _mm_mask_storeu_epi8(pg, k, result); pg += 2; @@ -1261,44 +1335,47 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512(uint16_t* y, uint16_t* b, uint16_ return 0; } -int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - uint16_t* y, mtl_iova_t y_iova, - uint16_t* b, mtl_iova_t b_iova, - uint16_t* r, mtl_iova_t r_iova, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h) { +int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, + mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { uint32_t pg_cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; - __m128i sllv_le_mask = _mm_loadu_si128((__m128i*)ple_to_be10_sllv_tbl_128); - __m128i shuffle_hi_mask = _mm_loadu_si128((__m128i*)ple_to_be10_shuffle_hi_tbl_128); - __m128i shuffle_lo_mask = _mm_loadu_si128((__m128i*)ple_to_be10_shuffle_lo_tbl_128); + __m128i sllv_le_mask = _mm_loadu_si128((__m128i *)ple_to_be10_sllv_tbl_128); + __m128i shuffle_hi_mask = + _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_hi_tbl_128); + __m128i shuffle_lo_mask = + _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_lo_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int caches_num = 4; int le_size_per_pg = (2 + 1 + 1) * sizeof(uint16_t); /* 2y 1b 1r per pg */ - int cache_pg_cnt = (256 * 1024) / le_size_per_pg; /* pg cnt for each cache */ - int align = caches_num * 8; /* align to caches_num and simd */ + int cache_pg_cnt = (256 * 1024) / le_size_per_pg; /* pg cnt for each cache */ + int align = caches_num * 8; /* align to caches_num and simd */ cache_pg_cnt = cache_pg_cnt / align * align; size_t cache_size = cache_pg_cnt * le_size_per_pg; int soc_id = dma->parent->soc_id; - uint16_t* le_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(3 * caches_num, soc_id, 3); + uint16_t *le_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(3 * caches_num, soc_id, 3); if (!le_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - le_caches); - if (le_caches) mt_rte_free(le_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, le_caches); + if (le_caches) + mt_rte_free(le_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_yuv422p10le_to_rfc4175_422be10_avx512(y, b, r, pg, w, h); } rte_iova_t le_caches_iova = rte_malloc_virt2iova(le_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - uint16_t* le_cache = le_caches + (i % caches_num) * cache_size / sizeof(*le_cache); + uint16_t *le_cache = + le_caches + (i % caches_num) * cache_size / sizeof(*le_cache); dbg("%s, cache batch idx %d le_cache %p\n", __func__, i, le_cache); int max_tran = i + caches_num; @@ -1306,7 +1383,8 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dm int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 2); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t cache_iova = le_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t cache_iova = + le_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, cache_iova, y_iova, cache_size / 2); y += (cache_pg_cnt * 2); /* two y in one pg */ @@ -1332,23 +1410,24 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dm /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 2) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } int batch = cache_pg_cnt / 8; - uint16_t* y_cache = le_cache; - uint16_t* b_cache = y_cache + cache_size / 2 / sizeof(uint16_t); - uint16_t* r_cache = b_cache + cache_size / 4 / sizeof(uint16_t); - dbg("%s, cache batch idx %d cache y %p b %p r %p\n", __func__, i, y_cache, b_cache, - r_cache); + uint16_t *y_cache = le_cache; + uint16_t *b_cache = y_cache + cache_size / 2 / sizeof(uint16_t); + uint16_t *r_cache = b_cache + cache_size / 4 / sizeof(uint16_t); + dbg("%s, cache batch idx %d cache y %p b %p r %p\n", __func__, i, y_cache, + b_cache, r_cache); for (int j = 0; j < batch; j++) { - __m128i src_y0 = _mm_loadu_si128((__m128i*)y_cache); /* y0-y7 */ + __m128i src_y0 = _mm_loadu_si128((__m128i *)y_cache); /* y0-y7 */ y_cache += 8; - __m128i src_y8 = _mm_loadu_si128((__m128i*)y_cache); /* y8-y15 */ + __m128i src_y8 = _mm_loadu_si128((__m128i *)y_cache); /* y8-y15 */ y_cache += 8; - __m128i src_b = _mm_loadu_si128((__m128i*)b_cache); /* b0-b7 */ + __m128i src_b = _mm_loadu_si128((__m128i *)b_cache); /* b0-b7 */ b_cache += 8; - __m128i src_r = _mm_loadu_si128((__m128i*)r_cache); /* r0-r7 */ + __m128i src_r = _mm_loadu_si128((__m128i *)r_cache); /* r0-r7 */ r_cache += 8; __m128i src_br_lo = @@ -1367,8 +1446,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dm for (int j = 0; j < 4; j++) { /* convert to PGs in __m128i */ __m128i srlv_le_result = _mm_sllv_epi16(src[j], sllv_le_mask); - __m128i shuffle_hi_result = _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); - __m128i shuffle_lo_result = _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); + __m128i shuffle_hi_result = + _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); + __m128i shuffle_lo_result = + _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); __m128i result = _mm_or_si128(shuffle_hi_result, shuffle_lo_result); _mm_mask_storeu_epi8(pg, k, result); pg += 2; @@ -1382,13 +1463,13 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dm /* each __m128i batch handle 4 __m128i, each __m128i with 2 pg group */ while (pg_cnt >= 8) { - __m128i src_y0 = _mm_loadu_si128((__m128i*)y); /* y0-y7 */ + __m128i src_y0 = _mm_loadu_si128((__m128i *)y); /* y0-y7 */ y += 8; - __m128i src_y8 = _mm_loadu_si128((__m128i*)y); /* y8-y15 */ + __m128i src_y8 = _mm_loadu_si128((__m128i *)y); /* y8-y15 */ y += 8; - __m128i src_b = _mm_loadu_si128((__m128i*)b); /* b0-b7 */ + __m128i src_b = _mm_loadu_si128((__m128i *)b); /* b0-b7 */ b += 8; - __m128i src_r = _mm_loadu_si128((__m128i*)r); /* r0-r7 */ + __m128i src_r = _mm_loadu_si128((__m128i *)r); /* r0-r7 */ r += 8; __m128i src_br_lo = @@ -1407,8 +1488,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dm for (int j = 0; j < 4; j++) { /* convert to PGs in __m128i */ __m128i srlv_le_result = _mm_sllv_epi16(src[j], sllv_le_mask); - __m128i shuffle_hi_result = _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); - __m128i shuffle_lo_result = _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); + __m128i shuffle_hi_result = + _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); + __m128i shuffle_lo_result = + _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); __m128i result = _mm_or_si128(shuffle_hi_result, shuffle_lo_result); _mm_mask_storeu_epi8(pg, k, result); pg += 2; @@ -1596,33 +1679,39 @@ static uint8_t le10_to_be_shuffle_r1_tbl_128[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422le10_to_422be10_avx512(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { +int st20_rfc4175_422le10_to_422be10_avx512( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_l0_tbl_128); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_r0_tbl_128); - __m128i and_l0 = _mm_loadu_si128((__m128i*)le10_to_be_and_l0_tbl_128); - __m128i and_r0 = _mm_loadu_si128((__m128i*)le10_to_be_and_r0_tbl_128); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_l1_tbl_128); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_r1_tbl_128); + __m128i shuffle_l0 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l0_tbl_128); + __m128i shuffle_r0 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r0_tbl_128); + __m128i and_l0 = _mm_loadu_si128((__m128i *)le10_to_be_and_l0_tbl_128); + __m128i and_r0 = _mm_loadu_si128((__m128i *)le10_to_be_and_r0_tbl_128); + __m128i shuffle_l1 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l1_tbl_128); + __m128i shuffle_r1 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r1_tbl_128); int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_le); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = + _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = + _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_be, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k, result); pg_be += 3; pg_le += 3; @@ -1655,17 +1744,20 @@ int st20_rfc4175_422le10_to_422be10_avx512(struct st20_rfc4175_422_10_pg2_le* pg return 0; } -int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_le* pg_le, - mtl_iova_t pg_le_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_l0_tbl_128); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_r0_tbl_128); - __m128i and_l0 = _mm_loadu_si128((__m128i*)le10_to_be_and_l0_tbl_128); - __m128i and_r0 = _mm_loadu_si128((__m128i*)le10_to_be_and_r0_tbl_128); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_l1_tbl_128); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)le10_to_be_shuffle_r1_tbl_128); +int st20_rfc4175_422le10_to_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h) { + __m128i shuffle_l0 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l0_tbl_128); + __m128i shuffle_r0 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r0_tbl_128); + __m128i and_l0 = _mm_loadu_si128((__m128i *)le10_to_be_and_l0_tbl_128); + __m128i and_r0 = _mm_loadu_si128((__m128i *)le10_to_be_and_r0_tbl_128); + __m128i shuffle_l1 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l1_tbl_128); + __m128i shuffle_r1 = + _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r1_tbl_128); __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; @@ -1676,24 +1768,26 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sizeof(*pg_le); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_le* le_caches = + struct st20_rfc4175_422_10_pg2_le *le_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!le_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - le_caches); - if (le_caches) mt_rte_free(le_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, le_caches); + if (le_caches) + mt_rte_free(le_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422le10_to_422be10_avx512(pg_le, pg_be, w, h); } rte_iova_t le_caches_iova = rte_malloc_virt2iova(le_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_le* le_cache = + struct st20_rfc4175_422_10_pg2_le *le_cache = le_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -1702,7 +1796,8 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t le_cache_iova = le_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t le_cache_iova = + le_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, le_cache_iova, pg_le_iova, cache_size); pg_le += cache_pg_cnt; pg_le_iova += cache_size; @@ -1714,23 +1809,26 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_le* le = le_cache; + struct st20_rfc4175_422_10_pg2_le *le = le_cache; int batch = cache_pg_cnt / 3; for (int j = 0; j < batch; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)le); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = + _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = + _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_be, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k, result); le += 3; pg_be += 3; @@ -1744,17 +1842,19 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_le); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = + _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = + _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_be, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k, result); pg_be += 3; pg_le += 3; @@ -1823,30 +1923,34 @@ static uint8_t v210_to_be10_and_r_tbl_128[16] = { 0x03, 0xFF, 0x00, 0x3F, 0x0F, 0x03, 0xFF, 0x00, }; -int st20_v210_to_rfc4175_422be10_avx512(uint8_t* pg_v210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_l0_tbl_128); - __m128i sllv = _mm_loadu_si128((__m128i*)v210_to_be10_sllv_tbl_128); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_l1_tbl_128); - __m128i and_l = _mm_loadu_si128((__m128i*)v210_to_be10_and_l_tbl_128); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_r0_tbl_128); - __m128i srlv = _mm_loadu_si128((__m128i*)v210_to_be10_srlv_tbl_128); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_r1_tbl_128); - __m128i and_r = _mm_loadu_si128((__m128i*)v210_to_be10_and_r_tbl_128); +int st20_v210_to_rfc4175_422be10_avx512( + uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h) { + __m128i shuffle_l0 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l0_tbl_128); + __m128i sllv = _mm_loadu_si128((__m128i *)v210_to_be10_sllv_tbl_128); + __m128i shuffle_l1 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l1_tbl_128); + __m128i and_l = _mm_loadu_si128((__m128i *)v210_to_be10_and_l_tbl_128); + __m128i shuffle_r0 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r0_tbl_128); + __m128i srlv = _mm_loadu_si128((__m128i *)v210_to_be10_srlv_tbl_128); + __m128i shuffle_r1 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r1_tbl_128); + __m128i and_r = _mm_loadu_si128((__m128i *)v210_to_be10_and_r_tbl_128); __mmask16 k_store = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", + __func__, pg_cnt); return -EINVAL; } int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_loadu_si128((__m128i*)pg_v210); + __m128i input = _mm_loadu_si128((__m128i *)pg_v210); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i sllv_result = _mm_sllv_epi16(shuffle_l0_result, sllv); __m128i shuffle_l1_result = _mm_shuffle_epi8(sllv_result, shuffle_l1); @@ -1857,7 +1961,7 @@ int st20_v210_to_rfc4175_422be10_avx512(uint8_t* pg_v210, __m128i and_r_result = _mm_and_si128(shuffle_r1_result, and_r); __m128i result = _mm_or_si128(and_l_result, and_r_result); - _mm_mask_storeu_epi8((__m128i*)pg_be, k_store, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); pg_be += 3; pg_v210 += 16; @@ -1866,25 +1970,28 @@ int st20_v210_to_rfc4175_422be10_avx512(uint8_t* pg_v210, return 0; } -int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - uint8_t* pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - __m128i shuffle_l0 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_l0_tbl_128); - __m128i sllv = _mm_loadu_si128((__m128i*)v210_to_be10_sllv_tbl_128); - __m128i shuffle_l1 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_l1_tbl_128); - __m128i and_l = _mm_loadu_si128((__m128i*)v210_to_be10_and_l_tbl_128); - __m128i shuffle_r0 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_r0_tbl_128); - __m128i srlv = _mm_loadu_si128((__m128i*)v210_to_be10_srlv_tbl_128); - __m128i shuffle_r1 = _mm_loadu_si128((__m128i*)v210_to_be10_shuffle_r1_tbl_128); - __m128i and_r = _mm_loadu_si128((__m128i*)v210_to_be10_and_r_tbl_128); +int st20_v210_to_rfc4175_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { + __m128i shuffle_l0 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l0_tbl_128); + __m128i sllv = _mm_loadu_si128((__m128i *)v210_to_be10_sllv_tbl_128); + __m128i shuffle_l1 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l1_tbl_128); + __m128i and_l = _mm_loadu_si128((__m128i *)v210_to_be10_and_l_tbl_128); + __m128i shuffle_r0 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r0_tbl_128); + __m128i srlv = _mm_loadu_si128((__m128i *)v210_to_be10_srlv_tbl_128); + __m128i shuffle_r1 = + _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r1_tbl_128); + __m128i and_r = _mm_loadu_si128((__m128i *)v210_to_be10_and_r_tbl_128); __mmask16 k_store = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", + __func__, pg_cnt); return -EINVAL; } @@ -1896,23 +2003,25 @@ int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sz_v210_3be / 3; int soc_id = dma->parent->soc_id; - uint8_t* v210_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + uint8_t *v210_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!v210_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - v210_caches); - if (v210_caches) mt_rte_free(v210_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, v210_caches); + if (v210_caches) + mt_rte_free(v210_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_v210_to_rfc4175_422be10_avx512(pg_v210, pg_be, w, h); } rte_iova_t v210_caches_iova = rte_malloc_virt2iova(v210_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - uint8_t* v210_cache = v210_caches + (i % caches_num) * cache_size; + uint8_t *v210_cache = v210_caches + (i % caches_num) * cache_size; dbg("%s, cache batch idx %d\n", __func__, i); int max_tran = i + caches_num; @@ -1933,13 +2042,14 @@ int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - uint8_t* v210 = v210_cache; + uint8_t *v210 = v210_cache; int batch = cache_pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_loadu_si128((__m128i*)v210); + __m128i input = _mm_loadu_si128((__m128i *)v210); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i sllv_result = _mm_sllv_epi16(shuffle_l0_result, sllv); __m128i shuffle_l1_result = _mm_shuffle_epi8(sllv_result, shuffle_l1); @@ -1950,7 +2060,7 @@ int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, __m128i and_r_result = _mm_and_si128(shuffle_r1_result, and_r); __m128i result = _mm_or_si128(and_l_result, and_r_result); - _mm_mask_storeu_epi8((__m128i*)pg_be, k_store, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); v210 += 16; pg_be += 3; @@ -1964,7 +2074,7 @@ int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 3; for (int i = 0; i < batch; i++) { - __m128i input = _mm_loadu_si128((__m128i*)pg_v210); + __m128i input = _mm_loadu_si128((__m128i *)pg_v210); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i sllv_result = _mm_sllv_epi16(shuffle_l0_result, sllv); __m128i shuffle_l1_result = _mm_shuffle_epi8(sllv_result, shuffle_l1); @@ -1975,7 +2085,7 @@ int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, __m128i and_r_result = _mm_and_si128(shuffle_r1_result, and_r); __m128i result = _mm_or_si128(and_l_result, and_r_result); - _mm_mask_storeu_epi8((__m128i*)pg_be, k_store, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); pg_be += 3; pg_v210 += 16; @@ -1999,11 +2109,13 @@ static uint16_t be10_to_y210_and_tbl_128[8] = { 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, }; -int st20_rfc4175_422be10_to_y210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint16_t* pg_y210, uint32_t w, uint32_t h) { - __m128i shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_y210_shuffle_tbl_128); - __m128i sllv_mask = _mm_loadu_si128((__m128i*)be10_to_y210_sllv_tbl_128); - __m128i and_mask = _mm_loadu_si128((__m128i*)be10_to_y210_and_tbl_128); +int st20_rfc4175_422be10_to_y210_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *pg_y210, uint32_t w, + uint32_t h) { + __m128i shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_y210_shuffle_tbl_128); + __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_y210_sllv_tbl_128); + __m128i and_mask = _mm_loadu_si128((__m128i *)be10_to_y210_and_tbl_128); __mmask16 k_load = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ @@ -2011,12 +2123,12 @@ int st20_rfc4175_422be10_to_y210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be int batch = pg_cnt / 2; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i *)pg_be); __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); __m128i result = _mm_and_si128(sllv_result, and_mask); - _mm_storeu_si128((__m128i*)pg_y210, result); + _mm_storeu_si128((__m128i *)pg_y210, result); pg_be += 2; pg_y210 += 8; @@ -2037,13 +2149,13 @@ int st20_rfc4175_422be10_to_y210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be return 0; } -int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* pg_y210, - uint32_t w, uint32_t h) { - __m128i shuffle_mask = _mm_loadu_si128((__m128i*)be10_to_y210_shuffle_tbl_128); - __m128i sllv_mask = _mm_loadu_si128((__m128i*)be10_to_y210_sllv_tbl_128); - __m128i and_mask = _mm_loadu_si128((__m128i*)be10_to_y210_and_tbl_128); +int st20_rfc4175_422be10_to_y210_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h) { + __m128i shuffle_mask = + _mm_loadu_si128((__m128i *)be10_to_y210_shuffle_tbl_128); + __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_y210_sllv_tbl_128); + __m128i and_mask = _mm_loadu_si128((__m128i *)be10_to_y210_and_tbl_128); __mmask16 k_load = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ @@ -2057,24 +2169,26 @@ int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_y210_avx512(pg_be, pg_y210, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -2083,7 +2197,8 @@ int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev* dma, int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -2095,17 +2210,18 @@ int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* be = be_cache; + struct st20_rfc4175_422_10_pg2_be *be = be_cache; int batch = cache_pg_cnt / 2; for (int j = 0; j < batch; j++) { - __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i*)be); + __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i *)be); __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); __m128i result = _mm_and_si128(sllv_result, and_mask); - _mm_storeu_si128((__m128i*)pg_y210, result); + _mm_storeu_si128((__m128i *)pg_y210, result); be += 2; pg_y210 += 8; @@ -2119,12 +2235,12 @@ int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 2; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k_load, (__m128i *)pg_be); __m128i shuffle_result = _mm_shuffle_epi8(input, shuffle_mask); __m128i sllv_result = _mm_sllv_epi16(shuffle_result, sllv_mask); __m128i result = _mm_and_si128(sllv_result, and_mask); - _mm_storeu_si128((__m128i*)pg_y210, result); + _mm_storeu_si128((__m128i *)pg_y210, result); pg_be += 2; pg_y210 += 8; @@ -2162,13 +2278,15 @@ static uint8_t y210_to_be10_shuffle1_tbl_128[16] = { 0, 0, 0, 0, 0, 0, }; -int st20_y210_to_rfc4175_422be10_avx512(uint16_t* pg_y210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - __m128i srlv_mask = - _mm_loadu_si128((__m128i*)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ - __m128i shuffle0_mask = _mm_loadu_si128((__m128i*)y210_to_be10_shuffle0_tbl_128); - __m128i shuffle1_mask = _mm_loadu_si128((__m128i*)y210_to_be10_shuffle1_tbl_128); +int st20_y210_to_rfc4175_422be10_avx512( + uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h) { + __m128i srlv_mask = _mm_loadu_si128( + (__m128i *)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ + __m128i shuffle0_mask = + _mm_loadu_si128((__m128i *)y210_to_be10_shuffle0_tbl_128); + __m128i shuffle1_mask = + _mm_loadu_si128((__m128i *)y210_to_be10_shuffle1_tbl_128); __mmask16 k_store = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ @@ -2176,13 +2294,15 @@ int st20_y210_to_rfc4175_422be10_avx512(uint16_t* pg_y210, int batch = pg_cnt / 2; for (int i = 0; i < batch; i++) { - __m128i input = _mm_loadu_si128((__m128i*)pg_y210); + __m128i input = _mm_loadu_si128((__m128i *)pg_y210); __m128i srlv_result = _mm_srlv_epi16(input, srlv_mask); - __m128i shuffle0_result = _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); - __m128i shuffle1_result = _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); + __m128i shuffle0_result = + _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); + __m128i shuffle1_result = + _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); __m128i result = _mm_or_si128(shuffle0_result, shuffle1_result); - _mm_mask_storeu_epi8((__m128i*)pg_be, k_store, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); pg_be += 2; pg_y210 += 8; @@ -2207,14 +2327,15 @@ int st20_y210_to_rfc4175_422be10_avx512(uint16_t* pg_y210, return 0; } -int st20_y210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - uint16_t* pg_y210, mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - __m128i srlv_mask = - _mm_loadu_si128((__m128i*)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ - __m128i shuffle0_mask = _mm_loadu_si128((__m128i*)y210_to_be10_shuffle0_tbl_128); - __m128i shuffle1_mask = _mm_loadu_si128((__m128i*)y210_to_be10_shuffle1_tbl_128); +int st20_y210_to_rfc4175_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { + __m128i srlv_mask = _mm_loadu_si128( + (__m128i *)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ + __m128i shuffle0_mask = + _mm_loadu_si128((__m128i *)y210_to_be10_shuffle0_tbl_128); + __m128i shuffle1_mask = + _mm_loadu_si128((__m128i *)y210_to_be10_shuffle1_tbl_128); __mmask16 k_store = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ @@ -2223,28 +2344,31 @@ int st20_y210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, int caches_num = 4; int cache_pg_cnt = (256 * 1024) / 8; /* pg cnt for each cache */ - int align = caches_num * 2; /* align to simd pg groups and caches_num */ + int align = caches_num * 2; /* align to simd pg groups and caches_num */ cache_pg_cnt = cache_pg_cnt / align * align; size_t cache_size = cache_pg_cnt * 8; int soc_id = dma->parent->soc_id; - uint16_t* y210_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + uint16_t *y210_caches = + mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!y210_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - y210_caches); - if (y210_caches) mt_rte_free(y210_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, y210_caches); + if (y210_caches) + mt_rte_free(y210_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_y210_to_rfc4175_422be10_avx512(pg_y210, pg_be, w, h); } rte_iova_t y210_caches_iova = rte_malloc_virt2iova(y210_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - uint16_t* y210_cache = y210_caches + (i % caches_num) * cache_pg_cnt * 4; + uint16_t *y210_cache = y210_caches + (i % caches_num) * cache_pg_cnt * 4; dbg("%s, cache batch idx %d\n", __func__, i); int max_tran = i + caches_num; @@ -2265,18 +2389,21 @@ int st20_y210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - uint16_t* y210 = y210_cache; + uint16_t *y210 = y210_cache; int batch = cache_pg_cnt / 2; for (int j = 0; j < batch; j++) { - __m128i input = _mm_loadu_si128((__m128i*)y210); + __m128i input = _mm_loadu_si128((__m128i *)y210); __m128i srlv_result = _mm_srlv_epi16(input, srlv_mask); - __m128i shuffle0_result = _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); - __m128i shuffle1_result = _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); + __m128i shuffle0_result = + _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); + __m128i shuffle1_result = + _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); __m128i result = _mm_or_si128(shuffle0_result, shuffle1_result); - _mm_mask_storeu_epi8((__m128i*)pg_be, k_store, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); pg_be += 2; y210 += 8; @@ -2290,13 +2417,15 @@ int st20_y210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 2; for (int i = 0; i < batch; i++) { - __m128i input = _mm_loadu_si128((__m128i*)pg_y210); + __m128i input = _mm_loadu_si128((__m128i *)pg_y210); __m128i srlv_result = _mm_srlv_epi16(input, srlv_mask); - __m128i shuffle0_result = _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); - __m128i shuffle1_result = _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); + __m128i shuffle0_result = + _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); + __m128i shuffle1_result = + _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); __m128i result = _mm_or_si128(shuffle0_result, shuffle1_result); - _mm_mask_storeu_epi8((__m128i*)pg_be, k_store, result); + _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); pg_be += 2; pg_y210 += 8; @@ -2337,11 +2466,11 @@ static uint8_t be12_to_le12_shuffle1_tbl_128[16] = { 0x80, 0x80, 0x80, 0x80, /*zeros*/ }; -int st20_rfc4175_422be12_to_422le12_avx512(struct st20_rfc4175_422_12_pg2_be* pg_be, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h) { - __m128i shuffle0 = _mm_loadu_si128((__m128i*)be12_to_le12_shuffle0_tbl_128); - __m128i shuffle1 = _mm_loadu_si128((__m128i*)be12_to_le12_shuffle1_tbl_128); +int st20_rfc4175_422be12_to_422le12_avx512( + struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h) { + __m128i shuffle0 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle0_tbl_128); + __m128i shuffle1 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle1_tbl_128); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ int pg_cnt = w * h / 2; @@ -2349,13 +2478,13 @@ int st20_rfc4175_422be12_to_422le12_avx512(struct st20_rfc4175_422_12_pg2_be* pg int batch = pg_cnt / 2; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle0_result = _mm_shuffle_epi8(input, shuffle0); __m128i sr_result = _mm_srli_epi32(shuffle0_result, 4); __m128i result = _mm_shuffle_epi8(sr_result, shuffle1); /* store to the first 12 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_le, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_le, k, result); pg_be += 2; pg_le += 2; @@ -2387,13 +2516,12 @@ int st20_rfc4175_422be12_to_422le12_avx512(struct st20_rfc4175_422_12_pg2_be* pg return 0; } -int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h) { - __m128i shuffle0 = _mm_loadu_si128((__m128i*)be12_to_le12_shuffle0_tbl_128); - __m128i shuffle1 = _mm_loadu_si128((__m128i*)be12_to_le12_shuffle1_tbl_128); +int st20_rfc4175_422be12_to_422le12_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, + uint32_t h) { + __m128i shuffle0 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle0_tbl_128); + __m128i shuffle1 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle1_tbl_128); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ int pg_cnt = w * h / 2; @@ -2404,24 +2532,26 @@ int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_12_pg2_be* be_caches = + struct st20_rfc4175_422_12_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be12_to_422le12_avx512(pg_be, pg_le, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_12_pg2_be* be_cache = + struct st20_rfc4175_422_12_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -2430,7 +2560,8 @@ int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev* dma, int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -2442,19 +2573,20 @@ int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_12_pg2_be* be = be_cache; + struct st20_rfc4175_422_12_pg2_be *be = be_cache; int batch = cache_pg_cnt / 2; for (int j = 0; j < batch; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)be); __m128i shuffle0_result = _mm_shuffle_epi8(input, shuffle0); __m128i sr_result = _mm_srli_epi32(shuffle0_result, 4); __m128i result = _mm_shuffle_epi8(sr_result, shuffle1); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_le, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_le, k, result); be += 2; pg_le += 2; @@ -2468,13 +2600,13 @@ int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 2; for (int i = 0; i < batch; i++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle0_result = _mm_shuffle_epi8(input, shuffle0); __m128i sr_result = _mm_srli_epi32(shuffle0_result, 4); __m128i result = _mm_shuffle_epi8(sr_result, shuffle1); /* store to the first 15 bytes after dest address */ - _mm_mask_storeu_epi8((__m128i*)pg_le, k, result); + _mm_mask_storeu_epi8((__m128i *)pg_le, k, result); pg_be += 2; pg_le += 2; @@ -2522,23 +2654,27 @@ static uint16_t be12_to_ple_and_mask_tbl_128[8] = { 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, }; -int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = _mm_loadu_si128((__m128i*)be12_to_ple_shuffle_tbl_128); - __m128i srlv_le_mask = _mm_loadu_si128((__m128i*)be12_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = _mm_loadu_si128((__m128i*)be12_to_ple_and_mask_tbl_128); - __m512i permute_mask = _mm512_loadu_si512((__m512i*)be10_to_ple_permute_tbl_512); +int st20_rfc4175_422be12_to_yuv422p12le_avx512( + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h) { + __m128i shuffle_le_mask = + _mm_loadu_si128((__m128i *)be12_to_ple_shuffle_tbl_128); + __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be12_to_ple_srlv_tbl_128); + __m128i srlv_and_mask = + _mm_loadu_si128((__m128i *)be12_to_ple_and_mask_tbl_128); + __m512i permute_mask = + _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); - /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group */ + /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group + */ while (pg_cnt >= 32) { /* cvt the result to __m128i(2 pg group) */ __m128i stage_m128i[16]; for (int j = 0; j < 16; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); @@ -2547,33 +2683,39 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be /* shift result to m128i */ __m512i stage_m512i[4]; for (int j = 0; j < 4; j++) { - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ - __m512i input_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[j * 4]); - /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} + */ + __m512i input_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} + */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); } /* shift m128i to m512i */ /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[1]); + result_m512i[1] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[3]); + result_m512i[3] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b10001000); - _mm512_storeu_si512((__m512i*)b, b_result_m512i); + _mm512_storeu_si512((__m512i *)b, b_result_m512i); b += 32; __m512i r_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b11011101); - _mm512_storeu_si512((__m512i*)r, r_result_m512i); + _mm512_storeu_si512((__m512i *)r, r_result_m512i); r += 32; pg_cnt -= 32; @@ -2583,14 +2725,14 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be while (pg_cnt >= 8) { __m128i stage_m128i[4]; for (int j = 0; j < 4; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg += 2; } // {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} - __m512i stage_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[0]); + __m512i stage_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[0]); /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ __m512i permute = _mm512_permutexvar_epi32(permute_mask, stage_m512i); @@ -2599,13 +2741,13 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be __m128i result_Y0 = _mm512_extracti32x4_epi32(permute, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(permute, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; pg_cnt -= 8; @@ -2626,13 +2768,16 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be } int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = _mm_loadu_si128((__m128i*)be12_to_ple_shuffle_tbl_128); - __m128i srlv_le_mask = _mm_loadu_si128((__m128i*)be12_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = _mm_loadu_si128((__m128i*)be12_to_ple_and_mask_tbl_128); - __m512i permute_mask = _mm512_loadu_si512((__m512i*)be10_to_ple_permute_tbl_512); + __m128i shuffle_le_mask = + _mm_loadu_si128((__m128i *)be12_to_ple_shuffle_tbl_128); + __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be12_to_ple_srlv_tbl_128); + __m128i srlv_and_mask = + _mm_loadu_si128((__m128i *)be12_to_ple_and_mask_tbl_128); + __m512i permute_mask = + _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ int pg_cnt = w * h / 2; @@ -2643,24 +2788,26 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_12_pg2_be* be_caches = + struct st20_rfc4175_422_12_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be12_to_yuv422p12le_avx512(pg_be, y, b, r, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_12_pg2_be* be_cache = + struct st20_rfc4175_422_12_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -2669,7 +2816,8 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -2681,51 +2829,61 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_12_pg2_be* pg = be_cache; + struct st20_rfc4175_422_12_pg2_be *pg = be_cache; int batch = cache_pg_cnt / 32; for (int j = 0; j < batch; j++) { /* cvt the result to __m128i(2 pg group) */ __m128i stage_m128i[16]; for (int j = 0; j < 16; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); - __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); + __m128i srlv_le_result = + _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg += 2; } /* shift result to m128i */ __m512i stage_m512i[4]; for (int j = 0; j < 4; j++) { - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ - __m512i input_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[j * 4]); - /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, + * Y7} */ + __m512i input_m512i = + _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, + * Y7} */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); } /* shift m128i to m512i */ - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} + */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[1]); + result_m512i[1] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[3]); + result_m512i[3] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b10001000); - _mm512_storeu_si512((__m512i*)b, b_result_m512i); + _mm512_storeu_si512((__m512i *)b, b_result_m512i); b += 32; __m512i r_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b11011101); - _mm512_storeu_si512((__m512i*)r, r_result_m512i); + _mm512_storeu_si512((__m512i *)r, r_result_m512i); r += 32; } } @@ -2736,12 +2894,13 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( /* remaining simd batch */ int batch = pg_cnt / 32; - /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group */ + /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group + */ for (int i = 0; i < batch; i++) { /* cvt the result to __m128i(2 pg group) */ __m128i stage_m128i[16]; for (int j = 0; j < 16; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); @@ -2750,33 +2909,39 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( /* shift result to m128i */ __m512i stage_m512i[4]; for (int j = 0; j < 4; j++) { - /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ - __m512i input_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[j * 4]); - /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ + /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} + */ + __m512i input_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} + */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); } /* shift m128i to m512i */ /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[1]); + result_m512i[1] = + _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); - _mm512_storeu_si512((__m512i*)y, result_m512i[3]); + result_m512i[3] = + _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b10001000); - _mm512_storeu_si512((__m512i*)b, b_result_m512i); + _mm512_storeu_si512((__m512i *)b, b_result_m512i); b += 32; __m512i r_result_m512i = _mm512_shuffle_i32x4(result_m512i[0], result_m512i[2], 0b11011101); - _mm512_storeu_si512((__m512i*)r, r_result_m512i); + _mm512_storeu_si512((__m512i *)r, r_result_m512i); r += 32; } pg_cnt = pg_cnt % 32; @@ -2786,14 +2951,14 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( for (int i = 0; i < batch; i++) { __m128i stage_m128i[4]; for (int j = 0; j < 4; j++) { - __m128i input = _mm_maskz_loadu_epi8(k, (__m128i*)pg_be); + __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg_be += 2; } // {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} - __m512i stage_m512i = _mm512_loadu_si512((__m512i*)&stage_m128i[0]); + __m512i stage_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[0]); /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, Y7} */ __m512i permute = _mm512_permutexvar_epi32(permute_mask, stage_m512i); @@ -2802,13 +2967,13 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( __m128i result_Y0 = _mm512_extracti32x4_epi32(permute, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(permute, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; } pg_cnt = pg_cnt % 8; diff --git a/lib/src/st2110/st_avx512.h b/lib/src/st2110/st_avx512.h index 05cffc96d..e9d202dec 100644 --- a/lib/src/st2110/st_avx512.h +++ b/lib/src/st2110/st_avx512.h @@ -7,116 +7,110 @@ #include "st_main.h" -int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv422p10le_avx512( + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le10_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le8_avx512(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le8_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le8_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_10, - mtl_iova_t pg_10_iova, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le8_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, + uint32_t h); -int st20_rfc4175_422le10_to_v210_avx512(uint8_t* pg_le, uint8_t* pg_v210, uint32_t w, - uint32_t h); +int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_v210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_v210_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, + uint32_t h); -int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, + uint32_t h); int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, uint32_t h); - -int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint8_t* pg_v210, - uint32_t w, uint32_t h); - -int st20_yuv422p10le_to_rfc4175_422be10_avx512(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h); - -int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - uint16_t* y, mtl_iova_t y_iova, - uint16_t* b, mtl_iova_t b_iova, - uint16_t* r, mtl_iova_t r_iova, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h); - -int st20_rfc4175_422le10_to_422be10_avx512(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); - -int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_le* pg_le, - mtl_iova_t pg_le_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); - -int st20_v210_to_rfc4175_422be10_avx512(uint8_t* pg_v210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h); -int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - uint8_t* pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_v210_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_y210_avx512(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint16_t* pg_y210, uint32_t w, uint32_t h); +int st20_yuv422p10le_to_rfc4175_422be10_avx512( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* pg_y210, - uint32_t w, uint32_t h); +int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, + mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h); -int st20_y210_to_rfc4175_422be10_avx512(uint16_t* pg_y210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); +int st20_rfc4175_422le10_to_422be10_avx512( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); + +int st20_rfc4175_422le10_to_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h); + +int st20_v210_to_rfc4175_422be10_avx512( + uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h); + +int st20_v210_to_rfc4175_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); + +int st20_rfc4175_422be10_to_y210_avx512( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *pg_y210, uint32_t w, + uint32_t h); + +int st20_rfc4175_422be10_to_y210_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h); + +int st20_y210_to_rfc4175_422be10_avx512( + uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h); -int st20_y210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev* dma, - uint16_t* pg_y210, mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); +int st20_y210_to_rfc4175_422be10_avx512_dma( + struct mtl_dma_lender_dev *dma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); -int st20_rfc4175_422be12_to_422le12_avx512(struct st20_rfc4175_422_12_pg2_be* pg_be, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h); +int st20_rfc4175_422be12_to_422le12_avx512( + struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h); -int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h); +int st20_rfc4175_422be12_to_422le12_avx512_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, + uint32_t h); -int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be12_to_yuv422p12le_avx512( + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h); int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, uint32_t h); + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h); -int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv422p8_avx512( + struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv420p8_avx512( + struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h); #endif \ No newline at end of file diff --git a/lib/src/st2110/st_avx512_vbmi.c b/lib/src/st2110/st_avx512_vbmi.c index a7a840b57..8a1f02900 100644 --- a/lib/src/st2110/st_avx512_vbmi.c +++ b/lib/src/st2110/st_avx512_vbmi.c @@ -11,14 +11,22 @@ MT_TARGET_CODE_START_AVX512_VBMI2 /* begin st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi */ static uint8_t be10_to_ple_permute_tbl_512[16 * 4] = { - 1, 0, 6, 5, 1 + 10, 0 + 10, 6 + 10, 5 + 10, /* b0, b1, b2, b3 */ - 1 + 20, 0 + 20, 6 + 20, 5 + 20, 1 + 30, 0 + 30, 6 + 30, 5 + 30, /* b4, b5, b6, b7 */ - 3, 2, 8, 7, 3 + 10, 2 + 10, 8 + 10, 7 + 10, /* r0, r1, r2, r3 */ - 3 + 20, 2 + 20, 8 + 20, 7 + 20, 3 + 30, 2 + 30, 8 + 30, 7 + 30, /* r4, r5, r6, r7 */ - 2, 1, 4, 3, 7, 6, 9, 8, /* y0 - y3 */ - 2 + 10, 1 + 10, 4 + 10, 3 + 10, 7 + 10, 6 + 10, 9 + 10, 8 + 10, /* y4 - y7 */ - 2 + 20, 1 + 20, 4 + 20, 3 + 20, 7 + 20, 6 + 20, 9 + 20, 8 + 20, /* y8 - y11 */ - 2 + 30, 1 + 30, 4 + 30, 3 + 30, 7 + 30, 6 + 30, 9 + 30, 8 + 30, /* y12 - y15 */ + 1, 0, 6, 5, + 1 + 10, 0 + 10, 6 + 10, 5 + 10, /* b0, b1, b2, b3 */ + 1 + 20, 0 + 20, 6 + 20, 5 + 20, + 1 + 30, 0 + 30, 6 + 30, 5 + 30, /* b4, b5, b6, b7 */ + 3, 2, 8, 7, + 3 + 10, 2 + 10, 8 + 10, 7 + 10, /* r0, r1, r2, r3 */ + 3 + 20, 2 + 20, 8 + 20, 7 + 20, + 3 + 30, 2 + 30, 8 + 30, 7 + 30, /* r4, r5, r6, r7 */ + 2, 1, 4, 3, + 7, 6, 9, 8, /* y0 - y3 */ + 2 + 10, 1 + 10, 4 + 10, 3 + 10, + 7 + 10, 6 + 10, 9 + 10, 8 + 10, /* y4 - y7 */ + 2 + 20, 1 + 20, 4 + 20, 3 + 20, + 7 + 20, 6 + 20, 9 + 20, 8 + 20, /* y8 - y11 */ + 2 + 30, 1 + 30, 4 + 30, 3 + 30, + 7 + 30, 6 + 30, 9 + 30, 8 + 30, /* y12 - y15 */ }; static uint16_t be10_to_ple_srlv_tbl_512[8 * 4] = { @@ -29,15 +37,19 @@ static uint16_t be10_to_ple_srlv_tbl_512[8 * 4] = { }; static uint16_t be10_to_ple_and_tbl_512[8 * 4] = { - 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* b0 - b7 */ - 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* r0 - r7 */ - 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y0 - y7 */ - 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y8 - y15 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, + 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* b0 - b7 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, + 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* r0 - r7 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, + 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y0 - y7 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, + 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y8 - y15 */ }; -int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h) { __m512i permute_le_mask = _mm512_loadu_si512(be10_to_ple_permute_tbl_512); __m512i srlv_le_mask = _mm512_loadu_si512(be10_to_ple_srlv_tbl_512); __m512i srlv_and_mask = _mm512_loadu_si512(be10_to_ple_and_tbl_512); @@ -99,13 +111,13 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(struct st20_rfc4175_422_10_p __m128i result_Y0 = _mm512_extracti32x4_epi32(stage_m512i, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(stage_m512i, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; pg_cnt -= 8; @@ -125,8 +137,8 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(struct st20_rfc4175_422_10_p } int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { __m512i permute_le_mask = _mm512_loadu_si512(be10_to_ple_permute_tbl_512); __m512i srlv_le_mask = _mm512_loadu_si512(be10_to_ple_srlv_tbl_512); @@ -141,24 +153,27 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); - return st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(pg_be, y, b, r, w, h); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); + return st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(pg_be, y, b, r, w, + h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -167,7 +182,8 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -179,15 +195,18 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* pg = be_cache; + struct st20_rfc4175_422_10_pg2_be *pg = be_cache; int batch = cache_pg_cnt / 8; for (int j = 0; j < batch; j++) { __m512i input = _mm512_maskz_loadu_epi8(k, pg); - __m512i permute_le_result = _mm512_permutexvar_epi8(permute_le_mask, input); - __m512i srlv_le_result = _mm512_srlv_epi16(permute_le_result, srlv_le_mask); + __m512i permute_le_result = + _mm512_permutexvar_epi8(permute_le_mask, input); + __m512i srlv_le_result = + _mm512_srlv_epi16(permute_le_result, srlv_le_mask); __m512i stage_m512i = _mm512_and_si512(srlv_le_result, srlv_and_mask); pg += 8; @@ -197,13 +216,13 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( __m128i result_Y0 = _mm512_extracti32x4_epi32(stage_m512i, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(stage_m512i, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; } } @@ -214,7 +233,8 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( /* remaining simd batch */ int batch = pg_cnt / 8; - /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group */ + /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group + */ for (int i = 0; i < batch; i++) { __m512i input = _mm512_maskz_loadu_epi8(k, pg_be); __m512i permute_le_result = _mm512_permutexvar_epi8(permute_le_mask, input); @@ -228,13 +248,13 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( __m128i result_Y0 = _mm512_extracti32x4_epi32(stage_m512i, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(stage_m512i, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; } pg_cnt = pg_cnt % 8; @@ -256,57 +276,91 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( /* begin st20_rfc4175_422be10_to_422le10_avx512_vbmi */ static uint8_t be10_to_le_permute_l0_tbl_512[64] = { - 1, 0, 3, 2, /* 4 bytes from pg0 */ - 6, 5, 8, 7, /* 4 bytes from pg1 */ - 11, 10, 13, 12, /* 4 bytes from pg2 */ - 0, 5, 10, 63, /* 5th bytes from pg0,pg1,pg2, and a padding */ - 1 + 15, 0 + 15, 3 + 15, 2 + 15, /* 4 bytes from pg3 */ - 6 + 15, 5 + 15, 8 + 15, 7 + 15, /* 4 bytes from pg4 */ - 11 + 15, 10 + 15, 13 + 15, 12 + 15, /* 4 bytes from pg5 */ - 0 + 15, 5 + 15, 10 + 15, 63, /* 5th bytes from pg3,pg4,pg5, and a padding */ - 1 + 30, 0 + 30, 3 + 30, 2 + 30, /* 4 bytes from pg6 */ - 6 + 30, 5 + 30, 8 + 30, 7 + 30, /* 4 bytes from pg7 */ - 11 + 30, 10 + 30, 13 + 30, 12 + 30, /* 4 bytes from pg8 */ - 0 + 30, 5 + 30, 10 + 30, 63, /* 5th bytes from pg6,pg7,pg8, and a padding */ - 1 + 45, 0 + 45, 3 + 45, 2 + 45, /* 4 bytes from pg9 */ - 6 + 45, 5 + 45, 8 + 45, 7 + 45, /* 4 bytes from pg10 */ - 11 + 45, 10 + 45, 13 + 45, 12 + 45, /* 4 bytes from pg11 */ - 0 + 45, 5 + 45, 10 + 45, 63, /* 5th bytes from pg9,pg10,pg11, and a padding */ + 1, 0, + 3, 2, /* 4 bytes from pg0 */ + 6, 5, + 8, 7, /* 4 bytes from pg1 */ + 11, 10, + 13, 12, /* 4 bytes from pg2 */ + 0, 5, + 10, 63, /* 5th bytes from pg0,pg1,pg2, and a padding */ + 1 + 15, 0 + 15, + 3 + 15, 2 + 15, /* 4 bytes from pg3 */ + 6 + 15, 5 + 15, + 8 + 15, 7 + 15, /* 4 bytes from pg4 */ + 11 + 15, 10 + 15, + 13 + 15, 12 + 15, /* 4 bytes from pg5 */ + 0 + 15, 5 + 15, + 10 + 15, 63, /* 5th bytes from pg3,pg4,pg5, and a padding */ + 1 + 30, 0 + 30, + 3 + 30, 2 + 30, /* 4 bytes from pg6 */ + 6 + 30, 5 + 30, + 8 + 30, 7 + 30, /* 4 bytes from pg7 */ + 11 + 30, 10 + 30, + 13 + 30, 12 + 30, /* 4 bytes from pg8 */ + 0 + 30, 5 + 30, + 10 + 30, 63, /* 5th bytes from pg6,pg7,pg8, and a padding */ + 1 + 45, 0 + 45, + 3 + 45, 2 + 45, /* 4 bytes from pg9 */ + 6 + 45, 5 + 45, + 8 + 45, 7 + 45, /* 4 bytes from pg10 */ + 11 + 45, 10 + 45, + 13 + 45, 12 + 45, /* 4 bytes from pg11 */ + 0 + 45, 5 + 45, + 10 + 45, 63, /* 5th bytes from pg9,pg10,pg11, and a padding */ }; static uint8_t be10_to_le_and_l0_tbl_512[64] = { - 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, - 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, - 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, - 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, - 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, + 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, + 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, + 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, + 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, + 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, + 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, }; static uint8_t be10_to_le_permute_r0_tbl_512[64] = { - 2, 1, 4, 3, /* 4 bytes from pg0 */ - 7, 6, 9, 8, /* 4 bytes from pg1 */ - 12, 11, 14, 13, /* 4 bytes from pg2 */ - 63, 4, 9, 14, /* 1st bytes from pg0,pg1,pg2, and a padding */ - 2 + 15, 1 + 15, 4 + 15, 3 + 15, /* 4 bytes from pg3 */ - 7 + 15, 6 + 15, 9 + 15, 8 + 15, /* 4 bytes from pg4 */ - 12 + 15, 11 + 15, 14 + 15, 13 + 15, /* 4 bytes from pg5 */ - 63, 4 + 15, 9 + 15, 14 + 15, /* 1st bytes from pg3,pg4,pg5, and a padding */ - 2 + 30, 1 + 30, 4 + 30, 3 + 30, /* 4 bytes from pg6 */ - 7 + 30, 6 + 30, 9 + 30, 8 + 30, /* 4 bytes from pg7 */ - 12 + 30, 11 + 30, 14 + 30, 13 + 30, /* 4 bytes from pg8 */ - 63, 4 + 30, 9 + 30, 14 + 30, /* 1st bytes from pg6,pg7,pg8, and a padding */ - 2 + 45, 1 + 45, 4 + 45, 3 + 45, /* 4 bytes from pg6 */ - 7 + 45, 6 + 45, 9 + 45, 8 + 45, /* 4 bytes from pg7 */ - 12 + 45, 11 + 45, 14 + 45, 13 + 45, /* 4 bytes from pg8 */ - 63, 4 + 45, 9 + 45, 14 + 45, /* 1st bytes from pg9,pg10,pg11, and a padding */ + 2, 1, + 4, 3, /* 4 bytes from pg0 */ + 7, 6, + 9, 8, /* 4 bytes from pg1 */ + 12, 11, + 14, 13, /* 4 bytes from pg2 */ + 63, 4, + 9, 14, /* 1st bytes from pg0,pg1,pg2, and a padding */ + 2 + 15, 1 + 15, + 4 + 15, 3 + 15, /* 4 bytes from pg3 */ + 7 + 15, 6 + 15, + 9 + 15, 8 + 15, /* 4 bytes from pg4 */ + 12 + 15, 11 + 15, + 14 + 15, 13 + 15, /* 4 bytes from pg5 */ + 63, 4 + 15, + 9 + 15, 14 + 15, /* 1st bytes from pg3,pg4,pg5, and a padding */ + 2 + 30, 1 + 30, + 4 + 30, 3 + 30, /* 4 bytes from pg6 */ + 7 + 30, 6 + 30, + 9 + 30, 8 + 30, /* 4 bytes from pg7 */ + 12 + 30, 11 + 30, + 14 + 30, 13 + 30, /* 4 bytes from pg8 */ + 63, 4 + 30, + 9 + 30, 14 + 30, /* 1st bytes from pg6,pg7,pg8, and a padding */ + 2 + 45, 1 + 45, + 4 + 45, 3 + 45, /* 4 bytes from pg6 */ + 7 + 45, 6 + 45, + 9 + 45, 8 + 45, /* 4 bytes from pg7 */ + 12 + 45, 11 + 45, + 14 + 45, 13 + 45, /* 4 bytes from pg8 */ + 63, 4 + 45, + 9 + 45, 14 + 45, /* 1st bytes from pg9,pg10,pg11, and a padding */ }; static uint8_t be10_to_le_and_r0_tbl_512[64] = { - 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, - 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, - 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, - 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, - 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, + 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, + 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, + 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, + 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, + 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, + 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, }; static uint8_t be10_to_le_permute_l1_tbl_512[64] = { @@ -341,32 +395,38 @@ static uint8_t be10_to_le_permute_r1_tbl_512[64] = { 63, 63, 63, 63, /* zeros */ }; -int st20_rfc4175_422be10_to_422le10_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h) { - __m512i permute_l0 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_l0_tbl_512); - __m512i permute_r0 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_r0_tbl_512); - __m512i and_l0 = _mm512_loadu_si512((__m512i*)be10_to_le_and_l0_tbl_512); - __m512i and_r0 = _mm512_loadu_si512((__m512i*)be10_to_le_and_r0_tbl_512); - __m512i permute_l1 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_l1_tbl_512); - __m512i permute_r1 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_r1_tbl_512); +int st20_rfc4175_422be10_to_422le10_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { + __m512i permute_l0 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_l0_tbl_512); + __m512i permute_r0 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_r0_tbl_512); + __m512i and_l0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_l0_tbl_512); + __m512i and_r0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_r0_tbl_512); + __m512i permute_l1 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_l1_tbl_512); + __m512i permute_r1 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)pg_be); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_be); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = + _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = + _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ - _mm512_mask_storeu_epi32((__m512i*)pg_le, k, result); + _mm512_mask_storeu_epi32((__m512i *)pg_le, k, result); pg_be += 12; pg_le += 12; @@ -398,15 +458,19 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi(struct st20_rfc4175_422_10_pg2_b } int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le* pg_le, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { - __m512i permute_l0 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_l0_tbl_512); - __m512i permute_r0 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_r0_tbl_512); - __m512i and_l0 = _mm512_loadu_si512((__m512i*)be10_to_le_and_l0_tbl_512); - __m512i and_r0 = _mm512_loadu_si512((__m512i*)be10_to_le_and_r0_tbl_512); - __m512i permute_l1 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_l1_tbl_512); - __m512i permute_r1 = _mm512_loadu_si512((__m512i*)be10_to_le_permute_r1_tbl_512); + __m512i permute_l0 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_l0_tbl_512); + __m512i permute_r0 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_r0_tbl_512); + __m512i and_l0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_l0_tbl_512); + __m512i and_r0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_r0_tbl_512); + __m512i permute_l1 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_l1_tbl_512); + __m512i permute_r1 = + _mm512_loadu_si512((__m512i *)be10_to_le_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; @@ -417,25 +481,27 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); /* two type be(0) or le(1) */ - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le10_avx512_vbmi(pg_be, pg_le, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -444,7 +510,8 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -456,25 +523,28 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* be = be_cache; + struct st20_rfc4175_422_10_pg2_be *be = be_cache; int batch = cache_pg_cnt / 12; for (int j = 0; j < batch; j++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)be); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)be); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); - __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); - __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); + __m512i rl_result_shuffle = + _mm512_permutexvar_epi8(permute_l1, rl_result); + __m512i rr_result_shuffle = + _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ - _mm512_mask_storeu_epi32((__m512i*)pg_le, k, result); + _mm512_mask_storeu_epi32((__m512i *)pg_le, k, result); be += 12; pg_le += 12; @@ -488,17 +558,19 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( /* remaining simd batch */ int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)pg_be); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_be); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = + _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = + _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ - _mm512_mask_storeu_epi32((__m512i*)pg_le, k, result); + _mm512_mask_storeu_epi32((__m512i *)pg_le, k, result); pg_be += 12; pg_le += 12; @@ -569,11 +641,13 @@ static uint8_t be10_to_le8_multishift_tbl_512[16 * 4] = { 24, 54, 44, 34, /* pg11 */ }; -int st20_rfc4175_422be10_to_422le8_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h) { - __m512i permute_mask = _mm512_loadu_si512((__m512i*)be10_to_le8_permute_tbl_512); - __m512i multishift_mask = _mm512_loadu_si512((__m512i*)be10_to_le8_multishift_tbl_512); +int st20_rfc4175_422be10_to_422le8_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { + __m512i permute_mask = + _mm512_loadu_si512((__m512i *)be10_to_le8_permute_tbl_512); + __m512i multishift_mask = + _mm512_loadu_si512((__m512i *)be10_to_le8_multishift_tbl_512); __mmask16 k_load = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ __mmask32 k_compress = 0xDBDBDBDB; int pg_cnt = w * h / 2; @@ -610,11 +684,13 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be } int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_10, - mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le* pg_8, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { - __m512i permute_mask = _mm512_loadu_si512((__m512i*)be10_to_le8_permute_tbl_512); - __m512i multishift_mask = _mm512_loadu_si512((__m512i*)be10_to_le8_multishift_tbl_512); + __m512i permute_mask = + _mm512_loadu_si512((__m512i *)be10_to_le8_permute_tbl_512); + __m512i multishift_mask = + _mm512_loadu_si512((__m512i *)be10_to_le8_multishift_tbl_512); __mmask16 k_load = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ __mmask32 k_compress = 0xDBDBDBDB; int pg_cnt = w * h / 2; @@ -627,25 +703,27 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( size_t cache_size = cache_pg_cnt * sizeof(*pg_10); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be10_caches = + struct st20_rfc4175_422_10_pg2_be *be10_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); /* two type be(0) or le(1) */ - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be10_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be10_caches); - if (be10_caches) mt_rte_free(be10_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be10_caches); + if (be10_caches) + mt_rte_free(be10_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le8_avx512_vbmi(pg_10, pg_8, w, h); } rte_iova_t be10_caches_iova = rte_malloc_virt2iova(be10_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be10_cache = + struct st20_rfc4175_422_10_pg2_be *be10_cache = be10_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -667,9 +745,10 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* be_10 = be10_cache; + struct st20_rfc4175_422_10_pg2_be *be_10 = be10_cache; int batch = cache_pg_cnt / 12; for (int j = 0; j < batch; j++) { __m512i input = _mm512_maskz_loadu_epi32(k_load, be_10); @@ -722,14 +801,14 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( /* begin st20_rfc4175_422le10_to_v210_avx512_vbmi */ static uint8_t le10_to_v210_permute_tbl_512[16 * 4] = { - 0, 1, 2, 3, 4, 5, 6, 7, - 7, 8, 9, 10, 11, 12, 13, 14, /* pg0-2 */ - 0 + 15, 1 + 15, 2 + 15, 3 + 15, 4 + 15, 5 + 15, 6 + 15, 7 + 15, - 7 + 15, 8 + 15, 9 + 15, 10 + 15, 11 + 15, 12 + 15, 13 + 15, 14 + 15, /* pg3-5 */ - 0 + 30, 1 + 30, 2 + 30, 3 + 30, 4 + 30, 5 + 30, 6 + 30, 7 + 30, - 7 + 30, 8 + 30, 9 + 30, 10 + 30, 11 + 30, 12 + 30, 13 + 30, 14 + 30, /* pg6-8 */ - 0 + 45, 1 + 45, 2 + 45, 3 + 45, 4 + 45, 5 + 45, 6 + 45, 7 + 45, - 7 + 45, 8 + 45, 9 + 45, 10 + 45, 11 + 45, 12 + 45, 13 + 45, 14 + 45, /* pg9-11 */ + 0, 1, 2, 3, 4, 5, 6, 7, 7, + 8, 9, 10, 11, 12, 13, 14, /* pg0-2 */ + 0 + 15, 1 + 15, 2 + 15, 3 + 15, 4 + 15, 5 + 15, 6 + 15, 7 + 15, 7 + 15, + 8 + 15, 9 + 15, 10 + 15, 11 + 15, 12 + 15, 13 + 15, 14 + 15, /* pg3-5 */ + 0 + 30, 1 + 30, 2 + 30, 3 + 30, 4 + 30, 5 + 30, 6 + 30, 7 + 30, 7 + 30, + 8 + 30, 9 + 30, 10 + 30, 11 + 30, 12 + 30, 13 + 30, 14 + 30, /* pg6-8 */ + 0 + 45, 1 + 45, 2 + 45, 3 + 45, 4 + 45, 5 + 45, 6 + 45, 7 + 45, 7 + 45, + 8 + 45, 9 + 45, 10 + 45, 11 + 45, 12 + 45, 13 + 45, 14 + 45, /* pg9-11 */ }; static uint8_t le10_to_v210_multishift_tbl_512[16 * 4] = { @@ -739,36 +818,40 @@ static uint8_t le10_to_v210_multishift_tbl_512[16 * 4] = { 0, 8, 16, 24, 30, 38, 46, 54, 4, 12, 20, 28, 34, 42, 50, 58, }; static uint8_t le10_to_v210_and_tbl_512[16 * 4] = { - 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, - 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, - 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, - 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, - 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, + 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, + 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, + 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, + 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, + 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, + 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, }; -int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t* pg_le, uint8_t* pg_v210, uint32_t w, - uint32_t h) { - __m512i permute_mask = _mm512_loadu_si512((__m512i*)le10_to_v210_permute_tbl_512); - __m512i multishift_mask = _mm512_loadu_si512((__m512i*)le10_to_v210_multishift_tbl_512); - __m512i padding_mask = _mm512_loadu_si512((__m512i*)le10_to_v210_and_tbl_512); +int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t *pg_le, uint8_t *pg_v210, + uint32_t w, uint32_t h) { + __m512i permute_mask = + _mm512_loadu_si512((__m512i *)le10_to_v210_permute_tbl_512); + __m512i multishift_mask = + _mm512_loadu_si512((__m512i *)le10_to_v210_multishift_tbl_512); + __m512i padding_mask = + _mm512_loadu_si512((__m512i *)le10_to_v210_and_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", + __func__, pg_cnt); return -EINVAL; } int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)pg_le); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_le); __m512i permute_result = _mm512_permutexvar_epi8(permute_mask, input); __m512i multishift_result = _mm512_multishift_epi64_epi8(multishift_mask, permute_result); __m512i result = _mm512_and_si512(multishift_result, padding_mask); - _mm512_storeu_si512((__m512i*)pg_v210, result); + _mm512_storeu_si512((__m512i *)pg_v210, result); pg_le += 60; pg_v210 += 64; @@ -780,14 +863,18 @@ int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t* pg_le, uint8_t* pg_v210, u /* begin st20_rfc4175_422be10_to_v210_avx512_vbmi */ static uint8_t be10_to_v210_permute0_tbl_512[16 * 4] = { - 1, 0, 3, 2, 4, 3, 7, 6, - 8, 7, 11, 10, 12, 11, 14, 13, /* pg 0-2 */ - 1 + 15, 0 + 15, 3 + 15, 2 + 15, 4 + 15, 3 + 15, 7 + 15, 6 + 15, - 8 + 15, 7 + 15, 11 + 15, 10 + 15, 12 + 15, 11 + 15, 14 + 15, 13 + 15, /* pg 3-5 */ - 1 + 30, 0 + 30, 3 + 30, 2 + 30, 4 + 30, 3 + 30, 7 + 30, 6 + 30, - 8 + 30, 7 + 30, 11 + 30, 10 + 30, 12 + 30, 11 + 30, 14 + 30, 13 + 30, /* pg 6-8 */ - 1 + 45, 0 + 45, 3 + 45, 2 + 45, 4 + 45, 3 + 45, 7 + 45, 6 + 45, - 8 + 45, 7 + 45, 11 + 45, 10 + 45, 12 + 45, 11 + 45, 14 + 45, 13 + 45, /* pg 9-11 */ + 1, 0, 3, 2, 4, 3, + 7, 6, 8, 7, 11, 10, + 12, 11, 14, 13, /* pg 0-2 */ + 1 + 15, 0 + 15, 3 + 15, 2 + 15, 4 + 15, 3 + 15, + 7 + 15, 6 + 15, 8 + 15, 7 + 15, 11 + 15, 10 + 15, + 12 + 15, 11 + 15, 14 + 15, 13 + 15, /* pg 3-5 */ + 1 + 30, 0 + 30, 3 + 30, 2 + 30, 4 + 30, 3 + 30, + 7 + 30, 6 + 30, 8 + 30, 7 + 30, 11 + 30, 10 + 30, + 12 + 30, 11 + 30, 14 + 30, 13 + 30, /* pg 6-8 */ + 1 + 45, 0 + 45, 3 + 45, 2 + 45, 4 + 45, 3 + 45, + 7 + 45, 6 + 45, 8 + 45, 7 + 45, 11 + 45, 10 + 45, + 12 + 45, 11 + 45, 14 + 45, 13 + 45, /* pg 9-11 */ }; static uint8_t be10_to_v210_multishift0_tbl_512[16 * 4] = { 6, 14, 14, 22, 32, 40, 48, 56, 2, 10, 18, 26, 36, 44, 44, 52, /* pg 0-2 */ @@ -796,11 +883,12 @@ static uint8_t be10_to_v210_multishift0_tbl_512[16 * 4] = { 6, 14, 14, 22, 32, 40, 48, 56, 2, 10, 18, 26, 36, 44, 44, 52, /* pg 9-11 */ }; static uint8_t be10_to_v210_and0_tbl_512[16 * 4] = { - 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, - 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, - 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, - 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, - 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, + 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, + 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, + 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, + 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, + 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, + 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, }; static uint8_t be10_to_v210_permute1_tbl_512[16 * 4] = { 63, 2, 1, 63, 63, 6, 5, 63, @@ -819,35 +907,39 @@ static uint8_t be10_to_v210_multishift1_tbl_512[16 * 4] = { 0, 10, 18, 0, 0, 44, 52, 0, 0, 6, 14, 0, 0, 40, 48, 0, /* pg 9-11 */ }; static uint8_t be10_to_v210_and1_tbl_512[16 * 4] = { - 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, - 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, - 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, - 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, - 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, + 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, + 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, + 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, + 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, + 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, + 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, }; -int st20_rfc4175_422be10_to_v210_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210, uint32_t w, uint32_t h) { - __m512i permute0_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_permute0_tbl_512); +int st20_rfc4175_422be10_to_v210_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, + uint32_t h) { + __m512i permute0_mask = + _mm512_loadu_si512((__m512i *)be10_to_v210_permute0_tbl_512); __m512i multishift0_mask = - _mm512_loadu_si512((__m512i*)be10_to_v210_multishift0_tbl_512); - __m512i and0_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_and0_tbl_512); - __m512i permute1_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_permute1_tbl_512); + _mm512_loadu_si512((__m512i *)be10_to_v210_multishift0_tbl_512); + __m512i and0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and0_tbl_512); + __m512i permute1_mask = + _mm512_loadu_si512((__m512i *)be10_to_v210_permute1_tbl_512); __m512i multishift1_mask = - _mm512_loadu_si512((__m512i*)be10_to_v210_multishift1_tbl_512); - __m512i and1_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_and1_tbl_512); + _mm512_loadu_si512((__m512i *)be10_to_v210_multishift1_tbl_512); + __m512i and1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", + __func__, pg_cnt); return -EINVAL; } int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)pg_be); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_be); __m512i permute0_result = _mm512_permutexvar_epi8(permute0_mask, input); __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, permute0_result); @@ -858,7 +950,7 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* __m512i and1_result = _mm512_and_si512(multishift1_result, and1_mask); __m512i result = _mm512_or_si512(and0_result, and1_result); - _mm512_storeu_si512((__m512i*)pg_v210, result); + _mm512_storeu_si512((__m512i *)pg_v210, result); pg_be += 12; pg_v210 += 64; @@ -867,24 +959,25 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* return 0; } -int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint8_t* pg_v210, - uint32_t w, uint32_t h) { - __m512i permute0_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_permute0_tbl_512); +int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h) { + __m512i permute0_mask = + _mm512_loadu_si512((__m512i *)be10_to_v210_permute0_tbl_512); __m512i multishift0_mask = - _mm512_loadu_si512((__m512i*)be10_to_v210_multishift0_tbl_512); - __m512i and0_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_and0_tbl_512); - __m512i permute1_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_permute1_tbl_512); + _mm512_loadu_si512((__m512i *)be10_to_v210_multishift0_tbl_512); + __m512i and0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and0_tbl_512); + __m512i permute1_mask = + _mm512_loadu_si512((__m512i *)be10_to_v210_permute1_tbl_512); __m512i multishift1_mask = - _mm512_loadu_si512((__m512i*)be10_to_v210_multishift1_tbl_512); - __m512i and1_mask = _mm512_loadu_si512((__m512i*)be10_to_v210_and1_tbl_512); + _mm512_loadu_si512((__m512i *)be10_to_v210_multishift1_tbl_512); + __m512i and1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", + __func__, pg_cnt); return -EINVAL; } @@ -895,25 +988,27 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); /* two type be(0) or le(1) */ - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_v210_avx512_vbmi(pg_be, pg_v210, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -922,7 +1017,8 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -934,13 +1030,14 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* be = be_cache; + struct st20_rfc4175_422_10_pg2_be *be = be_cache; int batch = cache_pg_cnt / 12; for (int j = 0; j < batch; j++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)be); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)be); __m512i permute0_result = _mm512_permutexvar_epi8(permute0_mask, input); __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, permute0_result); @@ -951,7 +1048,7 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, __m512i and1_result = _mm512_and_si512(multishift1_result, and1_mask); __m512i result = _mm512_or_si512(and0_result, and1_result); - _mm512_storeu_si512((__m512i*)pg_v210, result); + _mm512_storeu_si512((__m512i *)pg_v210, result); be += 12; pg_v210 += 64; @@ -965,7 +1062,7 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)pg_be); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_be); __m512i permute0_result = _mm512_permutexvar_epi8(permute0_mask, input); __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, permute0_result); @@ -976,7 +1073,7 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, __m512i and1_result = _mm512_and_si512(multishift1_result, and1_mask); __m512i result = _mm512_or_si512(and0_result, and1_result); - _mm512_storeu_si512((__m512i*)pg_v210, result); + _mm512_storeu_si512((__m512i *)pg_v210, result); pg_be += 12; pg_v210 += 64; @@ -1026,35 +1123,47 @@ static uint16_t ple_to_be10_sllv_tbl_512[8 * 4] = { 0, }; -static uint8_t ple_to_be10_permute_hi_tbl_512[16 * 4] = { - 1 + (2 * 0), 0 + (2 * 0), 16 + (4 * 0), 32 + (2 * 0), 18 + (4 * 0), /* pg0 */ - 1 + (2 * 1), 0 + (2 * 1), 16 + (4 * 1), 32 + (2 * 1), 18 + (4 * 1), /* pg1 */ - 1 + (2 * 2), 0 + (2 * 2), 16 + (4 * 2), 32 + (2 * 2), 18 + (4 * 2), /* pg2 */ - 1 + (2 * 3), 0 + (2 * 3), 16 + (4 * 3), 32 + (2 * 3), 18 + (4 * 3), /* pg3 */ - 1 + (2 * 4), 0 + (2 * 4), 48 + (4 * 0), 32 + (2 * 4), 50 + (4 * 0), /* pg4 */ - 1 + (2 * 5), 0 + (2 * 5), 48 + (4 * 1), 32 + (2 * 5), 50 + (4 * 1), /* pg5 */ - 1 + (2 * 6), 0 + (2 * 6), 48 + (4 * 2), 32 + (2 * 6), 50 + (4 * 2), /* pg6 */ - 1 + (2 * 7), 0 + (2 * 7), 48 + (4 * 3), 32 + (2 * 7), 50 + (4 * 3), /* pg7 */ - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, /* 40-48 */ - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, /* 49-53 */ - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, /* 54-63 */ +static uint8_t ple_to_be10_permute_hi_tbl_512[16 * 4] = + { + 1 + (2 * 0), 0 + (2 * 0), 16 + (4 * 0), 32 + (2 * 0), + 18 + (4 * 0), /* pg0 */ + 1 + (2 * 1), 0 + (2 * 1), 16 + (4 * 1), 32 + (2 * 1), + 18 + (4 * 1), /* pg1 */ + 1 + (2 * 2), 0 + (2 * 2), 16 + (4 * 2), 32 + (2 * 2), + 18 + (4 * 2), /* pg2 */ + 1 + (2 * 3), 0 + (2 * 3), 16 + (4 * 3), 32 + (2 * 3), + 18 + (4 * 3), /* pg3 */ + 1 + (2 * 4), 0 + (2 * 4), 48 + (4 * 0), 32 + (2 * 4), + 50 + (4 * 0), /* pg4 */ + 1 + (2 * 5), 0 + (2 * 5), 48 + (4 * 1), 32 + (2 * 5), + 50 + (4 * 1), /* pg5 */ + 1 + (2 * 6), 0 + (2 * 6), 48 + (4 * 2), 32 + (2 * 6), + 50 + (4 * 2), /* pg6 */ + 1 + (2 * 7), 0 + (2 * 7), 48 + (4 * 3), 32 + (2 * 7), + 50 + (4 * 3), /* pg7 */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 40-48 */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 49-53 */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, /* 54-63 */ }; static uint8_t ple_to_be10_permute_lo_tbl_512[16 * 4] = { - 0, 17 + (4 * 0), 33 + (2 * 0), 19 + (4 * 0), 0, /* pg0 */ - 0, 17 + (4 * 1), 33 + (2 * 1), 19 + (4 * 1), 0, /* pg1 */ - 0, 17 + (4 * 2), 33 + (2 * 2), 19 + (4 * 2), 0, /* pg2 */ - 0, 17 + (4 * 3), 33 + (2 * 3), 19 + (4 * 3), 0, /* pg3 */ - 0, 49 + (4 * 0), 33 + (2 * 4), 51 + (4 * 0), 0, /* pg4 */ - 0, 49 + (4 * 1), 33 + (2 * 5), 51 + (4 * 1), 0, /* pg5 */ - 0, 49 + (4 * 2), 33 + (2 * 6), 51 + (4 * 2), 0, /* pg6 */ - 0, 49 + (4 * 3), 33 + (2 * 7), 51 + (4 * 3), 0, /* pg7 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40-48 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 49-53 */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 54-63 */ + 0, 17 + (4 * 0), 33 + (2 * 0), 19 + (4 * 0), 0, /* pg0 */ + 0, 17 + (4 * 1), 33 + (2 * 1), 19 + (4 * 1), 0, /* pg1 */ + 0, 17 + (4 * 2), 33 + (2 * 2), 19 + (4 * 2), 0, /* pg2 */ + 0, 17 + (4 * 3), 33 + (2 * 3), 19 + (4 * 3), 0, /* pg3 */ + 0, 49 + (4 * 0), 33 + (2 * 4), 51 + (4 * 0), 0, /* pg4 */ + 0, 49 + (4 * 1), 33 + (2 * 5), 51 + (4 * 1), 0, /* pg5 */ + 0, 49 + (4 * 2), 33 + (2 * 6), 51 + (4 * 2), 0, /* pg6 */ + 0, 49 + (4 * 3), 33 + (2 * 7), 51 + (4 * 3), 0, /* pg7 */ + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, /* 40-48 */ + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, /* 49-53 */ + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, /* 54-63 */ }; static uint8_t ple_to_be10_and_lo_tbl_512[16 * 4] = { @@ -1071,9 +1180,9 @@ static uint8_t ple_to_be10_and_lo_tbl_512[16 * 4] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 54-63 */ }; -int st20_yuv422p10le_to_rfc4175_422be10_vbmi(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h) { +int st20_yuv422p10le_to_rfc4175_422be10_vbmi( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { uint32_t pg_cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; __m512i sllv_le_mask = _mm512_loadu_si512(ple_to_be10_sllv_tbl_512); @@ -1086,13 +1195,13 @@ int st20_yuv422p10le_to_rfc4175_422be10_vbmi(uint16_t* y, uint16_t* b, uint16_t* /* each __m512i batch handle 4 __m128i, each __m128i with 2 pg group */ while (pg_cnt >= 8) { __m128i src_128i[4]; - src_128i[0] = _mm_loadu_si128((__m128i*)b); /* b0-b7 */ + src_128i[0] = _mm_loadu_si128((__m128i *)b); /* b0-b7 */ b += 8; - src_128i[1] = _mm_loadu_si128((__m128i*)y); /* y0-y7 */ + src_128i[1] = _mm_loadu_si128((__m128i *)y); /* y0-y7 */ y += 8; - src_128i[2] = _mm_loadu_si128((__m128i*)r); /* r0-r7 */ + src_128i[2] = _mm_loadu_si128((__m128i *)r); /* r0-r7 */ r += 8; - src_128i[3] = _mm_loadu_si128((__m128i*)y); /* y8-y15 */ + src_128i[3] = _mm_loadu_si128((__m128i *)y); /* y8-y15 */ y += 8; /* b0-b7, y0-y7, r0-r7, y8-y15 */ @@ -1103,8 +1212,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_vbmi(uint16_t* y, uint16_t* b, uint16_t* /* b0, r0, y0, y1, b1, r1, y2, y3 */ __m512i srlv_le_result = _mm512_sllv_epi16(src, sllv_le_mask); - __m512i permute_hi_result = _mm512_permutexvar_epi8(permute_hi_mask, srlv_le_result); - __m512i permute_lo_result = _mm512_permutexvar_epi8(permute_lo_mask, srlv_le_result); + __m512i permute_hi_result = + _mm512_permutexvar_epi8(permute_hi_mask, srlv_le_result); + __m512i permute_lo_result = + _mm512_permutexvar_epi8(permute_lo_mask, srlv_le_result); permute_lo_result = _mm512_and_si512(permute_lo_result, and_lo_mask); __m512i result = _mm512_or_si512(permute_hi_result, permute_lo_result); _mm512_mask_storeu_epi8(pg, k, result); @@ -1272,32 +1383,38 @@ static uint8_t le10_to_be_permute_r1_tbl_512[64] = { 0x3F, 0x3F, 0x3F, 0x3F, /* zeros */ }; -int st20_rfc4175_422le10_to_422be10_vbmi(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { - __m512i permute_l0 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_l0_tbl_512); - __m512i permute_r0 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_r0_tbl_512); - __m512i and_l0 = _mm512_loadu_si512((__m512i*)le10_to_be_and_l0_tbl_512); - __m512i and_r0 = _mm512_loadu_si512((__m512i*)le10_to_be_and_r0_tbl_512); - __m512i permute_l1 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_l1_tbl_512); - __m512i permute_r1 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_r1_tbl_512); +int st20_rfc4175_422le10_to_422be10_vbmi( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { + __m512i permute_l0 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_l0_tbl_512); + __m512i permute_r0 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_r0_tbl_512); + __m512i and_l0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_l0_tbl_512); + __m512i and_r0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_r0_tbl_512); + __m512i permute_l1 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_l1_tbl_512); + __m512i permute_r1 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)pg_le); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_le); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = + _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = + _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ - _mm512_mask_storeu_epi32((__m512i*)pg_be, k, result); + _mm512_mask_storeu_epi32((__m512i *)pg_be, k, result); pg_be += 12; pg_le += 12; @@ -1330,15 +1447,19 @@ int st20_rfc4175_422le10_to_422be10_vbmi(struct st20_rfc4175_422_10_pg2_le* pg_l } int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_le* pg_le, - mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be* pg_be, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { - __m512i permute_l0 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_l0_tbl_512); - __m512i permute_r0 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_r0_tbl_512); - __m512i and_l0 = _mm512_loadu_si512((__m512i*)le10_to_be_and_l0_tbl_512); - __m512i and_r0 = _mm512_loadu_si512((__m512i*)le10_to_be_and_r0_tbl_512); - __m512i permute_l1 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_l1_tbl_512); - __m512i permute_r1 = _mm512_loadu_si512((__m512i*)le10_to_be_permute_r1_tbl_512); + __m512i permute_l0 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_l0_tbl_512); + __m512i permute_r0 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_r0_tbl_512); + __m512i and_l0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_l0_tbl_512); + __m512i and_r0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_r0_tbl_512); + __m512i permute_l1 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_l1_tbl_512); + __m512i permute_r1 = + _mm512_loadu_si512((__m512i *)le10_to_be_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; @@ -1349,25 +1470,27 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( size_t cache_size = cache_pg_cnt * sizeof(*pg_le); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_le* le_caches = + struct st20_rfc4175_422_10_pg2_le *le_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); /* two type be(0) or le(1) */ - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!le_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - le_caches); - if (le_caches) mt_rte_free(le_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, le_caches); + if (le_caches) + mt_rte_free(le_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le10_avx512_vbmi(pg_be, pg_le, w, h); } rte_iova_t le_caches_iova = rte_malloc_virt2iova(le_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_le* le_cache = + struct st20_rfc4175_422_10_pg2_le *le_cache = le_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -1376,7 +1499,8 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = le_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + le_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_le_iova, cache_size); pg_le += cache_pg_cnt; pg_le_iova += cache_size; @@ -1388,25 +1512,28 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_le* le = le_cache; + struct st20_rfc4175_422_10_pg2_le *le = le_cache; int batch = cache_pg_cnt / 12; for (int j = 0; j < batch; j++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)le); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)le); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); - __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); - __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); + __m512i rl_result_shuffle = + _mm512_permutexvar_epi8(permute_l1, rl_result); + __m512i rr_result_shuffle = + _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ - _mm512_mask_storeu_epi32((__m512i*)pg_be, k, result); + _mm512_mask_storeu_epi32((__m512i *)pg_be, k, result); le += 12; pg_be += 12; @@ -1420,17 +1547,19 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( /* remaining simd batch */ int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i*)pg_le); + __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_le); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = + _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = + _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ - _mm512_mask_storeu_epi32((__m512i*)pg_be, k, result); + _mm512_mask_storeu_epi32((__m512i *)pg_be, k, result); pg_be += 12; pg_le += 12; @@ -1541,30 +1670,32 @@ static uint8_t v210_to_be10_and_tbl_512[16 * 4] = { 0x00, /* not used */ }; -int st20_v210_to_rfc4175_422be10_avx512_vbmi(uint8_t* pg_v210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { +int st20_v210_to_rfc4175_422be10_avx512_vbmi( + uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h) { __m512i multishift0_mask = - _mm512_loadu_si512((__m512i*)v210_to_be10_multishift0_tbl_512); - __m512i shuffle_mask = _mm512_loadu_si512((__m512i*)v210_to_be10_shuffle_tbl_512); + _mm512_loadu_si512((__m512i *)v210_to_be10_multishift0_tbl_512); + __m512i shuffle_mask = + _mm512_loadu_si512((__m512i *)v210_to_be10_shuffle_tbl_512); __m512i multishift1_mask = - _mm512_loadu_si512((__m512i*)v210_to_be10_multishift1_tbl_512); - __m512i and_mask = _mm512_loadu_si512((__m512i*)v210_to_be10_and_tbl_512); + _mm512_loadu_si512((__m512i *)v210_to_be10_multishift1_tbl_512); + __m512i and_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_and_tbl_512); __mmask64 k_store = 0x7FFF7FFF7FFF7FFF; /* each __m128i with 3 pg group, 15 bytes, 4*xmms*/ int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", + __func__, pg_cnt); return -EINVAL; } int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_loadu_si512((__m512i*)pg_v210); - __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, input); + __m512i input = _mm512_loadu_si512((__m512i *)pg_v210); + __m512i multishift0_result = + _mm512_multishift_epi64_epi8(multishift0_mask, input); __m512i shuffle_result = _mm512_shuffle_epi8(input, shuffle_mask); __m512i multishift1_result = _mm512_multishift_epi64_epi8(multishift1_mask, shuffle_result); @@ -1572,7 +1703,7 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi(uint8_t* pg_v210, __m512i and1_result = _mm512_andnot_si512(and_mask, multishift1_result); __m512i result = _mm512_or_si512(and0_result, and1_result); - _mm512_mask_compressstoreu_epi8((__m512i*)pg_be, k_store, result); + _mm512_mask_compressstoreu_epi8((__m512i *)pg_be, k_store, result); pg_be += 12; pg_v210 += 64; @@ -1581,53 +1712,55 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi(uint8_t* pg_v210, return 0; } -int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, - uint8_t* pg_v210, - mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { +int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( + struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { __m512i multishift0_mask = - _mm512_loadu_si512((__m512i*)v210_to_be10_multishift0_tbl_512); - __m512i shuffle_mask = _mm512_loadu_si512((__m512i*)v210_to_be10_shuffle_tbl_512); + _mm512_loadu_si512((__m512i *)v210_to_be10_multishift0_tbl_512); + __m512i shuffle_mask = + _mm512_loadu_si512((__m512i *)v210_to_be10_shuffle_tbl_512); __m512i multishift1_mask = - _mm512_loadu_si512((__m512i*)v210_to_be10_multishift1_tbl_512); - __m512i and_mask = _mm512_loadu_si512((__m512i*)v210_to_be10_and_tbl_512); + _mm512_loadu_si512((__m512i *)v210_to_be10_multishift1_tbl_512); + __m512i and_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_and_tbl_512); __mmask64 k_store = 0x7FFF7FFF7FFF7FFF; /* each __m128i with 3 pg group, 15 bytes, 4*xmms */ int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, - pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", + __func__, pg_cnt); return -EINVAL; } int caches_num = 4; int cache_3_pg_cnt = (256 * 1024) / 16; /* 3pg cnt for each cache */ - int align = caches_num * 4; /* align to simd pg groups and caches_num */ + int align = caches_num * 4; /* align to simd pg groups and caches_num */ cache_3_pg_cnt = cache_3_pg_cnt / align * align; size_t cache_size = cache_3_pg_cnt * 16; int soc_id = dma->parent->soc_id; - uint8_t* v210_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); + uint8_t *v210_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); /* two type v210(0) or be(1) */ - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!v210_caches || !ctx) { err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_3_pg_cnt, cache_size, v210_caches); - if (v210_caches) mt_rte_free(v210_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); + if (v210_caches) + mt_rte_free(v210_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); return st20_v210_to_rfc4175_422be10_avx512_vbmi(pg_v210, pg_be, w, h); } rte_iova_t v210_caches_iova = rte_malloc_virt2iova(v210_caches); /* first with caches batch step */ int cache_batch = pg_cnt / (cache_3_pg_cnt * 3); - dbg("%s, pg_cnt %d cache_3_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_3_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_3_pg_cnt %d caches_num %d cache_batch %d\n", + __func__, pg_cnt, cache_3_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - uint8_t* v210_cache = v210_caches + (i % caches_num) * (cache_3_pg_cnt * 16); + uint8_t *v210_cache = + v210_caches + (i % caches_num) * (cache_3_pg_cnt * 16); dbg("%s, cache batch idx %d\n", __func__, i); int max_tran = i + caches_num; @@ -1648,14 +1781,16 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - uint8_t* v210 = v210_cache; + uint8_t *v210 = v210_cache; int batch = cache_3_pg_cnt / 4; for (int j = 0; j < batch; j++) { - __m512i input = _mm512_loadu_si512((__m512i*)v210); - __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, input); + __m512i input = _mm512_loadu_si512((__m512i *)v210); + __m512i multishift0_result = + _mm512_multishift_epi64_epi8(multishift0_mask, input); __m512i shuffle_result = _mm512_shuffle_epi8(input, shuffle_mask); __m512i multishift1_result = _mm512_multishift_epi64_epi8(multishift1_mask, shuffle_result); @@ -1663,7 +1798,7 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, __m512i and1_result = _mm512_andnot_si512(and_mask, multishift1_result); __m512i result = _mm512_or_si512(and0_result, and1_result); - _mm512_mask_compressstoreu_epi8((__m512i*)pg_be, k_store, result); + _mm512_mask_compressstoreu_epi8((__m512i *)pg_be, k_store, result); pg_be += 12; v210 += 64; @@ -1677,8 +1812,9 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, /* remaining simd batch */ int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { - __m512i input = _mm512_loadu_si512((__m512i*)pg_v210); - __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, input); + __m512i input = _mm512_loadu_si512((__m512i *)pg_v210); + __m512i multishift0_result = + _mm512_multishift_epi64_epi8(multishift0_mask, input); __m512i shuffle_result = _mm512_shuffle_epi8(input, shuffle_mask); __m512i multishift1_result = _mm512_multishift_epi64_epi8(multishift1_mask, shuffle_result); @@ -1686,7 +1822,7 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, __m512i and1_result = _mm512_andnot_si512(and_mask, multishift1_result); __m512i result = _mm512_or_si512(and0_result, and1_result); - _mm512_mask_compressstoreu_epi8((__m512i*)pg_be, k_store, result); + _mm512_mask_compressstoreu_epi8((__m512i *)pg_be, k_store, result); pg_be += 12; pg_v210 += 64; @@ -1696,7 +1832,8 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, } /* end st20_v210_to_rfc4175_422be10_avx512_vbmi */ -int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t* pg_old, uint8_t* pg_new, +int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t *pg_old, + uint8_t *pg_new, uint32_t w, uint32_t h, uint32_t linesize_old, uint32_t linesize_new) { @@ -1707,8 +1844,8 @@ int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t* pg_old, uint8_t int batches = new_pg_per_line / new_pg_in_zmm; for (int line = 0; line < h; line++) { /* calculate offset */ - uint8_t* src = pg_old + linesize_old * line * 2; - uint8_t* dst = pg_new + linesize_new * line; + uint8_t *src = pg_old + linesize_old * line * 2; + uint8_t *dst = pg_new + linesize_new * line; /* for each batch */ for (int i = 0; i < batches; i++) { __m512i input = _mm512_loadu_si512(src); @@ -1730,14 +1867,22 @@ int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t* pg_old, uint8_t /* begin st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi */ static uint8_t be12_to_ple_permute_tbl_512[16 * 4] = { - 1, 0, 1 + 6, 0 + 6, 1 + 12, 0 + 12, 1 + 18, 0 + 18, /* b0, b1, b2, b3 */ - 1 + 24, 0 + 24, 1 + 30, 0 + 30, 1 + 36, 0 + 36, 1 + 42, 0 + 42, /* b4, b5, b6, b7 */ - 4, 3, 4 + 6, 3 + 6, 4 + 12, 3 + 12, 4 + 18, 3 + 18, /* r0, r1, r2, r3 */ - 4 + 24, 3 + 24, 4 + 30, 3 + 30, 4 + 36, 3 + 36, 4 + 42, 3 + 42, /* r4, r5, r6, r7 */ - 2, 1, 5, 4, 2 + 6, 1 + 6, 5 + 6, 4 + 6, /* y0 - y3 */ - 2 + 12, 1 + 12, 5 + 12, 4 + 12, 2 + 18, 1 + 18, 5 + 18, 4 + 18, /* y4 - y7 */ - 2 + 24, 1 + 24, 5 + 24, 4 + 24, 2 + 30, 1 + 30, 5 + 30, 4 + 30, /* y8 - y11 */ - 2 + 36, 1 + 36, 5 + 36, 4 + 36, 2 + 42, 1 + 42, 5 + 42, 4 + 42, /* y12 - y15 */ + 1, 0, 1 + 6, 0 + 6, + 1 + 12, 0 + 12, 1 + 18, 0 + 18, /* b0, b1, b2, b3 */ + 1 + 24, 0 + 24, 1 + 30, 0 + 30, + 1 + 36, 0 + 36, 1 + 42, 0 + 42, /* b4, b5, b6, b7 */ + 4, 3, 4 + 6, 3 + 6, + 4 + 12, 3 + 12, 4 + 18, 3 + 18, /* r0, r1, r2, r3 */ + 4 + 24, 3 + 24, 4 + 30, 3 + 30, + 4 + 36, 3 + 36, 4 + 42, 3 + 42, /* r4, r5, r6, r7 */ + 2, 1, 5, 4, + 2 + 6, 1 + 6, 5 + 6, 4 + 6, /* y0 - y3 */ + 2 + 12, 1 + 12, 5 + 12, 4 + 12, + 2 + 18, 1 + 18, 5 + 18, 4 + 18, /* y4 - y7 */ + 2 + 24, 1 + 24, 5 + 24, 4 + 24, + 2 + 30, 1 + 30, 5 + 30, 4 + 30, /* y8 - y11 */ + 2 + 36, 1 + 36, 5 + 36, 4 + 36, + 2 + 42, 1 + 42, 5 + 42, 4 + 42, /* y12 - y15 */ }; static uint16_t be12_to_ple_srlv_tbl_512[8 * 4] = { @@ -1748,15 +1893,19 @@ static uint16_t be12_to_ple_srlv_tbl_512[8 * 4] = { }; static uint16_t be12_to_ple_and_tbl_512[8 * 4] = { - 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* b0 - b7 */ - 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* r0 - r7 */ - 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y0 - y7 */ - 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y8 - y15 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, + 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* b0 - b7 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, + 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* r0 - r7 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, + 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y0 - y7 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, + 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y8 - y15 */ }; -int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(struct st20_rfc4175_422_12_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { +int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi( + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h) { __m512i permute_le_mask = _mm512_loadu_si512(be12_to_ple_permute_tbl_512); __m512i srlv_le_mask = _mm512_loadu_si512(be12_to_ple_srlv_tbl_512); __m512i srlv_and_mask = _mm512_loadu_si512(be12_to_ple_and_tbl_512); @@ -1779,13 +1928,13 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(struct st20_rfc4175_422_12_p __m128i result_Y0 = _mm512_extracti32x4_epi32(stage_m512i, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(stage_m512i, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; pg_cnt -= 8; @@ -1805,8 +1954,8 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(struct st20_rfc4175_422_12_p } int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { __m512i permute_le_mask = _mm512_loadu_si512(be12_to_ple_permute_tbl_512); __m512i srlv_le_mask = _mm512_loadu_si512(be12_to_ple_srlv_tbl_512); @@ -1821,24 +1970,27 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( size_t cache_size = cache_pg_cnt * sizeof(*pg_be); int soc_id = dma->parent->soc_id; - struct st20_rfc4175_422_10_pg2_be* be_caches = + struct st20_rfc4175_422_10_pg2_be *be_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); - struct mt_cvt_dma_ctx* ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); + struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, - be_caches); - if (be_caches) mt_rte_free(be_caches); - if (ctx) mt_cvt_dma_ctx_uinit(ctx); - return st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(pg_be, y, b, r, w, h); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, + cache_size, be_caches); + if (be_caches) + mt_rte_free(be_caches); + if (ctx) + mt_cvt_dma_ctx_uinit(ctx); + return st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(pg_be, y, b, r, w, + h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, - cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, + pg_cnt, cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - struct st20_rfc4175_422_10_pg2_be* be_cache = + struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; dbg("%s, cache batch idx %d\n", __func__, i); @@ -1847,7 +1999,8 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = + be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -1859,15 +2012,18 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) + mt_cvt_dma_ctx_pop(ctx); } - struct st20_rfc4175_422_10_pg2_be* pg = be_cache; + struct st20_rfc4175_422_10_pg2_be *pg = be_cache; int batch = cache_pg_cnt / 8; for (int j = 0; j < batch; j++) { __m512i input = _mm512_maskz_loadu_epi8(k, pg); - __m512i permute_le_result = _mm512_permutexvar_epi8(permute_le_mask, input); - __m512i srlv_le_result = _mm512_srlv_epi16(permute_le_result, srlv_le_mask); + __m512i permute_le_result = + _mm512_permutexvar_epi8(permute_le_mask, input); + __m512i srlv_le_result = + _mm512_srlv_epi16(permute_le_result, srlv_le_mask); __m512i stage_m512i = _mm512_and_si512(srlv_le_result, srlv_and_mask); pg += 8; @@ -1877,13 +2033,13 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( __m128i result_Y0 = _mm512_extracti32x4_epi32(stage_m512i, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(stage_m512i, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; } } @@ -1894,7 +2050,8 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( /* remaining simd batch */ int batch = pg_cnt / 8; - /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group */ + /* each m512i batch handle 4 __m512i(16 __m128i), each __m128i with 2 pg group + */ for (int i = 0; i < batch; i++) { __m512i input = _mm512_maskz_loadu_epi8(k, pg_be); __m512i permute_le_result = _mm512_permutexvar_epi8(permute_le_mask, input); @@ -1908,13 +2065,13 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( __m128i result_Y0 = _mm512_extracti32x4_epi32(stage_m512i, 2); __m128i result_Y1 = _mm512_extracti32x4_epi32(stage_m512i, 3); - _mm_storeu_si128((__m128i*)b, result_B); + _mm_storeu_si128((__m128i *)b, result_B); b += 2 * 4; - _mm_storeu_si128((__m128i*)r, result_R); + _mm_storeu_si128((__m128i *)r, result_R); r += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y0); + _mm_storeu_si128((__m128i *)y, result_Y0); y += 2 * 4; - _mm_storeu_si128((__m128i*)y, result_Y1); + _mm_storeu_si128((__m128i *)y, result_Y1); y += 2 * 4; } pg_cnt = pg_cnt % 8; diff --git a/lib/src/st2110/st_avx512_vbmi.h b/lib/src/st2110/st_avx512_vbmi.h index a0d99680a..5cdad5435 100644 --- a/lib/src/st2110/st_avx512_vbmi.h +++ b/lib/src/st2110/st_avx512_vbmi.h @@ -7,75 +7,76 @@ #include "st_main.h" -int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le10_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le8_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le8_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h); int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_10, - mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le* pg_8, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h); -int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t* pg_le, uint8_t* pg_v210, uint32_t w, - uint32_t h); +int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t *pg_le, uint8_t *pg_v210, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_v210_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_v210_avx512_vbmi( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, + uint32_t h); int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le* pg_le, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h); int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, uint32_t h); + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h); -int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint8_t* pg_v210, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h); -int st20_yuv422p10le_to_rfc4175_422be10_vbmi(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h); +int st20_yuv422p10le_to_rfc4175_422be10_vbmi( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h); -int st20_rfc4175_422le10_to_422be10_vbmi(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); +int st20_rfc4175_422le10_to_422be10_vbmi( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_10_pg2_le* pg_le, - mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be* pg_be, uint32_t w, + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); -int st20_v210_to_rfc4175_422be10_avx512_vbmi(uint8_t* pg_v210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); +int st20_v210_to_rfc4175_422be10_avx512_vbmi( + uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h); -int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev* dma, - uint8_t* pg_v210, - mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h); +int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( + struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); -int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(struct st20_rfc4175_422_12_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi( + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h); int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( - struct mtl_dma_lender_dev* dma, struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, uint32_t h); + struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h); -int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t* pg_old, uint8_t* pg_new, +int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t *pg_old, + uint8_t *pg_new, uint32_t w, uint32_t h, uint32_t linesize_old, uint32_t linesize_new); diff --git a/lib/src/st2110/st_convert.c b/lib/src/st2110/st_convert.c index c882a8acc..73944f535 100644 --- a/lib/src/st2110/st_convert.c +++ b/lib/src/st2110/st_convert.c @@ -19,31 +19,33 @@ #include "st_avx512_vbmi.h" #endif -static bool has_lines_padding(struct st_frame* src, struct st_frame* dst) { +static bool has_lines_padding(struct st_frame *src, struct st_frame *dst) { int planes = 0; planes = st_frame_fmt_planes(src->fmt); for (int plane = 0; plane < planes; plane++) { - if (src->linesize[plane] > st_frame_least_linesize(src->fmt, src->width, plane)) + if (src->linesize[plane] > + st_frame_least_linesize(src->fmt, src->width, plane)) return true; } planes = st_frame_fmt_planes(dst->fmt); for (int plane = 0; plane < planes; plane++) { - if (dst->linesize[plane] > st_frame_least_linesize(dst->fmt, dst->width, plane)) + if (dst->linesize[plane] > + st_frame_least_linesize(dst->fmt, dst->width, plane)) return true; } return false; } -static int convert_rfc4175_422be10_to_yuv422p10le(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_422be10_to_yuv422p10le(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -64,10 +66,11 @@ static int convert_rfc4175_422be10_to_yuv422p10le(struct st_frame* src, return ret; } -static int convert_rfc4175_422be10_to_422le8(struct st_frame* src, struct st_frame* dst) { +static int convert_rfc4175_422be10_to_422le8(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - struct st20_rfc4175_422_8_pg2_le* le8 = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + struct st20_rfc4175_422_8_pg2_le *le8 = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -84,13 +87,13 @@ static int convert_rfc4175_422be10_to_422le8(struct st_frame* src, struct st_fra return ret; } -static int convert_rfc4175_422be10_to_yuv422p8(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_422be10_to_yuv422p8(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint8_t* y = NULL; - uint8_t* b = NULL; - uint8_t* r = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint8_t *y = NULL; + uint8_t *b = NULL; + uint8_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -111,13 +114,13 @@ static int convert_rfc4175_422be10_to_yuv422p8(struct st_frame* src, return ret; } -static int convert_rfc4175_422be10_to_yuv420p8(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_422be10_to_yuv420p8(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint8_t* y = NULL; - uint8_t* b = NULL; - uint8_t* r = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint8_t *y = NULL; + uint8_t *b = NULL; + uint8_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -138,10 +141,11 @@ static int convert_rfc4175_422be10_to_yuv420p8(struct st_frame* src, return ret; } -static int convert_rfc4175_422be10_to_v210(struct st_frame* src, struct st_frame* dst) { +static int convert_rfc4175_422be10_to_v210(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint8_t* v210 = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint8_t *v210 = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -158,10 +162,11 @@ static int convert_rfc4175_422be10_to_v210(struct st_frame* src, struct st_frame return ret; } -static int convert_rfc4175_422be10_to_y210(struct st_frame* src, struct st_frame* dst) { +static int convert_rfc4175_422be10_to_y210(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint16_t* y210 = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint16_t *y210 = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -178,13 +183,13 @@ static int convert_rfc4175_422be10_to_y210(struct st_frame* src, struct st_frame return ret; } -static int convert_rfc4175_422be12_to_yuv422p12le(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_422be12_to_yuv422p12le(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_12_pg2_be* be12 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_422_12_pg2_be *be12 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -205,13 +210,13 @@ static int convert_rfc4175_422be12_to_yuv422p12le(struct st_frame* src, return ret; } -static int convert_rfc4175_444be10_to_yuv444p10le(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_444be10_to_yuv444p10le(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_10_pg4_be* be10 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_10_pg4_be *be10 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -232,13 +237,13 @@ static int convert_rfc4175_444be10_to_yuv444p10le(struct st_frame* src, return ret; } -static int convert_rfc4175_444be10_to_gbrp10le(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_444be10_to_gbrp10le(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_10_pg4_be* be10 = NULL; - uint16_t* g = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_10_pg4_be *be10 = NULL; + uint16_t *g = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -259,13 +264,13 @@ static int convert_rfc4175_444be10_to_gbrp10le(struct st_frame* src, return ret; } -static int convert_rfc4175_444be12_to_yuv444p12le(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_444be12_to_yuv444p12le(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_12_pg2_be* be12 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_12_pg2_be *be12 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -286,13 +291,13 @@ static int convert_rfc4175_444be12_to_yuv444p12le(struct st_frame* src, return ret; } -static int convert_rfc4175_444be12_to_gbrp12le(struct st_frame* src, - struct st_frame* dst) { +static int convert_rfc4175_444be12_to_gbrp12le(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_12_pg2_be* be12 = NULL; - uint16_t* g = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_12_pg2_be *be12 = NULL; + uint16_t *g = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -313,13 +318,13 @@ static int convert_rfc4175_444be12_to_gbrp12le(struct st_frame* src, return ret; } -static int convert_yuv422p10le_to_rfc4175_422be10(struct st_frame* src, - struct st_frame* dst) { +static int convert_yuv422p10le_to_rfc4175_422be10(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -340,10 +345,11 @@ static int convert_yuv422p10le_to_rfc4175_422be10(struct st_frame* src, return ret; } -static int convert_v210_to_rfc4175_422be10(struct st_frame* src, struct st_frame* dst) { +static int convert_v210_to_rfc4175_422be10(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint8_t* v210 = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint8_t *v210 = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -360,10 +366,11 @@ static int convert_v210_to_rfc4175_422be10(struct st_frame* src, struct st_frame return ret; } -static int convert_y210_to_rfc4175_422be10(struct st_frame* src, struct st_frame* dst) { +static int convert_y210_to_rfc4175_422be10(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_10_pg2_be* be10 = NULL; - uint16_t* y210 = NULL; + struct st20_rfc4175_422_10_pg2_be *be10 = NULL; + uint16_t *y210 = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -380,13 +387,13 @@ static int convert_y210_to_rfc4175_422be10(struct st_frame* src, struct st_frame return ret; } -static int convert_yuv422p12le_to_rfc4175_422be12(struct st_frame* src, - struct st_frame* dst) { +static int convert_yuv422p12le_to_rfc4175_422be12(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_422_12_pg2_be* be12 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_422_12_pg2_be *be12 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -407,13 +414,13 @@ static int convert_yuv422p12le_to_rfc4175_422be12(struct st_frame* src, return ret; } -static int convert_yuv444p10le_to_rfc4175_444be10(struct st_frame* src, - struct st_frame* dst) { +static int convert_yuv444p10le_to_rfc4175_444be10(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_10_pg4_be* be10 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_10_pg4_be *be10 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -434,13 +441,13 @@ static int convert_yuv444p10le_to_rfc4175_444be10(struct st_frame* src, return ret; } -static int convert_gbrp10le_to_rfc4175_444be10(struct st_frame* src, - struct st_frame* dst) { +static int convert_gbrp10le_to_rfc4175_444be10(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_10_pg4_be* be10 = NULL; - uint16_t* g = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_10_pg4_be *be10 = NULL; + uint16_t *g = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -461,13 +468,13 @@ static int convert_gbrp10le_to_rfc4175_444be10(struct st_frame* src, return ret; } -static int convert_yuv444p12le_to_rfc4175_444be12(struct st_frame* src, - struct st_frame* dst) { +static int convert_yuv444p12le_to_rfc4175_444be12(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_12_pg2_be* be12 = NULL; - uint16_t* y = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_12_pg2_be *be12 = NULL; + uint16_t *y = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -488,13 +495,13 @@ static int convert_yuv444p12le_to_rfc4175_444be12(struct st_frame* src, return ret; } -static int convert_gbrp12le_to_rfc4175_444be12(struct st_frame* src, - struct st_frame* dst) { +static int convert_gbrp12le_to_rfc4175_444be12(struct st_frame *src, + struct st_frame *dst) { int ret = 0; - struct st20_rfc4175_444_12_pg2_be* be12 = NULL; - uint16_t* g = NULL; - uint16_t* b = NULL; - uint16_t* r = NULL; + struct st20_rfc4175_444_12_pg2_be *be12 = NULL; + uint16_t *g = NULL; + uint16_t *b = NULL; + uint16_t *r = NULL; uint32_t h = st_frame_data_height(dst); if (!has_lines_padding(src, dst)) { @@ -613,7 +620,7 @@ static const struct st_frame_converter converters[] = { }, }; -int st_frame_convert(struct st_frame* src, struct st_frame* dst) { +int st_frame_convert(struct st_frame *src, struct st_frame *dst) { if (src->width != dst->width || src->height != dst->height) { err("%s, width/height mismatch, source: %u x %u, dest: %u x %u\n", __func__, src->width, src->height, dst->width, dst->height); @@ -627,7 +634,8 @@ int st_frame_convert(struct st_frame* src, struct st_frame* dst) { return converter.convert_func(src, dst); } -static int field_frame_check(const struct st_frame* field, const struct st_frame* frame) { +static int field_frame_check(const struct st_frame *field, + const struct st_frame *frame) { if (!field->interlaced) { err("%s, field is not field\n", __func__); return -EINVAL; @@ -638,14 +646,16 @@ static int field_frame_check(const struct st_frame* field, const struct st_frame return -EINVAL; } if (field->fmt != frame->fmt) { - err("%s, fmt mismatch, field: %d, frame: %d\n", __func__, field->fmt, frame->fmt); + err("%s, fmt mismatch, field: %d, frame: %d\n", __func__, field->fmt, + frame->fmt); return -EINVAL; } return 0; } -static int fields_frame_match(const struct st_frame* first, const struct st_frame* second, - const struct st_frame* frame) { +static int fields_frame_match(const struct st_frame *first, + const struct st_frame *second, + const struct st_frame *frame) { int ret = field_frame_check(first, frame); if (ret < 0) { err("%s, first field check fail %d\n", __func__, ret); @@ -667,19 +677,21 @@ static int fields_frame_match(const struct st_frame* first, const struct st_fram return 0; } -int st_field_merge(const struct st_frame* first, const struct st_frame* second, - struct st_frame* frame) { +int st_field_merge(const struct st_frame *first, const struct st_frame *second, + struct st_frame *frame) { int ret = fields_frame_match(first, second, frame); - if (ret < 0) return ret; + if (ret < 0) + return ret; uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint32_t line = 0; line < frame->height; line += 2) { for (uint8_t plane = 0; plane < planes; plane++) { - size_t linesize = st_frame_least_linesize(frame->fmt, frame->width, plane); + size_t linesize = + st_frame_least_linesize(frame->fmt, frame->width, plane); uint32_t field_line = line / 2; /* first line */ - void* f_addr = frame->addr[plane] + frame->linesize[plane] * line; - void* src = first->addr[plane] + first->linesize[plane] * field_line; + void *f_addr = frame->addr[plane] + frame->linesize[plane] * line; + void *src = first->addr[plane] + first->linesize[plane] * field_line; mtl_memcpy(f_addr, src, linesize); /* second line */ f_addr = frame->addr[plane] + frame->linesize[plane] * (line + 1); @@ -692,19 +704,21 @@ int st_field_merge(const struct st_frame* first, const struct st_frame* second, } /** split one full frame to two fields */ -int st_field_split(const struct st_frame* frame, struct st_frame* first, - struct st_frame* second) { +int st_field_split(const struct st_frame *frame, struct st_frame *first, + struct st_frame *second) { int ret = fields_frame_match(first, second, frame); - if (ret < 0) return ret; + if (ret < 0) + return ret; uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint32_t line = 0; line < frame->height; line += 2) { for (uint8_t plane = 0; plane < planes; plane++) { - size_t linesize = st_frame_least_linesize(frame->fmt, frame->width, plane); + size_t linesize = + st_frame_least_linesize(frame->fmt, frame->width, plane); uint32_t field_line = line / 2; /* first line */ - void* f_addr = frame->addr[plane] + frame->linesize[plane] * line; - void* src = first->addr[plane] + first->linesize[plane] * field_line; + void *f_addr = frame->addr[plane] + frame->linesize[plane] * line; + void *src = first->addr[plane] + first->linesize[plane] * field_line; mtl_memcpy(src, f_addr, linesize); /* second line */ f_addr = frame->addr[plane] + frame->linesize[plane] * (line + 1); @@ -717,7 +731,7 @@ int st_field_split(const struct st_frame* frame, struct st_frame* first, } int st_frame_get_converter(enum st_frame_fmt src_fmt, enum st_frame_fmt dst_fmt, - struct st_frame_converter* converter) { + struct st_frame_converter *converter) { for (int i = 0; i < MTL_ARRAY_SIZE(converters); i++) { if (src_fmt == converters[i].src_fmt && dst_fmt == converters[i].dst_fmt) { *converter = converters[i]; @@ -730,8 +744,8 @@ int st_frame_get_converter(enum st_frame_fmt src_fmt, enum st_frame_fmt dst_fmt, return -EINVAL; } -static int downsample_rfc4175_wh_half(struct st_frame* old_frame, - struct st_frame* new_frame, int idx) { +static int downsample_rfc4175_wh_half(struct st_frame *old_frame, + struct st_frame *new_frame, int idx) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret = 0; @@ -746,24 +760,24 @@ static int downsample_rfc4175_wh_half(struct st_frame* old_frame, uint32_t height = st_frame_data_height(new_frame); uint32_t src_linesize = old_frame->linesize[0]; uint32_t dst_linesize = new_frame->linesize[0]; - uint8_t* src_start = old_frame->addr[0]; - uint8_t* dst_start = new_frame->addr[0]; + uint8_t *src_start = old_frame->addr[0]; + uint8_t *dst_start = new_frame->addr[0]; /* check the idx and set src offset */ switch (idx) { - case 0: - break; - case 1: - src_start += st20_pg.size; - break; - case 2: - src_start += src_linesize; - break; - case 3: - src_start += src_linesize + st20_pg.size; - break; - default: - err("%s, wrong sample idx %d\n", __func__, idx); - return -EINVAL; + case 0: + break; + case 1: + src_start += st20_pg.size; + break; + case 2: + src_start += src_linesize; + break; + case 3: + src_start += src_linesize + st20_pg.size; + break; + default: + err("%s, wrong sample idx %d\n", __func__, idx); + return -EINVAL; } #ifdef MTL_HAS_AVX512_VBMI2 @@ -772,7 +786,8 @@ static int downsample_rfc4175_wh_half(struct st_frame* old_frame, dbg("%s, avx512_vbmi way\n", __func__); ret = st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi( src_start, dst_start, width, height, src_linesize, dst_linesize); - if (ret == 0) return 0; + if (ret == 0) + return 0; err("%s, avx512_vbmi way failed %d\n", __func__, ret); } } @@ -780,8 +795,8 @@ static int downsample_rfc4175_wh_half(struct st_frame* old_frame, /* scalar fallback */ for (int line = 0; line < height; line++) { - uint8_t* src = src_start + src_linesize * line * 2; - uint8_t* dst = dst_start + dst_linesize * line; + uint8_t *src = src_start + src_linesize * line * 2; + uint8_t *dst = dst_start + dst_linesize * line; for (int pg = 0; pg < width / st20_pg.coverage; pg++) { mtl_memcpy(dst, src, st20_pg.size); src += 2 * st20_pg.size; @@ -791,7 +806,7 @@ static int downsample_rfc4175_wh_half(struct st_frame* old_frame, return 0; } -int st_frame_downsample(struct st_frame* src, struct st_frame* dst, int idx) { +int st_frame_downsample(struct st_frame *src, struct st_frame *dst, int idx) { if (src->fmt == dst->fmt) { if (st_frame_fmt_to_transport(src->fmt) != ST20_FMT_MAX) { if (src->width == dst->width * 2 && src->height == dst->height * 2) { @@ -800,15 +815,15 @@ int st_frame_downsample(struct st_frame* src, struct st_frame* dst, int idx) { } } - err("%s, downsample not supported, source: %s %ux%u, dest: %s %ux%u\n", __func__, - st_frame_fmt_name(src->fmt), src->width, src->height, st_frame_fmt_name(dst->fmt), - dst->width, dst->height); + err("%s, downsample not supported, source: %s %ux%u, dest: %s %ux%u\n", + __func__, st_frame_fmt_name(src->fmt), src->width, src->height, + st_frame_fmt_name(dst->fmt), dst->width, dst->height); return -EINVAL; } static int st20_yuv422p10le_to_rfc4175_422be10_scalar( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h) { + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -833,10 +848,10 @@ static int st20_yuv422p10le_to_rfc4175_422be10_scalar( return 0; } -int st20_yuv422p10le_to_rfc4175_422be10_simd(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_be* pg, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_yuv422p10le_to_rfc4175_422be10_simd( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -844,10 +859,12 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd(uint16_t* y, uint16_t* b, uint16_t* MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_yuv422p10le_to_rfc4175_422be10_avx512(y, b, r, pg, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; err("%s, avx512 ways failed %d\n", __func__, ret); } #endif @@ -857,9 +874,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd(uint16_t* y, uint16_t* b, uint16_t* } int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint16_t* y, mtl_iova_t y_iova, uint16_t* b, mtl_iova_t b_iova, - uint16_t* r, mtl_iova_t r_iova, struct st20_rfc4175_422_10_pg2_be* pg, uint32_t w, - uint32_t h, enum mtl_simd_level level) { + mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, + mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, + struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -867,11 +885,13 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(udma, y, y_iova, b, b_iova, r, - r_iova, pg, w, h); - if (ret == 0) return 0; + ret = st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( + udma, y, y_iova, b, b_iova, r, r_iova, pg, w, h); + if (ret == 0) + return 0; err("%s, avx512 ways failed %d\n", __func__, ret); } #endif @@ -881,8 +901,8 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( } static int st20_rfc4175_422be10_to_yuv422p10le_scalar( - struct st20_rfc4175_422_10_pg2_be* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -902,10 +922,9 @@ static int st20_rfc4175_422be10_to_yuv422p10le_scalar( return 0; } -int st20_rfc4175_422be10_to_yuv422p10le_simd(struct st20_rfc4175_422_10_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_yuv422p10le_simd( + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -918,16 +937,19 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd(struct st20_rfc4175_422_10_pg2_be* (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(pg, y, b, r, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv422p10le_avx512(pg, y, b, r, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -937,9 +959,10 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd(struct st20_rfc4175_422_10_pg2_be* } static int st20_rfc4175_422be10_to_yuv422p10le_scalar_2way( - struct st20_rfc4175_422_10_pg2_be* pg_be, uint16_t* y_full, uint16_t* b_full, - uint16_t* r_full, uint32_t w, uint32_t h, uint16_t* y_decimated, - uint16_t* b_decimated, uint16_t* r_decimated, int decimator) { + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, + uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, + uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, + int decimator) { uint32_t pg_per_line = w / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; int stride = decimator - 1; @@ -971,10 +994,10 @@ static int st20_rfc4175_422be10_to_yuv422p10le_scalar_2way( } int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( - struct st20_rfc4175_422_10_pg2_be* pg_be, uint16_t* y_full, uint16_t* b_full, - uint16_t* r_full, uint32_t w, uint32_t h, uint16_t* y_decimated, - uint16_t* b_decimated, uint16_t* r_decimated, int decimator, - enum mtl_simd_level level) { + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, + uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, + uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, + int decimator, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -996,16 +1019,15 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( } /* the last option */ - return st20_rfc4175_422be10_to_yuv422p10le_scalar_2way(pg_be, y_full, b_full, r_full, w, - h, y_decimated, b_decimated, - r_decimated, decimator); + return st20_rfc4175_422be10_to_yuv422p10le_scalar_2way( + pg_be, y_full, b_full, r_full, w, h, y_decimated, b_decimated, + r_decimated, decimator); } -int st20_rfc4175_422be10_to_yuv422p10le_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, - uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_yuv422p10le_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1016,19 +1038,22 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_dma(mtl_udma_handle udma, if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma(udma, pg_be, pg_be_iova, y, - b, r, w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( + udma, pg_be, pg_be_iova, y, b, r, w, h); + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_dma(udma, pg_be, pg_be_iova, y, b, r, - w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( + udma, pg_be, pg_be_iova, y, b, r, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1037,9 +1062,9 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_dma(mtl_udma_handle udma, return st20_rfc4175_422be10_to_yuv422p10le_scalar(pg_be, y, b, r, w, h); } -int st20_yuv422p10le_to_rfc4175_422le10(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_10_pg2_le* pg, uint32_t w, - uint32_t h) { +int st20_yuv422p10le_to_rfc4175_422le10(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_le *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -1064,9 +1089,9 @@ int st20_yuv422p10le_to_rfc4175_422le10(uint16_t* y, uint16_t* b, uint16_t* r, return 0; } -int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le* pg, - uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h) { +int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -1086,9 +1111,9 @@ int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le* pg, return 0; } -int st20_rfc4175_422be10_to_422le10_scalar(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_422le10_scalar( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; uint16_t cb, y0, cr, y1; @@ -1114,10 +1139,10 @@ int st20_rfc4175_422be10_to_422le10_scalar(struct st20_rfc4175_422_10_pg2_be* pg return 0; } -int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_422le10_simd( + struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1129,16 +1154,19 @@ int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be* pg_b (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_422le10_avx512_vbmi(pg_be, pg_le, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_422le10_avx512(pg_be, pg_le, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1147,7 +1175,8 @@ int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be* pg_b if ((level >= MTL_SIMD_LEVEL_AVX2) && (cpu_level >= MTL_SIMD_LEVEL_AVX2)) { dbg("%s, avx2 ways\n", __func__); ret = st20_rfc4175_422be10_to_422le10_avx2(pg_be, pg_le, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx2 ways failed\n", __func__); } #endif @@ -1156,13 +1185,11 @@ int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be* pg_b return st20_rfc4175_422be10_to_422le10_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422be10_to_422le10_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_10_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { - struct mtl_dma_lender_dev* dma = udma; +int st20_rfc4175_422be10_to_422le10_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, + uint32_t h, enum mtl_simd_level level) { + struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1174,18 +1201,22 @@ int st20_rfc4175_422be10_to_422le10_simd_dma(mtl_udma_handle udma, if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma(dma, pg_be, pg_be_iova, pg_le, - w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( + dma, pg_be, pg_be_iova, pg_le, w, h); + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le10_avx512_dma(dma, pg_be, pg_be_iova, pg_le, w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_422le10_avx512_dma(dma, pg_be, pg_be_iova, + pg_le, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1194,9 +1225,9 @@ int st20_rfc4175_422be10_to_422le10_simd_dma(mtl_udma_handle udma, return st20_rfc4175_422be10_to_422le10_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422le10_to_422be10_scalar(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { +int st20_rfc4175_422le10_to_422be10_scalar( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -1222,10 +1253,10 @@ int st20_rfc4175_422le10_to_422be10_scalar(struct st20_rfc4175_422_10_pg2_le* pg return 0; } -int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le* pg_le, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422le10_to_422be10_simd( + struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1237,16 +1268,19 @@ int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le* pg_l (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422le10_to_422be10_vbmi(pg_le, pg_be, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422le10_to_422be10_avx512(pg_le, pg_be, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1255,7 +1289,8 @@ int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le* pg_l if ((level >= MTL_SIMD_LEVEL_AVX2) && (cpu_level >= MTL_SIMD_LEVEL_AVX2)) { dbg("%s, avx2 ways\n", __func__); ret = st20_rfc4175_422le10_to_422be10_avx2(pg_le, pg_be, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx2 ways failed\n", __func__); } #endif @@ -1264,13 +1299,11 @@ int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le* pg_l return st20_rfc4175_422le10_to_422be10_scalar(pg_le, pg_be, w, h); } -int st20_rfc4175_422le10_to_422be10_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_le* pg_le, - mtl_iova_t pg_le_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { - struct mtl_dma_lender_dev* dma = udma; +int st20_rfc4175_422le10_to_422be10_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h, enum mtl_simd_level level) { + struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1282,18 +1315,22 @@ int st20_rfc4175_422le10_to_422be10_simd_dma(mtl_udma_handle udma, if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma(dma, pg_le, pg_le_iova, pg_be, - w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( + dma, pg_le, pg_le_iova, pg_be, w, h); + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422le10_to_422be10_avx512_dma(dma, pg_le, pg_le_iova, pg_be, w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422le10_to_422be10_avx512_dma(dma, pg_le, pg_le_iova, + pg_be, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1302,9 +1339,9 @@ int st20_rfc4175_422le10_to_422be10_simd_dma(mtl_udma_handle udma, return st20_rfc4175_422le10_to_422be10_scalar(pg_le, pg_be, w, h); } -int st20_rfc4175_422be10_to_422le8_scalar(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_422le8_scalar( + struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; for (uint32_t i = 0; i < cnt; i++) { @@ -1317,10 +1354,10 @@ int st20_rfc4175_422be10_to_422le8_scalar(struct st20_rfc4175_422_10_pg2_be* pg_ return 0; } -int st20_rfc4175_422be10_to_422le8_simd(struct st20_rfc4175_422_10_pg2_be* pg_10, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_422le8_simd( + struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1332,16 +1369,19 @@ int st20_rfc4175_422be10_to_422le8_simd(struct st20_rfc4175_422_10_pg2_be* pg_10 (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_422le8_avx512_vbmi(pg_10, pg_8, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_422le8_avx512(pg_10, pg_8, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1350,13 +1390,11 @@ int st20_rfc4175_422be10_to_422le8_simd(struct st20_rfc4175_422_10_pg2_be* pg_10 return st20_rfc4175_422be10_to_422le8_scalar(pg_10, pg_8, w, h); } -int st20_rfc4175_422be10_to_422le8_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_10, - mtl_iova_t pg_10_iova, - struct st20_rfc4175_422_8_pg2_le* pg_8, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { - struct mtl_dma_lender_dev* dma = udma; +int st20_rfc4175_422be10_to_422le8_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, + uint32_t h, enum mtl_simd_level level) { + struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1368,18 +1406,22 @@ int st20_rfc4175_422be10_to_422le8_simd_dma(mtl_udma_handle udma, if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma(dma, pg_10, pg_10_iova, pg_8, w, - h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma(dma, pg_10, pg_10_iova, + pg_8, w, h); + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le8_avx512_dma(dma, pg_10, pg_10_iova, pg_8, w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_422le8_avx512_dma(dma, pg_10, pg_10_iova, + pg_8, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1388,9 +1430,10 @@ int st20_rfc4175_422be10_to_422le8_simd_dma(mtl_udma_handle udma, return st20_rfc4175_422be10_to_422le8_scalar(pg_10, pg_8, w, h); } -static int st20_rfc4175_422be10_to_yuv422p8_scalar(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h) { +static int +st20_rfc4175_422be10_to_yuv422p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ for (uint32_t pg2 = 0; pg2 < cnt; pg2++) { @@ -1404,9 +1447,10 @@ static int st20_rfc4175_422be10_to_yuv422p8_scalar(struct st20_rfc4175_422_10_pg return 0; } -int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1415,10 +1459,12 @@ int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv422p8_avx512(pg, y, b, r, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1427,9 +1473,10 @@ int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, return st20_rfc4175_422be10_to_yuv422p8_scalar(pg, y, b, r, w, h); } -static int st20_rfc4175_422be10_to_yuv420p8_scalar(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, - uint32_t w, uint32_t h) { +static int +st20_rfc4175_422be10_to_yuv420p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { uint32_t line_pg_cnt = w / 2; /* two pgs in one convert */ for (uint32_t i = 0; i < (h / 2); i++) { /* 2 lines each loop */ @@ -1452,9 +1499,10 @@ static int st20_rfc4175_422be10_to_yuv420p8_scalar(struct st20_rfc4175_422_10_pg return 0; } -int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, - uint8_t* y, uint8_t* b, uint8_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1463,10 +1511,12 @@ int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv420p8_avx512(pg, y, b, r, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1475,12 +1525,12 @@ int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be* pg, return st20_rfc4175_422be10_to_yuv420p8_scalar(pg, y, b, r, w, h); } -int st20_rfc4175_422le10_to_v210_scalar(uint8_t* pg_le, uint8_t* pg_v210, uint32_t w, - uint32_t h) { +int st20_rfc4175_422le10_to_v210_scalar(uint8_t *pg_le, uint8_t *pg_v210, + uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, - pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", + __func__, pg_count); return -EINVAL; } @@ -1513,8 +1563,9 @@ int st20_rfc4175_422le10_to_v210_scalar(uint8_t* pg_le, uint8_t* pg_v210, uint32 return 0; } -int st20_rfc4175_422le10_to_v210_simd(uint8_t* pg_le, uint8_t* pg_v210, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422le10_to_v210_simd(uint8_t *pg_le, uint8_t *pg_v210, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1526,16 +1577,19 @@ int st20_rfc4175_422le10_to_v210_simd(uint8_t* pg_le, uint8_t* pg_v210, uint32_t (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422le10_to_v210_avx512_vbmi(pg_le, pg_v210, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422le10_to_v210_avx512(pg_le, pg_v210, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1544,12 +1598,12 @@ int st20_rfc4175_422le10_to_v210_simd(uint8_t* pg_le, uint8_t* pg_v210, uint32_t return st20_rfc4175_422le10_to_v210_scalar(pg_le, pg_v210, w, h); } -int st20_v210_to_rfc4175_422le10(uint8_t* pg_v210, uint8_t* pg_le, uint32_t w, +int st20_v210_to_rfc4175_422le10(uint8_t *pg_v210, uint8_t *pg_le, uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, - pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", + __func__, pg_count); return -EINVAL; } @@ -1580,12 +1634,12 @@ int st20_v210_to_rfc4175_422le10(uint8_t* pg_v210, uint8_t* pg_le, uint32_t w, return 0; } -int st20_rfc4175_422be10_to_v210_scalar(uint8_t* pg_be, uint8_t* pg_v210, uint32_t w, - uint32_t h) { +int st20_rfc4175_422be10_to_v210_scalar(uint8_t *pg_be, uint8_t *pg_v210, + uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, - pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", + __func__, pg_count); return -EINVAL; } @@ -1595,13 +1649,15 @@ int st20_rfc4175_422be10_to_v210_scalar(uint8_t* pg_be, uint8_t* pg_v210, uint32 int k = i * 16; pg_v210[k] = pg_be[j] << 2 | pg_be[j + 1] >> 6; - pg_v210[k + 1] = pg_be[j] >> 6 | pg_be[j + 1] << 6 | ((pg_be[j + 2] >> 2) & 0x3C); - pg_v210[k + 2] = ((pg_be[j + 1] >> 2) & 0x0F) | ((pg_be[j + 3] << 2) & 0xF0); + pg_v210[k + 1] = + pg_be[j] >> 6 | pg_be[j + 1] << 6 | ((pg_be[j + 2] >> 2) & 0x3C); + pg_v210[k + 2] = + ((pg_be[j + 1] >> 2) & 0x0F) | ((pg_be[j + 3] << 2) & 0xF0); pg_v210[k + 3] = (pg_be[j + 2] << 2 | pg_be[j + 3] >> 6) & 0x3F; pg_v210[k + 4] = pg_be[j + 4]; - pg_v210[k + 5] = - (pg_be[j + 5] << 4) | ((pg_be[j + 6] >> 4) & 0x0C) | (pg_be[j + 3] & 0x03); + pg_v210[k + 5] = (pg_be[j + 5] << 4) | ((pg_be[j + 6] >> 4) & 0x0C) | + (pg_be[j + 3] & 0x03); pg_v210[k + 6] = (pg_be[j + 5] >> 4) | (pg_be[j + 7] & 0xF0); pg_v210[k + 7] = (pg_be[j + 6]) & 0x3F; @@ -1620,8 +1676,8 @@ int st20_rfc4175_422be10_to_v210_scalar(uint8_t* pg_be, uint8_t* pg_v210, uint32 return 0; } -int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210, uint32_t w, uint32_t h, +int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1634,27 +1690,32 @@ int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_v210_avx512_vbmi(pg_be, pg_v210, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_v210_avx512(pg_be, pg_v210, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif /* the last option */ - return st20_rfc4175_422be10_to_v210_scalar((uint8_t*)pg_be, pg_v210, w, h); + return st20_rfc4175_422be10_to_v210_scalar((uint8_t *)pg_be, pg_v210, w, h); } -int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t* pg_be, uint8_t* pg_v210_full, - uint32_t w, uint32_t h, - uint8_t* pg_v210_decimated, int decimator) { +int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t *pg_be, + uint8_t *pg_v210_full, uint32_t w, + uint32_t h, + uint8_t *pg_v210_decimated, + int decimator) { uint32_t line_pg_count = w / 2; uint32_t line_batch = line_pg_count / 3; @@ -1662,19 +1723,21 @@ int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t* pg_be, uint8_t* pg_v210_fu for (uint32_t line = 0; line < h; line++) { for (uint32_t i = 0; i < line_batch; i++) { pg_v210_full[0] = pg_be[0] << 2 | pg_be[1] >> 6; - pg_v210_full[1] = pg_be[0] >> 6 | pg_be[1] << 6 | ((pg_be[2] >> 2) & 0x3C); + pg_v210_full[1] = + pg_be[0] >> 6 | pg_be[1] << 6 | ((pg_be[2] >> 2) & 0x3C); pg_v210_full[2] = ((pg_be[1] >> 2) & 0x0F) | ((pg_be[3] << 2) & 0xF0); pg_v210_full[3] = (pg_be[2] << 2 | pg_be[3] >> 6) & 0x3F; pg_v210_full[4] = pg_be[4]; - pg_v210_full[5] = (pg_be[5] << 4) | ((pg_be[6] >> 4) & 0x0C) | (pg_be[3] & 0x03); + pg_v210_full[5] = + (pg_be[5] << 4) | ((pg_be[6] >> 4) & 0x0C) | (pg_be[3] & 0x03); pg_v210_full[6] = (pg_be[5] >> 4) | (pg_be[7] & 0xF0); pg_v210_full[7] = (pg_be[6]) & 0x3F; pg_v210_full[8] = (pg_be[7] << 6) | (pg_be[8] >> 2); pg_v210_full[9] = ((pg_be[7] >> 2) & 0x03) | (pg_be[9] << 2); - pg_v210_full[10] = ((pg_be[8] << 2) & 0x0C) | (pg_be[9] >> 6) | (pg_be[10] << 6) | - ((pg_be[11] >> 2) & 0x30); + pg_v210_full[10] = ((pg_be[8] << 2) & 0x0C) | (pg_be[9] >> 6) | + (pg_be[10] << 6) | ((pg_be[11] >> 2) & 0x30); pg_v210_full[11] = (pg_be[10] >> 2); pg_v210_full[12] = (pg_be[12] >> 4) | (pg_be[11] << 4); @@ -1687,7 +1750,7 @@ int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t* pg_be, uint8_t* pg_v210_fu /* handle pg_v210_decimated */ if (((line % decimator) == stride) && ((i % decimator) == stride)) { - uint8_t* v210 = pg_v210_full - decimator * 16; + uint8_t *v210 = pg_v210_full - decimator * 16; memcpy(pg_v210_decimated, v210, 16); pg_v210_decimated += 16; } @@ -1697,10 +1760,10 @@ int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t* pg_be, uint8_t* pg_v210_fu return 0; } -int st20_rfc4175_422be10_to_v210_simd_2way(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint8_t* pg_v210_full, uint32_t w, uint32_t h, - uint8_t* pg_v210_decimated, int decimator, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_v210_simd_2way( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210_full, uint32_t w, + uint32_t h, uint8_t *pg_v210_decimated, int decimator, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1710,7 +1773,8 @@ int st20_rfc4175_422be10_to_v210_simd_2way(struct st20_rfc4175_422_10_pg2_be* pg uint32_t line_pg_count = w / 2; if (line_pg_count % 3 != 0) { - err("%s, invalid line_pg_count %d, pixel group number must be multiple of 3!\n", + err("%s, invalid line_pg_count %d, pixel group number must be multiple of " + "3!\n", __func__, line_pg_count); return -EINVAL; } @@ -1728,16 +1792,15 @@ int st20_rfc4175_422be10_to_v210_simd_2way(struct st20_rfc4175_422_10_pg2_be* pg } /* the last option */ - return st20_rfc4175_422be10_to_v210_scalar_2way((uint8_t*)pg_be, pg_v210_full, w, h, - pg_v210_decimated, decimator); + return st20_rfc4175_422be10_to_v210_scalar_2way( + (uint8_t *)pg_be, pg_v210_full, w, h, pg_v210_decimated, decimator); } -int st20_rfc4175_422be10_to_v210_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint8_t* pg_v210, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { - struct mtl_dma_lender_dev* dma = udma; +int st20_rfc4175_422be10_to_v210_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h, + enum mtl_simd_level level) { + struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1749,32 +1812,36 @@ int st20_rfc4175_422be10_to_v210_simd_dma(mtl_udma_handle udma, if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(dma, pg_be, pg_be_iova, pg_v210, w, - h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(dma, pg_be, pg_be_iova, + pg_v210, w, h); + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_v210_avx512_dma(dma, pg_be, pg_be_iova, pg_v210, w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_v210_avx512_dma(dma, pg_be, pg_be_iova, + pg_v210, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif /* the last option */ - return st20_rfc4175_422be10_to_v210_scalar((uint8_t*)pg_be, pg_v210, w, h); + return st20_rfc4175_422be10_to_v210_scalar((uint8_t *)pg_be, pg_v210, w, h); } -int st20_v210_to_rfc4175_422be10_scalar(uint8_t* v210, uint8_t* be, uint32_t w, +int st20_v210_to_rfc4175_422be10_scalar(uint8_t *v210, uint8_t *be, uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, - pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", + __func__, pg_count); return -EINVAL; } @@ -1784,20 +1851,23 @@ int st20_v210_to_rfc4175_422be10_scalar(uint8_t* v210, uint8_t* be, uint32_t w, int k = i * 15; be[k + 0] = (v210[j + 1] << 6) | (v210[j + 0] >> 2); - be[k + 1] = (v210[j + 0] << 6) | ((v210[j + 2] << 2) & 0x3C) | (v210[j + 1] >> 6); + be[k + 1] = + (v210[j + 0] << 6) | ((v210[j + 2] << 2) & 0x3C) | (v210[j + 1] >> 6); be[k + 2] = ((v210[j + 1] << 2) & 0xF0) | ((v210[j + 3] >> 2) & 0x0F); - be[k + 3] = (v210[j + 5] & 0x03) | ((v210[j + 2] >> 2) & 0x3C) | (v210[j + 3] << 6); + be[k + 3] = + (v210[j + 5] & 0x03) | ((v210[j + 2] >> 2) & 0x3C) | (v210[j + 3] << 6); be[k + 4] = v210[j + 4]; be[k + 5] = (v210[j + 6] << 4) | (v210[j + 5] >> 4); be[k + 6] = ((v210[j + 5] << 4) & 0xC0) | (v210[j + 7] & 0x3F); - be[k + 7] = (v210[j + 6] & 0xF0) | ((v210[j + 9] << 2) & 0x0C) | (v210[j + 8] >> 6); + be[k + 7] = + (v210[j + 6] & 0xF0) | ((v210[j + 9] << 2) & 0x0C) | (v210[j + 8] >> 6); be[k + 8] = (v210[j + 8] << 2) | ((v210[j + 10] >> 2) & 0x3); be[k + 9] = (v210[j + 10] << 6) | (v210[j + 9] >> 2); be[k + 10] = (v210[j + 11] << 2) | (v210[j + 10] >> 6); - be[k + 11] = - ((v210[j + 10] << 2) & 0xC0) | ((v210[j + 13] << 4) & 0x30) | (v210[j + 12] >> 4); + be[k + 11] = ((v210[j + 10] << 2) & 0xC0) | ((v210[j + 13] << 4) & 0x30) | + (v210[j + 12] >> 4); be[k + 12] = (v210[j + 12] << 4) | (v210[j + 14] & 0x0F); be[k + 13] = (v210[j + 13] & 0xFC) | ((v210[j + 15] >> 4) & 0x03); be[k + 14] = (v210[j + 15] << 4) | (v210[j + 14] >> 4); @@ -1806,9 +1876,10 @@ int st20_v210_to_rfc4175_422be10_scalar(uint8_t* v210, uint8_t* be, uint32_t w, return 0; } -int st20_v210_to_rfc4175_422be10_simd(uint8_t* pg_v210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, enum mtl_simd_level level) { +int st20_v210_to_rfc4175_422be10_simd(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1820,29 +1891,31 @@ int st20_v210_to_rfc4175_422be10_simd(uint8_t* pg_v210, (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_v210_to_rfc4175_422be10_avx512_vbmi(pg_v210, pg_be, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_v210_to_rfc4175_422be10_avx512(pg_v210, pg_be, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif /* the last option */ - return st20_v210_to_rfc4175_422be10_scalar(pg_v210, (uint8_t*)pg_be, w, h); + return st20_v210_to_rfc4175_422be10_scalar(pg_v210, (uint8_t *)pg_be, w, h); } -int st20_v210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint8_t* pg_v210, - mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_v210_to_rfc4175_422be10_simd_dma( + mtl_udma_handle udma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1853,29 +1926,33 @@ int st20_v210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint8_t* pg_v210 if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(udma, pg_v210, pg_v210_iova, pg_be, - w, h); - if (ret == 0) return 0; + ret = st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( + udma, pg_v210, pg_v210_iova, pg_be, w, h); + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = - st20_v210_to_rfc4175_422be10_avx512_dma(udma, pg_v210, pg_v210_iova, pg_be, w, h); - if (ret == 0) return 0; + ret = st20_v210_to_rfc4175_422be10_avx512_dma(udma, pg_v210, pg_v210_iova, + pg_be, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif /* the last option */ - return st20_v210_to_rfc4175_422be10_scalar(pg_v210, (uint8_t*)pg_be, w, h); + return st20_v210_to_rfc4175_422be10_scalar(pg_v210, (uint8_t *)pg_be, w, h); } -int st20_rfc4175_422be10_to_y210_scalar(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint16_t* pg_y210, uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_y210_scalar( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *pg_y210, uint32_t w, + uint32_t h) { uint32_t pg_count = w * h / 2; for (uint32_t i = 0; i < pg_count; i++) { @@ -1890,8 +1967,8 @@ int st20_rfc4175_422be10_to_y210_scalar(struct st20_rfc4175_422_10_pg2_be* pg_be return 0; } -int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, - uint16_t* pg_y210, uint32_t w, uint32_t h, +int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint16_t *pg_y210, uint32_t w, uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1900,10 +1977,12 @@ int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_y210_avx512(pg_be, pg_y210, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1912,12 +1991,11 @@ int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be* pg_be, return st20_rfc4175_422be10_to_y210_scalar(pg_be, pg_y210, w, h); } -int st20_rfc4175_422be10_to_y210_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_10_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* pg_y210, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { - struct mtl_dma_lender_dev* dma = udma; +int st20_rfc4175_422be10_to_y210_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h, + enum mtl_simd_level level) { + struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1926,10 +2004,13 @@ int st20_rfc4175_422be10_to_y210_simd_dma(mtl_udma_handle udma, MTL_MAY_UNUSED(dma); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_y210_avx512_dma(dma, pg_be, pg_be_iova, pg_y210, w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be10_to_y210_avx512_dma(dma, pg_be, pg_be_iova, + pg_y210, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1938,9 +2019,9 @@ int st20_rfc4175_422be10_to_y210_simd_dma(mtl_udma_handle udma, return st20_rfc4175_422be10_to_y210_scalar(pg_be, pg_y210, w, h); } -int st20_y210_to_rfc4175_422be10_scalar(uint16_t* pg_y210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h) { +int st20_y210_to_rfc4175_422be10_scalar( + uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, + uint32_t h) { uint32_t pg_count = w * h / 2; for (uint32_t i = 0; i < pg_count; i++) { @@ -1960,9 +2041,10 @@ int st20_y210_to_rfc4175_422be10_scalar(uint16_t* pg_y210, return 0; } -int st20_y210_to_rfc4175_422be10_simd(uint16_t* pg_y210, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, enum mtl_simd_level level) { +int st20_y210_to_rfc4175_422be10_simd(uint16_t *pg_y210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1970,10 +2052,12 @@ int st20_y210_to_rfc4175_422be10_simd(uint16_t* pg_y210, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_y210_to_rfc4175_422be10_avx512(pg_y210, pg_be, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1982,11 +2066,10 @@ int st20_y210_to_rfc4175_422be10_simd(uint16_t* pg_y210, return st20_y210_to_rfc4175_422be10_scalar(pg_y210, pg_be, w, h); } -int st20_y210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint16_t* pg_y210, - mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_y210_to_rfc4175_422be10_simd_dma( + mtl_udma_handle udma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1994,11 +2077,13 @@ int st20_y210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint16_t* pg_y21 MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = - st20_y210_to_rfc4175_422be10_avx512_dma(udma, pg_y210, pg_y210_iova, pg_be, w, h); - if (ret == 0) return 0; + ret = st20_y210_to_rfc4175_422be10_avx512_dma(udma, pg_y210, pg_y210_iova, + pg_be, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2008,8 +2093,8 @@ int st20_y210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint16_t* pg_y21 } static int st20_yuv422p12le_to_rfc4175_422be12_scalar( - uint16_t* y, uint16_t* b, uint16_t* r, struct st20_rfc4175_422_12_pg2_be* pg, - uint32_t w, uint32_t h) { + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_be *pg, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2034,18 +2119,18 @@ static int st20_yuv422p12le_to_rfc4175_422be12_scalar( return 0; } -int st20_yuv422p12le_to_rfc4175_422be12_simd(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_12_pg2_be* pg, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_yuv422p12le_to_rfc4175_422be12_simd( + uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_be *pg, uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_yuv422p12le_to_rfc4175_422be12_scalar(y, b, r, pg, w, h); } static int st20_rfc4175_422be12_to_yuv422p12le_scalar( - struct st20_rfc4175_422_12_pg2_be* pg, uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h) { + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2065,10 +2150,9 @@ static int st20_rfc4175_422be12_to_yuv422p12le_scalar( return 0; } -int st20_rfc4175_422be12_to_yuv422p12le_simd(struct st20_rfc4175_422_12_pg2_be* pg, - uint16_t* y, uint16_t* b, uint16_t* r, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be12_to_yuv422p12le_simd( + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, + uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2080,16 +2164,19 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd(struct st20_rfc4175_422_12_pg2_be* (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(pg, y, b, r, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be12_to_yuv422p12le_avx512(pg, y, b, r, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2098,12 +2185,11 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd(struct st20_rfc4175_422_12_pg2_be* return st20_rfc4175_422be12_to_yuv422p12le_scalar(pg, y, b, r, w, h); } -int st20_rfc4175_422be12_to_yuv422p12le_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, uint16_t* y, - uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h, enum mtl_simd_level level) { - struct mtl_dma_lender_dev* dma = udma; +int st20_rfc4175_422be12_to_yuv422p12le_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level) { + struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2112,11 +2198,13 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd_dma(mtl_udma_handle udma, MTL_MAY_UNUSED(dma); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be12_to_yuv422p12le_avx512_dma(udma, pg_be, pg_be_iova, y, b, r, - w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( + udma, pg_be, pg_be_iova, y, b, r, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2125,9 +2213,9 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd_dma(mtl_udma_handle udma, return st20_rfc4175_422be12_to_yuv422p12le_scalar(pg_be, y, b, r, w, h); } -int st20_yuv422p12le_to_rfc4175_422le12(uint16_t* y, uint16_t* b, uint16_t* r, - struct st20_rfc4175_422_12_pg2_le* pg, uint32_t w, - uint32_t h) { +int st20_yuv422p12le_to_rfc4175_422le12(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_le *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2152,9 +2240,9 @@ int st20_yuv422p12le_to_rfc4175_422le12(uint16_t* y, uint16_t* b, uint16_t* r, return 0; } -int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le* pg, - uint16_t* y, uint16_t* b, uint16_t* r, uint32_t w, - uint32_t h) { +int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2174,9 +2262,9 @@ int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le* pg, return 0; } -int st20_rfc4175_422be12_to_422le12_scalar(struct st20_rfc4175_422_12_pg2_be* pg_be, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h) { +int st20_rfc4175_422be12_to_422le12_scalar( + struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; uint16_t cb, y0, cr, y1; @@ -2202,10 +2290,10 @@ int st20_rfc4175_422be12_to_422le12_scalar(struct st20_rfc4175_422_12_pg2_be* pg return 0; } -int st20_rfc4175_422be12_to_422le12_simd(struct st20_rfc4175_422_12_pg2_be* pg_be, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be12_to_422le12_simd( + struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2213,10 +2301,12 @@ int st20_rfc4175_422be12_to_422le12_simd(struct st20_rfc4175_422_12_pg2_be* pg_b MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be12_to_422le12_avx512(pg_be, pg_le, w, h); - if (ret == 0) return 0; + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2225,13 +2315,11 @@ int st20_rfc4175_422be12_to_422le12_simd(struct st20_rfc4175_422_12_pg2_be* pg_b return st20_rfc4175_422be12_to_422le12_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422be12_to_422le12_simd_dma(mtl_udma_handle udma, - struct st20_rfc4175_422_12_pg2_be* pg_be, - mtl_iova_t pg_be_iova, - struct st20_rfc4175_422_12_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { - struct mtl_dma_lender_dev* dma = udma; +int st20_rfc4175_422be12_to_422le12_simd_dma( + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, + uint32_t h, enum mtl_simd_level level) { + struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2240,10 +2328,13 @@ int st20_rfc4175_422be12_to_422le12_simd_dma(mtl_udma_handle udma, MTL_MAY_UNUSED(dma); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && + (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be12_to_422le12_avx512_dma(dma, pg_be, pg_be_iova, pg_le, w, h); - if (ret == 0) return 0; + ret = st20_rfc4175_422be12_to_422le12_avx512_dma(dma, pg_be, pg_be_iova, + pg_le, w, h); + if (ret == 0) + return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2252,9 +2343,9 @@ int st20_rfc4175_422be12_to_422le12_simd_dma(mtl_udma_handle udma, return st20_rfc4175_422be12_to_422le12_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422le12_to_422be12_scalar(struct st20_rfc4175_422_12_pg2_le* pg_le, - struct st20_rfc4175_422_12_pg2_be* pg_be, - uint32_t w, uint32_t h) { +int st20_rfc4175_422le12_to_422be12_scalar( + struct st20_rfc4175_422_12_pg2_le *pg_le, + struct st20_rfc4175_422_12_pg2_be *pg_be, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2280,21 +2371,21 @@ int st20_rfc4175_422le12_to_422be12_scalar(struct st20_rfc4175_422_12_pg2_le* pg return 0; } -int st20_rfc4175_422le12_to_422be12_simd(struct st20_rfc4175_422_12_pg2_le* pg_le, - struct st20_rfc4175_422_12_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422le12_to_422be12_simd( + struct st20_rfc4175_422_12_pg2_le *pg_le, + struct st20_rfc4175_422_12_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_422le12_to_422be12_scalar(pg_le, pg_be, w, h); } -static int st20_444p10le_to_rfc4175_444be10_scalar(uint16_t* y_g, uint16_t* b_r, - uint16_t* r_b, - struct st20_rfc4175_444_10_pg4_be* pg, - uint32_t w, uint32_t h) { +static int st20_444p10le_to_rfc4175_444be10_scalar( + uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_be *pg, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, + y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = *b_r++; @@ -2341,8 +2432,9 @@ static int st20_444p10le_to_rfc4175_444be10_scalar(uint16_t* y_g, uint16_t* b_r, return 0; } -int st20_444p10le_to_rfc4175_444be10_simd(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_10_pg4_be* pg, +int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level) { MTL_MAY_UNUSED(level); @@ -2350,12 +2442,13 @@ int st20_444p10le_to_rfc4175_444be10_simd(uint16_t* y_g, uint16_t* b_r, uint16_t return st20_444p10le_to_rfc4175_444be10_scalar(y_g, b_r, r_b, pg, w, h); } -static int st20_rfc4175_444be10_to_444p10le_scalar(struct st20_rfc4175_444_10_pg4_be* pg, - uint16_t* y_g, uint16_t* b_r, - uint16_t* r_b, uint32_t w, - uint32_t h) { +static int +st20_rfc4175_444be10_to_444p10le_scalar(struct st20_rfc4175_444_10_pg4_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, + y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = (pg->Cb_R00 << 2) + pg->Cb_R00_; @@ -2389,20 +2482,22 @@ static int st20_rfc4175_444be10_to_444p10le_scalar(struct st20_rfc4175_444_10_pg return 0; } -int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be* pg, - uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - uint32_t w, uint32_t h, +int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h, enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be10_to_444p10le_scalar(pg, y_g, b_r, r_b, w, h); } -int st20_444p10le_to_rfc4175_444le10(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_10_pg4_le* pg, uint32_t w, - uint32_t h) { +int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_le *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, + y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = *b_r++; @@ -2449,11 +2544,12 @@ int st20_444p10le_to_rfc4175_444le10(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b return 0; } -int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le* pg, uint16_t* y_g, - uint16_t* b_r, uint16_t* r_b, uint32_t w, - uint32_t h) { +int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, + y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = pg->Cb_R00 + (pg->Cb_R00_ << 8); @@ -2487,11 +2583,12 @@ int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le* pg, uint return 0; } -int st20_rfc4175_444be10_to_444le10_scalar(struct st20_rfc4175_444_10_pg4_be* pg_be, - struct st20_rfc4175_444_10_pg4_le* pg_le, - uint32_t w, uint32_t h) { +int st20_rfc4175_444be10_to_444le10_scalar( + struct st20_rfc4175_444_10_pg4_be *pg_be, + struct st20_rfc4175_444_10_pg4_le *pg_le, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, + y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = (pg_be->Cb_R00 << 2) + pg_be->Cb_R00_; @@ -2539,20 +2636,21 @@ int st20_rfc4175_444be10_to_444le10_scalar(struct st20_rfc4175_444_10_pg4_be* pg return 0; } -int st20_rfc4175_444be10_to_444le10_simd(struct st20_rfc4175_444_10_pg4_be* pg_be, - struct st20_rfc4175_444_10_pg4_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444be10_to_444le10_simd( + struct st20_rfc4175_444_10_pg4_be *pg_be, + struct st20_rfc4175_444_10_pg4_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be10_to_444le10_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_444le10_to_444be10_scalar(struct st20_rfc4175_444_10_pg4_le* pg_le, - struct st20_rfc4175_444_10_pg4_be* pg_be, - uint32_t w, uint32_t h) { +int st20_rfc4175_444le10_to_444be10_scalar( + struct st20_rfc4175_444_10_pg4_le *pg_le, + struct st20_rfc4175_444_10_pg4_be *pg_be, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, + y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = pg_le->Cb_R00 + (pg_le->Cb_R00_ << 8); @@ -2600,19 +2698,18 @@ int st20_rfc4175_444le10_to_444be10_scalar(struct st20_rfc4175_444_10_pg4_le* pg return 0; } -int st20_rfc4175_444le10_to_444be10_simd(struct st20_rfc4175_444_10_pg4_le* pg_le, - struct st20_rfc4175_444_10_pg4_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444le10_to_444be10_simd( + struct st20_rfc4175_444_10_pg4_le *pg_le, + struct st20_rfc4175_444_10_pg4_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444le10_to_444be10_scalar(pg_le, pg_be, w, h); } -static int st20_444p12le_to_rfc4175_444be12_scalar(uint16_t* y_g, uint16_t* b_r, - uint16_t* r_b, - struct st20_rfc4175_444_12_pg2_be* pg, - uint32_t w, uint32_t h) { +static int st20_444p12le_to_rfc4175_444be12_scalar( + uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_be *pg, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2643,8 +2740,9 @@ static int st20_444p12le_to_rfc4175_444be12_scalar(uint16_t* y_g, uint16_t* b_r, return 0; } -int st20_444p12le_to_rfc4175_444be12_simd(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_12_pg2_be* pg, +int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level) { MTL_MAY_UNUSED(level); @@ -2652,10 +2750,10 @@ int st20_444p12le_to_rfc4175_444be12_simd(uint16_t* y_g, uint16_t* b_r, uint16_t return st20_444p12le_to_rfc4175_444be12_scalar(y_g, b_r, r_b, pg, w, h); } -static int st20_rfc4175_444be12_to_444p12le_scalar(struct st20_rfc4175_444_12_pg2_be* pg, - uint16_t* y_g, uint16_t* b_r, - uint16_t* r_b, uint32_t w, - uint32_t h) { +static int +st20_rfc4175_444be12_to_444p12le_scalar(struct st20_rfc4175_444_12_pg2_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2679,18 +2777,19 @@ static int st20_rfc4175_444be12_to_444p12le_scalar(struct st20_rfc4175_444_12_pg return 0; } -int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be* pg, - uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - uint32_t w, uint32_t h, +int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h, enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be12_to_444p12le_scalar(pg, y_g, b_r, r_b, w, h); } -int st20_444p12le_to_rfc4175_444le12(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b, - struct st20_rfc4175_444_12_pg2_le* pg, uint32_t w, - uint32_t h) { +int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_le *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2721,9 +2820,9 @@ int st20_444p12le_to_rfc4175_444le12(uint16_t* y_g, uint16_t* b_r, uint16_t* r_b return 0; } -int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le* pg, uint16_t* y_g, - uint16_t* b_r, uint16_t* r_b, uint32_t w, - uint32_t h) { +int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2747,9 +2846,9 @@ int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le* pg, uint return 0; } -int st20_rfc4175_444be12_to_444le12_scalar(struct st20_rfc4175_444_12_pg2_be* pg_be, - struct st20_rfc4175_444_12_pg2_le* pg_le, - uint32_t w, uint32_t h) { +int st20_rfc4175_444be12_to_444le12_scalar( + struct st20_rfc4175_444_12_pg2_be *pg_be, + struct st20_rfc4175_444_12_pg2_le *pg_le, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2781,18 +2880,18 @@ int st20_rfc4175_444be12_to_444le12_scalar(struct st20_rfc4175_444_12_pg2_be* pg return 0; } -int st20_rfc4175_444be12_to_444le12_simd(struct st20_rfc4175_444_12_pg2_be* pg_be, - struct st20_rfc4175_444_12_pg2_le* pg_le, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444be12_to_444le12_simd( + struct st20_rfc4175_444_12_pg2_be *pg_be, + struct st20_rfc4175_444_12_pg2_le *pg_le, uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be12_to_444le12_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_444le12_to_444be12_scalar(struct st20_rfc4175_444_12_pg2_le* pg_le, - struct st20_rfc4175_444_12_pg2_be* pg_be, - uint32_t w, uint32_t h) { +int st20_rfc4175_444le12_to_444be12_scalar( + struct st20_rfc4175_444_12_pg2_le *pg_le, + struct st20_rfc4175_444_12_pg2_be *pg_be, uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2824,16 +2923,16 @@ int st20_rfc4175_444le12_to_444be12_scalar(struct st20_rfc4175_444_12_pg2_le* pg return 0; } -int st20_rfc4175_444le12_to_444be12_simd(struct st20_rfc4175_444_12_pg2_le* pg_le, - struct st20_rfc4175_444_12_pg2_be* pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444le12_to_444be12_simd( + struct st20_rfc4175_444_12_pg2_le *pg_le, + struct st20_rfc4175_444_12_pg2_be *pg_be, uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444le12_to_444be12_scalar(pg_le, pg_be, w, h); } -int st31_am824_to_aes3(struct st31_am824* sf_am824, struct st31_aes3* sf_aes3, +int st31_am824_to_aes3(struct st31_am824 *sf_am824, struct st31_aes3 *sf_aes3, uint16_t subframes) { for (int i = 0; i < subframes; ++i) { /* preamble bits definition refer to @@ -2870,7 +2969,7 @@ int st31_am824_to_aes3(struct st31_am824* sf_am824, struct st31_aes3* sf_aes3, return 0; } -int st31_aes3_to_am824(struct st31_aes3* sf_aes3, struct st31_am824* sf_am824, +int st31_aes3_to_am824(struct st31_aes3 *sf_aes3, struct st31_am824 *sf_am824, uint16_t subframes) { for (int i = 0; i < subframes; ++i) { /* preamble bits definition refer to @@ -2902,7 +3001,8 @@ int st31_aes3_to_am824(struct st31_aes3* sf_aes3, struct st31_am824* sf_am824, /* copy audio data */ sf_am824->data[0] = sf_aes3->data_0 | (sf_aes3->data_1 << 4); sf_am824->data[1] = sf_aes3->data_1 >> 4; - sf_am824->data[2] = (sf_aes3->data_2 << 4) | ((uint16_t)sf_aes3->data_1 >> 12); + sf_am824->data[2] = + (sf_aes3->data_2 << 4) | ((uint16_t)sf_aes3->data_1 >> 12); sf_aes3++; sf_am824++; diff --git a/lib/src/st2110/st_convert.h b/lib/src/st2110/st_convert.h index 8dcdfb8d2..5ec3d8993 100644 --- a/lib/src/st2110/st_convert.h +++ b/lib/src/st2110/st_convert.h @@ -11,10 +11,10 @@ struct st_frame_converter { enum st_frame_fmt src_fmt; enum st_frame_fmt dst_fmt; - int (*convert_func)(struct st_frame* src, struct st_frame* dst); + int (*convert_func)(struct st_frame *src, struct st_frame *dst); }; int st_frame_get_converter(enum st_frame_fmt src_fmt, enum st_frame_fmt dst_fmt, - struct st_frame_converter* converter); + struct st_frame_converter *converter); #endif diff --git a/lib/src/st2110/st_fmt.c b/lib/src/st2110/st_fmt.c index 4eeb69978..216e067df 100644 --- a/lib/src/st2110/st_fmt.c +++ b/lib/src/st2110/st_fmt.c @@ -469,15 +469,16 @@ enum st_frame_fmt st_codec_codestream_fmt(enum st22_codec codec) { return ST_FRAME_FMT_MAX; } -static const char* st_pacing_way_names[ST21_TX_PACING_WAY_MAX] = { +static const char *st_pacing_way_names[ST21_TX_PACING_WAY_MAX] = { "auto", "ratelimit", "tsc", "tsn", "ptp", "be", "tsc_narrow", }; -const char* st_tx_pacing_way_name(enum st21_tx_pacing_way way) { +const char *st_tx_pacing_way_name(enum st21_tx_pacing_way way) { return st_pacing_way_names[way]; } -size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, uint8_t plane) { +size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, + uint8_t plane) { size_t linesize = 0; if (st_frame_fmt_planes(fmt) == 1) { @@ -487,49 +488,49 @@ size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, uint8_t pl linesize = st_frame_size(fmt, width, 1, false); } else { switch (st_frame_fmt_get_sampling(fmt)) { - case ST_FRAME_SAMPLING_422: - switch (plane) { - case 0: - linesize = st_frame_size(fmt, width, 1, false) / 2; - break; - case 1: - case 2: - linesize = st_frame_size(fmt, width, 1, false) / 4; - break; - default: - err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); - break; - } + case ST_FRAME_SAMPLING_422: + switch (plane) { + case 0: + linesize = st_frame_size(fmt, width, 1, false) / 2; break; - case ST_FRAME_SAMPLING_444: - switch (plane) { - case 0: - case 1: - case 2: - linesize = st_frame_size(fmt, width, 1, false) / 3; - break; - default: - err("%s, invalid plane idx %u for 444 planar fmt\n", __func__, plane); - break; - } + case 1: + case 2: + linesize = st_frame_size(fmt, width, 1, false) / 4; break; - case ST_FRAME_SAMPLING_420: - switch (plane) { - case 0: - linesize = st_frame_size(fmt, width, 1, false) * 4 / 6; - break; - case 1: - case 2: - linesize = st_frame_size(fmt, width, 1, false) / 6; - break; - default: - err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); - break; - } + default: + err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); + break; + } + break; + case ST_FRAME_SAMPLING_444: + switch (plane) { + case 0: + case 1: + case 2: + linesize = st_frame_size(fmt, width, 1, false) / 3; + break; + default: + err("%s, invalid plane idx %u for 444 planar fmt\n", __func__, plane); + break; + } + break; + case ST_FRAME_SAMPLING_420: + switch (plane) { + case 0: + linesize = st_frame_size(fmt, width, 1, false) * 4 / 6; + break; + case 1: + case 2: + linesize = st_frame_size(fmt, width, 1, false) / 6; break; default: - err("%s, invalid sampling for fmt %d\n", __func__, fmt); + err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); break; + } + break; + default: + err("%s, invalid sampling for fmt %d\n", __func__, fmt); + break; } } @@ -542,65 +543,66 @@ size_t st_frame_size(enum st_frame_fmt fmt, uint32_t width, uint32_t height, size_t pixels = (size_t)width * height; switch (fmt) { - case ST_FRAME_FMT_YUV422PLANAR10LE: - case ST_FRAME_FMT_YUV422PLANAR12LE: - case ST_FRAME_FMT_Y210: - size = pixels * 2 * 2; /* 10/12bits in two bytes */ - break; - case ST_FRAME_FMT_V210: - if (pixels % 3) { - err("%s, invalid width %u height %u for v210 fmt, not multiple of 3\n", __func__, - width, height); - } else { - size = pixels * 8 / 3; - } - break; - case ST_FRAME_FMT_YUV422PLANAR8: - case ST_FRAME_FMT_YUV422CUSTOM8: - case ST_FRAME_FMT_UYVY: - size = pixels * 2; - break; - case ST_FRAME_FMT_YUV444PLANAR10LE: - case ST_FRAME_FMT_YUV444PLANAR12LE: - case ST_FRAME_FMT_GBRPLANAR10LE: - case ST_FRAME_FMT_GBRPLANAR12LE: - size = pixels * 2 * 3; /* 10bits in two bytes */ - break; - case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - size = st20_frame_size(ST20_FMT_YUV_422_10BIT, width, height); - break; - case ST_FRAME_FMT_YUV422RFC4175PG2BE12: - size = st20_frame_size(ST20_FMT_YUV_422_12BIT, width, height); - break; - case ST_FRAME_FMT_YUV444RFC4175PG4BE10: - case ST_FRAME_FMT_RGBRFC4175PG4BE10: - size = st20_frame_size(ST20_FMT_YUV_444_10BIT, width, height); - break; - case ST_FRAME_FMT_YUV444RFC4175PG2BE12: - case ST_FRAME_FMT_RGBRFC4175PG2BE12: - size = st20_frame_size(ST20_FMT_YUV_444_12BIT, width, height); - break; - case ST_FRAME_FMT_ARGB: - case ST_FRAME_FMT_BGRA: - size = pixels * 4; /* 8 bits ARGB pixel in a 32 bits */ - break; - case ST_FRAME_FMT_RGB8: - size = pixels * 3; /* 8 bits RGB pixel in a 24 bits */ - break; - case ST_FRAME_FMT_YUV420CUSTOM8: - case ST_FRAME_FMT_YUV420PLANAR8: - size = st20_frame_size(ST20_FMT_YUV_420_8BIT, width, height); - break; - default: - err("%s, invalid fmt %d\n", __func__, fmt); - break; + case ST_FRAME_FMT_YUV422PLANAR10LE: + case ST_FRAME_FMT_YUV422PLANAR12LE: + case ST_FRAME_FMT_Y210: + size = pixels * 2 * 2; /* 10/12bits in two bytes */ + break; + case ST_FRAME_FMT_V210: + if (pixels % 3) { + err("%s, invalid width %u height %u for v210 fmt, not multiple of 3\n", + __func__, width, height); + } else { + size = pixels * 8 / 3; + } + break; + case ST_FRAME_FMT_YUV422PLANAR8: + case ST_FRAME_FMT_YUV422CUSTOM8: + case ST_FRAME_FMT_UYVY: + size = pixels * 2; + break; + case ST_FRAME_FMT_YUV444PLANAR10LE: + case ST_FRAME_FMT_YUV444PLANAR12LE: + case ST_FRAME_FMT_GBRPLANAR10LE: + case ST_FRAME_FMT_GBRPLANAR12LE: + size = pixels * 2 * 3; /* 10bits in two bytes */ + break; + case ST_FRAME_FMT_YUV422RFC4175PG2BE10: + size = st20_frame_size(ST20_FMT_YUV_422_10BIT, width, height); + break; + case ST_FRAME_FMT_YUV422RFC4175PG2BE12: + size = st20_frame_size(ST20_FMT_YUV_422_12BIT, width, height); + break; + case ST_FRAME_FMT_YUV444RFC4175PG4BE10: + case ST_FRAME_FMT_RGBRFC4175PG4BE10: + size = st20_frame_size(ST20_FMT_YUV_444_10BIT, width, height); + break; + case ST_FRAME_FMT_YUV444RFC4175PG2BE12: + case ST_FRAME_FMT_RGBRFC4175PG2BE12: + size = st20_frame_size(ST20_FMT_YUV_444_12BIT, width, height); + break; + case ST_FRAME_FMT_ARGB: + case ST_FRAME_FMT_BGRA: + size = pixels * 4; /* 8 bits ARGB pixel in a 32 bits */ + break; + case ST_FRAME_FMT_RGB8: + size = pixels * 3; /* 8 bits RGB pixel in a 24 bits */ + break; + case ST_FRAME_FMT_YUV420CUSTOM8: + case ST_FRAME_FMT_YUV420PLANAR8: + size = st20_frame_size(ST20_FMT_YUV_420_8BIT, width, height); + break; + default: + err("%s, invalid fmt %d\n", __func__, fmt); + break; } - if (interlaced) size /= 2; /* if all fmt support interlace? */ + if (interlaced) + size /= 2; /* if all fmt support interlace? */ return size; } -int st_frame_sanity_check(struct st_frame* frame) { +int st_frame_sanity_check(struct st_frame *frame) { RTE_BUILD_BUG_ON(ST_FRAME_FMT_MAX > 64); int planes = st_frame_fmt_planes(frame->fmt); @@ -629,16 +631,17 @@ int st_frame_sanity_check(struct st_frame* frame) { /* check data size */ if (frame->data_size > frame->buffer_size) { - err("%s, frame data size %" PRIu64 " exceeds buffer size %" PRIu64 "\n", __func__, - frame->data_size, frame->buffer_size); + err("%s, frame data size %" PRIu64 " exceeds buffer size %" PRIu64 "\n", + __func__, frame->data_size, frame->buffer_size); return -EINVAL; } /* check data size is enough */ - size_t least_sz = - st_frame_size(frame->fmt, frame->width, frame->height, frame->interlaced); + size_t least_sz = st_frame_size(frame->fmt, frame->width, frame->height, + frame->interlaced); if (frame->data_size < least_sz) { - err("%s, frame data size %" PRIu64 " small then frame least_sz %" PRIu64 "\n", + err("%s, frame data size %" PRIu64 " small then frame least_sz %" PRIu64 + "\n", __func__, frame->data_size, least_sz); return -EINVAL; } @@ -647,7 +650,7 @@ int st_frame_sanity_check(struct st_frame* frame) { return 0; } -int st20_get_pgroup(enum st20_fmt fmt, struct st20_pgroup* pg) { +int st20_get_pgroup(enum st20_fmt fmt, struct st20_pgroup *pg) { int i; for (i = 0; i < MTL_ARRAY_SIZE(st20_pgroups); i++) { @@ -673,15 +676,15 @@ size_t st20_frame_size(enum st20_fmt fmt, uint32_t width, uint32_t height) { size_t size = (size_t)width * height; if (size % pg.coverage) { - err("%s, fmt %d, invalid w %u h %u, not multiple of %u\n", __func__, fmt, width, - height, pg.coverage); + err("%s, fmt %d, invalid w %u h %u, not multiple of %u\n", __func__, fmt, + width, height, pg.coverage); return 0; } return size * pg.size / pg.coverage; } -const char* st20_fmt_name(enum st20_fmt fmt) { +const char *st20_fmt_name(enum st20_fmt fmt) { struct st20_pgroup pg; memset(&pg, 0, sizeof(pg)); @@ -693,7 +696,7 @@ const char* st20_fmt_name(enum st20_fmt fmt) { return pg.name; } -enum st20_fmt st20_name_to_fmt(const char* name) { +enum st20_fmt st20_name_to_fmt(const char *name) { int i; for (i = 0; i < MTL_ARRAY_SIZE(st20_pgroups); i++) { @@ -706,7 +709,7 @@ enum st20_fmt st20_name_to_fmt(const char* name) { return ST20_FMT_MAX; } -int st_get_fps_timing(enum st_fps fps, struct st_fps_timing* fps_tm) { +int st_get_fps_timing(enum st_fps fps, struct st_fps_timing *fps_tm) { int i; for (i = 0; i < MTL_ARRAY_SIZE(st_fps_timings); i++) { @@ -738,8 +741,10 @@ enum st_fps st_frame_rate_to_st_fps(double framerate) { for (i = 0; i < MTL_ARRAY_SIZE(st_fps_timings); i++) { if (framerate == st_fps_timings[i].framerate || - ((framerate >= st_fps_timings[i].framerate - st_fps_timings[i].lower_limit) && - (framerate <= st_fps_timings[i].framerate + st_fps_timings[i].upper_limit))) { + ((framerate >= + st_fps_timings[i].framerate - st_fps_timings[i].lower_limit) && + (framerate <= + st_fps_timings[i].framerate + st_fps_timings[i].upper_limit))) { return st_fps_timings[i].fps; } } @@ -748,7 +753,7 @@ enum st_fps st_frame_rate_to_st_fps(double framerate) { return ST_FPS_MAX; } -enum st_fps st_name_to_fps(const char* name) { +enum st_fps st_name_to_fps(const char *name) { int i; for (i = 0; i < MTL_ARRAY_SIZE(st_fps_timings); i++) { @@ -761,7 +766,7 @@ enum st_fps st_name_to_fps(const char* name) { return ST_FPS_MAX; } -const char* st_frame_fmt_name(enum st_frame_fmt fmt) { +const char *st_frame_fmt_name(enum st_frame_fmt fmt) { int i; for (i = 0; i < MTL_ARRAY_SIZE(st_frame_fmt_descs); i++) { @@ -774,7 +779,7 @@ const char* st_frame_fmt_name(enum st_frame_fmt fmt) { return "unknown"; } -enum st_frame_fmt st_frame_name_to_fmt(const char* name) { +enum st_frame_fmt st_frame_name_to_fmt(const char *name) { int i; for (i = 0; i < MTL_ARRAY_SIZE(st_frame_fmt_descs); i++) { @@ -787,7 +792,7 @@ enum st_frame_fmt st_frame_name_to_fmt(const char* name) { return ST_FRAME_FMT_MAX; } -enum st22_codec st_name_to_codec(const char* name) { +enum st22_codec st_name_to_codec(const char *name) { if (!strcmp(name, "jpegxs")) return ST22_CODEC_JPEGXS; else if (!strcmp(name, "h264_cbr")) @@ -831,67 +836,69 @@ enum st_frame_sampling st_frame_fmt_get_sampling(enum st_frame_fmt fmt) { enum st20_fmt st_frame_fmt_to_transport(enum st_frame_fmt fmt) { switch (fmt) { - case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - return ST20_FMT_YUV_422_10BIT; - case ST_FRAME_FMT_UYVY: - case ST_FRAME_FMT_YUV422CUSTOM8: - return ST20_FMT_YUV_422_8BIT; - case ST_FRAME_FMT_YUV422RFC4175PG2BE12: - return ST20_FMT_YUV_422_12BIT; - case ST_FRAME_FMT_YUV444RFC4175PG4BE10: - return ST20_FMT_YUV_444_10BIT; - case ST_FRAME_FMT_YUV444RFC4175PG2BE12: - return ST20_FMT_YUV_444_12BIT; - case ST_FRAME_FMT_YUV420CUSTOM8: - return ST20_FMT_YUV_420_8BIT; - case ST_FRAME_FMT_RGBRFC4175PG4BE10: - return ST20_FMT_RGB_10BIT; - case ST_FRAME_FMT_RGBRFC4175PG2BE12: - return ST20_FMT_RGB_12BIT; - case ST_FRAME_FMT_RGB8: - return ST20_FMT_RGB_8BIT; - default: - err("%s, invalid fmt %d\n", __func__, fmt); - return ST20_FMT_MAX; + case ST_FRAME_FMT_YUV422RFC4175PG2BE10: + return ST20_FMT_YUV_422_10BIT; + case ST_FRAME_FMT_UYVY: + case ST_FRAME_FMT_YUV422CUSTOM8: + return ST20_FMT_YUV_422_8BIT; + case ST_FRAME_FMT_YUV422RFC4175PG2BE12: + return ST20_FMT_YUV_422_12BIT; + case ST_FRAME_FMT_YUV444RFC4175PG4BE10: + return ST20_FMT_YUV_444_10BIT; + case ST_FRAME_FMT_YUV444RFC4175PG2BE12: + return ST20_FMT_YUV_444_12BIT; + case ST_FRAME_FMT_YUV420CUSTOM8: + return ST20_FMT_YUV_420_8BIT; + case ST_FRAME_FMT_RGBRFC4175PG4BE10: + return ST20_FMT_RGB_10BIT; + case ST_FRAME_FMT_RGBRFC4175PG2BE12: + return ST20_FMT_RGB_12BIT; + case ST_FRAME_FMT_RGB8: + return ST20_FMT_RGB_8BIT; + default: + err("%s, invalid fmt %d\n", __func__, fmt); + return ST20_FMT_MAX; } } enum st_frame_fmt st_frame_fmt_from_transport(enum st20_fmt tfmt) { switch (tfmt) { - case ST20_FMT_YUV_422_10BIT: - return ST_FRAME_FMT_YUV422RFC4175PG2BE10; - case ST20_FMT_YUV_422_8BIT: - return ST_FRAME_FMT_UYVY; - case ST20_FMT_YUV_422_12BIT: - return ST_FRAME_FMT_YUV422RFC4175PG2BE12; - case ST20_FMT_YUV_444_10BIT: - return ST_FRAME_FMT_YUV444RFC4175PG4BE10; - case ST20_FMT_YUV_444_12BIT: - return ST_FRAME_FMT_YUV444RFC4175PG2BE12; - case ST20_FMT_YUV_420_8BIT: - return ST_FRAME_FMT_YUV420CUSTOM8; - case ST20_FMT_RGB_10BIT: - return ST_FRAME_FMT_RGBRFC4175PG4BE10; - case ST20_FMT_RGB_12BIT: - return ST_FRAME_FMT_RGBRFC4175PG2BE12; - case ST20_FMT_RGB_8BIT: - return ST_FRAME_FMT_RGB8; - case ST20_FMT_YUV_422_PLANAR10LE: - return ST_FRAME_FMT_YUV422PLANAR10LE; - case ST20_FMT_V210: - return ST_FRAME_FMT_V210; - default: - err("%s, invalid tfmt %d\n", __func__, tfmt); - return ST_FRAME_FMT_MAX; + case ST20_FMT_YUV_422_10BIT: + return ST_FRAME_FMT_YUV422RFC4175PG2BE10; + case ST20_FMT_YUV_422_8BIT: + return ST_FRAME_FMT_UYVY; + case ST20_FMT_YUV_422_12BIT: + return ST_FRAME_FMT_YUV422RFC4175PG2BE12; + case ST20_FMT_YUV_444_10BIT: + return ST_FRAME_FMT_YUV444RFC4175PG4BE10; + case ST20_FMT_YUV_444_12BIT: + return ST_FRAME_FMT_YUV444RFC4175PG2BE12; + case ST20_FMT_YUV_420_8BIT: + return ST_FRAME_FMT_YUV420CUSTOM8; + case ST20_FMT_RGB_10BIT: + return ST_FRAME_FMT_RGBRFC4175PG4BE10; + case ST20_FMT_RGB_12BIT: + return ST_FRAME_FMT_RGBRFC4175PG2BE12; + case ST20_FMT_RGB_8BIT: + return ST_FRAME_FMT_RGB8; + case ST20_FMT_YUV_422_PLANAR10LE: + return ST_FRAME_FMT_YUV422PLANAR10LE; + case ST20_FMT_V210: + return ST_FRAME_FMT_V210; + default: + err("%s, invalid tfmt %d\n", __func__, tfmt); + return ST_FRAME_FMT_MAX; } } bool st_frame_fmt_equal_transport(enum st_frame_fmt fmt, enum st20_fmt tfmt) { - if (fmt == ST_FRAME_FMT_YUV422CUSTOM8 || fmt == ST_FRAME_FMT_YUV420CUSTOM8) return true; + if (fmt == ST_FRAME_FMT_YUV422CUSTOM8 || fmt == ST_FRAME_FMT_YUV420CUSTOM8) + return true; enum st_frame_fmt to_fmt = st_frame_fmt_from_transport(tfmt); - if (to_fmt == ST_FRAME_FMT_MAX) return false; + if (to_fmt == ST_FRAME_FMT_MAX) + return false; return (fmt == to_fmt) ? true : false; } @@ -908,40 +915,42 @@ uint64_t st10_media_clk_to_ns(uint32_t media_ts, uint32_t sampling_rate) { return ts; } -int st_draw_logo(struct st_frame* frame, struct st_frame* logo, uint32_t x, uint32_t y) { +int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, + uint32_t y) { if (frame->fmt != logo->fmt) { err("%s, mismatch fmt %d %d\n", __func__, frame->fmt, logo->fmt); return -EINVAL; } if (frame->fmt != ST_FRAME_FMT_YUV422RFC4175PG2BE10) { - err("%s, err fmt %d, only ST_FRAME_FMT_YUV422RFC4175PG2BE10\n", __func__, frame->fmt); + err("%s, err fmt %d, only ST_FRAME_FMT_YUV422RFC4175PG2BE10\n", __func__, + frame->fmt); return -EINVAL; } if ((x + logo->width) > frame->width) { - err("%s, err w, x %u logo width %u frame width %u\n", __func__, x, logo->width, - frame->width); + err("%s, err w, x %u logo width %u frame width %u\n", __func__, x, + logo->width, frame->width); return -EINVAL; } if ((y + logo->height) > frame->height) { - err("%s, err h, y %u logo height %u frame height %u\n", __func__, y, logo->height, - frame->height); + err("%s, err h, y %u logo height %u frame height %u\n", __func__, y, + logo->height, frame->height); return -EINVAL; } size_t logo_col_size = logo->width / 2 * 5; for (uint32_t col = 0; col < logo->height; col++) { - void* dst = frame->addr[0] + (((col + y) * frame->width) + x) / 2 * 5; - void* src = logo->addr[0] + (col * logo->width) / 2 * 5; + void *dst = frame->addr[0] + (((col + y) * frame->width) + x) / 2 * 5; + void *src = logo->addr[0] + (col * logo->width) / 2 * 5; mtl_memcpy(dst, src, logo_col_size); } return 0; } -int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, enum st_fps fps, - bool interlaced, uint64_t* bps) { +int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, + enum st_fps fps, bool interlaced, uint64_t *bps) { struct st20_pgroup pg; struct st_fps_timing fps_tm; int ret; @@ -951,30 +960,34 @@ int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, enum st_fps memset(&fps_tm, 0, sizeof(fps_tm)); ret = st20_get_pgroup(fmt, &pg); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = st_get_fps_timing(fps, &fps_tm); - if (ret < 0) return ret; + if (ret < 0) + return ret; double reactive = 1080.0 / 1125.0; - traffic = - (uint64_t)width * height * 8 * pg.size / pg.coverage * fps_tm.mul / fps_tm.den; - if (interlaced) traffic /= 2; + traffic = (uint64_t)width * height * 8 * pg.size / pg.coverage * fps_tm.mul / + fps_tm.den; + if (interlaced) + traffic /= 2; traffic = traffic / reactive; *bps = traffic; return 0; } -int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, enum st_fps fps, - uint64_t* bps) { +int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, + enum st_fps fps, uint64_t *bps) { struct st_fps_timing fps_tm; int ret; memset(&fps_tm, 0, sizeof(fps_tm)); ret = st_get_fps_timing(fps, &fps_tm); - if (ret < 0) return ret; + if (ret < 0) + return ret; double reactive = 1080.0 / 1125.0; *bps = (uint64_t)total_pkts * pkt_size * fps_tm.mul / fps_tm.den; @@ -982,14 +995,16 @@ int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, enum st_fps f return 0; } -int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, uint64_t* bps) { +int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, + uint64_t *bps) { struct st_fps_timing fps_tm; int ret; memset(&fps_tm, 0, sizeof(fps_tm)); ret = st_get_fps_timing(fps, &fps_tm); - if (ret < 0) return ret; + if (ret < 0) + return ret; double reactive = 1080.0 / 1125.0; *bps = frame_size * fps_tm.mul / fps_tm.den; @@ -1000,149 +1015,149 @@ int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, uint64_t* bps) double st30_get_packet_time(enum st30_ptime ptime) { double packet_time_ns = 0.0; /* in nanoseconds */ switch (ptime) { + case ST30_PTIME_1MS: + packet_time_ns = (double)1000000000.0 * 1 / 1000; + break; + case ST30_PTIME_125US: + packet_time_ns = (double)1000000000.0 * 1 / 8000; + break; + case ST30_PTIME_250US: + packet_time_ns = (double)1000000000.0 * 1 / 4000; + break; + case ST30_PTIME_333US: + packet_time_ns = (double)1000000000.0 * 1 / 3000; + break; + case ST30_PTIME_4MS: + packet_time_ns = (double)1000000000.0 * 4 / 1000; + break; + case ST31_PTIME_80US: + packet_time_ns = (double)1000000000.0 * 1 / 12500; + break; + case ST31_PTIME_1_09MS: + packet_time_ns = (double)1000000000.0 * 48 / 44100; + break; + case ST31_PTIME_0_14MS: + packet_time_ns = (double)1000000000.0 * 6 / 44100; + break; + case ST31_PTIME_0_09MS: + packet_time_ns = (double)1000000000.0 * 4 / 44100; + break; + default: + err("%s, wrong ptime %d\n", __func__, ptime); + return -EINVAL; + } + return packet_time_ns; +} + +int st30_get_sample_size(enum st30_fmt fmt) { + int sample_size = 0; + switch (fmt) { + case ST30_FMT_PCM16: + sample_size = 2; + break; + case ST30_FMT_PCM24: + sample_size = 3; + break; + case ST30_FMT_PCM8: + sample_size = 1; + break; + case ST31_FMT_AM824: + sample_size = 4; + break; + default: + err("%s, wrong fmt %d\n", __func__, fmt); + return -EINVAL; + } + return sample_size; +} + +int st30_get_sample_num(enum st30_ptime ptime, enum st30_sampling sampling) { + int samples = 0; + switch (sampling) { + case ST30_SAMPLING_48K: + switch (ptime) { case ST30_PTIME_1MS: - packet_time_ns = (double)1000000000.0 * 1 / 1000; + samples = 48; break; case ST30_PTIME_125US: - packet_time_ns = (double)1000000000.0 * 1 / 8000; + samples = 6; break; case ST30_PTIME_250US: - packet_time_ns = (double)1000000000.0 * 1 / 4000; + samples = 12; break; case ST30_PTIME_333US: - packet_time_ns = (double)1000000000.0 * 1 / 3000; + samples = 16; break; case ST30_PTIME_4MS: - packet_time_ns = (double)1000000000.0 * 4 / 1000; + samples = 192; break; case ST31_PTIME_80US: - packet_time_ns = (double)1000000000.0 * 1 / 12500; - break; - case ST31_PTIME_1_09MS: - packet_time_ns = (double)1000000000.0 * 48 / 44100; - break; - case ST31_PTIME_0_14MS: - packet_time_ns = (double)1000000000.0 * 6 / 44100; - break; - case ST31_PTIME_0_09MS: - packet_time_ns = (double)1000000000.0 * 4 / 44100; + samples = 4; break; default: - err("%s, wrong ptime %d\n", __func__, ptime); + err("%s, wrong ptime %d for 48k\n", __func__, ptime); return -EINVAL; - } - return packet_time_ns; -} - -int st30_get_sample_size(enum st30_fmt fmt) { - int sample_size = 0; - switch (fmt) { - case ST30_FMT_PCM16: - sample_size = 2; + } + break; + case ST30_SAMPLING_96K: + switch (ptime) { + case ST30_PTIME_1MS: + samples = 96; break; - case ST30_FMT_PCM24: - sample_size = 3; + case ST30_PTIME_125US: + samples = 12; break; - case ST30_FMT_PCM8: - sample_size = 1; + case ST30_PTIME_250US: + samples = 24; break; - case ST31_FMT_AM824: - sample_size = 4; + case ST30_PTIME_333US: + samples = 32; + break; + case ST30_PTIME_4MS: + samples = 384; + break; + case ST31_PTIME_80US: + samples = 8; break; default: - err("%s, wrong fmt %d\n", __func__, fmt); + err("%s, wrong ptime %d for 96k\n", __func__, ptime); return -EINVAL; - } - return sample_size; -} - -int st30_get_sample_num(enum st30_ptime ptime, enum st30_sampling sampling) { - int samples = 0; - switch (sampling) { - case ST30_SAMPLING_48K: - switch (ptime) { - case ST30_PTIME_1MS: - samples = 48; - break; - case ST30_PTIME_125US: - samples = 6; - break; - case ST30_PTIME_250US: - samples = 12; - break; - case ST30_PTIME_333US: - samples = 16; - break; - case ST30_PTIME_4MS: - samples = 192; - break; - case ST31_PTIME_80US: - samples = 4; - break; - default: - err("%s, wrong ptime %d for 48k\n", __func__, ptime); - return -EINVAL; - } + } + break; + case ST31_SAMPLING_44K: + switch (ptime) { + case ST31_PTIME_1_09MS: + samples = 48; break; - case ST30_SAMPLING_96K: - switch (ptime) { - case ST30_PTIME_1MS: - samples = 96; - break; - case ST30_PTIME_125US: - samples = 12; - break; - case ST30_PTIME_250US: - samples = 24; - break; - case ST30_PTIME_333US: - samples = 32; - break; - case ST30_PTIME_4MS: - samples = 384; - break; - case ST31_PTIME_80US: - samples = 8; - break; - default: - err("%s, wrong ptime %d for 96k\n", __func__, ptime); - return -EINVAL; - } + case ST31_PTIME_0_14MS: + samples = 6; break; - case ST31_SAMPLING_44K: - switch (ptime) { - case ST31_PTIME_1_09MS: - samples = 48; - break; - case ST31_PTIME_0_14MS: - samples = 6; - break; - case ST31_PTIME_0_09MS: - samples = 4; - break; - default: - err("%s, wrong ptime %d for 44k\n", __func__, ptime); - return -EINVAL; - } + case ST31_PTIME_0_09MS: + samples = 4; break; default: - err("%s, wrong sampling %d\n", __func__, sampling); + err("%s, wrong ptime %d for 44k\n", __func__, ptime); return -EINVAL; + } + break; + default: + err("%s, wrong sampling %d\n", __func__, sampling); + return -EINVAL; } return samples; } int st30_get_sample_rate(enum st30_sampling sampling) { switch (sampling) { - case ST30_SAMPLING_48K: - return 48000; - case ST30_SAMPLING_96K: - return 96000; - case ST31_SAMPLING_44K: - return 44100; - default: - err("%s, wrong sampling %d\n", __func__, sampling); - return -EINVAL; + case ST30_SAMPLING_48K: + return 48000; + case ST30_SAMPLING_96K: + return 96000; + case ST31_SAMPLING_44K: + return 44100; + default: + err("%s, wrong sampling %d\n", __func__, sampling); + return -EINVAL; } } @@ -1153,11 +1168,13 @@ int st30_get_packet_size(enum st30_fmt fmt, enum st30_ptime ptime, int sample_num; ret = st30_get_sample_size(fmt); - if (ret < 0) return ret; + if (ret < 0) + return ret; sample_size = ret; ret = st30_get_sample_num(ptime, sampling); - if (ret < 0) return ret; + if (ret < 0) + return ret; sample_num = ret; if (!channel) { @@ -1170,7 +1187,7 @@ int st30_get_packet_size(enum st30_fmt fmt, enum st30_ptime ptime, int st30_calculate_framebuff_size(enum st30_fmt fmt, enum st30_ptime ptime, enum st30_sampling sampling, uint16_t channel, - uint64_t desired_frame_time_ns, double* fps) { + uint64_t desired_frame_time_ns, double *fps) { /* count frame size */ int pkt_per_frame = 1; int pkt_len = st30_get_packet_size(fmt, ptime, sampling, channel); @@ -1187,28 +1204,32 @@ int st30_calculate_framebuff_size(enum st30_fmt fmt, enum st30_ptime ptime, return framebuff_size; } -void st_frame_init_plane_single_src(struct st_frame* frame, void* addr, mtl_iova_t iova) { +void st_frame_init_plane_single_src(struct st_frame *frame, void *addr, + mtl_iova_t iova) { uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint8_t plane = 0; plane < planes; plane++) { - frame->linesize[plane] = st_frame_least_linesize(frame->fmt, frame->width, plane); + frame->linesize[plane] = + st_frame_least_linesize(frame->fmt, frame->width, plane); if (plane == 0) { frame->addr[plane] = addr; frame->iova[plane] = iova; } else { - frame->addr[plane] = frame->addr[plane - 1] + - frame->linesize[plane - 1] * st_frame_data_height(frame); - frame->iova[plane] = frame->iova[plane - 1] + - frame->linesize[plane - 1] * st_frame_data_height(frame); + frame->addr[plane] = + frame->addr[plane - 1] + + frame->linesize[plane - 1] * st_frame_data_height(frame); + frame->iova[plane] = + frame->iova[plane - 1] + + frame->linesize[plane - 1] * st_frame_data_height(frame); } } } -struct st_frame* st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, uint32_t w, - uint32_t h, bool interlaced) { - struct mtl_main_impl* impl = mt; +struct st_frame *st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, + uint32_t w, uint32_t h, bool interlaced) { + struct mtl_main_impl *impl = mt; int soc_id = mt_socket_id(impl, MTL_PORT_P); - struct st_frame* frame = mt_rte_zmalloc_socket(sizeof(*frame), soc_id); + struct st_frame *frame = mt_rte_zmalloc_socket(sizeof(*frame), soc_id); if (!frame) { err("%s, frame malloc fail\n", __func__); return NULL; @@ -1220,7 +1241,7 @@ struct st_frame* st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, uint32_t frame->flags = ST_FRAME_FLAG_SINGLE_MALLOC | ST_FRAME_FLAG_RTE_MALLOC; size_t data_sz = st_frame_size(fmt, w, h, interlaced); - void* data = mt_rte_zmalloc_socket(data_sz, soc_id); + void *data = mt_rte_zmalloc_socket(data_sz, soc_id); if (!data) { err("%s, data malloc fail, size %" PRIu64 "\n", __func__, data_sz); st_frame_free(frame); @@ -1233,9 +1254,9 @@ struct st_frame* st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, uint32_t return frame; } -struct st_frame* st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, uint32_t h, - bool interlaced) { - struct st_frame* frame = mt_zmalloc(sizeof(*frame)); +struct st_frame *st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, + uint32_t h, bool interlaced) { + struct st_frame *frame = mt_zmalloc(sizeof(*frame)); if (!frame) { err("%s, frame malloc fail\n", __func__); return NULL; @@ -1247,7 +1268,7 @@ struct st_frame* st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, ui frame->flags = ST_FRAME_FLAG_SINGLE_MALLOC; size_t data_sz = st_frame_size(fmt, w, h, interlaced); - void* data = mt_zmalloc(data_sz); + void *data = mt_zmalloc(data_sz); if (!data) { err("%s, data malloc fail, size %" PRIu64 "\n", __func__, data_sz); st_frame_free(frame); @@ -1260,9 +1281,10 @@ struct st_frame* st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, ui return frame; } -int st_frame_free(struct st_frame* frame) { +int st_frame_free(struct st_frame *frame) { if (!(frame->flags & ST_FRAME_FLAG_SINGLE_MALLOC)) { - err("%s, frame %p is not created by ST_FRAME_FLAG_SINGLE_MALLOC\n", __func__, frame); + err("%s, frame %p is not created by ST_FRAME_FLAG_SINGLE_MALLOC\n", + __func__, frame); return -EINVAL; } if (frame->flags & ST_FRAME_FLAG_RTE_MALLOC) { @@ -1349,7 +1371,8 @@ static const struct cvl_pad_table g_cvl_static_pad_tables[] = { .fps = ST_FPS_P59_94, .packing = ST20_PACKING_BPM, .interlaced = false, - .pad_interval = 262, /* measured with VERO avg vrx: 7.0, narrow vrx: 9 */ + .pad_interval = + 262, /* measured with VERO avg vrx: 7.0, narrow vrx: 9 */ }, { /* 4kp50 gpm */ @@ -1393,22 +1416,25 @@ static const struct cvl_pad_table g_cvl_static_pad_tables[] = { }, }; -uint16_t st20_pacing_static_profiling(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +uint16_t st20_pacing_static_profiling(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { - const struct cvl_pad_table* refer; - struct st20_tx_ops* ops = &s->ops; + const struct cvl_pad_table *refer; + struct st20_tx_ops *ops = &s->ops; MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(s_port); - if (s->s_type == MT_ST22_HANDLE_TX_VIDEO) return 0; /* no for st22 */ + if (s->s_type == MT_ST22_HANDLE_TX_VIDEO) + return 0; /* no for st22 */ for (int i = 0; i < MTL_ARRAY_SIZE(g_cvl_static_pad_tables); i++) { refer = &g_cvl_static_pad_tables[i]; if ((ops->fmt == refer->fmt) && (ops->width == refer->width) && (ops->height == refer->height) && (ops->fps == refer->fps) && - (ops->packing == refer->packing) && (ops->interlaced == refer->interlaced)) { - dbg("%s(%d), reference pad_interval %u\n", __func__, s->idx, refer->pad_interval); + (ops->packing == refer->packing) && + (ops->interlaced == refer->interlaced)) { + dbg("%s(%d), reference pad_interval %u\n", __func__, s->idx, + refer->pad_interval); return refer->pad_interval; } } @@ -1416,24 +1442,28 @@ uint16_t st20_pacing_static_profiling(struct mtl_main_impl* impl, return 0; /* not found */ } -int st_rxp_para_port_set(struct st_rx_port* p, enum mtl_session_port port, char* name) { +int st_rxp_para_port_set(struct st_rx_port *p, enum mtl_session_port port, + char *name) { return snprintf(p->port[port], MTL_PORT_MAX_LEN, "%s", name); } -int st_rxp_para_ip_set(struct st_rx_port* p, enum mtl_port port, char* ip) { +int st_rxp_para_ip_set(struct st_rx_port *p, enum mtl_port port, char *ip) { int ret = inet_pton(AF_INET, ip, p->ip_addr[port]); - if (ret == 1) return 0; + if (ret == 1) + return 0; err("%s, fail to inet_pton for %s\n", __func__, ip); return -EIO; } -int st_txp_para_port_set(struct st_tx_port* p, enum mtl_session_port port, char* name) { +int st_txp_para_port_set(struct st_tx_port *p, enum mtl_session_port port, + char *name) { return snprintf(p->port[port], MTL_PORT_MAX_LEN, "%s", name); } -int st_txp_para_dip_set(struct st_tx_port* p, enum mtl_port port, char* ip) { +int st_txp_para_dip_set(struct st_tx_port *p, enum mtl_port port, char *ip) { int ret = inet_pton(AF_INET, ip, p->dip_addr[port]); - if (ret == 1) return 0; + if (ret == 1) + return 0; err("%s, fail to inet_pton for %s\n", __func__, ip); return -EIO; } diff --git a/lib/src/st2110/st_fmt.h b/lib/src/st2110/st_fmt.h index 983c872c7..debf59249 100644 --- a/lib/src/st2110/st_fmt.h +++ b/lib/src/st2110/st_fmt.h @@ -10,7 +10,7 @@ struct st_fps_timing { enum st_fps fps; - char* name; + char *name; int sampling_clock_rate; /* 90k of sampling clock rate */ int mul; /* 60000 for ST_FPS_P59_94 */ int den; /* 1001 for ST_FPS_P59_94 */ @@ -28,27 +28,27 @@ enum st_frame_sampling { struct st_frame_fmt_desc { enum st_frame_fmt fmt; - char* name; + char *name; uint8_t planes; enum st_frame_sampling sampling; }; -const char* st20_fmt_name(enum st20_fmt fmt); +const char *st20_fmt_name(enum st20_fmt fmt); -const char* st_tx_pacing_way_name(enum st21_tx_pacing_way way); +const char *st_tx_pacing_way_name(enum st21_tx_pacing_way way); -int st_get_fps_timing(enum st_fps fps, struct st_fps_timing* fps_tm); +int st_get_fps_timing(enum st_fps fps, struct st_fps_timing *fps_tm); enum st_frame_sampling st_frame_fmt_get_sampling(enum st_frame_fmt fmt); -int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, enum st_fps fps, - uint64_t* bps); +int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, + enum st_fps fps, uint64_t *bps); -int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, uint64_t* bps); +int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, uint64_t *bps); -static inline void st20_unpack_pg2be_422le10(struct st20_rfc4175_422_10_pg2_be* pg, - uint16_t* cb00, uint16_t* y00, - uint16_t* cr00, uint16_t* y01) { +static inline void +st20_unpack_pg2be_422le10(struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *cb00, + uint16_t *y00, uint16_t *cr00, uint16_t *y01) { uint16_t cb, y0, cr, y1; cb = (pg->Cb00 << 2) + pg->Cb00_; @@ -62,9 +62,9 @@ static inline void st20_unpack_pg2be_422le10(struct st20_rfc4175_422_10_pg2_be* *y01 = y1; } -static inline void st20_unpack_pg2be_422le12(struct st20_rfc4175_422_12_pg2_be* pg, - uint16_t* cb00, uint16_t* y00, - uint16_t* cr00, uint16_t* y01) { +static inline void +st20_unpack_pg2be_422le12(struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *cb00, + uint16_t *y00, uint16_t *cr00, uint16_t *y01) { uint16_t cb, y0, cr, y1; cb = (pg->Cb00 << 4) + pg->Cb00_; @@ -78,7 +78,8 @@ static inline void st20_unpack_pg2be_422le12(struct st20_rfc4175_422_12_pg2_be* *y01 = y1; } -void st_frame_init_plane_single_src(struct st_frame* frame, void* addr, mtl_iova_t iova); +void st_frame_init_plane_single_src(struct st_frame *frame, void *addr, + mtl_iova_t iova); enum st_frame_fmt st_codec_codestream_fmt(enum st22_codec codec); diff --git a/lib/src/st2110/st_header.h b/lib/src/st2110/st_header.h index 5640fa0a1..af021294f 100644 --- a/lib/src/st2110/st_header.h +++ b/lib/src/st2110/st_header.h @@ -29,8 +29,10 @@ /* max 8 1080p rx(without DMA) session per sch lcore */ #define ST_QUOTA_RX1080P_NO_DMA_PER_SCH (8) -#define ST_SCH_MAX_TX_VIDEO_SESSIONS (60) /* max video tx sessions per sch lcore */ -#define ST_SCH_MAX_RX_VIDEO_SESSIONS (60) /* max video rx sessions per sch lcore */ +#define ST_SCH_MAX_TX_VIDEO_SESSIONS \ + (60) /* max video tx sessions per sch lcore */ +#define ST_SCH_MAX_RX_VIDEO_SESSIONS \ + (60) /* max video rx sessions per sch lcore */ #define ST_SESSION_MAX_BULK (4) #define ST_TX_VIDEO_SESSIONS_RING_SIZE (512) @@ -44,9 +46,11 @@ #define ST_VIDEO_BPM_SIZE (1260) /* max tx/rx audio(st_30) sessions */ -#define ST_SCH_MAX_TX_AUDIO_SESSIONS (512) /* max audio tx sessions per sch lcore */ +#define ST_SCH_MAX_TX_AUDIO_SESSIONS \ + (512) /* max audio tx sessions per sch lcore */ #define ST_TX_AUDIO_SESSIONS_RING_SIZE (ST_SCH_MAX_TX_AUDIO_SESSIONS * 2) -#define ST_SCH_MAX_RX_AUDIO_SESSIONS (512 * 2) /* max audio rx sessions per sch lcore */ +#define ST_SCH_MAX_RX_AUDIO_SESSIONS \ + (512 * 2) /* max audio rx sessions per sch lcore */ /* max tx/rx anc(st_40) sessions */ #define ST_MAX_TX_ANC_SESSIONS (180) @@ -94,7 +98,7 @@ enum st40_tx_frame_status { struct st_tx_muf_priv_data { uint64_t tsc_time_stamp; /* tsc time stamp of current mbuf */ uint64_t ptp_time_stamp; /* ptp time stamp of current mbuf */ - void* priv; /* private data to current frame */ + void *priv; /* private data to current frame */ uint32_t idx; /* index of packet in current frame */ }; @@ -113,24 +117,25 @@ struct st_rx_muf_priv_data { /* IOVA mapping info of each page in frame, used for IOVA:PA mode */ struct st_page_info { rte_iova_t iova; /* page begin iova */ - void* addr; /* page begin va */ + void *addr; /* page begin va */ size_t len; /* page length */ }; /* describe the frame used in transport(both tx and rx) */ struct st_frame_trans { int idx; - void* addr; /* virtual address */ - rte_iova_t iova; /* iova for hw */ - struct st_page_info* page_table; /* page table for hw, used for IOVA:PA mode */ - uint16_t page_table_len; /* page table len for hw, used for IOVA:PA mode */ - rte_atomic32_t refcnt; /* 0 means it's free */ - void* priv; /* private data for lib */ + void *addr; /* virtual address */ + rte_iova_t iova; /* iova for hw */ + struct st_page_info + *page_table; /* page table for hw, used for IOVA:PA mode */ + uint16_t page_table_len; /* page table len for hw, used for IOVA:PA mode */ + rte_atomic32_t refcnt; /* 0 means it's free */ + void *priv; /* private data for lib */ uint32_t flags; /* ST_FT_FLAG_* */ struct rte_mbuf_ext_shared_info sh_info; /* for st20 tx ext shared */ - void* user_meta; /* the meta data from user */ + void *user_meta; /* the meta data from user */ size_t user_meta_buffer_size; size_t user_meta_data_size; @@ -147,13 +152,14 @@ struct st_frame_trans { /* timing for pacing */ struct st_tx_video_pacing { - double trs; /* in ns for of 2 consecutive packets, T-Frame / N-Packets */ - double tr_offset; /* in ns, tr offset time of each frame */ - uint32_t vrx; /* packets unit, VRX start value of each frame */ - uint32_t warm_pkts; /* packets unit, pkts for RL pacing warm boot */ - double frame_time; /* time of the frame in nanoseconds */ + double trs; /* in ns for of 2 consecutive packets, T-Frame / N-Packets */ + double tr_offset; /* in ns, tr offset time of each frame */ + uint32_t vrx; /* packets unit, VRX start value of each frame */ + uint32_t warm_pkts; /* packets unit, pkts for RL pacing warm boot */ + double frame_time; /* time of the frame in nanoseconds */ double frame_time_sampling; /* time of the frame in sampling(90k) */ - /* in ns, idle time at the end of frame, frame_time - tr_offset - (trs * pkts) */ + /* in ns, idle time at the end of frame, frame_time - tr_offset - (trs * pkts) + */ double frame_idle_time; double reactive; float pad_interval; /* padding pkt interval(pkts level) for RL pacing */ @@ -227,10 +233,10 @@ struct st22_boxes { struct st22_tx_video_info { /* app callback */ - int (*get_next_frame)(void* priv, uint16_t* next_frame_idx, - struct st22_tx_frame_meta* meta); - int (*notify_frame_done)(void* priv, uint16_t frame_idx, - struct st22_tx_frame_meta* meta); + int (*get_next_frame)(void *priv, uint16_t *next_frame_idx, + struct st22_tx_frame_meta *meta); + int (*notify_frame_done)(void *priv, uint16_t frame_idx, + struct st22_tx_frame_meta *meta); struct st22_rfc9134_rtp_hdr rtp_hdr[MTL_SESSION_PORT_MAX]; int pkt_idx; /* for P&F counter*/ @@ -248,15 +254,15 @@ struct st_vsync_info { }; struct st_tx_video_session_impl { - struct mtl_main_impl* impl; - struct st_tx_video_sessions_mgr* mgr; + struct mtl_main_impl *impl; + struct st_tx_video_sessions_mgr *mgr; int socket_id; bool active; enum mtl_port port_maps[MTL_SESSION_PORT_MAX]; - struct rte_mempool* mbuf_mempool_hdr[MTL_SESSION_PORT_MAX]; + struct rte_mempool *mbuf_mempool_hdr[MTL_SESSION_PORT_MAX]; bool mbuf_mempool_reuse_rx[MTL_SESSION_PORT_MAX]; /* af_xdp zero copy */ - struct rte_mempool* mbuf_mempool_chain; - struct rte_mempool* mbuf_mempool_copy_chain; + struct rte_mempool *mbuf_mempool_chain; + struct rte_mempool *mbuf_mempool_copy_chain; bool tx_mono_pool; /* if reuse tx mono pool */ bool tx_no_chain; /* if tx not use chain mbuf */ bool multi_src_port; /* if tx use multiple src port */ @@ -265,15 +271,15 @@ struct st_tx_video_session_impl { /* if the eth dev support ipv4 checksum offload */ bool eth_ipv4_cksum_offload[MTL_SESSION_PORT_MAX]; unsigned int ring_count; - struct rte_ring* ring[MTL_SESSION_PORT_MAX]; - struct rte_ring* packet_ring; /* rtp ring */ - struct mt_txq_entry* queue[MTL_SESSION_PORT_MAX]; + struct rte_ring *ring[MTL_SESSION_PORT_MAX]; + struct rte_ring *packet_ring; /* rtp ring */ + struct mt_txq_entry *queue[MTL_SESSION_PORT_MAX]; int idx; /* index for current tx_session */ uint64_t advice_sleep_us; int recovery_idx; - struct st_tx_video_session_handle_impl* st20_handle; - struct st22_tx_video_session_handle_impl* st22_handle; + struct st_tx_video_session_handle_impl *st20_handle; + struct st22_tx_video_session_handle_impl *st22_handle; uint16_t st20_src_port[MTL_SESSION_PORT_MAX]; /* udp port */ uint16_t st20_dst_port[MTL_SESSION_PORT_MAX]; /* udp port */ @@ -281,9 +287,9 @@ struct st_tx_video_session_impl { struct st_tx_video_pacing pacing; enum st21_tx_pacing_way pacing_way[MTL_SESSION_PORT_MAX]; - int (*pacing_tasklet_func[MTL_SESSION_PORT_MAX])(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, - enum mtl_session_port s_port); + int (*pacing_tasklet_func[MTL_SESSION_PORT_MAX])( + struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, + enum mtl_session_port s_port); struct st_vsync_info vsync; bool second_field; @@ -294,18 +300,19 @@ struct st_tx_video_session_impl { enum mt_handle_type s_type; /* st22 or st20 */ unsigned int bulk; /* Enqueue bulk objects on the ring */ - struct rte_mbuf* inflight[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; + struct rte_mbuf *inflight[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; int inflight_cnt[MTL_SESSION_PORT_MAX]; /* for stats */ /* info for transmitter */ uint64_t trs_target_tsc[MTL_SESSION_PORT_MAX]; uint64_t trs_target_ptp[MTL_SESSION_PORT_MAX]; - struct rte_mbuf* trs_inflight[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; + struct rte_mbuf *trs_inflight[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; unsigned int trs_inflight_num[MTL_SESSION_PORT_MAX]; unsigned int trs_inflight_idx[MTL_SESSION_PORT_MAX]; - unsigned int trs_pad_inflight_num[MTL_SESSION_PORT_MAX]; /* inflight padding */ - int trs_inflight_cnt[MTL_SESSION_PORT_MAX]; /* for stats */ - struct rte_mbuf* trs_inflight2[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; + unsigned int + trs_pad_inflight_num[MTL_SESSION_PORT_MAX]; /* inflight padding */ + int trs_inflight_cnt[MTL_SESSION_PORT_MAX]; /* for stats */ + struct rte_mbuf *trs_inflight2[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; unsigned int trs_inflight_num2[MTL_SESSION_PORT_MAX]; unsigned int trs_inflight_idx2[MTL_SESSION_PORT_MAX]; int trs_inflight_cnt2[MTL_SESSION_PORT_MAX]; /* for stats */ @@ -319,7 +326,7 @@ struct st_tx_video_session_impl { size_t st20_fb_size; /* frame buffer size, with lines' padding */ size_t st20_linesize; /* line size including padding bytes */ uint16_t st20_frames_cnt; /* numbers of frames requested */ - struct st_frame_trans* st20_frames; + struct st_frame_trans *st20_frames; uint16_t st20_frame_idx; /* current frame index */ enum st21_tx_frame_status st20_frame_stat; @@ -340,19 +347,19 @@ struct st_tx_video_session_impl { int st21_vrx_wide; /* pass criteria for wide */ struct st20_packet_group_info st20_pkt_info[ST20_PKT_TYPE_MAX]; - struct rte_mbuf* pad[MTL_SESSION_PORT_MAX][ST20_PKT_TYPE_MAX]; + struct rte_mbuf *pad[MTL_SESSION_PORT_MAX][ST20_PKT_TYPE_MAX]; /* the cpu resource to handle tx, 0: full, 100: cpu is very busy */ double cpu_busy_score; rte_atomic32_t cbs_build_timeout; /* info for st22 */ - struct st22_tx_video_info* st22_info; + struct st22_tx_video_info *st22_info; uint16_t st22_box_hdr_length; size_t st22_codestream_size; - struct mt_rtcp_tx* rtcp_tx[MTL_SESSION_PORT_MAX]; - struct mt_rxq_entry* rtcp_q[MTL_SESSION_PORT_MAX]; + struct mt_rtcp_tx *rtcp_tx[MTL_SESSION_PORT_MAX]; + struct mt_rxq_entry *rtcp_q[MTL_SESSION_PORT_MAX]; /* use atomic safe? */ struct st20_tx_port_status port_user_stats[MTL_SESSION_PORT_MAX]; @@ -370,12 +377,15 @@ struct st_tx_video_session_impl { uint32_t stat_epoch_drop; uint32_t stat_epoch_onward; uint32_t stat_error_user_timestamp; - uint32_t stat_epoch_troffset_mismatch; /* pacing mismatch the epoch troffset */ - uint32_t stat_trans_troffset_mismatch; /* transmitter mismatch the epoch troffset */ + uint32_t + stat_epoch_troffset_mismatch; /* pacing mismatch the epoch troffset */ + uint32_t stat_trans_troffset_mismatch; /* transmitter mismatch the epoch + troffset */ uint32_t stat_trans_recalculate_warmup; uint32_t stat_exceed_frame_time; bool stat_user_busy_first; - uint32_t stat_user_busy; /* get_next_frame or dequeue_bulk from rtp ring fail */ + uint32_t + stat_user_busy; /* get_next_frame or dequeue_bulk from rtp ring fail */ uint32_t stat_lines_not_ready; /* query app lines not ready */ uint32_t stat_vsync_mismatch; uint64_t stat_bytes_tx[MTL_SESSION_PORT_MAX]; @@ -395,20 +405,20 @@ struct st_tx_video_session_impl { }; struct st_tx_video_sessions_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; /* index for current session mgr */ int max_idx; /* max session index */ - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; - struct st_tx_video_session_impl* sessions[ST_SCH_MAX_TX_VIDEO_SESSIONS]; + struct st_tx_video_session_impl *sessions[ST_SCH_MAX_TX_VIDEO_SESSIONS]; /* protect session, spin(fast) lock as it call from tasklet aslo */ rte_spinlock_t mutex[ST_SCH_MAX_TX_VIDEO_SESSIONS]; }; struct st_video_transmitter_impl { - struct mtl_main_impl* parent; - struct st_tx_video_sessions_mgr* mgr; - struct mt_sch_tasklet_impl* tasklet; + struct mtl_main_impl *parent; + struct st_tx_video_sessions_mgr *mgr; + struct mt_sch_tasklet_impl *tasklet; int idx; /* index for current transmitter */ }; @@ -429,8 +439,8 @@ struct st_rx_video_slot_impl { uint16_t seq_id_base; /* seq id for the first packet */ uint32_t seq_id_base_u32; /* seq id for the first packet with u32 */ bool seq_id_got; - struct st_frame_trans* frame; /* only for frame type */ - uint8_t* frame_bitmap; + struct st_frame_trans *frame; /* only for frame type */ + uint8_t *frame_bitmap; size_t frame_recv_size; /* for frame type */ size_t pkt_lcore_frame_recv_size; /* frame_recv_size for pkt lcore */ /* the total packets received, not include the redundant packets */ @@ -440,7 +450,8 @@ struct st_rx_video_slot_impl { struct st22_rx_frame_meta st22_meta; /* only for st22 frame type */ /* Second field type indicate */ bool second_field; - struct st_rx_video_slot_slice_info* slice_info; /* for ST20_TYPE_SLICE_LEVEL */ + struct st_rx_video_slot_slice_info + *slice_info; /* for ST20_TYPE_SLICE_LEVEL */ /* payload len for codestream packetization mode */ uint16_t st22_payload_length; uint16_t st22_box_hdr_length; @@ -471,14 +482,15 @@ struct st_rx_video_detector { struct st22_rx_video_info { /* app callback */ - int (*notify_frame_ready)(void* priv, void* frame, struct st22_rx_frame_meta* meta); + int (*notify_frame_ready)(void *priv, void *frame, + struct st22_rx_frame_meta *meta); struct st22_rx_frame_meta meta; size_t cur_frame_size; /* size per frame */ }; struct st_rx_video_hdr_split_info { - void* frames; + void *frames; size_t frames_size; rte_iova_t frames_iova; uint32_t mbuf_alloc_idx; @@ -487,7 +499,7 @@ struct st_rx_video_hdr_split_info { bool mbuf_pool_ready; /* base frame add for current frame */ - void* cur_frame_addr; + void *cur_frame_addr; /* mbuf idx for current frame */ uint32_t cur_frame_mbuf_idx; }; @@ -495,8 +507,8 @@ struct st_rx_video_hdr_split_info { struct st_rx_video_sessions_mgr; /* forward declare */ struct st_rx_session_priv { - void* session; - struct mtl_main_impl* impl; + void *session; + struct mtl_main_impl *impl; enum mtl_session_port s_port; }; @@ -553,11 +565,11 @@ struct st_rx_video_tp { }; struct st_rx_video_session_impl { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; int idx; /* index for current session */ int socket_id; bool attached; - struct st_rx_video_sessions_mgr* parent; + struct st_rx_video_sessions_mgr *parent; struct st_rx_session_priv priv[MTL_SESSION_PORT_MAX]; uint16_t rx_burst_size; uint16_t cur_succ_burst_cnt; @@ -568,14 +580,14 @@ struct st_rx_video_session_impl { uint64_t advice_sleep_us; enum mtl_port port_maps[MTL_SESSION_PORT_MAX]; - struct mt_rxq_entry* rxq[MTL_SESSION_PORT_MAX]; + struct mt_rxq_entry *rxq[MTL_SESSION_PORT_MAX]; uint16_t st20_dst_port[MTL_SESSION_PORT_MAX]; /* udp port */ bool mcast_joined[MTL_SESSION_PORT_MAX]; - struct st_rx_video_session_handle_impl* st20_handle; - struct st22_rx_video_session_handle_impl* st22_handle; + struct st_rx_video_session_handle_impl *st20_handle; + struct st22_rx_video_session_handle_impl *st22_handle; - struct st22_rx_video_info* st22_info; + struct st22_rx_video_info *st22_info; bool is_hdr_split; struct st_rx_video_hdr_split_info hdr_split_info[MTL_SESSION_PORT_MAX]; @@ -593,7 +605,7 @@ struct st_rx_video_session_impl { size_t st20_bytes_in_line; /* bytes per line not including padding */ size_t st20_frame_bitmap_size; /* bitmap size per frame */ int st20_frames_cnt; /* numbers of frames requested */ - struct st_frame_trans* st20_frames; + struct st_frame_trans *st20_frames; struct st20_pgroup st20_pg; double frame_time; /* time of the frame in nanoseconds */ double frame_time_sampling; /* time of the frame in sampling(90k) */ @@ -605,12 +617,13 @@ struct st_rx_video_session_impl { uint32_t st22_ops_flags; /* copy of st22_rx_ops->flags */ size_t st22_expect_frame_size; /* total frame size calculated from marker */ - /* expect for each frame, st22_expect_frame_size is clear to zero in the init slot of - * each frame, in case we don't get maker, it can use previous frame size */ + /* expect for each frame, st22_expect_frame_size is clear to zero in the init + * slot of each frame, in case we don't get maker, it can use previous frame + * size */ size_t st22_expect_size_per_frame; /* rtp info */ - struct rte_ring* rtps_ring; + struct rte_ring *rtps_ring; /* record two frames in case pkts out of order within marker */ struct st_rx_video_slot_impl slots[ST_VIDEO_RX_REC_NUM_OFO]; @@ -623,9 +636,9 @@ struct st_rx_video_session_impl { struct st20_rx_slice_meta slice_meta; /* dma dev */ - struct mtl_dma_lender_dev* dma_dev; + struct mtl_dma_lender_dev *dma_dev; uint16_t dma_nb_desc; - struct st_rx_video_slot_impl* dma_slot; + struct st_rx_video_slot_impl *dma_slot; bool dma_copy; /* pcap dumper */ @@ -634,7 +647,7 @@ struct st_rx_video_session_impl { /* additional lcore for pkt handling */ unsigned int pkt_lcore; bool has_pkt_lcore; - struct rte_ring* pkt_lcore_ring; + struct rte_ring *pkt_lcore_ring; rte_atomic32_t pkt_lcore_active; rte_atomic32_t pkt_lcore_stopped; @@ -645,7 +658,7 @@ struct st_rx_video_session_impl { rte_atomic32_t dma_previous_busy_cnt; rte_atomic32_t cbs_incomplete_frame_cnt; - struct mt_rtcp_rx* rtcp_rx[MTL_SESSION_PORT_MAX]; + struct mt_rtcp_rx *rtcp_rx[MTL_SESSION_PORT_MAX]; uint16_t burst_loss_max; float sim_loss_rate; uint16_t burst_loss_cnt; @@ -653,14 +666,14 @@ struct st_rx_video_session_impl { /* use atomic safe? */ struct st20_rx_port_status port_user_stats[MTL_SESSION_PORT_MAX]; - int (*pkt_handler)(struct st_rx_video_session_impl* s, struct rte_mbuf* mbuf, + int (*pkt_handler)(struct st_rx_video_session_impl *s, struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread); /* if enable the parser for the st2110-21 timing */ bool enable_timing_parser; bool enable_timing_parser_stat; bool enable_timing_parser_meta; - struct st_rx_video_tp* tp; + struct st_rx_video_tp *tp; /* status */ int stat_pkts_idx_dropped; @@ -715,13 +728,13 @@ struct st_rx_video_session_impl { }; struct st_rx_video_sessions_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; /* index for current session mgr */ int max_idx; /* max session index */ /* pkt rx task */ - struct mt_sch_tasklet_impl* pkt_rx_tasklet; + struct mt_sch_tasklet_impl *pkt_rx_tasklet; - struct st_rx_video_session_impl* sessions[ST_SCH_MAX_RX_VIDEO_SESSIONS]; + struct st_rx_video_session_impl *sessions[ST_SCH_MAX_RX_VIDEO_SESSIONS]; /* protect session, spin(fast) lock as it call from tasklet aslo */ rte_spinlock_t mutex[ST_SCH_MAX_RX_VIDEO_SESSIONS]; }; @@ -753,9 +766,9 @@ enum st30_tx_rl_stage { struct st_tx_audio_session_rl_port { /* two queues used per port */ - struct mt_txq_entry* queue[ST30_TX_RL_QUEUES_USED]; - struct rte_mbuf* pad; /* pkt with pad_pkt_size len */ - struct rte_mbuf* pkt; /* pkt with st30_pkt_size len */ + struct mt_txq_entry *queue[ST30_TX_RL_QUEUES_USED]; + struct rte_mbuf *pad; /* pkt with pad_pkt_size len */ + struct rte_mbuf *pkt; /* pkt with st30_pkt_size len */ int cur_queue; int cur_pkt_idx; uint64_t trs_target_tsc; @@ -790,26 +803,26 @@ struct st_tx_audio_session_impl { char ops_name[ST_MAX_NAME_LEN]; int recovery_idx; bool active; - struct st_tx_audio_sessions_mgr* mgr; + struct st_tx_audio_sessions_mgr *mgr; enum mtl_port port_maps[MTL_SESSION_PORT_MAX]; - struct rte_mempool* mbuf_mempool_hdr[MTL_SESSION_PORT_MAX]; - struct rte_mempool* mbuf_mempool_chain; + struct rte_mempool *mbuf_mempool_hdr[MTL_SESSION_PORT_MAX]; + struct rte_mempool *mbuf_mempool_chain; bool tx_mono_pool; /* if reuse tx mono pool */ bool tx_no_chain; /* if tx not use chain mbuf */ /* if the eth dev support chain buff */ bool eth_has_chain[MTL_SESSION_PORT_MAX]; /* if the eth dev support ipv4 checksum offload */ bool eth_ipv4_cksum_offload[MTL_SESSION_PORT_MAX]; - struct rte_mbuf* inflight[MTL_SESSION_PORT_MAX]; + struct rte_mbuf *inflight[MTL_SESSION_PORT_MAX]; int inflight_cnt[MTL_SESSION_PORT_MAX]; /* for stats */ - struct mt_u64_fifo* trans_ring[MTL_SESSION_PORT_MAX]; + struct mt_u64_fifo *trans_ring[MTL_SESSION_PORT_MAX]; uint16_t trans_ring_thresh; - struct rte_mbuf* trans_ring_inflight[MTL_SESSION_PORT_MAX]; - struct rte_ring* packet_ring; + struct rte_mbuf *trans_ring_inflight[MTL_SESSION_PORT_MAX]; + struct rte_ring *packet_ring; bool pacing_in_build; /* if control pacing in the build stage */ /* dedicated queue tx mode */ - struct mt_txq_entry* queue[MTL_SESSION_PORT_MAX]; + struct mt_txq_entry *queue[MTL_SESSION_PORT_MAX]; bool shared_queue; enum st30_tx_pacing_way tx_pacing_way; @@ -817,7 +830,7 @@ struct st_tx_audio_session_impl { struct st_tx_audio_session_rl_info rl; uint16_t st30_frames_cnt; /* numbers of frames requested */ - struct st_frame_trans* st30_frames; + struct st_frame_trans *st30_frames; uint32_t st30_frame_size; /* size per frame*/ uint16_t st30_frame_idx; /* current frame index */ enum st30_tx_frame_status st30_frame_stat; @@ -849,7 +862,7 @@ struct st_tx_audio_session_impl { int stat_build_ret_code; int stat_transmit_ret_code; - struct mt_rtcp_tx* rtcp_tx[MTL_SESSION_PORT_MAX]; + struct mt_rtcp_tx *rtcp_tx[MTL_SESSION_PORT_MAX]; /* stat */ rte_atomic32_t st30_stat_frame_cnt; @@ -872,20 +885,20 @@ struct st_tx_audio_session_impl { }; struct st_tx_audio_sessions_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int socket_id; int idx; /* index for current sessions mgr */ int max_idx; /* max session index */ - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; /* all audio sessions share same ring/queue */ - struct rte_ring* ring[MTL_PORT_MAX]; - struct mt_txq_entry* queue[MTL_PORT_MAX]; + struct rte_ring *ring[MTL_PORT_MAX]; + struct mt_txq_entry *queue[MTL_PORT_MAX]; /* the last burst succ time(tsc) */ uint64_t last_burst_succ_time_tsc[MTL_PORT_MAX]; uint64_t tx_hang_detect_time_thresh; - struct st_tx_audio_session_impl* sessions[ST_SCH_MAX_TX_AUDIO_SESSIONS]; + struct st_tx_audio_session_impl *sessions[ST_SCH_MAX_TX_AUDIO_SESSIONS]; /* protect session, spin(fast) lock as it call from tasklet aslo */ rte_spinlock_t mutex[ST_SCH_MAX_TX_AUDIO_SESSIONS]; /* protect session */ @@ -900,12 +913,12 @@ struct st_tx_audio_sessions_mgr { }; struct st_audio_transmitter_impl { - struct mtl_main_impl* parent; - struct st_tx_audio_sessions_mgr* mgr; - struct mt_sch_tasklet_impl* tasklet; + struct mtl_main_impl *parent; + struct st_tx_audio_sessions_mgr *mgr; + struct mt_sch_tasklet_impl *tasklet; int idx; /* index for current transmitter */ - struct rte_mbuf* inflight[MTL_PORT_MAX]; /* inflight mbuf */ + struct rte_mbuf *inflight[MTL_PORT_MAX]; /* inflight mbuf */ int inflight_cnt[MTL_PORT_MAX]; /* for stats */ }; @@ -956,29 +969,29 @@ struct st_rx_audio_tp { struct st_rx_audio_session_impl { int idx; /* index for current session */ - struct st_rx_audio_sessions_mgr* mgr; + struct st_rx_audio_sessions_mgr *mgr; int socket_id; bool attached; struct st30_rx_ops ops; char ops_name[ST_MAX_NAME_LEN]; struct st_rx_session_priv priv[MTL_SESSION_PORT_MAX]; - struct st_rx_audio_session_handle_impl* st30_handle; + struct st_rx_audio_session_handle_impl *st30_handle; bool enable_timing_parser; bool enable_timing_parser_stat; bool enable_timing_parser_meta; - struct st_rx_audio_tp* tp; + struct st_rx_audio_tp *tp; enum mtl_port port_maps[MTL_SESSION_PORT_MAX]; - struct mt_rxq_entry* rxq[MTL_SESSION_PORT_MAX]; + struct mt_rxq_entry *rxq[MTL_SESSION_PORT_MAX]; uint16_t st30_dst_port[MTL_SESSION_PORT_MAX]; /* udp port */ bool mcast_joined[MTL_SESSION_PORT_MAX]; - struct st_frame_trans* st30_frames; + struct st_frame_trans *st30_frames; int st30_frames_cnt; /* numbers of frames requested */ size_t st30_frame_size; - struct st_frame_trans* st30_cur_frame; /* pointer to current frame */ + struct st_frame_trans *st30_cur_frame; /* pointer to current frame */ int frames_per_sec; /* pcap dumper */ @@ -999,11 +1012,11 @@ struct st_rx_audio_session_impl { size_t frame_recv_size; /* st30 rtp info */ - struct rte_ring* st30_rtps_ring; + struct rte_ring *st30_rtps_ring; struct st30_rx_frame_meta meta; /* only for frame type */ - struct mt_rtcp_rx* rtcp_rx[MTL_SESSION_PORT_MAX]; + struct mt_rtcp_rx *rtcp_rx[MTL_SESSION_PORT_MAX]; /* status */ int st30_stat_pkts_dropped; @@ -1023,12 +1036,12 @@ struct st_rx_audio_session_impl { }; struct st_rx_audio_sessions_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; /* index for current session mgr */ int max_idx; /* max session index */ - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; - struct st_rx_audio_session_impl* sessions[ST_SCH_MAX_RX_AUDIO_SESSIONS]; + struct st_rx_audio_session_impl *sessions[ST_SCH_MAX_RX_AUDIO_SESSIONS]; /* protect session, spin(fast) lock as it call from tasklet aslo */ rte_spinlock_t mutex[ST_SCH_MAX_RX_AUDIO_SESSIONS]; }; @@ -1050,32 +1063,32 @@ struct st_tx_ancillary_session_pacing { struct st_tx_ancillary_session_impl { int idx; /* index for current session */ int socket_id; - struct st_tx_ancillary_sessions_mgr* mgr; + struct st_tx_ancillary_sessions_mgr *mgr; struct st40_tx_ops ops; char ops_name[ST_MAX_NAME_LEN]; enum mtl_port port_maps[MTL_SESSION_PORT_MAX]; - struct rte_mempool* mbuf_mempool_hdr[MTL_SESSION_PORT_MAX]; - struct rte_mempool* mbuf_mempool_chain; + struct rte_mempool *mbuf_mempool_hdr[MTL_SESSION_PORT_MAX]; + struct rte_mempool *mbuf_mempool_chain; bool tx_mono_pool; /* if reuse tx mono pool */ bool tx_no_chain; /* if tx not use chain mbuf */ /* if the eth dev support chain buff */ bool eth_has_chain[MTL_SESSION_PORT_MAX]; /* if the eth dev support ipv4 checksum offload */ bool eth_ipv4_cksum_offload[MTL_SESSION_PORT_MAX]; - struct rte_mbuf* inflight[MTL_SESSION_PORT_MAX]; + struct rte_mbuf *inflight[MTL_SESSION_PORT_MAX]; int inflight_cnt[MTL_SESSION_PORT_MAX]; /* for stats */ - struct rte_ring* packet_ring; + struct rte_ring *packet_ring; bool second_field; /* dedicated queue tx mode */ - struct mt_txq_entry* queue[MTL_SESSION_PORT_MAX]; + struct mt_txq_entry *queue[MTL_SESSION_PORT_MAX]; bool shared_queue; uint32_t max_pkt_len; /* max data len(byte) for each pkt */ uint16_t st40_frames_cnt; /* numbers of frames requested */ - struct st_frame_trans* st40_frames; + struct st_frame_trans *st40_frames; uint16_t st40_frame_idx; /* current frame index */ enum st40_tx_frame_status st40_frame_stat; @@ -1096,7 +1109,7 @@ struct st_tx_ancillary_session_impl { int stat_build_ret_code; - struct mt_rtcp_tx* rtcp_tx[MTL_SESSION_PORT_MAX]; + struct mt_rtcp_tx *rtcp_tx[MTL_SESSION_PORT_MAX]; /* stat */ rte_atomic32_t st40_stat_frame_cnt; @@ -1118,17 +1131,17 @@ struct st_tx_ancillary_session_impl { }; struct st_tx_ancillary_sessions_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int socket_id; int idx; /* index for current sessions mgr */ int max_idx; /* max session index */ - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; /* all anc sessions share same ring/queue */ - struct rte_ring* ring[MTL_PORT_MAX]; - struct mt_txq_entry* queue[MTL_PORT_MAX]; + struct rte_ring *ring[MTL_PORT_MAX]; + struct mt_txq_entry *queue[MTL_PORT_MAX]; - struct st_tx_ancillary_session_impl* sessions[ST_MAX_TX_ANC_SESSIONS]; + struct st_tx_ancillary_session_impl *sessions[ST_MAX_TX_ANC_SESSIONS]; /* protect session, spin(fast) lock as it call from tasklet aslo */ rte_spinlock_t mutex[ST_MAX_TX_ANC_SESSIONS]; @@ -1144,23 +1157,23 @@ struct st_tx_ancillary_sessions_mgr { struct st_rx_ancillary_session_impl { int idx; /* index for current session */ int socket_id; - struct st_rx_ancillary_sessions_mgr* mgr; + struct st_rx_ancillary_sessions_mgr *mgr; bool attached; struct st40_rx_ops ops; char ops_name[ST_MAX_NAME_LEN]; struct st_rx_session_priv priv[MTL_SESSION_PORT_MAX]; - struct st_rx_ancillary_session_handle_impl* st40_handle; + struct st_rx_ancillary_session_handle_impl *st40_handle; enum mtl_port port_maps[MTL_SESSION_PORT_MAX]; - struct mt_rxq_entry* rxq[MTL_SESSION_PORT_MAX]; - struct rte_ring* packet_ring; + struct mt_rxq_entry *rxq[MTL_SESSION_PORT_MAX]; + struct rte_ring *packet_ring; uint16_t st40_dst_port[MTL_SESSION_PORT_MAX]; /* udp port */ bool mcast_joined[MTL_SESSION_PORT_MAX]; int latest_seq_id; /* latest seq id */ - struct mt_rtcp_rx* rtcp_rx[MTL_SESSION_PORT_MAX]; + struct mt_rtcp_rx *rtcp_rx[MTL_SESSION_PORT_MAX]; uint32_t tmstamp; /* status */ @@ -1183,23 +1196,23 @@ struct st_rx_ancillary_session_impl { }; struct st_rx_ancillary_sessions_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; /* index for current session mgr */ int max_idx; /* max session index */ - struct mt_sch_tasklet_impl* tasklet; + struct mt_sch_tasklet_impl *tasklet; - struct st_rx_ancillary_session_impl* sessions[ST_MAX_RX_ANC_SESSIONS]; + struct st_rx_ancillary_session_impl *sessions[ST_MAX_RX_ANC_SESSIONS]; /* protect session, spin(fast) lock as it call from tasklet aslo */ rte_spinlock_t mutex[ST_MAX_RX_ANC_SESSIONS]; }; struct st_ancillary_transmitter_impl { - struct mtl_main_impl* parent; - struct st_tx_ancillary_sessions_mgr* mgr; - struct mt_sch_tasklet_impl* tasklet; + struct mtl_main_impl *parent; + struct st_tx_ancillary_sessions_mgr *mgr; + struct mt_sch_tasklet_impl *tasklet; int idx; /* index for current transmitter */ - struct rte_mbuf* inflight[MTL_PORT_MAX]; /* inflight mbuf */ + struct rte_mbuf *inflight[MTL_PORT_MAX]; /* inflight mbuf */ int inflight_cnt[MTL_PORT_MAX]; /* for stats */ }; @@ -1207,39 +1220,42 @@ struct st22_get_encoder_request { enum st_plugin_device device; struct st22_encoder_create_req req; - void* priv; - struct st22_encode_frame_meta* (*get_frame)(void* priv); - int (*wake_block)(void* priv); - int (*set_block_timeout)(void* priv, uint64_t timedwait_ns); - int (*put_frame)(void* priv, struct st22_encode_frame_meta* frame, int result); - int (*dump)(void* priv); + void *priv; + struct st22_encode_frame_meta *(*get_frame)(void *priv); + int (*wake_block)(void *priv); + int (*set_block_timeout)(void *priv, uint64_t timedwait_ns); + int (*put_frame)(void *priv, struct st22_encode_frame_meta *frame, + int result); + int (*dump)(void *priv); }; struct st22_get_decoder_request { enum st_plugin_device device; struct st22_decoder_create_req req; - void* priv; - struct st22_decode_frame_meta* (*get_frame)(void* priv); - int (*wake_block)(void* priv); - int (*set_block_timeout)(void* priv, uint64_t timedwait_ns); - int (*put_frame)(void* priv, struct st22_decode_frame_meta* frame, int result); - int (*dump)(void* priv); + void *priv; + struct st22_decode_frame_meta *(*get_frame)(void *priv); + int (*wake_block)(void *priv); + int (*set_block_timeout)(void *priv, uint64_t timedwait_ns); + int (*put_frame)(void *priv, struct st22_decode_frame_meta *frame, + int result); + int (*dump)(void *priv); }; struct st20_get_converter_request { enum st_plugin_device device; struct st20_converter_create_req req; - void* priv; - struct st20_convert_frame_meta* (*get_frame)(void* priv); - int (*put_frame)(void* priv, struct st20_convert_frame_meta* frame, int result); - int (*dump)(void* priv); + void *priv; + struct st20_convert_frame_meta *(*get_frame)(void *priv); + int (*put_frame)(void *priv, struct st20_convert_frame_meta *frame, + int result); + int (*dump)(void *priv); }; struct st22_encode_session_impl { int idx; - void* parent; /* point to struct st22_encode_dev_impl */ + void *parent; /* point to struct st22_encode_dev_impl */ st22_encode_priv session; enum mt_handle_type type; /* for sanity check */ @@ -1250,7 +1266,7 @@ struct st22_encode_session_impl { struct st22_encode_dev_impl { enum mt_handle_type type; /* for sanity check */ - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; char name[ST_MAX_NAME_LEN]; struct st22_encoder_dev dev; @@ -1260,7 +1276,7 @@ struct st22_encode_dev_impl { struct st22_decode_session_impl { int idx; - void* parent; /* point to struct st22_decode_dev_impl */ + void *parent; /* point to struct st22_decode_dev_impl */ st22_decode_priv session; enum mt_handle_type type; /* for sanity check */ @@ -1269,7 +1285,7 @@ struct st22_decode_session_impl { struct st22_decode_dev_impl { enum mt_handle_type type; /* for sanity check */ - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; char name[ST_MAX_NAME_LEN]; struct st22_decoder_dev dev; @@ -1279,7 +1295,7 @@ struct st22_decode_dev_impl { struct st20_convert_session_impl { int idx; - void* parent; /* point to struct st20_convert_dev_impl */ + void *parent; /* point to struct st20_convert_dev_impl */ st20_convert_priv session; enum mt_handle_type type; /* for sanity check */ @@ -1288,7 +1304,7 @@ struct st20_convert_session_impl { struct st20_convert_dev_impl { enum mt_handle_type type; /* for sanity check */ - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; int idx; char name[ST_MAX_NAME_LEN]; struct st20_converter_dev dev; @@ -1299,7 +1315,7 @@ struct st20_convert_dev_impl { struct st_dl_plugin_impl { int idx; char path[ST_PLUGIN_MAX_PATH_LEN]; - void* dl_handle; + void *dl_handle; st_plugin_create_fn create; st_plugin_priv handle; st_plugin_free_fn free; @@ -1308,76 +1324,76 @@ struct st_dl_plugin_impl { struct st_plugin_mgr { pthread_mutex_t lock; /* lock for encode_devs/decode_devs */ - struct st22_encode_dev_impl* encode_devs[ST_MAX_ENCODER_DEV]; - struct st22_decode_dev_impl* decode_devs[ST_MAX_DECODER_DEV]; - struct st20_convert_dev_impl* convert_devs[ST_MAX_CONVERTER_DEV]; + struct st22_encode_dev_impl *encode_devs[ST_MAX_ENCODER_DEV]; + struct st22_decode_dev_impl *decode_devs[ST_MAX_DECODER_DEV]; + struct st20_convert_dev_impl *convert_devs[ST_MAX_CONVERTER_DEV]; pthread_mutex_t plugins_lock; /* lock for plugins */ - struct st_dl_plugin_impl* plugins[ST_MAX_DL_PLUGINS]; + struct st_dl_plugin_impl *plugins[ST_MAX_DL_PLUGINS]; int plugins_nb; }; struct st_tx_video_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_tx_video_session_impl* impl; + struct st_tx_video_session_impl *impl; }; struct st22_tx_video_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_tx_video_session_impl* impl; + struct st_tx_video_session_impl *impl; }; struct st_tx_audio_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_tx_audio_session_impl* impl; + struct st_tx_audio_session_impl *impl; }; struct st_tx_ancillary_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_tx_ancillary_session_impl* impl; + struct st_tx_ancillary_session_impl *impl; }; struct st_rx_video_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_rx_video_session_impl* impl; + struct st_rx_video_session_impl *impl; }; struct st22_rx_video_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_rx_video_session_impl* impl; + struct st_rx_video_session_impl *impl; }; struct st_rx_audio_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_rx_audio_session_impl* impl; + struct st_rx_audio_session_impl *impl; }; struct st_rx_ancillary_session_handle_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; - struct mtl_sch_impl* sch; /* the sch this session attached */ + struct mtl_sch_impl *sch; /* the sch this session attached */ int quota_mbs; /* data quota for this session */ - struct st_rx_ancillary_session_impl* impl; + struct st_rx_ancillary_session_impl *impl; }; static inline bool st20_is_frame_type(enum st20_type type) { diff --git a/lib/src/st2110/st_main.h b/lib/src/st2110/st_main.h index 45bf82574..d893dbc15 100644 --- a/lib/src/st2110/st_main.h +++ b/lib/src/st2110/st_main.h @@ -13,8 +13,8 @@ #include "../mt_simd.h" #include "../mt_util.h" -static inline enum st21_tx_pacing_way st_tx_pacing_way(struct mtl_main_impl* impl, - enum mtl_port port) { +static inline enum st21_tx_pacing_way +st_tx_pacing_way(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->tx_pacing_way; } diff --git a/lib/src/st2110/st_pkt.h b/lib/src/st2110/st_pkt.h index deffabc0b..25924025a 100644 --- a/lib/src/st2110/st_pkt.h +++ b/lib/src/st2110/st_pkt.h @@ -60,20 +60,20 @@ struct st_rfc8331_anc_hdr { struct st40_rfc8331_rtp_hdr rtp; /* size: 20 */ } __attribute__((__packed__)) __rte_aligned(2); -#define ST_PKT_VIDEO_HDR_LEN \ +#define ST_PKT_VIDEO_HDR_LEN \ (sizeof(struct st_rfc4175_video_hdr) - sizeof(struct rte_ether_hdr)) -#define ST22_PKT_VIDEO_HDR_LEN \ +#define ST22_PKT_VIDEO_HDR_LEN \ (sizeof(struct st22_rfc9134_video_hdr) - sizeof(struct rte_ether_hdr)) -#define ST_PKT_AUDIO_HDR_LEN \ +#define ST_PKT_AUDIO_HDR_LEN \ (sizeof(struct st_rfc3550_audio_hdr) - sizeof(struct rte_ether_hdr)) -#define ST_PKT_ANC_HDR_LEN \ +#define ST_PKT_ANC_HDR_LEN \ (sizeof(struct st_rfc8331_anc_hdr) - sizeof(struct rte_ether_hdr)) /* standard UDP is 1460 bytes */ -#define ST_PKT_MAX_ETHER_BYTES \ +#define ST_PKT_MAX_ETHER_BYTES \ (1460 + sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)) #endif diff --git a/lib/src/st2110/st_rx_ancillary_session.c b/lib/src/st2110/st_rx_ancillary_session.c index 74aff6d58..af6477080 100644 --- a/lib/src/st2110/st_rx_ancillary_session.c +++ b/lib/src/st2110/st_rx_ancillary_session.c @@ -10,37 +10,45 @@ #include "st_ancillary_transmitter.h" /* call rx_ancillary_session_put always if get successfully */ -static inline struct st_rx_ancillary_session_impl* rx_ancillary_session_get( - struct st_rx_ancillary_sessions_mgr* mgr, int idx) { +static inline struct st_rx_ancillary_session_impl * +rx_ancillary_session_get(struct st_rx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_rx_ancillary_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); + struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline struct st_rx_ancillary_session_impl* rx_ancillary_session_try_get( - struct st_rx_ancillary_sessions_mgr* mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; - struct st_rx_ancillary_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_rx_ancillary_session_impl * +rx_ancillary_session_try_get(struct st_rx_ancillary_sessions_mgr *mgr, + int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) + return NULL; + struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline struct st_rx_ancillary_session_impl* rx_ancillary_session_get_timeout( - struct st_rx_ancillary_sessions_mgr* mgr, int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; - struct st_rx_ancillary_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_rx_ancillary_session_impl * +rx_ancillary_session_get_timeout(struct st_rx_ancillary_sessions_mgr *mgr, + int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) + return NULL; + struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline bool rx_ancillary_session_get_empty( - struct st_rx_ancillary_sessions_mgr* mgr, int idx) { +static inline bool +rx_ancillary_session_get_empty(struct st_rx_ancillary_sessions_mgr *mgr, + int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_rx_ancillary_session_impl* s = mgr->sessions[idx]; + struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; if (s) { rte_spinlock_unlock(&mgr->mutex[idx]); /* not null, unlock it */ return false; @@ -49,66 +57,68 @@ static inline bool rx_ancillary_session_get_empty( } } -static inline void rx_ancillary_session_put(struct st_rx_ancillary_sessions_mgr* mgr, - int idx) { +static inline void +rx_ancillary_session_put(struct st_rx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -static inline uint16_t rx_ancillary_queue_id(struct st_rx_ancillary_session_impl* s, - enum mtl_session_port s_port) { +static inline uint16_t +rx_ancillary_queue_id(struct st_rx_ancillary_session_impl *s, + enum mtl_session_port s_port) { return mt_rxq_queue_id(s->rxq[s_port]); } -static int rx_ancillary_session_init(struct st_rx_ancillary_sessions_mgr* mgr, - struct st_rx_ancillary_session_impl* s, int idx) { +static int rx_ancillary_session_init(struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s, + int idx) { MTL_MAY_UNUSED(mgr); s->idx = idx; return 0; } -static int rx_ancillary_sessions_tasklet_start(void* priv) { - struct st_rx_ancillary_sessions_mgr* mgr = priv; +static int rx_ancillary_sessions_tasklet_start(void *priv) { + struct st_rx_ancillary_sessions_mgr *mgr = priv; int idx = mgr->idx; info("%s(%d), succ\n", __func__, idx); return 0; } -static int rx_ancillary_sessions_tasklet_stop(void* priv) { - struct st_rx_ancillary_sessions_mgr* mgr = priv; +static int rx_ancillary_sessions_tasklet_stop(void *priv) { + struct st_rx_ancillary_sessions_mgr *mgr = priv; int idx = mgr->idx; info("%s(%d), succ\n", __func__, idx); return 0; } -static int rx_ancillary_session_handle_pkt(struct mtl_main_impl* impl, - struct st_rx_ancillary_session_impl* s, - struct rte_mbuf* mbuf, - enum mtl_session_port s_port) { - struct st40_rx_ops* ops = &s->ops; - size_t hdr_offset = sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); - struct st_rfc3550_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr*, hdr_offset); +static int rx_ancillary_session_handle_pkt( + struct mtl_main_impl *impl, struct st_rx_ancillary_session_impl *s, + struct rte_mbuf *mbuf, enum mtl_session_port s_port) { + struct st40_rx_ops *ops = &s->ops; + size_t hdr_offset = + sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); + struct st_rfc3550_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr *, hdr_offset); uint16_t seq_id = ntohs(rtp->seq_number); uint8_t payload_type = rtp->payload_type; - struct st40_rfc8331_rtp_hdr* rfc8331 = (struct st40_rfc8331_rtp_hdr*)rtp; + struct st40_rfc8331_rtp_hdr *rfc8331 = (struct st40_rfc8331_rtp_hdr *)rtp; MTL_MAY_UNUSED(s_port); uint32_t pkt_len = mbuf->data_len - sizeof(struct st40_rfc8331_rtp_hdr); MTL_MAY_UNUSED(pkt_len); uint32_t tmstamp = ntohl(rtp->tmstamp); if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, - payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, + s_port, payload_type, ops->payload_type); s->st40_stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, - ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, + ssrc, ops->ssrc); s->st40_stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } @@ -132,10 +142,12 @@ static int rx_ancillary_session_handle_pkt(struct mtl_main_impl* impl, } /* set if it is first pkt */ - if (unlikely(s->latest_seq_id == -1)) s->latest_seq_id = seq_id - 1; + if (unlikely(s->latest_seq_id == -1)) + s->latest_seq_id = seq_id - 1; /* drop old packet */ if (st_rx_seq_drop(seq_id, s->latest_seq_id, 5)) { - dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, seq_id); + dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, + seq_id); s->st40_stat_pkts_redundant++; return 0; } @@ -146,10 +158,10 @@ static int rx_ancillary_session_handle_pkt(struct mtl_main_impl* impl, s->latest_seq_id = seq_id; /* enqueue to packet ring to let app to handle */ - int ret = rte_ring_sp_enqueue(s->packet_ring, (void*)mbuf); + int ret = rte_ring_sp_enqueue(s->packet_ring, (void *)mbuf); if (ret < 0) { - err("%s(%d), can not enqueue to the rte ring, packet drop, pkt seq %d\n", __func__, - s->idx, seq_id); + err("%s(%d), can not enqueue to the rte ring, packet drop, pkt seq %d\n", + __func__, s->idx, seq_id); s->st40_stat_pkts_enqueue_fail++; MT_USDT_ST40_RX_MBUF_ENQUEUE_FAIL(s->mgr->idx, s->idx, mbuf, tmstamp); return 0; @@ -165,7 +177,8 @@ static int rx_ancillary_session_handle_pkt(struct mtl_main_impl* impl, /* get a valid packet */ uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); ops->notify_rtp_ready(ops->priv); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; @@ -176,11 +189,11 @@ static int rx_ancillary_session_handle_pkt(struct mtl_main_impl* impl, return 0; } -static int rx_ancillary_session_handle_mbuf(void* priv, struct rte_mbuf** mbuf, +static int rx_ancillary_session_handle_mbuf(void *priv, struct rte_mbuf **mbuf, uint16_t nb) { - struct st_rx_session_priv* s_priv = priv; - struct st_rx_ancillary_session_impl* s = s_priv->session; - struct mtl_main_impl* impl = s_priv->impl; + struct st_rx_session_priv *s_priv = priv; + struct st_rx_ancillary_session_impl *s = s_priv->session; + struct mtl_main_impl *impl = s_priv->impl; enum mtl_session_port s_port = s_priv->s_port; if (!s->attached) { @@ -194,14 +207,16 @@ static int rx_ancillary_session_handle_mbuf(void* priv, struct rte_mbuf** mbuf, return 0; } -static int rx_ancillary_session_tasklet(struct st_rx_ancillary_session_impl* s) { - struct rte_mbuf* mbuf[ST_RX_ANCILLARY_BURST_SIZE]; +static int +rx_ancillary_session_tasklet(struct st_rx_ancillary_session_impl *s) { + struct rte_mbuf *mbuf[ST_RX_ANCILLARY_BURST_SIZE]; uint16_t rv; int num_port = s->ops.num_port; bool done = true; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rxq[s_port]) continue; + if (!s->rxq[s_port]) + continue; rv = mt_rxq_burst(s->rxq[s_port], &mbuf[0], ST_RX_ANCILLARY_BURST_SIZE); if (rv) { @@ -209,24 +224,27 @@ static int rx_ancillary_session_tasklet(struct st_rx_ancillary_session_impl* s) rte_pktmbuf_free_bulk(&mbuf[0], rv); } - if (rv) done = false; + if (rv) + done = false; } return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int rx_ancillary_sessions_tasklet_handler(void* priv) { - struct st_rx_ancillary_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_rx_ancillary_session_impl* s; +static int rx_ancillary_sessions_tasklet_handler(void *priv) { + struct st_rx_ancillary_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_rx_ancillary_session_impl *s; int pending = MTL_TASKLET_ALL_DONE; uint64_t tsc_s = 0; bool time_measure = mt_sessions_time_measure(impl); for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_ancillary_session_try_get(mgr, sidx); - if (!s) continue; - if (time_measure) tsc_s = mt_get_tsc(impl); + if (!s) + continue; + if (time_measure) + tsc_s = mt_get_tsc(impl); pending += rx_ancillary_session_tasklet(s); @@ -240,7 +258,8 @@ static int rx_ancillary_sessions_tasklet_handler(void* priv) { return pending; } -static int rx_ancillary_session_uinit_hw(struct st_rx_ancillary_session_impl* s) { +static int +rx_ancillary_session_uinit_hw(struct st_rx_ancillary_session_impl *s) { int num_port = s->ops.num_port; for (int i = 0; i < num_port; i++) { @@ -253,8 +272,9 @@ static int rx_ancillary_session_uinit_hw(struct st_rx_ancillary_session_impl* s) return 0; } -static int rx_ancillary_session_init_hw(struct mtl_main_impl* impl, - struct st_rx_ancillary_session_impl* s) { +static int +rx_ancillary_session_init_hw(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { int idx = s->idx, num_port = s->ops.num_port; struct mt_rxq_flow flow; enum mtl_port port; @@ -273,12 +293,13 @@ static int rx_ancillary_session_init_hw(struct mtl_main_impl* impl, else rte_memcpy(flow.sip_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); flow.dst_port = s->st40_dst_port[i]; - if (mt_has_cni_rx(impl, port)) flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; + if (mt_has_cni_rx(impl, port)) + flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; /* no flow for data path only */ if (s->ops.flags & ST40_RX_FLAG_DATA_PATH_ONLY) { - info("%s(%d), rxq get without flow for port %d as data path only\n", __func__, - s->idx, i); + info("%s(%d), rxq get without flow for port %d as data path only\n", + __func__, s->idx, i); s->rxq[i] = mt_rxq_get(impl, port, NULL); } else { s->rxq[i] = mt_rxq_get(impl, port, &flow); @@ -295,13 +316,15 @@ static int rx_ancillary_session_init_hw(struct mtl_main_impl* impl, return 0; } -static int rx_ancillary_session_uinit_mcast(struct mtl_main_impl* impl, - struct st_rx_ancillary_session_impl* s) { - struct st40_rx_ops* ops = &s->ops; +static int +rx_ancillary_session_uinit_mcast(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { + struct st40_rx_ops *ops = &s->ops; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!s->mcast_joined[i]) continue; + if (!s->mcast_joined[i]) + continue; port = mt_port_logic2phy(s->port_maps, i); mt_mcast_leave(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); @@ -310,14 +333,16 @@ static int rx_ancillary_session_uinit_mcast(struct mtl_main_impl* impl, return 0; } -static int rx_ancillary_session_init_mcast(struct mtl_main_impl* impl, - struct st_rx_ancillary_session_impl* s) { - struct st40_rx_ops* ops = &s->ops; +static int +rx_ancillary_session_init_mcast(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { + struct st40_rx_ops *ops = &s->ops; int ret; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!mt_is_multicast_ip(ops->ip_addr[i])) continue; + if (!mt_is_multicast_ip(ops->ip_addr[i])) + continue; port = mt_port_logic2phy(s->port_maps, i); if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { info("%s(%d), skip mcast join for port %d\n", __func__, s->idx, i); @@ -325,22 +350,25 @@ static int rx_ancillary_session_init_mcast(struct mtl_main_impl* impl, } ret = mt_mcast_join(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->mcast_joined[i] = true; } return 0; } -static int rx_ancillary_session_init_sw(struct st_rx_ancillary_sessions_mgr* mgr, - struct st_rx_ancillary_session_impl* s) { +static int +rx_ancillary_session_init_sw(struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s) { char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_RX_ANCILLARY_PREFIX, mgr_idx, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ops.rtp_ring_size; ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (count <= 0) { @@ -356,7 +384,8 @@ static int rx_ancillary_session_init_sw(struct st_rx_ancillary_sessions_mgr* mgr return 0; } -static int rx_ancillary_session_uinit_sw(struct st_rx_ancillary_session_impl* s) { +static int +rx_ancillary_session_uinit_sw(struct st_rx_ancillary_session_impl *s) { if (s->packet_ring) { mt_ring_dequeue_clean(s->packet_ring); rte_ring_free(s->packet_ring); @@ -366,25 +395,27 @@ static int rx_ancillary_session_uinit_sw(struct st_rx_ancillary_session_impl* s) return 0; } -static int rx_ancillary_session_uinit(struct mtl_main_impl* impl, - struct st_rx_ancillary_session_impl* s) { +static int rx_ancillary_session_uinit(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { rx_ancillary_session_uinit_mcast(impl, s); rx_ancillary_session_uinit_sw(s); rx_ancillary_session_uinit_hw(s); return 0; } -static int rx_ancillary_session_attach(struct mtl_main_impl* impl, - struct st_rx_ancillary_sessions_mgr* mgr, - struct st_rx_ancillary_session_impl* s, - struct st40_rx_ops* ops) { +static int rx_ancillary_session_attach(struct mtl_main_impl *impl, + struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s, + struct st40_rx_ops *ops) { int ret; int idx = s->idx, num_port = ops->num_port; - char* ports[MTL_SESSION_PORT_MAX]; + char *ports[MTL_SESSION_PORT_MAX]; - for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) + ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->mgr = mgr; if (ops->name) { @@ -394,7 +425,8 @@ static int rx_ancillary_session_attach(struct mtl_main_impl* impl, } s->ops = *ops; for (int i = 0; i < num_port; i++) { - s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); + s->st40_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); } s->latest_seq_id = -1; @@ -420,18 +452,19 @@ static int rx_ancillary_session_attach(struct mtl_main_impl* impl, ret = rx_ancillary_session_init_mcast(impl, s); if (ret < 0) { - err("%s(%d), rx_ancillary_session_init_mcast fail %d\n", __func__, idx, ret); + err("%s(%d), rx_ancillary_session_init_mcast fail %d\n", __func__, idx, + ret); rx_ancillary_session_uinit(impl, s); return -EIO; } s->attached = true; - info("%s(%d), flags 0x%x pt %u, %s\n", __func__, idx, ops->flags, ops->payload_type, - ops->interlaced ? "interlace" : "progressive"); + info("%s(%d), flags 0x%x pt %u, %s\n", __func__, idx, ops->flags, + ops->payload_type, ops->interlaced ? "interlace" : "progressive"); return 0; } -static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl* s) { +static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl *s) { int idx = s->idx; uint64_t cur_time_ns = mt_get_monotonic_time(); double time_sec = (double)(cur_time_ns - s->st40_stat_last_time) / NS_PER_S; @@ -440,17 +473,19 @@ static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl* s) { rte_atomic32_set(&s->st40_stat_frames_received, 0); - notice("RX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d\n", idx, s->ops_name, framerate, - frames_received, s->st40_stat_pkts_received); + notice("RX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d\n", idx, s->ops_name, + framerate, frames_received, s->st40_stat_pkts_received); s->st40_stat_pkts_received = 0; s->st40_stat_last_time = cur_time_ns; if (s->st40_stat_pkts_redundant) { - notice("RX_ANC_SESSION(%d): redundant pkts %d\n", idx, s->st40_stat_pkts_redundant); + notice("RX_ANC_SESSION(%d): redundant pkts %d\n", idx, + s->st40_stat_pkts_redundant); s->st40_stat_pkts_redundant = 0; } if (s->st40_stat_pkts_dropped) { - notice("RX_ANC_SESSION(%d): dropped pkts %d\n", idx, s->st40_stat_pkts_dropped); + notice("RX_ANC_SESSION(%d): dropped pkts %d\n", idx, + s->st40_stat_pkts_dropped); s->st40_stat_pkts_dropped = 0; } if (s->st40_stat_pkts_out_of_order) { @@ -479,40 +514,43 @@ static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl* s) { s->st40_stat_pkts_enqueue_fail = 0; } if (s->ops.interlaced) { - notice("RX_ANC_SESSION(%d): interlace first field %u second field %u\n", idx, - s->stat_interlace_first_field, s->stat_interlace_second_field); + notice("RX_ANC_SESSION(%d): interlace first field %u second field %u\n", + idx, s->stat_interlace_first_field, s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } - struct mt_stat_u64* stat_time = &s->stat_time; + struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("RX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", idx, - (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice( + "RX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", + idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_notify_rtp_us > 8) { - notice("RX_ANC_SESSION(%d): notify rtp max %uus\n", idx, s->stat_max_notify_rtp_us); + notice("RX_ANC_SESSION(%d): notify rtp max %uus\n", idx, + s->stat_max_notify_rtp_us); } s->stat_max_notify_rtp_us = 0; } -static int rx_ancillary_session_detach(struct mtl_main_impl* impl, - struct st_rx_ancillary_session_impl* s) { +static int rx_ancillary_session_detach(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { s->attached = false; rx_ancillary_session_stat(s); rx_ancillary_session_uinit(impl, s); return 0; } -static int rx_ancillary_session_update_src(struct mtl_main_impl* impl, - struct st_rx_ancillary_session_impl* s, - struct st_rx_source_info* src) { +static int +rx_ancillary_session_update_src(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; - struct st40_rx_ops* ops = &s->ops; + struct st40_rx_ops *ops = &s->ops; rx_ancillary_session_uinit_mcast(impl, s); rx_ancillary_session_uinit_hw(s); @@ -522,7 +560,8 @@ static int rx_ancillary_session_update_src(struct mtl_main_impl* impl, memcpy(ops->ip_addr[i], src->ip_addr[i], MTL_IP_ADDR_LEN); memcpy(ops->mcast_sip_addr[i], src->mcast_sip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = src->udp_port[i]; - s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); + s->st40_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); } /* reset seq id */ s->latest_seq_id = -1; @@ -542,9 +581,10 @@ static int rx_ancillary_session_update_src(struct mtl_main_impl* impl, return 0; } -static int rx_ancillary_sessions_mgr_update_src(struct st_rx_ancillary_sessions_mgr* mgr, - struct st_rx_ancillary_session_impl* s, - struct st_rx_source_info* src) { +static int +rx_ancillary_sessions_mgr_update_src(struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = rx_ancillary_session_get(mgr, idx); /* get the lock */ @@ -563,13 +603,14 @@ static int rx_ancillary_sessions_mgr_update_src(struct st_rx_ancillary_sessions_ return 0; } -static int st_rx_ancillary_sessions_stat(void* priv) { - struct st_rx_ancillary_sessions_mgr* mgr = priv; - struct st_rx_ancillary_session_impl* s; +static int st_rx_ancillary_sessions_stat(void *priv) { + struct st_rx_ancillary_sessions_mgr *mgr = priv; + struct st_rx_ancillary_session_impl *s; for (int j = 0; j < mgr->max_idx; j++) { s = rx_ancillary_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) continue; + if (!s) + continue; rx_ancillary_session_stat(s); rx_ancillary_session_put(mgr, j); } @@ -577,9 +618,10 @@ static int st_rx_ancillary_sessions_stat(void* priv) { return 0; } -static int rx_ancillary_sessions_mgr_init(struct mtl_main_impl* impl, - struct mtl_sch_impl* sch, - struct st_rx_ancillary_sessions_mgr* mgr) { +static int +rx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_rx_ancillary_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; @@ -608,17 +650,19 @@ static int rx_ancillary_sessions_mgr_init(struct mtl_main_impl* impl, return 0; } -static struct st_rx_ancillary_session_impl* rx_ancillary_sessions_mgr_attach( - struct mtl_sch_impl* sch, struct st40_rx_ops* ops) { - struct st_rx_ancillary_sessions_mgr* mgr = &sch->rx_anc_mgr; +static struct st_rx_ancillary_session_impl * +rx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, + struct st40_rx_ops *ops) { + struct st_rx_ancillary_sessions_mgr *mgr = &sch->rx_anc_mgr; int midx = mgr->idx; int ret; - struct st_rx_ancillary_session_impl* s; + struct st_rx_ancillary_session_impl *s; int socket = mt_sch_socket_id(sch); /* find one empty slot in the mgr */ for (int i = 0; i < ST_MAX_RX_ANC_SESSIONS; i++) { - if (!rx_ancillary_session_get_empty(mgr, i)) continue; + if (!rx_ancillary_session_get_empty(mgr, i)) + continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -652,8 +696,9 @@ static struct st_rx_ancillary_session_impl* rx_ancillary_sessions_mgr_attach( return NULL; } -static int rx_ancillary_sessions_mgr_detach(struct st_rx_ancillary_sessions_mgr* mgr, - struct st_rx_ancillary_session_impl* s) { +static int +rx_ancillary_sessions_mgr_detach(struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -672,20 +717,23 @@ static int rx_ancillary_sessions_mgr_detach(struct st_rx_ancillary_sessions_mgr* return 0; } -static int rx_ancillary_sessions_mgr_update(struct st_rx_ancillary_sessions_mgr* mgr) { +static int +rx_ancillary_sessions_mgr_update(struct st_rx_ancillary_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_MAX_RX_ANC_SESSIONS; i++) { - if (mgr->sessions[i]) max_idx = i + 1; + if (mgr->sessions[i]) + max_idx = i + 1; } mgr->max_idx = max_idx; return 0; } -static int rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr* mgr) { +static int +rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr *mgr) { int m_idx = mgr->idx; - struct st_rx_ancillary_session_impl* s; + struct st_rx_ancillary_session_impl *s; mt_stat_unregister(mgr->parent, st_rx_ancillary_sessions_stat, mgr); @@ -696,7 +744,8 @@ static int rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr* for (int i = 0; i < ST_MAX_RX_ANC_SESSIONS; i++) { s = rx_ancillary_session_get(mgr, i); - if (!s) continue; + if (!s) + continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); rx_ancillary_sessions_mgr_detach(mgr, s); @@ -707,9 +756,9 @@ static int rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr* return 0; } -static int rx_ancillary_ops_check(struct st40_rx_ops* ops) { +static int rx_ancillary_ops_check(struct st40_rx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip = NULL; + uint8_t *ip = NULL; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { err("%s, invalid num_ports %d\n", __func__, num_ports); @@ -720,14 +769,16 @@ static int rx_ancillary_ops_check(struct st40_rx_ops* ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -751,10 +802,12 @@ static int rx_ancillary_ops_check(struct st40_rx_ops* ops) { return 0; } -static int st_rx_anc_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { +static int st_rx_anc_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { int ret; - if (sch->rx_anc_init) return 0; + if (sch->rx_anc_init) + return 0; /* create rx ancillary context */ ret = rx_ancillary_sessions_mgr_init(impl, sch, &sch->rx_anc_mgr); @@ -767,8 +820,9 @@ static int st_rx_anc_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) return 0; } -int st_rx_ancillary_sessions_sch_uinit(struct mtl_sch_impl* sch) { - if (!sch->rx_anc_init) return 0; +int st_rx_ancillary_sessions_sch_uinit(struct mtl_sch_impl *sch) { + if (!sch->rx_anc_init) + return 0; rx_ancillary_sessions_mgr_uinit(&sch->rx_anc_mgr); @@ -776,11 +830,11 @@ int st_rx_ancillary_sessions_sch_uinit(struct mtl_sch_impl* sch) { return 0; } -st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct mtl_sch_impl* sch; - struct st_rx_ancillary_session_handle_impl* s_impl; - struct st_rx_ancillary_session_impl* s; +st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct mtl_sch_impl *sch; + struct st_rx_ancillary_session_handle_impl *s_impl; + struct st_rx_ancillary_session_impl *s; int ret; int quota_mbs; @@ -798,7 +852,8 @@ st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops* ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); s_impl = mt_rte_zmalloc_socket(sizeof(*s_impl), socket); @@ -808,8 +863,8 @@ st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops* ops) { } quota_mbs = 0; - sch = - mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); + sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, + MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -848,10 +903,11 @@ st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops* ops) { return s_impl; } -int st40_rx_update_source(st40_rx_handle handle, struct st_rx_source_info* src) { - struct st_rx_ancillary_session_handle_impl* s_impl = handle; - struct st_rx_ancillary_session_impl* s; - struct mtl_sch_impl* sch; +int st40_rx_update_source(st40_rx_handle handle, + struct st_rx_source_info *src) { + struct st_rx_ancillary_session_handle_impl *s_impl = handle; + struct st_rx_ancillary_session_impl *s; + struct mtl_sch_impl *sch; int idx, ret, sch_idx; if (s_impl->type != MT_HANDLE_RX_ANC) { @@ -865,7 +921,8 @@ int st40_rx_update_source(st40_rx_handle handle, struct st_rx_source_info* src) sch_idx = sch->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = rx_ancillary_sessions_mgr_update_src(&sch->rx_anc_mgr, s, src); if (ret < 0) { @@ -878,10 +935,10 @@ int st40_rx_update_source(st40_rx_handle handle, struct st_rx_source_info* src) } int st40_rx_free(st40_rx_handle handle) { - struct st_rx_ancillary_session_handle_impl* s_impl = handle; - struct mtl_main_impl* impl; - struct st_rx_ancillary_session_impl* s; - struct mtl_sch_impl* sch; + struct st_rx_ancillary_session_handle_impl *s_impl = handle; + struct mtl_main_impl *impl; + struct st_rx_ancillary_session_impl *s; + struct mtl_sch_impl *sch; int ret, idx; int sch_idx; @@ -900,10 +957,12 @@ int st40_rx_free(st40_rx_handle handle) { mt_pthread_mutex_lock(&sch->rx_anc_mgr_mutex); ret = rx_ancillary_sessions_mgr_detach(&sch->rx_anc_mgr, s); mt_pthread_mutex_unlock(&sch->rx_anc_mgr_mutex); - if (ret < 0) err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -917,11 +976,11 @@ int st40_rx_free(st40_rx_handle handle) { return 0; } -void* st40_rx_get_mbuf(st40_rx_handle handle, void** usrptr, uint16_t* len) { - struct st_rx_ancillary_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt; - struct st_rx_ancillary_session_impl* s; - struct rte_ring* packet_ring; +void *st40_rx_get_mbuf(st40_rx_handle handle, void **usrptr, uint16_t *len) { + struct st_rx_ancillary_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt; + struct st_rx_ancillary_session_impl *s; + struct rte_ring *packet_ring; int idx, ret; if (s_impl->type != MT_HANDLE_RX_ANC) { @@ -937,22 +996,22 @@ void* st40_rx_get_mbuf(st40_rx_handle handle, void** usrptr, uint16_t* len) { return NULL; } - ret = rte_ring_sc_dequeue(packet_ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(packet_ring, (void **)&pkt); if (ret == 0) { - int header_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + - sizeof(struct rte_udp_hdr); + int header_len = sizeof(struct rte_ether_hdr) + + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr); *len = pkt->data_len - header_len; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, header_len); - return (void*)pkt; + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, header_len); + return (void *)pkt; } return NULL; } -void st40_rx_put_mbuf(st40_rx_handle handle, void* mbuf) { - struct st_rx_ancillary_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; - struct st_rx_ancillary_session_impl* s; +void st40_rx_put_mbuf(st40_rx_handle handle, void *mbuf) { + struct st_rx_ancillary_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; + struct st_rx_ancillary_session_impl *s; if (s_impl->type != MT_HANDLE_RX_ANC) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -962,13 +1021,14 @@ void st40_rx_put_mbuf(st40_rx_handle handle, void* mbuf) { s = s_impl->impl; MTL_MAY_UNUSED(s); - if (pkt) rte_pktmbuf_free(pkt); + if (pkt) + rte_pktmbuf_free(pkt); MT_USDT_ST40_RX_MBUF_PUT(s->mgr->idx, s->idx, mbuf); } -int st40_rx_get_queue_meta(st40_rx_handle handle, struct st_queue_meta* meta) { - struct st_rx_ancillary_session_handle_impl* s_impl = handle; - struct st_rx_ancillary_session_impl* s; +int st40_rx_get_queue_meta(st40_rx_handle handle, struct st_queue_meta *meta) { + struct st_rx_ancillary_session_handle_impl *s_impl = handle; + struct st_rx_ancillary_session_impl *s; if (s_impl->type != MT_HANDLE_RX_ANC) { err("%s, invalid type %d\n", __func__, s_impl->type); diff --git a/lib/src/st2110/st_rx_ancillary_session.h b/lib/src/st2110/st_rx_ancillary_session.h index 101ece174..fc680892f 100644 --- a/lib/src/st2110/st_rx_ancillary_session.h +++ b/lib/src/st2110/st_rx_ancillary_session.h @@ -11,6 +11,6 @@ #define ST_RX_ANCILLARY_PREFIX "RC_" -int st_rx_ancillary_sessions_sch_uinit(struct mtl_sch_impl* sch); +int st_rx_ancillary_sessions_sch_uinit(struct mtl_sch_impl *sch); #endif \ No newline at end of file diff --git a/lib/src/st2110/st_rx_audio_session.c b/lib/src/st2110/st_rx_audio_session.c index a892a8b82..0d82b3831 100644 --- a/lib/src/st2110/st_rx_audio_session.c +++ b/lib/src/st2110/st_rx_audio_session.c @@ -12,43 +12,49 @@ #include "../mt_stat.h" #include "st_rx_timing_parser.h" -static inline uint16_t rx_audio_queue_id(struct st_rx_audio_session_impl* s, +static inline uint16_t rx_audio_queue_id(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port) { return mt_rxq_queue_id(s->rxq[s_port]); } /* call rx_audio_session_put always if get successfully */ -static inline struct st_rx_audio_session_impl* rx_audio_session_get( - struct st_rx_audio_sessions_mgr* mgr, int idx) { +static inline struct st_rx_audio_session_impl * +rx_audio_session_get(struct st_rx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_rx_audio_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); + struct st_rx_audio_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_audio_session_put always if get successfully */ -static inline struct st_rx_audio_session_impl* rx_audio_session_get_timeout( - struct st_rx_audio_sessions_mgr* mgr, int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; - struct st_rx_audio_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_rx_audio_session_impl * +rx_audio_session_get_timeout(struct st_rx_audio_sessions_mgr *mgr, int idx, + int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) + return NULL; + struct st_rx_audio_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_audio_session_put always if get successfully */ -static inline struct st_rx_audio_session_impl* rx_audio_session_try_get( - struct st_rx_audio_sessions_mgr* mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; - struct st_rx_audio_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_rx_audio_session_impl * +rx_audio_session_try_get(struct st_rx_audio_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) + return NULL; + struct st_rx_audio_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_audio_session_put always if get successfully */ -static inline bool rx_audio_session_get_empty(struct st_rx_audio_sessions_mgr* mgr, - int idx) { +static inline bool +rx_audio_session_get_empty(struct st_rx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_rx_audio_session_impl* s = mgr->sessions[idx]; + struct st_rx_audio_session_impl *s = mgr->sessions[idx]; if (s) { rte_spinlock_unlock(&mgr->mutex[idx]); /* not null, unlock it */ return false; @@ -57,13 +63,14 @@ static inline bool rx_audio_session_get_empty(struct st_rx_audio_sessions_mgr* m } } -static inline void rx_audio_session_put(struct st_rx_audio_sessions_mgr* mgr, int idx) { +static inline void rx_audio_session_put(struct st_rx_audio_sessions_mgr *mgr, + int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -static struct st_frame_trans* rx_audio_session_get_frame( - struct st_rx_audio_session_impl* s) { - struct st_frame_trans* frame_info; +static struct st_frame_trans * +rx_audio_session_get_frame(struct st_rx_audio_session_impl *s) { + struct st_frame_trans *frame_info; for (int i = 0; i < s->st30_frames_cnt; i++) { frame_info = &s->st30_frames[i]; @@ -79,8 +86,8 @@ static struct st_frame_trans* rx_audio_session_get_frame( return NULL; } -static int rx_audio_session_put_frame(struct st_rx_audio_session_impl* s, - struct st_frame_trans* frame) { +static int rx_audio_session_put_frame(struct st_rx_audio_session_impl *s, + struct st_frame_trans *frame) { MTL_MAY_UNUSED(s); dbg("%s(%d), put frame at %d\n", __func__, s->idx, frame->idx); rte_atomic32_dec(&frame->refcnt); @@ -88,14 +95,14 @@ static int rx_audio_session_put_frame(struct st_rx_audio_session_impl* s, return -EIO; } -static int rx_audio_session_free_frames(struct st_rx_audio_session_impl* s) { +static int rx_audio_session_free_frames(struct st_rx_audio_session_impl *s) { /* free frames */ if (s->st30_frames) { if (s->st30_cur_frame) { rx_audio_session_put_frame(s, s->st30_cur_frame); s->st30_cur_frame = NULL; } - struct st_frame_trans* frame; + struct st_frame_trans *frame; for (int i = 0; i < s->st30_frames_cnt; i++) { frame = &s->st30_frames[i]; st_frame_trans_uinit(frame); @@ -108,15 +115,15 @@ static int rx_audio_session_free_frames(struct st_rx_audio_session_impl* s) { return 0; } -static int rx_audio_session_alloc_frames(struct st_rx_audio_session_impl* s) { +static int rx_audio_session_alloc_frames(struct st_rx_audio_session_impl *s) { int soc_id = s->socket_id; int idx = s->idx; size_t size = s->st30_frame_size; - struct st_frame_trans* st30_frame; - void* frame; + struct st_frame_trans *st30_frame; + void *frame; - s->st30_frames = - mt_rte_zmalloc_socket(sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); + s->st30_frames = mt_rte_zmalloc_socket( + sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); if (!s->st30_frames) { err("%s(%d), st30_frames alloc fail\n", __func__, idx); return -ENOMEM; @@ -133,7 +140,8 @@ static int rx_audio_session_alloc_frames(struct st_rx_audio_session_impl* s) { frame = mt_rte_zmalloc_socket(size, soc_id); if (!frame) { - err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, size, i); + err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, size, + i); rx_audio_session_free_frames(s); return -ENOMEM; } @@ -146,7 +154,7 @@ static int rx_audio_session_alloc_frames(struct st_rx_audio_session_impl* s) { return 0; } -static int rx_audio_session_free_rtps(struct st_rx_audio_session_impl* s) { +static int rx_audio_session_free_rtps(struct st_rx_audio_session_impl *s) { if (s->st30_rtps_ring) { mt_ring_dequeue_clean(s->st30_rtps_ring); rte_ring_free(s->st30_rtps_ring); @@ -156,15 +164,16 @@ static int rx_audio_session_free_rtps(struct st_rx_audio_session_impl* s) { return 0; } -static int rx_audio_session_alloc_rtps(struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s) { +static int rx_audio_session_alloc_rtps(struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s) { char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_RTP", ST_RX_AUDIO_PREFIX, mgr_idx, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ops.rtp_ring_size; if (count <= 0) { err("%s(%d,%d), invalid rtp_ring_size %d\n", __func__, mgr_idx, idx, count); @@ -180,54 +189,56 @@ static int rx_audio_session_alloc_rtps(struct st_rx_audio_sessions_mgr* mgr, return 0; } -static int rx_audio_sessions_tasklet_start(void* priv) { - struct st_rx_audio_sessions_mgr* mgr = priv; +static int rx_audio_sessions_tasklet_start(void *priv) { + struct st_rx_audio_sessions_mgr *mgr = priv; int idx = mgr->idx; info("%s(%d), succ\n", __func__, idx); return 0; } -static int rx_audio_sessions_tasklet_stop(void* priv) { - struct st_rx_audio_sessions_mgr* mgr = priv; +static int rx_audio_sessions_tasklet_stop(void *priv) { + struct st_rx_audio_sessions_mgr *mgr = priv; int idx = mgr->idx; info("%s(%d), succ\n", __func__, idx); return 0; } -static int rx_audio_session_usdt_dump_close(struct st_rx_audio_session_impl* s) { +static int +rx_audio_session_usdt_dump_close(struct st_rx_audio_session_impl *s) { int idx = s->idx; if (s->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, s->usdt_dump_fd, - s->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, + s->usdt_dump_fd, s->usdt_dumped_frames); close(s->usdt_dump_fd); s->usdt_dump_fd = -1; } return 0; } -static int rx_audio_session_usdt_dump_frame(struct st_rx_audio_session_impl* s, - struct st_frame_trans* frame) { - struct st_rx_audio_sessions_mgr* mgr = s->mgr; +static int rx_audio_session_usdt_dump_frame(struct st_rx_audio_session_impl *s, + struct st_frame_trans *frame) { + struct st_rx_audio_sessions_mgr *mgr = s->mgr; int idx = s->idx; int ret; if (s->usdt_dump_fd < 0) { - struct st30_rx_ops* ops = &s->ops; + struct st30_rx_ops *ops = &s->ops; snprintf(s->usdt_dump_path, sizeof(s->usdt_dump_path), "imtl_usdt_st30rx_m%ds%d_%d_%d_c%u_XXXXXX.pcm", mgr->idx, idx, - st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, - ops->channel); + st30_get_sample_rate(ops->sampling), + st30_get_sample_size(ops->fmt) * 8, ops->channel); ret = mt_mkstemps(s->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, + ret); return ret; } s->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, s->usdt_dump_path, - s->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, + s->usdt_dump_path, s->usdt_dump_fd); } /* write frame to dump file */ @@ -246,16 +257,16 @@ static int rx_audio_session_usdt_dump_frame(struct st_rx_audio_session_impl* s, return 0; } -static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, - struct st_rx_audio_session_impl* s, - struct rte_mbuf* mbuf, +static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl *impl, + struct st_rx_audio_session_impl *s, + struct rte_mbuf *mbuf, enum mtl_session_port s_port) { - struct st30_rx_ops* ops = &s->ops; + struct st30_rx_ops *ops = &s->ops; size_t hdr_offset = sizeof(struct st_rfc3550_audio_hdr) - sizeof(struct st_rfc3550_rtp_hdr); - struct st_rfc3550_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr*, hdr_offset); - void* payload = &rtp[1]; + struct st_rfc3550_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr *, hdr_offset); + void *payload = &rtp[1]; uint16_t seq_id = ntohs(rtp->seq_number); uint32_t tmstamp = ntohl(rtp->tmstamp); @@ -263,33 +274,35 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, uint32_t pkt_len = mbuf->data_len - sizeof(struct st_rfc3550_audio_hdr); if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, - payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, + s_port, payload_type, ops->payload_type); s->st30_stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, - ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, + ssrc, ops->ssrc); s->st30_stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } } if (pkt_len != s->pkt_len) { - dbg("%s(%d,%d), drop as pkt_len mismatch now %u expect %u\n", __func__, s->idx, - s_port, pkt_len, s->pkt_len); + dbg("%s(%d,%d), drop as pkt_len mismatch now %u expect %u\n", __func__, + s->idx, s_port, pkt_len, s->pkt_len); s->st30_stat_pkts_len_mismatch_dropped++; return -EINVAL; } /* set first seq_id - 1 */ - if (unlikely(s->latest_seq_id == -1)) s->latest_seq_id = seq_id - 1; + if (unlikely(s->latest_seq_id == -1)) + s->latest_seq_id = seq_id - 1; /* drop old packet */ if (st_rx_seq_drop(seq_id, s->latest_seq_id, 5)) { - dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, seq_id); + dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, + seq_id); s->st30_stat_pkts_redundant++; if (s->enable_timing_parser) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); @@ -299,8 +312,8 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, } if (seq_id != (uint16_t)(s->latest_seq_id + 1)) { s->st30_stat_pkts_out_of_order++; - info("%s(%d,%d), ooo, seq now %u last %d\n", __func__, s->idx, s_port, seq_id, - s->latest_seq_id); + info("%s(%d,%d), ooo, seq now %u last %d\n", __func__, s->idx, s_port, + seq_id, s->latest_seq_id); } /* update seq id */ s->latest_seq_id = seq_id; @@ -309,7 +322,8 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, if (!s->st30_cur_frame) { s->st30_cur_frame = rx_audio_session_get_frame(s); if (!s->st30_cur_frame) { - dbg("%s(%d,%d), seq %d drop as frame run out\n", __func__, s->idx, s_port, seq_id); + dbg("%s(%d,%d), seq %d drop as frame run out\n", __func__, s->idx, s_port, + seq_id); s->stat_slot_get_frame_fail++; MT_USDT_ST30_RX_NO_FRAMEBUFFER(s->mgr->idx, s->idx, tmstamp); return -EIO; @@ -317,8 +331,8 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, } uint32_t offset = s->st30_pkt_idx * s->pkt_len; if ((offset + s->pkt_len) > s->st30_frame_size) { - dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, s->idx, s_port, - offset, s->st30_frame_size); + dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, + s->idx, s_port, offset, s->st30_frame_size); s->st30_stat_pkts_dropped++; return -EIO; } @@ -334,17 +348,17 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, // notify frame done if (s->frame_recv_size >= s->st30_frame_size) { - struct st30_rx_frame_meta* meta = &s->meta; + struct st30_rx_frame_meta *meta = &s->meta; uint64_t tsc_start = 0; - struct st_frame_trans* frame = s->st30_cur_frame; + struct st_frame_trans *frame = s->st30_cur_frame; if (s->enable_timing_parser) { /* parse timing result every 200ms */ - struct st_rx_audio_tp* tp = s->tp; + struct st_rx_audio_tp *tp = s->tp; uint64_t now = mt_get_tsc(impl); if ((now - tp->last_parse_time) > (200 * NS_PER_MS)) { for (int sp = 0; sp < ops->num_port; sp++) { - struct st_ra_tp_slot* slot = &s->tp->slot[sp]; + struct st_ra_tp_slot *slot = &s->tp->slot[sp]; ra_tp_slot_parse_result(s, sp); if (s->enable_timing_parser_meta) { ops->notify_timing_parser_result(ops->priv, sp, &slot->meta); @@ -363,7 +377,8 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, meta->rtp_timestamp = tmstamp; meta->frame_recv_size = s->frame_recv_size; - MT_USDT_ST30_RX_FRAME_AVAILABLE(s->mgr->idx, s->idx, frame->idx, frame->addr, tmstamp, + MT_USDT_ST30_RX_FRAME_AVAILABLE(s->mgr->idx, s->idx, frame->idx, + frame->addr, tmstamp, meta->frame_recv_size); /* check if dump USDT enabled */ if (MT_USDT_ST30_RX_FRAME_DUMP_ENABLED()) { @@ -374,11 +389,13 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, /* get a full frame */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); int ret = ops->notify_frame_ready(ops->priv, frame->addr, meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = + RTE_MAX(s->stat_max_notify_frame_us, delta_us); } if (ret < 0) { err("%s(%d), notify_frame_ready return fail %d\n", __func__, s->idx, ret); @@ -393,15 +410,15 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl* impl, return 0; } -static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl, - struct st_rx_audio_session_impl* s, - struct rte_mbuf* mbuf, +static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl *impl, + struct st_rx_audio_session_impl *s, + struct rte_mbuf *mbuf, enum mtl_session_port s_port) { - struct st30_rx_ops* ops = &s->ops; + struct st30_rx_ops *ops = &s->ops; size_t hdr_offset = sizeof(struct st_rfc3550_audio_hdr) - sizeof(struct st_rfc3550_rtp_hdr); - struct st_rfc3550_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr*, hdr_offset); + struct st_rfc3550_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr *, hdr_offset); MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(s_port); @@ -409,26 +426,28 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl, uint8_t payload_type = rtp->payload_type; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, - payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, + s_port, payload_type, ops->payload_type); s->st30_stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, - ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, + ssrc, ops->ssrc); s->st30_stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } } /* set first seq_id - 1 */ - if (unlikely(s->latest_seq_id == -1)) s->latest_seq_id = seq_id - 1; + if (unlikely(s->latest_seq_id == -1)) + s->latest_seq_id = seq_id - 1; /* drop old packet */ if (st_rx_seq_drop(seq_id, s->latest_seq_id, 5)) { - dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, seq_id); + dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, + seq_id); s->st30_stat_pkts_redundant++; return -EIO; } @@ -439,9 +458,10 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl, s->latest_seq_id = seq_id; /* enqueue the packet ring to app */ - int ret = rte_ring_sp_enqueue(s->st30_rtps_ring, (void*)mbuf); + int ret = rte_ring_sp_enqueue(s->st30_rtps_ring, (void *)mbuf); if (ret < 0) { - dbg("%s(%d,%d), drop as rtps ring full, seq id %d\n", __func__, seq_id, s_port); + dbg("%s(%d,%d), drop as rtps ring full, seq id %d\n", __func__, seq_id, + s_port); s->st30_stat_pkts_rtp_ring_full++; return -EIO; } @@ -453,14 +473,15 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl* impl, return 0; } -static int ra_stop_pcap(struct st_rx_audio_session_impl* s, +static int ra_stop_pcap(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port) { - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; - if (!pcap->pcap) return 0; + if (!pcap->pcap) + return 0; - info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, s->idx, - s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); + info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, + s->idx, s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); MT_USDT_ST30_RX_PCAP_DUMP(s->mgr->idx, s->idx, s_port, pcap->file_name, pcap->dumped_pkts); pcap->required_pkts = 0; @@ -469,26 +490,27 @@ static int ra_stop_pcap(struct st_rx_audio_session_impl* s, return 0; } -static int rv_stop_pcap_dump(struct st_rx_audio_session_impl* s) { +static int rv_stop_pcap_dump(struct st_rx_audio_session_impl *s) { for (int s_port = 0; s_port < s->ops.num_port; s_port++) { ra_stop_pcap(s, s_port); } return 0; } -static int ra_start_pcap(struct st_rx_audio_session_impl* s, enum mtl_session_port s_port, +static int ra_start_pcap(struct st_rx_audio_session_impl *s, + enum mtl_session_port s_port, uint32_t max_dump_packets) { int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->pcap) { err("%s(%d,%d), pcap dump already started\n", __func__, idx, s_port); return -EIO; } - snprintf(pcap->file_name, sizeof(pcap->file_name), "st30rx_s%dp%d_%u_XXXXXX.pcapng", - idx, s_port, max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), + "st30rx_s%dp%d_%u_XXXXXX.pcapng", idx, s_port, max_dump_packets); int fd = mt_mkstemps(pcap->file_name, strlen(".pcapng")); if (fd < 0) { err("%s(%d,%d), failed to create pcap file %s\n", __func__, idx, s_port, @@ -506,25 +528,27 @@ static int ra_start_pcap(struct st_rx_audio_session_impl* s, enum mtl_session_po pcap->dumped_pkts = 0; pcap->dropped_pkts = 0; pcap->required_pkts = max_dump_packets; - info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, s_port, - pcap->file_name, max_dump_packets); + info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, + s_port, pcap->file_name, max_dump_packets); return 0; } -static int ra_dump_pcap(struct st_rx_audio_session_impl* s, struct rte_mbuf** mbufs, - uint16_t nb, enum mtl_session_port s_port) { +static int ra_dump_pcap(struct st_rx_audio_session_impl *s, + struct rte_mbuf **mbufs, uint16_t nb, + enum mtl_session_port s_port) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; uint16_t dump = mt_pcap_dump(s->mgr->parent, port, pcap->pcap, mbufs, nb); pcap->dumped_pkts += dump; pcap->dropped_pkts += nb - dump; return 0; } -static int rx_audio_session_handle_mbuf(void* priv, struct rte_mbuf** mbuf, uint16_t nb) { - struct st_rx_session_priv* s_priv = priv; - struct st_rx_audio_session_impl* s = s_priv->session; - struct mtl_main_impl* impl = s_priv->impl; +static int rx_audio_session_handle_mbuf(void *priv, struct rte_mbuf **mbuf, + uint16_t nb) { + struct st_rx_session_priv *s_priv = priv; + struct st_rx_audio_session_impl *s = s_priv->session; + struct mtl_main_impl *impl = s_priv->impl; enum mtl_session_port s_port = s_priv->s_port; enum st30_type st30_type = s->ops.type; @@ -533,10 +557,12 @@ static int rx_audio_session_handle_mbuf(void* priv, struct rte_mbuf** mbuf, uint return -EIO; } - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->required_pkts) { if (pcap->dumped_pkts < pcap->required_pkts) { - ra_dump_pcap(s, mbuf, RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), s_port); + ra_dump_pcap(s, mbuf, + RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), + s_port); } else { /* got enough packets, stop dumping */ ra_stop_pcap(s, s_port); } @@ -554,17 +580,18 @@ static int rx_audio_session_handle_mbuf(void* priv, struct rte_mbuf** mbuf, uint return 0; } -static int rx_audio_session_tasklet(struct st_rx_audio_session_impl* s) { - struct rte_mbuf* mbuf[ST_RX_AUDIO_BURST_SIZE]; +static int rx_audio_session_tasklet(struct st_rx_audio_session_impl *s) { + struct rte_mbuf *mbuf[ST_RX_AUDIO_BURST_SIZE]; uint16_t rv; int num_port = s->ops.num_port; bool done = true; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rxq[s_port]) continue; + if (!s->rxq[s_port]) + continue; - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; /* if any pcap progress */ if (MT_USDT_ST30_RX_PCAP_DUMP_ENABLED()) { if (!pcap->usdt_dump) { @@ -581,12 +608,14 @@ static int rx_audio_session_tasklet(struct st_rx_audio_session_impl* s) { } rv = mt_rxq_burst(s->rxq[s_port], &mbuf[0], ST_RX_AUDIO_BURST_SIZE); - if (!rv) continue; + if (!rv) + continue; rx_audio_session_handle_mbuf(&s->priv[s_port], &mbuf[0], rv); rte_pktmbuf_free_bulk(&mbuf[0], rv); if (s->enable_timing_parser && s->tp) { - if (rv > 1) s->tp->stat_bursted_cnt[s_port]++; + if (rv > 1) + s->tp->stat_bursted_cnt[s_port]++; } done = false; } @@ -594,18 +623,20 @@ static int rx_audio_session_tasklet(struct st_rx_audio_session_impl* s) { return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int rx_audio_sessions_tasklet_handler(void* priv) { - struct st_rx_audio_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_rx_audio_session_impl* s; +static int rx_audio_sessions_tasklet_handler(void *priv) { + struct st_rx_audio_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_rx_audio_session_impl *s; int pending = MTL_TASKLET_ALL_DONE; uint64_t tsc_s = 0; bool time_measure = mt_sessions_time_measure(impl); for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_audio_session_try_get(mgr, sidx); - if (!s) continue; - if (time_measure) tsc_s = mt_get_tsc(impl); + if (!s) + continue; + if (time_measure) + tsc_s = mt_get_tsc(impl); pending += rx_audio_session_tasklet(s); @@ -619,7 +650,7 @@ static int rx_audio_sessions_tasklet_handler(void* priv) { return pending; } -static int rx_audio_session_uinit_hw(struct st_rx_audio_session_impl* s) { +static int rx_audio_session_uinit_hw(struct st_rx_audio_session_impl *s) { int num_port = s->ops.num_port; for (int i = 0; i < num_port; i++) { @@ -632,8 +663,8 @@ static int rx_audio_session_uinit_hw(struct st_rx_audio_session_impl* s) { return 0; } -static int rx_audio_session_init_hw(struct mtl_main_impl* impl, - struct st_rx_audio_session_impl* s) { +static int rx_audio_session_init_hw(struct mtl_main_impl *impl, + struct st_rx_audio_session_impl *s) { int idx = s->idx, num_port = s->ops.num_port; struct mt_rxq_flow flow; enum mtl_port port; @@ -652,12 +683,13 @@ static int rx_audio_session_init_hw(struct mtl_main_impl* impl, else rte_memcpy(flow.sip_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); flow.dst_port = s->st30_dst_port[i]; - if (mt_has_cni_rx(impl, port)) flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; + if (mt_has_cni_rx(impl, port)) + flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; /* no flow for data path only */ if (s->ops.flags & ST30_RX_FLAG_DATA_PATH_ONLY) { - info("%s(%d), rxq get without flow for port %d as data path only\n", __func__, - s->idx, i); + info("%s(%d), rxq get without flow for port %d as data path only\n", + __func__, s->idx, i); s->rxq[i] = mt_rxq_get(impl, port, NULL); } else { s->rxq[i] = mt_rxq_get(impl, port, &flow); @@ -674,13 +706,14 @@ static int rx_audio_session_init_hw(struct mtl_main_impl* impl, return 0; } -static int rx_audio_session_uinit_mcast(struct mtl_main_impl* impl, - struct st_rx_audio_session_impl* s) { - struct st30_rx_ops* ops = &s->ops; +static int rx_audio_session_uinit_mcast(struct mtl_main_impl *impl, + struct st_rx_audio_session_impl *s) { + struct st30_rx_ops *ops = &s->ops; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!s->mcast_joined[i]) continue; + if (!s->mcast_joined[i]) + continue; port = mt_port_logic2phy(s->port_maps, i); mt_mcast_leave(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); @@ -689,14 +722,15 @@ static int rx_audio_session_uinit_mcast(struct mtl_main_impl* impl, return 0; } -static int rx_audio_session_init_mcast(struct mtl_main_impl* impl, - struct st_rx_audio_session_impl* s) { - struct st30_rx_ops* ops = &s->ops; +static int rx_audio_session_init_mcast(struct mtl_main_impl *impl, + struct st_rx_audio_session_impl *s) { + struct st30_rx_ops *ops = &s->ops; int ret; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!mt_is_multicast_ip(ops->ip_addr[i])) continue; + if (!mt_is_multicast_ip(ops->ip_addr[i])) + continue; port = mt_port_logic2phy(s->port_maps, i); if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { info("%s(%d), skip mcast join for port %d\n", __func__, s->idx, i); @@ -704,44 +738,46 @@ static int rx_audio_session_init_mcast(struct mtl_main_impl* impl, } ret = mt_mcast_join(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->mcast_joined[i] = true; } return 0; } -static int rx_audio_session_uinit_sw(struct st_rx_audio_session_impl* s) { +static int rx_audio_session_uinit_sw(struct st_rx_audio_session_impl *s) { rx_audio_session_free_frames(s); rx_audio_session_free_rtps(s); rx_audio_session_usdt_dump_close(s); return 0; } -static int rx_audio_session_init_sw(struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s) { +static int rx_audio_session_init_sw(struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s) { enum st30_type st30_type = s->ops.type; int idx = s->idx; int ret; switch (st30_type) { - case ST30_TYPE_FRAME_LEVEL: - ret = rx_audio_session_alloc_frames(s); - break; - case ST30_TYPE_RTP_LEVEL: - ret = rx_audio_session_alloc_rtps(mgr, s); - break; - default: - err("%s(%d), error st30_type %d\n", __func__, idx, st30_type); - return -EIO; + case ST30_TYPE_FRAME_LEVEL: + ret = rx_audio_session_alloc_frames(s); + break; + case ST30_TYPE_RTP_LEVEL: + ret = rx_audio_session_alloc_rtps(mgr, s); + break; + default: + err("%s(%d), error st30_type %d\n", __func__, idx, st30_type); + return -EIO; } - if (ret < 0) return ret; + if (ret < 0) + return ret; return 0; } -static int rx_audio_session_uinit(struct mtl_main_impl* impl, - struct st_rx_audio_session_impl* s) { +static int rx_audio_session_uinit(struct mtl_main_impl *impl, + struct st_rx_audio_session_impl *s) { rv_stop_pcap_dump(s); ra_tp_uinit(s); rx_audio_session_uinit_mcast(impl, s); @@ -750,34 +786,40 @@ static int rx_audio_session_uinit(struct mtl_main_impl* impl, return 0; } -static int rx_audio_session_attach(struct mtl_main_impl* impl, - struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s, - struct st30_rx_ops* ops) { +static int rx_audio_session_attach(struct mtl_main_impl *impl, + struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s, + struct st30_rx_ops *ops) { int ret; int idx = s->idx, num_port = ops->num_port; - char* ports[MTL_SESSION_PORT_MAX]; + char *ports[MTL_SESSION_PORT_MAX]; - for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) + ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->mgr = mgr; if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, idx); + snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, + idx); } s->ops = *ops; for (int i = 0; i < num_port; i++) { - s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); + s->st30_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); } ret = st30_get_packet_size(ops->fmt, ops->ptime, ops->sampling, ops->channel); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->pkt_len = ret; - size_t bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); + size_t bytes_in_pkt = + ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); s->st30_pkt_size = s->pkt_len + sizeof(struct st_rfc3550_audio_hdr); if (s->pkt_len > bytes_in_pkt) { err("%s(%d), invalid pkt_len %d\n", __func__, idx, s->pkt_len); @@ -788,8 +830,8 @@ static int rx_audio_session_attach(struct mtl_main_impl* impl, s->st30_total_pkts = ops->framebuff_size / s->pkt_len; if (ops->framebuff_size % s->pkt_len) { /* todo: add the support? */ - err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, s->pkt_len, - ops->framebuff_size); + err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, + s->pkt_len, ops->framebuff_size); return -EIO; } s->st30_pkt_idx = 0; @@ -810,7 +852,8 @@ static int rx_audio_session_attach(struct mtl_main_impl* impl, } if (ops->flags & ST30_RX_FLAG_TIMING_PARSER_META) { if (!ops->notify_timing_parser_result) { - err("%s(%d), notify_timing_parser_result callback is NULL\n", __func__, idx); + err("%s(%d), notify_timing_parser_result callback is NULL\n", __func__, + idx); return -EIO; } info("%s(%d), enable the timing analyze meta\n", __func__, idx); @@ -851,15 +894,16 @@ static int rx_audio_session_attach(struct mtl_main_impl* impl, s->frames_per_sec = (double)NS_PER_S / st30_get_packet_time(ops->ptime) / s->st30_total_pkts; s->attached = true; - info("%s(%d), fmt %d channel %u sampling %d ptime %d payload_type %u\n", __func__, idx, - ops->fmt, ops->channel, ops->sampling, ops->ptime, ops->payload_type); - info("%s(%d), pkt_len %u frame_size %" PRId64 ", expect fps %d\n", __func__, idx, - s->pkt_len, s->st30_frame_size, s->frames_per_sec); + info("%s(%d), fmt %d channel %u sampling %d ptime %d payload_type %u\n", + __func__, idx, ops->fmt, ops->channel, ops->sampling, ops->ptime, + ops->payload_type); + info("%s(%d), pkt_len %u frame_size %" PRId64 ", expect fps %d\n", __func__, + idx, s->pkt_len, s->st30_frame_size, s->frames_per_sec); return 0; } -static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s) { +static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s) { int idx = s->idx; int m_idx = mgr->idx; uint64_t cur_time_ns = mt_get_monotonic_time(); @@ -890,18 +934,18 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr* mgr, s->st30_stat_pkts_dropped = 0; } if (s->st30_stat_pkts_wrong_pt_dropped) { - notice("RX_AUDIO_SESSION(%d,%d): wrong hdr payload_type dropped pkts %d\n", m_idx, - idx, s->st30_stat_pkts_wrong_pt_dropped); + notice("RX_AUDIO_SESSION(%d,%d): wrong hdr payload_type dropped pkts %d\n", + m_idx, idx, s->st30_stat_pkts_wrong_pt_dropped); s->st30_stat_pkts_wrong_pt_dropped = 0; } if (s->st30_stat_pkts_wrong_ssrc_dropped) { - notice("RX_AUDIO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, idx, - s->st30_stat_pkts_wrong_ssrc_dropped); + notice("RX_AUDIO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, + idx, s->st30_stat_pkts_wrong_ssrc_dropped); s->st30_stat_pkts_wrong_ssrc_dropped = 0; } if (s->st30_stat_pkts_len_mismatch_dropped) { - notice("RX_AUDIO_SESSION(%d,%d): pkt len mismatch dropped pkts %d\n", m_idx, idx, - s->st30_stat_pkts_len_mismatch_dropped); + notice("RX_AUDIO_SESSION(%d,%d): pkt len mismatch dropped pkts %d\n", m_idx, + idx, s->st30_stat_pkts_len_mismatch_dropped); s->st30_stat_pkts_len_mismatch_dropped = 0; } if (s->stat_slot_get_frame_fail) { @@ -910,11 +954,13 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr* mgr, s->stat_slot_get_frame_fail = 0; } - struct mt_stat_u64* stat_time = &s->stat_time; + struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("RX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + notice("RX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, + (float)stat_time->max / NS_PER_US, (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } @@ -924,31 +970,33 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr* mgr, } s->stat_max_notify_frame_us = 0; - if (s->enable_timing_parser_stat) ra_tp_stat(s); + if (s->enable_timing_parser_stat) + ra_tp_stat(s); for (int s_port = 0; s_port < s->ops.num_port; s_port++) { - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->pcap) { - MT_USDT_ST30_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, pcap->dumped_pkts); + MT_USDT_ST30_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, + pcap->dumped_pkts); } } } -static int rx_audio_session_detach(struct mtl_main_impl* impl, - struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s) { +static int rx_audio_session_detach(struct mtl_main_impl *impl, + struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s) { s->attached = false; rx_audio_session_stat(mgr, s); rx_audio_session_uinit(impl, s); return 0; } -static int rx_audio_session_update_src(struct mtl_main_impl* impl, - struct st_rx_audio_session_impl* s, - struct st_rx_source_info* src) { +static int rx_audio_session_update_src(struct mtl_main_impl *impl, + struct st_rx_audio_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; - struct st30_rx_ops* ops = &s->ops; + struct st30_rx_ops *ops = &s->ops; rx_audio_session_uinit_mcast(impl, s); rx_audio_session_uinit_hw(s); @@ -958,7 +1006,8 @@ static int rx_audio_session_update_src(struct mtl_main_impl* impl, memcpy(ops->ip_addr[i], src->ip_addr[i], MTL_IP_ADDR_LEN); memcpy(ops->mcast_sip_addr[i], src->mcast_sip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = src->udp_port[i]; - s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); + s->st30_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); } /* reset seq id */ s->latest_seq_id = -1; @@ -978,9 +1027,10 @@ static int rx_audio_session_update_src(struct mtl_main_impl* impl, return 0; } -static int rx_audio_sessions_mgr_update_src(struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s, - struct st_rx_source_info* src) { +static int +rx_audio_sessions_mgr_update_src(struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = rx_audio_session_get(mgr, idx); /* get the lock */ @@ -999,13 +1049,14 @@ static int rx_audio_sessions_mgr_update_src(struct st_rx_audio_sessions_mgr* mgr return 0; } -static int st_rx_audio_sessions_stat(void* priv) { - struct st_rx_audio_sessions_mgr* mgr = priv; - struct st_rx_audio_session_impl* s; +static int st_rx_audio_sessions_stat(void *priv) { + struct st_rx_audio_sessions_mgr *mgr = priv; + struct st_rx_audio_session_impl *s; for (int j = 0; j < mgr->max_idx; j++) { s = rx_audio_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) continue; + if (!s) + continue; rx_audio_session_stat(mgr, s); rx_audio_session_put(mgr, j); } @@ -1013,9 +1064,9 @@ static int st_rx_audio_sessions_stat(void* priv) { return 0; } -static int rx_audio_sessions_mgr_init(struct mtl_main_impl* impl, - struct mtl_sch_impl* sch, - struct st_rx_audio_sessions_mgr* mgr) { +static int rx_audio_sessions_mgr_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_rx_audio_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; @@ -1044,24 +1095,26 @@ static int rx_audio_sessions_mgr_init(struct mtl_main_impl* impl, return 0; } -static int rx_audio_session_init(struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s, int idx) { +static int rx_audio_session_init(struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s, int idx) { MTL_MAY_UNUSED(mgr); s->idx = idx; return 0; } -static struct st_rx_audio_session_impl* rx_audio_sessions_mgr_attach( - struct mtl_sch_impl* sch, struct st30_rx_ops* ops) { - struct st_rx_audio_sessions_mgr* mgr = &sch->rx_a_mgr; +static struct st_rx_audio_session_impl * +rx_audio_sessions_mgr_attach(struct mtl_sch_impl *sch, + struct st30_rx_ops *ops) { + struct st_rx_audio_sessions_mgr *mgr = &sch->rx_a_mgr; int midx = mgr->idx; int ret; - struct st_rx_audio_session_impl* s; + struct st_rx_audio_session_impl *s; int socket = mt_sch_socket_id(sch); /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_RX_AUDIO_SESSIONS; i++) { - if (!rx_audio_session_get_empty(mgr, i)) continue; + if (!rx_audio_session_get_empty(mgr, i)) + continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -1095,8 +1148,8 @@ static struct st_rx_audio_session_impl* rx_audio_sessions_mgr_attach( return NULL; } -static int rx_audio_sessions_mgr_detach(struct st_rx_audio_sessions_mgr* mgr, - struct st_rx_audio_session_impl* s) { +static int rx_audio_sessions_mgr_detach(struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -1115,20 +1168,21 @@ static int rx_audio_sessions_mgr_detach(struct st_rx_audio_sessions_mgr* mgr, return 0; } -static int rx_audio_sessions_mgr_update(struct st_rx_audio_sessions_mgr* mgr) { +static int rx_audio_sessions_mgr_update(struct st_rx_audio_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_SCH_MAX_RX_AUDIO_SESSIONS; i++) { - if (mgr->sessions[i]) max_idx = i + 1; + if (mgr->sessions[i]) + max_idx = i + 1; } mgr->max_idx = max_idx; return 0; } -static int rx_audio_sessions_mgr_uinit(struct st_rx_audio_sessions_mgr* mgr) { +static int rx_audio_sessions_mgr_uinit(struct st_rx_audio_sessions_mgr *mgr) { int m_idx = mgr->idx; - struct st_rx_audio_session_impl* s; + struct st_rx_audio_session_impl *s; mt_stat_unregister(mgr->parent, st_rx_audio_sessions_stat, mgr); @@ -1139,7 +1193,8 @@ static int rx_audio_sessions_mgr_uinit(struct st_rx_audio_sessions_mgr* mgr) { for (int i = 0; i < ST_SCH_MAX_RX_AUDIO_SESSIONS; i++) { s = rx_audio_session_get(mgr, i); - if (!s) continue; + if (!s) + continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); rx_audio_sessions_mgr_detach(mgr, s); @@ -1150,9 +1205,9 @@ static int rx_audio_sessions_mgr_uinit(struct st_rx_audio_sessions_mgr* mgr) { return 0; } -static int rx_audio_ops_check(struct st30_rx_ops* ops) { +static int rx_audio_ops_check(struct st30_rx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip = NULL; + uint8_t *ip = NULL; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { err("%s, invalid num_ports %d\n", __func__, num_ports); @@ -1163,14 +1218,16 @@ static int rx_audio_ops_check(struct st30_rx_ops* ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -1208,10 +1265,12 @@ static int rx_audio_ops_check(struct st30_rx_ops* ops) { return 0; } -static int st_rx_audio_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { +static int st_rx_audio_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { int ret; - if (sch->rx_a_init) return 0; + if (sch->rx_a_init) + return 0; /* create rx audio context */ ret = rx_audio_sessions_mgr_init(impl, sch, &sch->rx_a_mgr); @@ -1224,8 +1283,9 @@ static int st_rx_audio_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch return 0; } -int st_rx_audio_sessions_sch_uinit(struct mtl_sch_impl* sch) { - if (!sch->rx_a_init) return 0; +int st_rx_audio_sessions_sch_uinit(struct mtl_sch_impl *sch) { + if (!sch->rx_a_init) + return 0; rx_audio_sessions_mgr_uinit(&sch->rx_a_mgr); @@ -1233,11 +1293,11 @@ int st_rx_audio_sessions_sch_uinit(struct mtl_sch_impl* sch) { return 0; } -st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct mtl_sch_impl* sch; - struct st_rx_audio_session_handle_impl* s_impl; - struct st_rx_audio_session_impl* s; +st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct mtl_sch_impl *sch; + struct st_rx_audio_session_handle_impl *s_impl; + struct st_rx_audio_session_impl *s; int quota_mbs, ret; notice("%s, start for %s\n", __func__, mt_string_safe(ops->name)); @@ -1254,7 +1314,8 @@ st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops* ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30_RX_FLAG_FORCE_NUMA) { @@ -1268,9 +1329,10 @@ st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops* ops) { return NULL; } - quota_mbs = impl->main_sch->data_quota_mbs_limit / impl->rx_audio_sessions_max_per_sch; - sch = - mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); + quota_mbs = impl->main_sch->data_quota_mbs_limit / + impl->rx_audio_sessions_max_per_sch; + sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, + MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -1309,10 +1371,11 @@ st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops* ops) { return s_impl; } -int st30_rx_update_source(st30_rx_handle handle, struct st_rx_source_info* src) { - struct st_rx_audio_session_handle_impl* s_impl = handle; - struct st_rx_audio_session_impl* s; - struct mtl_sch_impl* sch; +int st30_rx_update_source(st30_rx_handle handle, + struct st_rx_source_info *src) { + struct st_rx_audio_session_handle_impl *s_impl = handle; + struct st_rx_audio_session_impl *s; + struct mtl_sch_impl *sch; int idx, ret, sch_idx; if (s_impl->type != MT_HANDLE_RX_AUDIO) { @@ -1326,7 +1389,8 @@ int st30_rx_update_source(st30_rx_handle handle, struct st_rx_source_info* src) sch_idx = sch->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = rx_audio_sessions_mgr_update_src(&sch->rx_a_mgr, s, src); if (ret < 0) { @@ -1339,10 +1403,10 @@ int st30_rx_update_source(st30_rx_handle handle, struct st_rx_source_info* src) } int st30_rx_free(st30_rx_handle handle) { - struct st_rx_audio_session_handle_impl* s_impl = handle; - struct mtl_main_impl* impl; - struct mtl_sch_impl* sch; - struct st_rx_audio_session_impl* s; + struct st_rx_audio_session_handle_impl *s_impl = handle; + struct mtl_main_impl *impl; + struct mtl_sch_impl *sch; + struct st_rx_audio_session_impl *s; int ret, idx; int sch_idx; @@ -1361,10 +1425,12 @@ int st30_rx_free(st30_rx_handle handle) { mt_pthread_mutex_lock(&sch->rx_a_mgr_mutex); ret = rx_audio_sessions_mgr_detach(&sch->rx_a_mgr, s); mt_pthread_mutex_unlock(&sch->rx_a_mgr_mutex); - if (ret < 0) err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -1378,10 +1444,10 @@ int st30_rx_free(st30_rx_handle handle) { return 0; } -int st30_rx_put_framebuff(st30_rx_handle handle, void* frame) { - struct st_rx_audio_session_handle_impl* s_impl = handle; - struct st_rx_audio_session_impl* s; - struct st_frame_trans* st30_frame; +int st30_rx_put_framebuff(st30_rx_handle handle, void *frame) { + struct st_rx_audio_session_handle_impl *s_impl = handle; + struct st_rx_audio_session_impl *s; + struct st_frame_trans *st30_frame; if (s_impl->type != MT_HANDLE_RX_AUDIO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -1402,11 +1468,11 @@ int st30_rx_put_framebuff(st30_rx_handle handle, void* frame) { return -EIO; } -void* st30_rx_get_mbuf(st30_rx_handle handle, void** usrptr, uint16_t* len) { - struct st_rx_audio_session_handle_impl* s_impl = handle; - struct st_rx_audio_session_impl* s; - struct rte_mbuf* pkt; - struct rte_ring* rtps_ring; +void *st30_rx_get_mbuf(st30_rx_handle handle, void **usrptr, uint16_t *len) { + struct st_rx_audio_session_handle_impl *s_impl = handle; + struct st_rx_audio_session_impl *s; + struct rte_mbuf *pkt; + struct rte_ring *rtps_ring; int idx, ret; if (s_impl->type != MT_HANDLE_RX_AUDIO) { @@ -1422,7 +1488,7 @@ void* st30_rx_get_mbuf(st30_rx_handle handle, void** usrptr, uint16_t* len) { return NULL; } - ret = rte_ring_sc_dequeue(rtps_ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(rtps_ring, (void **)&pkt); if (ret < 0) { dbg("%s(%d), rtp ring is empty\n", __func__, idx); return NULL; @@ -1431,23 +1497,24 @@ void* st30_rx_get_mbuf(st30_rx_handle handle, void** usrptr, uint16_t* len) { size_t hdr_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr); *len = pkt->data_len - hdr_len; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, hdr_len); + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, hdr_len); return pkt; } -void st30_rx_put_mbuf(st30_rx_handle handle, void* mbuf) { - struct st_rx_audio_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; +void st30_rx_put_mbuf(st30_rx_handle handle, void *mbuf) { + struct st_rx_audio_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; if (s_impl->type != MT_HANDLE_RX_AUDIO) err("%s, invalid type %d\n", __func__, s_impl->type); - if (pkt) rte_pktmbuf_free(pkt); + if (pkt) + rte_pktmbuf_free(pkt); } -int st30_rx_get_queue_meta(st30_rx_handle handle, struct st_queue_meta* meta) { - struct st_rx_audio_session_handle_impl* s_impl = handle; - struct st_rx_audio_session_impl* s; +int st30_rx_get_queue_meta(st30_rx_handle handle, struct st_queue_meta *meta) { + struct st_rx_audio_session_handle_impl *s_impl = handle; + struct st_rx_audio_session_impl *s; if (s_impl->type != MT_HANDLE_RX_AUDIO) { err("%s, invalid type %d\n", __func__, s_impl->type); diff --git a/lib/src/st2110/st_rx_audio_session.h b/lib/src/st2110/st_rx_audio_session.h index 3ef0312c2..a2c17d6b5 100644 --- a/lib/src/st2110/st_rx_audio_session.h +++ b/lib/src/st2110/st_rx_audio_session.h @@ -11,6 +11,6 @@ #define ST_RX_AUDIO_PREFIX "RA_" -int st_rx_audio_sessions_sch_uinit(struct mtl_sch_impl* sch); +int st_rx_audio_sessions_sch_uinit(struct mtl_sch_impl *sch); #endif \ No newline at end of file diff --git a/lib/src/st2110/st_rx_timing_parser.c b/lib/src/st2110/st_rx_timing_parser.c index 52011e786..48b337618 100644 --- a/lib/src/st2110/st_rx_timing_parser.c +++ b/lib/src/st2110/st_rx_timing_parser.c @@ -10,10 +10,10 @@ static inline float rv_tp_calculate_avg(uint32_t cnt, int64_t sum) { return cnt ? ((float)sum / cnt) : -1.0f; } -void rv_tp_on_packet(struct st_rx_video_session_impl* s, enum mtl_session_port s_port, - struct st_rv_tp_slot* slot, uint32_t rtp_tmstamp, uint64_t pkt_time, - int pkt_idx) { - struct st_rx_video_tp* tp = s->tp; +void rv_tp_on_packet(struct st_rx_video_session_impl *s, + enum mtl_session_port s_port, struct st_rv_tp_slot *slot, + uint32_t rtp_tmstamp, uint64_t pkt_time, int pkt_idx) { + struct st_rx_video_tp *tp = s->tp; uint64_t epoch_tmstamp; double tvd, trs = tp->trs; @@ -30,7 +30,8 @@ void rv_tp_on_packet(struct st_rx_video_session_impl* s, enum mtl_session_port s uint64_t tmstamp64 = epochs * s->frame_time_sampling; uint32_t tmstamp32 = tmstamp64; double diff_rtp_ts = (double)rtp_tmstamp - tmstamp32; - double diff_rtp_ts_ns = diff_rtp_ts * s->frame_time / s->frame_time_sampling; + double diff_rtp_ts_ns = + diff_rtp_ts * s->frame_time / s->frame_time_sampling; slot->meta.latency = slot->meta.fpt - diff_rtp_ts_ns; slot->meta.rtp_offset = diff_rtp_ts; if (tp->pre_rtp_tmstamp[s_port]) { @@ -50,7 +51,8 @@ void rv_tp_on_packet(struct st_rx_video_session_impl* s, enum mtl_session_port s slot->meta.vrx_max = RTE_MAX(vrx_cur, slot->meta.vrx_max); /* Calculate C-inst */ - int exp_cin_pkts = ((pkt_time - slot->first_pkt_time) / trs) * ST_TP_CINST_DRAIN_FACTOR; + int exp_cin_pkts = + ((pkt_time - slot->first_pkt_time) / trs) * ST_TP_CINST_DRAIN_FACTOR; int cinst = RTE_MAX(0, pkt_idx - exp_cin_pkts); slot->cinst_sum += cinst; slot->meta.cinst_min = RTE_MIN(cinst, slot->meta.cinst_min); @@ -69,12 +71,13 @@ void rv_tp_on_packet(struct st_rx_video_session_impl* s, enum mtl_session_port s slot->meta.pkts_cnt++; } -static void rv_tp_compliant_set_cause(struct st20_rx_tp_meta* meta, char* cause) { +static void rv_tp_compliant_set_cause(struct st20_rx_tp_meta *meta, + char *cause) { snprintf(meta->failed_cause, sizeof(meta->failed_cause), "%s", cause); } -static enum st_rx_tp_compliant rv_tp_compliant(struct st_rx_video_tp* tp, - struct st_rv_tp_slot* slot) { +static enum st_rx_tp_compliant rv_tp_compliant(struct st_rx_video_tp *tp, + struct st_rv_tp_slot *slot) { /* fpt check */ if (slot->meta.fpt > tp->pass.tr_offset) { rv_tp_compliant_set_cause(&slot->meta, "fpt exceed tr_offset"); @@ -137,9 +140,10 @@ static enum st_rx_tp_compliant rv_tp_compliant(struct st_rx_video_tp* tp, return ST_RX_TP_COMPLIANT_NARROW; } -void rv_tp_slot_parse_result(struct st_rx_video_session_impl* s, - enum mtl_session_port s_port, struct st_rv_tp_slot* slot) { - struct st_rx_video_tp* tp = s->tp; +void rv_tp_slot_parse_result(struct st_rx_video_session_impl *s, + enum mtl_session_port s_port, + struct st_rv_tp_slot *slot) { + struct st_rx_video_tp *tp = s->tp; float cinst_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->cinst_sum); float vrx_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->vrx_sum); float ipt_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->ipt_sum); @@ -147,34 +151,42 @@ void rv_tp_slot_parse_result(struct st_rx_video_session_impl* s, slot->meta.cinst_avg = cinst_avg; slot->meta.vrx_avg = vrx_avg; slot->meta.ipt_avg = ipt_avg; - dbg("%s(%d), Cinst AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, cinst_avg, - slot->cinst_min, slot->cinst_max, rv_tp_cinst_result(tp, slot)); - dbg("%s(%d), VRX AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, vrx_avg, - slot->vrx_min, slot->vrx_max, rv_tp_vrx_result(tp, slot)); - dbg("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, s->idx, - ipt_avg, slot->ipt_min, slot->ipt_max); + dbg("%s(%d), Cinst AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, + cinst_avg, slot->cinst_min, slot->cinst_max, + rv_tp_cinst_result(tp, slot)); + dbg("%s(%d), VRX AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, + vrx_avg, slot->vrx_min, slot->vrx_max, rv_tp_vrx_result(tp, slot)); + dbg("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, + s->idx, ipt_avg, slot->ipt_min, slot->ipt_max); /* parse tp compliant for current frame */ enum st_rx_tp_compliant compliant = rv_tp_compliant(tp, slot); slot->meta.compliant = compliant; - if (!s->enable_timing_parser_stat) return; + if (!s->enable_timing_parser_stat) + return; /* update stat */ - struct st_rv_tp_stat* stat = &tp->stat[s_port]; - struct st_rv_tp_slot* stat_slot = &stat->slot; + struct st_rv_tp_stat *stat = &tp->stat[s_port]; + struct st_rv_tp_slot *stat_slot = &stat->slot; stat->stat_compliant_result[compliant]++; stat_slot->vrx_sum += slot->vrx_sum; - stat_slot->meta.vrx_min = RTE_MIN(stat_slot->meta.vrx_min, slot->meta.vrx_min); - stat_slot->meta.vrx_max = RTE_MAX(stat_slot->meta.vrx_min, slot->meta.vrx_max); + stat_slot->meta.vrx_min = + RTE_MIN(stat_slot->meta.vrx_min, slot->meta.vrx_min); + stat_slot->meta.vrx_max = + RTE_MAX(stat_slot->meta.vrx_min, slot->meta.vrx_max); stat_slot->cinst_sum += slot->cinst_sum; - stat_slot->meta.cinst_min = RTE_MIN(stat_slot->meta.cinst_min, slot->meta.cinst_min); - stat_slot->meta.cinst_max = RTE_MAX(stat_slot->meta.cinst_max, slot->meta.cinst_max); + stat_slot->meta.cinst_min = + RTE_MIN(stat_slot->meta.cinst_min, slot->meta.cinst_min); + stat_slot->meta.cinst_max = + RTE_MAX(stat_slot->meta.cinst_max, slot->meta.cinst_max); stat_slot->ipt_sum += slot->ipt_sum; - stat_slot->meta.ipt_min = RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); - stat_slot->meta.ipt_max = RTE_MAX(stat_slot->meta.ipt_min, slot->meta.ipt_max); + stat_slot->meta.ipt_min = + RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); + stat_slot->meta.ipt_max = + RTE_MAX(stat_slot->meta.ipt_min, slot->meta.ipt_max); stat_slot->meta.pkts_cnt += slot->meta.pkts_cnt; stat->stat_fpt_min = RTE_MIN(stat->stat_fpt_min, slot->meta.fpt); @@ -183,8 +195,10 @@ void rv_tp_slot_parse_result(struct st_rx_video_session_impl* s, stat->stat_latency_min = RTE_MIN(stat->stat_latency_min, slot->meta.latency); stat->stat_latency_max = RTE_MAX(stat->stat_latency_max, slot->meta.latency); stat->stat_latency_sum += slot->meta.latency; - stat->stat_rtp_offset_min = RTE_MIN(stat->stat_rtp_offset_min, slot->meta.rtp_offset); - stat->stat_rtp_offset_max = RTE_MAX(stat->stat_rtp_offset_max, slot->meta.rtp_offset); + stat->stat_rtp_offset_min = + RTE_MIN(stat->stat_rtp_offset_min, slot->meta.rtp_offset); + stat->stat_rtp_offset_max = + RTE_MAX(stat->stat_rtp_offset_max, slot->meta.rtp_offset); stat->stat_rtp_offset_sum += slot->meta.rtp_offset; if (slot->meta.rtp_ts_delta) { stat->stat_rtp_ts_delta_min = @@ -196,11 +210,11 @@ void rv_tp_slot_parse_result(struct st_rx_video_session_impl* s, stat->stat_frame_cnt++; } -static void rv_tp_stat_init(struct st_rx_video_session_impl* s, - struct st_rx_video_tp* tp) { +static void rv_tp_stat_init(struct st_rx_video_session_impl *s, + struct st_rx_video_tp *tp) { MTL_MAY_UNUSED(s); for (int s_port = 0; s_port < MTL_SESSION_PORT_MAX; s_port++) { - struct st_rv_tp_stat* stat = &tp->stat[s_port]; + struct st_rv_tp_stat *stat = &tp->stat[s_port]; memset(stat, 0, sizeof(*stat)); rv_tp_slot_init(&stat->slot); @@ -215,48 +229,56 @@ static void rv_tp_stat_init(struct st_rx_video_session_impl* s, } } -void rv_tp_stat(struct st_rx_video_session_impl* s) { +void rv_tp_stat(struct st_rx_video_session_impl *s) { int idx = s->idx; - struct st_rx_video_tp* tp = s->tp; - if (!tp) return; + struct st_rx_video_tp *tp = s->tp; + if (!tp) + return; for (int s_port = 0; s_port < s->ops.num_port; s_port++) { - struct st_rv_tp_stat* stat = &tp->stat[s_port]; - struct st_rv_tp_slot* stat_slot = &stat->slot; + struct st_rv_tp_stat *stat = &tp->stat[s_port]; + struct st_rv_tp_slot *stat_slot = &stat->slot; - info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, s_port, - stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], + info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, + s_port, stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_WIDE], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED]); - float cinst_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->cinst_sum); - float vrx_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->vrx_sum); - float ipt_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); + float cinst_avg = + rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->cinst_sum); + float vrx_avg = + rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->vrx_sum); + float ipt_avg = + rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); info("%s(%d), Cinst AVG %.2f MIN %d MAX %d!\n", __func__, idx, cinst_avg, stat_slot->meta.cinst_min, stat_slot->meta.cinst_max); info("%s(%d), VRX AVG %.2f MIN %d MAX %d!\n", __func__, idx, vrx_avg, stat_slot->meta.vrx_min, stat_slot->meta.vrx_max); - info("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, idx, - ipt_avg, stat_slot->meta.ipt_min, stat_slot->meta.ipt_max); - float fpt_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_fpt_sum); - info("%s(%d), FPT AVG %.2f MIN %d MAX %d DIFF %d!\n", __func__, idx, fpt_avg, - stat->stat_fpt_min, stat->stat_fpt_max, stat->stat_fpt_max - stat->stat_fpt_min); - float latency_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_latency_sum); - info("%s(%d), LATENCY AVG %.2f MIN %d MAX %d!\n", __func__, idx, latency_avg, - stat->stat_latency_min, stat->stat_latency_max); + info("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, + idx, ipt_avg, stat_slot->meta.ipt_min, stat_slot->meta.ipt_max); + float fpt_avg = + rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_fpt_sum); + info("%s(%d), FPT AVG %.2f MIN %d MAX %d DIFF %d!\n", __func__, idx, + fpt_avg, stat->stat_fpt_min, stat->stat_fpt_max, + stat->stat_fpt_max - stat->stat_fpt_min); + float latency_avg = + rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_latency_sum); + info("%s(%d), LATENCY AVG %.2f MIN %d MAX %d!\n", __func__, idx, + latency_avg, stat->stat_latency_min, stat->stat_latency_max); float rtp_offset_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_rtp_offset_sum); - info("%s(%d), RTP OFFSET AVG %.2f MIN %d MAX %d!\n", __func__, idx, rtp_offset_avg, - stat->stat_rtp_offset_min, stat->stat_rtp_offset_max); + info("%s(%d), RTP OFFSET AVG %.2f MIN %d MAX %d!\n", __func__, idx, + rtp_offset_avg, stat->stat_rtp_offset_min, stat->stat_rtp_offset_max); float rtp_ts_delta_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_rtp_ts_delta_sum); info("%s(%d), RTP TS DELTA AVG %.2f MIN %d MAX %d!\n", __func__, idx, - rtp_ts_delta_avg, stat->stat_rtp_ts_delta_min, stat->stat_rtp_ts_delta_max); + rtp_ts_delta_avg, stat->stat_rtp_ts_delta_min, + stat->stat_rtp_ts_delta_max); } rv_tp_stat_init(s, tp); } -void rv_tp_slot_init(struct st_rv_tp_slot* slot) { +void rv_tp_slot_init(struct st_rv_tp_slot *slot) { memset(slot, 0, sizeof(*slot)); slot->meta.cinst_max = INT_MIN; @@ -267,7 +289,7 @@ void rv_tp_slot_init(struct st_rv_tp_slot* slot) { slot->meta.ipt_min = INT_MAX; } -int rv_tp_uinit(struct st_rx_video_session_impl* s) { +int rv_tp_uinit(struct st_rx_video_session_impl *s) { if (s->tp) { mt_rte_free(s->tp); s->tp = NULL; @@ -276,12 +298,12 @@ int rv_tp_uinit(struct st_rx_video_session_impl* s) { return 0; } -int rv_tp_init(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { +int rv_tp_init(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { enum mtl_port port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); int soc_id = mt_socket_id(impl, port); int idx = s->idx, ret; - struct st_rx_video_tp* tp; - struct st20_rx_ops* ops = &s->ops; + struct st_rx_video_tp *tp; + struct st20_rx_ops *ops = &s->ops; double frame_time = s->frame_time; double frame_time_s; struct st_fps_timing fps_tm; @@ -313,8 +335,8 @@ int rv_tp_init(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { } tp->trs = frame_time * reactive / st20_total_pkts; if (!ops->interlaced) { - tp->pass.tr_offset = - ops->height >= 1080 ? frame_time * (43.0 / 1125.0) : frame_time * (28.0 / 750.0); + tp->pass.tr_offset = ops->height >= 1080 ? frame_time * (43.0 / 1125.0) + : frame_time * (28.0 / 750.0); } else { if (ops->height == 480) { tp->pass.tr_offset = frame_time * (20.0 / 525.0) * 2; @@ -327,15 +349,18 @@ int rv_tp_init(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { tp->pass.cinst_max_narrow = RTE_MAX(4, (double)st20_total_pkts / (43200 * reactive * frame_time_s)); - tp->pass.cinst_max_wide = RTE_MAX(16, (double)st20_total_pkts / (21600 * frame_time_s)); + tp->pass.cinst_max_wide = + RTE_MAX(16, (double)st20_total_pkts / (21600 * frame_time_s)); tp->pass.cinst_min = 0; - tp->pass.vrx_max_narrow = RTE_MAX(8, st20_total_pkts / (27000 * frame_time_s)); + tp->pass.vrx_max_narrow = + RTE_MAX(8, st20_total_pkts / (27000 * frame_time_s)); tp->pass.vrx_max_wide = RTE_MAX(720, st20_total_pkts / (300 * frame_time_s)); tp->pass.vrx_min = 0; tp->pass.latency_max = 1000 * 1000; /* 1000 us */ tp->pass.latency_min = 0; tp->pass.rtp_offset_max = - ceil((double)tp->pass.tr_offset * fps_tm.sampling_clock_rate / NS_PER_S) + 1; + ceil((double)tp->pass.tr_offset * fps_tm.sampling_clock_rate / NS_PER_S) + + 1; tp->pass.rtp_offset_min = -1; int32_t sampling = s->frame_time_sampling; tp->pass.rtp_ts_delta_max = sampling + 1; @@ -345,17 +370,17 @@ int rv_tp_init(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { info("%s[%02d], trs %f tr offset %d sampling %f\n", __func__, idx, tp->trs, tp->pass.tr_offset, s->frame_time_sampling); - info( - "%s[%02d], cinst_max_narrow %d cinst_max_wide %d vrx_max_narrow %d vrx_max_wide %d " - "rtp_offset_max %d\n", - __func__, idx, tp->pass.cinst_max_narrow, tp->pass.cinst_max_wide, - tp->pass.vrx_max_narrow, tp->pass.vrx_max_wide, tp->pass.rtp_offset_max); + info("%s[%02d], cinst_max_narrow %d cinst_max_wide %d vrx_max_narrow %d " + "vrx_max_wide %d " + "rtp_offset_max %d\n", + __func__, idx, tp->pass.cinst_max_narrow, tp->pass.cinst_max_wide, + tp->pass.vrx_max_narrow, tp->pass.vrx_max_wide, tp->pass.rtp_offset_max); return 0; } -static void ra_tp_stat_init(struct st_rx_audio_tp* tp) { +static void ra_tp_stat_init(struct st_rx_audio_tp *tp) { for (int s_port = 0; s_port < MTL_SESSION_PORT_MAX; s_port++) { - struct st_ra_tp_stat* stat = &tp->stat[s_port]; + struct st_ra_tp_stat *stat = &tp->stat[s_port]; memset(stat, 0, sizeof(*stat)); ra_tp_slot_init(&stat->slot); @@ -364,12 +389,13 @@ static void ra_tp_stat_init(struct st_rx_audio_tp* tp) { } } -static void ra_tp_compliant_set_cause(struct st30_rx_tp_meta* meta, char* cause) { +static void ra_tp_compliant_set_cause(struct st30_rx_tp_meta *meta, + char *cause) { snprintf(meta->failed_cause, sizeof(meta->failed_cause), "%s", cause); } -static enum st_rx_tp_compliant ra_tp_slot_compliant(struct st_rx_audio_tp* tp, - struct st_ra_tp_slot* slot, +static enum st_rx_tp_compliant ra_tp_slot_compliant(struct st_rx_audio_tp *tp, + struct st_ra_tp_slot *slot, int32_t tsdf) { /* dpvr and tsdf check */ if (slot->meta.dpvr_min < 0) { @@ -400,18 +426,19 @@ static enum st_rx_tp_compliant ra_tp_slot_compliant(struct st_rx_audio_tp* tp, return ST_RX_TP_COMPLIANT_NARROW; } -void ra_tp_slot_parse_result(struct st_rx_audio_session_impl* s, +void ra_tp_slot_parse_result(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port) { - struct st_rx_audio_tp* tp = s->tp; - struct st_ra_tp_slot* slot = &s->tp->slot[s_port]; + struct st_rx_audio_tp *tp = s->tp; + struct st_ra_tp_slot *slot = &s->tp->slot[s_port]; dbg("%s(%d,%d), start\n", __func__, s->idx, s_port); slot->meta.ipt_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->ipt_sum); - slot->meta.dpvr_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->dpvr_sum); + slot->meta.dpvr_avg = + rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->dpvr_sum); /* calculate tsdf */ - int32_t tsdf = - (slot->meta.dpvr_max - slot->dpvr_first) - (slot->meta.dpvr_min - slot->dpvr_first); + int32_t tsdf = (slot->meta.dpvr_max - slot->dpvr_first) - + (slot->meta.dpvr_min - slot->dpvr_first); slot->meta.tsdf = tsdf; /* parse tp compliant for current frame */ @@ -419,8 +446,8 @@ void ra_tp_slot_parse_result(struct st_rx_audio_session_impl* s, slot->meta.compliant = compliant; /* update stat */ - struct st_ra_tp_stat* stat = &tp->stat[s_port]; - struct st_ra_tp_slot* stat_slot = &stat->slot; + struct st_ra_tp_stat *stat = &tp->stat[s_port]; + struct st_ra_tp_slot *stat_slot = &stat->slot; stat->stat_compliant_result[compliant]++; stat->tsdf_min = RTE_MIN(stat->tsdf_min, tsdf); @@ -429,22 +456,28 @@ void ra_tp_slot_parse_result(struct st_rx_audio_session_impl* s, stat->tsdf_cnt++; stat_slot->dpvr_sum += slot->dpvr_sum; - stat_slot->meta.dpvr_min = RTE_MIN(stat_slot->meta.dpvr_min, slot->meta.dpvr_min); - stat_slot->meta.dpvr_max = RTE_MAX(stat_slot->meta.dpvr_max, slot->meta.dpvr_max); + stat_slot->meta.dpvr_min = + RTE_MIN(stat_slot->meta.dpvr_min, slot->meta.dpvr_min); + stat_slot->meta.dpvr_max = + RTE_MAX(stat_slot->meta.dpvr_max, slot->meta.dpvr_max); - if (!stat_slot->dpvr_first) stat_slot->dpvr_first = slot->dpvr_first; + if (!stat_slot->dpvr_first) + stat_slot->dpvr_first = slot->dpvr_first; stat_slot->ipt_sum += slot->ipt_sum; - stat_slot->meta.ipt_min = RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); - stat_slot->meta.ipt_max = RTE_MAX(stat_slot->meta.ipt_max, slot->meta.ipt_max); + stat_slot->meta.ipt_min = + RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); + stat_slot->meta.ipt_max = + RTE_MAX(stat_slot->meta.ipt_max, slot->meta.ipt_max); stat_slot->meta.pkts_cnt += slot->meta.pkts_cnt; } -void ra_tp_on_packet(struct st_rx_audio_session_impl* s, enum mtl_session_port s_port, - uint32_t rtp_tmstamp, uint64_t pkt_time) { - struct st_rx_audio_tp* tp = s->tp; - struct st_ra_tp_slot* slot = &tp->slot[s_port]; +void ra_tp_on_packet(struct st_rx_audio_session_impl *s, + enum mtl_session_port s_port, uint32_t rtp_tmstamp, + uint64_t pkt_time) { + struct st_rx_audio_tp *tp = s->tp; + struct st_ra_tp_slot *slot = &tp->slot[s_port]; uint64_t epoch = (double)pkt_time / tp->pkt_time; uint64_t epoch_ns = (double)epoch * tp->pkt_time; @@ -463,7 +496,8 @@ void ra_tp_on_packet(struct st_rx_audio_session_impl* s, enum mtl_session_port s slot->meta.dpvr_max = RTE_MAX(dpvr, slot->meta.dpvr_max); slot->dpvr_sum += dpvr; - if (!slot->dpvr_first) slot->dpvr_first = dpvr; + if (!slot->dpvr_first) + slot->dpvr_first = dpvr; if (tp->prev_pkt_time[s_port]) { double ipt = (double)pkt_time - tp->prev_pkt_time[s_port]; @@ -475,12 +509,12 @@ void ra_tp_on_packet(struct st_rx_audio_session_impl* s, enum mtl_session_port s tp->prev_pkt_time[s_port] = pkt_time; } -int ra_tp_init(struct mtl_main_impl* impl, struct st_rx_audio_session_impl* s) { +int ra_tp_init(struct mtl_main_impl *impl, struct st_rx_audio_session_impl *s) { enum mtl_port port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); int soc_id = mt_socket_id(impl, port); int idx = s->idx; - struct st_rx_audio_tp* tp; - struct st30_rx_ops* ops = &s->ops; + struct st_rx_audio_tp *tp; + struct st30_rx_ops *ops = &s->ops; tp = mt_rte_zmalloc_socket(sizeof(*tp), soc_id); if (!tp) { @@ -502,15 +536,16 @@ int ra_tp_init(struct mtl_main_impl* impl, struct st_rx_audio_session_impl* s) { tp->last_parse_time = mt_get_tsc(impl); - info("%s(%d), Delta Packet vs RTP Pass Criteria in us, narrow %d wide %d\n", __func__, - idx, tp->dpvr_max_pass_narrow, tp->dpvr_max_pass_wide); - info("%s(%d), Timestamped Delay Factor Pass Criteria in us, narrow %d wide %d\n", + info("%s(%d), Delta Packet vs RTP Pass Criteria in us, narrow %d wide %d\n", + __func__, idx, tp->dpvr_max_pass_narrow, tp->dpvr_max_pass_wide); + info("%s(%d), Timestamped Delay Factor Pass Criteria in us, narrow %d wide " + "%d\n", __func__, idx, tp->tsdf_max_pass_narrow, tp->tsdf_max_pass_wide); return 0; } -int ra_tp_uinit(struct st_rx_audio_session_impl* s) { +int ra_tp_uinit(struct st_rx_audio_session_impl *s) { if (s->tp) { mt_rte_free(s->tp); s->tp = NULL; @@ -519,29 +554,33 @@ int ra_tp_uinit(struct st_rx_audio_session_impl* s) { return 0; } -void ra_tp_stat(struct st_rx_audio_session_impl* s) { +void ra_tp_stat(struct st_rx_audio_session_impl *s) { int idx = s->idx; - struct st_rx_audio_tp* tp = s->tp; - if (!tp) return; + struct st_rx_audio_tp *tp = s->tp; + if (!tp) + return; for (int s_port = 0; s_port < s->ops.num_port; s_port++) { - struct st_ra_tp_stat* stat = &tp->stat[s_port]; - struct st_ra_tp_slot* stat_slot = &stat->slot; + struct st_ra_tp_stat *stat = &tp->stat[s_port]; + struct st_ra_tp_slot *stat_slot = &stat->slot; - info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, s_port, - stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], + info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, + s_port, stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_WIDE], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED]); - float dpvr_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->dpvr_sum); - info("%s(%d), dpvr(us) AVG %.2f MIN %d MAX %d, pkt_cnt %u\n", __func__, idx, dpvr_avg, - stat_slot->meta.dpvr_min, stat_slot->meta.dpvr_max, stat_slot->meta.pkts_cnt); + float dpvr_avg = + rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->dpvr_sum); + info("%s(%d), dpvr(us) AVG %.2f MIN %d MAX %d, pkt_cnt %u\n", __func__, idx, + dpvr_avg, stat_slot->meta.dpvr_min, stat_slot->meta.dpvr_max, + stat_slot->meta.pkts_cnt); /* Maximum Timestamped Delay Factor */ float tsdf_avg = rv_tp_calculate_avg(stat->tsdf_cnt, stat->tsdf_sum); info("%s(%d), tsdf(us) AVG %.2f MIN %d MAX %d\n", __func__, idx, tsdf_avg, stat->tsdf_min, stat->tsdf_max); - float ipt_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); + float ipt_avg = + rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); info("%s(%d), ipt(ns) AVG %.2f MIN %d MAX %d\n", __func__, idx, ipt_avg, stat_slot->meta.ipt_min, stat_slot->meta.ipt_max); @@ -555,7 +594,7 @@ void ra_tp_stat(struct st_rx_audio_session_impl* s) { ra_tp_stat_init(tp); } -void ra_tp_slot_init(struct st_ra_tp_slot* slot) { +void ra_tp_slot_init(struct st_ra_tp_slot *slot) { memset(slot, 0, sizeof(*slot)); slot->meta.dpvr_max = INT_MIN; diff --git a/lib/src/st2110/st_rx_timing_parser.h b/lib/src/st2110/st_rx_timing_parser.h index 97a4521e4..bda980dfd 100644 --- a/lib/src/st2110/st_rx_timing_parser.h +++ b/lib/src/st2110/st_rx_timing_parser.h @@ -7,31 +7,33 @@ #include "st_main.h" -int rv_tp_init(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s); -int rv_tp_uinit(struct st_rx_video_session_impl* s); +int rv_tp_init(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s); +int rv_tp_uinit(struct st_rx_video_session_impl *s); -void rv_tp_slot_init(struct st_rv_tp_slot* slot); +void rv_tp_slot_init(struct st_rv_tp_slot *slot); -void rv_tp_on_packet(struct st_rx_video_session_impl* s, enum mtl_session_port s_port, - struct st_rv_tp_slot* slot, uint32_t rtp_tmstamp, uint64_t pkt_time, - int pkt_idx); +void rv_tp_on_packet(struct st_rx_video_session_impl *s, + enum mtl_session_port s_port, struct st_rv_tp_slot *slot, + uint32_t rtp_tmstamp, uint64_t pkt_time, int pkt_idx); -void rv_tp_slot_parse_result(struct st_rx_video_session_impl* s, - enum mtl_session_port s_port, struct st_rv_tp_slot* slot); +void rv_tp_slot_parse_result(struct st_rx_video_session_impl *s, + enum mtl_session_port s_port, + struct st_rv_tp_slot *slot); -void rv_tp_stat(struct st_rx_video_session_impl* s); +void rv_tp_stat(struct st_rx_video_session_impl *s); -int ra_tp_init(struct mtl_main_impl* impl, struct st_rx_audio_session_impl* s); -int ra_tp_uinit(struct st_rx_audio_session_impl* s); +int ra_tp_init(struct mtl_main_impl *impl, struct st_rx_audio_session_impl *s); +int ra_tp_uinit(struct st_rx_audio_session_impl *s); -void ra_tp_on_packet(struct st_rx_audio_session_impl* s, enum mtl_session_port s_port, - uint32_t rtp_tmstamp, uint64_t pkt_time); +void ra_tp_on_packet(struct st_rx_audio_session_impl *s, + enum mtl_session_port s_port, uint32_t rtp_tmstamp, + uint64_t pkt_time); -void ra_tp_slot_parse_result(struct st_rx_audio_session_impl* s, +void ra_tp_slot_parse_result(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port); -void ra_tp_stat(struct st_rx_audio_session_impl* s); +void ra_tp_stat(struct st_rx_audio_session_impl *s); -void ra_tp_slot_init(struct st_ra_tp_slot* slot); +void ra_tp_slot_init(struct st_ra_tp_slot *slot); #endif \ No newline at end of file diff --git a/lib/src/st2110/st_rx_video_session.c b/lib/src/st2110/st_rx_video_session.c index f7a118ee4..debd7b861 100644 --- a/lib/src/st2110/st_rx_video_session.c +++ b/lib/src/st2110/st_rx_video_session.c @@ -15,21 +15,22 @@ #include "st_fmt.h" #include "st_rx_timing_parser.h" -static int rv_init_pkt_handler(struct st_rx_video_session_impl* s); -static int rvs_mgr_update(struct st_rx_video_sessions_mgr* mgr); +static int rv_init_pkt_handler(struct st_rx_video_session_impl *s); +static int rvs_mgr_update(struct st_rx_video_sessions_mgr *mgr); -static inline struct mtl_main_impl* rv_get_impl(struct st_rx_video_session_impl* s) { +static inline struct mtl_main_impl * +rv_get_impl(struct st_rx_video_session_impl *s) { return s->parent->parent; } -static inline uint16_t rv_queue_id(struct st_rx_video_session_impl* s, +static inline uint16_t rv_queue_id(struct st_rx_video_session_impl *s, enum mtl_session_port s_port) { return mt_rxq_queue_id(s->rxq[s_port]); } -static int rv_detector_init(struct st_rx_video_session_impl* s) { - struct st_rx_video_detector* detector = &s->detector; - struct st20_detect_meta* meta = &detector->meta; +static int rv_detector_init(struct st_rx_video_session_impl *s) { + struct st_rx_video_detector *detector = &s->detector; + struct st20_detect_meta *meta = &detector->meta; detector->status = ST20_DETECT_STAT_DETECTING; detector->bpm = true; @@ -45,123 +46,125 @@ static int rv_detector_init(struct st_rx_video_session_impl* s) { return 0; } -static void rv_detector_calculate_dimension(struct st_rx_video_session_impl* s, - struct st_rx_video_detector* detector, - int max_line_num) { - struct st20_detect_meta* meta = &detector->meta; +static void +rv_detector_calculate_dimension(struct st_rx_video_session_impl *s, + struct st_rx_video_detector *detector, + int max_line_num) { + struct st20_detect_meta *meta = &detector->meta; dbg("%s(%d), interlaced %d, max_line_num %d\n", __func__, s->idx, meta->interlaced ? 1 : 0, max_line_num); if (meta->interlaced) { switch (max_line_num) { - case 539: - meta->height = 1080; - meta->width = 1920; - break; - case 239: - meta->height = 480; - meta->width = 640; - break; - case 359: - meta->height = 720; - meta->width = 1280; - break; - case 1079: - meta->height = 2160; - meta->width = 3840; - break; - case 2159: - meta->height = 4320; - meta->width = 7680; - break; - default: - err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); - break; + case 539: + meta->height = 1080; + meta->width = 1920; + break; + case 239: + meta->height = 480; + meta->width = 640; + break; + case 359: + meta->height = 720; + meta->width = 1280; + break; + case 1079: + meta->height = 2160; + meta->width = 3840; + break; + case 2159: + meta->height = 4320; + meta->width = 7680; + break; + default: + err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); + break; } } else { switch (max_line_num) { - case 1079: - meta->height = 1080; - meta->width = 1920; - break; - case 479: - meta->height = 480; - meta->width = 640; - break; - case 719: - meta->height = 720; - meta->width = 1280; - break; - case 2159: - meta->height = 2160; - meta->width = 3840; - break; - case 4319: - meta->height = 4320; - meta->width = 7680; - break; - default: - err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); - break; - } - } -} - -static void rv_detector_calculate_fps(struct st_rx_video_session_impl* s, - struct st_rx_video_detector* detector) { - struct st20_detect_meta* meta = &detector->meta; + case 1079: + meta->height = 1080; + meta->width = 1920; + break; + case 479: + meta->height = 480; + meta->width = 640; + break; + case 719: + meta->height = 720; + meta->width = 1280; + break; + case 2159: + meta->height = 2160; + meta->width = 3840; + break; + case 4319: + meta->height = 4320; + meta->width = 7680; + break; + default: + err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); + break; + } + } +} + +static void rv_detector_calculate_fps(struct st_rx_video_session_impl *s, + struct st_rx_video_detector *detector) { + struct st20_detect_meta *meta = &detector->meta; int d0 = detector->rtp_tm[1] - detector->rtp_tm[0]; int d1 = detector->rtp_tm[2] - detector->rtp_tm[1]; if (abs(d0 - d1) <= 1) { dbg("%s(%d), d0 = %d, d1 = %d\n", __func__, s->idx, d0, d1); switch (d0) { - case 750: - meta->fps = ST_FPS_P120; - return; - case 751: - meta->fps = ST_FPS_P119_88; - return; - case 900: - meta->fps = ST_FPS_P100; - return; - case 1500: - meta->fps = ST_FPS_P60; - return; - case 1501: - case 1502: - meta->fps = ST_FPS_P59_94; - return; - case 1800: - meta->fps = ST_FPS_P50; - return; - case 3000: - meta->fps = ST_FPS_P30; - return; - case 3003: - meta->fps = ST_FPS_P29_97; - return; - case 3600: - meta->fps = ST_FPS_P25; - return; - case 3750: - meta->fps = ST_FPS_P24; - return; - case 3753: - case 3754: - meta->fps = ST_FPS_P23_98; - return; - default: - err("%s(%d), err d0 %d d1 %d\n", __func__, s->idx, d0, d1); - break; + case 750: + meta->fps = ST_FPS_P120; + return; + case 751: + meta->fps = ST_FPS_P119_88; + return; + case 900: + meta->fps = ST_FPS_P100; + return; + case 1500: + meta->fps = ST_FPS_P60; + return; + case 1501: + case 1502: + meta->fps = ST_FPS_P59_94; + return; + case 1800: + meta->fps = ST_FPS_P50; + return; + case 3000: + meta->fps = ST_FPS_P30; + return; + case 3003: + meta->fps = ST_FPS_P29_97; + return; + case 3600: + meta->fps = ST_FPS_P25; + return; + case 3750: + meta->fps = ST_FPS_P24; + return; + case 3753: + case 3754: + meta->fps = ST_FPS_P23_98; + return; + default: + err("%s(%d), err d0 %d d1 %d\n", __func__, s->idx, d0, d1); + break; } } else { err("%s(%d), err d0 %d d1 %d\n", __func__, s->idx, d0, d1); } } -static void rv_detector_calculate_n_packet(struct st_rx_video_session_impl* s, - struct st_rx_video_detector* detector) { +static void +rv_detector_calculate_n_packet(struct st_rx_video_session_impl *s, + struct st_rx_video_detector *detector) { int total0 = detector->pkt_num[1] - detector->pkt_num[0]; int total1 = detector->pkt_num[2] - detector->pkt_num[1]; @@ -172,8 +175,9 @@ static void rv_detector_calculate_n_packet(struct st_rx_video_session_impl* s, } } -static void rv_detector_calculate_packing(struct st_rx_video_detector* detector) { - struct st20_detect_meta* meta = &detector->meta; +static void +rv_detector_calculate_packing(struct st_rx_video_detector *detector) { + struct st20_detect_meta *meta = &detector->meta; if (detector->bpm) meta->packing = ST20_PACKING_BPM; @@ -183,16 +187,16 @@ static void rv_detector_calculate_packing(struct st_rx_video_detector* detector) meta->packing = ST20_PACKING_GPM; } -static bool inline rv_is_hdr_split(struct st_rx_video_session_impl* s) { +static bool inline rv_is_hdr_split(struct st_rx_video_session_impl *s) { return s->is_hdr_split; } -static bool inline rv_is_dynamic_ext_frame(struct st_rx_video_session_impl* s) { +static bool inline rv_is_dynamic_ext_frame(struct st_rx_video_session_impl *s) { return s->ops.query_ext_frame != NULL; } -static struct st_frame_trans* rv_get_frame(struct st_rx_video_session_impl* s) { - struct st_frame_trans* st20_frame; +static struct st_frame_trans *rv_get_frame(struct st_rx_video_session_impl *s) { + struct st_frame_trans *st20_frame; for (int i = 0; i < s->st20_frames_cnt; i++) { st20_frame = &s->st20_frames[i]; @@ -208,8 +212,8 @@ static struct st_frame_trans* rv_get_frame(struct st_rx_video_session_impl* s) { return NULL; } -static int rv_put_frame(struct st_rx_video_session_impl* s, - struct st_frame_trans* frame) { +static int rv_put_frame(struct st_rx_video_session_impl *s, + struct st_frame_trans *frame) { MTL_MAY_UNUSED(s); dbg("%s(%d), put frame at %d\n", __func__, s->idx, frame->idx); rte_atomic32_dec(&frame->refcnt); @@ -220,10 +224,11 @@ static int rv_put_frame(struct st_rx_video_session_impl* s, return 0; } -static int rv_uinit_hdr_split_frame(struct st_rx_video_session_impl* s) { +static int rv_uinit_hdr_split_frame(struct st_rx_video_session_impl *s) { for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { if (s->hdr_split_info[i].frames) { - if (!s->ops.ext_frames) mt_rte_free(s->hdr_split_info[i].frames); + if (!s->ops.ext_frames) + mt_rte_free(s->hdr_split_info[i].frames); s->hdr_split_info[i].frames = NULL; } } @@ -231,7 +236,7 @@ static int rv_uinit_hdr_split_frame(struct st_rx_video_session_impl* s) { return 0; } -static int rv_init_hdr_split_frame(struct st_rx_video_session_impl* s) { +static int rv_init_hdr_split_frame(struct st_rx_video_session_impl *s) { int num_port = s->ops.num_port; int idx = s->idx; size_t frame_size = s->st20_frame_size; @@ -240,7 +245,8 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl* s) { uint32_t mbufs_total; mbufs_per_frame = frame_size / ST_VIDEO_BPM_SIZE; - if (frame_size % ST_VIDEO_BPM_SIZE) mbufs_per_frame++; + if (frame_size % ST_VIDEO_BPM_SIZE) + mbufs_per_frame++; mbufs_total = mbufs_per_frame * s->st20_frames_cnt; /* extra mbufs since frame may not start from zero pos */ mbufs_total += (mbufs_per_frame - 1); @@ -256,11 +262,11 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl* s) { /* more extra space since rte_mbuf_data_iova_default has offset */ size_t malloc_size = frames_size + 4096; - void* frames; + void *frames; rte_iova_t frames_iova; if (s->ops.ext_frames) { - struct st20_ext_frame* ext_frame = &s->ops.ext_frames[i]; + struct st20_ext_frame *ext_frame = &s->ops.ext_frames[i]; frames = ext_frame->buf_addr; if (!frames) { err("%s(%d, %d), NULL frame for ext frames\n", __func__, idx, i); @@ -274,8 +280,8 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl* s) { return -EIO; } if (ext_frame->buf_len < malloc_size) { - err("%s(%d, %d), ext frames size too small, need %" PRIu64 " but only %" PRIu64 - "\n", + err("%s(%d, %d), ext frames size too small, need %" PRIu64 + " but only %" PRIu64 "\n", __func__, idx, i, malloc_size, ext_frame->buf_len); rv_uinit_hdr_split_frame(s); return -EIO; @@ -283,8 +289,8 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl* s) { } else { frames = mt_rte_zmalloc_socket(malloc_size, soc_id); if (!frames) { - err("%s(%d), frames malloc fail for %d, mbufs_total %u\n", __func__, idx, i, - mbufs_total); + err("%s(%d), frames malloc fail for %d, mbufs_total %u\n", __func__, + idx, i, mbufs_total); rv_uinit_hdr_split_frame(s); return -ENOMEM; } @@ -295,16 +301,17 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl* s) { s->hdr_split_info[i].frames_size = frames_size; s->hdr_split_info[i].mbufs_per_frame = mbufs_per_frame; s->hdr_split_info[i].mbufs_total = mbufs_total; - info("%s(%d,%d), frames (%p-%p), mbufs_total %u, iova %" PRIx64 "\n", __func__, idx, - i, frames, frames + frames_size, mbufs_total, s->hdr_split_info[i].frames_iova); + info("%s(%d,%d), frames (%p-%p), mbufs_total %u, iova %" PRIx64 "\n", + __func__, idx, i, frames, frames + frames_size, mbufs_total, + s->hdr_split_info[i].frames_iova); } return 0; } -static int rv_free_frames(struct st_rx_video_session_impl* s) { +static int rv_free_frames(struct st_rx_video_session_impl *s) { if (s->st20_frames) { - struct st_frame_trans* frame; + struct st_frame_trans *frame; for (int i = 0; i < s->st20_frames_cnt; i++) { frame = &s->st20_frames[i]; st_frame_trans_uinit(frame); @@ -319,59 +326,64 @@ static int rv_free_frames(struct st_rx_video_session_impl* s) { return 0; } -static rte_iova_t rv_frame_get_offset_iova(struct st_rx_video_session_impl* s, - struct st_frame_trans* frame_info, +static rte_iova_t rv_frame_get_offset_iova(struct st_rx_video_session_impl *s, + struct st_frame_trans *frame_info, size_t offset) { - if (frame_info->page_table_len == 0) return frame_info->iova + offset; - void* addr = RTE_PTR_ADD(frame_info->addr, offset); - struct st_page_info* page; + if (frame_info->page_table_len == 0) + return frame_info->iova + offset; + void *addr = RTE_PTR_ADD(frame_info->addr, offset); + struct st_page_info *page; for (uint16_t i = 0; i < frame_info->page_table_len; i++) { page = &frame_info->page_table[i]; if (addr >= page->addr && addr < RTE_PTR_ADD(page->addr, page->len)) return page->iova + RTE_PTR_DIFF(addr, page->addr); } - err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, frame_info->idx, - offset); + err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, + frame_info->idx, offset); return MTL_BAD_IOVA; } -static int rv_frame_create_page_table(struct st_rx_video_session_impl* s, - struct st_frame_trans* frame_info) { - struct rte_memseg* mseg = rte_mem_virt2memseg(frame_info->addr, NULL); +static int rv_frame_create_page_table(struct st_rx_video_session_impl *s, + struct st_frame_trans *frame_info) { + struct rte_memseg *mseg = rte_mem_virt2memseg(frame_info->addr, NULL); if (mseg == NULL) { err("%s(%d,%d), get mseg fail\n", __func__, s->idx, frame_info->idx); return -EIO; } size_t hugepage_sz = mseg->hugepage_sz; - info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, frame_info->idx, - hugepage_sz); + info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, + frame_info->idx, hugepage_sz); /* calculate num hugepages */ uint16_t num_pages = - RTE_PTR_DIFF(RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), - RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / + RTE_PTR_DIFF( + RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), + RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / hugepage_sz; int soc_id = s->socket_id; - struct st_page_info* pages = mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); + struct st_page_info *pages = + mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); if (pages == NULL) { - err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, frame_info->idx); + err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, + frame_info->idx); return -ENOMEM; } /* get IOVA start of each page */ - void* addr = frame_info->addr; + void *addr = frame_info->addr; for (uint16_t i = 0; i < num_pages; i++) { /* touch the page before getting its IOVA */ - *(volatile char*)addr = 0; + *(volatile char *)addr = 0; pages[i].iova = rte_mem_virt2iova(addr); pages[i].addr = addr; - void* next_addr = RTE_PTR_ALIGN(RTE_PTR_ADD(addr, 1), hugepage_sz); + void *next_addr = RTE_PTR_ALIGN(RTE_PTR_ADD(addr, 1), hugepage_sz); pages[i].len = RTE_PTR_DIFF(next_addr, addr); addr = next_addr; - info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", __func__, - s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, pages[i].len); + info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", + __func__, s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, + pages[i].len); } frame_info->page_table = pages; frame_info->page_table_len = num_pages; @@ -379,25 +391,27 @@ static int rv_frame_create_page_table(struct st_rx_video_session_impl* s, return 0; } -static inline bool rv_frame_payload_cross_page(struct st_rx_video_session_impl* s, - struct st_frame_trans* frame_info, - size_t offset, size_t len) { - if (frame_info->page_table_len == 0) return false; +static inline bool +rv_frame_payload_cross_page(struct st_rx_video_session_impl *s, + struct st_frame_trans *frame_info, size_t offset, + size_t len) { + if (frame_info->page_table_len == 0) + return false; return ((rv_frame_get_offset_iova(s, frame_info, offset + len - 1) - rv_frame_get_offset_iova(s, frame_info, offset)) != len - 1); } -static int rv_alloc_frames(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s) { +static int rv_alloc_frames(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { int soc_id = s->socket_id; int idx = s->idx; size_t size = s->st20_uframe_size ? s->st20_uframe_size : s->st20_fb_size; - struct st_frame_trans* st20_frame; - void* frame; + struct st_frame_trans *st20_frame; + void *frame; int ret; - s->st20_frames = - mt_rte_zmalloc_socket(sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); + s->st20_frames = mt_rte_zmalloc_socket( + sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); if (!s->st20_frames) { err("%s(%d), st20_frames alloc fail\n", __func__, idx); return -ENOMEM; @@ -440,8 +454,8 @@ static int rv_alloc_frames(struct mtl_main_impl* impl, st20_frame->addr = frame; st20_frame->iova = frame_iova; st20_frame->flags = ST_FT_FLAG_EXT; - info("%s(%d), attach external frame %d, addr %p, iova %" PRIu64 "\n", __func__, idx, - i, frame, frame_iova); + info("%s(%d), attach external frame %d, addr %p, iova %" PRIu64 "\n", + __func__, idx, i, frame, frame_iova); } else if (rv_is_dynamic_ext_frame(s)) { st20_frame->iova = 0; /* detect later */ st20_frame->addr = NULL; @@ -449,7 +463,8 @@ static int rv_alloc_frames(struct mtl_main_impl* impl, } else { frame = mt_rte_zmalloc_socket(size, soc_id); if (!frame) { - err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, size, i); + err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, + size, i); rv_free_frames(s); return -ENOMEM; } @@ -481,7 +496,7 @@ static int rv_alloc_frames(struct mtl_main_impl* impl, return 0; } -static int rv_free_rtps(struct st_rx_video_session_impl* s) { +static int rv_free_rtps(struct st_rx_video_session_impl *s) { if (s->rtps_ring) { mt_ring_dequeue_clean(s->rtps_ring); rte_ring_free(s->rtps_ring); @@ -491,15 +506,16 @@ static int rv_free_rtps(struct st_rx_video_session_impl* s) { return 0; } -static int rv_alloc_rtps(struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s) { +static int rv_alloc_rtps(struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s) { char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_RTP", ST_RX_VIDEO_PREFIX, mgr_idx, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ops.rtp_ring_size; if (count <= 0) { err("%s(%d,%d), invalid rtp_ring_size %d\n", __func__, mgr_idx, idx, count); @@ -517,23 +533,28 @@ static int rv_alloc_rtps(struct st_rx_video_sessions_mgr* mgr, #ifdef ST_HAS_DPDK_HDR_SPLIT /* run within the context of receiver lcore */ -static int rv_hdrs_mbuf_callback_fn(void* priv, struct rte_eth_hdrs_mbuf* mbuf) { - struct st_rx_video_session_impl* s = priv; - struct st_rx_video_hdr_split_info* hdr_split = &s->hdr_split_info[MTL_SESSION_PORT_P]; +static int rv_hdrs_mbuf_callback_fn(void *priv, + struct rte_eth_hdrs_mbuf *mbuf) { + struct st_rx_video_session_impl *s = priv; + struct st_rx_video_hdr_split_info *hdr_split = + &s->hdr_split_info[MTL_SESSION_PORT_P]; uint32_t alloc_idx = hdr_split->mbuf_alloc_idx; uint32_t cur_frame_mbuf_idx = hdr_split->cur_frame_mbuf_idx; if (cur_frame_mbuf_idx) { - uint32_t next_frame_start_idx = cur_frame_mbuf_idx + hdr_split->mbufs_per_frame; + uint32_t next_frame_start_idx = + cur_frame_mbuf_idx + hdr_split->mbufs_per_frame; if (alloc_idx == next_frame_start_idx) { - /* start of next frame, reset if remaining frame space is capable one frame */ + /* start of next frame, reset if remaining frame space is capable one + * frame */ if ((alloc_idx + hdr_split->mbufs_per_frame) >= hdr_split->mbufs_total) { - dbg("%s(%d), idx reset at idx %u, cur_frame_mbuf_idx %u\n", __func__, s->idx, - alloc_idx, cur_frame_mbuf_idx); + dbg("%s(%d), idx reset at idx %u, cur_frame_mbuf_idx %u\n", __func__, + s->idx, alloc_idx, cur_frame_mbuf_idx); /* notify for mismatch frame address */ if (cur_frame_mbuf_idx % hdr_split->mbufs_per_frame) { - dbg("%s(%d), idx reset for mismatch frame at idx %u, cur_frame_mbuf_idx %u\n", + dbg("%s(%d), idx reset for mismatch frame at idx %u, " + "cur_frame_mbuf_idx %u\n", __func__, s->idx, alloc_idx, cur_frame_mbuf_idx); } alloc_idx = 0; @@ -543,7 +564,8 @@ static int rv_hdrs_mbuf_callback_fn(void* priv, struct rte_eth_hdrs_mbuf* mbuf) uint32_t remaining_mbufs = hdr_split->mbufs_total - alloc_idx; if (remaining_mbufs < hdr_split->mbufs_per_frame) { /* all mbuf ready, start from zero */ - info("%s(%d), alloc idx reset at %u as pool ready\n", __func__, s->idx, alloc_idx); + info("%s(%d), alloc idx reset at %u as pool ready\n", __func__, s->idx, + alloc_idx); alloc_idx = 0; hdr_split->mbuf_pool_ready = true; } @@ -551,7 +573,8 @@ static int rv_hdrs_mbuf_callback_fn(void* priv, struct rte_eth_hdrs_mbuf* mbuf) mbuf->buf_addr = hdr_split->frames + alloc_idx * ST_VIDEO_BPM_SIZE; mbuf->buf_iova = hdr_split->frames_iova + alloc_idx * ST_VIDEO_BPM_SIZE; - dbg("%s(%d), mbuf alloc idx %u, buf %p\n", __func__, s->idx, alloc_idx, mbuf->buf_addr); + dbg("%s(%d), mbuf alloc idx %u, buf %p\n", __func__, s->idx, alloc_idx, + mbuf->buf_addr); /* point to next alloc_idx */ alloc_idx++; @@ -568,44 +591,47 @@ static int rv_hdrs_mbuf_callback_fn(void* priv, struct rte_eth_hdrs_mbuf* mbuf) } #endif -static inline void rv_slot_init_frame_size(struct st_rx_video_slot_impl* slot) { +static inline void rv_slot_init_frame_size(struct st_rx_video_slot_impl *slot) { slot->frame_recv_size = 0; slot->pkt_lcore_frame_recv_size = 0; } -static inline size_t rv_slot_get_frame_size(struct st_rx_video_slot_impl* slot) { +static inline size_t +rv_slot_get_frame_size(struct st_rx_video_slot_impl *slot) { return slot->frame_recv_size + slot->pkt_lcore_frame_recv_size; } -static inline void rv_slot_add_frame_size(struct st_rx_video_slot_impl* slot, +static inline void rv_slot_add_frame_size(struct st_rx_video_slot_impl *slot, size_t size) { slot->frame_recv_size += size; } -static inline void rv_slot_pkt_lcore_add_frame_size(struct st_rx_video_slot_impl* slot, - size_t size) { +static inline void +rv_slot_pkt_lcore_add_frame_size(struct st_rx_video_slot_impl *slot, + size_t size) { slot->pkt_lcore_frame_recv_size += size; } -void rv_slot_dump(struct st_rx_video_session_impl* s) { - struct st_rx_video_slot_impl* slot; +void rv_slot_dump(struct st_rx_video_session_impl *s) { + struct st_rx_video_slot_impl *slot; for (int i = 0; i < ST_VIDEO_RX_REC_NUM_OFO; i++) { slot = &s->slots[i]; - info("%s(%d), tmstamp %u recv_size %" PRIu64 " pkts_received %u\n", __func__, i, - slot->tmstamp, rv_slot_get_frame_size(slot), slot->pkts_received); + info("%s(%d), tmstamp %u recv_size %" PRIu64 " pkts_received %u\n", + __func__, i, slot->tmstamp, rv_slot_get_frame_size(slot), + slot->pkts_received); } } -static int rv_init(struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, int idx) { +static int rv_init(struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, int idx) { s->idx = idx; s->parent = mgr; return 0; } -static int rv_uinit_slot(struct st_rx_video_session_impl* s) { - struct st_rx_video_slot_impl* slot; +static int rv_uinit_slot(struct st_rx_video_session_impl *s) { + struct st_rx_video_slot_impl *slot; for (int i = 0; i < ST_VIDEO_RX_REC_NUM_OFO; i++) { slot = &s->slots[i]; @@ -627,13 +653,13 @@ static int rv_uinit_slot(struct st_rx_video_session_impl* s) { return 0; } -static int rv_init_slot(struct st_rx_video_session_impl* s) { +static int rv_init_slot(struct st_rx_video_session_impl *s) { int soc_id = s->socket_id; int idx = s->idx; size_t bitmap_size = s->st20_frame_bitmap_size; - struct st_rx_video_slot_impl* slot; - uint8_t* frame_bitmap; - struct st_rx_video_slot_slice_info* slice_info; + struct st_rx_video_slot_impl *slot; + uint8_t *frame_bitmap; + struct st_rx_video_slot_slice_info *slice_info; enum st20_type type = s->ops.type; /* init slot */ @@ -648,7 +674,8 @@ static int rv_init_slot(struct st_rx_video_session_impl* s) { slot->seq_id_got = false; frame_bitmap = mt_rte_zmalloc_socket(bitmap_size, soc_id); if (!frame_bitmap) { - err("%s(%d), bitmap malloc %" PRIu64 " fail\n", __func__, idx, bitmap_size); + err("%s(%d), bitmap malloc %" PRIu64 " fail\n", __func__, idx, + bitmap_size); return -ENOMEM; } slot->frame_bitmap = frame_bitmap; @@ -672,52 +699,58 @@ static int rv_init_slot(struct st_rx_video_session_impl* s) { return 0; } -static inline int rv_notify_frame_ready(struct st_rx_video_session_impl* s, void* frame, - struct st20_rx_frame_meta* meta) { +static inline int rv_notify_frame_ready(struct st_rx_video_session_impl *s, + void *frame, + struct st20_rx_frame_meta *meta) { int ret; uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(s->impl); - if (time_measure) tsc_start = mt_get_tsc(s->impl); + if (time_measure) + tsc_start = mt_get_tsc(s->impl); ret = s->ops.notify_frame_ready(s->ops.priv, frame, meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(s->impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = + RTE_MAX(s->stat_max_notify_frame_us, delta_us); } return ret; } -static inline int st22_notify_frame_ready(struct st_rx_video_session_impl* s, void* frame, - struct st22_rx_frame_meta* meta) { +static inline int st22_notify_frame_ready(struct st_rx_video_session_impl *s, + void *frame, + struct st22_rx_frame_meta *meta) { int ret; uint64_t tsc_start = 0; - struct st22_rx_video_info* st22_info = s->st22_info; + struct st22_rx_video_info *st22_info = s->st22_info; bool time_measure = mt_sessions_time_measure(s->impl); - if (time_measure) tsc_start = mt_get_tsc(s->impl); + if (time_measure) + tsc_start = mt_get_tsc(s->impl); ret = st22_info->notify_frame_ready(s->ops.priv, frame, meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(s->impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = + RTE_MAX(s->stat_max_notify_frame_us, delta_us); } return ret; } -static int rv_usdt_dump_frame(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s, - struct st_frame_trans* frame) { - struct st_rx_video_sessions_mgr* mgr = s->parent; +static int rv_usdt_dump_frame(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s, + struct st_frame_trans *frame) { + struct st_rx_video_sessions_mgr *mgr = s->parent; int idx = s->idx; int fd; char usdt_dump_path[64]; - struct st20_rx_ops* ops = &s->ops; + struct st20_rx_ops *ops = &s->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20rx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, ops->width, - ops->height); + "imtl_usdt_st20rx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, + ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -729,7 +762,8 @@ static int rv_usdt_dump_frame(struct mtl_main_impl* impl, if (n != s->st20_frame_size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST20_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); + MT_USDT_ST20_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, + n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -738,19 +772,19 @@ static int rv_usdt_dump_frame(struct mtl_main_impl* impl, return 0; } -static int rv_st22_usdt_dump_frame(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s, - struct st_frame_trans* frame, size_t size) { - struct st_rx_video_sessions_mgr* mgr = s->parent; +static int rv_st22_usdt_dump_frame(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s, + struct st_frame_trans *frame, size_t size) { + struct st_rx_video_sessions_mgr *mgr = s->parent; int idx = s->idx; int fd; char usdt_dump_path[64]; - struct st20_rx_ops* ops = &s->ops; + struct st20_rx_ops *ops = &s->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22rx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, ops->width, - ops->height); + "imtl_usdt_st22rx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, + ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".raw")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -762,7 +796,8 @@ static int rv_st22_usdt_dump_frame(struct mtl_main_impl* impl, if (n != size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST22_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); + MT_USDT_ST22_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, + n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -771,15 +806,15 @@ static int rv_st22_usdt_dump_frame(struct mtl_main_impl* impl, return 0; } -static void rv_frame_notify(struct st_rx_video_session_impl* s, - struct st_rx_video_slot_impl* slot) { - struct st20_rx_ops* ops = &s->ops; - struct st20_rx_frame_meta* meta = &slot->meta; - struct st_frame_trans* frame = slot->frame; +static void rv_frame_notify(struct st_rx_video_session_impl *s, + struct st_rx_video_slot_impl *slot) { + struct st20_rx_ops *ops = &s->ops; + struct st20_rx_frame_meta *meta = &slot->meta; + struct st_frame_trans *frame = slot->frame; if (s->enable_timing_parser) { for (int s_port = 0; s_port < ops->num_port; s_port++) { - struct st_rv_tp_slot* tp_slot = &s->tp->slots[slot->idx][s_port]; + struct st_rv_tp_slot *tp_slot = &s->tp->slots[slot->idx][s_port]; rv_tp_slot_parse_result(s, s_port, tp_slot); if (s->enable_timing_parser_meta) { meta->tp[s_port] = &tp_slot->meta; @@ -813,8 +848,8 @@ static void rv_frame_notify(struct st_rx_video_session_impl* s, meta->uframe_total_size = s->st20_uframe_size; meta->frame_recv_size = rv_slot_get_frame_size(slot); meta->pkts_total = slot->pkts_received; - for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; s_port < MTL_SESSION_PORT_MAX; - s_port++) { + for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; + s_port < MTL_SESSION_PORT_MAX; s_port++) { meta->pkts_recv[s_port] = slot->pkts_recv_per_port[s_port]; } meta->rtp_timestamp = slot->tmstamp; @@ -827,8 +862,9 @@ static void rv_frame_notify(struct st_rx_video_session_impl* s, meta->user_meta = NULL; } - MT_USDT_ST20_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, frame->addr, - slot->tmstamp, meta->frame_recv_size); + MT_USDT_ST20_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, + frame->addr, slot->tmstamp, + meta->frame_recv_size); /* check if dump USDT enabled */ if (MT_USDT_ST20_RX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -843,7 +879,8 @@ static void rv_frame_notify(struct st_rx_video_session_impl* s, if (meta->frame_recv_size >= s->st20_frame_size) { meta->status = ST_FRAME_STATUS_COMPLETE; if (ops->num_port > 1) { - if ((slot->pkts_recv_per_port[MTL_SESSION_PORT_P] < slot->pkts_received) && + if ((slot->pkts_recv_per_port[MTL_SESSION_PORT_P] < + slot->pkts_received) && (slot->pkts_recv_per_port[MTL_SESSION_PORT_R] < slot->pkts_received)) meta->status = ST_FRAME_STATUS_RECONSTRUCTED; } @@ -863,16 +900,21 @@ static void rv_frame_notify(struct st_rx_video_session_impl* s, double reactive = 1080.0 / 1125.0; s->trs = s->frame_time * reactive / meta->pkts_total; } else { - dbg("%s(%d): frame_recv_size %" PRIu64 ", frame_total_size %" PRIu64 ", tmstamp %u\n", - __func__, s->idx, meta->frame_recv_size, meta->frame_total_size, slot->tmstamp); - MT_USDT_ST20_RX_FRAME_INCOMPLETE(s->parent->idx, s->idx, frame->idx, slot->tmstamp, - meta->frame_recv_size, s->st20_frame_size); + dbg("%s(%d): frame_recv_size %" PRIu64 ", frame_total_size %" PRIu64 + ", tmstamp %u\n", + __func__, s->idx, meta->frame_recv_size, meta->frame_total_size, + slot->tmstamp); + MT_USDT_ST20_RX_FRAME_INCOMPLETE(s->parent->idx, s->idx, frame->idx, + slot->tmstamp, meta->frame_recv_size, + s->st20_frame_size); meta->status = ST_FRAME_STATUS_CORRUPTED; s->stat_frames_dropped++; /* record the miss pkts */ float pd_sz_per_pkt = (float)meta->frame_recv_size / slot->pkts_received; - int miss_pkts = (s->st20_frame_size - meta->frame_recv_size) / pd_sz_per_pkt; - dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, miss_pkts); + int miss_pkts = + (s->st20_frame_size - meta->frame_recv_size) / pd_sz_per_pkt; + dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, + miss_pkts); s->stat_frames_pks_missed += miss_pkts; #if 0 /* for miss pkt detail */ int total_pkts = s->st20_frame_size / pd_sz_per_pkt; @@ -894,12 +936,12 @@ static void rv_frame_notify(struct st_rx_video_session_impl* s, } } -static void rv_st22_frame_notify(struct st_rx_video_session_impl* s, - struct st_rx_video_slot_impl* slot, +static void rv_st22_frame_notify(struct st_rx_video_session_impl *s, + struct st_rx_video_slot_impl *slot, enum st_frame_status status) { - struct st20_rx_ops* ops = &s->ops; - struct st22_rx_frame_meta* meta = &slot->st22_meta; - struct st_frame_trans* frame = slot->frame; + struct st20_rx_ops *ops = &s->ops; + struct st22_rx_frame_meta *meta = &slot->st22_meta; + struct st_frame_trans *frame = slot->frame; meta->second_field = slot->second_field; if (ops->interlaced) { @@ -914,13 +956,14 @@ static void rv_st22_frame_notify(struct st_rx_video_session_impl* s, meta->frame_total_size = rv_slot_get_frame_size(slot); meta->status = status; meta->pkts_total = slot->pkts_received; - for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; s_port < MTL_SESSION_PORT_MAX; - s_port++) { + for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; + s_port < MTL_SESSION_PORT_MAX; s_port++) { meta->pkts_recv[s_port] = slot->pkts_recv_per_port[s_port]; } - MT_USDT_ST22_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, frame->addr, - slot->tmstamp, meta->frame_total_size); + MT_USDT_ST22_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, + frame->addr, slot->tmstamp, + meta->frame_total_size); /* check if dump USDT enabled */ if (MT_USDT_ST22_RX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -950,11 +993,14 @@ static void rv_st22_frame_notify(struct st_rx_video_session_impl* s, } else { s->stat_frames_dropped++; /* record the miss pkts */ - float pd_sz_per_pkt = (float)s->st22_expect_size_per_frame / slot->pkts_received; - int miss_pkts = - (s->st22_expect_size_per_frame - meta->frame_total_size) / pd_sz_per_pkt; - if (miss_pkts < 0) miss_pkts = 0; - dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, miss_pkts); + float pd_sz_per_pkt = + (float)s->st22_expect_size_per_frame / slot->pkts_received; + int miss_pkts = (s->st22_expect_size_per_frame - meta->frame_total_size) / + pd_sz_per_pkt; + if (miss_pkts < 0) + miss_pkts = 0; + dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, + miss_pkts); s->stat_frames_pks_missed += miss_pkts; #if 0 /* for miss pkt detail */ int total_pkts = s->st22_expect_size_per_frame / pd_sz_per_pkt; @@ -977,11 +1023,11 @@ static void rv_st22_frame_notify(struct st_rx_video_session_impl* s, s->st22_expect_frame_size = 0; } -static void rv_slice_notify(struct st_rx_video_session_impl* s, - struct st_rx_video_slot_impl* slot, - struct st_rx_video_slot_slice_info* slice_info) { - struct st20_rx_ops* ops = &s->ops; - struct st20_rx_slice_meta* meta = &s->slice_meta; +static void rv_slice_notify(struct st_rx_video_session_impl *s, + struct st_rx_video_slot_impl *slot, + struct st_rx_video_slot_slice_info *slice_info) { + struct st20_rx_ops *ops = &s->ops; + struct st20_rx_slice_meta *meta = &s->slice_meta; /* w, h, fps, fmt, etc are fixed info */ meta->timestamp = slot->tmstamp; @@ -992,13 +1038,13 @@ static void rv_slice_notify(struct st_rx_video_session_impl* s, s->stat_slices_received++; } -static void rv_slice_add(struct st_rx_video_session_impl* s, - struct st_rx_video_slot_impl* slot, uint32_t offset, +static void rv_slice_add(struct st_rx_video_session_impl *s, + struct st_rx_video_slot_impl *slot, uint32_t offset, uint32_t size) { - struct st_rx_video_slot_slice_info* slice_info = slot->slice_info; - struct st_rx_video_slot_slice* main_slice = &slice_info->slices[0]; + struct st_rx_video_slot_slice_info *slice_info = slot->slice_info; + struct st_rx_video_slot_slice *main_slice = &slice_info->slices[0]; uint32_t ready_slices = 0; - struct st_rx_video_slot_slice* slice; + struct st_rx_video_slot_slice *slice; /* main slice always start from 0(seq_id_base) */ if (unlikely(offset != main_slice->size)) { @@ -1009,7 +1055,8 @@ static void rv_slice_add(struct st_rx_video_session_impl* s, slice->offset = offset; slice->size = size; slice_info->extra_slices++; - dbg("%s(%d), slice(%u:%u) add to %d\n", __func__, s->idx, offset, size, i); + dbg("%s(%d), slice(%u:%u) add to %d\n", __func__, s->idx, offset, size, + i); return; } @@ -1039,10 +1086,12 @@ static void rv_slice_add(struct st_rx_video_session_impl* s, merged = true; slice_info->extra_slices--; s->stat_pkts_slice_merged++; - dbg("%s(%d), slice %d(%u:%u) merge to main\n", __func__, s->idx, i, offset, size); + dbg("%s(%d), slice %d(%u:%u) merge to main\n", __func__, s->idx, i, + offset, size); } } - if (merged) goto repeat_merge; + if (merged) + goto repeat_merge; } /* check ready slice */ @@ -1054,11 +1103,11 @@ static void rv_slice_add(struct st_rx_video_session_impl* s, } } -static struct st_rx_video_slot_impl* rv_slot_by_tmstamp( - struct st_rx_video_session_impl* s, uint32_t tmstamp, void* hdr_split_pd, - bool* exist_ts) { +static struct st_rx_video_slot_impl * +rv_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp, + void *hdr_split_pd, bool *exist_ts) { int i, slot_idx; - struct st_rx_video_slot_impl* slot; + struct st_rx_video_slot_impl *slot; for (i = 0; i < s->slot_max; i++) { slot = &s->slots[i]; @@ -1101,12 +1150,12 @@ static struct st_rx_video_slot_impl* rv_slot_by_tmstamp( if (s->enable_timing_parser) { for (int s_port = 0; s_port < s->ops.num_port; s_port++) { - struct st_rv_tp_slot* tp_slot = &s->tp->slots[slot->idx][s_port]; + struct st_rv_tp_slot *tp_slot = &s->tp->slots[slot->idx][s_port]; rv_tp_slot_init(tp_slot); } } - struct st_frame_trans* frame_info = rv_get_frame(s); + struct st_frame_trans *frame_info = rv_get_frame(s); if (!frame_info) { s->stat_slot_get_frame_fail++; if (s->st22_info) @@ -1121,9 +1170,10 @@ static struct st_rx_video_slot_impl* rv_slot_by_tmstamp( } if (rv_is_dynamic_ext_frame(s)) { struct st20_ext_frame ext_frame; - struct st20_rx_ops* ops = &s->ops; - struct st20_rx_frame_meta* meta = &slot->meta; - size_t fb_size = s->st20_uframe_size ? s->st20_uframe_size : s->st20_fb_size; + struct st20_rx_ops *ops = &s->ops; + struct st20_rx_frame_meta *meta = &slot->meta; + size_t fb_size = + s->st20_uframe_size ? s->st20_uframe_size : s->st20_fb_size; meta->width = ops->width; meta->height = ops->height; @@ -1141,7 +1191,8 @@ static struct st_rx_video_slot_impl* rv_slot_by_tmstamp( } if (ext_frame.buf_len < fb_size) { s->stat_slot_query_ext_fail++; - err("%s(%d): ext frame size too small, required %" PRIu64 " but get %" PRIu64 "\n", + err("%s(%d): ext frame size too small, required %" PRIu64 + " but get %" PRIu64 "\n", __func__, s->idx, fb_size, ext_frame.buf_len); rte_atomic32_dec(&frame_info->refcnt); return NULL; @@ -1159,23 +1210,25 @@ static struct st_rx_video_slot_impl* rv_slot_by_tmstamp( /* clear bitmap */ memset(slot->frame_bitmap, 0x0, s->st20_frame_bitmap_size); - if (slot->slice_info) memset(slot->slice_info, 0x0, sizeof(*slot->slice_info)); + if (slot->slice_info) + memset(slot->slice_info, 0x0, sizeof(*slot->slice_info)); - dbg("%s(%d): assign slot %d framebuff %p for tmstamp %u\n", __func__, s->idx, slot_idx, - slot->frame->addr, tmstamp); + dbg("%s(%d): assign slot %d framebuff %p for tmstamp %u\n", __func__, s->idx, + slot_idx, slot->frame->addr, tmstamp); return slot; } -static struct st_rx_video_slot_impl* rv_rtp_slot_by_tmstamp( - struct st_rx_video_session_impl* s, uint32_t tmstamp) { +static struct st_rx_video_slot_impl * +rv_rtp_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp) { int i; int slot_idx = 0; - struct st_rx_video_slot_impl* slot; + struct st_rx_video_slot_impl *slot; for (i = 0; i < ST_VIDEO_RX_REC_NUM_OFO; i++) { slot = &s->slots[i]; - if (tmstamp == slot->tmstamp) return slot; + if (tmstamp == slot->tmstamp) + return slot; } /* replace the oldest slot*/ @@ -1194,8 +1247,8 @@ static struct st_rx_video_slot_impl* rv_rtp_slot_by_tmstamp( return slot; } -static void rv_slot_full_frame(struct st_rx_video_session_impl* s, - struct st_rx_video_slot_impl* slot) { +static void rv_slot_full_frame(struct st_rx_video_session_impl *s, + struct st_rx_video_slot_impl *slot) { /* end of frame */ rv_frame_notify(s, slot); rv_slot_init_frame_size(slot); @@ -1205,8 +1258,8 @@ static void rv_slot_full_frame(struct st_rx_video_session_impl* s, slot->frame = NULL; /* frame pass to app */ } -static void rv_st22_slot_full_frame(struct st_rx_video_session_impl* s, - struct st_rx_video_slot_impl* slot) { +static void rv_st22_slot_full_frame(struct st_rx_video_session_impl *s, + struct st_rx_video_slot_impl *slot) { /* end of frame */ rv_st22_frame_notify(s, slot, ST_FRAME_STATUS_COMPLETE); rv_slot_init_frame_size(slot); @@ -1229,7 +1282,8 @@ static void rv_st22_slot_drop_frame(struct st_rx_video_session_impl* s, } #endif -static int rv_free_dma(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { +static int rv_free_dma(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { if (s->dma_dev) { mt_dma_free_dev(impl, s->dma_dev); s->dma_dev = NULL; @@ -1238,13 +1292,15 @@ static int rv_free_dma(struct mtl_main_impl* impl, struct st_rx_video_session_im return 0; } -static int rv_slice_dma_drop_mbuf(void* priv, struct rte_mbuf* mbuf) { - struct st_rx_video_session_impl* s = priv; - rv_slice_add(s, s->dma_slot, st_rx_mbuf_get_offset(mbuf), st_rx_mbuf_get_len(mbuf)); +static int rv_slice_dma_drop_mbuf(void *priv, struct rte_mbuf *mbuf) { + struct st_rx_video_session_impl *s = priv; + rv_slice_add(s, s->dma_slot, st_rx_mbuf_get_offset(mbuf), + st_rx_mbuf_get_len(mbuf)); return 0; } -static int rv_init_dma(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { +static int rv_init_dma(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { int idx = s->idx; enum st20_type type = s->ops.type; @@ -1258,7 +1314,7 @@ static int rv_init_dma(struct mtl_main_impl* impl, struct st_rx_video_session_im req.drop_mbuf_cb = rv_slice_dma_drop_mbuf; else req.drop_mbuf_cb = NULL; - struct mtl_dma_lender_dev* dma_dev = mt_dma_request_dev(impl, &req); + struct mtl_dma_lender_dev *dma_dev = mt_dma_request_dev(impl, &req); if (!dma_dev) { info("%s(%d), fail, can not request dma dev\n", __func__, idx); return -EIO; @@ -1266,19 +1322,20 @@ static int rv_init_dma(struct mtl_main_impl* impl, struct st_rx_video_session_im s->dma_dev = dma_dev; - info("%s(%d), succ, dma %d lender id %u\n", __func__, idx, mt_dma_dev_id(dma_dev), - mt_dma_lender_id(dma_dev)); + info("%s(%d), succ, dma %d lender id %u\n", __func__, idx, + mt_dma_dev_id(dma_dev), mt_dma_lender_id(dma_dev)); return 0; } -static int rv_stop_pcap(struct st_rx_video_session_impl* s, +static int rv_stop_pcap(struct st_rx_video_session_impl *s, enum mtl_session_port s_port) { - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; - if (!pcap->pcap) return 0; + if (!pcap->pcap) + return 0; - info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, s->idx, - s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); + info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, + s->idx, s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); MT_USDT_ST20_RX_PCAP_DUMP(s->parent->idx, s->idx, s_port, pcap->file_name, pcap->dumped_pkts); pcap->required_pkts = 0; @@ -1287,12 +1344,13 @@ static int rv_stop_pcap(struct st_rx_video_session_impl* s, return 0; } -static int rv_start_pcap(struct st_rx_video_session_impl* s, enum mtl_session_port s_port, +static int rv_start_pcap(struct st_rx_video_session_impl *s, + enum mtl_session_port s_port, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta) { + struct st_pcap_dump_meta *meta) { int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->pcap) { err("%s(%d,%d), pcap dump already started\n", __func__, idx, s_port); @@ -1300,11 +1358,11 @@ static int rv_start_pcap(struct st_rx_video_session_impl* s, enum mtl_session_po } if (s->st22_info) { - snprintf(pcap->file_name, sizeof(pcap->file_name), "st22rx_s%dp%d_%u_XXXXXX.pcapng", - idx, s_port, max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), + "st22rx_s%dp%d_%u_XXXXXX.pcapng", idx, s_port, max_dump_packets); } else { - snprintf(pcap->file_name, sizeof(pcap->file_name), "st22rx_s%dp%d_%u_XXXXXX.pcapng", - idx, s_port, max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), + "st22rx_s%dp%d_%u_XXXXXX.pcapng", idx, s_port, max_dump_packets); } int fd = mt_mkstemps(pcap->file_name, strlen(".pcapng")); if (fd < 0) { @@ -1323,14 +1381,15 @@ static int rv_start_pcap(struct st_rx_video_session_impl* s, enum mtl_session_po pcap->dumped_pkts = 0; pcap->dropped_pkts = 0; pcap->required_pkts = max_dump_packets; - info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, s_port, - pcap->file_name, max_dump_packets); + info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, + s_port, pcap->file_name, max_dump_packets); if (sync) { int time_out = 100; /* 100*100ms, 10s */ int i = 0; for (; i < time_out; i++) { - if (!pcap->pcap) break; + if (!pcap->pcap) + break; mt_sleep_ms(100); } if (i >= time_out) { @@ -1348,36 +1407,38 @@ static int rv_start_pcap(struct st_rx_video_session_impl* s, enum mtl_session_po return 0; } -static int rv_start_pcap_dump(struct st_rx_video_session_impl* s, +static int rv_start_pcap_dump(struct st_rx_video_session_impl *s, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta) { + struct st_pcap_dump_meta *meta) { int ret; for (int s_port = 0; s_port < s->ops.num_port; s_port++) { ret = rv_start_pcap(s, s_port, max_dump_packets, sync, meta); - if (ret < 0) return ret; + if (ret < 0) + return ret; } return 0; } -static int rv_stop_pcap_dump(struct st_rx_video_session_impl* s) { +static int rv_stop_pcap_dump(struct st_rx_video_session_impl *s) { for (int s_port = 0; s_port < s->ops.num_port; s_port++) { rv_stop_pcap(s, s_port); } return 0; } -static int rv_dump_pcap(struct st_rx_video_session_impl* s, struct rte_mbuf** mbufs, - uint16_t nb, enum mtl_session_port s_port) { +static int rv_dump_pcap(struct st_rx_video_session_impl *s, + struct rte_mbuf **mbufs, uint16_t nb, + enum mtl_session_port s_port) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; uint16_t dump = mt_pcap_dump(s->impl, port, pcap->pcap, mbufs, nb); pcap->dumped_pkts += dump; pcap->dropped_pkts += nb - dump; return 0; } -static int rv_dma_dequeue(struct st_rx_video_session_impl* s) { - struct mtl_dma_lender_dev* dma_dev = s->dma_dev; +static int rv_dma_dequeue(struct st_rx_video_session_impl *s) { + struct mtl_dma_lender_dev *dma_dev = s->dma_dev; uint16_t nb_dq = mt_dma_completed(dma_dev, s->rx_burst_size, NULL, NULL); @@ -1387,7 +1448,7 @@ static int rv_dma_dequeue(struct st_rx_video_session_impl* s) { } /* all dma action finished */ - struct st_rx_video_slot_impl* dma_slot = s->dma_slot; + struct st_rx_video_slot_impl *dma_slot = s->dma_slot; if (mt_dma_empty(dma_dev) && dma_slot) { dbg("%s(%d), nb_dq %u\n", __func__, s->idx, nb_dq); int32_t frame_recv_size = rv_slot_get_frame_size(dma_slot); @@ -1401,18 +1462,19 @@ static int rv_dma_dequeue(struct st_rx_video_session_impl* s) { return 0; } -static inline uint32_t rfc4175_rtp_seq_id(struct st20_rfc4175_rtp_hdr* rtp) { +static inline uint32_t rfc4175_rtp_seq_id(struct st20_rfc4175_rtp_hdr *rtp) { uint16_t seq_id_base = ntohs(rtp->base.seq_number); uint16_t seq_id_ext = ntohs(rtp->seq_number_ext); uint32_t seq_id = (uint32_t)seq_id_base | (((uint32_t)seq_id_ext) << 16); return seq_id; } -static inline void rv_tp_pkt_handle(struct st_rx_video_session_impl* s, - struct rte_mbuf* mbuf, enum mtl_session_port s_port, - struct st_rx_video_slot_impl* slot, uint32_t tmstamp, - int pkt_idx) { - struct st_rx_video_tp* tp = s->tp; +static inline void rv_tp_pkt_handle(struct st_rx_video_session_impl *s, + struct rte_mbuf *mbuf, + enum mtl_session_port s_port, + struct st_rx_video_slot_impl *slot, + uint32_t tmstamp, int pkt_idx) { + struct st_rx_video_tp *tp = s->tp; if (s->cur_succ_burst_cnt > (tp->pass.cinst_max_narrow / 2)) { /* untrusted result */ tp->stat_untrusted_pkts++; @@ -1423,35 +1485,38 @@ static inline void rv_tp_pkt_handle(struct st_rx_video_session_impl* s, tp->stat_untrusted_pkts++; return; } - struct mtl_main_impl* impl = rv_get_impl(s); + struct mtl_main_impl *impl = rv_get_impl(s); enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); uint64_t pkt_ns = mt_mbuf_time_stamp(impl, mbuf, port); - struct st_rv_tp_slot* tp_slot = &tp->slots[slot->idx][s_port]; - dbg("%s(%d,%d), tmstamp %u pkt_ns %" PRIu64 " pkt_idx %d\n", __func__, s->idx, s_port, - tmstamp, pkt_ns, pkt_idx); + struct st_rv_tp_slot *tp_slot = &tp->slots[slot->idx][s_port]; + dbg("%s(%d,%d), tmstamp %u pkt_ns %" PRIu64 " pkt_idx %d\n", __func__, s->idx, + s_port, tmstamp, pkt_ns, pkt_idx); rv_tp_on_packet(s, s_port, tp_slot, tmstamp, pkt_ns, pkt_idx); } -static inline void* rv_frame_memcpy(void* dst, const void* src, size_t n) { +static inline void *rv_frame_memcpy(void *dst, const void *src, size_t n) { /* not use rte_memcpy since it find performance issue on writing frame */ return memcpy(dst, src, n); } -static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mbuf* mbuf, +static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, + struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread) { - struct st20_rx_ops* ops = &s->ops; + struct st20_rx_ops *ops = &s->ops; // size_t hdr_offset = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; size_t hdr_offset = sizeof(struct st_rfc4175_video_hdr) - sizeof(struct st20_rfc4175_rtp_hdr); - struct st20_rfc4175_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st20_rfc4175_rtp_hdr*, hdr_offset); - void* payload = &rtp[1]; + struct st20_rfc4175_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st20_rfc4175_rtp_hdr *, hdr_offset); + void *payload = &rtp[1]; uint16_t line1_number = ntohs(rtp->row_number); /* 0 to 1079 for 1080p */ bool second_field = (line1_number & ST20_SECOND_FIELD) ? true : false; - if (second_field) line1_number &= ~ST20_SECOND_FIELD; - uint16_t line1_offset = ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ - struct st20_rfc4175_extra_rtp_hdr* extra_rtp = NULL; + if (second_field) + line1_number &= ~ST20_SECOND_FIELD; + uint16_t line1_offset = + ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ + struct st20_rfc4175_extra_rtp_hdr *extra_rtp = NULL; if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { line1_offset &= ~ST20_SRD_OFFSET_CONTINUATION; extra_rtp = payload; @@ -1466,21 +1531,21 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb uint32_t seq_id_u32 = rfc4175_rtp_seq_id(rtp); uint8_t payload_type = rtp->base.payload_type; int pkt_idx = -1, ret; - struct rte_mbuf* mbuf_next = mbuf->next; + struct rte_mbuf *mbuf_next = mbuf->next; dbg("%s(%d,%d): line info %u %u %u\n", __func__, s->idx, s_port, line1_number, line1_offset, line1_length); if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, - payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, + s_port, payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->base.ssrc); - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, - ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, + ssrc, ops->ssrc); if (ssrc != ops->ssrc) { s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; @@ -1502,7 +1567,8 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb /* find the target slot by tmstamp */ bool exist_ts = false; - struct st_rx_video_slot_impl* slot = rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); + struct st_rx_video_slot_impl *slot = + rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); if (!slot || !slot->frame) { if (exist_ts) { s->stat_pkts_redundant_dropped++; @@ -1513,11 +1579,12 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb return -EIO; } - /* special MTL extension to carry optional meta data between tx and rx, not standard of - * ST2110 */ + /* special MTL extension to carry optional meta data between tx and rx, not + * standard of ST2110 */ if (line1_length & ST20_LEN_USER_META) { line1_length &= ~ST20_LEN_USER_META; - dbg("%s(%d,%d): ST20_LEN_USER_META %u\n", __func__, s->idx, s_port, line1_length); + dbg("%s(%d,%d): ST20_LEN_USER_META %u\n", __func__, s->idx, s_port, + line1_length); if (line1_length <= slot->frame->user_meta_buffer_size) { rte_memcpy(slot->frame->user_meta, payload, line1_length); slot->frame->user_meta_data_size = line1_length; @@ -1529,7 +1596,7 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb return 0; } - uint8_t* bitmap = slot->frame_bitmap; + uint8_t *bitmap = slot->frame_bitmap; slot->second_field = second_field; /* calculate offset */ @@ -1537,20 +1604,22 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb offset = line1_number * (uint32_t)s->st20_linesize + line1_offset / s->st20_pg.coverage * s->st20_pg.size; size_t payload_length = line1_length; - if (extra_rtp) payload_length += ntohs(extra_rtp->row_length); + if (extra_rtp) + payload_length += ntohs(extra_rtp->row_length); if ((offset + payload_length) > s->st20_fb_size + s->st20_bytes_in_line - s->st20_linesize) { - dbg("%s(%d,%d): invalid offset %u frame buffer size %" PRIu64 "\n", __func__, s->idx, - s_port, offset, s->st20_fb_size); - dbg("%s, number %u offset %u len %u\n", __func__, line1_number, line1_offset, - line1_length); + dbg("%s(%d,%d): invalid offset %u frame buffer size %" PRIu64 "\n", + __func__, s->idx, s_port, offset, s->st20_fb_size); + dbg("%s, number %u offset %u len %u\n", __func__, line1_number, + line1_offset, line1_length); s->stat_pkts_offset_dropped++; return -EIO; } /* check if valid pkt len */ size_t pkt_payload_len = mbuf->pkt_len - sizeof(struct st_rfc4175_video_hdr); - if (extra_rtp) pkt_payload_len -= sizeof(*extra_rtp); + if (extra_rtp) + pkt_payload_len -= sizeof(*extra_rtp); if (pkt_payload_len != payload_length) { dbg("%s, invalid pkt_payload_len %" PRIu64 " payload_length %" PRIu64 " retransmit %d\n", @@ -1567,16 +1636,16 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb else pkt_idx = seq_id_u32 + (0xFFFFFFFF - slot->seq_id_base_u32) + 1; if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, - pkt_idx, slot->seq_id_base_u32); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, + s_port, pkt_idx, slot->seq_id_base_u32); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, s_port, - pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, + s_port, pkt_idx); s->stat_pkts_redundant_dropped++; slot->pkts_recv_per_port[s_port]++; /* tp for the redundant packet */ @@ -1591,23 +1660,24 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb /* the first pkt should always dispatch to control thread */ if (ctrl_thread) { if (offset % payload_length) { /* GPM_SL packing */ - int bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); + int bytes_in_pkt = + ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); int pkts_in_line = (s->st20_bytes_in_line / bytes_in_pkt) + 1; int pixel_in_pkt = (ops->width + pkts_in_line - 1) / pkts_in_line; pkt_idx = line1_number * pkts_in_line + line1_offset / pixel_in_pkt; - dbg("%s(%d,%d), GPM_SL pkts_in_line %d pixel_in_pkt %d pkt_idx %d\n", __func__, - s->idx, s_port, pkts_in_line, pixel_in_pkt, pkt_idx); + dbg("%s(%d,%d), GPM_SL pkts_in_line %d pixel_in_pkt %d pkt_idx %d\n", + __func__, s->idx, s_port, pkts_in_line, pixel_in_pkt, pkt_idx); } else { pkt_idx = offset / payload_length; } slot->seq_id_base_u32 = seq_id_u32 - pkt_idx; slot->seq_id_got = true; mt_bitmap_test_and_set(bitmap, pkt_idx); - dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, seq_id_u32, - tmstamp); + dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, + seq_id_u32, tmstamp); } else { - dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, s->idx, - s_port, seq_id_u32, line1_number, line1_offset); + dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, + s->idx, s_port, seq_id_u32, line1_number, line1_offset); s->stat_pkts_idx_dropped++; return -EIO; } @@ -1615,15 +1685,16 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb slot->last_pkt_idx = pkt_idx; /* if enable_timing_parser */ - if (s->enable_timing_parser) rv_tp_pkt_handle(s, mbuf, s_port, slot, tmstamp, pkt_idx); + if (s->enable_timing_parser) + rv_tp_pkt_handle(s, mbuf, s_port, slot, tmstamp, pkt_idx); bool dma_copy = false; bool need_copy = true; - struct mtl_dma_lender_dev* dma_dev = s->dma_dev; + struct mtl_dma_lender_dev *dma_dev = s->dma_dev; if (s->st20_uframe_size) { /* user frame mode, pass to app to handle the payload */ - struct st20_rx_uframe_pg_meta* pg_meta = &s->pg_meta; + struct st20_rx_uframe_pg_meta *pg_meta = &s->pg_meta; pg_meta->payload = payload; pg_meta->row_length = line1_length; pg_meta->row_number = line1_number; @@ -1648,12 +1719,15 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb payload + line1_length, payload_length - line1_length); } else if (dma_dev && (payload_length > ST_RX_VIDEO_DMA_MIN_SIZE) && !mt_dma_full(dma_dev) && - !rv_frame_payload_cross_page(s, slot->frame, offset, payload_length)) { + !rv_frame_payload_cross_page(s, slot->frame, offset, + payload_length)) { rte_iova_t payload_iova = rte_pktmbuf_iova_offset(mbuf, sizeof(struct st_rfc4175_video_hdr)); - if (extra_rtp) payload_iova += sizeof(*extra_rtp); - ret = mt_dma_copy(dma_dev, rv_frame_get_offset_iova(s, slot->frame, offset), - payload_iova, payload_length); + if (extra_rtp) + payload_iova += sizeof(*extra_rtp); + ret = + mt_dma_copy(dma_dev, rv_frame_get_offset_iova(s, slot->frame, offset), + payload_iova, payload_length); if (ret < 0) { /* use cpu copy if dma copy fail */ rv_frame_memcpy(slot->frame->addr + offset, payload, payload_length); @@ -1663,7 +1737,8 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb st_rx_mbuf_set_len(mbuf, payload_length); ret = mt_dma_borrow_mbuf(dma_dev, mbuf); if (ret) - err("%s(%d,%d), mbuf copied but not enqueued \n", __func__, s->idx, s_port); + err("%s(%d,%d), mbuf copied but not enqueued \n", __func__, s->idx, + s_port); dma_copy = true; s->stat_pkts_dma++; } @@ -1690,61 +1765,66 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl* s, struct rte_mb size_t frame_recv_size = rv_slot_get_frame_size(slot); bool end_frame = false; if (dma_dev) { - if (frame_recv_size >= s->st20_frame_size && mt_dma_empty(dma_dev)) end_frame = true; + if (frame_recv_size >= s->st20_frame_size && mt_dma_empty(dma_dev)) + end_frame = true; } else { - if (frame_recv_size >= s->st20_frame_size) end_frame = true; + if (frame_recv_size >= s->st20_frame_size) + end_frame = true; } if (end_frame) { dbg("%s(%d,%d): full frame on %p(%" PRIu64 ")\n", __func__, s->idx, s_port, slot->frame->addr, frame_recv_size); - dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, slot->tmstamp, - slot->idx); + dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, + slot->tmstamp, slot->idx); /* end of frame */ rv_slot_full_frame(s, slot); } - if (dma_copy) s->dma_copy = true; + if (dma_copy) + s->dma_copy = true; return 0; } -static int rv_handle_rtp_pkt(struct st_rx_video_session_impl* s, struct rte_mbuf* mbuf, +static int rv_handle_rtp_pkt(struct st_rx_video_session_impl *s, + struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread) { MTL_MAY_UNUSED(s_port); MTL_MAY_UNUSED(ctrl_thread); - struct st20_rx_ops* ops = &s->ops; - size_t hdr_offset = sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); - struct st_rfc3550_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr*, hdr_offset); + struct st20_rx_ops *ops = &s->ops; + size_t hdr_offset = + sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); + struct st_rfc3550_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr *, hdr_offset); uint32_t tmstamp = ntohl(rtp->tmstamp); uint16_t seq_id = ntohs(rtp->seq_number); - uint32_t seq_id_u32 = rfc4175_rtp_seq_id((struct st20_rfc4175_rtp_hdr*)rtp); + uint32_t seq_id_u32 = rfc4175_rtp_seq_id((struct st20_rfc4175_rtp_hdr *)rtp); uint8_t payload_type = rtp->payload_type; int pkt_idx = -1; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, - payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, + s_port, payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, - ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, + ssrc, ops->ssrc); s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } } /* find the target slot by tmstamp */ - struct st_rx_video_slot_impl* slot = rv_rtp_slot_by_tmstamp(s, tmstamp); + struct st_rx_video_slot_impl *slot = rv_rtp_slot_by_tmstamp(s, tmstamp); if (!slot || !slot->frame_bitmap) { s->stat_pkts_no_slot++; return -ENOMEM; } - uint8_t* bitmap = slot->frame_bitmap; + uint8_t *bitmap = slot->frame_bitmap; /* check if the same pks got already */ if (slot->seq_id_got) { @@ -1761,14 +1841,15 @@ static int rv_handle_rtp_pkt(struct st_rx_video_session_impl* s, struct rte_mbuf } if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, - pkt_idx, slot->seq_id_base); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, + s_port, pkt_idx, slot->seq_id_base); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, idx, s_port, pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, idx, s_port, + pkt_idx); s->stat_pkts_redundant_dropped++; return 0; } @@ -1784,11 +1865,11 @@ static int rv_handle_rtp_pkt(struct st_rx_video_session_impl* s, struct rte_mbuf s->port_user_stats[MTL_SESSION_PORT_P].frames++; mt_bitmap_test_and_set(bitmap, 0); pkt_idx = 0; - dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, idx, s_port, seq_id, - tmstamp); + dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, idx, s_port, + seq_id, tmstamp); } else { - dbg("%s(%d,%d), drop seq_id %d as base seq id %d not got\n", __func__, s->idx, - s_port, seq_id, slot->seq_id_base); + dbg("%s(%d,%d), drop seq_id %d as base seq id %d not got\n", __func__, + s->idx, s_port, seq_id, slot->seq_id_base); s->stat_pkts_idx_dropped++; return -EIO; } @@ -1796,10 +1877,10 @@ static int rv_handle_rtp_pkt(struct st_rx_video_session_impl* s, struct rte_mbuf slot->last_pkt_idx = pkt_idx; /* enqueue the packet ring to app */ - int ret = rte_ring_sp_enqueue(s->rtps_ring, (void*)mbuf); + int ret = rte_ring_sp_enqueue(s->rtps_ring, (void *)mbuf); if (ret < 0) { - dbg("%s(%d,%d), drop as rtps ring full, pkt_idx %d base %u\n", __func__, idx, s_port, - pkt_idx, slot->seq_id_base); + dbg("%s(%d,%d), drop as rtps ring full, pkt_idx %d base %u\n", __func__, + idx, s_port, pkt_idx, slot->seq_id_base); s->stat_pkts_rtp_ring_full++; return -EIO; } @@ -1817,11 +1898,11 @@ struct st22_box { }; /* Video Support Box and Color Specification Box */ -static int rv_parse_st22_boxes(struct st_rx_video_session_impl* s, void* boxes, - struct st_rx_video_slot_impl* slot) { +static int rv_parse_st22_boxes(struct st_rx_video_session_impl *s, void *boxes, + struct st_rx_video_slot_impl *slot) { uint32_t jpvs_len = 0; uint32_t colr_len = 0; - struct st22_box* box; + struct st22_box *box; box = boxes; if (0 == strncmp(box->tbox, "jpvs", 4)) { @@ -1836,12 +1917,14 @@ static int rv_parse_st22_boxes(struct st_rx_video_session_impl* s, void* boxes, } if ((jpvs_len + colr_len) > 512) { - err("%s(%d): err jpvs_len %u colr_len %u\n", __func__, s->idx, jpvs_len, colr_len); + err("%s(%d): err jpvs_len %u colr_len %u\n", __func__, s->idx, jpvs_len, + colr_len); return -EIO; } slot->st22_box_hdr_length = jpvs_len + colr_len; - dbg("%s(%d): st22_box_hdr_length %u\n", __func__, s->idx, slot->st22_box_hdr_length); + dbg("%s(%d): st22_box_hdr_length %u\n", __func__, s->idx, + slot->st22_box_hdr_length); if (slot->st22_box_hdr_length) { s->stat_st22_boxes++; @@ -1857,22 +1940,25 @@ static int rv_parse_st22_boxes(struct st_rx_video_session_impl* s, void* boxes, return 0; } -static int rv_handle_st22_pkt(struct st_rx_video_session_impl* s, struct rte_mbuf* mbuf, +static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, + struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread) { MTL_MAY_UNUSED(s_port); MTL_MAY_UNUSED(ctrl_thread); - struct st20_rx_ops* ops = &s->ops; + struct st20_rx_ops *ops = &s->ops; // size_t hdr_offset = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; - size_t hdr_offset = - sizeof(struct st22_rfc9134_video_hdr) - sizeof(struct st22_rfc9134_rtp_hdr); - struct st22_rfc9134_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st22_rfc9134_rtp_hdr*, hdr_offset); - void* payload = &rtp[1]; - uint16_t payload_length = mbuf->data_len - sizeof(struct st22_rfc9134_video_hdr); + size_t hdr_offset = sizeof(struct st22_rfc9134_video_hdr) - + sizeof(struct st22_rfc9134_rtp_hdr); + struct st22_rfc9134_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st22_rfc9134_rtp_hdr *, hdr_offset); + void *payload = &rtp[1]; + uint16_t payload_length = + mbuf->data_len - sizeof(struct st22_rfc9134_video_hdr); uint32_t tmstamp = ntohl(rtp->base.tmstamp); uint16_t seq_id = ntohs(rtp->base.seq_number); uint8_t payload_type = rtp->base.payload_type; - uint16_t p_counter = (uint16_t)rtp->p_counter_lo + ((uint16_t)rtp->p_counter_hi << 8); + uint16_t p_counter = + (uint16_t)rtp->p_counter_lo + ((uint16_t)rtp->p_counter_hi << 8); uint16_t sep_counter = (uint16_t)rtp->sep_counter_lo + ((uint16_t)rtp->sep_counter_hi << 5); int pkt_counter = p_counter + sep_counter * 2048; @@ -1880,16 +1966,16 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl* s, struct rte_mbu int ret; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, - payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, + s_port, payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->base.ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, - ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, + ssrc, ops->ssrc); s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } @@ -1909,15 +1995,16 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl* s, struct rte_mbu } else { if (rtp->interlaced) { s->stat_pkts_wrong_interlace_dropped++; - dbg("%s(%d,%d), rtp interlaced 0x%x set for progressive\n", __func__, s->idx, - s_port, rtp->interlaced); + dbg("%s(%d,%d), rtp interlaced 0x%x set for progressive\n", __func__, + s->idx, s_port, rtp->interlaced); return -EINVAL; } } /* find the target slot by tmstamp */ bool exist_ts = false; - struct st_rx_video_slot_impl* slot = rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); + struct st_rx_video_slot_impl *slot = + rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); if (!slot || !slot->frame) { if (exist_ts) { s->stat_pkts_redundant_dropped++; @@ -1927,14 +2014,14 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl* s, struct rte_mbu } return -EIO; } - uint8_t* bitmap = slot->frame_bitmap; + uint8_t *bitmap = slot->frame_bitmap; slot->second_field = (rtp->interlaced == 0x3) ? true : false; - dbg("%s(%d,%d), seq_id %d kmode %u trans_order %u\n", __func__, s->idx, s_port, seq_id, - rtp->kmode, rtp->trans_order); - dbg("%s(%d,%d), seq_id %d p_counter %u sep_counter %u\n", __func__, s->idx, s_port, - seq_id, p_counter, sep_counter); + dbg("%s(%d,%d), seq_id %d kmode %u trans_order %u\n", __func__, s->idx, + s_port, seq_id, rtp->kmode, rtp->trans_order); + dbg("%s(%d,%d), seq_id %d p_counter %u sep_counter %u\n", __func__, s->idx, + s_port, seq_id, p_counter, sep_counter); if (slot->seq_id_got) { if (!rtp->base.marker && (payload_length != slot->st22_payload_length)) { @@ -1947,16 +2034,16 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl* s, struct rte_mbu else pkt_idx = seq_id + (0xFFFF - slot->seq_id_base) + 1; if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, - pkt_idx, slot->seq_id_base); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, + s_port, pkt_idx, slot->seq_id_base); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, s_port, - pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, + s_port, pkt_idx); s->stat_pkts_redundant_dropped++; slot->pkts_recv_per_port[s_port]++; return 0; @@ -1996,11 +2083,12 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl* s, struct rte_mbu payload += slot->st22_box_hdr_length; payload_length -= slot->st22_box_hdr_length; } else { - offset = pkt_counter * slot->st22_payload_length - slot->st22_box_hdr_length; + offset = + pkt_counter * slot->st22_payload_length - slot->st22_box_hdr_length; } if ((offset + payload_length) > s->st20_frame_size) { - dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, s->idx, s_port, - offset, s->st20_frame_size); + dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, + s->idx, s_port, offset, s->st20_frame_size); s->stat_pkts_offset_dropped++; return -EIO; } @@ -2020,34 +2108,39 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl* s, struct rte_mbu if (s->st22_expect_frame_size) { size_t rece_frame_size = rv_slot_get_frame_size(slot); - dbg("%s(%d,%d): marker got, frame size %" PRIu64 " %" PRIu64 ", tmstamp %u\n", - __func__, s->idx, s_port, rece_frame_size, s->st22_expect_frame_size, tmstamp); + dbg("%s(%d,%d): marker got, frame size %" PRIu64 " %" PRIu64 + ", tmstamp %u\n", + __func__, s->idx, s_port, rece_frame_size, s->st22_expect_frame_size, + tmstamp); if (s->st22_expect_frame_size == rece_frame_size) { rv_st22_slot_full_frame(s, slot); } else { dbg("%s(%d,%d): still has %" PRIu64 " bytes unarrived pkt before marker, tmstamp %u\n", - __func__, s->idx, s_port, s->st22_expect_frame_size - rece_frame_size, tmstamp); + __func__, s->idx, s_port, s->st22_expect_frame_size - rece_frame_size, + tmstamp); } } return 0; } -static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, - struct rte_mbuf* mbuf, enum mtl_session_port s_port, +static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, + struct rte_mbuf *mbuf, + enum mtl_session_port s_port, bool ctrl_thread) { MTL_MAY_UNUSED(ctrl_thread); - struct st20_rx_ops* ops = &s->ops; + struct st20_rx_ops *ops = &s->ops; // size_t hdr_offset = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; size_t hdr_offset = sizeof(struct st_rfc4175_video_hdr) - sizeof(struct st20_rfc4175_rtp_hdr); - struct st20_rfc4175_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st20_rfc4175_rtp_hdr*, hdr_offset); - void* payload = &rtp[1]; + struct st20_rfc4175_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st20_rfc4175_rtp_hdr *, hdr_offset); + void *payload = &rtp[1]; uint16_t line1_number = ntohs(rtp->row_number); /* 0 to 1079 for 1080p */ - uint16_t line1_offset = ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ - struct st20_rfc4175_extra_rtp_hdr* extra_rtp = NULL; + uint16_t line1_offset = + ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ + struct st20_rfc4175_extra_rtp_hdr *extra_rtp = NULL; if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { line1_offset &= ~ST20_SRD_OFFSET_CONTINUATION; extra_rtp = payload; @@ -2058,20 +2151,20 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, uint32_t seq_id_u32 = rfc4175_rtp_seq_id(rtp); uint8_t payload_type = rtp->base.payload_type; int pkt_idx = -1; - struct st_rx_video_hdr_split_info* hdr_split = &s->hdr_split_info[s_port]; - struct rte_mbuf* mbuf_next = mbuf->next; + struct st_rx_video_hdr_split_info *hdr_split = &s->hdr_split_info[s_port]; + struct rte_mbuf *mbuf_next = mbuf->next; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, - payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, + s_port, payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->base.ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, - ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, + ssrc, ops->ssrc); s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } @@ -2082,12 +2175,13 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, } if (mbuf_next && mbuf_next->data_len) { - payload = rte_pktmbuf_mtod(mbuf_next, void*); + payload = rte_pktmbuf_mtod(mbuf_next, void *); } /* find the target slot by tmstamp */ bool exist_ts = false; - struct st_rx_video_slot_impl* slot = rv_slot_by_tmstamp(s, tmstamp, payload, &exist_ts); + struct st_rx_video_slot_impl *slot = + rv_slot_by_tmstamp(s, tmstamp, payload, &exist_ts); if (!slot || !slot->frame) { if (exist_ts) { s->stat_pkts_redundant_dropped++; @@ -2097,7 +2191,7 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, } return -EIO; } - uint8_t* bitmap = slot->frame_bitmap; + uint8_t *bitmap = slot->frame_bitmap; slot->second_field = (line1_number & ST20_SECOND_FIELD) ? true : false; line1_number &= ~ST20_SECOND_FIELD; @@ -2108,15 +2202,15 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, else pkt_idx = seq_id_u32 + (0xFFFFFFFF - slot->seq_id_base_u32) + 1; if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, - pkt_idx, slot->seq_id_base_u32); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, + s_port, pkt_idx, slot->seq_id_base_u32); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, s_port, - pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, + s_port, pkt_idx); s->stat_pkts_redundant_dropped++; slot->pkts_recv_per_port[s_port]++; return 0; @@ -2130,11 +2224,11 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, slot->seq_id_got = true; mt_bitmap_test_and_set(bitmap, 0); pkt_idx = 0; - dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, seq_id_u32, - tmstamp); + dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, + seq_id_u32, tmstamp); } else { - dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, s->idx, - s_port, seq_id_u32, line1_number, line1_offset); + dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, + s->idx, s_port, seq_id_u32, line1_number, line1_offset); s->stat_pkts_idx_dropped++; return -EIO; } @@ -2142,15 +2236,16 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, slot->last_pkt_idx = pkt_idx; /* calculate offset */ - uint32_t offset = - (line1_number * ops->width + line1_offset) / s->st20_pg.coverage * s->st20_pg.size; + uint32_t offset = (line1_number * ops->width + line1_offset) / + s->st20_pg.coverage * s->st20_pg.size; size_t payload_length = line1_length; - if (extra_rtp) payload_length += ntohs(extra_rtp->row_length); + if (extra_rtp) + payload_length += ntohs(extra_rtp->row_length); if ((offset + payload_length) > s->st20_frame_size) { - dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, s->idx, s_port, - offset, s->st20_frame_size); - dbg("%s, number %u offset %u len %u\n", __func__, line1_number, line1_offset, - line1_length); + dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, + s->idx, s_port, offset, s->st20_frame_size); + dbg("%s, number %u offset %u len %u\n", __func__, line1_number, + line1_offset, line1_length); s->stat_pkts_offset_dropped++; return -EIO; } @@ -2167,22 +2262,26 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, hdr_split->cur_frame_addr = payload; /* Cut RTE_PKTMBUF_HEADROOM since rte_mbuf_data_iova_default has offset */ hdr_split->cur_frame_mbuf_idx = - (payload - RTE_PKTMBUF_HEADROOM - hdr_split->frames) / ST_VIDEO_BPM_SIZE; - dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u\n", __func__, s->idx, s_port, - hdr_split->cur_frame_addr, slot->cur_frame_mbuf_idx); + (payload - RTE_PKTMBUF_HEADROOM - hdr_split->frames) / + ST_VIDEO_BPM_SIZE; + dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u\n", __func__, s->idx, + s_port, hdr_split->cur_frame_addr, slot->cur_frame_mbuf_idx); if (hdr_split->cur_frame_mbuf_idx % hdr_split->mbufs_per_frame) { s->stat_mismatch_hdr_split_frame++; - dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u mbufs_per_frame %u\n", __func__, - s->idx, s_port, hdr_split->cur_frame_addr, hdr_split->cur_frame_mbuf_idx, - hdr_split->mbufs_per_frame); + dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u mbufs_per_frame %u\n", + __func__, s->idx, s_port, hdr_split->cur_frame_addr, + hdr_split->cur_frame_mbuf_idx, hdr_split->mbufs_per_frame); } } else { - void* expect_payload = hdr_split->cur_frame_addr + pkt_idx * ST_VIDEO_BPM_SIZE; + void *expect_payload = + hdr_split->cur_frame_addr + pkt_idx * ST_VIDEO_BPM_SIZE; if (expect_payload != payload) { - dbg("%s(%d,%d), payload mismatch %p:%p on pkt %d\n", __func__, s->idx, s_port, - payload, expect_payload, pkt_idx); - /* may caused by ooo, imiss, the last pkt(ddp not split for unknow cause) */ - if (marker && (expect_payload < (hdr_split->frames + hdr_split->frames_size))) { + dbg("%s(%d,%d), payload mismatch %p:%p on pkt %d\n", __func__, s->idx, + s_port, payload, expect_payload, pkt_idx); + /* may caused by ooo, imiss, the last pkt(ddp not split for unknow cause) + */ + if (marker && + (expect_payload < (hdr_split->frames + hdr_split->frames_size))) { need_copy = true; s->stat_pkts_copy_hdr_split++; } else { /* no way to recover since nic is in writing dram */ @@ -2209,18 +2308,18 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl* s, /* check if frame is full */ size_t frame_recv_size = rv_slot_get_frame_size(slot); if (frame_recv_size >= s->st20_frame_size) { - dbg("%s(%d,%d): full frame on %p(%d)\n", __func__, s->idx, s_port, slot->frame->addr, - frame_recv_size); - dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, slot->tmstamp, - slot->idx); + dbg("%s(%d,%d): full frame on %p(%d)\n", __func__, s->idx, s_port, + slot->frame->addr, frame_recv_size); + dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, + slot->tmstamp, slot->idx); rv_slot_full_frame(s, slot); } return 0; } -static int rv_uinit_pkt_lcore(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s) { +static int rv_uinit_pkt_lcore(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { int idx = s->idx; if (rte_atomic32_read(&s->pkt_lcore_active)) { @@ -2246,14 +2345,14 @@ static int rv_uinit_pkt_lcore(struct mtl_main_impl* impl, return 0; } -static int rv_pkt_lcore_func(void* args) { - struct st_rx_video_session_impl* s = args; +static int rv_pkt_lcore_func(void *args) { + struct st_rx_video_session_impl *s = args; int idx = s->idx, ret; - struct rte_mbuf* pkt = NULL; + struct rte_mbuf *pkt = NULL; info("%s(%d), start\n", __func__, idx); while (rte_atomic32_read(&s->pkt_lcore_active)) { - ret = rte_ring_sc_dequeue(s->pkt_lcore_ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(s->pkt_lcore_ring, (void **)&pkt); if (ret >= 0) { rv_handle_frame_pkt(s, pkt, MTL_SESSION_PORT_P, true); rte_pktmbuf_free(pkt); @@ -2265,16 +2364,17 @@ static int rv_pkt_lcore_func(void* args) { return 0; } -static int rv_init_pkt_lcore(struct mtl_main_impl* impl, - struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s) { +static int rv_init_pkt_lcore(struct mtl_main_impl *impl, + struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s) { char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count, lcore; int mgr_idx = mgr->idx, idx = s->idx, ret; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_RX_VIDEO_PREFIX, mgr_idx, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->rx_burst_size; ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { @@ -2283,7 +2383,8 @@ static int rv_init_pkt_lcore(struct mtl_main_impl* impl, } s->pkt_lcore_ring = ring; - ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_RXV_RING_LCORE, s->socket_id); + ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_RXV_RING_LCORE, + s->socket_id); if (ret < 0) { err("%s(%d,%d), get lcore fail %d\n", __func__, mgr_idx, idx, ret); rv_uinit_pkt_lcore(impl, s); @@ -2304,12 +2405,13 @@ static int rv_init_pkt_lcore(struct mtl_main_impl* impl, return 0; } -static int rv_init_st22(struct st_rx_video_session_impl* s, - struct st22_rx_ops* st22_frame_ops) { - struct st22_rx_video_info* st22_info; +static int rv_init_st22(struct st_rx_video_session_impl *s, + struct st22_rx_ops *st22_frame_ops) { + struct st22_rx_video_info *st22_info; st22_info = mt_rte_zmalloc_socket(sizeof(*st22_info), s->socket_id); - if (!st22_info) return -ENOMEM; + if (!st22_info) + return -ENOMEM; st22_info->notify_frame_ready = st22_frame_ops->notify_frame_ready; @@ -2320,7 +2422,7 @@ static int rv_init_st22(struct st_rx_video_session_impl* s, return 0; } -static int rv_uinit_st22(struct st_rx_video_session_impl* s) { +static int rv_uinit_st22(struct st_rx_video_session_impl *s) { if (s->st22_info) { mt_rte_free(s->st22_info); s->st22_info = NULL; @@ -2329,7 +2431,8 @@ static int rv_uinit_st22(struct st_rx_video_session_impl* s) { return 0; } -static int rv_uinit_sw(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { +static int rv_uinit_sw(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { rv_tp_uinit(s); rv_uinit_pkt_lcore(impl, s); rv_free_dma(impl, s); @@ -2340,9 +2443,11 @@ static int rv_uinit_sw(struct mtl_main_impl* impl, struct st_rx_video_session_im return 0; } -static int rv_init_sw(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, struct st22_rx_ops* st22_ops) { - struct st20_rx_ops* ops = &s->ops; +static int rv_init_sw(struct mtl_main_impl *impl, + struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, + struct st22_rx_ops *st22_ops) { + struct st20_rx_ops *ops = &s->ops; enum st20_type type = ops->type; int idx = s->idx; int ret; @@ -2381,7 +2486,7 @@ static int rv_init_sw(struct mtl_main_impl* impl, struct st_rx_video_sessions_mg } if (type == ST20_TYPE_SLICE_LEVEL) { - struct st20_rx_slice_meta* slice_meta = &s->slice_meta; + struct st20_rx_slice_meta *slice_meta = &s->slice_meta; slice_meta->width = ops->width; slice_meta->height = ops->height; slice_meta->fmt = ops->fmt; @@ -2395,14 +2500,15 @@ static int rv_init_sw(struct mtl_main_impl* impl, struct st_rx_video_sessions_mg if (s->st20_uframe_size) { /* user frame mode */ - struct st20_rx_uframe_pg_meta* pg_meta = &s->pg_meta; + struct st20_rx_uframe_pg_meta *pg_meta = &s->pg_meta; pg_meta->width = ops->width; pg_meta->height = ops->height; pg_meta->fmt = ops->fmt; pg_meta->fps = ops->fps; pg_meta->frame_total_size = s->st20_frame_size; pg_meta->uframe_total_size = s->st20_uframe_size; - info("%s(%d), uframe size %" PRIu64 "\n", __func__, idx, s->st20_uframe_size); + info("%s(%d), uframe size %" PRIu64 "\n", __func__, idx, + s->st20_uframe_size); } s->has_pkt_lcore = false; @@ -2421,27 +2527,31 @@ static int rv_init_sw(struct mtl_main_impl* impl, struct st_rx_video_sessions_mg if (st20_is_frame_type(type)) { /* for traffic > 40g, two lcore used */ if ((bps / (1000 * 1000)) > (40 * 1000)) { - if (!s->dma_dev) pkt_handle_lcore = true; + if (!s->dma_dev) + pkt_handle_lcore = true; } if (ops->flags & ST20_RX_FLAG_USE_MULTI_THREADS) { - info("%s(%d), user enable ST20_RX_FLAG_USE_MULTI_THREADS\n", __func__, idx); + info("%s(%d), user enable ST20_RX_FLAG_USE_MULTI_THREADS\n", __func__, + idx); pkt_handle_lcore = true; } } /* only one core for hdr split mode */ - if (rv_is_hdr_split(s)) pkt_handle_lcore = false; + if (rv_is_hdr_split(s)) + pkt_handle_lcore = false; if (pkt_handle_lcore) { if (type == ST20_TYPE_SLICE_LEVEL) { - err("%s(%d), additional pkt lcore not support slice type\n", __func__, idx); + err("%s(%d), additional pkt lcore not support slice type\n", __func__, + idx); rv_uinit_sw(impl, s); return -EINVAL; } if (ops->num_port > 1) { - err("%s(%d), additional pkt lcore not support redundant, num_port %u\n", __func__, - idx, ops->num_port); + err("%s(%d), additional pkt lcore not support redundant, num_port %u\n", + __func__, idx, ops->num_port); rv_uinit_sw(impl, s); return -EINVAL; } @@ -2480,63 +2590,73 @@ static int rv_init_sw(struct mtl_main_impl* impl, struct st_rx_video_sessions_mg double sleep_ns = s->trs * 128; s->advice_sleep_us = sleep_ns / NS_PER_US; if (mt_user_tasklet_sleep(impl)) { - info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, s->advice_sleep_us); + info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, + s->advice_sleep_us); } return 0; } -static int rv_handle_detect_err(struct st_rx_video_session_impl* s, struct rte_mbuf* mbuf, - enum mtl_session_port s_port, bool ctrl_thread) { +static int rv_handle_detect_err(struct st_rx_video_session_impl *s, + struct rte_mbuf *mbuf, + enum mtl_session_port s_port, + bool ctrl_thread) { MTL_MAY_UNUSED(ctrl_thread); MTL_MAY_UNUSED(mbuf); - err_once("%s(%d,%d), detect fail, please choose the right format\n", __func__, s->idx, - s_port); + err_once("%s(%d,%d), detect fail, please choose the right format\n", __func__, + s->idx, s_port); return 0; } -static int rv_detect_change_status(struct st_rx_video_session_impl* s, +static int rv_detect_change_status(struct st_rx_video_session_impl *s, enum st20_detect_status new_status) { - if (s->detector.status == new_status) return 0; + if (s->detector.status == new_status) + return 0; s->detector.status = new_status; rv_init_pkt_handler(s); return 0; } -static int rv_handle_detect_pkt(struct st_rx_video_session_impl* s, struct rte_mbuf* mbuf, - enum mtl_session_port s_port, bool ctrl_thread) { +static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, + struct rte_mbuf *mbuf, + enum mtl_session_port s_port, + bool ctrl_thread) { int ret; - struct st20_rx_ops* ops = &s->ops; - struct st_rx_video_detector* detector = &s->detector; - struct st20_detect_meta* meta = &detector->meta; + struct st20_rx_ops *ops = &s->ops; + struct st_rx_video_detector *detector = &s->detector; + struct st20_detect_meta *meta = &detector->meta; size_t hdr_offset = sizeof(struct st_rfc4175_video_hdr) - sizeof(struct st20_rfc4175_rtp_hdr); - struct st20_rfc4175_rtp_hdr* rtp = - rte_pktmbuf_mtod_offset(mbuf, struct st20_rfc4175_rtp_hdr*, hdr_offset); - void* payload = &rtp[1]; + struct st20_rfc4175_rtp_hdr *rtp = + rte_pktmbuf_mtod_offset(mbuf, struct st20_rfc4175_rtp_hdr *, hdr_offset); + void *payload = &rtp[1]; uint16_t line1_number = ntohs(rtp->row_number); uint16_t line1_offset = ntohs(rtp->row_offset); /* detect field bit */ - if (line1_number & ST20_SECOND_FIELD) meta->interlaced = true; + if (line1_number & ST20_SECOND_FIELD) + meta->interlaced = true; line1_number &= ~ST20_SECOND_FIELD; - struct st20_rfc4175_extra_rtp_hdr* extra_rtp = NULL; + struct st20_rfc4175_extra_rtp_hdr *extra_rtp = NULL; if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { line1_offset &= ~ST20_SRD_OFFSET_CONTINUATION; extra_rtp = payload; payload += sizeof(*extra_rtp); } uint32_t payload_length = ntohs(rtp->row_length); - if (extra_rtp) payload_length += ntohs(extra_rtp->row_length); + if (extra_rtp) + payload_length += ntohs(extra_rtp->row_length); uint32_t tmstamp = ntohl(rtp->base.tmstamp); uint8_t payload_type = rtp->base.payload_type; MTL_MAY_UNUSED(ctrl_thread); /* only detect on the main port */ - if (MTL_SESSION_PORT_P != s_port) return 0; + if (MTL_SESSION_PORT_P != s_port) + return 0; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s, payload_type mismatch %d %d\n", __func__, payload_type, ops->payload_type); + dbg("%s, payload_type mismatch %d %d\n", __func__, payload_type, + ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } @@ -2549,9 +2669,11 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl* s, struct rte_m } /* detect continuous bit */ - if (extra_rtp) detector->single_line = false; + if (extra_rtp) + detector->single_line = false; /* detect bpm */ - if (payload_length % 180 != 0) detector->bpm = false; + if (payload_length % 180 != 0) + detector->bpm = false; /* on frame/field marker bit */ if (rtp->base.marker) { if (detector->frame_num < 3) { @@ -2568,8 +2690,8 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl* s, struct rte_m if (meta->fps != ST_FPS_MAX && meta->packing != ST20_PACKING_MAX) { if (!meta->height) { rv_detect_change_status(s, ST20_DETECT_STAT_FAIL); - err("%s(%d,%d): st20 failed to detect dimension, max_line: %d\n", __func__, - s->idx, s_port, line1_number); + err("%s(%d,%d): st20 failed to detect dimension, max_line: %d\n", + __func__, s->idx, s_port, line1_number); } else { /* detected */ ops->width = meta->width; ops->height = meta->height; @@ -2580,23 +2702,27 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl* s, struct rte_m struct st20_detect_reply reply = {0}; ret = ops->notify_detected(ops->priv, meta, &reply); if (ret < 0) { - err("%s(%d), notify_detected return fail %d\n", __func__, s->idx, ret); + err("%s(%d), notify_detected return fail %d\n", __func__, s->idx, + ret); rv_detect_change_status(s, ST20_DETECT_STAT_FAIL); return ret; } s->slice_lines = reply.slice_lines; s->st20_uframe_size = reply.uframe_size; - info("%s(%d), detected, slice_lines %u, uframe_size %" PRIu64 "\n", __func__, - s->idx, s->slice_lines, s->st20_uframe_size); + info("%s(%d), detected, slice_lines %u, uframe_size %" PRIu64 "\n", + __func__, s->idx, s->slice_lines, s->st20_uframe_size); } - if (!s->slice_lines) s->slice_lines = ops->height / 32; + if (!s->slice_lines) + s->slice_lines = ops->height / 32; s->slice_size = ops->width * s->slice_lines * s->st20_pg.size / s->st20_pg.coverage; s->st20_frames_cnt = ops->framebuff_cnt; s->st20_frame_size = ops->width * ops->height * s->st20_pg.size / s->st20_pg.coverage; - if (ops->interlaced) s->st20_frame_size = s->st20_frame_size >> 1; - s->st20_bytes_in_line = ops->width * s->st20_pg.size / s->st20_pg.coverage; + if (ops->interlaced) + s->st20_frame_size = s->st20_frame_size >> 1; + s->st20_bytes_in_line = + ops->width * s->st20_pg.size / s->st20_pg.coverage; s->st20_linesize = s->st20_bytes_in_line; if (ops->linesize > s->st20_linesize) s->st20_linesize = ops->linesize; @@ -2605,7 +2731,8 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl* s, struct rte_m return -EINVAL; } s->st20_fb_size = s->st20_linesize * ops->height; - if (ops->interlaced) s->st20_fb_size = s->st20_fb_size >> 1; + if (ops->interlaced) + s->st20_fb_size = s->st20_fb_size >> 1; /* at least 1000 byte for each packet */ s->st20_frame_bitmap_size = s->st20_frame_size / 1000 / 8; /* one line at line 2 packets for all the format */ @@ -2617,12 +2744,14 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl* s, struct rte_m rv_detect_change_status(s, ST20_DETECT_STAT_FAIL); return ret; } - rvs_mgr_update(s->parent); /* update mgr since we has new advice sleep us */ + rvs_mgr_update( + s->parent); /* update mgr since we has new advice sleep us */ rv_detect_change_status(s, ST20_DETECT_STAT_SUCCESS); - info("st20 detected(%d,%d): width: %d, height: %d, fps: %f\n", s->idx, s_port, - meta->width, meta->height, st_frame_rate(meta->fps)); - info("st20 detected(%d,%d): packing: %d, field: %s, pkts per %s: %d\n", s->idx, - s_port, meta->packing, meta->interlaced ? "interlaced" : "progressive", + info("st20 detected(%d,%d): width: %d, height: %d, fps: %f\n", s->idx, + s_port, meta->width, meta->height, st_frame_rate(meta->fps)); + info("st20 detected(%d,%d): packing: %d, field: %s, pkts per %s: %d\n", + s->idx, s_port, meta->packing, + meta->interlaced ? "interlaced" : "progressive", meta->interlaced ? "field" : "frame", detector->pkt_per_frame); } } @@ -2632,7 +2761,7 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl* s, struct rte_m return 0; } -static bool rv_simulate_pkt_loss(struct st_rx_video_session_impl* s) { +static bool rv_simulate_pkt_loss(struct st_rx_video_session_impl *s) { if (s->burst_loss_cnt == 0) { /* create a burst of pkt loss at fixed rate */ if (((float)rand() / (float)RAND_MAX) < s->sim_loss_rate) { @@ -2649,9 +2778,9 @@ static bool rv_simulate_pkt_loss(struct st_rx_video_session_impl* s) { return true; } -static int rv_handle_mbuf(void* priv, struct rte_mbuf** mbuf, uint16_t nb) { - struct st_rx_session_priv* s_priv = priv; - struct st_rx_video_session_impl* s = s_priv->session; +static int rv_handle_mbuf(void *priv, struct rte_mbuf **mbuf, uint16_t nb) { + struct st_rx_session_priv *s_priv = priv; + struct st_rx_video_session_impl *s = s_priv->session; enum mtl_session_port s_port = s_priv->s_port; if (!s->attached) { @@ -2659,14 +2788,16 @@ static int rv_handle_mbuf(void* priv, struct rte_mbuf** mbuf, uint16_t nb) { return -EIO; } - struct rte_ring* pkt_ring = s->pkt_lcore_ring; + struct rte_ring *pkt_ring = s->pkt_lcore_ring; bool ctl_thread = pkt_ring ? false : true; int ret = 0; - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->required_pkts) { if (pcap->dumped_pkts < pcap->required_pkts) { - rv_dump_pcap(s, mbuf, RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), s_port); + rv_dump_pcap(s, mbuf, + RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), + s_port); } else { /* got enough packets, stop dumping */ rv_stop_pcap(s, s_port); } @@ -2674,21 +2805,24 @@ static int rv_handle_mbuf(void* priv, struct rte_mbuf** mbuf, uint16_t nb) { if (pkt_ring) { /* first pass to the pkt ring if it has pkt handling lcore */ - unsigned int n = - rte_ring_sp_enqueue_bulk(s->pkt_lcore_ring, (void**)&mbuf[0], nb, NULL); - for (uint16_t i = 0; i < (uint16_t)n; i++) rte_mbuf_refcnt_update(mbuf[i], 1); + unsigned int n = rte_ring_sp_enqueue_bulk(s->pkt_lcore_ring, + (void **)&mbuf[0], nb, NULL); + for (uint16_t i = 0; i < (uint16_t)n; i++) + rte_mbuf_refcnt_update(mbuf[i], 1); nb -= n; /* n is zero or nb */ s->stat_pkts_enqueue_fallback += nb; } - if (!nb) return 0; + if (!nb) + return 0; /* now dispatch the pkts to handler */ for (uint16_t i = 0; i < nb; i++) { - if ((s->ops.flags & ST20_RX_FLAG_SIMULATE_PKT_LOSS) && rv_simulate_pkt_loss(s)) + if ((s->ops.flags & ST20_RX_FLAG_SIMULATE_PKT_LOSS) && + rv_simulate_pkt_loss(s)) continue; if (s->rtcp_rx[s_port]) { - struct st_rfc3550_rtp_hdr* rtp = rte_pktmbuf_mtod_offset( - mbuf[i], struct st_rfc3550_rtp_hdr*, sizeof(struct mt_udp_hdr)); + struct st_rfc3550_rtp_hdr *rtp = rte_pktmbuf_mtod_offset( + mbuf[i], struct st_rfc3550_rtp_hdr *, sizeof(struct mt_udp_hdr)); mt_rtcp_rx_parse_rtp_packet(s->rtcp_rx[s_port], rtp); } int handler_ret = s->pkt_handler(s, mbuf[i], s_port, ctl_thread); @@ -2704,8 +2838,8 @@ static int rv_handle_mbuf(void* priv, struct rte_mbuf** mbuf, uint16_t nb) { return ret; } -static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl* s) { - struct rte_mbuf* mbuf[s->rx_burst_size]; +static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl *s) { + struct rte_mbuf *mbuf[s->rx_burst_size]; uint16_t rv; int num_port = s->ops.num_port; @@ -2714,14 +2848,16 @@ static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl* s) { if (s->dma_dev) { rv_dma_dequeue(s); /* check if has pending pkts in dma */ - if (!mt_dma_empty(s->dma_dev)) done = false; + if (!mt_dma_empty(s->dma_dev)) + done = false; } s->dma_copy = false; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rxq[s_port]) continue; + if (!s->rxq[s_port]) + continue; - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; /* if any pcap progress */ if (MT_USDT_ST20_RX_PCAP_DUMP_ENABLED()) { if (!pcap->usdt_dump) { @@ -2742,7 +2878,8 @@ static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl* s) { if (rv) { s->stat_burst_succ_cnt++; s->stat_burst_pkts_sum += rv; - if (rv > s->stat_burst_pkts_max) s->stat_burst_pkts_max = rv; + if (rv > s->stat_burst_pkts_max) + s->stat_burst_pkts_max = rv; if (rv >= (s->rx_burst_size / 2)) { s->in_continuous_burst[s_port] = true; } @@ -2757,12 +2894,13 @@ static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl* s) { } /* submit if any */ - if (s->dma_copy && s->dma_dev) mt_dma_submit(s->dma_dev); + if (s->dma_copy && s->dma_dev) + mt_dma_submit(s->dma_dev); return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int rv_uinit_hw(struct st_rx_video_session_impl* s) { +static int rv_uinit_hw(struct st_rx_video_session_impl *s) { int num_port = s->ops.num_port; for (int i = 0; i < num_port; i++) { @@ -2775,8 +2913,9 @@ static int rv_uinit_hw(struct st_rx_video_session_impl* s) { return 0; } -static int rv_init_hw(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { - struct st20_rx_ops* ops = &s->ops; +static int rv_init_hw(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { + struct st20_rx_ops *ops = &s->ops; int idx = s->idx, num_port = ops->num_port; struct mt_rxq_flow flow; enum mtl_port port; @@ -2791,8 +2930,8 @@ static int rv_init_hw(struct mtl_main_impl* impl, struct st_rx_video_session_imp memset(&flow, 0, sizeof(flow)); bps = 0; - st20_get_bandwidth_bps(ops->width, ops->height, ops->fmt, ops->fps, ops->interlaced, - &bps); + st20_get_bandwidth_bps(ops->width, ops->height, ops->fmt, ops->fps, + ops->interlaced, &bps); flow.bytes_per_sec = bps / 8; rte_memcpy(flow.dip_addr, ops->ip_addr[i], MTL_IP_ADDR_LEN); if (mt_is_multicast_ip(flow.dip_addr)) @@ -2811,12 +2950,13 @@ static int rv_init_hw(struct mtl_main_impl* impl, struct st_rx_video_session_imp return -ENOTSUP; #endif } - if (mt_has_cni_rx(impl, port)) flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; + if (mt_has_cni_rx(impl, port)) + flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; /* no flow for data path only */ if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { - info("%s(%d), rxq get without flow for port %d as data path only\n", __func__, - s->idx, i); + info("%s(%d), rxq get without flow for port %d as data path only\n", + __func__, s->idx, i); s->rxq[i] = mt_rxq_get(impl, port, NULL); } else { s->rxq[i] = mt_rxq_get(impl, port, &flow); @@ -2832,13 +2972,14 @@ static int rv_init_hw(struct mtl_main_impl* impl, struct st_rx_video_session_imp return 0; } -static int rv_uinit_mcast(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s) { - struct st20_rx_ops* ops = &s->ops; +static int rv_uinit_mcast(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { + struct st20_rx_ops *ops = &s->ops; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!s->mcast_joined[i]) continue; + if (!s->mcast_joined[i]) + continue; port = mt_port_logic2phy(s->port_maps, i); mt_mcast_leave(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); @@ -2847,13 +2988,15 @@ static int rv_uinit_mcast(struct mtl_main_impl* impl, return 0; } -static int rv_init_mcast(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { - struct st20_rx_ops* ops = &s->ops; +static int rv_init_mcast(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { + struct st20_rx_ops *ops = &s->ops; int ret; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!mt_is_multicast_ip(ops->ip_addr[i])) continue; + if (!mt_is_multicast_ip(ops->ip_addr[i])) + continue; port = mt_port_logic2phy(s->port_maps, i); if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { info("%s(%d), skip mcast join for port %d\n", __func__, s->idx, i); @@ -2861,38 +3004,41 @@ static int rv_init_mcast(struct mtl_main_impl* impl, struct st_rx_video_session_ } ret = mt_mcast_join(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->mcast_joined[i] = true; } return 0; } -static int rv_init_rtcp_uhdr(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s, - enum mtl_session_port s_port, struct mt_udp_hdr* uhdr) { +static int rv_init_rtcp_uhdr(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s, + enum mtl_session_port s_port, + struct mt_udp_hdr *uhdr) { int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); int ret; - struct rte_ether_hdr* eth = &uhdr->eth; - struct rte_ipv4_hdr* ipv4 = &uhdr->ipv4; - struct rte_udp_hdr* udp = &uhdr->udp; - struct st20_rx_ops* ops = &s->ops; - uint8_t* dip = ops->ip_addr[s_port]; - uint8_t* sip = mt_sip_addr(impl, port); - struct rte_ether_addr* d_addr = mt_eth_d_addr(eth); + struct rte_ether_hdr *eth = &uhdr->eth; + struct rte_ipv4_hdr *ipv4 = &uhdr->ipv4; + struct rte_udp_hdr *udp = &uhdr->udp; + struct st20_rx_ops *ops = &s->ops; + uint8_t *dip = ops->ip_addr[s_port]; + uint8_t *sip = mt_sip_addr(impl, port); + struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); /* ether hdr */ ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], - dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], + dip[1], dip[2], dip[3]); return ret; } ret = mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); if (ret < 0) { - err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, s_port); + err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, + s_port); return ret; } eth->ether_type = htons(RTE_ETHER_TYPE_IPV4); @@ -2915,11 +3061,12 @@ static int rv_init_rtcp_uhdr(struct mtl_main_impl* impl, return 0; } -static int rv_init_rtcp(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s) { +static int rv_init_rtcp(struct mtl_main_impl *impl, + struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s) { int idx = s->idx; int mgr_idx = mgr->idx; - struct st20_rx_ops* ops = &s->ops; + struct st20_rx_ops *ops = &s->ops; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { @@ -2927,12 +3074,15 @@ static int rv_init_rtcp(struct mtl_main_impl* impl, struct st_rx_video_sessions_ struct mt_udp_hdr uhdr; memset(&uhdr, 0x0, sizeof(uhdr)); int ret = rv_init_rtcp_uhdr(impl, s, i, &uhdr); - if (ret < 0) return ret; + if (ret < 0) + return ret; char name[MT_RTCP_MAX_NAME_LEN]; - snprintf(name, sizeof(name), ST_RX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, i); + snprintf(name, sizeof(name), ST_RX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, + i); if (!ops->rtcp.nack_interval_us) ops->rtcp.nack_interval_us = 250; /* default 250 us */ - if (!ops->rtcp.seq_bitmap_size) ops->rtcp.seq_bitmap_size = 64; + if (!ops->rtcp.seq_bitmap_size) + ops->rtcp.seq_bitmap_size = 64; struct mt_rtcp_rx_ops rtcp_ops = { .port = port, .name = name, @@ -2943,7 +3093,8 @@ static int rv_init_rtcp(struct mtl_main_impl* impl, struct st_rx_video_sessions_ }; s->rtcp_rx[i] = mt_rtcp_rx_create(impl, &rtcp_ops); if (!s->rtcp_rx[i]) { - err("%s(%d,%d), mt_rtcp_rx_create fail on port %d\n", __func__, mgr_idx, idx, i); + err("%s(%d,%d), mt_rtcp_rx_create fail on port %d\n", __func__, mgr_idx, + idx, i); return -EIO; } } @@ -2951,7 +3102,7 @@ static int rv_init_rtcp(struct mtl_main_impl* impl, struct st_rx_video_sessions_ return 0; } -static int rv_uinit_rtcp(struct st_rx_video_session_impl* s) { +static int rv_uinit_rtcp(struct st_rx_video_session_impl *s) { for (int i = 0; i < s->ops.num_port; i++) { if (s->rtcp_rx[i]) { mt_rtcp_rx_free(s->rtcp_rx[i]); @@ -2962,7 +3113,7 @@ static int rv_uinit_rtcp(struct st_rx_video_session_impl* s) { return 0; } -static int rv_init_pkt_handler(struct st_rx_video_session_impl* s) { +static int rv_init_pkt_handler(struct st_rx_video_session_impl *s) { if (st20_is_frame_type(s->ops.type)) { enum st20_detect_status detect_status = s->detector.status; if (detect_status == ST20_DETECT_STAT_DETECTING) { @@ -2985,7 +3136,8 @@ static int rv_init_pkt_handler(struct st_rx_video_session_impl* s) { return 0; } -static int rv_uinit(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { +static int rv_uinit(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { rv_stop_pcap_dump(s); rv_uinit_mcast(impl, s); rv_uinit_rtcp(s); @@ -2994,17 +3146,20 @@ static int rv_uinit(struct mtl_main_impl* impl, struct st_rx_video_session_impl* return 0; } -static int rv_attach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, struct st20_rx_ops* ops, - struct st22_rx_ops* st22_ops) { +static int rv_attach(struct mtl_main_impl *impl, + struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, + struct st20_rx_ops *ops, struct st22_rx_ops *st22_ops) { int ret; int idx = s->idx, num_port = ops->num_port; - char* ports[MTL_SESSION_PORT_MAX]; + char *ports[MTL_SESSION_PORT_MAX]; struct st_fps_timing fps_tm; - for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) + ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = st20_get_pgroup(ops->fmt, &s->st20_pg); if (ret < 0) { @@ -3024,7 +3179,8 @@ static int rv_attach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr s->impl = impl; s->frame_time = (double)1000000000.0 * fps_tm.den / fps_tm.mul; - s->frame_time_sampling = (double)(fps_tm.sampling_clock_rate) * fps_tm.den / fps_tm.mul; + s->frame_time_sampling = + (double)(fps_tm.sampling_clock_rate) * fps_tm.den / fps_tm.mul; s->st20_bytes_in_line = ops->width * s->st20_pg.size / s->st20_pg.coverage; s->st20_linesize = s->st20_bytes_in_line; if (ops->linesize > s->st20_linesize) @@ -3035,19 +3191,24 @@ static int rv_attach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr } s->st20_fb_size = s->st20_linesize * ops->height; - if (ops->interlaced) s->st20_fb_size = s->st20_fb_size >> 1; + if (ops->interlaced) + s->st20_fb_size = s->st20_fb_size >> 1; s->slice_lines = ops->slice_lines; - if (!s->slice_lines) s->slice_lines = ops->height / 32; - s->slice_size = ops->width * s->slice_lines * s->st20_pg.size / s->st20_pg.coverage; + if (!s->slice_lines) + s->slice_lines = ops->height / 32; + s->slice_size = + ops->width * s->slice_lines * s->st20_pg.size / s->st20_pg.coverage; s->st20_frames_cnt = ops->framebuff_cnt; if (st22_ops) { s->st20_frame_size = st22_ops->framebuff_max_size; s->st20_fb_size = s->st20_frame_size; s->st22_ops_flags = st22_ops->flags; } else - s->st20_frame_size = ops->width * ops->height * s->st20_pg.size / s->st20_pg.coverage; + s->st20_frame_size = + ops->width * ops->height * s->st20_pg.size / s->st20_pg.coverage; s->st20_uframe_size = ops->uframe_size; - if (ops->interlaced) s->st20_frame_size = s->st20_frame_size >> 1; + if (ops->interlaced) + s->st20_frame_size = s->st20_frame_size >> 1; /* at least 800 byte for each packet */ s->st20_frame_bitmap_size = s->st20_frame_size / 800 / 8; /* one line at line 2 packets for all the format */ @@ -3056,11 +3217,13 @@ static int rv_attach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "RX_VIDEO_M%dS%d", mgr->idx, idx); + snprintf(s->ops_name, sizeof(s->ops_name), "RX_VIDEO_M%dS%d", mgr->idx, + idx); } s->ops = *ops; for (int i = 0; i < num_port; i++) { - s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); } /* init estimated trs */ @@ -3069,7 +3232,8 @@ static int rv_attach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr if (ops->rx_burst_size) { s->rx_burst_size = ops->rx_burst_size; - info("%s(%d), user customized rx_burst_size %u\n", __func__, idx, s->rx_burst_size); + info("%s(%d), user customized rx_burst_size %u\n", __func__, idx, + s->rx_burst_size); } else { s->rx_burst_size = 128; } @@ -3078,7 +3242,8 @@ static int rv_attach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr if (s->ops.flags & ST20_RX_FLAG_SIMULATE_PKT_LOSS) { uint16_t burst_loss_max = 1; float sim_loss_rate = 0.1; - if (ops->rtcp.burst_loss_max) burst_loss_max = ops->rtcp.burst_loss_max; + if (ops->rtcp.burst_loss_max) + burst_loss_max = ops->rtcp.burst_loss_max; if (ops->rtcp.sim_loss_rate > 0.0 && ops->rtcp.sim_loss_rate < 1.0) sim_loss_rate = ops->rtcp.sim_loss_rate; s->burst_loss_max = burst_loss_max; @@ -3174,45 +3339,53 @@ static int rv_attach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr } s->attached = true; - info("%s(%d), %d frames with size %" PRIu64 "(%" PRIu64 ",%" PRIu64 "), type %d, %s\n", - __func__, idx, s->st20_frames_cnt, s->st20_frame_size, s->st20_frame_bitmap_size, - s->st20_uframe_size, ops->type, ops->interlaced ? "interlace" : "progressive"); - info("%s(%d), w %u h %u fmt %s packing %d pt %d flags 0x%x frame time %fms fps %f\n", - __func__, idx, ops->width, ops->height, st20_fmt_name(ops->fmt), ops->packing, - ops->payload_type, ops->flags, s->frame_time / NS_PER_MS, + info("%s(%d), %d frames with size %" PRIu64 "(%" PRIu64 ",%" PRIu64 + "), type %d, %s\n", + __func__, idx, s->st20_frames_cnt, s->st20_frame_size, + s->st20_frame_bitmap_size, s->st20_uframe_size, ops->type, + ops->interlaced ? "interlace" : "progressive"); + info("%s(%d), w %u h %u fmt %s packing %d pt %d flags 0x%x frame time %fms " + "fps %f\n", + __func__, idx, ops->width, ops->height, st20_fmt_name(ops->fmt), + ops->packing, ops->payload_type, ops->flags, s->frame_time / NS_PER_MS, st_frame_rate(s->ops.fps)); return 0; } -static int rv_poll_vsync(struct mtl_main_impl* impl, struct st_rx_video_session_impl* s) { - struct st_vsync_info* vsync = &s->vsync; +static int rv_poll_vsync(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { + struct st_vsync_info *vsync = &s->vsync; uint64_t cur_tsc = mt_get_tsc(impl); - if (!vsync->init) return 0; + if (!vsync->init) + return 0; if (cur_tsc > vsync->next_epoch_tsc) { uint64_t tsc_delta = cur_tsc - vsync->next_epoch_tsc; - dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, vsync->meta.epoch); + dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, + vsync->meta.epoch); s->ops.notify_event(s->ops.priv, ST_EVENT_VSYNC, &vsync->meta); st_vsync_calculate(impl, vsync); /* set next vsync */ /* check tsc delta for status */ - if (tsc_delta > NS_PER_MS) s->stat_vsync_mismatch++; + if (tsc_delta > NS_PER_MS) + s->stat_vsync_mismatch++; } return 0; } -static int rv_send_nack(struct st_rx_video_session_impl* s) { +static int rv_send_nack(struct st_rx_video_session_impl *s) { for (int i = 0; i < s->ops.num_port; i++) { - if (s->rtcp_rx[i]) mt_rtcp_rx_send_nack_packet(s->rtcp_rx[i]); + if (s->rtcp_rx[i]) + mt_rtcp_rx_send_nack_packet(s->rtcp_rx[i]); } return 0; } -static int rvs_pkt_rx_tasklet_handler(void* priv) { - struct st_rx_video_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_rx_video_session_impl* s; +static int rvs_pkt_rx_tasklet_handler(void *priv) { + struct st_rx_video_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_rx_video_session_impl *s; int sidx; int pending = MTL_TASKLET_ALL_DONE; uint64_t tsc_s = 0; @@ -3220,14 +3393,18 @@ static int rvs_pkt_rx_tasklet_handler(void* priv) { for (sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_video_session_try_get(mgr, sidx); - if (!s) continue; - if (time_measure) tsc_s = mt_get_tsc(impl); + if (!s) + continue; + if (time_measure) + tsc_s = mt_get_tsc(impl); pending += rv_pkt_rx_tasklet(s); /* check vsync if it has vsync flag enabled */ - if (s->ops.flags & ST20_RX_FLAG_ENABLE_VSYNC) rv_poll_vsync(impl, s); - if (s->ops.flags & ST20_RX_FLAG_ENABLE_RTCP) rv_send_nack(s); + if (s->ops.flags & ST20_RX_FLAG_ENABLE_VSYNC) + rv_poll_vsync(impl, s); + if (s->ops.flags & ST20_RX_FLAG_ENABLE_RTCP) + rv_send_nack(s); if (time_measure) { uint64_t delta_ns = mt_get_tsc(impl) - tsc_s; @@ -3240,7 +3417,7 @@ static int rvs_pkt_rx_tasklet_handler(void* priv) { return pending; } -void rx_video_session_clear_cpu_busy(struct st_rx_video_session_impl* s) { +void rx_video_session_clear_cpu_busy(struct st_rx_video_session_impl *s) { rte_atomic32_set(&s->dma_previous_busy_cnt, 0); rte_atomic32_set(&s->cbs_incomplete_frame_cnt, 0); s->cpu_busy_score = 0; @@ -3248,13 +3425,13 @@ void rx_video_session_clear_cpu_busy(struct st_rx_video_session_impl* s) { s->imiss_busy_score = 0; } -void rx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, - struct st_rx_video_session_impl* s) { +void rx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, + struct st_rx_video_session_impl *s) { uint64_t avg_ns_per_loop = mt_sch_avg_ns_loop(sch); /* assume one taskelt can bulk 3 pkts */ s->cpu_busy_score = (double)avg_ns_per_loop / 3 / s->trs * 100.0; - dbg("%s(%d), avg_ns_per_loop %" PRIu64 ", trs %f, busy %f\n", __func__, s->idx, - avg_ns_per_loop, s->trs, s->cpu_busy_score); + dbg("%s(%d), avg_ns_per_loop %" PRIu64 ", trs %f, busy %f\n", __func__, + s->idx, avg_ns_per_loop, s->trs, s->cpu_busy_score); s->stat_cpu_busy_score = s->cpu_busy_score; /* update imiss busy */ @@ -3266,12 +3443,14 @@ void rx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, memset(&stats, 0, sizeof(stats)); mt_read_admin_port_stats(s->impl, port, &stats); if (stats.rx_hw_dropped_packets) { - dbg("%s(%d,%d), incomplete %d and hw_dropped_pkts %" PRIu64 "\n", __func__, - sch->idx, s->idx, incomplete_frame_cnt, stats.rx_hw_dropped_packets); + dbg("%s(%d,%d), incomplete %d and hw_dropped_pkts %" PRIu64 "\n", + __func__, sch->idx, s->idx, incomplete_frame_cnt, + stats.rx_hw_dropped_packets); s->imiss_busy_score += 40.0; } if (s->imiss_busy_score > 95.0) { - notice("%s(%d,%d), imiss busy, incomplete %d and hw_dropped_pkts %" PRIu64 "\n", + notice("%s(%d,%d), imiss busy, incomplete %d and hw_dropped_pkts %" PRIu64 + "\n", __func__, sch->idx, s->idx, incomplete_frame_cnt, stats.rx_hw_dropped_packets); } @@ -3293,15 +3472,15 @@ void rx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, } } -static int rv_migrate_dma(struct mtl_main_impl* impl, - struct st_rx_video_session_impl* s) { +static int rv_migrate_dma(struct mtl_main_impl *impl, + struct st_rx_video_session_impl *s) { rv_free_dma(impl, s); rv_init_dma(impl, s); return 0; } -static void rv_stat(struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s) { +static void rv_stat(struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s) { int m_idx = mgr ? mgr->idx : 0, idx = s->idx; uint64_t cur_time_ns = mt_get_monotonic_time(); double time_sec = (double)(cur_time_ns - s->stat_last_time) / NS_PER_S; @@ -3312,14 +3491,15 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, rte_atomic32_set(&s->stat_frames_received, 0); if (s->stat_slices_received) { - notice("RX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d slices %d\n", m_idx, idx, - s->ops_name, framerate, frames_received, s->stat_pkts_received, - s->stat_slices_received); + notice("RX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d slices %d\n", + m_idx, idx, s->ops_name, framerate, frames_received, + s->stat_pkts_received, s->stat_slices_received); } else { notice("RX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d\n", m_idx, idx, s->ops_name, framerate, frames_received, s->stat_pkts_received); } - notice("RX_VIDEO_SESSION(%d,%d): throughput %f Mb/s, cpu busy %f\n", m_idx, idx, + notice("RX_VIDEO_SESSION(%d,%d): throughput %f Mb/s, cpu busy %f\n", m_idx, + idx, (double)s->stat_bytes_received * 8 / dump_period_s / MTL_STAT_M_UNIT, s->stat_cpu_busy_score); s->stat_pkts_received = 0; @@ -3327,21 +3507,22 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_slices_received = 0; s->stat_last_time = cur_time_ns; - if (s->stat_frames_dropped || s->stat_pkts_idx_dropped || s->stat_pkts_offset_dropped) { - notice( - "RX_VIDEO_SESSION(%d,%d): incomplete frames %d, pkts (idx error: %d, offset " - "error: %d, idx out of bitmap: %d, missed: %d)\n", - m_idx, idx, s->stat_frames_dropped, s->stat_pkts_idx_dropped, - s->stat_pkts_offset_dropped, s->stat_pkts_idx_oo_bitmap, - s->stat_frames_pks_missed); + if (s->stat_frames_dropped || s->stat_pkts_idx_dropped || + s->stat_pkts_offset_dropped) { + notice("RX_VIDEO_SESSION(%d,%d): incomplete frames %d, pkts (idx error: " + "%d, offset " + "error: %d, idx out of bitmap: %d, missed: %d)\n", + m_idx, idx, s->stat_frames_dropped, s->stat_pkts_idx_dropped, + s->stat_pkts_offset_dropped, s->stat_pkts_idx_oo_bitmap, + s->stat_frames_pks_missed); s->stat_frames_dropped = 0; s->stat_pkts_idx_dropped = 0; s->stat_pkts_idx_oo_bitmap = 0; s->stat_frames_pks_missed = 0; } if (s->stat_pkts_rtp_ring_full) { - notice("RX_VIDEO_SESSION(%d,%d): rtp dropped pkts %d as ring full\n", m_idx, idx, - s->stat_pkts_rtp_ring_full); + notice("RX_VIDEO_SESSION(%d,%d): rtp dropped pkts %d as ring full\n", m_idx, + idx, s->stat_pkts_rtp_ring_full); s->stat_pkts_rtp_ring_full = 0; } if (s->stat_pkts_no_slot) { @@ -3360,18 +3541,18 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_pkts_redundant_dropped = 0; } if (s->stat_pkts_wrong_pt_dropped) { - notice("RX_VIDEO_SESSION(%d,%d): wrong hdr payload type dropped pkts %d\n", m_idx, - idx, s->stat_pkts_wrong_pt_dropped); + notice("RX_VIDEO_SESSION(%d,%d): wrong hdr payload type dropped pkts %d\n", + m_idx, idx, s->stat_pkts_wrong_pt_dropped); s->stat_pkts_wrong_pt_dropped = 0; } if (s->stat_pkts_wrong_ssrc_dropped) { - notice("RX_VIDEO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, idx, - s->stat_pkts_wrong_ssrc_dropped); + notice("RX_VIDEO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, + idx, s->stat_pkts_wrong_ssrc_dropped); s->stat_pkts_wrong_ssrc_dropped = 0; } if (s->stat_pkts_wrong_interlace_dropped) { - notice("RX_VIDEO_SESSION(%d,%d): wrong hdr interlace dropped pkts %d\n", m_idx, idx, - s->stat_pkts_wrong_interlace_dropped); + notice("RX_VIDEO_SESSION(%d,%d): wrong hdr interlace dropped pkts %d\n", + m_idx, idx, s->stat_pkts_wrong_interlace_dropped); s->stat_pkts_wrong_interlace_dropped = 0; } if (s->stat_pkts_wrong_len_dropped) { @@ -3380,18 +3561,18 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_pkts_wrong_len_dropped = 0; } if (s->stat_pkts_enqueue_fallback) { - notice("RX_VIDEO_SESSION(%d,%d): lcore enqueue fallback pkts %d\n", m_idx, idx, - s->stat_pkts_enqueue_fallback); + notice("RX_VIDEO_SESSION(%d,%d): lcore enqueue fallback pkts %d\n", m_idx, + idx, s->stat_pkts_enqueue_fallback); s->stat_pkts_enqueue_fallback = 0; } if (s->dma_dev) { - notice("RX_VIDEO_SESSION(%d,%d): pkts %d by dma copy, dma busy %f\n", m_idx, idx, - s->stat_pkts_dma, s->dma_busy_score); + notice("RX_VIDEO_SESSION(%d,%d): pkts %d by dma copy, dma busy %f\n", m_idx, + idx, s->stat_pkts_dma, s->dma_busy_score); s->stat_pkts_dma = 0; } if (s->stat_pkts_slice_fail) { - notice("RX_VIDEO_SESSION(%d,%d): pkts %d drop as slice add fail\n", m_idx, idx, - s->stat_pkts_slice_fail); + notice("RX_VIDEO_SESSION(%d,%d): pkts %d drop as slice add fail\n", m_idx, + idx, s->stat_pkts_slice_fail); s->stat_pkts_slice_fail = 0; } if (s->stat_pkts_slice_merged) { @@ -3410,13 +3591,13 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_pkts_not_bpm = 0; } if (s->stat_pkts_wrong_payload_hdr_split) { - notice("RX_VIDEO_SESSION(%d,%d): wrong payload hdr split pkts %d\n", m_idx, idx, - s->stat_pkts_wrong_payload_hdr_split); + notice("RX_VIDEO_SESSION(%d,%d): wrong payload hdr split pkts %d\n", m_idx, + idx, s->stat_pkts_wrong_payload_hdr_split); s->stat_pkts_wrong_payload_hdr_split = 0; } if (s->stat_mismatch_hdr_split_frame) { - notice("RX_VIDEO_SESSION(%d,%d): hdr split mismatch frames %d\n", m_idx, idx, - s->stat_mismatch_hdr_split_frame); + notice("RX_VIDEO_SESSION(%d,%d): hdr split mismatch frames %d\n", m_idx, + idx, s->stat_mismatch_hdr_split_frame); s->stat_mismatch_hdr_split_frame = 0; } if (s->stat_pkts_copy_hdr_split) { @@ -3445,8 +3626,8 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_pkts_simulate_loss = 0; } if (s->stat_pkts_user_meta) { - notice("RX_VIDEO_SESSION(%d,%d): user meta pkts %d invalid %d\n", m_idx, idx, - s->stat_pkts_user_meta, s->stat_pkts_user_meta_err); + notice("RX_VIDEO_SESSION(%d,%d): user meta pkts %d invalid %d\n", m_idx, + idx, s->stat_pkts_user_meta, s->stat_pkts_user_meta_err); s->stat_pkts_user_meta = 0; s->stat_pkts_user_meta_err = 0; } @@ -3456,14 +3637,16 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_pkts_retransmit = 0; } if (s->ops.interlaced) { - notice("RX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", m_idx, - idx, s->stat_interlace_first_field, s->stat_interlace_second_field); + notice( + "RX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", + m_idx, idx, s->stat_interlace_first_field, + s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } if (s->stat_st22_boxes) { - notice("RX_VIDEO_SESSION(%d,%d): st22 video support boxes received %u \n", m_idx, idx, - s->stat_st22_boxes); + notice("RX_VIDEO_SESSION(%d,%d): st22 video support boxes received %u \n", + m_idx, idx, s->stat_st22_boxes); s->stat_st22_boxes = 0; } if (s->stat_burst_succ_cnt) { @@ -3475,19 +3658,22 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_burst_pkts_sum = 0; } - struct st_rx_video_tp* tp = s->tp; + struct st_rx_video_tp *tp = s->tp; if (tp && tp->stat_untrusted_pkts) { info("%s(%d), untrusted %u pkts time for timing parser\n", __func__, idx, tp->stat_untrusted_pkts); tp->stat_untrusted_pkts = 0; } - if (s->enable_timing_parser_stat) rv_tp_stat(s); + if (s->enable_timing_parser_stat) + rv_tp_stat(s); - struct mt_stat_u64* stat_time = &s->stat_time; + struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("RX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + notice("RX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, + (float)stat_time->max / NS_PER_US, (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } @@ -3498,22 +3684,24 @@ static void rv_stat(struct st_rx_video_sessions_mgr* mgr, s->stat_max_notify_frame_us = 0; for (int s_port = 0; s_port < s->ops.num_port; s_port++) { - struct mt_rx_pcap* pcap = &s->pcap[s_port]; + struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->pcap) { - MT_USDT_ST20_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, pcap->dumped_pkts); + MT_USDT_ST20_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, + pcap->dumped_pkts); } } } -static int rvs_pkt_rx_tasklet_start(void* priv) { - struct st_rx_video_sessions_mgr* mgr = priv; +static int rvs_pkt_rx_tasklet_start(void *priv) { + struct st_rx_video_sessions_mgr *mgr = priv; int idx = mgr->idx; - struct mtl_main_impl* impl = mgr->parent; - struct st_rx_video_session_impl* s; + struct mtl_main_impl *impl = mgr->parent; + struct st_rx_video_session_impl *s; for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_video_session_try_get(mgr, sidx); - if (!s) continue; + if (!s) + continue; /* re-calculate the vsync */ st_vsync_calculate(impl, &s->vsync); rx_video_session_put(mgr, sidx); @@ -3523,21 +3711,22 @@ static int rvs_pkt_rx_tasklet_start(void* priv) { return 0; } -static int rv_detach(struct mtl_main_impl* impl, struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s) { +static int rv_detach(struct mtl_main_impl *impl, + struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s) { s->attached = false; rv_stat(mgr, s); rv_uinit(impl, s); return 0; } -static int rv_update_src(struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, - struct st_rx_source_info* src) { +static int rv_update_src(struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; - struct st20_rx_ops* ops = &s->ops; - struct mtl_main_impl* impl = mgr->parent; + struct st20_rx_ops *ops = &s->ops; + struct mtl_main_impl *impl = mgr->parent; rv_uinit_rtcp(s); rv_uinit_mcast(impl, s); @@ -3548,7 +3737,8 @@ static int rv_update_src(struct st_rx_video_sessions_mgr* mgr, memcpy(ops->ip_addr[i], src->ip_addr[i], MTL_IP_ADDR_LEN); memcpy(ops->mcast_sip_addr[i], src->mcast_sip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = src->udp_port[i]; - s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); } ret = rv_init_hw(impl, s); @@ -3577,9 +3767,9 @@ static int rv_update_src(struct st_rx_video_sessions_mgr* mgr, return 0; } -static int rv_mgr_update_src(struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, - struct st_rx_source_info* src) { +static int rv_mgr_update_src(struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = rx_video_session_get(mgr, idx); /* get the lock */ @@ -3597,8 +3787,8 @@ static int rv_mgr_update_src(struct st_rx_video_sessions_mgr* mgr, return 0; } -static int rvs_mgr_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_rx_video_sessions_mgr* mgr) { +static int rvs_mgr_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, + struct st_rx_video_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; @@ -3625,17 +3815,17 @@ static int rvs_mgr_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, return 0; } -static int rvs_mgr_detach(struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, int idx) { +static int rvs_mgr_detach(struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, int idx) { rv_detach(mgr->parent, mgr, s); mgr->sessions[idx] = NULL; mt_rte_free(s); return 0; } -static int rvs_mgr_uinit(struct st_rx_video_sessions_mgr* mgr) { +static int rvs_mgr_uinit(struct st_rx_video_sessions_mgr *mgr) { int m_idx = mgr->idx; - struct st_rx_video_session_impl* s; + struct st_rx_video_session_impl *s; if (mgr->pkt_rx_tasklet) { mtl_sch_unregister_tasklet(mgr->pkt_rx_tasklet); @@ -3644,7 +3834,8 @@ static int rvs_mgr_uinit(struct st_rx_video_sessions_mgr* mgr) { for (int i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { s = rx_video_session_get(mgr, i); - if (!s) continue; + if (!s) + continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); rvs_mgr_detach(mgr, s, i); @@ -3655,18 +3846,19 @@ static int rvs_mgr_uinit(struct st_rx_video_sessions_mgr* mgr) { return 0; } -static struct st_rx_video_session_impl* rv_mgr_attach(struct mtl_sch_impl* sch, - struct st20_rx_ops* ops, - struct st22_rx_ops* st22_ops) { - struct st_rx_video_sessions_mgr* mgr = &sch->rx_video_mgr; +static struct st_rx_video_session_impl * +rv_mgr_attach(struct mtl_sch_impl *sch, struct st20_rx_ops *ops, + struct st22_rx_ops *st22_ops) { + struct st_rx_video_sessions_mgr *mgr = &sch->rx_video_mgr; int midx = mgr->idx; int ret; - struct st_rx_video_session_impl* s; + struct st_rx_video_session_impl *s; int socket = mt_sch_socket_id(sch); /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { - if (!rx_video_session_get_empty(mgr, i)) continue; + if (!rx_video_session_get_empty(mgr, i)) + continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -3700,8 +3892,8 @@ static struct st_rx_video_session_impl* rv_mgr_attach(struct mtl_sch_impl* sch, return NULL; } -static int st_rvs_mgr_detach(struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s) { +static int st_rvs_mgr_detach(struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -3718,32 +3910,35 @@ static int st_rvs_mgr_detach(struct st_rx_video_sessions_mgr* mgr, return 0; } -static int rvs_mgr_update(struct st_rx_video_sessions_mgr* mgr) { +static int rvs_mgr_update(struct st_rx_video_sessions_mgr *mgr) { int max_idx = 0; - struct mtl_main_impl* impl = mgr->parent; + struct mtl_main_impl *impl = mgr->parent; uint64_t sleep_us = mt_sch_default_sleep_us(impl); - struct st_rx_video_session_impl* s; + struct st_rx_video_session_impl *s; for (int i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { s = mgr->sessions[i]; - if (!s) continue; + if (!s) + continue; max_idx = i + 1; sleep_us = RTE_MIN(s->advice_sleep_us, sleep_us); } - dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, sleep_us, - max_idx); + dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, + sleep_us, max_idx); mgr->max_idx = max_idx; - if (mgr->pkt_rx_tasklet) mt_tasklet_set_sleep(mgr->pkt_rx_tasklet, sleep_us); + if (mgr->pkt_rx_tasklet) + mt_tasklet_set_sleep(mgr->pkt_rx_tasklet, sleep_us); return 0; } -static int rv_sessions_stat(void* priv) { - struct st_rx_video_sessions_mgr* mgr = priv; - struct st_rx_video_session_impl* s; +static int rv_sessions_stat(void *priv) { + struct st_rx_video_sessions_mgr *mgr = priv; + struct st_rx_video_session_impl *s; for (int j = 0; j < mgr->max_idx; j++) { s = rx_video_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) continue; + if (!s) + continue; rv_stat(mgr, s); rx_video_session_put(mgr, j); } @@ -3751,12 +3946,14 @@ static int rv_sessions_stat(void* priv) { return 0; } -int st_rx_video_sessions_sch_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { +int st_rx_video_sessions_sch_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { int ret, idx = sch->idx; - if (sch->rx_video_init) return 0; + if (sch->rx_video_init) + return 0; - struct st_rx_video_sessions_mgr* rx_video_mgr = &sch->rx_video_mgr; + struct st_rx_video_sessions_mgr *rx_video_mgr = &sch->rx_video_mgr; /* create video context */ ret = rvs_mgr_init(impl, sch, rx_video_mgr); @@ -3770,10 +3967,12 @@ int st_rx_video_sessions_sch_init(struct mtl_main_impl* impl, struct mtl_sch_imp return 0; } -int st_rx_video_sessions_sch_uinit(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { - if (!sch->rx_video_init) return 0; +int st_rx_video_sessions_sch_uinit(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { + if (!sch->rx_video_init) + return 0; - struct st_rx_video_sessions_mgr* rx_video_mgr = &sch->rx_video_mgr; + struct st_rx_video_sessions_mgr *rx_video_mgr = &sch->rx_video_mgr; mt_stat_unregister(impl, rv_sessions_stat, rx_video_mgr); rvs_mgr_uinit(rx_video_mgr); @@ -3782,17 +3981,18 @@ int st_rx_video_sessions_sch_uinit(struct mtl_main_impl* impl, struct mtl_sch_im return 0; } -int st_rx_video_session_migrate(struct mtl_main_impl* impl, - struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, int idx) { +int st_rx_video_session_migrate(struct mtl_main_impl *impl, + struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, int idx) { rv_init(mgr, s, idx); - if (s->dma_dev) rv_migrate_dma(impl, s); + if (s->dma_dev) + rv_migrate_dma(impl, s); return 0; } -static int rv_ops_check(struct st20_rx_ops* ops) { +static int rv_ops_check(struct st20_rx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip; + uint8_t *ip; enum st20_type type = ops->type; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { @@ -3804,14 +4004,16 @@ static int rv_ops_check(struct st20_rx_ops* ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -3840,14 +4042,17 @@ static int rv_ops_check(struct st20_rx_ops* ops) { } if (ops->query_ext_frame) { if (!(ops->flags & ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME)) { - err("%s, pls enable incomplete frame flag for query ext mode\n", __func__); + err("%s, pls enable incomplete frame flag for query ext mode\n", + __func__); return -EINVAL; } } if (ops->flags & ST20_RX_FLAG_HDR_SPLIT) { if (num_ports > 1) { - /* only 1 port allowed since the pkt payload is assigned to frame directly */ - err("%s, hdr split only support 1 port, num_ports %d\n", __func__, num_ports); + /* only 1 port allowed since the pkt payload is assigned to frame + * directly */ + err("%s, hdr split only support 1 port, num_ports %d\n", __func__, + num_ports); return -EINVAL; } } @@ -3873,7 +4078,8 @@ static int rv_ops_check(struct st20_rx_ops* ops) { if (type == ST20_TYPE_SLICE_LEVEL) { if (!(ops->flags & ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME)) { - err("%s, pls enable ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME for silce mode\n", + err("%s, pls enable ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME for silce " + "mode\n", __func__); return -EINVAL; } @@ -3888,9 +4094,9 @@ static int rv_ops_check(struct st20_rx_ops* ops) { return 0; } -static int rv_st22_ops_check(struct st22_rx_ops* ops) { +static int rv_st22_ops_check(struct st22_rx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip; + uint8_t *ip; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { err("%s, invalid num_ports %d\n", __func__, num_ports); @@ -3901,14 +4107,16 @@ static int rv_st22_ops_check(struct st22_rx_ops* ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -3953,11 +4161,12 @@ static int rv_st22_ops_check(struct st22_rx_ops* ops) { return 0; } -st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl* impl, - struct st20_rx_ops* ops, mt_sch_mask_t sch_mask) { - struct mtl_sch_impl* sch; - struct st_rx_video_session_handle_impl* s_impl; - struct st_rx_video_session_impl* s; +st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, + struct st20_rx_ops *ops, + mt_sch_mask_t sch_mask) { + struct mtl_sch_impl *sch; + struct st_rx_video_session_handle_impl *s_impl; + struct st_rx_video_session_impl *s; int quota_mbs, ret, quota_mbs_wo_dma = 0; uint64_t bps; @@ -3973,7 +4182,8 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl* impl, } if (ops->flags & ST20_RX_FLAG_AUTO_DETECT) { - ret = st20_get_bandwidth_bps(1920, 1080, ops->fmt, ST_FPS_P59_94, false, &bps); + ret = st20_get_bandwidth_bps(1920, 1080, ops->fmt, ST_FPS_P59_94, false, + &bps); } else { ret = st20_get_bandwidth_bps(ops->width, ops->height, ops->fmt, ops->fps, ops->interlaced, &bps); @@ -3987,16 +4197,19 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl* impl, quota_mbs *= ops->num_port; if (!mt_user_quota_active(impl)) { if (ST20_TYPE_RTP_LEVEL == ops->type) { - quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_RTP_PER_SCH; + quota_mbs = + quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_RTP_PER_SCH; } else { - quota_mbs_wo_dma = - quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_NO_DMA_PER_SCH; - quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_PER_SCH; + quota_mbs_wo_dma = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / + ST_QUOTA_RX1080P_NO_DMA_PER_SCH; + quota_mbs = + quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_PER_SCH; } } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20_RX_FLAG_FORCE_NUMA) { @@ -4010,8 +4223,9 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl* impl, return NULL; } - enum mt_sch_type type = - mt_user_rxv_separate_sch(impl) ? MT_SCH_TYPE_RX_VIDEO_ONLY : MT_SCH_TYPE_DEFAULT; + enum mt_sch_type type = mt_user_rxv_separate_sch(impl) + ? MT_SCH_TYPE_RX_VIDEO_ONLY + : MT_SCH_TYPE_DEFAULT; sch = mt_sch_get_by_socket(impl, quota_mbs, type, sch_mask, socket); if (!sch) { mt_rte_free(s_impl); @@ -4039,10 +4253,12 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl* impl, return NULL; } - if (!mt_user_quota_active(impl) && st20_is_frame_type(ops->type) && !s->dma_dev) { + if (!mt_user_quota_active(impl) && st20_is_frame_type(ops->type) && + !s->dma_dev) { int extra_quota_mbs = quota_mbs_wo_dma - quota_mbs; ret = mt_sch_add_quota(sch, extra_quota_mbs); - if (ret >= 0) quota_mbs += extra_quota_mbs; + if (ret >= 0) + quota_mbs += extra_quota_mbs; } /* update mgr status */ @@ -4062,13 +4278,14 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl* impl, return s_impl; } -st20_rx_handle st20_rx_create(mtl_handle mt, struct st20_rx_ops* ops) { +st20_rx_handle st20_rx_create(mtl_handle mt, struct st20_rx_ops *ops) { return st20_rx_create_with_mask(mt, ops, MT_SCH_MASK_ALL); } -int st20_rx_update_source(st20_rx_handle handle, struct st_rx_source_info* src) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; +int st20_rx_update_source(st20_rx_handle handle, + struct st_rx_source_info *src) { + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; int idx, ret; if (s_impl->type != MT_HANDLE_RX_VIDEO) { @@ -4080,7 +4297,8 @@ int st20_rx_update_source(st20_rx_handle handle, struct st_rx_source_info* src) idx = s->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = rv_mgr_update_src(&s_impl->sch->rx_video_mgr, s, src); if (ret < 0) { @@ -4093,7 +4311,7 @@ int st20_rx_update_source(st20_rx_handle handle, struct st_rx_source_info* src) } int st20_rx_get_sch_idx(st20_rx_handle handle) { - struct st_rx_video_session_handle_impl* s_impl = handle; + struct st_rx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4103,10 +4321,10 @@ int st20_rx_get_sch_idx(st20_rx_handle handle) { return s_impl->sch->idx; } -int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s = s_impl->impl; +int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta) { + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s = s_impl->impl; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4117,14 +4335,14 @@ int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, bool s } int st20_rx_get_port_stats(st20_rx_handle handle, enum mtl_session_port port, - struct st20_rx_port_status* stats) { - struct st_rx_video_session_handle_impl* s_impl = handle; + struct st20_rx_port_status *stats) { + struct st_rx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); return -EINVAL; } - struct st_rx_video_session_impl* s = s_impl->impl; + struct st_rx_video_session_impl *s = s_impl->impl; if (port >= s->ops.num_port) { err("%s, invalid port %d\n", __func__, port); return -EIO; @@ -4134,14 +4352,15 @@ int st20_rx_get_port_stats(st20_rx_handle handle, enum mtl_session_port port, return 0; } -int st20_rx_reset_port_stats(st20_rx_handle handle, enum mtl_session_port port) { - struct st_rx_video_session_handle_impl* s_impl = handle; +int st20_rx_reset_port_stats(st20_rx_handle handle, + enum mtl_session_port port) { + struct st_rx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); return -EINVAL; } - struct st_rx_video_session_impl* s = s_impl->impl; + struct st_rx_video_session_impl *s = s_impl->impl; if (port >= s->ops.num_port) { err("%s, invalid port %d\n", __func__, port); return -EIO; @@ -4152,10 +4371,10 @@ int st20_rx_reset_port_stats(st20_rx_handle handle, enum mtl_session_port port) } int st20_rx_free(st20_rx_handle handle) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct mtl_sch_impl* sch; - struct st_rx_video_session_impl* s; - struct mtl_main_impl* impl; + struct st_rx_video_session_handle_impl *s_impl = handle; + struct mtl_sch_impl *sch; + struct st_rx_video_session_impl *s; + struct mtl_main_impl *impl; int ret, sch_idx, idx; if (s_impl->type != MT_HANDLE_RX_VIDEO) { @@ -4174,10 +4393,12 @@ int st20_rx_free(st20_rx_handle handle) { ret = st_rvs_mgr_detach(&sch->rx_video_mgr, s); mt_pthread_mutex_unlock(&sch->rx_video_mgr_mutex); if (ret < 0) - err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, idx); + err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, + idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4191,10 +4412,10 @@ int st20_rx_free(st20_rx_handle handle) { return 0; } -int st20_rx_put_framebuff(st20_rx_handle handle, void* framebuff) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; - struct st_frame_trans* st20_frame; +int st20_rx_put_framebuff(st20_rx_handle handle, void *framebuff) { + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; + struct st_frame_trans *st20_frame; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4216,8 +4437,8 @@ int st20_rx_put_framebuff(st20_rx_handle handle, void* framebuff) { } size_t st20_rx_get_framebuffer_size(st20_rx_handle handle) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4229,8 +4450,8 @@ size_t st20_rx_get_framebuffer_size(st20_rx_handle handle) { } int st20_rx_get_framebuffer_count(st20_rx_handle handle) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4241,12 +4462,12 @@ int st20_rx_get_framebuffer_count(st20_rx_handle handle) { return s->st20_frames_cnt; } -void* st20_rx_get_mbuf(st20_rx_handle handle, void** usrptr, uint16_t* len) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; - struct rte_mbuf* pkt; +void *st20_rx_get_mbuf(st20_rx_handle handle, void **usrptr, uint16_t *len) { + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; + struct rte_mbuf *pkt; int idx, ret; - struct rte_ring* rtps_ring; + struct rte_ring *rtps_ring; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4261,7 +4482,7 @@ void* st20_rx_get_mbuf(st20_rx_handle handle, void** usrptr, uint16_t* len) { return NULL; } - ret = rte_ring_sc_dequeue(rtps_ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(rtps_ring, (void **)&pkt); if (ret < 0) { dbg("%s(%d), rtp ring is empty\n", __func__, idx); return NULL; @@ -4270,23 +4491,24 @@ void* st20_rx_get_mbuf(st20_rx_handle handle, void** usrptr, uint16_t* len) { size_t hdr_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr); *len = pkt->data_len - hdr_len; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, hdr_len); + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, hdr_len); return pkt; } -void st20_rx_put_mbuf(st20_rx_handle handle, void* mbuf) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; +void st20_rx_put_mbuf(st20_rx_handle handle, void *mbuf) { + struct st_rx_video_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; if (s_impl->type != MT_HANDLE_RX_VIDEO) err("%s, invalid type %d\n", __func__, s_impl->type); - if (pkt) rte_pktmbuf_free(pkt); + if (pkt) + rte_pktmbuf_free(pkt); } bool st20_rx_dma_enabled(st20_rx_handle handle) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4298,9 +4520,9 @@ bool st20_rx_dma_enabled(st20_rx_handle handle) { return s->dma_dev ? true : false; } -int st20_rx_get_queue_meta(st20_rx_handle handle, struct st_queue_meta* meta) { - struct st_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; +int st20_rx_get_queue_meta(st20_rx_handle handle, struct st_queue_meta *meta) { + struct st_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4318,15 +4540,16 @@ int st20_rx_get_queue_meta(st20_rx_handle handle, struct st_queue_meta* meta) { return 0; } -int st20_rx_timing_parser_critical(st20_rx_handle handle, struct st20_rx_tp_pass* pass) { - struct st_rx_video_session_handle_impl* s_impl = handle; +int st20_rx_timing_parser_critical(st20_rx_handle handle, + struct st20_rx_tp_pass *pass) { + struct st_rx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); return -EIO; } - struct st_rx_video_session_impl* s = s_impl->impl; + struct st_rx_video_session_impl *s = s_impl->impl; int idx = s->idx; if (!s->enable_timing_parser) { err("%s(%d), timing parser control not enabled\n", __func__, idx); @@ -4341,11 +4564,11 @@ int st20_rx_timing_parser_critical(st20_rx_handle handle, struct st20_rx_tp_pass return 0; } -st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct mtl_sch_impl* sch; - struct st22_rx_video_session_handle_impl* s_impl; - struct st_rx_video_session_impl* s; +st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct mtl_sch_impl *sch; + struct st22_rx_video_session_handle_impl *s_impl; + struct st_rx_video_session_impl *s; int quota_mbs, ret; uint64_t bps; struct st20_rx_ops st20_ops; @@ -4362,8 +4585,8 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops) { } if (ST22_TYPE_RTP_LEVEL == ops->type) { - ret = st20_get_bandwidth_bps(ops->width, ops->height, ST20_FMT_YUV_422_10BIT, - ops->fps, false, &bps); + ret = st20_get_bandwidth_bps(ops->width, ops->height, + ST20_FMT_YUV_422_10BIT, ops->fps, false, &bps); if (ret < 0) { err("%s, get_bandwidth_bps fail\n", __func__); return NULL; @@ -4383,7 +4606,8 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22_RX_FLAG_FORCE_NUMA) { @@ -4397,8 +4621,9 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops) { return NULL; } - enum mt_sch_type type = - mt_user_rxv_separate_sch(impl) ? MT_SCH_TYPE_RX_VIDEO_ONLY : MT_SCH_TYPE_DEFAULT; + enum mt_sch_type type = mt_user_rxv_separate_sch(impl) + ? MT_SCH_TYPE_RX_VIDEO_ONLY + : MT_SCH_TYPE_DEFAULT; sch = mt_sch_get_by_socket(impl, quota_mbs, type, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); @@ -4429,7 +4654,8 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops) { } if (ops->flags & ST22_RX_FLAG_DATA_PATH_ONLY) st20_ops.flags |= ST20_RX_FLAG_DATA_PATH_ONLY; - if (ops->flags & ST22_RX_FLAG_ENABLE_VSYNC) st20_ops.flags |= ST20_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22_RX_FLAG_ENABLE_VSYNC) + st20_ops.flags |= ST20_RX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22_RX_FLAG_RECEIVE_INCOMPLETE_FRAME) st20_ops.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; if (ops->flags & ST22_RX_FLAG_ENABLE_RTCP) { @@ -4476,9 +4702,10 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops* ops) { return s_impl; } -int st22_rx_update_source(st22_rx_handle handle, struct st_rx_source_info* src) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; +int st22_rx_update_source(st22_rx_handle handle, + struct st_rx_source_info *src) { + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; int idx, ret; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { @@ -4490,7 +4717,8 @@ int st22_rx_update_source(st22_rx_handle handle, struct st_rx_source_info* src) idx = s->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = rv_mgr_update_src(&s_impl->sch->rx_video_mgr, s, src); if (ret < 0) { @@ -4503,7 +4731,7 @@ int st22_rx_update_source(st22_rx_handle handle, struct st_rx_source_info* src) } int st22_rx_get_sch_idx(st22_rx_handle handle) { - struct st22_rx_video_session_handle_impl* s_impl = handle; + struct st22_rx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4513,10 +4741,10 @@ int st22_rx_get_sch_idx(st22_rx_handle handle) { return s_impl->sch->idx; } -int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, bool sync, - struct st_pcap_dump_meta* meta) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s = s_impl->impl; +int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, + bool sync, struct st_pcap_dump_meta *meta) { + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s = s_impl->impl; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4527,10 +4755,10 @@ int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, bool s } int st22_rx_free(st22_rx_handle handle) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct mtl_sch_impl* sch; - struct st_rx_video_session_impl* s; - struct mtl_main_impl* impl; + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct mtl_sch_impl *sch; + struct st_rx_video_session_impl *s; + struct mtl_main_impl *impl; int ret, sch_idx, idx; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { @@ -4548,10 +4776,12 @@ int st22_rx_free(st22_rx_handle handle) { ret = st_rvs_mgr_detach(&sch->rx_video_mgr, s); mt_pthread_mutex_unlock(&sch->rx_video_mgr_mutex); if (ret < 0) - err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, idx); + err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, + idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4565,12 +4795,12 @@ int st22_rx_free(st22_rx_handle handle) { return 0; } -void* st22_rx_get_mbuf(st22_rx_handle handle, void** usrptr, uint16_t* len) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; - struct rte_mbuf* pkt; +void *st22_rx_get_mbuf(st22_rx_handle handle, void **usrptr, uint16_t *len) { + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; + struct rte_mbuf *pkt; int idx, ret; - struct rte_ring* rtps_ring; + struct rte_ring *rtps_ring; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4585,7 +4815,7 @@ void* st22_rx_get_mbuf(st22_rx_handle handle, void** usrptr, uint16_t* len) { return NULL; } - ret = rte_ring_sc_dequeue(rtps_ring, (void**)&pkt); + ret = rte_ring_sc_dequeue(rtps_ring, (void **)&pkt); if (ret < 0) { dbg("%s(%d), rtp ring is empty\n", __func__, idx); return NULL; @@ -4594,24 +4824,25 @@ void* st22_rx_get_mbuf(st22_rx_handle handle, void** usrptr, uint16_t* len) { size_t hdr_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr); *len = pkt->data_len - hdr_len; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, hdr_len); + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, hdr_len); return pkt; } -void st22_rx_put_mbuf(st22_rx_handle handle, void* mbuf) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; +void st22_rx_put_mbuf(st22_rx_handle handle, void *mbuf) { + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) err("%s, invalid type %d\n", __func__, s_impl->type); - if (pkt) rte_pktmbuf_free(pkt); + if (pkt) + rte_pktmbuf_free(pkt); } -int st22_rx_put_framebuff(st22_rx_handle handle, void* framebuff) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; - struct st_frame_trans* st20_frame; +int st22_rx_put_framebuff(st22_rx_handle handle, void *framebuff) { + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; + struct st_frame_trans *st20_frame; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4632,9 +4863,9 @@ int st22_rx_put_framebuff(st22_rx_handle handle, void* framebuff) { return -EIO; } -void* st22_rx_get_fb_addr(st22_rx_handle handle, uint16_t idx) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; +void *st22_rx_get_fb_addr(st22_rx_handle handle, uint16_t idx) { + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4656,9 +4887,9 @@ void* st22_rx_get_fb_addr(st22_rx_handle handle, uint16_t idx) { return s->st20_frames[idx].addr; } -int st22_rx_get_queue_meta(st22_rx_handle handle, struct st_queue_meta* meta) { - struct st22_rx_video_session_handle_impl* s_impl = handle; - struct st_rx_video_session_impl* s; +int st22_rx_get_queue_meta(st22_rx_handle handle, struct st_queue_meta *meta) { + struct st22_rx_video_session_handle_impl *s_impl = handle; + struct st_rx_video_session_impl *s; if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); diff --git a/lib/src/st2110/st_rx_video_session.h b/lib/src/st2110/st_rx_video_session.h index 6b109d772..12d5e8ce2 100644 --- a/lib/src/st2110/st_rx_video_session.h +++ b/lib/src/st2110/st_rx_video_session.h @@ -14,42 +14,50 @@ #define ST_RX_VIDEO_PREFIX "RV_" -int st_rx_video_sessions_sch_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch); +int st_rx_video_sessions_sch_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch); -int st_rx_video_sessions_sch_uinit(struct mtl_main_impl* impl, struct mtl_sch_impl* sch); +int st_rx_video_sessions_sch_uinit(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch); /* call rx_video_session_put always if get successfully */ -static inline struct st_rx_video_session_impl* rx_video_session_get( - struct st_rx_video_sessions_mgr* mgr, int idx) { +static inline struct st_rx_video_session_impl * +rx_video_session_get(struct st_rx_video_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_rx_video_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); + struct st_rx_video_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_video_session_put always if get successfully */ -static inline struct st_rx_video_session_impl* rx_video_session_get_timeout( - struct st_rx_video_sessions_mgr* mgr, int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; - struct st_rx_video_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_rx_video_session_impl * +rx_video_session_get_timeout(struct st_rx_video_sessions_mgr *mgr, int idx, + int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) + return NULL; + struct st_rx_video_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_video_session_put always if get successfully */ -static inline struct st_rx_video_session_impl* rx_video_session_try_get( - struct st_rx_video_sessions_mgr* mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; - struct st_rx_video_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_rx_video_session_impl * +rx_video_session_try_get(struct st_rx_video_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) + return NULL; + struct st_rx_video_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_video_session_put always if get successfully */ -static inline bool rx_video_session_get_empty(struct st_rx_video_sessions_mgr* mgr, - int idx) { +static inline bool +rx_video_session_get_empty(struct st_rx_video_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_rx_video_session_impl* s = mgr->sessions[idx]; + struct st_rx_video_session_impl *s = mgr->sessions[idx]; if (s) { rte_spinlock_unlock(&mgr->mutex[idx]); /* not null, unlock it */ return false; @@ -58,38 +66,46 @@ static inline bool rx_video_session_get_empty(struct st_rx_video_sessions_mgr* m } } -static inline void rx_video_session_put(struct st_rx_video_sessions_mgr* mgr, int idx) { +static inline void rx_video_session_put(struct st_rx_video_sessions_mgr *mgr, + int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl* impl, - struct st20_rx_ops* ops, mt_sch_mask_t sch_mask); +st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, + struct st20_rx_ops *ops, + mt_sch_mask_t sch_mask); -void rx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, - struct st_rx_video_session_impl* s); -void rx_video_session_clear_cpu_busy(struct st_rx_video_session_impl* s); +void rx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, + struct st_rx_video_session_impl *s); +void rx_video_session_clear_cpu_busy(struct st_rx_video_session_impl *s); -static inline bool rx_video_session_is_cpu_busy(struct st_rx_video_session_impl* s) { - if (s->dma_dev && (s->dma_busy_score > 90)) return true; - if (s->imiss_busy_score > 95.0) return true; - if (s->cpu_busy_score > 95.0) return true; +static inline bool +rx_video_session_is_cpu_busy(struct st_rx_video_session_impl *s) { + if (s->dma_dev && (s->dma_busy_score > 90)) + return true; + if (s->imiss_busy_score > 95.0) + return true; + if (s->cpu_busy_score > 95.0) + return true; return false; } -static inline float rx_video_session_get_cpu_busy(struct st_rx_video_session_impl* s) { +static inline float +rx_video_session_get_cpu_busy(struct st_rx_video_session_impl *s) { return s->cpu_busy_score; } -static inline bool rx_video_session_can_migrate(struct st_rx_video_session_impl* s) { +static inline bool +rx_video_session_can_migrate(struct st_rx_video_session_impl *s) { if (s->ops.flags & ST20_RX_FLAG_DISABLE_MIGRATE) return false; else return true; } -int st_rx_video_session_migrate(struct mtl_main_impl* impl, - struct st_rx_video_sessions_mgr* mgr, - struct st_rx_video_session_impl* s, int idx); +int st_rx_video_session_migrate(struct mtl_main_impl *impl, + struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, int idx); #endif diff --git a/lib/src/st2110/st_tx_ancillary_session.c b/lib/src/st2110/st_tx_ancillary_session.c index 14fd789f3..d5e8d1b8e 100644 --- a/lib/src/st2110/st_tx_ancillary_session.c +++ b/lib/src/st2110/st_tx_ancillary_session.c @@ -11,37 +11,45 @@ #include "st_err.h" /* call tx_ancillary_session_put always if get successfully */ -static inline struct st_tx_ancillary_session_impl* tx_ancillary_session_get( - struct st_tx_ancillary_sessions_mgr* mgr, int idx) { +static inline struct st_tx_ancillary_session_impl * +tx_ancillary_session_get(struct st_tx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_tx_ancillary_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); + struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_ancillary_session_put always if get successfully */ -static inline struct st_tx_ancillary_session_impl* tx_ancillary_session_try_get( - struct st_tx_ancillary_sessions_mgr* mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; - struct st_tx_ancillary_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_tx_ancillary_session_impl * +tx_ancillary_session_try_get(struct st_tx_ancillary_sessions_mgr *mgr, + int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) + return NULL; + struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_ancillary_session_put always if get successfully */ -static inline struct st_tx_ancillary_session_impl* tx_ancillary_session_get_timeout( - struct st_tx_ancillary_sessions_mgr* mgr, int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; - struct st_tx_ancillary_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_tx_ancillary_session_impl * +tx_ancillary_session_get_timeout(struct st_tx_ancillary_sessions_mgr *mgr, + int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) + return NULL; + struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline bool tx_ancillary_session_get_empty( - struct st_tx_ancillary_sessions_mgr* mgr, int idx) { +static inline bool +tx_ancillary_session_get_empty(struct st_tx_ancillary_sessions_mgr *mgr, + int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_tx_ancillary_session_impl* s = mgr->sessions[idx]; + struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; if (s) { rte_spinlock_unlock(&mgr->mutex[idx]); /* not null, unlock it */ return false; @@ -50,18 +58,20 @@ static inline bool tx_ancillary_session_get_empty( } } -static inline void tx_ancillary_session_put(struct st_tx_ancillary_sessions_mgr* mgr, - int idx) { +static inline void +tx_ancillary_session_put(struct st_tx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -static int tx_ancillary_session_free_frames(struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_free_frames(struct st_tx_ancillary_session_impl *s) { if (s->st40_frames) { - struct st_frame_trans* frame; + struct st_frame_trans *frame; /* dec ref for current frame */ frame = &s->st40_frames[s->st40_frame_idx]; - if (rte_atomic32_read(&frame->refcnt)) rte_atomic32_dec(&frame->refcnt); + if (rte_atomic32_read(&frame->refcnt)) + rte_atomic32_dec(&frame->refcnt); for (int i = 0; i < s->st40_frames_cnt; i++) { frame = &s->st40_frames[i]; @@ -76,18 +86,19 @@ static int tx_ancillary_session_free_frames(struct st_tx_ancillary_session_impl* return 0; } -static int tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl *s) { int soc_id = s->socket_id; int idx = s->idx; - struct st_frame_trans* frame_info; + struct st_frame_trans *frame_info; if (s->st40_frames) { err("%s(%d), st40_frames already alloc\n", __func__, idx); return -EIO; } - s->st40_frames = - mt_rte_zmalloc_socket(sizeof(*s->st40_frames) * s->st40_frames_cnt, soc_id); + s->st40_frames = mt_rte_zmalloc_socket( + sizeof(*s->st40_frames) * s->st40_frames_cnt, soc_id); if (!s->st40_frames) { err("%s(%d), st30_frames malloc fail\n", __func__, idx); return -ENOMEM; @@ -102,7 +113,7 @@ static int tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl for (int i = 0; i < s->st40_frames_cnt; i++) { frame_info = &s->st40_frames[i]; - void* frame = mt_rte_zmalloc_socket(sizeof(struct st40_frame), soc_id); + void *frame = mt_rte_zmalloc_socket(sizeof(struct st40_frame), soc_id); if (!frame) { err("%s(%d), frame malloc fail at %d\n", __func__, idx, i); tx_ancillary_session_free_frames(s); @@ -117,36 +128,39 @@ static int tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl return 0; } -static int tx_ancillary_session_init_hdr(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s, - enum mtl_session_port s_port) { +static int tx_ancillary_session_init_hdr( + struct mtl_main_impl *impl, struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, enum mtl_session_port s_port) { MTL_MAY_UNUSED(mgr); int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct st40_tx_ops* ops = &s->ops; + struct st40_tx_ops *ops = &s->ops; int ret; - struct st_rfc8331_anc_hdr* hdr = &s->hdr[s_port]; - struct rte_ether_hdr* eth = &hdr->eth; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; - struct st40_rfc8331_rtp_hdr* rtp = &hdr->rtp; - uint8_t* dip = ops->dip_addr[s_port]; - uint8_t* sip = mt_sip_addr(impl, port); - struct rte_ether_addr* d_addr = mt_eth_d_addr(eth); + struct st_rfc8331_anc_hdr *hdr = &s->hdr[s_port]; + struct rte_ether_hdr *eth = &hdr->eth; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; + struct st40_rfc8331_rtp_hdr *rtp = &hdr->rtp; + uint8_t *dip = ops->dip_addr[s_port]; + uint8_t *sip = mt_sip_addr(impl, port); + struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); /* ether hdr */ - if ((s_port == MTL_SESSION_PORT_P) && (ops->flags & ST40_TX_FLAG_USER_P_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); + if ((s_port == MTL_SESSION_PORT_P) && + (ops->flags & ST40_TX_FLAG_USER_P_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], + RTE_ETHER_ADDR_LEN); info("%s, USER_P_TX_MAC\n", __func__); - } else if ((s_port == MTL_SESSION_PORT_R) && (ops->flags & ST40_TX_FLAG_USER_R_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); + } else if ((s_port == MTL_SESSION_PORT_R) && + (ops->flags & ST40_TX_FLAG_USER_R_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], + RTE_ETHER_ADDR_LEN); info("%s, USER_R_TX_MAC\n", __func__); } else { ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], - dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, + dip[0], dip[1], dip[2], dip[3]); return ret; } } @@ -188,62 +202,73 @@ static int tx_ancillary_session_init_hdr(struct mtl_main_impl* impl, s->st40_seq_id = 0; s->st40_ext_seq_id = 0; - info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], dip[1], - dip[2], dip[3], s->st40_src_port[s_port], s->st40_dst_port[s_port]); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", __func__, idx, - d_addr->addr_bytes[0], d_addr->addr_bytes[1], d_addr->addr_bytes[2], - d_addr->addr_bytes[3], d_addr->addr_bytes[4], d_addr->addr_bytes[5], ssrc); + info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], + dip[1], dip[2], dip[3], s->st40_src_port[s_port], + s->st40_dst_port[s_port]); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", + __func__, idx, d_addr->addr_bytes[0], d_addr->addr_bytes[1], + d_addr->addr_bytes[2], d_addr->addr_bytes[3], d_addr->addr_bytes[4], + d_addr->addr_bytes[5], ssrc); return 0; } -static int tx_ancillary_session_init_pacing(struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_init_pacing(struct st_tx_ancillary_session_impl *s) { int idx = s->idx; - struct st_tx_ancillary_session_pacing* pacing = &s->pacing; + struct st_tx_ancillary_session_pacing *pacing = &s->pacing; double frame_time = (double)1000000000.0 * s->fps_tm.den / s->fps_tm.mul; pacing->frame_time = frame_time; pacing->frame_time_sampling = (double)(s->fps_tm.sampling_clock_rate) * s->fps_tm.den / s->fps_tm.mul; pacing->max_onward_epochs = (double)(NS_PER_S * 1) / frame_time; /* 1s */ - dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, pacing->max_onward_epochs); + dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, + pacing->max_onward_epochs); info("%s[%02d], frame_time %f frame_time_sampling %f\n", __func__, idx, pacing->frame_time, pacing->frame_time_sampling); return 0; } -static int tx_ancillary_session_init_pacing_epoch( - struct mtl_main_impl* impl, struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_init_pacing_epoch(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s) { uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); - struct st_tx_ancillary_session_pacing* pacing = &s->pacing; + struct st_tx_ancillary_session_pacing *pacing = &s->pacing; pacing->cur_epochs = ptp_time / pacing->frame_time; return 0; } -static inline double tx_ancillary_pacing_time( - struct st_tx_ancillary_session_pacing* pacing, uint64_t epochs) { +static inline double +tx_ancillary_pacing_time(struct st_tx_ancillary_session_pacing *pacing, + uint64_t epochs) { return epochs * pacing->frame_time; } -static inline uint32_t tx_ancillary_pacing_time_stamp( - struct st_tx_ancillary_session_pacing* pacing, uint64_t epochs) { +static inline uint32_t +tx_ancillary_pacing_time_stamp(struct st_tx_ancillary_session_pacing *pacing, + uint64_t epochs) { uint64_t tmstamp64 = epochs * pacing->frame_time_sampling; uint32_t tmstamp32 = tmstamp64; return tmstamp32; } -static uint64_t tx_ancillary_pacing_required_tai(struct st_tx_ancillary_session_impl* s, - enum st10_timestamp_fmt tfmt, - uint64_t timestamp) { +static uint64_t +tx_ancillary_pacing_required_tai(struct st_tx_ancillary_session_impl *s, + enum st10_timestamp_fmt tfmt, + uint64_t timestamp) { uint64_t required_tai = 0; - if (!(s->ops.flags & ST40_TX_FLAG_USER_PACING)) return 0; - if (!timestamp) return 0; + if (!(s->ops.flags & ST40_TX_FLAG_USER_PACING)) + return 0; + if (!timestamp) + return 0; if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (timestamp > 0xFFFFFFFF) { - err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, timestamp); + err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, + timestamp); } required_tai = st10_media_clk_to_ns((uint32_t)timestamp, 90 * 1000); } else { @@ -253,11 +278,10 @@ static uint64_t tx_ancillary_pacing_required_tai(struct st_tx_ancillary_session_ return required_tai; } -static int tx_ancillary_session_sync_pacing(struct mtl_main_impl* impl, - struct st_tx_ancillary_session_impl* s, - bool sync, uint64_t required_tai, - bool second_field) { - struct st_tx_ancillary_session_pacing* pacing = &s->pacing; +static int tx_ancillary_session_sync_pacing( + struct mtl_main_impl *impl, struct st_tx_ancillary_session_impl *s, + bool sync, uint64_t required_tai, bool second_field) { + struct st_tx_ancillary_session_pacing *pacing = &s->pacing; double frame_time = pacing->frame_time; /* always use MTL_PORT_P for ptp now */ uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); @@ -269,9 +293,11 @@ static int tx_ancillary_session_sync_pacing(struct mtl_main_impl* impl, if (required_tai) { uint64_t ptp_epochs = ptp_time / frame_time; epochs = required_tai / frame_time; - dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 " epochs %" PRIu64 "\n", + dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 + " epochs %" PRIu64 "\n", __func__, s->idx, required_tai, ptp_epochs, epochs); - if (epochs < ptp_epochs) s->stat_error_user_timestamp++; + if (epochs < ptp_epochs) + s->stat_error_user_timestamp++; } else { epochs = ptp_time / frame_time; } @@ -288,10 +314,12 @@ static int tx_ancillary_session_sync_pacing(struct mtl_main_impl* impl, if (interlaced) { if (second_field) { /* align to odd epoch */ - if (!(epochs & 0x1)) epochs++; + if (!(epochs & 0x1)) + epochs++; s->stat_interlace_second_field++; } else { /* align to even epoch */ - if (epochs & 0x1) epochs++; + if (epochs & 0x1) + epochs++; s->stat_interlace_first_field++; } } @@ -303,17 +331,19 @@ static int tx_ancillary_session_sync_pacing(struct mtl_main_impl* impl, to_epoch = 0; /* send asap */ } - if (epochs > next_epochs) s->stat_epoch_drop += (epochs - next_epochs); - if (epochs < next_epochs) s->stat_epoch_onward += (next_epochs - epochs); + if (epochs > next_epochs) + s->stat_epoch_drop += (epochs - next_epochs); + if (epochs < next_epochs) + s->stat_epoch_onward += (next_epochs - epochs); pacing->cur_epochs = epochs; pacing->cur_epoch_time = tx_ancillary_pacing_time(pacing, epochs); pacing->pacing_time_stamp = tx_ancillary_pacing_time_stamp(pacing, epochs); pacing->rtp_time_stamp = pacing->pacing_time_stamp; pacing->tsc_time_cursor = (double)mt_get_tsc(impl) + to_epoch; - dbg("%s(%d), epochs %" PRIu64 " time_stamp %u time_cursor %f to_epoch %f\n", __func__, - s->idx, pacing->cur_epochs, pacing->pacing_time_stamp, pacing->tsc_time_cursor, - to_epoch); + dbg("%s(%d), epochs %" PRIu64 " time_stamp %u time_cursor %f to_epoch %f\n", + __func__, s->idx, pacing->cur_epochs, pacing->pacing_time_stamp, + pacing->tsc_time_cursor, to_epoch); if (sync) { dbg("%s(%d), delay to epoch_time %f, cur %" PRIu64 "\n", __func__, s->idx, @@ -324,14 +354,16 @@ static int tx_ancillary_session_sync_pacing(struct mtl_main_impl* impl, return 0; } -static int tx_ancillary_session_init_next_meta(struct st_tx_ancillary_session_impl* s, - struct st40_tx_frame_meta* meta) { - struct st_tx_ancillary_session_pacing* pacing = &s->pacing; - struct st40_tx_ops* ops = &s->ops; +static int +tx_ancillary_session_init_next_meta(struct st_tx_ancillary_session_impl *s, + struct st40_tx_frame_meta *meta) { + struct st_tx_ancillary_session_pacing *pacing = &s->pacing; + struct st40_tx_ops *ops = &s->ops; memset(meta, 0, sizeof(*meta)); meta->fps = ops->fps; - if (ops->interlaced) { /* init second_field but user still can customize also */ + if (ops->interlaced) { /* init second_field but user still can customize also + */ meta->second_field = s->second_field; } /* point to next epoch */ @@ -341,21 +373,23 @@ static int tx_ancillary_session_init_next_meta(struct st_tx_ancillary_session_im return 0; } -static int tx_ancillary_session_init(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s, int idx) { +static int tx_ancillary_session_init(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + int idx) { MTL_MAY_UNUSED(mgr); s->idx = idx; return 0; } -static int tx_ancillary_sessions_tasklet_start(void* priv) { - struct st_tx_ancillary_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_ancillary_session_impl* s; +static int tx_ancillary_sessions_tasklet_start(void *priv) { + struct st_tx_ancillary_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_ancillary_session_impl *s; for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_ancillary_session_get(mgr, sidx); - if (!s) continue; + if (!s) + continue; tx_ancillary_session_init_pacing_epoch(impl, s); tx_ancillary_session_put(mgr, sidx); @@ -364,11 +398,12 @@ static int tx_ancillary_sessions_tasklet_start(void* priv) { return 0; } -static int tx_ancillary_session_update_redundant(struct st_tx_ancillary_session_impl* s, - struct rte_mbuf* pkt_r) { - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr*); - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; +static int +tx_ancillary_session_update_redundant(struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt_r) { + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr *); + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; /* update the hdr: eth, ip, udp */ rte_memcpy(hdr, &s->hdr[MTL_SESSION_PORT_R], sizeof(*hdr)); @@ -384,17 +419,18 @@ static int tx_ancillary_session_update_redundant(struct st_tx_ancillary_session_ return 0; } -static int tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl* s, - struct rte_mbuf* pkt) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st40_rfc8331_rtp_hdr* rtp; +static int +tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st40_rfc8331_rtp_hdr *rtp; - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; - rtp = (struct st40_rfc8331_rtp_hdr*)&udp[1]; + rtp = (struct st40_rfc8331_rtp_hdr *)&udp[1]; /* copy the hdr: eth, ip, udp */ rte_memcpy(&hdr->eth, &s->hdr[MTL_SESSION_PORT_P].eth, sizeof(hdr->eth)); @@ -411,25 +447,27 @@ static int tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl /* update rtp */ rtp->base.seq_number = htons(s->st40_seq_id); rtp->seq_number_ext = htons(s->st40_ext_seq_id); - if (s->st40_seq_id == 0xFFFF) s->st40_ext_seq_id++; + if (s->st40_seq_id == 0xFFFF) + s->st40_ext_seq_id++; s->st40_seq_id++; rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); /* Set place for payload just behind rtp header */ - uint8_t* payload = (uint8_t*)&rtp[1]; - struct st_frame_trans* frame_info = &s->st40_frames[s->st40_frame_idx]; + uint8_t *payload = (uint8_t *)&rtp[1]; + struct st_frame_trans *frame_info = &s->st40_frames[s->st40_frame_idx]; uint32_t offset = s->st40_pkt_idx * s->max_pkt_len; - void* src_addr = frame_info->addr + offset; - struct st40_frame* src = src_addr; + void *src_addr = frame_info->addr + offset; + struct st40_frame *src = src_addr; int anc_count = src->meta_num; int total_udw = 0; int idx = 0; for (idx = s->st40_pkt_idx; idx < anc_count; idx++) { uint16_t udw_size = src->meta[idx].udw_size; total_udw += udw_size; - if ((total_udw * 10 / 8) > s->max_pkt_len) break; - struct st40_rfc8331_payload_hdr* pktBuff = - (struct st40_rfc8331_payload_hdr*)(payload); + if ((total_udw * 10 / 8) > s->max_pkt_len) + break; + struct st40_rfc8331_payload_hdr *pktBuff = + (struct st40_rfc8331_payload_hdr *)(payload); pktBuff->first_hdr_chunk.c = src->meta[idx].c; pktBuff->first_hdr_chunk.line_number = src->meta[idx].line_number; pktBuff->first_hdr_chunk.horizontal_offset = src->meta[idx].hori_offset; @@ -445,23 +483,25 @@ static int tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl int offset = src->meta[idx].udw_offset; for (; i < udw_size; i++) { st40_set_udw(i + 3, st40_add_parity_bits(src->data[offset++]), - (uint8_t*)&pktBuff->second_hdr_chunk); + (uint8_t *)&pktBuff->second_hdr_chunk); } uint16_t checksum = 0; - checksum = st40_calc_checksum(3 + udw_size, (uint8_t*)&pktBuff->second_hdr_chunk); - st40_set_udw(i + 3, checksum, (uint8_t*)&pktBuff->second_hdr_chunk); + checksum = + st40_calc_checksum(3 + udw_size, (uint8_t *)&pktBuff->second_hdr_chunk); + st40_set_udw(i + 3, checksum, (uint8_t *)&pktBuff->second_hdr_chunk); uint16_t total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - uint16_t size_to_send = - sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = + (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + uint16_t size_to_send = sizeof(struct st40_rfc8331_payload_hdr) - 4 + + total_size; // Full size of one ANC payload = payload + size_to_send; } - int payload_size = payload - (uint8_t*)&rtp[1]; + int payload_size = payload - (uint8_t *)&rtp[1]; pkt->data_len += payload_size + sizeof(struct st40_rfc8331_rtp_hdr); pkt->pkt_len = pkt->data_len; rtp->length = htons(payload_size); @@ -474,7 +514,8 @@ static int tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl } else { rtp->f = 0b00; } - if (idx == anc_count) rtp->base.marker = 1; + if (idx == anc_count) + rtp->base.marker = 1; dbg("%s(%d), anc_count %d, payload_size %d\n", __func__, s->idx, anc_count, payload_size); @@ -489,35 +530,38 @@ static int tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl return idx; } -static int tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl* s, - struct rte_mbuf* pkt, int anc_idx) { - struct st40_rfc8331_rtp_hdr* rtp; +static int +tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt, int anc_idx) { + struct st40_rfc8331_rtp_hdr *rtp; - rtp = rte_pktmbuf_mtod(pkt, struct st40_rfc8331_rtp_hdr*); + rtp = rte_pktmbuf_mtod(pkt, struct st40_rfc8331_rtp_hdr *); rte_memcpy(rtp, &s->hdr[MTL_SESSION_PORT_P].rtp, sizeof(*rtp)); /* update rtp */ rtp->base.seq_number = htons(s->st40_seq_id); rtp->seq_number_ext = htons(s->st40_ext_seq_id); - if (s->st40_seq_id == 0xFFFF) s->st40_ext_seq_id++; + if (s->st40_seq_id == 0xFFFF) + s->st40_ext_seq_id++; s->st40_seq_id++; rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); /* Set place for payload just behind rtp header */ - uint8_t* payload = (uint8_t*)&rtp[1]; - struct st_frame_trans* frame_info = &s->st40_frames[s->st40_frame_idx]; + uint8_t *payload = (uint8_t *)&rtp[1]; + struct st_frame_trans *frame_info = &s->st40_frames[s->st40_frame_idx]; uint32_t offset = s->st40_pkt_idx * s->max_pkt_len; - void* src_addr = frame_info->addr + offset; - struct st40_frame* src = src_addr; + void *src_addr = frame_info->addr + offset; + struct st40_frame *src = src_addr; int anc_count = src->meta_num; int total_udw = 0; int idx = 0; for (idx = anc_idx; idx < anc_count; idx++) { uint16_t udw_size = src->meta[idx].udw_size; total_udw += udw_size; - if ((total_udw * 10 / 8) > s->max_pkt_len) break; - struct st40_rfc8331_payload_hdr* pktBuff = - (struct st40_rfc8331_payload_hdr*)(payload); + if ((total_udw * 10 / 8) > s->max_pkt_len) + break; + struct st40_rfc8331_payload_hdr *pktBuff = + (struct st40_rfc8331_payload_hdr *)(payload); pktBuff->first_hdr_chunk.c = src->meta[idx].c; pktBuff->first_hdr_chunk.line_number = src->meta[idx].line_number; pktBuff->first_hdr_chunk.horizontal_offset = src->meta[idx].hori_offset; @@ -533,23 +577,25 @@ static int tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_ int offset = src->meta[idx].udw_offset; for (; i < udw_size; i++) { st40_set_udw(i + 3, st40_add_parity_bits(src->data[offset++]), - (uint8_t*)&pktBuff->second_hdr_chunk); + (uint8_t *)&pktBuff->second_hdr_chunk); } uint16_t checksum = 0; - checksum = st40_calc_checksum(3 + udw_size, (uint8_t*)&pktBuff->second_hdr_chunk); - st40_set_udw(i + 3, checksum, (uint8_t*)&pktBuff->second_hdr_chunk); + checksum = + st40_calc_checksum(3 + udw_size, (uint8_t *)&pktBuff->second_hdr_chunk); + st40_set_udw(i + 3, checksum, (uint8_t *)&pktBuff->second_hdr_chunk); uint16_t total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - uint16_t size_to_send = - sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = + (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + uint16_t size_to_send = sizeof(struct st40_rfc8331_payload_hdr) - 4 + + total_size; // Full size of one ANC payload = payload + size_to_send; } - int payload_size = payload - (uint8_t*)&rtp[1]; + int payload_size = payload - (uint8_t *)&rtp[1]; pkt->data_len = payload_size + sizeof(struct st40_rfc8331_rtp_hdr); pkt->pkt_len = pkt->data_len; rtp->length = htons(payload_size); @@ -562,25 +608,27 @@ static int tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_ } else { rtp->f = 0b00; } - if (idx == anc_count) rtp->base.marker = 1; + if (idx == anc_count) + rtp->base.marker = 1; dbg("%s(%d), anc_count %d, payload_size %d\n", __func__, s->idx, anc_count, payload_size); return idx; } -static int tx_ancillary_session_rtp_update_packet(struct mtl_main_impl* impl, - struct st_tx_ancillary_session_impl* s, - struct rte_mbuf* pkt) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct st_rfc3550_rtp_hdr* rtp; - struct rte_udp_hdr* udp; +static int +tx_ancillary_session_rtp_update_packet(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct st_rfc3550_rtp_hdr *rtp; + struct rte_udp_hdr *udp; - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; - rtp = - rte_pktmbuf_mtod_offset(pkt, struct st_rfc3550_rtp_hdr*, sizeof(struct mt_udp_hdr)); + rtp = rte_pktmbuf_mtod_offset(pkt, struct st_rfc3550_rtp_hdr *, + sizeof(struct mt_udp_hdr)); /* copy the hdr: eth, ip, udp */ rte_memcpy(&hdr->eth, &s->hdr[MTL_SESSION_PORT_P].eth, sizeof(hdr->eth)); @@ -594,7 +642,7 @@ static int tx_ancillary_session_rtp_update_packet(struct mtl_main_impl* impl, s->st40_rtp_time = rtp->tmstamp; bool second_field = false; if (s->ops.interlaced) { - struct st40_rfc8331_rtp_hdr* rfc8331 = (struct st40_rfc8331_rtp_hdr*)rtp; + struct st40_rfc8331_rtp_hdr *rfc8331 = (struct st40_rfc8331_rtp_hdr *)rtp; second_field = (rfc8331->f == 0b11) ? true : false; } tx_ancillary_session_sync_pacing(impl, s, false, 0, second_field); @@ -618,17 +666,16 @@ static int tx_ancillary_session_rtp_update_packet(struct mtl_main_impl* impl, return 0; } -static int tx_ancillary_session_build_packet_chain(struct mtl_main_impl* impl, - struct st_tx_ancillary_session_impl* s, - struct rte_mbuf* pkt, - struct rte_mbuf* pkt_rtp, - enum mtl_session_port s_port) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st40_tx_ops* ops = &s->ops; - - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); +static int tx_ancillary_session_build_packet_chain( + struct mtl_main_impl *impl, struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt, struct rte_mbuf *pkt_rtp, + enum mtl_session_port s_port) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st40_tx_ops *ops = &s->ops; + + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; @@ -641,8 +688,8 @@ static int tx_ancillary_session_build_packet_chain(struct mtl_main_impl* impl, if (s_port == MTL_SESSION_PORT_P) { /* update rtp time for rtp path */ if (ops->type == ST40_TYPE_RTP_LEVEL) { - struct st40_rfc8331_rtp_hdr* rtp = - rte_pktmbuf_mtod(pkt_rtp, struct st40_rfc8331_rtp_hdr*); + struct st40_rfc8331_rtp_hdr *rtp = + rte_pktmbuf_mtod(pkt_rtp, struct st40_rfc8331_rtp_hdr *); if (rtp->base.tmstamp != s->st40_rtp_time) { /* start of a new frame */ s->st40_pkt_idx = 0; @@ -650,7 +697,8 @@ static int tx_ancillary_session_build_packet_chain(struct mtl_main_impl* impl, s->st40_rtp_time = rtp->base.tmstamp; bool second_field = false; if (s->ops.interlaced) { - struct st40_rfc8331_rtp_hdr* rfc8331 = (struct st40_rfc8331_rtp_hdr*)&udp[1]; + struct st40_rfc8331_rtp_hdr *rfc8331 = + (struct st40_rfc8331_rtp_hdr *)&udp[1]; second_field = (rfc8331->f == 0b11) ? true : false; } tx_ancillary_session_sync_pacing(impl, s, false, 0, second_field); @@ -679,18 +727,20 @@ static int tx_ancillary_session_build_packet_chain(struct mtl_main_impl* impl, } /* rtp packet used twice for redundant path */ - if (s_port == MTL_SESSION_PORT_R) rte_mbuf_refcnt_update(pkt_rtp, 1); + if (s_port == MTL_SESSION_PORT_R) + rte_mbuf_refcnt_update(pkt_rtp, 1); return 0; } -static inline int tx_ancillary_session_send_pkt(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s, - enum mtl_session_port s_port, - struct rte_mbuf* pkt) { +static inline int +tx_ancillary_session_send_pkt(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + enum mtl_session_port s_port, + struct rte_mbuf *pkt) { int ret; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct rte_ring* ring = mgr->ring[port]; + struct rte_ring *ring = mgr->ring[port]; if (s->queue[s_port]) { uint16_t tx = mt_txq_burst(s->queue[s_port], &pkt, 1); @@ -699,24 +749,25 @@ static inline int tx_ancillary_session_send_pkt(struct st_tx_ancillary_sessions_ else ret = 0; } else { - ret = rte_ring_mp_enqueue(ring, (void*)pkt); + ret = rte_ring_mp_enqueue(ring, (void *)pkt); } return ret; } -static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx; - struct st40_tx_ops* ops = &s->ops; - struct st_tx_ancillary_session_pacing* pacing = &s->pacing; + struct st40_tx_ops *ops = &s->ops; + struct st_tx_ancillary_session_pacing *pacing = &s->pacing; int ret; bool send_r = false; enum mtl_port port_p = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); - struct rte_mempool* hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; - struct rte_mempool* hdr_pool_r = NULL; - struct rte_mempool* chain_pool = s->mbuf_mempool_chain; - struct rte_ring* ring_p = mgr->ring[port_p]; + struct rte_mempool *hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; + struct rte_mempool *hdr_pool_r = NULL; + struct rte_mempool *chain_pool = s->mbuf_mempool_chain; + struct rte_ring *ring_p = mgr->ring[port_p]; if (ring_p && rte_ring_full(ring_p)) { s->stat_build_ret_code = -STI_FRAME_RING_FULL; @@ -761,7 +812,8 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; dbg("%s(%d), frame %d build time out %" PRIu64 " us\n", __func__, idx, - s->st40_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); + s->st40_frame_idx, + (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } s->check_frame_done_time = false; } @@ -770,7 +822,8 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, /* Query next frame buffer idx */ uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); ret = ops->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; @@ -782,10 +835,11 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, return MTL_TASKLET_ALL_DONE; } /* check frame refcnt */ - struct st_frame_trans* frame = &s->st40_frames[next_frame_idx]; + struct st_frame_trans *frame = &s->st40_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, + next_frame_idx, refcnt); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -794,18 +848,20 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, s->st40_frame_idx = next_frame_idx; dbg("%s(%d), next_frame_idx %d start\n", __func__, idx, next_frame_idx); s->st40_frame_stat = ST40_TX_STAT_SENDING_PKTS; - struct st40_frame* src = (struct st40_frame*)frame->addr; - for (int i = 0; i < src->meta_num; i++) total_udw += src->meta[i].udw_size; + struct st40_frame *src = (struct st40_frame *)frame->addr; + for (int i = 0; i < src->meta_num; i++) + total_udw += src->meta[i].udw_size; int total_size = total_udw * 10 / 8; s->st40_pkt_idx = 0; s->st40_total_pkts = total_size / s->max_pkt_len; - if (total_size % s->max_pkt_len) s->st40_total_pkts++; + if (total_size % s->max_pkt_len) + s->st40_total_pkts++; /* how do we split if it need two or more pkts? */ - dbg("%s(%d), st40_total_pkts %d total_udw %d meta_num %u src %p\n", __func__, idx, - s->st40_total_pkts, total_udw, src->meta_num, src); + dbg("%s(%d), st40_total_pkts %d total_udw %d meta_num %u src %p\n", + __func__, idx, s->st40_total_pkts, total_udw, src->meta_num, src); if (s->st40_total_pkts > 1) { - err("%s(%d), frame %u invalid st40_total_pkts %d\n", __func__, idx, next_frame_idx, - s->st40_total_pkts); + err("%s(%d), frame %u invalid st40_total_pkts %d\n", __func__, idx, + next_frame_idx, s->st40_total_pkts); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -816,12 +872,13 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, /* sync pacing */ if (s->calculate_time_cursor) { - struct st_frame_trans* frame = &s->st40_frames[s->st40_frame_idx]; + struct st_frame_trans *frame = &s->st40_frames[s->st40_frame_idx]; /* user timestamp control if any */ - uint64_t required_tai = tx_ancillary_pacing_required_tai(s, frame->tc_meta.tfmt, - frame->tc_meta.timestamp); + uint64_t required_tai = tx_ancillary_pacing_required_tai( + s, frame->tc_meta.tfmt, frame->tc_meta.timestamp); bool second_field = frame->tc_meta.second_field; - tx_ancillary_session_sync_pacing(impl, s, false, required_tai, second_field); + tx_ancillary_session_sync_pacing(impl, s, false, required_tai, + second_field); if (ops->flags & ST40_TX_FLAG_USER_TIMESTAMP && (frame->ta_meta.tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK)) { pacing->rtp_time_stamp = (uint32_t)frame->tc_meta.timestamp; @@ -840,20 +897,20 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, uint64_t target_tsc = pacing->tsc_time_cursor; if (cur_tsc < target_tsc) { uint64_t delta = target_tsc - cur_tsc; - // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, cur_tsc, - // target_tsc); + // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, + // cur_tsc, target_tsc); if (likely(delta < NS_PER_S)) { s->stat_build_ret_code = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, + idx, cur_tsc, target_tsc); } } - struct rte_mbuf* pkt = NULL; - struct rte_mbuf* pkt_r = NULL; + struct rte_mbuf *pkt = NULL; + struct rte_mbuf *pkt_r = NULL; pkt = rte_pktmbuf_alloc(hdr_pool_p); if (!pkt) { @@ -863,7 +920,7 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, } if (!s->tx_no_chain) { - struct rte_mbuf* pkt_rtp = rte_pktmbuf_alloc(chain_pool); + struct rte_mbuf *pkt_rtp = rte_pktmbuf_alloc(chain_pool); if (!pkt_rtp) { err("%s(%d), pkt_rtp alloc fail\n", __func__, idx); rte_pktmbuf_free(pkt); @@ -871,7 +928,8 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, return MTL_TASKLET_ALL_DONE; } tx_ancillary_session_build_rtp_packet(s, pkt_rtp, s->st40_pkt_idx); - tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, MTL_SESSION_PORT_P); + tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, + MTL_SESSION_PORT_P); if (send_r) { pkt_r = rte_pktmbuf_alloc(hdr_pool_r); @@ -932,17 +990,19 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, if (s->st40_pkt_idx >= s->st40_total_pkts) { dbg("%s(%d), frame %d done\n", __func__, idx, s->st40_frame_idx); - struct st_frame_trans* frame = &s->st40_frames[s->st40_frame_idx]; - struct st40_tx_frame_meta* tc_meta = &frame->tc_meta; + struct st_frame_trans *frame = &s->st40_frames[s->st40_frame_idx]; + struct st40_tx_frame_meta *tc_meta = &frame->tc_meta; uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); /* end of current frame */ if (s->ops.notify_frame_done) ops->notify_frame_done(ops->priv, s->st40_frame_idx, tc_meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = + RTE_MAX(s->stat_max_notify_frame_us, delta_us); } rte_atomic32_dec(&frame->refcnt); s->st40_frame_stat = ST40_TX_STAT_WAIT_FRAME; @@ -957,17 +1017,18 @@ static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl* impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tx_ancillary_session_tasklet_rtp(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_tasklet_rtp(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx; int ret; - struct st_tx_ancillary_session_pacing* pacing = &s->pacing; + struct st_tx_ancillary_session_pacing *pacing = &s->pacing; bool send_r = false; enum mtl_port port_p = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); - struct rte_mempool* hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; - struct rte_mempool* hdr_pool_r = NULL; - struct rte_ring* ring_p = mgr->ring[port_p]; + struct rte_mempool *hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; + struct rte_mempool *hdr_pool_r = NULL; + struct rte_ring *ring_p = mgr->ring[port_p]; if (ring_p && rte_ring_full(ring_p)) { s->stat_build_ret_code = -STI_RTP_RING_FULL; @@ -1006,23 +1067,23 @@ static int tx_ancillary_session_tasklet_rtp(struct mtl_main_impl* impl, uint64_t target_tsc = pacing->tsc_time_cursor; if (cur_tsc < target_tsc) { uint64_t delta = target_tsc - cur_tsc; - // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, cur_tsc, - // target_tsc); + // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, + // cur_tsc, target_tsc); if (likely(delta < NS_PER_S)) { s->stat_build_ret_code = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, + idx, cur_tsc, target_tsc); } } - struct rte_mbuf* pkt = NULL; - struct rte_mbuf* pkt_r = NULL; - struct rte_mbuf* pkt_rtp = NULL; + struct rte_mbuf *pkt = NULL; + struct rte_mbuf *pkt_r = NULL; + struct rte_mbuf *pkt_rtp = NULL; - if (rte_ring_sc_dequeue(s->packet_ring, (void**)&pkt_rtp) != 0) { + if (rte_ring_sc_dequeue(s->packet_ring, (void **)&pkt_rtp) != 0) { dbg("%s(%d), rtp pkts not ready %d\n", __func__, idx, ret); s->stat_build_ret_code = -STI_RTP_APP_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; @@ -1054,7 +1115,8 @@ static int tx_ancillary_session_tasklet_rtp(struct mtl_main_impl* impl, pkt = pkt_rtp; tx_ancillary_session_rtp_update_packet(impl, s, pkt); } else { - tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, MTL_SESSION_PORT_P); + tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, + MTL_SESSION_PORT_P); } st_tx_mbuf_set_idx(pkt, s->st40_pkt_idx); st_tx_mbuf_set_tsc(pkt, pacing->tsc_time_cursor); @@ -1100,18 +1162,20 @@ static int tx_ancillary_session_tasklet_rtp(struct mtl_main_impl* impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tx_ancillary_sessions_tasklet_handler(void* priv) { - struct st_tx_ancillary_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_ancillary_session_impl* s; +static int tx_ancillary_sessions_tasklet_handler(void *priv) { + struct st_tx_ancillary_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_ancillary_session_impl *s; int pending = MTL_TASKLET_ALL_DONE; uint64_t tsc_s = 0; bool time_measure = mt_sessions_time_measure(impl); for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_ancillary_session_try_get(mgr, sidx); - if (!s) continue; - if (time_measure) tsc_s = mt_get_tsc(impl); + if (!s) + continue; + if (time_measure) + tsc_s = mt_get_tsc(impl); s->stat_build_ret_code = 0; if (s->ops.type == ST40_TYPE_FRAME_LEVEL) @@ -1129,16 +1193,18 @@ static int tx_ancillary_sessions_tasklet_handler(void* priv) { return pending; } -static int tx_ancillary_sessions_mgr_uinit_hw(struct st_tx_ancillary_sessions_mgr* mgr, - enum mtl_port port) { +static int +tx_ancillary_sessions_mgr_uinit_hw(struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { if (mgr->ring[port]) { rte_ring_free(mgr->ring[port]); mgr->ring[port] = NULL; } if (mgr->queue[port]) { - struct rte_mbuf* pad = mt_get_pad(mgr->parent, port); + struct rte_mbuf *pad = mt_get_pad(mgr->parent, port); /* flush all the pkts in the tx ring desc */ - if (pad) mt_txq_flush(mgr->queue[port], pad); + if (pad) + mt_txq_flush(mgr->queue[port], pad); mt_txq_put(mgr->queue[port]); mgr->queue[port] = NULL; } @@ -1147,15 +1213,17 @@ static int tx_ancillary_sessions_mgr_uinit_hw(struct st_tx_ancillary_sessions_mg return 0; } -static int tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - enum mtl_port port) { +static int +tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { unsigned int flags, count; - struct rte_ring* ring; + struct rte_ring *ring; char ring_name[32]; int mgr_idx = mgr->idx; - if (mgr->queue[port]) return 0; /* init already */ + if (mgr->queue[port]) + return 0; /* init already */ struct mt_txq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -1165,7 +1233,8 @@ static int tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl* impl, } snprintf(ring_name, 32, "%sM%dP%d", ST_TX_ANCILLARY_PREFIX, mgr_idx, port); - flags = RING_F_MP_HTS_ENQ | RING_F_SC_DEQ; /* multi-producer and single-consumer */ + flags = RING_F_MP_HTS_ENQ | + RING_F_SC_DEQ; /* multi-producer and single-consumer */ count = ST_TX_ANC_SESSIONS_RING_SIZE; ring = rte_ring_create(ring_name, count, mgr->socket_id, flags); if (!ring) { @@ -1180,18 +1249,19 @@ static int tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl* impl, return 0; } -static int tx_ancillary_session_sq_flush_port(struct st_tx_ancillary_sessions_mgr* mgr, - enum mtl_port port) { - struct mtl_main_impl* impl = mgr->parent; +static int +tx_ancillary_session_sq_flush_port(struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { + struct mtl_main_impl *impl = mgr->parent; int ret; int burst_pkts = mt_if_nb_tx_desc(impl, port); - struct rte_mbuf* pad = mt_get_pad(impl, port); + struct rte_mbuf *pad = mt_get_pad(impl, port); for (int i = 0; i < burst_pkts; i++) { rte_mbuf_refcnt_update(pad, 1); int retry = 0; do { - ret = rte_ring_mp_enqueue(mgr->ring[port], (void*)pad); + ret = rte_ring_mp_enqueue(mgr->ring[port], (void *)pad); if (ret != 0) { dbg("%s(%d), timeout at %d, ret %d\n", __func__, mgr->idx, i, ret); retry++; @@ -1208,67 +1278,76 @@ static int tx_ancillary_session_sq_flush_port(struct st_tx_ancillary_sessions_mg } /* wa to flush the ancillary transmitter tx queue */ -static int tx_ancillary_session_flush(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int tx_ancillary_session_flush(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int mgr_idx = mgr->idx, s_idx = s->idx; - if (!s->shared_queue) return 0; /* skip as not shared queue */ + if (!s->shared_queue) + return 0; /* skip as not shared queue */ for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { - struct rte_mempool* pool = s->mbuf_mempool_hdr[i]; + struct rte_mempool *pool = s->mbuf_mempool_hdr[i]; if (pool && rte_mempool_in_use_count(pool) && rte_atomic32_read(&mgr->transmitter_started)) { info("%s(%d,%d), start to flush port %d\n", __func__, mgr_idx, s_idx, i); - tx_ancillary_session_sq_flush_port(mgr, mt_port_logic2phy(s->port_maps, i)); + tx_ancillary_session_sq_flush_port(mgr, + mt_port_logic2phy(s->port_maps, i)); info("%s(%d,%d), flush port %d end\n", __func__, mgr_idx, s_idx, i); int retry = 100; /* max 1000ms */ while (retry > 0) { retry--; - if (!rte_mempool_in_use_count(pool)) break; + if (!rte_mempool_in_use_count(pool)) + break; mt_sleep_ms(10); } - info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, retry); + info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, + retry); } } return 0; } -int tx_ancillary_session_mempool_free(struct st_tx_ancillary_session_impl* s) { +int tx_ancillary_session_mempool_free(struct st_tx_ancillary_session_impl *s) { int ret; if (s->mbuf_mempool_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_chain); - if (ret >= 0) s->mbuf_mempool_chain = NULL; + if (ret >= 0) + s->mbuf_mempool_chain = NULL; } for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { if (s->mbuf_mempool_hdr[i] && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_hdr[i]); - if (ret >= 0) s->mbuf_mempool_hdr[i] = NULL; + if (ret >= 0) + s->mbuf_mempool_hdr[i] = NULL; } } return 0; } -static bool tx_ancillary_session_has_chain_buf(struct st_tx_ancillary_session_impl* s) { - struct st40_tx_ops* ops = &s->ops; +static bool +tx_ancillary_session_has_chain_buf(struct st_tx_ancillary_session_impl *s) { + struct st40_tx_ops *ops = &s->ops; int num_ports = ops->num_port; for (int port = 0; port < num_ports; port++) { - if (!s->eth_has_chain[port]) return false; + if (!s->eth_has_chain[port]) + return false; } /* all ports capable chain */ return true; } -static int tx_ancillary_session_mempool_init(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { - struct st40_tx_ops* ops = &s->ops; +static int +tx_ancillary_session_mempool_init(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { + struct st40_tx_ops *ops = &s->ops; int num_port = ops->num_port, idx = s->idx; enum mtl_port port; unsigned int n; @@ -1291,13 +1370,14 @@ static int tx_ancillary_session_mempool_init(struct mtl_main_impl* impl, warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, i); } else { n = mt_if_nb_tx_desc(impl, port) + ST_TX_ANC_SESSIONS_RING_SIZE; - if (ops->type == ST40_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; + if (ops->type == ST40_TYPE_RTP_LEVEL) + n += ops->rtp_ring_size; char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%dP%d_HDR", ST_TX_ANCILLARY_PREFIX, mgr->idx, idx, - i); - struct rte_mempool* mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), - hdr_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%dP%d_HDR", ST_TX_ANCILLARY_PREFIX, + mgr->idx, idx, i); + struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( + impl, pool_name, n, MT_MBUF_CACHE_SIZE, + sizeof(struct mt_muf_priv_data), hdr_room_size, s->socket_id); if (!mbuf_pool) { tx_ancillary_session_mempool_free(s); return -ENOMEM; @@ -1310,7 +1390,8 @@ static int tx_ancillary_session_mempool_init(struct mtl_main_impl* impl, if (!s->tx_no_chain) { port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); n = mt_if_nb_tx_desc(impl, port) + ST_TX_ANC_SESSIONS_RING_SIZE; - if (ops->type == ST40_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; + if (ops->type == ST40_TYPE_RTP_LEVEL) + n += ops->rtp_ring_size; if (s->tx_mono_pool) { s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port); @@ -1320,10 +1401,11 @@ static int tx_ancillary_session_mempool_init(struct mtl_main_impl* impl, warn("%s(%d), use previous chain mempool\n", __func__, idx); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_CHAIN", ST_TX_ANCILLARY_PREFIX, mgr->idx, idx); - struct rte_mempool* mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), - chain_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%d_CHAIN", ST_TX_ANCILLARY_PREFIX, + mgr->idx, idx); + struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( + impl, pool_name, n, MT_MBUF_CACHE_SIZE, + sizeof(struct mt_muf_priv_data), chain_room_size, s->socket_id); if (!mbuf_pool) { tx_ancillary_session_mempool_free(s); return -ENOMEM; @@ -1335,15 +1417,17 @@ static int tx_ancillary_session_mempool_init(struct mtl_main_impl* impl, return 0; } -static int tx_ancillary_session_init_rtp(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_init_rtp(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count = s->ops.rtp_ring_size; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_TX_ANCILLARY_PREFIX, mgr_idx, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { err("%s(%d,%d), rte_ring_create fail\n", __func__, mgr_idx, idx); @@ -1355,8 +1439,9 @@ static int tx_ancillary_session_init_rtp(struct st_tx_ancillary_sessions_mgr* mg return 0; } -static int tx_ancillary_session_uinit_sw(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_uinit_sw(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx, num_port = s->ops.num_port; for (int port = 0; port < num_port; port++) { @@ -1381,10 +1466,11 @@ static int tx_ancillary_session_uinit_sw(struct st_tx_ancillary_sessions_mgr* mg return 0; } -static int tx_ancillary_session_init_sw(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { - struct st40_tx_ops* ops = &s->ops; +static int +tx_ancillary_session_init_sw(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { + struct st40_tx_ops *ops = &s->ops; int idx = s->idx, ret; /* free the pool if any in previous session */ @@ -1410,8 +1496,9 @@ static int tx_ancillary_session_init_sw(struct mtl_main_impl* impl, return 0; } -static int tx_ancillary_session_uinit_queue(struct mtl_main_impl* impl, - struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_uinit_queue(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s) { MTL_MAY_UNUSED(impl); for (int i = 0; i < s->ops.num_port; i++) { @@ -1426,8 +1513,9 @@ static int tx_ancillary_session_uinit_queue(struct mtl_main_impl* impl, return 0; } -static int tx_ancillary_session_init_queue(struct mtl_main_impl* impl, - struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_session_init_queue(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx; enum mtl_port port; uint16_t queue_id; @@ -1443,11 +1531,11 @@ static int tx_ancillary_session_init_queue(struct mtl_main_impl* impl, #ifdef MTL_HAS_RDMA_BACKEND int num_mrs = 1; /* always no tx chain for rdma_ud anc */ - void* mrs_bufs[num_mrs]; + void *mrs_bufs[num_mrs]; size_t mrs_sizes[num_mrs]; if (mt_pmd_is_rdma_ud(impl, port)) { /* register mempool memory to rdma */ - struct rte_mempool* pool = s->mbuf_mempool_hdr[i]; + struct rte_mempool *pool = s->mbuf_mempool_hdr[i]; mrs_bufs[0] = mt_mempool_mem_addr(pool); mrs_sizes[0] = mt_mempool_mem_size(pool); flow.num_mrs = num_mrs; @@ -1462,36 +1550,40 @@ static int tx_ancillary_session_init_queue(struct mtl_main_impl* impl, return -EIO; } queue_id = mt_txq_queue_id(s->queue[i]); - info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, queue_id); + info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, + queue_id); } return 0; } -static int tx_ancillary_session_uinit(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int tx_ancillary_session_uinit(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { tx_ancillary_session_uinit_queue(mgr->parent, s); tx_ancillary_session_uinit_sw(mgr, s); return 0; } -static int tx_ancillary_session_attach(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s, - struct st40_tx_ops* ops) { +static int tx_ancillary_session_attach(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + struct st40_tx_ops *ops) { int ret; int idx = s->idx, num_port = ops->num_port; - char* ports[MTL_SESSION_PORT_MAX]; + char *ports[MTL_SESSION_PORT_MAX]; bool rdma_ud = false; - for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) + ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* use dedicated queue for rdma_ud */ for (int i = 0; i < num_port; i++) { enum mtl_port port = mt_port_logic2phy(s->port_maps, i); - if (mt_pmd_is_rdma_ud(impl, port)) rdma_ud = true; + if (mt_pmd_is_rdma_ud(impl, port)) + rdma_ud = true; } s->mgr = mgr; @@ -1504,11 +1596,14 @@ static int tx_ancillary_session_attach(struct mtl_main_impl* impl, /* if disable shared queue */ s->shared_queue = true; - if (ops->flags & ST40_TX_FLAG_DEDICATE_QUEUE) s->shared_queue = false; - if (rdma_ud) s->shared_queue = false; + if (ops->flags & ST40_TX_FLAG_DEDICATE_QUEUE) + s->shared_queue = false; + if (rdma_ud) + s->shared_queue = false; for (int i = 0; i < num_port; i++) { - s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10200 + idx * 2); + s->st40_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (10200 + idx * 2); if (mt_user_random_src_port(impl)) s->st40_src_port[i] = mt_random_port(s->st40_dst_port[i]); else @@ -1528,8 +1623,10 @@ static int tx_ancillary_session_attach(struct mtl_main_impl* impl, } s->tx_mono_pool = mt_user_tx_mono_pool(impl); /* manually disable chain or any port can't support chain */ - s->tx_no_chain = mt_user_tx_no_chain(impl) || !tx_ancillary_session_has_chain_buf(s); - if (rdma_ud) s->tx_no_chain = true; + s->tx_no_chain = + mt_user_tx_no_chain(impl) || !tx_ancillary_session_has_chain_buf(s); + if (rdma_ud) + s->tx_no_chain = true; s->max_pkt_len = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc8331_anc_hdr); s->st40_frames_cnt = ops->framebuff_cnt; @@ -1583,12 +1680,13 @@ static int tx_ancillary_session_attach(struct mtl_main_impl* impl, rte_atomic32_inc(&mgr->transmitter_clients); } - info("%s(%d), type %d flags 0x%x pt %u, %s\n", __func__, idx, ops->type, ops->flags, - ops->payload_type, ops->interlaced ? "interlace" : "progressive"); + info("%s(%d), type %d flags 0x%x pt %u, %s\n", __func__, idx, ops->type, + ops->flags, ops->payload_type, + ops->interlaced ? "interlace" : "progressive"); return 0; } -static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl* s) { +static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl *s) { int idx = s->idx; int frame_cnt = rte_atomic32_read(&s->st40_stat_frame_cnt); uint64_t cur_time_ns = mt_get_monotonic_time(); @@ -1598,14 +1696,16 @@ static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl* s) { rte_atomic32_set(&s->st40_stat_frame_cnt, 0); s->stat_last_time = cur_time_ns; - notice("TX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d:%d\n", idx, s->ops_name, - framerate, frame_cnt, s->st40_stat_pkt_cnt[MTL_SESSION_PORT_P], + notice("TX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d:%d\n", idx, + s->ops_name, framerate, frame_cnt, + s->st40_stat_pkt_cnt[MTL_SESSION_PORT_P], s->st40_stat_pkt_cnt[MTL_SESSION_PORT_R]); s->st40_stat_pkt_cnt[MTL_SESSION_PORT_P] = 0; s->st40_stat_pkt_cnt[MTL_SESSION_PORT_R] = 0; if (s->stat_epoch_mismatch) { - notice("TX_ANC_SESSION(%d): st40 epoch mismatch %d\n", idx, s->stat_epoch_mismatch); + notice("TX_ANC_SESSION(%d): st40 epoch mismatch %d\n", idx, + s->stat_epoch_mismatch); s->stat_epoch_mismatch = 0; } if (s->stat_epoch_drop) { @@ -1625,8 +1725,8 @@ static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl* s) { warn("TX_ANC_SESSION(%d): build ret %d\n", idx, s->stat_build_ret_code); } if (s->ops.interlaced) { - notice("TX_ANC_SESSION(%d): interlace first field %u second field %u\n", idx, - s->stat_interlace_first_field, s->stat_interlace_second_field); + notice("TX_ANC_SESSION(%d): interlace first field %u second field %u\n", + idx, s->stat_interlace_first_field, s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } @@ -1637,24 +1737,26 @@ static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl* s) { s->stat_error_user_timestamp = 0; } - struct mt_stat_u64* stat_time = &s->stat_time; + struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("TX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", idx, - (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice( + "TX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", + idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_next_frame_us > 8 || s->stat_max_notify_frame_us > 8) { - notice("TX_ANC_SESSION(%d): get next frame max %uus, notify done max %uus\n", idx, - s->stat_max_next_frame_us, s->stat_max_notify_frame_us); + notice( + "TX_ANC_SESSION(%d): get next frame max %uus, notify done max %uus\n", + idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); } s->stat_max_next_frame_us = 0; s->stat_max_notify_frame_us = 0; } -static int tx_ancillary_session_detach(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int tx_ancillary_session_detach(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { tx_ancillary_session_stat(s); tx_ancillary_session_uinit(mgr, s); if (s->shared_queue) { @@ -1663,19 +1765,19 @@ static int tx_ancillary_session_detach(struct st_tx_ancillary_sessions_mgr* mgr, return 0; } -static int tx_ancillary_session_update_dst(struct mtl_main_impl* impl, - struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s, - struct st_tx_dest_info* dest) { +static int tx_ancillary_session_update_dst( + struct mtl_main_impl *impl, struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, struct st_tx_dest_info *dest) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; - struct st40_tx_ops* ops = &s->ops; + struct st40_tx_ops *ops = &s->ops; /* update ip and port */ for (int i = 0; i < num_port; i++) { memcpy(ops->dip_addr[i], dest->dip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = dest->udp_port[i]; - s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); + s->st40_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); s->st40_src_port[i] = (ops->udp_src_port[i]) ? (ops->udp_src_port[i]) : s->st40_dst_port[i]; @@ -1690,9 +1792,10 @@ static int tx_ancillary_session_update_dst(struct mtl_main_impl* impl, return 0; } -static int tx_ancillary_sessions_mgr_update_dst(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s, - struct st_tx_dest_info* dest) { +static int +tx_ancillary_sessions_mgr_update_dst(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + struct st_tx_dest_info *dest) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = tx_ancillary_session_get(mgr, idx); /* get the lock */ @@ -1711,13 +1814,14 @@ static int tx_ancillary_sessions_mgr_update_dst(struct st_tx_ancillary_sessions_ return 0; } -static int st_tx_ancillary_sessions_stat(void* priv) { - struct st_tx_ancillary_sessions_mgr* mgr = priv; - struct st_tx_ancillary_session_impl* s; +static int st_tx_ancillary_sessions_stat(void *priv) { + struct st_tx_ancillary_sessions_mgr *mgr = priv; + struct st_tx_ancillary_session_impl *s; for (int j = 0; j < mgr->max_idx; j++) { s = tx_ancillary_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) continue; + if (!s) + continue; tx_ancillary_session_stat(s); tx_ancillary_session_put(mgr, j); } @@ -1736,9 +1840,10 @@ static int st_tx_ancillary_sessions_stat(void* priv) { return 0; } -static int tx_ancillary_sessions_mgr_init(struct mtl_main_impl* impl, - struct mtl_sch_impl* sch, - struct st_tx_ancillary_sessions_mgr* mgr) { +static int +tx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_ancillary_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; int i; @@ -1770,17 +1875,19 @@ static int tx_ancillary_sessions_mgr_init(struct mtl_main_impl* impl, return 0; } -static struct st_tx_ancillary_session_impl* tx_ancillary_sessions_mgr_attach( - struct mtl_sch_impl* sch, struct st40_tx_ops* ops) { - struct st_tx_ancillary_sessions_mgr* mgr = &sch->tx_anc_mgr; +static struct st_tx_ancillary_session_impl * +tx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, + struct st40_tx_ops *ops) { + struct st_tx_ancillary_sessions_mgr *mgr = &sch->tx_anc_mgr; int midx = mgr->idx; int ret; - struct st_tx_ancillary_session_impl* s; + struct st_tx_ancillary_session_impl *s; int socket = mt_sch_socket_id(sch); /* find one empty slot in the mgr */ for (int i = 0; i < ST_MAX_TX_ANC_SESSIONS; i++) { - if (!tx_ancillary_session_get_empty(mgr, i)) continue; + if (!tx_ancillary_session_get_empty(mgr, i)) + continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -1814,8 +1921,9 @@ static struct st_tx_ancillary_session_impl* tx_ancillary_sessions_mgr_attach( return NULL; } -static int tx_ancillary_sessions_mgr_detach(struct st_tx_ancillary_sessions_mgr* mgr, - struct st_tx_ancillary_session_impl* s) { +static int +tx_ancillary_sessions_mgr_detach(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -1834,21 +1942,24 @@ static int tx_ancillary_sessions_mgr_detach(struct st_tx_ancillary_sessions_mgr* return 0; } -static int tx_ancillary_sessions_mgr_update(struct st_tx_ancillary_sessions_mgr* mgr) { +static int +tx_ancillary_sessions_mgr_update(struct st_tx_ancillary_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_MAX_TX_ANC_SESSIONS; i++) { - if (mgr->sessions[i]) max_idx = i + 1; + if (mgr->sessions[i]) + max_idx = i + 1; } mgr->max_idx = max_idx; return 0; } -static int tx_ancillary_sessions_mgr_uinit(struct st_tx_ancillary_sessions_mgr* mgr) { +static int +tx_ancillary_sessions_mgr_uinit(struct st_tx_ancillary_sessions_mgr *mgr) { int m_idx = mgr->idx; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_ancillary_session_impl* s; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_ancillary_session_impl *s; mt_stat_unregister(mgr->parent, st_tx_ancillary_sessions_stat, mgr); @@ -1859,7 +1970,8 @@ static int tx_ancillary_sessions_mgr_uinit(struct st_tx_ancillary_sessions_mgr* for (int i = 0; i < ST_MAX_TX_ANC_SESSIONS; i++) { s = tx_ancillary_session_get(mgr, i); - if (!s) continue; + if (!s) + continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); tx_ancillary_sessions_mgr_detach(mgr, s); @@ -1874,9 +1986,9 @@ static int tx_ancillary_sessions_mgr_uinit(struct st_tx_ancillary_sessions_mgr* return 0; } -static int tx_ancillary_ops_check(struct st40_tx_ops* ops) { +static int tx_ancillary_ops_check(struct st40_tx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip = NULL; + uint8_t *ip = NULL; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { err("%s, invalid num_ports %d\n", __func__, num_ports); @@ -1887,14 +1999,16 @@ static int tx_ancillary_ops_check(struct st40_tx_ops* ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -1927,10 +2041,12 @@ static int tx_ancillary_ops_check(struct st40_tx_ops* ops) { return 0; } -static int st_tx_anc_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { +static int st_tx_anc_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { int ret; - if (sch->tx_anc_init) return 0; + if (sch->tx_anc_init) + return 0; /* create tx ancillary context */ ret = tx_ancillary_sessions_mgr_init(impl, sch, &sch->tx_anc_mgr); @@ -1938,7 +2054,8 @@ static int st_tx_anc_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) err("%s, tx_ancillary_sessions_mgr_init fail\n", __func__); return ret; } - ret = st_ancillary_transmitter_init(impl, sch, &sch->tx_anc_mgr, &sch->anc_trs); + ret = + st_ancillary_transmitter_init(impl, sch, &sch->tx_anc_mgr, &sch->anc_trs); if (ret < 0) { tx_ancillary_sessions_mgr_uinit(&sch->tx_anc_mgr); err("%s, st_ancillary_transmitter_init fail %d\n", __func__, ret); @@ -1949,8 +2066,9 @@ static int st_tx_anc_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) return 0; } -int st_tx_ancillary_sessions_sch_uinit(struct mtl_sch_impl* sch) { - if (!sch->tx_anc_init) return 0; +int st_tx_ancillary_sessions_sch_uinit(struct mtl_sch_impl *sch) { + if (!sch->tx_anc_init) + return 0; /* free tx ancillary context */ st_ancillary_transmitter_uinit(&sch->anc_trs); @@ -1960,11 +2078,11 @@ int st_tx_ancillary_sessions_sch_uinit(struct mtl_sch_impl* sch) { return 0; } -st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct st_tx_ancillary_session_handle_impl* s_impl; - struct st_tx_ancillary_session_impl* s; - struct mtl_sch_impl* sch; +st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct st_tx_ancillary_session_handle_impl *s_impl; + struct st_tx_ancillary_session_impl *s; + struct mtl_sch_impl *sch; int quota_mbs, ret; notice("%s, start for %s\n", __func__, mt_string_safe(ops->name)); @@ -1981,7 +2099,8 @@ st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops* ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); s_impl = mt_rte_zmalloc_socket(sizeof(*s_impl), socket); @@ -1991,8 +2110,8 @@ st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops* ops) { } quota_mbs = 0; - sch = - mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); + sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, + MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -2030,12 +2149,12 @@ st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops* ops) { return s_impl; } -void* st40_tx_get_mbuf(st40_tx_handle handle, void** usrptr) { - struct st_tx_ancillary_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = NULL; - struct st_tx_ancillary_session_impl* s; +void *st40_tx_get_mbuf(st40_tx_handle handle, void **usrptr) { + struct st_tx_ancillary_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = NULL; + struct st_tx_ancillary_session_impl *s; int idx; - struct rte_ring* packet_ring; + struct rte_ring *packet_ring; if (s_impl->type != MT_HANDLE_TX_ANC) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -2055,8 +2174,9 @@ void* st40_tx_get_mbuf(st40_tx_handle handle, void** usrptr) { return NULL; } - struct rte_mempool* mp = - s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; + struct rte_mempool *mp = s->tx_no_chain + ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] + : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -2064,15 +2184,15 @@ void* st40_tx_get_mbuf(st40_tx_handle handle, void** usrptr) { } size_t hdr_offset = s->tx_no_chain ? sizeof(struct mt_udp_hdr) : 0; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, hdr_offset); + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, hdr_offset); return pkt; } -int st40_tx_put_mbuf(st40_tx_handle handle, void* mbuf, uint16_t len) { - struct st_tx_ancillary_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; - struct st_tx_ancillary_session_impl* s; - struct rte_ring* packet_ring; +int st40_tx_put_mbuf(st40_tx_handle handle, void *mbuf, uint16_t len) { + struct st_tx_ancillary_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; + struct st_tx_ancillary_session_impl *s; + struct rte_ring *packet_ring; int idx, ret; if (s_impl->type != MT_HANDLE_TX_ANC) { @@ -2081,7 +2201,8 @@ int st40_tx_put_mbuf(st40_tx_handle handle, void* mbuf, uint16_t len) { } if (!mt_rtp_len_valid(len)) { - if (len) err("%s, invalid len %d\n", __func__, len); + if (len) + err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -2095,10 +2216,11 @@ int st40_tx_put_mbuf(st40_tx_handle handle, void* mbuf, uint16_t len) { return -EIO; } - if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) + len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; - ret = rte_ring_sp_enqueue(packet_ring, (void*)pkt); + ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); if (ret < 0) { err("%s(%d), can not enqueue to the rte ring\n", __func__, idx); rte_pktmbuf_free(mbuf); @@ -2108,10 +2230,11 @@ int st40_tx_put_mbuf(st40_tx_handle handle, void* mbuf, uint16_t len) { return 0; } -int st40_tx_update_destination(st40_tx_handle handle, struct st_tx_dest_info* dst) { - struct st_tx_ancillary_session_handle_impl* s_impl = handle; - struct st_tx_ancillary_session_impl* s; - struct mtl_sch_impl* sch; +int st40_tx_update_destination(st40_tx_handle handle, + struct st_tx_dest_info *dst) { + struct st_tx_ancillary_session_handle_impl *s_impl = handle; + struct st_tx_ancillary_session_impl *s; + struct mtl_sch_impl *sch; int idx, ret, sch_idx; if (s_impl->type != MT_HANDLE_TX_ANC) { @@ -2125,7 +2248,8 @@ int st40_tx_update_destination(st40_tx_handle handle, struct st_tx_dest_info* ds sch_idx = sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = tx_ancillary_sessions_mgr_update_dst(&sch->tx_anc_mgr, s, dst); if (ret < 0) { @@ -2138,10 +2262,10 @@ int st40_tx_update_destination(st40_tx_handle handle, struct st_tx_dest_info* ds } int st40_tx_free(st40_tx_handle handle) { - struct st_tx_ancillary_session_handle_impl* s_impl = handle; - struct st_tx_ancillary_session_impl* s; - struct mtl_sch_impl* sch; - struct mtl_main_impl* impl; + struct st_tx_ancillary_session_handle_impl *s_impl = handle; + struct st_tx_ancillary_session_impl *s; + struct mtl_sch_impl *sch; + struct mtl_main_impl *impl; int ret, idx; int sch_idx; @@ -2160,10 +2284,12 @@ int st40_tx_free(st40_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_anc_mgr_mutex); ret = tx_ancillary_sessions_mgr_detach(&sch->tx_anc_mgr, s); mt_pthread_mutex_unlock(&sch->tx_anc_mgr_mutex); - if (ret < 0) err("%s(%d), tx_ancillary_sessions_mgr_detach fail\n", __func__, idx); + if (ret < 0) + err("%s(%d), tx_ancillary_sessions_mgr_detach fail\n", __func__, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -2177,9 +2303,9 @@ int st40_tx_free(st40_tx_handle handle) { return 0; } -void* st40_tx_get_framebuffer(st40_tx_handle handle, uint16_t idx) { - struct st_tx_ancillary_session_handle_impl* s_impl = handle; - struct st_tx_ancillary_session_impl* s; +void *st40_tx_get_framebuffer(st40_tx_handle handle, uint16_t idx) { + struct st_tx_ancillary_session_handle_impl *s_impl = handle; + struct st_tx_ancillary_session_impl *s; if (s_impl->type != MT_HANDLE_TX_ANC) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -2197,7 +2323,7 @@ void* st40_tx_get_framebuffer(st40_tx_handle handle, uint16_t idx) { return NULL; } - struct st_frame_trans* frame_info = &s->st40_frames[idx]; + struct st_frame_trans *frame_info = &s->st40_frames[idx]; return frame_info->addr; } diff --git a/lib/src/st2110/st_tx_ancillary_session.h b/lib/src/st2110/st_tx_ancillary_session.h index 46036fcad..3fbc21428 100644 --- a/lib/src/st2110/st_tx_ancillary_session.h +++ b/lib/src/st2110/st_tx_ancillary_session.h @@ -9,6 +9,6 @@ #define ST_TX_ANCILLARY_PREFIX "TC_" -int st_tx_ancillary_sessions_sch_uinit(struct mtl_sch_impl* sch); +int st_tx_ancillary_sessions_sch_uinit(struct mtl_sch_impl *sch); #endif diff --git a/lib/src/st2110/st_tx_audio_session.c b/lib/src/st2110/st_tx_audio_session.c index 57877fe51..8a8a43104 100644 --- a/lib/src/st2110/st_tx_audio_session.c +++ b/lib/src/st2110/st_tx_audio_session.c @@ -11,37 +11,43 @@ #include "st_err.h" /* call tx_audio_session_put always if get successfully */ -static inline struct st_tx_audio_session_impl* tx_audio_session_get( - struct st_tx_audio_sessions_mgr* mgr, int idx) { +static inline struct st_tx_audio_session_impl * +tx_audio_session_get(struct st_tx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_tx_audio_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); + struct st_tx_audio_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_audio_session_put always if get successfully */ -static inline struct st_tx_audio_session_impl* tx_audio_session_get_timeout( - struct st_tx_audio_sessions_mgr* mgr, int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; - struct st_tx_audio_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_tx_audio_session_impl * +tx_audio_session_get_timeout(struct st_tx_audio_sessions_mgr *mgr, int idx, + int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) + return NULL; + struct st_tx_audio_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_audio_session_put always if get successfully */ -static inline struct st_tx_audio_session_impl* tx_audio_session_try_get( - struct st_tx_audio_sessions_mgr* mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; - struct st_tx_audio_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_tx_audio_session_impl * +tx_audio_session_try_get(struct st_tx_audio_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) + return NULL; + struct st_tx_audio_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_audio_session_put always if get successfully */ -static inline bool tx_audio_session_get_empty(struct st_tx_audio_sessions_mgr* mgr, - int idx) { +static inline bool +tx_audio_session_get_empty(struct st_tx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_tx_audio_session_impl* s = mgr->sessions[idx]; + struct st_tx_audio_session_impl *s = mgr->sessions[idx]; if (s) { rte_spinlock_unlock(&mgr->mutex[idx]); /* not null, unlock it */ return false; @@ -50,17 +56,19 @@ static inline bool tx_audio_session_get_empty(struct st_tx_audio_sessions_mgr* m } } -static inline void tx_audio_session_put(struct st_tx_audio_sessions_mgr* mgr, int idx) { +static inline void tx_audio_session_put(struct st_tx_audio_sessions_mgr *mgr, + int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -static int tx_audio_session_free_frames(struct st_tx_audio_session_impl* s) { +static int tx_audio_session_free_frames(struct st_tx_audio_session_impl *s) { if (s->st30_frames) { - struct st_frame_trans* frame; + struct st_frame_trans *frame; /* dec ref for current frame */ frame = &s->st30_frames[s->st30_frame_idx]; - if (rte_atomic32_read(&frame->refcnt)) rte_atomic32_dec(&frame->refcnt); + if (rte_atomic32_read(&frame->refcnt)) + rte_atomic32_dec(&frame->refcnt); for (int i = 0; i < s->st30_frames_cnt; i++) { frame = &s->st30_frames[i]; @@ -75,18 +83,18 @@ static int tx_audio_session_free_frames(struct st_tx_audio_session_impl* s) { return 0; } -static int tx_audio_session_alloc_frames(struct st_tx_audio_session_impl* s) { +static int tx_audio_session_alloc_frames(struct st_tx_audio_session_impl *s) { int soc_id = s->socket_id; int idx = s->idx; - struct st_frame_trans* frame_info; + struct st_frame_trans *frame_info; if (s->st30_frames) { err("%s(%d), st30_frames already alloc\n", __func__, idx); return -EIO; } - s->st30_frames = - mt_rte_zmalloc_socket(sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); + s->st30_frames = mt_rte_zmalloc_socket( + sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); if (!s->st30_frames) { err("%s(%d), st30_frames malloc fail\n", __func__, idx); return -ENOMEM; @@ -101,9 +109,10 @@ static int tx_audio_session_alloc_frames(struct st_tx_audio_session_impl* s) { for (int i = 0; i < s->st30_frames_cnt; i++) { frame_info = &s->st30_frames[i]; - void* frame = mt_rte_zmalloc_socket(s->st30_frame_size, soc_id); + void *frame = mt_rte_zmalloc_socket(s->st30_frame_size, soc_id); if (!frame) { - err("%s(%d), rte_malloc %u fail at %d\n", __func__, idx, s->st30_frame_size, i); + err("%s(%d), rte_malloc %u fail at %d\n", __func__, idx, + s->st30_frame_size, i); tx_audio_session_free_frames(s); return -ENOMEM; } @@ -116,36 +125,40 @@ static int tx_audio_session_alloc_frames(struct st_tx_audio_session_impl* s) { return 0; } -static int tx_audio_session_init_hdr(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s, +static int tx_audio_session_init_hdr(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, enum mtl_session_port s_port) { MTL_MAY_UNUSED(mgr); int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct st30_tx_ops* ops = &s->ops; + struct st30_tx_ops *ops = &s->ops; int ret; - struct st_rfc3550_audio_hdr* hdr = &s->hdr[s_port]; - struct rte_ether_hdr* eth = &hdr->eth; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; - struct st_rfc3550_rtp_hdr* rtp = &hdr->rtp; - uint8_t* dip = ops->dip_addr[s_port]; - uint8_t* sip = mt_sip_addr(impl, port); - struct rte_ether_addr* d_addr = mt_eth_d_addr(eth); + struct st_rfc3550_audio_hdr *hdr = &s->hdr[s_port]; + struct rte_ether_hdr *eth = &hdr->eth; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; + struct st_rfc3550_rtp_hdr *rtp = &hdr->rtp; + uint8_t *dip = ops->dip_addr[s_port]; + uint8_t *sip = mt_sip_addr(impl, port); + struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); /* ether hdr */ - if ((s_port == MTL_SESSION_PORT_P) && (ops->flags & ST30_TX_FLAG_USER_P_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); + if ((s_port == MTL_SESSION_PORT_P) && + (ops->flags & ST30_TX_FLAG_USER_P_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], + RTE_ETHER_ADDR_LEN); info("%s, USER_P_TX_MAC\n", __func__); - } else if ((s_port == MTL_SESSION_PORT_R) && (ops->flags & ST30_TX_FLAG_USER_R_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); + } else if ((s_port == MTL_SESSION_PORT_R) && + (ops->flags & ST30_TX_FLAG_USER_R_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], + RTE_ETHER_ADDR_LEN); info("%s, USER_R_TX_MAC\n", __func__); } else { ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], - dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, + dip[0], dip[1], dip[2], dip[3]); return ret; } } @@ -189,21 +202,23 @@ static int tx_audio_session_init_hdr(struct mtl_main_impl* impl, s->st30_seq_id = 0; - info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u payload_type %u\n", __func__, idx, s_port, - dip[0], dip[1], dip[2], dip[3], s->st30_src_port[s_port], s->st30_dst_port[s_port], - rtp->payload_type); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", __func__, idx, - d_addr->addr_bytes[0], d_addr->addr_bytes[1], d_addr->addr_bytes[2], - d_addr->addr_bytes[3], d_addr->addr_bytes[4], d_addr->addr_bytes[5], ssrc); + info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u payload_type %u\n", __func__, idx, + s_port, dip[0], dip[1], dip[2], dip[3], s->st30_src_port[s_port], + s->st30_dst_port[s_port], rtp->payload_type); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", + __func__, idx, d_addr->addr_bytes[0], d_addr->addr_bytes[1], + d_addr->addr_bytes[2], d_addr->addr_bytes[3], d_addr->addr_bytes[4], + d_addr->addr_bytes[5], ssrc); return 0; } -static int tx_audio_session_init_pacing(struct st_tx_audio_session_impl* s) { +static int tx_audio_session_init_pacing(struct st_tx_audio_session_impl *s) { int idx = s->idx; - struct st_tx_audio_session_pacing* pacing = &s->pacing; - struct st30_tx_ops* ops = &s->ops; + struct st_tx_audio_session_pacing *pacing = &s->pacing; + struct st30_tx_ops *ops = &s->ops; double pkt_time = st30_get_packet_time(ops->ptime); - if (pkt_time < 0) return -EINVAL; + if (pkt_time < 0) + return -EINVAL; pacing->pkt_time_sampling = (double)(s->sample_num * 1000) * 1 / 1000; pacing->trs = pkt_time; @@ -218,41 +233,47 @@ static int tx_audio_session_init_pacing(struct st_tx_audio_session_impl* s) { return 0; } -static int tx_audio_session_init_pacing_epoch(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s) { +static int +tx_audio_session_init_pacing_epoch(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); - struct st_tx_audio_session_pacing* pacing = &s->pacing; + struct st_tx_audio_session_pacing *pacing = &s->pacing; pacing->cur_epochs = ptp_time / pacing->trs; return 0; } -static inline double tx_audio_pacing_time(struct st_tx_audio_session_pacing* pacing, - uint64_t epochs) { +static inline double +tx_audio_pacing_time(struct st_tx_audio_session_pacing *pacing, + uint64_t epochs) { return epochs * pacing->trs; } -static inline uint32_t tx_audio_pacing_time_stamp( - struct st_tx_audio_session_pacing* pacing, uint64_t epochs) { +static inline uint32_t +tx_audio_pacing_time_stamp(struct st_tx_audio_session_pacing *pacing, + uint64_t epochs) { uint64_t tmstamp64 = epochs * pacing->pkt_time_sampling; uint32_t tmstamp32 = tmstamp64; return tmstamp32; } -static uint64_t tx_audio_pacing_required_tai(struct st_tx_audio_session_impl* s, +static uint64_t tx_audio_pacing_required_tai(struct st_tx_audio_session_impl *s, enum st10_timestamp_fmt tfmt, uint64_t timestamp) { uint64_t required_tai = 0; - if (!(s->ops.flags & ST30_TX_FLAG_USER_PACING)) return 0; - if (!timestamp) return 0; + if (!(s->ops.flags & ST30_TX_FLAG_USER_PACING)) + return 0; + if (!timestamp) + return 0; if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (timestamp > 0xFFFFFFFF) { - err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, timestamp); + err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, + timestamp); } - required_tai = - st10_media_clk_to_ns((uint32_t)timestamp, st30_get_sample_rate(s->ops.sampling)); + required_tai = st10_media_clk_to_ns((uint32_t)timestamp, + st30_get_sample_rate(s->ops.sampling)); } else { required_tai = timestamp; } @@ -260,10 +281,10 @@ static uint64_t tx_audio_pacing_required_tai(struct st_tx_audio_session_impl* s, return required_tai; } -static int tx_audio_session_sync_pacing(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s, bool sync, - uint64_t required_tai) { - struct st_tx_audio_session_pacing* pacing = &s->pacing; +static int tx_audio_session_sync_pacing(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s, + bool sync, uint64_t required_tai) { + struct st_tx_audio_session_pacing *pacing = &s->pacing; double pkt_time = pacing->trs; /* always use MTL_PORT_P for ptp now */ uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); @@ -274,9 +295,11 @@ static int tx_audio_session_sync_pacing(struct mtl_main_impl* impl, if (required_tai) { uint64_t ptp_epochs = ptp_time / pkt_time; epochs = required_tai / pkt_time; - dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 " epochs %" PRIu64 "\n", + dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 + " epochs %" PRIu64 "\n", __func__, s->idx, required_tai, ptp_epochs, epochs); - if (epochs < ptp_epochs) s->stat_error_user_timestamp++; + if (epochs < ptp_epochs) + s->stat_error_user_timestamp++; } else { epochs = ptp_time / pkt_time; @@ -305,16 +328,18 @@ static int tx_audio_session_sync_pacing(struct mtl_main_impl* impl, to_epoch = 0; /* send asap */ } - if (epochs > next_epochs) s->stat_epoch_drop += (epochs - next_epochs); - if (epochs < next_epochs) s->stat_epoch_onward += (next_epochs - epochs); + if (epochs > next_epochs) + s->stat_epoch_drop += (epochs - next_epochs); + if (epochs < next_epochs) + s->stat_epoch_onward += (next_epochs - epochs); pacing->cur_epochs = epochs; pacing->cur_epoch_time = tx_audio_pacing_time(pacing, epochs); pacing->pacing_time_stamp = tx_audio_pacing_time_stamp(pacing, epochs); pacing->rtp_time_stamp = pacing->pacing_time_stamp; pacing->tsc_time_cursor = (double)mt_get_tsc(impl) + to_epoch; - dbg("%s(%d), epochs %" PRIu64 ", rtp_time_stamp %u\n", __func__, s->idx, epochs, - pacing->rtp_time_stamp); + dbg("%s(%d), epochs %" PRIu64 ", rtp_time_stamp %u\n", __func__, s->idx, + epochs, pacing->rtp_time_stamp); if (sync) { dbg("%s(%d), delay to epoch_time %f, cur %" PRIu64 "\n", __func__, s->idx, @@ -325,10 +350,10 @@ static int tx_audio_session_sync_pacing(struct mtl_main_impl* impl, return 0; } -static int tx_audio_session_init_next_meta(struct st_tx_audio_session_impl* s, - struct st30_tx_frame_meta* meta) { - struct st_tx_audio_session_pacing* pacing = &s->pacing; - struct st30_tx_ops* ops = &s->ops; +static int tx_audio_session_init_next_meta(struct st_tx_audio_session_impl *s, + struct st30_tx_frame_meta *meta) { + struct st_tx_audio_session_pacing *pacing = &s->pacing; + struct st30_tx_ops *ops = &s->ops; memset(meta, 0, sizeof(*meta)); meta->fmt = ops->fmt; @@ -342,21 +367,22 @@ static int tx_audio_session_init_next_meta(struct st_tx_audio_session_impl* s, return 0; } -static int tx_audio_session_init(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s, int idx) { +static int tx_audio_session_init(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, int idx) { MTL_MAY_UNUSED(mgr); s->idx = idx; return 0; } -static int tx_audio_sessions_tasklet_start(void* priv) { - struct st_tx_audio_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_audio_session_impl* s; +static int tx_audio_sessions_tasklet_start(void *priv) { + struct st_tx_audio_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_audio_session_impl *s; for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_audio_session_get(mgr, sidx); - if (!s) continue; + if (!s) + continue; tx_audio_session_init_pacing_epoch(impl, s); tx_audio_session_put(mgr, sidx); @@ -365,11 +391,11 @@ static int tx_audio_sessions_tasklet_start(void* priv) { return 0; } -static int tx_audio_session_update_redundant(struct st_tx_audio_session_impl* s, - struct rte_mbuf* pkt_r) { - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr*); - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; +static int tx_audio_session_update_redundant(struct st_tx_audio_session_impl *s, + struct rte_mbuf *pkt_r) { + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr *); + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; /* update the hdr: eth, ip, udp */ rte_memcpy(hdr, &s->hdr[MTL_SESSION_PORT_R], sizeof(*hdr)); @@ -385,17 +411,17 @@ static int tx_audio_session_update_redundant(struct st_tx_audio_session_impl* s, return 0; } -static int tx_audio_session_build_packet(struct st_tx_audio_session_impl* s, - struct rte_mbuf* pkt) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st_rfc3550_rtp_hdr* rtp; +static int tx_audio_session_build_packet(struct st_tx_audio_session_impl *s, + struct rte_mbuf *pkt) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st_rfc3550_rtp_hdr *rtp; - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; - rtp = (struct st_rfc3550_rtp_hdr*)&udp[1]; + rtp = (struct st_rfc3550_rtp_hdr *)&udp[1]; /* copy the hdr: eth, ip, udp */ rte_memcpy(&hdr->eth, &s->hdr[MTL_SESSION_PORT_P].eth, sizeof(hdr->eth)); @@ -418,10 +444,10 @@ static int tx_audio_session_build_packet(struct st_tx_audio_session_impl* s, rtp->tmstamp = htonl(s->pacing.rtp_time_stamp); /* copy payload now */ - uint8_t* payload = (uint8_t*)&rtp[1]; + uint8_t *payload = (uint8_t *)&rtp[1]; uint32_t offset = s->st30_pkt_idx * s->pkt_len; - struct st_frame_trans* frame_info = &s->st30_frames[s->st30_frame_idx]; - uint8_t* src = frame_info->addr; + struct st_frame_trans *frame_info = &s->st30_frames[s->st30_frame_idx]; + uint8_t *src = frame_info->addr; rte_memcpy(payload, src + offset, s->pkt_len); pkt->data_len += len; @@ -438,12 +464,12 @@ static int tx_audio_session_build_packet(struct st_tx_audio_session_impl* s, return 0; } -static int tx_audio_session_build_rtp_packet(struct st_tx_audio_session_impl* s, - struct rte_mbuf* pkt) { - struct st_rfc3550_rtp_hdr* rtp; +static int tx_audio_session_build_rtp_packet(struct st_tx_audio_session_impl *s, + struct rte_mbuf *pkt) { + struct st_rfc3550_rtp_hdr *rtp; uint16_t len = s->pkt_len + sizeof(struct st_rfc3550_rtp_hdr); - rtp = rte_pktmbuf_mtod(pkt, struct st_rfc3550_rtp_hdr*); + rtp = rte_pktmbuf_mtod(pkt, struct st_rfc3550_rtp_hdr *); rte_memcpy(rtp, &s->hdr[MTL_SESSION_PORT_P].rtp, sizeof(*rtp)); /* update rtp */ @@ -452,10 +478,10 @@ static int tx_audio_session_build_rtp_packet(struct st_tx_audio_session_impl* s, rtp->tmstamp = htonl(s->pacing.rtp_time_stamp); /* copy payload now */ - uint8_t* payload = (uint8_t*)&rtp[1]; + uint8_t *payload = (uint8_t *)&rtp[1]; uint32_t offset = s->st30_pkt_idx * s->pkt_len; - struct st_frame_trans* frame_info = &s->st30_frames[s->st30_frame_idx]; - uint8_t* src = frame_info->addr; + struct st_frame_trans *frame_info = &s->st30_frames[s->st30_frame_idx]; + uint8_t *src = frame_info->addr; rte_memcpy(payload, src + offset, s->pkt_len); pkt->data_len = len; @@ -464,18 +490,19 @@ static int tx_audio_session_build_rtp_packet(struct st_tx_audio_session_impl* s, return 0; } -static int tx_audio_session_rtp_update_packet(struct st_tx_audio_session_impl* s, - struct rte_mbuf* pkt) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct st_rfc3550_rtp_hdr* rtp; - struct rte_udp_hdr* udp; +static int +tx_audio_session_rtp_update_packet(struct st_tx_audio_session_impl *s, + struct rte_mbuf *pkt) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct st_rfc3550_rtp_hdr *rtp; + struct rte_udp_hdr *udp; - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; - rtp = - rte_pktmbuf_mtod_offset(pkt, struct st_rfc3550_rtp_hdr*, sizeof(struct mt_udp_hdr)); + rtp = rte_pktmbuf_mtod_offset(pkt, struct st_rfc3550_rtp_hdr *, + sizeof(struct mt_udp_hdr)); /* copy the hdr: eth, ip, udp */ rte_memcpy(&hdr->eth, &s->hdr[MTL_SESSION_PORT_P].eth, sizeof(hdr->eth)); @@ -508,16 +535,15 @@ static int tx_audio_session_rtp_update_packet(struct st_tx_audio_session_impl* s return 0; } -static int tx_audio_session_build_packet_chain(struct st_tx_audio_session_impl* s, - struct rte_mbuf* pkt, - struct rte_mbuf* pkt_rtp, - enum mtl_session_port s_port) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st30_tx_ops* ops = &s->ops; +static int tx_audio_session_build_packet_chain( + struct st_tx_audio_session_impl *s, struct rte_mbuf *pkt, + struct rte_mbuf *pkt_rtp, enum mtl_session_port s_port) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st30_tx_ops *ops = &s->ops; - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; @@ -531,8 +557,8 @@ static int tx_audio_session_build_packet_chain(struct st_tx_audio_session_impl* if (s_port == MTL_SESSION_PORT_P) { /* update rtp time for rtp path */ if (ops->type == ST30_TYPE_RTP_LEVEL) { - struct st_rfc3550_rtp_hdr* rtp = - rte_pktmbuf_mtod(pkt_rtp, struct st_rfc3550_rtp_hdr*); + struct st_rfc3550_rtp_hdr *rtp = + rte_pktmbuf_mtod(pkt_rtp, struct st_rfc3550_rtp_hdr *); if (rtp->tmstamp != s->st30_rtp_time_app) { /* start of a new epoch */ s->st30_rtp_time_app = rtp->tmstamp; @@ -565,43 +591,46 @@ static int tx_audio_session_build_packet_chain(struct st_tx_audio_session_impl* } /* rtp packet used twice for redundant path */ - if (s_port == MTL_SESSION_PORT_R) rte_mbuf_refcnt_update(pkt_rtp, 1); + if (s_port == MTL_SESSION_PORT_R) + rte_mbuf_refcnt_update(pkt_rtp, 1); return 0; } -static int tx_audio_session_usdt_dump_close(struct st_tx_audio_session_impl* s) { +static int +tx_audio_session_usdt_dump_close(struct st_tx_audio_session_impl *s) { int idx = s->idx; if (s->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, s->usdt_dump_fd, - s->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, + s->usdt_dump_fd, s->usdt_dumped_frames); close(s->usdt_dump_fd); s->usdt_dump_fd = -1; } return 0; } -static int tx_audio_session_usdt_dump_frame(struct st_tx_audio_session_impl* s, - struct st_frame_trans* frame) { - struct st_tx_audio_sessions_mgr* mgr = s->mgr; +static int tx_audio_session_usdt_dump_frame(struct st_tx_audio_session_impl *s, + struct st_frame_trans *frame) { + struct st_tx_audio_sessions_mgr *mgr = s->mgr; int idx = s->idx; int ret; if (s->usdt_dump_fd < 0) { - struct st30_tx_ops* ops = &s->ops; + struct st30_tx_ops *ops = &s->ops; snprintf(s->usdt_dump_path, sizeof(s->usdt_dump_path), "imtl_usdt_st30tx_m%ds%d_%d_%d_c%u_XXXXXX.pcm", mgr->idx, idx, - st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, - ops->channel); + st30_get_sample_rate(ops->sampling), + st30_get_sample_size(ops->fmt) * 8, ops->channel); ret = mt_mkstemps(s->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, + ret); return ret; } s->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, s->usdt_dump_path, - s->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, + s->usdt_dump_path, s->usdt_dump_fd); } /* write frame to dump file */ @@ -620,18 +649,18 @@ static int tx_audio_session_usdt_dump_frame(struct st_tx_audio_session_impl* s, return 0; } -static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { int idx = s->idx; - struct st30_tx_ops* ops = &s->ops; - struct st_tx_audio_session_pacing* pacing = &s->pacing; + struct st30_tx_ops *ops = &s->ops; + struct st_tx_audio_session_pacing *pacing = &s->pacing; int ret; bool send_r = false; - struct rte_mempool* hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; - struct rte_mempool* hdr_pool_r = NULL; - struct rte_mempool* chain_pool = s->mbuf_mempool_chain; - struct mt_u64_fifo* ring_p = s->trans_ring[MTL_SESSION_PORT_P]; - struct mt_u64_fifo* ring_r = NULL; + struct rte_mempool *hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; + struct rte_mempool *hdr_pool_r = NULL; + struct rte_mempool *chain_pool = s->mbuf_mempool_chain; + struct mt_u64_fifo *ring_p = s->trans_ring[MTL_SESSION_PORT_P]; + struct mt_u64_fifo *ring_r = NULL; if (mt_u64_fifo_full(ring_p)) { s->stat_build_ret_code = -STI_FRAME_RING_FULL; @@ -680,7 +709,8 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; dbg("%s(%d), frame %d build time out %" PRIu64 " us\n", __func__, idx, - s->st30_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); + s->st30_frame_idx, + (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } s->check_frame_done_time = false; } @@ -688,11 +718,13 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, tx_audio_session_init_next_meta(s, &meta); /* Query next frame buffer idx */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); ret = ops->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_next_frame_us = RTE_MAX(s->stat_max_next_frame_us, delta_us); + s->stat_max_next_frame_us = + RTE_MAX(s->stat_max_next_frame_us, delta_us); } if (ret < 0) { /* no frame ready from app */ dbg("%s(%d), get_next_frame fail %d\n", __func__, idx, ret); @@ -700,11 +732,11 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, return MTL_TASKLET_ALL_DONE; } /* check frame refcnt */ - struct st_frame_trans* frame = &s->st30_frames[next_frame_idx]; + struct st_frame_trans *frame = &s->st30_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, - refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, + next_frame_idx, refcnt); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -713,7 +745,8 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, s->st30_frame_idx = next_frame_idx; dbg("%s(%d), next_frame_idx %d start\n", __func__, idx, next_frame_idx); s->st30_frame_stat = ST30_TX_STAT_SENDING_PKTS; - MT_USDT_ST30_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, frame->addr); + MT_USDT_ST30_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, + frame->addr); /* check if dump USDT enabled */ if (MT_USDT_ST30_TX_FRAME_DUMP_ENABLED()) { tx_audio_session_usdt_dump_frame(s, frame); @@ -724,10 +757,10 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, } if (s->calculate_time_cursor) { - struct st_frame_trans* frame = &s->st30_frames[s->st30_frame_idx]; + struct st_frame_trans *frame = &s->st30_frames[s->st30_frame_idx]; /* user timestamp control if any */ - uint64_t required_tai = - tx_audio_pacing_required_tai(s, frame->ta_meta.tfmt, frame->ta_meta.timestamp); + uint64_t required_tai = tx_audio_pacing_required_tai( + s, frame->ta_meta.tfmt, frame->ta_meta.timestamp); tx_audio_session_sync_pacing(impl, s, false, required_tai); if (ops->flags & ST30_TX_FLAG_USER_TIMESTAMP && (frame->ta_meta.tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK)) { @@ -744,21 +777,21 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, uint64_t target_tsc = pacing->tsc_time_cursor; if (cur_tsc < target_tsc) { uint64_t delta = target_tsc - cur_tsc; - // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, cur_tsc, - // target_tsc); + // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, + // cur_tsc, target_tsc); if (likely(delta < NS_PER_S)) { s->stat_build_ret_code = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", + __func__, idx, cur_tsc, target_tsc); } } } - struct rte_mbuf* pkt = NULL; - struct rte_mbuf* pkt_r = NULL; + struct rte_mbuf *pkt = NULL; + struct rte_mbuf *pkt_r = NULL; pkt = rte_pktmbuf_alloc(hdr_pool_p); if (!pkt) { @@ -768,7 +801,7 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, } if (!s->tx_no_chain) { - struct rte_mbuf* pkt_rtp = rte_pktmbuf_alloc(chain_pool); + struct rte_mbuf *pkt_rtp = rte_pktmbuf_alloc(chain_pool); if (!pkt_rtp) { err("%s(%d), pkt_rtp alloc fail\n", __func__, idx); rte_pktmbuf_free(pkt); @@ -786,7 +819,8 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL; return MTL_TASKLET_ALL_DONE; } - tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, MTL_SESSION_PORT_R); + tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, + MTL_SESSION_PORT_R); } } else { tx_audio_session_build_packet(s, pkt); @@ -832,17 +866,19 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, if (s->st30_pkt_idx >= s->st30_total_pkts) { dbg("%s(%d), frame %d done\n", __func__, idx, s->st30_frame_idx); - struct st_frame_trans* frame = &s->st30_frames[s->st30_frame_idx]; - struct st30_tx_frame_meta* ta_meta = &frame->ta_meta; + struct st_frame_trans *frame = &s->st30_frames[s->st30_frame_idx]; + struct st30_tx_frame_meta *ta_meta = &frame->ta_meta; uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); /* end of current frame */ if (ops->notify_frame_done) ops->notify_frame_done(ops->priv, s->st30_frame_idx, ta_meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = + RTE_MAX(s->stat_max_notify_frame_us, delta_us); } rte_atomic32_dec(&frame->refcnt); @@ -857,16 +893,16 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl* impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tx_audio_session_tasklet_rtp(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_tasklet_rtp(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { int idx = s->idx; int ret; - struct st_tx_audio_session_pacing* pacing = &s->pacing; + struct st_tx_audio_session_pacing *pacing = &s->pacing; bool send_r = false; - struct rte_mempool* hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; - struct rte_mempool* hdr_pool_r = NULL; - struct mt_u64_fifo* ring_p = s->trans_ring[MTL_SESSION_PORT_P]; - struct mt_u64_fifo* ring_r = NULL; + struct rte_mempool *hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; + struct rte_mempool *hdr_pool_r = NULL; + struct mt_u64_fifo *ring_p = s->trans_ring[MTL_SESSION_PORT_P]; + struct mt_u64_fifo *ring_r = NULL; if (mt_u64_fifo_full(ring_p)) { s->stat_build_ret_code = -STI_RTP_RING_FULL; @@ -905,31 +941,32 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl* impl, } /* sync pacing */ - if (!pacing->tsc_time_cursor) tx_audio_session_sync_pacing(impl, s, false, 0); + if (!pacing->tsc_time_cursor) + tx_audio_session_sync_pacing(impl, s, false, 0); if (s->pacing_in_build) { uint64_t cur_tsc = mt_get_tsc(impl); uint64_t target_tsc = pacing->tsc_time_cursor; if (cur_tsc < target_tsc) { uint64_t delta = target_tsc - cur_tsc; - // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, cur_tsc, - // target_tsc); + // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, + // cur_tsc, target_tsc); if (likely(delta < NS_PER_S)) { s->stat_build_ret_code = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", + __func__, idx, cur_tsc, target_tsc); } } } - struct rte_mbuf* pkt = NULL; - struct rte_mbuf* pkt_r = NULL; - struct rte_mbuf* pkt_rtp = NULL; + struct rte_mbuf *pkt = NULL; + struct rte_mbuf *pkt_r = NULL; + struct rte_mbuf *pkt_rtp = NULL; - if (rte_ring_sc_dequeue(s->packet_ring, (void**)&pkt_rtp) != 0) { + if (rte_ring_sc_dequeue(s->packet_ring, (void **)&pkt_rtp) != 0) { dbg("%s(%d), rtp pkts not ready\n", __func__, idx); s->stat_build_ret_code = -STI_RTP_APP_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; @@ -977,7 +1014,8 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl* impl, } tx_audio_session_update_redundant(s, pkt_r); } else { - tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, MTL_SESSION_PORT_R); + tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, + MTL_SESSION_PORT_R); } st_tx_mbuf_set_tsc(pkt_r, pacing->tsc_time_cursor); s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R]++; @@ -1000,14 +1038,13 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl* impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tx_audio_session_tasklet_transmit(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s, - int s_port) { +static int tx_audio_session_tasklet_transmit( + struct mtl_main_impl *impl, struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, int s_port) { int idx = s->idx, ret; - struct rte_mbuf* pkt; + struct rte_mbuf *pkt; enum mtl_port t_port = mt_port_logic2phy(s->port_maps, s_port); - struct rte_ring* trs_ring = mgr->ring[t_port]; + struct rte_ring *trs_ring = mgr->ring[t_port]; uint64_t cur_tsc; uint64_t target_tsc; @@ -1043,7 +1080,7 @@ static int tx_audio_session_tasklet_transmit(struct mtl_main_impl* impl, } /* try to dequeue pkt */ - ret = mt_u64_fifo_get(s->trans_ring[s_port], (uint64_t*)&pkt); + ret = mt_u64_fifo_get(s->trans_ring[s_port], (uint64_t *)&pkt); if (ret < 0) { s->stat_transmit_ret_code = -STI_TSCTRS_PKT_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; /* no pkt */ @@ -1053,16 +1090,16 @@ static int tx_audio_session_tasklet_transmit(struct mtl_main_impl* impl, target_tsc = st_tx_mbuf_get_tsc(pkt); if (cur_tsc < target_tsc) { uint64_t delta = target_tsc - cur_tsc; - // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, cur_tsc, - // target_tsc); + // dbg("%s(%d), cur_tsc %"PRIu64" target_tsc %"PRIu64"\n", __func__, idx, + // cur_tsc, target_tsc); if (likely(delta < NS_PER_S)) { s->stat_transmit_ret_code = -STI_TSCTRS_TARGET_TSC_NOT_REACH; s->trans_ring_inflight[s_port] = pkt; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, + idx, cur_tsc, target_tsc); } } @@ -1091,24 +1128,24 @@ static int tx_audio_session_tasklet_transmit(struct mtl_main_impl* impl, return 0; } -static const char* audio_pacing_way_names[ST30_TX_PACING_WAY_MAX] = { +static const char *audio_pacing_way_names[ST30_TX_PACING_WAY_MAX] = { "auto", "ratelimit", "tsc", }; -const char* audio_pacing_way_name(enum st30_tx_pacing_way way) { +const char *audio_pacing_way_name(enum st30_tx_pacing_way way) { return audio_pacing_way_names[way]; } -static int tx_audio_session_uinit_rl(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s) { - struct st_tx_audio_session_rl_info* rl = &s->rl; +static int tx_audio_session_uinit_rl(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { + struct st_tx_audio_session_rl_info *rl = &s->rl; MTL_MAY_UNUSED(impl); for (int i = 0; i < s->ops.num_port; i++) { enum mtl_port port = mt_port_logic2phy(s->port_maps, i); - struct st_tx_audio_session_rl_port* rl_port = &rl->port_info[i]; + struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[i]; for (int j = 0; j < ST30_TX_RL_QUEUES_USED; j++) { if (rl_port->queue[j]) { @@ -1130,17 +1167,18 @@ static int tx_audio_session_uinit_rl(struct mtl_main_impl* impl, return 0; } -static inline uint64_t tx_audio_session_initial_rl_bps( - struct st_tx_audio_session_impl* s) { - struct st_tx_audio_session_rl_info* rl = &s->rl; - double bps = (double)(s->st30_pkt_size + rl->pad_pkt_size * rl->pads_per_st30_pkt) * - (double)NS_PER_S / s->pacing.trs; +static inline uint64_t +tx_audio_session_initial_rl_bps(struct st_tx_audio_session_impl *s) { + struct st_tx_audio_session_rl_info *rl = &s->rl; + double bps = + (double)(s->st30_pkt_size + rl->pad_pkt_size * rl->pads_per_st30_pkt) * + (double)NS_PER_S / s->pacing.trs; return bps; } -static int double_cmp(const void* a, const void* b) { - const double* ai = a; - const double* bi = b; +static int double_cmp(const void *a, const void *b) { + const double *ai = a; + const double *bi = b; if (*ai < *bi) { return -1; @@ -1151,13 +1189,14 @@ static int double_cmp(const void* a, const void* b) { } static inline uint64_t tx_audio_session_profiling_rl_bps( - struct mtl_main_impl* impl, struct st_tx_audio_session_impl* s, - enum mtl_session_port s_port, uint64_t initial_bytes_per_sec, int rl_q_idx) { + struct mtl_main_impl *impl, struct st_tx_audio_session_impl *s, + enum mtl_session_port s_port, uint64_t initial_bytes_per_sec, + int rl_q_idx) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); int idx = s->idx; - struct st_tx_audio_session_rl_info* rl = &s->rl; - struct st_tx_audio_session_rl_port* rl_port = &rl->port_info[s_port]; - struct mt_txq_entry* queue = rl_port->queue[rl_q_idx]; + struct st_tx_audio_session_rl_info *rl = &s->rl; + struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; + struct mt_txq_entry *queue = rl_port->queue[rl_q_idx]; /* wait tsc calibrate done */ mt_wait_tsc_stable(impl); @@ -1166,7 +1205,7 @@ static inline uint64_t tx_audio_session_profiling_rl_bps( /* warm-up stage to consume all nix tx buf */ int pad_pkts = mt_if_nb_tx_desc(impl, port) * 1; - struct rte_mbuf* pad = rl_port->pad; + struct rte_mbuf *pad = rl_port->pad; for (int i = 0; i < pad_pkts; i++) { rte_mbuf_refcnt_update(pad, 1); mt_txq_burst_busy(queue, &pad, 1, 10); @@ -1193,8 +1232,8 @@ static inline uint64_t tx_audio_session_profiling_rl_bps( uint64_t tsc_end = mt_get_tsc(impl); double time_sec = (double)(tsc_end - tsc_start) / NS_PER_S; loop_actual_per_sec[loop] = total / time_sec; - dbg("%s(%d), pkts per second expect %f actual %f\n", __func__, idx, expect_per_sec, - loop_actual_per_sec[loop]); + dbg("%s(%d), pkts per second expect %f actual %f\n", __func__, idx, + expect_per_sec, loop_actual_per_sec[loop]); } /* sort */ qsort(loop_actual_per_sec, loop_cnt, sizeof(double), double_cmp); @@ -1207,20 +1246,20 @@ static inline uint64_t tx_audio_session_profiling_rl_bps( double actual_per_sec = actual_per_sec_sum / entry_in_sum; double ratio = actual_per_sec / expect_per_sec; if (ratio > 1.1 || ratio < 0.9) { - err("%s(%d), fail, expect %f but actual %f\n", __func__, idx, expect_per_sec, - actual_per_sec); + err("%s(%d), fail, expect %f but actual %f\n", __func__, idx, + expect_per_sec, actual_per_sec); return 0; } - info("%s(%d), pkts per second, expect %f actual %f with time %fs\n", __func__, idx, - expect_per_sec, actual_per_sec, + info("%s(%d), pkts per second, expect %f actual %f with time %fs\n", __func__, + idx, expect_per_sec, actual_per_sec, ((double)mt_get_tsc(impl) - train_start_tsc) / NS_PER_S); return initial_bytes_per_sec * expect_per_sec / actual_per_sec; } -static int tx_audio_session_init_rl(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_init_rl(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { int idx = s->idx; - struct st_tx_audio_session_rl_info* rl = &s->rl; + struct st_tx_audio_session_rl_info *rl = &s->rl; enum mtl_port port; uint16_t queue_id; uint64_t profiled_per_sec = 0; @@ -1234,7 +1273,8 @@ static int tx_audio_session_init_rl(struct mtl_main_impl* impl, rl->required_accuracy_ns = 40 * NS_PER_US; /* 40us */ } if (s->ops.rl_offset_ns) { - info("%s(%d), user required offset %dns\n", __func__, idx, s->ops.rl_offset_ns); + info("%s(%d), user required offset %dns\n", __func__, idx, + s->ops.rl_offset_ns); } rl->pkts_prepare_warmup = 4; rl->pads_per_st30_pkt = 3; @@ -1243,12 +1283,12 @@ static int tx_audio_session_init_rl(struct mtl_main_impl* impl, rl->pkts_per_sync = (double)NS_PER_S / s->pacing.trs / 100; for (int i = 0; i < s->ops.num_port; i++) { - struct st_tx_audio_session_rl_port* rl_port = &rl->port_info[i]; + struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[i]; port = mt_port_logic2phy(s->port_maps, i); uint64_t initial_bytes_per_sec = tx_audio_session_initial_rl_bps(s); - int profiled = mt_audio_pacing_train_result_search(impl, port, initial_bytes_per_sec, - &profiled_per_sec); + int profiled = mt_audio_pacing_train_result_search( + impl, port, initial_bytes_per_sec, &profiled_per_sec); /* pad pkt */ rl_port->pad = mt_build_pad(impl, mt_sys_tx_mempool(impl, port), port, @@ -1280,15 +1320,17 @@ static int tx_audio_session_init_rl(struct mtl_main_impl* impl, return -EIO; } if ((j == 0) && (profiled < 0)) { /* only profile on the first */ - uint64_t trained = - tx_audio_session_profiling_rl_bps(impl, s, i, initial_bytes_per_sec, j); + uint64_t trained = tx_audio_session_profiling_rl_bps( + impl, s, i, initial_bytes_per_sec, j); if (!trained) { tx_audio_session_uinit_rl(impl, s); return -EIO; } - mt_audio_pacing_train_result_add(impl, port, initial_bytes_per_sec, trained); - info("%s(%d), trained bytes_per_sec %" PRIu64 "\n", __func__, idx, trained); + mt_audio_pacing_train_result_add(impl, port, initial_bytes_per_sec, + trained); + info("%s(%d), trained bytes_per_sec %" PRIu64 "\n", __func__, idx, + trained); int ret = mt_txq_set_tx_bps(rl_port->queue[j], trained); if (ret < 0) { tx_audio_session_uinit_rl(impl, s); @@ -1297,41 +1339,43 @@ static int tx_audio_session_init_rl(struct mtl_main_impl* impl, initial_bytes_per_sec = trained; } queue_id = mt_txq_queue_id(rl_port->queue[j]); - info("%s(%d), port(l:%d,p:%d), queue %d at sync %d\n", __func__, idx, i, port, - queue_id, j); + info("%s(%d), port(l:%d,p:%d), queue %d at sync %d\n", __func__, idx, i, + port, queue_id, j); } } return 0; } -static void tx_audio_session_rl_switch_queue( - struct st_tx_audio_session_rl_port* rl_port) { +static void +tx_audio_session_rl_switch_queue(struct st_tx_audio_session_rl_port *rl_port) { int cur_queue = rl_port->cur_queue; cur_queue++; - if (cur_queue >= ST30_TX_RL_QUEUES_USED) cur_queue = 0; + if (cur_queue >= ST30_TX_RL_QUEUES_USED) + cur_queue = 0; rl_port->cur_queue = cur_queue; } -static void tx_audio_session_rl_inc_pkt_idx(struct st_tx_audio_session_rl_info* rl, - struct st_tx_audio_session_rl_port* rl_port) { +static void +tx_audio_session_rl_inc_pkt_idx(struct st_tx_audio_session_rl_info *rl, + struct st_tx_audio_session_rl_port *rl_port) { rl_port->cur_pkt_idx++; if (rl_port->cur_pkt_idx >= rl->pkts_per_sync) { - dbg("%s(%d,%d), switch to next queue, cur queue %d pkts %d send\n", __func__, idx, - s_port, cur_queue, rl_port->cur_pkt_idx); + dbg("%s(%d,%d), switch to next queue, cur queue %d pkts %d send\n", + __func__, idx, s_port, cur_queue, rl_port->cur_pkt_idx); rl_port->cur_pkt_idx = 0; tx_audio_session_rl_switch_queue(rl_port); } } -static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl* s, int s_port, - struct rte_mbuf* pkt) { - struct st_tx_audio_session_rl_info* rl = &s->rl; - struct st_tx_audio_session_rl_port* rl_port = &rl->port_info[s_port]; +static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl *s, + int s_port, struct rte_mbuf *pkt) { + struct st_tx_audio_session_rl_info *rl = &s->rl; + struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; int pads_per_st30_pkt = rl->pads_per_st30_pkt; int cur_queue = rl_port->cur_queue; - struct mt_txq_entry* queue = rl_port->queue[cur_queue]; - struct rte_mbuf* pads[pads_per_st30_pkt]; + struct mt_txq_entry *queue = rl_port->queue[cur_queue]; + struct rte_mbuf *pads[pads_per_st30_pkt]; uint16_t tx; tx = mt_txq_burst(queue, &pkt, 1); @@ -1349,8 +1393,8 @@ static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl* s, i tx = mt_txq_burst(queue, pads, pads_per_st30_pkt); rl_port->stat_pad_pkts_burst += tx; if (tx != pads_per_st30_pkt) { - dbg("%s(%d,%d), sending %u pad pkts only %u succ\n", __func__, s->idx, s_port, - pads_per_st30_pkt, tx); + dbg("%s(%d,%d), sending %u pad pkts only %u succ\n", __func__, s->idx, + s_port, pads_per_st30_pkt, tx); /* save to pad inflight */ rl_port->trs_pad_inflight_num = pads_per_st30_pkt - tx; } else { @@ -1360,13 +1404,14 @@ static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl* s, i return 1; } -static uint16_t tx_audio_session_rl_warmup_pkt(struct st_tx_audio_session_impl* s, - int s_port, int pre, int pkts) { - struct st_tx_audio_session_rl_info* rl = &s->rl; - struct st_tx_audio_session_rl_port* rl_port = &rl->port_info[s_port]; +static uint16_t +tx_audio_session_rl_warmup_pkt(struct st_tx_audio_session_impl *s, int s_port, + int pre, int pkts) { + struct st_tx_audio_session_rl_info *rl = &s->rl; + struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; int cur_queue = rl_port->cur_queue; - struct mt_txq_entry* queue = rl_port->queue[cur_queue]; - struct rte_mbuf* pad; + struct mt_txq_entry *queue = rl_port->queue[cur_queue]; + struct rte_mbuf *pad; /* sending the prepare warmup pkts */ pad = rl_port->pad; @@ -1393,17 +1438,19 @@ static uint16_t tx_audio_session_rl_warmup_pkt(struct st_tx_audio_session_impl* return 0; } -static uint16_t tx_audio_session_rl_first_pkt(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s, - int s_port, struct rte_mbuf* pkt) { - struct st_tx_audio_session_rl_info* rl = &s->rl; - struct st_tx_audio_session_rl_port* rl_port = &rl->port_info[s_port]; +static uint16_t +tx_audio_session_rl_first_pkt(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s, int s_port, + struct rte_mbuf *pkt) { + struct st_tx_audio_session_rl_info *rl = &s->rl; + struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; uint64_t target_tsc = rl_port->trs_target_tsc + s->ops.rl_offset_ns; uint64_t cur_tsc; cur_tsc = mt_get_tsc(impl); if (cur_tsc > target_tsc) { /* time already reach */ - dbg("%s(%d,%d), warmup fail, cur %" PRIu64 " target %" PRIu64 ", burst directly\n", + dbg("%s(%d,%d), warmup fail, cur %" PRIu64 " target %" PRIu64 + ", burst directly\n", __func__, s->idx, s_port, cur_tsc, target_tsc); rl_port->trs_target_tsc = 0; /* clear target tsc */ rl_port->stat_mismatch_sync_point++; @@ -1413,20 +1460,22 @@ static uint16_t tx_audio_session_rl_first_pkt(struct mtl_main_impl* impl, return tx_audio_session_rl_tx_pkt(s, s_port, pkt); } - if (rl_port->force_sync_first_tsc) return 0; + if (rl_port->force_sync_first_tsc) + return 0; /* check if we are reaching the warmup stage */ uint32_t delta_tsc = target_tsc - cur_tsc; uint32_t trs = s->pacing.trs; uint32_t delta_pkts = delta_tsc / trs; if (delta_pkts > rl->max_warmup_trs) { - dbg("%s(%d,%d), delta_pkts %u too large\n", __func__, idx, s_port, delta_pkts); + dbg("%s(%d,%d), delta_pkts %u too large\n", __func__, idx, s_port, + delta_pkts); return 0; } uint32_t accuracy = delta_tsc % trs; if (accuracy > rl->required_accuracy_ns) { - dbg("%s(%d,%d), accuracy %u too large, delta_tsc %u trs %u\n", __func__, idx, s_port, - accuracy, delta_tsc, trs); + dbg("%s(%d,%d), accuracy %u too large, delta_tsc %u trs %u\n", __func__, + idx, s_port, accuracy, delta_tsc, trs); return 0; } dbg("%s(%d,%d), accuracy %u succ\n", __func__, idx, s_port, accuracy); @@ -1445,8 +1494,8 @@ static uint16_t tx_audio_session_rl_first_pkt(struct mtl_main_impl* impl, uint32_t delta_tsc_now = target_tsc - mt_get_tsc(impl); uint32_t delta_pkts_now = delta_tsc_now / trs; if (delta_pkts_now < (i - 0)) { - dbg("%s(%d), mismatch delta_pkts_now %d at %d\n", __func__, s->idx, delta_pkts_now, - i); + dbg("%s(%d), mismatch delta_pkts_now %d at %d\n", __func__, s->idx, + delta_pkts_now, i); /* try next sync point */ rl_port->stat_recalculate_warmup++; rl_port->force_sync_first_tsc = true; @@ -1459,13 +1508,14 @@ static uint16_t tx_audio_session_rl_first_pkt(struct mtl_main_impl* impl, return tx_audio_session_rl_tx_pkt(s, s_port, pkt); } -static int tx_audio_session_tasklet_rl_transmit(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s, - int s_port) { +static int +tx_audio_session_tasklet_rl_transmit(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s, + int s_port) { int ret; - struct rte_mbuf* pkt; - struct st_tx_audio_session_rl_info* rl = &s->rl; - struct st_tx_audio_session_rl_port* rl_port = &rl->port_info[s_port]; + struct rte_mbuf *pkt; + struct st_tx_audio_session_rl_info *rl = &s->rl; + struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; uint16_t tx; /* check if any pending pkt */ @@ -1486,8 +1536,8 @@ static int tx_audio_session_tasklet_rl_transmit(struct mtl_main_impl* impl, /* check if any padding inflight pkts in transmitter */ if (rl_port->trs_pad_inflight_num > 0) { int cur_queue = rl_port->cur_queue; - struct mt_txq_entry* queue = rl_port->queue[cur_queue]; - struct rte_mbuf* pad = rl_port->pad; + struct mt_txq_entry *queue = rl_port->queue[cur_queue]; + struct rte_mbuf *pad = rl_port->pad; tx = mt_txq_burst(queue, &pad, 1); rl_port->trs_pad_inflight_num -= tx; @@ -1501,7 +1551,7 @@ static int tx_audio_session_tasklet_rl_transmit(struct mtl_main_impl* impl, } /* try to dequeue pkt */ - ret = mt_u64_fifo_get(s->trans_ring[s_port], (uint64_t*)&pkt); + ret = mt_u64_fifo_get(s->trans_ring[s_port], (uint64_t *)&pkt); if (ret < 0) { s->stat_transmit_ret_code = -STI_RLTRS_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; /* no pkt */ @@ -1523,19 +1573,22 @@ static int tx_audio_session_tasklet_rl_transmit(struct mtl_main_impl* impl, return 0; } -static int tx_audio_sessions_tasklet(void* priv) { - struct st_tx_audio_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_audio_session_impl* s; +static int tx_audio_sessions_tasklet(void *priv) { + struct st_tx_audio_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_audio_session_impl *s; int pending = MTL_TASKLET_ALL_DONE; uint64_t tsc_s = 0; bool time_measure = mt_sessions_time_measure(impl); for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_audio_session_try_get(mgr, sidx); - if (!s) continue; - if (!s->active) goto exit; - if (time_measure) tsc_s = mt_get_tsc(impl); + if (!s) + continue; + if (!s->active) + goto exit; + if (time_measure) + tsc_s = mt_get_tsc(impl); s->stat_build_ret_code = 0; if (s->ops.type == ST30_TYPE_FRAME_LEVEL) @@ -1561,16 +1614,17 @@ static int tx_audio_sessions_tasklet(void* priv) { return pending; } -static int tx_audio_sessions_mgr_uinit_hw(struct st_tx_audio_sessions_mgr* mgr, +static int tx_audio_sessions_mgr_uinit_hw(struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port) { if (mgr->ring[port]) { rte_ring_free(mgr->ring[port]); mgr->ring[port] = NULL; } if (mgr->queue[port]) { - struct rte_mbuf* pad = mt_get_pad(mgr->parent, port); + struct rte_mbuf *pad = mt_get_pad(mgr->parent, port); /* flush all the pkts in the tx ring desc */ - if (pad) mt_txq_flush(mgr->queue[port], pad); + if (pad) + mt_txq_flush(mgr->queue[port], pad); mt_txq_put(mgr->queue[port]); mgr->queue[port] = NULL; } @@ -1579,15 +1633,16 @@ static int tx_audio_sessions_mgr_uinit_hw(struct st_tx_audio_sessions_mgr* mgr, return 0; } -static int tx_audio_sessions_mgr_init_hw(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, +static int tx_audio_sessions_mgr_init_hw(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port) { unsigned int flags, count; - struct rte_ring* ring; + struct rte_ring *ring; char ring_name[32]; int mgr_idx = mgr->idx; - if (mgr->queue[port]) return 0; /* init already */ + if (mgr->queue[port]) + return 0; /* init already */ struct mt_txq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -1597,7 +1652,8 @@ static int tx_audio_sessions_mgr_init_hw(struct mtl_main_impl* impl, } snprintf(ring_name, 32, "%sM%dP%d", ST_TX_AUDIO_PREFIX, mgr_idx, port); - flags = RING_F_MP_HTS_ENQ | RING_F_SC_DEQ; /* multi-producer and single-consumer */ + flags = RING_F_MP_HTS_ENQ | + RING_F_SC_DEQ; /* multi-producer and single-consumer */ count = ST_TX_AUDIO_SESSIONS_RING_SIZE; ring = rte_ring_create(ring_name, count, mgr->socket_id, flags); if (!ring) { @@ -1613,18 +1669,18 @@ static int tx_audio_sessions_mgr_init_hw(struct mtl_main_impl* impl, return 0; } -static int tx_audio_session_sq_flush_port(struct st_tx_audio_sessions_mgr* mgr, +static int tx_audio_session_sq_flush_port(struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port) { - struct mtl_main_impl* impl = mgr->parent; + struct mtl_main_impl *impl = mgr->parent; int ret; int burst_pkts = mt_if_nb_tx_desc(impl, port); - struct rte_mbuf* pad = mt_get_pad(impl, port); + struct rte_mbuf *pad = mt_get_pad(impl, port); for (int i = 0; i < burst_pkts; i++) { rte_mbuf_refcnt_update(pad, 1); int retry = 0; do { - ret = rte_ring_mp_enqueue(mgr->ring[port], (void*)pad); + ret = rte_ring_mp_enqueue(mgr->ring[port], (void *)pad); if (ret != 0) { dbg("%s(%d), timeout at %d, ret %d\n", __func__, mgr->idx, i, ret); retry++; @@ -1641,14 +1697,15 @@ static int tx_audio_session_sq_flush_port(struct st_tx_audio_sessions_mgr* mgr, } /* wa to flush the audio transmitter tx queue */ -static int tx_audio_session_sq_flush(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_sq_flush(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { int mgr_idx = mgr->idx, s_idx = s->idx; - if (!s->shared_queue) return 0; /* skip as not shared queue */ + if (!s->shared_queue) + return 0; /* skip as not shared queue */ for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { - struct rte_mempool* pool = s->mbuf_mempool_hdr[i]; + struct rte_mempool *pool = s->mbuf_mempool_hdr[i]; if (pool && rte_mempool_in_use_count(pool) && rte_atomic32_read(&mgr->transmitter_started)) { @@ -1659,50 +1716,55 @@ static int tx_audio_session_sq_flush(struct st_tx_audio_sessions_mgr* mgr, int retry = 100; /* max 1000ms */ while (retry > 0) { retry--; - if (!rte_mempool_in_use_count(pool)) break; + if (!rte_mempool_in_use_count(pool)) + break; mt_sleep_ms(10); } - info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, retry); + info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, + retry); } } return 0; } -int tx_audio_session_mempool_free(struct st_tx_audio_session_impl* s) { +int tx_audio_session_mempool_free(struct st_tx_audio_session_impl *s) { int ret; if (s->mbuf_mempool_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_chain); - if (ret >= 0) s->mbuf_mempool_chain = NULL; + if (ret >= 0) + s->mbuf_mempool_chain = NULL; } for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { if (s->mbuf_mempool_hdr[i] && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_hdr[i]); - if (ret >= 0) s->mbuf_mempool_hdr[i] = NULL; + if (ret >= 0) + s->mbuf_mempool_hdr[i] = NULL; } } return 0; } -static bool tx_audio_session_has_chain_buf(struct st_tx_audio_session_impl* s) { - struct st30_tx_ops* ops = &s->ops; +static bool tx_audio_session_has_chain_buf(struct st_tx_audio_session_impl *s) { + struct st30_tx_ops *ops = &s->ops; int num_ports = ops->num_port; for (int port = 0; port < num_ports; port++) { - if (!s->eth_has_chain[port]) return false; + if (!s->eth_has_chain[port]) + return false; } /* all ports capable chain */ return true; } -static int tx_audio_session_mempool_init(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { - struct st30_tx_ops* ops = &s->ops; +static int tx_audio_session_mempool_init(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { + struct st30_tx_ops *ops = &s->ops; int num_port = ops->num_port, idx = s->idx; enum mtl_port port; unsigned int n; @@ -1725,13 +1787,14 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl* impl, warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, i); } else { n = mt_if_nb_tx_desc(impl, port) + ST_TX_AUDIO_SESSIONS_RING_SIZE; - if (ops->type == ST30_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; + if (ops->type == ST30_TYPE_RTP_LEVEL) + n += ops->rtp_ring_size; char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_AUDIO_PREFIX, mgr->idx, idx, i, - s->recovery_idx); - struct rte_mempool* mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), - hdr_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_AUDIO_PREFIX, + mgr->idx, idx, i, s->recovery_idx); + struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( + impl, pool_name, n, MT_MBUF_CACHE_SIZE, + sizeof(struct mt_muf_priv_data), hdr_room_size, s->socket_id); if (!mbuf_pool) { tx_audio_session_mempool_free(s); return -ENOMEM; @@ -1744,7 +1807,8 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl* impl, if (!s->tx_no_chain) { port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); n = mt_if_nb_tx_desc(impl, port) + ST_TX_AUDIO_SESSIONS_RING_SIZE; - if (ops->type == ST30_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; + if (ops->type == ST30_TYPE_RTP_LEVEL) + n += ops->rtp_ring_size; if (s->tx_mono_pool) { s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port); @@ -1754,10 +1818,11 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl* impl, warn("%s(%d), use previous chain mempool\n", __func__, idx); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_AUDIO_PREFIX, mgr->idx, idx, - s->recovery_idx); - struct rte_mempool* mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, chain_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_AUDIO_PREFIX, mgr->idx, + idx, s->recovery_idx); + struct rte_mempool *mbuf_pool = + mt_mempool_create_by_socket(impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, + chain_room_size, s->socket_id); if (!mbuf_pool) { tx_audio_session_mempool_free(s); return -ENOMEM; @@ -1769,15 +1834,16 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl* impl, return 0; } -static int tx_audio_session_init_rtp(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_init_rtp(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count = s->ops.rtp_ring_size; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_TX_AUDIO_PREFIX, mgr_idx, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { err("%s(%d,%d), rte_ring_create fail\n", __func__, mgr_idx, idx); @@ -1789,7 +1855,8 @@ static int tx_audio_session_init_rtp(struct st_tx_audio_sessions_mgr* mgr, return 0; } -static int tx_audio_session_uinit_trans_ring(struct st_tx_audio_session_impl* s) { +static int +tx_audio_session_uinit_trans_ring(struct st_tx_audio_session_impl *s) { for (int port = 0; port < MTL_SESSION_PORT_MAX; port++) { if (s->trans_ring[port]) { mt_fifo_mbuf_clean(s->trans_ring[port]); @@ -1801,9 +1868,10 @@ static int tx_audio_session_uinit_trans_ring(struct st_tx_audio_session_impl* s) return 0; } -static int tx_audio_session_init_trans_ring(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { - struct mt_u64_fifo* ring; +static int +tx_audio_session_init_trans_ring(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { + struct mt_u64_fifo *ring; unsigned int count = ST_TX_AUDIO_SESSIONS_RING_SIZE; int mgr_idx = mgr->idx, idx = s->idx; int num_port = s->ops.num_port; @@ -1836,8 +1904,8 @@ static int tx_audio_session_init_trans_ring(struct st_tx_audio_sessions_mgr* mgr return 0; } -static int tx_audio_session_uinit_queue(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_uinit_queue(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { MTL_MAY_UNUSED(impl); for (int i = 0; i < s->ops.num_port; i++) { @@ -1852,8 +1920,8 @@ static int tx_audio_session_uinit_queue(struct mtl_main_impl* impl, return 0; } -static int tx_audio_session_init_queue(struct mtl_main_impl* impl, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_init_queue(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { int idx = s->idx; enum mtl_port port; uint16_t queue_id; @@ -1869,11 +1937,11 @@ static int tx_audio_session_init_queue(struct mtl_main_impl* impl, #ifdef MTL_HAS_RDMA_BACKEND int num_mrs = 1; /* always no tx chain for rdma_ud audio */ - void* mrs_bufs[num_mrs]; + void *mrs_bufs[num_mrs]; size_t mrs_sizes[num_mrs]; if (mt_pmd_is_rdma_ud(impl, port)) { /* register mempool memory to rdma */ - struct rte_mempool* pool = s->mbuf_mempool_hdr[i]; + struct rte_mempool *pool = s->mbuf_mempool_hdr[i]; mrs_bufs[0] = mt_mempool_mem_addr(pool); mrs_sizes[0] = mt_mempool_mem_size(pool); flow.num_mrs = num_mrs; @@ -1888,14 +1956,15 @@ static int tx_audio_session_init_queue(struct mtl_main_impl* impl, return -EIO; } queue_id = mt_txq_queue_id(s->queue[i]); - info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, queue_id); + info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, + queue_id); } return 0; } -static int tx_audio_session_uinit_sw(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_uinit_sw(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { int idx = s->idx, num_port = s->ops.num_port; for (int port = 0; port < num_port; port++) { @@ -1928,10 +1997,10 @@ static int tx_audio_session_uinit_sw(struct st_tx_audio_sessions_mgr* mgr, return 0; } -static int tx_audio_session_init_sw(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { - struct st30_tx_ops* ops = &s->ops; +static int tx_audio_session_init_sw(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { + struct st30_tx_ops *ops = &s->ops; int idx = s->idx, ret; /* free the pool if any in previous session */ @@ -1964,47 +2033,53 @@ static int tx_audio_session_init_sw(struct mtl_main_impl* impl, return 0; } -static int tx_audio_session_uinit(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_uinit(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { tx_audio_session_uinit_rl(mgr->parent, s); tx_audio_session_uinit_queue(mgr->parent, s); tx_audio_session_uinit_sw(mgr, s); return 0; } -static int tx_audio_session_attach(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s, - struct st30_tx_ops* ops) { +static int tx_audio_session_attach(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, + struct st30_tx_ops *ops) { int ret; int idx = s->idx, num_port = ops->num_port; - char* ports[MTL_SESSION_PORT_MAX]; + char *ports[MTL_SESSION_PORT_MAX]; bool rdma_ud = false; - for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) + ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->mgr = mgr; /* use dedicated queue for rdma_ud */ for (int i = 0; i < num_port; i++) { enum mtl_port port = mt_port_logic2phy(s->port_maps, i); - if (mt_pmd_is_rdma_ud(impl, port)) rdma_ud = true; + if (mt_pmd_is_rdma_ud(impl, port)) + rdma_ud = true; } /* detect pacing */ s->tx_pacing_way = ST30_TX_PACING_WAY_TSC; double pkt_time = st30_get_packet_time(ops->ptime); bool detect_rl = false; - if ((ops->pacing_way == ST30_TX_PACING_WAY_AUTO) && (pkt_time < (NS_PER_MS / 2))) { + if ((ops->pacing_way == ST30_TX_PACING_WAY_AUTO) && + (pkt_time < (NS_PER_MS / 2))) { info("%s(%d), try detect rl as pkt_time %fns\n", __func__, idx, pkt_time); detect_rl = true; } - if ((ops->pacing_way == ST30_TX_PACING_WAY_RL) && (pkt_time < (NS_PER_MS * 2))) { + if ((ops->pacing_way == ST30_TX_PACING_WAY_RL) && + (pkt_time < (NS_PER_MS * 2))) { detect_rl = true; } - if (rdma_ud) detect_rl = false; /* no rl for rdma_ud */ + if (rdma_ud) + detect_rl = false; /* no rl for rdma_ud */ if (detect_rl) { bool cap_rl = true; /* check if all port support rl */ @@ -2013,19 +2088,20 @@ static int tx_audio_session_attach(struct mtl_main_impl* impl, enum st21_tx_pacing_way sys_pacing_way = mt_if(impl, port)->tx_pacing_way; if (sys_pacing_way != ST21_TX_PACING_WAY_RL) { if (ops->pacing_way == ST30_TX_PACING_WAY_AUTO) { - info("%s(%d,%d), the port sys pacing way %d not capable to RL\n", __func__, idx, - port, sys_pacing_way); + info("%s(%d,%d), the port sys pacing way %d not capable to RL\n", + __func__, idx, port, sys_pacing_way); cap_rl = false; break; } else { - err("%s(%d,%d), the port sys pacing way %d not capable to RL\n", __func__, idx, - port, sys_pacing_way); + err("%s(%d,%d), the port sys pacing way %d not capable to RL\n", + __func__, idx, port, sys_pacing_way); return -ENOTSUP; } } } if (cap_rl) { - info("%s(%d), select rl based pacing for pkt_time %fns\n", __func__, idx, pkt_time); + info("%s(%d), select rl based pacing for pkt_time %fns\n", __func__, idx, + pkt_time); s->tx_pacing_way = ST30_TX_PACING_WAY_RL; } } @@ -2033,18 +2109,23 @@ static int tx_audio_session_attach(struct mtl_main_impl* impl, if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, idx); + snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, + idx); } s->ops = *ops; /* if disable shared queue */ s->shared_queue = true; - if (s->tx_pacing_way == ST30_TX_PACING_WAY_RL) s->shared_queue = false; - if (ops->flags & ST30_TX_FLAG_DEDICATE_QUEUE) s->shared_queue = false; - if (rdma_ud) s->shared_queue = false; + if (s->tx_pacing_way == ST30_TX_PACING_WAY_RL) + s->shared_queue = false; + if (ops->flags & ST30_TX_FLAG_DEDICATE_QUEUE) + s->shared_queue = false; + if (rdma_ud) + s->shared_queue = false; for (int i = 0; i < num_port; i++) { - s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10100 + idx * 2); + s->st30_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (10100 + idx * 2); if (mt_user_random_src_port(impl)) s->st30_src_port[i] = mt_random_port(s->st30_dst_port[i]); else @@ -2064,24 +2145,30 @@ static int tx_audio_session_attach(struct mtl_main_impl* impl, } s->tx_mono_pool = mt_user_tx_mono_pool(impl); /* manually disable chain or any port can't support chain */ - s->tx_no_chain = mt_user_tx_no_chain(impl) || !tx_audio_session_has_chain_buf(s); - if (rdma_ud) s->tx_no_chain = true; + s->tx_no_chain = + mt_user_tx_no_chain(impl) || !tx_audio_session_has_chain_buf(s); + if (rdma_ud) + s->tx_no_chain = true; s->st30_frames_cnt = ops->framebuff_cnt; ret = st30_get_sample_size(ops->fmt); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->sample_size = ret; ret = st30_get_sample_num(ops->ptime, ops->sampling); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->sample_num = ret; ret = st30_get_packet_size(ops->fmt, ops->ptime, ops->sampling, ops->channel); - if (ret < 0) return ret; + if (ret < 0) + return ret; s->pkt_len = ret; /* calculate pkts in line*/ - size_t bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); + size_t bytes_in_pkt = + ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); s->st30_pkt_size = s->pkt_len + sizeof(struct st_rfc3550_audio_hdr); if (s->pkt_len > bytes_in_pkt) { @@ -2092,8 +2179,8 @@ static int tx_audio_session_attach(struct mtl_main_impl* impl, s->st30_total_pkts = ops->framebuff_size / s->pkt_len; if (ops->framebuff_size % s->pkt_len) { /* todo: add the support? */ - err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, s->pkt_len, - ops->framebuff_size); + err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, + s->pkt_len, ops->framebuff_size); return -EIO; } s->st30_pkt_idx = 0; @@ -2113,7 +2200,8 @@ static int tx_audio_session_attach(struct mtl_main_impl* impl, s->inflight[i] = NULL; s->inflight_cnt[i] = 0; } - if (ops->flags & ST30_TX_FLAG_BUILD_PACING) s->pacing_in_build = true; + if (ops->flags & ST30_TX_FLAG_BUILD_PACING) + s->pacing_in_build = true; s->calculate_time_cursor = true; ret = tx_audio_session_init_pacing(s); if (ret < 0) { @@ -2157,28 +2245,29 @@ static int tx_audio_session_attach(struct mtl_main_impl* impl, s->frames_per_sec = (double)NS_PER_S / s->pacing.trs / s->st30_total_pkts; s->active = true; - info("%s(%d), fmt %d channel %u sampling %d ptime %d pt %u\n", __func__, idx, ops->fmt, - ops->channel, ops->sampling, ops->ptime, ops->payload_type); - info("%s(%d), pkt_len %u frame_size %u frames %u fps %f, pacing_way %s\n", __func__, - idx, s->pkt_len, s->st30_frame_size, s->st30_frames_cnt, + info("%s(%d), fmt %d channel %u sampling %d ptime %d pt %u\n", __func__, idx, + ops->fmt, ops->channel, ops->sampling, ops->ptime, ops->payload_type); + info("%s(%d), pkt_len %u frame_size %u frames %u fps %f, pacing_way %s\n", + __func__, idx, s->pkt_len, s->st30_frame_size, s->st30_frames_cnt, (double)NS_PER_S / s->pacing.trs / s->st30_total_pkts, audio_pacing_way_name(s->tx_pacing_way)); return 0; } -static int tx_audio_session_update_dst(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s, - struct st_tx_dest_info* dst) { +static int tx_audio_session_update_dst(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, + struct st_tx_dest_info *dst) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; - struct st30_tx_ops* ops = &s->ops; + struct st30_tx_ops *ops = &s->ops; /* update ip and port */ for (int i = 0; i < num_port; i++) { memcpy(ops->dip_addr[i], dst->dip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = dst->udp_port[i]; - s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); + s->st30_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); s->st30_src_port[i] = (ops->udp_src_port[i]) ? (ops->udp_src_port[i]) : s->st30_dst_port[i]; @@ -2193,9 +2282,10 @@ static int tx_audio_session_update_dst(struct mtl_main_impl* impl, return 0; } -static int tx_audio_sessions_mgr_update_dst(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s, - struct st_tx_dest_info* dst) { +static int +tx_audio_sessions_mgr_update_dst(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, + struct st_tx_dest_info *dst) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = tx_audio_session_get(mgr, idx); /* get the lock */ @@ -2214,8 +2304,8 @@ static int tx_audio_sessions_mgr_update_dst(struct st_tx_audio_sessions_mgr* mgr return 0; } -static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { +static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { int idx = s->idx; int m_idx = mgr->idx; int frame_cnt = rte_atomic32_read(&s->st30_stat_frame_cnt); @@ -2226,10 +2316,12 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr* mgr, rte_atomic32_set(&s->st30_stat_frame_cnt, 0); s->stat_last_time = cur_time_ns; - notice("TX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d, pkts %d:%d inflight %d:%d\n", + notice("TX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d, pkts %d:%d inflight " + "%d:%d\n", m_idx, idx, s->ops_name, framerate, frame_cnt, s->st30_stat_pkt_cnt[MTL_SESSION_PORT_P], - s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R], s->inflight_cnt[MTL_SESSION_PORT_P], + s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R], + s->inflight_cnt[MTL_SESSION_PORT_P], s->inflight_cnt[MTL_SESSION_PORT_R]); s->st30_stat_pkt_cnt[MTL_SESSION_PORT_P] = 0; s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R] = 0; @@ -2240,7 +2332,8 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr* mgr, s->stat_epoch_mismatch = 0; } if (s->stat_epoch_drop) { - notice("TX_AUDIO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, s->stat_epoch_drop); + notice("TX_AUDIO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, + s->stat_epoch_drop); s->stat_epoch_drop = 0; } if (s->stat_epoch_onward) { @@ -2249,7 +2342,8 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr* mgr, s->stat_epoch_onward = 0; } if (s->stat_epoch_late) { - notice("TX_AUDIO_SESSION(%d,%d): epoch late %u\n", m_idx, idx, s->stat_epoch_late); + notice("TX_AUDIO_SESSION(%d,%d): epoch late %u\n", m_idx, idx, + s->stat_epoch_late); s->stat_epoch_late = 0; } if (s->stat_exceed_frame_time) { @@ -2278,9 +2372,9 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr* mgr, /* not reset unrecoverable_error */ } if (s->tx_pacing_way == ST30_TX_PACING_WAY_RL) { - struct st_tx_audio_session_rl_port* rl_port = &s->rl.port_info[0]; - notice("TX_AUDIO_SESSION(%d,%d): rl pkts %u pads %u warmup %u\n", m_idx, idx, - rl_port->stat_pkts_burst, rl_port->stat_pad_pkts_burst, + struct st_tx_audio_session_rl_port *rl_port = &s->rl.port_info[0]; + notice("TX_AUDIO_SESSION(%d,%d): rl pkts %u pads %u warmup %u\n", m_idx, + idx, rl_port->stat_pkts_burst, rl_port->stat_pad_pkts_burst, rl_port->stat_warmup_pkts_burst); rl_port->stat_pkts_burst = 0; rl_port->stat_pad_pkts_burst = 0; @@ -2296,38 +2390,43 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr* mgr, rl_port->stat_recalculate_warmup = 0; } if (rl_port->stat_hit_backup_cp) { - notice("TX_AUDIO_SESSION(%d,%d): hit backup warmup checkpoint %u\n", m_idx, idx, - rl_port->stat_hit_backup_cp); + notice("TX_AUDIO_SESSION(%d,%d): hit backup warmup checkpoint %u\n", + m_idx, idx, rl_port->stat_hit_backup_cp); rl_port->stat_hit_backup_cp = 0; } } - struct mt_stat_u64* stat_time = &s->stat_time; + struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("TX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + notice("TX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, + (float)stat_time->max / NS_PER_US, (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } - struct mt_stat_u64* stat_tx_delta = &s->stat_tx_delta; + struct mt_stat_u64 *stat_tx_delta = &s->stat_tx_delta; if (stat_tx_delta->cnt) { uint64_t avg_ns = stat_tx_delta->sum / stat_tx_delta->cnt; - notice("TX_AUDIO_SESSION(%d,%d): tx delta avg %.2fus max %.2fus min %.2fus\n", m_idx, - idx, (float)avg_ns / NS_PER_US, (float)stat_tx_delta->max / NS_PER_US, - (float)stat_tx_delta->min / NS_PER_US); + notice( + "TX_AUDIO_SESSION(%d,%d): tx delta avg %.2fus max %.2fus min %.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, + (float)stat_tx_delta->max / NS_PER_US, + (float)stat_tx_delta->min / NS_PER_US); mt_stat_u64_init(stat_tx_delta); } if (s->stat_max_next_frame_us > 8 || s->stat_max_notify_frame_us > 8) { - notice("TX_AUDIO_SESSION(%d,%d): get next frame max %uus, notify done max %uus\n", + notice("TX_AUDIO_SESSION(%d,%d): get next frame max %uus, notify done max " + "%uus\n", m_idx, idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); } s->stat_max_next_frame_us = 0; s->stat_max_notify_frame_us = 0; } -static int tx_audio_session_detach(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { +static int tx_audio_session_detach(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { tx_audio_session_stat(mgr, s); tx_audio_session_uinit(mgr, s); if (s->shared_queue) { @@ -2336,25 +2435,28 @@ static int tx_audio_session_detach(struct st_tx_audio_sessions_mgr* mgr, return 0; } -static int st_tx_audio_sessions_stat(void* priv) { - struct st_tx_audio_sessions_mgr* mgr = priv; - struct st_tx_audio_session_impl* s; +static int st_tx_audio_sessions_stat(void *priv) { + struct st_tx_audio_sessions_mgr *mgr = priv; + struct st_tx_audio_session_impl *s; int m_idx = mgr->idx; for (int j = 0; j < mgr->max_idx; j++) { s = tx_audio_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) continue; + if (!s) + continue; tx_audio_session_stat(mgr, s); tx_audio_session_put(mgr, j); } if (mgr->st30_stat_pkts_burst > 0) { - notice("TX_AUDIO_MGR(%d), pkts burst %d\n", m_idx, mgr->st30_stat_pkts_burst); + notice("TX_AUDIO_MGR(%d), pkts burst %d\n", m_idx, + mgr->st30_stat_pkts_burst); mgr->st30_stat_pkts_burst = 0; } else { int32_t clients = rte_atomic32_read(&mgr->transmitter_clients); if ((clients > 0) && (mgr->max_idx > 0)) { for (int i = 0; i < mt_num_ports(mgr->parent); i++) { - warn("TX_AUDIO_MGR(%d): trs ret %d:%d\n", m_idx, i, mgr->stat_trs_ret_code[i]); + warn("TX_AUDIO_MGR(%d): trs ret %d:%d\n", m_idx, i, + mgr->stat_trs_ret_code[i]); } } } @@ -2372,9 +2474,9 @@ static int st_tx_audio_sessions_stat(void* priv) { return 0; } -static int tx_audio_sessions_mgr_init(struct mtl_main_impl* impl, - struct mtl_sch_impl* sch, - struct st_tx_audio_sessions_mgr* mgr) { +static int tx_audio_sessions_mgr_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_audio_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; int i; @@ -2407,17 +2509,19 @@ static int tx_audio_sessions_mgr_init(struct mtl_main_impl* impl, return 0; } -static struct st_tx_audio_session_impl* tx_audio_sessions_mgr_attach( - struct mtl_sch_impl* sch, struct st30_tx_ops* ops) { - struct st_tx_audio_sessions_mgr* mgr = &sch->tx_a_mgr; +static struct st_tx_audio_session_impl * +tx_audio_sessions_mgr_attach(struct mtl_sch_impl *sch, + struct st30_tx_ops *ops) { + struct st_tx_audio_sessions_mgr *mgr = &sch->tx_a_mgr; int midx = mgr->idx; int ret; - struct st_tx_audio_session_impl* s; + struct st_tx_audio_session_impl *s; int socket = mt_sch_socket_id(sch); /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_TX_AUDIO_SESSIONS; i++) { - if (!tx_audio_session_get_empty(mgr, i)) continue; + if (!tx_audio_session_get_empty(mgr, i)) + continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -2451,8 +2555,8 @@ static struct st_tx_audio_session_impl* tx_audio_sessions_mgr_attach( return NULL; } -static int tx_audio_sessions_mgr_detach(struct st_tx_audio_sessions_mgr* mgr, - struct st_tx_audio_session_impl* s) { +static int tx_audio_sessions_mgr_detach(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -2471,21 +2575,22 @@ static int tx_audio_sessions_mgr_detach(struct st_tx_audio_sessions_mgr* mgr, return 0; } -static int tx_audio_sessions_mgr_update(struct st_tx_audio_sessions_mgr* mgr) { +static int tx_audio_sessions_mgr_update(struct st_tx_audio_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_SCH_MAX_TX_AUDIO_SESSIONS; i++) { - if (mgr->sessions[i]) max_idx = i + 1; + if (mgr->sessions[i]) + max_idx = i + 1; } mgr->max_idx = max_idx; return 0; } -static int tx_audio_sessions_mgr_uinit(struct st_tx_audio_sessions_mgr* mgr) { +static int tx_audio_sessions_mgr_uinit(struct st_tx_audio_sessions_mgr *mgr) { int m_idx = mgr->idx; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_audio_session_impl* s; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_audio_session_impl *s; mt_stat_unregister(mgr->parent, st_tx_audio_sessions_stat, mgr); @@ -2496,7 +2601,8 @@ static int tx_audio_sessions_mgr_uinit(struct st_tx_audio_sessions_mgr* mgr) { for (int i = 0; i < ST_SCH_MAX_TX_AUDIO_SESSIONS; i++) { s = tx_audio_session_get(mgr, i); - if (!s) continue; + if (!s) + continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); tx_audio_sessions_mgr_detach(mgr, s); @@ -2511,9 +2617,9 @@ static int tx_audio_sessions_mgr_uinit(struct st_tx_audio_sessions_mgr* mgr) { return 0; } -static int tx_audio_ops_check(struct st30_tx_ops* ops) { +static int tx_audio_ops_check(struct st30_tx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip = NULL; + uint8_t *ip = NULL; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { err("%s, invalid num_ports %d\n", __func__, num_ports); @@ -2524,14 +2630,16 @@ static int tx_audio_ops_check(struct st30_tx_ops* ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -2568,10 +2676,12 @@ static int tx_audio_ops_check(struct st30_tx_ops* ops) { return 0; } -static int st_tx_audio_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { +static int st_tx_audio_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { int ret; - if (sch->tx_a_init) return 0; + if (sch->tx_a_init) + return 0; /* create tx audio context */ ret = tx_audio_sessions_mgr_init(impl, sch, &sch->tx_a_mgr); @@ -2590,11 +2700,12 @@ static int st_tx_audio_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch return 0; } -int st_audio_queue_fatal_error(struct mtl_main_impl* impl, - struct st_tx_audio_sessions_mgr* mgr, enum mtl_port port) { +int st_audio_queue_fatal_error(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + enum mtl_port port) { int idx = mgr->idx; int ret; - struct st_tx_audio_session_impl* s; + struct st_tx_audio_session_impl *s; if (!mgr->queue[port]) { err("%s(%d,%d), no queue\n", __func__, idx, port); @@ -2602,7 +2713,8 @@ int st_audio_queue_fatal_error(struct mtl_main_impl* impl, } /* clean mbuf in the ring as we will free the mempool then */ - if (mgr->ring[port]) mt_ring_dequeue_clean(mgr->ring[port]); + if (mgr->ring[port]) + mt_ring_dequeue_clean(mgr->ring[port]); /* clean the queue done mbuf */ mt_txq_done_cleanup(mgr->queue[port]); @@ -2610,23 +2722,27 @@ int st_audio_queue_fatal_error(struct mtl_main_impl* impl, mt_txq_put(mgr->queue[port]); mgr->queue[port] = NULL; - /* init all session mempool again as we don't know which session has the bad pkt */ + /* init all session mempool again as we don't know which session has the bad + * pkt */ for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_audio_session_get(mgr, sidx); - if (!s) continue; + if (!s) + continue; /* clear all tx ring buffer */ - if (s->packet_ring) mt_ring_dequeue_clean(s->packet_ring); + if (s->packet_ring) + mt_ring_dequeue_clean(s->packet_ring); for (uint8_t i = 0; i < s->ops.num_port; i++) { - if (s->trans_ring[i]) mt_fifo_mbuf_clean(s->trans_ring[i]); + if (s->trans_ring[i]) + mt_fifo_mbuf_clean(s->trans_ring[i]); } s->recovery_idx++; tx_audio_session_mempool_free(s); ret = tx_audio_session_mempool_init(impl, mgr, s); if (ret < 0) { - err("%s(%d,%d), init mempool fail %d for session %d\n", __func__, idx, port, ret, - sidx); + err("%s(%d,%d), init mempool fail %d for session %d\n", __func__, idx, + port, ret, sidx); s->stat_unrecoverable_error++; s->active = false; /* mark current session to dead */ } else { @@ -2651,8 +2767,9 @@ int st_audio_queue_fatal_error(struct mtl_main_impl* impl, return 0; } -int st_tx_audio_sessions_sch_uinit(struct mtl_sch_impl* sch) { - if (!sch->tx_a_init) return 0; +int st_tx_audio_sessions_sch_uinit(struct mtl_sch_impl *sch) { + if (!sch->tx_a_init) + return 0; /* free tx audio context */ st_audio_transmitter_uinit(&sch->a_trs); @@ -2662,11 +2779,11 @@ int st_tx_audio_sessions_sch_uinit(struct mtl_sch_impl* sch) { return 0; } -st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct st_tx_audio_session_handle_impl* s_impl; - struct st_tx_audio_session_impl* s; - struct mtl_sch_impl* sch; +st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct st_tx_audio_session_handle_impl *s_impl; + struct st_tx_audio_session_impl *s; + struct mtl_sch_impl *sch; int quota_mbs, ret; notice("%s, start for %s\n", __func__, mt_string_safe(ops->name)); @@ -2683,7 +2800,8 @@ st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops* ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30_TX_FLAG_FORCE_NUMA) { @@ -2697,9 +2815,10 @@ st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops* ops) { return NULL; } - quota_mbs = impl->main_sch->data_quota_mbs_limit / impl->tx_audio_sessions_max_per_sch; - sch = - mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); + quota_mbs = impl->main_sch->data_quota_mbs_limit / + impl->tx_audio_sessions_max_per_sch; + sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, + MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -2737,10 +2856,11 @@ st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops* ops) { return s_impl; } -int st30_tx_update_destination(st30_tx_handle handle, struct st_tx_dest_info* dst) { - struct st_tx_audio_session_handle_impl* s_impl = handle; - struct st_tx_audio_session_impl* s; - struct mtl_sch_impl* sch; +int st30_tx_update_destination(st30_tx_handle handle, + struct st_tx_dest_info *dst) { + struct st_tx_audio_session_handle_impl *s_impl = handle; + struct st_tx_audio_session_impl *s; + struct mtl_sch_impl *sch; int idx, ret, sch_idx; if (s_impl->type != MT_HANDLE_TX_AUDIO) { @@ -2754,7 +2874,8 @@ int st30_tx_update_destination(st30_tx_handle handle, struct st_tx_dest_info* ds sch_idx = sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = tx_audio_sessions_mgr_update_dst(&sch->tx_a_mgr, s, dst); if (ret < 0) { @@ -2767,10 +2888,10 @@ int st30_tx_update_destination(st30_tx_handle handle, struct st_tx_dest_info* ds } int st30_tx_free(st30_tx_handle handle) { - struct st_tx_audio_session_handle_impl* s_impl = handle; - struct mtl_sch_impl* sch; - struct mtl_main_impl* impl; - struct st_tx_audio_session_impl* s; + struct st_tx_audio_session_handle_impl *s_impl = handle; + struct mtl_sch_impl *sch; + struct mtl_main_impl *impl; + struct st_tx_audio_session_impl *s; int ret, idx; int sch_idx; @@ -2789,10 +2910,12 @@ int st30_tx_free(st30_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_a_mgr_mutex); ret = tx_audio_sessions_mgr_detach(&sch->tx_a_mgr, s); mt_pthread_mutex_unlock(&sch->tx_a_mgr_mutex); - if (ret < 0) err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -2806,9 +2929,9 @@ int st30_tx_free(st30_tx_handle handle) { return 0; } -void* st30_tx_get_framebuffer(st30_tx_handle handle, uint16_t idx) { - struct st_tx_audio_session_handle_impl* s_impl = handle; - struct st_tx_audio_session_impl* s; +void *st30_tx_get_framebuffer(st30_tx_handle handle, uint16_t idx) { + struct st_tx_audio_session_handle_impl *s_impl = handle; + struct st_tx_audio_session_impl *s; if (s_impl->type != MT_HANDLE_TX_AUDIO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -2827,17 +2950,17 @@ void* st30_tx_get_framebuffer(st30_tx_handle handle, uint16_t idx) { return NULL; } - struct st_frame_trans* frame_info = &s->st30_frames[idx]; + struct st_frame_trans *frame_info = &s->st30_frames[idx]; return frame_info->addr; } -void* st30_tx_get_mbuf(st30_tx_handle handle, void** usrptr) { - struct st_tx_audio_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt; - struct st_tx_audio_session_impl* s; +void *st30_tx_get_mbuf(st30_tx_handle handle, void **usrptr) { + struct st_tx_audio_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt; + struct st_tx_audio_session_impl *s; int idx; - struct rte_ring* packet_ring; + struct rte_ring *packet_ring; if (s_impl->type != MT_HANDLE_TX_AUDIO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -2857,8 +2980,9 @@ void* st30_tx_get_mbuf(st30_tx_handle handle, void** usrptr) { return NULL; } - struct rte_mempool* mp = - s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; + struct rte_mempool *mp = s->tx_no_chain + ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] + : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -2866,16 +2990,16 @@ void* st30_tx_get_mbuf(st30_tx_handle handle, void** usrptr) { } size_t hdr_offset = s->tx_no_chain ? sizeof(struct mt_udp_hdr) : 0; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, hdr_offset); + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, hdr_offset); return pkt; } -int st30_tx_put_mbuf(st30_tx_handle handle, void* mbuf, uint16_t len) { - struct st_tx_audio_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; - struct st_tx_audio_session_impl* s; +int st30_tx_put_mbuf(st30_tx_handle handle, void *mbuf, uint16_t len) { + struct st_tx_audio_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; + struct st_tx_audio_session_impl *s; int idx, ret; - struct rte_ring* packet_ring; + struct rte_ring *packet_ring; if (s_impl->type != MT_HANDLE_TX_AUDIO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -2884,7 +3008,8 @@ int st30_tx_put_mbuf(st30_tx_handle handle, void* mbuf, uint16_t len) { } if (!mt_rtp_len_valid(len)) { - if (len) err("%s, invalid len %d\n", __func__, len); + if (len) + err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -2898,10 +3023,11 @@ int st30_tx_put_mbuf(st30_tx_handle handle, void* mbuf, uint16_t len) { return -EIO; } - if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) + len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; - ret = rte_ring_sp_enqueue(packet_ring, (void*)pkt); + ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); if (ret < 0) { err("%s(%d), can not enqueue to the rte ring\n", __func__, idx); rte_pktmbuf_free(mbuf); diff --git a/lib/src/st2110/st_tx_audio_session.h b/lib/src/st2110/st_tx_audio_session.h index bd3b5b27c..1ebe7599d 100644 --- a/lib/src/st2110/st_tx_audio_session.h +++ b/lib/src/st2110/st_tx_audio_session.h @@ -9,6 +9,6 @@ #define ST_TX_AUDIO_PREFIX "TA_" -int st_tx_audio_sessions_sch_uinit(struct mtl_sch_impl* sch); +int st_tx_audio_sessions_sch_uinit(struct mtl_sch_impl *sch); #endif diff --git a/lib/src/st2110/st_tx_video_session.c b/lib/src/st2110/st_tx_video_session.c index 88442142d..900fabf0a 100644 --- a/lib/src/st2110/st_tx_video_session.c +++ b/lib/src/st2110/st_tx_video_session.c @@ -14,25 +14,27 @@ #include "st_err.h" #include "st_video_transmitter.h" -static inline double pacing_time(struct st_tx_video_pacing* pacing, uint64_t epochs) { +static inline double pacing_time(struct st_tx_video_pacing *pacing, + uint64_t epochs) { return epochs * pacing->frame_time; } -static inline double pacing_first_pkt_time(struct st_tx_video_pacing* pacing, +static inline double pacing_first_pkt_time(struct st_tx_video_pacing *pacing, uint64_t epochs) { - return pacing_time(pacing, epochs) + pacing->tr_offset - (pacing->vrx * pacing->trs); + return pacing_time(pacing, epochs) + pacing->tr_offset - + (pacing->vrx * pacing->trs); } /* pacing start time(warmup pkt if has warmup stage) of the frame */ -static inline double pacing_start_time(struct st_tx_video_pacing* pacing, +static inline double pacing_start_time(struct st_tx_video_pacing *pacing, uint64_t epochs) { return pacing_time(pacing, epochs) + pacing->tr_offset - ((pacing->vrx + pacing->warm_pkts) * pacing->trs); } /* time stamp on the first pkt video pkt(not the warmup) */ -static inline uint32_t pacing_time_stamp(struct st_tx_video_session_impl* s, - struct st_tx_video_pacing* pacing, +static inline uint32_t pacing_time_stamp(struct st_tx_video_session_impl *s, + struct st_tx_video_pacing *pacing, uint64_t epochs) { uint64_t tmstamp64; double time; @@ -42,14 +44,16 @@ static inline uint32_t pacing_time_stamp(struct st_tx_video_session_impl* s, } else if (s->ops.flags & ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT) { /* the start of first pkt */ time = pacing_first_pkt_time(pacing, epochs); - if (pacing->warm_pkts) time -= 3 * pacing->trs; /* deviation for VRX */ + if (pacing->warm_pkts) + time -= 3 * pacing->trs; /* deviation for VRX */ } else if (s->ops.rtp_timestamp_delta_us) { int32_t rtp_timestamp_delta_us = s->ops.rtp_timestamp_delta_us; time = pacing_time(pacing, epochs) + (rtp_timestamp_delta_us * NS_PER_US); } else { /* default to the start of first pkt */ time = pacing_first_pkt_time(pacing, epochs); - if (pacing->warm_pkts) time -= 3 * pacing->trs; /* deviation for VRX */ + if (pacing->warm_pkts) + time -= 3 * pacing->trs; /* deviation for VRX */ } tmstamp64 = (time / pacing->frame_time) * pacing->frame_time_sampling; uint32_t tmstamp32 = tmstamp64; @@ -57,56 +61,63 @@ static inline uint32_t pacing_time_stamp(struct st_tx_video_session_impl* s, return tmstamp32; } -static inline void pacing_set_mbuf_time_stamp(struct rte_mbuf* mbuf, - struct st_tx_video_pacing* pacing) { +static inline void +pacing_set_mbuf_time_stamp(struct rte_mbuf *mbuf, + struct st_tx_video_pacing *pacing) { st_tx_mbuf_set_tsc(mbuf, pacing->tsc_time_cursor); st_tx_mbuf_set_ptp(mbuf, pacing->ptp_time_cursor); } -static inline void pacing_forward_cursor(struct st_tx_video_pacing* pacing) { +static inline void pacing_forward_cursor(struct st_tx_video_pacing *pacing) { /* pkt forward */ pacing->tsc_time_cursor += pacing->trs; pacing->ptp_time_cursor += pacing->trs; } -static inline uint64_t tv_rl_bps(struct st_tx_video_session_impl* s) { +static inline uint64_t tv_rl_bps(struct st_tx_video_session_impl *s) { double reactive = 1.0; if (s->ops.interlaced && s->ops.height <= 576) { reactive = (s->ops.height == 480) ? 487.0 / 525.0 : 576.0 / 625.0; } - return (uint64_t)(s->st20_pkt_size * s->st20_total_pkts * 1.0 * s->fps_tm.mul / - s->fps_tm.den / reactive); + return (uint64_t)(s->st20_pkt_size * s->st20_total_pkts * 1.0 * + s->fps_tm.mul / s->fps_tm.den / reactive); } -static void tv_notify_frame_done(struct st_tx_video_session_impl* s, uint16_t frame_idx) { +static void tv_notify_frame_done(struct st_tx_video_session_impl *s, + uint16_t frame_idx) { uint64_t tsc_start = 0; - struct mtl_main_impl* impl = s->impl; + struct mtl_main_impl *impl = s->impl; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); if (s->st22_info) { - struct st22_tx_frame_meta* tx_st22_meta = &s->st20_frames[frame_idx].tx_st22_meta; + struct st22_tx_frame_meta *tx_st22_meta = + &s->st20_frames[frame_idx].tx_st22_meta; if (s->st22_info->notify_frame_done) s->st22_info->notify_frame_done(s->ops.priv, frame_idx, tx_st22_meta); MT_USDT_ST22_TX_FRAME_DONE(s->mgr->idx, s->idx, frame_idx, tx_st22_meta->rtp_timestamp); } else { - struct st20_tx_frame_meta* tv_meta = &s->st20_frames[frame_idx].tv_meta; + struct st20_tx_frame_meta *tv_meta = &s->st20_frames[frame_idx].tv_meta; if (s->ops.notify_frame_done) s->ops.notify_frame_done(s->ops.priv, frame_idx, tv_meta); - MT_USDT_ST20_TX_FRAME_DONE(s->mgr->idx, s->idx, frame_idx, tv_meta->rtp_timestamp); + MT_USDT_ST20_TX_FRAME_DONE(s->mgr->idx, s->idx, frame_idx, + tv_meta->rtp_timestamp); } if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = + RTE_MAX(s->stat_max_notify_frame_us, delta_us); } } -static void tv_frame_free_cb(void* addr, void* opaque) { - struct st_frame_trans* frame_info = opaque; - struct st_tx_video_session_impl* s = frame_info->priv; +static void tv_frame_free_cb(void *addr, void *opaque) { + struct st_frame_trans *frame_info = opaque; + struct st_tx_video_session_impl *s = frame_info->priv; int s_idx = s->idx, frame_idx = frame_info->idx; - if ((addr < frame_info->addr) || (addr >= (frame_info->addr + s->st20_fb_size))) { + if ((addr < frame_info->addr) || + (addr >= (frame_info->addr + s->st20_fb_size))) { err("%s(%d), addr %p does not belong to frame %d\n", __func__, s_idx, addr, frame_idx); return; @@ -114,8 +125,8 @@ static void tv_frame_free_cb(void* addr, void* opaque) { int refcnt = rte_atomic32_read(&frame_info->refcnt); if (refcnt != 1) { - warn("%s(%d), frame %d err refcnt %d addr %p\n", __func__, s_idx, frame_idx, refcnt, - addr); + warn("%s(%d), frame %d err refcnt %d addr %p\n", __func__, s_idx, frame_idx, + refcnt, addr); return; } @@ -130,58 +141,63 @@ static void tv_frame_free_cb(void* addr, void* opaque) { dbg("%s(%d), succ frame_idx %d\n", __func__, s_idx, frame_idx); } -static rte_iova_t tv_frame_get_offset_iova(struct st_tx_video_session_impl* s, - struct st_frame_trans* frame_info, +static rte_iova_t tv_frame_get_offset_iova(struct st_tx_video_session_impl *s, + struct st_frame_trans *frame_info, size_t offset) { - if (frame_info->page_table_len == 0) return frame_info->iova + offset; - void* addr = RTE_PTR_ADD(frame_info->addr, offset); - struct st_page_info* page; + if (frame_info->page_table_len == 0) + return frame_info->iova + offset; + void *addr = RTE_PTR_ADD(frame_info->addr, offset); + struct st_page_info *page; for (uint16_t i = 0; i < frame_info->page_table_len; i++) { page = &frame_info->page_table[i]; if (addr >= page->addr && addr < RTE_PTR_ADD(page->addr, page->len)) return page->iova + RTE_PTR_DIFF(addr, page->addr); } - err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, frame_info->idx, - offset); + err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, + frame_info->idx, offset); return MTL_BAD_IOVA; } -static int tv_frame_create_page_table(struct st_tx_video_session_impl* s, - struct st_frame_trans* frame_info) { - struct rte_memseg* mseg = rte_mem_virt2memseg(frame_info->addr, NULL); +static int tv_frame_create_page_table(struct st_tx_video_session_impl *s, + struct st_frame_trans *frame_info) { + struct rte_memseg *mseg = rte_mem_virt2memseg(frame_info->addr, NULL); if (mseg == NULL) { err("%s(%d,%d), get mseg fail\n", __func__, s->idx, frame_info->idx); return -EIO; } size_t hugepage_sz = mseg->hugepage_sz; - info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, frame_info->idx, - hugepage_sz); + info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, + frame_info->idx, hugepage_sz); /* calculate num hugepages */ uint16_t num_pages = - RTE_PTR_DIFF(RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), - RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / + RTE_PTR_DIFF( + RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), + RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / hugepage_sz; int soc_id = s->socket_id; - struct st_page_info* pages = mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); + struct st_page_info *pages = + mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); if (pages == NULL) { - err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, frame_info->idx); + err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, + frame_info->idx); return -ENOMEM; } /* get IOVA start of each page */ - void* addr = frame_info->addr; + void *addr = frame_info->addr; for (uint16_t i = 0; i < num_pages; i++) { /* touch the page before getting its IOVA */ - *(volatile char*)addr = 0; + *(volatile char *)addr = 0; pages[i].iova = rte_mem_virt2iova(addr); pages[i].addr = addr; - void* next_addr = RTE_PTR_ALIGN(RTE_PTR_ADD(addr, 1), hugepage_sz); + void *next_addr = RTE_PTR_ALIGN(RTE_PTR_ADD(addr, 1), hugepage_sz); pages[i].len = RTE_PTR_DIFF(next_addr, addr); addr = next_addr; - info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", __func__, - s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, pages[i].len); + info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", + __func__, s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, + pages[i].len); } frame_info->page_table = pages; frame_info->page_table_len = num_pages; @@ -189,23 +205,25 @@ static int tv_frame_create_page_table(struct st_tx_video_session_impl* s, return 0; } -static inline bool tv_frame_payload_cross_page(struct st_tx_video_session_impl* s, - struct st_frame_trans* frame_info, - size_t offset, size_t len) { - if (frame_info->page_table_len == 0) return false; +static inline bool +tv_frame_payload_cross_page(struct st_tx_video_session_impl *s, + struct st_frame_trans *frame_info, size_t offset, + size_t len) { + if (frame_info->page_table_len == 0) + return false; return ((tv_frame_get_offset_iova(s, frame_info, offset + len - 1) - tv_frame_get_offset_iova(s, frame_info, offset)) != len - 1); } -static int tv_alloc_frames(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s) { +static int tv_alloc_frames(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { int soc_id = s->socket_id; int idx = s->idx; - struct st_frame_trans* frame_info; - struct st22_tx_video_info* st22_info = s->st22_info; + struct st_frame_trans *frame_info; + struct st22_tx_video_info *st22_info = s->st22_info; - s->st20_frames = - mt_rte_zmalloc_socket(sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); + s->st20_frames = mt_rte_zmalloc_socket( + sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); if (!s->st20_frames) { err("%s(%d), st20_frames malloc fail\n", __func__, idx); return -ENOMEM; @@ -228,12 +246,13 @@ static int tv_alloc_frames(struct mtl_main_impl* impl, frame_info->iova = 0; frame_info->addr = NULL; frame_info->flags = ST_FT_FLAG_EXT; - info("%s(%d), use external framebuffer, skip allocation\n", __func__, idx); + info("%s(%d), use external framebuffer, skip allocation\n", __func__, + idx); } else { - void* frame = mt_rte_zmalloc_socket(s->st20_fb_size, soc_id); + void *frame = mt_rte_zmalloc_socket(s->st20_fb_size, soc_id); if (!frame) { - err("%s(%d), rte_malloc %" PRIu64 " fail at %d\n", __func__, idx, s->st20_fb_size, - i); + err("%s(%d), rte_malloc %" PRIu64 " fail at %d\n", __func__, idx, + s->st20_fb_size, i); return -ENOMEM; } if (st22_info && s->st22_box_hdr_length) { /* copy boxes */ @@ -263,9 +282,9 @@ static int tv_alloc_frames(struct mtl_main_impl* impl, return 0; } -static int tv_free_frames(struct st_tx_video_session_impl* s) { +static int tv_free_frames(struct st_tx_video_session_impl *s) { if (s->st20_frames) { - struct st_frame_trans* frame; + struct st_frame_trans *frame; for (int i = 0; i < s->st20_frames_cnt; i++) { frame = &s->st20_frames[i]; st_frame_trans_uinit(frame); @@ -279,25 +298,28 @@ static int tv_free_frames(struct st_tx_video_session_impl* s) { return 0; } -static int tv_poll_vsync(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s) { - struct st_vsync_info* vsync = &s->vsync; +static int tv_poll_vsync(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { + struct st_vsync_info *vsync = &s->vsync; uint64_t cur_tsc = mt_get_tsc(impl); if (cur_tsc > vsync->next_epoch_tsc) { uint64_t tsc_delta = cur_tsc - vsync->next_epoch_tsc; - dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, vsync->meta.epoch); + dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, + vsync->meta.epoch); s->ops.notify_event(s->ops.priv, ST_EVENT_VSYNC, &vsync->meta); st_vsync_calculate(impl, vsync); /* set next vsync */ /* check tsc delta for status */ - if (tsc_delta > NS_PER_MS) s->stat_vsync_mismatch++; + if (tsc_delta > NS_PER_MS) + s->stat_vsync_mismatch++; } return 0; } -static int uint64_t_cmp(const void* a, const void* b) { - const uint64_t* ai = a; - const uint64_t* bi = b; +static int uint64_t_cmp(const void *a, const void *b) { + const uint64_t *ai = a; + const uint64_t *bi = b; if (*ai < *bi) { return -1; @@ -307,13 +329,14 @@ static int uint64_t_cmp(const void* a, const void* b) { return 0; } -static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, +static int tv_train_pacing(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct rte_mbuf* pad; + struct rte_mbuf *pad; int idx = s->idx; - struct mt_txq_entry* queue = s->queue[s_port]; + struct mt_txq_entry *queue = s->queue[s_port]; int pad_pkts, ret; int up_trim = 5; int low_trim = up_trim + 1; @@ -341,13 +364,15 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio ret = mt_pacing_train_result_search(impl, port, rl_bps, &pad_interval); if (ret >= 0) { s->pacing.pad_interval = pad_interval; - info("%s(%d), use pre-train pad_interval %f\n", __func__, idx, pad_interval); + info("%s(%d), use pre-train pad_interval %f\n", __func__, idx, + pad_interval); return 0; } /* wait ptp and tsc calibrate done */ ret = mt_ptp_wait_stable(impl, MTL_PORT_P, 60 * 3 * MS_PER_S); - if (ret < 0) return ret; + if (ret < 0) + return ret; mt_wait_tsc_stable(impl); train_start_time = mt_get_tsc(impl); @@ -377,7 +402,8 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio uint32_t offset = s->st20_pkt_len * i; uint16_t line1_number = offset / s->st20_bytes_in_line; /* last pkt should be treated as normal pkt also */ - if ((offset + s->st20_pkt_len) < (line1_number + 1) * s->st20_bytes_in_line) { + if ((offset + s->st20_pkt_len) < + (line1_number + 1) * s->st20_bytes_in_line) { type = ST20_PKT_TYPE_NORMAL; } else { type = ST20_PKT_TYPE_EXTRA; @@ -399,7 +425,8 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio } for (int loop = 0; loop < loop_frame; loop++) { - dbg("%s(%d), frame_time_ns %" PRIu64 "\n", __func__, idx, frame_times_ns[loop]); + dbg("%s(%d), frame_time_ns %" PRIu64 "\n", __func__, idx, + frame_times_ns[loop]); } qsort(frame_times_ns, loop_frame, sizeof(uint64_t), uint64_t_cmp); for (int loop = 0; loop < loop_frame; loop++) { @@ -412,7 +439,8 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio frame_times_ns_sum += frame_times_ns[i]; entry_in_sum++; } - double frame_avg_time_sec = (double)frame_times_ns_sum / entry_in_sum / NS_PER_S; + double frame_avg_time_sec = + (double)frame_times_ns_sum / entry_in_sum / NS_PER_S; double pkts_per_sec = s->st20_total_pkts / frame_avg_time_sec; /* parse the pad interval */ @@ -429,9 +457,11 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio return -EINVAL; } - pad_interval = (float)s->st20_total_pkts / (pkts_per_frame - s->st20_total_pkts); + pad_interval = + (float)s->st20_total_pkts / (pkts_per_frame - s->st20_total_pkts); if (pad_interval < 32) { - err("%s(%d), too small pad_interval %f pkts_per_frame %f, st20_total_pkts %d\n", + err("%s(%d), too small pad_interval %f pkts_per_frame %f, st20_total_pkts " + "%d\n", __func__, idx, pad_interval, pkts_per_frame, s->st20_total_pkts); return -EINVAL; } @@ -439,16 +469,16 @@ static int tv_train_pacing(struct mtl_main_impl* impl, struct st_tx_video_sessio s->pacing.pad_interval = pad_interval; mt_pacing_train_result_add(impl, port, rl_bps, pad_interval); train_end_time = mt_get_tsc(impl); - info("%s(%d,%d), trained pad_interval %f pkts_per_frame %f with time %fs\n", __func__, - idx, s_port, pad_interval, pkts_per_frame, + info("%s(%d,%d), trained pad_interval %f pkts_per_frame %f with time %fs\n", + __func__, idx, s_port, pad_interval, pkts_per_frame, (double)(train_end_time - train_start_time) / NS_PER_S); return 0; } -static int tv_init_pacing(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s) { +static int tv_init_pacing(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { int idx = s->idx; - struct st_tx_video_pacing* pacing = &s->pacing; + struct st_tx_video_pacing *pacing = &s->pacing; double frame_time = (double)1000000000.0 * s->fps_tm.den / s->fps_tm.mul; pacing->frame_time = frame_time; @@ -457,8 +487,8 @@ static int tv_init_pacing(struct mtl_main_impl* impl, pacing->reactive = 1080.0 / 1125.0; /* calculate tr offset */ - pacing->tr_offset = - s->ops.height >= 1080 ? frame_time * (43.0 / 1125.0) : frame_time * (28.0 / 750.0); + pacing->tr_offset = s->ops.height >= 1080 ? frame_time * (43.0 / 1125.0) + : frame_time * (28.0 / 750.0); if (s->ops.interlaced) { if (s->ops.height <= 576) pacing->reactive = (s->ops.height == 480) ? 487.0 / 525.0 : 576.0 / 625.0; @@ -475,11 +505,13 @@ static int tv_init_pacing(struct mtl_main_impl* impl, frame_time - pacing->tr_offset - frame_time * pacing->reactive; dbg("%s[%02d], frame_idle_time %f\n", __func__, idx, pacing->frame_idle_time); if (pacing->frame_idle_time < 0) { - warn("%s[%02d], error frame_idle_time %f\n", __func__, idx, pacing->frame_idle_time); + warn("%s[%02d], error frame_idle_time %f\n", __func__, idx, + pacing->frame_idle_time); pacing->frame_idle_time = 0; } pacing->max_onward_epochs = (double)NS_PER_S / frame_time; /* 1s */ - dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, pacing->max_onward_epochs); + dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, + pacing->max_onward_epochs); /* default VRX compensate as rl accuracy, update later in tv_train_pacing */ pacing->pad_interval = s->st20_total_pkts; @@ -497,9 +529,11 @@ static int tv_init_pacing(struct mtl_main_impl* impl, } if (num_port > 1) { - if (s->pacing_way[MTL_SESSION_PORT_P] != s->pacing_way[MTL_SESSION_PORT_R]) { + if (s->pacing_way[MTL_SESSION_PORT_P] != + s->pacing_way[MTL_SESSION_PORT_R]) { /* currently not support two different pacing? */ - warn("%s(%d), different pacing detected, all set to tsc\n", __func__, idx); + warn("%s(%d), different pacing detected, all set to tsc\n", __func__, + idx); s->pacing_way[MTL_SESSION_PORT_P] = ST21_TX_PACING_WAY_TSC; s->pacing_way[MTL_SESSION_PORT_R] = ST21_TX_PACING_WAY_TSC; } @@ -525,7 +559,8 @@ static int tv_init_pacing(struct mtl_main_impl* impl, pacing->warm_pkts = 8; /* fix me */ pacing->vrx = s->st21_vrx_narrow; } - } else if (s->pacing_way[MTL_SESSION_PORT_P] == ST21_TX_PACING_WAY_TSC_NARROW) { + } else if (s->pacing_way[MTL_SESSION_PORT_P] == + ST21_TX_PACING_WAY_TSC_NARROW) { /* tsc narrow use single bulk for better accuracy */ s->bulk = 1; } else { @@ -539,10 +574,11 @@ static int tv_init_pacing(struct mtl_main_impl* impl, } if (s->ops.start_vrx) { if (s->ops.start_vrx >= pkts_in_tr_offset) { - err("%s[%02d], use start_vrx %u larger than pkts in tr offset %u\n", __func__, idx, - s->ops.start_vrx, pkts_in_tr_offset); + err("%s[%02d], use start_vrx %u larger than pkts in tr offset %u\n", + __func__, idx, s->ops.start_vrx, pkts_in_tr_offset); } else { - info("%s[%02d], use start_vrx %u from user\n", __func__, idx, s->ops.start_vrx); + info("%s[%02d], use start_vrx %u from user\n", __func__, idx, + s->ops.start_vrx); pacing->vrx = s->ops.start_vrx; } } else if (s->ops.pacing == ST21_PACING_WIDE) { @@ -552,31 +588,35 @@ static int tv_init_pacing(struct mtl_main_impl* impl, pacing->warm_pkts = 0; /* no need warmup for wide */ info("%s[%02d], wide pacing\n", __func__, idx); } - info("%s[%02d], trs %f trOffset %f vrx %u warm_pkts %u frame time %fms fps %f\n", - __func__, idx, pacing->trs, pacing->tr_offset, pacing->vrx, pacing->warm_pkts, - pacing->frame_time / NS_PER_MS, st_frame_rate(s->ops.fps)); + info("%s[%02d], trs %f trOffset %f vrx %u warm_pkts %u frame time %fms fps " + "%f\n", + __func__, idx, pacing->trs, pacing->tr_offset, pacing->vrx, + pacing->warm_pkts, pacing->frame_time / NS_PER_MS, + st_frame_rate(s->ops.fps)); /* resolve pacing tasklet */ for (int i = 0; i < num_port; i++) { ret = st_video_resolve_pacing_tasklet(s, i); - if (ret < 0) return ret; + if (ret < 0) + return ret; } return 0; } -static int tv_init_pacing_epoch(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s) { +static int tv_init_pacing_epoch(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); - struct st_tx_video_pacing* pacing = &s->pacing; + struct st_tx_video_pacing *pacing = &s->pacing; pacing->cur_epochs = ptp_time / pacing->frame_time; return 0; } -static int tv_sync_pacing(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, - bool sync, uint64_t required_tai, bool second_field) { +static int tv_sync_pacing(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, bool sync, + uint64_t required_tai, bool second_field) { int idx = s->idx; - struct st_tx_video_pacing* pacing = &s->pacing; + struct st_tx_video_pacing *pacing = &s->pacing; double frame_time = pacing->frame_time; /* always use MTL_PORT_P for ptp now */ uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); @@ -587,14 +627,17 @@ static int tv_sync_pacing(struct mtl_main_impl* impl, struct st_tx_video_session if (required_tai) { uint64_t ptp_epochs = ptp_time / frame_time; epochs = required_tai / frame_time; - dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 " epochs %" PRIu64 "\n", + dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 + " epochs %" PRIu64 "\n", __func__, idx, required_tai, ptp_epochs, epochs); - if (epochs < ptp_epochs) s->stat_error_user_timestamp++; + if (epochs < ptp_epochs) + s->stat_error_user_timestamp++; } else { epochs = ptp_time / frame_time; } - dbg("%s(%d), ptp epochs %" PRIu64 " cur_epochs %" PRIu64 ", ptp_time %" PRIu64 "ms\n", + dbg("%s(%d), ptp epochs %" PRIu64 " cur_epochs %" PRIu64 ", ptp_time %" PRIu64 + "ms\n", __func__, idx, epochs, pacing->cur_epochs, ptp_time / 1000 / 1000); if (epochs <= pacing->cur_epochs) { uint64_t diff = pacing->cur_epochs - epochs; @@ -606,10 +649,12 @@ static int tv_sync_pacing(struct mtl_main_impl* impl, struct st_tx_video_session if (interlaced) { if (second_field) { /* align to odd epoch */ - if (!(epochs & 0x1)) epochs++; + if (!(epochs & 0x1)) + epochs++; s->stat_interlace_second_field++; } else { /* align to even epoch */ - if (epochs & 0x1) epochs++; + if (epochs & 0x1) + epochs++; s->stat_interlace_first_field++; } } @@ -621,7 +666,8 @@ static int tv_sync_pacing(struct mtl_main_impl* impl, struct st_tx_video_session /* time larger than the next assigned epoch time */ dbg("%s(%d), to_epoch %f, ptp epochs %" PRIu64 " cur_epochs %" PRIu64 ", ptp_time %" PRIu64 "ms\n", - __func__, idx, to_epoch, epochs, pacing->cur_epochs, ptp_time / 1000 / 1000); + __func__, idx, to_epoch, epochs, pacing->cur_epochs, + ptp_time / 1000 / 1000); s->stat_epoch_troffset_mismatch++; epochs++; /* assign to next */ start_time_ptp = pacing_start_time(pacing, epochs); @@ -630,25 +676,27 @@ static int tv_sync_pacing(struct mtl_main_impl* impl, struct st_tx_video_session if (to_epoch < 0) { /* should never happen */ - err("%s(%d), error to_epoch %f, ptp_time %" PRIu64 ", epochs %" PRIu64 " %" PRIu64 - "\n", + err("%s(%d), error to_epoch %f, ptp_time %" PRIu64 ", epochs %" PRIu64 + " %" PRIu64 "\n", __func__, idx, to_epoch, ptp_time, epochs, pacing->cur_epochs); to_epoch = 0; } if (epochs > next_epochs) { - dbg("%s(%d), epochs %" PRIu64 " next_epochs %" PRIu64 "\n", __func__, idx, epochs, - next_epochs); + dbg("%s(%d), epochs %" PRIu64 " next_epochs %" PRIu64 "\n", __func__, idx, + epochs, next_epochs); s->stat_epoch_drop += (epochs - next_epochs); } - if (epochs < next_epochs) s->stat_epoch_onward += (next_epochs - epochs); + if (epochs < next_epochs) + s->stat_epoch_onward += (next_epochs - epochs); pacing->cur_epochs = epochs; pacing->cur_epoch_time = pacing_time(pacing, epochs); pacing->rtp_time_stamp = pacing_time_stamp(s, pacing, epochs); dbg("%s(%d), old time_cursor %fms\n", __func__, idx, pacing->tsc_time_cursor / 1000 / 1000); pacing->tsc_time_cursor = (double)mt_get_tsc(impl) + to_epoch; - dbg("%s(%d), epochs %" PRIu64 " time_stamp %u time_cursor %fms to_epoch %fms\n", + dbg("%s(%d), epochs %" PRIu64 + " time_stamp %u time_cursor %fms to_epoch %fms\n", __func__, idx, pacing->cur_epochs, pacing->rtp_time_stamp, pacing->tsc_time_cursor / 1000 / 1000, to_epoch / 1000 / 1000); pacing->ptp_time_cursor = start_time_ptp; @@ -663,28 +711,29 @@ static int tv_sync_pacing(struct mtl_main_impl* impl, struct st_tx_video_session return 0; } -static int tv_sync_pacing_st22(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, bool sync, +static int tv_sync_pacing_st22(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, bool sync, uint64_t required_tai, bool second_field, int pkts_in_frame) { - struct st_tx_video_pacing* pacing = &s->pacing; + struct st_tx_video_pacing *pacing = &s->pacing; /* reset trs */ pacing->trs = pacing->frame_time * pacing->reactive / pkts_in_frame; dbg("%s(%d), trs %f\n", __func__, s->idx, pacing->trs); return tv_sync_pacing(impl, s, sync, required_tai, second_field); } -static int tv_init_next_meta(struct st_tx_video_session_impl* s, - struct st20_tx_frame_meta* meta) { - struct st_tx_video_pacing* pacing = &s->pacing; - struct st20_tx_ops* ops = &s->ops; +static int tv_init_next_meta(struct st_tx_video_session_impl *s, + struct st20_tx_frame_meta *meta) { + struct st_tx_video_pacing *pacing = &s->pacing; + struct st20_tx_ops *ops = &s->ops; memset(meta, 0, sizeof(*meta)); meta->width = ops->width; meta->height = ops->height; meta->fps = ops->fps; meta->fmt = ops->fmt; - if (ops->interlaced) { /* init second_field but user still can customize also */ + if (ops->interlaced) { /* init second_field but user still can customize also + */ meta->second_field = s->second_field; } /* point to next epoch */ @@ -694,17 +743,18 @@ static int tv_init_next_meta(struct st_tx_video_session_impl* s, return 0; } -static int tv_init_st22_next_meta(struct st_tx_video_session_impl* s, - struct st22_tx_frame_meta* meta) { - struct st_tx_video_pacing* pacing = &s->pacing; - struct st20_tx_ops* ops = &s->ops; +static int tv_init_st22_next_meta(struct st_tx_video_session_impl *s, + struct st22_tx_frame_meta *meta) { + struct st_tx_video_pacing *pacing = &s->pacing; + struct st20_tx_ops *ops = &s->ops; memset(meta, 0, sizeof(*meta)); meta->width = ops->width; meta->height = ops->height; meta->fps = ops->fps; meta->codestream_size = s->st22_codestream_size; - if (ops->interlaced) { /* init second_field but user still can customize also */ + if (ops->interlaced) { /* init second_field but user still can customize also + */ meta->second_field = s->second_field; } /* point to next epoch */ @@ -714,9 +764,9 @@ static int tv_init_st22_next_meta(struct st_tx_video_session_impl* s, return 0; } -static int tv_init_st22_boxes(struct st_tx_video_session_impl* s) { - struct st22_tx_video_info* st22_info = s->st22_info; - struct st22_jpvs* jpvs = &st22_info->st22_boxes.jpvs; +static int tv_init_st22_boxes(struct st_tx_video_session_impl *s) { + struct st22_tx_video_info *st22_info = s->st22_info; + struct st22_jpvs *jpvs = &st22_info->st22_boxes.jpvs; uint32_t lbox = sizeof(*jpvs); jpvs->lbox = htonl(lbox); jpvs->tbox[0] = 'j'; @@ -724,7 +774,7 @@ static int tv_init_st22_boxes(struct st_tx_video_session_impl* s) { jpvs->tbox[2] = 'v'; jpvs->tbox[3] = 's'; - struct st22_jpvi* jpvi = &jpvs->jpvi; + struct st22_jpvi *jpvi = &jpvs->jpvi; lbox = sizeof(*jpvi); jpvi->lbox = htonl(lbox); jpvi->tbox[0] = 'j'; @@ -743,7 +793,7 @@ static int tv_init_st22_boxes(struct st_tx_video_session_impl* s) { /* zero now */ jpvi->tcod = htonl(0x0); - struct st22_jxpl* jxpl = &jpvs->jxpl; + struct st22_jxpl *jxpl = &jpvs->jxpl; lbox = sizeof(*jxpl); jxpl->lbox = htonl(lbox); jxpl->tbox[0] = 'j'; @@ -755,7 +805,7 @@ static int tv_init_st22_boxes(struct st_tx_video_session_impl* s) { /* 4k-1 full */ jxpl->plev = htons(0x2080); - struct st22_colr* colr = &st22_info->st22_boxes.colr; + struct st22_colr *colr = &st22_info->st22_boxes.colr; lbox = sizeof(*colr); colr->lbox = htonl(lbox); colr->tbox[0] = 'c'; @@ -772,40 +822,46 @@ static int tv_init_st22_boxes(struct st_tx_video_session_impl* s) { return 0; } -static int tv_init_hdr(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, +static int tv_init_hdr(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); int ret; - struct st_rfc4175_video_hdr* hdr = &s->s_hdr[s_port]; - struct rte_ether_hdr* eth = &hdr->eth; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; - struct st20_rfc4175_rtp_hdr* rtp = &hdr->rtp; - struct st20_tx_ops* ops = &s->ops; - uint8_t* dip = ops->dip_addr[s_port]; - uint8_t* sip = mt_sip_addr(impl, port); - struct rte_ether_addr* d_addr = mt_eth_d_addr(eth); + struct st_rfc4175_video_hdr *hdr = &s->s_hdr[s_port]; + struct rte_ether_hdr *eth = &hdr->eth; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; + struct st20_rfc4175_rtp_hdr *rtp = &hdr->rtp; + struct st20_tx_ops *ops = &s->ops; + uint8_t *dip = ops->dip_addr[s_port]; + uint8_t *sip = mt_sip_addr(impl, port); + struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); /* ether hdr */ - if ((s_port == MTL_SESSION_PORT_P) && (ops->flags & ST20_TX_FLAG_USER_P_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); + if ((s_port == MTL_SESSION_PORT_P) && + (ops->flags & ST20_TX_FLAG_USER_P_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], + RTE_ETHER_ADDR_LEN); info("%s, USER_P_TX_MAC\n", __func__); - } else if ((s_port == MTL_SESSION_PORT_R) && (ops->flags & ST20_TX_FLAG_USER_R_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); + } else if ((s_port == MTL_SESSION_PORT_R) && + (ops->flags & ST20_TX_FLAG_USER_R_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], + RTE_ETHER_ADDR_LEN); info("%s, USER_R_TX_MAC\n", __func__); } else { ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], - dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, + dip[0], dip[1], dip[2], dip[3]); return ret; } } ret = mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); if (ret < 0) { - err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, s_port); + err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, + s_port); return ret; } eth->ether_type = htons(RTE_ETHER_TYPE_IPV4); @@ -843,7 +899,7 @@ static int tv_init_hdr(struct mtl_main_impl* impl, struct st_tx_video_session_im /* st22_rfc9134_rtp_hdr if st22 frame mode */ if (s->st22_info) { - struct st22_rfc9134_rtp_hdr* st22_hdr = &s->st22_info->rtp_hdr[s_port]; + struct st22_rfc9134_rtp_hdr *st22_hdr = &s->st22_info->rtp_hdr[s_port]; /* copy base */ mtl_memcpy(&st22_hdr->base, &rtp->base, sizeof(st22_hdr->base)); st22_hdr->trans_order = 1; /* packets sent sequentially */ @@ -852,15 +908,17 @@ static int tv_init_hdr(struct mtl_main_impl* impl, struct st_tx_video_session_im st22_hdr->f_counter_lo = 0; } - info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], dip[1], - dip[2], dip[3], s->st20_src_port[s_port], s->st20_dst_port[s_port]); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", __func__, idx, - d_addr->addr_bytes[0], d_addr->addr_bytes[1], d_addr->addr_bytes[2], - d_addr->addr_bytes[3], d_addr->addr_bytes[4], d_addr->addr_bytes[5], ssrc); + info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], + dip[1], dip[2], dip[3], s->st20_src_port[s_port], + s->st20_dst_port[s_port]); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", + __func__, idx, d_addr->addr_bytes[0], d_addr->addr_bytes[1], + d_addr->addr_bytes[2], d_addr->addr_bytes[3], d_addr->addr_bytes[4], + d_addr->addr_bytes[5], ssrc); return 0; } -static int tv_uinit_rtcp(struct st_tx_video_session_impl* s) { +static int tv_uinit_rtcp(struct st_tx_video_session_impl *s) { for (int i = 0; i < s->ops.num_port; i++) { if (s->rtcp_tx[i]) { mt_rtcp_tx_free(s->rtcp_tx[i]); @@ -875,11 +933,12 @@ static int tv_uinit_rtcp(struct st_tx_video_session_impl* s) { return 0; } -static int tv_init_rtcp(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s) { +static int tv_init_rtcp(struct mtl_main_impl *impl, + struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s) { int idx = s->idx; int mgr_idx = mgr->idx; - struct st20_tx_ops* ops = &s->ops; + struct st20_tx_ops *ops = &s->ops; int num_port = ops->num_port; struct mt_rxq_flow flow; @@ -889,13 +948,15 @@ static int tv_init_rtcp(struct mtl_main_impl* impl, struct st_tx_video_sessions_ memset(&rtcp_ops, 0, sizeof(rtcp_ops)); rtcp_ops.port = port; char name[MT_RTCP_MAX_NAME_LEN]; - snprintf(name, sizeof(name), ST_TX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, i); + snprintf(name, sizeof(name), ST_TX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, + i); rtcp_ops.name = name; struct mt_udp_hdr hdr; mtl_memcpy(&hdr, &s->s_hdr[i], sizeof(hdr)); hdr.udp.dst_port++; rtcp_ops.udp_hdr = &hdr; - if (!ops->rtcp.buffer_size) ops->rtcp.buffer_size = ST_TX_VIDEO_RTCP_RING_SIZE; + if (!ops->rtcp.buffer_size) + ops->rtcp.buffer_size = ST_TX_VIDEO_RTCP_RING_SIZE; rtcp_ops.buffer_size = ops->rtcp.buffer_size; if (s->st22_info) rtcp_ops.payload_format = MT_RTP_PAYLOAD_FORMAT_RFC9134; @@ -903,7 +964,8 @@ static int tv_init_rtcp(struct mtl_main_impl* impl, struct st_tx_video_sessions_ rtcp_ops.payload_format = MT_RTP_PAYLOAD_FORMAT_RFC4175; s->rtcp_tx[i] = mt_rtcp_tx_create(impl, &rtcp_ops); if (!s->rtcp_tx[i]) { - err("%s(%d,%d), mt_rtcp_tx_create fail on port %d\n", __func__, mgr_idx, idx, i); + err("%s(%d,%d), mt_rtcp_tx_create fail on port %d\n", __func__, mgr_idx, + idx, i); tv_uinit_rtcp(s); return -EIO; } @@ -922,13 +984,13 @@ static int tv_init_rtcp(struct mtl_main_impl* impl, struct st_tx_video_sessions_ return 0; } -static int tv_build_st20_redundant(struct st_tx_video_session_impl* s, - struct rte_mbuf* pkt_r, - const struct rte_mbuf* pkt_base) { - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr*); - struct mt_udp_hdr* hdr_base = rte_pktmbuf_mtod(pkt_base, struct mt_udp_hdr*); - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; +static int tv_build_st20_redundant(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt_r, + const struct rte_mbuf *pkt_base) { + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr *); + struct mt_udp_hdr *hdr_base = rte_pktmbuf_mtod(pkt_base, struct mt_udp_hdr *); + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; /* update the hdr: eth, ip, udp */ rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_R], sizeof(*hdr)); @@ -944,28 +1006,29 @@ static int tv_build_st20_redundant(struct st_tx_video_session_impl* s, /* copy rtp and payload, assume it's only one segment */ size_t hdr_sz = sizeof(*hdr_base); - void* pd_base = rte_pktmbuf_mtod_offset(pkt_base, void*, hdr_sz); - void* pd_r = rte_pktmbuf_mtod_offset(pkt_r, void*, hdr_sz); + void *pd_base = rte_pktmbuf_mtod_offset(pkt_base, void *, hdr_sz); + void *pd_r = rte_pktmbuf_mtod_offset(pkt_r, void *, hdr_sz); size_t pd_len = pkt_base->pkt_len - hdr_sz; rte_memcpy(pd_r, pd_base, pd_len); return 0; } -static int tv_build_st20(struct st_tx_video_session_impl* s, struct rte_mbuf* pkt) { - struct st_rfc4175_video_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st20_rfc4175_rtp_hdr* rtp; - struct st20_rfc4175_extra_rtp_hdr* e_rtp = NULL; - struct st20_tx_ops* ops = &s->ops; +static int tv_build_st20(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt) { + struct st_rfc4175_video_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st20_rfc4175_rtp_hdr *rtp; + struct st20_rfc4175_extra_rtp_hdr *e_rtp = NULL; + struct st20_tx_ops *ops = &s->ops; uint32_t offset; uint16_t line1_number, line1_offset; uint16_t line1_length = 0, line2_length = 0; bool single_line = (ops->packing == ST20_PACKING_GPM_SL); - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; - hdr = rte_pktmbuf_mtod(pkt, struct st_rfc4175_video_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct st_rfc4175_video_hdr *); ipv4 = &hdr->ipv4; rtp = &hdr->rtp; udp = &hdr->udp; @@ -973,7 +1036,8 @@ static int tv_build_st20(struct st_tx_video_session_impl* s, struct rte_mbuf* pk /* copy the basic hdrs: eth, ip, udp, rtp */ rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_P], sizeof(*hdr)); - if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) + udp->src_port += (s->st20_pkt_idx / 128) % 8; /* calculate payload header */ if (single_line) { @@ -985,27 +1049,30 @@ static int tv_build_st20(struct st_tx_video_session_impl* s, struct rte_mbuf* pk } else { offset = s->st20_pkt_len * s->st20_pkt_idx; line1_number = offset / s->st20_bytes_in_line; - line1_offset = - (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; - if ((offset + s->st20_pkt_len > (line1_number + 1) * s->st20_bytes_in_line) && + line1_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / + s->st20_pg.size; + if ((offset + s->st20_pkt_len > + (line1_number + 1) * s->st20_bytes_in_line) && (offset + s->st20_pkt_len < s->st20_frame_size)) - e_rtp = - rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr*, sizeof(*hdr)); + e_rtp = rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr *, + sizeof(*hdr)); } /* update rtp hdr */ - if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) rtp->base.marker = 1; + if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) + rtp->base.marker = 1; rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); rtp->seq_number_ext = htons((uint16_t)(s->st20_seq_id >> 16)); s->st20_seq_id++; - uint16_t field = frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; + uint16_t field = + frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; rtp->row_number = htons(line1_number | field); rtp->row_offset = htons(line1_offset); rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); - uint32_t temp = - single_line ? ((ops->width - line1_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (s->st20_frame_size - offset); + uint32_t temp = single_line ? ((ops->width - line1_offset) / + s->st20_pg.coverage * s->st20_pg.size) + : (s->st20_frame_size - offset); uint16_t left_len = RTE_MIN(s->st20_pkt_len, temp); rtp->row_length = htons(left_len); @@ -1026,7 +1093,7 @@ static int tv_build_st20(struct st_tx_video_session_impl* s, struct rte_mbuf* pk /* update offset with line padding for copying */ offset = offset % s->st20_bytes_in_line + line1_number * s->st20_linesize; /* copy payload */ - void* payload = NULL; + void *payload = NULL; if (e_rtp) payload = &e_rtp[1]; else @@ -1035,12 +1102,14 @@ static int tv_build_st20(struct st_tx_video_session_impl* s, struct rte_mbuf* pk /* cross lines with padding case */ mtl_memcpy(payload, frame_info->addr + offset, line1_length); mtl_memcpy(payload + line1_length, - frame_info->addr + s->st20_linesize * (line1_number + 1), line2_length); + frame_info->addr + s->st20_linesize * (line1_number + 1), + line2_length); } else { mtl_memcpy(payload, frame_info->addr + offset, left_len); } pkt->data_len = sizeof(struct st_rfc4175_video_hdr) + left_len; - if (e_rtp) pkt->data_len += sizeof(*e_rtp); + if (e_rtp) + pkt->data_len += sizeof(*e_rtp); pkt->pkt_len = pkt->data_len; udp->dgram_len = htons(pkt->pkt_len - pkt->l2_len - pkt->l3_len); @@ -1053,21 +1122,22 @@ static int tv_build_st20(struct st_tx_video_session_impl* s, struct rte_mbuf* pk return 0; } -static int tv_build_st20_chain(struct st_tx_video_session_impl* s, struct rte_mbuf* pkt, - struct rte_mbuf* pkt_chain) { - struct st_rfc4175_video_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st20_rfc4175_rtp_hdr* rtp; - struct st20_rfc4175_extra_rtp_hdr* e_rtp = NULL; - struct st20_tx_ops* ops = &s->ops; +static int tv_build_st20_chain(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt, + struct rte_mbuf *pkt_chain) { + struct st_rfc4175_video_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st20_rfc4175_rtp_hdr *rtp; + struct st20_rfc4175_extra_rtp_hdr *e_rtp = NULL; + struct st20_tx_ops *ops = &s->ops; uint32_t offset; uint16_t line1_number, line1_offset; uint16_t line1_length = 0, line2_length = 0; bool single_line = (ops->packing == ST20_PACKING_GPM_SL); - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; - hdr = rte_pktmbuf_mtod(pkt, struct st_rfc4175_video_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct st_rfc4175_video_hdr *); ipv4 = &hdr->ipv4; rtp = &hdr->rtp; udp = &hdr->udp; @@ -1075,7 +1145,8 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl* s, struct rte_mb /* copy the hdr: eth, ip, udp, rtp */ rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_P], sizeof(*hdr)); - if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) + udp->src_port += (s->st20_pkt_idx / 128) % 8; if (single_line) { line1_number = s->st20_pkt_idx / s->st20_pkts_in_line; @@ -1086,27 +1157,30 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl* s, struct rte_mb } else { offset = s->st20_pkt_len * s->st20_pkt_idx; line1_number = offset / s->st20_bytes_in_line; - line1_offset = - (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; - if ((offset + s->st20_pkt_len > (line1_number + 1) * s->st20_bytes_in_line) && + line1_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / + s->st20_pg.size; + if ((offset + s->st20_pkt_len > + (line1_number + 1) * s->st20_bytes_in_line) && (offset + s->st20_pkt_len < s->st20_frame_size)) - e_rtp = - rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr*, sizeof(*hdr)); + e_rtp = rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr *, + sizeof(*hdr)); } /* update rtp */ - if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) rtp->base.marker = 1; + if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) + rtp->base.marker = 1; rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); rtp->seq_number_ext = htons((uint16_t)(s->st20_seq_id >> 16)); s->st20_seq_id++; - uint16_t field = frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; + uint16_t field = + frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; rtp->row_number = htons(line1_number | field); rtp->row_offset = htons(line1_offset); rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); - uint32_t temp = - single_line ? ((ops->width - line1_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (s->st20_frame_size - offset); + uint32_t temp = single_line ? ((ops->width - line1_offset) / + s->st20_pg.coverage * s->st20_pg.size) + : (s->st20_frame_size - offset); uint16_t left_len = RTE_MIN(s->st20_pkt_len, temp); rtp->row_length = htons(left_len); @@ -1123,7 +1197,8 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl* s, struct rte_mb /* update mbuf */ mt_mbuf_init_ipv4(pkt); pkt->data_len = sizeof(struct st_rfc4175_video_hdr); - if (e_rtp) pkt->data_len += sizeof(*e_rtp); + if (e_rtp) + pkt->data_len += sizeof(*e_rtp); pkt->pkt_len = pkt->data_len; if (!single_line && s->st20_linesize > s->st20_bytes_in_line) @@ -1136,24 +1211,26 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl* s, struct rte_mb rte_pktmbuf_free(pkt_chain); pkt_chain = rte_pktmbuf_alloc(s->mbuf_mempool_copy_chain); if (!pkt_chain) { - dbg("%s(%d), pkts chain realloc fail %d\n", __func__, s->idx, s->st20_pkt_idx); + dbg("%s(%d), pkts chain realloc fail %d\n", __func__, s->idx, + s->st20_pkt_idx); s->stat_pkts_chain_realloc_fail++; /* we can do nothing but count */ return -ENOMEM; } /* do not attach extbuf, copy to data room */ - void* payload = rte_pktmbuf_mtod(pkt_chain, void*); + void *payload = rte_pktmbuf_mtod(pkt_chain, void *); mtl_memcpy(payload, frame_info->addr + offset, line1_length); mtl_memcpy(payload + line1_length, - frame_info->addr + s->st20_linesize * (line1_number + 1), line2_length); + frame_info->addr + s->st20_linesize * (line1_number + 1), + line2_length); } else if (tv_frame_payload_cross_page(s, frame_info, offset, left_len)) { /* do not attach extbuf, copy to data room */ - void* payload = rte_pktmbuf_mtod(pkt_chain, void*); + void *payload = rte_pktmbuf_mtod(pkt_chain, void *); mtl_memcpy(payload, frame_info->addr + offset, left_len); } else { /* attach payload to chainbuf */ rte_pktmbuf_attach_extbuf(pkt_chain, frame_info->addr + offset, - tv_frame_get_offset_iova(s, frame_info, offset), left_len, - &frame_info->sh_info); + tv_frame_get_offset_iova(s, frame_info, offset), + left_len, &frame_info->sh_info); rte_mbuf_ext_refcnt_update(&frame_info->sh_info, 1); } pkt_chain->data_len = pkt_chain->pkt_len = left_len; @@ -1171,16 +1248,16 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl* s, struct rte_mb return 0; } -static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl* s, - struct rte_mbuf* pkt_r, - const struct rte_mbuf* pkt_base) { - struct st_rfc4175_video_hdr* hdr; - struct st_rfc4175_video_hdr* hdr_base; - struct rte_ipv4_hdr* ipv4; - struct st20_rfc4175_rtp_hdr* rtp; - struct st20_rfc4175_rtp_hdr* rtp_base; +static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt_r, + const struct rte_mbuf *pkt_base) { + struct st_rfc4175_video_hdr *hdr; + struct st_rfc4175_video_hdr *hdr_base; + struct rte_ipv4_hdr *ipv4; + struct st20_rfc4175_rtp_hdr *rtp; + struct st20_rfc4175_rtp_hdr *rtp_base; - hdr = rte_pktmbuf_mtod(pkt_r, struct st_rfc4175_video_hdr*); + hdr = rte_pktmbuf_mtod(pkt_r, struct st_rfc4175_video_hdr *); ipv4 = &hdr->ipv4; rtp = &hdr->rtp; @@ -1188,14 +1265,15 @@ static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl* s, rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_R], sizeof(*hdr)); /* update rtp */ - hdr_base = rte_pktmbuf_mtod(pkt_base, struct st_rfc4175_video_hdr*); + hdr_base = rte_pktmbuf_mtod(pkt_base, struct st_rfc4175_video_hdr *); rtp_base = &hdr_base->rtp; rte_memcpy(rtp, rtp_base, sizeof(*rtp)); /* copy extra if Continuation */ uint16_t line1_offset = ntohs(rtp->row_offset); if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { - rte_memcpy(&rtp[1], &rtp_base[1], sizeof(struct st20_rfc4175_extra_rtp_hdr)); + rte_memcpy(&rtp[1], &rtp_base[1], + sizeof(struct st20_rfc4175_extra_rtp_hdr)); } /* update mbuf */ @@ -1206,7 +1284,7 @@ static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl* s, pkt_r->ol_flags = pkt_base->ol_flags; pkt_r->nb_segs = 2; /* chain mbuf */ - struct rte_mbuf* pkt_chain = pkt_base->next; + struct rte_mbuf *pkt_chain = pkt_base->next; pkt_r->next = pkt_chain; rte_mbuf_refcnt_update(pkt_chain, 1); @@ -1220,37 +1298,40 @@ static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl* s, return 0; } -static int tv_build_rtp(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, - struct rte_mbuf* pkt) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct st_rfc3550_rtp_hdr* rtp; - struct rte_udp_hdr* udp; +static int tv_build_rtp(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct st_rfc3550_rtp_hdr *rtp; + struct rte_udp_hdr *udp; - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; - rtp = - rte_pktmbuf_mtod_offset(pkt, struct st_rfc3550_rtp_hdr*, sizeof(struct mt_udp_hdr)); + rtp = rte_pktmbuf_mtod_offset(pkt, struct st_rfc3550_rtp_hdr *, + sizeof(struct mt_udp_hdr)); /* copy the hdr: eth, ip, udp */ rte_memcpy(&hdr->eth, &s->s_hdr[MTL_SESSION_PORT_P].eth, sizeof(hdr->eth)); rte_memcpy(ipv4, &s->s_hdr[MTL_SESSION_PORT_P].ipv4, sizeof(hdr->ipv4)); rte_memcpy(udp, &s->s_hdr[MTL_SESSION_PORT_P].udp, sizeof(hdr->udp)); - if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) + udp->src_port += (s->st20_pkt_idx / 128) % 8; if (rtp->tmstamp != s->st20_rtp_time) { /* start of a new frame */ s->st20_pkt_idx = 0; rte_atomic32_inc(&s->stat_frame_cnt); s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (s->ops.num_port > 1) s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (s->ops.num_port > 1) + s->port_user_stats[MTL_SESSION_PORT_R].frames++; s->st20_rtp_time = rtp->tmstamp; bool second_field = false; if (s->ops.interlaced) { - struct st20_rfc4175_rtp_hdr* rfc4175 = rte_pktmbuf_mtod_offset( - pkt, struct st20_rfc4175_rtp_hdr*, sizeof(struct mt_udp_hdr)); + struct st20_rfc4175_rtp_hdr *rfc4175 = rte_pktmbuf_mtod_offset( + pkt, struct st20_rfc4175_rtp_hdr *, sizeof(struct mt_udp_hdr)); uint16_t line1_number = ntohs(rfc4175->row_number); second_field = (line1_number & ST20_SECOND_FIELD) ? true : false; } @@ -1258,7 +1339,8 @@ static int tv_build_rtp(struct mtl_main_impl* impl, struct st_tx_video_session_i if (s->ops.flags & ST20_TX_FLAG_USER_TIMESTAMP) { s->pacing.rtp_time_stamp = ntohl(rtp->tmstamp); } - dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, s->pacing.rtp_time_stamp); + dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, + s->pacing.rtp_time_stamp); } /* update rtp time*/ rtp->tmstamp = htonl(s->pacing.rtp_time_stamp); @@ -1276,37 +1358,40 @@ static int tv_build_rtp(struct mtl_main_impl* impl, struct st_tx_video_session_i return 0; } -static int tv_build_rtp_chain(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, struct rte_mbuf* pkt, - struct rte_mbuf* pkt_chain) { - struct mt_udp_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct st_rfc3550_rtp_hdr* rtp; - struct rte_udp_hdr* udp; +static int tv_build_rtp_chain(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt, + struct rte_mbuf *pkt_chain) { + struct mt_udp_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct st_rfc3550_rtp_hdr *rtp; + struct rte_udp_hdr *udp; - hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; udp = &hdr->udp; - rtp = rte_pktmbuf_mtod(pkt_chain, struct st_rfc3550_rtp_hdr*); + rtp = rte_pktmbuf_mtod(pkt_chain, struct st_rfc3550_rtp_hdr *); /* copy the hdr: eth, ip, udp */ rte_memcpy(&hdr->eth, &s->s_hdr[MTL_SESSION_PORT_P].eth, sizeof(hdr->eth)); rte_memcpy(ipv4, &s->s_hdr[MTL_SESSION_PORT_P].ipv4, sizeof(hdr->ipv4)); rte_memcpy(udp, &s->s_hdr[MTL_SESSION_PORT_P].udp, sizeof(hdr->udp)); - if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) + udp->src_port += (s->st20_pkt_idx / 128) % 8; if (rtp->tmstamp != s->st20_rtp_time) { /* start of a new frame */ s->st20_pkt_idx = 0; rte_atomic32_inc(&s->stat_frame_cnt); s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (s->ops.num_port > 1) s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (s->ops.num_port > 1) + s->port_user_stats[MTL_SESSION_PORT_R].frames++; s->st20_rtp_time = rtp->tmstamp; bool second_field = false; if (s->ops.interlaced) { - struct st20_rfc4175_rtp_hdr* rfc4175 = - rte_pktmbuf_mtod(pkt_chain, struct st20_rfc4175_rtp_hdr*); + struct st20_rfc4175_rtp_hdr *rfc4175 = + rte_pktmbuf_mtod(pkt_chain, struct st20_rfc4175_rtp_hdr *); uint16_t line1_number = ntohs(rfc4175->row_number); second_field = (line1_number & ST20_SECOND_FIELD) ? true : false; } @@ -1314,7 +1399,8 @@ static int tv_build_rtp_chain(struct mtl_main_impl* impl, if (s->ops.flags & ST20_TX_FLAG_USER_TIMESTAMP) { s->pacing.rtp_time_stamp = ntohl(rtp->tmstamp); } - dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, s->pacing.rtp_time_stamp); + dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, + s->pacing.rtp_time_stamp); } /* update rtp time*/ rtp->tmstamp = htonl(s->pacing.rtp_time_stamp); @@ -1336,13 +1422,13 @@ static int tv_build_rtp_chain(struct mtl_main_impl* impl, return 0; } -static int tv_build_rtp_redundant_chain(struct st_tx_video_session_impl* s, - struct rte_mbuf* pkt_r, - struct rte_mbuf* pkt_base) { - struct rte_ipv4_hdr* ipv4; - struct mt_udp_hdr* hdr; +static int tv_build_rtp_redundant_chain(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt_r, + struct rte_mbuf *pkt_base) { + struct rte_ipv4_hdr *ipv4; + struct mt_udp_hdr *hdr; - hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr*); + hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr *); ipv4 = &hdr->ipv4; /* copy the hdr: eth, ip, udp */ @@ -1358,7 +1444,7 @@ static int tv_build_rtp_redundant_chain(struct st_tx_video_session_impl* s, pkt_r->ol_flags = pkt_base->ol_flags; pkt_r->nb_segs = 2; /* chain mbuf */ - struct rte_mbuf* pkt_chain = pkt_base->next; + struct rte_mbuf *pkt_chain = pkt_base->next; pkt_r->next = pkt_chain; rte_mbuf_refcnt_update(pkt_chain, 1); @@ -1372,14 +1458,15 @@ static int tv_build_rtp_redundant_chain(struct st_tx_video_session_impl* s, return 0; } -static int tv_build_st22(struct st_tx_video_session_impl* s, struct rte_mbuf* pkt) { - struct st22_rfc9134_video_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st22_rfc9134_rtp_hdr* rtp; - struct st22_tx_video_info* st22_info = s->st22_info; +static int tv_build_st22(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt) { + struct st22_rfc9134_video_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st22_rfc9134_rtp_hdr *rtp; + struct st22_tx_video_info *st22_info = s->st22_info; - hdr = rte_pktmbuf_mtod(pkt, struct st22_rfc9134_video_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct st22_rfc9134_video_hdr *); ipv4 = &hdr->ipv4; rtp = &hdr->rtp; udp = &hdr->udp; @@ -1395,8 +1482,8 @@ static int tv_build_st22(struct st_tx_video_session_impl* s, struct rte_mbuf* pk if (s->st20_pkt_idx >= (st22_info->st22_total_pkts - 1)) { rtp->base.marker = 1; rtp->last_packet = 1; - dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, s->st20_pkt_idx, - s->st22_total_pkts); + dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, + s->st20_pkt_idx, s->st22_total_pkts); } rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); s->st20_seq_id++; @@ -1412,7 +1499,7 @@ static int tv_build_st22(struct st_tx_video_session_impl* s, struct rte_mbuf* pk rtp->f_counter_hi = f_counter >> 2; if (s->ops.interlaced) { - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; if (frame_info->tx_st22_meta.second_field) rtp->interlaced = 0x3; else @@ -1423,13 +1510,14 @@ static int tv_build_st22(struct st_tx_video_session_impl* s, struct rte_mbuf* pk mt_mbuf_init_ipv4(pkt); uint32_t offset = s->st20_pkt_idx * s->st20_pkt_len; - uint16_t left_len = RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); + uint16_t left_len = + RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); dbg("%s(%d), data len %u on pkt %d(total %d)\n", __func__, s->idx, left_len, s->st20_pkt_idx, s->st22_total_pkts); /* copy payload */ - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; - void* payload = &rtp[1]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; + void *payload = &rtp[1]; mtl_memcpy(payload, frame_info->addr + offset, left_len); pkt->data_len = sizeof(*hdr) + left_len; @@ -1445,15 +1533,16 @@ static int tv_build_st22(struct st_tx_video_session_impl* s, struct rte_mbuf* pk return 0; } -static int tv_build_st22_chain(struct st_tx_video_session_impl* s, struct rte_mbuf* pkt, - struct rte_mbuf* pkt_chain) { - struct st22_rfc9134_video_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct rte_udp_hdr* udp; - struct st22_rfc9134_rtp_hdr* rtp; - struct st22_tx_video_info* st22_info = s->st22_info; +static int tv_build_st22_chain(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt, + struct rte_mbuf *pkt_chain) { + struct st22_rfc9134_video_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct rte_udp_hdr *udp; + struct st22_rfc9134_rtp_hdr *rtp; + struct st22_tx_video_info *st22_info = s->st22_info; - hdr = rte_pktmbuf_mtod(pkt, struct st22_rfc9134_video_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct st22_rfc9134_video_hdr *); ipv4 = &hdr->ipv4; rtp = &hdr->rtp; udp = &hdr->udp; @@ -1469,8 +1558,8 @@ static int tv_build_st22_chain(struct st_tx_video_session_impl* s, struct rte_mb if (s->st20_pkt_idx >= (st22_info->st22_total_pkts - 1)) { rtp->base.marker = 1; rtp->last_packet = 1; - dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, s->st20_pkt_idx, - s->st22_total_pkts); + dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, + s->st20_pkt_idx, s->st22_total_pkts); } rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); s->st20_seq_id++; @@ -1486,7 +1575,7 @@ static int tv_build_st22_chain(struct st_tx_video_session_impl* s, struct rte_mb rtp->f_counter_hi = f_counter >> 2; if (s->ops.interlaced) { - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; if (frame_info->tx_st22_meta.second_field) rtp->interlaced = 0x3; else @@ -1499,20 +1588,21 @@ static int tv_build_st22_chain(struct st_tx_video_session_impl* s, struct rte_mb pkt->pkt_len = pkt->data_len; uint32_t offset = s->st20_pkt_idx * s->st20_pkt_len; - uint16_t left_len = RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); + uint16_t left_len = + RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); dbg("%s(%d), data len %u on pkt %d(total %d)\n", __func__, s->idx, left_len, s->st20_pkt_idx, s->st22_total_pkts); /* attach payload to chainbuf */ - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; if (tv_frame_payload_cross_page(s, frame_info, offset, left_len)) { /* do not attach extbuf, copy to data room */ - void* payload = rte_pktmbuf_mtod(pkt_chain, void*); + void *payload = rte_pktmbuf_mtod(pkt_chain, void *); mtl_memcpy(payload, frame_info->addr + offset, left_len); } else { /* attach payload */ rte_pktmbuf_attach_extbuf(pkt_chain, frame_info->addr + offset, - tv_frame_get_offset_iova(s, frame_info, offset), left_len, - &frame_info->sh_info); + tv_frame_get_offset_iova(s, frame_info, offset), + left_len, &frame_info->sh_info); rte_mbuf_ext_refcnt_update(&frame_info->sh_info, 1); } @@ -1531,16 +1621,16 @@ static int tv_build_st22_chain(struct st_tx_video_session_impl* s, struct rte_mb return 0; } -static int tv_build_st22_redundant_chain(struct st_tx_video_session_impl* s, - struct rte_mbuf* pkt_r, - struct rte_mbuf* pkt_base) { - struct st22_rfc9134_video_hdr* hdr; - struct st22_rfc9134_video_hdr* hdr_base; - struct rte_ipv4_hdr* ipv4; - struct st22_rfc9134_rtp_hdr* rtp; - struct st22_rfc9134_rtp_hdr* rtp_base; +static int tv_build_st22_redundant_chain(struct st_tx_video_session_impl *s, + struct rte_mbuf *pkt_r, + struct rte_mbuf *pkt_base) { + struct st22_rfc9134_video_hdr *hdr; + struct st22_rfc9134_video_hdr *hdr_base; + struct rte_ipv4_hdr *ipv4; + struct st22_rfc9134_rtp_hdr *rtp; + struct st22_rfc9134_rtp_hdr *rtp_base; - hdr = rte_pktmbuf_mtod(pkt_r, struct st22_rfc9134_video_hdr*); + hdr = rte_pktmbuf_mtod(pkt_r, struct st22_rfc9134_video_hdr *); ipv4 = &hdr->ipv4; rtp = &hdr->rtp; @@ -1548,7 +1638,7 @@ static int tv_build_st22_redundant_chain(struct st_tx_video_session_impl* s, rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_R], sizeof(*hdr)); /* update rtp */ - hdr_base = rte_pktmbuf_mtod(pkt_base, struct st22_rfc9134_video_hdr*); + hdr_base = rte_pktmbuf_mtod(pkt_base, struct st22_rfc9134_video_hdr *); rtp_base = &hdr_base->rtp; rte_memcpy(rtp, rtp_base, sizeof(*rtp)); @@ -1560,7 +1650,7 @@ static int tv_build_st22_redundant_chain(struct st_tx_video_session_impl* s, pkt_r->ol_flags = pkt_base->ol_flags; pkt_r->nb_segs = 2; /* chain mbuf */ - struct rte_mbuf* pkt_chain = pkt_base->next; + struct rte_mbuf *pkt_chain = pkt_base->next; pkt_r->next = pkt_chain; rte_mbuf_refcnt_update(pkt_chain, 1); @@ -1574,16 +1664,20 @@ static int tv_build_st22_redundant_chain(struct st_tx_video_session_impl* s, return 0; } -static uint64_t tv_pacing_required_tai(struct st_tx_video_session_impl* s, - enum st10_timestamp_fmt tfmt, uint64_t timestamp) { +static uint64_t tv_pacing_required_tai(struct st_tx_video_session_impl *s, + enum st10_timestamp_fmt tfmt, + uint64_t timestamp) { uint64_t required_tai = 0; - if (!(s->ops.flags & ST20_TX_FLAG_USER_PACING)) return 0; - if (!timestamp) return 0; + if (!(s->ops.flags & ST20_TX_FLAG_USER_PACING)) + return 0; + if (!timestamp) + return 0; if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (timestamp > 0xFFFFFFFF) { - err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, timestamp); + err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, + timestamp); } required_tai = st10_media_clk_to_ns((uint32_t)timestamp, 90 * 1000); } else { @@ -1593,16 +1687,18 @@ static uint64_t tv_pacing_required_tai(struct st_tx_video_session_impl* s, return required_tai; } -static int tv_tasklet_start(void* priv) { - struct st_tx_video_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_video_session_impl* s; +static int tv_tasklet_start(void *priv) { + struct st_tx_video_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_video_session_impl *s; for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_video_session_get(mgr, sidx); - if (!s) continue; + if (!s) + continue; /* re-calculate the vsync */ - if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) st_vsync_calculate(impl, &s->vsync); + if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) + st_vsync_calculate(impl, &s->vsync); for (int i = 0; i < s->ops.num_port; i++) { s->last_burst_succ_time_tsc[i] = mt_get_tsc(impl); } @@ -1614,19 +1710,19 @@ static int tv_tasklet_start(void* priv) { return 0; } -static int tv_usdt_dump_frame(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, - struct st_frame_trans* frame) { - struct st_tx_video_sessions_mgr* mgr = s->mgr; +static int tv_usdt_dump_frame(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + struct st_frame_trans *frame) { + struct st_tx_video_sessions_mgr *mgr = s->mgr; int idx = s->idx; int fd; char usdt_dump_path[64]; - struct st20_tx_ops* ops = &s->ops; + struct st20_tx_ops *ops = &s->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20tx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, ops->width, - ops->height); + "imtl_usdt_st20tx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, + ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -1638,7 +1734,8 @@ static int tv_usdt_dump_frame(struct mtl_main_impl* impl, if (n != s->st20_frame_size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST20_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); + MT_USDT_ST20_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, + n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -1647,20 +1744,20 @@ static int tv_usdt_dump_frame(struct mtl_main_impl* impl, return 0; } -static int tv_tasklet_frame(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s) { +static int tv_tasklet_frame(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { unsigned int bulk = s->bulk; unsigned int n; int idx = s->idx; - struct st20_tx_ops* ops = &s->ops; - struct st_tx_video_pacing* pacing = &s->pacing; + struct st20_tx_ops *ops = &s->ops; + struct st_tx_video_pacing *pacing = &s->pacing; int ret; bool send_r = false; - struct rte_mempool* hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; - struct rte_mempool* hdr_pool_r = NULL; - struct rte_mempool* chain_pool = s->mbuf_mempool_chain; - struct rte_ring* ring_p = s->ring[MTL_SESSION_PORT_P]; - struct rte_ring* ring_r = NULL; + struct rte_mempool *hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; + struct rte_mempool *hdr_pool_r = NULL; + struct rte_mempool *chain_pool = s->mbuf_mempool_chain; + struct rte_ring *ring_p = s->ring[MTL_SESSION_PORT_P]; + struct rte_ring *ring_r = NULL; int num_port = ops->num_port; if (rte_ring_full(ring_p)) { @@ -1676,8 +1773,8 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, /* check if any inflight pkts */ if (s->inflight[MTL_SESSION_PORT_P][0]) { - n = rte_ring_sp_enqueue_bulk(ring_p, (void**)&s->inflight[MTL_SESSION_PORT_P][0], - bulk, NULL); + n = rte_ring_sp_enqueue_bulk( + ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_P][0] = NULL; } else { @@ -1686,8 +1783,8 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, } } if (send_r && s->inflight[MTL_SESSION_PORT_R][0]) { - n = rte_ring_sp_enqueue_bulk(ring_r, (void**)&s->inflight[MTL_SESSION_PORT_R][0], - bulk, NULL); + n = rte_ring_sp_enqueue_bulk( + ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_R][0] = NULL; } else { @@ -1705,11 +1802,13 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, tv_init_next_meta(s, &meta); /* Query next frame buffer idx */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); ret = ops->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_next_frame_us = RTE_MAX(s->stat_max_next_frame_us, delta_us); + s->stat_max_next_frame_us = + RTE_MAX(s->stat_max_next_frame_us, delta_us); } if (ret < 0) { /* no frame ready from app */ if (s->stat_user_busy_first) { @@ -1721,11 +1820,11 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, return MTL_TASKLET_ALL_DONE; } /* check frame refcnt */ - struct st_frame_trans* frame = &s->st20_frames[next_frame_idx]; + struct st_frame_trans *frame = &s->st20_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, - refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, + next_frame_idx, refcnt); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -1734,8 +1833,8 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, frame->user_meta_data_size = 0; if (meta.user_meta) { if (meta.user_meta_size > frame->user_meta_buffer_size) { - err("%s(%d), frame %u user meta size %" PRId64 " too large\n", __func__, idx, - next_frame_idx, meta.user_meta_size); + err("%s(%d), frame %u user meta size %" PRId64 " too large\n", + __func__, idx, next_frame_idx, meta.user_meta_size); s->stat_build_ret_code = -STI_FRAME_APP_ERR_USER_META; return MTL_TASKLET_ALL_DONE; } @@ -1754,12 +1853,14 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, s->st20_frame_stat = ST21_TX_STAT_SENDING_PKTS; /* user timestamp control if any */ - uint64_t required_tai = tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); + uint64_t required_tai = + tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); bool second_field = frame->tv_meta.second_field; tv_sync_pacing(impl, s, false, required_tai, second_field); if (ops->flags & ST20_TX_FLAG_USER_TIMESTAMP && (frame->tv_meta.tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK)) { - pacing->rtp_time_stamp = st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); + pacing->rtp_time_stamp = + st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); } dbg("%s(%d), rtp time stamp %u\n", __func__, idx, pacing->rtp_time_stamp); frame->tv_meta.tfmt = ST10_TIMESTAMP_FMT_TAI; @@ -1770,8 +1871,8 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, if (ops->interlaced) { s->second_field = second_field ? false : true; } - MT_USDT_ST20_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, frame->addr, - pacing->rtp_time_stamp); + MT_USDT_ST20_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, + frame->addr, pacing->rtp_time_stamp); /* check if dump USDT enabled */ if (MT_USDT_ST20_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -1793,17 +1894,20 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, uint32_t offset = s->st20_pkt_len * (s->st20_pkt_idx + bulk); line_number = offset / s->st20_bytes_in_line + 1; } - if (line_number >= ops->height) line_number = ops->height - 1; + if (line_number >= ops->height) + line_number = ops->height - 1; if (line_number >= s->st20_frame_lines_ready) { struct st20_tx_slice_meta slice_meta; memset(&slice_meta, 0, sizeof(slice_meta)); - ret = ops->query_frame_lines_ready(ops->priv, s->st20_frame_idx, &slice_meta); - if (ret >= 0) s->st20_frame_lines_ready = slice_meta.lines_ready; - dbg("%s(%d), need line %u, ready lines %u\n", __func__, s->idx, ops->height, - s->st20_frame_lines_ready); + ret = ops->query_frame_lines_ready(ops->priv, s->st20_frame_idx, + &slice_meta); + if (ret >= 0) + s->st20_frame_lines_ready = slice_meta.lines_ready; + dbg("%s(%d), need line %u, ready lines %u\n", __func__, s->idx, + ops->height, s->st20_frame_lines_ready); if ((ret < 0) || (line_number >= s->st20_frame_lines_ready)) { - dbg("%s(%d), line %u not ready, ready lines %u\n", __func__, s->idx, line_number, - s->st20_frame_lines_ready); + dbg("%s(%d), line %u not ready, ready lines %u\n", __func__, s->idx, + line_number, s->st20_frame_lines_ready); s->stat_lines_not_ready++; s->stat_build_ret_code = -STI_FRAME_APP_SLICE_NOT_READY; return MTL_TASKLET_ALL_DONE; @@ -1811,9 +1915,9 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, } } - struct rte_mbuf* pkts[bulk]; - struct rte_mbuf* pkts_r[bulk]; - struct rte_mbuf* pkts_chain[bulk]; + struct rte_mbuf *pkts[bulk]; + struct rte_mbuf *pkts_r[bulk]; + struct rte_mbuf *pkts_chain[bulk]; ret = rte_pktmbuf_alloc_bulk(hdr_pool_p, pkts, bulk); if (ret < 0) { @@ -1837,7 +1941,8 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, if (ret < 0) { dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret); rte_pktmbuf_free_bulk(pkts, bulk); - if (!s->tx_no_chain) rte_pktmbuf_free_bulk(pkts_chain, bulk); + if (!s->tx_no_chain) + rte_pktmbuf_free_bulk(pkts_chain, bulk); s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL; return MTL_TASKLET_ALL_DONE; } @@ -1847,7 +1952,8 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, st_tx_mbuf_set_priv(pkts[i], &s->st20_frames[s->st20_frame_idx]); if (s->st20_pkt_idx >= s->st20_total_pkts) { s->stat_pkts_dummy++; - if (!s->tx_no_chain) rte_pktmbuf_free(pkts_chain[i]); + if (!s->tx_no_chain) + rte_pktmbuf_free(pkts_chain[i]); st_tx_mbuf_set_idx(pkts[i], ST_TX_DUMMY_PKT_IDX); } else { if (s->tx_no_chain) @@ -1881,15 +1987,16 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, } bool done = false; - n = rte_ring_sp_enqueue_bulk(ring_p, (void**)&pkts[0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&pkts[0], bulk, NULL); if (n == 0) { - for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; + for (unsigned int i = 0; i < bulk; i++) + s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; s->inflight_cnt[MTL_SESSION_PORT_P]++; s->stat_build_ret_code = -STI_FRAME_PKT_ENQUEUE_FAIL; done = true; } if (send_r) { - n = rte_ring_sp_enqueue_bulk(ring_r, (void**)&pkts_r[0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_r, (void **)&pkts_r[0], bulk, NULL); if (n == 0) { for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_R][i] = pkts_r[i]; @@ -1900,17 +2007,18 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, } if (s->st20_pkt_idx >= s->st20_total_pkts) { - dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, s->st20_frame_idx, - s->st20_pkt_idx); + dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, + s->st20_frame_idx, s->st20_pkt_idx); /* end of current frame */ s->st20_frame_stat = ST21_TX_STAT_WAIT_FRAME; s->st20_pkt_idx = 0; s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (send_r) s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (send_r) + s->port_user_stats[MTL_SESSION_PORT_R].frames++; rte_atomic32_inc(&s->stat_frame_cnt); if (s->tx_no_chain) { /* trigger extbuf free cb since mbuf attach not used */ - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; tv_frame_free_cb(frame_info->addr, frame_info); } @@ -1918,7 +2026,8 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; rte_atomic32_inc(&s->cbs_build_timeout); - dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, s->st20_frame_idx, + dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, + s->st20_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } /* point to tsc time of next epoch */ @@ -1928,20 +2037,21 @@ static int tv_tasklet_frame(struct mtl_main_impl* impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tv_tasklet_rtcp(struct st_tx_video_session_impl* s) { - struct rte_mbuf* mbuf[ST_TX_VIDEO_RTCP_BURST_SIZE]; +static int tv_tasklet_rtcp(struct st_tx_video_session_impl *s) { + struct rte_mbuf *mbuf[ST_TX_VIDEO_RTCP_BURST_SIZE]; uint16_t rv; int num_port = s->ops.num_port; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rtcp_q[s_port]) continue; + if (!s->rtcp_q[s_port]) + continue; rv = mt_rxq_burst(s->rtcp_q[s_port], &mbuf[0], ST_TX_VIDEO_RTCP_BURST_SIZE); if (rv) { for (uint16_t i = 0; i < rv; i++) { // rte_pktmbuf_dump(stdout, mbuf[i], mbuf[i]->pkt_len); - struct mt_rtcp_hdr* rtcp = rte_pktmbuf_mtod_offset(mbuf[i], struct mt_rtcp_hdr*, - sizeof(struct mt_udp_hdr)); + struct mt_rtcp_hdr *rtcp = rte_pktmbuf_mtod_offset( + mbuf[i], struct mt_rtcp_hdr *, sizeof(struct mt_udp_hdr)); mt_rtcp_tx_parse_rtcp_packet(s->rtcp_tx[s_port], rtcp); } rte_pktmbuf_free_bulk(&mbuf[0], rv); @@ -1951,20 +2061,20 @@ static int tv_tasklet_rtcp(struct st_tx_video_session_impl* s) { return 0; } -static int tv_tasklet_rtp(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s) { +static int tv_tasklet_rtp(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { unsigned int bulk = s->bulk; unsigned int n; #ifdef DEBUG int idx = s->idx; #endif - struct st_tx_video_pacing* pacing = &s->pacing; + struct st_tx_video_pacing *pacing = &s->pacing; int ret; bool send_r = false; - struct rte_mempool* hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; - struct rte_mempool* hdr_pool_r = NULL; - struct rte_ring* ring_p = s->ring[MTL_SESSION_PORT_P]; - struct rte_ring* ring_r = NULL; + struct rte_mempool *hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; + struct rte_mempool *hdr_pool_r = NULL; + struct rte_ring *ring_p = s->ring[MTL_SESSION_PORT_P]; + struct rte_ring *ring_r = NULL; if (rte_ring_full(ring_p)) { s->stat_build_ret_code = -STI_RTP_RING_FULL; @@ -1979,8 +2089,8 @@ static int tv_tasklet_rtp(struct mtl_main_impl* impl, /* check if any inflight pkts */ if (s->inflight[MTL_SESSION_PORT_P][0]) { - n = rte_ring_sp_enqueue_bulk(ring_p, (void**)&s->inflight[MTL_SESSION_PORT_P][0], - bulk, NULL); + n = rte_ring_sp_enqueue_bulk( + ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_P][0] = NULL; } else { @@ -1989,8 +2099,8 @@ static int tv_tasklet_rtp(struct mtl_main_impl* impl, } } if (send_r && s->inflight[MTL_SESSION_PORT_R][0]) { - n = rte_ring_sp_enqueue_bulk(ring_r, (void**)&s->inflight[MTL_SESSION_PORT_R][0], - bulk, NULL); + n = rte_ring_sp_enqueue_bulk( + ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_R][0] = false; } else { @@ -1999,17 +2109,19 @@ static int tv_tasklet_rtp(struct mtl_main_impl* impl, } } - struct rte_mbuf* pkts[bulk]; - struct rte_mbuf* pkts_r[bulk]; - struct rte_mbuf* pkts_rtp[bulk]; + struct rte_mbuf *pkts[bulk]; + struct rte_mbuf *pkts_r[bulk]; + struct rte_mbuf *pkts_rtp[bulk]; int pkts_remaining = s->st20_total_pkts - s->st20_pkt_idx; bool eof = (pkts_remaining > 0) && (pkts_remaining < bulk) ? true : false; unsigned int pkts_bulk = eof ? 1 : bulk; /* bulk one only at end of frame */ if (eof) - dbg("%s(%d), pkts_bulk %d pkt idx %d\n", __func__, idx, pkts_bulk, s->st20_pkt_idx); + dbg("%s(%d), pkts_bulk %d pkt idx %d\n", __func__, idx, pkts_bulk, + s->st20_pkt_idx); - n = mt_rte_ring_sc_dequeue_bulk(s->packet_ring, (void**)&pkts_rtp, pkts_bulk, NULL); + n = mt_rte_ring_sc_dequeue_bulk(s->packet_ring, (void **)&pkts_rtp, pkts_bulk, + NULL); if (n == 0) { if (s->stat_user_busy_first) { s->stat_user_busy++; @@ -2093,15 +2205,16 @@ static int tv_tasklet_rtp(struct mtl_main_impl* impl, } bool done = false; - n = rte_ring_sp_enqueue_bulk(ring_p, (void**)&pkts[0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&pkts[0], bulk, NULL); if (n == 0) { - for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; + for (unsigned int i = 0; i < bulk; i++) + s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; s->inflight_cnt[MTL_SESSION_PORT_P]++; s->stat_build_ret_code = -STI_RTP_PKT_ENQUEUE_FAIL; done = true; } if (send_r) { - n = rte_ring_sp_enqueue_bulk(ring_r, (void**)&pkts_r[0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_r, (void **)&pkts_r[0], bulk, NULL); if (n == 0) { for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_R][i] = pkts_r[i]; @@ -2114,19 +2227,20 @@ static int tv_tasklet_rtp(struct mtl_main_impl* impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tv_st22_usdt_dump_codestream(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, - struct st_frame_trans* frame, size_t size) { - struct st_tx_video_sessions_mgr* mgr = s->mgr; +static int tv_st22_usdt_dump_codestream(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + struct st_frame_trans *frame, + size_t size) { + struct st_tx_video_sessions_mgr *mgr = s->mgr; int idx = s->idx; int fd; char usdt_dump_path[64]; - struct st20_tx_ops* ops = &s->ops; + struct st20_tx_ops *ops = &s->ops; uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22tx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, ops->width, - ops->height); + "imtl_usdt_st22tx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, + ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".raw")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -2138,7 +2252,8 @@ static int tv_st22_usdt_dump_codestream(struct mtl_main_impl* impl, if (n != size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST22_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); + MT_USDT_ST22_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, + n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -2147,21 +2262,21 @@ static int tv_st22_usdt_dump_codestream(struct mtl_main_impl* impl, return 0; } -static int tv_tasklet_st22(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s) { +static int tv_tasklet_st22(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { unsigned int bulk = s->bulk; unsigned int n; int idx = s->idx; - struct st20_tx_ops* ops = &s->ops; - struct st22_tx_video_info* st22_info = s->st22_info; - struct st_tx_video_pacing* pacing = &s->pacing; + struct st20_tx_ops *ops = &s->ops; + struct st22_tx_video_info *st22_info = s->st22_info; + struct st_tx_video_pacing *pacing = &s->pacing; int ret; bool send_r = false; - struct rte_mempool* hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; - struct rte_mempool* hdr_pool_r = NULL; - struct rte_mempool* chain_pool = s->mbuf_mempool_chain; - struct rte_ring* ring_p = s->ring[MTL_SESSION_PORT_P]; - struct rte_ring* ring_r = NULL; + struct rte_mempool *hdr_pool_p = s->mbuf_mempool_hdr[MTL_SESSION_PORT_P]; + struct rte_mempool *hdr_pool_r = NULL; + struct rte_mempool *chain_pool = s->mbuf_mempool_chain; + struct rte_ring *ring_p = s->ring[MTL_SESSION_PORT_P]; + struct rte_ring *ring_r = NULL; if (rte_ring_full(ring_p)) { s->stat_build_ret_code = -STI_ST22_RING_FULL; @@ -2176,8 +2291,8 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, /* check if any inflight pkts */ if (s->inflight[MTL_SESSION_PORT_P][0]) { - n = rte_ring_sp_enqueue_bulk(ring_p, (void**)&s->inflight[MTL_SESSION_PORT_P][0], - bulk, NULL); + n = rte_ring_sp_enqueue_bulk( + ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_P][0] = NULL; } else { @@ -2186,8 +2301,8 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, } } if (send_r && s->inflight[MTL_SESSION_PORT_R][0]) { - n = rte_ring_sp_enqueue_bulk(ring_r, (void**)&s->inflight[MTL_SESSION_PORT_R][0], - bulk, NULL); + n = rte_ring_sp_enqueue_bulk( + ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_R][0] = NULL; } else { @@ -2205,11 +2320,13 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, tv_init_st22_next_meta(s, &meta); /* Query next frame buffer idx */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) tsc_start = mt_get_tsc(impl); + if (time_measure) + tsc_start = mt_get_tsc(impl); ret = st22_info->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_next_frame_us = RTE_MAX(s->stat_max_next_frame_us, delta_us); + s->stat_max_next_frame_us = + RTE_MAX(s->stat_max_next_frame_us, delta_us); } if (ret < 0) { /* no frame ready from app */ if (s->stat_user_busy_first) { @@ -2221,18 +2338,19 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, return MTL_TASKLET_ALL_DONE; } /* check frame refcnt */ - struct st_frame_trans* frame = &s->st20_frames[next_frame_idx]; + struct st_frame_trans *frame = &s->st20_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, - refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, + next_frame_idx, refcnt); s->stat_build_ret_code = -STI_ST22_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } /* check code stream size */ size_t codestream_size = meta.codestream_size; if ((codestream_size > s->st22_codestream_size) || !codestream_size) { - err("%s(%d), invalid codestream size %" PRIu64 ", allowed %" PRIu64 "\n", + err("%s(%d), invalid codestream size %" PRIu64 ", allowed %" PRIu64 + "\n", __func__, idx, codestream_size, s->st22_codestream_size); tv_notify_frame_done(s, next_frame_idx); s->stat_build_ret_code = -STI_ST22_APP_GET_FRAME_ERR_SIZE; @@ -2245,19 +2363,22 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, rte_atomic32_inc(&frame->refcnt); size_t frame_size = codestream_size + s->st22_box_hdr_length; st22_info->st22_total_pkts = frame_size / s->st20_pkt_len; - if (frame_size % s->st20_pkt_len) st22_info->st22_total_pkts++; + if (frame_size % s->st20_pkt_len) + st22_info->st22_total_pkts++; s->st20_total_pkts = st22_info->st22_total_pkts; st22_info->cur_frame_size = frame_size; s->st20_frame_idx = next_frame_idx; s->st20_frame_stat = ST21_TX_STAT_SENDING_PKTS; /* user timestamp control if any */ - uint64_t required_tai = tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); + uint64_t required_tai = + tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); bool second_field = frame->tx_st22_meta.second_field; tv_sync_pacing_st22(impl, s, false, required_tai, second_field, st22_info->st22_total_pkts); if (ops->flags & ST20_TX_FLAG_USER_TIMESTAMP) { - pacing->rtp_time_stamp = st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); + pacing->rtp_time_stamp = + st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); } dbg("%s(%d), rtp time stamp %u\n", __func__, idx, pacing->rtp_time_stamp); frame->tx_st22_meta.tfmt = ST10_TIMESTAMP_FMT_TAI; @@ -2268,8 +2389,9 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, if (ops->interlaced) { s->second_field = second_field ? false : true; } - MT_USDT_ST22_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, frame->addr, - pacing->rtp_time_stamp, codestream_size); + MT_USDT_ST22_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, + frame->addr, pacing->rtp_time_stamp, + codestream_size); /* check if dump USDT enabled */ if (MT_USDT_ST22_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -2280,10 +2402,11 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, } else { s->usdt_frame_cnt = 0; } - dbg("%s(%d), next_frame_idx %d(%d pkts) start\n", __func__, idx, next_frame_idx, - s->st20_total_pkts); - dbg("%s(%d), codestream_size %" PRId64 "(%d st22 pkts) time_stamp %u\n", __func__, - idx, codestream_size, st22_info->st22_total_pkts, pacing->rtp_time_stamp); + dbg("%s(%d), next_frame_idx %d(%d pkts) start\n", __func__, idx, + next_frame_idx, s->st20_total_pkts); + dbg("%s(%d), codestream_size %" PRId64 "(%d st22 pkts) time_stamp %u\n", + __func__, idx, codestream_size, st22_info->st22_total_pkts, + pacing->rtp_time_stamp); return MTL_TASKLET_HAS_PENDING; } else if (ST21_TX_STAT_SENDING_PKTS == s->st20_frame_stat) { uint64_t tsc_time_frame_start = s->pacing.tsc_time_frame_start; @@ -2296,12 +2419,12 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, } } - struct rte_mbuf* pkts[bulk]; - struct rte_mbuf* pkts_r[bulk]; + struct rte_mbuf *pkts[bulk]; + struct rte_mbuf *pkts_r[bulk]; if (s->st20_pkt_idx >= st22_info->st22_total_pkts) { /* build pad */ - struct rte_mbuf* pad = s->pad[MTL_SESSION_PORT_P][ST20_PKT_TYPE_NORMAL]; - struct rte_mbuf* pad_r = s->pad[MTL_SESSION_PORT_R][ST20_PKT_TYPE_NORMAL]; + struct rte_mbuf *pad = s->pad[MTL_SESSION_PORT_P][ST20_PKT_TYPE_NORMAL]; + struct rte_mbuf *pad_r = s->pad[MTL_SESSION_PORT_R][ST20_PKT_TYPE_NORMAL]; for (unsigned int i = 0; i < bulk; i++) { dbg("%s(%d), pad on pkt %d\n", __func__, s->idx, s->st20_pkt_idx); @@ -2321,7 +2444,7 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, s->stat_pkts_dummy++; } } else { - struct rte_mbuf* pkts_chain[bulk]; + struct rte_mbuf *pkts_chain[bulk]; ret = rte_pktmbuf_alloc_bulk(hdr_pool_p, pkts, bulk); if (ret < 0) { @@ -2345,7 +2468,8 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, if (ret < 0) { dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret); rte_pktmbuf_free_bulk(pkts, bulk); - if (!s->tx_no_chain) rte_pktmbuf_free_bulk(pkts_chain, bulk); + if (!s->tx_no_chain) + rte_pktmbuf_free_bulk(pkts_chain, bulk); s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL; return MTL_TASKLET_ALL_DONE; } @@ -2355,7 +2479,8 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, if (s->st20_pkt_idx >= st22_info->st22_total_pkts) { dbg("%s(%d), pad on pkt %d\n", __func__, s->idx, s->st20_pkt_idx); s->stat_pkts_dummy++; - if (!s->tx_no_chain) rte_pktmbuf_free(pkts_chain[i]); + if (!s->tx_no_chain) + rte_pktmbuf_free(pkts_chain[i]); st_tx_mbuf_set_idx(pkts[i], ST_TX_DUMMY_PKT_IDX); } else { if (s->tx_no_chain) @@ -2389,15 +2514,16 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, } bool done = false; - n = rte_ring_sp_enqueue_bulk(ring_p, (void**)&pkts[0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&pkts[0], bulk, NULL); if (n == 0) { - for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; + for (unsigned int i = 0; i < bulk; i++) + s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; s->inflight_cnt[MTL_SESSION_PORT_P]++; s->stat_build_ret_code = -STI_ST22_PKT_ENQUEUE_FAIL; done = true; } if (send_r) { - n = rte_ring_sp_enqueue_bulk(ring_r, (void**)&pkts_r[0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_r, (void **)&pkts_r[0], bulk, NULL); if (n == 0) { for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_R][i] = pkts_r[i]; @@ -2408,18 +2534,19 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, } if (s->st20_pkt_idx >= s->st20_total_pkts) { - dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, s->st20_frame_idx, - s->st20_pkt_idx); + dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, + s->st20_frame_idx, s->st20_pkt_idx); /* end of current frame */ s->st20_frame_stat = ST21_TX_STAT_WAIT_FRAME; s->st20_pkt_idx = 0; s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (send_r) s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (send_r) + s->port_user_stats[MTL_SESSION_PORT_R].frames++; rte_atomic32_inc(&s->stat_frame_cnt); st22_info->frame_idx++; if (s->tx_no_chain) { /* trigger extbuf free cb since mbuf attach not used */ - struct st_frame_trans* frame_info = &s->st20_frames[s->st20_frame_idx]; + struct st_frame_trans *frame_info = &s->st20_frames[s->st20_frame_idx]; tv_frame_free_cb(frame_info->addr, frame_info); } @@ -2427,7 +2554,8 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; rte_atomic32_inc(&s->cbs_build_timeout); - dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, s->st20_frame_idx, + dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, + s->st20_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } } @@ -2435,24 +2563,29 @@ static int tv_tasklet_st22(struct mtl_main_impl* impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tvs_tasklet_handler(void* priv) { - struct st_tx_video_sessions_mgr* mgr = priv; - struct mtl_main_impl* impl = mgr->parent; - struct st_tx_video_session_impl* s; +static int tvs_tasklet_handler(void *priv) { + struct st_tx_video_sessions_mgr *mgr = priv; + struct mtl_main_impl *impl = mgr->parent; + struct st_tx_video_session_impl *s; int pending = MTL_TASKLET_ALL_DONE; uint64_t tsc_s = 0; bool time_measure = mt_sessions_time_measure(impl); for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_video_session_try_get(mgr, sidx); - if (!s) continue; - if (!s->active) goto exit; + if (!s) + continue; + if (!s->active) + goto exit; - if (time_measure) tsc_s = mt_get_tsc(impl); + if (time_measure) + tsc_s = mt_get_tsc(impl); - if (s->ops.flags & ST20_TX_FLAG_ENABLE_RTCP) tv_tasklet_rtcp(s); + if (s->ops.flags & ST20_TX_FLAG_ENABLE_RTCP) + tv_tasklet_rtcp(s); /* check vsync if it has vsync enabled */ - if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) tv_poll_vsync(impl, s); + if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) + tv_poll_vsync(impl, s); s->stat_build_ret_code = 0; if (s->st22_info) @@ -2474,7 +2607,7 @@ static int tvs_tasklet_handler(void* priv) { return pending; } -static int tv_uinit_hw(struct st_tx_video_session_impl* s) { +static int tv_uinit_hw(struct st_tx_video_session_impl *s) { int num_port = s->ops.num_port; for (int i = 0; i < num_port; i++) { @@ -2485,9 +2618,10 @@ static int tv_uinit_hw(struct st_tx_video_session_impl* s) { } if (s->queue[i]) { - struct rte_mbuf* pad = s->pad[i][ST20_PKT_TYPE_NORMAL]; + struct rte_mbuf *pad = s->pad[i][ST20_PKT_TYPE_NORMAL]; /* flush all the pkts in the tx ring desc */ - if (pad) mt_txq_flush(s->queue[i], pad); + if (pad) + mt_txq_flush(s->queue[i], pad); mt_txq_put(s->queue[i]); s->queue[i] = NULL; } @@ -2503,14 +2637,15 @@ static int tv_uinit_hw(struct st_tx_video_session_impl* s) { return 0; } -static int tv_init_hw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s) { +static int tv_init_hw(struct mtl_main_impl *impl, + struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s) { unsigned int flags, count; - struct rte_ring* ring; + struct rte_ring *ring; char ring_name[32]; int mgr_idx = mgr->idx, idx = s->idx, num_port = s->ops.num_port; - struct rte_mempool* pad_mempool; - struct rte_mbuf* pad; + struct rte_mempool *pad_mempool; + struct rte_mbuf *pad; enum mtl_port port; uint16_t queue_id; @@ -2527,17 +2662,18 @@ static int tv_init_hw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mg flow.gso_sz = s->st20_pkt_size - sizeof(struct mt_udp_hdr); #ifdef MTL_HAS_RDMA_BACKEND int num_mrs = 1; - if (!s->tx_no_chain) num_mrs += s->st20_frames_cnt; - void* mrs_bufs[num_mrs]; + if (!s->tx_no_chain) + num_mrs += s->st20_frames_cnt; + void *mrs_bufs[num_mrs]; size_t mrs_sizes[num_mrs]; if (mt_pmd_is_rdma_ud(impl, port)) { /* register mempool memory to rdma */ - struct rte_mempool* pool = s->mbuf_mempool_hdr[i]; + struct rte_mempool *pool = s->mbuf_mempool_hdr[i]; mrs_bufs[0] = mt_mempool_mem_addr(pool); mrs_sizes[0] = mt_mempool_mem_size(pool); if (!s->tx_no_chain) { /* register frames memory to rdma */ - struct st_frame_trans* frame; + struct st_frame_trans *frame; for (int j = 0; j < s->st20_frames_cnt; j++) { frame = &s->st20_frames[j]; mrs_bufs[j + 1] = frame->addr; @@ -2557,30 +2693,33 @@ static int tv_init_hw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mg queue_id = mt_txq_queue_id(s->queue[i]); snprintf(ring_name, 32, "%sM%dS%dP%d", ST_TX_VIDEO_PREFIX, mgr_idx, idx, i); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ring_count; ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { - err("%s(%d,%d), rte_ring_create fail for port %d\n", __func__, mgr_idx, idx, i); + err("%s(%d,%d), rte_ring_create fail for port %d\n", __func__, mgr_idx, + idx, i); tv_uinit_hw(s); return -ENOMEM; } s->ring[i] = ring; - info("%s(%d,%d), port(l:%d,p:%d), queue %d, count %u\n", __func__, mgr_idx, idx, i, - port, queue_id, count); + info("%s(%d,%d), port(l:%d,p:%d), queue %d, count %u\n", __func__, mgr_idx, + idx, i, port, queue_id, count); if (mt_pmd_is_dpdk_af_xdp(impl, port) && s->mbuf_mempool_reuse_rx[i]) { if (s->mbuf_mempool_hdr[i]) { - err("%s(%d,%d), fail to reuse rx, has mempool_hdr for port %d\n", __func__, - mgr_idx, idx, i); + err("%s(%d,%d), fail to reuse rx, has mempool_hdr for port %d\n", + __func__, mgr_idx, idx, i); } else { /* reuse rx mempool for zero copy */ if (mt_user_rx_mono_pool(impl)) s->mbuf_mempool_hdr[i] = mt_sys_rx_mempool(impl, port); else - s->mbuf_mempool_hdr[i] = mt_if(impl, port)->rx_queues[queue_id].mbuf_pool; - info("%s(%d,%d), reuse rx mempool(%p) for port %d\n", __func__, mgr_idx, idx, - s->mbuf_mempool_hdr[i], i); + s->mbuf_mempool_hdr[i] = + mt_if(impl, port)->rx_queues[queue_id].mbuf_pool; + info("%s(%d,%d), reuse rx mempool(%p) for port %d\n", __func__, mgr_idx, + idx, s->mbuf_mempool_hdr[i], i); } } @@ -2591,7 +2730,8 @@ static int tv_init_hw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mg pad_mempool = mt_sys_tx_mempool(impl, port); } for (int j = 0; j < ST20_PKT_TYPE_MAX; j++) { - if (!s->st20_pkt_info[j].number) continue; + if (!s->st20_pkt_info[j].number) + continue; info("%s(%d), type %d number %u size %u\n", __func__, idx, j, s->st20_pkt_info[j].number, s->st20_pkt_info[j].size); pad = mt_build_pad(impl, pad_mempool, port, RTE_ETHER_TYPE_IPV4, @@ -2607,16 +2747,18 @@ static int tv_init_hw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mg return 0; } -static int tv_mempool_free(struct st_tx_video_session_impl* s) { +static int tv_mempool_free(struct st_tx_video_session_impl *s) { int ret; if (s->mbuf_mempool_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_chain); - if (ret >= 0) s->mbuf_mempool_chain = NULL; + if (ret >= 0) + s->mbuf_mempool_chain = NULL; } if (s->mbuf_mempool_copy_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_copy_chain); - if (ret >= 0) s->mbuf_mempool_copy_chain = NULL; + if (ret >= 0) + s->mbuf_mempool_copy_chain = NULL; } for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { @@ -2625,32 +2767,35 @@ static int tv_mempool_free(struct st_tx_video_session_impl* s) { ret = mt_mempool_free(s->mbuf_mempool_hdr[i]); else ret = 0; - if (ret >= 0) s->mbuf_mempool_hdr[i] = NULL; + if (ret >= 0) + s->mbuf_mempool_hdr[i] = NULL; } } return 0; } -static bool tv_has_chain_buf(struct st_tx_video_session_impl* s) { - struct st20_tx_ops* ops = &s->ops; +static bool tv_has_chain_buf(struct st_tx_video_session_impl *s) { + struct st20_tx_ops *ops = &s->ops; int num_ports = ops->num_port; for (int port = 0; port < num_ports; port++) { - if (!s->eth_has_chain[port]) return false; + if (!s->eth_has_chain[port]) + return false; } /* all ports capable chain */ return true; } -static bool tv_pkts_capable_chain(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s) { - struct st20_tx_ops* ops = &s->ops; +static bool tv_pkts_capable_chain(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s) { + struct st20_tx_ops *ops = &s->ops; int num_ports = ops->num_port; /* true for rtp type */ - if (!st20_is_frame_type(ops->type)) return true; + if (!st20_is_frame_type(ops->type)) + return true; for (int port = 0; port < num_ports; port++) { enum mtl_port s_port = mt_port_logic2phy(s->port_maps, port); @@ -2658,7 +2803,8 @@ static bool tv_pkts_capable_chain(struct mtl_main_impl* impl, // max_buffer_nb += s->ring_count; /* at least two swap buffer */ if ((s->st20_total_pkts * (s->st20_frames_cnt - 1)) < max_buffer_nb) { - warn("%s(%d), max_buffer_nb %u on s_port %d too large, st20_total_pkts %d\n", + warn("%s(%d), max_buffer_nb %u on s_port %d too large, st20_total_pkts " + "%d\n", __func__, s->idx, max_buffer_nb, s_port, s->st20_total_pkts); return false; } @@ -2668,10 +2814,10 @@ static bool tv_pkts_capable_chain(struct mtl_main_impl* impl, return true; } -static int tv_mempool_init(struct mtl_main_impl* impl, - struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s) { - struct st20_tx_ops* ops = &s->ops; +static int tv_mempool_init(struct mtl_main_impl *impl, + struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s) { + struct st20_tx_ops *ops = &s->ops; int num_port = ops->num_port, idx = s->idx; enum mtl_port port; unsigned int n; @@ -2709,21 +2855,24 @@ static int tv_mempool_init(struct mtl_main_impl* impl, s->mbuf_mempool_hdr[i], i); } else { n = mt_if_nb_tx_desc(impl, port) + s->ring_count; - if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) n += ops->rtcp.buffer_size; - if (ops->type == ST20_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; + if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) + n += ops->rtcp.buffer_size; + if (ops->type == ST20_TYPE_RTP_LEVEL) + n += ops->rtp_ring_size; if (mt_pmd_is_rdma_ud(impl, port)) - /* Unlike DPDK, the RDMA UD backend faces delays in freeing mbufs after send - * operations, requiring more mempool elements for now. */ + /* Unlike DPDK, the RDMA UD backend faces delays in freeing mbufs after + * send operations, requiring more mempool elements for now. */ n += 2048; if (s->mbuf_mempool_hdr[i]) { - warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, i); + warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, + i); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_VIDEO_PREFIX, mgr->idx, idx, - i, s->recovery_idx); - struct rte_mempool* mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), - hdr_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_VIDEO_PREFIX, + mgr->idx, idx, i, s->recovery_idx); + struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( + impl, pool_name, n, MT_MBUF_CACHE_SIZE, + sizeof(struct mt_muf_priv_data), hdr_room_size, s->socket_id); if (!mbuf_pool) { tv_mempool_free(s); return -ENOMEM; @@ -2737,9 +2886,12 @@ static int tv_mempool_init(struct mtl_main_impl* impl, if (!s->tx_no_chain) { port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); n = mt_if_nb_tx_desc(impl, port) + s->ring_count; - if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) n += ops->rtcp.buffer_size; - if (ops->type == ST20_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; - if (mt_pmd_is_rdma_ud(impl, port)) n += 2048; + if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) + n += ops->rtcp.buffer_size; + if (ops->type == ST20_TYPE_RTP_LEVEL) + n += ops->rtp_ring_size; + if (mt_pmd_is_rdma_ud(impl, port)) + n += 2048; if (s->tx_mono_pool) { s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port); @@ -2747,26 +2899,29 @@ static int tv_mempool_init(struct mtl_main_impl* impl, s->mbuf_mempool_chain); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_VIDEO_PREFIX, mgr->idx, idx, - s->recovery_idx); - struct rte_mempool* mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, chain_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_VIDEO_PREFIX, mgr->idx, + idx, s->recovery_idx); + struct rte_mempool *mbuf_pool = + mt_mempool_create_by_socket(impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, + chain_room_size, s->socket_id); if (!mbuf_pool) { tv_mempool_free(s); return -ENOMEM; } s->mbuf_mempool_chain = mbuf_pool; - /* has copy (not attach extbuf) and chain mbuf, create a special mempool */ + /* has copy (not attach extbuf) and chain mbuf, create a special mempool + */ if (s->st20_linesize > s->st20_bytes_in_line && s->ops.packing != ST20_PACKING_GPM_SL) { chain_room_size = s->st20_pkt_len; n /= s->st20_total_pkts / s->st20_pkt_info[ST20_PKT_TYPE_EXTRA].number; char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_COPY_%d", ST_TX_VIDEO_PREFIX, mgr->idx, idx, - s->recovery_idx); - struct rte_mempool* mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, chain_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%d_COPY_%d", ST_TX_VIDEO_PREFIX, + mgr->idx, idx, s->recovery_idx); + struct rte_mempool *mbuf_pool = + mt_mempool_create_by_socket(impl, pool_name, n, MT_MBUF_CACHE_SIZE, + 0, chain_room_size, s->socket_id); if (!mbuf_pool) { tv_mempool_free(s); return -ENOMEM; @@ -2779,15 +2934,16 @@ static int tv_mempool_init(struct mtl_main_impl* impl, return 0; } -static int tv_init_packet_ring(struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s) { +static int tv_init_packet_ring(struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s) { char ring_name[32]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count = s->ops.rtp_ring_size; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_TX_VIDEO_PREFIX, mgr_idx, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { err("%s(%d,%d), rte_ring_create fail\n", __func__, mgr_idx, idx); @@ -2798,7 +2954,7 @@ static int tv_init_packet_ring(struct st_tx_video_sessions_mgr* mgr, return 0; } -static int tv_uinit_sw(struct st_tx_video_session_impl* s) { +static int tv_uinit_sw(struct st_tx_video_session_impl *s) { int num_port = s->ops.num_port; for (int i = 0; i < num_port; i++) { @@ -2837,12 +2993,13 @@ static int tv_uinit_sw(struct st_tx_video_session_impl* s) { return 0; } -static int tv_init_st22_frame(struct st_tx_video_session_impl* s, - struct st22_tx_ops* st22_frame_ops) { - struct st22_tx_video_info* st22_info; +static int tv_init_st22_frame(struct st_tx_video_session_impl *s, + struct st22_tx_ops *st22_frame_ops) { + struct st22_tx_video_info *st22_info; st22_info = mt_rte_zmalloc_socket(sizeof(*st22_info), s->socket_id); - if (!st22_info) return -ENOMEM; + if (!st22_info) + return -ENOMEM; st22_info->get_next_frame = st22_frame_ops->get_next_frame; st22_info->notify_frame_done = st22_frame_ops->notify_frame_done; @@ -2852,9 +3009,10 @@ static int tv_init_st22_frame(struct st_tx_video_session_impl* s, return 0; } -static int tv_init_sw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s, - struct st22_tx_ops* st22_frame_ops) { +static int tv_init_sw(struct mtl_main_impl *impl, + struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s, + struct st22_tx_ops *st22_frame_ops) { int idx = s->idx, ret; enum st20_type type = s->ops.type; @@ -2890,8 +3048,10 @@ static int tv_init_sw(struct mtl_main_impl* impl, struct st_tx_video_sessions_mg return 0; } -static int tv_init_pkt(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, - struct st20_tx_ops* ops, struct st22_tx_ops* st22_frame_ops) { +static int tv_init_pkt(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + struct st20_tx_ops *ops, + struct st22_tx_ops *st22_frame_ops) { int idx = s->idx; uint32_t height = ops->interlaced ? (ops->height >> 1) : ops->height; enum st20_type type = ops->type; @@ -2911,7 +3071,8 @@ static int tv_init_pkt(struct mtl_main_impl* impl, struct st_tx_video_session_im uint32_t align = 128; max_data_len = max_data_len / align * align; s->st20_total_pkts = s->st20_frame_size / max_data_len; - if (s->st20_frame_size % max_data_len) s->st20_total_pkts++; + if (s->st20_frame_size % max_data_len) + s->st20_total_pkts++; s->st20_pkt_len = max_data_len; s->st20_pkt_size = s->st20_pkt_len + sizeof(struct st22_rfc9134_rtp_hdr); /* assume all are normal */ @@ -2926,12 +3087,14 @@ static int tv_init_pkt(struct mtl_main_impl* impl, struct st_tx_video_session_im s->st20_pkt_info[ST20_PKT_TYPE_NORMAL].number = s->st20_total_pkts; } else if (ops->packing == ST20_PACKING_GPM_SL) { /* calculate pkts in line */ - int bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); + int bytes_in_pkt = + ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); s->st20_pkts_in_line = (s->st20_bytes_in_line / bytes_in_pkt) + 1; - int pixel_in_pkt = (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; - s->st20_pkt_len = - (pixel_in_pkt + s->st20_pg.coverage - 1) / s->st20_pg.coverage * s->st20_pg.size; + int pixel_in_pkt = + (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; + s->st20_pkt_len = (pixel_in_pkt + s->st20_pg.coverage - 1) / + s->st20_pg.coverage * s->st20_pg.size; s->st20_pkt_size = s->st20_pkt_len + sizeof(struct st_rfc4175_video_hdr); s->st20_total_pkts = height * s->st20_pkts_in_line; @@ -2947,8 +3110,8 @@ static int tv_init_pkt(struct mtl_main_impl* impl, struct st_tx_video_session_im dbg("%s(%d), line_last_len: %d\n", __func__, idx, line_last_len); } else if (ops->packing == ST20_PACKING_BPM) { if (ST_VIDEO_BPM_SIZE % s->st20_pg.size) { - err("%s(%d), bpm size 1260 can not be divide by pg size %u\n", __func__, idx, - s->st20_pg.size); + err("%s(%d), bpm size 1260 can not be divide by pg size %u\n", __func__, + idx, s->st20_pg.size); return -EIO; } s->st20_pkt_len = ST_VIDEO_BPM_SIZE; @@ -2984,8 +3147,8 @@ static int tv_init_pkt(struct mtl_main_impl* impl, struct st_tx_video_session_im uint32_t align = s->st20_pg.size * 2; max_data_len = max_data_len / align * align; int pg_per_pkt = max_data_len / s->st20_pg.size; - s->st20_total_pkts = - (ceil)((double)ops->width * height / (s->st20_pg.coverage * pg_per_pkt)); + s->st20_total_pkts = (ceil)((double)ops->width * height / + (s->st20_pg.coverage * pg_per_pkt)); s->st20_pkt_len = pg_per_pkt * s->st20_pg.size; int last_pkt_len = s->st20_frame_size % s->st20_pkt_len; s->st20_pkt_size = s->st20_pkt_len + sizeof(struct st_rfc4175_video_hdr); @@ -3024,7 +3187,7 @@ static int tv_init_pkt(struct mtl_main_impl* impl, struct st_tx_video_session_im return 0; } -static int tv_uinit(struct st_tx_video_session_impl* s) { +static int tv_uinit(struct st_tx_video_session_impl *s) { tv_uinit_rtcp(s); /* must uinit hw firstly as frame use shared external buffer */ tv_uinit_hw(s); @@ -3032,16 +3195,20 @@ static int tv_uinit(struct st_tx_video_session_impl* s) { return 0; } -static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s, struct st20_tx_ops* ops, - enum mt_handle_type s_type, struct st22_tx_ops* st22_frame_ops) { +static int tv_attach(struct mtl_main_impl *impl, + struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s, + struct st20_tx_ops *ops, enum mt_handle_type s_type, + struct st22_tx_ops *st22_frame_ops) { int ret; int idx = s->idx, num_port = ops->num_port; - char* ports[MTL_SESSION_PORT_MAX]; + char *ports[MTL_SESSION_PORT_MAX]; - for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) + ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = st20_get_pgroup(ops->fmt, &s->st20_pg); if (ret < 0) { @@ -3057,7 +3224,8 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr s->impl = impl; s->mgr = mgr; - /* mark the queue to fatal error if burst fail exceed tx_hang_detect_time_thresh */ + /* mark the queue to fatal error if burst fail exceed + * tx_hang_detect_time_thresh */ if (ops->tx_hang_detect_ms) s->tx_hang_detect_time_thresh = ops->tx_hang_detect_ms * NS_PER_MS; else @@ -3080,10 +3248,11 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr s->st22_codestream_size = st22_frame_ops->framebuff_max_size; s->st20_frame_size = s->st22_codestream_size + s->st22_box_hdr_length; s->st20_fb_size = s->st20_frame_size; - info("%s(%d), st22 max codestream size %" PRId64 ", box len %u\n", __func__, idx, - s->st22_codestream_size, s->st22_box_hdr_length); + info("%s(%d), st22 max codestream size %" PRId64 ", box len %u\n", __func__, + idx, s->st22_codestream_size, s->st22_box_hdr_length); } else { - s->st20_frame_size = ops->width * height * s->st20_pg.size / s->st20_pg.coverage; + s->st20_frame_size = + ops->width * height * s->st20_pg.size / s->st20_pg.coverage; s->st20_fb_size = s->st20_linesize * height; } s->st20_frames_cnt = ops->framebuff_cnt; @@ -3115,12 +3284,14 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "TX_VIDEO_M%dS%d", mgr->idx, idx); + snprintf(s->ops_name, sizeof(s->ops_name), "TX_VIDEO_M%dS%d", mgr->idx, + idx); } s->ops = *ops; s->s_type = s_type; for (int i = 0; i < num_port; i++) { - s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); if (mt_user_random_src_port(impl)) s->st20_src_port[i] = mt_random_port(s->st20_dst_port[i]); else @@ -3145,7 +3316,8 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr } if (st22_frame_ops) { - /* no chain support for st22 since the pkts for each frame may be very small */ + /* no chain support for st22 since the pkts for each frame may be very small + */ s->tx_no_chain = true; } else { /* manually disable chain or any port can't support chain */ @@ -3184,7 +3356,8 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr for (int i = 0; i < num_port; i++) { ret = tv_init_hdr(impl, s, i); if (ret < 0) { - err("%s(%d), tx_session_init_hdr fail %d port %d\n", __func__, idx, ret, i); + err("%s(%d), tx_session_init_hdr fail %d port %d\n", __func__, idx, ret, + i); tv_uinit(s); return ret; } @@ -3214,7 +3387,8 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr double sleep_ns = s->pacing.trs * 128; s->advice_sleep_us = sleep_ns / NS_PER_US; if (mt_user_tasklet_sleep(impl)) { - info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, s->advice_sleep_us); + info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, + s->advice_sleep_us); } s->stat_lines_not_ready = 0; @@ -3239,22 +3413,24 @@ static int tv_attach(struct mtl_main_impl* impl, struct st_tx_video_sessions_mgr tv_init_pacing_epoch(impl, s); s->active = true; - info("%s(%d), len %d(%d) total %d each line %d type %d flags 0x%x, %s\n", __func__, idx, - s->st20_pkt_len, s->st20_pkt_size, s->st20_total_pkts, s->st20_pkts_in_line, - ops->type, ops->flags, ops->interlaced ? "interlace" : "progressive"); - info("%s(%d), w %u h %u fmt %s packing %d pt %d, pacing way: %s\n", __func__, idx, - ops->width, ops->height, st20_fmt_name(ops->fmt), ops->packing, ops->payload_type, + info("%s(%d), len %d(%d) total %d each line %d type %d flags 0x%x, %s\n", + __func__, idx, s->st20_pkt_len, s->st20_pkt_size, s->st20_total_pkts, + s->st20_pkts_in_line, ops->type, ops->flags, + ops->interlaced ? "interlace" : "progressive"); + info("%s(%d), w %u h %u fmt %s packing %d pt %d, pacing way: %s\n", __func__, + idx, ops->width, ops->height, st20_fmt_name(ops->fmt), ops->packing, + ops->payload_type, st_tx_pacing_way_name(s->pacing_way[MTL_SESSION_PORT_P])); return 0; } -void tx_video_session_clear_cpu_busy(struct st_tx_video_session_impl* s) { +void tx_video_session_clear_cpu_busy(struct st_tx_video_session_impl *s) { s->cpu_busy_score = 0; rte_atomic32_set(&s->cbs_build_timeout, 0); } -void tx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, - struct st_tx_video_session_impl* s) { +void tx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, + struct st_tx_video_session_impl *s) { uint64_t avg_ns_per_loop = mt_sch_avg_ns_loop(sch); int cbs_build_timeout; @@ -3272,8 +3448,8 @@ void tx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, s->stat_cpu_busy_score = s->cpu_busy_score; } -static void tv_stat(struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s) { +static void tv_stat(struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s) { int m_idx = mgr->idx, idx = s->idx; uint64_t cur_time_ns = mt_get_monotonic_time(); double time_sec = (double)(cur_time_ns - s->stat_last_time) / NS_PER_S; @@ -3282,14 +3458,18 @@ static void tv_stat(struct st_tx_video_sessions_mgr* mgr, rte_atomic32_set(&s->stat_frame_cnt, 0); - notice("TX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d:%d inflight %d:%d\n", + notice("TX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d:%d inflight " + "%d:%d\n", m_idx, idx, s->ops_name, framerate, frame_cnt, - s->stat_pkts_build[MTL_SESSION_PORT_P], s->stat_pkts_build[MTL_SESSION_PORT_R], - s->trs_inflight_cnt[0], s->inflight_cnt[0]); - notice("TX_VIDEO_SESSION(%d,%d): throughput %f Mb/s: %f Mb/s, cpu busy %f\n", m_idx, - idx, - (double)s->stat_bytes_tx[MTL_SESSION_PORT_P] * 8 / time_sec / MTL_STAT_M_UNIT, - (double)s->stat_bytes_tx[MTL_SESSION_PORT_R] * 8 / time_sec / MTL_STAT_M_UNIT, + s->stat_pkts_build[MTL_SESSION_PORT_P], + s->stat_pkts_build[MTL_SESSION_PORT_R], s->trs_inflight_cnt[0], + s->inflight_cnt[0]); + notice("TX_VIDEO_SESSION(%d,%d): throughput %f Mb/s: %f Mb/s, cpu busy %f\n", + m_idx, idx, + (double)s->stat_bytes_tx[MTL_SESSION_PORT_P] * 8 / time_sec / + MTL_STAT_M_UNIT, + (double)s->stat_bytes_tx[MTL_SESSION_PORT_R] * 8 / time_sec / + MTL_STAT_M_UNIT, s->stat_cpu_busy_score); s->stat_last_time = cur_time_ns; s->stat_pkts_build[MTL_SESSION_PORT_P] = 0; @@ -3313,17 +3493,18 @@ static void tv_stat(struct st_tx_video_sessions_mgr* mgr, s->stat_epoch_troffset_mismatch = 0; } if (s->stat_trans_troffset_mismatch) { - notice("TX_VIDEO_SESSION(%d,%d): transmitter mismatch troffset %u\n", m_idx, idx, - s->stat_trans_troffset_mismatch); + notice("TX_VIDEO_SESSION(%d,%d): transmitter mismatch troffset %u\n", m_idx, + idx, s->stat_trans_troffset_mismatch); s->stat_trans_troffset_mismatch = 0; } if (s->stat_trans_recalculate_warmup) { - notice("TX_VIDEO_SESSION(%d,%d): transmitter recalculate warmup %u\n", m_idx, idx, - s->stat_trans_recalculate_warmup); + notice("TX_VIDEO_SESSION(%d,%d): transmitter recalculate warmup %u\n", + m_idx, idx, s->stat_trans_recalculate_warmup); s->stat_trans_recalculate_warmup = 0; } if (s->stat_epoch_drop) { - notice("TX_VIDEO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, s->stat_epoch_drop); + notice("TX_VIDEO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, + s->stat_epoch_drop); s->stat_epoch_drop = 0; } if (s->stat_epoch_onward) { @@ -3342,13 +3523,13 @@ static void tv_stat(struct st_tx_video_sessions_mgr* mgr, s->stat_error_user_timestamp = 0; } if (s->stat_user_busy) { - notice("TX_VIDEO_SESSION(%d,%d): busy as no ready frame from user %u\n", m_idx, idx, - s->stat_user_busy); + notice("TX_VIDEO_SESSION(%d,%d): busy as no ready frame from user %u\n", + m_idx, idx, s->stat_user_busy); s->stat_user_busy = 0; } if (s->stat_lines_not_ready) { - notice("TX_VIDEO_SESSION(%d,%d): query new lines but app not ready %u\n", m_idx, idx, - s->stat_lines_not_ready); + notice("TX_VIDEO_SESSION(%d,%d): query new lines but app not ready %u\n", + m_idx, idx, s->stat_lines_not_ready); s->stat_lines_not_ready = 0; } if (s->stat_vsync_mismatch) { @@ -3357,14 +3538,15 @@ static void tv_stat(struct st_tx_video_sessions_mgr* mgr, s->stat_vsync_mismatch = 0; } if (s->stat_pkts_chain_realloc_fail) { - notice("TX_VIDEO_SESSION(%d,%d): chain pkt realloc fail cnt %u\n", m_idx, idx, - s->stat_pkts_chain_realloc_fail); + notice("TX_VIDEO_SESSION(%d,%d): chain pkt realloc fail cnt %u\n", m_idx, + idx, s->stat_pkts_chain_realloc_fail); notice("TX_VIDEO_SESSION(%d,%d): SERIOUS MEMORY ISSUE!\n", m_idx, idx); s->stat_pkts_chain_realloc_fail = 0; } if (frame_cnt <= 0) { - warn("TX_VIDEO_SESSION(%d,%d:%s): build ret %d, trs ret %d:%d\n", m_idx, idx, - s->ops_name, s->stat_build_ret_code, s->stat_trs_ret_code[MTL_SESSION_PORT_P], + warn("TX_VIDEO_SESSION(%d,%d:%s): build ret %d, trs ret %d:%d\n", m_idx, + idx, s->ops_name, s->stat_build_ret_code, + s->stat_trs_ret_code[MTL_SESSION_PORT_P], s->stat_trs_ret_code[MTL_SESSION_PORT_R]); } if (s->stat_user_meta_cnt || s->stat_user_meta_pkt_cnt) { @@ -3384,68 +3566,75 @@ static void tv_stat(struct st_tx_video_sessions_mgr* mgr, /* not reset unrecoverable_error */ } if (s->ops.interlaced) { - notice("TX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", m_idx, - idx, s->stat_interlace_first_field, s->stat_interlace_second_field); + notice( + "TX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", + m_idx, idx, s->stat_interlace_first_field, + s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } /* check frame busy stat */ if (s->st20_frames) { - struct st_frame_trans* frame_info; + struct st_frame_trans *frame_info; int frames_in_trans = 0; uint16_t framebuff_cnt = s->ops.framebuff_cnt; for (int i = 0; i < s->st20_frames_cnt; i++) { frame_info = &s->st20_frames[i]; - if (rte_atomic32_read(&frame_info->refcnt)) frames_in_trans++; + if (rte_atomic32_read(&frame_info->refcnt)) + frames_in_trans++; } if ((frames_in_trans > 2) || (frames_in_trans >= framebuff_cnt)) { - notice("TX_VIDEO_SESSION(%d,%d): %d frames are in trans, total %u\n", m_idx, idx, - frames_in_trans, framebuff_cnt); + notice("TX_VIDEO_SESSION(%d,%d): %d frames are in trans, total %u\n", + m_idx, idx, frames_in_trans, framebuff_cnt); } } - struct mt_stat_u64* stat_time = &s->stat_time; + struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("TX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + notice("TX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, + (float)stat_time->max / NS_PER_US, (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_next_frame_us > 8 || s->stat_max_notify_frame_us > 8) { - notice("TX_VIDEO_SESSION(%d,%d): get next frame max %uus, notify done max %uus\n", + notice("TX_VIDEO_SESSION(%d,%d): get next frame max %uus, notify done max " + "%uus\n", m_idx, idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); } s->stat_max_next_frame_us = 0; s->stat_max_notify_frame_us = 0; } -static int tv_detach(struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s) { +static int tv_detach(struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s) { tv_stat(mgr, s); tv_uinit(s); return 0; } -static int tv_init(struct st_tx_video_session_impl* s, int idx) { +static int tv_init(struct st_tx_video_session_impl *s, int idx) { s->idx = idx; return 0; } -static struct st_tx_video_session_impl* tv_mgr_attach( - struct mtl_sch_impl* sch, struct st20_tx_ops* ops, enum mt_handle_type s_type, - struct st22_tx_ops* st22_frame_ops) { - struct st_tx_video_sessions_mgr* mgr = &sch->tx_video_mgr; +static struct st_tx_video_session_impl * +tv_mgr_attach(struct mtl_sch_impl *sch, struct st20_tx_ops *ops, + enum mt_handle_type s_type, struct st22_tx_ops *st22_frame_ops) { + struct st_tx_video_sessions_mgr *mgr = &sch->tx_video_mgr; int midx = mgr->idx; - struct mtl_main_impl* impl = mgr->parent; + struct mtl_main_impl *impl = mgr->parent; int ret; - struct st_tx_video_session_impl* s; + struct st_tx_video_session_impl *s; int socket = mt_sch_socket_id(sch); /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { - if (!tx_video_session_get_empty(mgr, i)) continue; + if (!tx_video_session_get_empty(mgr, i)) + continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -3478,8 +3667,8 @@ static struct st_tx_video_session_impl* tv_mgr_attach( return NULL; } -static int tv_mgr_detach(struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s) { +static int tv_mgr_detach(struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -3498,17 +3687,19 @@ static int tv_mgr_detach(struct st_tx_video_sessions_mgr* mgr, return 0; } -static int tv_update_dst(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, - struct st_tx_dest_info* dst) { +static int tv_update_dst(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + struct st_tx_dest_info *dst) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; - struct st20_tx_ops* ops = &s->ops; + struct st20_tx_ops *ops = &s->ops; /* update ip and port */ for (int i = 0; i < num_port; i++) { memcpy(ops->dip_addr[i], dst->dip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = dst->udp_port[i]; - s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = + (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); s->st20_dst_port[i] = (ops->udp_src_port[i]) ? (ops->udp_src_port[i]) : s->st20_dst_port[i]; @@ -3523,9 +3714,9 @@ static int tv_update_dst(struct mtl_main_impl* impl, struct st_tx_video_session_ return 0; } -static int tv_mgr_update_dst(struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s, - struct st_tx_dest_info* dst) { +static int tv_mgr_update_dst(struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s, + struct st_tx_dest_info *dst) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = tx_video_session_get(mgr, idx); /* get the lock */ @@ -3544,8 +3735,8 @@ static int tv_mgr_update_dst(struct st_tx_video_sessions_mgr* mgr, return 0; } -static int tv_mgr_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_tx_video_sessions_mgr* mgr) { +static int tv_mgr_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, + struct st_tx_video_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; int i; @@ -3578,9 +3769,9 @@ static int tv_mgr_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, return 0; } -static int tv_mgr_uinit(struct st_tx_video_sessions_mgr* mgr) { +static int tv_mgr_uinit(struct st_tx_video_sessions_mgr *mgr) { int m_idx = mgr->idx; - struct st_tx_video_session_impl* s; + struct st_tx_video_session_impl *s; if (mgr->tasklet) { mtl_sch_unregister_tasklet(mgr->tasklet); @@ -3589,7 +3780,8 @@ static int tv_mgr_uinit(struct st_tx_video_sessions_mgr* mgr) { for (int i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { s = tx_video_session_get(mgr, i); - if (!s) continue; + if (!s) + continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); tv_mgr_detach(mgr, s); @@ -3600,32 +3792,35 @@ static int tv_mgr_uinit(struct st_tx_video_sessions_mgr* mgr) { return 0; } -static int tv_mgr_update(struct st_tx_video_sessions_mgr* mgr) { +static int tv_mgr_update(struct st_tx_video_sessions_mgr *mgr) { int max_idx = 0; - struct mtl_main_impl* impl = mgr->parent; + struct mtl_main_impl *impl = mgr->parent; uint64_t sleep_us = mt_sch_default_sleep_us(impl); - struct st_tx_video_session_impl* s; + struct st_tx_video_session_impl *s; for (int i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { s = mgr->sessions[i]; - if (!s) continue; + if (!s) + continue; max_idx = i + 1; sleep_us = RTE_MIN(s->advice_sleep_us, sleep_us); } - dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, sleep_us, - max_idx); + dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, + sleep_us, max_idx); mgr->max_idx = max_idx; - if (mgr->tasklet) mt_tasklet_set_sleep(mgr->tasklet, sleep_us); + if (mgr->tasklet) + mt_tasklet_set_sleep(mgr->tasklet, sleep_us); return 0; } -static int tv_sessions_stat(void* priv) { - struct st_tx_video_sessions_mgr* mgr = priv; - struct st_tx_video_session_impl* s; +static int tv_sessions_stat(void *priv) { + struct st_tx_video_sessions_mgr *mgr = priv; + struct st_tx_video_session_impl *s; for (int j = 0; j < mgr->max_idx; j++) { s = tx_video_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) continue; + if (!s) + continue; tv_stat(mgr, s); tx_video_session_put(mgr, j); } @@ -3633,20 +3828,23 @@ static int tv_sessions_stat(void* priv) { return 0; } -int st_tx_video_sessions_sch_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { +int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { int ret, idx = sch->idx; - if (sch->tx_video_init) return 0; + if (sch->tx_video_init) + return 0; /* create tx video context */ - struct st_tx_video_sessions_mgr* tx_video_mgr = &sch->tx_video_mgr; + struct st_tx_video_sessions_mgr *tx_video_mgr = &sch->tx_video_mgr; ret = tv_mgr_init(impl, sch, tx_video_mgr); if (ret < 0) { err("%s(%d), st_tv_mgr_init fail %d\n", __func__, idx, ret); return ret; } - ret = st_video_transmitter_init(impl, sch, tx_video_mgr, &sch->video_transmitter); + ret = st_video_transmitter_init(impl, sch, tx_video_mgr, + &sch->video_transmitter); if (ret < 0) { tv_mgr_uinit(tx_video_mgr); err("%s(%d), st_video_transmitter_init fail %d\n", __func__, idx, ret); @@ -3658,10 +3856,12 @@ int st_tx_video_sessions_sch_init(struct mtl_main_impl* impl, struct mtl_sch_imp return 0; } -int st_tx_video_sessions_sch_uinit(struct mtl_main_impl* impl, struct mtl_sch_impl* sch) { - if (!sch->tx_video_init) return 0; +int st_tx_video_sessions_sch_uinit(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch) { + if (!sch->tx_video_init) + return 0; - struct st_tx_video_sessions_mgr* tx_video_mgr = &sch->tx_video_mgr; + struct st_tx_video_sessions_mgr *tx_video_mgr = &sch->tx_video_mgr; mt_stat_unregister(impl, tv_sessions_stat, tx_video_mgr); st_video_transmitter_uinit(&sch->video_transmitter); @@ -3671,16 +3871,16 @@ int st_tx_video_sessions_sch_uinit(struct mtl_main_impl* impl, struct mtl_sch_im return 0; } -int st_tx_video_session_migrate(struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s, int idx) { +int st_tx_video_session_migrate(struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s, int idx) { MTL_MAY_UNUSED(mgr); tv_init(s, idx); return 0; } -static int tv_ops_check(struct st20_tx_ops* ops) { +static int tv_ops_check(struct st20_tx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip = NULL; + uint8_t *ip = NULL; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { err("%s, invalid num_ports %d\n", __func__, num_ports); @@ -3691,14 +3891,16 @@ static int tv_ops_check(struct st20_tx_ops* ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -3725,7 +3927,8 @@ static int tv_ops_check(struct st20_tx_ops* ops) { return -EINVAL; } if (ops->rtp_frame_total_pkts <= 0) { - err("%s, invalid rtp_frame_total_pkts %d\n", __func__, ops->rtp_frame_total_pkts); + err("%s, invalid rtp_frame_total_pkts %d\n", __func__, + ops->rtp_frame_total_pkts); return -EINVAL; } if (!mt_rtp_len_valid(ops->rtp_pkt_size)) { @@ -3746,9 +3949,9 @@ static int tv_ops_check(struct st20_tx_ops* ops) { return 0; } -static int tv_st22_ops_check(struct st22_tx_ops* ops) { +static int tv_st22_ops_check(struct st22_tx_ops *ops) { int num_ports = ops->num_port, ret; - uint8_t* ip = NULL; + uint8_t *ip = NULL; if ((num_ports > MTL_SESSION_PORT_MAX) || (num_ports <= 0)) { err("%s, invalid num_ports %d\n", __func__, num_ports); @@ -3759,14 +3962,16 @@ static int tv_st22_ops_check(struct st22_tx_ops* ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], + ip[3]); return -EINVAL; } } @@ -3814,8 +4019,8 @@ static int tv_st22_ops_check(struct st22_tx_ops* ops) { return 0; } -int st20_tx_queue_fatal_error(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); int idx = s->idx; @@ -3823,7 +4028,8 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl* impl, if (!mt_pmd_is_dpdk_user(impl, port)) { err("%s(%d,%d), not dpdk user pmd, nothing to do\n", __func__, s_port, idx); - if (s->ops.notify_event) s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); + if (s->ops.notify_event) + s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); return 0; } @@ -3833,9 +4039,11 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl* impl, } /* clear all tx ring buffer */ - if (s->packet_ring) mt_ring_dequeue_clean(s->packet_ring); + if (s->packet_ring) + mt_ring_dequeue_clean(s->packet_ring); for (uint8_t i = 0; i < s->ops.num_port; i++) { - if (s->ring[i]) mt_ring_dequeue_clean(s->ring[i]); + if (s->ring[i]) + mt_ring_dequeue_clean(s->ring[i]); } /* clean the queue done mbuf */ mt_txq_done_cleanup(s->queue[s_port]); @@ -3854,14 +4062,15 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl* impl, err("%s(%d,%d), get new txq fail\n", __func__, s_port, idx); s->stat_unrecoverable_error++; s->active = false; /* mark current session to dead */ - if (s->ops.notify_event) s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); + if (s->ops.notify_event) + s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); return -EIO; } uint16_t queue_id = mt_txq_queue_id(s->queue[s_port]); info("%s(%d,%d), new queue_id %u\n", __func__, s_port, idx, queue_id); /* cleanup frame manager */ - struct st_frame_trans* frame; + struct st_frame_trans *frame; for (uint16_t i = 0; i < s->st20_frames_cnt; i++) { frame = &s->st20_frames[i]; int refcnt = rte_atomic32_read(&frame->refcnt); @@ -3881,7 +4090,8 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl* impl, err("%s(%d,%d), reset mempool fail\n", __func__, s_port, idx); s->stat_unrecoverable_error++; s->active = false; /* mark current session to dead */ - if (s->ops.notify_event) s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); + if (s->ops.notify_event) + s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); return ret; } @@ -3896,20 +4106,23 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl* impl, } /* only st20 frame mode has this callback */ -int st20_frame_tx_start(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, - enum mtl_session_port s_port, struct st_frame_trans* frame) { +int st20_frame_tx_start(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, + struct st_frame_trans *frame) { dbg("%s(%d,%d), start trans for frame %p\n", __func__, s->idx, port, frame); - if (!frame->user_meta_data_size) return 0; + if (!frame->user_meta_data_size) + return 0; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); /* tx the user meta */ - struct rte_mbuf* pkt; - struct st_rfc4175_video_hdr* hdr; - struct rte_ipv4_hdr* ipv4; - struct st20_rfc4175_rtp_hdr* rtp; - struct rte_udp_hdr* udp; + struct rte_mbuf *pkt; + struct st_rfc4175_video_hdr *hdr; + struct rte_ipv4_hdr *ipv4; + struct st20_rfc4175_rtp_hdr *rtp; + struct rte_udp_hdr *udp; - struct rte_mempool* pool = mt_drv_no_sys_txq(impl, port) + struct rte_mempool *pool = mt_drv_no_sys_txq(impl, port) ? s->mbuf_mempool_hdr[s_port] : mt_sys_tx_mempool(impl, port); pkt = rte_pktmbuf_alloc(pool); @@ -3918,7 +4131,7 @@ int st20_frame_tx_start(struct mtl_main_impl* impl, struct st_tx_video_session_i return -ENOMEM; } - hdr = rte_pktmbuf_mtod(pkt, struct st_rfc4175_video_hdr*); + hdr = rte_pktmbuf_mtod(pkt, struct st_rfc4175_video_hdr *); ipv4 = &hdr->ipv4; rtp = &hdr->rtp; udp = &hdr->udp; @@ -3935,10 +4148,11 @@ int st20_frame_tx_start(struct mtl_main_impl* impl, struct st_tx_video_session_i mt_mbuf_init_ipv4(pkt); /* copy user meta */ - void* payload = &rtp[1]; + void *payload = &rtp[1]; mtl_memcpy(payload, frame->user_meta, frame->user_meta_data_size); - pkt->data_len = sizeof(struct st_rfc4175_video_hdr) + frame->user_meta_data_size; + pkt->data_len = + sizeof(struct st_rfc4175_video_hdr) + frame->user_meta_data_size; pkt->pkt_len = pkt->data_len; udp->dgram_len = htons(pkt->pkt_len - pkt->l2_len - pkt->l3_len); @@ -3961,11 +4175,11 @@ int st20_frame_tx_start(struct mtl_main_impl* impl, struct st_tx_video_session_i return 0; } -st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct mtl_sch_impl* sch; - struct st_tx_video_session_handle_impl* s_impl; - struct st_tx_video_session_impl* s; +st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct mtl_sch_impl *sch; + struct st_tx_video_session_handle_impl *s_impl; + struct st_tx_video_session_impl *s; int quota_mbs, ret; uint64_t bps; notice("%s, start for %s\n", __func__, mt_string_safe(ops->name)); @@ -3981,8 +4195,8 @@ st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops* ops) { return NULL; } int height = ops->interlaced ? (ops->height >> 1) : ops->height; - ret = st20_get_bandwidth_bps(ops->width, height, ops->fmt, ops->fps, ops->interlaced, - &bps); + ret = st20_get_bandwidth_bps(ops->width, height, ops->fmt, ops->fps, + ops->interlaced, &bps); if (ret < 0) { err("%s, st20_get_bandwidth_bps fail\n", __func__); return NULL; @@ -3991,12 +4205,14 @@ st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops* ops) { quota_mbs *= ops->num_port; if (!mt_user_quota_active(impl)) { if (ST20_TYPE_RTP_LEVEL == ops->type) { - quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; + quota_mbs = + quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; } } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20_TX_FLAG_FORCE_NUMA) { @@ -4010,8 +4226,8 @@ st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops* ops) { return NULL; } - sch = - mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); + sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, + MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -4057,9 +4273,9 @@ st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops* ops) { } int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, - struct st20_ext_frame* ext_frame) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct st_tx_video_session_impl* s; + struct st20_ext_frame *ext_frame) { + struct st_tx_video_session_handle_impl *s_impl = handle; + struct st_tx_video_session_impl *s; int s_idx; if (s_impl->type != MT_HANDLE_TX_VIDEO) { @@ -4076,40 +4292,44 @@ int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, s_idx = s->idx; if (ext_frame->buf_len < s->st20_fb_size) { - err("%s(%d), ext framebuffer size %" PRIu64 " can not hold frame, need %" PRIu64 "\n", + err("%s(%d), ext framebuffer size %" PRIu64 + " can not hold frame, need %" PRIu64 "\n", __func__, s_idx, ext_frame->buf_len, s->st20_fb_size); return -EIO; } - void* addr = ext_frame->buf_addr; + void *addr = ext_frame->buf_addr; if (!addr) { err("%s(%d), invalid ext frame address\n", __func__, s_idx); return -EIO; } rte_iova_t iova_addr = ext_frame->buf_iova; if (iova_addr == MTL_BAD_IOVA || iova_addr == 0) { - err("%s(%d), invalid ext frame iova 0x%" PRIx64 "\n", __func__, s_idx, iova_addr); + err("%s(%d), invalid ext frame iova 0x%" PRIx64 "\n", __func__, s_idx, + iova_addr); return -EIO; } for (int i = 0; i < s->st20_frames_cnt; i++) { if (addr == s->st20_frames[i].addr) { - warn_once("%s(%d), buffer %p still in tansport!\n", __func__, s_idx, addr); + warn_once("%s(%d), buffer %p still in tansport!\n", __func__, s_idx, + addr); } } if (idx >= s->st20_frames_cnt) { - err("%s(%d), invalid idx %d, should be in range [0, %d]\n", __func__, s_idx, idx, - s->st20_frames_cnt); + err("%s(%d), invalid idx %d, should be in range [0, %d]\n", __func__, s_idx, + idx, s->st20_frames_cnt); return -EIO; } if (!s->st20_frames) { err("%s(%d), st20_frames not valid\n", __func__, s_idx); return -EINVAL; } - struct st_frame_trans* frame = &s->st20_frames[idx]; + struct st_frame_trans *frame = &s->st20_frames[idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %d are not free, refcnt %d\n", __func__, s_idx, idx, refcnt); + err("%s(%d), frame %d are not free, refcnt %d\n", __func__, s_idx, idx, + refcnt); return -EINVAL; } if (!(frame->flags & ST_FT_FLAG_EXT)) { @@ -4122,9 +4342,9 @@ int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, return 0; } -void* st20_tx_get_framebuffer(st20_tx_handle handle, uint16_t idx) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct st_tx_video_session_impl* s; +void *st20_tx_get_framebuffer(st20_tx_handle handle, uint16_t idx) { + struct st_tx_video_session_handle_impl *s_impl = handle; + struct st_tx_video_session_impl *s; if (s_impl->type != MT_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4147,8 +4367,8 @@ void* st20_tx_get_framebuffer(st20_tx_handle handle, uint16_t idx) { } size_t st20_tx_get_framebuffer_size(st20_tx_handle handle) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct st_tx_video_session_impl* s; + struct st_tx_video_session_handle_impl *s_impl = handle; + struct st_tx_video_session_impl *s; if (s_impl->type != MT_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4160,8 +4380,8 @@ size_t st20_tx_get_framebuffer_size(st20_tx_handle handle) { } int st20_tx_get_framebuffer_count(st20_tx_handle handle) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct st_tx_video_session_impl* s; + struct st_tx_video_session_handle_impl *s_impl = handle; + struct st_tx_video_session_impl *s; if (s_impl->type != MT_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4172,12 +4392,12 @@ int st20_tx_get_framebuffer_count(st20_tx_handle handle) { return s->st20_frames_cnt; } -void* st20_tx_get_mbuf(st20_tx_handle handle, void** usrptr) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt; - struct st_tx_video_session_impl* s; +void *st20_tx_get_mbuf(st20_tx_handle handle, void **usrptr) { + struct st_tx_video_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt; + struct st_tx_video_session_impl *s; int idx; - struct rte_ring* packet_ring; + struct rte_ring *packet_ring; if (s_impl->type != MT_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4197,8 +4417,9 @@ void* st20_tx_get_mbuf(st20_tx_handle handle, void** usrptr) { return NULL; } - struct rte_mempool* mp = - s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; + struct rte_mempool *mp = s->tx_no_chain + ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] + : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -4206,19 +4427,20 @@ void* st20_tx_get_mbuf(st20_tx_handle handle, void** usrptr) { } size_t hdr_offset = s->tx_no_chain ? sizeof(struct mt_udp_hdr) : 0; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, hdr_offset); + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, hdr_offset); return pkt; } -int st20_tx_put_mbuf(st20_tx_handle handle, void* mbuf, uint16_t len) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; - struct st_tx_video_session_impl* s; - struct rte_ring* packet_ring; +int st20_tx_put_mbuf(st20_tx_handle handle, void *mbuf, uint16_t len) { + struct st_tx_video_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; + struct st_tx_video_session_impl *s; + struct rte_ring *packet_ring; int idx, ret; if (!mt_rtp_len_valid(len)) { - if (len) err("%s, invalid len %d\n", __func__, len); + if (len) + err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -4239,15 +4461,17 @@ int st20_tx_put_mbuf(st20_tx_handle handle, void* mbuf, uint16_t len) { } if (len > s->rtp_pkt_max_size) { - err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, s->rtp_pkt_max_size); + err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, + s->rtp_pkt_max_size); rte_pktmbuf_free(mbuf); return -EIO; } - if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) + len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; - ret = rte_ring_sp_enqueue(packet_ring, (void*)pkt); + ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); if (ret < 0) { err("%s(%d), can not enqueue to the rte ring\n", __func__, idx); rte_pktmbuf_free(mbuf); @@ -4258,7 +4482,7 @@ int st20_tx_put_mbuf(st20_tx_handle handle, void* mbuf, uint16_t len) { } int st20_tx_get_sch_idx(st20_tx_handle handle) { - struct st_tx_video_session_handle_impl* s_impl = handle; + struct st_tx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4269,14 +4493,14 @@ int st20_tx_get_sch_idx(st20_tx_handle handle) { } int st20_tx_get_port_stats(st20_tx_handle handle, enum mtl_session_port port, - struct st20_tx_port_status* stats) { - struct st_tx_video_session_handle_impl* s_impl = handle; + struct st20_tx_port_status *stats) { + struct st_tx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); return -EINVAL; } - struct st_tx_video_session_impl* s = s_impl->impl; + struct st_tx_video_session_impl *s = s_impl->impl; if (port >= s->ops.num_port) { err("%s, invalid port %d\n", __func__, port); return -EIO; @@ -4286,14 +4510,15 @@ int st20_tx_get_port_stats(st20_tx_handle handle, enum mtl_session_port port, return 0; } -int st20_tx_reset_port_stats(st20_tx_handle handle, enum mtl_session_port port) { - struct st_tx_video_session_handle_impl* s_impl = handle; +int st20_tx_reset_port_stats(st20_tx_handle handle, + enum mtl_session_port port) { + struct st_tx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); return -EINVAL; } - struct st_tx_video_session_impl* s = s_impl->impl; + struct st_tx_video_session_impl *s = s_impl->impl; if (port >= s->ops.num_port) { err("%s, invalid port %d\n", __func__, port); return -EIO; @@ -4304,10 +4529,10 @@ int st20_tx_reset_port_stats(st20_tx_handle handle, enum mtl_session_port port) } int st20_tx_free(st20_tx_handle handle) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct mtl_main_impl* impl; - struct mtl_sch_impl* sch; - struct st_tx_video_session_impl* s; + struct st_tx_video_session_handle_impl *s_impl = handle; + struct mtl_main_impl *impl; + struct mtl_sch_impl *sch; + struct st_tx_video_session_impl *s; int ret, sch_idx, idx; if (s_impl->type != MT_HANDLE_TX_VIDEO) { @@ -4325,10 +4550,12 @@ int st20_tx_free(st20_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_video_mgr_mutex); ret = tv_mgr_detach(&sch->tx_video_mgr, s); mt_pthread_mutex_unlock(&sch->tx_video_mgr_mutex); - if (ret < 0) err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4342,9 +4569,10 @@ int st20_tx_free(st20_tx_handle handle) { return 0; } -int st20_tx_update_destination(st20_tx_handle handle, struct st_tx_dest_info* dst) { - struct st_tx_video_session_handle_impl* s_impl = handle; - struct st_tx_video_session_impl* s; +int st20_tx_update_destination(st20_tx_handle handle, + struct st_tx_dest_info *dst) { + struct st_tx_video_session_handle_impl *s_impl = handle; + struct st_tx_video_session_impl *s; int idx, ret, sch_idx; if (s_impl->type != MT_HANDLE_TX_VIDEO) { @@ -4357,7 +4585,8 @@ int st20_tx_update_destination(st20_tx_handle handle, struct st_tx_dest_info* ds sch_idx = s_impl->sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = tv_mgr_update_dst(&s_impl->sch->tx_video_mgr, s, dst); if (ret < 0) { @@ -4369,11 +4598,11 @@ int st20_tx_update_destination(st20_tx_handle handle, struct st_tx_dest_info* ds return 0; } -st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops) { - struct mtl_main_impl* impl = mt; - struct mtl_sch_impl* sch; - struct st22_tx_video_session_handle_impl* s_impl; - struct st_tx_video_session_impl* s; +st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops) { + struct mtl_main_impl *impl = mt; + struct mtl_sch_impl *sch; + struct st22_tx_video_session_handle_impl *s_impl; + struct st_tx_video_session_impl *s; int quota_mbs, ret; uint64_t bps; struct st20_tx_ops st20_ops; @@ -4391,8 +4620,8 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops) { } if (ST22_TYPE_RTP_LEVEL == ops->type) { - ret = st22_rtp_bandwidth_bps(ops->rtp_frame_total_pkts, ops->rtp_pkt_size, ops->fps, - &bps); + ret = st22_rtp_bandwidth_bps(ops->rtp_frame_total_pkts, ops->rtp_pkt_size, + ops->fps, &bps); if (ret < 0) { err("%s, rtp_bandwidth_bps fail\n", __func__); return NULL; @@ -4400,7 +4629,8 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops) { quota_mbs = bps / (1000 * 1000); quota_mbs *= ops->num_port; if (!mt_user_quota_active(impl)) { - quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; + quota_mbs = + quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; } } else { ret = st22_frame_bandwidth_bps(ops->framebuff_max_size, ops->fps, &bps); @@ -4413,7 +4643,8 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) return NULL; + if (port >= MTL_PORT_MAX) + return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22_TX_FLAG_FORCE_NUMA) { @@ -4427,8 +4658,8 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops) { return NULL; } - sch = - mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); + sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, + MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -4468,15 +4699,18 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops) { st20_ops.flags |= ST20_TX_FLAG_USER_R_MAC; } } - if (ops->flags & ST22_TX_FLAG_USER_PACING) st20_ops.flags |= ST20_TX_FLAG_USER_PACING; + if (ops->flags & ST22_TX_FLAG_USER_PACING) + st20_ops.flags |= ST20_TX_FLAG_USER_PACING; if (ops->flags & ST22_TX_FLAG_USER_TIMESTAMP) st20_ops.flags |= ST20_TX_FLAG_USER_TIMESTAMP; - if (ops->flags & ST22_TX_FLAG_ENABLE_VSYNC) st20_ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22_TX_FLAG_ENABLE_VSYNC) + st20_ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22_TX_FLAG_ENABLE_RTCP) { st20_ops.flags |= ST20_TX_FLAG_ENABLE_RTCP; st20_ops.rtcp = ops->rtcp; } - if (ops->flags & ST22_TX_FLAG_DISABLE_BULK) st20_ops.flags |= ST20_TX_FLAG_DISABLE_BULK; + if (ops->flags & ST22_TX_FLAG_DISABLE_BULK) + st20_ops.flags |= ST20_TX_FLAG_DISABLE_BULK; st20_ops.pacing = ops->pacing; if (ST22_TYPE_RTP_LEVEL == ops->type) st20_ops.type = ST20_TYPE_RTP_LEVEL; @@ -4522,10 +4756,10 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops* ops) { } int st22_tx_free(st22_tx_handle handle) { - struct st22_tx_video_session_handle_impl* s_impl = handle; - struct mtl_main_impl* impl; - struct mtl_sch_impl* sch; - struct st_tx_video_session_impl* s; + struct st22_tx_video_session_handle_impl *s_impl = handle; + struct mtl_main_impl *impl; + struct mtl_sch_impl *sch; + struct st_tx_video_session_impl *s; int ret, sch_idx, idx; if (s_impl->type != MT_ST22_HANDLE_TX_VIDEO) { @@ -4543,10 +4777,12 @@ int st22_tx_free(st22_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_video_mgr_mutex); ret = tv_mgr_detach(&sch->tx_video_mgr, s); mt_pthread_mutex_unlock(&sch->tx_video_mgr_mutex); - if (ret < 0) err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) + err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4560,9 +4796,10 @@ int st22_tx_free(st22_tx_handle handle) { return 0; } -int st22_tx_update_destination(st22_tx_handle handle, struct st_tx_dest_info* dst) { - struct st22_tx_video_session_handle_impl* s_impl = handle; - struct st_tx_video_session_impl* s; +int st22_tx_update_destination(st22_tx_handle handle, + struct st_tx_dest_info *dst) { + struct st22_tx_video_session_handle_impl *s_impl = handle; + struct st_tx_video_session_impl *s; int idx, ret, sch_idx; if (s_impl->type != MT_ST22_HANDLE_TX_VIDEO) { @@ -4575,7 +4812,8 @@ int st22_tx_update_destination(st22_tx_handle handle, struct st_tx_dest_info* ds sch_idx = s_impl->sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = tv_mgr_update_dst(&s_impl->sch->tx_video_mgr, s, dst); if (ret < 0) { @@ -4587,12 +4825,12 @@ int st22_tx_update_destination(st22_tx_handle handle, struct st_tx_dest_info* ds return 0; } -void* st22_tx_get_mbuf(st22_tx_handle handle, void** usrptr) { - struct st22_tx_video_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt; - struct st_tx_video_session_impl* s; +void *st22_tx_get_mbuf(st22_tx_handle handle, void **usrptr) { + struct st22_tx_video_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt; + struct st_tx_video_session_impl *s; int idx; - struct rte_ring* packet_ring; + struct rte_ring *packet_ring; if (s_impl->type != MT_ST22_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4612,8 +4850,9 @@ void* st22_tx_get_mbuf(st22_tx_handle handle, void** usrptr) { return NULL; } - struct rte_mempool* mp = - s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; + struct rte_mempool *mp = s->tx_no_chain + ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] + : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -4621,19 +4860,20 @@ void* st22_tx_get_mbuf(st22_tx_handle handle, void** usrptr) { } size_t hdr_offset = s->tx_no_chain ? sizeof(struct mt_udp_hdr) : 0; - *usrptr = rte_pktmbuf_mtod_offset(pkt, void*, hdr_offset); + *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, hdr_offset); return pkt; } -int st22_tx_put_mbuf(st22_tx_handle handle, void* mbuf, uint16_t len) { - struct st22_tx_video_session_handle_impl* s_impl = handle; - struct rte_mbuf* pkt = (struct rte_mbuf*)mbuf; - struct st_tx_video_session_impl* s; - struct rte_ring* packet_ring; +int st22_tx_put_mbuf(st22_tx_handle handle, void *mbuf, uint16_t len) { + struct st22_tx_video_session_handle_impl *s_impl = handle; + struct rte_mbuf *pkt = (struct rte_mbuf *)mbuf; + struct st_tx_video_session_impl *s; + struct rte_ring *packet_ring; int idx, ret; if (!mt_rtp_len_valid(len)) { - if (len) err("%s, invalid len %d\n", __func__, len); + if (len) + err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -4654,15 +4894,17 @@ int st22_tx_put_mbuf(st22_tx_handle handle, void* mbuf, uint16_t len) { } if (len > s->rtp_pkt_max_size) { - err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, s->rtp_pkt_max_size); + err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, + s->rtp_pkt_max_size); rte_pktmbuf_free(mbuf); return -EIO; } - if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) + len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; - ret = rte_ring_sp_enqueue(packet_ring, (void*)pkt); + ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); if (ret < 0) { err("%s(%d), can not enqueue to the rte ring\n", __func__, idx); rte_pktmbuf_free(mbuf); @@ -4673,7 +4915,7 @@ int st22_tx_put_mbuf(st22_tx_handle handle, void* mbuf, uint16_t len) { } int st22_tx_get_sch_idx(st22_tx_handle handle) { - struct st22_tx_video_session_handle_impl* s_impl = handle; + struct st22_tx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_ST22_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); @@ -4683,9 +4925,9 @@ int st22_tx_get_sch_idx(st22_tx_handle handle) { return s_impl->sch->idx; } -void* st22_tx_get_fb_addr(st22_tx_handle handle, uint16_t idx) { - struct st22_tx_video_session_handle_impl* s_impl = handle; - struct st_tx_video_session_impl* s; +void *st22_tx_get_fb_addr(st22_tx_handle handle, uint16_t idx) { + struct st22_tx_video_session_handle_impl *s_impl = handle; + struct st_tx_video_session_impl *s; if (s_impl->type != MT_ST22_HANDLE_TX_VIDEO) { err("%s, invalid type %d\n", __func__, s_impl->type); diff --git a/lib/src/st2110/st_tx_video_session.h b/lib/src/st2110/st_tx_video_session.h index f5247a9dd..a306a54fa 100644 --- a/lib/src/st2110/st_tx_video_session.h +++ b/lib/src/st2110/st_tx_video_session.h @@ -12,42 +12,50 @@ #define ST_TX_VIDEO_RTCP_BURST_SIZE (32) #define ST_TX_VIDEO_RTCP_RING_SIZE (1024) -int st_tx_video_sessions_sch_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch); +int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch); -int st_tx_video_sessions_sch_uinit(struct mtl_main_impl* impl, struct mtl_sch_impl* sch); +int st_tx_video_sessions_sch_uinit(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch); /* call tx_video_session_put always if get successfully */ -static inline struct st_tx_video_session_impl* tx_video_session_get( - struct st_tx_video_sessions_mgr* mgr, int idx) { +static inline struct st_tx_video_session_impl * +tx_video_session_get(struct st_tx_video_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_tx_video_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); + struct st_tx_video_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_video_session_put always if get successfully */ -static inline struct st_tx_video_session_impl* tx_video_session_try_get( - struct st_tx_video_sessions_mgr* mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; - struct st_tx_video_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_tx_video_session_impl * +tx_video_session_try_get(struct st_tx_video_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) + return NULL; + struct st_tx_video_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_video_session_put always if get successfully */ -static inline struct st_tx_video_session_impl* tx_video_session_get_timeout( - struct st_tx_video_sessions_mgr* mgr, int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; - struct st_tx_video_session_impl* s = mgr->sessions[idx]; - if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); +static inline struct st_tx_video_session_impl * +tx_video_session_get_timeout(struct st_tx_video_sessions_mgr *mgr, int idx, + int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) + return NULL; + struct st_tx_video_session_impl *s = mgr->sessions[idx]; + if (!s) + rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_video_session_put always if get successfully */ -static inline bool tx_video_session_get_empty(struct st_tx_video_sessions_mgr* mgr, - int idx) { +static inline bool +tx_video_session_get_empty(struct st_tx_video_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); - struct st_tx_video_session_impl* s = mgr->sessions[idx]; + struct st_tx_video_session_impl *s = mgr->sessions[idx]; if (s) { rte_spinlock_unlock(&mgr->mutex[idx]); /* not null, unlock it */ return false; @@ -56,29 +64,33 @@ static inline bool tx_video_session_get_empty(struct st_tx_video_sessions_mgr* m } } -static inline void tx_video_session_put(struct st_tx_video_sessions_mgr* mgr, int idx) { +static inline void tx_video_session_put(struct st_tx_video_sessions_mgr *mgr, + int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -void tx_video_session_cal_cpu_busy(struct mtl_sch_impl* sch, - struct st_tx_video_session_impl* s); -void tx_video_session_clear_cpu_busy(struct st_tx_video_session_impl* s); +void tx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, + struct st_tx_video_session_impl *s); +void tx_video_session_clear_cpu_busy(struct st_tx_video_session_impl *s); -static inline bool tx_video_session_is_cpu_busy(struct st_tx_video_session_impl* s) { - if (s->cpu_busy_score > 95.0) return true; +static inline bool +tx_video_session_is_cpu_busy(struct st_tx_video_session_impl *s) { + if (s->cpu_busy_score > 95.0) + return true; return false; } -static inline float tx_video_session_get_cpu_busy(struct st_tx_video_session_impl* s) { +static inline float +tx_video_session_get_cpu_busy(struct st_tx_video_session_impl *s) { return s->cpu_busy_score; } -int st_tx_video_session_migrate(struct st_tx_video_sessions_mgr* mgr, - struct st_tx_video_session_impl* s, int idx); +int st_tx_video_session_migrate(struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s, int idx); -int st20_pacing_static_profiling(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +int st20_pacing_static_profiling(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port); #endif diff --git a/lib/src/st2110/st_video_transmitter.c b/lib/src/st2110/st_video_transmitter.c index efaadec62..7c330e081 100644 --- a/lib/src/st2110/st_video_transmitter.c +++ b/lib/src/st2110/st_video_transmitter.c @@ -13,25 +13,26 @@ #include "st_err.h" #include "st_tx_video_session.h" -static int video_trs_tasklet_start(void* priv) { - struct st_video_transmitter_impl* trs = priv; +static int video_trs_tasklet_start(void *priv) { + struct st_video_transmitter_impl *trs = priv; int idx = trs->idx; info("%s(%d), succ\n", __func__, idx); return 0; } -static int video_trs_tasklet_stop(void* priv) { - struct st_video_transmitter_impl* trs = priv; +static int video_trs_tasklet_stop(void *priv) { + struct st_video_transmitter_impl *trs = priv; int idx = trs->idx; info("%s(%d), succ\n", __func__, idx); return 0; } -static uint16_t video_trs_burst_fail(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, - enum mtl_session_port s_port, uint16_t nb_pkts) { +static uint16_t video_trs_burst_fail(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, + uint16_t nb_pkts) { uint64_t cur_tsc = mt_get_tsc(impl); uint64_t fail_duration = cur_tsc - s->last_burst_succ_time_tsc[s_port]; @@ -46,25 +47,29 @@ static uint16_t video_trs_burst_fail(struct mtl_main_impl* impl, return 0; } -static uint16_t video_trs_burst_pad(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +static uint16_t video_trs_burst_pad(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port, - struct rte_mbuf** tx_pkts, uint16_t nb_pkts) { + struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { uint16_t tx = mt_txq_burst(s->queue[s_port], tx_pkts, nb_pkts); - if (!tx) return video_trs_burst_fail(impl, s, s_port, nb_pkts); + if (!tx) + return video_trs_burst_fail(impl, s, s_port, nb_pkts); return tx; } /* for normal pkts, pad should call the video_trs_burst_pad */ -static uint16_t video_trs_burst(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, - enum mtl_session_port s_port, struct rte_mbuf** tx_pkts, - uint16_t nb_pkts) { - if (s->rtcp_tx[s_port]) mt_mbuf_refcnt_inc_bulk(tx_pkts, nb_pkts); +static uint16_t video_trs_burst(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { + if (s->rtcp_tx[s_port]) + mt_mbuf_refcnt_inc_bulk(tx_pkts, nb_pkts); uint16_t tx = mt_txq_burst(s->queue[s_port], tx_pkts, nb_pkts); s->stat_pkts_burst += tx; if (!tx) { - if (s->rtcp_tx[s_port]) rte_pktmbuf_free_bulk(tx_pkts, nb_pkts); + if (s->rtcp_tx[s_port]) + rte_pktmbuf_free_bulk(tx_pkts, nb_pkts); return video_trs_burst_fail(impl, s, s_port, nb_pkts); } @@ -75,8 +80,9 @@ static uint16_t video_trs_burst(struct mtl_main_impl* impl, int pkt_idx = st_tx_mbuf_get_idx(tx_pkts[0]); if (0 == pkt_idx) { - struct st_frame_trans* frame = st_tx_mbuf_get_priv(tx_pkts[0]); - if (frame) st20_frame_tx_start(impl, s, s_port, frame); + struct st_frame_trans *frame = st_tx_mbuf_get_priv(tx_pkts[0]); + if (frame) + st20_frame_tx_start(impl, s, s_port, frame); } for (uint16_t i = 0; i < tx; i++) { @@ -88,16 +94,16 @@ static uint16_t video_trs_burst(struct mtl_main_impl* impl, } /* warm start for the first packet */ -static int video_trs_rl_warm_up(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +static int video_trs_rl_warm_up(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { - struct st_tx_video_pacing* pacing = &s->pacing; + struct st_tx_video_pacing *pacing = &s->pacing; uint64_t target_ptp = s->trs_target_ptp[s_port]; uint64_t target_tsc = s->trs_target_tsc[s_port]; uint64_t cur_tsc, pre_tsc; uint64_t cur_ptp; int32_t warm_pkts = pacing->warm_pkts; - struct rte_mbuf* pads[1]; + struct rte_mbuf *pads[1]; int32_t delta_pkts; unsigned int tx; bool warm_use_tsc = true; @@ -134,18 +140,19 @@ static int video_trs_rl_warm_up(struct mtl_main_impl* impl, if (delta_pkts > i) { warm_pkts -= (delta_pkts - i); s->stat_trans_recalculate_warmup++; - dbg("%s(%d), mismatch delta_pkts %d at %d\n", __func__, s->idx, delta_pkts, i); + dbg("%s(%d), mismatch delta_pkts %d at %d\n", __func__, s->idx, + delta_pkts, i); } } return 0; } -static int video_burst_packet(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, - enum mtl_session_port s_port, struct rte_mbuf** pkts, - int bulk, bool use_two) { - struct st_tx_video_pacing* pacing = &s->pacing; +static int video_burst_packet(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, + struct rte_mbuf **pkts, int bulk, bool use_two) { + struct st_tx_video_pacing *pacing = &s->pacing; int tx = video_trs_burst(impl, s, s_port, &pkts[0], bulk); int pkt_idx = st_tx_mbuf_get_idx(pkts[0]); @@ -157,39 +164,46 @@ static int video_burst_packet(struct mtl_main_impl* impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) + s->trs_inflight[s_port][i] = pkts[tx + i]; } else { s->trs_inflight_num2[s_port] = remaining; s->trs_inflight_idx2[s_port] = 0; s->trs_inflight_cnt2[s_port]++; - for (i = 0; i < remaining; i++) s->trs_inflight2[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) + s->trs_inflight2[s_port][i] = pkts[tx + i]; } } /* check if it need insert padding packet */ - if (fmodf(pkt_idx + 1 + pacing->pad_interval / 2, pacing->pad_interval) < bulk) { + if (fmodf(pkt_idx + 1 + pacing->pad_interval / 2, pacing->pad_interval) < + bulk) { rte_mbuf_refcnt_update(s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); - tx = video_trs_burst_pad(impl, s, s_port, &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); - if (tx < 1) s->trs_pad_inflight_num[s_port]++; + tx = video_trs_burst_pad(impl, s, s_port, + &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); + if (tx < 1) + s->trs_pad_inflight_num[s_port]++; } return 0; } -static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, - enum mtl_session_port s_port, int* ret_status) { +static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, + int *ret_status) { unsigned int bulk = s->bulk; - struct rte_ring* ring = s->ring[s_port]; + struct rte_ring *ring = s->ring[s_port]; int idx = s->idx; unsigned int n, tx; uint32_t pkt_idx = 0; /* check if any inflight pkts in transmitter inflight 2 */ if (s->trs_inflight_num2[s_port] > 0) { - tx = video_trs_burst(impl, s, s_port, - &s->trs_inflight2[s_port][s->trs_inflight_idx2[s_port]], - s->trs_inflight_num2[s_port]); + tx = + video_trs_burst(impl, s, s_port, + &s->trs_inflight2[s_port][s->trs_inflight_idx2[s_port]], + s->trs_inflight_num2[s_port]); s->trs_inflight_num2[s_port] -= tx; s->trs_inflight_idx2[s_port] += tx; if (tx > 0) { @@ -211,8 +225,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", + __func__, idx, cur_tsc, target_tsc); } } video_trs_rl_warm_up(impl, s, s_port); @@ -223,7 +237,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, if (s->trs_pad_inflight_num[s_port] > 0) { dbg("%s(%d), inflight padding pkts %d\n", __func__, idx, s->trs_pad_inflight_num[s_port]); - tx = video_trs_burst_pad(impl, s, s_port, &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); + tx = video_trs_burst_pad(impl, s, s_port, + &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); s->trs_pad_inflight_num[s_port] -= tx; if (tx > 0) { return MTL_TASKLET_HAS_PENDING; @@ -249,8 +264,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, } /* dequeue from ring */ - struct rte_mbuf* pkts[bulk]; - n = mt_rte_ring_sc_dequeue_bulk(ring, (void**)&pkts[0], bulk, NULL); + struct rte_mbuf *pkts[bulk]; + n = mt_rte_ring_sc_dequeue_bulk(ring, (void **)&pkts[0], bulk, NULL); if (n == 0) { *ret_status = -STI_RLTRS_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; @@ -261,13 +276,15 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, pkt_idx = st_tx_mbuf_get_idx(pkts[i]); if ((pkt_idx == 0) || (pkt_idx == ST_TX_DUMMY_PKT_IDX)) { valid_bulk = i; - break; /* break if it's the first pkt of frame or it's the start of dummy */ + break; /* break if it's the first pkt of frame or it's the start of dummy + */ } } - dbg("%s(%d), pkt_idx %u valid_bulk %d ts %" PRIu64 "\n", __func__, idx, pkt_idx, - valid_bulk, st_tx_mbuf_get_tsc(pkts[0])); + dbg("%s(%d), pkt_idx %u valid_bulk %d ts %" PRIu64 "\n", __func__, idx, + pkt_idx, valid_bulk, st_tx_mbuf_get_tsc(pkts[0])); - /* builder always build bulk pkts per enqueue, pkts after dummy are all dummy */ + /* builder always build bulk pkts per enqueue, pkts after dummy are all dummy + */ if (unlikely(pkt_idx == ST_TX_DUMMY_PKT_IDX)) { video_burst_packet(impl, s, s_port, pkts, valid_bulk, false); rte_pktmbuf_free_bulk(&pkts[valid_bulk], bulk - valid_bulk); @@ -285,8 +302,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, } uint64_t target_tsc = st_tx_mbuf_get_tsc(pkts[valid_bulk]); uint64_t target_ptp = st_tx_mbuf_get_ptp(pkts[valid_bulk]); - dbg("%s(%d), first pkt, ts cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + dbg("%s(%d), first pkt, ts cur %" PRIu64 " target %" PRIu64 "\n", __func__, + idx, cur_tsc, target_tsc); if (likely(cur_tsc < target_tsc || s->trs_inflight_num2[s_port])) { unsigned int i; uint64_t delta = target_tsc - cur_tsc; @@ -304,7 +321,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc for first pkt cur %" PRIu64 " target %" PRIu64 "\n", + err("%s(%d), invalid tsc for first pkt cur %" PRIu64 " target %" PRIu64 + "\n", __func__, idx, cur_tsc, target_tsc); } } else { @@ -320,8 +338,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl* impl, return MTL_TASKLET_HAS_PENDING; } -static int video_trs_rl_tasklet(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +static int video_trs_rl_tasklet(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { int pending = MTL_TASKLET_ALL_DONE; int ret_status = 0; @@ -339,12 +357,13 @@ static int video_trs_rl_tasklet(struct mtl_main_impl* impl, return pending; } -static int video_trs_tsc_tasklet(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +static int video_trs_tsc_tasklet(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { unsigned int bulk = s->bulk; - if (s->pacing_way[s_port] == ST21_TX_PACING_WAY_BE) bulk = 1; - struct rte_ring* ring = s->ring[s_port]; + if (s->pacing_way[s_port] == ST21_TX_PACING_WAY_BE) + bulk = 1; + struct rte_ring *ring = s->ring[s_port]; int idx = s->idx, tx; unsigned int n; uint64_t target_tsc, cur_tsc; @@ -360,8 +379,8 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl* impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", + __func__, idx, cur_tsc, target_tsc); } } s->trs_target_tsc[s_port] = 0; @@ -383,8 +402,8 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl* impl, } /* dequeue from ring */ - struct rte_mbuf* pkts[bulk]; - n = mt_rte_ring_sc_dequeue_bulk(ring, (void**)&pkts[0], bulk, NULL); + struct rte_mbuf *pkts[bulk]; + n = mt_rte_ring_sc_dequeue_bulk(ring, (void **)&pkts[0], bulk, NULL); if (n == 0) { s->stat_trs_ret_code[s_port] = -STI_TSCTRS_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; @@ -420,13 +439,14 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl* impl, s->trs_inflight_num[s_port] = valid_bulk; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < valid_bulk; i++) s->trs_inflight[s_port][i] = pkts[i]; + for (i = 0; i < valid_bulk; i++) + s->trs_inflight[s_port][i] = pkts[i]; s->stat_trs_ret_code[s_port] = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", + __func__, idx, cur_tsc, target_tsc); } } } @@ -440,23 +460,24 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl* impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) + s->trs_inflight[s_port][i] = pkts[tx + i]; } return MTL_TASKLET_HAS_PENDING; } -static int video_trs_launch_time_tasklet(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +static int video_trs_launch_time_tasklet(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { unsigned int bulk = s->bulk; - struct rte_ring* ring = s->ring[s_port]; + struct rte_ring *ring = s->ring[s_port]; int tx = 0; unsigned int n; uint64_t i; uint64_t target_ptp; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); - struct mt_interface* inf = mt_if(impl, port); + struct mt_interface *inf = mt_if(impl, port); if (!mt_ptp_is_locked(impl, MTL_PORT_P)) { /* fallback to tsc if ptp is not synced */ @@ -481,8 +502,8 @@ static int video_trs_launch_time_tasklet(struct mtl_main_impl* impl, } /* dequeue from ring */ - struct rte_mbuf* pkts[bulk]; - n = mt_rte_ring_sc_dequeue_bulk(ring, (void**)&pkts[0], bulk, NULL); + struct rte_mbuf *pkts[bulk]; + n = mt_rte_ring_sc_dequeue_bulk(ring, (void **)&pkts[0], bulk, NULL); if (n == 0) { s->stat_trs_ret_code[s_port] = -STI_TSCTRS_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; @@ -508,7 +529,8 @@ static int video_trs_launch_time_tasklet(struct mtl_main_impl* impl, target_ptp = st_tx_mbuf_get_ptp(pkts[i]); /* Put tx timestamp into transmit descriptor */ pkts[i]->ol_flags |= inf->tx_launch_time_flag; - *RTE_MBUF_DYNFIELD(pkts[i], inf->tx_dynfield_offset, uint64_t*) = target_ptp; + *RTE_MBUF_DYNFIELD(pkts[i], inf->tx_dynfield_offset, uint64_t *) = + target_ptp; } tx = video_trs_burst(impl, s, s_port, &pkts[0], valid_bulk); @@ -519,7 +541,8 @@ static int video_trs_launch_time_tasklet(struct mtl_main_impl* impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) + s->trs_inflight[s_port][i] = pkts[tx + i]; } } @@ -532,11 +555,11 @@ static int video_trs_launch_time_tasklet(struct mtl_main_impl* impl, } } -static int video_trs_ptp_tasklet(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +static int video_trs_ptp_tasklet(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { unsigned int bulk = s->bulk; - struct rte_ring* ring = s->ring[s_port]; + struct rte_ring *ring = s->ring[s_port]; int idx = s->idx, tx; unsigned int n; uint64_t target_ptp, cur_ptp; @@ -552,8 +575,8 @@ static int video_trs_ptp_tasklet(struct mtl_main_impl* impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_ptp, target_ptp); + err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", + __func__, idx, cur_ptp, target_ptp); } } s->trs_target_tsc[s_port] = 0; @@ -575,8 +598,8 @@ static int video_trs_ptp_tasklet(struct mtl_main_impl* impl, } /* dequeue from ring */ - struct rte_mbuf* pkts[bulk]; - n = mt_rte_ring_sc_dequeue_bulk(ring, (void**)&pkts[0], bulk, NULL); + struct rte_mbuf *pkts[bulk]; + n = mt_rte_ring_sc_dequeue_bulk(ring, (void **)&pkts[0], bulk, NULL); if (n == 0) { s->stat_trs_ret_code[s_port] = -STI_TSCTRS_DEQUEUE_FAIL; return MTL_TASKLET_ALL_DONE; @@ -611,13 +634,14 @@ static int video_trs_ptp_tasklet(struct mtl_main_impl* impl, s->trs_inflight_num[s_port] = valid_bulk; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < valid_bulk; i++) s->trs_inflight[s_port][i] = pkts[i]; + for (i = 0; i < valid_bulk; i++) + s->trs_inflight[s_port][i] = pkts[i]; s->stat_trs_ret_code[s_port] = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, - cur_ptp, target_ptp); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, + idx, cur_ptp, target_ptp); } } @@ -630,26 +654,29 @@ static int video_trs_ptp_tasklet(struct mtl_main_impl* impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) + s->trs_inflight[s_port][i] = pkts[tx + i]; } return MTL_TASKLET_HAS_PENDING; } -static int video_trs_tasklet_handler(void* priv) { - struct st_video_transmitter_impl* trs = priv; - struct mtl_main_impl* impl = trs->parent; - struct st_tx_video_sessions_mgr* mgr = trs->mgr; - struct st_tx_video_session_impl* s; +static int video_trs_tasklet_handler(void *priv) { + struct st_video_transmitter_impl *trs = priv; + struct mtl_main_impl *impl = trs->parent; + struct st_tx_video_sessions_mgr *mgr = trs->mgr; + struct st_tx_video_session_impl *s; int sidx, s_port; int pending = MTL_TASKLET_ALL_DONE; for (sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_video_session_try_get(mgr, sidx); - if (!s) continue; + if (!s) + continue; for (s_port = 0; s_port < s->ops.num_port; s_port++) { - if (!s->queue[s_port]) continue; + if (!s->queue[s_port]) + continue; pending += s->pacing_tasklet_func[s_port](impl, s, s_port); } tx_video_session_put(mgr, sidx); @@ -658,35 +685,36 @@ static int video_trs_tasklet_handler(void* priv) { return pending; } -int st_video_resolve_pacing_tasklet(struct st_tx_video_session_impl* s, +int st_video_resolve_pacing_tasklet(struct st_tx_video_session_impl *s, enum mtl_session_port port) { int idx = s->idx; switch (s->pacing_way[port]) { - case ST21_TX_PACING_WAY_RL: - s->pacing_tasklet_func[port] = video_trs_rl_tasklet; - break; - case ST21_TX_PACING_WAY_TSN: - s->pacing_tasklet_func[port] = video_trs_launch_time_tasklet; - break; - case ST21_TX_PACING_WAY_TSC: - case ST21_TX_PACING_WAY_BE: - case ST21_TX_PACING_WAY_TSC_NARROW: - s->pacing_tasklet_func[port] = video_trs_tsc_tasklet; - break; - case ST21_TX_PACING_WAY_PTP: - s->pacing_tasklet_func[port] = video_trs_ptp_tasklet; - break; - default: - err("%s(%d), unknow pacing %d\n", __func__, idx, s->pacing_way[port]); - return -EIO; + case ST21_TX_PACING_WAY_RL: + s->pacing_tasklet_func[port] = video_trs_rl_tasklet; + break; + case ST21_TX_PACING_WAY_TSN: + s->pacing_tasklet_func[port] = video_trs_launch_time_tasklet; + break; + case ST21_TX_PACING_WAY_TSC: + case ST21_TX_PACING_WAY_BE: + case ST21_TX_PACING_WAY_TSC_NARROW: + s->pacing_tasklet_func[port] = video_trs_tsc_tasklet; + break; + case ST21_TX_PACING_WAY_PTP: + s->pacing_tasklet_func[port] = video_trs_ptp_tasklet; + break; + default: + err("%s(%d), unknow pacing %d\n", __func__, idx, s->pacing_way[port]); + return -EIO; } return 0; } -int st_video_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_tx_video_sessions_mgr* mgr, - struct st_video_transmitter_impl* trs) { +int st_video_transmitter_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_video_sessions_mgr *mgr, + struct st_video_transmitter_impl *trs) { int idx = sch->idx; struct mtl_tasklet_ops ops; @@ -711,7 +739,7 @@ int st_video_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* s return 0; } -int st_video_transmitter_uinit(struct st_video_transmitter_impl* trs) { +int st_video_transmitter_uinit(struct st_video_transmitter_impl *trs) { int idx = trs->idx; if (trs->tasklet) { diff --git a/lib/src/st2110/st_video_transmitter.h b/lib/src/st2110/st_video_transmitter.h index d9007b22c..84179b7c3 100644 --- a/lib/src/st2110/st_video_transmitter.h +++ b/lib/src/st2110/st_video_transmitter.h @@ -7,19 +7,22 @@ #include "st_main.h" -int st_video_transmitter_init(struct mtl_main_impl* impl, struct mtl_sch_impl* sch, - struct st_tx_video_sessions_mgr* mgr, - struct st_video_transmitter_impl* trs); -int st_video_transmitter_uinit(struct st_video_transmitter_impl* trs); +int st_video_transmitter_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_video_sessions_mgr *mgr, + struct st_video_transmitter_impl *trs); +int st_video_transmitter_uinit(struct st_video_transmitter_impl *trs); -int st_video_resolve_pacing_tasklet(struct st_tx_video_session_impl* s, +int st_video_resolve_pacing_tasklet(struct st_tx_video_session_impl *s, enum mtl_session_port port); -int st20_frame_tx_start(struct mtl_main_impl* impl, struct st_tx_video_session_impl* s, - enum mtl_session_port s_port, struct st_frame_trans* frame); +int st20_frame_tx_start(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, + struct st_frame_trans *frame); -int st20_tx_queue_fatal_error(struct mtl_main_impl* impl, - struct st_tx_video_session_impl* s, +int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, enum mtl_session_port s_port); #endif diff --git a/lib/src/udp/udp_main.c b/lib/src/udp/udp_main.c index 8d7a46a9e..80b734503 100644 --- a/lib/src/udp/udp_main.c +++ b/lib/src/udp/udp_main.c @@ -18,29 +18,29 @@ #define SO_COOKIE 57 #endif -static inline void udp_set_flag(struct mudp_impl* s, uint32_t flag) { +static inline void udp_set_flag(struct mudp_impl *s, uint32_t flag) { s->flags |= flag; } -static inline void udp_clear_flag(struct mudp_impl* s, uint32_t flag) { +static inline void udp_clear_flag(struct mudp_impl *s, uint32_t flag) { s->flags &= ~flag; } -static inline bool udp_get_flag(struct mudp_impl* s, uint32_t flag) { +static inline bool udp_get_flag(struct mudp_impl *s, uint32_t flag) { if (s->flags & flag) return true; else return false; } -static inline bool udp_alive(struct mudp_impl* s) { +static inline bool udp_alive(struct mudp_impl *s) { if (!mt_aborted(s->parent) && s->alive) return true; else return false; } -static inline bool udp_is_fallback(struct mudp_impl* s) { +static inline bool udp_is_fallback(struct mudp_impl *s) { if (s->fallback_fd >= 0) return true; else @@ -64,7 +64,7 @@ int mudp_verify_socket_args(int domain, int type, int protocol) { return 0; } -static int udp_verify_addr(const struct sockaddr_in* addr, socklen_t addrlen) { +static int udp_verify_addr(const struct sockaddr_in *addr, socklen_t addrlen) { if (addr->sin_family != AF_INET) { err("%s, invalid sa_family %d\n", __func__, addr->sin_family); MUDP_ERR_RET(EINVAL); @@ -77,34 +77,40 @@ static int udp_verify_addr(const struct sockaddr_in* addr, socklen_t addrlen) { return 0; } -static int udp_verify_bind_addr(struct mudp_impl* s, const struct sockaddr_in* addr, +static int udp_verify_bind_addr(struct mudp_impl *s, + const struct sockaddr_in *addr, socklen_t addrlen) { int idx = s->idx; int ret; ret = udp_verify_addr(addr, addrlen); - if (ret < 0) return ret; + if (ret < 0) + return ret; - if (!udp_get_flag(s, MUDP_BIND_ADDRESS_CHECK)) return 0; + if (!udp_get_flag(s, MUDP_BIND_ADDRESS_CHECK)) + return 0; /* check if our IP or any IP */ if (addr->sin_addr.s_addr == INADDR_ANY) return 0; /* kernel mcast bind use INADDR_ANY */ /* should we support INADDR_LOOPBACK? */ - if (memcmp(&addr->sin_addr.s_addr, mt_sip_addr(s->parent, s->port), MTL_IP_ADDR_LEN)) { - uint8_t* ip = (uint8_t*)&addr->sin_addr.s_addr; - err("%s(%d), invalid bind ip %u.%u.%u.%u\n", __func__, idx, ip[0], ip[1], ip[2], - ip[3]); + if (memcmp(&addr->sin_addr.s_addr, mt_sip_addr(s->parent, s->port), + MTL_IP_ADDR_LEN)) { + uint8_t *ip = (uint8_t *)&addr->sin_addr.s_addr; + err("%s(%d), invalid bind ip %u.%u.%u.%u\n", __func__, idx, ip[0], ip[1], + ip[2], ip[3]); MUDP_ERR_RET(EINVAL); } return 0; } -static int udp_verify_sendto_args(size_t len, int flags, const struct sockaddr_in* addr, +static int udp_verify_sendto_args(size_t len, int flags, + const struct sockaddr_in *addr, socklen_t addrlen) { int ret = udp_verify_addr(addr, addrlen); - if (ret < 0) return ret; + if (ret < 0) + return ret; if ((len <= 0) || (len > MUDP_MAX_GSO_BYTES)) { err("%s, invalid len %" PRIu64 "\n", __func__, len); @@ -118,7 +124,8 @@ static int udp_verify_sendto_args(size_t len, int flags, const struct sockaddr_i return 0; } -static int udp_verify_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout) { +static int udp_verify_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, + int timeout) { MTL_MAY_UNUSED(timeout); if (!fds) { @@ -140,13 +147,14 @@ static int udp_verify_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeou return 0; } -static int udp_build_tx_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, - struct rte_mbuf* pkt, const void* buf, size_t len, - const struct sockaddr_in* addr_in, int arp_timeout_ms) { - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); - struct rte_ether_hdr* eth = &hdr->eth; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; +static int udp_build_tx_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, + struct rte_mbuf *pkt, const void *buf, size_t len, + const struct sockaddr_in *addr_in, + int arp_timeout_ms) { + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); + struct rte_ether_hdr *eth = &hdr->eth; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; enum mtl_port port = s->port; int idx = s->idx; int ret; @@ -160,16 +168,16 @@ static int udp_build_tx_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, rte_memcpy(hdr, &s->hdr, sizeof(*hdr)); /* eth */ - struct rte_ether_addr* d_addr = mt_eth_d_addr(eth); - uint8_t* dip = (uint8_t*)&addr_in->sin_addr; + struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); + uint8_t *dip = (uint8_t *)&addr_in->sin_addr; if (udp_get_flag(s, MUDP_TX_USER_MAC)) { rte_memcpy(d_addr->addr_bytes, s->user_mac, RTE_ETHER_ADDR_LEN); } else { ret = mt_dst_ip_mac(impl, dip, d_addr, port, arp_timeout_ms); if (ret < 0) { if (arp_timeout_ms) /* log only if not zero timeout */ - err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, ret, dip[0], - dip[1], dip[2], dip[3]); + err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, + ret, dip[0], dip[1], dip[2], dip[3]); s->stat_pkt_arp_fail++; MUDP_ERR_RET(EIO); } @@ -188,7 +196,7 @@ static int udp_build_tx_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, pkt->pkt_len = pkt->data_len; /* copy payload */ - void* payload = &udp[1]; + void *payload = &udp[1]; mtl_memcpy(payload, buf, len); udp->dgram_len = htons(pkt->pkt_len - pkt->l2_len - pkt->l3_len); @@ -202,7 +210,7 @@ static int udp_build_tx_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, return 0; } -static ssize_t udp_msg_len(const struct msghdr* msg) { +static ssize_t udp_msg_len(const struct msghdr *msg) { size_t len = 0; for (int i = 0; i < msg->msg_iovlen; i++) { len += msg->msg_iov[i].iov_len; @@ -210,68 +218,69 @@ static ssize_t udp_msg_len(const struct msghdr* msg) { return len; } -static int udp_cmsg_handle(struct mudp_impl* s, const struct msghdr* msg) { - struct cmsghdr* cmsg = CMSG_FIRSTHDR(msg); - if (!cmsg) return 0; +static int udp_cmsg_handle(struct mudp_impl *s, const struct msghdr *msg) { + struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); + if (!cmsg) + return 0; int idx = s->idx; switch (cmsg->cmsg_level) { - case SOL_UDP: - if (cmsg->cmsg_type == UDP_SEGMENT) { - if (cmsg->cmsg_len == CMSG_LEN(sizeof(uint16_t))) { - uint16_t* p_val = (uint16_t*)CMSG_DATA(cmsg); - uint16_t val = *p_val; - dbg("%s(%d), UDP_SEGMENT val %u\n", __func__, idx, val); - s->gso_segment_sz = val; - } else { - err("%s(%d), unknow cmsg_len %" PRId64 " for UDP_SEGMENT\n", __func__, idx, - cmsg->cmsg_len); - MUDP_ERR_RET(EINVAL); - } + case SOL_UDP: + if (cmsg->cmsg_type == UDP_SEGMENT) { + if (cmsg->cmsg_len == CMSG_LEN(sizeof(uint16_t))) { + uint16_t *p_val = (uint16_t *)CMSG_DATA(cmsg); + uint16_t val = *p_val; + dbg("%s(%d), UDP_SEGMENT val %u\n", __func__, idx, val); + s->gso_segment_sz = val; + } else { + err("%s(%d), unknow cmsg_len %" PRId64 " for UDP_SEGMENT\n", __func__, + idx, cmsg->cmsg_len); + MUDP_ERR_RET(EINVAL); } - break; - default: - break; + } + break; + default: + break; } return 0; } -static int udp_build_tx_msg_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, - struct rte_mbuf** pkts, unsigned int pkts_nb, - const struct msghdr* msg, - const struct sockaddr_in* addr_in, int arp_timeout_ms, - size_t sz_per_pkt) { +static int udp_build_tx_msg_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, + struct rte_mbuf **pkts, unsigned int pkts_nb, + const struct msghdr *msg, + const struct sockaddr_in *addr_in, + int arp_timeout_ms, size_t sz_per_pkt) { enum mtl_port port = s->port; int idx = s->idx; int ret; /* get the dst mac address */ struct rte_ether_addr d_addr; - uint8_t* dip = (uint8_t*)&addr_in->sin_addr; + uint8_t *dip = (uint8_t *)&addr_in->sin_addr; if (udp_get_flag(s, MUDP_TX_USER_MAC)) { rte_memcpy(&d_addr.addr_bytes, s->user_mac, RTE_ETHER_ADDR_LEN); } else { ret = mt_dst_ip_mac(impl, dip, &d_addr, port, arp_timeout_ms); if (ret < 0) { if (arp_timeout_ms) /* log only if not zero timeout */ - err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, ret, dip[0], - dip[1], dip[2], dip[3]); + err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, + ret, dip[0], dip[1], dip[2], dip[3]); s->stat_pkt_arp_fail++; MUDP_ERR_RET(EIO); } } - void* payloads[pkts_nb]; + void *payloads[pkts_nb]; memset(payloads, 0, sizeof(payloads)); /* prvents maybe-uninitialized error */ /* fill hdr info for all pkts */ for (unsigned int i = 0; i < pkts_nb; i++) { - struct rte_mbuf* pkt = pkts[i]; - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); - struct rte_ether_hdr* eth = &hdr->eth; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; + struct rte_mbuf *pkt = pkts[i]; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); + struct rte_ether_hdr *eth = &hdr->eth; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; /* copy eth, ip, udp */ rte_memcpy(hdr, &s->hdr, sizeof(*hdr)); @@ -283,22 +292,24 @@ static int udp_build_tx_msg_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, udp->dst_port = addr_in->sin_port; /* pkt mbuf */ mt_mbuf_init_ipv4(pkt); - pkt->packet_type = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP; + pkt->packet_type = + RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP; payloads[i] = &udp[1]; s->stat_pkt_build++; } unsigned int pkt_idx = 0; - void* pd = payloads[pkt_idx]; + void *pd = payloads[pkt_idx]; size_t pd_len = sz_per_pkt; /* copy msg buffer to payload */ for (int i = 0; i < msg->msg_iovlen; i++) { size_t iov_len = msg->msg_iov[i].iov_len; - void* iov = msg->msg_iov[i].iov_base; + void *iov = msg->msg_iov[i].iov_base; while (iov_len > 0) { if (pd_len <= 0) { - err("%s(%d), no available payload, pkts_nb %u\n", __func__, idx, pkts_nb); + err("%s(%d), no available payload, pkts_nb %u\n", __func__, idx, + pkts_nb); MUDP_ERR_RET(EIO); } size_t clen = RTE_MIN(pd_len, iov_len); @@ -332,10 +343,10 @@ static int udp_build_tx_msg_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, /* fill the info according to the payload */ for (unsigned int i = 0; i < pkts_nb; i++) { - struct rte_mbuf* pkt = pkts[i]; - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; + struct rte_mbuf *pkt = pkts[i]; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; udp->dgram_len = htons(pkt->pkt_len - pkt->l2_len - pkt->l3_len); ipv4->total_length = htons(pkt->pkt_len - pkt->l2_len); @@ -348,8 +359,8 @@ static int udp_build_tx_msg_pkt(struct mtl_main_impl* impl, struct mudp_impl* s, return 0; } -static unsigned int udp_tx_pkts(struct mtl_main_impl* impl, struct mudp_impl* s, - struct rte_mbuf** pkts, unsigned int count) { +static unsigned int udp_tx_pkts(struct mtl_main_impl *impl, struct mudp_impl *s, + struct rte_mbuf **pkts, unsigned int count) { int idx = s->idx; unsigned int sent = 0; uint64_t start_ts = mt_get_tsc(impl); @@ -377,7 +388,7 @@ static unsigned int udp_tx_pkts(struct mtl_main_impl* impl, struct mudp_impl* s, return sent; } -static int udp_bind_port(struct mudp_impl* s, uint16_t bind_port) { +static int udp_bind_port(struct mudp_impl *s, uint16_t bind_port) { int idx = s->idx; if (!bind_port) { @@ -392,11 +403,11 @@ static int udp_bind_port(struct mudp_impl* s, uint16_t bind_port) { return 0; } -static int udp_init_hdr(struct mtl_main_impl* impl, struct mudp_impl* s) { - struct mt_udp_hdr* hdr = &s->hdr; - struct rte_ether_hdr* eth = &hdr->eth; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; - struct rte_udp_hdr* udp = &hdr->udp; +static int udp_init_hdr(struct mtl_main_impl *impl, struct mudp_impl *s) { + struct mt_udp_hdr *hdr = &s->hdr; + struct rte_ether_hdr *eth = &hdr->eth; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; + struct rte_udp_hdr *udp = &hdr->udp; int idx = s->idx; enum mtl_port port = s->port; int ret; @@ -428,7 +439,7 @@ static int udp_init_hdr(struct mtl_main_impl* impl, struct mudp_impl* s) { return 0; } -static int udp_uinit_txq(struct mtl_main_impl* impl, struct mudp_impl* s) { +static int udp_uinit_txq(struct mtl_main_impl *impl, struct mudp_impl *s) { enum mtl_port port = s->port; if (s->txq) { @@ -449,8 +460,8 @@ static int udp_uinit_txq(struct mtl_main_impl* impl, struct mudp_impl* s) { return 0; } -static int udp_init_txq(struct mtl_main_impl* impl, struct mudp_impl* s, - const struct sockaddr_in* addr_in) { +static int udp_init_txq(struct mtl_main_impl *impl, struct mudp_impl *s, + const struct sockaddr_in *addr_in) { enum mtl_port port = s->port; int idx = s->idx; uint16_t queue_id; @@ -475,8 +486,9 @@ static int udp_init_txq(struct mtl_main_impl* impl, struct mudp_impl* s, if (!s->tx_pool) { char pool_name[32]; snprintf(pool_name, 32, "%sP%dQ%uS%d_TX", MUDP_PREFIX, port, queue_id, idx); - struct rte_mempool* pool = mt_mempool_create(impl, port, pool_name, s->element_nb, - MT_MBUF_CACHE_SIZE, 0, s->element_size); + struct rte_mempool *pool = + mt_mempool_create(impl, port, pool_name, s->element_nb, + MT_MBUF_CACHE_SIZE, 0, s->element_size); if (!pool) { err("%s(%d), mempool create fail\n", __func__, idx); udp_uinit_txq(impl, s); @@ -491,7 +503,7 @@ static int udp_init_txq(struct mtl_main_impl* impl, struct mudp_impl* s, return 0; } -static int udp_uinit_rxq(struct mudp_impl* s) { +static int udp_uinit_rxq(struct mudp_impl *s) { if (s->rxq) { mur_client_put(s->rxq); s->rxq = NULL; @@ -499,7 +511,7 @@ static int udp_uinit_rxq(struct mudp_impl* s) { return 0; } -static int udp_init_rxq(struct mtl_main_impl* impl, struct mudp_impl* s) { +static int udp_init_rxq(struct mtl_main_impl *impl, struct mudp_impl *s) { int idx = s->idx; if (s->rxq) { @@ -524,8 +536,8 @@ static int udp_init_rxq(struct mtl_main_impl* impl, struct mudp_impl* s) { return 0; } -static int udp_stat_dump(void* priv) { - struct mudp_impl* s = priv; +static int udp_stat_dump(void *priv) { + struct mudp_impl *s = priv; int idx = s->idx; enum mtl_port port = s->port; @@ -534,18 +546,19 @@ static int udp_stat_dump(void* priv) { rte_ring_count(mur_client_ring(s->rxq))); } if (s->stat_rx_msg_cnt) { - notice("%s(%d,%d), rx_msg %u succ %u timeout %u again %u\n", __func__, port, idx, - s->stat_rx_msg_cnt, s->stat_rx_msg_succ_cnt, s->stat_rx_msg_timeout_cnt, - s->stat_rx_msg_again_cnt); + notice("%s(%d,%d), rx_msg %u succ %u timeout %u again %u\n", __func__, port, + idx, s->stat_rx_msg_cnt, s->stat_rx_msg_succ_cnt, + s->stat_rx_msg_timeout_cnt, s->stat_rx_msg_again_cnt); s->stat_rx_msg_cnt = 0; s->stat_rx_msg_succ_cnt = 0; s->stat_rx_msg_timeout_cnt = 0; s->stat_rx_msg_again_cnt = 0; } if (s->stat_poll_cnt) { - notice("%s(%d,%d), poll %u succ %u timeout %u 0-timeout %u query_ret %u\n", __func__, - port, idx, s->stat_poll_cnt, s->stat_poll_succ_cnt, s->stat_poll_timeout_cnt, - s->stat_poll_zero_timeout_cnt, s->stat_poll_query_ret_cnt); + notice("%s(%d,%d), poll %u succ %u timeout %u 0-timeout %u query_ret %u\n", + __func__, port, idx, s->stat_poll_cnt, s->stat_poll_succ_cnt, + s->stat_poll_timeout_cnt, s->stat_poll_zero_timeout_cnt, + s->stat_poll_query_ret_cnt); s->stat_poll_cnt = 0; s->stat_poll_succ_cnt = 0; s->stat_poll_timeout_cnt = 0; @@ -558,20 +571,23 @@ static int udp_stat_dump(void* priv) { s->stat_pkt_dequeue = 0; s->stat_pkt_deliver = 0; } - if (s->rxq) mur_client_dump(s->rxq); + if (s->rxq) + mur_client_dump(s->rxq); if (s->stat_pkt_build) { - notice("%s(%d,%d), pkt build %u tx %u\n", __func__, port, idx, s->stat_pkt_build, - s->stat_pkt_tx); + notice("%s(%d,%d), pkt build %u tx %u\n", __func__, port, idx, + s->stat_pkt_build, s->stat_pkt_tx); s->stat_pkt_build = 0; s->stat_pkt_tx = 0; } if (s->stat_tx_gso_count) { - notice("%s(%d,%d), tx gso count %u\n", __func__, port, idx, s->stat_tx_gso_count); + notice("%s(%d,%d), tx gso count %u\n", __func__, port, idx, + s->stat_tx_gso_count); s->stat_tx_gso_count = 0; } if (s->stat_pkt_arp_fail) { - warn("%s(%d,%d), pkt %u arp fail\n", __func__, port, idx, s->stat_pkt_arp_fail); + warn("%s(%d,%d), pkt %u arp fail\n", __func__, port, idx, + s->stat_pkt_arp_fail); s->stat_pkt_arp_fail = 0; } if (s->stat_tx_retry) { @@ -584,7 +600,8 @@ static int udp_stat_dump(void* priv) { return 0; } -static int udp_get_sndbuf(struct mudp_impl* s, void* optval, socklen_t* optlen) { +static int udp_get_sndbuf(struct mudp_impl *s, void *optval, + socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); @@ -597,7 +614,8 @@ static int udp_get_sndbuf(struct mudp_impl* s, void* optval, socklen_t* optlen) return 0; } -static int udp_get_rcvbuf(struct mudp_impl* s, void* optval, socklen_t* optlen) { +static int udp_get_rcvbuf(struct mudp_impl *s, void *optval, + socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); @@ -610,7 +628,8 @@ static int udp_get_rcvbuf(struct mudp_impl* s, void* optval, socklen_t* optlen) return 0; } -static int udp_set_sndbuf(struct mudp_impl* s, const void* optval, socklen_t optlen) { +static int udp_set_sndbuf(struct mudp_impl *s, const void *optval, + socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); uint32_t sndbuf_sz; @@ -620,13 +639,14 @@ static int udp_set_sndbuf(struct mudp_impl* s, const void* optval, socklen_t opt MUDP_ERR_RET(EINVAL); } - sndbuf_sz = *((uint32_t*)optval); + sndbuf_sz = *((uint32_t *)optval); info("%s(%d), sndbuf_sz %u\n", __func__, idx, sndbuf_sz); s->sndbuf_sz = sndbuf_sz; return 0; } -static int udp_set_rcvbuf(struct mudp_impl* s, const void* optval, socklen_t optlen) { +static int udp_set_rcvbuf(struct mudp_impl *s, const void *optval, + socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); uint32_t rcvbuf_sz; @@ -636,15 +656,16 @@ static int udp_set_rcvbuf(struct mudp_impl* s, const void* optval, socklen_t opt MUDP_ERR_RET(EINVAL); } - rcvbuf_sz = *((uint32_t*)optval); + rcvbuf_sz = *((uint32_t *)optval); info("%s(%d), rcvbuf_sz %u\n", __func__, idx, rcvbuf_sz); s->rcvbuf_sz = rcvbuf_sz; return 0; } -static int udp_get_rcvtimeo(struct mudp_impl* s, void* optval, socklen_t* optlen) { +static int udp_get_rcvtimeo(struct mudp_impl *s, void *optval, + socklen_t *optlen) { int idx = s->idx; - struct timeval* tv; + struct timeval *tv; size_t sz = sizeof(*tv); unsigned int us; @@ -654,13 +675,14 @@ static int udp_get_rcvtimeo(struct mudp_impl* s, void* optval, socklen_t* optlen } us = mudp_get_rx_timeout(s); - tv = (struct timeval*)optval; + tv = (struct timeval *)optval; tv->tv_sec = us / US_PER_S; tv->tv_usec = us % US_PER_S; return 0; } -static int udp_set_cookie(struct mudp_impl* s, const void* optval, socklen_t optlen) { +static int udp_set_cookie(struct mudp_impl *s, const void *optval, + socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(uint64_t); uint64_t cookie; @@ -670,13 +692,14 @@ static int udp_set_cookie(struct mudp_impl* s, const void* optval, socklen_t opt MUDP_ERR_RET(EINVAL); } - cookie = *((uint64_t*)optval); + cookie = *((uint64_t *)optval); info("%s(%d), cookie %" PRIu64 "\n", __func__, idx, cookie); s->cookie = cookie; return 0; } -static int udp_get_cookie(struct mudp_impl* s, void* optval, socklen_t* optlen) { +static int udp_get_cookie(struct mudp_impl *s, void *optval, + socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(uint64_t); @@ -689,9 +712,10 @@ static int udp_get_cookie(struct mudp_impl* s, void* optval, socklen_t* optlen) return 0; } -static int udp_set_rcvtimeo(struct mudp_impl* s, const void* optval, socklen_t optlen) { +static int udp_set_rcvtimeo(struct mudp_impl *s, const void *optval, + socklen_t optlen) { int idx = s->idx; - const struct timeval* tv; + const struct timeval *tv; size_t sz = sizeof(*tv); unsigned int us; @@ -700,13 +724,14 @@ static int udp_set_rcvtimeo(struct mudp_impl* s, const void* optval, socklen_t o MUDP_ERR_RET(EINVAL); } - tv = (const struct timeval*)optval; + tv = (const struct timeval *)optval; us = tv->tv_sec * 1000 * 1000 + tv->tv_usec; mudp_set_rx_timeout(s, us); return 0; } -static int udp_set_reuse_port(struct mudp_impl* s, const void* optval, socklen_t optlen) { +static int udp_set_reuse_port(struct mudp_impl *s, const void *optval, + socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(int); int reuse_port; @@ -716,13 +741,14 @@ static int udp_set_reuse_port(struct mudp_impl* s, const void* optval, socklen_t MUDP_ERR_RET(EINVAL); } - reuse_port = *((int*)optval); + reuse_port = *((int *)optval); info("%s(%d), reuse_port %d\n", __func__, idx, reuse_port); s->reuse_port = reuse_port; return 0; } -static int udp_get_reuse_port(struct mudp_impl* s, void* optval, socklen_t* optlen) { +static int udp_get_reuse_port(struct mudp_impl *s, void *optval, + socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(int); @@ -735,7 +761,8 @@ static int udp_get_reuse_port(struct mudp_impl* s, void* optval, socklen_t* optl return 0; } -static int udp_set_reuse_addr(struct mudp_impl* s, const void* optval, socklen_t optlen) { +static int udp_set_reuse_addr(struct mudp_impl *s, const void *optval, + socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(int); int reuse_addr; @@ -745,13 +772,14 @@ static int udp_set_reuse_addr(struct mudp_impl* s, const void* optval, socklen_t MUDP_ERR_RET(EINVAL); } - reuse_addr = *((int*)optval); + reuse_addr = *((int *)optval); info("%s(%d), reuse_addr %d\n", __func__, idx, reuse_addr); s->reuse_addr = reuse_addr; return 0; } -static int udp_get_reuse_addr(struct mudp_impl* s, void* optval, socklen_t* optlen) { +static int udp_get_reuse_addr(struct mudp_impl *s, void *optval, + socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(int); @@ -764,7 +792,7 @@ static int udp_get_reuse_addr(struct mudp_impl* s, void* optval, socklen_t* optl return 0; } -static int udp_init_mcast(struct mtl_main_impl* impl, struct mudp_impl* s) { +static int udp_init_mcast(struct mtl_main_impl *impl, struct mudp_impl *s) { int idx = s->idx; enum mtl_port port = s->port; @@ -772,8 +800,8 @@ static int udp_init_mcast(struct mtl_main_impl* impl, struct mudp_impl* s) { err("%s(%d), mcast addrs already init\n", __func__, idx); MUDP_ERR_RET(EIO); } - s->mcast_addrs = mt_rte_zmalloc_socket(sizeof(*s->mcast_addrs) * s->mcast_addrs_nb, - mt_socket_id(impl, port)); + s->mcast_addrs = mt_rte_zmalloc_socket( + sizeof(*s->mcast_addrs) * s->mcast_addrs_nb, mt_socket_id(impl, port)); if (!s->mcast_addrs) { err("%s(%d), mcast addrs malloc fail\n", __func__, idx); MUDP_ERR_RET(ENOMEM); @@ -783,7 +811,7 @@ static int udp_init_mcast(struct mtl_main_impl* impl, struct mudp_impl* s) { return 0; } -static int udp_uinit_mcast(struct mudp_impl* s) { +static int udp_uinit_mcast(struct mudp_impl *s) { int idx = s->idx; if (!s->mcast_addrs) { @@ -804,13 +832,14 @@ static int udp_uinit_mcast(struct mudp_impl* s) { return 0; } -static int udp_add_membership(struct mudp_impl* s, const void* optval, socklen_t optlen) { +static int udp_add_membership(struct mudp_impl *s, const void *optval, + socklen_t optlen) { int idx = s->idx; - struct mtl_main_impl* impl = s->parent; + struct mtl_main_impl *impl = s->parent; enum mtl_port port = s->port; - const struct ip_mreq* mreq; + const struct ip_mreq *mreq; size_t sz = sizeof(*mreq); - uint8_t* ip; + uint8_t *ip; int ret; if (optlen != sz) { @@ -827,8 +856,8 @@ static int udp_add_membership(struct mudp_impl* s, const void* optval, socklen_t } } - mreq = (const struct ip_mreq*)optval; - ip = (uint8_t*)&mreq->imr_multiaddr.s_addr; + mreq = (const struct ip_mreq *)optval; + ip = (uint8_t *)&mreq->imr_multiaddr.s_addr; uint32_t group_addr = mt_ip_to_u32(ip); ret = mt_mcast_join(s->parent, group_addr, 0, port); if (ret < 0) { @@ -842,8 +871,8 @@ static int udp_add_membership(struct mudp_impl* s, const void* optval, socklen_t if (!s->mcast_addrs[i]) { s->mcast_addrs[i] = group_addr; added = true; - info("%s(%d), add %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], ip[2], ip[3], - i); + info("%s(%d), add %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3], i); break; } } @@ -857,13 +886,13 @@ static int udp_add_membership(struct mudp_impl* s, const void* optval, socklen_t return 0; } -static int udp_drop_membership(struct mudp_impl* s, const void* optval, +static int udp_drop_membership(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; enum mtl_port port = s->port; - const struct ip_mreq* mreq; + const struct ip_mreq *mreq; size_t sz = sizeof(*mreq); - uint8_t* ip; + uint8_t *ip; if (optlen != sz) { err("%s(%d), invalid optlen %d\n", __func__, idx, optlen); @@ -874,8 +903,8 @@ static int udp_drop_membership(struct mudp_impl* s, const void* optval, MUDP_ERR_RET(EIO); } - mreq = (const struct ip_mreq*)optval; - ip = (uint8_t*)&mreq->imr_multiaddr.s_addr; + mreq = (const struct ip_mreq *)optval; + ip = (uint8_t *)&mreq->imr_multiaddr.s_addr; uint32_t group_addr = mt_ip_to_u32(ip); bool found = false; @@ -884,8 +913,8 @@ static int udp_drop_membership(struct mudp_impl* s, const void* optval, if (s->mcast_addrs[i] == group_addr) { found = true; s->mcast_addrs[i] = 0; - info("%s(%d), drop %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], ip[2], ip[3], - i); + info("%s(%d), drop %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3], i); break; } } @@ -899,22 +928,24 @@ static int udp_drop_membership(struct mudp_impl* s, const void* optval, return 0; } -static ssize_t udp_rx_dequeue(struct mudp_impl* s, void* buf, size_t len, int flags, - struct sockaddr* src_addr, socklen_t* addrlen) { +static ssize_t udp_rx_dequeue(struct mudp_impl *s, void *buf, size_t len, + int flags, struct sockaddr *src_addr, + socklen_t *addrlen) { int idx = s->idx; int ret; ssize_t copied = 0; - struct rte_mbuf* pkt = NULL; + struct rte_mbuf *pkt = NULL; MTL_MAY_UNUSED(flags); /* dequeue pkt from rx ring */ - ret = rte_ring_sc_dequeue(mur_client_ring(s->rxq), (void**)&pkt); - if (ret < 0) return ret; + ret = rte_ring_sc_dequeue(mur_client_ring(s->rxq), (void **)&pkt); + if (ret < 0) + return ret; s->stat_pkt_dequeue++; - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); - struct rte_udp_hdr* udp = &hdr->udp; - void* payload = &udp[1]; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); + struct rte_udp_hdr *udp = &hdr->udp; + void *payload = &udp[1]; ssize_t payload_len = ntohs(udp->dgram_len) - sizeof(*udp); dbg("%s(%d), payload_len %d bytes\n", __func__, idx, payload_len); @@ -925,15 +956,16 @@ static ssize_t udp_rx_dequeue(struct mudp_impl* s, void* buf, size_t len, int fl if (src_addr) { /* only AF_INET now*/ struct sockaddr_in addr_in; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; memset(&addr_in, 0, sizeof(addr_in)); addr_in.sin_family = AF_INET; addr_in.sin_port = udp->src_port; addr_in.sin_addr.s_addr = ipv4->src_addr; - dbg("%s(%d), dst port %u src port %u\n", __func__, idx, ntohs(udp->dst_port), - ntohs(udp->src_port)); - rte_memcpy((void*)src_addr, &addr_in, RTE_MIN(*addrlen, sizeof(addr_in))); + dbg("%s(%d), dst port %u src port %u\n", __func__, idx, + ntohs(udp->dst_port), ntohs(udp->src_port)); + rte_memcpy((void *)src_addr, &addr_in, + RTE_MIN(*addrlen, sizeof(addr_in))); } } else { err("%s(%d), payload len %" PRIu64 " buf len %" PRIu64 "\n", __func__, idx, @@ -944,20 +976,21 @@ static ssize_t udp_rx_dequeue(struct mudp_impl* s, void* buf, size_t len, int fl return copied; } -static ssize_t udp_rx_ret_timeout(struct mudp_impl* s, int flags) { +static ssize_t udp_rx_ret_timeout(struct mudp_impl *s, int flags) { MTL_MAY_UNUSED(flags); if (s->rx_timeout_us) { - dbg("%s(%d), timeout to %d ms, flags %d\n", __func__, s->idx, s->rx_timeout_us, - flags); + dbg("%s(%d), timeout to %d ms, flags %d\n", __func__, s->idx, + s->rx_timeout_us, flags); MUDP_ERR_RET(ETIMEDOUT); } else { MUDP_ERR_RET(EAGAIN); } } -static ssize_t udp_recvfrom(struct mudp_impl* s, void* buf, size_t len, int flags, - struct sockaddr* src_addr, socklen_t* addrlen) { - struct mtl_main_impl* impl = s->parent; +static ssize_t udp_recvfrom(struct mudp_impl *s, void *buf, size_t len, + int flags, struct sockaddr *src_addr, + socklen_t *addrlen) { + struct mtl_main_impl *impl = s->parent; ssize_t copied = 0; uint16_t rx; uint64_t start_ts = mt_get_tsc(impl); @@ -965,7 +998,8 @@ static ssize_t udp_recvfrom(struct mudp_impl* s, void* buf, size_t len, int flag dequeue: /* dequeue pkt from rx ring */ copied = udp_rx_dequeue(s, buf, len, flags, src_addr, addrlen); - if (copied > 0) return copied; + if (copied > 0) + return copied; rx = mur_client_rx(s->rxq); if (rx) { /* dequeue again as rx succ */ @@ -989,22 +1023,24 @@ static ssize_t udp_recvfrom(struct mudp_impl* s, void* buf, size_t len, int flag return udp_rx_ret_timeout(s, flags); } -static ssize_t udp_rx_msg_dequeue(struct mudp_impl* s, struct msghdr* msg, int flags) { +static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, + int flags) { int idx = s->idx; int ret; ssize_t copied = 0; - struct rte_mbuf* pkt = NULL; + struct rte_mbuf *pkt = NULL; MTL_MAY_UNUSED(flags); /* dequeue pkt from rx ring */ - ret = rte_ring_sc_dequeue(mur_client_ring(s->rxq), (void**)&pkt); - if (ret < 0) return ret; + ret = rte_ring_sc_dequeue(mur_client_ring(s->rxq), (void **)&pkt); + if (ret < 0) + return ret; s->stat_pkt_dequeue++; - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr*); - struct rte_udp_hdr* udp = &hdr->udp; - void* payload = &udp[1]; - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); + struct rte_udp_hdr *udp = &hdr->udp; + void *payload = &udp[1]; + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; ssize_t payload_len = ntohs(udp->dgram_len) - sizeof(*udp); dbg("%s(%d), payload_len %" PRId64 " bytes\n", __func__, idx, payload_len); @@ -1016,9 +1052,10 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl* s, struct msghdr* msg, int f addr_in.sin_family = AF_INET; addr_in.sin_port = udp->src_port; addr_in.sin_addr.s_addr = ipv4->src_addr; - dbg("%s(%d), dst port %u src port %u\n", __func__, idx, ntohs(udp->dst_port), - ntohs(udp->src_port)); - rte_memcpy(msg->msg_name, &addr_in, RTE_MIN(msg->msg_namelen, sizeof(addr_in))); + dbg("%s(%d), dst port %u src port %u\n", __func__, idx, + ntohs(udp->dst_port), ntohs(udp->src_port)); + rte_memcpy(msg->msg_name, &addr_in, + RTE_MIN(msg->msg_namelen, sizeof(addr_in))); } if (msg->msg_control) { /* Ancillary data */ @@ -1026,7 +1063,8 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl* s, struct msghdr* msg, int f memset(&chdr, 0, sizeof(chdr)); chdr.cmsg_len = sizeof(chdr); chdr.cmsg_level = ipv4->next_proto_id; - rte_memcpy(msg->msg_control, &chdr, RTE_MIN(msg->msg_controllen, sizeof(chdr))); + rte_memcpy(msg->msg_control, &chdr, + RTE_MIN(msg->msg_controllen, sizeof(chdr))); } if (msg->msg_iov) { /* Vector of data */ @@ -1036,7 +1074,8 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl* s, struct msghdr* msg, int f payload_len -= clen; payload += clen; copied += clen; - if (payload_len <= 0) break; + if (payload_len <= 0) + break; } s->stat_pkt_deliver++; } @@ -1045,12 +1084,13 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl* s, struct msghdr* msg, int f warn("%s(%d), %" PRIu64 " bytes not copied \n", __func__, idx, payload_len); rte_pktmbuf_free(pkt); - dbg("%s(%d), copied %" PRId64 " bytes, flags %d\n", __func__, idx, copied, flags); + dbg("%s(%d), copied %" PRId64 " bytes, flags %d\n", __func__, idx, copied, + flags); return copied; } -static ssize_t udp_recvmsg(struct mudp_impl* s, struct msghdr* msg, int flags) { - struct mtl_main_impl* impl = s->parent; +static ssize_t udp_recvmsg(struct mudp_impl *s, struct msghdr *msg, int flags) { + struct mtl_main_impl *impl = s->parent; ssize_t copied = 0; uint16_t rx; uint64_t start_ts = mt_get_tsc(impl); @@ -1089,8 +1129,9 @@ static ssize_t udp_recvmsg(struct mudp_impl* s, struct msghdr* msg, int flags) { return udp_rx_ret_timeout(s, flags); } -static int udp_fallback_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout) { - struct mudp_impl* s; +static int udp_fallback_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, + int timeout) { + struct mudp_impl *s; struct pollfd p_fds[nfds]; int ret; @@ -1122,10 +1163,10 @@ static int udp_fallback_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int time return ret; } -static int udp_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout, - int (*query)(void* priv), void* priv) { - struct mudp_impl* s = fds[0].fd; - struct mtl_main_impl* impl = s->parent; +static int udp_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout, + int (*query)(void *priv), void *priv) { + struct mudp_impl *s = fds[0].fd; + struct mtl_main_impl *impl = s->parent; uint64_t start_ts = mt_get_tsc(impl); int rc, ret; @@ -1191,7 +1232,8 @@ static int udp_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout, int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (((ms < timeout) || (timeout < 0)) && udp_alive(s)) { if (s->rx_poll_sleep_us) { - mur_client_timedwait(s->rxq, (timeout - ms) * US_PER_MS, s->rx_poll_sleep_us); + mur_client_timedwait(s->rxq, (timeout - ms) * US_PER_MS, + s->rx_poll_sleep_us); } goto rx_poll; } @@ -1207,15 +1249,16 @@ static int udp_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout, mudp_handle mudp_socket_port(mtl_handle mt, int domain, int type, int protocol, enum mtl_port port) { int ret; - struct mtl_main_impl* impl = mt; - struct mudp_impl* s; + struct mtl_main_impl *impl = mt; + struct mudp_impl *s; static int mudp_idx = 0; int idx = mudp_idx; mudp_idx++; ret = mudp_verify_socket_args(domain, type, protocol); - if (ret < 0) return NULL; + if (ret < 0) + return NULL; /* make sure tsc is ready, mudp_recvfrom will use tsc */ mt_wait_tsc_stable(impl); @@ -1289,8 +1332,8 @@ mudp_handle mudp_socket(mtl_handle mt, int domain, int type, int protocol) { } int mudp_close(mudp_handle ut) { - struct mudp_impl* s = ut; - struct mtl_main_impl* impl = s->parent; + struct mudp_impl *s = ut; + struct mtl_main_impl *impl = s->parent; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1318,11 +1361,11 @@ int mudp_close(mudp_handle ut) { return 0; } -int mudp_bind(mudp_handle ut, const struct sockaddr* addr, socklen_t addrlen) { - struct mudp_impl* s = ut; - struct mtl_main_impl* impl = s->parent; +int mudp_bind(mudp_handle ut, const struct sockaddr *addr, socklen_t addrlen) { + struct mudp_impl *s = ut; + struct mtl_main_impl *impl = s->parent; int idx = s->idx; - const struct sockaddr_in* addr_in = (struct sockaddr_in*)addr; + const struct sockaddr_in *addr_in = (struct sockaddr_in *)addr; int ret; if (s->type != MT_HANDLE_UDP) { @@ -1332,14 +1375,16 @@ int mudp_bind(mudp_handle ut, const struct sockaddr* addr, socklen_t addrlen) { if (udp_is_fallback(s)) { ret = bind(s->fallback_fd, addr, addrlen); - uint8_t* ip = (uint8_t*)&addr_in->sin_addr.s_addr; - info("%s(%d), fallback fd %d bind ip %u.%u.%u.%u port %u ret %d\n", __func__, idx, - s->fallback_fd, ip[0], ip[1], ip[2], ip[3], htons(addr_in->sin_port), ret); + uint8_t *ip = (uint8_t *)&addr_in->sin_addr.s_addr; + info("%s(%d), fallback fd %d bind ip %u.%u.%u.%u port %u ret %d\n", + __func__, idx, s->fallback_fd, ip[0], ip[1], ip[2], ip[3], + htons(addr_in->sin_port), ret); return ret; } ret = udp_verify_bind_addr(s, addr_in, addrlen); - if (ret < 0) return ret; + if (ret < 0) + return ret; /* uinit rx if any */ udp_uinit_rxq(s); @@ -1366,10 +1411,10 @@ int mudp_bind(mudp_handle ut, const struct sockaddr* addr, socklen_t addrlen) { return 0; } -ssize_t mudp_sendto(mudp_handle ut, const void* buf, size_t len, int flags, - const struct sockaddr* dest_addr, socklen_t addrlen) { - struct mudp_impl* s = ut; - struct mtl_main_impl* impl = s->parent; +ssize_t mudp_sendto(mudp_handle ut, const void *buf, size_t len, int flags, + const struct sockaddr *dest_addr, socklen_t addrlen) { + struct mudp_impl *s = ut; + struct mtl_main_impl *impl = s->parent; int idx = s->idx; int arp_timeout_ms = s->arp_timeout_us / 1000; int ret; @@ -1377,7 +1422,7 @@ ssize_t mudp_sendto(mudp_handle ut, const void* buf, size_t len, int flags, if (udp_is_fallback(s)) return sendto(s->fallback_fd, buf, len, flags, dest_addr, addrlen); - const struct sockaddr_in* addr_in = (struct sockaddr_in*)dest_addr; + const struct sockaddr_in *addr_in = (struct sockaddr_in *)dest_addr; ret = udp_verify_sendto_args(len, flags, addr_in, addrlen); if (ret < 0) { err("%s(%d), invalid args\n", __func__, idx); @@ -1395,10 +1440,12 @@ ssize_t mudp_sendto(mudp_handle ut, const void* buf, size_t len, int flags, size_t sz_per_pkt = s->gso_segment_sz; unsigned int pkts_nb = len / sz_per_pkt; - if (len % sz_per_pkt) pkts_nb++; - struct rte_mbuf* pkts[pkts_nb]; + if (len % sz_per_pkt) + pkts_nb++; + struct rte_mbuf *pkts[pkts_nb]; dbg("%s(%d), pkts_nb %u\n", __func__, idx, pkts_nb); - if (pkts_nb > 1) s->stat_tx_gso_count++; + if (pkts_nb > 1) + s->stat_tx_gso_count++; ret = rte_pktmbuf_alloc_bulk(s->tx_pool, pkts, pkts_nb); if (ret < 0) { @@ -1418,7 +1465,8 @@ ssize_t mudp_sendto(mudp_handle ut, const void* buf, size_t len, int flags, return ret; } else { mt_sleep_us(1); - /* align to kernel behavior which sendto succ even if arp not resolved */ + /* align to kernel behavior which sendto succ even if arp not resolved + */ return len; } } @@ -1437,18 +1485,19 @@ ssize_t mudp_sendto(mudp_handle ut, const void* buf, size_t len, int flags, return len; } -ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr* msg, int flags) { - struct mudp_impl* s = ut; - struct mtl_main_impl* impl = s->parent; +ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr *msg, int flags) { + struct mudp_impl *s = ut; + struct mtl_main_impl *impl = s->parent; int idx = s->idx; int arp_timeout_ms = s->msg_arp_timeout_us / 1000; int ret; #ifndef WINDOWSENV - if (udp_is_fallback(s)) return sendmsg(s->fallback_fd, msg, flags); + if (udp_is_fallback(s)) + return sendmsg(s->fallback_fd, msg, flags); #endif - const struct sockaddr_in* addr_in = (struct sockaddr_in*)msg->msg_name; + const struct sockaddr_in *addr_in = (struct sockaddr_in *)msg->msg_name; /* len to 1 to let the verify happy */ ret = udp_verify_sendto_args(1, flags, addr_in, msg->msg_namelen); if (ret < 0) { @@ -1471,16 +1520,19 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr* msg, int flags) { size_t sz_per_pkt = s->gso_segment_sz; size_t total_len = udp_msg_len(msg); unsigned int pkts_nb = total_len / sz_per_pkt; - if (total_len % sz_per_pkt) pkts_nb++; + if (total_len % sz_per_pkt) + pkts_nb++; /* Ensure pkts_nb is greater than 0 */ if (pkts_nb == 0) { err("%s(%d): pkts_nb is 0\n", __func__, idx); return -EINVAL; /* Invalid argument */ } - struct rte_mbuf* pkts[pkts_nb]; - dbg("%s(%d), pkts_nb %u total_len %" PRId64 "\n", __func__, idx, pkts_nb, total_len); - if (pkts_nb > 1) s->stat_tx_gso_count++; + struct rte_mbuf *pkts[pkts_nb]; + dbg("%s(%d), pkts_nb %u total_len %" PRId64 "\n", __func__, idx, pkts_nb, + total_len); + if (pkts_nb > 1) + s->stat_tx_gso_count++; ret = rte_pktmbuf_alloc_bulk(s->tx_pool, pkts, pkts_nb); if (ret < 0) { @@ -1488,8 +1540,8 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr* msg, int flags) { MUDP_ERR_RET(ENOMEM); } - ret = udp_build_tx_msg_pkt(impl, s, pkts, pkts_nb, msg, addr_in, arp_timeout_ms, - sz_per_pkt); + ret = udp_build_tx_msg_pkt(impl, s, pkts, pkts_nb, msg, addr_in, + arp_timeout_ms, sz_per_pkt); if (ret < 0) { rte_pktmbuf_free_bulk(pkts, pkts_nb); if (arp_timeout_ms) { @@ -1515,12 +1567,13 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr* msg, int flags) { return total_len; } -int mudp_poll_query(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout, - int (*query)(void* priv), void* priv) { +int mudp_poll_query(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout, + int (*query)(void *priv), void *priv) { int ret = udp_verify_poll(fds, nfds, timeout); - if (ret < 0) return ret; + if (ret < 0) + return ret; - struct mudp_impl* s = fds[0].fd; + struct mudp_impl *s = fds[0].fd; if (udp_is_fallback(s)) { if (query) { @@ -1533,14 +1586,14 @@ int mudp_poll_query(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout, } } -int mudp_poll(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout) { +int mudp_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout) { return mudp_poll_query(fds, nfds, timeout, NULL, NULL); } -ssize_t mudp_recvfrom(mudp_handle ut, void* buf, size_t len, int flags, - struct sockaddr* src_addr, socklen_t* addrlen) { - struct mudp_impl* s = ut; - struct mtl_main_impl* impl = s->parent; +ssize_t mudp_recvfrom(mudp_handle ut, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen) { + struct mudp_impl *s = ut; + struct mtl_main_impl *impl = s->parent; int idx = s->idx; int ret; @@ -1559,14 +1612,15 @@ ssize_t mudp_recvfrom(mudp_handle ut, void* buf, size_t len, int flags, return udp_recvfrom(s, buf, len, flags, src_addr, addrlen); } -ssize_t mudp_recvmsg(mudp_handle ut, struct msghdr* msg, int flags) { - struct mudp_impl* s = ut; - struct mtl_main_impl* impl = s->parent; +ssize_t mudp_recvmsg(mudp_handle ut, struct msghdr *msg, int flags) { + struct mudp_impl *s = ut; + struct mtl_main_impl *impl = s->parent; int idx = s->idx; int ret; #ifndef WINDOWSENV - if (udp_is_fallback(s)) return recvmsg(s->fallback_fd, msg, flags); + if (udp_is_fallback(s)) + return recvmsg(s->fallback_fd, msg, flags); #endif /* init rxq if not */ @@ -1581,130 +1635,134 @@ ssize_t mudp_recvmsg(mudp_handle ut, struct msghdr* msg, int flags) { return udp_recvmsg(s, msg, flags); } -int mudp_getsockopt(mudp_handle ut, int level, int optname, void* optval, - socklen_t* optlen) { - struct mudp_impl* s = ut; +int mudp_getsockopt(mudp_handle ut, int level, int optname, void *optval, + socklen_t *optlen) { + struct mudp_impl *s = ut; int idx = s->idx; if (udp_is_fallback(s)) return getsockopt(s->fallback_fd, level, optname, optval, optlen); switch (level) { - case SOL_SOCKET: { - switch (optname) { - case SO_SNDBUF: - case SO_SNDBUFFORCE: - return udp_get_sndbuf(s, optval, optlen); - case SO_RCVBUF: - case SO_RCVBUFFORCE: - return udp_get_rcvbuf(s, optval, optlen); - case SO_RCVTIMEO: - return udp_get_rcvtimeo(s, optval, optlen); - case SO_COOKIE: - return udp_get_cookie(s, optval, optlen); - case SO_REUSEPORT: - return udp_get_reuse_port(s, optval, optlen); - case SO_REUSEADDR: - return udp_get_reuse_addr(s, optval, optlen); - default: - err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, optname); - MUDP_ERR_RET(EINVAL); - } - } + case SOL_SOCKET: { + switch (optname) { + case SO_SNDBUF: + case SO_SNDBUFFORCE: + return udp_get_sndbuf(s, optval, optlen); + case SO_RCVBUF: + case SO_RCVBUFFORCE: + return udp_get_rcvbuf(s, optval, optlen); + case SO_RCVTIMEO: + return udp_get_rcvtimeo(s, optval, optlen); + case SO_COOKIE: + return udp_get_cookie(s, optval, optlen); + case SO_REUSEPORT: + return udp_get_reuse_port(s, optval, optlen); + case SO_REUSEADDR: + return udp_get_reuse_addr(s, optval, optlen); default: - err("%s(%d), unknown level %d\n", __func__, idx, level); + err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, + optname); MUDP_ERR_RET(EINVAL); + } + } + default: + err("%s(%d), unknown level %d\n", __func__, idx, level); + MUDP_ERR_RET(EINVAL); } return 0; } -int mudp_setsockopt(mudp_handle ut, int level, int optname, const void* optval, +int mudp_setsockopt(mudp_handle ut, int level, int optname, const void *optval, socklen_t optlen) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (udp_is_fallback(s)) return setsockopt(s->fallback_fd, level, optname, optval, optlen); switch (level) { - case SOL_SOCKET: { - switch (optname) { - case SO_SNDBUF: - case SO_SNDBUFFORCE: - return udp_set_sndbuf(s, optval, optlen); - case SO_RCVBUF: - case SO_RCVBUFFORCE: - return udp_set_rcvbuf(s, optval, optlen); - case SO_RCVTIMEO: - return udp_set_rcvtimeo(s, optval, optlen); - case SO_COOKIE: - return udp_set_cookie(s, optval, optlen); - case SO_REUSEADDR: /* skip now */ - return udp_set_reuse_addr(s, optval, optlen); - case SO_REUSEPORT: - return udp_set_reuse_port(s, optval, optlen); - default: - err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, optname); - MUDP_ERR_RET(EINVAL); - } + case SOL_SOCKET: { + switch (optname) { + case SO_SNDBUF: + case SO_SNDBUFFORCE: + return udp_set_sndbuf(s, optval, optlen); + case SO_RCVBUF: + case SO_RCVBUFFORCE: + return udp_set_rcvbuf(s, optval, optlen); + case SO_RCVTIMEO: + return udp_set_rcvtimeo(s, optval, optlen); + case SO_COOKIE: + return udp_set_cookie(s, optval, optlen); + case SO_REUSEADDR: /* skip now */ + return udp_set_reuse_addr(s, optval, optlen); + case SO_REUSEPORT: + return udp_set_reuse_port(s, optval, optlen); + default: + err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, + optname); + MUDP_ERR_RET(EINVAL); } - case IPPROTO_IP: { - switch (optname) { - case IP_ADD_MEMBERSHIP: - return udp_add_membership(s, optval, optlen); - case IP_DROP_MEMBERSHIP: - return udp_drop_membership(s, optval, optlen); - case IP_PKTINFO: - info("%s(%d), skip IP_PKTINFO\n", __func__, idx); - return 0; + } + case IPPROTO_IP: { + switch (optname) { + case IP_ADD_MEMBERSHIP: + return udp_add_membership(s, optval, optlen); + case IP_DROP_MEMBERSHIP: + return udp_drop_membership(s, optval, optlen); + case IP_PKTINFO: + info("%s(%d), skip IP_PKTINFO\n", __func__, idx); + return 0; #ifdef IP_RECVTOS - case IP_RECVTOS: - info("%s(%d), skip IP_RECVTOS\n", __func__, idx); - return 0; + case IP_RECVTOS: + info("%s(%d), skip IP_RECVTOS\n", __func__, idx); + return 0; #endif - case IP_MTU_DISCOVER: - info("%s(%d), skip IP_MTU_DISCOVER\n", __func__, idx); - return 0; - case IP_TOS: - dbg("%s(%d), skip IP_TOS\n", __func__, idx); - return 0; - default: - err("%s(%d), unknown optname %d for IPPROTO_IP\n", __func__, idx, optname); - MUDP_ERR_RET(EINVAL); - } - } + case IP_MTU_DISCOVER: + info("%s(%d), skip IP_MTU_DISCOVER\n", __func__, idx); + return 0; + case IP_TOS: + dbg("%s(%d), skip IP_TOS\n", __func__, idx); + return 0; default: - err("%s(%d), unknown level %d\n", __func__, idx, level); + err("%s(%d), unknown optname %d for IPPROTO_IP\n", __func__, idx, + optname); MUDP_ERR_RET(EINVAL); + } + } + default: + err("%s(%d), unknown level %d\n", __func__, idx, level); + MUDP_ERR_RET(EINVAL); } return 0; } int mudp_ioctl(mudp_handle ut, unsigned long cmd, va_list args) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; MTL_MAY_UNUSED(args); #ifndef WINDOWSENV - if (udp_is_fallback(s)) return ioctl(s->fallback_fd, cmd, args); + if (udp_is_fallback(s)) + return ioctl(s->fallback_fd, cmd, args); #endif switch (cmd) { - case FIONBIO: - info("%s(%d), skip FIONBIO now\n", __func__, idx); - break; - default: - err("%s(%d), unknown cmd %d\n", __func__, idx, (int)cmd); - MUDP_ERR_RET(EINVAL); + case FIONBIO: + info("%s(%d), skip FIONBIO now\n", __func__, idx); + break; + default: + err("%s(%d), unknown cmd %d\n", __func__, idx, (int)cmd); + MUDP_ERR_RET(EINVAL); } return 0; } int mudp_set_tx_mac(mudp_handle ut, uint8_t mac[MTL_MAC_ADDR_LEN]) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1714,13 +1772,13 @@ int mudp_set_tx_mac(mudp_handle ut, uint8_t mac[MTL_MAC_ADDR_LEN]) { rte_memcpy(s->user_mac, mac, MTL_MAC_ADDR_LEN); udp_set_flag(s, MUDP_TX_USER_MAC); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", __func__, idx, mac[0], - mac[1], mac[2], mac[3], mac[4], mac[5]); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", __func__, + idx, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); return 0; } int mudp_bind_address_check(mudp_handle ut, bool enable) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1736,7 +1794,7 @@ int mudp_bind_address_check(mudp_handle ut, bool enable) { } int mudp_set_tx_rate(mudp_handle ut, uint64_t bps) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1763,7 +1821,7 @@ int mudp_set_tx_rate(mudp_handle ut, uint64_t bps) { } uint64_t mudp_get_tx_rate(mudp_handle ut) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1775,7 +1833,7 @@ uint64_t mudp_get_tx_rate(mudp_handle ut) { } int mudp_set_tx_timeout(mudp_handle ut, unsigned int us) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1789,7 +1847,7 @@ int mudp_set_tx_timeout(mudp_handle ut, unsigned int us) { } unsigned int mudp_get_tx_timeout(mudp_handle ut) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1801,7 +1859,7 @@ unsigned int mudp_get_tx_timeout(mudp_handle ut) { } int mudp_set_rx_timeout(mudp_handle ut, unsigned int us) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1815,7 +1873,7 @@ int mudp_set_rx_timeout(mudp_handle ut, unsigned int us) { } unsigned int mudp_get_rx_timeout(mudp_handle ut) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1827,7 +1885,7 @@ unsigned int mudp_get_rx_timeout(mudp_handle ut) { } int mudp_set_arp_timeout(mudp_handle ut, unsigned int us) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1841,7 +1899,7 @@ int mudp_set_arp_timeout(mudp_handle ut, unsigned int us) { } unsigned int mudp_get_arp_timeout(mudp_handle ut) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1853,7 +1911,7 @@ unsigned int mudp_get_arp_timeout(mudp_handle ut) { } int mudp_set_rx_ring_count(mudp_handle ut, unsigned int count) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1872,7 +1930,7 @@ int mudp_set_rx_ring_count(mudp_handle ut, unsigned int count) { } int mudp_set_wake_thresh_count(mudp_handle ut, unsigned int count) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1881,12 +1939,13 @@ int mudp_set_wake_thresh_count(mudp_handle ut, unsigned int count) { } s->wake_thresh_count = count; - if (s->rxq) mur_client_set_wake_thresh(s->rxq, count); + if (s->rxq) + mur_client_set_wake_thresh(s->rxq, count); return 0; } int mudp_set_wake_timeout(mudp_handle ut, unsigned int us) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1895,12 +1954,13 @@ int mudp_set_wake_timeout(mudp_handle ut, unsigned int us) { } s->wake_timeout_us = us; - if (s->rxq) mur_client_set_wake_timeout(s->rxq, us); + if (s->rxq) + mur_client_set_wake_timeout(s->rxq, us); return 0; } int mudp_set_rx_poll_sleep(mudp_handle ut, unsigned int us) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1914,7 +1974,7 @@ int mudp_set_rx_poll_sleep(mudp_handle ut, unsigned int us) { } int mudp_get_sip(mudp_handle ut, uint8_t ip[MTL_IP_ADDR_LEN]) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1927,7 +1987,7 @@ int mudp_get_sip(mudp_handle ut, uint8_t ip[MTL_IP_ADDR_LEN]) { } int mudp_tx_valid_ip(mudp_handle ut, uint8_t dip[MTL_IP_ADDR_LEN]) { - struct mudp_impl* s = ut; + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1935,12 +1995,13 @@ int mudp_tx_valid_ip(mudp_handle ut, uint8_t dip[MTL_IP_ADDR_LEN]) { MUDP_ERR_RET(EIO); } - struct mtl_main_impl* impl = s->parent; + struct mtl_main_impl *impl = s->parent; enum mtl_port port = s->port; if (mt_is_multicast_ip(dip)) { return 0; - } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), mt_sip_netmask(impl, port))) { + } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), + mt_sip_netmask(impl, port))) { return 0; } else if (mt_ip_to_u32(mt_sip_gateway(impl, port))) { return 0; @@ -1949,8 +2010,9 @@ int mudp_tx_valid_ip(mudp_handle ut, uint8_t dip[MTL_IP_ADDR_LEN]) { MUDP_ERR_RET(EINVAL); } -int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void* priv), void* priv) { - struct mudp_impl* s = ut; +int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void *priv), + void *priv) { + struct mudp_impl *s = ut; int idx = s->idx; if (s->type != MT_HANDLE_UDP) { @@ -1968,8 +2030,8 @@ int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void* priv), void* pr return 0; } -bool mudp_is_multicast(const struct sockaddr_in* saddr) { - uint8_t* ip = (uint8_t*)&saddr->sin_addr; +bool mudp_is_multicast(const struct sockaddr_in *saddr) { + uint8_t *ip = (uint8_t *)&saddr->sin_addr; bool mcast = mt_is_multicast_ip(ip); dbg("%s, ip %u.%u.%u.%u\n", __func__, ip[0], ip[1], ip[2], ip[3]); return mcast; diff --git a/lib/src/udp/udp_main.h b/lib/src/udp/udp_main.h index dbd650944..727995e28 100644 --- a/lib/src/udp/udp_main.h +++ b/lib/src/udp/udp_main.h @@ -16,10 +16,10 @@ // clang-format on /* On error, -1 is returned, and errno is set appropriately. */ -#define MUDP_ERR_RET(code) \ - do { \ - errno = code; \ - return -1; \ +#define MUDP_ERR_RET(code) \ + do { \ + errno = code; \ + return -1; \ } while (0) /* if bind or not */ @@ -39,12 +39,12 @@ #define MUDP_PREFIX "MU_" struct mudp_impl { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mt_handle_type type; int idx; bool alive; - int (*user_dump)(void* priv); - void* user_dump_priv; + int (*user_dump)(void *priv); + void *user_dump_priv; enum mtl_port port; struct mt_udp_hdr hdr; @@ -53,11 +53,11 @@ struct mudp_impl { int fallback_fd; /* for MTL_PMD_KERNEL_SOCKET */ uint64_t txq_bps; /* bit per sec for q */ - struct mt_txq_entry* txq; - struct mur_client* rxq; + struct mt_txq_entry *txq; + struct mur_client *rxq; unsigned int rx_ring_count; unsigned int rx_poll_sleep_us; - struct rte_mempool* tx_pool; + struct rte_mempool *tx_pool; bool tx_pool_by_queue; uint16_t element_size; unsigned int element_nb; @@ -74,7 +74,7 @@ struct mudp_impl { unsigned int rx_timeout_us; uint8_t user_mac[MTL_MAC_ADDR_LEN]; - uint32_t* mcast_addrs; + uint32_t *mcast_addrs; int mcast_addrs_nb; pthread_mutex_t mcast_addrs_mutex; @@ -116,7 +116,7 @@ struct mudp_impl { int mudp_verify_socket_args(int domain, int type, int protocol); -int mudp_poll_query(struct mudp_pollfd* fds, mudp_nfds_t nfds, int timeout, - int (*query)(void* priv), void* priv); +int mudp_poll_query(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout, + int (*query)(void *priv), void *priv); #endif diff --git a/lib/src/udp/udp_rxq.c b/lib/src/udp/udp_rxq.c index 3ab7b0902..6f7b106fc 100644 --- a/lib/src/udp/udp_rxq.c +++ b/lib/src/udp/udp_rxq.c @@ -11,39 +11,39 @@ /* queue implementation */ -static inline void urq_mgr_lock(struct mudp_rxq_mgr* mgr) { +static inline void urq_mgr_lock(struct mudp_rxq_mgr *mgr) { mt_pthread_mutex_lock(&mgr->mutex); } -static inline void urq_mgr_unlock(struct mudp_rxq_mgr* mgr) { +static inline void urq_mgr_unlock(struct mudp_rxq_mgr *mgr) { mt_pthread_mutex_unlock(&mgr->mutex); } -static inline void urq_lock(struct mur_queue* q) { +static inline void urq_lock(struct mur_queue *q) { mt_pthread_mutex_lock(&q->mutex); } /* return true if try lock succ */ -static inline bool urq_try_lock(struct mur_queue* q) { +static inline bool urq_try_lock(struct mur_queue *q) { int ret = mt_pthread_mutex_try_lock(&q->mutex); return ret == 0 ? true : false; } -static inline void urq_unlock(struct mur_queue* q) { +static inline void urq_unlock(struct mur_queue *q) { mt_pthread_mutex_unlock(&q->mutex); } -static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, +static uint16_t urq_rx_handle(struct mur_queue *q, struct rte_mbuf **pkts, uint16_t nb_pkts) { uint16_t idx = q->rxq_id; - struct rte_mbuf* valid_mbuf[nb_pkts]; + struct rte_mbuf *valid_mbuf[nb_pkts]; uint16_t valid_mbuf_cnt = 0; uint16_t n = 0; /* check if valid udp pkt */ for (uint16_t i = 0; i < nb_pkts; i++) { - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(pkts[i], struct mt_udp_hdr*); - struct rte_ipv4_hdr* ipv4 = &hdr->ipv4; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkts[i], struct mt_udp_hdr *); + struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; if (ipv4->next_proto_id == IPPROTO_UDP) { valid_mbuf[valid_mbuf_cnt] = pkts[i]; @@ -55,7 +55,8 @@ static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, } } - if (!valid_mbuf_cnt) return 0; + if (!valid_mbuf_cnt) + return 0; int clients = q->clients; @@ -67,9 +68,10 @@ static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, /* enqueue the valid mbuf */ if (clients == 1) { - struct mur_client* c = MT_TAILQ_FIRST(&q->client_head); + struct mur_client *c = MT_TAILQ_FIRST(&q->client_head); c->stat_pkt_rx += valid_mbuf_cnt; - n = rte_ring_sp_enqueue_bulk(c->ring, (void**)&valid_mbuf[0], valid_mbuf_cnt, NULL); + n = rte_ring_sp_enqueue_bulk(c->ring, (void **)&valid_mbuf[0], + valid_mbuf_cnt, NULL); if (!n) { dbg("%s(%d), %u pkts enqueue fail\n", __func__, idx, valid_mbuf_cnt); rte_pktmbuf_free_bulk(&valid_mbuf[0], valid_mbuf_cnt); @@ -80,7 +82,7 @@ static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, } urq_lock(q); - struct mur_client* cs[clients]; + struct mur_client *cs[clients]; cs[0] = MT_TAILQ_FIRST(&q->client_head); for (int i = 1; i < clients; i++) { cs[i] = MT_TAILQ_NEXT(cs[i - 1], next); @@ -88,11 +90,11 @@ static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, int last_c_idx = -1; int c_pkts_nb = 0; - struct rte_mbuf* c_pkts[valid_mbuf_cnt]; + struct rte_mbuf *c_pkts[valid_mbuf_cnt]; for (uint16_t i = 0; i < valid_mbuf_cnt; i++) { - struct rte_mbuf* mbuf = valid_mbuf[i]; - struct mt_udp_hdr* hdr = rte_pktmbuf_mtod(mbuf, struct mt_udp_hdr*); + struct rte_mbuf *mbuf = valid_mbuf[i]; + struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(mbuf, struct mt_udp_hdr *); /* hash with ip and port of both src and dst */ uint32_t tuple[3]; rte_memcpy(tuple, &hdr->ipv4.src_addr, sizeof(tuple)); @@ -101,10 +103,10 @@ static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, if (c_idx != last_c_idx) { if (c_pkts_nb) { /* push last client */ - struct mur_client* c = cs[last_c_idx]; + struct mur_client *c = cs[last_c_idx]; c->stat_pkt_rx += c_pkts_nb; - unsigned int e = - rte_ring_sp_enqueue_bulk(c->ring, (void**)&c_pkts[0], c_pkts_nb, NULL); + unsigned int e = rte_ring_sp_enqueue_bulk(c->ring, (void **)&c_pkts[0], + c_pkts_nb, NULL); if (0 == e) { /* enqueue fail */ rte_pktmbuf_free_bulk(c_pkts, c_pkts_nb); c->stat_pkt_rx_enq_fail += c_pkts_nb; @@ -116,10 +118,10 @@ static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, c_pkts[c_pkts_nb++] = mbuf; } if (c_pkts_nb) { /* push last client */ - struct mur_client* c = cs[last_c_idx]; + struct mur_client *c = cs[last_c_idx]; c->stat_pkt_rx += c_pkts_nb; unsigned int e = - rte_ring_sp_enqueue_bulk(c->ring, (void**)&c_pkts[0], c_pkts_nb, NULL); + rte_ring_sp_enqueue_bulk(c->ring, (void **)&c_pkts[0], c_pkts_nb, NULL); if (0 == e) { /* enqueue fail */ rte_pktmbuf_free_bulk(c_pkts, c_pkts_nb); c->stat_pkt_rx_enq_fail += c_pkts_nb; @@ -132,11 +134,12 @@ static uint16_t urq_rx_handle(struct mur_queue* q, struct rte_mbuf** pkts, return n; } -static uint16_t urq_rx(struct mur_queue* q) { +static uint16_t urq_rx(struct mur_queue *q) { uint16_t rx_burst = q->rx_burst_pkts; - struct rte_mbuf* pkts[rx_burst]; + struct rte_mbuf *pkts[rx_burst]; - if (!urq_try_lock(q)) return 0; + if (!urq_try_lock(q)) + return 0; uint16_t rx = mt_rxq_burst(q->rxq, pkts, rx_burst); urq_unlock(q); @@ -146,12 +149,12 @@ static uint16_t urq_rx(struct mur_queue* q) { return n; } -static int urq_mgr_add(struct mudp_rxq_mgr* mgr, struct mur_queue* q) { +static int urq_mgr_add(struct mudp_rxq_mgr *mgr, struct mur_queue *q) { MT_TAILQ_INSERT_TAIL(&mgr->head, q, next); return 0; } -static int urq_mgr_del(struct mudp_rxq_mgr* mgr, struct mur_queue* q) { +static int urq_mgr_del(struct mudp_rxq_mgr *mgr, struct mur_queue *q) { struct mur_queue *item, *tmp_item; for (item = MT_TAILQ_FIRST(&mgr->head); item != NULL; item = tmp_item) { @@ -168,14 +171,15 @@ static int urq_mgr_del(struct mudp_rxq_mgr* mgr, struct mur_queue* q) { return -EIO; } -static struct mur_queue* urq_mgr_search(struct mudp_rxq_mgr* mgr, uint16_t dst_port) { - struct mur_queue* q; - struct mur_queue* ret = NULL; +static struct mur_queue *urq_mgr_search(struct mudp_rxq_mgr *mgr, + uint16_t dst_port) { + struct mur_queue *q; + struct mur_queue *ret = NULL; MT_TAILQ_FOREACH(q, &mgr->head, next) { if (q->dst_port == dst_port) { - info("%s(%d), dst_port %u already on q %p, reuse_port %d\n", __func__, mgr->port, - dst_port, q, q->reuse_port); + info("%s(%d), dst_port %u already on q %p, reuse_port %d\n", __func__, + mgr->port, dst_port, q, q->reuse_port); ret = q; } } @@ -183,8 +187,8 @@ static struct mur_queue* urq_mgr_search(struct mudp_rxq_mgr* mgr, uint16_t dst_p return ret; } -static int urq_put(struct mur_queue* q) { - struct mtl_main_impl* impl = q->parent; +static int urq_put(struct mur_queue *q) { + struct mtl_main_impl *impl = q->parent; if (!rte_atomic32_dec_and_test(&q->refcnt)) { info("%s(%d,%u), refcnt %d\n", __func__, q->port, q->dst_port, @@ -193,11 +197,11 @@ static int urq_put(struct mur_queue* q) { } info("%s(%d,%u), refcnt zero now\n", __func__, q->port, q->dst_port); - struct mudp_rxq_mgr* mgr = impl->mudp_rxq_mgr[q->port]; + struct mudp_rxq_mgr *mgr = impl->mudp_rxq_mgr[q->port]; urq_mgr_lock(mgr); /* check if any not removed client */ - struct mur_client* c; + struct mur_client *c; while ((c = MT_TAILQ_FIRST(&q->client_head))) { warn("%s(%d,%u), %p not removed\n", __func__, q->port, q->dst_port, c); MT_TAILQ_REMOVE(&q->client_head, c, next); @@ -216,13 +220,13 @@ static int urq_put(struct mur_queue* q) { return 0; } -static struct mur_queue* urq_get(struct mudp_rxq_mgr* mgr, - struct mur_client_create* create, int* idx) { - struct mtl_main_impl* impl = create->impl; +static struct mur_queue *urq_get(struct mudp_rxq_mgr *mgr, + struct mur_client_create *create, int *idx) { + struct mtl_main_impl *impl = create->impl; enum mtl_port port = create->port; uint16_t dst_port = create->dst_port; int ret; - struct mur_queue* q = NULL; + struct mur_queue *q = NULL; urq_mgr_lock(mgr); /* get the lock */ @@ -268,8 +272,8 @@ static struct mur_queue* urq_get(struct mudp_rxq_mgr* mgr, q->rxq = mt_rxq_get(impl, port, &flow); if (!q->rxq) { /* wa for e810 pf mode since it doesn't support MT_RXQ_FLOW_F_NO_IP */ - warn("%s(%d,%u), get rxq fail with no ip flow, try cni queue\n", __func__, port, - dst_port); + warn("%s(%d,%u), get rxq fail with no ip flow, try cni queue\n", __func__, + port, dst_port); flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; q->rxq = mt_rxq_get(impl, port, &flow); if (!q->rxq) { @@ -297,11 +301,12 @@ static struct mur_queue* urq_get(struct mudp_rxq_mgr* mgr, out_unlock_fail: urq_mgr_unlock(mgr); - if (q) urq_put(q); + if (q) + urq_put(q); return NULL; } -static int urq_add_client(struct mur_queue* q, struct mur_client* c) { +static int urq_add_client(struct mur_queue *q, struct mur_client *c) { urq_lock(q); MT_TAILQ_INSERT_TAIL(&q->client_head, c, next); q->clients++; @@ -310,7 +315,7 @@ static int urq_add_client(struct mur_queue* q, struct mur_client* c) { return 0; } -static int urq_del_client(struct mur_queue* q, struct mur_client* c) { +static int urq_del_client(struct mur_queue *q, struct mur_client *c) { struct mur_client *item, *tmp_item; urq_lock(q); @@ -333,21 +338,22 @@ static int urq_del_client(struct mur_queue* q, struct mur_client* c) { /* client implementation */ -static inline bool urc_lcore_mode(struct mur_client* c) { +static inline bool urc_lcore_mode(struct mur_client *c) { return c->lcore_tasklet ? true : false; } -static void urc_lcore_wakeup(struct mur_client* c) { +static void urc_lcore_wakeup(struct mur_client *c) { mt_pthread_mutex_lock(&c->lcore_wake_mutex); mt_pthread_cond_signal(&c->lcore_wake_cond); mt_pthread_mutex_unlock(&c->lcore_wake_mutex); } -static int urc_tasklet_handler(void* priv) { - struct mur_client* c = priv; - struct mtl_main_impl* impl = c->parent; +static int urc_tasklet_handler(void *priv) { + struct mur_client *c = priv; + struct mtl_main_impl *impl = c->parent; - if (c->q) urq_rx(c->q); + if (c->q) + urq_rx(c->q); unsigned int count = rte_ring_count(c->ring); if (count > 0) { @@ -361,8 +367,9 @@ static int urc_tasklet_handler(void* priv) { return 0; } -static int urc_init_tasklet(struct mtl_main_impl* impl, struct mur_client* c) { - if (!mt_user_udp_lcore(impl, c->port)) return 0; +static int urc_init_tasklet(struct mtl_main_impl *impl, struct mur_client *c) { + if (!mt_user_udp_lcore(impl, c->port)) + return 0; struct mtl_tasklet_ops ops; char name[32]; @@ -384,21 +391,22 @@ static int urc_init_tasklet(struct mtl_main_impl* impl, struct mur_client* c) { return 0; } -struct mur_client* mur_client_get(struct mur_client_create* create) { - struct mtl_main_impl* impl = create->impl; +struct mur_client *mur_client_get(struct mur_client_create *create) { + struct mtl_main_impl *impl = create->impl; enum mtl_port port = create->port; uint16_t dst_port = create->dst_port; - struct mudp_rxq_mgr* mgr = impl->mudp_rxq_mgr[port]; + struct mudp_rxq_mgr *mgr = impl->mudp_rxq_mgr[port]; int ret; int idx; - struct mur_queue* q = urq_get(mgr, create, &idx); + struct mur_queue *q = urq_get(mgr, create, &idx); if (!q) { err("%s(%d,%u), get queue fail\n", __func__, port, dst_port); return NULL; } - struct mur_client* c = mt_rte_zmalloc_socket(sizeof(*c), mt_socket_id(impl, port)); + struct mur_client *c = + mt_rte_zmalloc_socket(sizeof(*c), mt_socket_id(impl, port)); if (!c) { err("%s(%d,%u), client malloc fail\n", __func__, port, dst_port); urq_put(q); @@ -419,11 +427,12 @@ struct mur_client* mur_client_get(struct mur_client_create* create) { c->wake_tsc_last = mt_get_tsc(impl); char ring_name[64]; - struct rte_ring* ring; + struct rte_ring *ring; unsigned int flags, count; - snprintf(ring_name, sizeof(ring_name), "%sP%dDP%dQ%uC%d", MT_UDP_RXQ_PREFIX, port, - dst_port, q->rxq_id, idx); - flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + snprintf(ring_name, sizeof(ring_name), "%sP%dDP%dQ%uC%d", MT_UDP_RXQ_PREFIX, + port, dst_port, q->rxq_id, idx); + flags = + RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = create->ring_count; ring = rte_ring_create(ring_name, count, mt_socket_id(impl, port), flags); if (!ring) { @@ -452,7 +461,7 @@ struct mur_client* mur_client_get(struct mur_client_create* create) { return c; } -int mur_client_put(struct mur_client* c) { +int mur_client_put(struct mur_client *c) { urc_lcore_wakeup(c); /* wake up any pending wait */ if (c->lcore_tasklet) { @@ -479,23 +488,24 @@ int mur_client_put(struct mur_client* c) { return 0; } -int mur_client_dump(struct mur_client* c) { +int mur_client_dump(struct mur_client *c) { enum mtl_port port = c->port; uint16_t dst_port = c->dst_port; int idx = c->idx; if (c->stat_pkt_rx) { - notice("%s(%d,%u,%d), pkt rx %u\n", __func__, port, dst_port, idx, c->stat_pkt_rx); + notice("%s(%d,%u,%d), pkt rx %u\n", __func__, port, dst_port, idx, + c->stat_pkt_rx); c->stat_pkt_rx = 0; } if (c->stat_pkt_rx_enq_fail) { - warn("%s(%d,%u,%d), pkt rx %u enqueue fail\n", __func__, port, dst_port, idx, - c->stat_pkt_rx_enq_fail); + warn("%s(%d,%u,%d), pkt rx %u enqueue fail\n", __func__, port, dst_port, + idx, c->stat_pkt_rx_enq_fail); c->stat_pkt_rx_enq_fail = 0; } if (c->stat_timedwait) { - notice("%s(%d,%u,%d), timedwait %u timeout %u\n", __func__, port, dst_port, idx, - c->stat_timedwait, c->stat_timedwait_timeout); + notice("%s(%d,%u,%d), timedwait %u timeout %u\n", __func__, port, dst_port, + idx, c->stat_timedwait, c->stat_timedwait_timeout); c->stat_timedwait = 0; c->stat_timedwait_timeout = 0; } @@ -503,14 +513,14 @@ int mur_client_dump(struct mur_client* c) { return 0; } -uint16_t mur_client_rx(struct mur_client* c) { +uint16_t mur_client_rx(struct mur_client *c) { if (urc_lcore_mode(c)) return 0; else return urq_rx(c->q); } -int mur_client_timedwait(struct mur_client* c, unsigned int timedwait_us, +int mur_client_timedwait(struct mur_client *c, unsigned int timedwait_us, unsigned int poll_sleep_us) { if (!urc_lcore_mode(c)) { if (poll_sleep_us) { @@ -529,16 +539,17 @@ int mur_client_timedwait(struct mur_client* c, unsigned int timedwait_us, dbg("%s(%u), timedwait ret %d\n", __func__, q->dst_port, ret); mt_pthread_mutex_unlock(&c->lcore_wake_mutex); - if (ret == ETIMEDOUT) c->stat_timedwait_timeout++; + if (ret == ETIMEDOUT) + c->stat_timedwait_timeout++; return ret; } -int mudp_rxq_init(struct mtl_main_impl* impl) { +int mudp_rxq_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); int socket = mt_socket_id(impl, MTL_PORT_P); for (int i = 0; i < num_ports; i++) { - struct mudp_rxq_mgr* mgr = mt_rte_zmalloc_socket(sizeof(*mgr), socket); + struct mudp_rxq_mgr *mgr = mt_rte_zmalloc_socket(sizeof(*mgr), socket); if (!mgr) { err("%s(%d), mgr malloc fail\n", __func__, i); mudp_rxq_uinit(impl); @@ -556,13 +567,14 @@ int mudp_rxq_init(struct mtl_main_impl* impl) { return 0; } -int mudp_rxq_uinit(struct mtl_main_impl* impl) { - struct mudp_rxq_mgr* mgr; - struct mur_queue* q; +int mudp_rxq_uinit(struct mtl_main_impl *impl) { + struct mudp_rxq_mgr *mgr; + struct mur_queue *q; for (int i = 0; i < MTL_PORT_MAX; i++) { mgr = impl->mudp_rxq_mgr[i]; - if (!mgr) continue; + if (!mgr) + continue; /* check if any not unregister */ while ((q = MT_TAILQ_FIRST(&mgr->head))) { diff --git a/lib/src/udp/udp_rxq.h b/lib/src/udp/udp_rxq.h index 95b6ecba7..f3a29b377 100644 --- a/lib/src/udp/udp_rxq.h +++ b/lib/src/udp/udp_rxq.h @@ -15,18 +15,18 @@ struct mur_queue; struct mur_client { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; uint16_t dst_port; int idx; - struct rte_ring* ring; - struct mur_queue* q; /* the backend queue it attached */ + struct rte_ring *ring; + struct mur_queue *q; /* the backend queue it attached */ /* lcore mode */ pthread_cond_t lcore_wake_cond; pthread_mutex_t lcore_wake_mutex; - struct mt_sch_tasklet_impl* lcore_tasklet; + struct mt_sch_tasklet_impl *lcore_tasklet; /* bulk wakeup mode */ /* wakeup when rte_ring_count(s->rx_ring) reach this threshold */ unsigned int wake_thresh_count; @@ -47,13 +47,13 @@ MT_TAILQ_HEAD(mur_client_list, mur_client); /* support reuse port with load balancer */ struct mur_queue { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; rte_atomic32_t refcnt; int client_idx; /* incremental idx fort client */ pthread_mutex_t mutex; /* clients lock */ - struct mt_rxq_entry* rxq; + struct mt_rxq_entry *rxq; uint16_t rxq_id; uint16_t dst_port; uint16_t rx_burst_pkts; @@ -69,7 +69,7 @@ struct mur_queue { MT_TAILQ_HEAD(mur_queue_list, mur_queue); struct mudp_rxq_mgr { - struct mtl_main_impl* parent; + struct mtl_main_impl *parent; enum mtl_port port; pthread_mutex_t mutex; @@ -77,7 +77,7 @@ struct mudp_rxq_mgr { }; struct mur_client_create { - struct mtl_main_impl* impl; + struct mtl_main_impl *impl; enum mtl_port port; uint16_t dst_port; unsigned int ring_count; @@ -86,29 +86,31 @@ struct mur_client_create { int reuse_port; }; -int mur_client_put(struct mur_client* q); -struct mur_client* mur_client_get(struct mur_client_create* create); -uint16_t mur_client_rx(struct mur_client* q); -int mur_client_dump(struct mur_client* q); +int mur_client_put(struct mur_client *q); +struct mur_client *mur_client_get(struct mur_client_create *create); +uint16_t mur_client_rx(struct mur_client *q); +int mur_client_dump(struct mur_client *q); -int mur_client_timedwait(struct mur_client* cq, unsigned int timedwait_us, +int mur_client_timedwait(struct mur_client *cq, unsigned int timedwait_us, unsigned int poll_sleep_us); -static inline struct rte_ring* mur_client_ring(struct mur_client* c) { +static inline struct rte_ring *mur_client_ring(struct mur_client *c) { return c->ring; } -static inline int mur_client_set_wake_thresh(struct mur_client* c, unsigned int count) { +static inline int mur_client_set_wake_thresh(struct mur_client *c, + unsigned int count) { c->wake_thresh_count = count; return 0; } -static inline int mur_client_set_wake_timeout(struct mur_client* c, unsigned int us) { +static inline int mur_client_set_wake_timeout(struct mur_client *c, + unsigned int us) { c->wake_timeout_us = us; return 0; } -int mudp_rxq_init(struct mtl_main_impl* impl); -int mudp_rxq_uinit(struct mtl_main_impl* impl); +int mudp_rxq_init(struct mtl_main_impl *impl); +int mudp_rxq_uinit(struct mtl_main_impl *impl); #endif diff --git a/lib/src/udp/ufd_main.c b/lib/src/udp/ufd_main.c index 6b2863301..3bf7274b4 100644 --- a/lib/src/udp/ufd_main.c +++ b/lib/src/udp/ufd_main.c @@ -7,10 +7,10 @@ #include "../mt_log.h" #include "udp_main.h" -static struct ufd_mt_ctx* g_ufd_mt_ctx; +static struct ufd_mt_ctx *g_ufd_mt_ctx; static pthread_mutex_t g_ufd_mt_ctx_lock; -static struct mufd_override_params* g_rt_para; -static struct mufd_init_params* g_init_para; +static struct mufd_override_params *g_rt_para; +static struct mufd_init_params *g_init_para; static inline int ufd_mtl_ctx_lock(void) { return mt_pthread_mutex_lock(&g_ufd_mt_ctx_lock); @@ -30,19 +30,19 @@ static int ufd_uinit_global(void) { return 0; } -static inline int ufd_idx2fd(struct ufd_mt_ctx* ctx, int idx) { +static inline int ufd_idx2fd(struct ufd_mt_ctx *ctx, int idx) { return (ctx->init_params.fd_base + idx); } -static inline int ufd_fd2idx(struct ufd_mt_ctx* ctx, int fd) { +static inline int ufd_fd2idx(struct ufd_mt_ctx *ctx, int fd) { return (fd - ctx->init_params.fd_base); } -static inline int ufd_max_slot(struct ufd_mt_ctx* ctx) { +static inline int ufd_max_slot(struct ufd_mt_ctx *ctx) { return ctx->init_params.slots_nb_max; } -static int ufd_free_slot(struct ufd_mt_ctx* ctx, struct ufd_slot* slot) { +static int ufd_free_slot(struct ufd_mt_ctx *ctx, struct ufd_slot *slot) { int idx = slot->idx; if (ctx->slots[idx] != slot) { @@ -58,13 +58,14 @@ static int ufd_free_slot(struct ufd_mt_ctx* ctx, struct ufd_slot* slot) { return 0; } -static int ufd_free_mt_ctx(struct ufd_mt_ctx* ctx) { - struct mtl_main_impl* mt = ctx->mt; +static int ufd_free_mt_ctx(struct ufd_mt_ctx *ctx) { + struct mtl_main_impl *mt = ctx->mt; if (ctx->slots) { for (int i = 0; i < ufd_max_slot(ctx); i++) { /* check if any not free slot */ - if (!ctx->slots[i]) continue; + if (!ctx->slots[i]) + continue; warn("%s, not close slot on idx %d\n", __func__, i); ufd_free_slot(ctx, ctx->slots[i]); } @@ -86,11 +87,11 @@ static int ufd_free_mt_ctx(struct ufd_mt_ctx* ctx) { return 0; } -static int ufd_parse_interfaces(struct mufd_init_params* init, json_object* obj, +static int ufd_parse_interfaces(struct mufd_init_params *init, json_object *obj, enum mtl_port port) { - struct mtl_init_params* p = &init->mt_params; + struct mtl_init_params *p = &init->mt_params; - const char* name = json_object_get_string(mt_json_object_get(obj, "port")); + const char *name = json_object_get_string(mt_json_object_get(obj, "port")); if (!name) { err("%s, no port in the json interface\n", __func__); MUDP_ERR_RET(EINVAL); @@ -98,9 +99,9 @@ static int ufd_parse_interfaces(struct mufd_init_params* init, json_object* obj, snprintf(p->port[port], MTL_PORT_MAX_LEN, "%s", name); enum mtl_pmd_type pmd = mtl_pmd_by_port_name(name); - json_object* obj_item = mt_json_object_get(obj, "proto"); + json_object *obj_item = mt_json_object_get(obj, "proto"); if (obj_item) { - const char* proto = json_object_get_string(obj_item); + const char *proto = json_object_get_string(obj_item); if (strcmp(proto, "dhcp") == 0) { p->net_proto[port] = MTL_PROTO_DHCP; } else if (strcmp(proto, "static") == 0) { @@ -117,7 +118,7 @@ static int ufd_parse_interfaces(struct mufd_init_params* init, json_object* obj, err("%s, no ip in the json interface\n", __func__); MUDP_ERR_RET(EINVAL); } - const char* sip = json_object_get_string(obj_item); + const char *sip = json_object_get_string(obj_item); int ret = inet_pton(AF_INET, sip, p->sip_addr[port]); if (ret != 1) { err("%s, inet pton fail ip %s\n", __func__, sip); @@ -138,17 +139,18 @@ static int ufd_parse_interfaces(struct mufd_init_params* init, json_object* obj, return 0; } -static int ufd_parse_json(struct mufd_init_params* init, const char* filename) { - json_object* root = json_object_from_file(filename); +static int ufd_parse_json(struct mufd_init_params *init, const char *filename) { + json_object *root = json_object_from_file(filename); if (root == NULL) { err("%s, open json file %s fail\n", __func__, filename); MUDP_ERR_RET(EIO); } - info("%s, parse %s with json-c version: %s\n", __func__, filename, json_c_version()); + info("%s, parse %s with json-c version: %s\n", __func__, filename, + json_c_version()); int ret = -EIO; /* parse interfaces for system */ - json_object* interfaces_array = mt_json_object_get(root, "interfaces"); + json_object *interfaces_array = mt_json_object_get(root, "interfaces"); if (interfaces_array == NULL || json_object_get_type(interfaces_array) != json_type_array) { err("%s, can not parse interfaces\n", __func__); @@ -162,12 +164,14 @@ static int ufd_parse_json(struct mufd_init_params* init, const char* filename) { goto out; } for (int i = 0; i < num_interfaces; i++) { - ret = ufd_parse_interfaces(init, json_object_array_get_idx(interfaces_array, i), i); - if (ret < 0) goto out; + ret = ufd_parse_interfaces( + init, json_object_array_get_idx(interfaces_array, i), i); + if (ret < 0) + goto out; } - struct mtl_init_params* p = &init->mt_params; - json_object* obj; + struct mtl_init_params *p = &init->mt_params; + json_object *obj; obj = mt_json_object_get(root, "nb_nic_queues"); if (obj) { @@ -254,7 +258,7 @@ static int ufd_parse_json(struct mufd_init_params* init, const char* filename) { obj = mt_json_object_get(root, "log_level"); if (obj) { - const char* str = json_object_get_string(obj); + const char *str = json_object_get_string(obj); if (str) { if (!strcmp(str, "debug")) p->log_level = MTL_LOG_LEVEL_DEBUG; @@ -276,7 +280,8 @@ static int ufd_parse_json(struct mufd_init_params* init, const char* filename) { int fd_base = json_object_get_int(obj); int limit = INT_MAX / 2; if (fd_base < limit) { - err("%s, invalid fd_base %d, must bigger than %d\n", __func__, fd_base, limit); + err("%s, invalid fd_base %d, must bigger than %d\n", __func__, fd_base, + limit); ret = -EINVAL; goto out; } @@ -359,8 +364,8 @@ static int ufd_parse_json(struct mufd_init_params* init, const char* filename) { return ret; } -static int ufd_set_afxdp(struct ufd_mt_ctx* ctx) { - struct mtl_init_params* p = &ctx->init_params.mt_params; +static int ufd_set_afxdp(struct ufd_mt_ctx *ctx) { + struct mtl_init_params *p = &ctx->init_params.mt_params; for (uint8_t i = 0; i < p->num_ports; i++) { p->pmd[i] = mtl_pmd_by_port_name(p->port[i]); @@ -369,8 +374,8 @@ static int ufd_set_afxdp(struct ufd_mt_ctx* ctx) { return 0; } -static int ufd_config_init(struct ufd_mt_ctx* ctx) { - const char* cfg_path = getenv(MUFD_CFG_ENV_NAME); +static int ufd_config_init(struct ufd_mt_ctx *ctx) { + const char *cfg_path = getenv(MUFD_CFG_ENV_NAME); int ret; if (cfg_path) { @@ -384,10 +389,10 @@ static int ufd_config_init(struct ufd_mt_ctx* ctx) { return ret; } -static struct ufd_mt_ctx* ufd_create_mt_ctx(void) { - struct ufd_mt_ctx* ctx = mt_zmalloc(sizeof(*ctx)); - struct mufd_override_params* rt_para = g_rt_para; - struct mufd_init_params* init_para = g_init_para; +static struct ufd_mt_ctx *ufd_create_mt_ctx(void) { + struct ufd_mt_ctx *ctx = mt_zmalloc(sizeof(*ctx)); + struct mufd_override_params *rt_para = g_rt_para; + struct mufd_init_params *init_para = g_init_para; int ret; if (!ctx) { /* create a new ctx */ @@ -398,7 +403,7 @@ static struct ufd_mt_ctx* ufd_create_mt_ctx(void) { mt_pthread_mutex_init(&ctx->slots_lock, NULL); /* init mtl context */ - struct mtl_init_params* p = &ctx->init_params.mt_params; + struct mtl_init_params *p = &ctx->init_params.mt_params; p->flags |= MTL_FLAG_BIND_NUMA; /* default bind to numa */ p->log_level = MTL_LOG_LEVEL_INFO; /* default to info */ @@ -418,19 +423,25 @@ static struct ufd_mt_ctx* ufd_create_mt_ctx(void) { if (rt_para) { info("%s, applied override config\n", __func__); p->log_level = rt_para->log_level; - if (rt_para->shared_tx_queue) p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - if (rt_para->shared_rx_queue) p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - if (rt_para->rss_mode) p->rss_mode = rt_para->rss_mode; - if (rt_para->lcore_mode) p->flags |= MTL_FLAG_UDP_LCORE; + if (rt_para->shared_tx_queue) + p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + if (rt_para->shared_rx_queue) + p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + if (rt_para->rss_mode) + p->rss_mode = rt_para->rss_mode; + if (rt_para->lcore_mode) + p->flags |= MTL_FLAG_UDP_LCORE; } } /* assign a default if not set by user */ - if (!ctx->init_params.slots_nb_max) ctx->init_params.slots_nb_max = 1024; + if (!ctx->init_params.slots_nb_max) + ctx->init_params.slots_nb_max = 1024; /* ufd is assigned to top of INT, the bottom fd is used by OS */ if (!ctx->init_params.fd_base) ctx->init_params.fd_base = INT_MAX - ctx->init_params.slots_nb_max * 2; - if (!ctx->init_params.txq_bps) ctx->init_params.txq_bps = MUDP_DEFAULT_RL_BPS; + if (!ctx->init_params.txq_bps) + ctx->init_params.txq_bps = MUDP_DEFAULT_RL_BPS; /* udp lcore and shared queue, set tasklets_nb_per_sch to allow max slots */ if ((p->flags & (MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE)) && @@ -463,8 +474,8 @@ static struct ufd_mt_ctx* ufd_create_mt_ctx(void) { } /* save ctx with dpdk rte memory which can be shared between process */ - struct ufd_mt_ctx* ctx_rte = - mt_rte_zmalloc_socket(sizeof(*ctx_rte), mt_socket_id(ctx->mt, MTL_PORT_P)); + struct ufd_mt_ctx *ctx_rte = mt_rte_zmalloc_socket( + sizeof(*ctx_rte), mt_socket_id(ctx->mt, MTL_PORT_P)); if (!ctx_rte) { err("%s, ctx_rte malloc fail\n", __func__); ufd_free_mt_ctx(ctx); @@ -479,8 +490,8 @@ static struct ufd_mt_ctx* ufd_create_mt_ctx(void) { return ctx_rte; } -static struct ufd_mt_ctx* ufd_get_mt_ctx(bool create) { - struct ufd_mt_ctx* ctx = NULL; +static struct ufd_mt_ctx *ufd_get_mt_ctx(bool create) { + struct ufd_mt_ctx *ctx = NULL; if (create) { /* require lock as get/create the mt ctx */ ufd_mtl_ctx_lock(); @@ -506,27 +517,29 @@ static void ufd_clear_mt_ctx(void) { dbg("%s, succ\n", __func__); } -static inline struct ufd_slot* ufd_fd2slot(int sockfd) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); +static inline struct ufd_slot *ufd_fd2slot(int sockfd) { + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); if (sockfd < ctx->init_params.fd_base) { err("%s, invalid sockfd %d, base is %d\n", __func__, sockfd, ctx->init_params.fd_base); return NULL; } int idx = ufd_fd2idx(ctx, sockfd); - struct ufd_slot* slot = ctx->slots[idx]; + struct ufd_slot *slot = ctx->slots[idx]; - if (!slot) err("%s, invalid sockfd %d\n", __func__, sockfd); + if (!slot) + err("%s, invalid sockfd %d\n", __func__, sockfd); return slot; } int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port) { int ret; - struct ufd_mt_ctx* ctx; - struct ufd_slot* slot = NULL; + struct ufd_mt_ctx *ctx; + struct ufd_slot *slot = NULL; ret = mudp_verify_socket_args(domain, type, protocol); - if (ret < 0) return ret; + if (ret < 0) + return ret; ctx = ufd_get_mt_ctx(true); if (!ctx) { err("%s, fail to get ufd mt ctx\n", __func__); @@ -540,7 +553,8 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port) { /* find one empty slot */ mt_pthread_mutex_lock(&ctx->slots_lock); for (int i = 0; i < ufd_max_slot(ctx); i++) { - if (ctx->slots[i]) continue; + if (ctx->slots[i]) + continue; /* create a slot */ slot = mt_rte_zmalloc_socket(sizeof(*slot), mt_socket_id(ctx->mt, port)); if (!slot) { @@ -575,7 +589,8 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port) { if (ctx->init_params.rx_ring_count) mudp_set_rx_ring_count(slot->handle, ctx->init_params.rx_ring_count); if (ctx->init_params.wake_thresh_count) - mudp_set_wake_thresh_count(slot->handle, ctx->init_params.wake_thresh_count); + mudp_set_wake_thresh_count(slot->handle, + ctx->init_params.wake_thresh_count); if (ctx->init_params.wake_timeout_us) mudp_set_wake_timeout(slot->handle, ctx->init_params.wake_timeout_us); /* allow to set zero to disable sleep */ @@ -590,7 +605,7 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port) { int mufd_socket(int domain, int type, int protocol) { enum mtl_port port = MTL_PORT_P; /* port select from env */ - const char* port_u = getenv(MUFD_PORT_ENV_NAME); + const char *port_u = getenv(MUFD_PORT_ENV_NAME); if (port_u) { port = atoi(port_u); dbg("%s, port_u %s port %d\n", __func__, port_u, port); @@ -599,9 +614,9 @@ int mufd_socket(int domain, int type, int protocol) { } int mufd_close(int sockfd) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); int idx = ufd_fd2idx(ctx, sockfd); - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); if (!slot) { err("%s(%d), null slot for fd %d\n", __func__, idx, sockfd); @@ -612,26 +627,26 @@ int mufd_close(int sockfd) { return 0; } -int mufd_bind(int sockfd, const struct sockaddr* addr, socklen_t addrlen) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +int mufd_bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_bind(slot->handle, addr, addrlen); } -ssize_t mufd_sendto(int sockfd, const void* buf, size_t len, int flags, - const struct sockaddr* dest_addr, socklen_t addrlen) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +ssize_t mufd_sendto(int sockfd, const void *buf, size_t len, int flags, + const struct sockaddr *dest_addr, socklen_t addrlen) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_sendto(slot->handle, buf, len, flags, dest_addr, addrlen); } -ssize_t mufd_sendmsg(int sockfd, const struct msghdr* msg, int flags) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +ssize_t mufd_sendmsg(int sockfd, const struct msghdr *msg, int flags) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_sendmsg(slot->handle, msg, flags); } -int mufd_poll_query(struct pollfd* fds, nfds_t nfds, int timeout, - int (*query)(void* priv), void* priv) { +int mufd_poll_query(struct pollfd *fds, nfds_t nfds, int timeout, + int (*query)(void *priv), void *priv) { struct mudp_pollfd mfds[nfds]; - struct ufd_slot* slot; + struct ufd_slot *slot; for (nfds_t i = 0; i < nfds; i++) { dbg("%s, fd %d\n", __func__, fds[i].fd); @@ -647,34 +662,35 @@ int mufd_poll_query(struct pollfd* fds, nfds_t nfds, int timeout, return ret; } -int mufd_poll(struct pollfd* fds, nfds_t nfds, int timeout) { +int mufd_poll(struct pollfd *fds, nfds_t nfds, int timeout) { return mufd_poll_query(fds, nfds, timeout, NULL, NULL); } -ssize_t mufd_recvfrom(int sockfd, void* buf, size_t len, int flags, - struct sockaddr* src_addr, socklen_t* addrlen) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +ssize_t mufd_recvfrom(int sockfd, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_recvfrom(slot->handle, buf, len, flags, src_addr, addrlen); } -ssize_t mufd_recvmsg(int sockfd, struct msghdr* msg, int flags) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +ssize_t mufd_recvmsg(int sockfd, struct msghdr *msg, int flags) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_recvmsg(slot->handle, msg, flags); } -int mufd_getsockopt(int sockfd, int level, int optname, void* optval, socklen_t* optlen) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +int mufd_getsockopt(int sockfd, int level, int optname, void *optval, + socklen_t *optlen) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_getsockopt(slot->handle, level, optname, optval, optlen); } -int mufd_setsockopt(int sockfd, int level, int optname, const void* optval, +int mufd_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_setsockopt(slot->handle, level, optname, optval, optlen); } int mufd_fcntl(int sockfd, int cmd, va_list args) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); int idx = slot->idx; MTL_MAY_UNUSED(args); @@ -693,12 +709,12 @@ int mufd_fcntl(int sockfd, int cmd, va_list args) { } int mufd_ioctl(int sockfd, unsigned long cmd, va_list args) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_ioctl(slot->handle, cmd, args); } int mufd_cleanup(void) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); if (ctx) { pid_t pid = getpid(); if (pid == ctx->parent_pid) { @@ -709,13 +725,13 @@ int mufd_cleanup(void) { ufd_clear_mt_ctx(); } - struct mufd_override_params* rt_para = g_rt_para; + struct mufd_override_params *rt_para = g_rt_para; if (rt_para) { mt_free(rt_para); g_rt_para = NULL; } - struct mufd_init_params* init_para = g_init_para; + struct mufd_init_params *init_para = g_init_para; if (init_para) { mt_free(init_para); g_init_para = NULL; @@ -738,33 +754,34 @@ RTE_FINI_PRIO(mufd_finish_global, BUS) { } int mufd_abort(void) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); - if (ctx) mtl_abort(ctx->mt); + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); + if (ctx) + mtl_abort(ctx->mt); return 0; } int mufd_set_tx_mac(int sockfd, uint8_t mac[MTL_MAC_ADDR_LEN]) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_set_tx_mac(slot->handle, mac); } int mufd_set_tx_rate(int sockfd, uint64_t bps) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_set_tx_rate(slot->handle, bps); } uint64_t mufd_get_tx_rate(int sockfd) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_get_tx_rate(slot->handle); } -int mufd_commit_override_params(struct mufd_override_params* p) { +int mufd_commit_override_params(struct mufd_override_params *p) { if (g_rt_para) { err("%s, already committed\n", __func__); MUDP_ERR_RET(EIO); } - struct mufd_override_params* out = mt_zmalloc(sizeof(*out)); + struct mufd_override_params *out = mt_zmalloc(sizeof(*out)); if (!out) { err("%s, malloc out fail\n", __func__); MUDP_ERR_RET(ENOMEM); @@ -775,13 +792,13 @@ int mufd_commit_override_params(struct mufd_override_params* p) { return 0; } -int mufd_commit_init_params(struct mufd_init_params* p) { +int mufd_commit_init_params(struct mufd_init_params *p) { if (g_init_para) { err("%s, already committed\n", __func__); MUDP_ERR_RET(EIO); } - struct mufd_init_params* out = mt_zmalloc(sizeof(*out)); + struct mufd_init_params *out = mt_zmalloc(sizeof(*out)); if (!out) { err("%s, malloc out fail\n", __func__); MUDP_ERR_RET(ENOMEM); @@ -793,7 +810,7 @@ int mufd_commit_init_params(struct mufd_init_params* p) { } int mufd_get_sessions_max_nb(void) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(true); + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(true); if (!ctx) { err("%s, fail to get ufd mt ctx\n", __func__); MUDP_ERR_RET(EIO); @@ -803,25 +820,28 @@ int mufd_get_sessions_max_nb(void) { } int mufd_init_context(void) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(true); - if (!ctx) MUDP_ERR_RET(EIO); + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(true); + if (!ctx) + MUDP_ERR_RET(EIO); return 0; } int mufd_base_fd(void) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(true); - if (!ctx) MUDP_ERR_RET(EIO); + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(true); + if (!ctx) + MUDP_ERR_RET(EIO); return ctx->init_params.fd_base; } enum mtl_log_level mufd_log_level(void) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(true); - if (!ctx) return MTL_LOG_LEVEL_INFO; + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(true); + if (!ctx) + return MTL_LOG_LEVEL_INFO; return ctx->init_params.mt_params.log_level; } -void* mufd_hp_malloc(size_t size, enum mtl_port port) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); +void *mufd_hp_malloc(size_t size, enum mtl_port port) { + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); if (!ctx) { err("%s, ctx get fail\n", __func__); return NULL; @@ -830,8 +850,8 @@ void* mufd_hp_malloc(size_t size, enum mtl_port port) { return mtl_hp_malloc(ctx->mt, size, port); } -void* mufd_hp_zmalloc(size_t size, enum mtl_port port) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); +void *mufd_hp_zmalloc(size_t size, enum mtl_port port) { + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); if (!ctx) { err("%s, ctx get fail\n", __func__); return NULL; @@ -840,8 +860,8 @@ void* mufd_hp_zmalloc(size_t size, enum mtl_port port) { return mtl_hp_zmalloc(ctx->mt, size, port); } -void mufd_hp_free(void* ptr) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); +void mufd_hp_free(void *ptr) { + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); if (!ctx) { err("%s, ctx get fail\n", __func__); return; @@ -850,8 +870,8 @@ void mufd_hp_free(void* ptr) { return mtl_hp_free(ctx->mt, ptr); } -int mufd_set_opaque(int sockfd, void* pri) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +int mufd_set_opaque(int sockfd, void *pri) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); int idx = slot->idx; if (slot->opaque) { @@ -863,23 +883,24 @@ int mufd_set_opaque(int sockfd, void* pri) { return 0; } -void* mufd_get_opaque(int sockfd) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +void *mufd_get_opaque(int sockfd) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return slot->opaque; } int mufd_get_sip(int sockfd, uint8_t ip[MTL_IP_ADDR_LEN]) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_get_sip(slot->handle, ip); } int mufd_tx_valid_ip(int sockfd, uint8_t dip[MTL_IP_ADDR_LEN]) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_tx_valid_ip(slot->handle, dip); } -int mufd_register_stat_dump_cb(int sockfd, int (*dump)(void* priv), void* priv) { - struct ufd_slot* slot = ufd_fd2slot(sockfd); +int mufd_register_stat_dump_cb(int sockfd, int (*dump)(void *priv), + void *priv) { + struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_register_stat_dump_cb(slot->handle, dump, priv); } @@ -890,7 +911,7 @@ int mufd_socket_check(int domain, int type, int protocol) { int mufd_port_ip_info(enum mtl_port port, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN], uint8_t gateway[MTL_IP_ADDR_LEN]) { - struct ufd_mt_ctx* ctx = ufd_get_mt_ctx(false); + struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); if (!ctx) { err("%s, ctx get fail\n", __func__); return -EIO; diff --git a/lib/src/udp/ufd_main.h b/lib/src/udp/ufd_main.h index 718ac7850..7e1973f28 100644 --- a/lib/src/udp/ufd_main.h +++ b/lib/src/udp/ufd_main.h @@ -19,17 +19,17 @@ struct ufd_slot { mudp_handle handle; int idx; - void* opaque; + void *opaque; }; struct ufd_mt_ctx { struct mufd_init_params init_params; - struct mtl_main_impl* mt; + struct mtl_main_impl *mt; bool alloc_with_rte; pid_t parent_pid; int slot_last_idx; - struct ufd_slot** slots; /* slots with init_params.slots_nb_max */ + struct ufd_slot **slots; /* slots with init_params.slots_nb_max */ pthread_mutex_t slots_lock; /* lock slots */ }; diff --git a/lib/windows/win_posix.c b/lib/windows/win_posix.c index d277284d6..0303a8509 100644 --- a/lib/windows/win_posix.c +++ b/lib/windows/win_posix.c @@ -14,8 +14,9 @@ int shmget(key_t key, size_t size, int shmflg) { MTL_MAY_UNUSED(key); MTL_MAY_UNUSED(shmflg); int id = -1; - HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, - size >> 32, size & 0xffffffff, szName); + HANDLE hMapFile = + CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, size >> 32, + size & 0xffffffff, szName); if (hMapFile != NULL) { map_info[numberofmapping].maphandle = hMapFile; map_info[numberofmapping].size = size; @@ -25,21 +26,21 @@ int shmget(key_t key, size_t size, int shmflg) { return id; } -void* shmat(int shmid, const void* shmaddr, int shmflg) { +void *shmat(int shmid, const void *shmaddr, int shmflg) { MTL_MAY_UNUSED(shmaddr); MTL_MAY_UNUSED(shmflg); - void* pBuf = - MapViewOfFile(map_info[shmid].maphandle, FILE_MAP_ALL_ACCESS, 0, - map_info[shmid].size >> 32, map_info[shmid].size & 0xffffffff); + void *pBuf = MapViewOfFile(map_info[shmid].maphandle, FILE_MAP_ALL_ACCESS, 0, + map_info[shmid].size >> 32, + map_info[shmid].size & 0xffffffff); return pBuf; } -int shmdt(const void* shmaddr) { +int shmdt(const void *shmaddr) { int ret = UnmapViewOfFile(shmaddr); return ret ? 0 : 1; } -int shmctl(int shmid, int cmd, struct shmid_ds* buf) { +int shmctl(int shmid, int cmd, struct shmid_ds *buf) { MTL_MAY_UNUSED(shmid); if (cmd == IPC_STAT) { @@ -57,7 +58,7 @@ int shmctl(int shmid, int cmd, struct shmid_ds* buf) { */ #define DELTA_EPOCH_IN_100NS INT64_C(116444736000000000) -int clock_gettime(int clk_id, struct timespec* tp) { +int clock_gettime(int clk_id, struct timespec *tp) { unsigned __int64 t; LARGE_INTEGER pf, pc; union { @@ -66,29 +67,32 @@ int clock_gettime(int clk_id, struct timespec* tp) { } ct; switch (clk_id) { - case CLOCK_REALTIME: { - GetSystemTimePreciseAsFileTime(&ct.ft); - t = ct.u64 - DELTA_EPOCH_IN_100NS; - tp->tv_sec = t / POW10_7; - tp->tv_nsec = ((int)(t % POW10_7)) * 100; - return 0; - } + case CLOCK_REALTIME: { + GetSystemTimePreciseAsFileTime(&ct.ft); + t = ct.u64 - DELTA_EPOCH_IN_100NS; + tp->tv_sec = t / POW10_7; + tp->tv_nsec = ((int)(t % POW10_7)) * 100; + return 0; + } - case CLOCK_MONOTONIC: { - if (QueryPerformanceFrequency(&pf) == 0) return -1; - if (QueryPerformanceCounter(&pc) == 0) return -1; - tp->tv_sec = pc.QuadPart / pf.QuadPart; - tp->tv_nsec = (int)(((pc.QuadPart % pf.QuadPart) * POW10_9 + (pf.QuadPart >> 1)) / - pf.QuadPart); - if (tp->tv_nsec >= POW10_9) { - tp->tv_sec++; - tp->tv_nsec -= POW10_9; - } - return 0; + case CLOCK_MONOTONIC: { + if (QueryPerformanceFrequency(&pf) == 0) + return -1; + if (QueryPerformanceCounter(&pc) == 0) + return -1; + tp->tv_sec = pc.QuadPart / pf.QuadPart; + tp->tv_nsec = + (int)(((pc.QuadPart % pf.QuadPart) * POW10_9 + (pf.QuadPart >> 1)) / + pf.QuadPart); + if (tp->tv_nsec >= POW10_9) { + tp->tv_sec++; + tp->tv_nsec -= POW10_9; } + return 0; + } - default: - break; + default: + break; } return -1; diff --git a/lib/windows/win_posix.h b/lib/windows/win_posix.h index aa6df1396..a23067bb4 100644 --- a/lib/windows/win_posix.h +++ b/lib/windows/win_posix.h @@ -107,8 +107,8 @@ struct shmid_ds { pid_t shm_lpid; unsigned short shm_nattch; unsigned short shm_unused; - void* shm_unused2; - void* shm_unused3; + void *shm_unused2; + void *shm_unused3; }; static int inline flock(int fd, int operation) { @@ -117,41 +117,40 @@ static int inline flock(int fd, int operation) { return 0; } -static key_t inline ftok(const char* path, int id) { +static key_t inline ftok(const char *path, int id) { MTL_MAY_UNUSED(path); MTL_MAY_UNUSED(id); return 0; } -void* shmat(int shmid, const void* shmaddr, int shmflg); -int shmctl(int shmid, int cmd, struct shmid_ds* buf); -int shmdt(const void* shmaddr); +void *shmat(int shmid, const void *shmaddr, int shmflg); +int shmctl(int shmid, int cmd, struct shmid_ds *buf); +int shmdt(const void *shmaddr); int shmget(key_t key, size_t size, int shmflg); typedef intptr_t pthread_cond_t; typedef int pthread_condattr_t; -#ifdef __MTL_LIB_BUILD__ // only lib need this typedef +#ifdef __MTL_LIB_BUILD__ // only lib need this typedef typedef rte_cpuset_t cpu_set_t; #endif #define localtime_r(T, Tm) (localtime_s(Tm, T) ? NULL : Tm) pthread_t pthread_self(void); -int pthread_cond_signal(pthread_cond_t* cv); -int pthread_cond_init(pthread_cond_t* cv, const pthread_condattr_t* a); -int pthread_cond_wait(pthread_cond_t* cv, pthread_mutex_t* external_mutex); -int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, - const struct timespec* time); -int pthread_cond_destroy(pthread_cond_t* cv); -int pthread_mutex_trylock(pthread_mutex_t* mutex); +int pthread_cond_signal(pthread_cond_t *cv); +int pthread_cond_init(pthread_cond_t *cv, const pthread_condattr_t *a); +int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *external_mutex); +int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, + const struct timespec *time); +int pthread_cond_destroy(pthread_cond_t *cv); +int pthread_mutex_trylock(pthread_mutex_t *mutex); -int clock_gettime(int clk_id, struct timespec* tp); /* use precise time for windows */ +int clock_gettime(int clk_id, + struct timespec *tp); /* use precise time for windows */ #ifdef __MTL_LIB_BUILD__ -static inline pid_t getpid() { - return GetCurrentProcessId(); -} +static inline pid_t getpid() { return GetCurrentProcessId(); } #endif #endif diff --git a/manager/logging.hpp b/manager/logging.hpp index 7dd578881..83841b2a3 100644 --- a/manager/logging.hpp +++ b/manager/logging.hpp @@ -13,41 +13,40 @@ enum class log_level { DEBUG, INFO, WARNING, ERROR }; class logger { - public: - static void log(log_level level, const std::string& message) { +public: + static void log(log_level level, const std::string &message) { if (level >= log_level_min) { print_log_header(level); std::cout << message << std::endl; } } - static void set_log_level(log_level level) { - log_level_min = level; - } + static void set_log_level(log_level level) { log_level_min = level; } - private: +private: static log_level log_level_min; static void print_log_header(log_level level) { - auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - const char* level_str = get_log_level_string(level); + auto now = + std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + const char *level_str = get_log_level_string(level); - std::cout << "[" << std::put_time(std::localtime(&now), "%F %T") << "] [" << level_str - << "] "; + std::cout << "[" << std::put_time(std::localtime(&now), "%F %T") << "] [" + << level_str << "] "; } - static const char* get_log_level_string(log_level level) { + static const char *get_log_level_string(log_level level) { switch (level) { - case log_level::DEBUG: - return "DEBUG"; - case log_level::INFO: - return "INFO"; - case log_level::WARNING: - return "WARNING"; - case log_level::ERROR: - return "ERROR"; - default: - return "UNKNOWN"; + case log_level::DEBUG: + return "DEBUG"; + case log_level::INFO: + return "INFO"; + case log_level::WARNING: + return "WARNING"; + case log_level::ERROR: + return "ERROR"; + default: + return "UNKNOWN"; } } }; diff --git a/manager/mtl.xdp.c b/manager/mtl.xdp.c index c680141dc..f49fc7485 100644 --- a/manager/mtl.xdp.c +++ b/manager/mtl.xdp.c @@ -26,38 +26,43 @@ struct { } XDP_RUN_CONFIG(mtl_dp_filter); static int __always_inline lookup_udp4_dp(__u16 dp) { - __u8* value; + __u8 *value; value = bpf_map_lookup_elem(&udp4_dp_filter, &dp); - if (value && *value != 0) return 1; + if (value && *value != 0) + return 1; return 0; } SEC("xdp") -int mtl_dp_filter(struct xdp_md* ctx) { - void* data_end = (void*)(long)ctx->data_end; - void* data = (void*)(long)ctx->data; +int mtl_dp_filter(struct xdp_md *ctx) { + void *data_end = (void *)(long)ctx->data_end; + void *data = (void *)(long)ctx->data; struct hdr_cursor nh; - struct ethhdr* eth; + struct ethhdr *eth; int eth_type; nh.pos = data; eth_type = parse_ethhdr(&nh, data_end, ð); - if (eth_type != bpf_htons(ETH_P_IP)) return XDP_PASS; + if (eth_type != bpf_htons(ETH_P_IP)) + return XDP_PASS; - struct iphdr* iphdr; + struct iphdr *iphdr; int ip_type; ip_type = parse_iphdr(&nh, data_end, &iphdr); - if (ip_type != IPPROTO_UDP) return XDP_PASS; + if (ip_type != IPPROTO_UDP) + return XDP_PASS; - struct udphdr* udphdr; + struct udphdr *udphdr; int ret; ret = parse_udphdr(&nh, data_end, &udphdr); - if (ret < 0) return XDP_PASS; + if (ret < 0) + return XDP_PASS; __u16 dst_port = bpf_ntohs(udphdr->dest); - if (lookup_udp4_dp(dst_port) == 0) return XDP_PASS; + if (lookup_udp4_dp(dst_port) == 0) + return XDP_PASS; /* go to next program: xsk_def_prog */ return XDP_DROP; diff --git a/manager/mtl_instance.hpp b/manager/mtl_instance.hpp index 830860e80..c4da9b95c 100644 --- a/manager/mtl_instance.hpp +++ b/manager/mtl_instance.hpp @@ -21,7 +21,7 @@ #include "mtl_mproto.h" class mtl_instance { - private: +private: const int conn_fd; bool is_registered; int pid; @@ -30,26 +30,29 @@ class mtl_instance { std::unordered_set lcore_ids; std::unordered_map> interfaces; std::unordered_map> if_queue_ids; - std::unordered_map> if_flow_ids; + std::unordered_map> + if_flow_ids; - private: - void log(const log_level& level, const std::string& message) const { - logger::log(level, - "[Instance " + hostname + ":" + std::to_string(pid) + "] " + message); +private: + void log(const log_level &level, const std::string &message) const { + logger::log(level, "[Instance " + hostname + ":" + std::to_string(pid) + + "] " + message); } - void handle_message_get_lcore(mtl_lcore_message_t* lcore_msg); - void handle_message_put_lcore(mtl_lcore_message_t* lcore_msg); - void handle_message_register(mtl_register_message_t* register_msg); - void handle_message_if_xsk_map_fd(mtl_if_message_t* if_msg); - void handle_message_udp_dp_filter(mtl_udp_dp_filter_message_t* udp_dp_filter_msg, - bool add); - void handle_message_if_get_queue(mtl_if_message_t* if_msg); - void handle_message_if_put_queue(mtl_if_message_t* if_msg); - void handle_message_if_add_flow(mtl_if_message_t* if_msg); - void handle_message_if_del_flow(mtl_if_message_t* if_msg); - - int send_response(int response, mtl_message_type_t type = MTL_MSG_TYPE_RESPONSE) { + void handle_message_get_lcore(mtl_lcore_message_t *lcore_msg); + void handle_message_put_lcore(mtl_lcore_message_t *lcore_msg); + void handle_message_register(mtl_register_message_t *register_msg); + void handle_message_if_xsk_map_fd(mtl_if_message_t *if_msg); + void + handle_message_udp_dp_filter(mtl_udp_dp_filter_message_t *udp_dp_filter_msg, + bool add); + void handle_message_if_get_queue(mtl_if_message_t *if_msg); + void handle_message_if_put_queue(mtl_if_message_t *if_msg); + void handle_message_if_add_flow(mtl_if_message_t *if_msg); + void handle_message_if_del_flow(mtl_if_message_t *if_msg); + + int send_response(int response, + mtl_message_type_t type = MTL_MSG_TYPE_RESPONSE) { mtl_message_t msg; msg.header.magic = htonl(MTL_MANAGER_MAGIC); msg.header.type = (mtl_message_type_t)htonl(type); @@ -59,14 +62,15 @@ class mtl_instance { } std::shared_ptr get_interface(const unsigned int ifindex); - public: +public: mtl_instance(int conn_fd) - : conn_fd(conn_fd), is_registered(false), pid(-1), uid(-1), hostname("unknown") { - } + : conn_fd(conn_fd), is_registered(false), pid(-1), uid(-1), + hostname("unknown") {} ~mtl_instance() { log(log_level::INFO, "Remove client."); - for (const auto& lcore_id : lcore_ids) mtl_lcore::get_instance().put_lcore(lcore_id); - for (auto& pair : if_queue_ids) { + for (const auto &lcore_id : lcore_ids) + mtl_lcore::get_instance().put_lcore(lcore_id); + for (auto &pair : if_queue_ids) { auto interface = get_interface(pair.first); if (interface != nullptr) { for (uint16_t id : pair.second) { @@ -75,7 +79,7 @@ class mtl_instance { pair.second.clear(); } } - for (auto& pair : if_flow_ids) { + for (auto &pair : if_flow_ids) { auto interface = get_interface(pair.first); if (interface != nullptr) { for (unsigned int id : pair.second) { @@ -88,67 +92,60 @@ class mtl_instance { close(conn_fd); } - int get_conn_fd() const { - return conn_fd; - } - int get_pid() const { - return pid; - } - int get_uid() const { - return uid; - } - std::string get_hostname() const { - return hostname; - } - void handle_message(const char* buf, int len); + int get_conn_fd() const { return conn_fd; } + int get_pid() const { return pid; } + int get_uid() const { return uid; } + std::string get_hostname() const { return hostname; } + void handle_message(const char *buf, int len); }; -void mtl_instance::handle_message(const char* buf, int len) { - if ((size_t)len < sizeof(mtl_message_t)) return; - mtl_message_t* msg = (mtl_message_t*)buf; +void mtl_instance::handle_message(const char *buf, int len) { + if ((size_t)len < sizeof(mtl_message_t)) + return; + mtl_message_t *msg = (mtl_message_t *)buf; if (ntohl(msg->header.magic) != MTL_MANAGER_MAGIC) { log(log_level::ERROR, "Invalid magic"); return; } switch (ntohl(msg->header.type)) { - case MTL_MSG_TYPE_REGISTER: - handle_message_register(&msg->body.register_msg); - break; - case MTL_MSG_TYPE_GET_LCORE: - handle_message_get_lcore(&msg->body.lcore_msg); - break; - case MTL_MSG_TYPE_PUT_LCORE: - handle_message_put_lcore(&msg->body.lcore_msg); - break; - case MTL_MSG_TYPE_IF_XSK_MAP_FD: - handle_message_if_xsk_map_fd(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_ADD_UDP_DP_FILTER: - handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, true); - break; - case MTL_MSG_TYPE_DEL_UDP_DP_FILTER: - handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, false); - break; - case MTL_MSG_TYPE_IF_GET_QUEUE: - handle_message_if_get_queue(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_IF_PUT_QUEUE: - handle_message_if_put_queue(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_IF_ADD_FLOW: - handle_message_if_add_flow(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_IF_DEL_FLOW: - handle_message_if_del_flow(&msg->body.if_msg); - break; - default: - log(log_level::ERROR, "Unknown message type"); - break; + case MTL_MSG_TYPE_REGISTER: + handle_message_register(&msg->body.register_msg); + break; + case MTL_MSG_TYPE_GET_LCORE: + handle_message_get_lcore(&msg->body.lcore_msg); + break; + case MTL_MSG_TYPE_PUT_LCORE: + handle_message_put_lcore(&msg->body.lcore_msg); + break; + case MTL_MSG_TYPE_IF_XSK_MAP_FD: + handle_message_if_xsk_map_fd(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_ADD_UDP_DP_FILTER: + handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, true); + break; + case MTL_MSG_TYPE_DEL_UDP_DP_FILTER: + handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, false); + break; + case MTL_MSG_TYPE_IF_GET_QUEUE: + handle_message_if_get_queue(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_IF_PUT_QUEUE: + handle_message_if_put_queue(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_IF_ADD_FLOW: + handle_message_if_add_flow(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_IF_DEL_FLOW: + handle_message_if_del_flow(&msg->body.if_msg); + break; + default: + log(log_level::ERROR, "Unknown message type"); + break; } } -void mtl_instance::handle_message_get_lcore(mtl_lcore_message_t* lcore_msg) { +void mtl_instance::handle_message_get_lcore(mtl_lcore_message_t *lcore_msg) { if (!is_registered) { log(log_level::WARNING, "Instance is not registered"); return; @@ -164,7 +161,7 @@ void mtl_instance::handle_message_get_lcore(mtl_lcore_message_t* lcore_msg) { send_response(0); } -void mtl_instance::handle_message_put_lcore(mtl_lcore_message_t* lcore_msg) { +void mtl_instance::handle_message_put_lcore(mtl_lcore_message_t *lcore_msg) { if (!is_registered) { log(log_level::INFO, "Instance is not registered"); return; @@ -180,7 +177,8 @@ void mtl_instance::handle_message_put_lcore(mtl_lcore_message_t* lcore_msg) { send_response(0); } -void mtl_instance::handle_message_register(mtl_register_message_t* register_msg) { +void mtl_instance::handle_message_register( + mtl_register_message_t *register_msg) { pid = ntohl(register_msg->pid); uid = ntohl(register_msg->uid); hostname = std::string(register_msg->hostname, 64); @@ -189,7 +187,8 @@ void mtl_instance::handle_message_register(mtl_register_message_t* register_msg) unsigned int ifindex = ntohl(register_msg->ifindex[i]); auto interface = get_interface(ifindex); if (interface == nullptr) { - log(log_level::ERROR, "Could not get interface " + std::to_string(ifindex)); + log(log_level::ERROR, + "Could not get interface " + std::to_string(ifindex)); send_response(-1); return; } @@ -201,7 +200,8 @@ void mtl_instance::handle_message_register(mtl_register_message_t* register_msg) send_response(0); } -std::shared_ptr mtl_instance::get_interface(const unsigned int ifindex) { +std::shared_ptr +mtl_instance::get_interface(const unsigned int ifindex) { auto it = interfaces.find(ifindex); if (it != interfaces.end()) { log(log_level::DEBUG, "Returning existing interface."); @@ -211,30 +211,34 @@ std::shared_ptr mtl_instance::get_interface(const unsigned int if auto g_it = g_interfaces.find(ifindex); if (g_it != g_interfaces.end()) { if (auto g_interface = g_it->second.lock()) { - log(log_level::INFO, "Acquiring global interface " + std::to_string(ifindex)); + log(log_level::INFO, + "Acquiring global interface " + std::to_string(ifindex)); interfaces[ifindex] = g_interface; return g_interface; } } /* Interface does not exist, create and initialize it */ - log(log_level::INFO, "Initializing a new interface " + std::to_string(ifindex)); + log(log_level::INFO, + "Initializing a new interface " + std::to_string(ifindex)); try { auto new_interface = std::make_shared(ifindex); g_interfaces[ifindex] = new_interface; interfaces[ifindex] = new_interface; return new_interface; - } catch (const std::exception& e) { - log(log_level::ERROR, "Failed to initialize interface: " + std::string(e.what())); + } catch (const std::exception &e) { + log(log_level::ERROR, + "Failed to initialize interface: " + std::string(e.what())); return nullptr; } } -void mtl_instance::handle_message_if_xsk_map_fd(mtl_if_message_t* if_msg) { +void mtl_instance::handle_message_if_xsk_map_fd(mtl_if_message_t *if_msg) { int fd = -1; unsigned int ifindex = ntohl(if_msg->ifindex); auto interface = get_interface(ifindex); - if (interface != nullptr) fd = interface->get_xsks_map_fd(); + if (interface != nullptr) + fd = interface->get_xsks_map_fd(); struct msghdr msg = {0}; struct iovec iov[1]; @@ -249,17 +253,17 @@ void mtl_instance::handle_message_if_xsk_map_fd(mtl_if_message_t* if_msg) { msg.msg_controllen = CMSG_SPACE(sizeof(int)); msg.msg_control = control; - struct cmsghdr* cmsg = CMSG_FIRSTHDR(&msg); + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - *((int*)CMSG_DATA(cmsg)) = fd; + *((int *)CMSG_DATA(cmsg)) = fd; sendmsg(conn_fd, &msg, 0); } void mtl_instance::handle_message_udp_dp_filter( - mtl_udp_dp_filter_message_t* udp_dp_filter_msg, bool add) { + mtl_udp_dp_filter_message_t *udp_dp_filter_msg, bool add) { unsigned int ifindex = ntohl(udp_dp_filter_msg->ifindex); uint16_t port = ntohs(udp_dp_filter_msg->port); auto interface = get_interface(ifindex); @@ -272,7 +276,7 @@ void mtl_instance::handle_message_udp_dp_filter( send_response(ret); } -void mtl_instance::handle_message_if_get_queue(mtl_if_message_t* if_msg) { +void mtl_instance::handle_message_if_get_queue(mtl_if_message_t *if_msg) { unsigned int ifindex = ntohl(if_msg->ifindex); auto interface = get_interface(ifindex); if (interface == nullptr) { @@ -281,11 +285,12 @@ void mtl_instance::handle_message_if_get_queue(mtl_if_message_t* if_msg) { return; } int ret = interface->get_queue(); - if (ret > 0) if_queue_ids[ifindex].insert(ret); + if (ret > 0) + if_queue_ids[ifindex].insert(ret); send_response(ret, MTL_MSG_TYPE_IF_QUEUE_ID); } -void mtl_instance::handle_message_if_put_queue(mtl_if_message_t* if_msg) { +void mtl_instance::handle_message_if_put_queue(mtl_if_message_t *if_msg) { unsigned int ifindex = ntohl(if_msg->ifindex); auto interface = get_interface(ifindex); if (interface == nullptr) { @@ -295,11 +300,12 @@ void mtl_instance::handle_message_if_put_queue(mtl_if_message_t* if_msg) { } uint16_t queue_id = ntohs(if_msg->queue_id); int ret = interface->put_queue(queue_id); - if (ret == 0) if_queue_ids[ifindex].erase(queue_id); + if (ret == 0) + if_queue_ids[ifindex].erase(queue_id); send_response(ret); } -void mtl_instance::handle_message_if_add_flow(mtl_if_message_t* if_msg) { +void mtl_instance::handle_message_if_add_flow(mtl_if_message_t *if_msg) { unsigned int ifindex = ntohl(if_msg->ifindex); auto interface = get_interface(ifindex); if (interface == nullptr) { @@ -307,14 +313,15 @@ void mtl_instance::handle_message_if_add_flow(mtl_if_message_t* if_msg) { send_response(-1); return; } - int ret = interface->add_flow(ntohs(if_msg->queue_id), ntohl(if_msg->flow_type), - ntohl(if_msg->src_ip), ntohl(if_msg->dst_ip), - ntohs(if_msg->src_port), ntohs(if_msg->dst_port)); - if (ret > 0) if_flow_ids[ifindex].insert(ret); + int ret = interface->add_flow( + ntohs(if_msg->queue_id), ntohl(if_msg->flow_type), ntohl(if_msg->src_ip), + ntohl(if_msg->dst_ip), ntohs(if_msg->src_port), ntohs(if_msg->dst_port)); + if (ret > 0) + if_flow_ids[ifindex].insert(ret); send_response(ret, MTL_MSG_TYPE_IF_FLOW_ID); } -void mtl_instance::handle_message_if_del_flow(mtl_if_message_t* if_msg) { +void mtl_instance::handle_message_if_del_flow(mtl_if_message_t *if_msg) { unsigned int ifindex = ntohl(if_msg->ifindex); auto interface = get_interface(ifindex); if (interface == nullptr) { @@ -324,7 +331,8 @@ void mtl_instance::handle_message_if_del_flow(mtl_if_message_t* if_msg) { } unsigned int flow_id = ntohl(if_msg->flow_id); int ret = interface->del_flow(flow_id); - if (ret == 0) if_flow_ids[ifindex].erase(flow_id); + if (ret == 0) + if_flow_ids[ifindex].erase(flow_id); send_response(ret); } diff --git a/manager/mtl_interface.hpp b/manager/mtl_interface.hpp index 5cef1ee99..389a9940a 100644 --- a/manager/mtl_interface.hpp +++ b/manager/mtl_interface.hpp @@ -27,12 +27,12 @@ #define MTL_MAX_QUEUES 64 class mtl_interface { - private: +private: const unsigned int ifindex; uint32_t max_combined; uint32_t combined_count; #ifdef MTL_HAS_XDP_BACKEND - struct xdp_program* xdp_prog; + struct xdp_program *xdp_prog; int xsks_map_fd; int udp4_dp_filter_fd; enum xdp_attach_mode xdp_mode; @@ -40,9 +40,10 @@ class mtl_interface { #endif std::vector queues; - private: - void log(const log_level& level, const std::string& message) const { - logger::log(level, "[Interface " + std::to_string(ifindex) + "] " + message); +private: + void log(const log_level &level, const std::string &message) const { + logger::log(level, + "[Interface " + std::to_string(ifindex) + "] " + message); } int clear_flow_rules(); int parse_combined_info(); @@ -51,7 +52,7 @@ class mtl_interface { void unload_xdp(); #endif - public: +public: mtl_interface(unsigned int ifindex); ~mtl_interface(); @@ -65,8 +66,8 @@ class mtl_interface { int update_udp_dp_filter(uint16_t dst_port, bool add); int get_queue(); int put_queue(uint16_t queue_id); - int add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, uint32_t dst_ip, - uint16_t src_port, uint16_t dst_port); + int add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, + uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); int del_flow(uint32_t flow_id); }; @@ -78,7 +79,8 @@ mtl_interface::mtl_interface(unsigned int ifindex) xsks_map_fd = -1; udp4_dp_filter_fd = -1; xdp_mode = XDP_MODE_UNSPEC; - if (load_xdp() < 0) throw std::runtime_error("Failed to load XDP program."); + if (load_xdp() < 0) + throw std::runtime_error("Failed to load XDP program."); #else throw std::runtime_error("No XDP support for this build"); #endif @@ -124,14 +126,15 @@ int mtl_interface::update_udp_dp_filter(uint16_t dst_port, bool add) { uint8_t value = add ? 1 : 0; int ret = bpf_map_update_elem(udp4_dp_filter_fd, &dst_port, &value, BPF_ANY); if (ret < 0) { - log(log_level::ERROR, - "Failed to update udp4_dp_filter map, dst_port: " + std::to_string(dst_port) + - ", error: " + std::to_string(ret)); + log(log_level::ERROR, "Failed to update udp4_dp_filter map, dst_port: " + + std::to_string(dst_port) + + ", error: " + std::to_string(ret)); return -1; } std::string action = add ? "Added " : "Removed "; - log(log_level::INFO, action + std::to_string(dst_port) + " in udp4_dp_filter"); + log(log_level::INFO, + action + std::to_string(dst_port) + " in udp4_dp_filter"); return 0; #else @@ -194,7 +197,7 @@ int mtl_interface::clear_flow_rules() { } if (cmd.rule_cnt > 0) { - struct ethtool_rxnfc* cmd_w_rules = (struct ethtool_rxnfc*)calloc( + struct ethtool_rxnfc *cmd_w_rules = (struct ethtool_rxnfc *)calloc( 1, sizeof(*cmd_w_rules) + cmd.rule_cnt * sizeof(uint32_t)); if (!cmd_w_rules) { log(log_level::ERROR, "Failed to allocate memory"); @@ -264,8 +267,9 @@ int mtl_interface::parse_combined_info() { return 0; } -int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, - uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) { +int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, + uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, + uint16_t dst_port) { int ret = 0; int free_loc = -1, flow_id = -1; char ifname[IF_NAMESIZE]; @@ -294,8 +298,8 @@ int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ return ret; } - struct ethtool_rxnfc* cmd_w_rules; - cmd_w_rules = (struct ethtool_rxnfc*)calloc( + struct ethtool_rxnfc *cmd_w_rules; + cmd_w_rules = (struct ethtool_rxnfc *)calloc( 1, sizeof(*cmd_w_rules) + cmd.rule_cnt * sizeof(uint32_t)); cmd_w_rules->cmd = ETHTOOL_GRXCLSRLALL; cmd_w_rules->rule_cnt = cmd.rule_cnt; @@ -336,7 +340,7 @@ int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ /* set the flow rule */ memset(&cmd, 0, sizeof(cmd)); cmd.cmd = ETHTOOL_SRXCLSRLINS; - struct ethtool_rx_flow_spec* fs = &cmd.fs; + struct ethtool_rx_flow_spec *fs = &cmd.fs; fs->flow_type = flow_type; if (dst_port) { fs->m_u.udp_ip4_spec.pdst = 0xFFFF; @@ -360,7 +364,8 @@ int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ ifr.ifr_data = (caddr_t)&cmd; ret = ioctl(fd, SIOCETHTOOL, &ifr); if (ret < 0) { - log(log_level::ERROR, "Cannot insert flow rule: " + std::string(strerror(errno))); + log(log_level::ERROR, + "Cannot insert flow rule: " + std::string(strerror(errno))); close(fd); return ret; } @@ -368,8 +373,9 @@ int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ close(fd); - log(log_level::INFO, "Successfully inserted flow rule " + std::to_string(flow_id) + - " with queue " + std::to_string(queue_id)); + log(log_level::INFO, "Successfully inserted flow rule " + + std::to_string(flow_id) + " with queue " + + std::to_string(queue_id)); return flow_id; } @@ -396,14 +402,15 @@ int mtl_interface::del_flow(uint32_t flow_id) { ifr.ifr_data = (caddr_t)&cmd; ret = ioctl(fd, SIOCETHTOOL, &ifr); if (ret < 0) { - log(log_level::ERROR, "Cannot delete flow rule " + std::to_string(flow_id) + " ," + - std::string(strerror(errno))); + log(log_level::ERROR, "Cannot delete flow rule " + std::to_string(flow_id) + + " ," + std::string(strerror(errno))); close(fd); return ret; } close(fd); - log(log_level::INFO, "Successfully deleted flow rule " + std::to_string(flow_id)); + log(log_level::INFO, + "Successfully deleted flow rule " + std::to_string(flow_id)); return 0; } @@ -436,16 +443,16 @@ int mtl_interface::load_xdp() { } /* save the filter map fd */ - udp4_dp_filter_fd = bpf_map__fd( - bpf_object__find_map_by_name(xdp_program__bpf_obj(xdp_prog), "udp4_dp_filter")); + udp4_dp_filter_fd = bpf_map__fd(bpf_object__find_map_by_name( + xdp_program__bpf_obj(xdp_prog), "udp4_dp_filter")); if (udp4_dp_filter_fd < 0) { log(log_level::ERROR, "Failed to get udp4_dp_filter map fd."); unload_xdp(); return -1; } - log(log_level::INFO, - "Loaded xdp prog succ, udp4_dp_filter_fd: " + std::to_string(udp4_dp_filter_fd)); + log(log_level::INFO, "Loaded xdp prog succ, udp4_dp_filter_fd: " + + std::to_string(udp4_dp_filter_fd)); return 0; } diff --git a/manager/mtl_lcore.hpp b/manager/mtl_lcore.hpp index 2490c3270..e28930e90 100644 --- a/manager/mtl_lcore.hpp +++ b/manager/mtl_lcore.hpp @@ -11,21 +11,18 @@ #define MTL_MAX_LCORE 128 class mtl_lcore { - private: +private: std::bitset bs; std::mutex bs_mtx; - mtl_lcore() { - bs.reset(); - } - ~mtl_lcore() { - } + mtl_lcore() { bs.reset(); } + ~mtl_lcore() {} - public: - mtl_lcore(const mtl_lcore&) = delete; - mtl_lcore& operator=(const mtl_lcore&) = delete; +public: + mtl_lcore(const mtl_lcore &) = delete; + mtl_lcore &operator=(const mtl_lcore &) = delete; - static mtl_lcore& get_instance() { + static mtl_lcore &get_instance() { static mtl_lcore instance; return instance; } @@ -35,7 +32,8 @@ class mtl_lcore { }; int mtl_lcore::get_lcore(uint16_t lcore_id) { - if (lcore_id >= MTL_MAX_LCORE) return -1; + if (lcore_id >= MTL_MAX_LCORE) + return -1; std::lock_guard lock(bs_mtx); if (bs.test(lcore_id)) return -1; @@ -45,7 +43,8 @@ int mtl_lcore::get_lcore(uint16_t lcore_id) { } int mtl_lcore::put_lcore(uint16_t lcore_id) { - if (lcore_id >= MTL_MAX_LCORE) return -1; + if (lcore_id >= MTL_MAX_LCORE) + return -1; std::lock_guard lock(bs_mtx); if (!bs.test(lcore_id)) return -1; diff --git a/manager/mtl_manager.cpp b/manager/mtl_manager.cpp index 062949991..885a18cd7 100644 --- a/manager/mtl_manager.cpp +++ b/manager/mtl_manager.cpp @@ -21,13 +21,14 @@ namespace fs = std::filesystem; static const int MAX_CLIENTS = 10; -static const char* mtlm_version(void) { +static const char *mtlm_version(void) { static char version[128]; - if (version[0] != 0) return version; + if (version[0] != 0) + return version; snprintf(version, sizeof(version), "%d.%d.%d.%s %s %s %s", MTLM_VERSION_MAJOR, - MTLM_VERSION_MINOR, MTLM_VERSION_LAST, MTLM_VERSION_EXTRA, __TIMESTAMP__, - __MTLM_GIT__, MTLM_COMPILER); + MTLM_VERSION_MINOR, MTLM_VERSION_LAST, MTLM_VERSION_EXTRA, + __TIMESTAMP__, __MTLM_GIT__, MTLM_COMPILER); return version; } @@ -39,17 +40,19 @@ int main() { std::vector> clients; logger::set_log_level(log_level::INFO); - logger::log(log_level::INFO, "MTL Manager version: " + std::string(mtlm_version())); + logger::log(log_level::INFO, + "MTL Manager version: " + std::string(mtlm_version())); fs::path directory_path(MTL_MANAGER_SOCK_PATH); directory_path.remove_filename(); if (!fs::exists(directory_path)) { try { fs::create_directory(directory_path); - } catch (const std::exception& e) { - logger::log(log_level::ERROR, - "Failed to create dir:" + std::string(MTL_MANAGER_SOCK_PATH) + - ", please run the application with the appropriate privileges"); + } catch (const std::exception &e) { + logger::log( + log_level::ERROR, + "Failed to create dir:" + std::string(MTL_MANAGER_SOCK_PATH) + + ", please run the application with the appropriate privileges"); return -EIO; } } @@ -84,7 +87,7 @@ int main() { unlink(MTL_MANAGER_SOCK_PATH); - ret = bind(sockfd, (struct sockaddr*)&addr, sizeof(addr)); + ret = bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { logger::log(log_level::ERROR, "Failed to bind socket, please run the application with the " @@ -93,7 +96,8 @@ int main() { } /* Allow all users to connect (which might be insecure) */ - fs::permissions(MTL_MANAGER_SOCK_PATH, fs::perms::all, fs::perm_options::replace); + fs::permissions(MTL_MANAGER_SOCK_PATH, fs::perms::all, + fs::perm_options::replace); ret = listen(sockfd, MAX_CLIENTS); if (ret < 0) { @@ -156,16 +160,18 @@ int main() { ev.data.fd = client_sockfd; ret = epoll_ctl(epfd, EPOLL_CTL_ADD, client_sockfd, &ev); if (ret < 0) { - logger::log(log_level::ERROR, "Failed to add client socket fd to epoll."); + logger::log(log_level::ERROR, + "Failed to add client socket fd to epoll."); close(client_sockfd); continue; } auto client = std::make_unique(client_sockfd); clients.push_back(std::move(client)); + logger::log(log_level::INFO, "New client connected. fd: " + + std::to_string(client_sockfd)); logger::log(log_level::INFO, - "New client connected. fd: " + std::to_string(client_sockfd)); - logger::log(log_level::INFO, "Total clients: " + std::to_string(clients.size())); + "Total clients: " + std::to_string(clients.size())); } else if (evfd == signal_fd) { /* handle signal */ struct signalfd_siginfo siginfo; ssize_t len = read(signal_fd, &siginfo, sizeof(siginfo)); @@ -179,22 +185,25 @@ int main() { is_running = false; } } else { /* handle client message */ - auto it = std::find_if(clients.begin(), clients.end(), [&](auto& client) { - return client->get_conn_fd() == evfd; - }); + auto it = + std::find_if(clients.begin(), clients.end(), [&](auto &client) { + return client->get_conn_fd() == evfd; + }); if (it != clients.end()) { - auto& client = *it; + auto &client = *it; char buf[256]; int len = recv(evfd, buf, sizeof(buf), 0); if (len < 0) { logger::log(log_level::ERROR, - "Failed to receive data from client " + std::to_string(evfd)); + "Failed to receive data from client " + + std::to_string(evfd)); } else if (len == 0) { logger::log(log_level::INFO, "Client " + std::to_string(evfd) + " disconnected."); ret = epoll_ctl(epfd, EPOLL_CTL_DEL, evfd, NULL); if (ret < 0) - logger::log(log_level::WARNING, "Failed to remove client from epoll."); + logger::log(log_level::WARNING, + "Failed to remove client from epoll."); clients.erase(it); logger::log(log_level::INFO, "Total clients: " + std::to_string(clients.size())); @@ -208,9 +217,12 @@ int main() { logger::log(log_level::INFO, "MTL Manager exited."); out: - if (signal_fd >= 0) close(signal_fd); - if (epfd >= 0) close(epfd); - if (sockfd >= 0) close(sockfd); + if (signal_fd >= 0) + close(signal_fd); + if (epfd >= 0) + close(epfd); + if (sockfd >= 0) + close(sockfd); return ret; } \ No newline at end of file diff --git a/plugins/log.h b/plugins/log.h index a49d6014d..847119c7a 100644 --- a/plugins/log.h +++ b/plugins/log.h @@ -10,26 +10,26 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif \ No newline at end of file diff --git a/plugins/plugin_platform.h b/plugins/plugin_platform.h index c0bf21a0c..03dbeb881 100644 --- a/plugins/plugin_platform.h +++ b/plugins/plugin_platform.h @@ -17,37 +17,38 @@ #define NS_PER_S (1000000000) #endif -static inline int st_pthread_mutex_init(pthread_mutex_t* mutex, - pthread_mutexattr_t* attr) { +static inline int st_pthread_mutex_init(pthread_mutex_t *mutex, + pthread_mutexattr_t *attr) { return pthread_mutex_init(mutex, attr); } -static inline int st_pthread_mutex_lock(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); } -static inline int st_pthread_mutex_unlock(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_unlock(pthread_mutex_t *mutex) { return pthread_mutex_unlock(mutex); } -static inline int st_pthread_mutex_destroy(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_destroy(pthread_mutex_t *mutex) { return pthread_mutex_destroy(mutex); } -static inline int st_pthread_cond_init(pthread_cond_t* cond, - pthread_condattr_t* cond_attr) { +static inline int st_pthread_cond_init(pthread_cond_t *cond, + pthread_condattr_t *cond_attr) { return pthread_cond_init(cond, cond_attr); } -static inline int st_pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) { +static inline int st_pthread_cond_wait(pthread_cond_t *cond, + pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } -static inline int st_pthread_cond_destroy(pthread_cond_t* cond) { +static inline int st_pthread_cond_destroy(pthread_cond_t *cond) { return pthread_cond_destroy(cond); } -static inline int st_pthread_cond_signal(pthread_cond_t* cond) { +static inline int st_pthread_cond_signal(pthread_cond_t *cond) { return pthread_cond_signal(cond); } @@ -59,8 +60,8 @@ static inline uint64_t st_get_monotonic_time() { return ((uint64_t)ts.tv_sec * NS_PER_S) + ts.tv_nsec; } -static inline void st_usleep( - useconds_t usec) { // windows usleep function precision is only 1~15ms +static inline void +st_usleep(useconds_t usec) { // windows usleep function precision is only 1~15ms #ifdef WINDOWSENV LARGE_INTEGER delay; HANDLE delay_timer_handle = NULL; diff --git a/plugins/sample/convert_plugin_sample.c b/plugins/sample/convert_plugin_sample.c index 6c415c02a..b817ad96f 100644 --- a/plugins/sample/convert_plugin_sample.c +++ b/plugins/sample/convert_plugin_sample.c @@ -15,37 +15,38 @@ #include "../log.h" #include "../plugin_platform.h" -static int convert_frame(struct converter_session* s, - struct st20_convert_frame_meta* frame) { +static int convert_frame(struct converter_session *s, + struct st20_convert_frame_meta *frame) { switch (frame->src->fmt) { + case ST_FRAME_FMT_YUV422RFC4175PG2BE10: + switch (frame->dst->fmt) { + case ST_FRAME_FMT_V210: + st20_rfc4175_422be10_to_v210(frame->src->addr[0], frame->dst->addr[0], + frame->dst->width, frame->dst->height); + break; case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - switch (frame->dst->fmt) { - case ST_FRAME_FMT_V210: - st20_rfc4175_422be10_to_v210(frame->src->addr[0], frame->dst->addr[0], - frame->dst->width, frame->dst->height); - break; - case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - mtl_memcpy(frame->dst->addr[0], frame->src->addr[0], frame->dst->data_size); - break; - case ST_FRAME_FMT_UYVY: - st20_rfc4175_422be10_to_422le8(frame->src->addr[0], frame->dst->addr[0], - frame->dst->width, frame->dst->height); - break; - default: - break; - } + mtl_memcpy(frame->dst->addr[0], frame->src->addr[0], + frame->dst->data_size); + break; + case ST_FRAME_FMT_UYVY: + st20_rfc4175_422be10_to_422le8(frame->src->addr[0], frame->dst->addr[0], + frame->dst->width, frame->dst->height); break; default: break; + } + break; + default: + break; } s->frame_cnt++; return 0; } -static void* convert_thread(void* arg) { - struct converter_session* s = arg; +static void *convert_thread(void *arg) { + struct converter_session *s = arg; st20p_convert_session session_p = s->session_p; - struct st20_convert_frame_meta* frame; + struct st20_convert_frame_meta *frame; int result; info("%s(%d), start\n", __func__, s->idx); @@ -53,7 +54,8 @@ static void* convert_thread(void* arg) { frame = st20_converter_get_frame(session_p); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -65,17 +67,19 @@ static void* convert_thread(void* arg) { return NULL; } -static st20_convert_priv converter_create_session(void* priv, - st20p_convert_session session_p, - struct st20_converter_create_req* req) { - struct convert_ctx* ctx = priv; - struct converter_session* session = NULL; +static st20_convert_priv +converter_create_session(void *priv, st20p_convert_session session_p, + struct st20_converter_create_req *req) { + struct convert_ctx *ctx = priv; + struct converter_session *session = NULL; int ret; for (int i = 0; i < MAX_COLOR_CONVERT_SESSIONS; i++) { - if (ctx->converter_sessions[i]) continue; + if (ctx->converter_sessions[i]) + continue; session = malloc(sizeof(*session)); - if (!session) return NULL; + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->idx = i; st_pthread_mutex_init(&session->wake_mutex, NULL); @@ -84,7 +88,8 @@ static st20_convert_priv converter_create_session(void* priv, session->req = *req; session->session_p = session_p; - ret = pthread_create(&session->convert_thread, NULL, convert_thread, session); + ret = + pthread_create(&session->convert_thread, NULL, convert_thread, session); if (ret < 0) { info("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -103,9 +108,9 @@ static st20_convert_priv converter_create_session(void* priv, return NULL; } -static int converter_free_session(void* priv, st20_convert_priv session) { - struct convert_ctx* ctx = priv; - struct converter_session* converter_session = session; +static int converter_free_session(void *priv, st20_convert_priv session) { + struct convert_ctx *ctx = priv; + struct converter_session *converter_session = session; int idx = converter_session->idx; converter_session->stop = true; @@ -117,14 +122,15 @@ static int converter_free_session(void* priv, st20_convert_priv session) { st_pthread_mutex_destroy(&converter_session->wake_mutex); st_pthread_cond_destroy(&converter_session->wake_cond); - info("%s(%d), total %d convert frames\n", __func__, idx, converter_session->frame_cnt); + info("%s(%d), total %d convert frames\n", __func__, idx, + converter_session->frame_cnt); free(converter_session); ctx->converter_sessions[idx] = NULL; return 0; } -static int converter_frame_available(void* priv) { - struct converter_session* s = priv; +static int converter_frame_available(void *priv) { + struct converter_session *s = priv; dbg("%s(%d)\n", __func__, s->idx); st_pthread_mutex_lock(&s->wake_mutex); @@ -135,10 +141,11 @@ static int converter_frame_available(void* priv) { } st_plugin_priv st_plugin_create(mtl_handle st) { - struct convert_ctx* ctx; + struct convert_ctx *ctx; ctx = malloc(sizeof(*ctx)); - if (!ctx) return NULL; + if (!ctx) + return NULL; memset(ctx, 0, sizeof(*ctx)); struct st20_converter_dev c_dev; @@ -146,8 +153,8 @@ st_plugin_priv st_plugin_create(mtl_handle st) { c_dev.name = "color_convert_sample"; c_dev.priv = ctx; c_dev.target_device = ST_PLUGIN_DEVICE_CPU; - c_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_UYVY | ST_FMT_CAP_V210 | - ST_FMT_CAP_YUV422RFC4175PG2BE10; + c_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_UYVY | + ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; c_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_UYVY | ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; c_dev.create_session = converter_create_session; @@ -164,7 +171,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { return ctx; } int st_plugin_free(st_plugin_priv handle) { - struct convert_ctx* ctx = handle; + struct convert_ctx *ctx = handle; for (int i = 0; i < MAX_COLOR_CONVERT_SESSIONS; i++) { if (ctx->converter_sessions[i]) { @@ -178,7 +185,7 @@ int st_plugin_free(st_plugin_priv handle) { return 0; } -int st_plugin_get_meta(struct st_plugin_meta* meta) { +int st_plugin_get_meta(struct st_plugin_meta *meta) { meta->version = ST_PLUGIN_VERSION_V1; meta->magic = ST_PLUGIN_VERSION_V1_MAGIC; return 0; diff --git a/plugins/sample/convert_plugin_sample.h b/plugins/sample/convert_plugin_sample.h index 9b256b8bc..912e105b6 100644 --- a/plugins/sample/convert_plugin_sample.h +++ b/plugins/sample/convert_plugin_sample.h @@ -25,11 +25,11 @@ struct converter_session { struct convert_ctx { st20_converter_dev_handle converter_dev_handle; - struct converter_session* converter_sessions[MAX_COLOR_CONVERT_SESSIONS]; + struct converter_session *converter_sessions[MAX_COLOR_CONVERT_SESSIONS]; }; /* the APIs for plugin */ -int st_plugin_get_meta(struct st_plugin_meta* meta); +int st_plugin_get_meta(struct st_plugin_meta *meta); st_plugin_priv st_plugin_create(mtl_handle st); int st_plugin_free(st_plugin_priv handle); diff --git a/plugins/sample/st22_plugin_sample.c b/plugins/sample/st22_plugin_sample.c index 2dba2a370..3cd21b72f 100644 --- a/plugins/sample/st22_plugin_sample.c +++ b/plugins/sample/st22_plugin_sample.c @@ -16,8 +16,8 @@ #include "../log.h" #include "../plugin_platform.h" -static int encode_frame(struct st22_encoder_session* s, - struct st22_encode_frame_meta* frame) { +static int encode_frame(struct st22_encoder_session *s, + struct st22_encode_frame_meta *frame) { size_t codestream_size = s->req.max_codestream_size; if (frame->src->interlaced) { @@ -36,10 +36,10 @@ static int encode_frame(struct st22_encoder_session* s, return 0; } -static void* encode_thread(void* arg) { - struct st22_encoder_session* s = arg; +static void *encode_thread(void *arg) { + struct st22_encoder_session *s = arg; st22p_encode_session session_p = s->session_p; - struct st22_encode_frame_meta* frame; + struct st22_encode_frame_meta *frame; int result; info("%s(%d), start\n", __func__, s->idx); @@ -57,16 +57,19 @@ static void* encode_thread(void* arg) { return NULL; } -static st22_encode_priv encoder_create_session(void* priv, st22p_encode_session session_p, - struct st22_encoder_create_req* req) { - struct st22_sample_ctx* ctx = priv; - struct st22_encoder_session* session = NULL; +static st22_encode_priv +encoder_create_session(void *priv, st22p_encode_session session_p, + struct st22_encoder_create_req *req) { + struct st22_sample_ctx *ctx = priv; + struct st22_encoder_session *session = NULL; int ret; for (int i = 0; i < MAX_SAMPLE_ENCODER_SESSIONS; i++) { - if (ctx->encoder_sessions[i]) continue; + if (ctx->encoder_sessions[i]) + continue; session = malloc(sizeof(*session)); - if (!session) return NULL; + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->idx = i; @@ -98,9 +101,9 @@ static st22_encode_priv encoder_create_session(void* priv, st22p_encode_session return NULL; } -static int encoder_free_session(void* priv, st22_encode_priv session) { - struct st22_sample_ctx* ctx = priv; - struct st22_encoder_session* encoder_session = session; +static int encoder_free_session(void *priv, st22_encode_priv session) { + struct st22_sample_ctx *ctx = priv; + struct st22_encoder_session *encoder_session = session; int idx = encoder_session->idx; if (encoder_session->encode_thread) { @@ -109,20 +112,21 @@ static int encoder_free_session(void* priv, st22_encode_priv session) { pthread_join(encoder_session->encode_thread, NULL); } - info("%s(%d), total %d encode frames\n", __func__, idx, encoder_session->frame_cnt); + info("%s(%d), total %d encode frames\n", __func__, idx, + encoder_session->frame_cnt); free(encoder_session); ctx->encoder_sessions[idx] = NULL; return 0; } -static int encoder_frame_available(void* priv) { +static int encoder_frame_available(void *priv) { /* nothing to do, sample enable ST22_ENCODER_RESP_FLAG_BLOCK_GET */ MTL_MAY_UNUSED(priv); return 0; } -static int decode_frame(struct st22_decoder_session* s, - struct st22_decode_frame_meta* frame) { +static int decode_frame(struct st22_decoder_session *s, + struct st22_decode_frame_meta *frame) { size_t codestream_size = frame->src->data_size; if (frame->src->interlaced) { @@ -139,10 +143,10 @@ static int decode_frame(struct st22_decoder_session* s, return 0; } -static void* decode_thread(void* arg) { - struct st22_decoder_session* s = arg; +static void *decode_thread(void *arg) { + struct st22_decoder_session *s = arg; st22p_decode_session session_p = s->session_p; - struct st22_decode_frame_meta* frame; + struct st22_decode_frame_meta *frame; int result; info("%s(%d), start\n", __func__, s->idx); @@ -160,16 +164,19 @@ static void* decode_thread(void* arg) { return NULL; } -static st22_decode_priv decoder_create_session(void* priv, st22p_decode_session session_p, - struct st22_decoder_create_req* req) { - struct st22_sample_ctx* ctx = priv; - struct st22_decoder_session* session = NULL; +static st22_decode_priv +decoder_create_session(void *priv, st22p_decode_session session_p, + struct st22_decoder_create_req *req) { + struct st22_sample_ctx *ctx = priv; + struct st22_decoder_session *session = NULL; int ret; for (int i = 0; i < MAX_SAMPLE_DECODER_SESSIONS; i++) { - if (ctx->decoder_sessions[i]) continue; + if (ctx->decoder_sessions[i]) + continue; session = malloc(sizeof(*session)); - if (!session) return NULL; + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->idx = i; @@ -187,8 +194,9 @@ static st22_decode_priv decoder_create_session(void* priv, st22p_decode_session } ctx->decoder_sessions[i] = session; - info("%s(%d), input fmt: %s, output fmt: %s, scan: %s, socket id: %d\n", __func__, i, - st_frame_fmt_name(req->input_fmt), st_frame_fmt_name(req->output_fmt), + info("%s(%d), input fmt: %s, output fmt: %s, scan: %s, socket id: %d\n", + __func__, i, st_frame_fmt_name(req->input_fmt), + st_frame_fmt_name(req->output_fmt), req->interlaced ? "interlaced" : "progressive", req->socket_id); return session; } @@ -197,9 +205,9 @@ static st22_decode_priv decoder_create_session(void* priv, st22p_decode_session return NULL; } -static int decoder_free_session(void* priv, st22_decode_priv session) { - struct st22_sample_ctx* ctx = priv; - struct st22_decoder_session* decoder_session = session; +static int decoder_free_session(void *priv, st22_decode_priv session) { + struct st22_sample_ctx *ctx = priv; + struct st22_decoder_session *decoder_session = session; int idx = decoder_session->idx; if (decoder_session->decode_thread) { @@ -209,23 +217,25 @@ static int decoder_free_session(void* priv, st22_decode_priv session) { pthread_join(decoder_session->decode_thread, NULL); } - info("%s(%d), total %d decode frames\n", __func__, idx, decoder_session->frame_cnt); + info("%s(%d), total %d decode frames\n", __func__, idx, + decoder_session->frame_cnt); free(decoder_session); ctx->decoder_sessions[idx] = NULL; return 0; } -static int decoder_frame_available(void* priv) { +static int decoder_frame_available(void *priv) { /* nothing to do, sample enable ST22_DECODER_RESP_FLAG_BLOCK_GET */ MTL_MAY_UNUSED(priv); return 0; } st_plugin_priv st_plugin_create(mtl_handle st) { - struct st22_sample_ctx* ctx; + struct st22_sample_ctx *ctx; ctx = malloc(sizeof(*ctx)); - if (!ctx) return NULL; + if (!ctx) + return NULL; memset(ctx, 0, sizeof(*ctx)); struct st22_decoder_dev d_dev; @@ -233,10 +243,12 @@ st_plugin_priv st_plugin_create(mtl_handle st) { d_dev.name = "st22_decoder_sample"; d_dev.priv = ctx; d_dev.target_device = ST_PLUGIN_DEVICE_CPU; - d_dev.input_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + d_dev.input_fmt_caps = + ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; d_dev.output_fmt_caps = ST_FMT_CAP_ARGB | ST_FMT_CAP_BGRA | ST_FMT_CAP_RGB8; - d_dev.output_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8 | - ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; + d_dev.output_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | + ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_V210 | + ST_FMT_CAP_YUV422RFC4175PG2BE10; d_dev.output_fmt_caps |= ST_FMT_CAP_YUV420PLANAR8; d_dev.create_session = decoder_create_session; d_dev.free_session = decoder_free_session; @@ -255,10 +267,12 @@ st_plugin_priv st_plugin_create(mtl_handle st) { e_dev.target_device = ST_PLUGIN_DEVICE_CPU; e_dev.input_fmt_caps = ST_FMT_CAP_ARGB | ST_FMT_CAP_BGRA | ST_FMT_CAP_RGB8; - e_dev.input_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8 | - ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; + e_dev.input_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | + ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_V210 | + ST_FMT_CAP_YUV422RFC4175PG2BE10; e_dev.input_fmt_caps |= ST_FMT_CAP_YUV420PLANAR8; - e_dev.output_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + e_dev.output_fmt_caps = + ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; e_dev.create_session = encoder_create_session; e_dev.free_session = encoder_free_session; e_dev.notify_frame_available = encoder_frame_available; @@ -275,7 +289,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { } int st_plugin_free(st_plugin_priv handle) { - struct st22_sample_ctx* ctx = handle; + struct st22_sample_ctx *ctx = handle; for (int i = 0; i < MAX_SAMPLE_DECODER_SESSIONS; i++) { if (ctx->decoder_sessions[i]) { @@ -301,7 +315,7 @@ int st_plugin_free(st_plugin_priv handle) { return 0; } -int st_plugin_get_meta(struct st_plugin_meta* meta) { +int st_plugin_get_meta(struct st_plugin_meta *meta) { meta->version = ST_PLUGIN_VERSION_V1; meta->magic = ST_PLUGIN_VERSION_V1_MAGIC; return 0; diff --git a/plugins/sample/st22_plugin_sample.h b/plugins/sample/st22_plugin_sample.h index 6227c9032..c81f294da 100644 --- a/plugins/sample/st22_plugin_sample.h +++ b/plugins/sample/st22_plugin_sample.h @@ -35,12 +35,12 @@ struct st22_decoder_session { struct st22_sample_ctx { st22_encoder_dev_handle encoder_dev_handle; st22_decoder_dev_handle decoder_dev_handle; - struct st22_encoder_session* encoder_sessions[MAX_SAMPLE_ENCODER_SESSIONS]; - struct st22_decoder_session* decoder_sessions[MAX_SAMPLE_DECODER_SESSIONS]; + struct st22_encoder_session *encoder_sessions[MAX_SAMPLE_ENCODER_SESSIONS]; + struct st22_decoder_session *decoder_sessions[MAX_SAMPLE_DECODER_SESSIONS]; }; /* the APIs for plugin */ -int st_plugin_get_meta(struct st_plugin_meta* meta); +int st_plugin_get_meta(struct st_plugin_meta *meta); st_plugin_priv st_plugin_create(mtl_handle st); int st_plugin_free(st_plugin_priv handle); diff --git a/plugins/st22_avcodec/st22_avcodec_plugin.c b/plugins/st22_avcodec/st22_avcodec_plugin.c index 147893e3d..3fa281157 100644 --- a/plugins/st22_avcodec/st22_avcodec_plugin.c +++ b/plugins/st22_avcodec/st22_avcodec_plugin.c @@ -15,17 +15,17 @@ #include "../log.h" #include "../plugin_platform.h" -static int avcodec_encode_frame(struct st22_avcodec_encoder_session* s, - struct st22_encode_frame_meta* frame) { +static int avcodec_encode_frame(struct st22_avcodec_encoder_session *s, + struct st22_encode_frame_meta *frame) { int idx = s->idx; - AVFrame* f = s->codec_frame; - AVPacket* p = s->codec_pkt; - AVCodecContext* ctx = s->codec_ctx; + AVFrame *f = s->codec_frame; + AVPacket *p = s->codec_pkt; + AVCodecContext *ctx = s->codec_ctx; size_t data_size = 0; int ret; bool measure_time = false; uint64_t start_time = 0, end_time = 0; - struct st_frame* src = frame->src; + struct st_frame *src = frame->src; int f_idx = s->frame_cnt; if (measure_time) { @@ -46,23 +46,24 @@ static int avcodec_encode_frame(struct st22_avcodec_encoder_session* s, ret = avcodec_send_frame(ctx, f); if (ret < 0) { - err("%s(%d), send frame(%d) fail %s\n", __func__, idx, f_idx, av_err2str(ret)); + err("%s(%d), send frame(%d) fail %s\n", __func__, idx, f_idx, + av_err2str(ret)); return ret; } s->frame_cnt++; ret = avcodec_receive_packet(ctx, p); if (ret < 0) { - dbg("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, av_err2str(ret), - f_idx); + dbg("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, + av_err2str(ret), f_idx); /* log error if not EAGAIN or EOF*/ if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { - err("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, av_err2str(ret), - f_idx); + err("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, + av_err2str(ret), f_idx); } } else { - dbg("%s, receive packet %" PRId64 " size %d on frame %d\n", __func__, p->pts, p->size, - f_idx); + dbg("%s, receive packet %" PRId64 " size %d on frame %d\n", __func__, + p->pts, p->size, f_idx); /* copy codestream */ mtl_memcpy(frame->dst->addr[0] + data_size, p->data, p->size); data_size = p->size; @@ -76,15 +77,15 @@ static int avcodec_encode_frame(struct st22_avcodec_encoder_session* s, } frame->dst->data_size = data_size; - dbg("%s(%d), codestream size %" PRIu64 " on frame %d\n", __func__, idx, data_size, - f_idx); + dbg("%s(%d), codestream size %" PRIu64 " on frame %d\n", __func__, idx, + data_size, f_idx); return data_size > 0 ? 0 : -EIO; } -static void* avcodec_encode_thread(void* arg) { - struct st22_avcodec_encoder_session* s = arg; +static void *avcodec_encode_thread(void *arg) { + struct st22_avcodec_encoder_session *s = arg; st22p_encode_session session_p = s->session_p; - struct st22_encode_frame_meta* frame; + struct st22_encode_frame_meta *frame; int result; info("%s(%d), start\n", __func__, s->idx); @@ -102,7 +103,8 @@ static void* avcodec_encode_thread(void* arg) { return NULL; } -static int avcodec_encoder_uinit_session(struct st22_avcodec_encoder_session* session) { +static int +avcodec_encoder_uinit_session(struct st22_avcodec_encoder_session *session) { int idx = session->idx; if (session->encode_thread) { @@ -131,8 +133,9 @@ static int avcodec_encoder_uinit_session(struct st22_avcodec_encoder_session* se return 0; } -static int avcodec_encoder_init_session(struct st22_avcodec_encoder_session* session, - struct st22_encoder_create_req* req) { +static int +avcodec_encoder_init_session(struct st22_avcodec_encoder_session *session, + struct st22_encoder_create_req *req) { int idx = session->idx; int ret; @@ -145,16 +148,17 @@ static int avcodec_encoder_init_session(struct st22_avcodec_encoder_session* ses } else if (req->output_fmt == ST_FRAME_FMT_H264_CODESTREAM) { codec_id = AV_CODEC_ID_H264; } else { - err("%s(%d), invalid codec stream fmt %d\n", __func__, idx, req->output_fmt); + err("%s(%d), invalid codec stream fmt %d\n", __func__, idx, + req->output_fmt); return -EIO; } - const AVCodec* codec = avcodec_find_encoder(codec_id); + const AVCodec *codec = avcodec_find_encoder(codec_id); if (!codec) { err("%s(%d), codec %d create fail\n", __func__, idx, codec_id); avcodec_encoder_uinit_session(session); return -EIO; } - AVCodecContext* c = avcodec_alloc_context3(codec); + AVCodecContext *c = avcodec_alloc_context3(codec); if (!c) { err("%s(%d), codec ctx create fail\n", __func__, idx); avcodec_encoder_uinit_session(session); @@ -195,7 +199,7 @@ static int avcodec_encoder_init_session(struct st22_avcodec_encoder_session* ses return ret; } - AVFrame* f = av_frame_alloc(); + AVFrame *f = av_frame_alloc(); if (!f) { err("%s(%d), frame alloc fail\n", __func__, idx); avcodec_encoder_uinit_session(session); @@ -212,7 +216,7 @@ static int avcodec_encoder_init_session(struct st22_avcodec_encoder_session* ses return -EIO; } - AVPacket* p = av_packet_alloc(); + AVPacket *p = av_packet_alloc(); if (!p) { err("%s(%d), pkt alloc fail\n", __func__, idx); avcodec_encoder_uinit_session(session); @@ -220,7 +224,8 @@ static int avcodec_encoder_init_session(struct st22_avcodec_encoder_session* ses } session->codec_pkt = p; - ret = pthread_create(&session->encode_thread, NULL, avcodec_encode_thread, session); + ret = pthread_create(&session->encode_thread, NULL, avcodec_encode_thread, + session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, idx, ret); avcodec_encoder_uinit_session(session); @@ -230,16 +235,19 @@ static int avcodec_encoder_init_session(struct st22_avcodec_encoder_session* ses return 0; } -static st22_encode_priv avcodec_encoder_create_session( - void* priv, st22p_encode_session session_p, struct st22_encoder_create_req* req) { - struct st22_avcodec_plugin_ctx* ctx = priv; - struct st22_avcodec_encoder_session* session = NULL; +static st22_encode_priv +avcodec_encoder_create_session(void *priv, st22p_encode_session session_p, + struct st22_encoder_create_req *req) { + struct st22_avcodec_plugin_ctx *ctx = priv; + struct st22_avcodec_encoder_session *session = NULL; int ret; for (int i = 0; i < MAX_ST22_AVCODEC_ENCODER_SESSIONS; i++) { - if (ctx->encoder_sessions[i]) continue; + if (ctx->encoder_sessions[i]) + continue; session = malloc(sizeof(*session)); - if (!session) return NULL; + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->idx = i; session->session_p = session_p; @@ -263,12 +271,13 @@ static st22_encode_priv avcodec_encoder_create_session( return NULL; } -static int avcodec_encoder_free_session(void* priv, st22_encode_priv session) { - struct st22_avcodec_plugin_ctx* ctx = priv; - struct st22_avcodec_encoder_session* encoder_session = session; +static int avcodec_encoder_free_session(void *priv, st22_encode_priv session) { + struct st22_avcodec_plugin_ctx *ctx = priv; + struct st22_avcodec_encoder_session *encoder_session = session; int idx = encoder_session->idx; - info("%s(%d), total %d encode frames\n", __func__, idx, encoder_session->frame_cnt); + info("%s(%d), total %d encode frames\n", __func__, idx, + encoder_session->frame_cnt); avcodec_encoder_uinit_session(encoder_session); free(encoder_session); @@ -276,16 +285,16 @@ static int avcodec_encoder_free_session(void* priv, st22_encode_priv session) { return 0; } -static int avcodec_decode_frame(struct st22_avcodec_decoder_session* s, - struct st22_decode_frame_meta* frame) { +static int avcodec_decode_frame(struct st22_avcodec_decoder_session *s, + struct st22_decode_frame_meta *frame) { int idx = s->idx; int f_idx = s->frame_cnt; - AVCodecContext* ctx = s->codec_ctx; - AVFrame* f = s->codec_frame; - AVPacket* p = s->codec_pkt; + AVCodecContext *ctx = s->codec_ctx; + AVFrame *f = s->codec_frame; + AVPacket *p = s->codec_pkt; int ret; size_t src_size = frame->src->data_size; - struct st_frame* dst = frame->dst; + struct st_frame *dst = frame->dst; size_t frame_size = 0; av_packet_unref(p); @@ -293,22 +302,23 @@ static int avcodec_decode_frame(struct st22_avcodec_decoder_session* s, p->size = src_size; ret = avcodec_send_packet(ctx, p); if (ret < 0) { - err("%s(%d), send pkt(%d) fail %s\n", __func__, idx, f_idx, av_err2str(ret)); + err("%s(%d), send pkt(%d) fail %s\n", __func__, idx, f_idx, + av_err2str(ret)); return ret; } ret = avcodec_receive_frame(ctx, f); if (ret < 0) { - dbg("%s(%d), receive data fail %s on frame %d\n", __func__, idx, av_err2str(ret), - f_idx); + dbg("%s(%d), receive data fail %s on frame %d\n", __func__, idx, + av_err2str(ret), f_idx); /* log error if not EAGAIN or EOF*/ if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { - err("%s(%d), receive data fail %s on frame %d\n", __func__, idx, av_err2str(ret), - f_idx); + err("%s(%d), receive data fail %s on frame %d\n", __func__, idx, + av_err2str(ret), f_idx); } } else { - dbg("%s, format(%dx%d@%d) on frame %d\n", __func__, f->width, f->height, f->format, - f_idx); + dbg("%s, format(%dx%d@%d) on frame %d\n", __func__, f->width, f->height, + f->format, f_idx); frame_size = dst->data_size; /* copy data to frame */ mtl_memcpy(dst->addr[0], f->data[0], st_frame_plane_size(dst, 0)); @@ -323,10 +333,10 @@ static int avcodec_decode_frame(struct st22_avcodec_decoder_session* s, return frame_size > 0 ? 0 : -EIO; } -static void* avcodec_decode_thread(void* arg) { - struct st22_avcodec_decoder_session* s = arg; +static void *avcodec_decode_thread(void *arg) { + struct st22_avcodec_decoder_session *s = arg; st22p_decode_session session_p = s->session_p; - struct st22_decode_frame_meta* frame; + struct st22_decode_frame_meta *frame; int result; info("%s(%d), start\n", __func__, s->idx); @@ -344,7 +354,8 @@ static void* avcodec_decode_thread(void* arg) { return NULL; } -static int avcodec_decoder_uinit_session(struct st22_avcodec_decoder_session* session) { +static int +avcodec_decoder_uinit_session(struct st22_avcodec_decoder_session *session) { int idx = session->idx; if (session->decode_thread) { @@ -378,8 +389,9 @@ static int avcodec_decoder_uinit_session(struct st22_avcodec_decoder_session* se return 0; } -static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session* session, - struct st22_decoder_create_req* req) { +static int +avcodec_decoder_init_session(struct st22_avcodec_decoder_session *session, + struct st22_decoder_create_req *req) { int idx = session->idx; int ret; @@ -394,14 +406,14 @@ static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session* ses err("%s(%d), invalid codec stream fmt %d\n", __func__, idx, req->input_fmt); return -EIO; } - const AVCodec* codec = avcodec_find_decoder(codec_id); + const AVCodec *codec = avcodec_find_decoder(codec_id); if (!codec) { err("%s(%d), codec create fail\n", __func__, idx); avcodec_decoder_uinit_session(session); return -EIO; } - AVCodecParserContext* parser = av_parser_init(codec->id); + AVCodecParserContext *parser = av_parser_init(codec->id); if (!parser) { err("%s(%d), parser create fail\n", __func__, idx); avcodec_decoder_uinit_session(session); @@ -409,7 +421,7 @@ static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session* ses } session->codec_parser = parser; - AVCodecContext* c = avcodec_alloc_context3(codec); + AVCodecContext *c = avcodec_alloc_context3(codec); if (!c) { err("%s(%d), codec ctx create fail\n", __func__, idx); avcodec_decoder_uinit_session(session); @@ -439,7 +451,7 @@ static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session* ses return ret; } - AVFrame* f = av_frame_alloc(); + AVFrame *f = av_frame_alloc(); if (!f) { err("%s(%d), frame alloc fail\n", __func__, idx); avcodec_decoder_uinit_session(session); @@ -447,7 +459,7 @@ static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session* ses } session->codec_frame = f; - AVPacket* p = av_packet_alloc(); + AVPacket *p = av_packet_alloc(); if (!p) { err("%s(%d), pkt alloc fail\n", __func__, idx); avcodec_decoder_uinit_session(session); @@ -455,7 +467,8 @@ static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session* ses } session->codec_pkt = p; - ret = pthread_create(&session->decode_thread, NULL, avcodec_decode_thread, session); + ret = pthread_create(&session->decode_thread, NULL, avcodec_decode_thread, + session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, idx, ret); avcodec_decoder_uinit_session(session); @@ -465,16 +478,19 @@ static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session* ses return 0; } -static st22_decode_priv avcodec_decoder_create_session( - void* priv, st22p_decode_session session_p, struct st22_decoder_create_req* req) { - struct st22_avcodec_plugin_ctx* ctx = priv; - struct st22_avcodec_decoder_session* session = NULL; +static st22_decode_priv +avcodec_decoder_create_session(void *priv, st22p_decode_session session_p, + struct st22_decoder_create_req *req) { + struct st22_avcodec_plugin_ctx *ctx = priv; + struct st22_avcodec_decoder_session *session = NULL; int ret; for (int i = 0; i < MAX_ST22_AVCODEC_DECODER_SESSIONS; i++) { - if (ctx->decoder_sessions[i]) continue; + if (ctx->decoder_sessions[i]) + continue; session = malloc(sizeof(*session)); - if (!session) return NULL; + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->idx = i; session->session_p = session_p; @@ -496,12 +512,13 @@ static st22_decode_priv avcodec_decoder_create_session( return NULL; } -static int avcodec_decoder_free_session(void* priv, st22_decode_priv session) { - struct st22_avcodec_plugin_ctx* ctx = priv; - struct st22_avcodec_decoder_session* decoder_session = session; +static int avcodec_decoder_free_session(void *priv, st22_decode_priv session) { + struct st22_avcodec_plugin_ctx *ctx = priv; + struct st22_avcodec_decoder_session *decoder_session = session; int idx = decoder_session->idx; - info("%s(%d), total %d decode frames\n", __func__, idx, decoder_session->frame_cnt); + info("%s(%d), total %d decode frames\n", __func__, idx, + decoder_session->frame_cnt); avcodec_decoder_uinit_session(decoder_session); free(decoder_session); @@ -510,10 +527,11 @@ static int avcodec_decoder_free_session(void* priv, st22_decode_priv session) { } st_plugin_priv st_plugin_create(mtl_handle st) { - struct st22_avcodec_plugin_ctx* ctx; + struct st22_avcodec_plugin_ctx *ctx; ctx = malloc(sizeof(*ctx)); - if (!ctx) return NULL; + if (!ctx) + return NULL; memset(ctx, 0, sizeof(*ctx)); struct st22_decoder_dev d_dev; @@ -521,7 +539,8 @@ st_plugin_priv st_plugin_create(mtl_handle st) { d_dev.name = "st22_plugin_avcodec_decoder"; d_dev.priv = ctx; d_dev.target_device = ST_PLUGIN_DEVICE_CPU; - d_dev.input_fmt_caps = ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; + d_dev.input_fmt_caps = + ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; d_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_YUV420PLANAR8; d_dev.create_session = avcodec_decoder_create_session; d_dev.free_session = avcodec_decoder_free_session; @@ -538,7 +557,8 @@ st_plugin_priv st_plugin_create(mtl_handle st) { e_dev.priv = ctx; e_dev.target_device = ST_PLUGIN_DEVICE_CPU; e_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_YUV420PLANAR8; - e_dev.output_fmt_caps = ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; + e_dev.output_fmt_caps = + ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; e_dev.create_session = avcodec_encoder_create_session; e_dev.free_session = avcodec_encoder_free_session; ctx->encoder_dev_handle = st22_encoder_register(st, &e_dev); @@ -554,7 +574,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { } int st_plugin_free(st_plugin_priv handle) { - struct st22_avcodec_plugin_ctx* ctx = handle; + struct st22_avcodec_plugin_ctx *ctx = handle; for (int i = 0; i < MAX_ST22_AVCODEC_DECODER_SESSIONS; i++) { if (ctx->decoder_sessions[i]) { @@ -580,7 +600,7 @@ int st_plugin_free(st_plugin_priv handle) { return 0; } -int st_plugin_get_meta(struct st_plugin_meta* meta) { +int st_plugin_get_meta(struct st_plugin_meta *meta) { meta->version = ST_PLUGIN_VERSION_V1; meta->magic = ST_PLUGIN_VERSION_V1_MAGIC; return 0; diff --git a/plugins/st22_avcodec/st22_avcodec_plugin.h b/plugins/st22_avcodec/st22_avcodec_plugin.h index 674e8ceeb..b98354829 100644 --- a/plugins/st22_avcodec/st22_avcodec_plugin.h +++ b/plugins/st22_avcodec/st22_avcodec_plugin.h @@ -24,9 +24,9 @@ struct st22_avcodec_encoder_session { int frame_cnt; /* AVCodec info */ - AVCodecContext* codec_ctx; - AVFrame* codec_frame; - AVPacket* codec_pkt; + AVCodecContext *codec_ctx; + AVFrame *codec_frame; + AVPacket *codec_pkt; }; struct st22_avcodec_decoder_session { @@ -41,23 +41,23 @@ struct st22_avcodec_decoder_session { int frame_cnt; /* AVCodec info */ - AVCodecContext* codec_ctx; - AVFrame* codec_frame; - AVPacket* codec_pkt; - AVCodecParserContext* codec_parser; + AVCodecContext *codec_ctx; + AVFrame *codec_frame; + AVPacket *codec_pkt; + AVCodecParserContext *codec_parser; }; struct st22_avcodec_plugin_ctx { st22_encoder_dev_handle encoder_dev_handle; st22_decoder_dev_handle decoder_dev_handle; - struct st22_avcodec_encoder_session* - encoder_sessions[MAX_ST22_AVCODEC_ENCODER_SESSIONS]; - struct st22_avcodec_decoder_session* - decoder_sessions[MAX_ST22_AVCODEC_DECODER_SESSIONS]; + struct st22_avcodec_encoder_session + *encoder_sessions[MAX_ST22_AVCODEC_ENCODER_SESSIONS]; + struct st22_avcodec_decoder_session + *decoder_sessions[MAX_ST22_AVCODEC_DECODER_SESSIONS]; }; /* the APIs for plugin */ -int st_plugin_get_meta(struct st_plugin_meta* meta); +int st_plugin_get_meta(struct st_plugin_meta *meta); st_plugin_priv st_plugin_create(mtl_handle st); int st_plugin_free(st_plugin_priv handle); diff --git a/rdma/mt_rdma.c b/rdma/mt_rdma.c index eeb6e5de1..f7ed21865 100644 --- a/rdma/mt_rdma.c +++ b/rdma/mt_rdma.c @@ -11,12 +11,10 @@ static enum mtl_rdma_log_level rdma_log_level = MTL_RDMA_LOG_LEVEL_INFO; void mt_rdma_set_log_level(enum mtl_rdma_log_level level) { rdma_log_level = level; } -enum mtl_rdma_log_level mt_rdma_get_log_level(void) { - return rdma_log_level; -} +enum mtl_rdma_log_level mt_rdma_get_log_level(void) { return rdma_log_level; } -mtl_rdma_handle mtl_rdma_init(struct mtl_rdma_init_params* p) { - struct mt_rdma_impl* impl = NULL; +mtl_rdma_handle mtl_rdma_init(struct mtl_rdma_init_params *p) { + struct mt_rdma_impl *impl = NULL; impl = calloc(1, sizeof(*impl)); if (!impl) { err("%s, failed to allocate memory for mtl_rdma_impl\n", __func__); @@ -29,7 +27,7 @@ mtl_rdma_handle mtl_rdma_init(struct mtl_rdma_init_params* p) { } int mtl_rdma_uinit(mtl_rdma_handle mrh) { - struct mt_rdma_impl* impl = (struct mt_rdma_impl*)mrh; + struct mt_rdma_impl *impl = (struct mt_rdma_impl *)mrh; free(impl); return 0; } \ No newline at end of file diff --git a/rdma/mt_rdma.h b/rdma/mt_rdma.h index a0be26517..b09f63cf2 100644 --- a/rdma/mt_rdma.h +++ b/rdma/mt_rdma.h @@ -22,12 +22,12 @@ #define MT_RDMA_MSG_MAX_SIZE (1024) -#define MT_SAFE_FREE(obj, free_fn) \ - do { \ - if (obj) { \ - free_fn(obj); \ - obj = NULL; \ - } \ +#define MT_SAFE_FREE(obj, free_fn) \ + do { \ + if (obj) { \ + free_fn(obj); \ + obj = NULL; \ + } \ } while (0) void mt_rdma_set_log_level(enum mtl_rdma_log_level level); @@ -35,34 +35,39 @@ enum mtl_rdma_log_level mt_rdma_get_log_level(void); /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_DEBUG) printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_DEBUG) \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_INFO) printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_INFO) \ + printf(__VA_ARGS__); \ } while (0) -#define notce(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_NOTICE) printf(__VA_ARGS__); \ +#define notce(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_NOTICE) \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_WARNING) printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_WARNING) \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_ERR) printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_ERR) \ + printf(__VA_ARGS__); \ } while (0) -#define critical(...) \ - do { \ - printf(__VA_ARGS__); \ +#define critical(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) /* Remote buffer info for RDMA write */ @@ -111,8 +116,8 @@ struct mt_rdma_tx_buffer { uint16_t idx; enum mt_rdma_buffer_status status; struct mtl_rdma_buffer buffer; - struct ibv_mr* mr; - void* meta; + struct ibv_mr *mr; + void *meta; struct mt_rdma_remote_buffer remote_buffer; uint32_t ref_count; pthread_mutex_t lock; @@ -122,20 +127,20 @@ struct mt_rdma_tx_ctx { char ops_name[32]; struct mtl_rdma_tx_ops ops; /* RDMA context */ - struct rdma_event_channel* ec; - struct ibv_cq* cq; - struct ibv_comp_channel* cc; - struct rdma_cm_id* id; - struct ibv_pd* pd; - struct ibv_qp* qp; - struct ibv_mr* meta_mr; - struct ibv_mr* recv_msgs_mr; - struct rdma_cm_id* listen_id; + struct rdma_event_channel *ec; + struct ibv_cq *cq; + struct ibv_comp_channel *cc; + struct rdma_cm_id *id; + struct ibv_pd *pd; + struct ibv_qp *qp; + struct ibv_mr *meta_mr; + struct ibv_mr *recv_msgs_mr; + struct rdma_cm_id *listen_id; uint32_t buffer_seq_num; - void* meta_region; /* 1024 bytes * buf_cnt */ - struct mt_rdma_message* recv_msgs; - struct mt_rdma_tx_buffer* tx_buffers; + void *meta_region; /* 1024 bytes * buf_cnt */ + struct mt_rdma_message *recv_msgs; + struct mt_rdma_tx_buffer *tx_buffers; uint16_t buffer_cnt; pthread_t connect_thread; pthread_t cq_poll_thread; @@ -156,7 +161,7 @@ struct mt_rdma_rx_buffer { uint16_t idx; enum mt_rdma_buffer_status status; struct mtl_rdma_buffer buffer; - struct ibv_mr* mr; + struct ibv_mr *mr; pthread_mutex_t lock; uint8_t recv_mask; }; @@ -165,18 +170,18 @@ struct mt_rdma_rx_ctx { char ops_name[32]; struct mtl_rdma_rx_ops ops; /* RDMA context */ - struct rdma_event_channel* ec; - struct ibv_cq* cq; - struct ibv_comp_channel* cc; - struct rdma_cm_id* id; - struct ibv_pd* pd; - struct ibv_qp* qp; - struct ibv_mr* meta_mr; - struct ibv_mr* recv_msgs_mr; - - void* meta_region; /* 1024 bytes * buf_cnt */ - struct mt_rdma_message* recv_msgs; - struct mt_rdma_rx_buffer* rx_buffers; + struct rdma_event_channel *ec; + struct ibv_cq *cq; + struct ibv_comp_channel *cc; + struct rdma_cm_id *id; + struct ibv_pd *pd; + struct ibv_qp *qp; + struct ibv_mr *meta_mr; + struct ibv_mr *recv_msgs_mr; + + void *meta_region; /* 1024 bytes * buf_cnt */ + struct mt_rdma_message *recv_msgs; + struct mt_rdma_rx_buffer *rx_buffers; uint16_t buffer_cnt; pthread_t connect_thread; pthread_t cq_poll_thread; @@ -197,20 +202,21 @@ struct mt_rdma_impl { struct mtl_rdma_init_params para; }; -static inline struct mtl_rdma_init_params* mt_rdma_get_params(struct mt_rdma_impl* impl) { +static inline struct mtl_rdma_init_params * +mt_rdma_get_params(struct mt_rdma_impl *impl) { return &impl->para; } -static inline bool mt_rdma_low_latency(struct mt_rdma_impl* impl) { +static inline bool mt_rdma_low_latency(struct mt_rdma_impl *impl) { if (mt_rdma_get_params(impl)->flags & MTL_RDMA_FLAG_LOW_LATENCY) return true; else return false; } -static inline int mt_rdma_handle_cq_events(struct ibv_comp_channel* cc, - struct ibv_cq* cq) { - void* cq_ctx = NULL; +static inline int mt_rdma_handle_cq_events(struct ibv_comp_channel *cc, + struct ibv_cq *cq) { + void *cq_ctx = NULL; int ret = ibv_get_cq_event(cc, &cq, &cq_ctx); if (ret) { err("%s, ibv_get_cq_event failed\n", __func__); @@ -225,8 +231,9 @@ static inline int mt_rdma_handle_cq_events(struct ibv_comp_channel* cc, return 0; } -static inline int mt_rdma_post_write_imm(struct rdma_cm_id* id, void* context, void* addr, - size_t length, struct ibv_mr* mr, int flags, +static inline int mt_rdma_post_write_imm(struct rdma_cm_id *id, void *context, + void *addr, size_t length, + struct ibv_mr *mr, int flags, uint64_t remote_addr, uint32_t rkey, uint32_t imm_data) { struct ibv_send_wr wr, *bad_wr; diff --git a/rdma/mt_rdma_rx.c b/rdma/mt_rdma_rx.c index 5773d94ce..4196f7251 100644 --- a/rdma/mt_rdma_rx.c +++ b/rdma/mt_rdma_rx.c @@ -4,8 +4,8 @@ #include "mt_rdma.h" -static int rdma_rx_send_buffer_done(struct mt_rdma_rx_ctx* ctx, uint16_t idx) { - struct mt_rdma_rx_buffer* rx_buffer = &ctx->rx_buffers[idx]; +static int rdma_rx_send_buffer_done(struct mt_rdma_rx_ctx *ctx, uint16_t idx) { + struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[idx]; pthread_mutex_lock(&rx_buffer->lock); struct mt_rdma_message msg = { .magic = MT_RDMA_MSG_MAGIC, @@ -21,7 +21,8 @@ static int rdma_rx_send_buffer_done(struct mt_rdma_rx_ctx* ctx, uint16_t idx) { int ret = rdma_post_send(ctx->id, NULL, &msg, sizeof(msg), NULL, IBV_SEND_INLINE | IBV_SEND_SIGNALED); if (ret) { - err("%s(%s), rdma_post_send failed: %s\n", __func__, ctx->ops_name, strerror(errno)); + err("%s(%s), rdma_post_send failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); pthread_mutex_unlock(&rx_buffer->lock); return -EIO; } @@ -30,20 +31,20 @@ static int rdma_rx_send_buffer_done(struct mt_rdma_rx_ctx* ctx, uint16_t idx) { return 0; } -static int rdma_rx_uinit_mrs(struct mt_rdma_rx_ctx* ctx) { +static int rdma_rx_uinit_mrs(struct mt_rdma_rx_ctx *ctx) { MT_SAFE_FREE(ctx->meta_mr, ibv_dereg_mr); MT_SAFE_FREE(ctx->recv_msgs_mr, ibv_dereg_mr); for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_rx_buffer* rx_buffer = &ctx->rx_buffers[i]; + struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[i]; MT_SAFE_FREE(rx_buffer->mr, ibv_dereg_mr); } return 0; } -static int rdma_rx_init_mrs(struct mt_rdma_rx_ctx* ctx) { +static int rdma_rx_init_mrs(struct mt_rdma_rx_ctx *ctx) { for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_rx_buffer* rx_buffer = &ctx->rx_buffers[i]; - struct ibv_mr* mr = + struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[i]; + struct ibv_mr *mr = ibv_reg_mr(ctx->pd, rx_buffer->buffer.addr, rx_buffer->buffer.capacity, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); if (!mr) { @@ -54,9 +55,9 @@ static int rdma_rx_init_mrs(struct mt_rdma_rx_ctx* ctx) { rx_buffer->mr = mr; } - struct ibv_mr* mr = ibv_reg_mr(ctx->pd, ctx->recv_msgs, - ctx->buffer_cnt * sizeof(struct mt_rdma_message), - IBV_ACCESS_LOCAL_WRITE); + struct ibv_mr *mr = ibv_reg_mr( + ctx->pd, ctx->recv_msgs, ctx->buffer_cnt * sizeof(struct mt_rdma_message), + IBV_ACCESS_LOCAL_WRITE); if (!mr) { err("%s(%s), ibv_reg_mr message failed\n", __func__, ctx->ops_name); rdma_rx_uinit_mrs(ctx); @@ -64,7 +65,8 @@ static int rdma_rx_init_mrs(struct mt_rdma_rx_ctx* ctx) { } ctx->recv_msgs_mr = mr; - mr = ibv_reg_mr(ctx->pd, ctx->meta_region, ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, + mr = ibv_reg_mr(ctx->pd, ctx->meta_region, + ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); if (!mr) { err("%s(%s), ibv_reg_mr meta region failed\n", __func__, ctx->ops_name); @@ -76,7 +78,7 @@ static int rdma_rx_init_mrs(struct mt_rdma_rx_ctx* ctx) { return 0; } -static int rdma_rx_free_buffers(struct mt_rdma_rx_ctx* ctx) { +static int rdma_rx_free_buffers(struct mt_rdma_rx_ctx *ctx) { rdma_rx_uinit_mrs(ctx); MT_SAFE_FREE(ctx->meta_region, free); MT_SAFE_FREE(ctx->recv_msgs, free); @@ -87,8 +89,8 @@ static int rdma_rx_free_buffers(struct mt_rdma_rx_ctx* ctx) { return 0; } -static int rdma_rx_alloc_buffers(struct mt_rdma_rx_ctx* ctx) { - struct mtl_rdma_rx_ops* ops = &ctx->ops; +static int rdma_rx_alloc_buffers(struct mt_rdma_rx_ctx *ctx) { + struct mtl_rdma_rx_ops *ops = &ctx->ops; ctx->buffer_cnt = ops->num_buffers; /* alloc receive message region, send messages are inlined */ @@ -115,7 +117,7 @@ static int rdma_rx_alloc_buffers(struct mt_rdma_rx_ctx* ctx) { } for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_rx_buffer* rx_buffer = &ctx->rx_buffers[i]; + struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[i]; rx_buffer->idx = i; rx_buffer->status = MT_RDMA_BUFFER_STATUS_FREE; rx_buffer->buffer.addr = ops->buffers[i]; @@ -127,11 +129,12 @@ static int rdma_rx_alloc_buffers(struct mt_rdma_rx_ctx* ctx) { return 0; } -static int rdma_rx_handle_wc_recv_imm(struct mt_rdma_rx_ctx* ctx, struct ibv_wc* wc) { - struct mtl_rdma_rx_ops* ops = &ctx->ops; +static int rdma_rx_handle_wc_recv_imm(struct mt_rdma_rx_ctx *ctx, + struct ibv_wc *wc) { + struct mtl_rdma_rx_ops *ops = &ctx->ops; uint16_t idx = ntohl(wc->imm_data) >> 16; dbg("%s(%s), buffer %u write done\n", __func__, ctx->ops_name, idx); - struct mt_rdma_rx_buffer* rx_buffer = &ctx->rx_buffers[idx]; + struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[idx]; pthread_mutex_lock(&rx_buffer->lock); if (rx_buffer->status != MT_RDMA_BUFFER_STATUS_FREE) { @@ -143,19 +146,21 @@ static int rdma_rx_handle_wc_recv_imm(struct mt_rdma_rx_ctx* ctx, struct ibv_wc* rx_buffer->buffer.user_meta_size = ntohl(wc->imm_data) & 0x0000FFFF; rx_buffer->status = MT_RDMA_BUFFER_STATUS_READY; ctx->stat_buffer_received++; - if (ops->notify_buffer_ready) ops->notify_buffer_ready(ops->priv, &rx_buffer->buffer); + if (ops->notify_buffer_ready) + ops->notify_buffer_ready(ops->priv, &rx_buffer->buffer); pthread_mutex_unlock(&rx_buffer->lock); - struct mt_rdma_message* msg = (struct mt_rdma_message*)wc->wr_id; + struct mt_rdma_message *msg = (struct mt_rdma_message *)wc->wr_id; int ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, strerror(errno)); + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); return -EIO; } return 0; } -static int rdma_rx_handle_wc(struct mt_rdma_rx_ctx* ctx, struct ibv_wc* wc) { +static int rdma_rx_handle_wc(struct mt_rdma_rx_ctx *ctx, struct ibv_wc *wc) { if (wc->status != IBV_WC_SUCCESS) { err("%s(%s), work completion error: %s\n", __func__, ctx->ops_name, ibv_wc_status_str(wc->status)); @@ -165,22 +170,22 @@ static int rdma_rx_handle_wc(struct mt_rdma_rx_ctx* ctx, struct ibv_wc* wc) { } switch (wc->opcode) { - case IBV_WC_RECV_RDMA_WITH_IMM: - return rdma_rx_handle_wc_recv_imm(ctx, wc); - case IBV_WC_SEND: - return 0; /* nothing to do */ - default: - err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); - return -EIO; + case IBV_WC_RECV_RDMA_WITH_IMM: + return rdma_rx_handle_wc_recv_imm(ctx, wc); + case IBV_WC_SEND: + return 0; /* nothing to do */ + default: + err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); + return -EIO; } } /* cq poll thread */ -static void* rdma_rx_cq_poll_thread(void* arg) { +static void *rdma_rx_cq_poll_thread(void *arg) { int ret = 0; - struct mt_rdma_rx_ctx* ctx = arg; + struct mt_rdma_rx_ctx *ctx = arg; struct ibv_wc wc; - struct ibv_cq* cq = ctx->cq; + struct ibv_cq *cq = ctx->cq; int ms_timeout = 10; struct pollfd pfd = {0}; @@ -215,8 +220,10 @@ static void* rdma_rx_cq_poll_thread(void* arg) { } while (ibv_poll_cq(cq, 1, &wc)) { - if (ctx->cq_poll_stop) break; - if (rdma_rx_handle_wc(ctx, &wc)) goto out; + if (ctx->cq_poll_stop) + break; + if (rdma_rx_handle_wc(ctx, &wc)) + goto out; ctx->stat_cq_poll_done++; } @@ -229,10 +236,10 @@ static void* rdma_rx_cq_poll_thread(void* arg) { } /* connect thread */ -static void* rdma_rx_connect_thread(void* arg) { +static void *rdma_rx_connect_thread(void *arg) { int ret = 0; - struct mt_rdma_rx_ctx* ctx = arg; - struct rdma_cm_event* event; + struct mt_rdma_rx_ctx *ctx = arg; + struct rdma_cm_event *event; struct pollfd pfd = { .fd = ctx->ec->fd, .events = POLLIN, @@ -242,7 +249,8 @@ static void* rdma_rx_connect_thread(void* arg) { while (!ctx->connect_stop) { ret = poll(&pfd, 1, 200); if (ret < 0) { - err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, strerror(errno)); + err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); goto connect_err; } else if (ret == 0) { /* timeout */ @@ -251,106 +259,110 @@ static void* rdma_rx_connect_thread(void* arg) { ret = rdma_get_cm_event(ctx->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_ADDR_RESOLVED: - ret = rdma_resolve_route(ctx->id, 2000); - if (ret) { - err("%s(%s), rdma_resolve_route failed\n", __func__, ctx->ops_name); - goto connect_err; - } - break; - case RDMA_CM_EVENT_ROUTE_RESOLVED: - ctx->pd = ibv_alloc_pd(event->id->verbs); - if (!ctx->pd) { - err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ctx->cc = ibv_create_comp_channel(event->id->verbs); - if (!ctx->cc) { - err("%s(%s), ibv_create_comp_channel failed\n", __func__, ctx->ops_name); - goto connect_err; - } - } - ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); - if (!ctx->cq) { - err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ret = ibv_req_notify_cq(ctx->cq, 0); - if (ret) { - err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); - goto connect_err; - } - } - struct ibv_qp_init_attr init_qp_attr = { - .cap.max_send_wr = ctx->buffer_cnt * 2, - .cap.max_recv_wr = ctx->buffer_cnt * 2, - .cap.max_send_sge = 1, - .cap.max_recv_sge = 1, - .cap.max_inline_data = sizeof(struct mt_rdma_message), - .sq_sig_all = 0, - .send_cq = ctx->cq, - .recv_cq = ctx->cq, - .qp_type = IBV_QPT_RC, - }; - ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); - if (ret) { - err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); + case RDMA_CM_EVENT_ADDR_RESOLVED: + ret = rdma_resolve_route(ctx->id, 2000); + if (ret) { + err("%s(%s), rdma_resolve_route failed\n", __func__, ctx->ops_name); + goto connect_err; + } + break; + case RDMA_CM_EVENT_ROUTE_RESOLVED: + ctx->pd = ibv_alloc_pd(event->id->verbs); + if (!ctx->pd) { + err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); + goto connect_err; + } + if (!ctx->cq_poll_only) { + ctx->cc = ibv_create_comp_channel(event->id->verbs); + if (!ctx->cc) { + err("%s(%s), ibv_create_comp_channel failed\n", __func__, + ctx->ops_name); goto connect_err; } - ctx->qp = event->id->qp; - ret = rdma_rx_init_mrs(ctx); + } + ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); + if (!ctx->cq) { + err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); + goto connect_err; + } + if (!ctx->cq_poll_only) { + ret = ibv_req_notify_cq(ctx->cq, 0); if (ret) { - err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); + err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); goto connect_err; } - struct rdma_conn_param conn_param = { - .initiator_depth = 1, - .responder_resources = 1, - .rnr_retry_count = 7 /* infinite retry */, - }; - ret = rdma_connect(event->id, &conn_param); + } + struct ibv_qp_init_attr init_qp_attr = { + .cap.max_send_wr = ctx->buffer_cnt * 2, + .cap.max_recv_wr = ctx->buffer_cnt * 2, + .cap.max_send_sge = 1, + .cap.max_recv_sge = 1, + .cap.max_inline_data = sizeof(struct mt_rdma_message), + .sq_sig_all = 0, + .send_cq = ctx->cq, + .recv_cq = ctx->cq, + .qp_type = IBV_QPT_RC, + }; + ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); + if (ret) { + err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); + goto connect_err; + } + ctx->qp = event->id->qp; + ret = rdma_rx_init_mrs(ctx); + if (ret) { + err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); + goto connect_err; + } + struct rdma_conn_param conn_param = { + .initiator_depth = 1, + .responder_resources = 1, + .rnr_retry_count = 7 /* infinite retry */, + }; + ret = rdma_connect(event->id, &conn_param); + if (ret) { + err("%s(%s), rdma_connect failed\n", __func__, ctx->ops_name); + goto connect_err; + } + break; + case RDMA_CM_EVENT_ESTABLISHED: + for (uint16_t i = 0; i < ctx->buffer_cnt; i++) { /* start receiving */ + struct mt_rdma_message *msg = &ctx->recv_msgs[i]; + ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), + ctx->recv_msgs_mr); if (ret) { - err("%s(%s), rdma_connect failed\n", __func__, ctx->ops_name); + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); goto connect_err; } - break; - case RDMA_CM_EVENT_ESTABLISHED: - for (uint16_t i = 0; i < ctx->buffer_cnt; i++) { /* start receiving */ - struct mt_rdma_message* msg = &ctx->recv_msgs[i]; - ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); - if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); - goto connect_err; - } - ret = rdma_rx_send_buffer_done(ctx, i); - if (ret) { - err("%s(%s), rdma_rx_send_buffer_done failed\n", __func__, ctx->ops_name); - goto connect_err; - } - } - ctx->connected = true; - ctx->cq_poll_stop = false; - ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_rx_cq_poll_thread, ctx); + ret = rdma_rx_send_buffer_done(ctx, i); if (ret) { - err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); + err("%s(%s), rdma_rx_send_buffer_done failed\n", __func__, + ctx->ops_name); goto connect_err; } - info("%s(%s), connected\n", __func__, ctx->ops_name); - break; - case RDMA_CM_EVENT_DISCONNECTED: - info("%s(%s), TX disconnected.\n", __func__, ctx->ops_name); - ctx->connected = false; - ctx->cq_poll_stop = true; - ctx->connect_stop = true; - /* todo: handle resources clearing and notifying */ - break; - default: - err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, - rdma_event_str(event->event), event->status); + } + ctx->connected = true; + ctx->cq_poll_stop = false; + ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_rx_cq_poll_thread, + ctx); + if (ret) { + err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); goto connect_err; + } + info("%s(%s), connected\n", __func__, ctx->ops_name); + break; + case RDMA_CM_EVENT_DISCONNECTED: + info("%s(%s), TX disconnected.\n", __func__, ctx->ops_name); + ctx->connected = false; + ctx->cq_poll_stop = true; + ctx->connect_stop = true; + /* todo: handle resources clearing and notifying */ + break; + default: + err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, + rdma_event_str(event->event), event->status); + goto connect_err; } rdma_ack_cm_event(event); } @@ -366,14 +378,14 @@ static void* rdma_rx_connect_thread(void* arg) { return NULL; } -struct mtl_rdma_buffer* mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle) { - struct mt_rdma_rx_ctx* ctx = handle; +struct mtl_rdma_buffer *mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle) { + struct mt_rdma_rx_ctx *ctx = handle; if (!ctx->connected) { return NULL; } /* find a ready buffer */ for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_rx_buffer* rx_buffer = &ctx->rx_buffers[i]; + struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[i]; pthread_mutex_lock(&rx_buffer->lock); if (rx_buffer->status == MT_RDMA_BUFFER_STATUS_READY) { rx_buffer->status = MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION; @@ -386,18 +398,21 @@ struct mtl_rdma_buffer* mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle) { return NULL; } -int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, struct mtl_rdma_buffer* buffer) { - struct mt_rdma_rx_ctx* ctx = handle; +int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, + struct mtl_rdma_buffer *buffer) { + struct mt_rdma_rx_ctx *ctx = handle; if (!ctx->connected) { return -EIO; } for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_rx_buffer* rx_buffer = &ctx->rx_buffers[i]; - if (&rx_buffer->buffer != buffer) continue; + struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[i]; + if (&rx_buffer->buffer != buffer) + continue; pthread_mutex_lock(&rx_buffer->lock); if (rx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION) { - err("%s(%s), buffer %p not in consumption\n", __func__, ctx->ops_name, buffer); + err("%s(%s), buffer %p not in consumption\n", __func__, ctx->ops_name, + buffer); pthread_mutex_unlock(&rx_buffer->lock); return -EIO; } @@ -410,7 +425,7 @@ int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, struct mtl_rdma_buffer* bu } int mtl_rdma_rx_free(mtl_rdma_rx_handle handle) { - struct mt_rdma_rx_ctx* ctx = handle; + struct mt_rdma_rx_ctx *ctx = handle; if (!ctx) { return 0; @@ -422,8 +437,8 @@ int mtl_rdma_rx_free(mtl_rdma_rx_handle handle) { ctx->cq_poll_thread = 0; /* print cq poll stat */ - dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, ctx->ops_name, - ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); + dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, + ctx->ops_name, ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); } if (ctx->connect_thread) { @@ -450,9 +465,10 @@ int mtl_rdma_rx_free(mtl_rdma_rx_handle handle) { return 0; } -mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, struct mtl_rdma_rx_ops* ops) { +mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, + struct mtl_rdma_rx_ops *ops) { int ret = 0; - struct mt_rdma_rx_ctx* ctx = calloc(1, sizeof(*ctx)); + struct mt_rdma_rx_ctx *ctx = calloc(1, sizeof(*ctx)); if (!ctx) { err("%s(%s), malloc mt_rdma_rx_ctx failed\n", __func__, ops->name); return NULL; diff --git a/rdma/mt_rdma_tx.c b/rdma/mt_rdma_tx.c index e22156340..a9474adc4 100644 --- a/rdma/mt_rdma_tx.c +++ b/rdma/mt_rdma_tx.c @@ -4,20 +4,20 @@ #include "mt_rdma.h" -static int rdma_tx_uinit_mrs(struct mt_rdma_tx_ctx* ctx) { +static int rdma_tx_uinit_mrs(struct mt_rdma_tx_ctx *ctx) { MT_SAFE_FREE(ctx->meta_mr, ibv_dereg_mr); MT_SAFE_FREE(ctx->recv_msgs_mr, ibv_dereg_mr); for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_tx_buffer* tx_buffer = &ctx->tx_buffers[i]; + struct mt_rdma_tx_buffer *tx_buffer = &ctx->tx_buffers[i]; MT_SAFE_FREE(tx_buffer->mr, ibv_dereg_mr); } return 0; } -static int rdma_tx_init_mrs(struct mt_rdma_tx_ctx* ctx) { +static int rdma_tx_init_mrs(struct mt_rdma_tx_ctx *ctx) { for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_tx_buffer* tx_buffer = &ctx->tx_buffers[i]; - struct ibv_mr* mr = + struct mt_rdma_tx_buffer *tx_buffer = &ctx->tx_buffers[i]; + struct ibv_mr *mr = ibv_reg_mr(ctx->pd, tx_buffer->buffer.addr, tx_buffer->buffer.capacity, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); if (!mr) { @@ -29,17 +29,19 @@ static int rdma_tx_init_mrs(struct mt_rdma_tx_ctx* ctx) { tx_buffer->mr = mr; } - struct ibv_mr* mr = ibv_reg_mr(ctx->pd, ctx->recv_msgs, - ctx->buffer_cnt * sizeof(struct mt_rdma_message), - IBV_ACCESS_LOCAL_WRITE); + struct ibv_mr *mr = ibv_reg_mr( + ctx->pd, ctx->recv_msgs, ctx->buffer_cnt * sizeof(struct mt_rdma_message), + IBV_ACCESS_LOCAL_WRITE); if (!mr) { - err("%s(%s), ibv_reg_mr receive messages failed\n", __func__, ctx->ops_name); + err("%s(%s), ibv_reg_mr receive messages failed\n", __func__, + ctx->ops_name); rdma_tx_uinit_mrs(ctx); return -ENOMEM; } ctx->recv_msgs_mr = mr; - mr = ibv_reg_mr(ctx->pd, ctx->meta_region, ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, + mr = ibv_reg_mr(ctx->pd, ctx->meta_region, + ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); if (!mr) { err("%s(%s), ibv_reg_mr meta region failed\n", __func__, ctx->ops_name); @@ -51,7 +53,7 @@ static int rdma_tx_init_mrs(struct mt_rdma_tx_ctx* ctx) { return 0; } -static int rdma_tx_free_buffers(struct mt_rdma_tx_ctx* ctx) { +static int rdma_tx_free_buffers(struct mt_rdma_tx_ctx *ctx) { rdma_tx_uinit_mrs(ctx); MT_SAFE_FREE(ctx->meta_region, free); MT_SAFE_FREE(ctx->recv_msgs, free); @@ -62,8 +64,8 @@ static int rdma_tx_free_buffers(struct mt_rdma_tx_ctx* ctx) { return 0; } -static int rdma_tx_alloc_buffers(struct mt_rdma_tx_ctx* ctx) { - struct mtl_rdma_tx_ops* ops = &ctx->ops; +static int rdma_tx_alloc_buffers(struct mt_rdma_tx_ctx *ctx) { + struct mtl_rdma_tx_ops *ops = &ctx->ops; ctx->buffer_cnt = ops->num_buffers; /* alloc receive message region */ @@ -90,10 +92,11 @@ static int rdma_tx_alloc_buffers(struct mt_rdma_tx_ctx* ctx) { } for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_tx_buffer* tx_buffer = &ctx->tx_buffers[i]; + struct mt_rdma_tx_buffer *tx_buffer = &ctx->tx_buffers[i]; tx_buffer->idx = i; tx_buffer->status = - MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION; /* need to receive done form rx to start */ + MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION; /* need to receive done form rx to + start */ tx_buffer->ref_count = 1; tx_buffer->buffer.addr = ops->buffers[i]; tx_buffer->buffer.capacity = ops->buffer_capacity; @@ -104,76 +107,82 @@ static int rdma_tx_alloc_buffers(struct mt_rdma_tx_ctx* ctx) { return 0; } -static int rdma_tx_handle_wc_recv(struct mt_rdma_tx_ctx* ctx, struct ibv_wc* wc) { +static int rdma_tx_handle_wc_recv(struct mt_rdma_tx_ctx *ctx, + struct ibv_wc *wc) { int ret = 0; uint16_t idx = 0; - struct mt_rdma_tx_buffer* tx_buffer = NULL; - struct mtl_rdma_tx_ops* ops = &ctx->ops; - struct mt_rdma_message* msg = (struct mt_rdma_message*)wc->wr_id; + struct mt_rdma_tx_buffer *tx_buffer = NULL; + struct mtl_rdma_tx_ops *ops = &ctx->ops; + struct mt_rdma_message *msg = (struct mt_rdma_message *)wc->wr_id; if (msg->magic != MT_RDMA_MSG_MAGIC) { - err("%s(%s), received invalid magic %u\n", __func__, ctx->ops_name, msg->magic); + err("%s(%s), received invalid magic %u\n", __func__, ctx->ops_name, + msg->magic); return -EINVAL; } switch (msg->type) { - case MT_RDMA_MSG_BUFFER_DONE: - idx = msg->buf_done.buf_idx; - dbg("%s(%s), received buffer %u done message, seq %u\n", __func__, ctx->ops_name, - idx, msg->buf_done.seq_num); - tx_buffer = &ctx->tx_buffers[idx]; - pthread_mutex_lock(&tx_buffer->lock); - if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION) { - err("%s(%s), received buffer done message with invalid status %d\n", __func__, - ctx->ops_name, tx_buffer->status); - pthread_mutex_unlock(&tx_buffer->lock); - return -EINVAL; - } - tx_buffer->remote_buffer = msg->buf_done.remote_buffer; - tx_buffer->ref_count--; - if (tx_buffer->ref_count == 0) { - tx_buffer->status = MT_RDMA_BUFFER_STATUS_FREE; - if (ops->notify_buffer_done) - ops->notify_buffer_done(ops->priv, &tx_buffer->buffer); - } + case MT_RDMA_MSG_BUFFER_DONE: + idx = msg->buf_done.buf_idx; + dbg("%s(%s), received buffer %u done message, seq %u\n", __func__, + ctx->ops_name, idx, msg->buf_done.seq_num); + tx_buffer = &ctx->tx_buffers[idx]; + pthread_mutex_lock(&tx_buffer->lock); + if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION) { + err("%s(%s), received buffer done message with invalid status %d\n", + __func__, ctx->ops_name, tx_buffer->status); pthread_mutex_unlock(&tx_buffer->lock); - ctx->stat_buffer_acked++; - break; + return -EINVAL; + } + tx_buffer->remote_buffer = msg->buf_done.remote_buffer; + tx_buffer->ref_count--; + if (tx_buffer->ref_count == 0) { + tx_buffer->status = MT_RDMA_BUFFER_STATUS_FREE; + if (ops->notify_buffer_done) + ops->notify_buffer_done(ops->priv, &tx_buffer->buffer); + } + pthread_mutex_unlock(&tx_buffer->lock); + ctx->stat_buffer_acked++; + break; - default: - err("%s(%s), received unknown message type %d\n", __func__, ctx->ops_name, - msg->type); - return -EIO; + default: + err("%s(%s), received unknown message type %d\n", __func__, ctx->ops_name, + msg->type); + return -EIO; } ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, strerror(errno)); + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); return -EIO; } return 0; } -static int rdma_tx_handle_wc_write(struct mt_rdma_tx_ctx* ctx, struct ibv_wc* wc) { - struct mtl_rdma_tx_ops* ops = &ctx->ops; - struct mt_rdma_tx_buffer* tx_buffer = (struct mt_rdma_tx_buffer*)wc->wr_id; +static int rdma_tx_handle_wc_write(struct mt_rdma_tx_ctx *ctx, + struct ibv_wc *wc) { + struct mtl_rdma_tx_ops *ops = &ctx->ops; + struct mt_rdma_tx_buffer *tx_buffer = (struct mt_rdma_tx_buffer *)wc->wr_id; pthread_mutex_lock(&tx_buffer->lock); if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_TRANSMISSION) { - err("%s(%s), buffer write done with invalid status %d\n", __func__, ctx->ops_name, - tx_buffer->status); + err("%s(%s), buffer write done with invalid status %d\n", __func__, + ctx->ops_name, tx_buffer->status); pthread_mutex_unlock(&tx_buffer->lock); return -EINVAL; } - dbg("%s(%s), buffer %d write done\n", __func__, ctx->ops_name, tx_buffer->idx); + dbg("%s(%s), buffer %d write done\n", __func__, ctx->ops_name, + tx_buffer->idx); tx_buffer->status = MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION; tx_buffer->ref_count++; - if (ops->notify_buffer_sent) ops->notify_buffer_sent(ops->priv, &tx_buffer->buffer); + if (ops->notify_buffer_sent) + ops->notify_buffer_sent(ops->priv, &tx_buffer->buffer); pthread_mutex_unlock(&tx_buffer->lock); ctx->stat_buffer_sent++; return 0; } -static int rdma_tx_handle_wc(struct mt_rdma_tx_ctx* ctx, struct ibv_wc* wc) { +static int rdma_tx_handle_wc(struct mt_rdma_tx_ctx *ctx, struct ibv_wc *wc) { if (wc->status != IBV_WC_SUCCESS) { err("%s(%s), work completion error: %s\n", __func__, ctx->ops_name, ibv_wc_status_str(wc->status)); @@ -183,22 +192,22 @@ static int rdma_tx_handle_wc(struct mt_rdma_tx_ctx* ctx, struct ibv_wc* wc) { } switch (wc->opcode) { - case IBV_WC_RECV: - return rdma_tx_handle_wc_recv(ctx, wc); - case IBV_WC_RDMA_WRITE: - return rdma_tx_handle_wc_write(ctx, wc); - default: - err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); - return -EIO; + case IBV_WC_RECV: + return rdma_tx_handle_wc_recv(ctx, wc); + case IBV_WC_RDMA_WRITE: + return rdma_tx_handle_wc_write(ctx, wc); + default: + err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); + return -EIO; } } /* cq poll thread */ -static void* rdma_tx_cq_poll_thread(void* arg) { +static void *rdma_tx_cq_poll_thread(void *arg) { int ret = 0; - struct mt_rdma_tx_ctx* ctx = arg; + struct mt_rdma_tx_ctx *ctx = arg; struct ibv_wc wc; - struct ibv_cq* cq = ctx->cq; + struct ibv_cq *cq = ctx->cq; int ms_timeout = 10; struct pollfd pfd = {0}; @@ -233,8 +242,10 @@ static void* rdma_tx_cq_poll_thread(void* arg) { } while (ibv_poll_cq(cq, 1, &wc)) { - if (ctx->cq_poll_stop) break; - if (rdma_tx_handle_wc(ctx, &wc)) goto out; + if (ctx->cq_poll_stop) + break; + if (rdma_tx_handle_wc(ctx, &wc)) + goto out; ctx->stat_cq_poll_done++; } @@ -247,10 +258,10 @@ static void* rdma_tx_cq_poll_thread(void* arg) { } /* connect thread */ -static void* rdma_tx_connect_thread(void* arg) { +static void *rdma_tx_connect_thread(void *arg) { int ret = 0; - struct mt_rdma_tx_ctx* ctx = arg; - struct rdma_cm_event* event; + struct mt_rdma_tx_ctx *ctx = arg; + struct rdma_cm_event *event; struct pollfd pfd = { .fd = ctx->ec->fd, .events = POLLIN, @@ -260,7 +271,8 @@ static void* rdma_tx_connect_thread(void* arg) { while (!ctx->connect_stop) { ret = poll(&pfd, 1, 200); if (ret < 0) { - err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, strerror(errno)); + err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); goto connect_err; } else if (ret == 0) { /* timeout */ @@ -269,97 +281,100 @@ static void* rdma_tx_connect_thread(void* arg) { ret = rdma_get_cm_event(ctx->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_CONNECT_REQUEST: - ctx->pd = ibv_alloc_pd(event->id->verbs); - if (!ctx->pd) { - err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ctx->cc = ibv_create_comp_channel(event->id->verbs); - if (!ctx->cc) { - err("%s(%s), ibv_create_comp_channel failed\n", __func__, ctx->ops_name); - goto connect_err; - } - } - ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); - if (!ctx->cq) { - err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ret = ibv_req_notify_cq(ctx->cq, 0); - if (ret) { - err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); - goto connect_err; - } - } - struct ibv_qp_init_attr init_qp_attr = { - .cap.max_send_wr = ctx->buffer_cnt * 2, - .cap.max_recv_wr = ctx->buffer_cnt * 2, - .cap.max_send_sge = 1, - .cap.max_recv_sge = 1, - .cap.max_inline_data = sizeof(struct mt_rdma_message), - .sq_sig_all = 0, - .send_cq = ctx->cq, - .recv_cq = ctx->cq, - .qp_type = IBV_QPT_RC, - }; - ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); - if (ret) { - err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); + case RDMA_CM_EVENT_CONNECT_REQUEST: + ctx->pd = ibv_alloc_pd(event->id->verbs); + if (!ctx->pd) { + err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); + goto connect_err; + } + if (!ctx->cq_poll_only) { + ctx->cc = ibv_create_comp_channel(event->id->verbs); + if (!ctx->cc) { + err("%s(%s), ibv_create_comp_channel failed\n", __func__, + ctx->ops_name); goto connect_err; } - ctx->qp = event->id->qp; - - ret = rdma_tx_init_mrs(ctx); + } + ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); + if (!ctx->cq) { + err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); + goto connect_err; + } + if (!ctx->cq_poll_only) { + ret = ibv_req_notify_cq(ctx->cq, 0); if (ret) { - err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); + err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); goto connect_err; } + } + struct ibv_qp_init_attr init_qp_attr = { + .cap.max_send_wr = ctx->buffer_cnt * 2, + .cap.max_recv_wr = ctx->buffer_cnt * 2, + .cap.max_send_sge = 1, + .cap.max_recv_sge = 1, + .cap.max_inline_data = sizeof(struct mt_rdma_message), + .sq_sig_all = 0, + .send_cq = ctx->cq, + .recv_cq = ctx->cq, + .qp_type = IBV_QPT_RC, + }; + ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); + if (ret) { + err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); + goto connect_err; + } + ctx->qp = event->id->qp; - struct rdma_conn_param conn_param = { - .initiator_depth = 1, - .responder_resources = 1, - .rnr_retry_count = 7, - }; - ret = rdma_accept(event->id, &conn_param); - if (ret) { - err("%s(%s), rdma_accept failed\n", __func__, ctx->ops_name); - goto connect_err; - } - ctx->id = event->id; - break; - case RDMA_CM_EVENT_ESTABLISHED: - for (int i = 0; i < ctx->buffer_cnt; i++) { /* post receive done msg */ - struct mt_rdma_message* msg = &ctx->recv_msgs[i]; - ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); - if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); - goto connect_err; - } - } - ctx->connected = true; - ctx->cq_poll_stop = false; - ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_tx_cq_poll_thread, ctx); + ret = rdma_tx_init_mrs(ctx); + if (ret) { + err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); + goto connect_err; + } + + struct rdma_conn_param conn_param = { + .initiator_depth = 1, + .responder_resources = 1, + .rnr_retry_count = 7, + }; + ret = rdma_accept(event->id, &conn_param); + if (ret) { + err("%s(%s), rdma_accept failed\n", __func__, ctx->ops_name); + goto connect_err; + } + ctx->id = event->id; + break; + case RDMA_CM_EVENT_ESTABLISHED: + for (int i = 0; i < ctx->buffer_cnt; i++) { /* post receive done msg */ + struct mt_rdma_message *msg = &ctx->recv_msgs[i]; + ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), + ctx->recv_msgs_mr); if (ret) { - err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); goto connect_err; } - info("%s(%s), connected\n", __func__, ctx->ops_name); - break; - case RDMA_CM_EVENT_DISCONNECTED: - info("%s(%s), RX disconnected.\n", __func__, ctx->ops_name); - ctx->connected = false; - ctx->cq_poll_stop = true; - ctx->connect_stop = true; - /* todo: handle resources clearing and notifying */ - break; - default: - err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, - rdma_event_str(event->event), event->status); + } + ctx->connected = true; + ctx->cq_poll_stop = false; + ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_tx_cq_poll_thread, + ctx); + if (ret) { + err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); goto connect_err; + } + info("%s(%s), connected\n", __func__, ctx->ops_name); + break; + case RDMA_CM_EVENT_DISCONNECTED: + info("%s(%s), RX disconnected.\n", __func__, ctx->ops_name); + ctx->connected = false; + ctx->cq_poll_stop = true; + ctx->connect_stop = true; + /* todo: handle resources clearing and notifying */ + break; + default: + err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, + rdma_event_str(event->event), event->status); + goto connect_err; } rdma_ack_cm_event(event); } @@ -375,15 +390,15 @@ static void* rdma_tx_connect_thread(void* arg) { return NULL; } -struct mtl_rdma_buffer* mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle) { - struct mt_rdma_tx_ctx* ctx = handle; +struct mtl_rdma_buffer *mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle) { + struct mt_rdma_tx_ctx *ctx = handle; if (!ctx->connected) { return NULL; } /* change to use buffer_producer_idx to act as a queue */ for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_tx_buffer* tx_buffer = &ctx->tx_buffers[i]; + struct mt_rdma_tx_buffer *tx_buffer = &ctx->tx_buffers[i]; pthread_mutex_lock(&tx_buffer->lock); if (tx_buffer->status == MT_RDMA_BUFFER_STATUS_FREE) { tx_buffer->status = MT_RDMA_BUFFER_STATUS_IN_PRODUCTION; @@ -395,8 +410,9 @@ struct mtl_rdma_buffer* mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle) { return NULL; } -int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, struct mtl_rdma_buffer* buffer) { - struct mt_rdma_tx_ctx* ctx = handle; +int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, + struct mtl_rdma_buffer *buffer) { + struct mt_rdma_tx_ctx *ctx = handle; if (!ctx->connected) { return -EIO; } @@ -412,21 +428,24 @@ int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, struct mtl_rdma_buffer* bu } for (int i = 0; i < ctx->buffer_cnt; i++) { - struct mt_rdma_tx_buffer* tx_buffer = &ctx->tx_buffers[i]; - if (&tx_buffer->buffer != buffer) continue; + struct mt_rdma_tx_buffer *tx_buffer = &ctx->tx_buffers[i]; + if (&tx_buffer->buffer != buffer) + continue; pthread_mutex_lock(&tx_buffer->lock); if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_PRODUCTION) { - err("%s(%s), buffer %p is not in production\n", __func__, ctx->ops_name, buffer); + err("%s(%s), buffer %p is not in production\n", __func__, ctx->ops_name, + buffer); pthread_mutex_unlock(&tx_buffer->lock); return -EIO; } /* write buffer to rx immediately */ - int ret = rdma_post_write(ctx->id, tx_buffer, buffer->addr, buffer->size, - tx_buffer->mr, 0, tx_buffer->remote_buffer.remote_addr, - tx_buffer->remote_buffer.remote_key); + int ret = + rdma_post_write(ctx->id, tx_buffer, buffer->addr, buffer->size, + tx_buffer->mr, 0, tx_buffer->remote_buffer.remote_addr, + tx_buffer->remote_buffer.remote_key); if (ret) { err("%s(%s), rdma_post_write failed: %s\n", __func__, ctx->ops_name, strerror(errno)); @@ -436,15 +455,16 @@ int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, struct mtl_rdma_buffer* bu /* write metadata to rx with imm data */ memcpy(tx_buffer->meta, buffer->user_meta, buffer->user_meta_size); - uint32_t imm_data = - htonl((uint32_t)tx_buffer->idx << 16 | tx_buffer->buffer.user_meta_size); - ret = mt_rdma_post_write_imm(ctx->id, tx_buffer, tx_buffer->meta, - buffer->user_meta_size, ctx->meta_mr, IBV_SEND_SIGNALED, - tx_buffer->remote_buffer.remote_meta_addr, - tx_buffer->remote_buffer.remote_meta_key, imm_data); + uint32_t imm_data = htonl((uint32_t)tx_buffer->idx << 16 | + tx_buffer->buffer.user_meta_size); + ret = mt_rdma_post_write_imm( + ctx->id, tx_buffer, tx_buffer->meta, buffer->user_meta_size, + ctx->meta_mr, IBV_SEND_SIGNALED, + tx_buffer->remote_buffer.remote_meta_addr, + tx_buffer->remote_buffer.remote_meta_key, imm_data); if (ret) { - err("%s(%s), mt_rdma_post_write_imm failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), mt_rdma_post_write_imm failed: %s\n", __func__, + ctx->ops_name, strerror(errno)); pthread_mutex_unlock(&tx_buffer->lock); return -EIO; } @@ -461,7 +481,7 @@ int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, struct mtl_rdma_buffer* bu } int mtl_rdma_tx_free(mtl_rdma_tx_handle handle) { - struct mt_rdma_tx_ctx* ctx = handle; + struct mt_rdma_tx_ctx *ctx = handle; if (!ctx) { return 0; } @@ -472,8 +492,8 @@ int mtl_rdma_tx_free(mtl_rdma_tx_handle handle) { ctx->cq_poll_thread = 0; /* print cq poll stat */ - dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, ctx->ops_name, - ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); + dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, + ctx->ops_name, ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); } if (ctx->connect_thread) { @@ -500,9 +520,10 @@ int mtl_rdma_tx_free(mtl_rdma_tx_handle handle) { return 0; } -mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, struct mtl_rdma_tx_ops* ops) { +mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, + struct mtl_rdma_tx_ops *ops) { int ret = 0; - struct mt_rdma_tx_ctx* ctx = calloc(1, sizeof(*ctx)); + struct mt_rdma_tx_ctx *ctx = calloc(1, sizeof(*ctx)); if (!ctx) { err("%s(%s), malloc mt_rdma_tx_ctx failed\n", __func__, ops->name); return NULL; @@ -524,7 +545,7 @@ mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, struct mtl_rdma_tx_op goto out; } - struct rdma_cm_id* listen_id = NULL; + struct rdma_cm_id *listen_id = NULL; ret = rdma_create_id(ctx->ec, &listen_id, ctx, RDMA_PS_TCP); if (ret) { err("%s(%s), rdma_create_id failed\n", __func__, ops->name); @@ -532,8 +553,9 @@ mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, struct mtl_rdma_tx_op } ctx->listen_id = listen_id; - struct rdma_addrinfo hints = {.ai_port_space = RDMA_PS_TCP, .ai_flags = RAI_PASSIVE}; - struct rdma_addrinfo* rai; + struct rdma_addrinfo hints = {.ai_port_space = RDMA_PS_TCP, + .ai_flags = RAI_PASSIVE}; + struct rdma_addrinfo *rai; ret = rdma_getaddrinfo(ops->ip, ops->port, &hints, &rai); if (ret) { err("%s(%s), rdma_getaddrinfo failed\n", __func__, ops->name); diff --git a/rdma/mtl_rdma_api.h b/rdma/mtl_rdma_api.h index f66736716..34edaafee 100644 --- a/rdma/mtl_rdma_api.h +++ b/rdma/mtl_rdma_api.h @@ -26,12 +26,12 @@ extern "C" { /** * Handle to MTL RDMA transport context. */ -typedef struct mt_rdma_impl* mtl_rdma_handle; +typedef struct mt_rdma_impl *mtl_rdma_handle; /** Handle to RDMA TX session of lib. */ -typedef struct mt_rdma_tx_ctx* mtl_rdma_tx_handle; +typedef struct mt_rdma_tx_ctx *mtl_rdma_tx_handle; /** Handle to RDMA RX session of lib. */ -typedef struct mt_rdma_rx_ctx* mtl_rdma_rx_handle; +typedef struct mt_rdma_rx_ctx *mtl_rdma_rx_handle; /** * Log level type to MTL RDMA transport context @@ -56,7 +56,7 @@ enum mtl_rdma_log_level { /** The structure info for buffer meta. */ struct mtl_rdma_buffer { /** Buffer address, immutable at runtime */ - void* addr; + void *addr; /** Buffer data capacity, immutable at runtime */ size_t capacity; /** Buffer valid data offset, mutable at runtime */ @@ -69,7 +69,7 @@ struct mtl_rdma_buffer { uint64_t timestamp; /** User metadata */ - void* user_meta; + void *user_meta; /** User metadata size */ size_t user_meta_size; }; @@ -77,30 +77,31 @@ struct mtl_rdma_buffer { /** The structure describing how to create a TX session. */ struct mtl_rdma_tx_ops { /** RDMA server ip. */ - char* ip; + char *ip; /** RDMA server port. */ - char* port; + char *port; /** The number of buffers. */ uint16_t num_buffers; /** Buffers addresses. */ - void** buffers; + void **buffers; /** The max size of each buffer, all buffers should have the same capacity. */ size_t buffer_capacity; /** Session name */ - const char* name; + const char *name; /** Optional. Private data to the callback function */ - void* priv; + void *priv; /** * Optional. Callback function to notify the buffer is sent by local side. * Implement with non-blocking function as it runs in the polling thread. */ - int (*notify_buffer_sent)(void* priv, struct mtl_rdma_buffer* buffer); + int (*notify_buffer_sent)(void *priv, struct mtl_rdma_buffer *buffer); /** - * Optional. Callback function to notify the buffer is consumed by remote side. - * Implement with non-blocking function as it runs in the polling thread. + * Optional. Callback function to notify the buffer is consumed by remote + * side. Implement with non-blocking function as it runs in the polling + * thread. */ - int (*notify_buffer_done)(void* priv, struct mtl_rdma_buffer* buffer); + int (*notify_buffer_done)(void *priv, struct mtl_rdma_buffer *buffer); }; /** @@ -115,7 +116,8 @@ struct mtl_rdma_tx_ops { * - NULL on error. * - Otherwise, the handle to the TX session. */ -mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, struct mtl_rdma_tx_ops* ops); +mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, + struct mtl_rdma_tx_ops *ops); /** * Free the TX session. @@ -138,7 +140,7 @@ int mtl_rdma_tx_free(mtl_rdma_tx_handle handle); * - NULL if no available buffer in the session. * - Otherwise, the buffer pointer. */ -struct mtl_rdma_buffer* mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle); +struct mtl_rdma_buffer *mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle); /** * Put back the buffer which get by mtl_rdma_tx_get_buffer to the TX @@ -152,32 +154,33 @@ struct mtl_rdma_buffer* mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, struct mtl_rdma_buffer* buffer); +int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, + struct mtl_rdma_buffer *buffer); /** The structure describing how to create an RX session. */ struct mtl_rdma_rx_ops { /** Local RDMA interface ip */ - char* local_ip; + char *local_ip; /** RDMA server ip */ - char* ip; + char *ip; /** RDMA server port */ - char* port; + char *port; /** The number of buffers. */ uint16_t num_buffers; /** buffers addresses */ - void** buffers; + void **buffers; /** The max size of each buffer, all buffers should have the same capacity. */ size_t buffer_capacity; /** Session name */ - const char* name; + const char *name; /** Optional. Private data to the callback function */ - void* priv; + void *priv; /** * Callback function to notify the buffer is ready to consume. * Implement with non-blocking function as it runs in the polling thread. */ - int (*notify_buffer_ready)(void* priv, struct mtl_rdma_buffer* buffer); + int (*notify_buffer_ready)(void *priv, struct mtl_rdma_buffer *buffer); }; /** @@ -192,7 +195,8 @@ struct mtl_rdma_rx_ops { * - NULL on error. * - Otherwise, the handle to the RX session. */ -mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, struct mtl_rdma_rx_ops* ops); +mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, + struct mtl_rdma_rx_ops *ops); /** * Free the RX session. @@ -215,7 +219,7 @@ int mtl_rdma_rx_free(mtl_rdma_rx_handle handle); * - NULL if no available buffer in the session. * - Otherwise, the buffer pointer. */ -struct mtl_rdma_buffer* mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle); +struct mtl_rdma_buffer *mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle); /** * Put back the buffer which get by mtl_rdma_rx_get_buffer to the RX @@ -229,7 +233,8 @@ struct mtl_rdma_buffer* mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, struct mtl_rdma_buffer* buffer); +int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, + struct mtl_rdma_buffer *buffer); /** MTL RDMA init flag */ enum mtl_rdma_init_flag { @@ -254,7 +259,7 @@ struct mtl_rdma_init_params { /** Number of RDMA devices. (reserved for future) */ uint32_t num_devices; /** RDMA devices names. (reserved for future) */ - char** devices; + char **devices; /** RDMA flags. (reserved for future) */ uint64_t flags; /** Log Level */ @@ -271,7 +276,7 @@ struct mtl_rdma_init_params { * - NULL on error. * - Otherwise, the handle to the RDMA transport context. */ -mtl_rdma_handle mtl_rdma_init(struct mtl_rdma_init_params* p); +mtl_rdma_handle mtl_rdma_init(struct mtl_rdma_init_params *p); /** * Uninitialize RDMA transport. diff --git a/tests/src/cvt_test.cpp b/tests/src/cvt_test.cpp index 3466f7919..662fbc5b6 100644 --- a/tests/src/cvt_test.cpp +++ b/tests/src/cvt_test.cpp @@ -7,38 +7,44 @@ TEST(Cvt, simd_level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); - const char* name = mtl_get_simd_level_name(cpu_level); + const char *name = mtl_get_simd_level_name(cpu_level); info("simd level by cpu: %d(%s)\n", cpu_level, name); } -static void test_cvt_rfc4175_422be10_to_yuv422p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be10_to_yuv422p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p10_u16) + st_test_free(p10_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_yuv422p10le_simd( - pg, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h, cvt_level); + ret = st20_rfc4175_422be10_to_yuv422p10le_simd(pg, p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), w, + h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422be10_simd( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_2, w, h, back_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), + pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -75,8 +81,8 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512) { } TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_vbmi) { - test_cvt_rfc4175_422be10_to_yuv422p10le(1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le( + 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_yuv422p10le(722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_yuv422p10le(722, 111, MTL_SIMD_LEVEL_NONE, @@ -90,37 +96,43 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_vbmi) { } } -static void test_cvt_rfc4175_422be10_to_yuv422p10le_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be10_to_yuv422p10le_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, + MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) mtl_hp_free(st, pg); - if (pg_2) st_test_free(pg_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + mtl_hp_free(st, pg); + if (pg_2) + st_test_free(pg_2); + if (p10_u16) + st_test_free(p10_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_yuv422p10le_simd_dma( dma, pg, mtl_hp_virt2iova(st, pg), p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422be10_simd( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_2, w, h, back_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), + pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -131,91 +143,100 @@ static void test_cvt_rfc4175_422be10_to_yuv422p10le_dma(mtl_udma_handle dma, int } TEST(Cvt, rfc4175_422be10_to_yuv422p10le_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be10_to_yuv422p10le_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); } mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } -static void test_cvt_yuv422p10le_to_rfc4175_422be10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_yuv422p10le_to_rfc4175_422be10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p10_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p10_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p10_u16_2) st_test_free(p10_u16_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (p10_u16_2) + st_test_free(p10_u16_2); + if (p10_u16) + st_test_free(p10_u16); return; } @@ -223,12 +244,14 @@ static void test_cvt_yuv422p10le_to_rfc4175_422be10(int w, int h, p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - ret = st20_yuv422p10le_to_rfc4175_422be10_simd( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg, w, h, cvt_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), pg, + w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_yuv422p10le_simd( - pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, back_level); + pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, + back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p10_u16, p10_u16_2, planar_size)); @@ -265,8 +288,8 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512) { } TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_vbmi) { - test_cvt_yuv422p10le_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10( + 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_yuv422p10le_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_yuv422p10le_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_NONE, @@ -280,25 +303,29 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_vbmi) { } } -static void test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)mtl_hp_zmalloc(st, planar_size, MTL_PORT_P); + uint16_t *p10_u16 = (uint16_t *)mtl_hp_zmalloc(st, planar_size, MTL_PORT_P); mtl_iova_t p10_u16_iova = mtl_hp_virt2iova(st, p10_u16); - uint16_t* p10_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p10_u16_2) st_test_free(p10_u16_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (p10_u16_2) + st_test_free(p10_u16_2); + if (p10_u16) + st_test_free(p10_u16); return; } @@ -313,7 +340,8 @@ static void test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_yuv422p10le_simd( - pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, back_level); + pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, + back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p10_u16, p10_u16_2, planar_size)); @@ -324,103 +352,112 @@ static void test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int } TEST(Cvt, yuv422p10le_to_rfc4175_422be10_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } TEST(Cvt, yuv422p10le_to_rfc4175_422be10_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); mtl_udma_free(dma); } TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_NONE); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); } mtl_udma_free(dma); } TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_vbmi_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } -static void test_cvt_rfc4175_422le10_to_yuv422p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422le10_to_yuv422p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_le* pg = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_2 = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_2 = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p10_u16) + st_test_free(p10_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); ret = st20_rfc4175_422le10_to_yuv422p10le(pg, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422le10(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), pg_2, w, h); + ret = st20_yuv422p10le_to_rfc4175_422le10( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_2, w, h); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -440,22 +477,26 @@ TEST(Cvt, rfc4175_422le10_to_yuv422p10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_yuv422p10le_to_rfc4175_422le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_yuv422p10le_to_rfc4175_422le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_le* pg = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p10_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p10_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p10_u16_2) st_test_free(p10_u16_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (p10_u16_2) + st_test_free(p10_u16_2); + if (p10_u16) + st_test_free(p10_u16); return; } @@ -463,8 +504,8 @@ static void test_cvt_yuv422p10le_to_rfc4175_422le10(int w, int h, p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - ret = st20_yuv422p10le_to_rfc4175_422le10(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), pg, w, h); + ret = st20_yuv422p10le_to_rfc4175_422le10( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_yuv422p10le(pg, p10_u16_2, (p10_u16_2 + w * h), @@ -488,27 +529,30 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_422be10_to_422le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be10_to_422le10(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -524,7 +568,8 @@ static void test_cvt_rfc4175_422be10_to_422le10(int w, int h, } TEST(Cvt, rfc4175_422be10_to_422le10) { - test_cvt_rfc4175_422be10_to_422le10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le10(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_422le10_scalar) { @@ -535,12 +580,16 @@ TEST(Cvt, rfc4175_422be10_to_422le10_scalar) { TEST(Cvt, rfc4175_422be10_to_422le10_avx2) { test_cvt_rfc4175_422be10_to_422le10(1920, 1080, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, + MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_422le10(w, h, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422be10_to_422le10(w, h, MTL_SIMD_LEVEL_AVX2, + MTL_SIMD_LEVEL_AVX2); } } @@ -576,32 +625,37 @@ TEST(Cvt, rfc4175_422be10_to_422le10_avx512_vbmi) { } } -static void test_cvt_rfc4175_422be10_to_422le10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be10_to_422le10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, + MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) mtl_hp_free(st, pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + mtl_hp_free(st, pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), - pg_le, w, h, cvt_level); + ret = st20_rfc4175_422be10_to_422le10_simd_dma( + dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be_2, w, h, back_level); @@ -615,23 +669,25 @@ static void test_cvt_rfc4175_422be10_to_422le10_dma(mtl_udma_handle dma, int w, } TEST(Cvt, rfc4175_422be10_to_422le10_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le10_dma( + dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be10_to_422le10_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -639,13 +695,14 @@ TEST(Cvt, rfc4175_422be10_to_422le10_scalar_dma) { } TEST(Cvt, rfc4175_422be10_to_422le10_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_422le10_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, @@ -662,49 +719,54 @@ TEST(Cvt, rfc4175_422be10_to_422le10_avx512_dma) { } TEST(Cvt, rfc4175_422be10_to_422le10_avx512_vbmi_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_422le10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_422le10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le10_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } -static void test_cvt_rfc4175_422le10_to_422be10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422le10_to_422be10(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le_2 = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le_2 = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_le_2) st_test_free(pg_le_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_le_2) + st_test_free(pg_le_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -720,29 +782,34 @@ static void test_cvt_rfc4175_422le10_to_422be10(int w, int h, st_test_free(pg_le_2); } -static void test_cvt_rfc4175_422le10_to_422be10_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422le10_to_422be10_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -769,12 +836,16 @@ TEST(Cvt, rfc4175_422le10_to_422be10_scalar) { TEST(Cvt, rfc4175_422le10_to_422be10_avx2) { test_cvt_rfc4175_422le10_to_422be10(1920, 1080, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, + MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422le10_to_422be10(w, h, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422le10_to_422be10(w, h, MTL_SIMD_LEVEL_AVX2, + MTL_SIMD_LEVEL_AVX2); } } @@ -810,32 +881,37 @@ TEST(Cvt, rfc4175_422le10_to_422be10_vbmi) { } } -static void test_cvt_rfc4175_422le10_to_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422le10_to_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le_2 = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)mtl_hp_zmalloc(st, fb_pg2_size, + MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le_2 = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) mtl_hp_free(st, pg_le); - if (pg_le_2) st_test_free(pg_le_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + mtl_hp_free(st, pg_le); + if (pg_le_2) + st_test_free(pg_le_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le, mtl_hp_virt2iova(st, pg_le), - pg_be, w, h, cvt_level); + ret = st20_rfc4175_422le10_to_422be10_simd_dma( + dma, pg_le, mtl_hp_virt2iova(st, pg_le), pg_be, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le_2, w, h, back_level); @@ -849,23 +925,25 @@ static void test_cvt_rfc4175_422le10_to_422be10_dma(mtl_udma_handle dma, int w, } TEST(Cvt, rfc4175_422le10_to_422be10_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422le10_to_422be10_dma( + dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422le10_to_422be10_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -873,13 +951,14 @@ TEST(Cvt, rfc4175_422le10_to_422be10_scalar_dma) { } TEST(Cvt, rfc4175_422le10_to_422be10_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422le10_to_422be10_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, @@ -896,31 +975,33 @@ TEST(Cvt, rfc4175_422le10_to_422be10_avx512_dma) { } TEST(Cvt, rfc4175_422le10_to_422be10_avx512_vbmi_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422le10_to_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422le10_to_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422le10_to_422be10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422le10_to_422be10_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } static int test_cvt_extend_rfc4175_422le8_to_422be10( - int w, int h, struct st20_rfc4175_422_8_pg2_le* pg_8, - struct st20_rfc4175_422_10_pg2_be* pg_10) { + int w, int h, struct st20_rfc4175_422_8_pg2_le *pg_8, + struct st20_rfc4175_422_10_pg2_be *pg_10) { uint32_t cnt = w * h / 2; for (uint32_t i = 0; i < cnt; i++) { @@ -943,22 +1024,25 @@ static void test_cvt_rfc4175_422be10_to_422le8(int w, int h, int ret; size_t fb_pg2_size_10 = (size_t)w * h * 5 / 2; size_t fb_pg2_size_8 = (size_t)w * h * 2; - struct st20_rfc4175_422_10_pg2_be* pg_10 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size_10); - struct st20_rfc4175_422_8_pg2_le* pg_8 = - (struct st20_rfc4175_422_8_pg2_le*)st_test_zmalloc(fb_pg2_size_8); - struct st20_rfc4175_422_8_pg2_le* pg_8_2 = - (struct st20_rfc4175_422_8_pg2_le*)st_test_zmalloc(fb_pg2_size_8); + struct st20_rfc4175_422_10_pg2_be *pg_10 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size_10); + struct st20_rfc4175_422_8_pg2_le *pg_8 = + (struct st20_rfc4175_422_8_pg2_le *)st_test_zmalloc(fb_pg2_size_8); + struct st20_rfc4175_422_8_pg2_le *pg_8_2 = + (struct st20_rfc4175_422_8_pg2_le *)st_test_zmalloc(fb_pg2_size_8); if (!pg_10 || !pg_8 || !pg_8_2) { EXPECT_EQ(0, 1); - if (pg_10) st_test_free(pg_10); - if (pg_8) st_test_free(pg_8); - if (pg_8_2) st_test_free(pg_8_2); + if (pg_10) + st_test_free(pg_10); + if (pg_8) + st_test_free(pg_8); + if (pg_8_2) + st_test_free(pg_8_2); return; } - st_test_rand_data((uint8_t*)pg_8, fb_pg2_size_8, 0); + st_test_rand_data((uint8_t *)pg_8, fb_pg2_size_8, 0); test_cvt_extend_rfc4175_422le8_to_422be10(w, h, pg_8, pg_10); ret = st20_rfc4175_422be10_to_422le8_simd(pg_10, pg_8_2, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -971,7 +1055,8 @@ static void test_cvt_rfc4175_422be10_to_422le8(int w, int h, } TEST(Cvt, rfc4175_422be10_to_422le8) { - test_cvt_rfc4175_422be10_to_422le8(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le8(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_422le8_scalar) { @@ -1011,33 +1096,38 @@ TEST(Cvt, rfc4175_422be10_to_422le8_avx512_vbmi) { } } -static void test_cvt_rfc4175_422be10_to_422le8_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be10_to_422le8_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size_10 = (size_t)w * h * 5 / 2; size_t fb_pg2_size_8 = (size_t)w * h * 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_be* pg_10 = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_zmalloc(st, fb_pg2_size_10, MTL_PORT_P); - struct st20_rfc4175_422_8_pg2_le* pg_8 = - (struct st20_rfc4175_422_8_pg2_le*)st_test_zmalloc(fb_pg2_size_8); - struct st20_rfc4175_422_8_pg2_le* pg_8_2 = - (struct st20_rfc4175_422_8_pg2_le*)st_test_zmalloc(fb_pg2_size_8); + struct st20_rfc4175_422_10_pg2_be *pg_10 = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size_10, + MTL_PORT_P); + struct st20_rfc4175_422_8_pg2_le *pg_8 = + (struct st20_rfc4175_422_8_pg2_le *)st_test_zmalloc(fb_pg2_size_8); + struct st20_rfc4175_422_8_pg2_le *pg_8_2 = + (struct st20_rfc4175_422_8_pg2_le *)st_test_zmalloc(fb_pg2_size_8); if (!pg_10 || !pg_8 || !pg_8_2) { EXPECT_EQ(0, 1); - if (pg_10) mtl_hp_free(st, pg_10); - if (pg_8) st_test_free(pg_8); - if (pg_8_2) st_test_free(pg_8_2); + if (pg_10) + mtl_hp_free(st, pg_10); + if (pg_8) + st_test_free(pg_8); + if (pg_8_2) + st_test_free(pg_8_2); return; } - st_test_rand_data((uint8_t*)pg_8, fb_pg2_size_8, 0); + st_test_rand_data((uint8_t *)pg_8, fb_pg2_size_8, 0); test_cvt_extend_rfc4175_422le8_to_422be10(w, h, pg_8, pg_10); - ret = st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10, mtl_hp_virt2iova(st, pg_10), - pg_8_2, w, h, cvt_level); + ret = st20_rfc4175_422be10_to_422le8_simd_dma( + dma, pg_10, mtl_hp_virt2iova(st, pg_10), pg_8_2, w, h, cvt_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_8, pg_8_2, fb_pg2_size_8)); @@ -1048,23 +1138,25 @@ static void test_cvt_rfc4175_422be10_to_422le8_dma(mtl_udma_handle dma, int w, i } TEST(Cvt, rfc4175_422be10_to_422le8_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le8_dma( + dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be10_to_422le8_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -1072,10 +1164,11 @@ TEST(Cvt, rfc4175_422be10_to_422le8_scalar_dma) { } TEST(Cvt, rfc4175_422be10_to_422le8_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -1095,31 +1188,33 @@ TEST(Cvt, rfc4175_422be10_to_422le8_avx512_dma) { } TEST(Cvt, rfc4175_422be10_to_422le8_avx512_vbmi_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le8_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le8_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_422le8_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le8_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_422le8_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_422le8_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le8_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } static int test_cvt_extend_yuv422p8_to_rfc4175_422be10( - int w, int h, uint8_t* y, uint8_t* b, uint8_t* r, - struct st20_rfc4175_422_10_pg2_be* pg_10) { + int w, int h, uint8_t *y, uint8_t *b, uint8_t *r, + struct st20_rfc4175_422_10_pg2_be *pg_10) { uint32_t cnt = w * h / 2; for (uint32_t i = 0; i < cnt; i++) { @@ -1141,29 +1236,33 @@ static int test_cvt_extend_yuv422p8_to_rfc4175_422be10( return 0; } -static void test_cvt_rfc4175_422be10_to_yuv422p8(int w, int h, - enum mtl_simd_level cvt_level) { +static void +test_cvt_rfc4175_422be10_to_yuv422p8(int w, int h, + enum mtl_simd_level cvt_level) { int ret; size_t fb_pg2_size_10 = (size_t)w * h * 5 / 2; size_t fb_yuv422p8_size = (size_t)w * h * 2; - struct st20_rfc4175_422_10_pg2_be* pg_10 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size_10); - uint8_t* p8 = (uint8_t*)st_test_zmalloc(fb_yuv422p8_size); - uint8_t* p8_2 = (uint8_t*)st_test_zmalloc(fb_yuv422p8_size); + struct st20_rfc4175_422_10_pg2_be *pg_10 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size_10); + uint8_t *p8 = (uint8_t *)st_test_zmalloc(fb_yuv422p8_size); + uint8_t *p8_2 = (uint8_t *)st_test_zmalloc(fb_yuv422p8_size); if (!pg_10 || !p8 || !p8_2) { EXPECT_EQ(0, 1); - if (pg_10) st_test_free(pg_10); - if (p8) st_test_free(p8); - if (p8_2) st_test_free(p8_2); + if (pg_10) + st_test_free(pg_10); + if (p8) + st_test_free(p8); + if (p8_2) + st_test_free(p8_2); return; } st_test_rand_data(p8, fb_yuv422p8_size, 0); - test_cvt_extend_yuv422p8_to_rfc4175_422be10(w, h, p8, p8 + w * h, p8 + w * h * 3 / 2, - pg_10); - ret = st20_rfc4175_422be10_to_yuv422p8_simd(pg_10, p8_2, p8_2 + w * h, - p8_2 + w * h * 3 / 2, w, h, cvt_level); + test_cvt_extend_yuv422p8_to_rfc4175_422be10(w, h, p8, p8 + w * h, + p8 + w * h * 3 / 2, pg_10); + ret = st20_rfc4175_422be10_to_yuv422p8_simd( + pg_10, p8_2, p8_2 + w * h, p8_2 + w * h * 3 / 2, w, h, cvt_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p8, p8_2, fb_yuv422p8_size)); @@ -1212,25 +1311,29 @@ static void test_cvt_rfc4175_422be10_to_yuv420p8(int w, int h) { int ret; size_t fb_pg2_size_10 = (size_t)w * h * 5 / 2; size_t fb_yuv420p8_size = (size_t)w * h * 3 / 2; - struct st20_rfc4175_422_10_pg2_be* pg_10 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size_10); - uint8_t* p8 = (uint8_t*)st_test_zmalloc(fb_yuv420p8_size); - uint8_t* p8_2 = (uint8_t*)st_test_zmalloc(fb_yuv420p8_size); + struct st20_rfc4175_422_10_pg2_be *pg_10 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size_10); + uint8_t *p8 = (uint8_t *)st_test_zmalloc(fb_yuv420p8_size); + uint8_t *p8_2 = (uint8_t *)st_test_zmalloc(fb_yuv420p8_size); if (!pg_10 || !p8 || !p8_2) { EXPECT_EQ(0, 1); - if (pg_10) st_test_free(pg_10); - if (p8) st_test_free(p8); - if (p8_2) st_test_free(p8_2); + if (pg_10) + st_test_free(pg_10); + if (p8) + st_test_free(p8); + if (p8_2) + st_test_free(p8_2); return; } - st_test_rand_data((uint8_t*)pg_10, fb_pg2_size_10, 0); - ret = st20_rfc4175_422be10_to_yuv420p8_simd(pg_10, p8, p8 + w * h, p8 + w * h * 5 / 4, - w, h, MTL_SIMD_LEVEL_NONE); - EXPECT_EQ(0, ret); + st_test_rand_data((uint8_t *)pg_10, fb_pg2_size_10, 0); ret = st20_rfc4175_422be10_to_yuv420p8_simd( - pg_10, p8_2, p8_2 + w * h, p8_2 + w * h * 5 / 4, w, h, MTL_SIMD_LEVEL_AVX512); + pg_10, p8, p8 + w * h, p8 + w * h * 5 / 4, w, h, MTL_SIMD_LEVEL_NONE); + EXPECT_EQ(0, ret); + ret = st20_rfc4175_422be10_to_yuv420p8_simd(pg_10, p8_2, p8_2 + w * h, + p8_2 + w * h * 5 / 4, w, h, + MTL_SIMD_LEVEL_AVX512); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p8, p8_2, fb_yuv420p8_size)); @@ -1244,34 +1347,40 @@ TEST(Cvt, rfc4175_422be10_to_yuv420p8) { test_cvt_rfc4175_422be10_to_yuv420p8(1920, 1080); } -static void test_cvt_rfc4175_422le10_to_v210(int w, int h, enum mtl_simd_level cvt_level, +static void test_cvt_rfc4175_422le10_to_v210(int w, int h, + enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = + (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le_2 = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - uint8_t* pg_v210 = (uint8_t*)st_test_zmalloc(fb_pg2_size_v210); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le_2 = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + uint8_t *pg_v210 = (uint8_t *)st_test_zmalloc(fb_pg2_size_v210); if (!pg_le || !pg_le_2 || !pg_v210) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_le_2) st_test_free(pg_le_2); - if (pg_v210) st_test_free(pg_v210); + if (pg_le) + st_test_free(pg_le); + if (pg_le_2) + st_test_free(pg_le_2); + if (pg_v210) + st_test_free(pg_v210); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le10_to_v210_simd((uint8_t*)pg_le, pg_v210, w, h, cvt_level); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); + ret = st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le, pg_v210, w, h, + cvt_level); if (fail_case) EXPECT_NE(0, ret); else EXPECT_EQ(0, ret); - ret = st20_v210_to_rfc4175_422le10(pg_v210, (uint8_t*)pg_le_2, w, h); + ret = st20_v210_to_rfc4175_422le10(pg_v210, (uint8_t *)pg_le_2, w, h); if (fail_case) EXPECT_NE(0, ret); else @@ -1288,11 +1397,13 @@ static void test_cvt_rfc4175_422le10_to_v210(int w, int h, enum mtl_simd_level c } TEST(Cvt, rfc4175_422le10_to_v210) { - test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422le10_to_v210_scalar) { - test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rfc4175_422le10_to_v210_avx512) { @@ -1325,37 +1436,43 @@ TEST(Cvt, rfc4175_422le10_to_v210_avx512_vbmi) { MTL_SIMD_LEVEL_AVX512_VBMI2); } -static void test_cvt_rfc4175_422be10_to_v210(int w, int h, enum mtl_simd_level cvt_level, +static void test_cvt_rfc4175_422be10_to_v210(int w, int h, + enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = + (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - uint8_t* pg_v210 = (uint8_t*)st_test_zmalloc(fb_pg2_size_v210); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + uint8_t *pg_v210 = (uint8_t *)st_test_zmalloc(fb_pg2_size_v210); if (!pg_le || !pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (pg_v210) st_test_free(pg_v210); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (pg_v210) + st_test_free(pg_v210); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_v210_simd(pg_be, pg_v210, w, h, cvt_level); if (fail_case) EXPECT_NE(0, ret); else EXPECT_EQ(0, ret); - ret = st20_v210_to_rfc4175_422le10(pg_v210, (uint8_t*)pg_le, w, h); + ret = st20_v210_to_rfc4175_422le10(pg_v210, (uint8_t *)pg_le, w, h); if (fail_case) EXPECT_NE(0, ret); else @@ -1375,11 +1492,13 @@ static void test_cvt_rfc4175_422be10_to_v210(int w, int h, enum mtl_simd_level c } TEST(Cvt, rfc4175_422be10_to_v210) { - test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_v210_scalar) { - test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rfc4175_422be10_to_v210_avx512) { @@ -1412,41 +1531,48 @@ TEST(Cvt, rfc4175_422be10_to_v210_avx512_vbmi) { MTL_SIMD_LEVEL_AVX512_VBMI2); } -static void test_cvt_rfc4175_422be10_to_v210_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be10_to_v210_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; - bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = + (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); - uint8_t* pg_v210 = (uint8_t*)st_test_zmalloc(fb_pg2_size_v210); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, + MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); + uint8_t *pg_v210 = (uint8_t *)st_test_zmalloc(fb_pg2_size_v210); if (!pg_le || !pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) mtl_hp_free(st, pg_be); - if (pg_be_2) st_test_free(pg_be_2); - if (pg_v210) st_test_free(pg_v210); - if (pg_le) st_test_free(pg_le); + if (pg_be) + mtl_hp_free(st, pg_be); + if (pg_be_2) + st_test_free(pg_be_2); + if (pg_v210) + st_test_free(pg_v210); + if (pg_le) + st_test_free(pg_le); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), - pg_v210, w, h, cvt_level); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); + ret = st20_rfc4175_422be10_to_v210_simd_dma( + dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_v210, w, h, cvt_level); if (fail_case) EXPECT_NE(0, ret); else EXPECT_EQ(0, ret); - ret = st20_v210_to_rfc4175_422le10(pg_v210, (uint8_t*)pg_le, w, h); + ret = st20_v210_to_rfc4175_422le10(pg_v210, (uint8_t *)pg_le, w, h); if (fail_case) EXPECT_NE(0, ret); else @@ -1466,10 +1592,11 @@ static void test_cvt_rfc4175_422be10_to_v210_dma(mtl_udma_handle dma, int w, int } TEST(Cvt, rfc4175_422be10_to_v210_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -1478,10 +1605,11 @@ TEST(Cvt, rfc4175_422be10_to_v210_dma) { } TEST(Cvt, rfc4175_422be10_to_v210_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -1490,10 +1618,11 @@ TEST(Cvt, rfc4175_422be10_to_v210_scalar_dma) { } TEST(Cvt, rfc4175_422be10_to_v210_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -1512,48 +1641,57 @@ TEST(Cvt, rfc4175_422be10_to_v210_avx512_dma) { } TEST(Cvt, rfc4175_422be10_to_v210_avx512_vbmi_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); - test_cvt_rfc4175_422be10_to_v210_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_v210_dma(dma, 1921, 1079, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_v210_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_v210_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_v210_dma(dma, 1921, 1079, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); mtl_udma_free(dma); } -static void test_cvt_v210_to_rfc4175_422be10(int w, int h, enum mtl_simd_level cvt_level, +static void test_cvt_v210_to_rfc4175_422be10(int w, int h, + enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = + (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - uint8_t* pg_v210 = (uint8_t*)st_test_zmalloc(fb_pg2_size_v210); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + uint8_t *pg_v210 = (uint8_t *)st_test_zmalloc(fb_pg2_size_v210); if (!pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_v210) st_test_free(pg_v210); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_v210) + st_test_free(pg_v210); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_v210_simd(pg_be, pg_v210, w, h, cvt_level); if (fail_case) EXPECT_NE(0, ret); @@ -1578,11 +1716,13 @@ static void test_cvt_v210_to_rfc4175_422be10(int w, int h, enum mtl_simd_level c } TEST(Cvt, v210_to_rfc4175_422be10) { - test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, v210_to_rfc4175_422be10_scalar) { - test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } TEST(Cvt, v210_to_rfc4175_422be10_avx512) { @@ -1619,19 +1759,23 @@ static void test_cvt_v210_to_rfc4175_422be10_2(int w, int h, enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = + (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - uint8_t* pg_v210 = (uint8_t*)st_test_zmalloc(fb_pg2_size_v210); - uint8_t* pg_v210_2 = (uint8_t*)st_test_zmalloc(fb_pg2_size_v210); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + uint8_t *pg_v210 = (uint8_t *)st_test_zmalloc(fb_pg2_size_v210); + uint8_t *pg_v210_2 = (uint8_t *)st_test_zmalloc(fb_pg2_size_v210); if (!pg_be || !pg_v210 || !pg_v210_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_v210) st_test_free(pg_v210); - if (pg_v210_2) st_test_free(pg_v210_2); + if (pg_be) + st_test_free(pg_be); + if (pg_v210) + st_test_free(pg_v210); + if (pg_v210_2) + st_test_free(pg_v210_2); return; } @@ -1660,7 +1804,8 @@ static void test_cvt_v210_to_rfc4175_422be10_2(int w, int h, } TEST(Cvt, v210_to_rfc4175_422be10_2) { - test_cvt_v210_to_rfc4175_422be10_2(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_v210_to_rfc4175_422be10_2(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, v210_to_rfc4175_422be10_2_scalar) { @@ -1698,44 +1843,50 @@ TEST(Cvt, v210_to_rfc4175_422be10_2_vbmi) { MTL_SIMD_LEVEL_AVX512_VBMI2); } -static void test_cvt_v210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_v210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; - bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = + (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st_tests_context* ctx = st_test_ctx(); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - uint8_t* pg_v210 = (uint8_t*)mtl_hp_zmalloc(st, fb_pg2_size_v210, MTL_PORT_P); + uint8_t *pg_v210 = + (uint8_t *)mtl_hp_zmalloc(st, fb_pg2_size_v210, MTL_PORT_P); if (!pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_v210) mtl_hp_free(st, pg_v210); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_v210) + mtl_hp_free(st, pg_v210); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_v210_simd(pg_be, pg_v210, w, h, cvt_level); if (fail_case) EXPECT_NE(0, ret); else EXPECT_EQ(0, ret); - ret = st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210, mtl_hp_virt2iova(st, pg_v210), - pg_be_2, w, h, back_level); + ret = st20_v210_to_rfc4175_422be10_simd_dma( + dma, pg_v210, mtl_hp_virt2iova(st, pg_v210), pg_be_2, w, h, back_level); if (fail_case) EXPECT_NE(0, ret); else EXPECT_EQ(0, ret); - st_test_cmp((uint8_t*)pg_be, (uint8_t*)pg_be_2, fb_pg2_size); + st_test_cmp((uint8_t *)pg_be, (uint8_t *)pg_be_2, fb_pg2_size); if (fail_case) EXPECT_NE(0, memcmp(pg_be, pg_be_2, fb_pg2_size)); else @@ -1747,10 +1898,11 @@ static void test_cvt_v210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int } TEST(Cvt, v210_to_rfc4175_422be10_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -1759,10 +1911,11 @@ TEST(Cvt, v210_to_rfc4175_422be10_dma) { } TEST(Cvt, v210_to_rfc4175_422be10_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -1771,10 +1924,11 @@ TEST(Cvt, v210_to_rfc4175_422be10_scalar_dma) { } TEST(Cvt, v210_to_rfc4175_422be10_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -1793,47 +1947,55 @@ TEST(Cvt, v210_to_rfc4175_422be10_avx512_dma) { } TEST(Cvt, v210_to_rfc4175_422be10_vbmi_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); - test_cvt_v210_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_v210_to_rfc4175_422be10_dma(dma, 1921, 1079, MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_v210_to_rfc4175_422be10_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + test_cvt_v210_to_rfc4175_422be10_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_v210_to_rfc4175_422be10_dma(dma, 1921, 1079, + MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); mtl_udma_free(dma); } -static void test_cvt_rfc4175_422be10_to_y210(int w, int h, enum mtl_simd_level cvt_level, +static void test_cvt_rfc4175_422be10_to_y210(int w, int h, + enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_be* pg_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t fb_pg_y210_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* pg_y210 = (uint16_t*)st_test_zmalloc(fb_pg_y210_size); + uint16_t *pg_y210 = (uint16_t *)st_test_zmalloc(fb_pg_y210_size); if (!pg || !pg_2 || !pg_y210) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (pg_y210) st_test_free(pg_y210); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (pg_y210) + st_test_free(pg_y210); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_y210_simd(pg, pg_y210, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -1849,11 +2011,13 @@ static void test_cvt_rfc4175_422be10_to_y210(int w, int h, enum mtl_simd_level c } TEST(Cvt, rfc4175_422be10_to_y210) { - test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_y210_scalar) { - test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rfc4175_422be10_to_y210_avx512) { @@ -1861,40 +2025,48 @@ TEST(Cvt, rfc4175_422be10_to_y210_avx512) { MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_y210(w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_y210(w, h, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); } } -static void test_cvt_rfc4175_422be10_to_y210_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be10_to_y210_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; size_t fb_pg2_size_y210 = (size_t)w * h * 4; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - uint16_t* pg_y210 = (uint16_t*)st_test_zmalloc(fb_pg2_size_y210); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, + MTL_PORT_P); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + uint16_t *pg_y210 = (uint16_t *)st_test_zmalloc(fb_pg2_size_y210); if (!pg_be || !pg_y210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) mtl_hp_free(st, pg_be); - if (pg_be_2) st_test_free(pg_be_2); - if (pg_y210) st_test_free(pg_y210); + if (pg_be) + mtl_hp_free(st, pg_be); + if (pg_be_2) + st_test_free(pg_be_2); + if (pg_y210) + st_test_free(pg_y210); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_y210_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), - pg_y210, w, h, cvt_level); + ret = st20_rfc4175_422be10_to_y210_simd_dma( + dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_y210, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_y210_to_rfc4175_422be10(pg_y210, pg_be_2, w, h); @@ -1907,10 +2079,11 @@ static void test_cvt_rfc4175_422be10_to_y210_dma(mtl_udma_handle dma, int w, int } TEST(Cvt, rfc4175_422be10_to_y210_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_y210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -1919,10 +2092,11 @@ TEST(Cvt, rfc4175_422be10_to_y210_dma) { } TEST(Cvt, rfc4175_422be10_to_y210_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_y210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -1931,10 +2105,11 @@ TEST(Cvt, rfc4175_422be10_to_y210_scalar_dma) { } TEST(Cvt, rfc4175_422be10_to_y210_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be10_to_y210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -1953,21 +2128,25 @@ TEST(Cvt, rfc4175_422be10_to_y210_avx512_dma) { mtl_udma_free(dma); } -static void test_cvt_y210_to_rfc4175_422be10(int w, int h, enum mtl_simd_level cvt_level, +static void test_cvt_y210_to_rfc4175_422be10(int w, int h, + enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t fb_pg_y210_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* pg_y210 = (uint16_t*)st_test_zmalloc(fb_pg_y210_size); - uint16_t* pg_y210_2 = (uint16_t*)st_test_zmalloc(fb_pg_y210_size); + uint16_t *pg_y210 = (uint16_t *)st_test_zmalloc(fb_pg_y210_size); + uint16_t *pg_y210_2 = (uint16_t *)st_test_zmalloc(fb_pg_y210_size); if (!pg || !pg_y210_2 || !pg_y210) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_y210_2) st_test_free(pg_y210_2); - if (pg_y210) st_test_free(pg_y210); + if (pg) + st_test_free(pg); + if (pg_y210_2) + st_test_free(pg_y210_2); + if (pg_y210) + st_test_free(pg_y210); return; } @@ -1989,11 +2168,13 @@ static void test_cvt_y210_to_rfc4175_422be10(int w, int h, enum mtl_simd_level c } TEST(Cvt, y210_to_rfc4175_422be10) { - test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, y210_to_rfc4175_422be10_scalar) { - test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } TEST(Cvt, y210_to_rfc4175_422be10_avx512) { @@ -2001,33 +2182,41 @@ TEST(Cvt, y210_to_rfc4175_422be10_avx512) { MTL_SIMD_LEVEL_AVX512); test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); - test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); + test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512); + test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_y210_to_rfc4175_422be10(w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_y210_to_rfc4175_422be10(w, h, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); } } -static void test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t fb_pg_y210_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* pg_y210 = (uint16_t*)mtl_hp_zmalloc(st, fb_pg_y210_size, MTL_PORT_P); + uint16_t *pg_y210 = + (uint16_t *)mtl_hp_zmalloc(st, fb_pg_y210_size, MTL_PORT_P); mtl_iova_t pg_y210_iova = mtl_hp_virt2iova(st, pg_y210); - uint16_t* pg_y210_2 = (uint16_t*)st_test_zmalloc(fb_pg_y210_size); + uint16_t *pg_y210_2 = (uint16_t *)st_test_zmalloc(fb_pg_y210_size); if (!pg || !pg_y210_2 || !pg_y210) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_y210_2) st_test_free(pg_y210_2); - if (pg_y210) st_test_free(pg_y210); + if (pg) + st_test_free(pg); + if (pg_y210_2) + st_test_free(pg_y210_2); + if (pg_y210) + st_test_free(pg_y210); return; } @@ -2035,8 +2224,8 @@ static void test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int pg_y210[i] = rand() & 0xFFC0; /* only 10 bit */ } - ret = st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210, pg_y210_iova, pg, w, h, - cvt_level); + ret = st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210, pg_y210_iova, pg, w, + h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_y210_simd(pg, pg_y210_2, w, h, back_level); @@ -2050,10 +2239,11 @@ static void test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int } TEST(Cvt, y210_to_rfc4175_422be10_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_y210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -2062,10 +2252,11 @@ TEST(Cvt, y210_to_rfc4175_422be10_dma) { } TEST(Cvt, y210_to_rfc4175_422be10_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_y210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -2074,10 +2265,11 @@ TEST(Cvt, y210_to_rfc4175_422be10_scalar_dma) { } TEST(Cvt, y210_to_rfc4175_422be10_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_y210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -2097,29 +2289,33 @@ TEST(Cvt, y210_to_rfc4175_422be10_avx512_dma) { } static void test_rotate_rfc4175_422be10_422le10_yuv422p10le( - int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p10_u16) st_test_free(p10_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p10_u16) + st_test_free(p10_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le, w, h, cvt1_level); EXPECT_EQ(0, ret); @@ -2128,8 +2324,9 @@ static void test_rotate_rfc4175_422be10_422le10_yuv422p10le( (p10_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422be10_simd( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_be_2, w, h, cvt3_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), + pg_be_2, w, h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg2_size)); @@ -2142,59 +2339,70 @@ static void test_rotate_rfc4175_422be10_422le10_yuv422p10le( TEST(Cvt, rotate_rfc4175_422be10_422le10_yuv422p10le_avx512) { test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rotate_rfc4175_422be10_422le10_yuv422p10le_vbmi) { - test_rotate_rfc4175_422be10_422le10_yuv422p10le(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_rotate_rfc4175_422be10_422le10_yuv422p10le( + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512_VBMI2); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rotate_rfc4175_422be10_422le10_yuv422p10le_scalar) { test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } static void test_rotate_rfc4175_422be10_yuv422p10le_422le10( - int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; - struct st20_rfc4175_422_10_pg2_be* pg_be = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_10_pg2_le* pg_le = - (struct st20_rfc4175_422_10_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_be *pg_be = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_10_pg2_le *pg_le = + (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_422_10_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_10_pg2_be*)st_test_zmalloc(fb_pg2_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_422_10_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p10_u16) st_test_free(p10_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p10_u16) + st_test_free(p10_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_yuv422p10le_simd( - pg_be, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h, cvt1_level); + pg_be, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h, + cvt1_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422le10(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), pg_le, w, h); + ret = st20_yuv422p10le_to_rfc4175_422le10( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_le, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_422be10(pg_le, pg_be_2, w, h); @@ -2210,56 +2418,68 @@ static void test_rotate_rfc4175_422be10_yuv422p10le_422le10( TEST(Cvt, rotate_rfc4175_422be10_yuv422p10le_422le10_avx512) { test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_NONE); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512); } TEST(Cvt, rotate_rfc4175_422be10_yuv422p10le_422le10_vbmi) { - test_rotate_rfc4175_422be10_yuv422p10le_422le10(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); + test_rotate_rfc4175_422be10_yuv422p10le_422le10( + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512_VBMI2); } TEST(Cvt, rotate_rfc4175_422be10_yuv422p10le_422le10_scalar) { test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_422be12_to_yuv422p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be12_to_yuv422p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_be* pg = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_be* pg_2 = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_2 = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p12_u16) + st_test_free(p12_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); - ret = st20_rfc4175_422be12_to_yuv422p12le_simd( - pg, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h, cvt_level); + ret = st20_rfc4175_422be12_to_yuv422p12le_simd(pg, p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), w, + h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422be12_simd( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_2, w, h, back_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), + pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -2296,8 +2516,8 @@ TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512) { } TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512_vbmi) { - test_cvt_rfc4175_422be12_to_yuv422p12le(1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be12_to_yuv422p12le( + 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be12_to_yuv422p12le(722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be12_to_yuv422p12le(722, 111, MTL_SIMD_LEVEL_NONE, @@ -2311,37 +2531,43 @@ TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512_vbmi) { } } -static void test_cvt_rfc4175_422be12_to_yuv422p12le_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be12_to_yuv422p12le_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_12_pg2_be* pg = - (struct st20_rfc4175_422_12_pg2_be*)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); - struct st20_rfc4175_422_12_pg2_be* pg_2 = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg = + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, + MTL_PORT_P); + struct st20_rfc4175_422_12_pg2_be *pg_2 = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) mtl_hp_free(st, pg); - if (pg_2) st_test_free(pg_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + mtl_hp_free(st, pg); + if (pg_2) + st_test_free(pg_2); + if (p12_u16) + st_test_free(p12_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); ret = st20_rfc4175_422be12_to_yuv422p12le_simd_dma( dma, pg, mtl_hp_virt2iova(st, pg), p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422be12_simd( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_2, w, h, back_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), + pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -2352,68 +2578,75 @@ static void test_cvt_rfc4175_422be12_to_yuv422p12le_dma(mtl_udma_handle dma, int } TEST(Cvt, rfc4175_422be12_to_yuv422p12le_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be12_to_yuv422p12le_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma( + dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma( + dma, w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); } mtl_udma_free(dma); } -static void test_cvt_yuv422p12le_to_rfc4175_422be12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_yuv422p12le_to_rfc4175_422be12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_be* pg = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p12_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p12_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p12_u16_2) st_test_free(p12_u16_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (p12_u16_2) + st_test_free(p12_u16_2); + if (p12_u16) + st_test_free(p12_u16); return; } @@ -2421,12 +2654,14 @@ static void test_cvt_yuv422p12le_to_rfc4175_422be12(int w, int h, p12_u16[i] = rand() & 0xfff; /* only 12 bit */ } - ret = st20_yuv422p12le_to_rfc4175_422be12_simd( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg, w, h, cvt_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), pg, + w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be12_to_yuv422p12le_simd( - pg, p12_u16_2, (p12_u16_2 + w * h), (p12_u16_2 + w * h * 3 / 2), w, h, back_level); + pg, p12_u16_2, (p12_u16_2 + w * h), (p12_u16_2 + w * h * 3 / 2), w, h, + back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p12_u16, p12_u16_2, planar_size)); @@ -2446,34 +2681,38 @@ TEST(Cvt, yuv422p12le_to_rfc4175_422be12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_422le12_to_yuv422p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422le12_to_yuv422p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_le* pg = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_le* pg_2 = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg_2 = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p12_u16) + st_test_free(p12_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); ret = st20_rfc4175_422le12_to_yuv422p12le(pg, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422le12(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), pg_2, w, h); + ret = st20_yuv422p12le_to_rfc4175_422le12( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_2, w, h); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -2493,22 +2732,26 @@ TEST(Cvt, rfc4175_422le12_to_yuv422p12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_yuv422p12le_to_rfc4175_422le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_yuv422p12le_to_rfc4175_422le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_le* pg = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p12_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p12_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p12_u16_2) st_test_free(p12_u16_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (p12_u16_2) + st_test_free(p12_u16_2); + if (p12_u16) + st_test_free(p12_u16); return; } @@ -2516,8 +2759,8 @@ static void test_cvt_yuv422p12le_to_rfc4175_422le12(int w, int h, p12_u16[i] = rand() & 0xfff; /* only 12 bit */ } - ret = st20_yuv422p12le_to_rfc4175_422le12(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), pg, w, h); + ret = st20_yuv422p12le_to_rfc4175_422le12( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_yuv422p12le(pg, p12_u16_2, (p12_u16_2 + w * h), @@ -2541,27 +2784,30 @@ TEST(Cvt, yuv422p12le_to_rfc4175_422le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_422be12_to_422le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be12_to_422le12(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_le* pg_le = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg_le = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be12_to_422le12_simd(pg_be, pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -2577,7 +2823,8 @@ static void test_cvt_rfc4175_422be12_to_422le12(int w, int h, } TEST(Cvt, rfc4175_422be12_to_422le12) { - test_cvt_rfc4175_422be12_to_422le12(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be12_to_422le12(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be12_to_422le12_scalar) { @@ -2601,32 +2848,37 @@ TEST(Cvt, rfc4175_422be12_to_422le12_avx512) { } } -static void test_cvt_rfc4175_422be12_to_422le12_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422be12_to_422le12_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); - struct st20_rfc4175_422_12_pg2_le* pg_le = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, + MTL_PORT_P); + struct st20_rfc4175_422_12_pg2_le *pg_le = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) mtl_hp_free(st, pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + mtl_hp_free(st, pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be12_to_422le12_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), - pg_le, w, h, cvt_level); + ret = st20_rfc4175_422be12_to_422le12_simd_dma( + dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be_2, w, h, back_level); @@ -2640,23 +2892,25 @@ static void test_cvt_rfc4175_422be12_to_422le12_dma(mtl_udma_handle dma, int w, } TEST(Cvt, rfc4175_422be12_to_422le12_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be12_to_422le12_dma( + dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } TEST(Cvt, rfc4175_422be12_to_422le12_scalar_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -2664,13 +2918,14 @@ TEST(Cvt, rfc4175_422be12_to_422le12_scalar_dma) { } TEST(Cvt, rfc4175_422be12_to_422le12_avx512_dma) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) return; + if (!dma) + return; - test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_422le12_dma( + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be12_to_422le12_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be12_to_422le12_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, @@ -2686,27 +2941,30 @@ TEST(Cvt, rfc4175_422be12_to_422le12_avx512_dma) { mtl_udma_free(dma); } -static void test_cvt_rfc4175_422le12_to_422be12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422le12_to_422be12(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_le* pg_le = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_le* pg_le_2 = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg_le = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg_le_2 = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_le_2) st_test_free(pg_le_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_le_2) + st_test_free(pg_le_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -2722,29 +2980,34 @@ static void test_cvt_rfc4175_422le12_to_422be12(int w, int h, st_test_free(pg_le_2); } -static void test_cvt_rfc4175_422le12_to_422be12_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_422le12_to_422be12_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_le* pg_le = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg_le = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -2769,29 +3032,33 @@ TEST(Cvt, rfc4175_422le12_to_422be12_scalar) { } static void test_rotate_rfc4175_422be12_422le12_yuv422p12le( - int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_le* pg_le = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg_le = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_422_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_422_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p12_u16) st_test_free(p12_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p12_u16) + st_test_free(p12_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be12_to_422le12_simd(pg_be, pg_le, w, h, cvt1_level); EXPECT_EQ(0, ret); @@ -2800,8 +3067,9 @@ static void test_rotate_rfc4175_422be12_422le12_yuv422p12le( (p12_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422be12_simd( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_be_2, w, h, cvt3_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), + pg_be_2, w, h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg2_size)); @@ -2814,40 +3082,46 @@ static void test_rotate_rfc4175_422be12_422le12_yuv422p12le( TEST(Cvt, rotate_rfc4175_422be12_422le12_yuv422p12le_scalar) { test_rotate_rfc4175_422be12_422le12_yuv422p12le( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } static void test_rotate_rfc4175_422be12_yuv422p12le_422le12( - int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; - struct st20_rfc4175_422_12_pg2_be* pg_be = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_422_12_pg2_le* pg_le = - (struct st20_rfc4175_422_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_be *pg_be = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_422_12_pg2_le *pg_le = + (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_422_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_422_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_422_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p12_u16) st_test_free(p12_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p12_u16) + st_test_free(p12_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be12_to_yuv422p12le_simd( - pg_be, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h, cvt1_level); + pg_be, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h, + cvt1_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422le12(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), pg_le, w, h); + ret = st20_yuv422p12le_to_rfc4175_422le12( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_le, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_422be12(pg_le, pg_be_2, w, h); @@ -2863,37 +3137,43 @@ static void test_rotate_rfc4175_422be12_yuv422p12le_422le12( TEST(Cvt, rotate_rfc4175_422be12_yuv422p12le_422le12_scalar) { test_rotate_rfc4175_422be12_yuv422p12le_422le12( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444be10_to_444p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444be10_to_444p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_be* pg = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_be* pg_2 = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_2 = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p10_u16) + st_test_free(p10_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg4_size, 0); - ret = st20_rfc4175_444be10_to_444p10le_simd(pg, p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 2), w, h, cvt_level); + ret = st20_rfc4175_444be10_to_444p10le_simd( + pg, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_444p10le_to_rfc4175_444be10_simd( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), pg_2, w, h, back_level); + ret = st20_444p10le_to_rfc4175_444be10_simd(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 2), pg_2, w, h, + back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg4_size)); @@ -2913,22 +3193,26 @@ TEST(Cvt, rfc4175_444be10_to_444p10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_444p10le_to_rfc4175_444be10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_444p10le_to_rfc4175_444be10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_be* pg = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p10_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p10_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p10_u16_2) st_test_free(p10_u16_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (p10_u16_2) + st_test_free(p10_u16_2); + if (p10_u16) + st_test_free(p10_u16); return; } @@ -2936,12 +3220,13 @@ static void test_cvt_444p10le_to_rfc4175_444be10(int w, int h, p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - ret = st20_444p10le_to_rfc4175_444be10_simd(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 2), pg, w, h, cvt_level); + ret = st20_444p10le_to_rfc4175_444be10_simd( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), pg, w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_rfc4175_444be10_to_444p10le_simd(pg, p10_u16_2, (p10_u16_2 + w * h), - (p10_u16_2 + w * h * 2), w, h, back_level); + ret = st20_rfc4175_444be10_to_444p10le_simd( + pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 2), w, h, + back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p10_u16, p10_u16_2, planar_size)); @@ -2961,27 +3246,31 @@ TEST(Cvt, 444p10le_to_rfc4175_444be10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444le10_to_yuv444p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le10_to_yuv444p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_le* pg = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_le* pg_2 = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_2 = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p10_u16) + st_test_free(p10_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg4_size, 0); ret = st20_rfc4175_444le10_to_yuv444p10le(pg, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), w, h); @@ -3008,27 +3297,31 @@ TEST(Cvt, rfc4175_444le10_to_yuv444p10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444le10_to_gbrp10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le10_to_gbrp10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_le* pg = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_le* pg_2 = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_2 = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p10_u16) + st_test_free(p10_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg4_size, 0); ret = st20_rfc4175_444le10_to_gbrp10le(pg, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), w, h); @@ -3055,22 +3348,26 @@ TEST(Cvt, rfc4175_444le10_to_gbrp10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_yuv444p10le_to_rfc4175_444le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_yuv444p10le_to_rfc4175_444le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_le* pg = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p10_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p10_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p10_u16_2) st_test_free(p10_u16_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (p10_u16_2) + st_test_free(p10_u16_2); + if (p10_u16) + st_test_free(p10_u16); return; } @@ -3103,22 +3400,26 @@ TEST(Cvt, yuv444p10le_to_rfc4175_444le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_gbrp10le_to_rfc4175_444le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_gbrp10le_to_rfc4175_444le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_le* pg = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p10_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p10_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p10_u16_2) st_test_free(p10_u16_2); - if (p10_u16) st_test_free(p10_u16); + if (pg) + st_test_free(pg); + if (p10_u16_2) + st_test_free(p10_u16_2); + if (p10_u16) + st_test_free(p10_u16); return; } @@ -3151,27 +3452,30 @@ TEST(Cvt, gbrp10le_to_rfc4175_444le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444be10_to_444le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444be10_to_444le10(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_be* pg_be = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_le* pg_le = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_be* pg_be_2 = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_be = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_le = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_be_2 = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg4_size, 0); ret = st20_rfc4175_444be10_to_444le10_simd(pg_be, pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -3187,7 +3491,8 @@ static void test_cvt_rfc4175_444be10_to_444le10(int w, int h, } TEST(Cvt, rfc4175_444be10_to_444le10) { - test_cvt_rfc4175_444be10_to_444le10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_444be10_to_444le10(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_444be10_to_444le10_scalar) { @@ -3195,27 +3500,30 @@ TEST(Cvt, rfc4175_444be10_to_444le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444le10_to_444be10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le10_to_444be10(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_le* pg_le = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_be* pg_be = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_le* pg_le_2 = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_le = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_be = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_le_2 = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_le_2) st_test_free(pg_le_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_le_2) + st_test_free(pg_le_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg4_size, 0); ret = st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -3230,29 +3538,34 @@ static void test_cvt_rfc4175_444le10_to_444be10(int w, int h, st_test_free(pg_le_2); } -static void test_cvt_rfc4175_444le10_to_444be10_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le10_to_444be10_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_le* pg_le = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_be* pg_be = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_be* pg_be_2 = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_le = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_be = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_be_2 = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg4_size, 0); - ret = st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -3275,31 +3588,34 @@ TEST(Cvt, rfc4175_444le10_to_444be10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be10_444le10_444p10le(int w, int h, - enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be10_444le10_444p10le( + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_be* pg_be = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_le* pg_le = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_be = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_le = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_444_10_pg4_be* pg_be_2 = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_444_10_pg4_be *pg_be_2 = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p10_u16) st_test_free(p10_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p10_u16) + st_test_free(p10_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg4_size, 0); ret = st20_rfc4175_444be10_to_444le10_simd(pg_be, pg_le, w, h, cvt1_level); EXPECT_EQ(0, ret); @@ -3308,8 +3624,9 @@ static void test_rotate_rfc4175_444be10_444le10_444p10le(int w, int h, (p10_u16 + w * h * 2), w, h); EXPECT_EQ(0, ret); - ret = st20_444p10le_to_rfc4175_444be10_simd( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), pg_be_2, w, h, cvt3_level); + ret = st20_444p10le_to_rfc4175_444be10_simd(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 2), pg_be_2, w, + h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg4_size)); @@ -3322,37 +3639,42 @@ static void test_rotate_rfc4175_444be10_444le10_444p10le(int w, int h, TEST(Cvt, rotate_rfc4175_444be10_444le10_444p10le_scalar) { test_rotate_rfc4175_444be10_444le10_444p10le(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be10_444p10le_444le10(int w, int h, - enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be10_444p10le_444le10( + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; - struct st20_rfc4175_444_10_pg4_be* pg_be = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); - struct st20_rfc4175_444_10_pg4_le* pg_le = - (struct st20_rfc4175_444_10_pg4_le*)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_be *pg_be = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); + struct st20_rfc4175_444_10_pg4_le *pg_le = + (struct st20_rfc4175_444_10_pg4_le *)st_test_zmalloc(fb_pg4_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p10_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_444_10_pg4_be* pg_be_2 = - (struct st20_rfc4175_444_10_pg4_be*)st_test_zmalloc(fb_pg4_size); + uint16_t *p10_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_444_10_pg4_be *pg_be_2 = + (struct st20_rfc4175_444_10_pg4_be *)st_test_zmalloc(fb_pg4_size); if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p10_u16) st_test_free(p10_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p10_u16) + st_test_free(p10_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg4_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg4_size, 0); ret = st20_rfc4175_444be10_to_444p10le_simd(pg_be, p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 2), w, h, cvt1_level); + (p10_u16 + w * h * 2), w, h, + cvt1_level); EXPECT_EQ(0, ret); ret = st20_444p10le_to_rfc4175_444le10(p10_u16, (p10_u16 + w * h), @@ -3372,37 +3694,43 @@ static void test_rotate_rfc4175_444be10_444p10le_444le10(int w, int h, TEST(Cvt, rotate_rfc4175_444be10_444p10le_444le10_scalar) { test_rotate_rfc4175_444be10_444p10le_444le10(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444be12_to_444p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444be12_to_444p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_be* pg = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_be* pg_2 = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_2 = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p12_u16) + st_test_free(p12_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); - ret = st20_rfc4175_444be12_to_444p12le_simd(pg, p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 2), w, h, cvt_level); + ret = st20_rfc4175_444be12_to_444p12le_simd( + pg, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_444p12le_to_rfc4175_444be12_simd( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), pg_2, w, h, back_level); + ret = st20_444p12le_to_rfc4175_444be12_simd(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 2), pg_2, w, h, + back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -3422,22 +3750,26 @@ TEST(Cvt, rfc4175_444be12_to_444p12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_444p12le_to_rfc4175_444be12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_444p12le_to_rfc4175_444be12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_be* pg = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p12_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p12_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p12_u16_2) st_test_free(p12_u16_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (p12_u16_2) + st_test_free(p12_u16_2); + if (p12_u16) + st_test_free(p12_u16); return; } @@ -3445,12 +3777,13 @@ static void test_cvt_444p12le_to_rfc4175_444be12(int w, int h, p12_u16[i] = rand() & 0xfff; /* only 12 bit */ } - ret = st20_444p12le_to_rfc4175_444be12_simd(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 2), pg, w, h, cvt_level); + ret = st20_444p12le_to_rfc4175_444be12_simd( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), pg, w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_rfc4175_444be12_to_444p12le_simd(pg, p12_u16_2, (p12_u16_2 + w * h), - (p12_u16_2 + w * h * 2), w, h, back_level); + ret = st20_rfc4175_444be12_to_444p12le_simd( + pg, p12_u16_2, (p12_u16_2 + w * h), (p12_u16_2 + w * h * 2), w, h, + back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p12_u16, p12_u16_2, planar_size)); @@ -3470,27 +3803,31 @@ TEST(Cvt, 444p12le_to_rfc4175_444be12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444le12_to_yuv444p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le12_to_yuv444p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_le* pg = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_le* pg_2 = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_2 = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p12_u16) + st_test_free(p12_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); ret = st20_rfc4175_444le12_to_yuv444p12le(pg, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), w, h); @@ -3517,27 +3854,31 @@ TEST(Cvt, rfc4175_444le12_to_yuv444p12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444le12_to_gbrp12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le12_to_gbrp12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_le* pg = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_le* pg_2 = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_2 = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (pg_2) st_test_free(pg_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (pg_2) + st_test_free(pg_2); + if (p12_u16) + st_test_free(p12_u16); return; } - st_test_rand_data((uint8_t*)pg, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); ret = st20_rfc4175_444le12_to_gbrp12le(pg, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), w, h); @@ -3564,22 +3905,26 @@ TEST(Cvt, rfc4175_444le12_to_gbrp12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_yuv444p12le_to_rfc4175_444le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_yuv444p12le_to_rfc4175_444le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_le* pg = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p12_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p12_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p12_u16_2) st_test_free(p12_u16_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (p12_u16_2) + st_test_free(p12_u16_2); + if (p12_u16) + st_test_free(p12_u16); return; } @@ -3612,22 +3957,26 @@ TEST(Cvt, yuv444p12le_to_rfc4175_444le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_gbrp12le_to_rfc4175_444le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_gbrp12le_to_rfc4175_444le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_le* pg = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - uint16_t* p12_u16_2 = (uint16_t*)st_test_zmalloc(planar_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + uint16_t *p12_u16_2 = (uint16_t *)st_test_zmalloc(planar_size); if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) st_test_free(pg); - if (p12_u16_2) st_test_free(p12_u16_2); - if (p12_u16) st_test_free(p12_u16); + if (pg) + st_test_free(pg); + if (p12_u16_2) + st_test_free(p12_u16_2); + if (p12_u16) + st_test_free(p12_u16); return; } @@ -3660,27 +4009,30 @@ TEST(Cvt, gbrp12le_to_rfc4175_444le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444be12_to_444le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444be12_to_444le12(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_be* pg_be = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_le* pg_le = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_be = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_le = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_444be12_to_444le12_simd(pg_be, pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -3696,7 +4048,8 @@ static void test_cvt_rfc4175_444be12_to_444le12(int w, int h, } TEST(Cvt, rfc4175_444be12_to_444le12) { - test_cvt_rfc4175_444be12_to_444le12(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_444be12_to_444le12(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_444be12_to_444le12_scalar) { @@ -3704,27 +4057,30 @@ TEST(Cvt, rfc4175_444be12_to_444le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_cvt_rfc4175_444le12_to_444be12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le12_to_444be12(int w, int h, enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_le* pg_le = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_be* pg_be = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_le* pg_le_2 = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_le = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_be = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_le_2 = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_le_2) st_test_free(pg_le_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_le_2) + st_test_free(pg_le_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); ret = st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, cvt_level); EXPECT_EQ(0, ret); @@ -3739,29 +4095,34 @@ static void test_cvt_rfc4175_444le12_to_444be12(int w, int h, st_test_free(pg_le_2); } -static void test_cvt_rfc4175_444le12_to_444be12_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void +test_cvt_rfc4175_444le12_to_444be12_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_le* pg_le = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_be* pg_be = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_le = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_be = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) st_test_free(pg_be); - if (pg_le) st_test_free(pg_le); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_be) + st_test_free(pg_be); + if (pg_le) + st_test_free(pg_le); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_le, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, + MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -3784,31 +4145,34 @@ TEST(Cvt, rfc4175_444le12_to_444be12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be12_444le12_444p12le(int w, int h, - enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be12_444le12_444p12le( + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_be* pg_be = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_le* pg_le = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_be = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_le = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_444_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_444_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p12_u16) st_test_free(p12_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p12_u16) + st_test_free(p12_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_444be12_to_444le12_simd(pg_be, pg_le, w, h, cvt1_level); EXPECT_EQ(0, ret); @@ -3817,8 +4181,9 @@ static void test_rotate_rfc4175_444be12_444le12_444p12le(int w, int h, (p12_u16 + w * h * 2), w, h); EXPECT_EQ(0, ret); - ret = st20_444p12le_to_rfc4175_444be12_simd( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), pg_be_2, w, h, cvt3_level); + ret = st20_444p12le_to_rfc4175_444be12_simd(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 2), pg_be_2, w, + h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg2_size)); @@ -3831,37 +4196,42 @@ static void test_rotate_rfc4175_444be12_444le12_444p12le(int w, int h, TEST(Cvt, rotate_rfc4175_444be12_444le12_444p12le_scalar) { test_rotate_rfc4175_444be12_444le12_444p12le(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be12_444p12le_444le12(int w, int h, - enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, - enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be12_444p12le_444le12( + int w, int h, enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; - struct st20_rfc4175_444_12_pg2_be* pg_be = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); - struct st20_rfc4175_444_12_pg2_le* pg_le = - (struct st20_rfc4175_444_12_pg2_le*)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_be *pg_be = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); + struct st20_rfc4175_444_12_pg2_le *pg_le = + (struct st20_rfc4175_444_12_pg2_le *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 3 * sizeof(uint16_t); - uint16_t* p12_u16 = (uint16_t*)st_test_zmalloc(planar_size); - struct st20_rfc4175_444_12_pg2_be* pg_be_2 = - (struct st20_rfc4175_444_12_pg2_be*)st_test_zmalloc(fb_pg2_size); + uint16_t *p12_u16 = (uint16_t *)st_test_zmalloc(planar_size); + struct st20_rfc4175_444_12_pg2_be *pg_be_2 = + (struct st20_rfc4175_444_12_pg2_be *)st_test_zmalloc(fb_pg2_size); if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) st_test_free(pg_le); - if (pg_be) st_test_free(pg_be); - if (p12_u16) st_test_free(p12_u16); - if (pg_be_2) st_test_free(pg_be_2); + if (pg_le) + st_test_free(pg_le); + if (pg_be) + st_test_free(pg_be); + if (p12_u16) + st_test_free(p12_u16); + if (pg_be_2) + st_test_free(pg_be_2); return; } - st_test_rand_data((uint8_t*)pg_be, fb_pg2_size, 0); + st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_444be12_to_444p12le_simd(pg_be, p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 2), w, h, cvt1_level); + (p12_u16 + w * h * 2), w, h, + cvt1_level); EXPECT_EQ(0, ret); ret = st20_444p12le_to_rfc4175_444le12(p12_u16, (p12_u16 + w * h), @@ -3881,27 +4251,33 @@ static void test_rotate_rfc4175_444be12_444p12le_444le12(int w, int h, TEST(Cvt, rotate_rfc4175_444be12_444p12le_444le12_scalar) { test_rotate_rfc4175_444be12_444p12le_444le12(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); } static void test_am824_to_aes3(int blocks) { int ret; int subframes = blocks * 2 * 192; size_t blocks_size = subframes * 4; - struct st31_aes3* b_aes3 = (struct st31_aes3*)st_test_zmalloc(blocks_size); - struct st31_am824* b_am824 = (struct st31_am824*)st_test_zmalloc(blocks_size); - struct st31_am824* b_am824_2 = (struct st31_am824*)st_test_zmalloc(blocks_size); + struct st31_aes3 *b_aes3 = (struct st31_aes3 *)st_test_zmalloc(blocks_size); + struct st31_am824 *b_am824 = + (struct st31_am824 *)st_test_zmalloc(blocks_size); + struct st31_am824 *b_am824_2 = + (struct st31_am824 *)st_test_zmalloc(blocks_size); if (!b_aes3 || !b_am824 || !b_am824_2) { EXPECT_EQ(0, 1); - if (b_aes3) st_test_free(b_aes3); - if (b_am824) st_test_free(b_am824); - if (b_am824_2) st_test_free(b_am824_2); + if (b_aes3) + st_test_free(b_aes3); + if (b_am824) + st_test_free(b_am824); + if (b_am824_2) + st_test_free(b_am824_2); return; } - st_test_rand_data((uint8_t*)b_am824, blocks_size, 0); + st_test_rand_data((uint8_t *)b_am824, blocks_size, 0); /* set 'b' and 'f' for subframes */ - struct st31_am824* sf_am824 = b_am824; + struct st31_am824 *sf_am824 = b_am824; for (int i = 0; i < subframes; i++) { sf_am824->unused = 0; if (i % (192 * 2) == 0) { @@ -3940,20 +4316,24 @@ static void test_aes3_to_am824(int blocks) { int ret; int subframes = blocks * 2 * 192; size_t blocks_size = subframes * 4; - struct st31_aes3* b_aes3 = (struct st31_aes3*)st_test_zmalloc(blocks_size); - struct st31_am824* b_am824 = (struct st31_am824*)st_test_zmalloc(blocks_size); - struct st31_aes3* b_aes3_2 = (struct st31_aes3*)st_test_zmalloc(blocks_size); + struct st31_aes3 *b_aes3 = (struct st31_aes3 *)st_test_zmalloc(blocks_size); + struct st31_am824 *b_am824 = + (struct st31_am824 *)st_test_zmalloc(blocks_size); + struct st31_aes3 *b_aes3_2 = (struct st31_aes3 *)st_test_zmalloc(blocks_size); if (!b_aes3 || !b_am824 || !b_aes3_2) { EXPECT_EQ(0, 1); - if (b_aes3) st_test_free(b_aes3); - if (b_am824) st_test_free(b_am824); - if (b_aes3_2) st_test_free(b_aes3_2); + if (b_aes3) + st_test_free(b_aes3); + if (b_am824) + st_test_free(b_am824); + if (b_aes3_2) + st_test_free(b_aes3_2); return; } - st_test_rand_data((uint8_t*)b_am824, blocks_size, 0); + st_test_rand_data((uint8_t *)b_am824, blocks_size, 0); /* set 'b' and 'f' for subframes */ - struct st31_aes3* sf_aes3 = b_aes3; + struct st31_aes3 *sf_aes3 = b_aes3; for (int i = 0; i < subframes; i++) { if (i % (192 * 2) == 0) { sf_aes3->preamble = 0x2; @@ -3984,32 +4364,35 @@ TEST(Cvt, st31_aes3_to_am824) { test_aes3_to_am824(100); } -static void frame_malloc(struct st_frame* frame, uint8_t rand, bool align) { +static void frame_malloc(struct st_frame *frame, uint8_t rand, bool align) { int planes = st_frame_fmt_planes(frame->fmt); size_t fb_size = 0; for (int plane = 0; plane < planes; plane++) { - size_t least_line_size = st_frame_least_linesize(frame->fmt, frame->width, plane); - frame->linesize[plane] = align ? MTL_ALIGN(least_line_size, 512) : least_line_size; + size_t least_line_size = + st_frame_least_linesize(frame->fmt, frame->width, plane); + frame->linesize[plane] = + align ? MTL_ALIGN(least_line_size, 512) : least_line_size; fb_size += frame->linesize[plane] * frame->height; } - uint8_t* fb = (uint8_t*)st_test_zmalloc(fb_size); - if (!fb) return; + uint8_t *fb = (uint8_t *)st_test_zmalloc(fb_size); + if (!fb) + return; if (rand) { /* fill the framebuffer */ st_test_rand_data(fb, fb_size, rand); if (frame->fmt == ST_FRAME_FMT_YUV422PLANAR10LE) { /* only LSB 10 valid */ - uint16_t* p10_u16 = (uint16_t*)fb; + uint16_t *p10_u16 = (uint16_t *)fb; for (size_t j = 0; j < (fb_size / 2); j++) { p10_u16[j] &= 0x3ff; /* only 10 bit */ } } else if (frame->fmt == ST_FRAME_FMT_Y210) { /* only MSB 10 valid */ - uint16_t* y210_u16 = (uint16_t*)fb; + uint16_t *y210_u16 = (uint16_t *)fb; for (size_t j = 0; j < (fb_size / 2); j++) { y210_u16[j] &= 0xffc0; /* only 10 bit */ } } else if (frame->fmt == ST_FRAME_FMT_V210) { - uint32_t* v210_word = (uint32_t*)fb; + uint32_t *v210_word = (uint32_t *)fb; for (size_t j = 0; j < (fb_size / 4); j++) { v210_word[j] &= 0x3fffffff; /* only 30 bit */ } @@ -4017,34 +4400,36 @@ static void frame_malloc(struct st_frame* frame, uint8_t rand, bool align) { } frame->addr[0] = fb; for (int plane = 1; plane < planes; plane++) { - frame->addr[plane] = - (uint8_t*)frame->addr[plane - 1] + st_frame_plane_size(frame, plane - 1); + frame->addr[plane] = (uint8_t *)frame->addr[plane - 1] + + st_frame_plane_size(frame, plane - 1); } frame->data_size = frame->buffer_size = fb_size; } -static void frame_free(struct st_frame* frame) { - if (frame->addr[0]) st_test_free(frame->addr[0]); +static void frame_free(struct st_frame *frame) { + if (frame->addr[0]) + st_test_free(frame->addr[0]); int planes = st_frame_fmt_planes(frame->fmt); for (int plane = 0; plane < planes; plane++) { frame->addr[plane] = NULL; } } -static int frame_compare_each_line(struct st_frame* old_frame, - struct st_frame* new_frame) { +static int frame_compare_each_line(struct st_frame *old_frame, + struct st_frame *new_frame) { int ret = 0; int planes = st_frame_fmt_planes(old_frame->fmt); uint32_t h = st_frame_data_height(old_frame); for (int plane = 0; plane < planes; plane++) { for (uint32_t line = 0; line < h; line++) { - uint8_t* old_addr = - (uint8_t*)old_frame->addr[plane] + old_frame->linesize[plane] * line; - uint8_t* new_addr = - (uint8_t*)new_frame->addr[plane] + new_frame->linesize[plane] * line; - if (memcmp(old_addr, new_addr, - st_frame_least_linesize(old_frame->fmt, old_frame->width, plane))) + uint8_t *old_addr = + (uint8_t *)old_frame->addr[plane] + old_frame->linesize[plane] * line; + uint8_t *new_addr = + (uint8_t *)new_frame->addr[plane] + new_frame->linesize[plane] * line; + if (memcmp( + old_addr, new_addr, + st_frame_least_linesize(old_frame->fmt, old_frame->width, plane))) ret += -EIO; } } @@ -4052,8 +4437,8 @@ static int frame_compare_each_line(struct st_frame* old_frame, return ret; } -static void test_st_frame_convert(struct st_frame* src, struct st_frame* dst, - struct st_frame* new_src, bool expect_fail) { +static void test_st_frame_convert(struct st_frame *src, struct st_frame *dst, + struct st_frame *new_src, bool expect_fail) { int ret; ret = st_frame_convert(src, dst); if (expect_fail) @@ -4252,22 +4637,26 @@ TEST(Cvt, st_frame_convert_rotate_mix_padding) { static void test_field_to_frame(mtl_handle mt, uint32_t width, uint32_t height, enum st_frame_fmt fmt) { - struct st_frame* frame = st_frame_create(mt, fmt, width, height, false); - struct st_frame* first = st_frame_create(mt, fmt, width, height, true); - struct st_frame* second = st_frame_create(mt, fmt, width, height, true); - struct st_frame* back = st_frame_create(mt, fmt, width, height, false); + struct st_frame *frame = st_frame_create(mt, fmt, width, height, false); + struct st_frame *first = st_frame_create(mt, fmt, width, height, true); + struct st_frame *second = st_frame_create(mt, fmt, width, height, true); + struct st_frame *back = st_frame_create(mt, fmt, width, height, false); int ret; if (!frame || !first || !second || !back) { EXPECT_EQ(0, 1); - if (frame) st_frame_free(frame); - if (first) st_frame_free(first); - if (second) st_frame_free(second); - if (back) st_frame_free(back); + if (frame) + st_frame_free(frame); + if (first) + st_frame_free(first); + if (second) + st_frame_free(second); + if (back) + st_frame_free(back); return; } second->second_field = true; - st_test_rand_data((uint8_t*)frame->addr[0], frame->buffer_size, 0); + st_test_rand_data((uint8_t *)frame->addr[0], frame->buffer_size, 0); ret = st_field_split(frame, first, second); EXPECT_GE(ret, 0); @@ -4284,7 +4673,8 @@ static void test_field_to_frame(mtl_handle mt, uint32_t width, uint32_t height, } TEST(Cvt, field_to_frame) { - struct st_tests_context* ctx = st_test_ctx(); - test_field_to_frame(ctx->handle, 1920, 1080, ST_FRAME_FMT_YUV422RFC4175PG2BE10); + struct st_tests_context *ctx = st_test_ctx(); + test_field_to_frame(ctx->handle, 1920, 1080, + ST_FRAME_FMT_YUV422RFC4175PG2BE10); test_field_to_frame(ctx->handle, 1920, 1080, ST_FRAME_FMT_YUV422PLANAR10LE); } diff --git a/tests/src/dma_test.cpp b/tests/src/dma_test.cpp index f1fbfeb61..cce201902 100644 --- a/tests/src/dma_test.cpp +++ b/tests/src/dma_test.cpp @@ -5,18 +5,19 @@ #include "log.h" #include "tests.h" -static int test_dma_cnt(struct st_tests_context* ctx) { +static int test_dma_cnt(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; struct mtl_var_info var; int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) return ret; + if (ret < 0) + return ret; return var.dma_dev_cnt; } -static void test_dma_create_one(struct st_tests_context* ctx) { +static void test_dma_create_one(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; int base_cnt = test_dma_cnt(ctx), cnt, ret; mtl_udma_handle dma; @@ -31,7 +32,7 @@ static void test_dma_create_one(struct st_tests_context* ctx) { EXPECT_EQ(base_cnt, cnt); } -static void test_dma_create_max(struct st_tests_context* ctx) { +static void test_dma_create_max(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; int base_cnt = test_dma_cnt(ctx), cnt, ret, dma_idx; mtl_udma_handle dma[MTL_DMA_DEV_MAX]; @@ -39,7 +40,8 @@ static void test_dma_create_max(struct st_tests_context* ctx) { dma_idx = 0; while (true) { dma[dma_idx] = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma[dma_idx]) break; + if (!dma[dma_idx]) + break; dma_idx++; cnt = test_dma_cnt(ctx); EXPECT_EQ(base_cnt + dma_idx, cnt); @@ -54,27 +56,31 @@ static void test_dma_create_max(struct st_tests_context* ctx) { } TEST(Dma, create) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_create_one(ctx); } TEST(Dma, create_max) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_create_max(ctx); } TEST(Dma, create_multi) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; - for (int i = 0; i < 10; i++) test_dma_create_one(ctx); + for (int i = 0; i < 10; i++) + test_dma_create_one(ctx); } static void _test_dma_copy(mtl_handle st, mtl_udma_handle dma, uint32_t off, @@ -89,7 +95,7 @@ static void _test_dma_copy(mtl_handle st, mtl_udma_handle dma, uint32_t off, src = mtl_hp_malloc(st, len, MTL_PORT_P); ASSERT_TRUE(src != NULL); src_iova = mtl_hp_virt2iova(st, src); - st_test_rand_data((uint8_t*)src, len, 0); + st_test_rand_data((uint8_t *)src, len, 0); ret = mtl_udma_copy(dma, dst_iova + off, src_iova + off, len - off); EXPECT_GE(ret, 0); @@ -100,14 +106,15 @@ static void _test_dma_copy(mtl_handle st, mtl_udma_handle dma, uint32_t off, nb_dq = mtl_udma_completed(dma, 32); } - ret = memcmp((uint8_t*)src + off, (uint8_t*)dst + off, len - off); + ret = memcmp((uint8_t *)src + off, (uint8_t *)dst + off, len - off); EXPECT_EQ(ret, 0); mtl_hp_free(st, dst); mtl_hp_free(st, src); } -static void test_dma_copy(struct st_tests_context* ctx, uint32_t off, uint32_t len) { +static void test_dma_copy(struct st_tests_context *ctx, uint32_t off, + uint32_t len) { mtl_handle st = ctx->handle; mtl_udma_handle dma; int ret; @@ -121,7 +128,7 @@ static void test_dma_copy(struct st_tests_context* ctx, uint32_t off, uint32_t l EXPECT_GE(ret, 0); } -static void test_dma_copy_sanity(struct st_tests_context* ctx) { +static void test_dma_copy_sanity(struct st_tests_context *ctx) { mtl_handle st = ctx->handle; mtl_udma_handle dma; int ret; @@ -141,7 +148,7 @@ static void test_dma_copy_sanity(struct st_tests_context* ctx) { EXPECT_GE(ret, 0); } -static void test_dma_copy_fill_async(struct st_tests_context* ctx, bool fill) { +static void test_dma_copy_fill_async(struct st_tests_context *ctx, bool fill) { mtl_handle st = ctx->handle; mtl_udma_handle dma; int ret; @@ -169,18 +176,20 @@ static void test_dma_copy_fill_async(struct st_tests_context* ctx, bool fill) { if (fill) memset(fb_src, pattern, fb_size); else - st_test_rand_data((uint8_t*)fb_src, fb_size, 0); - SHA256((unsigned char*)fb_src, fb_size, fb_src_shas); + st_test_rand_data((uint8_t *)fb_src, fb_size, 0); + SHA256((unsigned char *)fb_src, fb_size, fb_src_shas); while (fb_dst_iova_off < fb_size) { /* try to copy */ while (fb_src_iova_off < fb_size) { if (fill) - ret = mtl_udma_fill_u8(dma, fb_dst_iova + fb_src_iova_off, pattern, element_size); + ret = mtl_udma_fill_u8(dma, fb_dst_iova + fb_src_iova_off, pattern, + element_size); else ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, element_size); - if (ret < 0) break; + if (ret < 0) + break; fb_src_iova_off += element_size; } /* submit */ @@ -191,7 +200,7 @@ static void test_dma_copy_fill_async(struct st_tests_context* ctx, bool fill) { } /* all copy completed, check sha */ - SHA256((unsigned char*)fb_dst, fb_size, fb_dst_shas); + SHA256((unsigned char *)fb_dst, fb_size, fb_dst_shas); ret = memcmp(fb_dst_shas, fb_src_shas, SHA256_DIGEST_LENGTH); EXPECT_EQ(ret, 0); @@ -203,41 +212,45 @@ static void test_dma_copy_fill_async(struct st_tests_context* ctx, bool fill) { } TEST(Dma, copy) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_copy(ctx, 0, 1024); test_dma_copy(ctx, 128, 1024 * 4); } TEST(Dma, copy_odd) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_copy(ctx, 33, 1024); test_dma_copy(ctx, 33, 1024 - 33); } TEST(Dma, copy_sanity) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_copy_sanity(ctx); } TEST(Dma, copy_async) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_copy_fill_async(ctx, false); } -static void _test_dma_fill(mtl_handle st, mtl_udma_handle dma, uint32_t off, uint32_t len, - uint8_t pattern) { +static void _test_dma_fill(mtl_handle st, mtl_udma_handle dma, uint32_t off, + uint32_t len, uint8_t pattern) { void *dst = NULL, *src = NULL; mtl_iova_t dst_iova; int ret; @@ -258,15 +271,15 @@ static void _test_dma_fill(mtl_handle st, mtl_udma_handle dma, uint32_t off, uin nb_dq = mtl_udma_completed(dma, 32); } - ret = memcmp((uint8_t*)src + off, (uint8_t*)dst + off, len - off); + ret = memcmp((uint8_t *)src + off, (uint8_t *)dst + off, len - off); EXPECT_EQ(ret, 0); mtl_hp_free(st, dst); mtl_hp_free(st, src); } -static void test_dma_fill(struct st_tests_context* ctx, uint32_t off, uint32_t len, - uint8_t pattern) { +static void test_dma_fill(struct st_tests_context *ctx, uint32_t off, + uint32_t len, uint8_t pattern) { mtl_handle st = ctx->handle; mtl_udma_handle dma; int ret; @@ -280,7 +293,7 @@ static void test_dma_fill(struct st_tests_context* ctx, uint32_t off, uint32_t l EXPECT_GE(ret, 0); } -static void test_dma_fill_sanity(struct st_tests_context* ctx) { +static void test_dma_fill_sanity(struct st_tests_context *ctx) { mtl_handle st = ctx->handle; mtl_udma_handle dma; int ret; @@ -301,40 +314,44 @@ static void test_dma_fill_sanity(struct st_tests_context* ctx) { } TEST(Dma, fill) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_fill(ctx, 0, 1024, 0xa5); test_dma_fill(ctx, 128, 1024 * 4, 0x5a); } TEST(Dma, fill_odd) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_fill(ctx, 33, 1024, 0x5a); test_dma_fill(ctx, 33, 1024 - 33, 0xa5); } TEST(Dma, fill_sanity) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_fill_sanity(ctx); } TEST(Dma, fill_async) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; test_dma_copy_fill_async(ctx, true); } -static void _test_dma_map(mtl_handle st, const void* vaddr, size_t size, +static void _test_dma_map(mtl_handle st, const void *vaddr, size_t size, bool expect_succ) { mtl_iova_t iova = mtl_dma_map(st, vaddr, size); if (expect_succ) { @@ -345,21 +362,21 @@ static void _test_dma_map(mtl_handle st, const void* vaddr, size_t size, EXPECT_FALSE(iova != MTL_BAD_IOVA); } -static void test_dma_map(struct st_tests_context* ctx, size_t size) { +static void test_dma_map(struct st_tests_context *ctx, size_t size) { auto st = ctx->handle; size_t pg_sz = mtl_page_size(st); /* 2 more pages to hold the head and tail */ - uint8_t* p = (uint8_t*)malloc(size + 2 * pg_sz); + uint8_t *p = (uint8_t *)malloc(size + 2 * pg_sz); ASSERT_TRUE(p != NULL); - uint8_t* align = (uint8_t*)MTL_ALIGN((uint64_t)p, pg_sz); + uint8_t *align = (uint8_t *)MTL_ALIGN((uint64_t)p, pg_sz); _test_dma_map(st, align, size, true); free(p); } TEST(Dma, map) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); auto st = ctx->handle; if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -372,25 +389,26 @@ TEST(Dma, map) { } TEST(Dma, map_fail) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); auto st = ctx->handle; size_t pg_sz = mtl_page_size(st); - uint8_t* p = (uint8_t*)malloc(pg_sz / 2); + uint8_t *p = (uint8_t *)malloc(pg_sz / 2); _test_dma_map(st, p, pg_sz / 2, false); free(p); } -static void test_dma_map_continues(struct st_tests_context* ctx, size_t size, int count) { +static void test_dma_map_continues(struct st_tests_context *ctx, size_t size, + int count) { auto st = ctx->handle; size_t pg_sz = mtl_page_size(st); /* 2 more pages to hold the head and tail */ - uint8_t* p = (uint8_t*)malloc((size + 2 * pg_sz) * count); + uint8_t *p = (uint8_t *)malloc((size + 2 * pg_sz) * count); ASSERT_TRUE(p != NULL); - uint8_t* align = (uint8_t*)MTL_ALIGN((uint64_t)p, pg_sz); - mtl_iova_t* iovas = new mtl_iova_t[count]; + uint8_t *align = (uint8_t *)MTL_ALIGN((uint64_t)p, pg_sz); + mtl_iova_t *iovas = new mtl_iova_t[count]; int ret; for (int i = 0; i < count; i++) { @@ -407,7 +425,7 @@ static void test_dma_map_continues(struct st_tests_context* ctx, size_t size, in } TEST(Dma, map_continues) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); auto st = ctx->handle; if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -418,14 +436,14 @@ TEST(Dma, map_continues) { test_dma_map_continues(ctx, 64 * mtl_page_size(st), 10); } -static void test_dma_remap(struct st_tests_context* ctx, size_t size) { +static void test_dma_remap(struct st_tests_context *ctx, size_t size) { auto st = ctx->handle; size_t pg_sz = mtl_page_size(st); /* 2 more pages to hold the head and tail */ - uint8_t* p = (uint8_t*)malloc(size + 2 * pg_sz); + uint8_t *p = (uint8_t *)malloc(size + 2 * pg_sz); ASSERT_TRUE(p != NULL); - uint8_t* align = (uint8_t*)MTL_ALIGN((uint64_t)p, pg_sz); + uint8_t *align = (uint8_t *)MTL_ALIGN((uint64_t)p, pg_sz); mtl_iova_t iova = mtl_dma_map(st, align, size); EXPECT_TRUE(iova != MTL_BAD_IOVA); @@ -451,7 +469,7 @@ static void test_dma_remap(struct st_tests_context* ctx, size_t size) { } TEST(Dma, map_remap) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); auto st = ctx->handle; if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -462,23 +480,25 @@ TEST(Dma, map_remap) { test_dma_remap(ctx, 64 * mtl_page_size(st)); } -static void test_dma_map_copy(mtl_handle st, mtl_udma_handle dma, size_t copy_size) { +static void test_dma_map_copy(mtl_handle st, mtl_udma_handle dma, + size_t copy_size) { void *dst = NULL, *src = NULL; size_t pg_sz = mtl_page_size(st); /* 2 more pages to hold the head and tail */ size_t size = copy_size + 2 * pg_sz; - dst = (uint8_t*)malloc(size); - if (!dst) return; - src = (uint8_t*)malloc(size); + dst = (uint8_t *)malloc(size); + if (!dst) + return; + src = (uint8_t *)malloc(size); if (!src) { free(dst); return; } - st_test_rand_data((uint8_t*)src, size, 0); + st_test_rand_data((uint8_t *)src, size, 0); - void* src_align = (void*)MTL_ALIGN((uint64_t)src, pg_sz); - void* dst_align = (void*)MTL_ALIGN((uint64_t)dst, pg_sz); + void *src_align = (void *)MTL_ALIGN((uint64_t)src, pg_sz); + void *dst_align = (void *)MTL_ALIGN((uint64_t)dst, pg_sz); mtl_iova_t src_iova = mtl_dma_map(st, src_align, copy_size); mtl_iova_t dst_iova = mtl_dma_map(st, dst_align, copy_size); ASSERT_TRUE(src_iova != MTL_BAD_IOVA); @@ -505,10 +525,11 @@ static void test_dma_map_copy(mtl_handle st, mtl_udma_handle dma, size_t copy_si } TEST(Dma, map_copy) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); auto st = ctx->handle; - if (!st_test_dma_available(ctx)) return; + if (!st_test_dma_available(ctx)) + return; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); ASSERT_TRUE(dma != NULL); @@ -519,7 +540,7 @@ TEST(Dma, map_copy) { EXPECT_GE(ret, 0); } -static void test_dma_mem_alloc_free(struct st_tests_context* ctx, size_t size) { +static void test_dma_mem_alloc_free(struct st_tests_context *ctx, size_t size) { auto st = ctx->handle; mtl_dma_mem_handle dma_mem = mtl_dma_mem_alloc(st, size); ASSERT_TRUE(dma_mem != NULL); @@ -531,7 +552,7 @@ static void test_dma_mem_alloc_free(struct st_tests_context* ctx, size_t size) { } TEST(Dma, mem_alloc_free) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); if (ctx->iova == MTL_IOVA_MODE_PA) { info("%s, skip as it's IOVA PA mode\n", __func__); diff --git a/tests/src/log.h b/tests/src/log.h index 8cd9ae7b4..ead3a3c62 100644 --- a/tests/src/log.h +++ b/tests/src/log.h @@ -10,24 +10,24 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) diff --git a/tests/src/sch_test.cpp b/tests/src/sch_test.cpp index 3d995c1b8..3a622c63e 100644 --- a/tests/src/sch_test.cpp +++ b/tests/src/sch_test.cpp @@ -41,7 +41,8 @@ static void sch_create_max_test(mtl_handle mt, int max) { for (int i = 0; i < max; i++) { mtl_sch_handle sch = mtl_sch_create(mt, &sch_ops); - if (!sch) break; + if (!sch) + break; ret = mtl_sch_start(sch); if (ret < 0) { ret = mtl_sch_free(sch); @@ -78,7 +79,7 @@ struct sch_digest_test_para { bool test_auto_unregister; }; -static void sch_digest_test_para_init(struct sch_digest_test_para* para) { +static void sch_digest_test_para_init(struct sch_digest_test_para *para) { memset(para, 0, sizeof(*para)); para->sch_cnt = 1; para->tasklets = 1; @@ -94,25 +95,26 @@ struct tasklet_test_ctx { mtl_tasklet_handle handle; }; -static int test_tasklet_start(void* priv) { - struct tasklet_test_ctx* ctx = (struct tasklet_test_ctx*)priv; +static int test_tasklet_start(void *priv) { + struct tasklet_test_ctx *ctx = (struct tasklet_test_ctx *)priv; ctx->start = true; return 0; } -static int test_tasklet_stop(void* priv) { - struct tasklet_test_ctx* ctx = (struct tasklet_test_ctx*)priv; +static int test_tasklet_stop(void *priv) { + struct tasklet_test_ctx *ctx = (struct tasklet_test_ctx *)priv; ctx->start = false; return 0; } -static int test_tasklet_handler(void* priv) { - struct tasklet_test_ctx* ctx = (struct tasklet_test_ctx*)priv; +static int test_tasklet_handler(void *priv) { + struct tasklet_test_ctx *ctx = (struct tasklet_test_ctx *)priv; ctx->job++; return 0; } -static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para* para) { +static void sch_tasklet_digest_test(mtl_handle mt, + struct sch_digest_test_para *para) { const int sch_cnt = para->sch_cnt; int tasklet_cnt = para->tasklets; std::vector schs(sch_cnt); @@ -130,7 +132,7 @@ static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para* ops.stop = test_tasklet_stop; ops.handler = test_tasklet_handler; - std::vector tasklet_ctxs; + std::vector tasklet_ctxs; tasklet_ctxs.resize((size_t)sch_cnt * tasklet_cnt); /* create the sch */ @@ -139,7 +141,7 @@ static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para* ASSERT_TRUE(sch != NULL); if (!para->runtime) { for (int j = 0; j < tasklet_cnt; j++) { - tasklet_test_ctx* ctx = new tasklet_test_ctx(); + tasklet_test_ctx *ctx = new tasklet_test_ctx(); ASSERT_TRUE(ctx != NULL); ctx->sch_idx = i; ctx->tasklet_idx = j; @@ -155,7 +157,7 @@ static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para* if (para->runtime) { for (int j = 0; j < tasklet_cnt; j++) { - tasklet_test_ctx* ctx = new tasklet_test_ctx(); + tasklet_test_ctx *ctx = new tasklet_test_ctx(); ASSERT_TRUE(ctx != NULL); ctx->sch_idx = i; ctx->tasklet_idx = j; @@ -173,7 +175,7 @@ static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para* mtl_sleep_us(1000 * 1000); /* check if all tasklet started */ for (int i = 0; i < sch_cnt * tasklet_cnt; i++) { - tasklet_test_ctx* ctx = tasklet_ctxs[i]; + tasklet_test_ctx *ctx = tasklet_ctxs[i]; EXPECT_TRUE(ctx->start); EXPECT_GT(ctx->job, 0); if (para->runtime) { @@ -190,7 +192,7 @@ static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para* if (!para->runtime && !para->test_auto_unregister) { for (int i = 0; i < sch_cnt * tasklet_cnt; i++) { - tasklet_test_ctx* ctx = tasklet_ctxs[i]; + tasklet_test_ctx *ctx = tasklet_ctxs[i]; ret = mtl_sch_unregister_tasklet(ctx->handle); EXPECT_GE(ret, 0); } @@ -204,7 +206,7 @@ static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para* /* check if all tasklet stopped */ for (int i = 0; i < sch_cnt * tasklet_cnt; i++) { - tasklet_test_ctx* ctx = tasklet_ctxs[i]; + tasklet_test_ctx *ctx = tasklet_ctxs[i]; EXPECT_FALSE(ctx->start); delete tasklet_ctxs[i]; } diff --git a/tests/src/st20_test.cpp b/tests/src/st20_test.cpp index f92b93517..5db26fc30 100644 --- a/tests/src/st20_test.cpp +++ b/tests/src/st20_test.cpp @@ -13,15 +13,16 @@ #define DUMP_INCOMPLITE_SLICE (0) -static int tx_next_video_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_next_video_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ if (ctx->slice) { - uint8_t* fb = - (uint8_t*)st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, ctx->fb_idx); + uint8_t *fb = (uint8_t *)st20_tx_get_framebuffer( + (st20_tx_handle)ctx->handle, ctx->fb_idx); memset(fb, 0x0, ctx->frame_size); ctx->lines_ready[ctx->fb_idx] = 0; } @@ -29,17 +30,20 @@ static int tx_next_video_frame(void* priv, uint16_t* next_frame_idx, *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_next_video_frame_timestamp(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_next_video_frame_timestamp(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ if (!ctx->ptp_time_first_frame) { ctx->ptp_time_first_frame = mtl_ptp_read_time(ctx->ctx->handle); @@ -49,25 +53,29 @@ static int tx_next_video_frame_timestamp(void* priv, uint16_t* next_frame_idx, if (ctx->user_pacing) { meta->tfmt = ST10_TIMESTAMP_FMT_TAI; - meta->timestamp = ctx->ptp_time_first_frame + ctx->frame_time * ctx->fb_send * 2; + meta->timestamp = + ctx->ptp_time_first_frame + ctx->frame_time * ctx->fb_send * 2; } else if (ctx->user_timestamp) { meta->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; meta->timestamp = ctx->fb_send; } - dbg("%s, next_frame_idx %u timestamp %" PRIu64 "\n", __func__, *next_frame_idx, - meta->timestamp); + dbg("%s, next_frame_idx %u timestamp %" PRIu64 "\n", __func__, + *next_frame_idx, meta->timestamp); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_next_ext_video_frame(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_next_ext_video_frame(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ if (ctx->ext_fb_in_use[ctx->fb_idx]) { err("%s, ext frame %d not available\n", __func__, ctx->fb_idx); @@ -77,7 +85,8 @@ static int tx_next_ext_video_frame(void* priv, uint16_t* next_frame_idx, int ret = st20_tx_set_ext_frame((st20_tx_handle)ctx->handle, ctx->fb_idx, &ctx->ext_frames[ctx->fb_idx]); if (ret < 0) { - err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, ctx->fb_idx); + err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, + ctx->fb_idx); return -EIO; } ctx->ext_fb_in_use[ctx->fb_idx] = true; @@ -85,17 +94,20 @@ static int tx_next_ext_video_frame(void* priv, uint16_t* next_frame_idx, *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_next_ext_video_field(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_next_ext_video_field(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ if (ctx->ext_fb_in_use[ctx->fb_idx]) { err("%s, ext frame %d not available\n", __func__, ctx->fb_idx); @@ -105,7 +117,8 @@ static int tx_next_ext_video_field(void* priv, uint16_t* next_frame_idx, int ret = st20_tx_set_ext_frame((st20_tx_handle)ctx->handle, ctx->fb_idx, &ctx->ext_frames[ctx->fb_idx]); if (ret < 0) { - err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, ctx->fb_idx); + err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, + ctx->fb_idx); return -EIO; } ctx->ext_fb_in_use[ctx->fb_idx] = true; @@ -114,19 +127,23 @@ static int tx_next_ext_video_field(void* priv, uint16_t* next_frame_idx, meta->second_field = ctx->fb_send % 2 ? true : false; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_notify_ext_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_notify_ext_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ - void* frame_addr = st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, frame_idx); + void *frame_addr = + st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, frame_idx); for (int i = 0; i < ctx->fb_cnt; ++i) { if (frame_addr == ctx->ext_frames[i].buf_addr) { ctx->ext_fb_in_use[i] = false; @@ -138,14 +155,16 @@ static int tx_notify_ext_frame_done(void* priv, uint16_t frame_idx, return -EIO; } -static int tx_notify_timestamp_frame_done(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_notify_timestamp_frame_done(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ if (ctx->user_timestamp && !ctx->user_pacing) { - dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, ctx->pre_timestamp); + dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, + ctx->pre_timestamp); } ctx->pre_timestamp = meta->timestamp; @@ -154,31 +173,32 @@ static int tx_notify_timestamp_frame_done(void* priv, uint16_t frame_idx, static enum st_fps tmstamp_delta_to_fps(int delta) { switch (delta) { - case 1500: - return ST_FPS_P60; - case 1501: - case 1502: - return ST_FPS_P59_94; - case 1800: - return ST_FPS_P50; - case 3000: - return ST_FPS_P30; - case 3003: - return ST_FPS_P29_97; - case 3600: - return ST_FPS_P25; - default: - dbg("%s, err delta %d\n", __func__, delta); - break; + case 1500: + return ST_FPS_P60; + case 1501: + case 1502: + return ST_FPS_P59_94; + case 1800: + return ST_FPS_P50; + case 3000: + return ST_FPS_P30; + case 3003: + return ST_FPS_P29_97; + case 3600: + return ST_FPS_P25; + default: + dbg("%s, err delta %d\n", __func__, delta); + break; } return ST_FPS_MAX; } -static int tx_notify_frame_done_check_tmstamp(void* priv, uint16_t frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_notify_frame_done_check_tmstamp(void *priv, uint16_t frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (ctx->rtp_tmstamp == 0) @@ -196,29 +216,34 @@ static int tx_notify_frame_done_check_tmstamp(void* priv, uint16_t frame_idx, return 0; } -static int tx_next_video_field(void* priv, uint16_t* next_frame_idx, - struct st20_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_next_video_field(void *priv, uint16_t *next_frame_idx, + struct st20_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; meta->second_field = ctx->fb_send % 2 ? true : false; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_frame_lines_ready(void* priv, uint16_t frame_idx, - struct st20_tx_slice_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_frame_lines_ready(void *priv, uint16_t frame_idx, + struct st20_tx_slice_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ - uint8_t* fb = (uint8_t*)st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, frame_idx); + uint8_t *fb = (uint8_t *)st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, + frame_idx); int offset = ctx->lines_ready[frame_idx] * ctx->stride; uint16_t lines = ctx->lines_per_slice; if (ctx->lines_ready[frame_idx] + lines > ctx->height) @@ -234,8 +259,8 @@ static int tx_frame_lines_ready(void* priv, uint16_t frame_idx, return 0; } -static int tx_video_build_ooo_mapping(tests_context* s) { - int* ooo_mapping = s->ooo_mapping; +static int tx_video_build_ooo_mapping(tests_context *s) { + int *ooo_mapping = s->ooo_mapping; int total_pkts = s->total_pkts_in_frame; int ooo_cnt = 0; @@ -246,9 +271,11 @@ static int tx_video_build_ooo_mapping(tests_context* s) { } int ooo_pkts = rand() % 4; - if (ooo_pkts <= 0) ooo_pkts = 4; + if (ooo_pkts <= 0) + ooo_pkts = 4; int ooo_start = rand() % 10; - if (ooo_start <= 0) ooo_start = 10; + if (ooo_start <= 0) + ooo_start = 10; int ooo_end = ooo_start + ooo_pkts; int ooo_step = total_pkts / 40; while (ooo_end < total_pkts) { @@ -271,28 +298,32 @@ static int tx_video_build_ooo_mapping(tests_context* s) { return 0; } -static int tx_video_build_rtp_packet(tests_context* s, struct st20_rfc4175_rtp_hdr* rtp, - uint16_t* pkt_len) { - struct st20_rfc4175_extra_rtp_hdr* e_rtp = NULL; +static int tx_video_build_rtp_packet(tests_context *s, + struct st20_rfc4175_rtp_hdr *rtp, + uint16_t *pkt_len) { + struct st20_rfc4175_extra_rtp_hdr *e_rtp = NULL; int offset; int frame_size = s->frame_size; uint16_t row_number, row_offset; - uint8_t* payload = (uint8_t*)rtp + sizeof(*rtp); + uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); int pkt_idx = s->pkt_idx; - if (s->out_of_order_pkt) pkt_idx = s->ooo_mapping[s->pkt_idx]; + if (s->out_of_order_pkt) + pkt_idx = s->ooo_mapping[s->pkt_idx]; if (s->single_line) { row_number = pkt_idx / s->pkts_in_line; int pixels_in_pkt = s->pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; row_offset = pixels_in_pkt * (pkt_idx % s->pkts_in_line); - offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; + offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * + s->st20_pg.size; } else { offset = s->pkt_data_len * pkt_idx; row_number = offset / s->bytes_in_line; - row_offset = (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; + row_offset = + (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; if ((offset + s->pkt_data_len > (row_number + 1) * s->bytes_in_line) && (offset + s->pkt_data_len < frame_size)) { - e_rtp = (struct st20_rfc4175_extra_rtp_hdr*)payload; + e_rtp = (struct st20_rfc4175_extra_rtp_hdr *)payload; payload += sizeof(*e_rtp); } } @@ -313,9 +344,10 @@ static int tx_video_build_rtp_packet(tests_context* s, struct st20_rfc4175_rtp_h rtp->base.seq_number = htons(s->seq_id); rtp->seq_number_ext = htons((uint16_t)(s->seq_id >> 16)); s->seq_id++; - int temp = s->single_line - ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (frame_size - offset); + int temp = + s->single_line + ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (frame_size - offset); uint16_t data_len = s->pkt_data_len > temp ? temp : s->pkt_data_len; rtp->row_length = htons(data_len); *pkt_len = data_len + sizeof(*rtp); @@ -330,7 +362,8 @@ static int tx_video_build_rtp_packet(tests_context* s, struct st20_rfc4175_rtp_h *pkt_len += sizeof(*e_rtp); } if (s->check_sha) { - mtl_memcpy(payload, s->frame_buf[s->fb_idx % TEST_SHA_HIST_NUM] + offset, data_len); + mtl_memcpy(payload, s->frame_buf[s->fb_idx % TEST_SHA_HIST_NUM] + offset, + data_len); } s->pkt_idx++; @@ -351,10 +384,10 @@ static int tx_video_build_rtp_packet(tests_context* s, struct st20_rfc4175_rtp_h return 0; } -static void tx_feed_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void tx_feed_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); while (!ctx->stop) { @@ -367,48 +400,54 @@ static void tx_feed_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - tx_video_build_rtp_packet(ctx, (struct st20_rfc4175_rtp_hdr*)usrptr, &mbuf_len); + tx_video_build_rtp_packet(ctx, (struct st20_rfc4175_rtp_hdr *)usrptr, + &mbuf_len); st20_tx_put_mbuf((st20_tx_handle)ctx->handle, mbuf, mbuf_len); } } -static int tx_rtp_done(void* args) { - auto ctx = (tests_context*)args; - if (!ctx->handle) return -EIO; /* not ready */ +static int tx_rtp_done(void *args) { + auto ctx = (tests_context *)args; + if (!ctx->handle) + return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int rx_rtp_ready(void* args) { - auto ctx = (tests_context*)args; - if (!ctx->handle) return -EIO; /* not ready */ +static int rx_rtp_ready(void *args) { + auto ctx = (tests_context *)args; + if (!ctx->handle) + return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static void rx_handle_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* hdr, +static void rx_handle_rtp(tests_context *s, struct st20_rfc4175_rtp_hdr *hdr, bool newframe) { int idx = s->idx; - struct st20_rfc4175_extra_rtp_hdr* e_hdr = NULL; + struct st20_rfc4175_extra_rtp_hdr *e_hdr = NULL; uint16_t row_number; /* 0 to 1079 for 1080p */ uint16_t row_offset; /* [0, 480, 960, 1440] for 1080p */ uint16_t row_length; /* 1200 for 1080p */ - uint8_t* frame; - uint8_t* payload; + uint8_t *frame; + uint8_t *payload; if (newframe) { if (s->frame_buf[0]) { @@ -416,29 +455,30 @@ static void rx_handle_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* hdr, s->buf_q.push(s->frame_buf[0]); s->cv.notify_all(); } - s->frame_buf[0] = (uint8_t*)st_test_zmalloc(s->frame_size); + s->frame_buf[0] = (uint8_t *)st_test_zmalloc(s->frame_size); ASSERT_TRUE(s->frame_buf[0] != NULL); } frame = s->frame_buf[0]; - payload = (uint8_t*)hdr + sizeof(*hdr); + payload = (uint8_t *)hdr + sizeof(*hdr); row_number = ntohs(hdr->row_number); row_offset = ntohs(hdr->row_offset); row_length = ntohs(hdr->row_length); - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, row_length); + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, + row_length); if (row_offset & ST20_SRD_OFFSET_CONTINUATION) { /* additional Sample Row Data */ row_offset &= ~ST20_SRD_OFFSET_CONTINUATION; - e_hdr = (struct st20_rfc4175_extra_rtp_hdr*)payload; + e_hdr = (struct st20_rfc4175_extra_rtp_hdr *)payload; payload += sizeof(*e_hdr); } /* copy the payload to target frame */ - uint32_t offset = - (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; + uint32_t offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * + s->st20_pg.size; if ((offset + row_length) > s->frame_size) { - err("%s(%d: invalid offset %u frame size %" PRIu64 "\n", __func__, idx, offset, - s->frame_size); + err("%s(%d: invalid offset %u frame size %" PRIu64 "\n", __func__, idx, + offset, s->frame_size); return; } mtl_memcpy(frame + offset, payload, row_length); @@ -447,12 +487,13 @@ static void rx_handle_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* hdr, uint16_t row2_offset = ntohs(e_hdr->row_offset); uint16_t row2_length = ntohs(e_hdr->row_length); - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, row2_length); - uint32_t offset2 = - (row2_number * s->width + row2_offset) / s->st20_pg.coverage * s->st20_pg.size; + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, + row2_length); + uint32_t offset2 = (row2_number * s->width + row2_offset) / + s->st20_pg.coverage * s->st20_pg.size; if ((offset2 + row2_length) > s->frame_size) { - err("%s(%d: invalid offset %u frame size %" PRIu64 " for extra hdr\n", __func__, - idx, offset2, s->frame_size); + err("%s(%d: invalid offset %u frame size %" PRIu64 " for extra hdr\n", + __func__, idx, offset2, s->frame_size); return; } mtl_memcpy(frame + offset2, payload + row_length, row2_length); @@ -461,13 +502,13 @@ static void rx_handle_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* hdr, return; } -static void rx_get_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void rx_get_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); - struct st20_rfc4175_rtp_hdr* hdr; + struct st20_rfc4175_rtp_hdr *hdr; while (!ctx->stop) { /* get available buffer*/ mbuf = st20_rx_get_mbuf((st20_rx_handle)ctx->handle, &usrptr, &mbuf_len); @@ -478,12 +519,13 @@ static void rx_get_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } - hdr = (struct st20_rfc4175_rtp_hdr*)usrptr; + hdr = (struct st20_rfc4175_rtp_hdr *)usrptr; uint32_t tmstamp = ntohl(hdr->base.tmstamp); bool newframe = false; ctx->packet_rec++; @@ -502,10 +544,12 @@ static void rx_get_packet(void* args) { } } -static int st20_rx_frame_ready(void* priv, void* frame, struct st20_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st20_rx_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; if (st_is_frame_complete(meta->status)) { ctx->fb_rec++; @@ -514,19 +558,21 @@ static int st20_rx_frame_ready(void* priv, void* frame, struct st20_rx_frame_met ctx->start_time = st_test_get_monotonic_time(); } } - if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) ctx->rtp_tmstamp = meta->timestamp; + if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) + ctx->rtp_tmstamp = meta->timestamp; st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); return 0; } -static void st20_tx_ops_init(tests_context* st20, struct st20_tx_ops* ops) { +static void st20_tx_ops_init(tests_context *st20, struct st20_tx_ops *ops) { auto ctx = st20->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st20_test"; ops->priv = st20; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; + if (ctx->same_dual_port) + ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -553,14 +599,15 @@ static void st20_tx_ops_init(tests_context* st20, struct st20_tx_ops* ops) { ops->rtp_ring_size = 1024; } -static void st20_rx_ops_init(tests_context* st20, struct st20_rx_ops* ops) { +static void st20_rx_ops_init(tests_context *st20, struct st20_rx_ops *ops) { auto ctx = st20->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st20_test"; ops->priv = st20; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; + if (ctx->same_dual_port) + ops->num_port = 1; memcpy(ops->ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -609,21 +656,13 @@ static void st20_rx_assert_cnt(int expect_s20_rx_cnt) { EXPECT_EQ(var.st20_rx_sessions_cnt, expect_s20_rx_cnt); } -TEST(St20_tx, create_free_single) { - create_free_test(st20_tx, 0, 1, 1); -} -TEST(St20_tx, create_free_multi) { - create_free_test(st20_tx, 0, 1, 6); -} -TEST(St20_tx, create_free_mix) { - create_free_test(st20_tx, 2, 3, 4); -} +TEST(St20_tx, create_free_single) { create_free_test(st20_tx, 0, 1, 1); } +TEST(St20_tx, create_free_multi) { create_free_test(st20_tx, 0, 1, 6); } +TEST(St20_tx, create_free_mix) { create_free_test(st20_tx, 2, 3, 4); } TEST(St20_tx, create_free_max) { create_free_max(st20_tx, TEST_CREATE_FREE_MAX); } -TEST(St20_tx, create_expect_fail) { - expect_fail_test(st20_tx); -} +TEST(St20_tx, create_expect_fail) { expect_fail_test(st20_tx); } TEST(St20_tx, create_expect_fail_fb_cnt) { uint16_t fbcnt = 1; expect_fail_test_fb_cnt(st20_tx, fbcnt); @@ -657,21 +696,13 @@ TEST(St20_tx, rtp_pkt_size) { expect_test_rtp_pkt_size(st20_tx, ST20_TYPE_RTP_LEVEL, rtp_pkt_size, false); } -TEST(St20_rx, create_free_single) { - create_free_test(st20_rx, 0, 1, 1); -} -TEST(St20_rx, create_free_multi) { - create_free_test(st20_rx, 0, 1, 6); -} -TEST(St20_rx, create_free_mix) { - create_free_test(st20_rx, 2, 3, 4); -} +TEST(St20_rx, create_free_single) { create_free_test(st20_rx, 0, 1, 1); } +TEST(St20_rx, create_free_multi) { create_free_test(st20_rx, 0, 1, 6); } +TEST(St20_rx, create_free_mix) { create_free_test(st20_rx, 2, 3, 4); } TEST(St20_rx, create_free_max) { create_free_max(st20_rx, TEST_CREATE_FREE_MAX); } -TEST(St20_rx, create_expect_fail) { - expect_fail_test(st20_rx); -} +TEST(St20_rx, create_expect_fail) { expect_fail_test(st20_rx); } TEST(St20_rx, create_expect_fail_fb_cnt) { uint16_t fbcnt = 0; expect_fail_test_fb_cnt(st20_rx, fbcnt); @@ -685,35 +716,41 @@ TEST(St20_rx, create_expect_fail_ring_sz) { expect_fail_test_rtp_ring(st20_rx, ST20_TYPE_RTP_LEVEL, ring_size); } -static void rtp_tx_specific_init(struct st20_tx_ops* ops, tests_context* test_ctx) { +static void rtp_tx_specific_init(struct st20_tx_ops *ops, + tests_context *test_ctx) { int ret; ret = st20_get_pgroup(ops->fmt, &test_ctx->st20_pg); ASSERT_TRUE(ret == 0); /* 4800 if 1080p yuv422 */ - size_t bytes_in_line = ops->width * test_ctx->st20_pg.size / test_ctx->st20_pg.coverage; + size_t bytes_in_line = + ops->width * test_ctx->st20_pg.size / test_ctx->st20_pg.coverage; if (ops->packing == ST20_PACKING_GPM_SL) { /* calculate pkts in line for rtp */ - size_t bytes_in_pkt = MTL_PKT_MAX_RTP_BYTES - sizeof(struct st20_rfc4175_rtp_hdr); + size_t bytes_in_pkt = + MTL_PKT_MAX_RTP_BYTES - sizeof(struct st20_rfc4175_rtp_hdr); int pkts_in_line = (bytes_in_line / bytes_in_pkt) + 1; test_ctx->total_pkts_in_frame = ops->height * pkts_in_line; int pixels_in_pkts = (ops->width + pkts_in_line - 1) / pkts_in_line; test_ctx->pkt_data_len = (pixels_in_pkts + test_ctx->st20_pg.coverage - 1) / - test_ctx->st20_pg.coverage * test_ctx->st20_pg.size; + test_ctx->st20_pg.coverage * + test_ctx->st20_pg.size; test_ctx->pkts_in_line = pkts_in_line; } else if (ops->packing == ST20_PACKING_BPM) { test_ctx->pkt_data_len = 1260; - int pixels_in_pkts = - test_ctx->pkt_data_len * test_ctx->st20_pg.coverage / test_ctx->st20_pg.size; + int pixels_in_pkts = test_ctx->pkt_data_len * test_ctx->st20_pg.coverage / + test_ctx->st20_pg.size; test_ctx->total_pkts_in_frame = ceil((double)ops->width * ops->height / pixels_in_pkts); } else if (ops->packing == ST20_PACKING_GPM) { - int max_data_len = MTL_PKT_MAX_RTP_BYTES - sizeof(struct st20_rfc4175_rtp_hdr) - + int max_data_len = MTL_PKT_MAX_RTP_BYTES - + sizeof(struct st20_rfc4175_rtp_hdr) - sizeof(struct st20_rfc4175_extra_rtp_hdr); int pg_per_pkt = max_data_len / test_ctx->st20_pg.size; - test_ctx->total_pkts_in_frame = (ceil)((double)ops->width * ops->height / - (test_ctx->st20_pg.coverage * pg_per_pkt)); + test_ctx->total_pkts_in_frame = + (ceil)((double)ops->width * ops->height / + (test_ctx->st20_pg.coverage * pg_per_pkt)); test_ctx->pkt_data_len = pg_per_pkt * test_ctx->st20_pg.size; } else { err("%s, invalid packing mode: %d\n", __func__, ops->packing); @@ -726,33 +763,36 @@ static void rtp_tx_specific_init(struct st20_tx_ops* ops, tests_context* test_ct test_ctx->bytes_in_line = bytes_in_line; test_ctx->width = ops->width; test_ctx->single_line = (ops->packing == ST20_PACKING_GPM_SL); - test_ctx->frame_size = - ops->width * ops->height * test_ctx->st20_pg.size / test_ctx->st20_pg.coverage; + test_ctx->frame_size = ops->width * ops->height * test_ctx->st20_pg.size / + test_ctx->st20_pg.coverage; ops->rtp_frame_total_pkts = test_ctx->total_pkts_in_frame; - ops->rtp_pkt_size = test_ctx->pkt_data_len + sizeof(struct st20_rfc4175_rtp_hdr); + ops->rtp_pkt_size = + test_ctx->pkt_data_len + sizeof(struct st20_rfc4175_rtp_hdr); if (ops->packing != ST20_PACKING_GPM_SL) /* no extra for GPM_SL */ ops->rtp_pkt_size += sizeof(struct st20_rfc4175_extra_rtp_hdr); ops->notify_rtp_done = tx_rtp_done; ops->rtp_ring_size = 1024; } -static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], int width[], - int height[], enum st20_fmt fmt, enum st_test_level level, - int sessions = 1, bool ext_buf = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], + int width[], int height[], enum st20_fmt fmt, + enum st_test_level level, int sessions = 1, + bool ext_buf = false) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops; - std::vector test_ctx; + std::vector test_ctx; std::vector handle; std::vector expect_framerate; std::vector framerate; std::vector rtp_thread; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ext_buf) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -799,24 +839,27 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], int width test_ctx[i]->frame_size = frame_size; if (ext_buf) { - test_ctx[i]->ext_frames = (struct st20_ext_frame*)malloc( + test_ctx[i]->ext_frames = (struct st20_ext_frame *)malloc( sizeof(*test_ctx[i]->ext_frames) * test_ctx[i]->fb_cnt); size_t pg_sz = mtl_page_size(m_handle); size_t fb_size = test_ctx[i]->frame_size * test_ctx[i]->fb_cnt; - test_ctx[i]->ext_fb_iova_map_sz = mtl_size_page_align(fb_size, pg_sz); /* align */ + test_ctx[i]->ext_fb_iova_map_sz = + mtl_size_page_align(fb_size, pg_sz); /* align */ size_t fb_size_malloc = test_ctx[i]->ext_fb_iova_map_sz + pg_sz; test_ctx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx[i]->ext_fb_malloc != NULL); test_ctx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx[i]->ext_fb_malloc, pg_sz); - test_ctx[i]->ext_fb_iova = - mtl_dma_map(m_handle, test_ctx[i]->ext_fb, test_ctx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx[i]->ext_fb_malloc, pg_sz); + test_ctx[i]->ext_fb_iova = mtl_dma_map(m_handle, test_ctx[i]->ext_fb, + test_ctx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx[i]->ext_fb); ASSERT_TRUE(test_ctx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx[i]->fb_cnt; j++) { - test_ctx[i]->ext_frames[j].buf_addr = test_ctx[i]->ext_fb + j * frame_size; - test_ctx[i]->ext_frames[j].buf_iova = test_ctx[i]->ext_fb_iova + j * frame_size; + test_ctx[i]->ext_frames[j].buf_addr = + test_ctx[i]->ext_fb + j * frame_size; + test_ctx[i]->ext_frames[j].buf_iova = + test_ctx[i]->ext_fb_iova + j * frame_size; test_ctx[i]->ext_frames[j].buf_len = frame_size; } } @@ -838,7 +881,8 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], int width for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx[i]->fb_send / time_sec; if (type[i] == ST20_TYPE_RTP_LEVEL) { test_ctx[i]->stop = true; @@ -855,8 +899,8 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], int width for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx[i]->fb_send, 0); EXPECT_LE(test_ctx[i]->tx_tmstamp_delta_fail_cnt, 1); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx[i]->fb_send, - framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, + test_ctx[i]->fb_send, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_tx_free(handle[i]); EXPECT_GE(ret, 0); @@ -869,22 +913,25 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], int width } } -static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width[], - int height[], enum st20_fmt fmt, enum st_test_level level, - int sessions = 1, bool ext_buf = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], + int width[], int height[], enum st20_fmt fmt, + enum st_test_level level, int sessions = 1, + bool ext_buf = false) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ext_buf) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -893,8 +940,8 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width } } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -925,11 +972,11 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -965,7 +1012,7 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width test_ctx_rx[i]->fb_idx = 0; if (ext_buf) { - test_ctx_rx[i]->ext_frames = (struct st20_ext_frame*)malloc( + test_ctx_rx[i]->ext_frames = (struct st20_ext_frame *)malloc( sizeof(*test_ctx_rx[i]->ext_frames) * test_ctx_rx[i]->fb_cnt); size_t frame_size = st20_frame_size(fmt, width[i], height[i]); size_t pg_sz = mtl_page_size(m_handle); @@ -976,14 +1023,15 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width test_ctx_rx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = mtl_dma_map(m_handle, test_ctx_rx[i]->ext_fb, - test_ctx_rx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); + test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( + m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - test_ctx_rx[i]->ext_frames[j].buf_addr = test_ctx_rx[i]->ext_fb + j * frame_size; + test_ctx_rx[i]->ext_frames[j].buf_addr = + test_ctx_rx[i]->ext_fb + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_iova = test_ctx_rx[i]->ext_fb_iova + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_len = frame_size; @@ -1036,7 +1084,8 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST20_TYPE_RTP_LEVEL) { @@ -1059,15 +1108,16 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); ret = st20_rx_free(rx_handle[i]); EXPECT_GE(ret, 0); if (ext_buf) { - mtl_dma_unmap(m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova, + mtl_dma_unmap(m_handle, test_ctx_rx[i]->ext_fb, + test_ctx_rx[i]->ext_fb_iova, test_ctx_rx[i]->ext_fb_iova_map_sz); } tests_context_unit(test_ctx_tx[i]); @@ -1082,56 +1132,64 @@ TEST(St20_tx, rtp_1080p_fps59_94_s1) { enum st_fps fps[1] = {ST_FPS_P59_94}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps29_97_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P29_97}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps50_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps30_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P30}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps60_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P60}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, rtp_720p_fps50_s1) { enum st20_type type[1] = {ST20_TYPE_RTP_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1280}; int height[1] = {720}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_yuv422_8bit_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_8BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_8BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_yuv420_10bit_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_tx, mix_1080p_fps59_94_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL, @@ -1139,8 +1197,8 @@ TEST(St20_tx, mix_1080p_fps59_94_s3) { enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P59_94, ST_FPS_P59_94}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 3); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_tx, mix_720p_fps29_97_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL, @@ -1148,24 +1206,24 @@ TEST(St20_tx, mix_720p_fps29_97_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P29_97, ST_FPS_P29_97}; int width[3] = {1280, 1280, 1280}; int height[3] = {720, 720, 720}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 3); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_tx, mix_1080p_fps50_fps29_97) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P29_97}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 2); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 2); } TEST(St20_tx, mix_1080p_fps50_fps59_94) { enum st20_type type[2] = {ST20_TYPE_RTP_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 2); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 2); } TEST(St20_tx, ext_frame_1080p_fps_mix_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1173,8 +1231,8 @@ TEST(St20_tx, ext_frame_1080p_fps_mix_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P59_94, ST_FPS_P50}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, 3, - true); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 3, true); } TEST(St20_rx, frame_1080p_fps50_s1) { @@ -1182,7 +1240,8 @@ TEST(St20_rx, frame_1080p_fps50_s1) { enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, ST_TEST_LEVEL_ALL); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, mix_1080p_fps50_s3) { enum st20_type type[3] = {ST20_TYPE_RTP_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1190,22 +1249,24 @@ TEST(St20_rx, mix_1080p_fps50_s3) { enum st_fps fps[3] = {ST_FPS_P50, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 3); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, rtp_1080p_fps59_94_s1) { enum st20_type type[1] = {ST20_TYPE_RTP_LEVEL}; enum st_fps fps[1] = {ST_FPS_P59_94}; int width[1] = {1920}; int height[1] = {1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, ST_TEST_LEVEL_ALL); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, rtp_1080p_fps29_97_s1) { enum st20_type type[1] = {ST20_TYPE_RTP_LEVEL}; enum st_fps fps[1] = {ST_FPS_P29_97}; int width[1] = {1920}; int height[1] = {1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, frame_1080p_fps29_97_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1213,32 +1274,32 @@ TEST(St20_rx, frame_1080p_fps29_97_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P29_97, ST_FPS_P29_97}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 3); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, mix_1080p_fps29_97_fp50) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; enum st_fps fps[2] = {ST_FPS_P29_97, ST_FPS_P50}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 2); } TEST(St20_rx, mix_1080p_fps59_94_fp50) { enum st20_type type[2] = {ST20_TYPE_RTP_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P50}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 2); } TEST(St20_rx, mix_1080p_fps29_97_720p_fp50) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; enum st_fps fps[2] = {ST_FPS_P29_97, ST_FPS_P50}; int width[2] = {1920, 1280}; int height[2] = {1080, 720}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 2); } TEST(St20_rx, ext_frame_1080p_fps_mix_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1246,8 +1307,8 @@ TEST(St20_rx, ext_frame_1080p_fps_mix_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P59_94, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, 3, - true); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 3, true); } TEST(St20_tx, mix_s3) { @@ -1274,8 +1335,8 @@ TEST(St20_rx, frame_s3) { enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P29_97}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 3); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, mix_s2) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; @@ -1290,8 +1351,8 @@ TEST(St20_rx, frame_mix_4k_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P50}; int width[2] = {1280, 3840}; int height[2] = {720, 2160}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, - 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, + ST_TEST_LEVEL_ALL, 2); } TEST(St20_rx, ext_frame_mix_s2) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; @@ -1302,15 +1363,17 @@ TEST(St20_rx, ext_frame_mix_s2) { ST_TEST_LEVEL_MANDATORY, 2, true); } -static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, - enum st_test_level level = ST_TEST_LEVEL_ALL) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void +st20_rx_update_src_test(enum st20_type type, int tx_sessions, + enum st_test_level level = ST_TEST_LEVEL_ALL) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } @@ -1318,14 +1381,15 @@ static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, bool tx_update_dst = (tx_sessions == 1); /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; int rx_sessions = 1; // 1501/1502 for one frame, max two frames. int max_rtp_delta = 3003; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -1358,17 +1422,17 @@ static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -1426,7 +1490,8 @@ static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, ops_rx.notify_frame_ready = st20_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; ops_rx.rtp_ring_size = 1024; - ops_rx.flags = ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; + ops_rx.flags = + ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; rx_handle[i] = st20_rx_create(m_handle, &ops_rx); test_ctx_rx[i]->total_pkts_in_frame = test_ctx_tx[i]->total_pkts_in_frame; @@ -1471,7 +1536,8 @@ static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1500,7 +1566,8 @@ static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1538,7 +1605,8 @@ static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1603,19 +1671,20 @@ TEST(St20_tx, update_dest_rtp) { st20_rx_update_src_test(ST20_TYPE_RTP_LEVEL, 1); } -static int st20_digest_rx_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st20_digest_rx_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; dbg("%s(%d), frame %p, opaque %p\n", __func__, ctx->idx, frame, meta->opaque); if (meta->opaque) { /* free dynamic ext frame */ - bool* in_use = (bool*)meta->opaque; + bool *in_use = (bool *)meta->opaque; EXPECT_TRUE(*in_use); *in_use = false; } - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; ctx->slice_recv_timestamp = 0; ctx->slice_recv_lines = 0; @@ -1642,8 +1711,8 @@ static int st20_digest_rx_frame_ready(void* priv, void* frame, } if (meta->fpt > (ctx->frame_time / 10)) { ctx->meta_timing_fail_cnt++; - dbg("%s(%d), fpt %" PRId64 ", frame time %fms\n", __func__, ctx->idx, meta->fpt, - ctx->frame_time / NS_PER_MS); + dbg("%s(%d), fpt %" PRId64 ", frame time %fms\n", __func__, ctx->idx, + meta->fpt, ctx->frame_time / NS_PER_MS); } double rx_time = (double)meta->timestamp_last_pkt - meta->timestamp_first_pkt; if (rx_time > ctx->frame_time) { @@ -1652,7 +1721,8 @@ static int st20_digest_rx_frame_ready(void* priv, void* frame, } if (ctx->user_timestamp && !ctx->user_pacing) { - dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, ctx->pre_timestamp); + dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, + ctx->pre_timestamp); if (ctx->pre_timestamp) { if ((uint32_t)meta->timestamp != (ctx->pre_timestamp + 1)) { ctx->incomplete_frame_cnt++; @@ -1669,35 +1739,43 @@ static int st20_digest_rx_frame_ready(void* priv, void* frame, st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); } ctx->fb_rec++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } #if DUMP_INCOMPLITE_SLICE -static void dump_slice_meta(struct st20_rx_slice_meta* meta) { +static void dump_slice_meta(struct st20_rx_slice_meta *meta) { info("%s, width %u height %u fps %d fmd %d field %d\n", __func__, meta->width, meta->height, meta->fps, meta->fmt, meta->second_field); - info("%s, frame total size %" PRIu64 " recv size %" PRIu64 " recv lines %u\n", __func__, - meta->frame_total_size, meta->frame_recv_size, meta->frame_recv_lines); + info("%s, frame total size %" PRIu64 " recv size %" PRIu64 " recv lines %u\n", + __func__, meta->frame_total_size, meta->frame_recv_size, + meta->frame_recv_lines); } #endif -static int st20_digest_rx_slice_ready(void* priv, void* frame, - struct st20_rx_slice_meta* meta) { - auto ctx = (tests_context*)priv; +static int st20_digest_rx_slice_ready(void *priv, void *frame, + struct st20_rx_slice_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; #if DUMP_INCOMPLITE_SLICE int old_incomplete_slice_cnt = ctx->incomplete_slice_cnt; #endif ctx->slice_cnt++; - struct st20_rx_slice_meta* expect_meta = (struct st20_rx_slice_meta*)ctx->priv; - if (expect_meta->width != meta->width) ctx->incomplete_slice_cnt++; - if (expect_meta->height != meta->height) ctx->incomplete_slice_cnt++; - if (expect_meta->fps != meta->fps) ctx->incomplete_slice_cnt++; - if (expect_meta->fmt != meta->fmt) ctx->incomplete_slice_cnt++; + struct st20_rx_slice_meta *expect_meta = + (struct st20_rx_slice_meta *)ctx->priv; + if (expect_meta->width != meta->width) + ctx->incomplete_slice_cnt++; + if (expect_meta->height != meta->height) + ctx->incomplete_slice_cnt++; + if (expect_meta->fps != meta->fps) + ctx->incomplete_slice_cnt++; + if (expect_meta->fmt != meta->fmt) + ctx->incomplete_slice_cnt++; if (expect_meta->frame_total_size != meta->frame_total_size) { ctx->incomplete_slice_cnt++; } @@ -1708,8 +1786,8 @@ static int st20_digest_rx_slice_ready(void* priv, void* frame, meta->frame_recv_lines * meta->width * st20_pg.size / st20_pg.coverage; if (meta->frame_recv_size < frame_ready_size) { ctx->incomplete_slice_cnt++; - dbg("%s, recv_size err %" PRIu64 " %" PRIu64 "\n", __func__, meta->frame_recv_size, - frame_ready_size); + dbg("%s, recv_size err %" PRIu64 " %" PRIu64 "\n", __func__, + meta->frame_recv_size, frame_ready_size); } if (meta->frame_recv_lines < ctx->slice_recv_lines) { ctx->incomplete_slice_cnt++; @@ -1720,8 +1798,8 @@ static int st20_digest_rx_slice_ready(void* priv, void* frame, } else { if (ctx->slice_recv_timestamp != meta->timestamp) { ctx->incomplete_slice_cnt++; - dbg("%s, time stamp err %" PRIu64 " %" PRIu64 "\n", __func__, meta->timestamp, - ctx->slice_recv_timestamp); + dbg("%s, time stamp err %" PRIu64 " %" PRIu64 "\n", __func__, + meta->timestamp, ctx->slice_recv_timestamp); } } #if DUMP_INCOMPLITE_SLICE @@ -1734,11 +1812,12 @@ static int st20_digest_rx_slice_ready(void* priv, void* frame, return 0; } -static int st20_digest_rx_field_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st20_digest_rx_field_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; ctx->slice_recv_timestamp = 0; ctx->slice_recv_lines = 0; @@ -1773,31 +1852,34 @@ static int st20_digest_rx_field_ready(void* priv, void* frame, st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); } ctx->fb_rec++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); dbg("%s, frame %p\n", __func__, frame); return 0; } -static void st20_digest_rx_frame_check(void* args) { - auto ctx = (tests_context*)args; +static void st20_digest_rx_frame_check(void *args) { + auto ctx = (tests_context *)args; std::unique_lock lck(ctx->mtx, std::defer_lock); unsigned char result[SHA256_DIGEST_LENGTH]; while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } else { - void* frame = ctx->buf_q.front(); + void *frame = ctx->buf_q.front(); ctx->buf_q.pop(); dbg("%s, frame %p\n", __func__, frame); int i; - SHA256((unsigned char*)frame, ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, - result); + SHA256((unsigned char *)frame, + ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = ctx->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20_rx_error_sha", result); @@ -1809,28 +1891,30 @@ static void st20_digest_rx_frame_check(void* args) { } } -static void st20_digest_rx_field_check(void* args) { - auto ctx = (tests_context*)args; +static void st20_digest_rx_field_check(void *args) { + auto ctx = (tests_context *)args; std::unique_lock lck(ctx->mtx, std::defer_lock); unsigned char result[SHA256_DIGEST_LENGTH]; while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } else { - void* frame = ctx->buf_q.front(); + void *frame = ctx->buf_q.front(); bool second_field = ctx->second_field_q.front(); ctx->buf_q.pop(); ctx->second_field_q.pop(); dbg("%s, frame %p\n", __func__, frame); int i; - SHA256((unsigned char*)frame, ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, - result); + SHA256((unsigned char *)frame, + ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = ctx->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20_rx_error_sha", result); @@ -1847,32 +1931,34 @@ static void st20_digest_rx_field_check(void* args) { } } -static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], - enum st20_packing packing[], enum st_fps fps[], - int width[], int height[], bool interlaced[], - enum st20_fmt fmt[], bool check_fps, - enum st_test_level level, int sessions = 1, - bool out_of_order = false, bool hdr_split = false, - bool enable_rtcp = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void +st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], + enum st20_packing packing[], enum st_fps fps[], int width[], + int height[], bool interlaced[], enum st20_fmt fmt[], + bool check_fps, enum st_test_level level, int sessions = 1, + bool out_of_order = false, bool hdr_split = false, + bool enable_rtcp = false) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } bool has_dma = st_test_dma_available(ctx); - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -1907,11 +1993,11 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); if (hdr_split) @@ -1928,7 +2014,8 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type ops_tx.fmt = fmt[i]; ops_tx.payload_type = ST20_TEST_PAYLOAD_TYPE; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; - ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = + interlaced[i] ? tx_next_video_field : tx_next_video_frame; ops_tx.query_frame_lines_ready = tx_frame_lines_ready; if (tx_type[i] == ST20_TYPE_RTP_LEVEL) { rtp_tx_specific_init(&ops_tx, test_ctx_tx[i]); @@ -1940,8 +2027,8 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type // out of order if (out_of_order) { - test_ctx_tx[i]->ooo_mapping = - (int*)st_test_zmalloc(sizeof(int) * test_ctx_tx[i]->total_pkts_in_frame); + test_ctx_tx[i]->ooo_mapping = (int *)st_test_zmalloc( + sizeof(int) * test_ctx_tx[i]->total_pkts_in_frame); ASSERT_TRUE(test_ctx_tx[i]->ooo_mapping != NULL); tx_video_build_ooo_mapping(test_ctx_tx[i]); } @@ -1953,29 +2040,33 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) frame_size = frame_size >> 1; + size_t frame_size = + ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) + frame_size = frame_size >> 1; if (tx_type[i] == ST20_TYPE_FRAME_LEVEL) { EXPECT_EQ(st20_tx_get_framebuffer_size(tx_handle[i]), frame_size); - EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), test_ctx_tx[i]->fb_cnt); + EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), + test_ctx_tx[i]->fb_cnt); } test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->slice = (tx_type[i] == ST20_TYPE_SLICE_LEVEL); test_ctx_tx[i]->lines_per_slice = ops_tx.height / 30; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { if (tx_type[i] == ST20_TYPE_FRAME_LEVEL) { - fb = (uint8_t*)st20_tx_get_framebuffer(tx_handle[i], frame); + fb = (uint8_t *)st20_tx_get_framebuffer(tx_handle[i], frame); } else { - test_ctx_tx[i]->frame_buf[frame] = (uint8_t*)st_test_zmalloc(frame_size); + test_ctx_tx[i]->frame_buf[frame] = + (uint8_t *)st_test_zmalloc(frame_size); fb = test_ctx_tx[i]->frame_buf[frame]; } ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st20_rx", result); } test_ctx_tx[i]->handle = tx_handle[i]; @@ -2026,7 +2117,8 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type ops_rx.notify_rtp_ready = rx_rtp_ready; ops_rx.rtp_ring_size = 1024 * 2; ops_rx.flags = ST20_RX_FLAG_DMA_OFFLOAD; - if (hdr_split) ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (hdr_split) + ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; if (enable_rtcp) { ops_rx.flags |= ST20_RX_FLAG_ENABLE_RTCP | ST20_RX_FLAG_SIMULATE_PKT_LOSS; ops_rx.rtcp.nack_interval_us = 250; @@ -2038,8 +2130,8 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { /* set expect meta data to private */ - auto meta = - (struct st20_rx_slice_meta*)st_test_zmalloc(sizeof(struct st20_rx_slice_meta)); + auto meta = (struct st20_rx_slice_meta *)st_test_zmalloc( + sizeof(struct st20_rx_slice_meta)); ASSERT_TRUE(meta != NULL); meta->width = ops_rx.width; meta->height = ops_rx.height; @@ -2072,9 +2164,11 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type } else { test_ctx_rx[i]->stop = false; if (interlaced[i]) { - rtp_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + rtp_thread_rx[i] = + std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - rtp_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + rtp_thread_rx[i] = + std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } } @@ -2096,7 +2190,8 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (tx_type[i] == ST20_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -2115,7 +2210,7 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type if (rx_type[i] == ST20_TYPE_RTP_LEVEL) { sha_check[i].join(); while (!test_ctx_rx[i]->buf_q.empty()) { - void* frame = test_ctx_rx[i]->buf_q.front(); + void *frame = test_ctx_rx[i]->buf_q.front(); st_test_free(frame); test_ctx_rx[i]->buf_q.pop(); } @@ -2144,8 +2239,10 @@ static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type test_ctx_rx[i]->fb_rec, framerate[i], test_ctx_tx[i]->fb_send); if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { int expect_slice_cnt = test_ctx_rx[i]->fb_rec * slices_per_frame; - if (interlaced[i]) expect_slice_cnt /= 2; - EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, expect_slice_cnt * 0.1); + if (interlaced[i]) + expect_slice_cnt /= 2; + EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, + expect_slice_cnt * 0.1); } if (check_fps) { EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); @@ -2170,8 +2267,8 @@ TEST(St20_rx, digest_frame_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest20_field_1080p_fps59_94_s1) { @@ -2183,8 +2280,8 @@ TEST(St20_rx, digest20_field_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_720p_fps59_94_s1_gpm) { @@ -2196,8 +2293,8 @@ TEST(St20_rx, digest_frame_720p_fps59_94_s1_gpm) { int height[1] = {720}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest20_field_720p_fps59_94_s1_gpm) { @@ -2209,8 +2306,8 @@ TEST(St20_rx, digest20_field_720p_fps59_94_s1_gpm) { int height[1] = {720}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_720p_fps29_97_s1_bpm) { @@ -2222,8 +2319,8 @@ TEST(St20_rx, digest_frame_720p_fps29_97_s1_bpm) { int height[1] = {720}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest20_field_720p_fps29_97_s1_bpm) { @@ -2235,8 +2332,8 @@ TEST(St20_rx, digest20_field_720p_fps29_97_s1_bpm) { int height[1] = {720}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_rtp_1080p_fps59_94_s1) { @@ -2248,8 +2345,8 @@ TEST(St20_rx, digest_rtp_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_720p_fps59_94_s3) { @@ -2265,8 +2362,8 @@ TEST(St20_rx, digest_frame_720p_fps59_94_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest20_field_720p_fps59_94_s3) { @@ -2282,8 +2379,8 @@ TEST(St20_rx, digest20_field_720p_fps59_94_s3) { bool interlaced[3] = {true, false, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest_frame_1080p_fps_mix_s3) { @@ -2299,8 +2396,8 @@ TEST(St20_rx, digest_frame_1080p_fps_mix_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest20_field_1080p_fps59_94_s3) { @@ -2316,8 +2413,8 @@ TEST(St20_rx, digest20_field_1080p_fps59_94_s3) { bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest_frame_1080p_fps59_94_s4_8bit) { @@ -2333,8 +2430,8 @@ TEST(St20_rx, digest_frame_1080p_fps59_94_s4_8bit) { bool interlaced[4] = {false, false, false, false}; enum st20_fmt fmt[4] = {ST20_FMT_YUV_422_8BIT, ST20_FMT_YUV_420_8BIT, ST20_FMT_YUV_444_8BIT, ST20_FMT_RGB_8BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 4); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 4); } TEST(St20_rx, digest20_field_4320p_fps59_94_s1) { @@ -2346,8 +2443,8 @@ TEST(St20_rx, digest20_field_4320p_fps59_94_s1) { int height[1] = {1080 * 4}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_s3) { @@ -2363,8 +2460,8 @@ TEST(St20_rx, digest_frame_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, digest_frame_field_s3) { @@ -2380,8 +2477,8 @@ TEST(St20_rx, digest_frame_field_s3) { bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest_frame_rtp_s3) { @@ -2397,8 +2494,8 @@ TEST(St20_rx, digest_frame_rtp_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, digest_frame_s4_8bit) { @@ -2408,14 +2505,15 @@ TEST(St20_rx, digest_frame_s4_8bit) { ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st20_packing packing[4] = {ST20_PACKING_GPM_SL, ST20_PACKING_GPM_SL, ST20_PACKING_BPM, ST20_PACKING_GPM}; - enum st_fps fps[4] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P59_94, ST_FPS_P119_88}; + enum st_fps fps[4] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P59_94, + ST_FPS_P119_88}; int width[4] = {1920, 1920, 1920, 1280}; int height[4] = {1080, 1080, 1080, 720}; bool interlaced[4] = {false, false, false, false}; enum st20_fmt fmt[4] = {ST20_FMT_YUV_422_8BIT, ST20_FMT_YUV_420_8BIT, ST20_FMT_YUV_444_8BIT, ST20_FMT_RGB_8BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 4); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 4); } TEST(St20_rx, digest_frame_s4_10bit) { @@ -2423,16 +2521,16 @@ TEST(St20_rx, digest_frame_s4_10bit) { ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st20_type rx_type[4] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; - enum st20_packing packing[4] = {ST20_PACKING_GPM_SL, ST20_PACKING_GPM, ST20_PACKING_BPM, - ST20_PACKING_BPM}; + enum st20_packing packing[4] = {ST20_PACKING_GPM_SL, ST20_PACKING_GPM, + ST20_PACKING_BPM, ST20_PACKING_BPM}; enum st_fps fps[4] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P59_94, ST_FPS_P50}; int width[4] = {1920, 1920, 1920, 1280}; int height[4] = {1080, 1080, 1080, 720}; bool interlaced[4] = {false, false, false, false}; enum st20_fmt fmt[4] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_420_10BIT, ST20_FMT_YUV_444_10BIT, ST20_FMT_RGB_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 4); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 4); } TEST(St20_rx, digest_rtp_s3) { @@ -2448,8 +2546,8 @@ TEST(St20_rx, digest_rtp_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, digest_ooo_frame_s3) { @@ -2465,8 +2563,8 @@ TEST(St20_rx, digest_ooo_frame_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 3, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 3, true); } TEST(St20_rx, digest_tx_slice_s3) { @@ -2482,8 +2580,8 @@ TEST(St20_rx, digest_tx_slice_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 3, false); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 3, false); } TEST(St20_rx, digest_slice_s3) { @@ -2499,8 +2597,8 @@ TEST(St20_rx, digest_slice_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 3, false); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 3, false); } TEST(St20_rx, digest20_field_slice_s3) { @@ -2516,8 +2614,8 @@ TEST(St20_rx, digest20_field_slice_s3) { bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL, 3, false); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 3, false); } TEST(St20_rx, digest_ooo_slice_s3) { @@ -2533,8 +2631,8 @@ TEST(St20_rx, digest_ooo_slice_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 3, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 3, true); } TEST(St20_rx, digest_frame_4320p_fps59_94_s1) { @@ -2546,8 +2644,8 @@ TEST(St20_rx, digest_frame_4320p_fps59_94_s1) { int height[1] = {1080 * 4}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_4096_2160_fps59_94_12bit_yuv444_s1) { @@ -2559,8 +2657,8 @@ TEST(St20_rx, digest_frame_4096_2160_fps59_94_12bit_yuv444_s1) { int height[1] = {2160}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_444_12BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 1); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 1); } TEST(St20_rx, digest_slice_4320p) { @@ -2573,8 +2671,8 @@ TEST(St20_rx, digest_slice_4320p) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; if (st_test_dma_available(st_test_ctx())) { - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, - false, ST_TEST_LEVEL_ALL, 1); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_ALL, 1); } else { info("%s, skip as no dma available\n", __func__); } @@ -2590,8 +2688,8 @@ TEST(St20_rx, digest_ooo_slice_4320p) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; if (st_test_dma_available(st_test_ctx())) { - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, - false, ST_TEST_LEVEL_MANDATORY, 1, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 1, true); } else { info("%s, skip as no dma available\n", __func__); } @@ -2607,8 +2705,8 @@ TEST(St20_rx, digest_hdr_split) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; if (st_test_ctx()->hdr_split) { - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, - false, ST_TEST_LEVEL_MANDATORY, 1, false, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, + fmt, false, ST_TEST_LEVEL_MANDATORY, 1, false, true); } else { info("%s, skip as no dma available\n", __func__); } @@ -2623,8 +2721,8 @@ TEST(St20_rx, digest_rtcp_s1) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; /* check fps */ - st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL, 1, false, false, true); + st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, + true, ST_TEST_LEVEL_ALL, 1, false, false, true); } TEST(St20_rx, digest_rtcp_s3) { @@ -2639,31 +2737,34 @@ TEST(St20_rx, digest_rtcp_s3) { enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; /* no fps check */ - st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, false, - ST_TEST_LEVEL_MANDATORY, 3, false, false, true); + st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, + false, ST_TEST_LEVEL_MANDATORY, 3, false, false, true); } -static int st20_tx_meta_build_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* rtp, - uint16_t* pkt_len) { - struct st20_rfc4175_extra_rtp_hdr* e_rtp = NULL; +static int st20_tx_meta_build_rtp(tests_context *s, + struct st20_rfc4175_rtp_hdr *rtp, + uint16_t *pkt_len) { + struct st20_rfc4175_extra_rtp_hdr *e_rtp = NULL; int offset; int frame_size = s->frame_size; uint16_t row_number, row_offset; - uint8_t* payload = (uint8_t*)rtp + sizeof(*rtp); + uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); int pkt_idx = s->pkt_idx; if (s->single_line) { row_number = pkt_idx / s->pkts_in_line; int pixels_in_pkt = s->pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; row_offset = pixels_in_pkt * (pkt_idx % s->pkts_in_line); - offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; + offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * + s->st20_pg.size; } else { offset = s->pkt_data_len * pkt_idx; row_number = offset / s->bytes_in_line; - row_offset = (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; + row_offset = + (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; if ((offset + s->pkt_data_len > (row_number + 1) * s->bytes_in_line) && (offset + s->pkt_data_len < frame_size)) { - e_rtp = (struct st20_rfc4175_extra_rtp_hdr*)payload; + e_rtp = (struct st20_rfc4175_extra_rtp_hdr *)payload; payload += sizeof(*e_rtp); } } @@ -2682,9 +2783,10 @@ static int st20_tx_meta_build_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* rtp->base.seq_number = htons(s->seq_id); rtp->seq_number_ext = htons((uint16_t)(s->seq_id >> 16)); s->seq_id++; - int temp = s->single_line - ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (frame_size - offset); + int temp = + s->single_line + ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (frame_size - offset); uint16_t data_len = s->pkt_data_len > temp ? temp : s->pkt_data_len; rtp->row_length = htons(data_len); *pkt_len = data_len + sizeof(*rtp); @@ -2702,9 +2804,11 @@ static int st20_tx_meta_build_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* s->pkt_idx++; /* build incomplete frame */ - if (s->pkt_idx >= s->total_pkts_in_frame) marker = true; + if (s->pkt_idx >= s->total_pkts_in_frame) + marker = true; if (s->fb_send % 2) { - if (s->pkt_idx >= (s->total_pkts_in_frame / 2)) marker = true; + if (s->pkt_idx >= (s->total_pkts_in_frame / 2)) + marker = true; } if (marker) { /* end of current frame */ @@ -2718,10 +2822,10 @@ static int st20_tx_meta_build_rtp(tests_context* s, struct st20_rfc4175_rtp_hdr* return 0; } -static void st20_rx_meta_feed_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void st20_rx_meta_feed_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); while (!ctx->stop) { @@ -2734,39 +2838,50 @@ static void st20_rx_meta_feed_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - st20_tx_meta_build_rtp(ctx, (struct st20_rfc4175_rtp_hdr*)usrptr, &mbuf_len); + st20_tx_meta_build_rtp(ctx, (struct st20_rfc4175_rtp_hdr *)usrptr, + &mbuf_len); st20_tx_put_mbuf((st20_tx_handle)ctx->handle, mbuf, mbuf_len); } } -static int st20_rx_meta_frame_ready(void* priv, void* frame, - struct st20_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; - auto expect_meta = (struct st20_rx_frame_meta*)ctx->priv; +static int st20_rx_meta_frame_ready(void *priv, void *frame, + struct st20_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; + auto expect_meta = (struct st20_rx_frame_meta *)ctx->priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; ctx->fb_rec++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); - if (expect_meta->width != meta->width) ctx->rx_meta_fail_cnt++; - if (expect_meta->height != meta->height) ctx->rx_meta_fail_cnt++; - if (expect_meta->fps != meta->fps) ctx->rx_meta_fail_cnt++; - if (expect_meta->fmt != meta->fmt) ctx->rx_meta_fail_cnt++; - if (expect_meta->timestamp == meta->timestamp) ctx->rx_meta_fail_cnt++; + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); + if (expect_meta->width != meta->width) + ctx->rx_meta_fail_cnt++; + if (expect_meta->height != meta->height) + ctx->rx_meta_fail_cnt++; + if (expect_meta->fps != meta->fps) + ctx->rx_meta_fail_cnt++; + if (expect_meta->fmt != meta->fmt) + ctx->rx_meta_fail_cnt++; + if (expect_meta->timestamp == meta->timestamp) + ctx->rx_meta_fail_cnt++; expect_meta->timestamp = meta->timestamp; if (!st_is_frame_complete(meta->status)) { ctx->incomplete_frame_cnt++; - if (meta->frame_total_size <= meta->frame_recv_size) ctx->rx_meta_fail_cnt++; + if (meta->frame_total_size <= meta->frame_recv_size) + ctx->rx_meta_fail_cnt++; } else { - if (meta->frame_total_size != meta->frame_recv_size) ctx->rx_meta_fail_cnt++; + if (meta->frame_total_size != meta->frame_recv_size) + ctx->rx_meta_fail_cnt++; } st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); @@ -2775,19 +2890,20 @@ static int st20_rx_meta_frame_ready(void* priv, void* frame, static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], enum st20_fmt fmt, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -2816,11 +2932,11 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -2870,7 +2986,8 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], ops_rx.fps = fps[i]; ops_rx.fmt = fmt; ops_rx.payload_type = ST20_TEST_PAYLOAD_TYPE; - ops_rx.flags = ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; + ops_rx.flags = + ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st20_rx_meta_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -2881,8 +2998,8 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->stop = false; /* set expect meta data to private */ - auto meta = - (struct st20_rx_frame_meta*)st_test_zmalloc(sizeof(struct st20_rx_frame_meta)); + auto meta = (struct st20_rx_frame_meta *)st_test_zmalloc( + sizeof(struct st20_rx_frame_meta)); ASSERT_TRUE(meta != NULL); meta->width = ops_rx.width; meta->height = ops_rx.height; @@ -2900,7 +3017,8 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; /* stop all thread */ @@ -2919,12 +3037,13 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); float expect_incomplete_frame_cnt = (float)test_ctx_rx[i]->fb_rec / 2; - EXPECT_NEAR(test_ctx_rx[i]->incomplete_frame_cnt, expect_incomplete_frame_cnt, - expect_incomplete_frame_cnt * 0.1); + EXPECT_NEAR(test_ctx_rx[i]->incomplete_frame_cnt, + expect_incomplete_frame_cnt, expect_incomplete_frame_cnt * 0.1); EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); EXPECT_EQ(test_ctx_rx[i]->rx_meta_fail_cnt, 0); - info("%s, session %d fb_rec %d fb_incomplete %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->incomplete_frame_cnt, framerate[i]); + info("%s, session %d fb_rec %d fb_incomplete %d framerate %f\n", __func__, + i, test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->incomplete_frame_cnt, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); @@ -2945,25 +3064,28 @@ TEST(St20_rx, frame_meta_1080p_fps59_94_s1) { } static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], - int width[], int height[], enum st20_fmt fmt, - int sessions, int repeat, enum st_test_level level) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + int width[], int height[], + enum st20_fmt fmt, int sessions, + int repeat, enum st_test_level level) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -2998,11 +3120,11 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3040,11 +3162,11 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3075,7 +3197,8 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; /* stop rx rtp if */ @@ -3091,8 +3214,8 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_rx_free(rx_handle[i]); EXPECT_GE(ret, 0); @@ -3132,8 +3255,8 @@ TEST(St20_rx, after_start_frame_720p_fps50_s1_r1) { enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1280}; int height[1] = {720}; - st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, 1, - ST_TEST_LEVEL_MANDATORY); + st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, + 1, ST_TEST_LEVEL_MANDATORY); } TEST(St20_rx, after_start_frame_720p_fps29_97_s1_r2) { @@ -3141,20 +3264,20 @@ TEST(St20_rx, after_start_frame_720p_fps29_97_s1_r2) { enum st_fps fps[1] = {ST_FPS_P29_97}; int width[1] = {1280}; int height[1] = {720}; - st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, 2, - ST_TEST_LEVEL_ALL); + st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, + 2, ST_TEST_LEVEL_ALL); } -static int st20_rx_uframe_pg_callback(void* priv, void* frame, - struct st20_rx_uframe_pg_meta* meta) { +static int st20_rx_uframe_pg_callback(void *priv, void *frame, + struct st20_rx_uframe_pg_meta *meta) { uint32_t w = meta->width; uint32_t h = meta->height; - uint16_t* p10_u16 = (uint16_t*)frame; - uint16_t* p10_u16_y = p10_u16; - uint16_t* p10_u16_b = p10_u16 + w * h; - uint16_t* p10_u16_r = p10_u16 + w * h * 3 / 2; - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)meta->payload; + uint16_t *p10_u16 = (uint16_t *)frame; + uint16_t *p10_u16_y = p10_u16; + uint16_t *p10_u16_b = p10_u16 + w * h; + uint16_t *p10_u16_r = p10_u16 + w * h * 3 / 2; + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)meta->payload; uint32_t p10_offset = meta->row_number * w + meta->row_offset; p10_u16_y += p10_offset; p10_u16_b += p10_offset / 2; @@ -3165,27 +3288,30 @@ static int st20_rx_uframe_pg_callback(void* priv, void* frame, return 0; } -static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing packing[], - enum st_fps fps[], int width[], int height[], - bool interlaced[], enum st20_fmt fmt, bool check_fps, +static void st20_rx_uframe_test(enum st20_type rx_type[], + enum st20_packing packing[], enum st_fps fps[], + int width[], int height[], bool interlaced[], + enum st20_fmt fmt, bool check_fps, enum st_test_level level, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -3218,11 +3344,11 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing pack ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3236,7 +3362,8 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing pack ops_tx.fmt = fmt; ops_tx.payload_type = ST20_TEST_PAYLOAD_TYPE; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; - ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = + interlaced[i] ? tx_next_video_field : tx_next_video_frame; tx_handle[i] = st20_tx_create(m_handle, &ops_tx); ASSERT_TRUE(tx_handle[i] != NULL); @@ -3244,32 +3371,37 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing pack /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) frame_size = frame_size >> 1; + size_t frame_size = + ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) + frame_size = frame_size >> 1; test_ctx_tx[i]->frame_size = frame_size; /* uframe fmt: yuv422 10bit planar */ - size_t uframe_size = (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); - if (interlaced[i]) uframe_size = uframe_size >> 1; + size_t uframe_size = + (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); + if (interlaced[i]) + uframe_size = uframe_size >> 1; test_ctx_tx[i]->uframe_size = uframe_size; test_ctx_tx[i]->slice = false; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - test_ctx_tx[i]->frame_buf[frame] = (uint8_t*)st_test_zmalloc(uframe_size); + test_ctx_tx[i]->frame_buf[frame] = + (uint8_t *)st_test_zmalloc(uframe_size); fb = test_ctx_tx[i]->frame_buf[frame]; ASSERT_TRUE(fb != NULL); - uint16_t* p10_u16 = (uint16_t*)fb; + uint16_t *p10_u16 = (uint16_t *)fb; for (size_t i = 0; i < (uframe_size / 2); i++) { p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, uframe_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, uframe_size, result); test_sha_dump("st20_rx", result); - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st20_tx_get_framebuffer(tx_handle[i], - frame); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st20_tx_get_framebuffer( + tx_handle[i], frame); st20_yuv422p10le_to_rfc4175_422be10( p10_u16, (p10_u16 + ops_tx.width * ops_tx.height), (p10_u16 + ops_tx.width * ops_tx.height * 3 / 2), pg, ops_tx.width, @@ -3317,14 +3449,15 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing pack ops_rx.notify_rtp_ready = rx_rtp_ready; ops_rx.rtp_ring_size = 1024 * 2; /* uframe fmt: yuv422 10bit planar */ - ops_rx.uframe_size = (size_t)ops_rx.width * ops_rx.height * 2 * sizeof(uint16_t); + ops_rx.uframe_size = + (size_t)ops_rx.width * ops_rx.height * 2 * sizeof(uint16_t); ops_rx.uframe_pg_callback = st20_rx_uframe_pg_callback; ops_rx.flags = ST20_RX_FLAG_DMA_OFFLOAD; if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { /* set expect meta data to private */ - auto meta = - (struct st20_rx_slice_meta*)st_test_zmalloc(sizeof(struct st20_rx_slice_meta)); + auto meta = (struct st20_rx_slice_meta *)st_test_zmalloc( + sizeof(struct st20_rx_slice_meta)); ASSERT_TRUE(meta != NULL); meta->width = ops_rx.width; meta->height = ops_rx.height; @@ -3350,9 +3483,11 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing pack test_ctx_rx[i]->handle = rx_handle[i]; test_ctx_rx[i]->stop = false; if (interlaced[i]) { - digest_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + digest_thread_rx[i] = + std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - digest_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + digest_thread_rx[i] = + std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } } @@ -3363,7 +3498,8 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing pack for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -3384,12 +3520,14 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing pack EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); else EXPECT_LE(test_ctx_rx[i]->sha_fail_cnt, 2); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { int expect_slice_cnt = test_ctx_rx[i]->fb_rec * slices_per_frame; - if (interlaced[i]) expect_slice_cnt /= 2; - EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, expect_slice_cnt * 0.1); + if (interlaced[i]) + expect_slice_cnt /= 2; + EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, + expect_slice_cnt * 0.1); } if (check_fps) { EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); @@ -3427,48 +3565,56 @@ TEST(St20_rx, uframe_mix_s2) { ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_MANDATORY, 1); } -static int st20_rx_detected(void* priv, const struct st20_detect_meta* meta, - struct st20_detect_reply* reply) { - auto ctx = (tests_context*)priv; +static int st20_rx_detected(void *priv, const struct st20_detect_meta *meta, + struct st20_detect_reply *reply) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ - struct st20_rx_slice_meta* s_meta = (struct st20_rx_slice_meta*)ctx->priv; + struct st20_rx_slice_meta *s_meta = (struct st20_rx_slice_meta *)ctx->priv; ctx->lines_per_slice = meta->height / 32; - if (s_meta) reply->slice_lines = ctx->lines_per_slice; + if (s_meta) + reply->slice_lines = ctx->lines_per_slice; if (ctx->uframe_size != 0) { /* uframe fmt: yuv422 10bit planar */ - ctx->uframe_size = (size_t)meta->width * meta->height * 2 * sizeof(uint16_t); + ctx->uframe_size = + (size_t)meta->width * meta->height * 2 * sizeof(uint16_t); reply->uframe_size = ctx->uframe_size; - if (s_meta) s_meta->uframe_total_size = ctx->uframe_size; + if (s_meta) + s_meta->uframe_total_size = ctx->uframe_size; } return 0; } -static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type[], +static void st20_rx_detect_test(enum st20_type tx_type[], + enum st20_type rx_type[], enum st20_packing packing[], enum st_fps fps[], int width[], int height[], bool interlaced[], - bool user_frame, enum st20_fmt fmt, bool check_fps, - enum st_test_level level, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + bool user_frame, enum st20_fmt fmt, + bool check_fps, enum st_test_level level, + int sessions = 1) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -3503,11 +3649,11 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3521,7 +3667,8 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type ops_tx.fmt = fmt; ops_tx.payload_type = ST20_TEST_PAYLOAD_TYPE; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; - ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = + interlaced[i] ? tx_next_video_field : tx_next_video_frame; ops_tx.query_frame_lines_ready = tx_frame_lines_ready; tx_handle[i] = st20_tx_create(m_handle, &ops_tx); @@ -3530,33 +3677,38 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) frame_size = frame_size >> 1; + size_t frame_size = + ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) + frame_size = frame_size >> 1; test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; - uint8_t* fb; + uint8_t *fb; if (user_frame) { /* uframe fmt: yuv422 10bit planar */ - size_t uframe_size = (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); - if (interlaced[i]) uframe_size = uframe_size >> 1; + size_t uframe_size = + (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); + if (interlaced[i]) + uframe_size = uframe_size >> 1; test_ctx_tx[i]->uframe_size = uframe_size; test_ctx_tx[i]->slice = false; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - test_ctx_tx[i]->frame_buf[frame] = (uint8_t*)st_test_zmalloc(uframe_size); + test_ctx_tx[i]->frame_buf[frame] = + (uint8_t *)st_test_zmalloc(uframe_size); fb = test_ctx_tx[i]->frame_buf[frame]; ASSERT_TRUE(fb != NULL); - uint16_t* p10_u16 = (uint16_t*)fb; + uint16_t *p10_u16 = (uint16_t *)fb; for (size_t i = 0; i < (uframe_size / 2); i++) { p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, uframe_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, uframe_size, result); test_sha_dump("st20_rx", result); - struct st20_rfc4175_422_10_pg2_be* pg = - (struct st20_rfc4175_422_10_pg2_be*)st20_tx_get_framebuffer(tx_handle[i], - frame); + struct st20_rfc4175_422_10_pg2_be *pg = + (struct st20_rfc4175_422_10_pg2_be *)st20_tx_get_framebuffer( + tx_handle[i], frame); st20_yuv422p10le_to_rfc4175_422be10( p10_u16, (p10_u16 + ops_tx.width * ops_tx.height), (p10_u16 + ops_tx.width * ops_tx.height * 3 / 2), pg, ops_tx.width, @@ -3566,11 +3718,11 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type test_ctx_tx[i]->lines_per_slice = ops_tx.height / 30; test_ctx_tx[i]->slice = (tx_type[i] == ST20_TYPE_SLICE_LEVEL); for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - fb = (uint8_t*)st20_tx_get_framebuffer(tx_handle[i], frame); + fb = (uint8_t *)st20_tx_get_framebuffer(tx_handle[i], frame); ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st20_rx", result); } } @@ -3624,8 +3776,8 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { /* set expect meta data to private */ - auto meta = - (struct st20_rx_slice_meta*)st_test_zmalloc(sizeof(struct st20_rx_slice_meta)); + auto meta = (struct st20_rx_slice_meta *)st_test_zmalloc( + sizeof(struct st20_rx_slice_meta)); ASSERT_TRUE(meta != NULL); meta->width = width[i]; meta->height = height[i]; @@ -3652,9 +3804,11 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type test_ctx_rx[i]->handle = rx_handle[i]; test_ctx_rx[i]->stop = false; if (interlaced[i]) { - rtp_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + rtp_thread_rx[i] = + std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - rtp_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + rtp_thread_rx[i] = + std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } } @@ -3665,7 +3819,8 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -3689,12 +3844,14 @@ static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); else EXPECT_LE(test_ctx_rx[i]->sha_fail_cnt, 2); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { int expect_slice_cnt = test_ctx_rx[i]->fb_rec * slices_per_frame; - if (interlaced[i]) expect_slice_cnt /= 2; - EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, expect_slice_cnt * 0.1); + if (interlaced[i]) + expect_slice_cnt /= 2; + EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, + expect_slice_cnt * 0.1); } if (check_fps) { EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); @@ -3719,8 +3876,9 @@ TEST(St20_rx, detect_1080p_fps59_94_s1) { int width[1] = {1920}; int height[1] = {1080}; bool interlaced[1] = {false}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, false, - ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_ALL, 1); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, + false, ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_ALL, + 1); } TEST(St20_rx, detect_uframe_mix_s2) { @@ -3731,8 +3889,9 @@ TEST(St20_rx, detect_uframe_mix_s2) { int width[2] = {1280, 1280}; int height[2] = {720, 720}; bool interlaced[2] = {false, false}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, true, - ST20_FMT_YUV_422_10BIT, false, ST_TEST_LEVEL_MANDATORY, 2); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, + true, ST20_FMT_YUV_422_10BIT, false, + ST_TEST_LEVEL_MANDATORY, 2); } TEST(St20_rx, detect_mix_frame_s3) { @@ -3746,8 +3905,9 @@ TEST(St20_rx, detect_mix_frame_s3) { int width[3] = {1280, 1920, 3840}; int height[3] = {720, 1080, 2160}; bool interlaced[3] = {false, false, true}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, false, - ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, + false, ST20_FMT_YUV_422_10BIT, true, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, detect_mix_slice_s3) { @@ -3761,19 +3921,22 @@ TEST(St20_rx, detect_mix_slice_s3) { int width[3] = {1280, 1920, 3840}; int height[3] = {720, 1080, 2160}; bool interlaced[3] = {false, false, true}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, false, - ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, + false, ST20_FMT_YUV_422_10BIT, true, + ST_TEST_LEVEL_MANDATORY, 3); } -static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], int width[], - int height[], enum st20_fmt fmt, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], + int width[], int height[], enum st20_fmt fmt, + int sessions = 1) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } @@ -3783,8 +3946,8 @@ static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], int widt return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -3815,11 +3978,11 @@ static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], int widt ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3902,12 +4065,14 @@ static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], int widt EXPECT_GE(ret, 0); EXPECT_EQ(meta.dumped_packets[MTL_SESSION_PORT_P], max_dump_packets); dbg("%s, file_name %s\n", __func__, meta.file_name[MTL_SESSION_PORT_P]); - if (ret >= 0) remove(meta.file_name[MTL_SESSION_PORT_P]); + if (ret >= 0) + remove(meta.file_name[MTL_SESSION_PORT_P]); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST20_TYPE_RTP_LEVEL) { @@ -3948,10 +4113,11 @@ TEST(St20_rx, pcap_dump) { st20_rx_dump_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 2); } -static int rx_query_ext_frame(void* priv, st20_ext_frame* ext_frame, - struct st20_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; - if (!ctx->handle) return -EIO; /* not ready */ +static int rx_query_ext_frame(void *priv, st20_ext_frame *ext_frame, + struct st20_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; + if (!ctx->handle) + return -EIO; /* not ready */ int i = ctx->ext_idx; /* check ext_fb_in_use */ @@ -3969,23 +4135,24 @@ static int rx_query_ext_frame(void* priv, st20_ext_frame* ext_frame, ext_frame->opaque = &ctx->ext_fb_in_use[i]; - if (++ctx->ext_idx >= ctx->fb_cnt) ctx->ext_idx = 0; + if (++ctx->ext_idx >= ctx->fb_cnt) + ctx->ext_idx = 0; return 0; } -static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], - enum st_fps fps[], int width[], int height[], - bool interlaced[], enum st20_fmt fmt[], - bool check_fps, enum st_test_level level, - int sessions = 1, bool dynamic = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st20_tx_ext_frame_rx_digest_test( + enum st20_packing packing[], enum st_fps fps[], int width[], int height[], + bool interlaced[], enum st20_fmt fmt[], bool check_fps, + enum st_test_level level, int sessions = 1, bool dynamic = false) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->iova == MTL_IOVA_MODE_PA) { info("%s, skip as it's PA iova mode\n", __func__); @@ -3993,15 +4160,16 @@ static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], } if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } bool has_dma = st_test_dma_available(ctx); - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -4035,11 +4203,11 @@ static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -4064,45 +4232,50 @@ static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) frame_size = frame_size >> 1; + size_t frame_size = + ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) + frame_size = frame_size >> 1; EXPECT_EQ(st20_tx_get_framebuffer_size(tx_handle[i]), frame_size); - EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), test_ctx_tx[i]->fb_cnt); + EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), + test_ctx_tx[i]->fb_cnt); test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; - test_ctx_tx[i]->ext_frames = (struct st20_ext_frame*)malloc( + test_ctx_tx[i]->ext_frames = (struct st20_ext_frame *)malloc( sizeof(*test_ctx_tx[i]->ext_frames) * test_ctx_tx[i]->fb_cnt); size_t pg_sz = mtl_page_size(m_handle); size_t fb_size = test_ctx_tx[i]->frame_size * test_ctx_tx[i]->fb_cnt; - test_ctx_tx[i]->ext_fb_iova_map_sz = mtl_size_page_align(fb_size, pg_sz); /* align */ + test_ctx_tx[i]->ext_fb_iova_map_sz = + mtl_size_page_align(fb_size, pg_sz); /* align */ size_t fb_size_malloc = test_ctx_tx[i]->ext_fb_iova_map_sz + pg_sz; test_ctx_tx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_malloc != NULL); test_ctx_tx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); - test_ctx_tx[i]->ext_fb_iova = - mtl_dma_map(m_handle, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); + test_ctx_tx[i]->ext_fb_iova = mtl_dma_map( + m_handle, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_iova != MTL_BAD_IOVA); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_tx[i]->ext_fb); for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { - test_ctx_tx[i]->ext_frames[j].buf_addr = test_ctx_tx[i]->ext_fb + j * frame_size; + test_ctx_tx[i]->ext_frames[j].buf_addr = + test_ctx_tx[i]->ext_fb + j * frame_size; test_ctx_tx[i]->ext_frames[j].buf_iova = test_ctx_tx[i]->ext_fb_iova + j * frame_size; test_ctx_tx[i]->ext_frames[j].buf_len = frame_size; } - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - fb = (uint8_t*)test_ctx_tx[i]->ext_fb + frame * frame_size; + fb = (uint8_t *)test_ctx_tx[i]->ext_fb + frame * frame_size; ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st20_rx", result); } @@ -4119,24 +4292,26 @@ static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], test_ctx_rx[i]->fb_idx = 0; test_ctx_rx[i]->check_sha = true; - test_ctx_rx[i]->ext_frames = (struct st20_ext_frame*)malloc( + test_ctx_rx[i]->ext_frames = (struct st20_ext_frame *)malloc( sizeof(*test_ctx_rx[i]->ext_frames) * test_ctx_rx[i]->fb_cnt); size_t frame_size = st20_frame_size(fmt[i], width[i], height[i]); size_t pg_sz = mtl_page_size(m_handle); size_t fb_size = frame_size * test_ctx_rx[i]->fb_cnt; - test_ctx_rx[i]->ext_fb_iova_map_sz = mtl_size_page_align(fb_size, pg_sz); /* align */ + test_ctx_rx[i]->ext_fb_iova_map_sz = + mtl_size_page_align(fb_size, pg_sz); /* align */ size_t fb_size_malloc = test_ctx_rx[i]->ext_fb_iova_map_sz + pg_sz; test_ctx_rx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = - mtl_dma_map(m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); + test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( + m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - test_ctx_rx[i]->ext_frames[j].buf_addr = test_ctx_rx[i]->ext_fb + j * frame_size; + test_ctx_rx[i]->ext_frames[j].buf_addr = + test_ctx_rx[i]->ext_fb + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_iova = test_ctx_rx[i]->ext_fb_iova + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_len = frame_size; @@ -4188,9 +4363,11 @@ static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], test_ctx_rx[i]->stop = false; if (interlaced[i]) { - rtp_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + rtp_thread_rx[i] = + std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - rtp_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + rtp_thread_rx[i] = + std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } bool dma_enabled = st20_rx_dma_enabled(rx_handle[i]); @@ -4211,7 +4388,8 @@ static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -4258,8 +4436,8 @@ TEST(St20_rx, ext_frame_digest_frame_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, + true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, ext_frame_digest20_field_1080p_fps59_94_s1) { @@ -4269,8 +4447,8 @@ TEST(St20_rx, ext_frame_digest20_field_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, + true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, ext_frame_digest_frame_720p_fps59_94_s1_gpm) { @@ -4280,66 +4458,73 @@ TEST(St20_rx, ext_frame_digest_frame_720p_fps59_94_s1_gpm) { int height[1] = {720}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_ALL); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, + true, ST_TEST_LEVEL_ALL); } TEST(St20_rx, ext_frame_s3) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, + ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_MANDATORY, 3); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, + true, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, ext_frame_s3_2) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, + ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; bool interlaced[3] = {true, false, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_12BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_8BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_MANDATORY, 3); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, + true, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, dynamic_ext_frame_s3) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, + ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P29_97}; int width[3] = {1280, 1280, 1920}; int height[3] = {720, 720, 1080}; bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, - ST_TEST_LEVEL_MANDATORY, 3, true); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, + true, ST_TEST_LEVEL_MANDATORY, 3, true); } -static void st20_tx_user_pacing_test(int width[], int height[], enum st20_fmt fmt[], - bool user_pacing[], bool user_timestamp[], - enum st_test_level level, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st20_tx_user_pacing_test(int width[], int height[], + enum st20_fmt fmt[], bool user_pacing[], + bool user_timestamp[], + enum st_test_level level, + int sessions = 1) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -4380,11 +4565,11 @@ static void st20_tx_user_pacing_test(int width[], int height[], enum st20_fmt fm ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -4400,8 +4585,10 @@ static void st20_tx_user_pacing_test(int width[], int height[], enum st20_fmt fm ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_next_video_frame_timestamp; ops_tx.notify_frame_done = tx_notify_timestamp_frame_done; - if (user_pacing[i]) ops_tx.flags |= ST20_TX_FLAG_USER_PACING; - if (user_timestamp[i]) ops_tx.flags |= ST20_TX_FLAG_USER_TIMESTAMP; + if (user_pacing[i]) + ops_tx.flags |= ST20_TX_FLAG_USER_PACING; + if (user_timestamp[i]) + ops_tx.flags |= ST20_TX_FLAG_USER_TIMESTAMP; tx_handle[i] = st20_tx_create(m_handle, &ops_tx); ASSERT_TRUE(tx_handle[i] != NULL); @@ -4409,17 +4596,18 @@ static void st20_tx_user_pacing_test(int width[], int height[], enum st20_fmt fm /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + size_t frame_size = + ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - fb = (uint8_t*)st20_tx_get_framebuffer(tx_handle[i], frame); + fb = (uint8_t *)st20_tx_get_framebuffer(tx_handle[i], frame); ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st20_rx", result); } test_ctx_tx[i]->handle = tx_handle[i]; @@ -4482,7 +4670,8 @@ static void st20_tx_user_pacing_test(int width[], int height[], enum st20_fmt fm for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; rx_framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; tx_framerate[i] = test_ctx_tx[i]->fb_send / time_sec; @@ -4502,13 +4691,15 @@ static void st20_tx_user_pacing_test(int width[], int height[], enum st20_fmt fm EXPECT_LT(test_ctx_rx[i]->incomplete_frame_cnt, 2); EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - rx_framerate[i]); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - tx_framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, rx_framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, tx_framerate[i]); - EXPECT_NEAR(tx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); - EXPECT_NEAR(rx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); + EXPECT_NEAR(tx_framerate[i], expect_framerate[i], + expect_framerate[i] * 0.1); + EXPECT_NEAR(rx_framerate[i], expect_framerate[i], + expect_framerate[i] * 0.1); ret = st20_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); ret = st20_rx_free(rx_handle[i]); @@ -4531,19 +4722,21 @@ TEST(St20_tx, tx_user_pacing) { ST_TEST_LEVEL_MANDATORY, 3); } -static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps fps[], - int width[], int height[], int linesize[], +static void st20_linesize_digest_test(enum st20_packing packing[], + enum st_fps fps[], int width[], + int height[], int linesize[], bool interlaced[], enum st20_fmt fmt[], bool check_fps, enum st_test_level level, int sessions = 1, bool ext = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ext) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -4553,15 +4746,16 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f } if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } bool has_dma = st_test_dma_available(ctx); - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -4591,11 +4785,11 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -4617,7 +4811,8 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f interlaced[i] ? tx_next_ext_video_field : tx_next_ext_video_frame; ops_tx.notify_frame_done = tx_notify_ext_frame_done; } else { - ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = + interlaced[i] ? tx_next_video_field : tx_next_video_frame; } tx_handle[i] = st20_tx_create(m_handle, &ops_tx); @@ -4626,8 +4821,10 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) frame_size = frame_size >> 1; + size_t frame_size = + ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) + frame_size = frame_size >> 1; test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; @@ -4636,14 +4833,16 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f if (linesize[i] > test_ctx_tx[i]->stride) { test_ctx_tx[i]->stride = linesize[i]; fb_size = (size_t)linesize[i] * height[i]; - if (interlaced[i]) fb_size = fb_size >> 1; + if (interlaced[i]) + fb_size = fb_size >> 1; } test_ctx_tx[i]->fb_size = fb_size; EXPECT_EQ(st20_tx_get_framebuffer_size(tx_handle[i]), fb_size); - EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), test_ctx_tx[i]->fb_cnt); + EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), + test_ctx_tx[i]->fb_cnt); if (ext) { - test_ctx_tx[i]->ext_frames = (struct st20_ext_frame*)malloc( + test_ctx_tx[i]->ext_frames = (struct st20_ext_frame *)malloc( sizeof(*test_ctx_tx[i]->ext_frames) * test_ctx_tx[i]->fb_cnt); size_t fbs_size = fb_size * test_ctx_tx[i]->fb_cnt; mtl_dma_mem_handle dma_mem = mtl_dma_mem_alloc(m_handle, fbs_size); @@ -4652,30 +4851,34 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { test_ctx_tx[i]->ext_frames[j].buf_addr = - (uint8_t*)mtl_dma_mem_addr(dma_mem) + j * fb_size; - test_ctx_tx[i]->ext_frames[j].buf_iova = mtl_dma_mem_iova(dma_mem) + j * fb_size; + (uint8_t *)mtl_dma_mem_addr(dma_mem) + j * fb_size; + test_ctx_tx[i]->ext_frames[j].buf_iova = + mtl_dma_mem_iova(dma_mem) + j * fb_size; test_ctx_tx[i]->ext_frames[j].buf_len = fb_size; } } - uint8_t* fb; + uint8_t *fb; int total_lines = height[i]; - size_t bytes_per_line = (size_t)ops_tx.width / st20_pg.coverage * st20_pg.size; - if (interlaced[i]) total_lines /= 2; + size_t bytes_per_line = + (size_t)ops_tx.width / st20_pg.coverage * st20_pg.size; + if (interlaced[i]) + total_lines /= 2; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { if (ext) { - fb = (uint8_t*)test_ctx_tx[i]->ext_frames[frame].buf_addr; + fb = (uint8_t *)test_ctx_tx[i]->ext_frames[frame].buf_addr; } else { - fb = (uint8_t*)st20_tx_get_framebuffer(tx_handle[i], frame); + fb = (uint8_t *)st20_tx_get_framebuffer(tx_handle[i], frame); } ASSERT_TRUE(fb != NULL); for (int line = 0; line < total_lines; line++) { - st_test_rand_data(fb + test_ctx_tx[i]->stride * line, bytes_per_line, frame); + st_test_rand_data(fb + test_ctx_tx[i]->stride * line, bytes_per_line, + frame); } - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, fb_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, fb_size, result); test_sha_dump("st20_rx", result); } @@ -4696,7 +4899,7 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f test_ctx_rx[i]->frame_size = test_ctx_tx[i]->frame_size; if (ext) { - test_ctx_rx[i]->ext_frames = (struct st20_ext_frame*)malloc( + test_ctx_rx[i]->ext_frames = (struct st20_ext_frame *)malloc( sizeof(*test_ctx_rx[i]->ext_frames) * test_ctx_rx[i]->fb_cnt); size_t fbs_size = test_ctx_rx[i]->fb_size * test_ctx_rx[i]->fb_cnt; mtl_dma_mem_handle dma_mem = mtl_dma_mem_alloc(m_handle, fbs_size); @@ -4705,7 +4908,7 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { test_ctx_rx[i]->ext_frames[j].buf_addr = - (uint8_t*)mtl_dma_mem_addr(dma_mem) + j * test_ctx_rx[i]->fb_size; + (uint8_t *)mtl_dma_mem_addr(dma_mem) + j * test_ctx_rx[i]->fb_size; test_ctx_rx[i]->ext_frames[j].buf_iova = mtl_dma_mem_iova(dma_mem) + j * test_ctx_rx[i]->fb_size; test_ctx_rx[i]->ext_frames[j].buf_len = test_ctx_rx[i]->fb_size; @@ -4738,7 +4941,8 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f ops_rx.notify_frame_ready = interlaced[i] ? st20_digest_rx_field_ready : st20_digest_rx_frame_ready; ops_rx.flags = ST20_RX_FLAG_DMA_OFFLOAD; - if (ext) ops_rx.ext_frames = test_ctx_rx[i]->ext_frames; + if (ext) + ops_rx.ext_frames = test_ctx_rx[i]->ext_frames; rx_handle[i] = st20_rx_create(m_handle, &ops_rx); @@ -4776,7 +4980,8 @@ static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps f for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -4826,12 +5031,13 @@ TEST(St20_rx, linesize_digest_s3) { bool interlaced[3] = {false, true, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, fmt, true, - ST_TEST_LEVEL_MANDATORY, 3); + st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, + fmt, true, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, linesize_digest_crosslines_s3) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_GPM, ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_GPM, + ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; @@ -4839,8 +5045,8 @@ TEST(St20_rx, linesize_digest_crosslines_s3) { bool interlaced[3] = {true, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, fmt, true, - ST_TEST_LEVEL_MANDATORY, 3); + st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, + fmt, true, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, linesize_digest_ext_s3) { @@ -4853,6 +5059,6 @@ TEST(St20_rx, linesize_digest_ext_s3) { bool interlaced[3] = {true, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, fmt, true, - ST_TEST_LEVEL_MANDATORY, 3, true); + st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, + fmt, true, ST_TEST_LEVEL_MANDATORY, 3, true); } \ No newline at end of file diff --git a/tests/src/st20p_test.cpp b/tests/src/st20p_test.cpp index 7719a0c47..97367fe0a 100644 --- a/tests/src/st20p_test.cpp +++ b/tests/src/st20p_test.cpp @@ -10,25 +10,33 @@ #define ST20P_TEST_PAYLOAD_TYPE (112) #define ST20P_TEST_UDP_PORT (20000) -static int test_convert_frame(struct test_converter_session* s, - struct st20_convert_frame_meta* frame) { - struct st20_converter_create_req* req = &s->req; +static int test_convert_frame(struct test_converter_session *s, + struct st20_convert_frame_meta *frame) { + struct st20_converter_create_req *req = &s->req; /* check frame sanity */ - if (frame->src->width != req->width) return -EIO; - if (frame->dst->width != req->width) return -EIO; - if (frame->src->height != req->height) return -EIO; - if (frame->dst->height != req->height) return -EIO; - if (frame->src->fmt != req->input_fmt) return -EIO; - if (frame->dst->fmt != req->output_fmt) return -EIO; + if (frame->src->width != req->width) + return -EIO; + if (frame->dst->width != req->width) + return -EIO; + if (frame->src->height != req->height) + return -EIO; + if (frame->dst->height != req->height) + return -EIO; + if (frame->src->fmt != req->input_fmt) + return -EIO; + if (frame->dst->fmt != req->output_fmt) + return -EIO; /* copy src sha to the start of convert frame */ if (req->input_fmt == ST_FRAME_FMT_YUV422PLANAR10LE) memcpy(frame->dst->addr[0], - (uint8_t*)frame->src->addr[0] + frame->src->data_size - SHA256_DIGEST_LENGTH, + (uint8_t *)frame->src->addr[0] + frame->src->data_size - + SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH); else - memcpy((uint8_t*)frame->dst->addr[0] + frame->dst->data_size - SHA256_DIGEST_LENGTH, + memcpy((uint8_t *)frame->dst->addr[0] + frame->dst->data_size - + SHA256_DIGEST_LENGTH, frame->src->addr[0], SHA256_DIGEST_LENGTH); st_usleep(s->sleep_time_us); @@ -50,10 +58,10 @@ static int test_convert_frame(struct test_converter_session* s, return 0; } -static void* test_convert_thread(void* arg) { - struct test_converter_session* s = (struct test_converter_session*)arg; +static void *test_convert_thread(void *arg) { + struct test_converter_session *s = (struct test_converter_session *)arg; st20p_convert_session session_p = s->session_p; - struct st20_convert_frame_meta* frame; + struct st20_convert_frame_meta *frame; int result; dbg("%s(%d), start\n", __func__, s->idx); @@ -61,7 +69,8 @@ static void* test_convert_thread(void* arg) { frame = st20_converter_get_frame(session_p); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -73,16 +82,19 @@ static void* test_convert_thread(void* arg) { return NULL; } -static st20_convert_priv test_converter_create_session( - void* priv, st20p_convert_session session_p, struct st20_converter_create_req* req) { - struct st_tests_context* ctx = (struct st_tests_context*)priv; - struct test_converter_session* session = NULL; +static st20_convert_priv +test_converter_create_session(void *priv, st20p_convert_session session_p, + struct st20_converter_create_req *req) { + struct st_tests_context *ctx = (struct st_tests_context *)priv; + struct test_converter_session *session = NULL; int ret; for (int i = 0; i < MAX_TEST_CONVERTER_SESSIONS; i++) { - if (ctx->converter_sessions[i]) continue; - session = (struct test_converter_session*)malloc(sizeof(*session)); - if (!session) return NULL; + if (ctx->converter_sessions[i]) + continue; + session = (struct test_converter_session *)malloc(sizeof(*session)); + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->idx = i; st_pthread_mutex_init(&session->wake_mutex, NULL); @@ -91,14 +103,16 @@ static st20_convert_priv test_converter_create_session( session->req = *req; session->session_p = session_p; double fps = st_frame_rate(req->fps); - if (!fps) fps = 60; + if (!fps) + fps = 60; session->sleep_time_us = 1000 * 1000 / fps / 2; dbg("%s(%d), sleep_time_us %d\n", __func__, i, session->sleep_time_us); session->fail_interval = ctx->plugin_fail_interval; session->timeout_interval = ctx->plugin_timeout_interval; session->timeout_ms = ctx->plugin_timeout_ms; - ret = pthread_create(&session->convert_thread, NULL, test_convert_thread, session); + ret = pthread_create(&session->convert_thread, NULL, test_convert_thread, + session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -117,10 +131,10 @@ static st20_convert_priv test_converter_create_session( return NULL; } -static int test_converter_free_session(void* priv, st20_convert_priv session) { - struct st_tests_context* ctx = (struct st_tests_context*)priv; - struct test_converter_session* converter_sessions = - (struct test_converter_session*)session; +static int test_converter_free_session(void *priv, st20_convert_priv session) { + struct st_tests_context *ctx = (struct st_tests_context *)priv; + struct test_converter_session *converter_sessions = + (struct test_converter_session *)session; int idx = converter_sessions->idx; converter_sessions->stop = true; @@ -132,14 +146,15 @@ static int test_converter_free_session(void* priv, st20_convert_priv session) { st_pthread_mutex_destroy(&converter_sessions->wake_mutex); st_pthread_cond_destroy(&converter_sessions->wake_cond); - dbg("%s(%d), total %d convert frames\n", __func__, idx, converter_sessions->frame_cnt); + dbg("%s(%d), total %d convert frames\n", __func__, idx, + converter_sessions->frame_cnt); free(converter_sessions); ctx->converter_sessions[idx] = NULL; return 0; } -static int test_converter_frame_available(void* priv) { - struct test_converter_session* s = (struct test_converter_session*)priv; +static int test_converter_frame_available(void *priv) { + struct test_converter_session *s = (struct test_converter_session *)priv; // dbg("%s(%d)\n", __func__, s->idx); st_pthread_mutex_lock(&s->wake_mutex); @@ -149,7 +164,7 @@ static int test_converter_frame_available(void* priv) { return 0; } -int st_test_convert_plugin_unregister(struct st_tests_context* ctx) { +int st_test_convert_plugin_unregister(struct st_tests_context *ctx) { if (ctx->converter_dev_handle) { st20_converter_unregister(ctx->converter_dev_handle); ctx->converter_dev_handle = NULL; @@ -158,7 +173,7 @@ int st_test_convert_plugin_unregister(struct st_tests_context* ctx) { return 0; } -int st_test_convert_plugin_register(struct st_tests_context* ctx) { +int st_test_convert_plugin_register(struct st_tests_context *ctx) { auto st = ctx->handle; int ret = 0; @@ -167,8 +182,10 @@ int st_test_convert_plugin_register(struct st_tests_context* ctx) { c_dev.name = "test_converter"; c_dev.priv = ctx; c_dev.target_device = ST_PLUGIN_DEVICE_TEST; - c_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; - c_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; + c_dev.input_fmt_caps = + ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; + c_dev.output_fmt_caps = + ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; c_dev.create_session = test_converter_create_session; c_dev.free_session = test_converter_free_session; c_dev.notify_frame_available = test_converter_frame_available; @@ -182,7 +199,7 @@ int st_test_convert_plugin_register(struct st_tests_context* ctx) { return 0; } -static void plugin_register_test(const char* so_name, bool expect_succ) { +static void plugin_register_test(const char *so_name, bool expect_succ) { auto ctx = st_test_ctx(); auto st = ctx->handle; @@ -198,29 +215,32 @@ static void plugin_register_test(const char* so_name, bool expect_succ) { } TEST(St20p, plugin_register_single) { - plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", true); + plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", + true); } TEST(St20p, plugin_register_fail) { - plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", - false); + plugin_register_test( + "/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", false); } -static int test_st20p_tx_frame_available(void* priv) { - tests_context* s = (tests_context*)priv; +static int test_st20p_tx_frame_available(void *priv) { + tests_context *s = (tests_context *)priv; s->cv.notify_all(); return 0; } -static int test_st20p_tx_frame_done(void* priv, struct st_frame* frame) { - tests_context* s = (tests_context*)priv; +static int test_st20p_tx_frame_done(void *priv, struct st_frame *frame) { + tests_context *s = (tests_context *)priv; - if (!s->handle) return -EIO; /* not ready */ + if (!s->handle) + return -EIO; /* not ready */ s->fb_send_done++; - if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) return 0; + if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) + return 0; for (int i = 0; i < s->fb_cnt; ++i) { if (frame->addr[0] == s->ext_fb + i * s->frame_size) { @@ -234,23 +254,24 @@ static int test_st20p_tx_frame_done(void* priv, struct st_frame* frame) { return 0; } -static int test_st20p_rx_frame_available(void* priv) { - tests_context* s = (tests_context*)priv; +static int test_st20p_rx_frame_available(void *priv) { + tests_context *s = (tests_context *)priv; s->cv.notify_all(); return 0; } -static void st20p_tx_ops_init(tests_context* st20, struct st20p_tx_ops* ops_tx) { +static void st20p_tx_ops_init(tests_context *st20, + struct st20p_tx_ops *ops_tx) { auto ctx = st20->ctx; memset(ops_tx, 0, sizeof(*ops_tx)); ops_tx->name = "st20p_test"; ops_tx->priv = st20; ops_tx->port.num_port = 1; - memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx->port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + st20->idx; @@ -264,19 +285,20 @@ static void st20p_tx_ops_init(tests_context* st20, struct st20p_tx_ops* ops_tx) ops_tx->framebuff_cnt = st20->fb_cnt; ops_tx->notify_frame_available = test_st20p_tx_frame_available; ops_tx->notify_event = test_ctx_notify_event; - st20->frame_size = - st_frame_size(ops_tx->input_fmt, ops_tx->width, ops_tx->height, ops_tx->interlaced); + st20->frame_size = st_frame_size(ops_tx->input_fmt, ops_tx->width, + ops_tx->height, ops_tx->interlaced); } -static void st20p_rx_ops_init(tests_context* st20, struct st20p_rx_ops* ops_rx) { +static void st20p_rx_ops_init(tests_context *st20, + struct st20p_rx_ops *ops_rx) { auto ctx = st20->ctx; memset(ops_rx, 0, sizeof(*ops_rx)); ops_rx->name = "st20p_test"; ops_rx->priv = st20; ops_rx->port.num_port = 1; - memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx->port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + st20->idx; @@ -290,8 +312,8 @@ static void st20p_rx_ops_init(tests_context* st20, struct st20p_rx_ops* ops_rx) ops_rx->framebuff_cnt = st20->fb_cnt; ops_rx->notify_frame_available = test_st20p_rx_frame_available; ops_rx->notify_event = test_ctx_notify_event; - st20->frame_size = st_frame_size(ops_rx->output_fmt, ops_rx->width, ops_rx->height, - ops_rx->interlaced); + st20->frame_size = st_frame_size(ops_rx->output_fmt, ops_rx->width, + ops_rx->height, ops_rx->interlaced); } static void st20p_tx_assert_cnt(int expect_st20_tx_cnt) { @@ -340,12 +362,8 @@ TEST(St20p, tx_create_free_max) { TEST(St20p, rx_create_free_max) { pipeline_create_free_max(st20p_rx, TEST_CREATE_FREE_MAX); } -TEST(St20p, tx_create_expect_fail) { - pipeline_expect_fail_test(st20p_tx); -} -TEST(St20p, rx_create_expect_fail) { - pipeline_expect_fail_test(st20p_rx); -} +TEST(St20p, tx_create_expect_fail) { pipeline_expect_fail_test(st20p_tx); } +TEST(St20p, rx_create_expect_fail) { pipeline_expect_fail_test(st20p_rx); } TEST(St20p, tx_create_expect_fail_fb_cnt) { uint16_t fbcnt = 1; pipeline_expect_fail_test_fb_cnt(st20p_tx, fbcnt); @@ -359,10 +377,10 @@ TEST(St20p, rx_create_expect_fail_fb_cnt) { pipeline_expect_fail_test_fb_cnt(st20p_rx, fbcnt); } -static void test_st20p_tx_frame_thread(void* args) { - tests_context* s = (tests_context*)args; +static void test_st20p_tx_frame_thread(void *args) { + tests_context *s = (tests_context *)args; auto handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; struct test_user_meta meta; std::unique_lock lck(s->mtx, std::defer_lock); @@ -372,16 +390,22 @@ static void test_st20p_tx_frame_thread(void* args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) s->cv.wait(lck); + if (!s->stop) + s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->width != s->width) s->incomplete_frame_cnt++; - if (frame->height != s->height) s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->width != s->width) + s->incomplete_frame_cnt++; + if (frame->height != s->height) + s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) + s->incomplete_frame_cnt++; if (s->user_timestamp) { frame->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; frame->timestamp = s->fb_send; @@ -398,12 +422,14 @@ static void test_st20p_tx_frame_thread(void* args) { int ret = st20p_tx_put_ext_frame((st20p_tx_handle)handle, frame, &s->p_ext_frames[s->ext_idx]); if (ret < 0) { - err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, s->ext_idx); + err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, + s->ext_idx); continue; } s->ext_fb_in_use[s->ext_idx] = true; s->ext_idx++; - if (s->ext_idx >= s->fb_cnt) s->ext_idx = 0; + if (s->ext_idx >= s->fb_cnt) + s->ext_idx = 0; } else { /* directly put */ st20p_tx_put_frame((st20p_tx_handle)handle, frame); @@ -417,8 +443,8 @@ static void test_st20p_tx_frame_thread(void* args) { dbg("%s(%d), stop\n", __func__, s->idx); } -static void test_st20p_rx_user_meta(tests_context* s, struct st_frame* frame) { - struct test_user_meta* meta = (struct test_user_meta*)frame->user_meta; +static void test_st20p_rx_user_meta(tests_context *s, struct st_frame *frame) { + struct test_user_meta *meta = (struct test_user_meta *)frame->user_meta; if (!meta) { s->user_meta_fail_cnt++; @@ -427,21 +453,24 @@ static void test_st20p_rx_user_meta(tests_context* s, struct st_frame* frame) { dbg("%s(%d), meta idx session %d frame %d magic 0x%x\n", __func__, s->idx, meta->session_idx, meta->frame_idx, meta->magic); - if (frame->user_meta_size != sizeof(*meta)) s->user_meta_fail_cnt++; - if (meta->magic != TEST_USER_META_MAGIC) s->user_meta_fail_cnt++; - if (meta->session_idx != s->idx) s->user_meta_fail_cnt++; + if (frame->user_meta_size != sizeof(*meta)) + s->user_meta_fail_cnt++; + if (meta->magic != TEST_USER_META_MAGIC) + s->user_meta_fail_cnt++; + if (meta->session_idx != s->idx) + s->user_meta_fail_cnt++; if (meta->frame_idx <= s->last_user_meta_frame_idx) { - err("%s(%d), err user meta frame idx %d:%d\n", __func__, s->idx, meta->frame_idx, - s->last_user_meta_frame_idx); + err("%s(%d), err user meta frame idx %d:%d\n", __func__, s->idx, + meta->frame_idx, s->last_user_meta_frame_idx); s->user_meta_fail_cnt++; } s->last_user_meta_frame_idx = meta->frame_idx; } -static void test_st20p_rx_frame_thread(void* args) { - tests_context* s = (tests_context*)args; +static void test_st20p_rx_frame_thread(void *args) { + tests_context *s = (tests_context *)args; auto handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; std::unique_lock lck(s->mtx, std::defer_lock); uint64_t timestamp = 0; @@ -451,13 +480,15 @@ static void test_st20p_rx_frame_thread(void* args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) s->cv.wait(lck); + if (!s->stop) + s->cv.wait(lck); lck.unlock(); } continue; } - if (s->user_meta) test_st20p_rx_user_meta(s, frame); + if (s->user_meta) + test_st20p_rx_user_meta(s, frame); if (!st_is_frame_complete(frame->status)) { s->incomplete_frame_cnt++; @@ -465,16 +496,23 @@ static void test_st20p_rx_frame_thread(void* args) { continue; } - if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->width != s->width) s->incomplete_frame_cnt++; - if (frame->height != s->height) s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->width != s->width) + s->incomplete_frame_cnt++; + if (frame->height != s->height) + s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) + s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) + s->incomplete_frame_cnt++; timestamp = frame->timestamp; if (s->rx_timing_parser) { - if (!frame->tp[MTL_SESSION_PORT_P]) s->incomplete_frame_cnt++; + if (!frame->tp[MTL_SESSION_PORT_P]) + s->incomplete_frame_cnt++; } /* check user timestamp if it has */ @@ -486,19 +524,20 @@ static void test_st20p_rx_frame_thread(void* args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, - s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", + __func__, s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; } - unsigned char* sha = - (unsigned char*)frame->addr[0] + frame->data_size - SHA256_DIGEST_LENGTH; + unsigned char *sha = (unsigned char *)frame->addr[0] + frame->data_size - + SHA256_DIGEST_LENGTH; int i = 0; for (i = 0; i < TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = s->shas[i]; - if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = s->shas[i]; + if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20p_rx_error_sha", sha); @@ -507,15 +546,16 @@ static void test_st20p_rx_frame_thread(void* args) { /* directly put */ st20p_rx_put_frame((st20p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) + s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } -static void test_internal_st20p_rx_frame_thread(void* args) { - tests_context* s = (tests_context*)args; +static void test_internal_st20p_rx_frame_thread(void *args) { + tests_context *s = (tests_context *)args; auto handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; std::unique_lock lck(s->mtx, std::defer_lock); uint64_t timestamp = 0; unsigned char result[SHA256_DIGEST_LENGTH]; @@ -526,7 +566,8 @@ static void test_internal_st20p_rx_frame_thread(void* args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) s->cv.wait(lck); + if (!s->stop) + s->cv.wait(lck); lck.unlock(); } continue; @@ -534,12 +575,13 @@ static void test_internal_st20p_rx_frame_thread(void* args) { if (frame->opaque) { /* free dynamic ext frame */ - bool* in_use = (bool*)frame->opaque; + bool *in_use = (bool *)frame->opaque; EXPECT_TRUE(*in_use); *in_use = false; } - if (s->user_meta) test_st20p_rx_user_meta(s, frame); + if (s->user_meta) + test_st20p_rx_user_meta(s, frame); if (!st_is_frame_complete(frame->status)) { s->incomplete_frame_cnt++; @@ -547,13 +589,19 @@ static void test_internal_st20p_rx_frame_thread(void* args) { continue; } - if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->width != s->width) s->incomplete_frame_cnt++; - if (frame->height != s->height) s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->width != s->width) + s->incomplete_frame_cnt++; + if (frame->height != s->height) + s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) + s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) + s->incomplete_frame_cnt++; timestamp = frame->timestamp; /* check user timestamp if it has */ @@ -565,19 +613,20 @@ static void test_internal_st20p_rx_frame_thread(void* args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, - s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", + __func__, s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; } int i = 0; - unsigned char* fb = (unsigned char*)frame->addr[0]; + unsigned char *fb = (unsigned char *)frame->addr[0]; SHA256(fb, s->frame_size, result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = s->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = s->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20p_rx_error_sha", result); @@ -586,14 +635,15 @@ static void test_internal_st20p_rx_frame_thread(void* args) { /* directly put */ st20p_rx_put_frame((st20p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) + s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } -static int test_st20p_rx_query_ext_frame(void* priv, st_ext_frame* ext_frame, - struct st20_rx_frame_meta* meta) { - tests_context* s = (tests_context*)priv; +static int test_st20p_rx_query_ext_frame(void *priv, st_ext_frame *ext_frame, + struct st20_rx_frame_meta *meta) { + tests_context *s = (tests_context *)priv; int i = s->ext_idx; /* check ext_fb_in_use */ @@ -607,7 +657,8 @@ static int test_st20p_rx_query_ext_frame(void* priv, st_ext_frame* ext_frame, ext_frame->opaque = &s->ext_fb_in_use[i]; - if (++s->ext_idx >= s->fb_cnt) s->ext_idx = 0; + if (++s->ext_idx >= s->fb_cnt) + s->ext_idx = 0; return 0; } @@ -641,7 +692,8 @@ struct st20p_rx_digest_test_para { bool zero_payload_type; }; -static void test_st20p_init_rx_digest_para(struct st20p_rx_digest_test_para* para) { +static void +test_st20p_init_rx_digest_para(struct st20p_rx_digest_test_para *para) { memset(para, 0, sizeof(*para)); para->device = ST_PLUGIN_DEVICE_TEST; @@ -671,10 +723,11 @@ static void test_st20p_init_rx_digest_para(struct st20p_rx_digest_test_para* par } static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], - enum st_frame_fmt tx_fmt[], enum st20_fmt t_fmt[], + enum st_frame_fmt tx_fmt[], + enum st20_fmt t_fmt[], enum st_frame_fmt rx_fmt[], - struct st20p_rx_digest_test_para* para) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + struct st20p_rx_digest_test_para *para) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto st = ctx->handle; int ret; struct st20p_tx_ops ops_tx; @@ -686,12 +739,14 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], st_test_jxs_timeout_ms(ctx, para->timeout_ms); if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled, one for tx and one for rx\n", __func__); + info("%s, dual port should be enabled, one for tx and one for rx\n", + __func__); return; } /* return if level lower than global */ - if (para->level < ctx->level) return; + if (para->level < ctx->level) + return; if (para->tx_ext || para->rx_ext) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -708,8 +763,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], } } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate_tx; @@ -737,8 +792,9 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { expect_framerate_tx[i] = st_frame_rate(fps[i]); if (para->timeout_interval) { - expect_framerate_tx[i] = - expect_framerate_tx[i] * (para->timeout_interval - 1) / para->timeout_interval; + expect_framerate_tx[i] = expect_framerate_tx[i] * + (para->timeout_interval - 1) / + para->timeout_interval; } test_ctx_tx[i] = new tests_context(); @@ -760,15 +816,16 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + i * 2; - ops_tx.port.payload_type = para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; + ops_tx.port.payload_type = + para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; ops_tx.port.ssrc = para->ssrc; ops_tx.width = width[i]; ops_tx.height = height[i]; @@ -790,8 +847,10 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], if (para->tx_ext) { ops_tx.flags |= ST20P_TX_FLAG_EXT_FRAME; } - if (para->user_timestamp) ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; - if (para->vsync) ops_tx.flags |= ST20P_TX_FLAG_ENABLE_VSYNC; + if (para->user_timestamp) + ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; + if (para->vsync) + ops_tx.flags |= ST20P_TX_FLAG_ENABLE_VSYNC; if (para->rtcp) { ops_tx.flags |= ST20P_TX_FLAG_ENABLE_RTCP; @@ -818,11 +877,11 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], /* sha calculate */ size_t frame_size = test_ctx_tx[i]->frame_size; - uint8_t* fb; + uint8_t *fb; /* init ext frames, only for no convert */ if (para->tx_ext) { - test_ctx_tx[i]->p_ext_frames = (struct st_ext_frame*)malloc( + test_ctx_tx[i]->p_ext_frames = (struct st_ext_frame *)malloc( sizeof(*test_ctx_tx[i]->p_ext_frames) * test_ctx_tx[i]->fb_cnt); size_t pg_sz = mtl_page_size(st); size_t fb_size = frame_size * test_ctx_tx[i]->fb_cnt; @@ -832,14 +891,15 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_tx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_malloc != NULL); test_ctx_tx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); - test_ctx_tx[i]->ext_fb_iova = - mtl_dma_map(st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); + test_ctx_tx[i]->ext_fb_iova = mtl_dma_map( + st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_iova != MTL_BAD_IOVA); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_tx[i]->ext_fb); for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; + plane++) { /* assume planes continuous */ test_ctx_tx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(rx_fmt[i], width[i], plane) + para->line_padding_size; @@ -850,7 +910,7 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_tx[i]->ext_fb_iova + j * frame_size; } else { test_ctx_tx[i]->p_ext_frames[j].addr[plane] = - (uint8_t*)test_ctx_tx[i]->p_ext_frames[j].addr[plane - 1] + + (uint8_t *)test_ctx_tx[i]->p_ext_frames[j].addr[plane - 1] + test_ctx_tx[i]->p_ext_frames[j].linesize[plane - 1] * height[i]; test_ctx_tx[i]->p_ext_frames[j].iova[plane] = test_ctx_tx[i]->p_ext_frames[j].iova[plane - 1] + @@ -864,47 +924,51 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { if (para->tx_ext) - fb = (uint8_t*)test_ctx_tx[i]->ext_fb + frame * frame_size; + fb = (uint8_t *)test_ctx_tx[i]->ext_fb + frame * frame_size; else - fb = (uint8_t*)st20p_tx_get_fb_addr(tx_handle[i], frame); + fb = (uint8_t *)st20p_tx_get_fb_addr(tx_handle[i], frame); ASSERT_TRUE(fb != NULL); if (!para->line_padding_size) st_test_rand_data(fb, frame_size, frame); else { for (int plane = 0; plane < planes; plane++) { - size_t least_line_size = st_frame_least_linesize(tx_fmt[i], width[i], plane); - uint8_t* start = (uint8_t*)test_ctx_tx[i]->p_ext_frames[frame].addr[plane]; + size_t least_line_size = + st_frame_least_linesize(tx_fmt[i], width[i], plane); + uint8_t *start = + (uint8_t *)test_ctx_tx[i]->p_ext_frames[frame].addr[plane]; for (int line = 0; line < height[i]; line++) { - uint8_t* cur_line = - start + test_ctx_tx[i]->p_ext_frames[frame].linesize[plane] * line; + uint8_t *cur_line = + start + + test_ctx_tx[i]->p_ext_frames[frame].linesize[plane] * line; st_test_rand_data(cur_line, least_line_size, frame); } } } if (tx_fmt[i] == ST_FRAME_FMT_YUV422PLANAR10LE) { /* only LSB 10 valid */ - uint16_t* p10_u16 = (uint16_t*)fb; + uint16_t *p10_u16 = (uint16_t *)fb; for (size_t j = 0; j < (frame_size / 2); j++) { p10_u16[j] &= 0x3ff; /* only 10 bit */ } } else if (tx_fmt[i] == ST_FRAME_FMT_Y210) { /* only MSB 10 valid */ - uint16_t* y210_u16 = (uint16_t*)fb; + uint16_t *y210_u16 = (uint16_t *)fb; for (size_t j = 0; j < (frame_size / 2); j++) { y210_u16[j] &= 0xffc0; /* only 10 bit */ } } else if (tx_fmt[i] == ST_FRAME_FMT_V210) { - uint32_t* v210_word = (uint32_t*)fb; + uint32_t *v210_word = (uint32_t *)fb; for (size_t j = 0; j < (frame_size / 4); j++) { v210_word[j] &= 0x3fffffff; /* only 30 bit */ } } - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st20p_tx", result); /* copy sha to the end of frame */ if (para->device == ST_PLUGIN_DEVICE_TEST) - memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, SHA256_DIGEST_LENGTH); + memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, + SHA256_DIGEST_LENGTH); } test_ctx_tx[i]->handle = tx_handle[i]; @@ -915,8 +979,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { if (para->fail_interval) { /* loss in the tx */ - expect_framerate_tx[i] = - expect_framerate_tx[i] * (para->fail_interval - 1) / para->fail_interval; + expect_framerate_tx[i] = expect_framerate_tx[i] * + (para->fail_interval - 1) / para->fail_interval; } expect_framerate_rx[i] = expect_framerate_tx[i]; test_ctx_rx[i] = new tests_context(); @@ -942,10 +1006,11 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], /* init ext frames, only for no convert */ if (para->rx_ext) { uint8_t planes = st_frame_fmt_planes(rx_fmt[i]); - test_ctx_rx[i]->p_ext_frames = (struct st_ext_frame*)malloc( + test_ctx_rx[i]->p_ext_frames = (struct st_ext_frame *)malloc( sizeof(*test_ctx_rx[i]->p_ext_frames) * test_ctx_rx[i]->fb_cnt); - size_t frame_size = st_frame_size(rx_fmt[i], width[i], height[i], para->interlace) + - para->line_padding_size * height[i] * planes; + size_t frame_size = + st_frame_size(rx_fmt[i], width[i], height[i], para->interlace) + + para->line_padding_size * height[i] * planes; size_t pg_sz = mtl_page_size(st); size_t fb_size = frame_size * test_ctx_rx[i]->fb_cnt; test_ctx_rx[i]->ext_fb_iova_map_sz = @@ -954,14 +1019,15 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = - mtl_dma_map(st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); + test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( + st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; + plane++) { /* assume planes continuous */ test_ctx_rx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(rx_fmt[i], width[i], plane) + para->line_padding_size; @@ -972,7 +1038,7 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->ext_fb_iova + j * frame_size; } else { test_ctx_rx[i]->p_ext_frames[j].addr[plane] = - (uint8_t*)test_ctx_rx[i]->p_ext_frames[j].addr[plane - 1] + + (uint8_t *)test_ctx_rx[i]->p_ext_frames[j].addr[plane - 1] + test_ctx_rx[i]->p_ext_frames[j].linesize[plane - 1] * height[i]; test_ctx_rx[i]->p_ext_frames[j].iova[plane] = test_ctx_rx[i]->p_ext_frames[j].iova[plane - 1] + @@ -990,15 +1056,16 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.priv = test_ctx_rx[i]; ops_rx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + i * 2; - ops_rx.port.payload_type = para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; + ops_rx.port.payload_type = + para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; ops_rx.port.ssrc = para->ssrc; ops_rx.width = width[i]; ops_rx.height = height[i]; @@ -1013,7 +1080,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.flags |= ST20P_RX_FLAG_BLOCK_GET; else ops_rx.notify_frame_available = test_st20p_rx_frame_available; - if (para->rx_timing_parser) ops_rx.flags |= ST20P_RX_FLAG_TIMING_PARSER_META; + if (para->rx_timing_parser) + ops_rx.flags |= ST20P_RX_FLAG_TIMING_PARSER_META; ops_rx.notify_event = test_ctx_notify_event; if (para->rx_ext) { if (para->rx_dedicated_ext) { @@ -1021,16 +1089,21 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], } else { ops_rx.flags |= ST20P_RX_FLAG_EXT_FRAME; ops_rx.query_ext_frame = test_st20p_rx_query_ext_frame; - if (st_frame_fmt_equal_transport(ops_rx.output_fmt, ops_rx.transport_fmt)) + if (st_frame_fmt_equal_transport(ops_rx.output_fmt, + ops_rx.transport_fmt)) ops_rx.flags |= ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; } } - if (para->vsync) ops_rx.flags |= ST20P_RX_FLAG_ENABLE_VSYNC; - if (para->pkt_convert) ops_rx.flags |= ST20P_RX_FLAG_PKT_CONVERT; - if (para->rx_auto_detect) ops_rx.flags |= ST20P_RX_FLAG_AUTO_DETECT; + if (para->vsync) + ops_rx.flags |= ST20P_RX_FLAG_ENABLE_VSYNC; + if (para->pkt_convert) + ops_rx.flags |= ST20P_RX_FLAG_PKT_CONVERT; + if (para->rx_auto_detect) + ops_rx.flags |= ST20P_RX_FLAG_AUTO_DETECT; if (para->rtcp) { - ops_rx.flags |= ST20P_RX_FLAG_ENABLE_RTCP | ST20P_RX_FLAG_SIMULATE_PKT_LOSS; + ops_rx.flags |= + ST20P_RX_FLAG_ENABLE_RTCP | ST20P_RX_FLAG_SIMULATE_PKT_LOSS; ops_rx.rtcp.nack_interval_us = 250; ops_rx.rtcp.seq_bitmap_size = 64; ops_rx.rtcp.seq_skip_window = 0; @@ -1054,7 +1127,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->handle = rx_handle[i]; if (para->device == ST_PLUGIN_DEVICE_TEST_INTERNAL) - rx_thread[i] = std::thread(test_internal_st20p_rx_frame_thread, test_ctx_rx[i]); + rx_thread[i] = + std::thread(test_internal_st20p_rx_frame_thread, test_ctx_rx[i]); else rx_thread[i] = std::thread(test_st20p_rx_frame_thread, test_ctx_rx[i]); @@ -1073,19 +1147,23 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; framerate_tx[i] = test_ctx_tx[i]->fb_send / time_sec; /* vsync check */ - time_sec = (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; + time_sec = + (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; vsyncrate_tx[i] = test_ctx_tx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_tx[i], test_ctx_tx[i]->vsync_cnt, vsyncrate_tx[i]); EXPECT_GT(test_ctx_tx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), + st_frame_rate(fps[i]) * 0.1); test_ctx_tx[i]->stop = true; - if (para->block_get) st20p_tx_wake_block(tx_handle[i]); + if (para->block_get) + st20p_tx_wake_block(tx_handle[i]); test_ctx_tx[i]->cv.notify_all(); tx_thread[i].join(); if (para->send_done_check) { @@ -1099,19 +1177,23 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate_rx[i] = test_ctx_rx[i]->fb_rec / time_sec; /* vsync check */ - time_sec = (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; + time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; vsyncrate_rx[i] = test_ctx_rx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_rx[i], test_ctx_rx[i]->vsync_cnt, vsyncrate_rx[i]); EXPECT_GT(test_ctx_rx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), + st_frame_rate(fps[i]) * 0.1); test_ctx_rx[i]->stop = true; - if (para->block_get) st20p_rx_wake_block(rx_handle[i]); + if (para->block_get) + st20p_rx_wake_block(rx_handle[i]); test_ctx_rx[i]->cv.notify_all(); rx_thread[i].join(); } @@ -1277,9 +1359,11 @@ TEST(St20p, digest_1080p_internal_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1295,9 +1379,11 @@ TEST(St20p, digest_1080p_no_convert_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, ST_FRAME_FMT_RGB8}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, + ST_FRAME_FMT_RGB8}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_RGB_8BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, ST_FRAME_FMT_RGB8}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, + ST_FRAME_FMT_RGB8}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1312,9 +1398,11 @@ TEST(St20p, digest_1080p_packet_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1351,9 +1439,11 @@ TEST(St20p, tx_ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_V210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_V210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1390,9 +1480,11 @@ TEST(St20p, rx_ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_V210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_V210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1408,9 +1500,11 @@ TEST(St20p, rx_ext_digest_1080p_packet_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1449,9 +1543,11 @@ TEST(St20p, ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_V210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_V210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1470,9 +1566,11 @@ TEST(St20p, rx_dedicated_ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P29_97, ST_FPS_P59_94}; int width[2] = {1920, 1280}; int height[2] = {1080, 720}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1488,9 +1586,11 @@ TEST(St20p, ext_digest_1080p_convert_with_padding_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1508,9 +1608,11 @@ TEST(St20p, rx_dedicated_ext_digest_1080p_convert_with_padding_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1529,9 +1631,11 @@ TEST(St20p, ext_digest_1080p_packet_convert_with_padding_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, + ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); diff --git a/tests/src/st22_test.cpp b/tests/src/st22_test.cpp index b1cc0acf0..d7e8ce566 100644 --- a/tests/src/st22_test.cpp +++ b/tests/src/st22_test.cpp @@ -9,73 +9,85 @@ #define ST22_TEST_PAYLOAD_TYPE (114) -static int st22_tx_rtp_done(void* args) { - auto ctx = (tests_context*)args; +static int st22_tx_rtp_done(void *args) { + auto ctx = (tests_context *)args; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int st22_rx_rtp_ready(void* args) { - auto ctx = (tests_context*)args; +static int st22_rx_rtp_ready(void *args) { + auto ctx = (tests_context *)args; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int st22_next_video_frame(void* priv, uint16_t* next_frame_idx, - struct st22_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st22_next_video_frame(void *priv, uint16_t *next_frame_idx, + struct st22_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; meta->codestream_size = ctx->frame_size; - dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, *next_frame_idx, - meta->codestream_size); + dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, + *next_frame_idx, meta->codestream_size); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int st22_next_video_frame_timestamp(void* priv, uint16_t* next_frame_idx, - struct st22_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st22_next_video_frame_timestamp(void *priv, uint16_t *next_frame_idx, + struct st22_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; meta->codestream_size = ctx->frame_size; meta->tfmt = ST10_TIMESTAMP_FMT_TAI; meta->timestamp = mtl_ptp_read_time(ctx->ctx->handle) + 35 * 1000 * 1000; - dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, *next_frame_idx, - meta->codestream_size); + dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, + *next_frame_idx, meta->codestream_size); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int st22_frame_done(void* priv, uint16_t frame_idx, - struct st22_tx_frame_meta* meta) { +static int st22_frame_done(void *priv, uint16_t frame_idx, + struct st22_tx_frame_meta *meta) { return 0; } -static int st22_rx_frame_ready(void* priv, void* frame, struct st22_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st22_rx_frame_ready(void *priv, void *frame, + struct st22_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; ctx->fb_rec++; if (!ctx->start_time) { @@ -83,19 +95,21 @@ static int st22_rx_frame_ready(void* priv, void* frame, struct st22_rx_frame_met ctx->start_time = st_test_get_monotonic_time(); } - if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) ctx->rtp_tmstamp = meta->timestamp; + if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) + ctx->rtp_tmstamp = meta->timestamp; st22_rx_put_framebuff((st22_rx_handle)ctx->handle, frame); return 0; } -static void st22_tx_ops_init(tests_context* st22, struct st22_tx_ops* ops) { +static void st22_tx_ops_init(tests_context *st22, struct st22_tx_ops *ops) { auto ctx = st22->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st22_test"; ops->priv = st22; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; + if (ctx->same_dual_port) + ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -123,14 +137,15 @@ static void st22_tx_ops_init(tests_context* st22, struct st22_tx_ops* ops) { ops->get_next_frame = st22_next_video_frame; } -static void st22_rx_ops_init(tests_context* st22, struct st22_rx_ops* ops) { +static void st22_rx_ops_init(tests_context *st22, struct st22_rx_ops *ops) { auto ctx = st22->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st22_test"; ops->priv = st22; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; + if (ctx->same_dual_port) + ops->num_port = 1; memcpy(ops->ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -178,21 +193,13 @@ static void st22_rx_assert_cnt(int expect_s22_rx_cnt) { EXPECT_EQ(var.st22_rx_sessions_cnt, expect_s22_rx_cnt); } -TEST(St22_tx, create_free_single) { - create_free_test(st22_tx, 0, 1, 1); -} -TEST(St22_tx, create_free_multi) { - create_free_test(st22_tx, 0, 1, 6); -} -TEST(St22_tx, create_free_mix) { - create_free_test(st22_tx, 2, 3, 4); -} +TEST(St22_tx, create_free_single) { create_free_test(st22_tx, 0, 1, 1); } +TEST(St22_tx, create_free_multi) { create_free_test(st22_tx, 0, 1, 6); } +TEST(St22_tx, create_free_mix) { create_free_test(st22_tx, 2, 3, 4); } TEST(St22_tx, create_free_max) { create_free_max(st22_tx, TEST_CREATE_FREE_MAX); } -TEST(St22_tx, create_expect_fail) { - expect_fail_test(st22_tx); -} +TEST(St22_tx, create_expect_fail) { expect_fail_test(st22_tx); } TEST(St22_tx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st22_tx, ST22_TYPE_RTP_LEVEL, ring_size); @@ -214,21 +221,13 @@ TEST(St22_tx, create_expect_fail_fb_cnt) { expect_fail_test_fb_cnt(st22_tx, fbcnt); } -TEST(St22_rx, create_free_single) { - create_free_test(st22_rx, 0, 1, 1); -} -TEST(St22_rx, create_free_multi) { - create_free_test(st22_rx, 0, 1, 6); -} -TEST(St22_rx, create_free_mix) { - create_free_test(st22_rx, 2, 3, 4); -} +TEST(St22_rx, create_free_single) { create_free_test(st22_rx, 0, 1, 1); } +TEST(St22_rx, create_free_multi) { create_free_test(st22_rx, 0, 1, 6); } +TEST(St22_rx, create_free_mix) { create_free_test(st22_rx, 2, 3, 4); } TEST(St22_rx, create_free_max) { create_free_max(st22_rx, TEST_CREATE_FREE_MAX); } -TEST(St22_rx, create_expect_fail) { - expect_fail_test(st22_rx); -} +TEST(St22_rx, create_expect_fail) { expect_fail_test(st22_rx); } TEST(St22_rx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st22_rx, ST22_TYPE_RTP_LEVEL, ring_size); @@ -242,8 +241,9 @@ TEST(St22_rx, create_expect_fail_fb_cnt) { expect_fail_test_fb_cnt(st22_rx, fbcnt); } -static int st22_tx_build_rtp_packet(tests_context* s, struct st22_rfc9134_rtp_hdr* rtp, - uint16_t* pkt_len) { +static int st22_tx_build_rtp_packet(tests_context *s, + struct st22_rfc9134_rtp_hdr *rtp, + uint16_t *pkt_len) { /* update hdr */ rtp->base.csrc_count = 0; rtp->base.extension = 0; @@ -259,9 +259,10 @@ static int st22_tx_build_rtp_packet(tests_context* s, struct st22_rfc9134_rtp_hd *pkt_len = data_len + sizeof(*rtp); /* todo: build the payload data */ if (s->check_sha) { - uint8_t* payload = (uint8_t*)rtp + sizeof(*rtp); + uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); mtl_memcpy(payload, - s->frame_buf[s->fb_idx % ST22_TEST_SHA_HIST_NUM] + s->pkt_idx * data_len, + s->frame_buf[s->fb_idx % ST22_TEST_SHA_HIST_NUM] + + s->pkt_idx * data_len, data_len); } @@ -278,10 +279,10 @@ static int st22_tx_build_rtp_packet(tests_context* s, struct st22_rfc9134_rtp_hd return 0; } -static void st22_tx_feed_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void st22_tx_feed_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); while (!ctx->stop) { @@ -294,23 +295,26 @@ static void st22_tx_feed_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - st22_tx_build_rtp_packet(ctx, (struct st22_rfc9134_rtp_hdr*)usrptr, &mbuf_len); + st22_tx_build_rtp_packet(ctx, (struct st22_rfc9134_rtp_hdr *)usrptr, + &mbuf_len); st22_tx_put_mbuf((st22_tx_handle)ctx->handle, mbuf, mbuf_len); } } -static void st22_rx_handle_rtp(tests_context* s, struct st22_rfc9134_rtp_hdr* hdr, - bool newframe, int mbuf_len) { - uint8_t* frame; - uint8_t* payload; +static void st22_rx_handle_rtp(tests_context *s, + struct st22_rfc9134_rtp_hdr *hdr, bool newframe, + int mbuf_len) { + uint8_t *frame; + uint8_t *payload; if (newframe) { if (s->frame_buf[0]) { @@ -318,27 +322,28 @@ static void st22_rx_handle_rtp(tests_context* s, struct st22_rfc9134_rtp_hdr* hd s->buf_q.push(s->frame_buf[0]); s->cv.notify_all(); } - s->frame_buf[0] = (uint8_t*)st_test_zmalloc(s->frame_size); + s->frame_buf[0] = (uint8_t *)st_test_zmalloc(s->frame_size); ASSERT_TRUE(s->frame_buf[0] != NULL); } frame = s->frame_buf[0]; - payload = (uint8_t*)hdr + sizeof(*hdr); + payload = (uint8_t *)hdr + sizeof(*hdr); int index = ntohs(hdr->base.seq_number) - s->seq_id; if (index < 0) { index = index + 0x10000; } - mtl_memcpy(frame + index * (mbuf_len - sizeof(*hdr)), payload, mbuf_len - sizeof(*hdr)); + mtl_memcpy(frame + index * (mbuf_len - sizeof(*hdr)), payload, + mbuf_len - sizeof(*hdr)); return; } -static void st22_rx_get_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void st22_rx_get_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); - struct st22_rfc9134_rtp_hdr* hdr; + struct st22_rfc9134_rtp_hdr *hdr; while (!ctx->stop) { /* get available buffer*/ mbuf = st22_rx_get_mbuf((st22_rx_handle)ctx->handle, &usrptr, &mbuf_len); @@ -349,12 +354,13 @@ static void st22_rx_get_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } - hdr = (struct st22_rfc9134_rtp_hdr*)usrptr; + hdr = (struct st22_rfc9134_rtp_hdr *)usrptr; bool newframe = false; uint32_t tmstamp = ntohl(hdr->base.tmstamp); if (tmstamp != ctx->rtp_tmstamp) { @@ -371,25 +377,28 @@ static void st22_rx_get_packet(void* args) { } } -static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], int width[], - int height[], int pkt_data_len[], int total_pkts[], - enum st_test_level level, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], + int width[], int height[], int pkt_data_len[], + int total_pkts[], enum st_test_level level, + int sessions = 1) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level lower than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -421,11 +430,11 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], int width ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -439,9 +448,10 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], int width ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = - (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * + test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -499,9 +509,10 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], int width ops_rx.rtp_ring_size = 1024; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = - (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * + test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -526,7 +537,8 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], int width for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST22_TYPE_RTP_LEVEL) { @@ -549,8 +561,8 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], int width EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st22_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); @@ -579,29 +591,31 @@ TEST(St22_rx, fps_mix_s2) { int height[2] = {1080, 720}; int pkt_data_len[2] = {1280, 1300}; int total_pkts[2] = {540, 150}; - st22_rx_fps_test(type, fps, width, height, pkt_data_len, total_pkts, ST_TEST_LEVEL_ALL, - 2); + st22_rx_fps_test(type, fps, width, height, pkt_data_len, total_pkts, + ST_TEST_LEVEL_ALL, 2); } static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level lower than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; int rx_sessions = 1; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -630,17 +644,17 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -655,8 +669,8 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { test_ctx_tx[i]->pkt_data_len = 1280; test_ctx_tx[i]->total_pkts_in_frame = 520; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = - (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * + test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -709,8 +723,8 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { test_ctx_rx[i]->pkt_data_len = 1280; test_ctx_rx[i]->total_pkts_in_frame = 520; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = - (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * + test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -742,7 +756,8 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -767,7 +782,8 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -792,7 +808,8 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -817,26 +834,26 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { } } -TEST(St22_rx, update_source) { - st22_rx_update_src_test(2, ST_TEST_LEVEL_ALL); -} +TEST(St22_rx, update_source) { st22_rx_update_src_test(2, ST_TEST_LEVEL_ALL); } -static void st22_rx_after_start_test(enum st_fps fps[], int width[], int height[], - int pkt_data_len[], int total_pkts[], int sessions, +static void st22_rx_after_start_test(enum st_fps fps[], int width[], + int height[], int pkt_data_len[], + int total_pkts[], int sessions, int repeat) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -870,11 +887,11 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], int height[ ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -889,8 +906,8 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], int height[ test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; - test_ctx_tx[i]->frame_size = - (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * + test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -923,11 +940,11 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], int height[ ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -946,8 +963,8 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], int height[ test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = - (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * + test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -964,15 +981,17 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], int height[ /* check fps, stop rx */ for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; } for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); - EXPECT_LT(test_ctx_rx[i]->sha_fail_cnt, 2); // the first frame may be incomplete + EXPECT_LT(test_ctx_rx[i]->sha_fail_cnt, + 2); // the first frame may be incomplete ret = st22_rx_free(rx_handle[i]); EXPECT_GE(ret, 0); } @@ -999,14 +1018,16 @@ TEST(St22_rx, after_start_s2) { } static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], - int pkt_data_len[], int total_pkts[], int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + int pkt_data_len[], int total_pkts[], + int sessions = 1) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } @@ -1016,8 +1037,8 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -1045,11 +1066,11 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -1063,9 +1084,10 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = - (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * + test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -1116,9 +1138,10 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = - (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * + test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -1144,12 +1167,14 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], EXPECT_GE(ret, 0); EXPECT_EQ(meta.dumped_packets[MTL_SESSION_PORT_P], max_dump_packets); dbg("%s, file_name %s\n", __func__, meta.file_name[MTL_SESSION_PORT_P]); - if (ret >= 0) remove(meta.file_name[MTL_SESSION_PORT_P]); + if (ret >= 0) + remove(meta.file_name[MTL_SESSION_PORT_P]); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; } @@ -1174,11 +1199,12 @@ TEST(St22_rx, pcap_dump) { st22_rx_dump_test(fps, width, height, pkt_data_len, total_pkts, 1); } -static int st22_digest_rx_frame_ready(void* priv, void* frame, - struct st22_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st22_digest_rx_frame_ready(void *priv, void *frame, + struct st22_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; if (meta->frame_total_size != ctx->frame_size) { ctx->incomplete_frame_cnt++; @@ -1194,30 +1220,33 @@ static int st22_digest_rx_frame_ready(void* priv, void* frame, st22_rx_put_framebuff((st22_rx_handle)ctx->handle, frame); } ctx->fb_rec++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); dbg("%s, frame %p\n", __func__, frame); return 0; } -static void st22_digest_rx_frame_check(void* args) { - auto ctx = (tests_context*)args; +static void st22_digest_rx_frame_check(void *args) { + auto ctx = (tests_context *)args; std::unique_lock lck(ctx->mtx, std::defer_lock); unsigned char result[SHA256_DIGEST_LENGTH]; while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } else { - void* frame = ctx->buf_q.front(); + void *frame = ctx->buf_q.front(); ctx->buf_q.pop(); dbg("%s, frame %p\n", __func__, frame); int i; - SHA256((unsigned char*)frame, ctx->frame_size, result); + SHA256((unsigned char *)frame, ctx->frame_size, result); for (i = 0; i < ST22_TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = ctx->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= ST22_TEST_SHA_HIST_NUM) { test_sha_dump("st22_rx_error_sha", result); @@ -1234,23 +1263,25 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], int pkt_data_len[], int total_pkts[], enum st_test_level level, int sessions = 1, bool enable_rtcp = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -1280,11 +1311,11 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -1298,9 +1329,10 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = - (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * + test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -1322,13 +1354,13 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], /* sha calculate */ size_t frame_size = test_ctx_tx[i]->frame_size; - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < ST22_TEST_SHA_HIST_NUM; frame++) { - fb = (uint8_t*)st22_tx_get_fb_addr(tx_handle[i], frame); + fb = (uint8_t *)st22_tx_get_fb_addr(tx_handle[i], frame); ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st20_rx", result); } @@ -1376,9 +1408,10 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.rtp_ring_size = 1024; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = - (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * + test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -1408,7 +1441,8 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; @@ -1420,8 +1454,8 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); EXPECT_GT(test_ctx_rx[i]->check_sha_frame_cnt, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); EXPECT_EQ(test_ctx_rx[i]->incomplete_frame_cnt, 0); @@ -1450,30 +1484,33 @@ TEST(St22_rx, digest_rtcp_s2) { int height[2] = {1080, 1080}; int pkt_data_len[2] = {1280, 1280}; int total_pkts[2] = {551, 1520}; - st22_rx_digest_test(fps, width, height, pkt_data_len, total_pkts, ST_TEST_LEVEL_ALL, 2, - true); + st22_rx_digest_test(fps, width, height, pkt_data_len, total_pkts, + ST_TEST_LEVEL_ALL, 2, true); } -static void st22_tx_user_pacing_test(int width[], int height[], int pkt_data_len[], - int total_pkts[], enum st_test_level level, +static void st22_tx_user_pacing_test(int width[], int height[], + int pkt_data_len[], int total_pkts[], + enum st_test_level level, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -1505,11 +1542,11 @@ static void st22_tx_user_pacing_test(int width[], int height[], int pkt_data_len ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -1524,9 +1561,10 @@ static void st22_tx_user_pacing_test(int width[], int height[], int pkt_data_len ops_tx.flags = ST22_TX_FLAG_USER_PACING; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = - (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * + test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -1571,9 +1609,10 @@ static void st22_tx_user_pacing_test(int width[], int height[], int pkt_data_len ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = - (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = + total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * + test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -1593,7 +1632,8 @@ static void st22_tx_user_pacing_test(int width[], int height[], int pkt_data_len for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; rx_framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; tx_framerate[i] = test_ctx_tx[i]->fb_send / time_sec; @@ -1603,12 +1643,14 @@ static void st22_tx_user_pacing_test(int width[], int height[], int pkt_data_len EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - rx_framerate[i]); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx_tx[i]->fb_send, - tx_framerate[i]); - EXPECT_NEAR(rx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); - EXPECT_NEAR(tx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, rx_framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, + test_ctx_tx[i]->fb_send, tx_framerate[i]); + EXPECT_NEAR(rx_framerate[i], expect_framerate[i], + expect_framerate[i] * 0.1); + EXPECT_NEAR(tx_framerate[i], expect_framerate[i], + expect_framerate[i] * 0.1); ret = st22_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); ret = st22_rx_free(rx_handle[i]); @@ -1623,5 +1665,6 @@ TEST(St22_tx, tx_user_pacing) { int height[1] = {1080}; int pkt_data_len[1] = {1260}; int total_pkts[1] = {602}; - st22_tx_user_pacing_test(width, height, pkt_data_len, total_pkts, ST_TEST_LEVEL_ALL, 1); + st22_tx_user_pacing_test(width, height, pkt_data_len, total_pkts, + ST_TEST_LEVEL_ALL, 1); } diff --git a/tests/src/st22p_test.cpp b/tests/src/st22p_test.cpp index b063b6e21..654d9ed04 100644 --- a/tests/src/st22p_test.cpp +++ b/tests/src/st22p_test.cpp @@ -10,22 +10,29 @@ #define ST22P_TEST_PAYLOAD_TYPE (114) #define ST22P_TEST_UDP_PORT (16000) -static int test_encode_frame(struct test_st22_encoder_session* s, - struct st22_encode_frame_meta* frame) { - struct st22_encoder_create_req* req = &s->req; +static int test_encode_frame(struct test_st22_encoder_session *s, + struct st22_encode_frame_meta *frame) { + struct st22_encoder_create_req *req = &s->req; size_t codestream_size = req->max_codestream_size; /* check frame sanity */ - if (frame->src->width != req->width) return -EIO; - if (frame->dst->width != req->width) return -EIO; - if (frame->src->height != req->height) return -EIO; - if (frame->dst->height != req->height) return -EIO; - if (frame->src->fmt != req->input_fmt) return -EIO; - if (frame->dst->fmt != req->output_fmt) return -EIO; + if (frame->src->width != req->width) + return -EIO; + if (frame->dst->width != req->width) + return -EIO; + if (frame->src->height != req->height) + return -EIO; + if (frame->dst->height != req->height) + return -EIO; + if (frame->src->fmt != req->input_fmt) + return -EIO; + if (frame->dst->fmt != req->output_fmt) + return -EIO; /* copy src sha to the start of encode frame */ memcpy(frame->dst->addr[0], - (uint8_t*)frame->src->addr[0] + frame->src->data_size - SHA256_DIGEST_LENGTH, + (uint8_t *)frame->src->addr[0] + frame->src->data_size - + SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH); st_usleep(s->sleep_time_us); /* data size indicate the encode stream size for current frame */ @@ -36,7 +43,8 @@ static int test_encode_frame(struct test_st22_encoder_session* s, frame->dst->data_size = codestream_size; s->frame_cnt++; - dbg("%s(%d), succ, codestream_size %" PRIu64 "\n", __func__, s->idx, codestream_size); + dbg("%s(%d), succ, codestream_size %" PRIu64 "\n", __func__, s->idx, + codestream_size); /* simulate fail and timeout */ if (s->fail_interval) { @@ -53,14 +61,15 @@ static int test_encode_frame(struct test_st22_encoder_session* s, return 0; } -static void* test_encode_thread(void* arg) { - struct test_st22_encoder_session* s = (struct test_st22_encoder_session*)arg; +static void *test_encode_thread(void *arg) { + struct test_st22_encoder_session *s = (struct test_st22_encoder_session *)arg; st22p_encode_session session_p = s->session_p; - struct st_tests_context* ctx = s->ctx; - struct st22_encode_frame_meta* frame; + struct st_tests_context *ctx = s->ctx; + struct st22_encode_frame_meta *frame; int result; - if (ctx->encoder_use_block_get) st22_encoder_set_block_timeout(session_p, NS_PER_S); + if (ctx->encoder_use_block_get) + st22_encoder_set_block_timeout(session_p, NS_PER_S); dbg("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -68,7 +77,8 @@ static void* test_encode_thread(void* arg) { if (!frame) { /* no frame */ if (!ctx->encoder_use_block_get) { st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); } continue; @@ -81,17 +91,19 @@ static void* test_encode_thread(void* arg) { return NULL; } -static st22_encode_priv test_encoder_create_session(void* priv, - st22p_encode_session session_p, - struct st22_encoder_create_req* req) { - struct st_tests_context* ctx = (struct st_tests_context*)priv; - struct test_st22_encoder_session* session = NULL; +static st22_encode_priv +test_encoder_create_session(void *priv, st22p_encode_session session_p, + struct st22_encoder_create_req *req) { + struct st_tests_context *ctx = (struct st_tests_context *)priv; + struct test_st22_encoder_session *session = NULL; int ret; for (int i = 0; i < MAX_TEST_ENCODER_SESSIONS; i++) { - if (ctx->encoder_sessions[i]) continue; - session = (struct test_st22_encoder_session*)malloc(sizeof(*session)); - if (!session) return NULL; + if (ctx->encoder_sessions[i]) + continue; + session = (struct test_st22_encoder_session *)malloc(sizeof(*session)); + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->ctx = ctx; session->idx = i; @@ -99,12 +111,14 @@ static st22_encode_priv test_encoder_create_session(void* priv, st_pthread_cond_init(&session->wake_cond, NULL); req->max_codestream_size = req->codestream_size; - if (ctx->encoder_use_block_get) req->resp_flag |= ST22_ENCODER_RESP_FLAG_BLOCK_GET; + if (ctx->encoder_use_block_get) + req->resp_flag |= ST22_ENCODER_RESP_FLAG_BLOCK_GET; session->req = *req; session->session_p = session_p; double fps = st_frame_rate(req->fps); - if (!fps) fps = 60; + if (!fps) + fps = 60; session->sleep_time_us = 1000 * 1000 / fps * 8 / 10; dbg("%s(%d), sleep_time_us %d\n", __func__, i, session->sleep_time_us); session->fail_interval = ctx->plugin_fail_interval; @@ -112,7 +126,8 @@ static st22_encode_priv test_encoder_create_session(void* priv, session->timeout_ms = ctx->plugin_timeout_ms; session->rand_ratio = ctx->plugin_rand_ratio; - ret = pthread_create(&session->encode_thread, NULL, test_encode_thread, session); + ret = pthread_create(&session->encode_thread, NULL, test_encode_thread, + session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -132,10 +147,10 @@ static st22_encode_priv test_encoder_create_session(void* priv, return NULL; } -static int test_encoder_free_session(void* priv, st22_encode_priv session) { - struct st_tests_context* ctx = (struct st_tests_context*)priv; - struct test_st22_encoder_session* encoder_session = - (struct test_st22_encoder_session*)session; +static int test_encoder_free_session(void *priv, st22_encode_priv session) { + struct st_tests_context *ctx = (struct st_tests_context *)priv; + struct test_st22_encoder_session *encoder_session = + (struct test_st22_encoder_session *)session; int idx = encoder_session->idx; encoder_session->stop = true; @@ -151,17 +166,20 @@ static int test_encoder_free_session(void* priv, st22_encode_priv session) { st_pthread_mutex_destroy(&encoder_session->wake_mutex); st_pthread_cond_destroy(&encoder_session->wake_cond); - dbg("%s(%d), total %d encode frames\n", __func__, idx, encoder_session->frame_cnt); + dbg("%s(%d), total %d encode frames\n", __func__, idx, + encoder_session->frame_cnt); free(encoder_session); ctx->encoder_sessions[idx] = NULL; return 0; } -static int test_encoder_frame_available(void* priv) { - struct test_st22_encoder_session* s = (struct test_st22_encoder_session*)priv; - struct st_tests_context* ctx = s->ctx; +static int test_encoder_frame_available(void *priv) { + struct test_st22_encoder_session *s = + (struct test_st22_encoder_session *)priv; + struct st_tests_context *ctx = s->ctx; - if (ctx->encoder_use_block_get) return 0; + if (ctx->encoder_use_block_get) + return 0; // dbg("%s(%d)\n", __func__, s->idx); st_pthread_mutex_lock(&s->wake_mutex); @@ -171,21 +189,29 @@ static int test_encoder_frame_available(void* priv) { return 0; } -static int test_decode_frame(struct test_st22_decoder_session* s, - struct st22_decode_frame_meta* frame) { - struct st22_decoder_create_req* req = &s->req; +static int test_decode_frame(struct test_st22_decoder_session *s, + struct st22_decode_frame_meta *frame) { + struct st22_decoder_create_req *req = &s->req; /* check frame sanity */ - if (frame->src->width != req->width) return -EIO; - if (frame->dst->width != req->width) return -EIO; - if (frame->src->height != req->height) return -EIO; - if (frame->dst->height != req->height) return -EIO; - if (frame->src->fmt != req->input_fmt) return -EIO; - if (frame->dst->fmt != req->output_fmt) return -EIO; - if (frame->src->data_size > frame->src->buffer_size) return -EIO; + if (frame->src->width != req->width) + return -EIO; + if (frame->dst->width != req->width) + return -EIO; + if (frame->src->height != req->height) + return -EIO; + if (frame->dst->height != req->height) + return -EIO; + if (frame->src->fmt != req->input_fmt) + return -EIO; + if (frame->dst->fmt != req->output_fmt) + return -EIO; + if (frame->src->data_size > frame->src->buffer_size) + return -EIO; /* copy sha to the end of decode frame */ - memcpy((uint8_t*)frame->dst->addr[0] + frame->dst->data_size - SHA256_DIGEST_LENGTH, + memcpy((uint8_t *)frame->dst->addr[0] + frame->dst->data_size - + SHA256_DIGEST_LENGTH, frame->src->addr[0], SHA256_DIGEST_LENGTH); st_usleep(s->sleep_time_us); @@ -207,14 +233,15 @@ static int test_decode_frame(struct test_st22_decoder_session* s, return 0; } -static void* test_decode_thread(void* arg) { - struct test_st22_decoder_session* s = (struct test_st22_decoder_session*)arg; +static void *test_decode_thread(void *arg) { + struct test_st22_decoder_session *s = (struct test_st22_decoder_session *)arg; st22p_decode_session session_p = s->session_p; - struct st_tests_context* ctx = s->ctx; - struct st22_decode_frame_meta* frame; + struct st_tests_context *ctx = s->ctx; + struct st22_decode_frame_meta *frame; int result; - if (ctx->encoder_use_block_get) st22_decoder_set_block_timeout(session_p, NS_PER_S); + if (ctx->encoder_use_block_get) + st22_decoder_set_block_timeout(session_p, NS_PER_S); dbg("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -222,7 +249,8 @@ static void* test_decode_thread(void* arg) { if (!frame) { /* no frame */ if (!ctx->decoder_use_block_get) { st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) + st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); } continue; @@ -235,17 +263,19 @@ static void* test_decode_thread(void* arg) { return NULL; } -static st22_decode_priv test_decoder_create_session(void* priv, - st22p_decode_session session_p, - struct st22_decoder_create_req* req) { - struct st_tests_context* ctx = (struct st_tests_context*)priv; - struct test_st22_decoder_session* session = NULL; +static st22_decode_priv +test_decoder_create_session(void *priv, st22p_decode_session session_p, + struct st22_decoder_create_req *req) { + struct st_tests_context *ctx = (struct st_tests_context *)priv; + struct test_st22_decoder_session *session = NULL; int ret; for (int i = 0; i < MAX_TEST_DECODER_SESSIONS; i++) { - if (ctx->decoder_sessions[i]) continue; - session = (struct test_st22_decoder_session*)malloc(sizeof(*session)); - if (!session) return NULL; + if (ctx->decoder_sessions[i]) + continue; + session = (struct test_st22_decoder_session *)malloc(sizeof(*session)); + if (!session) + return NULL; memset(session, 0, sizeof(*session)); session->idx = i; session->ctx = ctx; @@ -259,14 +289,16 @@ static st22_decode_priv test_decoder_create_session(void* priv, session->req = *req; session->session_p = session_p; double fps = st_frame_rate(req->fps); - if (!fps) fps = 60; + if (!fps) + fps = 60; session->sleep_time_us = 1000 * 1000 / fps * 8 / 10; dbg("%s(%d), sleep_time_us %d\n", __func__, i, session->sleep_time_us); session->fail_interval = ctx->plugin_fail_interval; session->timeout_interval = ctx->plugin_timeout_interval; session->timeout_ms = ctx->plugin_timeout_ms; - ret = pthread_create(&session->decode_thread, NULL, test_decode_thread, session); + ret = pthread_create(&session->decode_thread, NULL, test_decode_thread, + session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -285,10 +317,10 @@ static st22_decode_priv test_decoder_create_session(void* priv, return NULL; } -static int test_decoder_free_session(void* priv, st22_decode_priv session) { - struct st_tests_context* ctx = (struct st_tests_context*)priv; - struct test_st22_decoder_session* decoder_session = - (struct test_st22_decoder_session*)session; +static int test_decoder_free_session(void *priv, st22_decode_priv session) { + struct st_tests_context *ctx = (struct st_tests_context *)priv; + struct test_st22_decoder_session *decoder_session = + (struct test_st22_decoder_session *)session; int idx = decoder_session->idx; decoder_session->stop = true; @@ -304,17 +336,20 @@ static int test_decoder_free_session(void* priv, st22_decode_priv session) { st_pthread_mutex_destroy(&decoder_session->wake_mutex); st_pthread_cond_destroy(&decoder_session->wake_cond); - dbg("%s(%d), total %d decode frames\n", __func__, idx, decoder_session->frame_cnt); + dbg("%s(%d), total %d decode frames\n", __func__, idx, + decoder_session->frame_cnt); free(decoder_session); ctx->decoder_sessions[idx] = NULL; return 0; } -static int test_decoder_frame_available(void* priv) { - struct test_st22_decoder_session* s = (struct test_st22_decoder_session*)priv; - struct st_tests_context* ctx = s->ctx; +static int test_decoder_frame_available(void *priv) { + struct test_st22_decoder_session *s = + (struct test_st22_decoder_session *)priv; + struct st_tests_context *ctx = s->ctx; - if (ctx->decoder_use_block_get) return 0; + if (ctx->decoder_use_block_get) + return 0; // dbg("%s(%d)\n", __func__, s->idx); st_pthread_mutex_lock(&s->wake_mutex); @@ -324,7 +359,7 @@ static int test_decoder_frame_available(void* priv) { return 0; } -int st_test_st22_plugin_unregister(struct st_tests_context* ctx) { +int st_test_st22_plugin_unregister(struct st_tests_context *ctx) { if (ctx->decoder_dev_handle) { st22_decoder_unregister(ctx->decoder_dev_handle); ctx->decoder_dev_handle = NULL; @@ -337,7 +372,7 @@ int st_test_st22_plugin_unregister(struct st_tests_context* ctx) { return 0; } -int st_test_st22_plugin_register(struct st_tests_context* ctx) { +int st_test_st22_plugin_register(struct st_tests_context *ctx) { auto st = ctx->handle; int ret = 0; @@ -346,8 +381,10 @@ int st_test_st22_plugin_register(struct st_tests_context* ctx) { d_dev.name = "st22_test_decoder"; d_dev.priv = ctx; d_dev.target_device = ST_PLUGIN_DEVICE_TEST; - d_dev.input_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; - d_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8; + d_dev.input_fmt_caps = + ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + d_dev.output_fmt_caps = + ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8; d_dev.create_session = test_decoder_create_session; d_dev.free_session = test_decoder_free_session; d_dev.notify_frame_available = test_decoder_frame_available; @@ -363,7 +400,8 @@ int st_test_st22_plugin_register(struct st_tests_context* ctx) { e_dev.priv = ctx; e_dev.target_device = ST_PLUGIN_DEVICE_TEST; e_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8; - e_dev.output_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + e_dev.output_fmt_caps = + ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; e_dev.create_session = test_encoder_create_session; e_dev.free_session = test_encoder_free_session; e_dev.notify_frame_available = test_encoder_frame_available; @@ -377,7 +415,7 @@ int st_test_st22_plugin_register(struct st_tests_context* ctx) { return 0; } -static void plugin_register_test(const char* so_name, bool expect_succ) { +static void plugin_register_test(const char *so_name, bool expect_succ) { auto ctx = st_test_ctx(); auto st = ctx->handle; @@ -393,26 +431,27 @@ static void plugin_register_test(const char* so_name, bool expect_succ) { } TEST(St22p, plugin_register_single) { - plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", true); + plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", + true); } TEST(St22p, plugin_register_fail) { - plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", - false); + plugin_register_test( + "/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", false); } static void frame_draw_logo_test(enum st_frame_fmt fmt, uint32_t w, uint32_t h, - uint32_t logo_w, uint32_t logo_h, uint32_t x, uint32_t y, - bool expect) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + uint32_t logo_w, uint32_t logo_h, uint32_t x, + uint32_t y, bool expect) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto st = ctx->handle; size_t logo_size = st_frame_size(fmt, logo_w, logo_h, false); size_t frame_size = st_frame_size(fmt, w, h, false); - void* frame_buf = mtl_hp_malloc(st, frame_size, MTL_PORT_P); + void *frame_buf = mtl_hp_malloc(st, frame_size, MTL_PORT_P); if (!frame_buf) { err("%s, frame_buf malloc fail\n", __func__); return; } - void* logo_buf = mtl_hp_malloc(st, logo_size, MTL_PORT_P); + void *logo_buf = mtl_hp_malloc(st, logo_size, MTL_PORT_P); if (!logo_buf) { err("%s, logo_buf malloc fail\n", __func__); mtl_hp_free(st, frame_buf); @@ -441,36 +480,38 @@ static void frame_draw_logo_test(enum st_frame_fmt fmt, uint32_t w, uint32_t h, } TEST(St22p, draw_logo_rfc4175_1080p) { - frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 200, 200, 16, 16, - true); + frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 200, 200, + 16, 16, true); } TEST(St22p, draw_logo_rfc4175_1080p_full) { - frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, 1080, 0, 0, - true); + frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, + 1080, 0, 0, true); } TEST(St22p, draw_logo_rfc4175_1080p_fail) { - frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, 1080, 100, - 100, false); + frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, + 1080, 100, 100, false); } -static int test_st22p_tx_frame_available(void* priv) { - tests_context* s = (tests_context*)priv; +static int test_st22p_tx_frame_available(void *priv) { + tests_context *s = (tests_context *)priv; s->cv.notify_all(); return 0; } -static int test_st22p_tx_frame_done(void* priv, struct st_frame* frame) { - tests_context* s = (tests_context*)priv; +static int test_st22p_tx_frame_done(void *priv, struct st_frame *frame) { + tests_context *s = (tests_context *)priv; - if (!s->handle) return -EIO; /* not ready */ + if (!s->handle) + return -EIO; /* not ready */ s->fb_send_done++; - if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) return 0; + if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) + return 0; for (int i = 0; i < s->fb_cnt; ++i) { if (frame->addr[0] == s->ext_fb + i * s->frame_size) { @@ -484,18 +525,19 @@ static int test_st22p_tx_frame_done(void* priv, struct st_frame* frame) { return 0; } -static int test_st22p_rx_frame_available(void* priv) { - tests_context* s = (tests_context*)priv; +static int test_st22p_rx_frame_available(void *priv) { + tests_context *s = (tests_context *)priv; s->cv.notify_all(); return 0; } -static int test_st22p_rx_query_ext_frame(void* priv, st_ext_frame* ext_frame, - struct st22_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; - if (!ctx->handle) return -EIO; /* not ready */ +static int test_st22p_rx_query_ext_frame(void *priv, st_ext_frame *ext_frame, + struct st22_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; + if (!ctx->handle) + return -EIO; /* not ready */ int i = ctx->ext_idx; /* check ext_fb_in_use */ @@ -505,24 +547,27 @@ static int test_st22p_rx_query_ext_frame(void* priv, st_ext_frame* ext_frame, } *ext_frame = ctx->p_ext_frames[i]; - dbg("%s(%d), set ext frame %d(%p) to use\n", __func__, ctx->idx, i, ext_frame->addr); + dbg("%s(%d), set ext frame %d(%p) to use\n", __func__, ctx->idx, i, + ext_frame->addr); ctx->ext_fb_in_use[i] = true; ext_frame->opaque = &ctx->ext_fb_in_use[i]; - if (++ctx->ext_idx >= ctx->fb_cnt) ctx->ext_idx = 0; + if (++ctx->ext_idx >= ctx->fb_cnt) + ctx->ext_idx = 0; return 0; } -static void st22p_tx_ops_init(tests_context* st22, struct st22p_tx_ops* ops_tx) { +static void st22p_tx_ops_init(tests_context *st22, + struct st22p_tx_ops *ops_tx) { auto ctx = st22->ctx; memset(ops_tx, 0, sizeof(*ops_tx)); ops_tx->name = "st22p_test"; ops_tx->priv = st22; ops_tx->port.num_port = 1; - memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx->port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + st22->idx; @@ -543,15 +588,16 @@ static void st22p_tx_ops_init(tests_context* st22, struct st22p_tx_ops* ops_tx) ops_tx->notify_event = test_ctx_notify_event; } -static void st22p_rx_ops_init(tests_context* st22, struct st22p_rx_ops* ops_rx) { +static void st22p_rx_ops_init(tests_context *st22, + struct st22p_rx_ops *ops_rx) { auto ctx = st22->ctx; memset(ops_rx, 0, sizeof(*ops_rx)); ops_rx->name = "st22p_test"; ops_rx->priv = st22; ops_rx->port.num_port = 1; - memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx->port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + st22->idx; @@ -616,12 +662,8 @@ TEST(St22p, tx_create_free_max) { TEST(St22p, rx_create_free_max) { pipeline_create_free_max(st22p_rx, TEST_CREATE_FREE_MAX); } -TEST(St22p, tx_create_expect_fail) { - pipeline_expect_fail_test(st22p_tx); -} -TEST(St22p, rx_create_expect_fail) { - pipeline_expect_fail_test(st22p_rx); -} +TEST(St22p, tx_create_expect_fail) { pipeline_expect_fail_test(st22p_tx); } +TEST(St22p, rx_create_expect_fail) { pipeline_expect_fail_test(st22p_rx); } TEST(St22p, tx_create_expect_fail_fb_cnt) { uint16_t fbcnt = 1; pipeline_expect_fail_test_fb_cnt(st22p_tx, fbcnt); @@ -635,10 +677,10 @@ TEST(St22p, rx_create_expect_fail_fb_cnt) { pipeline_expect_fail_test_fb_cnt(st22p_rx, fbcnt); } -static void test_st22p_tx_frame_thread(void* args) { - tests_context* s = (tests_context*)args; +static void test_st22p_tx_frame_thread(void *args) { + tests_context *s = (tests_context *)args; auto handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; std::unique_lock lck(s->mtx, std::defer_lock); dbg("%s(%d), start\n", __func__, s->idx); @@ -647,16 +689,22 @@ static void test_st22p_tx_frame_thread(void* args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) s->cv.wait(lck); + if (!s->stop) + s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->width != s->width) s->incomplete_frame_cnt++; - if (frame->height != s->height) s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->width != s->width) + s->incomplete_frame_cnt++; + if (frame->height != s->height) + s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) + s->incomplete_frame_cnt++; if (s->user_timestamp) { frame->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; frame->timestamp = s->fb_send; @@ -666,12 +714,14 @@ static void test_st22p_tx_frame_thread(void* args) { int ret = st22p_tx_put_ext_frame((st22p_tx_handle)handle, frame, &s->p_ext_frames[s->ext_idx]); if (ret < 0) { - err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, s->ext_idx); + err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, + s->ext_idx); continue; } s->ext_fb_in_use[s->ext_idx] = true; s->ext_idx++; - if (s->ext_idx >= s->fb_cnt) s->ext_idx = 0; + if (s->ext_idx >= s->fb_cnt) + s->ext_idx = 0; } else { /* directly put */ st22p_tx_put_frame((st22p_tx_handle)handle, frame); @@ -685,10 +735,10 @@ static void test_st22p_tx_frame_thread(void* args) { dbg("%s(%d), stop\n", __func__, s->idx); } -static void test_st22p_rx_frame_thread(void* args) { - tests_context* s = (tests_context*)args; +static void test_st22p_rx_frame_thread(void *args) { + tests_context *s = (tests_context *)args; auto handle = s->handle; - struct st_frame* frame; + struct st_frame *frame; std::unique_lock lck(s->mtx, std::defer_lock); uint64_t timestamp = 0; @@ -698,24 +748,31 @@ static void test_st22p_rx_frame_thread(void* args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) s->cv.wait(lck); + if (!s->stop) + s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->buffer_size < s->frame_size) s->incomplete_frame_cnt++; - if (frame->width != s->width) s->incomplete_frame_cnt++; - if (frame->height != s->height) s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->buffer_size < s->frame_size) + s->incomplete_frame_cnt++; + if (frame->width != s->width) + s->incomplete_frame_cnt++; + if (frame->height != s->height) + s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) + s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) + s->incomplete_frame_cnt++; timestamp = frame->timestamp; if (frame->opaque) { /* free dynamic ext frame */ - bool* in_use = (bool*)frame->opaque; + bool *in_use = (bool *)frame->opaque; EXPECT_TRUE(*in_use); *in_use = false; } @@ -729,19 +786,20 @@ static void test_st22p_rx_frame_thread(void* args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, - s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", + __func__, s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; } - unsigned char* sha = - (unsigned char*)frame->addr[0] + frame->data_size - SHA256_DIGEST_LENGTH; + unsigned char *sha = (unsigned char *)frame->addr[0] + frame->data_size - + SHA256_DIGEST_LENGTH; int i = 0; for (i = 0; i < ST22_TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = s->shas[i]; - if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = s->shas[i]; + if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= ST22_TEST_SHA_HIST_NUM) { test_sha_dump("st22p_rx_error_sha", sha); @@ -750,7 +808,8 @@ static void test_st22p_rx_frame_thread(void* args) { /* directly put */ st22p_rx_put_frame((st22p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) + s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } @@ -775,7 +834,8 @@ struct st22p_rx_digest_test_para { bool derive; }; -static void test_st22p_init_rx_digest_para(struct st22p_rx_digest_test_para* para) { +static void +test_st22p_init_rx_digest_para(struct st22p_rx_digest_test_para *para) { memset(para, 0, sizeof(*para)); para->sessions = 1; @@ -797,10 +857,10 @@ static void test_st22p_init_rx_digest_para(struct st22p_rx_digest_test_para* par } static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], - enum st_frame_fmt fmt[], enum st22_codec codec[], - int compress_ratio[], - struct st22p_rx_digest_test_para* para) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + enum st_frame_fmt fmt[], + enum st22_codec codec[], int compress_ratio[], + struct st22p_rx_digest_test_para *para) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto st = ctx->handle; int ret; struct st22p_tx_ops ops_tx; @@ -814,12 +874,14 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], st_test_jxs_use_block_get(ctx, para->codec_block_get); if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled, one for tx and one for rx\n", __func__); + info("%s, dual port should be enabled, one for tx and one for rx\n", + __func__); return; } /* return if level lower than global */ - if (para->level < ctx->level) return; + if (para->level < ctx->level) + return; if (para->tx_ext || para->rx_ext) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -828,8 +890,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], } } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate_tx; @@ -857,8 +919,9 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { expect_framerate_tx[i] = st_frame_rate(fps[i]); if (para->timeout_interval) { - expect_framerate_tx[i] = - expect_framerate_tx[i] * (para->timeout_interval - 1) / para->timeout_interval; + expect_framerate_tx[i] = expect_framerate_tx[i] * + (para->timeout_interval - 1) / + para->timeout_interval; } test_ctx_tx[i] = new tests_context(); @@ -879,11 +942,11 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + i * 2; @@ -905,8 +968,10 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.notify_frame_available = test_st22p_tx_frame_available; ops_tx.notify_event = test_ctx_notify_event; ops_tx.notify_frame_done = test_st22p_tx_frame_done; - if (para->user_timestamp) ops_tx.flags |= ST22P_TX_FLAG_USER_TIMESTAMP; - if (para->vsync) ops_tx.flags |= ST22P_TX_FLAG_ENABLE_VSYNC; + if (para->user_timestamp) + ops_tx.flags |= ST22P_TX_FLAG_USER_TIMESTAMP; + if (para->vsync) + ops_tx.flags |= ST22P_TX_FLAG_ENABLE_VSYNC; if (para->tx_ext) { ops_tx.flags |= ST22P_TX_FLAG_EXT_FRAME; } @@ -920,8 +985,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.codestream_size = ops_tx.width * ops_tx.height / compress_ratio[i]; test_ctx_tx[i]->frame_size = ops_tx.codestream_size; } else { - test_ctx_tx[i]->frame_size = - st_frame_size(ops_tx.input_fmt, ops_tx.width, ops_tx.height, ops_tx.interlaced); + test_ctx_tx[i]->frame_size = st_frame_size( + ops_tx.input_fmt, ops_tx.width, ops_tx.height, ops_tx.interlaced); ops_tx.codestream_size = test_ctx_tx[i]->frame_size / compress_ratio[i]; } @@ -939,7 +1004,7 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], uint8_t planes = st_frame_fmt_planes(fmt[i]); size_t frame_size = test_ctx_tx[i]->frame_size; - test_ctx_tx[i]->p_ext_frames = (struct st_ext_frame*)malloc( + test_ctx_tx[i]->p_ext_frames = (struct st_ext_frame *)malloc( sizeof(*test_ctx_tx[i]->p_ext_frames) * test_ctx_tx[i]->fb_cnt); size_t pg_sz = mtl_page_size(st); size_t fb_size = test_ctx_tx[i]->frame_size * test_ctx_tx[i]->fb_cnt; @@ -949,14 +1014,15 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_tx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_malloc != NULL); test_ctx_tx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); - test_ctx_tx[i]->ext_fb_iova = - mtl_dma_map(st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); + test_ctx_tx[i]->ext_fb_iova = mtl_dma_map( + st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_iova != MTL_BAD_IOVA); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_tx[i]->ext_fb); for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; + plane++) { /* assume planes continuous */ test_ctx_tx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(fmt[i], width[i], plane); if (plane == 0) { @@ -966,7 +1032,7 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_tx[i]->ext_fb_iova + j * frame_size; } else { test_ctx_tx[i]->p_ext_frames[j].addr[plane] = - (uint8_t*)test_ctx_tx[i]->p_ext_frames[j].addr[plane - 1] + + (uint8_t *)test_ctx_tx[i]->p_ext_frames[j].addr[plane - 1] + test_ctx_tx[i]->p_ext_frames[j].linesize[plane - 1] * height[i]; test_ctx_tx[i]->p_ext_frames[j].iova[plane] = test_ctx_tx[i]->p_ext_frames[j].iova[plane - 1] + @@ -980,19 +1046,20 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], /* sha calculate */ size_t frame_size = test_ctx_tx[i]->frame_size; - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < ST22_TEST_SHA_HIST_NUM; frame++) { if (para->tx_ext) - fb = (uint8_t*)test_ctx_tx[i]->ext_fb + frame * frame_size; + fb = (uint8_t *)test_ctx_tx[i]->ext_fb + frame * frame_size; else - fb = (uint8_t*)st22p_tx_get_fb_addr(tx_handle[i], frame); + fb = (uint8_t *)st22p_tx_get_fb_addr(tx_handle[i], frame); ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st22p_tx", result); /* copy sha to the end of frame */ - memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, SHA256_DIGEST_LENGTH); + memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, + SHA256_DIGEST_LENGTH); } test_ctx_tx[i]->handle = tx_handle[i]; @@ -1003,8 +1070,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { if (para->fail_interval) { /* loss in the tx */ - expect_framerate_tx[i] = - expect_framerate_tx[i] * (para->fail_interval - 1) / para->fail_interval; + expect_framerate_tx[i] = expect_framerate_tx[i] * + (para->fail_interval - 1) / para->fail_interval; } expect_framerate_rx[i] = expect_framerate_tx[i]; test_ctx_rx[i] = new tests_context(); @@ -1025,7 +1092,7 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], if (para->rx_ext) { uint8_t planes = st_frame_fmt_planes(fmt[i]); - test_ctx_rx[i]->p_ext_frames = (struct st_ext_frame*)malloc( + test_ctx_rx[i]->p_ext_frames = (struct st_ext_frame *)malloc( sizeof(*test_ctx_rx[i]->p_ext_frames) * test_ctx_rx[i]->fb_cnt); size_t frame_size = st_frame_size(fmt[i], width[i], height[i], false); size_t pg_sz = mtl_page_size(st); @@ -1036,14 +1103,15 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = - (uint8_t*)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = - mtl_dma_map(st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); + (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); + test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( + st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; + plane++) { /* assume planes continuous */ test_ctx_rx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(fmt[i], width[i], plane); if (plane == 0) { @@ -1053,7 +1121,7 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->ext_fb_iova + j * frame_size; } else { test_ctx_rx[i]->p_ext_frames[j].addr[plane] = - (uint8_t*)test_ctx_rx[i]->p_ext_frames[j].addr[plane - 1] + + (uint8_t *)test_ctx_rx[i]->p_ext_frames[j].addr[plane - 1] + test_ctx_rx[i]->p_ext_frames[j].linesize[plane - 1] * height[i]; test_ctx_rx[i]->p_ext_frames[j].iova[plane] = test_ctx_rx[i]->p_ext_frames[j].iova[plane - 1] + @@ -1070,11 +1138,11 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.priv = test_ctx_rx[i]; ops_rx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + i * 2; @@ -1094,14 +1162,16 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], else ops_rx.notify_frame_available = test_st22p_rx_frame_available; ops_rx.notify_event = test_ctx_notify_event; - if (para->vsync) ops_rx.flags |= ST22P_RX_FLAG_ENABLE_VSYNC; + if (para->vsync) + ops_rx.flags |= ST22P_RX_FLAG_ENABLE_VSYNC; if (para->rx_ext) { ops_rx.flags |= ST22P_RX_FLAG_EXT_FRAME; ops_rx.query_ext_frame = test_st22p_rx_query_ext_frame; } if (para->rtcp) { - ops_rx.flags |= ST22P_RX_FLAG_ENABLE_RTCP | ST22P_RX_FLAG_SIMULATE_PKT_LOSS; + ops_rx.flags |= + ST22P_RX_FLAG_ENABLE_RTCP | ST22P_RX_FLAG_SIMULATE_PKT_LOSS; ops_rx.rtcp.nack_interval_us = 100; ops_rx.rtcp.seq_skip_window = 0; ops_rx.rtcp.burst_loss_max = 4; @@ -1111,8 +1181,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], if (para->derive) test_ctx_rx[i]->frame_size = test_ctx_tx[i]->frame_size; else - test_ctx_rx[i]->frame_size = st_frame_size(ops_rx.output_fmt, ops_rx.width, - ops_rx.height, ops_rx.interlaced); + test_ctx_rx[i]->frame_size = st_frame_size( + ops_rx.output_fmt, ops_rx.width, ops_rx.height, ops_rx.interlaced); rx_handle[i] = st22p_rx_create(st, &ops_rx); ASSERT_TRUE(rx_handle[i] != NULL); @@ -1142,37 +1212,45 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; framerate_tx[i] = test_ctx_tx[i]->fb_send / time_sec; /* vsync check */ - time_sec = (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; + time_sec = + (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; vsyncrate_tx[i] = test_ctx_tx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_tx[i], test_ctx_tx[i]->vsync_cnt, vsyncrate_tx[i]); EXPECT_GT(test_ctx_tx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), + st_frame_rate(fps[i]) * 0.1); test_ctx_tx[i]->stop = true; - if (para->block_get) st22p_tx_wake_block(tx_handle[i]); + if (para->block_get) + st22p_tx_wake_block(tx_handle[i]); test_ctx_tx[i]->cv.notify_all(); tx_thread[i].join(); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate_rx[i] = test_ctx_rx[i]->fb_rec / time_sec; /* vsync check */ - time_sec = (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; + time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; vsyncrate_rx[i] = test_ctx_rx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_rx[i], test_ctx_rx[i]->vsync_cnt, vsyncrate_rx[i]); EXPECT_GT(test_ctx_rx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), + st_frame_rate(fps[i]) * 0.1); test_ctx_rx[i]->stop = true; - if (para->block_get) st22p_rx_wake_block(rx_handle[i]); + if (para->block_get) + st22p_rx_wake_block(rx_handle[i]); test_ctx_rx[i]->cv.notify_all(); rx_thread[i].join(); } diff --git a/tests/src/st30_test.cpp b/tests/src/st30_test.cpp index 26bd1da0f..19bc970f5 100644 --- a/tests/src/st30_test.cpp +++ b/tests/src/st30_test.cpp @@ -9,34 +9,39 @@ #define ST30_TEST_PAYLOAD_TYPE (111) -static int tx_audio_next_frame(void* priv, uint16_t* next_frame_idx, - struct st30_tx_frame_meta* meta) { +static int tx_audio_next_frame(void *priv, uint16_t *next_frame_idx, + struct st30_tx_frame_meta *meta) { return tx_next_frame(priv, next_frame_idx); } -static int tx_audio_next_frame_timestamp(void* priv, uint16_t* next_frame_idx, - struct st30_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_audio_next_frame_timestamp(void *priv, uint16_t *next_frame_idx, + struct st30_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ if (!ctx->ptp_time_first_frame) { ctx->ptp_time_first_frame = mtl_ptp_read_time(ctx->ctx->handle); } meta->tfmt = ST10_TIMESTAMP_FMT_TAI; - meta->timestamp = ctx->ptp_time_first_frame + ctx->fb_send * ctx->frame_time * 2; + meta->timestamp = + ctx->ptp_time_first_frame + ctx->fb_send * ctx->frame_time * 2; *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_audio_build_rtp_packet(tests_context* s, struct st_rfc3550_rtp_hdr* rtp, - uint16_t* pkt_len) { +static int tx_audio_build_rtp_packet(tests_context *s, + struct st_rfc3550_rtp_hdr *rtp, + uint16_t *pkt_len) { /* rtp hdr */ memset(rtp, 0x0, sizeof(*rtp)); rtp->csrc_count = 0; @@ -50,21 +55,23 @@ static int tx_audio_build_rtp_packet(tests_context* s, struct st_rfc3550_rtp_hdr s->rtp_tmstamp++; rtp->seq_number = htons(s->seq_id); s->seq_id++; - if (s->seq_id == 0x10000) s->seq_id = 0; + if (s->seq_id == 0x10000) + s->seq_id = 0; if (s->check_sha) { - uint8_t* payload = (uint8_t*)rtp + sizeof(*rtp); + uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); mtl_memcpy(payload, s->frame_buf[s->fb_idx], s->pkt_data_len); s->fb_idx++; - if (s->fb_idx >= TEST_SHA_HIST_NUM) s->fb_idx = 0; + if (s->fb_idx >= TEST_SHA_HIST_NUM) + s->fb_idx = 0; } *pkt_len = sizeof(struct st_rfc3550_rtp_hdr) + s->pkt_data_len; return 0; } -static void tx_feed_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void tx_feed_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); while (!ctx->stop) { @@ -77,45 +84,51 @@ static void tx_feed_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - tx_audio_build_rtp_packet(ctx, (struct st_rfc3550_rtp_hdr*)usrptr, &mbuf_len); + tx_audio_build_rtp_packet(ctx, (struct st_rfc3550_rtp_hdr *)usrptr, + &mbuf_len); st30_tx_put_mbuf((st30_tx_handle)ctx->handle, mbuf, mbuf_len); } } -static int tx_rtp_done(void* args) { - auto ctx = (tests_context*)args; +static int tx_rtp_done(void *args) { + auto ctx = (tests_context *)args; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); ctx->fb_send++; return 0; } -static int rx_rtp_ready(void* args) { - auto ctx = (tests_context*)args; +static int rx_rtp_ready(void *args) { + auto ctx = (tests_context *)args; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static void rx_get_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void rx_get_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); while (!ctx->stop) { @@ -128,20 +141,22 @@ static void rx_get_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } if (ctx->check_sha) { - struct st_rfc3550_rtp_hdr* hdr = (struct st_rfc3550_rtp_hdr*)usrptr; - uint8_t* payload = (uint8_t*)hdr + sizeof(*hdr); + struct st_rfc3550_rtp_hdr *hdr = (struct st_rfc3550_rtp_hdr *)usrptr; + uint8_t *payload = (uint8_t *)hdr + sizeof(*hdr); unsigned char result[SHA256_DIGEST_LENGTH]; - SHA256((unsigned char*)payload, ctx->frame_size, result); + SHA256((unsigned char *)payload, ctx->frame_size, result); int i; for (i = 0; i < TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = ctx->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st30_rx_error_sha", result); @@ -154,19 +169,22 @@ static void rx_get_packet(void* args) { } } -static int st30_rx_frame_ready(void* priv, void* frame, struct st30_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int st30_rx_frame_ready(void *priv, void *frame, + struct st30_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; /* direct do the sha check since frame_size is small */ if (ctx->check_sha) { unsigned char result[SHA256_DIGEST_LENGTH]; - SHA256((unsigned char*)frame, ctx->frame_size, result); + SHA256((unsigned char *)frame, ctx->frame_size, result); int i; for (i = 0; i < TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = ctx->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st30_rx_error_sha", result); @@ -177,24 +195,30 @@ static int st30_rx_frame_ready(void* priv, void* frame, struct st30_rx_frame_met st30_rx_put_framebuff((st30_rx_handle)ctx->handle, frame); ctx->fb_rec++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static void st30_rx_ops_init(tests_context* st30, struct st30_rx_ops* ops) { +static void st30_rx_ops_init(tests_context *st30, struct st30_rx_ops *ops) { auto ctx = st30->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st30_test"; ops->priv = st30; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; - memcpy(ops->ip_addr[MTL_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf(ops->port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); + if (ctx->same_dual_port) + ops->num_port = 1; + memcpy(ops->ip_addr[MTL_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf(ops->port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", + ctx->para.port[MTL_PORT_P]); ops->udp_port[MTL_PORT_P] = 20000 + st30->idx; if (ops->num_port == 2) { - memcpy(ops->ip_addr[MTL_PORT_R], ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf(ops->port[MTL_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); + memcpy(ops->ip_addr[MTL_PORT_R], ctx->mcast_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf(ops->port[MTL_PORT_R], MTL_PORT_MAX_LEN, "%s", + ctx->para.port[MTL_PORT_R]); ops->udp_port[MTL_PORT_R] = 20000 + st30->idx; } ops->type = ST30_TYPE_FRAME_LEVEL; @@ -211,14 +235,15 @@ static void st30_rx_ops_init(tests_context* st30, struct st30_rx_ops* ops) { ops->rtp_ring_size = 1024; } -static void st30_tx_ops_init(tests_context* st30, struct st30_tx_ops* ops) { +static void st30_tx_ops_init(tests_context *st30, struct st30_tx_ops *ops) { auto ctx = st30->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st30_test"; ops->priv = st30; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; + if (ctx->same_dual_port) + ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -268,21 +293,13 @@ static void st30_rx_assert_cnt(int expect_s30_rx_cnt) { EXPECT_EQ(var.st30_rx_sessions_cnt, expect_s30_rx_cnt); } -TEST(St30_tx, create_free_single) { - create_free_test(st30_tx, 0, 1, 1); -} -TEST(St30_tx, create_free_multi) { - create_free_test(st30_tx, 0, 1, 6); -} -TEST(St30_tx, create_free_mix) { - create_free_test(st30_tx, 2, 3, 4); -} +TEST(St30_tx, create_free_single) { create_free_test(st30_tx, 0, 1, 1); } +TEST(St30_tx, create_free_multi) { create_free_test(st30_tx, 0, 1, 6); } +TEST(St30_tx, create_free_mix) { create_free_test(st30_tx, 2, 3, 4); } TEST(St30_tx, create_free_max) { create_free_max(st30_tx, TEST_CREATE_FREE_MAX); } -TEST(St30_tx, create_expect_fail) { - expect_fail_test(st30_tx); -} +TEST(St30_tx, create_expect_fail) { expect_fail_test(st30_tx); } TEST(St30_tx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st30_tx, ST30_TYPE_RTP_LEVEL, ring_size); @@ -302,21 +319,13 @@ TEST(St30_tx, get_framebuffer_expect_fail) { expect_fail_test_get_framebuffer(st30_tx, fbcnt); } -TEST(St30_rx, create_free_single) { - create_free_test(st30_rx, 0, 1, 1); -} -TEST(St30_rx, create_free_multi) { - create_free_test(st30_rx, 0, 1, 6); -} -TEST(St30_rx, create_free_mix) { - create_free_test(st30_rx, 2, 3, 4); -} +TEST(St30_rx, create_free_single) { create_free_test(st30_rx, 0, 1, 1); } +TEST(St30_rx, create_free_multi) { create_free_test(st30_rx, 0, 1, 6); } +TEST(St30_rx, create_free_mix) { create_free_test(st30_rx, 2, 3, 4); } TEST(St30_rx, create_free_max) { create_free_max(st30_rx, TEST_CREATE_FREE_MAX); } -TEST(St30_rx, create_expect_fail) { - expect_fail_test(st30_rx); -} +TEST(St30_rx, create_expect_fail) { expect_fail_test(st30_rx); } TEST(St30_rx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st30_rx, ST30_TYPE_RTP_LEVEL, ring_size); @@ -328,19 +337,20 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], enum st30_ptime ptime[], uint16_t channel[], enum st30_fmt fmt[], enum st_test_level level, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st30_tx_ops ops; - std::vector test_ctx; + std::vector test_ctx; std::vector handle; std::vector expect_framerate; std::vector framerate; std::vector rtp_thread; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; test_ctx.resize(sessions); handle.resize(sessions); @@ -365,7 +375,8 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops.payload_type = ST30_TEST_PAYLOAD_TYPE; ops.ptime = ptime[i]; ops.framebuff_size = st30_get_sample_size(ops.fmt) * - st30_get_sample_num(ops.ptime, ops.sampling) * ops.channel; + st30_get_sample_num(ops.ptime, ops.sampling) * + ops.channel; test_ctx[i]->pkt_data_len = st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); @@ -385,7 +396,8 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], sleep(5); for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx[i]->fb_send / time_sec; test_ctx[i]->stop = true; if (type[i] == ST30_TYPE_RTP_LEVEL) { @@ -401,8 +413,8 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx[i]->fb_send, 0); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx[i]->fb_send, - framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, + test_ctx[i]->fb_send, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st30_tx_free(handle[i]); EXPECT_GE(ret, 0); @@ -414,23 +426,25 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], enum st30_ptime ptime[], uint16_t channel[], enum st30_fmt fmt[], enum st_test_level level, int sessions = 1, bool check_sha = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st30_tx_ops ops_tx; struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector framerate; @@ -463,11 +477,11 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -479,8 +493,8 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops_tx.ssrc = i ? i + 0x66666666 : 0; ops_tx.ptime = ptime[i]; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = - st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = st30_get_packet_size( + ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); EXPECT_GE(ops_tx.framebuff_size, 0); ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_audio_next_frame; @@ -492,19 +506,19 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], test_ctx_tx[i]->check_sha = check_sha; if (check_sha) { - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { if (type[i] == ST30_TYPE_FRAME_LEVEL) { - fb = (uint8_t*)st30_tx_get_framebuffer(tx_handle[i], frame); + fb = (uint8_t *)st30_tx_get_framebuffer(tx_handle[i], frame); } else { test_ctx_tx[i]->frame_buf[frame] = - (uint8_t*)st_test_zmalloc(ops_tx.framebuff_size); + (uint8_t *)st_test_zmalloc(ops_tx.framebuff_size); fb = test_ctx_tx[i]->frame_buf[frame]; } ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, ops_tx.framebuff_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, ops_tx.framebuff_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, ops_tx.framebuff_size, result); test_sha_dump("st30_rx", result); } } @@ -545,8 +559,8 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ssrc = i ? i + 0x66666666 : 0; ops_rx.ptime = ptime[i]; - ops_rx.framebuff_size = - st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = st30_get_packet_size( + ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -585,7 +599,8 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST30_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -611,8 +626,8 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], if (check_sha) { EXPECT_GT(test_ctx_rx[i]->check_sha_frame_cnt, 0); } - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st30_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); @@ -635,7 +650,8 @@ TEST(St30_tx, frame_48k_mono_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {1}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, rtp_96k_mono_s1) { enum st30_type type[1] = {ST30_TYPE_RTP_LEVEL}; @@ -643,7 +659,8 @@ TEST(St30_tx, rtp_96k_mono_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {1}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_48k_stereo_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -651,7 +668,8 @@ TEST(St30_tx, frame_48k_stereo_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_48k_stereo_125us_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -659,7 +677,8 @@ TEST(St30_tx, frame_48k_stereo_125us_s1) { enum st30_ptime pt[1] = {ST30_PTIME_125US}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, rtp_48k_stereo_125us_s1) { enum st30_type type[1] = {ST30_TYPE_RTP_LEVEL}; @@ -667,7 +686,8 @@ TEST(St30_tx, rtp_48k_stereo_125us_s1) { enum st30_ptime pt[1] = {ST30_PTIME_125US}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, rtp_96k_stereo_s1) { enum st30_type type[1] = {ST30_TYPE_RTP_LEVEL}; @@ -675,7 +695,8 @@ TEST(St30_tx, rtp_96k_stereo_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_48k_sgrp_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -683,7 +704,8 @@ TEST(St30_tx, frame_48k_sgrp_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_96k_sgrp_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -691,12 +713,14 @@ TEST(St30_tx, frame_96k_sgrp_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) + st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, mix_96k_stereo_s3) { enum st30_type type[3] = {ST30_TYPE_RTP_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_RTP_LEVEL}; - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, ST30_SAMPLING_96K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, + ST30_SAMPLING_96K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_1MS}; uint16_t c[3] = {2, 2, 2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -706,7 +730,8 @@ TEST(St30_tx, mix_96k_stereo_s3) { TEST(St30_tx, mix_48k_96_mix) { enum st30_type type[3] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_RTP_LEVEL, ST30_TYPE_RTP_LEVEL}; - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_1MS}; uint16_t c[3] = {2, 1, 4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -715,7 +740,8 @@ TEST(St30_tx, mix_48k_96_mix) { TEST(St30_rx, mix_48k_96_mix) { enum st30_type type[3] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_RTP_LEVEL, ST30_TYPE_RTP_LEVEL}; - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_1MS}; uint16_t c[3] = {2, 1, 4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -765,78 +791,84 @@ TEST(St30_rx, frame_digest_stereo_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K, ST30_SAMPLING_48K}; + enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_4MS, ST31_PTIME_80US}; uint16_t c[5] = {2, 2, 2, 2, 2}; - enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, - ST31_FMT_AM824}; + enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, + ST30_FMT_PCM16, ST31_FMT_AM824}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_ALL, 5, true); } TEST(St30_rx, frame_digest_max_channel_48k_16bit_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K, ST30_SAMPLING_48K}; + enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_1MS, ST30_PTIME_4MS}; uint16_t c[5] = {120, 60, 45, 15, 3}; - enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, - ST30_FMT_PCM16}; + enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, + ST30_FMT_PCM16, ST30_FMT_PCM16}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_ALL, 5, true); } TEST(St30_rx, frame_digest_max_channel_48k_24bit_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K, ST30_SAMPLING_48K}; + enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_1MS, ST30_PTIME_4MS}; uint16_t c[5] = {80, 40, 30, 10, 2}; - enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, - ST30_FMT_PCM24}; + enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, + ST30_FMT_PCM24, ST30_FMT_PCM24}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_MANDATORY, 5, true); } TEST(St30_rx, frame_digest_max_channel_96k_24bit_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, ST30_SAMPLING_96K, - ST30_SAMPLING_96K, ST30_SAMPLING_96K}; + enum st30_sampling s[5] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, + ST30_SAMPLING_96K, ST30_SAMPLING_96K, + ST30_SAMPLING_96K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_1MS, ST30_PTIME_4MS}; uint16_t c[5] = {40, 20, 15, 5, 1}; - enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, - ST30_FMT_PCM24}; + enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, + ST30_FMT_PCM24, ST30_FMT_PCM24}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_MANDATORY, 5, true); } static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, enum st_test_level level) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st30_tx_ops ops_tx; struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level lower than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; ASSERT_TRUE(tx_sessions >= 1); bool tx_update_dst = (tx_sessions == 1); int rx_sessions = 1; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; double expect_framerate = 1000.0; @@ -865,17 +897,17 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -886,8 +918,8 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, ops_tx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_tx.ptime = ST30_PTIME_1MS; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = - st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = st30_get_packet_size( + ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_audio_next_frame; ops_tx.notify_rtp_done = tx_rtp_done; @@ -931,8 +963,8 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, ops_rx.fmt = ST30_FMT_PCM24; ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ptime = ST30_PTIME_1MS; - ops_rx.framebuff_size = - st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = st30_get_packet_size( + ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -980,7 +1012,8 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1006,7 +1039,8 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1041,7 +1075,8 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1101,19 +1136,25 @@ TEST(St30_tx, update_dest_rtp) { st30_rx_update_src_test(ST30_TYPE_RTP_LEVEL, 1, ST_TEST_LEVEL_ALL); } -static int st30_rx_meta_frame_ready(void* priv, void* frame, - struct st30_rx_frame_meta* meta) { - auto ctx = (tests_context*)priv; - auto expect_meta = (struct st30_rx_frame_meta*)ctx->priv; +static int st30_rx_meta_frame_ready(void *priv, void *frame, + struct st30_rx_frame_meta *meta) { + auto ctx = (tests_context *)priv; + auto expect_meta = (struct st30_rx_frame_meta *)ctx->priv; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; ctx->fb_rec++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); - if (expect_meta->sampling != meta->sampling) ctx->rx_meta_fail_cnt++; - if (expect_meta->channel != meta->channel) ctx->rx_meta_fail_cnt++; - if (expect_meta->fmt != meta->fmt) ctx->rx_meta_fail_cnt++; - if (expect_meta->timestamp == meta->timestamp) ctx->rx_meta_fail_cnt++; + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); + if (expect_meta->sampling != meta->sampling) + ctx->rx_meta_fail_cnt++; + if (expect_meta->channel != meta->channel) + ctx->rx_meta_fail_cnt++; + if (expect_meta->fmt != meta->fmt) + ctx->rx_meta_fail_cnt++; + if (expect_meta->timestamp == meta->timestamp) + ctx->rx_meta_fail_cnt++; expect_meta->timestamp = meta->timestamp; st30_rx_put_framebuff((st30_rx_handle)ctx->handle, frame); @@ -1121,30 +1162,34 @@ static int st30_rx_meta_frame_ready(void* priv, void* frame, return 0; } -static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[], - uint16_t channel[], enum st_test_level level, - int sessions = 1, bool user_timestamp = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st30_rx_meta_test(enum st30_fmt fmt[], + enum st30_sampling sampling[], uint16_t channel[], + enum st_test_level level, int sessions = 1, + bool user_timestamp = false) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st30_tx_ops ops_tx; struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level lower than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; double expect_framerate = 1000.0; std::vector framerate; - if (user_timestamp) expect_framerate /= 2; + if (user_timestamp) + expect_framerate /= 2; test_ctx_tx.resize(sessions); test_ctx_rx.resize(sessions); @@ -1165,11 +1210,11 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[] ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -1180,8 +1225,8 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[] ops_tx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_tx.ptime = ST30_PTIME_1MS; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = - st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = st30_get_packet_size( + ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); ; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; if (user_timestamp) { @@ -1229,8 +1274,8 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[] ops_rx.fmt = fmt[i]; ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ptime = ST30_PTIME_1MS; - ops_rx.framebuff_size = - st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = st30_get_packet_size( + ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_meta_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -1242,8 +1287,8 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[] test_ctx_rx[i]->stop = false; /* set expect meta data to private */ - auto meta = - (struct st30_rx_frame_meta*)st_test_zmalloc(sizeof(struct st30_rx_frame_meta)); + auto meta = (struct st30_rx_frame_meta *)st_test_zmalloc( + sizeof(struct st30_rx_frame_meta)); ASSERT_TRUE(meta != NULL); meta->channel = ops_rx.channel; meta->sampling = ops_rx.sampling; @@ -1259,7 +1304,8 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[] for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; /* stop all thread */ @@ -1276,9 +1322,9 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[] EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d fail %d framerate %f, fb send %d\n", __func__, i, - test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->rx_meta_fail_cnt, framerate[i], - test_ctx_tx[i]->fb_send); + info("%s, session %d fb_rec %d fail %d framerate %f, fb send %d\n", + __func__, i, test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->rx_meta_fail_cnt, + framerate[i], test_ctx_tx[i]->fb_send); EXPECT_LE(test_ctx_rx[i]->rx_meta_fail_cnt, 2); EXPECT_NEAR(framerate[i], expect_framerate, expect_framerate * 0.1); ret = st30_tx_free(tx_handle[i]); @@ -1306,25 +1352,28 @@ TEST(St30_rx, frame_user_timestamp) { } static void st30_create_after_start_test(enum st30_type type[], - enum st30_sampling sample[], uint16_t channel[], - enum st30_fmt fmt[], int sessions, int repeat, - enum st_test_level level) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + enum st30_sampling sample[], + uint16_t channel[], + enum st30_fmt fmt[], int sessions, + int repeat, enum st_test_level level) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st30_tx_ops ops_tx; struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level lower than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; double expect_framerate = 1000.0; @@ -1357,11 +1406,11 @@ static void st30_create_after_start_test(enum st30_type type[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -1372,8 +1421,8 @@ static void st30_create_after_start_test(enum st30_type type[], ops_tx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_tx.ptime = ST30_PTIME_1MS; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = - st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = st30_get_packet_size( + ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_audio_next_frame; ops_tx.notify_rtp_done = tx_rtp_done; @@ -1403,11 +1452,11 @@ static void st30_create_after_start_test(enum st30_type type[], ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -1417,8 +1466,8 @@ static void st30_create_after_start_test(enum st30_type type[], ops_rx.fmt = fmt[i]; ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ptime = ST30_PTIME_1MS; - ops_rx.framebuff_size = - st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = st30_get_packet_size( + ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -1439,7 +1488,8 @@ static void st30_create_after_start_test(enum st30_type type[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST30_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -1459,8 +1509,8 @@ static void st30_create_after_start_test(enum st30_type type[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate, expect_framerate * 0.1); ret = st30_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); diff --git a/tests/src/st30p_test.cpp b/tests/src/st30p_test.cpp index 159633b75..9c976e0ff 100644 --- a/tests/src/st30p_test.cpp +++ b/tests/src/st30p_test.cpp @@ -10,38 +10,40 @@ #define ST30P_TEST_PAYLOAD_TYPE (111) #define ST30P_TEST_UDP_PORT (50000) -static int test_st30p_tx_frame_available(void* priv) { - tests_context* s = (tests_context*)priv; +static int test_st30p_tx_frame_available(void *priv) { + tests_context *s = (tests_context *)priv; s->cv.notify_all(); return 0; } -static int test_st30p_tx_frame_done(void* priv, struct st30_frame* frame) { - tests_context* s = (tests_context*)priv; +static int test_st30p_tx_frame_done(void *priv, struct st30_frame *frame) { + tests_context *s = (tests_context *)priv; - if (!s->handle) return -EIO; /* not ready */ + if (!s->handle) + return -EIO; /* not ready */ s->fb_send_done++; return 0; } -static int test_st30p_rx_frame_available(void* priv) { - tests_context* s = (tests_context*)priv; +static int test_st30p_rx_frame_available(void *priv) { + tests_context *s = (tests_context *)priv; s->cv.notify_all(); return 0; } -static void st30p_tx_ops_init(tests_context* st30, struct st30p_tx_ops* ops_tx) { +static void st30p_tx_ops_init(tests_context *st30, + struct st30p_tx_ops *ops_tx) { auto ctx = st30->ctx; memset(ops_tx, 0, sizeof(*ops_tx)); ops_tx->name = "st30p_test"; ops_tx->priv = st30; ops_tx->port.num_port = 1; - memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx->port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + st30->idx; @@ -51,9 +53,9 @@ static void st30p_tx_ops_init(tests_context* st30, struct st30p_tx_ops* ops_tx) ops_tx->sampling = ST30_SAMPLING_48K; ops_tx->ptime = ST30_PTIME_1MS; /* count frame size for 10ms */ - ops_tx->framebuff_size = - st30_calculate_framebuff_size(ops_tx->fmt, ops_tx->ptime, ops_tx->sampling, - ops_tx->channel, 10 * NS_PER_MS, NULL); + ops_tx->framebuff_size = st30_calculate_framebuff_size( + ops_tx->fmt, ops_tx->ptime, ops_tx->sampling, ops_tx->channel, + 10 * NS_PER_MS, NULL); ops_tx->framebuff_cnt = st30->fb_cnt; ops_tx->notify_frame_available = test_st30p_tx_frame_available; @@ -61,15 +63,16 @@ static void st30p_tx_ops_init(tests_context* st30, struct st30p_tx_ops* ops_tx) st30->frame_size = ops_tx->framebuff_size; } -static void st30p_rx_ops_init(tests_context* st30, struct st30p_rx_ops* ops_rx) { +static void st30p_rx_ops_init(tests_context *st30, + struct st30p_rx_ops *ops_rx) { auto ctx = st30->ctx; memset(ops_rx, 0, sizeof(*ops_rx)); ops_rx->name = "st30p_test"; ops_rx->priv = st30; ops_rx->port.num_port = 1; - memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx->port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + st30->idx; @@ -79,9 +82,9 @@ static void st30p_rx_ops_init(tests_context* st30, struct st30p_rx_ops* ops_rx) ops_rx->sampling = ST30_SAMPLING_48K; ops_rx->ptime = ST30_PTIME_1MS; /* count frame size */ - ops_rx->framebuff_size = - st30_calculate_framebuff_size(ops_rx->fmt, ops_rx->ptime, ops_rx->sampling, - ops_rx->channel, 10 * NS_PER_MS, NULL); + ops_rx->framebuff_size = st30_calculate_framebuff_size( + ops_rx->fmt, ops_rx->ptime, ops_rx->sampling, ops_rx->channel, + 10 * NS_PER_MS, NULL); ops_rx->framebuff_cnt = st30->fb_cnt; ops_rx->notify_frame_available = test_st30p_rx_frame_available; @@ -134,17 +137,13 @@ TEST(St30p, tx_create_free_max) { TEST(St30p, rx_create_free_max) { pipeline_create_free_max(st30p_rx, TEST_CREATE_FREE_MAX); } -TEST(St30p, tx_create_expect_fail) { - pipeline_expect_fail_test(st30p_tx); -} -TEST(St30p, rx_create_expect_fail) { - pipeline_expect_fail_test(st30p_rx); -} +TEST(St30p, tx_create_expect_fail) { pipeline_expect_fail_test(st30p_tx); } +TEST(St30p, rx_create_expect_fail) { pipeline_expect_fail_test(st30p_rx); } -static void test_st30p_tx_frame_thread(void* args) { - tests_context* s = (tests_context*)args; +static void test_st30p_tx_frame_thread(void *args) { + tests_context *s = (tests_context *)args; auto handle = s->handle; - struct st30_frame* frame; + struct st30_frame *frame; std::unique_lock lck(s->mtx, std::defer_lock); dbg("%s(%d), start\n", __func__, s->idx); @@ -153,17 +152,24 @@ static void test_st30p_tx_frame_thread(void* args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) s->cv.wait(lck); + if (!s->stop) + s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->fmt != s->audio_fmt) s->incomplete_frame_cnt++; - if (frame->channel != s->audio_channel) s->incomplete_frame_cnt++; - if (frame->ptime != s->audio_ptime) s->incomplete_frame_cnt++; - if (frame->sampling != s->audio_sampling) s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->fmt != s->audio_fmt) + s->incomplete_frame_cnt++; + if (frame->channel != s->audio_channel) + s->incomplete_frame_cnt++; + if (frame->ptime != s->audio_ptime) + s->incomplete_frame_cnt++; + if (frame->sampling != s->audio_sampling) + s->incomplete_frame_cnt++; if (s->user_timestamp) { frame->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; frame->timestamp = s->fb_send; @@ -181,10 +187,10 @@ static void test_st30p_tx_frame_thread(void* args) { dbg("%s(%d), stop\n", __func__, s->idx); } -static void test_st30p_rx_frame_thread(void* args) { - tests_context* s = (tests_context*)args; +static void test_st30p_rx_frame_thread(void *args) { + tests_context *s = (tests_context *)args; auto handle = s->handle; - struct st30_frame* frame; + struct st30_frame *frame; std::unique_lock lck(s->mtx, std::defer_lock); uint64_t timestamp = 0; @@ -194,21 +200,29 @@ static void test_st30p_rx_frame_thread(void* args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) s->cv.wait(lck); + if (!s->stop) + s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; - if (frame->fmt != s->audio_fmt) s->incomplete_frame_cnt++; - if (frame->channel != s->audio_channel) s->incomplete_frame_cnt++; - if (frame->ptime != s->audio_ptime) s->incomplete_frame_cnt++; - if (frame->sampling != s->audio_sampling) s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) + s->incomplete_frame_cnt++; + if (frame->fmt != s->audio_fmt) + s->incomplete_frame_cnt++; + if (frame->channel != s->audio_channel) + s->incomplete_frame_cnt++; + if (frame->ptime != s->audio_ptime) + s->incomplete_frame_cnt++; + if (frame->sampling != s->audio_sampling) + s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) + s->incomplete_frame_cnt++; timestamp = frame->timestamp; /* check user timestamp if it has */ @@ -220,19 +234,20 @@ static void test_st30p_rx_frame_thread(void* args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, - s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", + __func__, s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; } unsigned char result[SHA256_DIGEST_LENGTH]; - SHA256((unsigned char*)frame->addr, s->frame_size, result); + SHA256((unsigned char *)frame->addr, s->frame_size, result); int i = 0; for (i = 0; i < TEST_MAX_SHA_HIST_NUM; i++) { - unsigned char* target_sha = s->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = s->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_MAX_SHA_HIST_NUM) { test_sha_dump("st30p_rx_error_sha", result); @@ -241,7 +256,8 @@ static void test_st30p_rx_frame_thread(void* args) { /* directly put */ st30p_rx_put_frame((st30p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) + s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } @@ -257,7 +273,8 @@ struct st30p_rx_digest_test_para { bool zero_payload_type; }; -static void test_st30p_init_rx_digest_para(struct st30p_rx_digest_test_para* para) { +static void +test_st30p_init_rx_digest_para(struct st30p_rx_digest_test_para *para) { memset(para, 0, sizeof(*para)); para->sessions = 1; @@ -271,9 +288,10 @@ static void test_st30p_init_rx_digest_para(struct st30p_rx_digest_test_para* par } static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], - enum st30_sampling sampling[], enum st30_ptime ptime[], - struct st30p_rx_digest_test_para* para) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + enum st30_sampling sampling[], + enum st30_ptime ptime[], + struct st30p_rx_digest_test_para *para) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto st = ctx->handle; int ret; struct st30p_tx_ops ops_tx; @@ -281,15 +299,17 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], int sessions = para->sessions; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled, one for tx and one for rx\n", __func__); + info("%s, dual port should be enabled, one for tx and one for rx\n", + __func__); return; } /* return if level lower than global */ - if (para->level < ctx->level) return; + if (para->level < ctx->level) + return; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate_tx; @@ -329,30 +349,33 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], ops_tx.priv = test_ctx_tx[i]; ops_tx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + i * 2; - ops_tx.port.payload_type = para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; + ops_tx.port.payload_type = + para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; ops_tx.port.ssrc = para->ssrc; ops_tx.fmt = fmt[i]; ops_tx.channel = channel[i]; ops_tx.sampling = sampling[i]; ops_tx.ptime = ptime[i]; double fps; - ops_tx.framebuff_size = st30_calculate_framebuff_size( - ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel, 10 * NS_PER_MS, &fps); + ops_tx.framebuff_size = + st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, + ops_tx.channel, 10 * NS_PER_MS, &fps); expect_framerate_tx[i] = fps; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; if (para->block_get) ops_tx.flags |= ST30P_TX_FLAG_BLOCK_GET; else ops_tx.notify_frame_available = test_st30p_tx_frame_available; - if (para->dedicated_tx_queue) ops_tx.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; + if (para->dedicated_tx_queue) + ops_tx.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; ops_tx.notify_frame_done = test_st30p_tx_frame_done; test_ctx_tx[i]->frame_size = ops_tx.framebuff_size; @@ -367,14 +390,14 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], /* sha calculate */ size_t frame_size = test_ctx_tx[i]->frame_size; - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < test_ctx_tx[i]->fb_cnt; frame++) { - fb = (uint8_t*)st30p_tx_get_fb_addr(tx_handle[i], frame); + fb = (uint8_t *)st30p_tx_get_fb_addr(tx_handle[i], frame); ASSERT_TRUE(fb != NULL); st_test_rand_data(fb, frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st30p_tx", result); } @@ -408,15 +431,16 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], ops_rx.priv = test_ctx_rx[i]; ops_rx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + i * 2; - ops_rx.port.payload_type = para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; + ops_rx.port.payload_type = + para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; ops_rx.port.ssrc = para->ssrc; ops_rx.fmt = fmt[i]; ops_rx.channel = channel[i]; @@ -448,22 +472,26 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; framerate_tx[i] = test_ctx_tx[i]->fb_send / time_sec; test_ctx_tx[i]->stop = true; - if (para->block_get) st30p_tx_wake_block(tx_handle[i]); + if (para->block_get) + st30p_tx_wake_block(tx_handle[i]); test_ctx_tx[i]->cv.notify_all(); tx_thread[i].join(); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate_rx[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; - if (para->block_get) st30p_rx_wake_block(rx_handle[i]); + if (para->block_get) + st30p_rx_wake_block(rx_handle[i]); test_ctx_rx[i]->cv.notify_all(); rx_thread[i].join(); } @@ -492,14 +520,16 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], } EXPECT_LE(test_ctx_rx[i]->user_meta_fail_cnt, 2); if (para->check_fps) { - EXPECT_NEAR(framerate_rx[i], expect_framerate_rx[i], expect_framerate_rx[i] * 0.1); + EXPECT_NEAR(framerate_rx[i], expect_framerate_rx[i], + expect_framerate_rx[i] * 0.1); } delete test_ctx_rx[i]; } } TEST(St30p, digest_s3) { - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_125US}; uint16_t c[3] = {8, 2, 4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -516,7 +546,8 @@ TEST(St30p, digest_s3) { } TEST(St30p, digest_s3_block) { - enum st30_sampling s[3] = {ST31_SAMPLING_44K, ST30_SAMPLING_96K, ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST31_SAMPLING_44K, ST30_SAMPLING_96K, + ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST31_PTIME_1_09MS, ST30_PTIME_1MS, ST30_PTIME_125US}; uint16_t c[3] = {3, 5, 7}; enum st30_fmt f[3] = {ST31_FMT_AM824, ST30_FMT_PCM16, ST30_FMT_PCM24}; diff --git a/tests/src/st40_test.cpp b/tests/src/st40_test.cpp index 9e94f651d..490d782f8 100644 --- a/tests/src/st40_test.cpp +++ b/tests/src/st40_test.cpp @@ -9,30 +9,34 @@ #define ST40_TEST_PAYLOAD_TYPE (113) -static int tx_anc_next_frame(void* priv, uint16_t* next_frame_idx, - struct st40_tx_frame_meta* meta) { +static int tx_anc_next_frame(void *priv, uint16_t *next_frame_idx, + struct st40_tx_frame_meta *meta) { return tx_next_frame(priv, next_frame_idx); } -static int tx_anc_next_frame_timestamp(void* priv, uint16_t* next_frame_idx, - struct st40_tx_frame_meta* meta) { - auto ctx = (tests_context*)priv; +static int tx_anc_next_frame_timestamp(void *priv, uint16_t *next_frame_idx, + struct st40_tx_frame_meta *meta) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ meta->tfmt = ST10_TIMESTAMP_FMT_TAI; meta->timestamp = mtl_ptp_read_time(ctx->ctx->handle) + 40 * 1000 * 1000; *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_anc_build_rtp_packet(tests_context* s, struct st40_rfc8331_rtp_hdr* rtp, - uint16_t* pkt_len) { +static int tx_anc_build_rtp_packet(tests_context *s, + struct st40_rfc8331_rtp_hdr *rtp, + uint16_t *pkt_len) { /* rtp hdr */ memset(rtp, 0x0, sizeof(*rtp)); rtp->base.marker = 1; @@ -51,8 +55,8 @@ static int tx_anc_build_rtp_packet(tests_context* s, struct st40_rfc8331_rtp_hdr s->rtp_tmstamp++; s->seq_id++; if (s->check_sha) { - struct st40_rfc8331_payload_hdr* payload_hdr = - (struct st40_rfc8331_payload_hdr*)(&rtp[1]); + struct st40_rfc8331_payload_hdr *payload_hdr = + (struct st40_rfc8331_payload_hdr *)(&rtp[1]); int total_size, payload_len, udw_size = s->frame_size; payload_hdr->first_hdr_chunk.c = 0; payload_hdr->first_hdr_chunk.line_number = 10; @@ -62,24 +66,30 @@ static int tx_anc_build_rtp_packet(tests_context* s, struct st40_rfc8331_rtp_hdr payload_hdr->second_hdr_chunk.did = st40_add_parity_bits(0x43); payload_hdr->second_hdr_chunk.sdid = st40_add_parity_bits(0x02); payload_hdr->second_hdr_chunk.data_count = st40_add_parity_bits(udw_size); - payload_hdr->swaped_first_hdr_chunk = htonl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = + htonl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = + htonl(payload_hdr->swaped_second_hdr_chunk); rtp->anc_count = 1; for (int i = 0; i < udw_size; i++) { - st40_set_udw(i + 3, - st40_add_parity_bits(s->frame_buf[s->seq_id % TEST_SHA_HIST_NUM][i]), - (uint8_t*)&payload_hdr->second_hdr_chunk); + st40_set_udw( + i + 3, + st40_add_parity_bits(s->frame_buf[s->seq_id % TEST_SHA_HIST_NUM][i]), + (uint8_t *)&payload_hdr->second_hdr_chunk); } - uint16_t check_sum = - st40_calc_checksum(3 + udw_size, (uint8_t*)&payload_hdr->second_hdr_chunk); - st40_set_udw(udw_size + 3, check_sum, (uint8_t*)&payload_hdr->second_hdr_chunk); - total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = - sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC + uint16_t check_sum = st40_calc_checksum( + 3 + udw_size, (uint8_t *)&payload_hdr->second_hdr_chunk); + st40_set_udw(udw_size + 3, check_sum, + (uint8_t *)&payload_hdr->second_hdr_chunk); + total_size = + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = + (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + + total_size; // Full size of one ANC rtp->length = htons(payload_len); *pkt_len = payload_len + sizeof(struct st40_rfc8331_rtp_hdr); } else { @@ -88,10 +98,10 @@ static int tx_anc_build_rtp_packet(tests_context* s, struct st40_rfc8331_rtp_hdr return 0; } -static void tx_feed_packet(void* args) { - auto ctx = (tests_context*)args; - void* mbuf; - void* usrptr = NULL; +static void tx_feed_packet(void *args) { + auto ctx = (tests_context *)args; + void *mbuf; + void *usrptr = NULL; uint16_t mbuf_len = 0; std::unique_lock lck(ctx->mtx, std::defer_lock); while (!ctx->stop) { @@ -104,39 +114,45 @@ static void tx_feed_packet(void* args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - tx_anc_build_rtp_packet(ctx, (struct st40_rfc8331_rtp_hdr*)usrptr, &mbuf_len); + tx_anc_build_rtp_packet(ctx, (struct st40_rfc8331_rtp_hdr *)usrptr, + &mbuf_len); st40_tx_put_mbuf((st40_tx_handle)ctx->handle, mbuf, mbuf_len); } } -static int tx_rtp_done(void* args) { - auto ctx = (tests_context*)args; +static int tx_rtp_done(void *args) { + auto ctx = (tests_context *)args; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); ctx->fb_send++; return 0; } -static void rx_handle_rtp(tests_context* s, struct st40_rfc8331_rtp_hdr* hdr) { - struct st40_rfc8331_payload_hdr* payload_hdr = - (struct st40_rfc8331_payload_hdr*)(&hdr[1]); +static void rx_handle_rtp(tests_context *s, struct st40_rfc8331_rtp_hdr *hdr) { + struct st40_rfc8331_payload_hdr *payload_hdr = + (struct st40_rfc8331_payload_hdr *)(&hdr[1]); int anc_count = hdr->anc_count; int idx, total_size, payload_len; for (idx = 0; idx < anc_count; idx++) { - payload_hdr->swaped_first_hdr_chunk = ntohl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = ntohl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = + ntohl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = + ntohl(payload_hdr->swaped_second_hdr_chunk); if (!st40_check_parity_bits(payload_hdr->second_hdr_chunk.did) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.sdid) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.data_count)) { @@ -148,19 +164,22 @@ static void rx_handle_rtp(tests_context* s, struct st40_rfc8331_rtp_hdr* hdr) { // verify checksum uint16_t checksum = 0; - checksum = st40_get_udw(udw_size + 3, (uint8_t*)&payload_hdr->second_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); + checksum = + st40_get_udw(udw_size + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = + htonl(payload_hdr->swaped_second_hdr_chunk); if (checksum != - st40_calc_checksum(3 + udw_size, (uint8_t*)&payload_hdr->second_hdr_chunk)) { + st40_calc_checksum(3 + udw_size, + (uint8_t *)&payload_hdr->second_hdr_chunk)) { s->sha_fail_cnt++; return; } // get payload uint16_t data; - uint8_t* udw = (uint8_t*)st_test_zmalloc(udw_size); + uint8_t *udw = (uint8_t *)st_test_zmalloc(udw_size); ASSERT_TRUE(udw != NULL); for (int i = 0; i < udw_size; i++) { - data = st40_get_udw(i + 3, (uint8_t*)&payload_hdr->second_hdr_chunk); + data = st40_get_udw(i + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); if (!st40_check_parity_bits(data)) { err("anc RTP checkParityBits for udw error\n"); s->rx_meta_fail_cnt++; @@ -173,48 +192,55 @@ static void rx_handle_rtp(tests_context* s, struct st40_rfc8331_rtp_hdr* hdr) { s->cv.notify_all(); } - total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = - sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC - payload_hdr = (struct st40_rfc8331_payload_hdr*)((uint8_t*)payload_hdr + payload_len); + total_size = + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = + (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + + total_size; // Full size of one ANC + payload_hdr = (struct st40_rfc8331_payload_hdr *)((uint8_t *)payload_hdr + + payload_len); } } -static int rx_rtp_ready(void* priv) { - auto ctx = (tests_context*)priv; - void* useptr; - void* mbuf; +static int rx_rtp_ready(void *priv) { + auto ctx = (tests_context *)priv; + void *useptr; + void *mbuf; uint16_t len; - if (!ctx->handle) return -EIO; + if (!ctx->handle) + return -EIO; while (1) { mbuf = st40_rx_get_mbuf((st40_rx_handle)ctx->handle, &useptr, &len); - if (!mbuf) break; /* no mbuf */ + if (!mbuf) + break; /* no mbuf */ if (ctx->check_sha) { - rx_handle_rtp(ctx, (struct st40_rfc8331_rtp_hdr*)useptr); + rx_handle_rtp(ctx, (struct st40_rfc8331_rtp_hdr *)useptr); } st40_rx_put_mbuf((st40_rx_handle)ctx->handle, mbuf); ctx->fb_rec++; } - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -static void st40_rx_ops_init(tests_context* st40, struct st40_rx_ops* ops) { +static void st40_rx_ops_init(tests_context *st40, struct st40_rx_ops *ops) { auto ctx = st40->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st40_test"; ops->priv = st40; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; + if (ctx->same_dual_port) + ops->num_port = 1; memcpy(ops->ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -232,14 +258,15 @@ static void st40_rx_ops_init(tests_context* st40, struct st40_rx_ops* ops) { ops->payload_type = ST40_TEST_PAYLOAD_TYPE; } -static void st40_tx_ops_init(tests_context* st40, struct st40_tx_ops* ops) { +static void st40_tx_ops_init(tests_context *st40, struct st40_tx_ops *ops) { auto ctx = st40->ctx; memset(ops, 0, sizeof(*ops)); ops->name = "st40_test"; ops->priv = st40; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) ops->num_port = 1; + if (ctx->same_dual_port) + ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -284,21 +311,13 @@ static void st40_rx_assert_cnt(int expect_s40_rx_cnt) { EXPECT_EQ(var.st40_rx_sessions_cnt, expect_s40_rx_cnt); } -TEST(St40_tx, create_free_single) { - create_free_test(st40_tx, 0, 1, 1); -} -TEST(St40_tx, create_free_multi) { - create_free_test(st40_tx, 0, 1, 6); -} -TEST(St40_tx, create_free_mix) { - create_free_test(st40_tx, 2, 3, 4); -} +TEST(St40_tx, create_free_single) { create_free_test(st40_tx, 0, 1, 1); } +TEST(St40_tx, create_free_multi) { create_free_test(st40_tx, 0, 1, 6); } +TEST(St40_tx, create_free_mix) { create_free_test(st40_tx, 2, 3, 4); } TEST(St40_tx, create_free_max) { create_free_max(st40_tx, TEST_CREATE_FREE_MAX); } -TEST(St40_tx, create_expect_fail) { - expect_fail_test(st40_tx); -} +TEST(St40_tx, create_expect_fail) { expect_fail_test(st40_tx); } TEST(St40_tx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st40_tx, ST40_TYPE_RTP_LEVEL, ring_size); @@ -318,21 +337,13 @@ TEST(St40_tx, get_framebuffer_expect_fail) { expect_fail_test_get_framebuffer(st40_tx, fbcnt); } -TEST(St40_rx, create_free_single) { - create_free_test(st40_rx, 0, 1, 1); -} -TEST(St40_rx, create_free_multi) { - create_free_test(st40_rx, 0, 1, 6); -} -TEST(St40_rx, create_free_mix) { - create_free_test(st40_rx, 2, 3, 4); -} +TEST(St40_rx, create_free_single) { create_free_test(st40_rx, 0, 1, 1); } +TEST(St40_rx, create_free_multi) { create_free_test(st40_rx, 0, 1, 6); } +TEST(St40_rx, create_free_mix) { create_free_test(st40_rx, 2, 3, 4); } TEST(St40_rx, create_free_max) { create_free_max(st40_rx, TEST_CREATE_FREE_MAX); } -TEST(St40_rx, create_expect_fail) { - expect_fail_test(st40_rx); -} +TEST(St40_rx, create_expect_fail) { expect_fail_test(st40_rx); } TEST(St40_rx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring_2(st40_rx, ring_size); @@ -340,20 +351,22 @@ TEST(St40_rx, create_expect_fail_ring_sz) { expect_fail_test_rtp_ring_2(st40_rx, ring_size); } -static void st40_tx_frame_init(tests_context* st40, st40_tx_handle handle, +static void st40_tx_frame_init(tests_context *st40, st40_tx_handle handle, enum st40_type type) { size_t frame_size = 240; - if (st40->st40_empty_frame) frame_size = 0; + if (st40->st40_empty_frame) + frame_size = 0; st40->pkt_data_len = frame_size; st40->frame_size = frame_size; for (int frame = 0; frame < st40->fb_cnt; frame++) { - st40->frame_buf[frame] = (uint8_t*)st_test_zmalloc(frame_size); + st40->frame_buf[frame] = (uint8_t *)st_test_zmalloc(frame_size); ASSERT_TRUE(st40->frame_buf[frame] != NULL); if (ST40_TYPE_FRAME_LEVEL == type) { - struct st40_frame* dst = (struct st40_frame*)st40_tx_get_framebuffer(handle, frame); + struct st40_frame *dst = + (struct st40_frame *)st40_tx_get_framebuffer(handle, frame); ASSERT_TRUE(dst != NULL); dst->data_size = dst->meta[0].udw_size = frame_size; @@ -374,7 +387,7 @@ static void st40_tx_frame_init(tests_context* st40, st40_tx_handle handle, } } -static void st40_tx_frame_uinit(tests_context* st40) { +static void st40_tx_frame_uinit(tests_context *st40) { for (int frame = 0; frame < st40->fb_cnt; frame++) { if (st40->frame_buf[frame]) { st_test_free(st40->frame_buf[frame]); @@ -385,19 +398,20 @@ static void st40_tx_frame_uinit(tests_context* st40) { static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], enum st_test_level level, int sessions = 1) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st40_tx_ops ops; - std::vector test_ctx; + std::vector test_ctx; std::vector handle; std::vector expect_framerate; std::vector framerate; std::vector rtp_thread; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; test_ctx.resize(sessions); handle.resize(sessions); @@ -437,7 +451,8 @@ static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx[i]->fb_send / time_sec; if (type[i] == ST40_TYPE_RTP_LEVEL) { test_ctx[i]->stop = true; @@ -454,8 +469,8 @@ static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx[i]->fb_send, 0); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx[i]->fb_send, - framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, + test_ctx[i]->fb_send, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st40_tx_free(handle[i]); EXPECT_GE(ret, 0); @@ -466,26 +481,29 @@ static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], enum st_test_level level, int sessions = 1, - bool check_sha = false, bool user_timestamp = false, + bool check_sha = false, + bool user_timestamp = false, bool empty_frame = false, bool interlaced = false, bool dedicate_tx_queue = false) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st40_tx_ops ops_tx; struct st40_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -506,7 +524,8 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], test_ctx_tx[i] = new tests_context(); ASSERT_TRUE(test_ctx_tx[i] != NULL); expect_framerate[i] = st_frame_rate(fps[i]); - if (user_timestamp) expect_framerate[i] /= 2; + if (user_timestamp) + expect_framerate[i] /= 2; test_ctx_tx[i]->idx = i; test_ctx_tx[i]->ctx = ctx; @@ -518,11 +537,11 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -538,7 +557,8 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], } else { ops_tx.get_next_frame = tx_anc_next_frame; } - if (dedicate_tx_queue) ops_tx.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; + if (dedicate_tx_queue) + ops_tx.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; ops_tx.rtp_ring_size = 1024; ops_tx.notify_rtp_done = tx_rtp_done; @@ -548,12 +568,12 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], test_ctx_tx[i]->check_sha = check_sha; st40_tx_frame_init(test_ctx_tx[i], tx_handle[i], type[i]); if (check_sha) { - uint8_t* fb; + uint8_t *fb; for (int frame = 0; frame < test_ctx_tx[i]->fb_cnt; frame++) { fb = test_ctx_tx[i]->frame_buf[frame]; st_test_rand_data(fb, test_ctx_tx[i]->frame_size, frame); - unsigned char* result = test_ctx_tx[i]->shas[frame]; - SHA256((unsigned char*)fb, test_ctx_tx[i]->frame_size, result); + unsigned char *result = test_ctx_tx[i]->shas[frame]; + SHA256((unsigned char *)fb, test_ctx_tx[i]->frame_size, result); test_sha_dump("st40_rx", result); } } @@ -617,7 +637,8 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST40_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -635,7 +656,7 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], } sha_check[i].join(); while (!test_ctx_rx[i]->buf_q.empty()) { - void* frame = test_ctx_rx[i]->buf_q.front(); + void *frame = test_ctx_rx[i]->buf_q.front(); st_test_free(frame); test_ctx_rx[i]->buf_q.pop(); } @@ -646,8 +667,8 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); EXPECT_LE(test_ctx_rx[i]->sha_fail_cnt, 2); EXPECT_LE(test_ctx_rx[i]->rx_meta_fail_cnt, 2); @@ -660,7 +681,7 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], } /* free all payload in buf_q */ while (!test_ctx_rx[i]->buf_q.empty()) { - void* frame = test_ctx_rx[i]->buf_q.front(); + void *frame = test_ctx_rx[i]->buf_q.front(); st_test_free(frame); test_ctx_rx[i]->buf_q.pop(); } @@ -727,8 +748,8 @@ TEST(St40_rx, frame_fps29_97_fps59_94) { TEST(St40_rx, mix_s2) { enum st40_type type[2] = {ST40_TYPE_RTP_LEVEL, ST40_TYPE_FRAME_LEVEL}; enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; - st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 2, true, false, false, false, - true); + st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 2, true, false, false, + false, true); } TEST(St40_rx, frame_fps50_fps59_94_digest) { enum st40_type type[2] = {ST40_TYPE_FRAME_LEVEL, ST40_TYPE_FRAME_LEVEL}; @@ -749,32 +770,35 @@ TEST(St40_rx, frame_interlaced_empty) { enum st40_type type[1] = {ST40_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; /* no sha check */ - st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 1, false, false, true, true); + st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 1, false, false, true, + true); } static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, enum st_test_level level) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st40_tx_ops ops_tx; struct st40_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } /* return if level lower than global */ - if (level < ctx->level) return; + if (level < ctx->level) + return; ASSERT_TRUE(tx_sessions >= 1); bool tx_update_dst = (tx_sessions == 1); int rx_sessions = 1; - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -805,17 +829,17 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -902,7 +926,8 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -928,7 +953,8 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -963,7 +989,8 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1008,22 +1035,23 @@ TEST(St40_tx, update_dest_rtp) { st40_rx_update_src_test(ST40_TYPE_RTP_LEVEL, 1, ST_TEST_LEVEL_ALL); } -static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], int sessions, - int repeat) { - auto ctx = (struct st_tests_context*)st_test_ctx(); +static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], + int sessions, int repeat) { + auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st40_tx_ops ops_tx; struct st40_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for rx\n", + info("%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", __func__); return; } - std::vector test_ctx_tx; - std::vector test_ctx_rx; + std::vector test_ctx_tx; + std::vector test_ctx_rx; std::vector tx_handle; std::vector rx_handle; std::vector expect_framerate; @@ -1056,11 +1084,11 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], int ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -1098,11 +1126,11 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], int ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], + ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -1119,7 +1147,8 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], int for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = + (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST40_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -1134,8 +1163,8 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], int /* check fps */ for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, - framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st40_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); diff --git a/tests/src/st_test.cpp b/tests/src/st_test.cpp index e0f6fa611..ce657120b 100644 --- a/tests/src/st_test.cpp +++ b/tests/src/st_test.cpp @@ -5,18 +5,19 @@ #include "log.h" #include "tests.h" -int st_test_sch_cnt(struct st_tests_context* ctx) { +int st_test_sch_cnt(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; struct mtl_var_info var; int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) return ret; + if (ret < 0) + return ret; return var.sch_cnt; } -bool st_test_dma_available(struct st_tests_context* ctx) { +bool st_test_dma_available(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; struct mtl_var_info var; struct mtl_fix_info fix; @@ -28,10 +29,12 @@ bool st_test_dma_available(struct st_tests_context* ctx) { } ret = mtl_get_var_info(handle, &var); - if (ret < 0) return ret; + if (ret < 0) + return ret; ret = mtl_get_fix_info(handle, &fix); - if (ret < 0) return ret; + if (ret < 0) + return ret; if (var.dma_dev_cnt < fix.dma_dev_cnt_max) return true; @@ -40,7 +43,7 @@ bool st_test_dma_available(struct st_tests_context* ctx) { } static void init_expect_fail_test(void) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle; struct mtl_init_params para; @@ -52,15 +55,18 @@ static void init_expect_fail_test(void) { handle = mtl_init(¶); EXPECT_TRUE(handle == NULL); - memcpy(mtl_p_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(mtl_p_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); handle = mtl_init(¶); EXPECT_TRUE(handle == NULL); - snprintf(para.port[MTL_PORT_P], sizeof(para.port[MTL_PORT_P]), "0000:55:00.0"); + snprintf(para.port[MTL_PORT_P], sizeof(para.port[MTL_PORT_P]), + "0000:55:00.0"); handle = mtl_init(¶); EXPECT_TRUE(handle == NULL); - memcpy(mtl_r_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(mtl_r_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); /* test with 0 num_ports */ para.num_ports = 0; @@ -78,24 +84,20 @@ static void init_expect_fail_test(void) { EXPECT_TRUE(handle == NULL); } -TEST(Main, init_expect_fail) { - init_expect_fail_test(); -} +TEST(Main, init_expect_fail) { init_expect_fail_test(); } static void reinit_expect_fail_test(void) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle; handle = mtl_init(&ctx->para); EXPECT_TRUE(handle == NULL); } -TEST(Main, re_init_fail) { - reinit_expect_fail_test(); -} +TEST(Main, re_init_fail) { reinit_expect_fail_test(); } static void start_stop_test(int repeat) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; int ret; @@ -107,16 +109,12 @@ static void start_stop_test(int repeat) { } } -TEST(Main, start_stop_single) { - start_stop_test(1); -} +TEST(Main, start_stop_single) { start_stop_test(1); } -TEST(Main, start_stop_multi) { - start_stop_test(5); -} +TEST(Main, start_stop_multi) { start_stop_test(5); } static void start_expect_fail_test(void) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; int ret; @@ -128,12 +126,10 @@ static void start_expect_fail_test(void) { EXPECT_GE(ret, 0); } -TEST(Main, start_expect_fail) { - start_expect_fail_test(); -} +TEST(Main, start_expect_fail) { start_expect_fail_test(); } static void stop_expect_fail_test(void) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; int ret; @@ -149,12 +145,10 @@ static void stop_expect_fail_test(void) { EXPECT_GE(ret, 0); } -TEST(Main, stop_expect_fail) { - stop_expect_fail_test(); -} +TEST(Main, stop_expect_fail) { stop_expect_fail_test(); } TEST(Main, get_fix) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; struct mtl_fix_info fix; int ret; @@ -166,7 +160,7 @@ TEST(Main, get_fix) { } TEST(Main, get_var) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; struct mtl_var_info var; int ret; @@ -175,18 +169,19 @@ TEST(Main, get_var) { EXPECT_GE(ret, 0); } -static int test_lcore_cnt(struct st_tests_context* ctx) { +static int test_lcore_cnt(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; struct mtl_var_info var; int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) return ret; + if (ret < 0) + return ret; return var.lcore_cnt; } -static void test_lcore_one(struct st_tests_context* ctx) { +static void test_lcore_one(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; int base_cnt = test_lcore_cnt(ctx); int ret; @@ -201,13 +196,13 @@ static void test_lcore_one(struct st_tests_context* ctx) { } TEST(Main, lcore) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); test_lcore_one(ctx); } TEST(Main, lcore_max) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; int base_cnt = test_lcore_cnt(ctx), max = 100; int ret, i; @@ -215,18 +210,20 @@ TEST(Main, lcore_max) { for (i = 0; i < max; i++) { ret = mtl_get_lcore(handle, &lcore[i]); - if (ret < 0) break; + if (ret < 0) + break; } EXPECT_EQ(test_lcore_cnt(ctx), base_cnt + i); max = i; - for (i = 0; i < max; i++) mtl_put_lcore(handle, lcore[i]); + for (i = 0; i < max; i++) + mtl_put_lcore(handle, lcore[i]); EXPECT_EQ(test_lcore_cnt(ctx), base_cnt); test_lcore_one(ctx); } TEST(Main, lcore_expect_fail) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; int ret = mtl_put_lcore(handle, 10000); @@ -234,19 +231,20 @@ TEST(Main, lcore_expect_fail) { test_lcore_one(ctx); } -static bool test_dev_started(struct st_tests_context* ctx) { +static bool test_dev_started(struct st_tests_context *ctx) { mtl_handle handle = ctx->handle; struct mtl_var_info var; int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) return false; + if (ret < 0) + return false; return var.dev_started; } TEST(Main, dev_started) { - struct st_tests_context* ctx = st_test_ctx(); + struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; int ret = mtl_start(handle); @@ -259,14 +257,14 @@ TEST(Main, dev_started) { TEST(Main, bandwidth) { uint64_t bandwidth_1080p_mps = st20_1080p59_yuv422_10bit_bandwidth_mps(); uint64_t bandwidth_1080p = 0; - int ret = st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, - false, &bandwidth_1080p); + int ret = st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, + ST_FPS_P59_94, false, &bandwidth_1080p); EXPECT_GE(ret, 0); EXPECT_EQ(bandwidth_1080p / 1000 / 1000, bandwidth_1080p_mps); uint64_t bandwidth_720p = 0; - ret = st20_get_bandwidth_bps(1280, 720, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, false, - &bandwidth_720p); + ret = st20_get_bandwidth_bps(1280, 720, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, + false, &bandwidth_720p); EXPECT_GE(ret, 0); EXPECT_GT(bandwidth_1080p, bandwidth_720p); } @@ -281,9 +279,7 @@ static void st20_frame_size_test() { EXPECT_EQ(size, expect_size); } -TEST(Main, st20_frame_size) { - st20_frame_size_test(); -} +TEST(Main, st20_frame_size) { st20_frame_size_test(); } static void fmt_frame_equal_transport_test() { bool equal; @@ -291,25 +287,27 @@ static void fmt_frame_equal_transport_test() { equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422RFC4175PG2BE10, ST20_FMT_YUV_422_10BIT); EXPECT_TRUE(equal); - equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_8BIT); + equal = + st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_8BIT); EXPECT_TRUE(equal); equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_RGB8, ST20_FMT_RGB_8BIT); EXPECT_TRUE(equal); - equal = - st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR10LE, ST20_FMT_YUV_422_10BIT); + equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR10LE, + ST20_FMT_YUV_422_10BIT); EXPECT_FALSE(equal); - equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_V210, ST20_FMT_YUV_422_10BIT); + equal = + st_frame_fmt_equal_transport(ST_FRAME_FMT_V210, ST20_FMT_YUV_422_10BIT); EXPECT_FALSE(equal); - equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR8, ST20_FMT_YUV_422_8BIT); + equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR8, + ST20_FMT_YUV_422_8BIT); EXPECT_FALSE(equal); - equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_12BIT); + equal = + st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_12BIT); EXPECT_FALSE(equal); } -TEST(Main, fmt_equal_transport) { - fmt_frame_equal_transport_test(); -} +TEST(Main, fmt_equal_transport) { fmt_frame_equal_transport_test(); } static void fmt_frame_fom_transport_test() { enum st_frame_fmt to_fmt; @@ -321,13 +319,12 @@ static void fmt_frame_fom_transport_test() { to_fmt = st_frame_fmt_from_transport(ST20_FMT_RGB_8BIT); EXPECT_TRUE(to_fmt == ST_FRAME_FMT_RGB8); - to_fmt = st_frame_fmt_from_transport(ST20_FMT_YUV_444_16BIT); /* not support now */ + to_fmt = + st_frame_fmt_from_transport(ST20_FMT_YUV_444_16BIT); /* not support now */ EXPECT_TRUE(to_fmt == ST_FRAME_FMT_MAX); } -TEST(Main, fmt_frame_transport) { - fmt_frame_fom_transport_test(); -} +TEST(Main, fmt_frame_transport) { fmt_frame_fom_transport_test(); } static void fmt_frame_to_transport_test() { enum st20_fmt to_fmt; @@ -345,9 +342,7 @@ static void fmt_frame_to_transport_test() { EXPECT_TRUE(to_fmt == ST20_FMT_MAX); } -TEST(Main, fmt_to_transport) { - fmt_frame_to_transport_test(); -} +TEST(Main, fmt_to_transport) { fmt_frame_to_transport_test(); } static void frame_api_test() { uint32_t w = 1920; @@ -373,7 +368,8 @@ static void frame_api_test() { EXPECT_GT(st_frame_least_linesize(fmt, w, 0), szero); } /* codestream */ - for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; i++) { + for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; + i++) { fmt = (enum st_frame_fmt)i; size = st_frame_size(fmt, w, h, false); EXPECT_EQ(size, szero); @@ -394,8 +390,8 @@ static void frame_api_test() { static void frame_name_test() { int result; - const char* fail = "unknown"; - const char* name; + const char *fail = "unknown"; + const char *name; enum st_frame_fmt fmt; /* yuv */ @@ -413,7 +409,8 @@ static void frame_name_test() { EXPECT_EQ(st_frame_name_to_fmt(name), fmt); } /* codestream */ - for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; i++) { + for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; + i++) { fmt = (enum st_frame_fmt)i; name = st_frame_fmt_name(fmt); EXPECT_NE(strcmp(fail, name), 0); @@ -433,12 +430,8 @@ static void frame_name_test() { EXPECT_EQ(st_frame_name_to_fmt(fail), ST_FRAME_FMT_MAX); } -TEST(Main, frame_api) { - frame_api_test(); -} -TEST(Main, frame_name) { - frame_name_test(); -} +TEST(Main, frame_api) { frame_api_test(); } +TEST(Main, frame_name) { frame_name_test(); } static void size_page_align_test() { size_t pg_sz = 4096; @@ -470,11 +463,10 @@ static void size_page_align_test() { EXPECT_EQ(sz, expect_sz); } -TEST(Main, size_page_align) { - size_page_align_test(); -} +TEST(Main, size_page_align) { size_page_align_test(); } -class fps_23_98 : public ::testing::TestWithParam> {}; +class fps_23_98 + : public ::testing::TestWithParam> {}; TEST_P(fps_23_98, conv_fps_to_st_fps_23_98_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -489,7 +481,8 @@ PARAMETERIZED_TEST(Main, fps_23_98, std::make_tuple(ST_FPS_P23_98, 23.99), std::make_tuple(ST_FPS_P24, 24.00))); -class fps_24 : public ::testing::TestWithParam> {}; +class fps_24 + : public ::testing::TestWithParam> {}; TEST_P(fps_24, conv_fps_to_st_fps_24_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -502,7 +495,8 @@ PARAMETERIZED_TEST(Main, fps_24, std::make_tuple(ST_FPS_P24, 24.99), std::make_tuple(ST_FPS_P25, 25.00))); -class fps_25 : public ::testing::TestWithParam> {}; +class fps_25 + : public ::testing::TestWithParam> {}; TEST_P(fps_25, conv_fps_to_st_fps_25_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -514,7 +508,8 @@ PARAMETERIZED_TEST(Main, fps_25, std::make_tuple(ST_FPS_P25, 26.00), std::make_tuple(ST_FPS_MAX, 27.00))); -class fps_29_97 : public ::testing::TestWithParam> {}; +class fps_29_97 + : public ::testing::TestWithParam> {}; TEST_P(fps_29_97, conv_fps_to_st_fps_29_97_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -528,7 +523,8 @@ PARAMETERIZED_TEST(Main, fps_29_97, std::make_tuple(ST_FPS_P29_97, 29.99), std::make_tuple(ST_FPS_P30, 30.00))); -class fps_30 : public ::testing::TestWithParam> {}; +class fps_30 + : public ::testing::TestWithParam> {}; TEST_P(fps_30, conv_fps_to_st_fps_30_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -541,7 +537,8 @@ PARAMETERIZED_TEST(Main, fps_30, std::make_tuple(ST_FPS_MAX, 31.01), std::make_tuple(ST_FPS_MAX, 32.00))); -class fps_50 : public ::testing::TestWithParam> {}; +class fps_50 + : public ::testing::TestWithParam> {}; TEST_P(fps_50, conv_fps_to_st_fps_50_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -557,7 +554,8 @@ PARAMETERIZED_TEST(Main, fps_50, std::make_tuple(ST_FPS_P50, 51.00), std::make_tuple(ST_FPS_MAX, 52.00))); -class fps_59_94 : public ::testing::TestWithParam> {}; +class fps_59_94 + : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_59_94, ::testing::Values(std::make_tuple(ST_FPS_MAX, 58.93), @@ -571,7 +569,8 @@ TEST_P(fps_59_94, conv_fps_to_st_fps_50_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_60 : public ::testing::TestWithParam> {}; +class fps_60 + : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_60, ::testing::Values(std::make_tuple(ST_FPS_P60, 60.00), @@ -584,7 +583,8 @@ TEST_P(fps_60, conv_fps_to_st_fps_60_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_100 : public ::testing::TestWithParam> {}; +class fps_100 + : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_100, ::testing::Values(std::make_tuple(ST_FPS_MAX, 98.99), @@ -598,7 +598,8 @@ TEST_P(fps_100, conv_fps_to_st_fps_100_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_119_98 : public ::testing::TestWithParam> {}; +class fps_119_98 + : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_119_98, ::testing::Values(std::make_tuple(ST_FPS_MAX, 118.87), @@ -612,7 +613,8 @@ TEST_P(fps_119_98, conv_fps_to_st_fps_119_98_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_120 : public ::testing::TestWithParam> {}; +class fps_120 + : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_120, ::testing::Values(std::make_tuple(ST_FPS_P120, 120.00), diff --git a/tests/src/test_platform.h b/tests/src/test_platform.h index a4989eb4c..59c9baf67 100644 --- a/tests/src/test_platform.h +++ b/tests/src/test_platform.h @@ -39,42 +39,43 @@ typedef unsigned long int nfds_t; #define MSG_DONTWAIT (0x40) #endif -static inline int st_pthread_mutex_init(pthread_mutex_t* mutex, - pthread_mutexattr_t* attr) { +static inline int st_pthread_mutex_init(pthread_mutex_t *mutex, + pthread_mutexattr_t *attr) { return pthread_mutex_init(mutex, attr); } -static inline int st_pthread_mutex_lock(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_lock(pthread_mutex_t *mutex) { return pthread_mutex_lock(mutex); } -static inline int st_pthread_mutex_unlock(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_unlock(pthread_mutex_t *mutex) { return pthread_mutex_unlock(mutex); } -static inline int st_pthread_mutex_destroy(pthread_mutex_t* mutex) { +static inline int st_pthread_mutex_destroy(pthread_mutex_t *mutex) { return pthread_mutex_destroy(mutex); } -static inline int st_pthread_cond_init(pthread_cond_t* cond, - pthread_condattr_t* cond_attr) { +static inline int st_pthread_cond_init(pthread_cond_t *cond, + pthread_condattr_t *cond_attr) { return pthread_cond_init(cond, cond_attr); } -static inline int st_pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) { +static inline int st_pthread_cond_wait(pthread_cond_t *cond, + pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } -static inline int st_pthread_cond_destroy(pthread_cond_t* cond) { +static inline int st_pthread_cond_destroy(pthread_cond_t *cond) { return pthread_cond_destroy(cond); } -static inline int st_pthread_cond_signal(pthread_cond_t* cond) { +static inline int st_pthread_cond_signal(pthread_cond_t *cond) { return pthread_cond_signal(cond); } -static inline void st_usleep( - useconds_t usec) { // windows usleep function precision is only 1~15ms +static inline void +st_usleep(useconds_t usec) { // windows usleep function precision is only 1~15ms #ifdef WINDOWSENV LARGE_INTEGER delay; HANDLE delay_timer_handle = NULL; diff --git a/tests/src/test_util.cpp b/tests/src/test_util.cpp index c50cf9ca0..24e5ded05 100644 --- a/tests/src/test_util.cpp +++ b/tests/src/test_util.cpp @@ -8,17 +8,18 @@ #include "log.h" -void test_sha_dump(const char* tag, unsigned char* sha) { +void test_sha_dump(const char *tag, unsigned char *sha) { for (size_t i = 0; i < SHA256_DIGEST_LENGTH; i++) { dbg("0x%02x ", sha[i]); } dbg(", %s done\n", tag); } -int st_test_check_patter(uint8_t* p, size_t sz, uint8_t base) { +int st_test_check_patter(uint8_t *p, size_t sz, uint8_t base) { for (size_t i = 0; i < sz; i++) { if (p[i] != ((base + i) & 0xFF)) { - err("%s, fail data 0x%x on %" PRIu64 " base 0x%x\n", __func__, p[i], i, base); + err("%s, fail data 0x%x on %" PRIu64 " base 0x%x\n", __func__, p[i], i, + base); return -EIO; } } @@ -26,10 +27,11 @@ int st_test_check_patter(uint8_t* p, size_t sz, uint8_t base) { return 0; } -int st_test_cmp(uint8_t* s1, uint8_t* s2, size_t sz) { +int st_test_cmp(uint8_t *s1, uint8_t *s2, size_t sz) { for (size_t i = 0; i < sz; i++) { if (s1[i] != s2[i]) { - err("%s, mismatch on %" PRIu64 ", 0x%x 0x%x\n", __func__, i, s1[i], s2[i]); + err("%s, mismatch on %" PRIu64 ", 0x%x 0x%x\n", __func__, i, s1[i], + s2[i]); return -EIO; } } @@ -37,7 +39,7 @@ int st_test_cmp(uint8_t* s1, uint8_t* s2, size_t sz) { return 0; } -int st_test_cmp_u16(uint16_t* s1, uint16_t* s2, size_t sz) { +int st_test_cmp_u16(uint16_t *s1, uint16_t *s2, size_t sz) { for (size_t i = 0; i < sz; i++) { if (s1[i] != s2[i]) { err("%s, mismatch on %" PRIu64 "\n", __func__, i); diff --git a/tests/src/test_util.h b/tests/src/test_util.h index 17e1c5a21..845332fb1 100644 --- a/tests/src/test_util.h +++ b/tests/src/test_util.h @@ -36,17 +36,16 @@ enum st_test_level { ST_TEST_LEVEL_MAX, /* max value of this enum */ }; -static inline void* st_test_zmalloc(size_t sz) { - void* p = malloc(sz); - if (p) memset(p, 0x0, sz); +static inline void *st_test_zmalloc(size_t sz) { + void *p = malloc(sz); + if (p) + memset(p, 0x0, sz); return p; } -static inline void st_test_free(void* p) { - free(p); -} +static inline void st_test_free(void *p) { free(p); } -static inline void st_test_rand_data(uint8_t* p, size_t sz, uint8_t base) { +static inline void st_test_rand_data(uint8_t *p, size_t sz, uint8_t base) { for (size_t i = 0; i < sz; i++) { #if TEST_DATA_FIXED_PATTER p[i] = base + i; @@ -56,22 +55,23 @@ static inline void st_test_rand_data(uint8_t* p, size_t sz, uint8_t base) { } } -static inline void st_test_rand_v210(uint8_t* p, size_t sz, uint8_t base) { +static inline void st_test_rand_v210(uint8_t *p, size_t sz, uint8_t base) { for (size_t i = 0; i < sz; i++) { #if TEST_DATA_FIXED_PATTER p[i] = base + i; #else p[i] = rand(); #endif - if ((i % 4) == 3) p[i] &= 0x3F; + if ((i % 4) == 3) + p[i] &= 0x3F; } } -int st_test_check_patter(uint8_t* p, size_t sz, uint8_t base); +int st_test_check_patter(uint8_t *p, size_t sz, uint8_t base); -int st_test_cmp(uint8_t* s1, uint8_t* s2, size_t sz); +int st_test_cmp(uint8_t *s1, uint8_t *s2, size_t sz); -int st_test_cmp_u16(uint16_t* s1, uint16_t* s2, size_t sz); +int st_test_cmp_u16(uint16_t *s1, uint16_t *s2, size_t sz); /* Monotonic time (in nanoseconds) since some unspecified starting point. */ static inline uint64_t st_test_get_monotonic_time() { @@ -81,4 +81,4 @@ static inline uint64_t st_test_get_monotonic_time() { return ((uint64_t)ts.tv_sec * NS_PER_S) + ts.tv_nsec; } -void test_sha_dump(const char* tag, unsigned char* sha); +void test_sha_dump(const char *tag, unsigned char *sha); diff --git a/tests/src/tests.cpp b/tests/src/tests.cpp index 9c27da6d9..419e0ad60 100644 --- a/tests/src/tests.cpp +++ b/tests/src/tests.cpp @@ -88,214 +88,218 @@ static struct option test_args_options[] = { {0, 0, 0, 0}}; -static struct st_tests_context* g_test_ctx; +static struct st_tests_context *g_test_ctx; -struct st_tests_context* st_test_ctx(void) { +struct st_tests_context *st_test_ctx(void) { return g_test_ctx; } -static int test_args_dma_dev(struct mtl_init_params* p, const char* in_dev) { - if (!in_dev) return -EIO; +static int test_args_dma_dev(struct mtl_init_params *p, const char *in_dev) { + if (!in_dev) + return -EIO; char devs[128] = {0}; snprintf(devs, 128 - 1, "%s", in_dev); dbg("%s, dev list %s\n", __func__, devs); - char* next_dev = strtok(devs, ","); + char *next_dev = strtok(devs, ","); while (next_dev && (p->num_dma_dev_port < MTL_DMA_DEV_MAX)) { dbg("next_dev: %s\n", next_dev); - snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", next_dev); + snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", + next_dev); p->num_dma_dev_port++; next_dev = strtok(NULL, ","); } return 0; } -static int test_parse_args(struct st_tests_context* ctx, struct mtl_init_params* p, - int argc, char** argv) { +static int test_parse_args(struct st_tests_context *ctx, + struct mtl_init_params *p, int argc, char **argv) { int cmd = -1, opt_idx = 0; int nb; while (1) { cmd = getopt_long_only(argc, argv, "hv", test_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case TEST_ARG_P_PORT: - snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); - p->num_ports++; - break; - case TEST_ARG_R_PORT: - snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); - p->num_ports++; - break; - case TEST_ARG_LCORES: - p->lcores = optarg; - break; - case TEST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ - nb = atoi(optarg); - if (nb > 0 && nb < 100) { - p->data_quota_mbs_per_sch = nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); - } - break; - case TEST_ARG_DMA_DEV: - test_args_dma_dev(p, optarg); - break; - case TEST_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case TEST_ARG_CNI_THREAD: - p->flags |= MTL_FLAG_CNI_THREAD; - break; - case TEST_ARG_RX_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - break; - case TEST_ARG_TX_MONO_POOL: - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case TEST_ARG_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case TEST_ARG_RX_SEPARATE_VIDEO_LCORE: - p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; - break; - case TEST_ARG_MIGRATE_ENABLE: - p->flags |= MTL_FLAG_RX_VIDEO_MIGRATE; - p->flags |= MTL_FLAG_TX_VIDEO_MIGRATE; - break; - case TEST_ARG_MIGRATE_DISABLE: - p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; - p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; - break; - case TEST_ARG_LIB_PTP: - p->flags |= MTL_FLAG_PTP_ENABLE; - p->ptp_get_time_fn = NULL; /* clear the user ptp func */ - break; - case TEST_ARG_NB_TX_DESC: - p->nb_tx_desc = atoi(optarg); - break; - case TEST_ARG_NB_RX_DESC: - p->nb_rx_desc = atoi(optarg); - break; - case TEST_ARG_LEVEL: - if (!strcmp(optarg, "all")) - ctx->level = ST_TEST_LEVEL_ALL; - else if (!strcmp(optarg, "mandatory")) - ctx->level = ST_TEST_LEVEL_MANDATORY; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case TEST_ARG_AUTO_START_STOP: - p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; - break; - case TEST_ARG_AF_XDP_ZC_DISABLE: - p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; - break; - case TEST_ARG_QUEUE_CNT: { - uint16_t cnt = atoi(optarg); - p->tx_queues_cnt[MTL_PORT_P] = cnt; - p->tx_queues_cnt[MTL_PORT_R] = cnt; - p->rx_queues_cnt[MTL_PORT_P] = cnt; - p->rx_queues_cnt[MTL_PORT_R] = cnt; - break; + case TEST_ARG_P_PORT: + snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); + p->num_ports++; + break; + case TEST_ARG_R_PORT: + snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); + p->num_ports++; + break; + case TEST_ARG_LCORES: + p->lcores = optarg; + break; + case TEST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ + nb = atoi(optarg); + if (nb > 0 && nb < 100) { + p->data_quota_mbs_per_sch = + nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); } - case TEST_ARG_HDR_SPLIT: - ctx->hdr_split = true; - break; - case TEST_ARG_TASKLET_THREAD: - p->flags |= MTL_FLAG_TASKLET_THREAD; - break; - case TEST_ARG_TSC_PACING: + break; + case TEST_ARG_DMA_DEV: + test_args_dma_dev(p, optarg); + break; + case TEST_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case TEST_ARG_CNI_THREAD: + p->flags |= MTL_FLAG_CNI_THREAD; + break; + case TEST_ARG_RX_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + break; + case TEST_ARG_TX_MONO_POOL: + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case TEST_ARG_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case TEST_ARG_RX_SEPARATE_VIDEO_LCORE: + p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; + break; + case TEST_ARG_MIGRATE_ENABLE: + p->flags |= MTL_FLAG_RX_VIDEO_MIGRATE; + p->flags |= MTL_FLAG_TX_VIDEO_MIGRATE; + break; + case TEST_ARG_MIGRATE_DISABLE: + p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; + p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; + break; + case TEST_ARG_LIB_PTP: + p->flags |= MTL_FLAG_PTP_ENABLE; + p->ptp_get_time_fn = NULL; /* clear the user ptp func */ + break; + case TEST_ARG_NB_TX_DESC: + p->nb_tx_desc = atoi(optarg); + break; + case TEST_ARG_NB_RX_DESC: + p->nb_rx_desc = atoi(optarg); + break; + case TEST_ARG_LEVEL: + if (!strcmp(optarg, "all")) + ctx->level = ST_TEST_LEVEL_ALL; + else if (!strcmp(optarg, "mandatory")) + ctx->level = ST_TEST_LEVEL_MANDATORY; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case TEST_ARG_AUTO_START_STOP: + p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; + break; + case TEST_ARG_AF_XDP_ZC_DISABLE: + p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; + break; + case TEST_ARG_QUEUE_CNT: { + uint16_t cnt = atoi(optarg); + p->tx_queues_cnt[MTL_PORT_P] = cnt; + p->tx_queues_cnt[MTL_PORT_R] = cnt; + p->rx_queues_cnt[MTL_PORT_P] = cnt; + p->rx_queues_cnt[MTL_PORT_R] = cnt; + break; + } + case TEST_ARG_HDR_SPLIT: + ctx->hdr_split = true; + break; + case TEST_ARG_TASKLET_THREAD: + p->flags |= MTL_FLAG_TASKLET_THREAD; + break; + case TEST_ARG_TSC_PACING: + p->pacing = ST21_TX_PACING_WAY_TSC; + break; + case TEST_ARG_RXTX_SIMD_512: + p->flags |= MTL_FLAG_RXTX_SIMD_512; + break; + case TEST_ARG_PACING_WAY: + if (!strcmp(optarg, "auto")) + p->pacing = ST21_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + p->pacing = ST21_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsn")) + p->pacing = ST21_TX_PACING_WAY_TSN; + else if (!strcmp(optarg, "tsc")) p->pacing = ST21_TX_PACING_WAY_TSC; - break; - case TEST_ARG_RXTX_SIMD_512: - p->flags |= MTL_FLAG_RXTX_SIMD_512; - break; - case TEST_ARG_PACING_WAY: - if (!strcmp(optarg, "auto")) - p->pacing = ST21_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - p->pacing = ST21_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsn")) - p->pacing = ST21_TX_PACING_WAY_TSN; - else if (!strcmp(optarg, "tsc")) - p->pacing = ST21_TX_PACING_WAY_TSC; - else if (!strcmp(optarg, "ptp")) - p->pacing = ST21_TX_PACING_WAY_PTP; - else if (!strcmp(optarg, "be")) - p->pacing = ST21_TX_PACING_WAY_BE; - else - err("%s, unknow pacing way %s\n", __func__, optarg); - break; - case TEST_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case TEST_ARG_TX_NO_CHAIN: - p->flags |= MTL_FLAG_TX_NO_CHAIN; - break; - case TEST_ARG_IOVA_MODE: - if (!strcmp(optarg, "va")) - p->iova_mode = MTL_IOVA_MODE_VA; - else if (!strcmp(optarg, "pa")) - p->iova_mode = MTL_IOVA_MODE_PA; - else - err("%s, unknow iova mode %s\n", __func__, optarg); - break; - case TEST_ARG_MULTI_SRC_PORT: - p->flags |= MTL_FLAG_MULTI_SRC_PORT; - break; - case TEST_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; ++port) - p->net_proto[port] = MTL_PROTO_DHCP; - ctx->dhcp = true; - break; - case TEST_ARG_MCAST_ONLY: - ctx->mcast_only = true; - break; - case TEST_ARG_ALLOW_ACROSS_NUMA_CORE: - p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; - break; - case TEST_ARG_AUDIO_TX_PACING: - if (!strcmp(optarg, "auto")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsc")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; - else - err("%s, unknow audio tx pacing %s\n", __func__, optarg); - break; - default: - break; + else if (!strcmp(optarg, "ptp")) + p->pacing = ST21_TX_PACING_WAY_PTP; + else if (!strcmp(optarg, "be")) + p->pacing = ST21_TX_PACING_WAY_BE; + else + err("%s, unknow pacing way %s\n", __func__, optarg); + break; + case TEST_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case TEST_ARG_TX_NO_CHAIN: + p->flags |= MTL_FLAG_TX_NO_CHAIN; + break; + case TEST_ARG_IOVA_MODE: + if (!strcmp(optarg, "va")) + p->iova_mode = MTL_IOVA_MODE_VA; + else if (!strcmp(optarg, "pa")) + p->iova_mode = MTL_IOVA_MODE_PA; + else + err("%s, unknow iova mode %s\n", __func__, optarg); + break; + case TEST_ARG_MULTI_SRC_PORT: + p->flags |= MTL_FLAG_MULTI_SRC_PORT; + break; + case TEST_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; ++port) + p->net_proto[port] = MTL_PROTO_DHCP; + ctx->dhcp = true; + break; + case TEST_ARG_MCAST_ONLY: + ctx->mcast_only = true; + break; + case TEST_ARG_ALLOW_ACROSS_NUMA_CORE: + p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; + break; + case TEST_ARG_AUDIO_TX_PACING: + if (!strcmp(optarg, "auto")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsc")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; + else + err("%s, unknow audio tx pacing %s\n", __func__, optarg); + break; + default: + break; } }; return 0; } -static void test_random_ip(struct st_tests_context* ctx) { - struct mtl_init_params* p = &ctx->para; - uint8_t* p_ip = mtl_p_sip_addr(p); - uint8_t* r_ip = mtl_r_sip_addr(p); +static void test_random_ip(struct st_tests_context *ctx) { + struct mtl_init_params *p = &ctx->para; + uint8_t *p_ip = mtl_p_sip_addr(p); + uint8_t *r_ip = mtl_r_sip_addr(p); srand(st_test_get_monotonic_time()); @@ -329,8 +333,8 @@ static void test_random_ip(struct st_tests_context* ctx) { } } -static uint64_t test_ptp_from_real_time(void* priv) { - auto ctx = (struct st_tests_context*)priv; +static uint64_t test_ptp_from_real_time(void *priv) { + auto ctx = (struct st_tests_context *)priv; struct timespec spec; #ifndef WINDOWSENV clock_gettime(CLOCK_REALTIME, &spec); @@ -350,10 +354,10 @@ static uint64_t test_ptp_from_real_time(void* priv) { return ctx->ptp_time; } -static void test_ctx_init(struct st_tests_context* ctx) { - struct mtl_init_params* p = &ctx->para; +static void test_ctx_init(struct st_tests_context *ctx) { + struct mtl_init_params *p = &ctx->para; int cpus_per_soc = 4; - char* lcores_list = ctx->lcores_list; + char *lcores_list = ctx->lcores_list; int pos = 0; #ifndef WINDOWSENV int numa_nodes = 0; @@ -383,16 +387,20 @@ static void test_ctx_init(struct st_tests_context* ctx) { pos += snprintf(lcores_list + pos, TEST_LCORE_LIST_MAX_LEN - pos, "0-%d", cpus_per_soc - 1); #ifndef WINDOWSENV - /* build lcore list for other numa, e.g 0-2,28,29,30 for a two socket system */ + /* build lcore list for other numa, e.g 0-2,28,29,30 for a two socket system + */ for (int numa = 1; numa < numa_nodes; numa++) { int cpus_add = 0; for (int cpu = 0; cpu < max_cpus; cpu++) { if (numa_node_of_cpu(cpu) == numa) { - int n = snprintf(lcores_list + pos, TEST_LCORE_LIST_MAX_LEN - pos, ",%d", cpu); - if (n < 0 || n >= (TEST_LCORE_LIST_MAX_LEN - pos)) break; + int n = snprintf(lcores_list + pos, TEST_LCORE_LIST_MAX_LEN - pos, + ",%d", cpu); + if (n < 0 || n >= (TEST_LCORE_LIST_MAX_LEN - pos)) + break; pos += n; cpus_add++; - if (cpus_add >= cpus_per_soc) break; + if (cpus_add >= cpus_per_soc) + break; } } } @@ -401,7 +409,7 @@ static void test_ctx_init(struct st_tests_context* ctx) { p->lcores = ctx->lcores_list; } -static void test_ctx_uinit(struct st_tests_context* ctx) { +static void test_ctx_uinit(struct st_tests_context *ctx) { mtl_uninit(ctx->handle); ctx->handle = NULL; st_test_free(ctx); @@ -417,23 +425,24 @@ TEST(Misc, version) { } TEST(Misc, version_compare) { - auto version_next = - MTL_VERSION_NUM(MTL_VERSION_MAJOR + 1, MTL_VERSION_MINOR, MTL_VERSION_LAST); + auto version_next = MTL_VERSION_NUM(MTL_VERSION_MAJOR + 1, MTL_VERSION_MINOR, + MTL_VERSION_LAST); EXPECT_LT(MTL_VERSION, version_next); - version_next = - MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR + 1, MTL_VERSION_LAST); + version_next = MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR + 1, + MTL_VERSION_LAST); EXPECT_LT(MTL_VERSION, version_next); - version_next = - MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR, MTL_VERSION_LAST + 1); + version_next = MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR, + MTL_VERSION_LAST + 1); EXPECT_LT(MTL_VERSION, version_next); } static void mtl_memcpy_test(size_t size) { ASSERT_TRUE(size > 0); - char* src = new char[size]; - char* dst = new char[size]; + char *src = new char[size]; + char *dst = new char[size]; - for (size_t i = 0; i < size; i++) src[i] = i; + for (size_t i = 0; i < size; i++) + src[i] = i; memset(dst, 0, size); mtl_memcpy(dst, src, size); @@ -449,10 +458,10 @@ TEST(Misc, memcpy) { mtl_memcpy_test(4096 + 100); } -static void hp_malloc_test(struct st_tests_context* ctx, size_t size, enum mtl_port port, - bool zero, bool expect_succ) { +static void hp_malloc_test(struct st_tests_context *ctx, size_t size, + enum mtl_port port, bool zero, bool expect_succ) { auto m_handle = ctx->handle; - void* p; + void *p; if (zero) p = mtl_hp_malloc(m_handle, size, port); @@ -464,7 +473,7 @@ static void hp_malloc_test(struct st_tests_context* ctx, size_t size, enum mtl_p EXPECT_TRUE(p == NULL); if (p) { if (zero) { - void* dst = malloc(size); + void *dst = malloc(size); memset(dst, 0, size); EXPECT_EQ(0, memcmp(p, dst, size)); free(dst); @@ -474,46 +483,51 @@ static void hp_malloc_test(struct st_tests_context* ctx, size_t size, enum mtl_p } } -static void hp_malloc_tests(struct st_tests_context* ctx, enum mtl_port port, bool zero) { +static void hp_malloc_tests(struct st_tests_context *ctx, enum mtl_port port, + bool zero) { hp_malloc_test(ctx, 1, port, zero, true); hp_malloc_test(ctx, 1024, port, zero, true); hp_malloc_test(ctx, 1024 + 3, port, zero, true); } TEST(Misc, hp_malloc) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); int num_port = st_test_num_port(ctx); hp_malloc_tests(ctx, MTL_PORT_P, false); - if (num_port > 1) hp_malloc_tests(ctx, MTL_PORT_R, false); + if (num_port > 1) + hp_malloc_tests(ctx, MTL_PORT_R, false); } TEST(Misc, hp_zmalloc) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); int num_port = st_test_num_port(ctx); hp_malloc_tests(ctx, MTL_PORT_P, true); - if (num_port > 1) hp_malloc_tests(ctx, MTL_PORT_R, true); + if (num_port > 1) + hp_malloc_tests(ctx, MTL_PORT_R, true); } TEST(Misc, hp_malloc_expect_fail) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); int num_port = st_test_num_port(ctx); hp_malloc_test(ctx, 0, MTL_PORT_P, false, false); - if (num_port > 1) hp_malloc_test(ctx, 0, MTL_PORT_R, false, false); + if (num_port > 1) + hp_malloc_test(ctx, 0, MTL_PORT_R, false, false); } TEST(Misc, hp_zmalloc_expect_fail) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); int num_port = st_test_num_port(ctx); hp_malloc_test(ctx, 0, MTL_PORT_P, true, false); - if (num_port > 1) hp_malloc_test(ctx, 0, MTL_PORT_R, true, false); + if (num_port > 1) + hp_malloc_test(ctx, 0, MTL_PORT_R, true, false); } TEST(Misc, ptp) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto handle = ctx->handle; uint64_t real_time; uint64_t diff; @@ -536,7 +550,7 @@ TEST(Misc, ptp) { } TEST(Misc, log_level) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto handle = ctx->handle; int ret; @@ -550,7 +564,7 @@ TEST(Misc, log_level) { } TEST(Misc, get_numa_id) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto handle = ctx->handle; int ret; @@ -567,7 +581,7 @@ TEST(Misc, get_numa_id) { } static void st10_timestamp_test(uint32_t sampling_rate) { - auto ctx = (struct st_tests_context*)st_test_ctx(); + auto ctx = (struct st_tests_context *)st_test_ctx(); auto handle = ctx->handle; uint64_t ptp1 = mtl_ptp_read_time(handle); @@ -591,14 +605,14 @@ TEST(Misc, st10_timestamp) { st10_timestamp_test(96 * 1000); } -GTEST_API_ int main(int argc, char** argv) { - struct st_tests_context* ctx; +GTEST_API_ int main(int argc, char **argv) { + struct st_tests_context *ctx; int ret; bool link_flap_wa = false; testing::InitGoogleTest(&argc, argv); - ctx = (struct st_tests_context*)st_test_zmalloc(sizeof(*ctx)); + ctx = (struct st_tests_context *)st_test_zmalloc(sizeof(*ctx)); if (!ctx) { err("%s, ctx alloc fail\n", __func__); return -ENOMEM; @@ -631,9 +645,9 @@ GTEST_API_ int main(int argc, char** argv) { for (int i = 0; i < ctx->para.num_ports; i++) { mtl_port_ip_info(ctx->handle, (enum mtl_port)i, ctx->para.sip_addr[i], ctx->para.netmask[i], ctx->para.gateway[i]); - uint8_t* ip = ctx->para.sip_addr[i]; - info("%s, if ip %u.%u.%u.%u for port %s\n", __func__, ip[0], ip[1], ip[2], ip[3], - ctx->para.port[i]); + uint8_t *ip = ctx->para.sip_addr[i]; + info("%s, if ip %u.%u.%u.%u for port %s\n", __func__, ip[0], ip[1], ip[2], + ip[3], ctx->para.port[i]); } if (ctx->para.num_ports > 1) { @@ -658,7 +672,8 @@ GTEST_API_ int main(int argc, char** argv) { int time_least = 10; if (link_flap_wa && (time_s < time_least)) { /* wa for linkFlapErrDisabled in the hub */ - info("%s, sleep %ds before disable the port\n", __func__, time_least - time_s); + info("%s, sleep %ds before disable the port\n", __func__, + time_least - time_s); sleep(time_least - time_s); } @@ -669,39 +684,44 @@ GTEST_API_ int main(int argc, char** argv) { return ret; } -int tx_next_frame(void* priv, uint16_t* next_frame_idx) { - auto ctx = (tests_context*)priv; +int tx_next_frame(void *priv, uint16_t *next_frame_idx) { + auto ctx = (tests_context *)priv; - if (!ctx->handle) return -EIO; /* not ready */ + if (!ctx->handle) + return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) + ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) + ctx->start_time = st_test_get_monotonic_time(); return 0; } -void sha_frame_check(void* args) { - auto ctx = (tests_context*)args; +void sha_frame_check(void *args) { + auto ctx = (tests_context *)args; std::unique_lock lck(ctx->mtx, std::defer_lock); unsigned char result[SHA256_DIGEST_LENGTH]; while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) ctx->cv.wait(lck); + if (!ctx->stop) + ctx->cv.wait(lck); lck.unlock(); continue; } else { - void* frame = ctx->buf_q.front(); + void *frame = ctx->buf_q.front(); ctx->buf_q.pop(); dbg("%s, frame %p\n", __func__, frame); int i; - SHA256((unsigned char*)frame, ctx->frame_size, result); + SHA256((unsigned char *)frame, ctx->frame_size, result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { - unsigned char* target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; + unsigned char *target_sha = ctx->shas[i]; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) + break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("rx_error_sha", result); @@ -713,9 +733,10 @@ void sha_frame_check(void* args) { } } -int tests_context_unit(tests_context* ctx) { +int tests_context_unit(tests_context *ctx) { for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - if (ctx->frame_buf[frame]) st_test_free(ctx->frame_buf[frame]); + if (ctx->frame_buf[frame]) + st_test_free(ctx->frame_buf[frame]); ctx->frame_buf[frame] = NULL; } if (ctx->ooo_mapping) { @@ -738,15 +759,16 @@ int tests_context_unit(tests_context* ctx) { return 0; } -int test_ctx_notify_event(void* priv, enum st_event event, void* args) { +int test_ctx_notify_event(void *priv, enum st_event event, void *args) { if (event == ST_EVENT_VSYNC) { - tests_context* s = (tests_context*)priv; + tests_context *s = (tests_context *)priv; s->vsync_cnt++; - if (!s->first_vsync_time) s->first_vsync_time = st_test_get_monotonic_time(); + if (!s->first_vsync_time) + s->first_vsync_time = st_test_get_monotonic_time(); #ifdef DEBUG - struct st10_vsync_meta* meta = (struct st10_vsync_meta*)args; - dbg("%s(%d,%p), epoch %" PRIu64 " vsync_cnt %d\n", __func__, s->idx, s, meta->epoch, - s->vsync_cnt); + struct st10_vsync_meta *meta = (struct st10_vsync_meta *)args; + dbg("%s(%d,%p), epoch %" PRIu64 " vsync_cnt %d\n", __func__, s->idx, s, + meta->epoch, s->vsync_cnt); #endif } return 0; diff --git a/tests/src/tests.h b/tests/src/tests.h index baa105b81..b249acf3b 100644 --- a/tests/src/tests.h +++ b/tests/src/tests.h @@ -69,7 +69,7 @@ struct test_st22_encoder_session { int timeout_ms; int rand_ratio; - struct st_tests_context* ctx; + struct st_tests_context *ctx; }; struct test_st22_decoder_session { @@ -89,7 +89,7 @@ struct test_st22_decoder_session { int timeout_interval; int timeout_ms; - struct st_tests_context* ctx; + struct st_tests_context *ctx; }; struct st_tests_context { @@ -111,9 +111,10 @@ struct st_tests_context { st22_encoder_dev_handle encoder_dev_handle; st22_decoder_dev_handle decoder_dev_handle; st20_converter_dev_handle converter_dev_handle; - struct test_st22_encoder_session* encoder_sessions[MAX_TEST_ENCODER_SESSIONS]; - struct test_st22_decoder_session* decoder_sessions[MAX_TEST_DECODER_SESSIONS]; - struct test_converter_session* converter_sessions[MAX_TEST_CONVERTER_SESSIONS]; + struct test_st22_encoder_session *encoder_sessions[MAX_TEST_ENCODER_SESSIONS]; + struct test_st22_decoder_session *decoder_sessions[MAX_TEST_DECODER_SESSIONS]; + struct test_converter_session + *converter_sessions[MAX_TEST_CONVERTER_SESSIONS]; bool encoder_use_block_get; bool decoder_use_block_get; int plugin_fail_interval; @@ -122,51 +123,55 @@ struct st_tests_context { int plugin_rand_ratio; }; -struct st_tests_context* st_test_ctx(void); +struct st_tests_context *st_test_ctx(void); -static inline int st_test_num_port(struct st_tests_context* ctx) { +static inline int st_test_num_port(struct st_tests_context *ctx) { return ctx->para.num_ports; } -static inline void st_test_jxs_fail_interval(struct st_tests_context* ctx, int interval) { +static inline void st_test_jxs_fail_interval(struct st_tests_context *ctx, + int interval) { ctx->plugin_fail_interval = interval; } -static inline void st_test_jxs_timeout_interval(struct st_tests_context* ctx, +static inline void st_test_jxs_timeout_interval(struct st_tests_context *ctx, int interval) { ctx->plugin_timeout_interval = interval; } -static inline void st_test_jxs_timeout_ms(struct st_tests_context* ctx, int ms) { +static inline void st_test_jxs_timeout_ms(struct st_tests_context *ctx, + int ms) { ctx->plugin_timeout_ms = ms; } -static inline void st_test_jxs_rand_ratio(struct st_tests_context* ctx, int rand_ratio) { +static inline void st_test_jxs_rand_ratio(struct st_tests_context *ctx, + int rand_ratio) { ctx->plugin_rand_ratio = rand_ratio; } -static inline void st_test_jxs_use_block_get(struct st_tests_context* ctx, bool block) { +static inline void st_test_jxs_use_block_get(struct st_tests_context *ctx, + bool block) { ctx->decoder_use_block_get = block; ctx->encoder_use_block_get = block; } -int st_test_sch_cnt(struct st_tests_context* ctx); +int st_test_sch_cnt(struct st_tests_context *ctx); -bool st_test_dma_available(struct st_tests_context* ctx); +bool st_test_dma_available(struct st_tests_context *ctx); -int st_test_st22_plugin_register(struct st_tests_context* ctx); +int st_test_st22_plugin_register(struct st_tests_context *ctx); -int st_test_st22_plugin_unregister(struct st_tests_context* ctx); +int st_test_st22_plugin_unregister(struct st_tests_context *ctx); -int st_test_convert_plugin_register(struct st_tests_context* ctx); +int st_test_convert_plugin_register(struct st_tests_context *ctx); -int st_test_convert_plugin_unregister(struct st_tests_context* ctx); +int st_test_convert_plugin_unregister(struct st_tests_context *ctx); -void sha_frame_check(void* args); +void sha_frame_check(void *args); class tests_context { - public: - struct st_tests_context* ctx = NULL; +public: + struct st_tests_context *ctx = NULL; int idx = 0; int fb_cnt = 0; uint16_t fb_idx = 0; @@ -177,8 +182,8 @@ class tests_context { uint64_t first_vsync_time = 0; int packet_rec = 0; uint64_t start_time = 0; - void* handle = NULL; - void* priv = NULL; /* private data for the test */ + void *handle = NULL; + void *priv = NULL; /* private data for the test */ bool stop = false; std::mutex mtx = {}; std::condition_variable cv = {}; @@ -198,7 +203,7 @@ class tests_context { int stride = 0; bool single_line = false; bool slice = false; - std::queue buf_q = {}; + std::queue buf_q = {}; std::queue second_field_q = {}; int lines_per_slice = 0; @@ -213,7 +218,7 @@ class tests_context { size_t uframe_size = 0; uint8_t shas[TEST_MAX_SHA_HIST_NUM][SHA256_DIGEST_LENGTH] = {}; /* frame buff alloc in the test context */ - uint8_t* frame_buf[TEST_MAX_SHA_HIST_NUM] = {}; + uint8_t *frame_buf[TEST_MAX_SHA_HIST_NUM] = {}; uint16_t lines_ready[TEST_MAX_SHA_HIST_NUM] = {}; bool check_sha = false; int sha_fail_cnt = 0; /* fail as sha check fail */ @@ -227,16 +232,16 @@ class tests_context { int last_user_meta_frame_idx = 0; int user_meta_fail_cnt = 0; bool out_of_order_pkt = false; /* out of order pkt index */ - int* ooo_mapping = NULL; + int *ooo_mapping = NULL; int slice_cnt = 0; uint32_t slice_recv_lines = 0; uint64_t slice_recv_timestamp = 0; - void* ext_fb_malloc; - uint8_t* ext_fb = NULL; + void *ext_fb_malloc; + uint8_t *ext_fb = NULL; mtl_iova_t ext_fb_iova = 0; size_t ext_fb_iova_map_sz = 0; - struct st20_ext_frame* ext_frames; - struct st_ext_frame* p_ext_frames; + struct st20_ext_frame *ext_frames; + struct st_ext_frame *p_ext_frames; int ext_idx = 0; bool ext_fb_in_use[3] = {false}; /* assume 3 framebuffer */ mtl_dma_mem_handle dma_mem = NULL; @@ -261,483 +266,485 @@ struct test_user_meta { int frame_idx; }; -int tests_context_unit(tests_context* ctx); +int tests_context_unit(tests_context *ctx); -int test_ctx_notify_event(void* priv, enum st_event event, void* args); +int test_ctx_notify_event(void *priv, enum st_event event, void *args); -int tx_next_frame(void* priv, uint16_t* next_frame_idx); +int tx_next_frame(void *priv, uint16_t *next_frame_idx); #define TEST_CREATE_FREE_MAX (16) -#define create_free_max(A, max) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - auto act = 0; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - auto sch_cnt = st_test_sch_cnt(ctx); \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle[max]; \ - for (int i = 0; i < max; i++) { \ - handle[i] = A##_create(m_handle, &ops); \ - if (!handle[i]) break; \ - ops.udp_port[MTL_SESSION_PORT_P]++; \ - ops.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - st_usleep(100 * 1000); \ - } \ - info("%s, max session cnt %d\n", __func__, expect_cnt); \ - act = expect_cnt; \ - for (int i = 0; i < act; i++) { \ - ret = A##_free(handle[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - st_usleep(100 * 1000); \ - } \ - \ - A##_assert_cnt(0); \ - EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ - \ - delete test_ctx; \ +#define create_free_max(A, max) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + auto act = 0; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + auto sch_cnt = st_test_sch_cnt(ctx); \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle[max]; \ + for (int i = 0; i < max; i++) { \ + handle[i] = A##_create(m_handle, &ops); \ + if (!handle[i]) \ + break; \ + ops.udp_port[MTL_SESSION_PORT_P]++; \ + ops.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + st_usleep(100 * 1000); \ + } \ + info("%s, max session cnt %d\n", __func__, expect_cnt); \ + act = expect_cnt; \ + for (int i = 0; i < act; i++) { \ + ret = A##_free(handle[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + st_usleep(100 * 1000); \ + } \ + \ + A##_assert_cnt(0); \ + EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ + \ + delete test_ctx; \ } while (0) -#define create_free_test(A, base, step, repeat) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle_base[base]; \ - for (int i = 0; i < base; i++) { \ - handle_base[i] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle_base[i]); \ - ops.udp_port[MTL_SESSION_PORT_P]++; \ - ops.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - for (int i = 0; i < repeat; i++) { \ - A##_handle handle[step]; \ - \ - for (int j = 0; j < step; j++) { \ - handle[j] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle[j] != NULL); \ - ops.udp_port[MTL_SESSION_PORT_P]++; \ - ops.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - st_usleep(100 * 1000); \ - for (int j = 0; j < step; j++) { \ - ret = A##_free(handle[j]); \ - ASSERT_TRUE(ret >= 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - st_usleep(100 * 1000); \ - } \ - \ - for (int i = 0; i < base; i++) { \ - ret = A##_free(handle_base[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - A##_assert_cnt(0); \ - \ - delete test_ctx; \ +#define create_free_test(A, base, step, repeat) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle_base[base]; \ + for (int i = 0; i < base; i++) { \ + handle_base[i] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle_base[i]); \ + ops.udp_port[MTL_SESSION_PORT_P]++; \ + ops.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + for (int i = 0; i < repeat; i++) { \ + A##_handle handle[step]; \ + \ + for (int j = 0; j < step; j++) { \ + handle[j] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle[j] != NULL); \ + ops.udp_port[MTL_SESSION_PORT_P]++; \ + ops.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + st_usleep(100 * 1000); \ + for (int j = 0; j < step; j++) { \ + ret = A##_free(handle[j]); \ + ASSERT_TRUE(ret >= 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + st_usleep(100 * 1000); \ + } \ + \ + for (int i = 0; i < base; i++) { \ + ret = A##_free(handle_base[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + A##_assert_cnt(0); \ + \ + delete test_ctx; \ } while (0) -#define expect_fail_test(A) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - EXPECT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 0 num_port */ \ - ops.num_port = 0; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with crazy big num_port */ \ - ops.num_port = 100; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with negative num_port */ \ - ops.num_port = -1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with 2 num_port */ \ - if (ctx->para.num_ports != 2) { \ - ops.num_port = 2; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - } \ - delete test_ctx; \ +#define expect_fail_test(A) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + EXPECT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 0 num_port */ \ + ops.num_port = 0; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with crazy big num_port */ \ + ops.num_port = 100; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with negative num_port */ \ + ops.num_port = -1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with 2 num_port */ \ + if (ctx->para.num_ports != 2) { \ + ops.num_port = 2; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + } \ + delete test_ctx; \ } while (0) -#define expect_fail_test_fb_cnt(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define expect_fail_test_fb_cnt(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) -#define test_get_framebuffer(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle != NULL); \ - void* fb_buff; \ - for (uint16_t idx = 0; idx < fb_nb; idx++) { \ - fb_buff = A##_get_framebuffer(handle, idx); \ - EXPECT_TRUE(fb_buff != NULL); \ - } \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - delete test_ctx; \ +#define test_get_framebuffer(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle != NULL); \ + void *fb_buff; \ + for (uint16_t idx = 0; idx < fb_nb; idx++) { \ + fb_buff = A##_get_framebuffer(handle, idx); \ + EXPECT_TRUE(fb_buff != NULL); \ + } \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + delete test_ctx; \ } while (0) -#define expect_fail_test_get_framebuffer(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle != NULL); \ - void* fb_buff; \ - fb_buff = A##_get_framebuffer(handle, fb_nb); \ - EXPECT_TRUE(fb_buff == NULL); \ - fb_buff = A##_get_framebuffer(handle, fb_nb * 2); \ - EXPECT_TRUE(fb_buff == NULL); \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - delete test_ctx; \ +#define expect_fail_test_get_framebuffer(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle != NULL); \ + void *fb_buff; \ + fb_buff = A##_get_framebuffer(handle, fb_nb); \ + EXPECT_TRUE(fb_buff == NULL); \ + fb_buff = A##_get_framebuffer(handle, fb_nb * 2); \ + EXPECT_TRUE(fb_buff == NULL); \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + delete test_ctx; \ } while (0) -#define expect_fail_test_rtp_ring(A, s_type, ring_sz) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.type = s_type; \ - ops.rtp_ring_size = ring_sz; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define expect_fail_test_rtp_ring(A, s_type, ring_sz) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.type = s_type; \ + ops.rtp_ring_size = ring_sz; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) -#define expect_fail_test_rtp_ring_2(A, ring_sz) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.rtp_ring_size = ring_sz; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define expect_fail_test_rtp_ring_2(A, ring_sz) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.rtp_ring_size = ring_sz; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) -#define expect_test_rtp_pkt_size(A, s_type, pkt_sz, expect) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.type = s_type; \ - ops.rtp_ring_size = 1024; \ - ops.rtp_frame_total_pkts = 1024; \ - ops.rtp_pkt_size = pkt_sz; \ - handle = A##_create(m_handle, &ops); \ - if (expect) \ - EXPECT_TRUE(handle != NULL); \ - else \ - EXPECT_TRUE(handle == NULL); \ - if (handle) { \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - } \ - delete test_ctx; \ +#define expect_test_rtp_pkt_size(A, s_type, pkt_sz, expect) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.type = s_type; \ + ops.rtp_ring_size = 1024; \ + ops.rtp_frame_total_pkts = 1024; \ + ops.rtp_pkt_size = pkt_sz; \ + handle = A##_create(m_handle, &ops); \ + if (expect) \ + EXPECT_TRUE(handle != NULL); \ + else \ + EXPECT_TRUE(handle == NULL); \ + if (handle) { \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + } \ + delete test_ctx; \ } while (0) -#define expect_test_rtp_pkt_size_2(A, s_type, pkt_sz, expect) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.rtp_ring_size = 1024; \ - ops.rtp_pkt_size = pkt_sz; \ - ops.type = s_type; \ - handle = A##_create(m_handle, &ops); \ - if (expect) \ - EXPECT_TRUE(handle != NULL); \ - else \ - EXPECT_TRUE(handle == NULL); \ - if (handle) { \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - } \ - delete test_ctx; \ +#define expect_test_rtp_pkt_size_2(A, s_type, pkt_sz, expect) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.rtp_ring_size = 1024; \ + ops.rtp_pkt_size = pkt_sz; \ + ops.type = s_type; \ + handle = A##_create(m_handle, &ops); \ + if (expect) \ + EXPECT_TRUE(handle != NULL); \ + else \ + EXPECT_TRUE(handle == NULL); \ + if (handle) { \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + } \ + delete test_ctx; \ } while (0) /* pipeline test marco */ -#define pipeline_create_free_test(A, base, step, repeat) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle_base[base]; \ - for (int i = 0; i < base; i++) { \ - handle_base[i] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle_base[i]); \ - ops.port.udp_port[MTL_SESSION_PORT_P]++; \ - ops.port.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - for (int i = 0; i < repeat; i++) { \ - A##_handle handle[step]; \ - \ - for (int j = 0; j < step; j++) { \ - handle[j] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle[j] != NULL); \ - ops.port.udp_port[MTL_SESSION_PORT_P]++; \ - ops.port.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - for (int j = 0; j < step; j++) { \ - ret = A##_free(handle[j]); \ - ASSERT_TRUE(ret >= 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - } \ - \ - for (int i = 0; i < base; i++) { \ - ret = A##_free(handle_base[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - A##_assert_cnt(0); \ - \ - delete test_ctx; \ +#define pipeline_create_free_test(A, base, step, repeat) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle_base[base]; \ + for (int i = 0; i < base; i++) { \ + handle_base[i] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle_base[i]); \ + ops.port.udp_port[MTL_SESSION_PORT_P]++; \ + ops.port.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + for (int i = 0; i < repeat; i++) { \ + A##_handle handle[step]; \ + \ + for (int j = 0; j < step; j++) { \ + handle[j] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle[j] != NULL); \ + ops.port.udp_port[MTL_SESSION_PORT_P]++; \ + ops.port.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + for (int j = 0; j < step; j++) { \ + ret = A##_free(handle[j]); \ + ASSERT_TRUE(ret >= 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + } \ + \ + for (int i = 0; i < base; i++) { \ + ret = A##_free(handle_base[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + A##_assert_cnt(0); \ + \ + delete test_ctx; \ } while (0) -#define pipeline_create_free_max(A, max) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - auto act = 0; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - auto sch_cnt = st_test_sch_cnt(ctx); \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle[max]; \ - for (int i = 0; i < max; i++) { \ - handle[i] = A##_create(m_handle, &ops); \ - if (!handle[i]) break; \ - ops.port.udp_port[MTL_SESSION_PORT_P]++; \ - ops.port.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - info("%s, max session cnt %d\n", __func__, expect_cnt); \ - act = expect_cnt; \ - for (int i = 0; i < act; i++) { \ - ret = A##_free(handle[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - A##_assert_cnt(0); \ - EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ - \ - delete test_ctx; \ +#define pipeline_create_free_max(A, max) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + auto act = 0; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + auto sch_cnt = st_test_sch_cnt(ctx); \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle[max]; \ + for (int i = 0; i < max; i++) { \ + handle[i] = A##_create(m_handle, &ops); \ + if (!handle[i]) \ + break; \ + ops.port.udp_port[MTL_SESSION_PORT_P]++; \ + ops.port.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + info("%s, max session cnt %d\n", __func__, expect_cnt); \ + act = expect_cnt; \ + for (int i = 0; i < act; i++) { \ + ret = A##_free(handle[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + A##_assert_cnt(0); \ + EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ + \ + delete test_ctx; \ } while (0) -#define pipeline_expect_fail_test(A) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - EXPECT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 0 num_port */ \ - ops.port.num_port = 0; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with crazy big num_port */ \ - ops.port.num_port = 100; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with negative num_port */ \ - ops.port.num_port = -1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with 2 num_port */ \ - if (ctx->para.num_ports != 2) { \ - ops.port.num_port = 2; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - } \ - delete test_ctx; \ +#define pipeline_expect_fail_test(A) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + EXPECT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 0 num_port */ \ + ops.port.num_port = 0; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with crazy big num_port */ \ + ops.port.num_port = 100; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with negative num_port */ \ + ops.port.num_port = -1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with 2 num_port */ \ + if (ctx->para.num_ports != 2) { \ + ops.port.num_port = 2; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + } \ + delete test_ctx; \ } while (0) -#define pipeline_expect_fail_test_fb_cnt(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.port.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define pipeline_expect_fail_test_fb_cnt(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.port.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) diff --git a/tests/src/ufd_loop_test.cpp b/tests/src/ufd_loop_test.cpp index 5d716363c..31df67141 100644 --- a/tests/src/ufd_loop_test.cpp +++ b/tests/src/ufd_loop_test.cpp @@ -19,8 +19,8 @@ struct loop_para { bool use_poll; }; -static bool loop_dedicated_mode(struct utest_ctx* ctx) { - struct mtl_init_params* p = &ctx->init_params.mt_params; +static bool loop_dedicated_mode(struct utest_ctx *ctx) { + struct mtl_init_params *p = &ctx->init_params.mt_params; if (p->flags & (MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE)) { return false; @@ -29,7 +29,7 @@ static bool loop_dedicated_mode(struct utest_ctx* ctx) { return true; } -static int loop_para_init(struct loop_para* para) { +static int loop_para_init(struct loop_para *para) { memset(para, 0x0, sizeof(*para)); para->sessions = 1; para->udp_port = 10000; @@ -44,7 +44,7 @@ static int loop_para_init(struct loop_para* para) { return 0; } -static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { +static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { int sessions = para->sessions; uint16_t udp_port = para->udp_port; int udp_len = para->udp_len; @@ -57,12 +57,12 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { std::vector rx_addr(sessions); std::vector tx_bind_addr(sessions); /* for dual loop */ std::vector rx_bind_addr(sessions); - struct pollfd* fds = new struct pollfd[sessions]; + struct pollfd *fds = new struct pollfd[sessions]; int ret; - struct mtl_init_params* p = &ctx->init_params.mt_params; + struct mtl_init_params *p = &ctx->init_params.mt_params; - char* send_buf = new char[udp_len]; - char* recv_buf = new char[udp_len]; + char *send_buf = new char[udp_len]; + char *recv_buf = new char[udp_len]; int payload_len = udp_len - SHA256_DIGEST_LENGTH; ssize_t send; ssize_t recv; @@ -80,47 +80,56 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { } else { mufd_init_sockaddr(&tx_addr[i], p->sip_addr[MTL_PORT_P], udp_port + i); mufd_init_sockaddr(&rx_addr[i], p->sip_addr[MTL_PORT_R], udp_port + i); - mufd_init_sockaddr(&tx_bind_addr[i], p->sip_addr[MTL_PORT_P], udp_port + i); - mufd_init_sockaddr(&rx_bind_addr[i], p->sip_addr[MTL_PORT_R], udp_port + i); + mufd_init_sockaddr(&tx_bind_addr[i], p->sip_addr[MTL_PORT_P], + udp_port + i); + mufd_init_sockaddr(&rx_bind_addr[i], p->sip_addr[MTL_PORT_R], + udp_port + i); } } for (int i = 0; i < sessions; i++) { ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_P); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; tx_fds[i] = ret; if (dual_loop) { - ret = mufd_bind(tx_fds[i], (const struct sockaddr*)&tx_bind_addr[i], + ret = mufd_bind(tx_fds[i], (const struct sockaddr *)&tx_bind_addr[i], sizeof(tx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; - ret = mufd_setsockopt(tx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + ret = + mufd_setsockopt(tx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; } ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_R); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; rx_fds[i] = ret; - ret = mufd_bind(rx_fds[i], (const struct sockaddr*)&rx_bind_addr[i], + ret = mufd_bind(rx_fds[i], (const struct sockaddr *)&rx_bind_addr[i], sizeof(rx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; ret = mufd_setsockopt(rx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; if (para->mcast) { struct ip_mreq mreq; @@ -128,27 +137,31 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - ret = - mufd_setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + ret = mufd_setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, + sizeof(mreq)); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; } } for (int loop = 0; loop < para->tx_pkts; loop++) { /* tx */ for (int i = 0; i < sessions; i++) { - st_test_rand_data((uint8_t*)send_buf, payload_len, 0); + st_test_rand_data((uint8_t *)send_buf, payload_len, 0); send_buf[0] = i; - SHA256((unsigned char*)send_buf, payload_len, - (unsigned char*)send_buf + payload_len); + SHA256((unsigned char *)send_buf, payload_len, + (unsigned char *)send_buf + payload_len); - send = mufd_sendto(tx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr*)&rx_addr[i], sizeof(rx_addr[i])); + send = + mufd_sendto(tx_fds[i], send_buf, udp_len, 0, + (const struct sockaddr *)&rx_addr[i], sizeof(rx_addr[i])); EXPECT_EQ((size_t)send, udp_len); } - if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) + st_usleep(para->tx_sleep_us); if (para->use_poll) { int poll_succ = 0; @@ -165,11 +178,13 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { EXPECT_GE(ret, 0); poll_succ = 0; for (int i = 0; i < sessions; i++) { - if (fds[i].revents) poll_succ++; + if (fds[i].revents) + poll_succ++; } dbg("%s, %d succ on sessions %d on %d\n", __func__, poll_succ, sessions, poll_retry); - if ((poll_succ >= sessions) && (poll_retry > 0)) break; + if ((poll_succ >= sessions) && (poll_retry > 0)) + break; poll_retry++; st_usleep(1000); @@ -184,15 +199,15 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { recv = mufd_recvfrom(rx_fds[i], recv_buf, udp_len, 0, NULL, NULL); if (recv < 0) { /* timeout */ rx_timeout[i]++; - err("%s, recv fail %d at session %d pkt %d fd %d\n", __func__, (int)recv, i, loop, - rx_fds[i]); + err("%s, recv fail %d at session %d pkt %d fd %d\n", __func__, + (int)recv, i, loop, rx_fds[i]); continue; } EXPECT_EQ((size_t)recv, udp_len); /* check idx */ EXPECT_EQ((char)i, recv_buf[0]); /* check sha */ - SHA256((unsigned char*)recv_buf, payload_len, sha_result); + SHA256((unsigned char *)recv_buf, payload_len, sha_result); ret = memcmp(recv_buf + payload_len, sha_result, SHA256_DIGEST_LENGTH); EXPECT_EQ(ret, 0); // test_sha_dump("upd_loop_sha", sha_result); @@ -200,29 +215,31 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { if (dual_loop) { for (int i = 0; i < sessions; i++) { - st_test_rand_data((uint8_t*)send_buf, payload_len, 0); + st_test_rand_data((uint8_t *)send_buf, payload_len, 0); send_buf[0] = i; - SHA256((unsigned char*)send_buf, payload_len, - (unsigned char*)send_buf + payload_len); + SHA256((unsigned char *)send_buf, payload_len, + (unsigned char *)send_buf + payload_len); send = mufd_sendto(rx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr*)&tx_addr[i], sizeof(tx_addr[i])); + (const struct sockaddr *)&tx_addr[i], + sizeof(tx_addr[i])); EXPECT_EQ((size_t)send, udp_len); } - if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) + st_usleep(para->tx_sleep_us); for (int i = 0; i < sessions; i++) { recv = mufd_recvfrom(tx_fds[i], recv_buf, udp_len, 0, NULL, NULL); if (recv < 0) { /* timeout */ rx_timeout[i]++; - err("%s, back recv fail %d at session %d pkt %d\n", __func__, (int)recv, i, - loop); + err("%s, back recv fail %d at session %d pkt %d\n", __func__, + (int)recv, i, loop); continue; } EXPECT_EQ((size_t)recv, udp_len); /* check idx */ EXPECT_EQ((char)i, recv_buf[0]); /* check sha */ - SHA256((unsigned char*)recv_buf, payload_len, sha_result); + SHA256((unsigned char *)recv_buf, payload_len, sha_result); ret = memcmp(recv_buf + payload_len, sha_result, SHA256_DIGEST_LENGTH); EXPECT_EQ(ret, 0); } @@ -236,7 +253,8 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { exit: for (int i = 0; i < sessions; i++) { - if (tx_fds[i] > 0) mufd_close(tx_fds[i]); + if (tx_fds[i] > 0) + mufd_close(tx_fds[i]); if (rx_fds[i] > 0) { if (para->mcast) { struct ip_mreq mreq; @@ -244,7 +262,8 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); ret = mufd_setsockopt(rx_fds[i], IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); EXPECT_GE(ret, 0); @@ -259,7 +278,7 @@ static int loop_sanity_test(struct utest_ctx* ctx, struct loop_para* para) { } TEST(Loop, single) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -267,7 +286,7 @@ TEST(Loop, single) { } TEST(Loop, multi) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -277,7 +296,7 @@ TEST(Loop, multi) { } TEST(Loop, multi_no_sleep) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -287,7 +306,7 @@ TEST(Loop, multi_no_sleep) { } TEST(Loop, multi_shared_max) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; if (loop_dedicated_mode(ctx)) { @@ -304,7 +323,7 @@ TEST(Loop, multi_shared_max) { } TEST(Loop, poll_single) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -313,7 +332,7 @@ TEST(Loop, poll_single) { } TEST(Loop, poll_multi) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -324,7 +343,7 @@ TEST(Loop, poll_multi) { } TEST(Loop, poll_multi_no_sleep) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -335,7 +354,7 @@ TEST(Loop, poll_multi_no_sleep) { } TEST(Loop, poll_shared_max) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; if (loop_dedicated_mode(ctx)) { @@ -353,7 +372,7 @@ TEST(Loop, poll_shared_max) { } TEST(Loop, dual_single) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -362,7 +381,7 @@ TEST(Loop, dual_single) { } TEST(Loop, dual_multi) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -373,7 +392,7 @@ TEST(Loop, dual_multi) { } TEST(Loop, dual_multi_no_sleep) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -384,7 +403,7 @@ TEST(Loop, dual_multi_no_sleep) { } TEST(Loop, dual_multi_shared_max) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; if (loop_dedicated_mode(ctx)) { @@ -402,7 +421,7 @@ TEST(Loop, dual_multi_shared_max) { } TEST(Loop, mcast_single) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -411,7 +430,7 @@ TEST(Loop, mcast_single) { } TEST(Loop, mcast_multi) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -422,7 +441,7 @@ TEST(Loop, mcast_multi) { } TEST(Loop, mcast_multi_shared_max) { - struct utest_ctx* ctx = utest_get_ctx(); + struct utest_ctx *ctx = utest_get_ctx(); struct loop_para para; if (loop_dedicated_mode(ctx)) { diff --git a/tests/src/ufd_test.cpp b/tests/src/ufd_test.cpp index 676a2b123..fb01796da 100644 --- a/tests/src/ufd_test.cpp +++ b/tests/src/ufd_test.cpp @@ -28,82 +28,83 @@ static struct option utest_args_options[] = { {"rss_mode", required_argument, 0, UTEST_ARG_RSS_MODE}, {0, 0, 0, 0}}; -static struct utest_ctx* g_utest_ctx; +static struct utest_ctx *g_utest_ctx; -struct utest_ctx* utest_get_ctx(void) { +struct utest_ctx *utest_get_ctx(void) { return g_utest_ctx; } -static int utest_parse_args(struct utest_ctx* ctx, int argc, char** argv) { +static int utest_parse_args(struct utest_ctx *ctx, int argc, char **argv) { int cmd = -1, opt_idx = 0; - struct mtl_init_params* p = &ctx->init_params.mt_params; + struct mtl_init_params *p = &ctx->init_params.mt_params; while (1) { cmd = getopt_long_only(argc, argv, "hv", utest_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case UTEST_ARG_P_PORT: - snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); - p->num_ports++; - break; - case UTEST_ARG_R_PORT: - snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); - p->num_ports++; - break; - case UTEST_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case UTEST_ARG_QUEUE_MODE: - if (!strcmp(optarg, "shared")) - p->flags |= (MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); - else if (!strcmp(optarg, "dedicated")) - p->flags &= ~(MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); - else - err("%s, unknow queue mode %s\n", __func__, optarg); - break; - case UTEST_ARG_UDP_LCORE: - p->flags |= MTL_FLAG_UDP_LCORE; - break; - case UTEST_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case UTEST_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; ++port) - p->net_proto[port] = MTL_PROTO_DHCP; - ctx->dhcp = true; - break; - default: - break; + case UTEST_ARG_P_PORT: + snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); + p->num_ports++; + break; + case UTEST_ARG_R_PORT: + snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); + p->num_ports++; + break; + case UTEST_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case UTEST_ARG_QUEUE_MODE: + if (!strcmp(optarg, "shared")) + p->flags |= (MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); + else if (!strcmp(optarg, "dedicated")) + p->flags &= ~(MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); + else + err("%s, unknow queue mode %s\n", __func__, optarg); + break; + case UTEST_ARG_UDP_LCORE: + p->flags |= MTL_FLAG_UDP_LCORE; + break; + case UTEST_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case UTEST_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; ++port) + p->net_proto[port] = MTL_PROTO_DHCP; + ctx->dhcp = true; + break; + default: + break; } }; return 0; } -static void utest_random_ip(struct utest_ctx* ctx) { - struct mtl_init_params* p = &ctx->init_params.mt_params; - uint8_t* p_ip = mtl_p_sip_addr(p); - uint8_t* r_ip = mtl_r_sip_addr(p); +static void utest_random_ip(struct utest_ctx *ctx) { + struct mtl_init_params *p = &ctx->init_params.mt_params; + uint8_t *p_ip = mtl_p_sip_addr(p); + uint8_t *r_ip = mtl_r_sip_addr(p); srand(st_test_get_monotonic_time()); @@ -123,8 +124,8 @@ static void utest_random_ip(struct utest_ctx* ctx) { p_ip[3] = rand() % 0xFF; } -static void utest_ctx_init(struct utest_ctx* ctx) { - struct mtl_init_params* p = &ctx->init_params.mt_params; +static void utest_ctx_init(struct utest_ctx *ctx) { + struct mtl_init_params *p = &ctx->init_params.mt_params; memset(p, 0x0, sizeof(*p)); @@ -139,26 +140,21 @@ static void utest_ctx_init(struct utest_ctx* ctx) { p->tasklets_nb_per_sch = ctx->init_params.slots_nb_max + 8; } -static void utest_ctx_uinit(struct utest_ctx* ctx) { - st_test_free(ctx); -} +static void utest_ctx_uinit(struct utest_ctx *ctx) { st_test_free(ctx); } static void socket_single_test(enum mtl_port port) { int ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, port); EXPECT_GE(ret, 0); - if (ret < 0) return; + if (ret < 0) + return; int fd = ret; ret = mufd_close(fd); EXPECT_GE(ret, 0); } -TEST(Api, socket_single) { - socket_single_test(MTL_PORT_P); -} -TEST(Api, socket_single_r) { - socket_single_test(MTL_PORT_R); -} +TEST(Api, socket_single) { socket_single_test(MTL_PORT_P); } +TEST(Api, socket_single_r) { socket_single_test(MTL_PORT_R); } static void socket_expect_fail_test(enum mtl_port port) { int ret; @@ -169,12 +165,8 @@ static void socket_expect_fail_test(enum mtl_port port) { EXPECT_LT(ret, 0); } -TEST(Api, socket_expect_fail) { - socket_expect_fail_test(MTL_PORT_P); -} -TEST(Api, socket_expect_fail_r) { - socket_expect_fail_test(MTL_PORT_R); -} +TEST(Api, socket_expect_fail) { socket_expect_fail_test(MTL_PORT_P); } +TEST(Api, socket_expect_fail_r) { socket_expect_fail_test(MTL_PORT_R); } static void socket_max_test(enum mtl_port port) { int ret; @@ -202,21 +194,15 @@ static void socket_max_test(enum mtl_port port) { } } -TEST(Api, socket_max) { - socket_max_test(MTL_PORT_P); -} -TEST(Api, socket_max_r) { - socket_max_test(MTL_PORT_R); -} +TEST(Api, socket_max) { socket_max_test(MTL_PORT_P); } +TEST(Api, socket_max_r) { socket_max_test(MTL_PORT_R); } -template -static void socketopt_double(OPT_TYPE* i) { +template static void socketopt_double(OPT_TYPE *i) { OPT_TYPE value = *i; *i = value * 2; } -template -static void socketopt_half(OPT_TYPE* i) { +template static void socketopt_half(OPT_TYPE *i) { OPT_TYPE value = *i; *i = value / 2; } @@ -225,7 +211,8 @@ template static void socketopt_test(int level, int optname) { int ret = mufd_socket(AF_INET, SOCK_DGRAM, 0); EXPECT_GE(ret, 0); - if (ret < 0) return; + if (ret < 0) + return; int fd = ret; /* get */ @@ -236,7 +223,7 @@ static void socketopt_test(int level, int optname) { /* double */ socketopt_double(&bufsize); - ret = mufd_setsockopt(fd, level, optname, (const void*)&bufsize, val_size); + ret = mufd_setsockopt(fd, level, optname, (const void *)&bufsize, val_size); EXPECT_GE(ret, 0); /* read again */ OPT_TYPE bufsize_read; @@ -247,7 +234,7 @@ static void socketopt_test(int level, int optname) { /* revert back */ socketopt_half(&bufsize); - ret = mufd_setsockopt(fd, level, optname, (const void*)&bufsize, val_size); + ret = mufd_setsockopt(fd, level, optname, (const void *)&bufsize, val_size); EXPECT_GE(ret, 0); /* read again */ ret = mufd_getsockopt(fd, level, optname, &bufsize_read, &val_size); @@ -259,30 +246,22 @@ static void socketopt_test(int level, int optname) { val_size *= 2; ret = mufd_getsockopt(fd, level, optname, &bufsize, &val_size); EXPECT_LT(ret, 0); - ret = mufd_setsockopt(fd, level, optname, (const void*)&bufsize, val_size); + ret = mufd_setsockopt(fd, level, optname, (const void *)&bufsize, val_size); EXPECT_LT(ret, 0); ret = mufd_close(fd); EXPECT_GE(ret, 0); } -TEST(Api, socket_snd_buf) { - socketopt_test(SOL_SOCKET, SO_SNDBUF); -} -TEST(Api, socket_rcv_buf) { - socketopt_test(SOL_SOCKET, SO_RCVBUF); -} -TEST(Api, socket_cookie) { - socketopt_test(SOL_SOCKET, SO_COOKIE); -} +TEST(Api, socket_snd_buf) { socketopt_test(SOL_SOCKET, SO_SNDBUF); } +TEST(Api, socket_rcv_buf) { socketopt_test(SOL_SOCKET, SO_RCVBUF); } +TEST(Api, socket_cookie) { socketopt_test(SOL_SOCKET, SO_COOKIE); } -template <> -void socketopt_double(struct timeval* i) { +template <> void socketopt_double(struct timeval *i) { i->tv_sec *= 2; i->tv_usec *= 2; } -template <> -void socketopt_half(struct timeval* i) { +template <> void socketopt_half(struct timeval *i) { i->tv_sec /= 2; i->tv_usec /= 2; } @@ -290,16 +269,16 @@ TEST(Api, socket_rcvtimeo) { socketopt_test(SOL_SOCKET, SO_RCVTIMEO); } -static int check_r_port_alive(struct mtl_init_params* p) { +static int check_r_port_alive(struct mtl_init_params *p) { int tx_fd = -1; int rx_fd = -1; int ret = -EIO; struct sockaddr_in tx_addr; struct sockaddr_in rx_addr; size_t payload_len = 1024; - char* send_buf = new char[payload_len]; - char* recv_buf = new char[payload_len]; - st_test_rand_data((uint8_t*)send_buf, payload_len, 0); + char *send_buf = new char[payload_len]; + char *recv_buf = new char[payload_len]; + st_test_rand_data((uint8_t *)send_buf, payload_len, 0); /* max timeout 3 min */ int sleep_ms = 10; int max_retry = 1000 / sleep_ms * 60 * 3; @@ -310,25 +289,29 @@ static int check_r_port_alive(struct mtl_init_params* p) { mufd_init_sockaddr(&rx_addr, p->sip_addr[MTL_PORT_R], 20000); ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_P); - if (ret < 0) goto out; + if (ret < 0) + goto out; tx_fd = ret; ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_R); - if (ret < 0) goto out; + if (ret < 0) + goto out; rx_fd = ret; - ret = mufd_bind(rx_fd, (const struct sockaddr*)&rx_addr, sizeof(rx_addr)); - if (ret < 0) goto out; + ret = mufd_bind(rx_fd, (const struct sockaddr *)&rx_addr, sizeof(rx_addr)); + if (ret < 0) + goto out; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; ret = mufd_setsockopt(rx_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - if (ret < 0) goto out; + if (ret < 0) + goto out; while (retry < max_retry) { - if (mufd_sendto(tx_fd, send_buf, payload_len, 0, (const struct sockaddr*)&rx_addr, - sizeof(rx_addr)) < 0) + if (mufd_sendto(tx_fd, send_buf, payload_len, 0, + (const struct sockaddr *)&rx_addr, sizeof(rx_addr)) < 0) warn("%s, send buf fail at %d\n", __func__, retry); ssize_t recv = mufd_recvfrom(rx_fd, recv_buf, payload_len, 0, NULL, NULL); @@ -342,21 +325,23 @@ static int check_r_port_alive(struct mtl_init_params* p) { } out: - if (tx_fd > 0) mufd_close(tx_fd); - if (rx_fd > 0) mufd_close(rx_fd); + if (tx_fd > 0) + mufd_close(tx_fd); + if (rx_fd > 0) + mufd_close(rx_fd); delete[] send_buf; delete[] recv_buf; return ret; } -GTEST_API_ int main(int argc, char** argv) { - struct utest_ctx* ctx; +GTEST_API_ int main(int argc, char **argv) { + struct utest_ctx *ctx; int ret; bool link_flap_wa = true; testing::InitGoogleTest(&argc, argv); - ctx = (struct utest_ctx*)st_test_zmalloc(sizeof(*ctx)); + ctx = (struct utest_ctx *)st_test_zmalloc(sizeof(*ctx)); if (!ctx) { err("%s, ctx alloc fail\n", __func__); return -ENOMEM; @@ -368,7 +353,8 @@ GTEST_API_ int main(int argc, char** argv) { utest_random_ip(ctx); if (ctx->init_params.mt_params.num_ports != 2) { - err("%s, error, pls pass 2 ports, ex: ./build/tests/KahawaiUfdTest --p_port " + err("%s, error, pls pass 2 ports, ex: ./build/tests/KahawaiUfdTest " + "--p_port " "0000:af:01.0 --r_port 0000:af:01.1\n", __func__); utest_ctx_uinit(ctx); @@ -388,7 +374,8 @@ GTEST_API_ int main(int argc, char** argv) { if (ctx->dhcp) { for (int i = 0; i < ctx->init_params.mt_params.num_ports; i++) { /* get the assigned dhcp ip */ - mufd_port_ip_info((enum mtl_port)i, ctx->init_params.mt_params.sip_addr[i], + mufd_port_ip_info((enum mtl_port)i, + ctx->init_params.mt_params.sip_addr[i], ctx->init_params.mt_params.netmask[i], ctx->init_params.mt_params.gateway[i]); } @@ -399,14 +386,16 @@ GTEST_API_ int main(int argc, char** argv) { /* before test we should make sure the rx port is ready */ ret = check_r_port_alive(&ctx->init_params.mt_params); - if (ret >= 0) ret = RUN_ALL_TESTS(); + if (ret >= 0) + ret = RUN_ALL_TESTS(); uint64_t end_time_ns = st_test_get_monotonic_time(); int time_s = (end_time_ns - start_time_ns) / NS_PER_S; int time_least = 10; if (link_flap_wa && (time_s < time_least)) { /* wa for linkFlapErrDisabled in the hub */ - info("%s, sleep %ds before disable the port\n", __func__, time_least - time_s); + info("%s, sleep %ds before disable the port\n", __func__, + time_least - time_s); sleep(time_least - time_s); } diff --git a/tests/src/ufd_test.h b/tests/src/ufd_test.h index 4c02f4634..3e793db2f 100644 --- a/tests/src/ufd_test.h +++ b/tests/src/ufd_test.h @@ -23,4 +23,4 @@ struct utest_ctx { bool dhcp; }; -struct utest_ctx* utest_get_ctx(void); +struct utest_ctx *utest_get_ctx(void); diff --git a/tests/src/upl_loop_test.cpp b/tests/src/upl_loop_test.cpp index 713843fb4..1123a6318 100644 --- a/tests/src/upl_loop_test.cpp +++ b/tests/src/upl_loop_test.cpp @@ -31,7 +31,7 @@ struct loop_para { int reuse_tx_sessions; }; -static int loop_para_init(struct loop_para* para) { +static int loop_para_init(struct loop_para *para) { memset(para, 0x0, sizeof(*para)); para->sessions = 1; para->udp_port = 10000; @@ -52,9 +52,10 @@ static int loop_para_init(struct loop_para* para) { return 0; } -static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { +static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { int tx_sessions = para->sessions; - if (para->reuse_port) tx_sessions = para->reuse_tx_sessions; + if (para->reuse_port) + tx_sessions = para->reuse_tx_sessions; int rx_sessions = para->sessions; uint16_t udp_port = para->udp_port; int udp_len = para->udp_len; @@ -73,8 +74,8 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { int epoll_fd = -1; int sfd = -1; - char* send_buf = new char[udp_len]; - char* recv_buf = new char[udp_len]; + char *send_buf = new char[udp_len]; + char *recv_buf = new char[udp_len]; int payload_len = udp_len - SHA256_DIGEST_LENGTH; ssize_t send; ssize_t recv; @@ -83,13 +84,15 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { for (int i = 0; i < tx_sessions; i++) { tx_fds[i] = -1; uint16_t fd_udp_port = udp_port + i; - if (para->reuse_port) fd_udp_port = udp_port; + if (para->reuse_port) + fd_udp_port = udp_port; if (para->mcast) { uplt_init_sockaddr(&tx_addr[i], ctx->mcast_ip_addr, fd_udp_port); uplt_init_sockaddr_any(&tx_bind_addr[i], fd_udp_port); } else { uplt_init_sockaddr(&tx_addr[i], ctx->sip_addr[UPLT_PORT_P], fd_udp_port); - uplt_init_sockaddr(&tx_bind_addr[i], ctx->sip_addr[UPLT_PORT_P], fd_udp_port); + uplt_init_sockaddr(&tx_bind_addr[i], ctx->sip_addr[UPLT_PORT_P], + fd_udp_port); } } for (int i = 0; i < rx_sessions; i++) { @@ -97,62 +100,71 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { rx_timeout[i] = 0; rx_pkts[i] = 0; uint16_t fd_udp_port = udp_port + i; - if (para->reuse_port) fd_udp_port = udp_port; + if (para->reuse_port) + fd_udp_port = udp_port; if (para->mcast) { uplt_init_sockaddr(&rx_addr[i], ctx->mcast_ip_addr, fd_udp_port); uplt_init_sockaddr_any(&rx_bind_addr[i], fd_udp_port); } else { uplt_init_sockaddr(&rx_addr[i], ctx->sip_addr[UPLT_PORT_R], fd_udp_port); - uplt_init_sockaddr(&rx_bind_addr[i], ctx->sip_addr[UPLT_PORT_R], fd_udp_port); + uplt_init_sockaddr(&rx_bind_addr[i], ctx->sip_addr[UPLT_PORT_R], + fd_udp_port); } } for (int i = 0; i < tx_sessions; i++) { ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_P); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; tx_fds[i] = ret; if (dual_loop) { - ret = bind(tx_fds[i], (const struct sockaddr*)&tx_bind_addr[i], + ret = bind(tx_fds[i], (const struct sockaddr *)&tx_bind_addr[i], sizeof(tx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; ret = setsockopt(tx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; } } for (int i = 0; i < rx_sessions; i++) { ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_R); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; rx_fds[i] = ret; if (para->reuse_port) { int reuse = 1; - ret = setsockopt(rx_fds[i], SOL_SOCKET, SO_REUSEPORT, (const void*)&reuse, - sizeof(reuse)); + ret = setsockopt(rx_fds[i], SOL_SOCKET, SO_REUSEPORT, + (const void *)&reuse, sizeof(reuse)); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; } - ret = bind(rx_fds[i], (const struct sockaddr*)&rx_bind_addr[i], + ret = bind(rx_fds[i], (const struct sockaddr *)&rx_bind_addr[i], sizeof(rx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; ret = setsockopt(rx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; if (para->mcast) { struct ip_mreq mreq; @@ -160,10 +172,13 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], UPLT_IP_ADDR_LEN); - ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], + UPLT_IP_ADDR_LEN); + ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, + sizeof(mreq)); EXPECT_GE(ret, 0); - if (ret < 0) goto exit; + if (ret < 0) + goto exit; } } @@ -197,10 +212,10 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { for (int loop = 0; loop < para->tx_pkts; loop++) { /* tx */ for (int i = 0; i < tx_sessions; i++) { - st_test_rand_data((uint8_t*)send_buf, payload_len, 0); + st_test_rand_data((uint8_t *)send_buf, payload_len, 0); send_buf[0] = i; - SHA256((unsigned char*)send_buf, payload_len, - (unsigned char*)send_buf + payload_len); + SHA256((unsigned char *)send_buf, payload_len, + (unsigned char *)send_buf + payload_len); struct msghdr msg; memset(&msg, 0, sizeof(msg)); @@ -213,7 +228,7 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { } if (para->sendmsg_gso) { int gso_nb = 4; - char* gso_buf = new char[udp_len * gso_nb]; + char *gso_buf = new char[udp_len * gso_nb]; for (int gso = 0; gso < gso_nb; gso++) { memcpy(&gso_buf[gso * udp_len], send_buf, udp_len); } @@ -225,13 +240,13 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { char msg_control[CMSG_SPACE(sizeof(uint16_t))]; msg.msg_control = msg_control; msg.msg_controllen = sizeof(msg_control); - struct cmsghdr* cmsg; + struct cmsghdr *cmsg; cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = 17; // SOL_UDP; - cmsg->cmsg_type = 103; // UDP_SEGMENT; + cmsg->cmsg_level = 17; // SOL_UDP; + cmsg->cmsg_type = 103; // UDP_SEGMENT; cmsg->cmsg_len = CMSG_LEN(sizeof(uint16_t)); - uint16_t* val_p; - val_p = (uint16_t*)CMSG_DATA(cmsg); + uint16_t *val_p; + val_p = (uint16_t *)CMSG_DATA(cmsg); *val_p = udp_len; dbg("%s, use gso sendmsg\n", __func__); send = sendmsg(tx_fds[i], &msg, 0); @@ -248,16 +263,19 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { EXPECT_EQ((size_t)send, udp_len); } else { if (para->reuse_port) { /* reuse test use same port */ - send = sendto(tx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr*)&rx_addr[0], sizeof(rx_addr[0])); + send = + sendto(tx_fds[i], send_buf, udp_len, 0, + (const struct sockaddr *)&rx_addr[0], sizeof(rx_addr[0])); } else { - send = sendto(tx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr*)&rx_addr[i], sizeof(rx_addr[i])); + send = + sendto(tx_fds[i], send_buf, udp_len, 0, + (const struct sockaddr *)&rx_addr[i], sizeof(rx_addr[i])); } EXPECT_EQ((size_t)send, udp_len); } } - if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) + st_usleep(para->tx_sleep_us); int poll_succ = 0; int poll_retry = 0; @@ -265,7 +283,7 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { if (para->use_poll) { while (poll_retry < max_retry) { - struct pollfd* fds = new struct pollfd[rx_sessions + 1]; + struct pollfd *fds = new struct pollfd[rx_sessions + 1]; memset(fds, 0, sizeof(*fds) * (rx_sessions + 1)); for (int i = 0; i < rx_sessions; i++) { fds[i].fd = rx_fds[i]; @@ -281,11 +299,13 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { EXPECT_GE(ret, 0); poll_succ = 0; for (int i = 0; i < rx_sessions; i++) { - if (fds[i].revents) poll_succ++; + if (fds[i].revents) + poll_succ++; } - dbg("%s, poll %d succ on sessions %d on %d\n", __func__, poll_succ, rx_sessions, - poll_retry); - if (poll_succ >= rx_sessions) break; + dbg("%s, poll %d succ on sessions %d on %d\n", __func__, poll_succ, + rx_sessions, poll_retry); + if (poll_succ >= rx_sessions) + break; poll_retry++; st_usleep(1000); @@ -301,12 +321,14 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { timeout.tv_usec = para->rx_timeout_us; for (int i = 0; i < rx_sessions; i++) { FD_SET(rx_fds[i], &readfds); - if (rx_fds[i] > nfds) nfds = rx_fds[i]; + if (rx_fds[i] > nfds) + nfds = rx_fds[i]; dbg("%s, i %d fd %d\n", __func__, i, rx_fds[i]); } if (sfd > 0) { FD_SET(sfd, &readfds); - if (sfd > nfds) nfds = sfd; + if (sfd > nfds) + nfds = sfd; } nfds += 1; /* highest-numbered fd plus 1 */ ret = select(nfds, &readfds, NULL, NULL, &timeout); @@ -314,23 +336,27 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { dbg("%s, ret %d nfds %d\n", __func__, ret, nfds); poll_succ = 0; for (int i = 0; i < rx_sessions; i++) { - if (FD_ISSET(rx_fds[i], &readfds)) poll_succ++; + if (FD_ISSET(rx_fds[i], &readfds)) + poll_succ++; } - dbg("%s, select %d succ on sessions %d on %d\n", __func__, poll_succ, rx_sessions, - poll_retry); - if (poll_succ >= rx_sessions) break; + dbg("%s, select %d succ on sessions %d on %d\n", __func__, poll_succ, + rx_sessions, poll_retry); + if (poll_succ >= rx_sessions) + break; poll_retry++; st_usleep(1000); } } else if (para->use_epoll) { while (poll_retry < max_retry) { - struct epoll_event* events = new struct epoll_event[rx_sessions]; - ret = epoll_wait(epoll_fd, events, rx_sessions, para->rx_timeout_us / 1000); + struct epoll_event *events = new struct epoll_event[rx_sessions]; + ret = epoll_wait(epoll_fd, events, rx_sessions, + para->rx_timeout_us / 1000); EXPECT_GE(ret, 0); poll_succ = ret; dbg("%s, ret %d\n", __func__, ret); - if (poll_succ >= rx_sessions) break; + if (poll_succ >= rx_sessions) + break; poll_retry++; st_usleep(1000); } @@ -370,25 +396,27 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { EXPECT_EQ((char)i, recv_buf[0]); } /* check sha */ - SHA256((unsigned char*)recv_buf, payload_len, sha_result); + SHA256((unsigned char *)recv_buf, payload_len, sha_result); ret = memcmp(recv_buf + payload_len, sha_result, SHA256_DIGEST_LENGTH); EXPECT_EQ(ret, 0); rx_pkts[i]++; // test_sha_dump("upd_loop_sha", sha_result); - if (para->sendmsg_gso || para->reuse_port) goto session_rx; + if (para->sendmsg_gso || para->reuse_port) + goto session_rx; } if (dual_loop) { for (int i = 0; i < rx_sessions; i++) { - st_test_rand_data((uint8_t*)send_buf, payload_len, 0); + st_test_rand_data((uint8_t *)send_buf, payload_len, 0); send_buf[0] = i; - SHA256((unsigned char*)send_buf, payload_len, - (unsigned char*)send_buf + payload_len); + SHA256((unsigned char *)send_buf, payload_len, + (unsigned char *)send_buf + payload_len); send = sendto(rx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr*)&tx_addr[i], sizeof(tx_addr[i])); + (const struct sockaddr *)&tx_addr[i], sizeof(tx_addr[i])); EXPECT_EQ((size_t)send, udp_len); } - if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) + st_usleep(para->tx_sleep_us); for (int i = 0; i < tx_sessions; i++) { recv = recvfrom(tx_fds[i], recv_buf, udp_len, 0, NULL, NULL); @@ -401,7 +429,7 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { /* check idx */ EXPECT_EQ((char)i, recv_buf[0]); /* check sha */ - SHA256((unsigned char*)recv_buf, payload_len, sha_result); + SHA256((unsigned char *)recv_buf, payload_len, sha_result); ret = memcmp(recv_buf + payload_len, sha_result, SHA256_DIGEST_LENGTH); EXPECT_EQ(ret, 0); } @@ -417,7 +445,8 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { } if (para->reuse_port) { info("%s, total_rx_pkts %d for reuse test\n", __func__, total_rx_pkts); - /* leave some space for miss since we disable the rx timeout for reuse test */ + /* leave some space for miss since we disable the rx timeout for reuse test + */ EXPECT_GT(total_rx_pkts, (para->tx_pkts - 1) * tx_sessions); } @@ -431,7 +460,8 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { sfd = -1; } for (int i = 0; i < tx_sessions; i++) { - if (tx_fds[i] > 0) close(tx_fds[i]); + if (tx_fds[i] > 0) + close(tx_fds[i]); } for (int i = 0; i < rx_sessions; i++) { if (rx_fds[i] > 0) { @@ -441,8 +471,10 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], UPLT_IP_ADDR_LEN); - ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], + UPLT_IP_ADDR_LEN); + ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, + sizeof(mreq)); EXPECT_GE(ret, 0); } close(rx_fds[i]); @@ -454,7 +486,7 @@ static int loop_sanity_test(struct uplt_ctx* ctx, struct loop_para* para) { } TEST(Loop, single) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -462,7 +494,7 @@ TEST(Loop, single) { } TEST(Loop, poll_multi_no_sleep) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -473,7 +505,7 @@ TEST(Loop, poll_multi_no_sleep) { } TEST(Loop, poll_multi_mix_fd) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -485,7 +517,7 @@ TEST(Loop, poll_multi_mix_fd) { } TEST(Loop, dual_single) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -494,7 +526,7 @@ TEST(Loop, dual_single) { } TEST(Loop, dual_multi_no_sleep) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -505,7 +537,7 @@ TEST(Loop, dual_multi_no_sleep) { } TEST(Loop, mcast_multi) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -516,7 +548,7 @@ TEST(Loop, mcast_multi) { } TEST(Loop, select_multi_no_sleep) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -527,7 +559,7 @@ TEST(Loop, select_multi_no_sleep) { } TEST(Loop, select_multi_mix_fd) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -538,7 +570,7 @@ TEST(Loop, select_multi_mix_fd) { } TEST(Loop, epoll_multi_no_sleep) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -550,7 +582,7 @@ TEST(Loop, epoll_multi_no_sleep) { } TEST(Loop, epoll_multi_mix_fd) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -562,7 +594,7 @@ TEST(Loop, epoll_multi_mix_fd) { } TEST(Loop, sendmsg_multi) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -574,7 +606,7 @@ TEST(Loop, sendmsg_multi) { } TEST(Loop, sendmsg_gso) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -588,7 +620,7 @@ TEST(Loop, sendmsg_gso) { } TEST(Loop, recvmsg_multi) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); @@ -600,7 +632,7 @@ TEST(Loop, recvmsg_multi) { } TEST(Loop, reuse_port) { - struct uplt_ctx* ctx = uplt_get_ctx(); + struct uplt_ctx *ctx = uplt_get_ctx(); struct loop_para para; loop_para_init(¶); diff --git a/tests/src/upl_test.cpp b/tests/src/upl_test.cpp index 380823557..2a12957af 100644 --- a/tests/src/upl_test.cpp +++ b/tests/src/upl_test.cpp @@ -8,17 +8,17 @@ #include "log.h" -static struct uplt_ctx* g_uplt_ctx; +static struct uplt_ctx *g_uplt_ctx; -struct uplt_ctx* uplt_get_ctx(void) { +struct uplt_ctx *uplt_get_ctx(void) { return g_uplt_ctx; } -static void uplt_ctx_init(struct uplt_ctx* ctx) { +static void uplt_ctx_init(struct uplt_ctx *ctx) { inet_pton(AF_INET, "192.168.89.80", ctx->sip_addr[UPLT_PORT_P]); inet_pton(AF_INET, "192.168.89.81", ctx->sip_addr[UPLT_PORT_R]); - uint8_t* p_ip; + uint8_t *p_ip; srand(st_test_get_monotonic_time()); p_ip = ctx->mcast_ip_addr; p_ip[0] = 239; @@ -27,9 +27,7 @@ static void uplt_ctx_init(struct uplt_ctx* ctx) { p_ip[3] = rand() % 0xFF; } -static void uplt_ctx_uinit(struct uplt_ctx* ctx) { - st_test_free(ctx); -} +static void uplt_ctx_uinit(struct uplt_ctx *ctx) { st_test_free(ctx); } static int uplt_set_port(int port) { char port_u[16]; @@ -47,32 +45,27 @@ int uplt_socket_port(int domain, int type, int protocol, int port) { static void socket_single_test(int port) { int ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, port); EXPECT_GE(ret, 0); - if (ret < 0) return; + if (ret < 0) + return; int fd = ret; ret = close(fd); EXPECT_GE(ret, 0); } -TEST(Api, socket_single) { - socket_single_test(UPLT_PORT_P); -} -TEST(Api, socket_single_r) { - socket_single_test(UPLT_PORT_R); -} -TEST(Api, socket_single_port_max) { - socket_single_test(32); -} +TEST(Api, socket_single) { socket_single_test(UPLT_PORT_P); } +TEST(Api, socket_single_r) { socket_single_test(UPLT_PORT_R); } +TEST(Api, socket_single_port_max) { socket_single_test(32); } -static int check_r_port_alive(struct uplt_ctx* ctx) { +static int check_r_port_alive(struct uplt_ctx *ctx) { int tx_fd = -1; int rx_fd = -1; int ret = -EIO; struct sockaddr_in rx_addr; size_t payload_len = 1024; - char* send_buf = new char[payload_len]; - char* recv_buf = new char[payload_len]; - st_test_rand_data((uint8_t*)send_buf, payload_len, 0); + char *send_buf = new char[payload_len]; + char *recv_buf = new char[payload_len]; + st_test_rand_data((uint8_t *)send_buf, payload_len, 0); /* max timeout 3 min */ int sleep_ms = 10; int max_retry = 1000 / sleep_ms * 60 * 3; @@ -81,26 +74,30 @@ static int check_r_port_alive(struct uplt_ctx* ctx) { uplt_init_sockaddr(&rx_addr, ctx->sip_addr[1], 20000); ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_P); - if (ret < 0) goto out; + if (ret < 0) + goto out; tx_fd = ret; ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_R); - if (ret < 0) goto out; + if (ret < 0) + goto out; rx_fd = ret; - ret = bind(rx_fd, (const struct sockaddr*)&rx_addr, sizeof(rx_addr)); - if (ret < 0) goto out; + ret = bind(rx_fd, (const struct sockaddr *)&rx_addr, sizeof(rx_addr)); + if (ret < 0) + goto out; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; ret = setsockopt(rx_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - if (ret < 0) goto out; + if (ret < 0) + goto out; info("%s, start to rx port status\n", __func__); while (retry < max_retry) { - if (sendto(tx_fd, send_buf, payload_len, 0, (const struct sockaddr*)&rx_addr, - sizeof(rx_addr)) < 0) + if (sendto(tx_fd, send_buf, payload_len, 0, + (const struct sockaddr *)&rx_addr, sizeof(rx_addr)) < 0) continue; ssize_t recv = recvfrom(rx_fd, recv_buf, payload_len, 0, NULL, NULL); if (recv > 0) { @@ -113,8 +110,10 @@ static int check_r_port_alive(struct uplt_ctx* ctx) { } out: - if (tx_fd > 0) close(tx_fd); - if (rx_fd > 0) close(rx_fd); + if (tx_fd > 0) + close(tx_fd); + if (rx_fd > 0) + close(rx_fd); delete[] send_buf; delete[] recv_buf; return ret; @@ -131,37 +130,38 @@ static struct option uplt_args_options[] = { {"r_sip", required_argument, 0, UPLT_ARG_R_SIP}, {0, 0, 0, 0}}; -static int uplt_parse_args(struct uplt_ctx* ctx, int argc, char** argv) { +static int uplt_parse_args(struct uplt_ctx *ctx, int argc, char **argv) { int cmd = -1, opt_idx = 0; while (1) { cmd = getopt_long_only(argc, argv, "hv", uplt_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case UPLT_ARG_P_SIP: - inet_pton(AF_INET, optarg, ctx->sip_addr[0]); - break; - case UPLT_ARG_R_SIP: - inet_pton(AF_INET, optarg, ctx->sip_addr[1]); - break; - default: - break; + case UPLT_ARG_P_SIP: + inet_pton(AF_INET, optarg, ctx->sip_addr[0]); + break; + case UPLT_ARG_R_SIP: + inet_pton(AF_INET, optarg, ctx->sip_addr[1]); + break; + default: + break; } }; return 0; } -GTEST_API_ int main(int argc, char** argv) { - struct uplt_ctx* ctx; +GTEST_API_ int main(int argc, char **argv) { + struct uplt_ctx *ctx; int ret; bool link_flap_wa = true; testing::InitGoogleTest(&argc, argv); - ctx = (struct uplt_ctx*)st_test_zmalloc(sizeof(*ctx)); + ctx = (struct uplt_ctx *)st_test_zmalloc(sizeof(*ctx)); if (!ctx) { err("%s, ctx alloc fail\n", __func__); return -ENOMEM; @@ -176,14 +176,16 @@ GTEST_API_ int main(int argc, char** argv) { /* before test we should make sure the rx port is ready */ ret = check_r_port_alive(ctx); - if (ret >= 0) ret = RUN_ALL_TESTS(); + if (ret >= 0) + ret = RUN_ALL_TESTS(); uint64_t end_time_ns = st_test_get_monotonic_time(); int time_s = (end_time_ns - start_time_ns) / NS_PER_S; int time_least = 10; if (link_flap_wa && (time_s < time_least)) { /* wa for linkFlapErrDisabled in the hub */ - info("%s, sleep %ds before disable the port\n", __func__, time_least - time_s); + info("%s, sleep %ds before disable the port\n", __func__, + time_least - time_s); sleep(time_least - time_s); } diff --git a/tests/src/upl_test.h b/tests/src/upl_test.h index e6e66e15a..1760eba51 100644 --- a/tests/src/upl_test.h +++ b/tests/src/upl_test.h @@ -18,19 +18,21 @@ struct uplt_ctx { uint8_t mcast_ip_addr[UPLT_IP_ADDR_LEN]; }; -struct uplt_ctx* uplt_get_ctx(void); +struct uplt_ctx *uplt_get_ctx(void); int uplt_socket_port(int domain, int type, int protocol, int port); -static void inline uplt_init_sockaddr(struct sockaddr_in* saddr, - uint8_t ip[UPLT_IP_ADDR_LEN], uint16_t port) { +static void inline uplt_init_sockaddr(struct sockaddr_in *saddr, + uint8_t ip[UPLT_IP_ADDR_LEN], + uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; memcpy(&saddr->sin_addr.s_addr, ip, UPLT_IP_ADDR_LEN); saddr->sin_port = htons(port); } -static void inline uplt_init_sockaddr_any(struct sockaddr_in* saddr, uint16_t port) { +static void inline uplt_init_sockaddr_any(struct sockaddr_in *saddr, + uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; saddr->sin_addr.s_addr = INADDR_ANY; diff --git a/tools/ebpf/et.c b/tools/ebpf/et.c index 0cf35c5bb..636ff262a 100644 --- a/tools/ebpf/et.c +++ b/tools/ebpf/et.c @@ -22,7 +22,7 @@ static volatile bool stop = false; -static int libbpf_print_fn(enum libbpf_print_level level, const char* format, +static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va_list args) { return vfprintf(stderr, format, args); } @@ -31,25 +31,25 @@ static void et_sig_handler(int signo) { printf("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + stop = true; + break; } return; } -static int udp_send_handler(void* ctx, void* data, size_t data_sz) { - const struct udp_send_event* e = data; +static int udp_send_handler(void *ctx, void *data, size_t data_sz) { + const struct udp_send_event *e = data; - printf("%s: pid %d, gso_size %u, bytes %u, duration_ns %llu\n", __func__, e->pid, - e->gso_size, e->udp_send_bytes, e->duration_ns); + printf("%s: pid %d, gso_size %u, bytes %u, duration_ns %llu\n", __func__, + e->pid, e->gso_size, e->udp_send_bytes, e->duration_ns); return 0; } static int et_fentry_loop() { - struct ring_buffer* rb = NULL; - struct fentry_bpf* skel; + struct ring_buffer *rb = NULL; + struct fentry_bpf *skel; int ret = 0; skel = fentry_bpf__open_and_load(); @@ -66,7 +66,8 @@ static int et_fentry_loop() { printf("fentry_bpf__attach() succeeded\n"); - rb = ring_buffer__new(bpf_map__fd(skel->maps.rb), udp_send_handler, NULL, NULL); + rb = ring_buffer__new(bpf_map__fd(skel->maps.rb), udp_send_handler, NULL, + NULL); if (!rb) { ret = -1; fprintf(stderr, "failed to create ring buffer\n"); @@ -91,7 +92,7 @@ static int et_fentry_loop() { return ret; } -static int et_xdp_loop(struct et_ctx* ctx) { +static int et_xdp_loop(struct et_ctx *ctx) { int ret = 0; int if_cnt = ctx->xdp_if_cnt; @@ -100,7 +101,7 @@ static int et_xdp_loop(struct et_ctx* ctx) { return -EIO; } - struct xdp_program* prog[if_cnt]; + struct xdp_program *prog[if_cnt]; /* load xdp program for each interface */ for (int i = 0; i < if_cnt; i++) { @@ -149,60 +150,64 @@ static void et_print_help() { printf("##### Usage: #####\n\n"); printf(" Params:\n"); - printf(" --help Print this help information\n"); + printf(" --help Print this help " + "information\n"); printf(" --print Print libbpf output\n"); printf("\n Prog Commands:\n"); - printf(" --prog Attach to program of \n"); + printf(" --prog Attach to program of " + "\n"); printf( - " --prog xdp --ifname --xdp_path /path/to/xdp.o Load a custom " + " --prog xdp --ifname --xdp_path /path/to/xdp.o " + "Load a custom " "XDP kernel program from the specified path and attach it to specified " "interfaces\n"); printf("\n"); } -static int et_parse_args(struct et_ctx* ctx, int argc, char** argv) { +static int et_parse_args(struct et_ctx *ctx, int argc, char **argv) { int cmd = -1, opt_idx = 0; while (1) { cmd = getopt_long_only(argc, argv, "hv", et_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; switch (cmd) { - case ET_ARG_PROG: - if (strcmp(optarg, "fentry") == 0) { - ctx->prog_type = ET_PROG_FENTRY; - } else if (strcmp(optarg, "xdp") == 0) { - ctx->prog_type = ET_PROG_XDP; - } - break; - case ET_ARG_PRINT_LIBBPF: - libbpf_set_print(libbpf_print_fn); - break; - case ET_ARG_IFNAME: - char* ifname; - ctx->xdp_if_cnt = 0; - ifname = strtok(optarg, ","); - while (ifname) { - ctx->xdp_ifindex[ctx->xdp_if_cnt++] = if_nametoindex(ifname); - ifname = strtok(NULL, ","); - } - break; - case ET_ARG_XDP_PATH: - ctx->xdp_path = optarg; - break; - case ET_ARG_HELP: - default: - et_print_help(); - return -1; + case ET_ARG_PROG: + if (strcmp(optarg, "fentry") == 0) { + ctx->prog_type = ET_PROG_FENTRY; + } else if (strcmp(optarg, "xdp") == 0) { + ctx->prog_type = ET_PROG_XDP; + } + break; + case ET_ARG_PRINT_LIBBPF: + libbpf_set_print(libbpf_print_fn); + break; + case ET_ARG_IFNAME: + char *ifname; + ctx->xdp_if_cnt = 0; + ifname = strtok(optarg, ","); + while (ifname) { + ctx->xdp_ifindex[ctx->xdp_if_cnt++] = if_nametoindex(ifname); + ifname = strtok(NULL, ","); + } + break; + case ET_ARG_XDP_PATH: + ctx->xdp_path = optarg; + break; + case ET_ARG_HELP: + default: + et_print_help(); + return -1; } } return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct et_ctx ctx; memset(&ctx, 0, sizeof(ctx)); et_parse_args(&ctx, argc, argv); @@ -210,14 +215,14 @@ int main(int argc, char** argv) { printf("prog type is %s\n", prog_type_str[ctx.prog_type]); switch (ctx.prog_type) { - case ET_PROG_FENTRY: - et_fentry_loop(); - break; - case ET_PROG_XDP: - et_xdp_loop(&ctx); - break; - default: - break; + case ET_PROG_FENTRY: + et_fentry_loop(); + break; + case ET_PROG_XDP: + et_xdp_loop(&ctx); + break; + default: + break; } return 0; diff --git a/tools/ebpf/et.h b/tools/ebpf/et.h index 7c2999dce..48d98c977 100644 --- a/tools/ebpf/et.h +++ b/tools/ebpf/et.h @@ -34,7 +34,7 @@ enum et_prog_type { ET_PROG_XDP, }; -static const char* prog_type_str[] = { +static const char *prog_type_str[] = { [ET_PROG_FENTRY] = "fentry", [ET_PROG_KPROBE] = "kprobe", [ET_PROG_TRACEPOINT] = "tracepoint", @@ -45,7 +45,7 @@ struct et_ctx { enum et_prog_type prog_type; int xdp_ifindex[8]; int xdp_if_cnt; - char* xdp_path; + char *xdp_path; }; #endif /* __ET_H */ \ No newline at end of file diff --git a/tools/ebpf/fentry.bpf.c b/tools/ebpf/fentry.bpf.c index 2ea1db04c..b5cc6470f 100644 --- a/tools/ebpf/fentry.bpf.c +++ b/tools/ebpf/fentry.bpf.c @@ -25,8 +25,8 @@ struct { } rb SEC(".maps"); SEC("fentry/udp_send_skb") -int BPF_PROG(udp_send_skb, struct sk_buff* skb, struct flowi4* fl4, - struct inet_cork* cork) { +int BPF_PROG(udp_send_skb, struct sk_buff *skb, struct flowi4 *fl4, + struct inet_cork *cork) { u64 ts; u64 skb_addr = (u64)skb; @@ -37,20 +37,22 @@ int BPF_PROG(udp_send_skb, struct sk_buff* skb, struct flowi4* fl4, } SEC("fexit/udp_send_skb") -int BPF_PROG(udp_send_skb_exit, struct sk_buff* skb, struct flowi4* fl4, - struct inet_cork* cork, long ret) { - struct udp_send_event* e; +int BPF_PROG(udp_send_skb_exit, struct sk_buff *skb, struct flowi4 *fl4, + struct inet_cork *cork, long ret) { + struct udp_send_event *e; pid_t pid; u64 *start_ts, duration_ns = 0; u64 skb_addr = (u64)skb; pid = bpf_get_current_pid_tgid() >> 32; start_ts = bpf_map_lookup_elem(&start_time, &skb_addr); - if (start_ts) duration_ns = bpf_ktime_get_ns() - *start_ts; + if (start_ts) + duration_ns = bpf_ktime_get_ns() - *start_ts; bpf_map_delete_elem(&start_time, &skb_addr); e = bpf_ringbuf_reserve(&rb, sizeof(*e), 0); - if (!e) return 0; + if (!e) + return 0; e->pid = pid; e->gso_size = cork->gso_size; diff --git a/tools/ebpf/lcore_monitor.bpf.c b/tools/ebpf/lcore_monitor.bpf.c index 922986baf..d9fbb43d9 100644 --- a/tools/ebpf/lcore_monitor.bpf.c +++ b/tools/ebpf/lcore_monitor.bpf.c @@ -23,16 +23,16 @@ struct { __uint(max_entries, 512 * 1024); } lm_events_map SEC(".maps"); -static struct lcore_tid_cfg* lm_get_cfg(void) { - struct lcore_tid_cfg* cfg; +static struct lcore_tid_cfg *lm_get_cfg(void) { + struct lcore_tid_cfg *cfg; uint32_t key = 0; cfg = bpf_map_lookup_elem(&lm_cfg_map, &key); return cfg; } static int lm_switch_event_submit(enum lcore_tid_event_type type, - struct trace_event_raw_sched_switch* args) { - struct lcore_tid_event* e; + struct trace_event_raw_sched_switch *args) { + struct lcore_tid_event *e; e = bpf_ringbuf_reserve(&lm_events_map, sizeof(*e), 0); if (!e) { @@ -50,12 +50,14 @@ static int lm_switch_event_submit(enum lcore_tid_event_type type, } SEC("tracepoint/sched/sched_switch") -int bpf_prog_sched_switch(struct trace_event_raw_sched_switch* args) { - struct lcore_tid_cfg* cfg = lm_get_cfg(); - if (!cfg) return 0; +int bpf_prog_sched_switch(struct trace_event_raw_sched_switch *args) { + struct lcore_tid_cfg *cfg = lm_get_cfg(); + if (!cfg) + return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) + return 0; if (cfg->bpf_trace) { char fmt[] = "sched_switch: prev_pid %d next_pid in %d\n"; @@ -131,7 +133,7 @@ int bpf_prog_irq_handler_exit(struct trace_event_raw_irq_handler_entry* args) { #endif static int lm_vector_event_submit(enum lcore_tid_event_type type, int vector) { - struct lcore_tid_event* e; + struct lcore_tid_event *e; e = bpf_ringbuf_reserve(&lm_events_map, sizeof(*e), 0); if (!e) { @@ -150,11 +152,13 @@ static int lm_vector_event_submit(enum lcore_tid_event_type type, int vector) { SEC("raw_tp/irq_work_entry") int BPF_PROG(irq_work_entry, unsigned int vector) { - struct lcore_tid_cfg* cfg = lm_get_cfg(); - if (!cfg) return 0; + struct lcore_tid_cfg *cfg = lm_get_cfg(); + if (!cfg) + return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) + return 0; if (cfg->bpf_trace) { char fmt[] = "irq_work_entry, vector %d\n"; @@ -168,11 +172,13 @@ int BPF_PROG(irq_work_entry, unsigned int vector) { SEC("raw_tp/irq_work_exit") int BPF_PROG(irq_work_exit, unsigned int vector) { - struct lcore_tid_cfg* cfg = lm_get_cfg(); - if (!cfg) return 0; + struct lcore_tid_cfg *cfg = lm_get_cfg(); + if (!cfg) + return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) + return 0; if (cfg->bpf_trace) { char fmt[] = "irq_work_exit, vector %d\n"; @@ -185,7 +191,7 @@ int BPF_PROG(irq_work_exit, unsigned int vector) { } static int lm_syscall_event_submit(enum lcore_tid_event_type type, int id) { - struct lcore_tid_event* e; + struct lcore_tid_event *e; e = bpf_ringbuf_reserve(&lm_events_map, sizeof(*e), 0); if (!e) { @@ -203,12 +209,14 @@ static int lm_syscall_event_submit(enum lcore_tid_event_type type, int id) { } SEC("tracepoint/raw_syscalls/sys_enter") -int bpf_prog_sys_enter(struct trace_event_raw_sys_enter* args) { - struct lcore_tid_cfg* cfg = lm_get_cfg(); - if (!cfg) return 0; +int bpf_prog_sys_enter(struct trace_event_raw_sys_enter *args) { + struct lcore_tid_cfg *cfg = lm_get_cfg(); + if (!cfg) + return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) + return 0; if (cfg->bpf_trace) { char fmt[] = "sys_enter: id %d\n"; @@ -221,12 +229,14 @@ int bpf_prog_sys_enter(struct trace_event_raw_sys_enter* args) { } SEC("tracepoint/raw_syscalls/sys_exit") -int bpf_prog_sys_enxit(struct trace_event_raw_sys_exit* args) { - struct lcore_tid_cfg* cfg = lm_get_cfg(); - if (!cfg) return 0; +int bpf_prog_sys_enxit(struct trace_event_raw_sys_exit *args) { + struct lcore_tid_cfg *cfg = lm_get_cfg(); + if (!cfg) + return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) + return 0; if (cfg->bpf_trace) { char fmt[] = "sys_enter: id %d\n"; diff --git a/tools/ebpf/lcore_monitor.c b/tools/ebpf/lcore_monitor.c index c0a150371..c8090f7f8 100644 --- a/tools/ebpf/lcore_monitor.c +++ b/tools/ebpf/lcore_monitor.c @@ -53,37 +53,39 @@ static void lm_print_help() { printf(" Params:\n"); printf(" --lcore Set the monitor lcore\n"); printf(" --t_pid Set the monitor t_pid\n"); - printf(" --filter_us Report the sch/irq event only if the time > filter_us\n"); + printf(" --filter_us Report the sch/irq event only if the time > " + "filter_us\n"); printf(" --bpf_trace Enable bpf trace\n"); printf(" --help Print help info\n"); printf("\n"); } -static int lm_parse_args(struct lcore_monitor_ctx* ctx, int argc, char** argv) { +static int lm_parse_args(struct lcore_monitor_ctx *ctx, int argc, char **argv) { int cmd = -1, opt_idx = 0; while (1) { cmd = getopt_long_only(argc, argv, "hv", et_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; switch (cmd) { - case LM_ARG_CORE: - ctx->cfg.core_id = atoi(optarg); - break; - case LM_ARG_T_PID: - ctx->cfg.t_pid = atoi(optarg); - break; - case LM_ARG_BPF_TRACE: - ctx->cfg.bpf_trace = true; - break; - case LM_ARG_FILTER_US: - ctx->filter_ns = atoi(optarg) * 1000; - break; - case LM_ARG_HELP: - default: - lm_print_help(); - return -1; + case LM_ARG_CORE: + ctx->cfg.core_id = atoi(optarg); + break; + case LM_ARG_T_PID: + ctx->cfg.t_pid = atoi(optarg); + break; + case LM_ARG_BPF_TRACE: + ctx->cfg.bpf_trace = true; + break; + case LM_ARG_FILTER_US: + ctx->filter_ns = atoi(optarg) * 1000; + break; + case LM_ARG_HELP: + default: + lm_print_help(); + return -1; } } @@ -96,17 +98,18 @@ static void lm_sig_handler(int signo) { info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + stop = true; + break; } return; } -static int get_process_name_by_pid(pid_t pid, char* process_name, size_t max_len) { +static int get_process_name_by_pid(pid_t pid, char *process_name, + size_t max_len) { char path[128]; - FILE* fp; + FILE *fp; snprintf(path, sizeof(path), "/proc/%d/comm", pid); fp = fopen(path, "r"); @@ -130,9 +133,9 @@ static int get_process_name_by_pid(pid_t pid, char* process_name, size_t max_len return 0; } -static int lm_event_handler(void* pri, void* data, size_t data_sz) { - struct lcore_monitor_ctx* ctx = pri; - const struct lcore_tid_event* e = data; +static int lm_event_handler(void *pri, void *data, size_t data_sz) { + struct lcore_monitor_ctx *ctx = pri; + const struct lcore_tid_event *e = data; int ret; dbg("%s: type %d, ns %" PRIu64 "\n", __func__, e->type, e->ns); @@ -143,14 +146,16 @@ static int lm_event_handler(void* pri, void* data, size_t data_sz) { } if (e->type == LCORE_SCHED_IN) { float ns = e->ns - ctx->sched_out.ns; - if (ns < ctx->filter_ns) return 0; + if (ns < ctx->filter_ns) + return 0; int next_pid = ctx->sched_out.next_pid; char process_name[64]; ret = get_process_name_by_pid(next_pid, process_name, sizeof(process_name)); if (ret < 0) info("%s: sched out %.3fus as pid: %d\n", __func__, ns / 1000, next_pid); else - info("%s: sched out %.3fus as comm: %s\n", __func__, ns / 1000, process_name); + info("%s: sched out %.3fus as comm: %s\n", __func__, ns / 1000, + process_name); return 0; } @@ -161,7 +166,8 @@ static int lm_event_handler(void* pri, void* data, size_t data_sz) { } if (e->type == LCORE_IRQ_EXIT) { float ns = e->ns - ctx->irq_entry.ns; - if (ns < ctx->filter_ns) return 0; + if (ns < ctx->filter_ns) + return 0; info("%s: sched out %.3fus as irq: %d\n", __func__, ns / 1000, e->irq); return 0; } @@ -173,8 +179,10 @@ static int lm_event_handler(void* pri, void* data, size_t data_sz) { } if (e->type == LCORE_VECTOR_EXIT) { float ns = e->ns - ctx->vector_entry.ns; - if (ns < ctx->filter_ns) return 0; - info("%s: sched out %.3fus as vector: %d\n", __func__, ns / 1000, e->vector); + if (ns < ctx->filter_ns) + return 0; + info("%s: sched out %.3fus as vector: %d\n", __func__, ns / 1000, + e->vector); return 0; } @@ -185,7 +193,8 @@ static int lm_event_handler(void* pri, void* data, size_t data_sz) { } if (e->type == LCORE_SYS_EXIT) { float ns = e->ns - ctx->syscall.ns; - if (ns < ctx->filter_ns) return 0; + if (ns < ctx->filter_ns) + return 0; info("%s: syscall out %.3fus as syscall: %d\n", __func__, ns / 1000, e->id); return 0; } @@ -194,13 +203,14 @@ static int lm_event_handler(void* pri, void* data, size_t data_sz) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct lcore_monitor_ctx ctx; int ret; memset(&ctx, 0, sizeof(ctx)); ret = lm_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; if (!ctx.cfg.core_id) { err("%s, no core id define\n", __func__); lm_print_help(); @@ -212,8 +222,8 @@ int main(int argc, char** argv) { return -1; } - struct lcore_monitor_bpf* skel = NULL; - struct ring_buffer* rb = NULL; + struct lcore_monitor_bpf *skel = NULL; + struct ring_buffer *rb = NULL; skel = lcore_monitor_bpf__open_and_load(); if (!skel) { @@ -256,7 +266,9 @@ int main(int argc, char** argv) { info("%s, stop now\n", __func__); exit: - if (rb) ring_buffer__free(rb); - if (skel) lcore_monitor_bpf__destroy(skel); + if (rb) + ring_buffer__free(rb); + if (skel) + lcore_monitor_bpf__destroy(skel); return 0; } diff --git a/tools/ebpf/log.h b/tools/ebpf/log.h index 14f724a96..95698495c 100644 --- a/tools/ebpf/log.h +++ b/tools/ebpf/log.h @@ -10,26 +10,26 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif \ No newline at end of file diff --git a/tools/ebpf/udp_monitor.bpf.c b/tools/ebpf/udp_monitor.bpf.c index b76f1fa71..086813db0 100644 --- a/tools/ebpf/udp_monitor.bpf.c +++ b/tools/ebpf/udp_monitor.bpf.c @@ -21,8 +21,8 @@ struct { } udp_hdr_rb SEC(".maps"); SEC("socket") -int bpf_socket_handler(struct __sk_buff* skb) { - struct udp_pkt_entry* e; +int bpf_socket_handler(struct __sk_buff *skb) { + struct udp_pkt_entry *e; __u8 verlen; __u16 proto; __u8 ip_proto; @@ -33,17 +33,21 @@ int bpf_socket_handler(struct __sk_buff* skb) { if (proto != ETH_P_IP) { /* not ipv4 */ return 0; } - bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, protocol), &ip_proto, 1); + bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, protocol), &ip_proto, + 1); if (ip_proto != IPPROTO_UDP) { /* not udp */ return 0; } e = bpf_ringbuf_reserve(&udp_hdr_rb, sizeof(*e), 0); - if (!e) return 0; + if (!e) + return 0; /* fill src and dst ip */ - bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, saddr), &(e->tuple.src_ip), 4); - bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, daddr), &(e->tuple.dst_ip), 4); + bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, saddr), + &(e->tuple.src_ip), 4); + bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, daddr), + &(e->tuple.dst_ip), 4); /* fill src and dst port */ bpf_skb_load_bytes(skb, nhoff + 0, &verlen, 1); bpf_skb_load_bytes(skb, nhoff + ((verlen & 0xF) << 2), &(e->tuple.ports), 4); diff --git a/tools/ebpf/udp_monitor.c b/tools/ebpf/udp_monitor.c index 44d2a9b82..8c5ca69e8 100644 --- a/tools/ebpf/udp_monitor.c +++ b/tools/ebpf/udp_monitor.c @@ -38,7 +38,7 @@ TAILQ_HEAD(udp_detect_list, udp_detect_entry); struct udp_monitor_ctx { struct udp_detect_list detect; - const char* interface; + const char *interface; int dump_period_s; bool skip_sys; bool promisc; @@ -61,13 +61,14 @@ static struct option um_args_options[] = { {"help", no_argument, 0, UM_ARG_HELP}, {0, 0, 0, 0}}; -static inline void* um_zmalloc(size_t sz) { - void* p = malloc(sz); - if (p) memset(p, 0x0, sz); +static inline void *um_zmalloc(size_t sz) { + void *p = malloc(sz); + if (p) + memset(p, 0x0, sz); return p; } -static inline uint64_t um_timespec_to_ns(const struct timespec* ts) { +static inline uint64_t um_timespec_to_ns(const struct timespec *ts) { return ((uint64_t)ts->tv_sec * NS_PER_S) + ts->tv_nsec; } @@ -93,52 +94,55 @@ static void um_print_help() { printf("\n"); } -static int um_parse_args(struct udp_monitor_ctx* ctx, int argc, char** argv) { +static int um_parse_args(struct udp_monitor_ctx *ctx, int argc, char **argv) { int cmd = -1, opt_idx = 0; while (1) { cmd = getopt_long_only(argc, argv, "hv", um_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; switch (cmd) { - case UM_ARG_INTERFACE: - ctx->interface = optarg; - break; - case UM_ARG_DUMP_PERIOD_S: - ctx->dump_period_s = atoi(optarg); - break; - case UM_ARG_NO_SKIP_SYS: - ctx->skip_sys = false; - break; - case UM_ARG_NO_PROMISC: - ctx->promisc = false; - break; - case UM_ARG_HELP: - default: - um_print_help(); - return -1; + case UM_ARG_INTERFACE: + ctx->interface = optarg; + break; + case UM_ARG_DUMP_PERIOD_S: + ctx->dump_period_s = atoi(optarg); + break; + case UM_ARG_NO_SKIP_SYS: + ctx->skip_sys = false; + break; + case UM_ARG_NO_PROMISC: + ctx->promisc = false; + break; + case UM_ARG_HELP: + default: + um_print_help(); + return -1; } } return 0; } -static int udp_hdr_list_dump(struct udp_monitor_ctx* ctx, bool clear, bool skip_sys, - double dump_period_s) { - struct udp_detect_list* list = &ctx->detect; - struct udp_detect_entry* entry; +static int udp_hdr_list_dump(struct udp_monitor_ctx *ctx, bool clear, + bool skip_sys, double dump_period_s) { + struct udp_detect_list *list = &ctx->detect; + struct udp_detect_entry *entry; TAILQ_FOREACH(entry, list, next) { - if (!entry->pkt_cnt) continue; - if (skip_sys && entry->sys) continue; + if (!entry->pkt_cnt) + continue; + if (skip_sys && entry->sys) + continue; - uint8_t* dip = (uint8_t*)&entry->tuple.dst_ip; - uint8_t* sip = (uint8_t*)&entry->tuple.src_ip; + uint8_t *dip = (uint8_t *)&entry->tuple.dst_ip; + uint8_t *sip = (uint8_t *)&entry->tuple.src_ip; double rate_m = (double)entry->tx_bytes * 8 / dump_period_s / (1000 * 1000); - info("%u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, %f Mb/s pkts %u\n", sip[0], sip[1], sip[2], - sip[3], ntohs(entry->tuple.src_port), dip[0], dip[1], dip[2], dip[3], - ntohs(entry->tuple.dst_port), rate_m, entry->pkt_cnt); + info("%u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, %f Mb/s pkts %u\n", sip[0], sip[1], + sip[2], sip[3], ntohs(entry->tuple.src_port), dip[0], dip[1], dip[2], + dip[3], ntohs(entry->tuple.dst_port), rate_m, entry->pkt_cnt); if (clear) { entry->pkt_cnt = 0; entry->tx_bytes = 0; @@ -148,17 +152,17 @@ static int udp_hdr_list_dump(struct udp_monitor_ctx* ctx, bool clear, bool skip_ return 0; } -static int udp_hdr_entry_handler(void* pri, void* data, size_t data_sz) { - struct udp_monitor_ctx* ctx = pri; - const struct udp_pkt_entry* e = data; - struct udp_detect_list* list = &ctx->detect; - struct udp_detect_entry* entry; +static int udp_hdr_entry_handler(void *pri, void *data, size_t data_sz) { + struct udp_monitor_ctx *ctx = pri; + const struct udp_pkt_entry *e = data; + struct udp_detect_list *list = &ctx->detect; + struct udp_detect_entry *entry; - uint8_t* dip = (uint8_t*)&e->tuple.dst_ip; - uint8_t* sip = (uint8_t*)&e->tuple.src_ip; - dbg("%s, %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", __func__, sip[0], sip[1], sip[2], - sip[3], ntohs(e->tuple.src_port), dip[0], dip[1], dip[2], dip[3], - ntohs(e->tuple.dst_port), e->len); + uint8_t *dip = (uint8_t *)&e->tuple.dst_ip; + uint8_t *sip = (uint8_t *)&e->tuple.src_ip; + dbg("%s, %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", __func__, sip[0], + sip[1], sip[2], sip[3], ntohs(e->tuple.src_port), dip[0], dip[1], dip[2], + dip[3], ntohs(e->tuple.dst_port), e->len); /* check if any exist */ TAILQ_FOREACH(entry, list, next) { @@ -178,24 +182,27 @@ static int udp_hdr_entry_handler(void* pri, void* data, size_t data_sz) { entry->pkt_cnt++; entry->tx_bytes += e->len; /* 224.0.1.129 */ - if (dip[0] == 224 && dip[1] == 0 && dip[2] == 1 && dip[3] == 129) entry->sys = true; + if (dip[0] == 224 && dip[1] == 0 && dip[2] == 1 && dip[3] == 129) + entry->sys = true; /* 255.255.255.255 */ - if (dip[0] == 255 && dip[1] == 255 && dip[2] == 255 && dip[3] == 255) entry->sys = true; + if (dip[0] == 255 && dip[1] == 255 && dip[2] == 255 && dip[3] == 255) + entry->sys = true; /* add to list */ TAILQ_INSERT_TAIL(list, entry, next); - info("%s, new detected stream: %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", __func__, - sip[0], sip[1], sip[2], sip[3], ntohs(e->tuple.src_port), dip[0], dip[1], dip[2], - dip[3], ntohs(e->tuple.dst_port), e->len); + info("%s, new detected stream: %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", + __func__, sip[0], sip[1], sip[2], sip[3], ntohs(e->tuple.src_port), + dip[0], dip[1], dip[2], dip[3], ntohs(e->tuple.dst_port), e->len); return 0; } -static int open_raw_sock(const char* if_name) { +static int open_raw_sock(const char *if_name) { struct sockaddr_ll sll; int fd; int ret; - fd = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, htons(ETH_P_ALL)); + fd = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, + htons(ETH_P_ALL)); if (fd < 0) { err("%s, failed to create raw socket\n", __func__); return -1; @@ -205,9 +212,10 @@ static int open_raw_sock(const char* if_name) { sll.sll_family = AF_PACKET; sll.sll_ifindex = if_nametoindex(if_name); sll.sll_protocol = htons(ETH_P_ALL); - ret = bind(fd, (struct sockaddr*)&sll, sizeof(sll)); + ret = bind(fd, (struct sockaddr *)&sll, sizeof(sll)); if (ret < 0) { - err("%s, failed to bind to %s: %d, %s\n", __func__, if_name, ret, strerror(errno)); + err("%s, failed to bind to %s: %d, %s\n", __func__, if_name, ret, + strerror(errno)); close(fd); return ret; } @@ -215,7 +223,7 @@ static int open_raw_sock(const char* if_name) { return fd; } -static int enable_promisc(int sock, const char* if_name, int enable) { +static int enable_promisc(int sock, const char *if_name, int enable) { struct ifreq ifr; int ret; @@ -248,21 +256,21 @@ static void um_sig_handler(int signo) { info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - g_um_stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + g_um_stop = true; + break; } return; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct udp_monitor_ctx ctx; int ret; int sock_raw_fd = -1; int sock_fd = -1; - struct udp_monitor_bpf* skel = NULL; - struct ring_buffer* rb = NULL; + struct udp_monitor_bpf *skel = NULL; + struct ring_buffer *rb = NULL; int prog_fd = -1; uint64_t last_ns, cur_ns, ns_diff; @@ -272,7 +280,8 @@ int main(int argc, char** argv) { ctx.promisc = true; ret = um_parse_args(&ctx, argc, argv); - if (ret < 0) return ret; + if (ret < 0) + return ret; if (!ctx.interface) { err("%s, no interface assigned\n", __func__); um_print_help(); @@ -315,27 +324,28 @@ int main(int argc, char** argv) { /* Attach BPF program to raw socket */ prog_fd = bpf_program__fd(skel->progs.bpf_socket_handler); - ret = setsockopt(sock_raw_fd, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd, sizeof(prog_fd)); + ret = setsockopt(sock_raw_fd, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd, + sizeof(prog_fd)); if (ret < 0) { err("%s, failed attach to raw socket %d\n", __func__, ret); goto exit; } - info("%s, attach bpf skeleton to %s succ, sock_raw_fd %d\n", __func__, ctx.interface, - sock_raw_fd); + info("%s, attach bpf skeleton to %s succ, sock_raw_fd %d\n", __func__, + ctx.interface, sock_raw_fd); if (ctx.promisc) { ret = enable_promisc(sock_fd, ctx.interface, 1); if (ret < 0) { err("%s, failed to enable promisc %d\n", __func__, ret); goto exit; } - info("%s, enable promisc for %s succ, sock_fd %d\n", __func__, ctx.interface, - sock_fd); + info("%s, enable promisc for %s succ, sock_fd %d\n", __func__, + ctx.interface, sock_fd); } signal(SIGINT, um_sig_handler); - info("%s, start to poll udp pkts for %s, dump period %ds\n", __func__, ctx.interface, - ctx.dump_period_s); + info("%s, start to poll udp pkts for %s, dump period %ds\n", __func__, + ctx.interface, ctx.dump_period_s); last_ns = um_get_monotonic_time(); while (!g_um_stop) { ret = ring_buffer__poll(rb, 100); @@ -360,16 +370,21 @@ int main(int argc, char** argv) { } info("%s, stop now\n", __func__); - if (sock_fd >= 0) enable_promisc(sock_fd, ctx.interface, 0); + if (sock_fd >= 0) + enable_promisc(sock_fd, ctx.interface, 0); exit: - if (rb) ring_buffer__free(rb); - if (skel) udp_monitor_bpf__destroy(skel); - if (sock_fd >= 0) close(sock_fd); - if (sock_raw_fd >= 0) close(sock_raw_fd); + if (rb) + ring_buffer__free(rb); + if (skel) + udp_monitor_bpf__destroy(skel); + if (sock_fd >= 0) + close(sock_fd); + if (sock_raw_fd >= 0) + close(sock_raw_fd); /* free all entries in list */ - struct udp_detect_entry* entry; + struct udp_detect_entry *entry; while ((entry = TAILQ_FIRST(&ctx.detect))) { TAILQ_REMOVE(&ctx.detect, entry, next); free(entry); diff --git a/tools/readpcap/readpcap.c b/tools/readpcap/readpcap.c index d283339b0..5a840364f 100644 --- a/tools/readpcap/readpcap.c +++ b/tools/readpcap/readpcap.c @@ -16,9 +16,9 @@ #include #define NS_PER_S 1000000000 -#define TR_OFFSET_NS (500 * 1000) // 500us +#define TR_OFFSET_NS (500 * 1000) // 500us -static inline uint64_t TimespecToNs(const struct timeval* ts) { +static inline uint64_t TimespecToNs(const struct timeval *ts) { return ((uint64_t)ts->tv_sec * NS_PER_S) + ts->tv_usec; } @@ -28,8 +28,8 @@ static uint64_t last_tn = 0; static uint64_t frame_tn = 0; static int g_target_frame_idx = -2; -void packetHandler(u_char* userData, const struct pcap_pkthdr* pkthdr, - const u_char* packet) { +void packetHandler(u_char *userData, const struct pcap_pkthdr *pkthdr, + const u_char *packet) { uint64_t tn = TimespecToNs(&pkthdr->ts); if (last_tn) { if ((tn - last_tn) > TR_OFFSET_NS) { @@ -46,8 +46,8 @@ void packetHandler(u_char* userData, const struct pcap_pkthdr* pkthdr, last_tn = tn; } -int main(int argc, char** argv) { - pcap_t* fp; +int main(int argc, char **argv) { + pcap_t *fp; char errbuf[PCAP_ERRBUF_SIZE]; char source[1500]; int i, maxCountSyn = 0, maxCountHttp = 0, maxIdxSyn = 0, maxIdxHttp = 0; @@ -62,8 +62,8 @@ int main(int argc, char** argv) { printf("target_frame %d\n", g_target_frame_idx); } - fp = pcap_open_offline_with_tstamp_precision(argv[1], PCAP_TSTAMP_PRECISION_NANO, - errbuf); + fp = pcap_open_offline_with_tstamp_precision( + argv[1], PCAP_TSTAMP_PRECISION_NANO, errbuf); if (fp == NULL) { fprintf(stderr, "pcap_open_offline() failed: %s\n", errbuf); return 0; diff --git a/tools/readpcap/readpcap_31.c b/tools/readpcap/readpcap_31.c index 34e3906b6..30ebb513e 100644 --- a/tools/readpcap/readpcap_31.c +++ b/tools/readpcap/readpcap_31.c @@ -65,18 +65,19 @@ struct aes3_le { typedef struct aes3_le aes3_t; struct user_data { - uint8_t* cursor; - uint8_t* begin; - uint8_t* end; + uint8_t *cursor; + uint8_t *begin; + uint8_t *end; }; static int g_pkt_idx = 0; -void packetHandler(uint8_t* userData, const struct pcap_pkthdr* pkthdr, - const uint8_t* packet) { - struct user_data* ud = (struct user_data*)userData; - uint8_t* payload = packet + sizeof(struct ether_header) + sizeof(struct iphdr) + - sizeof(struct udphdr) + RFC3550_RTP_HDR_LEN; +void packetHandler(uint8_t *userData, const struct pcap_pkthdr *pkthdr, + const uint8_t *packet) { + struct user_data *ud = (struct user_data *)userData; + uint8_t *payload = packet + sizeof(struct ether_header) + + sizeof(struct iphdr) + sizeof(struct udphdr) + + RFC3550_RTP_HDR_LEN; uint16_t payload_len = pkthdr->len - sizeof(struct ether_header) - sizeof(struct iphdr) - sizeof(struct udphdr) - RFC3550_RTP_HDR_LEN; @@ -85,19 +86,20 @@ void packetHandler(uint8_t* userData, const struct pcap_pkthdr* pkthdr, return; } int num_subframes = payload_len / 4; - int sample_per_packet = 48; // 48khz, 1ms packet time + int sample_per_packet = 48; // 48khz, 1ms packet time int num_channels = num_subframes / sample_per_packet; - printf("pkt %d, %d subframes of %d channels\n", g_pkt_idx, num_subframes, num_channels); - am824_t* am = (am824_t*)payload; + printf("pkt %d, %d subframes of %d channels\n", g_pkt_idx, num_subframes, + num_channels); + am824_t *am = (am824_t *)payload; for (int i = 0; i < num_subframes; i++) { - uint32_t am_32 = *(uint32_t*)am; - printf("pkt %d, subframe %d, hex: %08x, channel bit: %u\n", g_pkt_idx, i, am_32, - am->c); + uint32_t am_32 = *(uint32_t *)am; + printf("pkt %d, subframe %d, hex: %08x, channel bit: %u\n", g_pkt_idx, i, + am_32, am->c); if (am->f) { printf("pkt %d, subframe %d, first subframe of frame\n", g_pkt_idx, i); if (am->b) { - printf("pkt %d, subframe %d, first subframe of block %08x\n", g_pkt_idx, i, - am_32); + printf("pkt %d, subframe %d, first subframe of block %08x\n", g_pkt_idx, + i, am_32); } } @@ -114,8 +116,8 @@ void packetHandler(uint8_t* userData, const struct pcap_pkthdr* pkthdr, g_pkt_idx++; } -int main(int argc, char** argv) { - pcap_t* fp; +int main(int argc, char **argv) { + pcap_t *fp; int fd; char errbuf[PCAP_ERRBUF_SIZE]; @@ -140,7 +142,7 @@ int main(int argc, char** argv) { struct user_data ud; - uint8_t* m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + uint8_t *m = mmap(NULL, f_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (MAP_FAILED == m) { printf("mmap fail\n"); close(fd); diff --git a/tools/sch_smi_emulate/sch_smi_emulate.c b/tools/sch_smi_emulate/sch_smi_emulate.c index a41ffa528..85a2dba69 100644 --- a/tools/sch_smi_emulate/sch_smi_emulate.c +++ b/tools/sch_smi_emulate/sch_smi_emulate.c @@ -31,29 +31,30 @@ static struct option se_args_options[] = { {0, 0, 0, 0}}; -static int se_parse_args(struct se_context* ctx, int argc, char** argv) { +static int se_parse_args(struct se_context *ctx, int argc, char **argv) { int cmd = -1, opt_idx = 0; while (1) { cmd = getopt_long_only(argc, argv, "hv", se_args_options, &opt_idx); - if (cmd == -1) break; + if (cmd == -1) + break; switch (cmd) { - case SE_ARG_SLEEP_MS: - ctx->sleep_time_ms = atoi(optarg); - break; - case SE_ARG_WORK_US: - ctx->work_time_us = atoi(optarg); - break; - default: - break; + case SE_ARG_SLEEP_MS: + ctx->sleep_time_ms = atoi(optarg); + break; + case SE_ARG_WORK_US: + ctx->work_time_us = atoi(optarg); + break; + default: + break; } }; return 0; } -static int se_init(struct se_context* ctx) { +static int se_init(struct se_context *ctx) { ctx->sleep_time_ms = 100; ctx->work_time_us = 100; return 0; @@ -66,11 +67,12 @@ static inline uint64_t se_get_monotonic_time() { return ((uint64_t)ts.tv_sec * NS_PER_S) + ts.tv_nsec; } -static int se_loop(struct se_context* ctx) { +static int se_loop(struct se_context *ctx) { uint64_t start, end; volatile int sum; - printf("sleep_time_ms %d work_time_us %d\n", ctx->sleep_time_ms, ctx->work_time_us); + printf("sleep_time_ms %d work_time_us %d\n", ctx->sleep_time_ms, + ctx->work_time_us); while (1) { usleep(ctx->sleep_time_ms * 1000); @@ -86,7 +88,7 @@ static int se_loop(struct se_context* ctx) { return 0; } -int main(int argc, char** argv) { +int main(int argc, char **argv) { struct se_context ctx; se_init(&ctx); From bc55cadb8b44992a3ff0d69e89db2b3347c840cb Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 12:16:29 +0000 Subject: [PATCH 29/35] update format-coding.sh --- .github/linters/.clang-format | 9 +++------ format-coding.sh | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/linters/.clang-format b/.github/linters/.clang-format index 47fef013c..cce0ab3f3 100644 --- a/.github/linters/.clang-format +++ b/.github/linters/.clang-format @@ -1,6 +1,3 @@ -# SPDX-License-Identifier: GPL-2.0 ---- -BasedOnStyle: Google -DerivePointerAlignment: false -ColumnLimit: 90 -AllowShortFunctionsOnASingleLine: None +#SPDX - License - Identifier : GPL - 2.0 +-- -BasedOnStyle : Google DerivePointerAlignment + : false ColumnLimit : 90 AllowShortFunctionsOnASingleLine : None diff --git a/format-coding.sh b/format-coding.sh index 5bd835585..5f3b51def 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -10,7 +10,7 @@ set -e echo "clang-format check" find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' \ - ! -name 'vmlinux.h' -exec clang-format --style=file ".github/linters/clang-format.yaml" --verbose -i {} + + ! -name 'vmlinux.h' -exec clang-format -i --style=file ".github/linters/.clang-format" --verbose {} + # CONFIG=".github/linters/.pyproject.toml" # black --config "$CONFIG" python/ From 27538e632b4d2d2f366dd7590fcd51474a47a516 Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 16:26:28 +0000 Subject: [PATCH 30/35] reformat .clang-format config file --- .github/linters/.clang-format | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/linters/.clang-format b/.github/linters/.clang-format index cce0ab3f3..f9bce2573 100644 --- a/.github/linters/.clang-format +++ b/.github/linters/.clang-format @@ -1,3 +1,9 @@ -#SPDX - License - Identifier : GPL - 2.0 --- -BasedOnStyle : Google DerivePointerAlignment - : false ColumnLimit : 90 AllowShortFunctionsOnASingleLine : None +# SPDX-License-Identifier: GPL-2.0 +BasedOnStyle: Google +DerivePointerAlignment: false +ColumnLimit: 90 +AllowShortFunctionsOnASingleLine: None +WarningsAsErrors: [] +CheckOptions: + - key: cppcoreguidelines-pro-type-cstyle-cast + value: false \ No newline at end of file From 82b57d382a3aef0bcff3c6fbf3b36bca2be143b1 Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 16:38:55 +0000 Subject: [PATCH 31/35] fix clang format syntax --- .github/linters/.clang-format | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/linters/.clang-format b/.github/linters/.clang-format index f9bce2573..172d23484 100644 --- a/.github/linters/.clang-format +++ b/.github/linters/.clang-format @@ -3,7 +3,4 @@ BasedOnStyle: Google DerivePointerAlignment: false ColumnLimit: 90 AllowShortFunctionsOnASingleLine: None -WarningsAsErrors: [] -CheckOptions: - - key: cppcoreguidelines-pro-type-cstyle-cast - value: false \ No newline at end of file +PointerAlignment: Right \ No newline at end of file From 438516d4b92202984e540d5b7f0f201163968252 Mon Sep 17 00:00:00 2001 From: zLukas Date: Mon, 24 Feb 2025 16:57:39 +0000 Subject: [PATCH 32/35] propper clang config file handling in clang formatter --- app/perf/p10le_to_rfc4175_422be10.c | 97 +- app/perf/perf_dma.c | 21 +- app/perf/rfc4175_422be10_to_le.c | 49 +- app/perf/rfc4175_422be10_to_le8.c | 49 +- app/perf/rfc4175_422be10_to_p10le.c | 97 +- app/perf/rfc4175_422be10_to_p8.c | 24 +- app/perf/rfc4175_422be10_to_v210.c | 103 +- app/perf/rfc4175_422be10_to_y210.c | 52 +- app/perf/rfc4175_422be12_to_le.c | 33 +- app/perf/rfc4175_422be12_to_p12le.c | 97 +- app/perf/rfc4175_422le10_to_be.c | 53 +- app/perf/v210_to_rfc4175_422be10.c | 62 +- app/perf/y210_to_rfc4175_422be10.c | 41 +- app/sample/dma/dma_sample.c | 28 +- .../rx_st20_redundant_combined_sample.c | 48 +- .../rx_st20_pipeline_dyn_ext_frame_sample.c | 46 +- .../ext_frame/rx_st20p_hdr_split_gpu_direct.c | 69 +- .../tx_st20_pipeline_ext_frame_sample.c | 54 +- app/sample/ext_frame/tx_video_split_sample.c | 29 +- app/sample/fwd/rx_st20_tx_st20_split_fwd.c | 36 +- .../fwd/rx_st20p_tx_st20p_downsample_fwd.c | 22 +- .../rx_st20p_tx_st20p_downsample_merge_fwd.c | 24 +- app/sample/fwd/rx_st20p_tx_st20p_fwd.c | 47 +- app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c | 21 +- app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c | 21 +- app/sample/fwd/rx_st20p_tx_st22p_fwd.c | 32 +- app/sample/legacy/rx_st20_tx_st20_fwd.c | 62 +- app/sample/legacy/rx_st22_video_sample.c | 49 +- app/sample/legacy/rx_video_sample.c | 66 +- app/sample/legacy/tx_st22_video_sample.c | 42 +- app/sample/legacy/tx_video_sample.c | 55 +- app/sample/low_level/rx_rtp_video_sample.c | 26 +- app/sample/low_level/rx_slice_video_sample.c | 44 +- app/sample/low_level/tx_rtp_video_sample.c | 28 +- app/sample/low_level/tx_slice_video_sample.c | 52 +- app/sample/msvc/imtl_sample/imtl_sample.cpp | 15 +- app/sample/rdma/rdma_rx.c | 9 +- app/sample/rdma/rdma_tx.c | 13 +- app/sample/rdma/rdma_video_rx.c | 29 +- app/sample/rdma/rdma_video_rx_multi.c | 38 +- app/sample/rdma/rdma_video_tx.c | 17 +- app/sample/rdma/rdma_video_tx_multi.c | 26 +- app/sample/rx_st20_pipeline_sample.c | 34 +- app/sample/rx_st20p_auto_detect_sample.c | 37 +- app/sample/rx_st20p_timing_parser_sample.c | 64 +- app/sample/rx_st22_pipeline_sample.c | 30 +- app/sample/rx_st30_pipeline_sample.c | 39 +- app/sample/sample_util.c | 632 +++--- app/sample/sample_util.h | 38 +- app/sample/tx_st20_pipeline_sample.c | 50 +- app/sample/tx_st22_pipeline_sample.c | 35 +- app/sample/tx_st30_pipeline_sample.c | 53 +- app/src/app_base.h | 24 +- app/src/app_platform.h | 7 +- app/src/args.c | 1013 +++++----- app/src/args.h | 4 +- app/src/experimental/rx_st20r_app.c | 130 +- app/src/fmt.c | 9 +- app/src/fmt.h | 3 +- app/src/legacy/rx_audio_app.c | 138 +- app/src/legacy/rx_st22_app.c | 56 +- app/src/legacy/rx_video_app.c | 218 +- app/src/legacy/tx_audio_app.c | 119 +- app/src/legacy/tx_st22_app.c | 62 +- app/src/legacy/tx_video_app.c | 215 +- app/src/log.h | 45 +- app/src/parse_json.c | 956 ++++----- app/src/player.c | 25 +- app/src/player.h | 4 +- app/src/rx_ancillary_app.c | 101 +- app/src/rx_st20p_app.c | 121 +- app/src/rx_st22p_app.c | 87 +- app/src/rx_st30p_app.c | 75 +- app/src/rxtx_app.c | 111 +- app/src/tx_ancillary_app.c | 131 +- app/src/tx_st20p_app.c | 92 +- app/src/tx_st22p_app.c | 62 +- app/src/tx_st30p_app.c | 56 +- app/tools/convert_app.c | 114 +- app/tools/convert_app_args.c | 61 +- app/tools/convert_app_base.h | 7 +- app/tools/lcore_shmem_mgr.c | 66 +- app/tools/log.h | 22 +- app/udp/udp_client_sample.c | 53 +- app/udp/udp_server_sample.c | 55 +- app/udp/ufd_client_sample.c | 59 +- app/udp/ufd_server_sample.c | 64 +- app/udp/usocket_client_sample.c | 40 +- app/udp/usocket_server_sample.c | 60 +- app/v4l2_to_ip/v4l2_to_ip.c | 546 +++-- ecosystem/ffmpeg_plugin/mtl_common.c | 55 +- ecosystem/ffmpeg_plugin/mtl_common.h | 137 +- ecosystem/ffmpeg_plugin/mtl_st20p_rx.c | 53 +- ecosystem/ffmpeg_plugin/mtl_st20p_tx.c | 37 +- ecosystem/ffmpeg_plugin/mtl_st22p_rx.c | 73 +- ecosystem/ffmpeg_plugin/mtl_st22p_tx.c | 60 +- ecosystem/ffmpeg_plugin/mtl_st30p_rx.c | 26 +- ecosystem/ffmpeg_plugin/mtl_st30p_tx.c | 26 +- ecosystem/obs_mtl/linux-mtl/linux-mtl.c | 52 +- ecosystem/obs_mtl/linux-mtl/linux-mtl.h | 2 +- ecosystem/obs_mtl/linux-mtl/mtl-input.c | 141 +- ecosystem/obs_mtl/linux-mtl/mtl-output.c | 48 +- format-coding.sh | 8 +- include/experimental/st20_combined_api.h | 12 +- include/mtl_api.h | 56 +- include/mtl_lcore_shm_api.h | 3 +- include/mtl_sch_api.h | 5 +- include/mudp_api.h | 12 +- include/mudp_sockfd_api.h | 12 +- include/mudp_win.h | 10 +- include/st20_api.h | 46 +- include/st30_api.h | 11 +- include/st30_pipeline_api.h | 3 +- include/st40_api.h | 8 +- include/st_api.h | 26 +- include/st_convert_api.h | 364 ++-- include/st_convert_internal.h | 413 ++-- include/st_pipeline_api.h | 113 +- ld_preload/preload_platform.h | 4 +- ld_preload/udp/udp_preload.c | 356 ++-- ld_preload/udp/udp_preload.h | 68 +- lib/src/datapath/mt_dp_socket.c | 151 +- lib/src/datapath/mt_dp_socket.h | 14 +- lib/src/datapath/mt_queue.c | 112 +- lib/src/datapath/mt_queue.h | 7 +- lib/src/datapath/mt_shared_queue.c | 135 +- lib/src/datapath/mt_shared_queue.h | 6 +- lib/src/datapath/mt_shared_rss.c | 118 +- lib/src/datapath/mt_shared_rss.h | 10 +- lib/src/dev/mt_af_xdp.c | 179 +- lib/src/dev/mt_af_xdp.h | 31 +- lib/src/dev/mt_dev.c | 483 ++--- lib/src/dev/mt_dev.h | 22 +- lib/src/dev/mt_rdma_ud.c | 347 ++-- lib/src/dev/mt_rdma_ud.h | 31 +- lib/src/mt_admin.c | 76 +- lib/src/mt_arp.c | 125 +- lib/src/mt_arp.h | 6 +- lib/src/mt_cni.c | 181 +- lib/src/mt_config.c | 24 +- lib/src/mt_dhcp.c | 62 +- lib/src/mt_dma.c | 108 +- lib/src/mt_dma.h | 9 +- lib/src/mt_flow.c | 68 +- lib/src/mt_flow.h | 5 +- lib/src/mt_instance.c | 40 +- lib/src/mt_instance.h | 8 +- lib/src/mt_log.c | 64 +- lib/src/mt_log.h | 110 +- lib/src/mt_main.c | 177 +- lib/src/mt_main.h | 134 +- lib/src/mt_mcast.c | 199 +- lib/src/mt_mcast.h | 8 +- lib/src/mt_mem.h | 15 +- lib/src/mt_pcap.c | 16 +- lib/src/mt_pcap.h | 16 +- lib/src/mt_platform.h | 8 +- lib/src/mt_ptp.c | 511 ++--- lib/src/mt_ptp.h | 9 +- lib/src/mt_quirk.h | 6 +- lib/src/mt_rtcp.c | 117 +- lib/src/mt_rtcp.h | 27 +- lib/src/mt_sch.c | 286 ++- lib/src/mt_sch.h | 18 +- lib/src/mt_simd.h | 14 +- lib/src/mt_socket.c | 73 +- lib/src/mt_socket.h | 11 +- lib/src/mt_stat.c | 16 +- lib/src/mt_stat.h | 3 +- lib/src/mt_tap.c | 285 ++- lib/src/mt_tap.h | 7 +- lib/src/mt_usdt.h | 229 +-- lib/src/mt_util.c | 276 +-- lib/src/mt_util.h | 107 +- .../experimental/st20_redundant_combined_rx.c | 65 +- lib/src/st2110/pipeline/st20_pipeline_rx.c | 301 ++- lib/src/st2110/pipeline/st20_pipeline_tx.c | 170 +- lib/src/st2110/pipeline/st22_pipeline_rx.c | 152 +- lib/src/st2110/pipeline/st22_pipeline_tx.c | 187 +- lib/src/st2110/pipeline/st30_pipeline_rx.c | 101 +- lib/src/st2110/pipeline/st30_pipeline_tx.c | 94 +- lib/src/st2110/pipeline/st_plugin.c | 280 +-- lib/src/st2110/pipeline/st_plugin.h | 18 +- lib/src/st2110/st_ancillary.c | 188 +- lib/src/st2110/st_ancillary_transmitter.c | 19 +- lib/src/st2110/st_ancillary_transmitter.h | 3 +- lib/src/st2110/st_audio_transmitter.c | 18 +- lib/src/st2110/st_audio_transmitter.h | 6 +- lib/src/st2110/st_avx2.c | 24 +- lib/src/st2110/st_avx2.h | 12 +- lib/src/st2110/st_avx512.c | 745 +++---- lib/src/st2110/st_avx512.h | 172 +- lib/src/st2110/st_avx512_vbmi.c | 700 +++---- lib/src/st2110/st_avx512_vbmi.h | 75 +- lib/src/st2110/st_convert.c | 863 ++++---- lib/src/st2110/st_fmt.c | 632 +++--- lib/src/st2110/st_fmt.h | 19 +- lib/src/st2110/st_header.h | 67 +- lib/src/st2110/st_main.h | 4 +- lib/src/st2110/st_pkt.h | 10 +- lib/src/st2110/st_rx_ancillary_session.c | 270 +-- lib/src/st2110/st_rx_audio_session.c | 333 ++-- lib/src/st2110/st_rx_timing_parser.c | 186 +- lib/src/st2110/st_rx_timing_parser.h | 14 +- lib/src/st2110/st_rx_video_session.c | 1277 +++++------- lib/src/st2110/st_rx_video_session.h | 62 +- lib/src/st2110/st_tx_ancillary_session.c | 599 +++--- lib/src/st2110/st_tx_audio_session.c | 622 +++--- lib/src/st2110/st_tx_video_session.c | 1036 ++++------ lib/src/st2110/st_tx_video_session.h | 50 +- lib/src/st2110/st_video_transmitter.c | 152 +- lib/src/st2110/st_video_transmitter.h | 9 +- lib/src/udp/udp_main.c | 421 ++-- lib/src/udp/udp_main.h | 8 +- lib/src/udp/udp_rxq.c | 60 +- lib/src/udp/udp_rxq.h | 6 +- lib/src/udp/ufd_main.c | 67 +- lib/windows/win_posix.c | 54 +- lib/windows/win_posix.h | 9 +- manager/logging.hpp | 35 +- manager/mtl.xdp.c | 15 +- manager/mtl_instance.hpp | 152 +- manager/mtl_interface.hpp | 53 +- manager/mtl_lcore.hpp | 17 +- manager/mtl_manager.cpp | 50 +- plugins/log.h | 28 +- plugins/plugin_platform.h | 7 +- plugins/sample/convert_plugin_sample.c | 59 +- plugins/sample/st22_plugin_sample.c | 52 +- plugins/st22_avcodec/st22_avcodec_plugin.c | 96 +- rdma/mt_rdma.c | 4 +- rdma/mt_rdma.h | 65 +- rdma/mt_rdma_rx.c | 240 ++- rdma/mt_rdma_tx.c | 320 ++- rdma/mtl_rdma_api.h | 12 +- tests/src/cvt_test.cpp | 1760 +++++++---------- tests/src/dma_test.cpp | 71 +- tests/src/log.h | 28 +- tests/src/sch_test.cpp | 6 +- tests/src/st20_test.cpp | 1303 ++++++------ tests/src/st20p_test.cpp | 402 ++-- tests/src/st22_test.cpp | 400 ++-- tests/src/st22p_test.cpp | 344 ++-- tests/src/st30_test.cpp | 380 ++-- tests/src/st30p_test.cpp | 155 +- tests/src/st40_test.cpp | 265 ++- tests/src/st_test.cpp | 148 +- tests/src/test_platform.h | 7 +- tests/src/test_util.cpp | 6 +- tests/src/test_util.h | 10 +- tests/src/tests.cpp | 415 ++-- tests/src/tests.h | 907 +++++---- tests/src/ufd_loop_test.cpp | 71 +- tests/src/ufd_test.cpp | 192 +- tests/src/upl_loop_test.cpp | 113 +- tests/src/upl_test.cpp | 66 +- tests/src/upl_test.h | 6 +- tools/ebpf/et.c | 94 +- tools/ebpf/fentry.bpf.c | 6 +- tools/ebpf/lcore_monitor.bpf.c | 30 +- tools/ebpf/lcore_monitor.c | 76 +- tools/ebpf/log.h | 28 +- tools/ebpf/udp_monitor.bpf.c | 12 +- tools/ebpf/udp_monitor.c | 117 +- tools/readpcap/readpcap.c | 6 +- tools/readpcap/readpcap_31.c | 18 +- tools/sch_smi_emulate/sch_smi_emulate.c | 22 +- 267 files changed, 14269 insertions(+), 19749 deletions(-) diff --git a/app/perf/p10le_to_rfc4175_422be10.c b/app/perf/p10le_to_rfc4175_422be10.c index cfcb92d01..599f7de53 100644 --- a/app/perf/p10le_to_rfc4175_422be10.c +++ b/app/perf/p10le_to_rfc4175_422be10.c @@ -12,8 +12,7 @@ #include "../sample/sample_util.h" -static void fill_422_planar_le(uint16_t *y, uint16_t *b, uint16_t *r, int w, - int h) { +static void fill_422_planar_le(uint16_t *y, uint16_t *b, uint16_t *r, int w, int h) { int pg_size = w * h / 2; for (int pg = 0; pg < pg_size; pg++) { @@ -24,16 +23,15 @@ static void fill_422_planar_le(uint16_t *y, uint16_t *b, uint16_t *r, int w, } } -static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, - int frames, int fb_cnt) { +static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = (struct st20_rfc4175_422_10_pg2_be *)malloc(fb_pg2_size * fb_cnt); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); float planar_size_m = (float)planar_size / 1024 / 1024; - uint16_t *p10_u16 = - (uint16_t *)mtl_hp_malloc(st, planar_size * fb_cnt, MTL_PORT_P); + uint16_t *p10_u16 = (uint16_t *)mtl_hp_malloc(st, planar_size * fb_cnt, MTL_PORT_P); uint16_t *p10_u16_b = p10_u16 + w * h; uint16_t *p10_u16_r = p10_u16 + w * h * 3 / 2; mtl_iova_t p10_u16_y_iova = mtl_hp_virt2iova(st, p10_u16); @@ -49,10 +47,8 @@ static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, for (int i = 0; i < fb_cnt; i++) { p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); fill_422_planar_le(p10_u16_in, p10_u16_b_in, p10_u16_r_in, w, h); } @@ -63,58 +59,49 @@ static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, - p10_u16_r_in, pg_be_out, w, h, - MTL_SIMD_LEVEL_NONE); + p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, p10_u16_r_in, + pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, - p10_u16_r_in, pg_be_out, w, h, - MTL_SIMD_LEVEL_AVX512); + p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, p10_u16_r_in, + pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); p10_u16_y_in_iova = p10_u16_y_iova + (i % fb_cnt) * (planar_size); p10_u16_b_in_iova = p10_u16_b_iova + (i % fb_cnt) * (planar_size); p10_u16_r_in_iova = p10_u16_r_iova + (i % fb_cnt) * (planar_size); st20_yuv422p10le_to_rfc4175_422be10_simd_dma( dma, p10_u16_in, p10_u16_y_in_iova, p10_u16_b_in, p10_u16_b_in_iova, - p10_u16_r_in, p10_u16_r_in_iova, pg_be_out, w, h, - MTL_SIMD_LEVEL_AVX512); + p10_u16_r_in, p10_u16_r_in_iova, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512+dma, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512+dma, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512+dma, %fx performance to scalar\n", duration / duration_simd); } } @@ -124,28 +111,24 @@ static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, - p10_u16_r_in, pg_be_out, w, h, + p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16_in, p10_u16_b_in, p10_u16_r_in, + pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_in = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_in = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_in = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_in = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_in = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); p10_u16_y_in_iova = p10_u16_y_iova + (i % fb_cnt) * (planar_size); p10_u16_b_in_iova = p10_u16_b_iova + (i % fb_cnt) * (planar_size); p10_u16_r_in_iova = p10_u16_r_iova + (i % fb_cnt) * (planar_size); @@ -158,15 +141,13 @@ static int perf_cvt_planar_le_to_422_10_pg2(mtl_handle st, int w, int h, float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("avx512_vbmi+dma, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("avx512_vbmi+dma, %fx performance to scalar\n", - duration / duration_simd); + info("avx512_vbmi+dma, %fx performance to scalar\n", duration / duration_simd); } } free(pg_be); mtl_hp_free(st, p10_u16); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -188,10 +169,8 @@ static void *perf_thread(void *arg) { perf_cvt_planar_le_to_422_10_pg2(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 2, 1080 * 2, frames, - fb_cnt); - perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 4, 1080 * 4, frames, - fb_cnt); + perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); + perf_cvt_planar_le_to_422_10_pg2(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); mtl_put_lcore(dev_handle, lcore); @@ -204,8 +183,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -215,8 +193,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/perf_dma.c b/app/perf/perf_dma.c index 315d1006e..135abf119 100644 --- a/app/perf/perf_dma.c +++ b/app/perf/perf_dma.c @@ -10,8 +10,7 @@ static inline void rand_data(uint8_t *p, size_t sz, uint8_t base) { } } -static int dma_copy_perf(mtl_handle st, int w, int h, int frames, - int pkt_size) { +static int dma_copy_perf(mtl_handle st, int w, int h, int frames, int pkt_size) { mtl_udma_handle dma; int ret; uint16_t nb_desc = 1024; @@ -61,8 +60,8 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, } end = clock(); duration_cpu = (float)(end - start) / CLOCKS_PER_SEC; - info("cpu, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", - duration_cpu, frames, w, h, fb_size_m, pkt_size); + info("cpu, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", duration_cpu, + frames, w, h, fb_size_m, pkt_size); start = clock(); for (int idx = 0; idx < frames; idx++) { @@ -74,8 +73,8 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, } end = clock(); duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("simd, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", - duration_simd, frames, w, h, fb_size_m, pkt_size); + info("simd, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", duration_simd, + frames, w, h, fb_size_m, pkt_size); info("simd, %fx performance to cpu\n", duration_cpu / duration_simd); start = clock(); @@ -85,8 +84,7 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, while (fb_src_iova_off < fb_size) { ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, pkt_size); - if (ret < 0) - break; + if (ret < 0) break; fb_src_iova_off += pkt_size; } /* submit */ @@ -99,8 +97,8 @@ static int dma_copy_perf(mtl_handle st, int w, int h, int frames, } end = clock(); duration_dma = (float)(end - start) / CLOCKS_PER_SEC; - info("dma, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", - duration_dma, frames, w, h, fb_size_m, pkt_size); + info("dma, time: %f secs with %d frames(%dx%d,%fm), pkt_size %d\n", duration_dma, + frames, w, h, fb_size_m, pkt_size); info("dma, %fx performance to cpu\n", duration_cpu / duration_dma); info("\n"); @@ -117,8 +115,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = dma_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { diff --git a/app/perf/rfc4175_422be10_to_le.c b/app/perf/rfc4175_422be10_to_le.c index 9a53299b0..b6ddcd3ec 100644 --- a/app/perf/rfc4175_422be10_to_le.c +++ b/app/perf/rfc4175_422be10_to_le.c @@ -9,8 +9,8 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, size_t fb_pg2_size = w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( - st, fb_pg2_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, + MTL_PORT_P); struct st20_rfc4175_422_10_pg2_le *pg_le = (struct st20_rfc4175_422_10_pg2_le *)malloc(fb_pg2_size * fb_cnt); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); @@ -34,13 +34,12 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames * 1; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, - MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX2) { start = clock(); @@ -52,8 +51,8 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, + w, h, fb_cnt); info("avx2, %fx performance to scalar\n", duration / duration_simd); } @@ -67,8 +66,8 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -77,14 +76,13 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, - pg_le_out, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_le_out, + w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -99,8 +97,8 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -109,23 +107,20 @@ static int perf_cvt_422_10_pg2_be_to_le(mtl_handle st, int w, int h, int frames, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, - pg_le_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_le_out, + w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", - duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); } } mtl_hp_free(st, pg_be); free(pg_le); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -161,8 +156,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -172,8 +166,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_le8.c b/app/perf/rfc4175_422be10_to_le8.c index 8d395c784..76dcbdea1 100644 --- a/app/perf/rfc4175_422be10_to_le8.c +++ b/app/perf/rfc4175_422be10_to_le8.c @@ -4,13 +4,13 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, - int frames, int fb_cnt) { +static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg10_size = (size_t)w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_10 = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( - st, fb_pg10_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc(st, fb_pg10_size * fb_cnt, + MTL_PORT_P); mtl_iova_t pg_10_iova = mtl_hp_virt2iova(st, pg_10); mtl_iova_t pg_10_in_iova; size_t fb_pg8_size = (size_t)w * h * 2; @@ -34,13 +34,12 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_422le8_simd(pg_10_in, pg_8_out, w, h, - MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422be10_to_422le8_simd(pg_10_in, pg_8_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, fb_pg8_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, fb_pg8_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); @@ -52,8 +51,8 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -62,14 +61,13 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_10_in_iova = pg_10_iova + (i % fb_cnt) * (fb_pg10_size); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, - pg_8_out, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, pg_8_out, w, + h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -84,8 +82,8 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -94,23 +92,20 @@ static int perf_cvt_422_10_pg2_be_to_le8(mtl_handle st, int w, int h, pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_10_in_iova = pg_10_iova + (i % fb_cnt) * (fb_pg10_size); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, - pg_8_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10_in, pg_10_in_iova, pg_8_out, w, + h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", - duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); } } mtl_hp_free(st, pg_10); free(pg_8); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -146,8 +141,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -157,8 +151,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_p10le.c b/app/perf/rfc4175_422be10_to_p10le.c index f220432ac..80be6bcd8 100644 --- a/app/perf/rfc4175_422be10_to_p10le.c +++ b/app/perf/rfc4175_422be10_to_p10le.c @@ -4,13 +4,13 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, - int frames, int fb_cnt) { +static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( - st, fb_pg2_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, + MTL_PORT_P); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); @@ -37,36 +37,31 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, - p10_u16_b_out, p10_u16_r_out, w, h, - MTL_SIMD_LEVEL_NONE); + p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, p10_u16_b_out, + p10_u16_r_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, - p10_u16_b_out, p10_u16_r_out, w, - h, MTL_SIMD_LEVEL_AVX512); + p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, p10_u16_b_out, + p10_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -75,18 +70,16 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); st20_rfc4175_422be10_to_yuv422p10le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, - p10_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512); + dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, p10_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -96,18 +89,16 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); - st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, - p10_u16_b_out, p10_u16_r_out, w, - h, MTL_SIMD_LEVEL_AVX512_VBMI2); + p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + st20_rfc4175_422be10_to_yuv422p10le_simd(pg_be_in, p10_u16_out, p10_u16_b_out, + p10_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -116,27 +107,23 @@ static int perf_cvt_422_10_pg2_to_planar_le(mtl_handle st, int w, int h, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p10_u16_out = p10_u16 + (i % fb_cnt) * (planar_size / sizeof(*p10_u16)); - p10_u16_b_out = - p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); - p10_u16_r_out = - p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); + p10_u16_b_out = p10_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_b)); + p10_u16_r_out = p10_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p10_u16_r)); st20_rfc4175_422be10_to_yuv422p10le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, - p10_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); + dma, pg_be_in, pg_be_in_iova, p10_u16_out, p10_u16_b_out, p10_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", - duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); } } mtl_hp_free(st, pg_be); free(p10_u16); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -158,10 +145,8 @@ static void *perf_thread(void *arg) { perf_cvt_422_10_pg2_to_planar_le(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, - fb_cnt); - perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, - fb_cnt); + perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); + perf_cvt_422_10_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); mtl_put_lcore(dev_handle, lcore); @@ -174,8 +159,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -185,8 +169,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_p8.c b/app/perf/rfc4175_422be10_to_p8.c index 92c4b2e67..68d126c04 100644 --- a/app/perf/rfc4175_422be10_to_p8.c +++ b/app/perf/rfc4175_422be10_to_p8.c @@ -8,8 +8,8 @@ static int perf_cvt_422_10_pg2_be_to_p8(mtl_handle st, int w, int h, int frames, int fb_cnt) { size_t fb_pg10_size = (size_t)w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_be *pg_10 = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( - st, fb_pg10_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc(st, fb_pg10_size * fb_cnt, + MTL_PORT_P); size_t fb_pg8_size = (size_t)w * h * 2; float fb_pg8_size_m = (float)fb_pg8_size / 1024 / 1024; uint8_t *pg_8 = (uint8_t *)malloc(fb_pg8_size * fb_cnt); @@ -36,22 +36,22 @@ static int perf_cvt_422_10_pg2_be_to_p8(mtl_handle st, int w, int h, int frames, } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, fb_pg8_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, fb_pg8_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_10_in = pg_10 + (i % fb_cnt) * (fb_pg10_size / sizeof(*pg_10)); pg_8_out = pg_8 + (i % fb_cnt) * (fb_pg8_size / sizeof(*pg_8)); - st20_rfc4175_422be10_to_yuv422p8_simd( - pg_10_in, pg_8_out, pg_8_out + w * h, pg_8_out + w * h * 3 / 2, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be10_to_yuv422p8_simd(pg_10_in, pg_8_out, pg_8_out + w * h, + pg_8_out + w * h * 3 / 2, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); } @@ -92,8 +92,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -103,8 +102,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_v210.c b/app/perf/rfc4175_422be10_to_v210.c index c8b3ebaa6..4d9e1aa86 100644 --- a/app/perf/rfc4175_422be10_to_v210.c +++ b/app/perf/rfc4175_422be10_to_v210.c @@ -6,14 +6,14 @@ #define TEST_2_STEPS (0) -static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, - int frames, int fb_cnt) { +static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( - st, fb_pg2_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, + MTL_PORT_P); struct st20_rfc4175_422_10_pg2_le *pg_le = (struct st20_rfc4175_422_10_pg2_le *)malloc(fb_pg2_size * fb_cnt); uint8_t *pg_v210 = (uint8_t *)malloc(fb_pg2_size_v210 * fb_cnt); @@ -23,8 +23,7 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, float planar_size_m = (float)planar_size / 1024 / 1024; enum mtl_simd_level cpu_level = mtl_get_simd_level(); - size_t be_1line_size = - st_frame_size(ST_FRAME_FMT_YUV422RFC4175PG2BE10, w, 1, false); + size_t be_1line_size = st_frame_size(ST_FRAME_FMT_YUV422RFC4175PG2BE10, w, 1, false); size_t v210_1line_size = st_frame_size(ST_FRAME_FMT_V210, w, 1, false); info("v210_1line_size %" PRIu64 "\n", v210_1line_size); @@ -43,29 +42,26 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, - MTL_SIMD_LEVEL_NONE); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (v210_1line_size) { @@ -73,8 +69,7 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); for (int j = 0; j < h; j++) { st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, 1, @@ -87,8 +82,7 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("avx512_1line, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("avx512_1line, %fx performance to scalar\n", - duration / duration_simd); + info("avx512_1line, %fx performance to scalar\n", duration / duration_simd); } if (dma) { @@ -96,16 +90,14 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, - pg_v210_out, w, h, - MTL_SIMD_LEVEL_AVX512); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_v210_out, + w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -113,15 +105,14 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_v210_simd(pg_be_in, pg_v210_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -129,18 +120,15 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, - pg_v210_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_v210_out, + w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", - duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); } } @@ -151,25 +139,22 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); - st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, - MTL_SIMD_LEVEL_NONE); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_NONE); st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le_out, pg_v210_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_AVX512); st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le_out, pg_v210_out, w, h, @@ -177,8 +162,8 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); } @@ -187,8 +172,7 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - pg_v210_out = - pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); + pg_v210_out = pg_v210 + (i % fb_cnt) * (fb_pg2_size_v210 / sizeof(*pg_v210)); st20_rfc4175_422be10_to_422le10_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le_out, pg_v210_out, w, h, @@ -196,8 +180,8 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); } #endif @@ -205,8 +189,7 @@ static int perf_cvt_422_10_pg2_be_to_v210(mtl_handle st, int w, int h, mtl_hp_free(st, pg_be); free(pg_le); free(pg_v210); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -228,10 +211,8 @@ static void *perf_thread(void *arg) { perf_cvt_422_10_pg2_be_to_v210(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 2, 1080 * 2, frames, - fb_cnt); - perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 4, 1080 * 4, frames, - fb_cnt); + perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); + perf_cvt_422_10_pg2_be_to_v210(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); mtl_put_lcore(dev_handle, lcore); @@ -244,8 +225,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -255,8 +235,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be10_to_y210.c b/app/perf/rfc4175_422be10_to_y210.c index acb4a24f2..2504c2e94 100644 --- a/app/perf/rfc4175_422be10_to_y210.c +++ b/app/perf/rfc4175_422be10_to_y210.c @@ -4,14 +4,14 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, - int frames, int fb_cnt) { +static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; size_t fb_pg2_size_y210 = (size_t)w * h * 4; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc( - st, fb_pg2_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, + MTL_PORT_P); uint16_t *pg_y210 = (uint16_t *)malloc(fb_pg2_size_y210 * fb_cnt); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; @@ -33,29 +33,26 @@ static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_y210_out = - pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); - st20_rfc4175_422be10_to_y210_simd(pg_be_in, pg_y210_out, w, h, - MTL_SIMD_LEVEL_NONE); + pg_y210_out = pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); + st20_rfc4175_422be10_to_y210_simd(pg_be_in, pg_y210_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - pg_y210_out = - pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); + pg_y210_out = pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); st20_rfc4175_422be10_to_y210_simd(pg_be_in, pg_y210_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -63,24 +60,21 @@ static int perf_cvt_422_10_pg2_be_to_y210(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); - pg_y210_out = - pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); - st20_rfc4175_422be10_to_y210_simd_dma(dma, pg_be_in, pg_be_in_iova, - pg_y210_out, w, h, - MTL_SIMD_LEVEL_AVX512); + pg_y210_out = pg_y210 + (i % fb_cnt) * (fb_pg2_size_y210 / sizeof(*pg_y210)); + st20_rfc4175_422be10_to_y210_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_y210_out, + w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_be); free(pg_y210); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -102,10 +96,8 @@ static void *perf_thread(void *arg) { perf_cvt_422_10_pg2_be_to_y210(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 2, 1080 * 2, frames, - fb_cnt); - perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 4, 1080 * 4, frames, - fb_cnt); + perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); + perf_cvt_422_10_pg2_be_to_y210(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); mtl_put_lcore(dev_handle, lcore); @@ -118,8 +110,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -129,8 +120,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be12_to_le.c b/app/perf/rfc4175_422be12_to_le.c index a228859ae..284440990 100644 --- a/app/perf/rfc4175_422be12_to_le.c +++ b/app/perf/rfc4175_422be12_to_le.c @@ -9,8 +9,8 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, size_t fb_pg2_size = (size_t)w * h * 3; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_12_pg2_be *pg_be = - (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_malloc( - st, fb_pg2_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, + MTL_PORT_P); struct st20_rfc4175_422_12_pg2_le *pg_le = (struct st20_rfc4175_422_12_pg2_le *)malloc(fb_pg2_size * fb_cnt); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); @@ -34,13 +34,12 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames * 1; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be12_to_422le12_simd(pg_be_in, pg_le_out, w, h, - MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422be12_to_422le12_simd(pg_be_in, pg_le_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); @@ -52,8 +51,8 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -62,22 +61,20 @@ static int perf_cvt_422_12_pg2_be_to_le(mtl_handle st, int w, int h, int frames, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_out = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422be12_to_422le12_simd_dma(dma, pg_be_in, pg_be_in_iova, - pg_le_out, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422be12_to_422le12_simd_dma(dma, pg_be_in, pg_be_in_iova, pg_le_out, + w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_be); free(pg_le); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -113,8 +110,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -124,8 +120,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422be12_to_p12le.c b/app/perf/rfc4175_422be12_to_p12le.c index c1ccd08a0..6604c9a12 100644 --- a/app/perf/rfc4175_422be12_to_p12le.c +++ b/app/perf/rfc4175_422be12_to_p12le.c @@ -4,13 +4,13 @@ #include "../sample/sample_util.h" -static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, - int frames, int fb_cnt) { +static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, int frames, + int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 6 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_12_pg2_be *pg_be = - (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_malloc( - st, fb_pg2_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, + MTL_PORT_P); mtl_iova_t pg_be_iova = mtl_hp_virt2iova(st, pg_be); mtl_iova_t pg_be_in_iova; size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); @@ -37,36 +37,31 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = - p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = - p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); - st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, - p12_u16_b_out, p12_u16_r_out, w, h, - MTL_SIMD_LEVEL_NONE); + p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, p12_u16_b_out, + p12_u16_r_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = - p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = - p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); - st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, - p12_u16_b_out, p12_u16_r_out, w, - h, MTL_SIMD_LEVEL_AVX512); + p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, p12_u16_b_out, + p12_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -75,18 +70,16 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = - p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = - p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); st20_rfc4175_422be12_to_yuv422p12le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, - p12_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512); + dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, p12_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -96,18 +89,16 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, for (int i = 0; i < frames; i++) { pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = - p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = - p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); - st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, - p12_u16_b_out, p12_u16_r_out, w, - h, MTL_SIMD_LEVEL_AVX512_VBMI2); + p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + st20_rfc4175_422be12_to_yuv422p12le_simd(pg_be_in, p12_u16_out, p12_u16_b_out, + p12_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { @@ -116,27 +107,23 @@ static int perf_cvt_422_12_pg2_to_planar_le(mtl_handle st, int w, int h, pg_be_in = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_in_iova = pg_be_iova + (i % fb_cnt) * (fb_pg2_size); p12_u16_out = p12_u16 + (i % fb_cnt) * (planar_size / sizeof(*p12_u16)); - p12_u16_b_out = - p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); - p12_u16_r_out = - p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); + p12_u16_b_out = p12_u16_b + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_b)); + p12_u16_r_out = p12_u16_r + (i % fb_cnt) * (planar_size / sizeof(*p12_u16_r)); st20_rfc4175_422be12_to_yuv422p12le_simd_dma( - dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, - p12_u16_r_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); + dma, pg_be_in, pg_be_in_iova, p12_u16_out, p12_u16_b_out, p12_u16_r_out, w, h, + MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", - duration / duration_vbmi); + info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); } } mtl_hp_free(st, pg_be); free(p12_u16); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -158,10 +145,8 @@ static void *perf_thread(void *arg) { perf_cvt_422_12_pg2_to_planar_le(dev_handle, 640, 480, frames, fb_cnt); perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1280, 720, frames, fb_cnt); perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920, 1080, frames, fb_cnt); - perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, - fb_cnt); - perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, - fb_cnt); + perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 2, 1080 * 2, frames, fb_cnt); + perf_cvt_422_12_pg2_to_planar_le(dev_handle, 1920 * 4, 1080 * 4, frames, fb_cnt); mtl_put_lcore(dev_handle, lcore); @@ -174,8 +159,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -185,8 +169,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/rfc4175_422le10_to_be.c b/app/perf/rfc4175_422le10_to_be.c index 6c6fc16bf..b889b533f 100644 --- a/app/perf/rfc4175_422le10_to_be.c +++ b/app/perf/rfc4175_422le10_to_be.c @@ -4,8 +4,8 @@ #include "../sample/sample_util.h" -static void fill_422_10_pg2_le_data(struct st20_rfc4175_422_10_pg2_le *data, - int w, int h) { +static void fill_422_10_pg2_le_data(struct st20_rfc4175_422_10_pg2_le *data, int w, + int h) { int pg_size = w * h / 2; uint16_t cb, y0, cr, y1; /* 10 bit */ @@ -38,8 +38,8 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, size_t fb_pg2_size = w * h * 5 / 2; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_le *pg_le = - (struct st20_rfc4175_422_10_pg2_le *)mtl_hp_malloc( - st, fb_pg2_size * fb_cnt, MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_le *)mtl_hp_malloc(st, fb_pg2_size * fb_cnt, + MTL_PORT_P); mtl_iova_t pg_le_iova = mtl_hp_virt2iova(st, pg_le); mtl_iova_t pg_le_in_iova; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -63,13 +63,12 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames * 1; i++) { pg_le_in = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422le10_to_422be10_simd(pg_le_in, pg_be_out, w, h, - MTL_SIMD_LEVEL_NONE); + st20_rfc4175_422le10_to_422be10_simd(pg_le_in, pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, planar_size_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, planar_size_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX2) { start = clock(); @@ -81,8 +80,8 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx2, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, + w, h, fb_cnt); info("avx2, %fx performance to scalar\n", duration / duration_simd); } @@ -96,8 +95,8 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { @@ -106,14 +105,13 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, pg_le_in_iova = pg_le_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_in = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, - pg_be_out, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, pg_be_out, + w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } @@ -128,8 +126,8 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { start = clock(); @@ -137,23 +135,20 @@ static int perf_cvt_422_10_pg2_le_to_be(mtl_handle st, int w, int h, int frames, pg_le_in_iova = pg_le_iova + (i % fb_cnt) * (fb_pg2_size); pg_le_in = pg_le + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_le)); - st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, - pg_be_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le_in, pg_le_in_iova, pg_be_out, + w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", - duration / duration_simd); + info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_le); free(pg_be); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -189,8 +184,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -200,8 +194,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/v210_to_rfc4175_422be10.c b/app/perf/v210_to_rfc4175_422be10.c index 2f424d9e6..a1db7ef53 100644 --- a/app/perf/v210_to_rfc4175_422be10.c +++ b/app/perf/v210_to_rfc4175_422be10.c @@ -7,20 +7,17 @@ static void fill_rand_v210(uint8_t *p, size_t sz) { for (size_t i = 0; i < sz; i++) { p[i] = rand(); - if ((i % 4) == 3) - p[i] &= 0x3F; + if ((i % 4) == 3) p[i] &= 0x3F; } } -static int perf_cvt_v210_to_be(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_v210_to_be(mtl_handle st, int w, int h, int frames, int fb_cnt) { size_t fb_pg2_size = w * h * 5 / 2; size_t fb_size_v210 = w * h * 8 / 3; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = (struct st20_rfc4175_422_10_pg2_be *)malloc(fb_pg2_size * fb_cnt); - uint8_t *pg_v210 = - (uint8_t *)mtl_hp_malloc(st, fb_size_v210 * fb_cnt, MTL_PORT_P); + uint8_t *pg_v210 = (uint8_t *)mtl_hp_malloc(st, fb_size_v210 * fb_cnt, MTL_PORT_P); mtl_iova_t pg_v210_iova = mtl_hp_virt2iova(st, pg_v210); mtl_iova_t pg_v210_in_iova; float fb_size_v210_m = (float)fb_size_v210 / 1024 / 1024; @@ -41,84 +38,75 @@ static int perf_cvt_v210_to_be(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames; i++) { pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, - MTL_SIMD_LEVEL_NONE); + st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, fb_size_v210_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, fb_size_v210_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = - pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = - pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_v210_in_iova = pg_v210_iova + (i % fb_cnt) * (fb_size_v210); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, - pg_be_out, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, pg_be_out, + w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } if (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = - pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); st20_v210_to_rfc4175_422be10_simd(pg_v210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_vbmi = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_vbmi, frames, w, h, fb_cnt); + info("avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_vbmi, + frames, w, h, fb_cnt); info("avx512_vbmi, %fx performance to scalar\n", duration / duration_vbmi); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { - pg_v210_in = - pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); + pg_v210_in = pg_v210 + (i % fb_cnt) * (fb_size_v210 / sizeof(*pg_v210_in)); pg_v210_in_iova = pg_v210_iova + (i % fb_cnt) * (fb_size_v210); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, - pg_be_out, w, h, - MTL_SIMD_LEVEL_AVX512_VBMI2); + st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210_in, pg_v210_in_iova, pg_be_out, + w, h, MTL_SIMD_LEVEL_AVX512_VBMI2); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; info("dma+avx512_vbmi, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, frames, w, h, fb_cnt); - info("dma+avx512_vbmi, %fx performance to scalar\n", - duration / duration_simd); + info("dma+avx512_vbmi, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_v210); free(pg_be); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -154,8 +142,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -165,8 +152,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/perf/y210_to_rfc4175_422be10.c b/app/perf/y210_to_rfc4175_422be10.c index b8510c95b..0bfb6ba02 100644 --- a/app/perf/y210_to_rfc4175_422be10.c +++ b/app/perf/y210_to_rfc4175_422be10.c @@ -18,15 +18,13 @@ static void fill_rand_y210(uint16_t *p, size_t sz) { } } -static int perf_cvt_y210_to_be(mtl_handle st, int w, int h, int frames, - int fb_cnt) { +static int perf_cvt_y210_to_be(mtl_handle st, int w, int h, int frames, int fb_cnt) { size_t fb_pg2_size = (size_t)w * h * 5 / 2; size_t fb_size_y210 = (size_t)w * h * 4; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = (struct st20_rfc4175_422_10_pg2_be *)malloc(fb_pg2_size * fb_cnt); - uint16_t *pg_y210 = - (uint16_t *)mtl_hp_malloc(st, fb_size_y210 * fb_cnt, MTL_PORT_P); + uint16_t *pg_y210 = (uint16_t *)mtl_hp_malloc(st, fb_size_y210 * fb_cnt, MTL_PORT_P); mtl_iova_t pg_y210_iova = mtl_hp_virt2iova(st, pg_y210); mtl_iova_t pg_y210_in_iova; float fb_size_y210_m = (float)fb_size_y210 / 1024 / 1024; @@ -47,51 +45,46 @@ static int perf_cvt_y210_to_be(mtl_handle st, int w, int h, int frames, for (int i = 0; i < frames; i++) { pg_y210_in = pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_y210_to_rfc4175_422be10_simd(pg_y210_in, pg_be_out, w, h, - MTL_SIMD_LEVEL_NONE); + st20_y210_to_rfc4175_422be10_simd(pg_y210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_NONE); } end = clock(); duration = (float)(end - start) / CLOCKS_PER_SEC; - info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, - frames, w, h, fb_size_y210_m, fb_cnt); + info("scalar, time: %f secs with %d frames(%dx%d,%fm@%d buffers)\n", duration, frames, + w, h, fb_size_y210_m, fb_cnt); if (cpu_level >= MTL_SIMD_LEVEL_AVX512) { start = clock(); for (int i = 0; i < frames; i++) { - pg_y210_in = - pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); + pg_y210_in = pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); st20_y210_to_rfc4175_422be10_simd(pg_y210_in, pg_be_out, w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("avx512, %fx performance to scalar\n", duration / duration_simd); if (dma) { start = clock(); for (int i = 0; i < frames; i++) { - pg_y210_in = - pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); + pg_y210_in = pg_y210 + (i % fb_cnt) * (fb_size_y210 / sizeof(*pg_y210_in)); pg_y210_in_iova = pg_y210_iova + (i % fb_cnt) * (fb_size_y210); pg_be_out = pg_be + (i % fb_cnt) * (fb_pg2_size / sizeof(*pg_be)); - st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210_in, pg_y210_in_iova, - pg_be_out, w, h, - MTL_SIMD_LEVEL_AVX512); + st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210_in, pg_y210_in_iova, pg_be_out, + w, h, MTL_SIMD_LEVEL_AVX512); } end = clock(); float duration_simd = (float)(end - start) / CLOCKS_PER_SEC; - info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", - duration_simd, frames, w, h, fb_cnt); + info("dma+avx512, time: %f secs with %d frames(%dx%d@%d buffers)\n", duration_simd, + frames, w, h, fb_cnt); info("dma+avx512, %fx performance to scalar\n", duration / duration_simd); } } mtl_hp_free(st, pg_y210); free(pg_be); - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return 0; } @@ -127,8 +120,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -138,8 +130,7 @@ int main(int argc, char **argv) { pthread_t thread; ret = pthread_create(&thread, NULL, perf_thread, &ctx); - if (ret) - goto exit; + if (ret) goto exit; pthread_join(thread, NULL); exit: diff --git a/app/sample/dma/dma_sample.c b/app/sample/dma/dma_sample.c index 5cf720461..17864c0ba 100644 --- a/app/sample/dma/dma_sample.c +++ b/app/sample/dma/dma_sample.c @@ -57,8 +57,7 @@ static int dma_copy_sample(mtl_handle st) { while (fb_src_iova_off < fb_size) { ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, element_size); - if (ret < 0) - break; + if (ret < 0) break; fb_src_iova_off += element_size; } /* submit */ @@ -151,8 +150,7 @@ static int dma_map_copy_sample(mtl_handle st) { while (fb_src_iova_off < fb_size) { ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, element_size); - if (ret < 0) - break; + if (ret < 0) break; fb_src_iova_off += element_size; } /* submit */ @@ -172,23 +170,20 @@ static int dma_map_copy_sample(mtl_handle st) { if (ret != 0) { err("%s: sha check fail\n", __func__); } else { - info("%s: dma map copy %" PRIu64 "k with time %dus\n", __func__, - fb_size / 1024, (int)(end_ns - start_ns) / 1000); + info("%s: dma map copy %" PRIu64 "k with time %dus\n", __func__, fb_size / 1024, + (int)(end_ns - start_ns) / 1000); } out: if (fb_src_malloc) { - if (fb_src_iova != MTL_BAD_IOVA) - mtl_dma_unmap(st, fb_src, fb_src_iova, fb_size); + if (fb_src_iova != MTL_BAD_IOVA) mtl_dma_unmap(st, fb_src, fb_src_iova, fb_size); free(fb_src_malloc); } if (fb_dst_malloc) { - if (fb_dst_iova != MTL_BAD_IOVA) - mtl_dma_unmap(st, fb_dst, fb_dst_iova, fb_size); + if (fb_dst_iova != MTL_BAD_IOVA) mtl_dma_unmap(st, fb_dst, fb_dst_iova, fb_size); free(fb_dst_malloc); } - if (dma) - mtl_udma_free(dma); + if (dma) mtl_udma_free(dma); return ret; } @@ -198,8 +193,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = dma_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -209,12 +203,10 @@ int main(int argc, char **argv) { /* dma copy with st_hp_*** memory */ ret = dma_copy_sample(ctx.st); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; /* dma copy with malloc/free memory, use map before passing to DMA */ ret = dma_map_copy_sample(ctx.st); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; exit: /* release sample(st) dev */ diff --git a/app/sample/experimental/rx_st20_redundant_combined_sample.c b/app/sample/experimental/rx_st20_redundant_combined_sample.c index 3672ce32a..d13223d01 100644 --- a/app/sample/experimental/rx_st20_redundant_combined_sample.c +++ b/app/sample/experimental/rx_st20_redundant_combined_sample.c @@ -23,8 +23,7 @@ struct st20rc_sample_ctx { struct st_rx_frame *framebuffs; }; -static int rx_video_enqueue_frame(struct st20rc_sample_ctx *s, void *frame, - size_t size) { +static int rx_video_enqueue_frame(struct st20rc_sample_ctx *s, void *frame, size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; @@ -37,8 +36,7 @@ static int rx_video_enqueue_frame(struct st20rc_sample_ctx *s, void *frame, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } @@ -47,8 +45,7 @@ static int rx_video_frame_ready(void *priv, void *frame, struct st20_rx_frame_meta *meta) { struct st20rc_sample_ctx *s = (struct st20rc_sample_ctx *)priv; - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -95,8 +92,7 @@ static void *rx_video_frame_thread(void *arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -109,8 +105,7 @@ static void *rx_video_frame_thread(void *arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -144,8 +139,7 @@ int main(int argc, char **argv) { // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = - (struct st20rc_sample_ctx *)malloc(sizeof(struct st20rc_sample_ctx)); + app[i] = (struct st20rc_sample_ctx *)malloc(sizeof(struct st20rc_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -157,8 +151,8 @@ int main(int argc, char **argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = (struct st_rx_frame *)malloc( - sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = + (struct st_rx_frame *)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -172,7 +166,7 @@ int main(int argc, char **argv) { struct st20rc_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20rc_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 2; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -192,8 +186,7 @@ int main(int argc, char **argv) { ops_rx.framebuff_cnt = app[i]->framebuff_cnt; ops_rx.payload_type = ctx.payload_type; ops_rx.notify_frame_ready = rx_video_frame_ready; - if (ctx.hdr_split) - ops_rx.flags |= ST20RC_RX_FLAG_HDR_SPLIT; + if (ctx.hdr_split) ops_rx.flags |= ST20RC_RX_FLAG_HDR_SPLIT; rx_handle[i] = st20rc_rx_create(ctx.st, &ops_rx); if (!rx_handle[i]) { @@ -203,8 +196,7 @@ int main(int argc, char **argv) { } app[i]->handle = rx_handle[i]; - ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, - app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); goto error; @@ -218,13 +210,11 @@ int main(int argc, char **argv) { loop++; if (0 == (loop % 10)) { uint64_t end_time_ns = mtl_ptp_read_time(ctx.st); - double time_sec = - (double)(end_time_ns - sart_time_ns) / (1000 * 1000 * 1000); + double time_sec = (double)(end_time_ns - sart_time_ns) / (1000 * 1000 * 1000); for (int i = 0; i < session_num; i++) { int fb_rec = app[i]->fb_rec - app[i]->stat_fb_rec; double framerate = fb_rec / time_sec; - info("%s(%d), fps %f, %d frame received\n", __func__, i, framerate, - fb_rec); + info("%s(%d), fps %f, %d frame received\n", __func__, i, framerate, fb_rec); app[i]->stat_fb_rec = app[i]->fb_rec; } sart_time_ns = end_time_ns; @@ -244,8 +234,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); ret = -EIO; } } @@ -253,14 +242,11 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20rc_rx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20rc_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) - free(app[i]->framebuffs); + if (app[i]->framebuffs) free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c b/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c index 36b498614..cdb63949b 100644 --- a/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c +++ b/app/sample/ext_frame/rx_st20_pipeline_dyn_ext_frame_sample.c @@ -52,8 +52,7 @@ static int rx_st20p_query_ext_frame(void *priv, struct st_ext_frame *ext_frame, /* save your private data here get it from st_frame.opaque */ /* ext_frame->opaque = ?; */ - if (++s->ext_idx >= s->fb_cnt) - s->ext_idx = 0; + if (++s->ext_idx >= s->fb_cnt) s->ext_idx = 0; return 0; } @@ -71,8 +70,7 @@ static int rx_st20p_close_source(struct rx_st20p_sample_ctx *s) { return 0; } -static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, - const char *file) { +static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -102,16 +100,15 @@ static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, fb_cnt, file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, + file, m, f_size); return 0; } static void rx_st20p_consume_frame(struct rx_st20p_sample_ctx *s, struct st_frame *frame) { - if (s->dst_cursor + s->frame_size > s->dst_end) - s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; /* parse private data for dynamic ext frame @@ -132,8 +129,7 @@ static void *rx_st20p_frame_thread(void *arg) { frame = st20p_rx_get_frame(handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -152,8 +148,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -186,7 +181,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -206,8 +201,8 @@ int main(int argc, char **argv) { if (equal) { /* no convert, use ext frame for example */ - app[i]->ext_frames = (struct st20_ext_frame *)malloc( - sizeof(*app[i]->ext_frames) * app[i]->fb_cnt); + app[i]->ext_frames = + (struct st20_ext_frame *)malloc(sizeof(*app[i]->ext_frames) * app[i]->fb_cnt); size_t framebuff_size = st20_frame_size(ops_rx.transport_fmt, ops_rx.width, ops_rx.height); size_t fb_size = framebuff_size * app[i]->fb_cnt; @@ -221,10 +216,8 @@ int main(int argc, char **argv) { app[i]->dma_mem = dma_mem; for (int j = 0; j < app[i]->fb_cnt; ++j) { - app[i]->ext_frames[j].buf_addr = - mtl_dma_mem_addr(dma_mem) + j * framebuff_size; - app[i]->ext_frames[j].buf_iova = - mtl_dma_mem_iova(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_addr = mtl_dma_mem_addr(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_iova = mtl_dma_mem_iova(dma_mem) + j * framebuff_size; app[i]->ext_frames[j].buf_len = framebuff_size; } app[i]->ext_idx = 0; @@ -248,8 +241,7 @@ int main(int argc, char **argv) { goto error; } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -276,8 +268,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); ret = -EIO; } } @@ -285,12 +276,9 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st20p_rx_free(app[i]->handle); - if (ctx.st && app[i]->dma_mem) - mtl_dma_mem_free(ctx.st, app[i]->dma_mem); - if (app[i]->ext_frames) - free(app[i]->ext_frames); + if (app[i]->handle) st20p_rx_free(app[i]->handle); + if (ctx.st && app[i]->dma_mem) mtl_dma_mem_free(ctx.st, app[i]->dma_mem); + if (app[i]->ext_frames) free(app[i]->ext_frames); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c b/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c index 59ea396f0..3fd626024 100644 --- a/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c +++ b/app/sample/ext_frame/rx_st20p_hdr_split_gpu_direct.c @@ -48,15 +48,13 @@ static int gaddr_profiling(struct rx_st20p_hg_ctx *ctx) { float throughput_bit; uint8_t buf[256]; - info("%s, start on %p, size %" PRIu64 "\n", __func__, frame->addr[0], - frame->size); + info("%s, start on %p, size %" PRIu64 "\n", __func__, frame->addr[0], frame->size); /* read */ loop_cnt = 3; start = clock(); /* read is very slow, not known why */ size_t r_sz = 0x100000; - if (frame->size < r_sz) - r_sz = frame->size; + if (frame->size < r_sz) r_sz = frame->size; for (int loop = 0; loop < loop_cnt; loop++) { uint8_t *addr = (uint8_t *)frame->addr[0]; for (size_t i = 0; i < r_sz; i++) { @@ -87,16 +85,15 @@ static int gaddr_profiling(struct rx_st20p_hg_ctx *ctx) { return 0; } -static int gddr_map(struct st_sample_context *ctx, struct st_ext_frame *frame, - size_t sz, int fd) { +static int gddr_map(struct st_sample_context *ctx, struct st_ext_frame *frame, size_t sz, + int fd) { off_t off = ctx->gddr_pa + ctx->gddr_offset; void *map = mmap(0, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, off); if (MAP_FAILED == map) { err("%s, map size %" PRIu64 " fail\n", __func__, sz); return -EIO; } - info("%s, map %p with size %" PRIu64 " offset %" PRIx64 "\n", __func__, map, - sz, off); + info("%s, map %p with size %" PRIu64 " offset %" PRIx64 "\n", __func__, map, sz, off); mtl_iova_t iova; if (mtl_iova_mode_get(ctx->st) == MTL_IOVA_MODE_PA) { @@ -106,8 +103,7 @@ static int gddr_map(struct st_sample_context *ctx, struct st_ext_frame *frame, dbg("%s, iova va mode\n", __func__); iova = mtl_dma_map(ctx->st, map, sz); if (MTL_BAD_IOVA == iova) { - err("%s, dma map fail for va %p sz %" PRIu64 " fail\n", __func__, map, - sz); + err("%s, dma map fail for va %p sz %" PRIu64 " fail\n", __func__, map, sz); munmap(map, sz); return -EIO; } @@ -173,24 +169,21 @@ static int rx_st20p_open_source(struct rx_st20p_hg_ctx *s, const char *file) { s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, fb_cnt, file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, + file, m, f_size); return 0; } -static void rx_st20p_consume_frame(struct rx_st20p_hg_ctx *s, - struct st_frame *frame) { +static void rx_st20p_consume_frame(struct rx_st20p_hg_ctx *s, struct st_frame *frame) { if (s->dst_fd > 0) { - if (s->dst_cursor + s->frame_size > s->dst_end) - s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; } else { uint32_t *d; if (s->use_cpu_copy) { - if (s->cpu_copy_offset + s->frame_size > s->gddr_frame.size) - s->cpu_copy_offset = 0; + if (s->cpu_copy_offset + s->frame_size > s->gddr_frame.size) s->cpu_copy_offset = 0; void *gddr = s->gddr_frame.addr[0] + s->cpu_copy_offset; mtl_memcpy(gddr, frame->addr[0], s->frame_size); d = (uint32_t *)gddr; @@ -199,8 +192,7 @@ static void rx_st20p_consume_frame(struct rx_st20p_hg_ctx *s, d = (uint32_t *)frame->addr[0]; } if (0 == (s->fb_recv % 60)) { - info("%s(%d), frame %p, value 0x%x 0x%x\n", __func__, s->idx, d, d[0], - d[1]); + info("%s(%d), frame %p, value 0x%x 0x%x\n", __func__, s->idx, d, d[0], d[1]); } } s->fb_recv++; @@ -216,8 +208,7 @@ static void *rx_st20p_frame_thread(void *arg) { frame = st20p_rx_get_frame(handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -237,8 +228,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (!ctx.use_cpu_copy) { /* enable hdr split */ @@ -287,7 +277,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -311,16 +301,13 @@ int main(int argc, char **argv) { ops_rx.notify_frame_available = rx_st20p_frame_available; /* map gddr */ - app[i]->frame_size = st_frame_size(ops_rx.output_fmt, ops_rx.width, - ops_rx.height, ops_rx.interlaced); - size_t fb_sz = - app[i]->frame_size * (app[i]->fb_cnt + 1) + app[i]->pg_sz * 2; + app[i]->frame_size = + st_frame_size(ops_rx.output_fmt, ops_rx.width, ops_rx.height, ops_rx.interlaced); + size_t fb_sz = app[i]->frame_size * (app[i]->fb_cnt + 1) + app[i]->pg_sz * 2; fb_sz = mtl_size_page_align(fb_sz, app[i]->pg_sz); ret = gddr_map(&ctx, &app[i]->gddr_frame, fb_sz, dev_mem_fd); - if (ret < 0) - goto error; - if (ctx.profiling_gddr) - gaddr_profiling(app[i]); + if (ret < 0) goto error; + if (ctx.profiling_gddr) gaddr_profiling(app[i]); if (!ctx.use_cpu_copy) { ops_rx.flags |= ST20P_RX_FLAG_HDR_SPLIT; @@ -342,8 +329,7 @@ int main(int argc, char **argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -370,8 +356,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); ret = -EIO; } } @@ -379,12 +364,11 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st20p_rx_free(app[i]->handle); + if (app[i]->handle) st20p_rx_free(app[i]->handle); if (app[i]->gddr_frame.iova[0]) { if (mtl_iova_mode_get(ctx.st) != MTL_IOVA_MODE_PA) { - mtl_dma_unmap(ctx.st, app[i]->gddr_frame.addr[0], - app[i]->gddr_frame.iova[0], app[i]->gddr_frame.size); + mtl_dma_unmap(ctx.st, app[i]->gddr_frame.addr[0], app[i]->gddr_frame.iova[0], + app[i]->gddr_frame.size); } } if (app[i]->gddr_frame.addr[0]) { @@ -396,8 +380,7 @@ int main(int argc, char **argv) { } } - if (dev_mem_fd > 0) - close(dev_mem_fd); + if (dev_mem_fd > 0) close(dev_mem_fd); /* release sample(st) dev */ if (ctx.st) { mtl_uninit(ctx.st); diff --git a/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c b/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c index 8339a3cc1..833d50544 100644 --- a/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c +++ b/app/sample/ext_frame/tx_st20_pipeline_ext_frame_sample.c @@ -26,8 +26,7 @@ struct tx_st20p_sample_ctx { }; static int tx_st20p_close_source(struct tx_st20p_sample_ctx *s) { - if (s->dma_mem) - mtl_dma_mem_free(s->st, s->dma_mem); + if (s->dma_mem) mtl_dma_mem_free(s->st, s->dma_mem); return 0; } @@ -57,8 +56,8 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx *s, char *file) { return -EIO; } if (i.st_size % s->frame_size) { - err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", - __func__, file, s->frame_size); + err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", __func__, file, + s->frame_size); close(fd); return -EIO; } @@ -82,10 +81,8 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx *s, char *file) { mtl_dma_mem_handle dma_mem = mtl_dma_mem_alloc(s->st, fbs_size); if (!dma_mem) { err("%s(%d), dma mem alloc/map fail\n", __func__, s->idx); - if (m) - munmap(m, fbs_size); - if (fd >= 0) - close(fd); + if (m) munmap(m, fbs_size); + if (fd >= 0) close(fd); return -EIO; } s->dma_mem = dma_mem; @@ -103,11 +100,9 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx *s, char *file) { munmap(m, fbs_size); } s->source_end = s->source_begin + fbs_size; - info("%s, source begin at %p, end at %p\n", __func__, s->source_begin, - s->source_end); + info("%s, source begin at %p, end at %p\n", __func__, s->source_begin, s->source_end); - if (fd >= 0) - close(fd); + if (fd >= 0) close(fd); return 0; } @@ -142,26 +137,22 @@ static void *tx_st20p_frame_thread(void *arg) { frame = st20p_tx_get_frame(handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } struct st_ext_frame ext_frame; ext_frame.addr[0] = s->frame_cursor; - ext_frame.iova[0] = - s->source_begin_iova + (s->frame_cursor - s->source_begin); - ext_frame.linesize[0] = - st_frame_least_linesize(frame->fmt, frame->width, 0); + ext_frame.iova[0] = s->source_begin_iova + (s->frame_cursor - s->source_begin); + ext_frame.linesize[0] = st_frame_least_linesize(frame->fmt, frame->width, 0); uint8_t planes = st_frame_fmt_planes(frame->fmt); - for (uint8_t plane = 1; plane < planes; - plane++) { /* assume planes continous */ + for (uint8_t plane = 1; plane < planes; plane++) { /* assume planes continous */ ext_frame.linesize[plane] = st_frame_least_linesize(frame->fmt, frame->width, plane); ext_frame.addr[plane] = (uint8_t *)ext_frame.addr[plane - 1] + ext_frame.linesize[plane - 1] * frame->height; - ext_frame.iova[plane] = ext_frame.iova[plane - 1] + - ext_frame.linesize[plane - 1] * frame->height; + ext_frame.iova[plane] = + ext_frame.iova[plane - 1] + ext_frame.linesize[plane - 1] * frame->height; } ext_frame.size = s->frame_size; ext_frame.opaque = NULL; @@ -187,8 +178,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -219,16 +209,16 @@ int main(int argc, char **argv) { struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], - ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -261,8 +251,7 @@ int main(int argc, char **argv) { goto error; } - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -299,8 +288,7 @@ int main(int argc, char **argv) { if (app[i]) { st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->handle) - st20p_tx_free(app[i]->handle); + if (app[i]->handle) st20p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/ext_frame/tx_video_split_sample.c b/app/sample/ext_frame/tx_video_split_sample.c index 66a6eae1b..5850eadbe 100644 --- a/app/sample/ext_frame/tx_video_split_sample.c +++ b/app/sample/ext_frame/tx_video_split_sample.c @@ -27,8 +27,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, int ret = 0; MTL_MAY_UNUSED(meta); - if (!s->handle) - return -EIO; /* not ready */ + if (!s->handle) return -EIO; /* not ready */ /* the fb_idx of each session is not synced here, * which may need to consider in real production */ @@ -42,18 +41,15 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, *next_frame_idx = s->nfi; s->nfi++; - if (s->nfi >= s->fb_cnt) - s->nfi = 0; + if (s->nfi >= s->fb_cnt) s->nfi = 0; s->fb_idx++; - if (s->fb_idx >= s->fb_total) - s->fb_idx = 0; + if (s->fb_idx >= s->fb_total) s->fb_idx = 0; return ret; } -int tx_video_frame_done(void *priv, uint16_t frame_idx, - struct st20_tx_frame_meta *meta) { +int tx_video_frame_done(void *priv, uint16_t frame_idx, struct st20_tx_frame_meta *meta) { struct tv_split_sample_ctx *s = priv; MTL_MAY_UNUSED(frame_idx); MTL_MAY_UNUSED(meta); @@ -93,8 +89,7 @@ int main(int argc, char **argv) { // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = (struct tv_split_sample_ctx *)malloc( - sizeof(struct tv_split_sample_ctx)); + app[i] = (struct tv_split_sample_ctx *)malloc(sizeof(struct tv_split_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -110,7 +105,7 @@ int main(int argc, char **argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_tx"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -163,8 +158,7 @@ int main(int argc, char **argv) { goto error; } if (st.st_size < (app[i]->fb_size * app[i]->fb_cnt)) { - err("%s, %s file size too small %" PRIu64 "\n", __func__, ctx.tx_url, - st.st_size); + err("%s, %s file size too small %" PRIu64 "\n", __func__, ctx.tx_url, st.st_size); close(fd); ret = -EIO; goto error; @@ -217,15 +211,12 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20_tx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20_tx_free(app[i]->handle); info("%s(%d), sent frames %d\n", __func__, i, app[i]->fb_send); free(app[i]); } - if (dma_mem) - mtl_dma_mem_free(ctx.st, dma_mem); + if (dma_mem) mtl_dma_mem_free(ctx.st, dma_mem); /* release sample(st) dev */ if (ctx.st) { diff --git a/app/sample/fwd/rx_st20_tx_st20_split_fwd.c b/app/sample/fwd/rx_st20_tx_st20_split_fwd.c index c0f9a6ed9..74b57ef8f 100644 --- a/app/sample/fwd/rx_st20_tx_st20_split_fwd.c +++ b/app/sample/fwd/rx_st20_tx_st20_split_fwd.c @@ -57,8 +57,7 @@ static int sending_frames_insert(struct split_fwd_sample_ctx *app, return 0; } -static int sending_frames_delete(struct split_fwd_sample_ctx *app, - uint64_t tmstamp) { +static int sending_frames_delete(struct split_fwd_sample_ctx *app, uint64_t tmstamp) { int i; for (i = 0; i < FB_CNT; i++) { struct frame_info *fi = app->sending_frames[i]; @@ -81,22 +80,18 @@ static int sending_frames_delete(struct split_fwd_sample_ctx *app, return 0; } -static int rx_st20_frame_ready(void *priv, void *frame, - struct st20_rx_frame_meta *meta) { +static int rx_st20_frame_ready(void *priv, void *frame, struct st20_rx_frame_meta *meta) { struct split_fwd_sample_ctx *s = (struct split_fwd_sample_ctx *)priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; /* incomplete frame */ - if (!st_is_frame_complete(meta->status) || - meta->tfmt != ST10_TIMESTAMP_FMT_MEDIA_CLK) { + if (!st_is_frame_complete(meta->status) || meta->tfmt != ST10_TIMESTAMP_FMT_MEDIA_CLK) { st20_rx_put_framebuff(s->rx_handle, frame); return -EIO; } - struct frame_info *fi = - (struct frame_info *)malloc(sizeof(struct frame_info)); + struct frame_info *fi = (struct frame_info *)malloc(sizeof(struct frame_info)); if (!fi) { st20_rx_put_framebuff(s->rx_handle, frame); return -EIO; @@ -117,8 +112,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, struct tx_ctx *s = priv; struct split_fwd_sample_ctx *app = s->app; - if (!app->ready) - return -EIO; + if (!app->ready) return -EIO; int ret; int consumer_idx = s->fb_idx; @@ -132,8 +126,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, struct st20_ext_frame ext_frame; ext_frame.buf_addr = fi->frame_addr + s->fb_offset; - ext_frame.buf_iova = - mtl_hp_virt2iova(app->st, fi->frame_addr) + s->fb_offset; + ext_frame.buf_iova = mtl_hp_virt2iova(app->st, fi->frame_addr) + s->fb_offset; ext_frame.buf_len = app->fb_size / 2; st20_tx_set_ext_frame(s->tx_handle, consumer_idx, &ext_frame); @@ -150,8 +143,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, } consumer_idx++; - if (consumer_idx >= FB_CNT) - consumer_idx = 0; + if (consumer_idx >= FB_CNT) consumer_idx = 0; s->fb_idx = consumer_idx; } else { /* not ready */ @@ -168,8 +160,7 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, MTL_MAY_UNUSED(frame_idx); /* try to release the sending frame */ - if (app->ready) - sending_frames_delete(app, meta->timestamp); + if (app->ready) sending_frames_delete(app, meta->timestamp); return 0; } @@ -230,12 +221,10 @@ int main(int argc, char **argv) { ops_rx.name = "st20_fwd"; ops_rx.priv = &app; ops_rx.num_port = 1; - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - ops_rx.udp_port[MTL_SESSION_PORT_P] = - ctx.udp_port; // user config the udp port. + ops_rx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_FRAME_LEVEL; ops_rx.width = ctx.width; @@ -294,8 +283,7 @@ int main(int argc, char **argv) { app.tx[0].fb_offset = 0; /* origin */ app.tx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.tx[2].fb_offset = - (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.tx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.tx[3].fb_offset = app.tx[2].fb_offset + app.tx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; diff --git a/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c index fad7eeaf2..5d2ce57d8 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_downsample_fwd.c @@ -24,8 +24,7 @@ struct rx_st20p_tx_st20p_sample_ctx { static int tx_st20p_frame_available(void *priv) { struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -37,8 +36,7 @@ static int tx_st20p_frame_available(void *priv) { static int rx_st20p_frame_available(void *priv) { struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -56,8 +54,7 @@ static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx *s, tx_frame = st20p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -80,8 +77,7 @@ static void *st20_fwd_st20_thread(void *arg) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -94,8 +90,7 @@ static void *st20_fwd_st20_thread(void *arg) { return NULL; } -static int -rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx *app) { +static int rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx *app) { if (app->tx_handle) { st20p_tx_free(app->tx_handle); app->tx_handle = NULL; @@ -117,8 +112,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -141,7 +135,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -170,7 +164,7 @@ int main(int argc, char **argv) { struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_fwd"; - ops_tx.priv = &app; // app handle register to lib + ops_tx.priv = &app; // app handle register to lib ops_tx.port.num_port = 1; memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); diff --git a/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c index 734cf0118..c8a9c8703 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_downsample_merge_fwd.c @@ -33,8 +33,7 @@ struct merge_fwd_sample_ctx { static int tx_st20p_frame_available(void *priv) { struct merge_fwd_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->tx_wake_mutex); st_pthread_cond_signal(&s->tx_wake_cond); @@ -47,8 +46,7 @@ static int rx_st20p_frame_available(void *priv) { struct rx_ctx *s = priv; struct merge_fwd_sample_ctx *app = s->app; - if (!app->ready) - return -EIO; + if (!app->ready) return -EIO; st_pthread_mutex_lock(&s->rx_wake_mutex); st_pthread_cond_signal(&s->rx_wake_cond); @@ -73,14 +71,12 @@ static void *tx_st20p_fwd_thread(void *args) { frame = st20p_tx_get_frame(tx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->tx_wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); st_pthread_mutex_unlock(&s->tx_wake_mutex); continue; } /* set downsample frame */ - down_frame.linesize[0] = - frame->linesize[0]; /* leave paddings for neighbor frame */ + down_frame.linesize[0] = frame->linesize[0]; /* leave paddings for neighbor frame */ down_frame.width = frame->width / 2; down_frame.height = frame->height / 2; down_frame.fmt = frame->fmt; @@ -97,16 +93,14 @@ static void *tx_st20p_fwd_thread(void *args) { rx_frame = st20p_rx_get_frame(rx_handle); if (!rx_frame) { /* no frame */ st_pthread_mutex_lock(&rx->rx_wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); + if (!s->stop) st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); st_pthread_mutex_unlock(&rx->rx_wake_mutex); continue; } } if (s->sync_tmstamp) { uint64_t tmstamp = rx_frame->timestamp; - if (!tx_tmstamp) - tx_tmstamp = tmstamp; + if (!tx_tmstamp) tx_tmstamp = tmstamp; if (tx_tmstamp < tmstamp) { err("%s, newer timestamp occurs %" PRIu64 ", frame %" PRIu64 " may have dropped packets\n", @@ -213,8 +207,7 @@ int main(int argc, char **argv) { ops_tx.transport_fmt = ctx.fmt; ops_tx.device = ST_PLUGIN_DEVICE_AUTO; ops_tx.framebuff_cnt = ctx.framebuff_cnt; - if (app.sync_tmstamp) - ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; + if (app.sync_tmstamp) ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; ops_tx.notify_frame_available = tx_st20p_frame_available; st20p_tx_handle tx_handle = st20p_tx_create(ctx.st, &ops_tx); if (!tx_handle) { @@ -270,8 +263,7 @@ int main(int argc, char **argv) { st20_get_pgroup(ctx.fmt, &st20_pg); app.rx[0].fb_offset = 0; app.rx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.rx[2].fb_offset = - (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.rx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.rx[3].fb_offset = app.rx[2].fb_offset + app.rx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; diff --git a/app/sample/fwd/rx_st20p_tx_st20p_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_fwd.c index bc59dd878..c18a54ff9 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_fwd.c @@ -41,28 +41,24 @@ static int rx_st20p_enqueue_frame(struct rx_st20p_tx_st20p_sample_ctx *s, s->framebuffs[producer_idx] = frame; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -struct st_frame * -rx_st20p_dequeue_frame(struct rx_st20p_tx_st20p_sample_ctx *s) { +struct st_frame *rx_st20p_dequeue_frame(struct rx_st20p_tx_st20p_sample_ctx *s) { uint16_t consumer_idx = s->framebuff_consumer_idx; struct st_frame *frame = s->framebuffs[consumer_idx]; s->framebuffs[consumer_idx] = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; return frame; } static int st20_fwd_open_logo(struct st_sample_context *ctx, - struct rx_st20p_tx_st20p_sample_ctx *s, - char *file) { + struct rx_st20p_tx_st20p_sample_ctx *s, char *file) { FILE *fp_logo = st_fopen(file, "rb"); if (!fp_logo) { err("%s, open %s fail\n", __func__, file); @@ -100,8 +96,7 @@ static int st20_fwd_open_logo(struct st_sample_context *ctx, static int tx_st20p_frame_done(void *priv, struct st_frame *frame) { struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st20p_rx_handle rx_handle = s->rx_handle; @@ -117,8 +112,7 @@ static int tx_st20p_frame_done(void *priv, struct st_frame *frame) { static int tx_st20p_frame_available(void *priv) { struct rx_st20p_tx_st20p_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -128,11 +122,9 @@ static int tx_st20p_frame_available(void *priv) { } static int rx_st20p_frame_available(void *priv) { - struct rx_st20p_tx_st20p_sample_ctx *s = - (struct rx_st20p_tx_st20p_sample_ctx *)priv; + struct rx_st20p_tx_st20p_sample_ctx *s = (struct rx_st20p_tx_st20p_sample_ctx *)priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -147,8 +139,8 @@ static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx *s, struct st_frame *tx_frame; if (frame->data_size != s->framebuff_size) { - err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, - s->idx, frame->data_size, s->framebuff_size); + err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, s->idx, + frame->data_size, s->framebuff_size); return; } @@ -156,8 +148,7 @@ static void fwd_st20_consume_frame(struct rx_st20p_tx_st20p_sample_ctx *s, tx_frame = st20p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -193,8 +184,7 @@ static void *st20_fwd_st20_thread(void *arg) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -217,8 +207,7 @@ static void *st20_fwd_st20_thread(void *arg) { return NULL; } -static int -rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx *app) { +static int rx_st20p_tx_st20p_free_app(struct rx_st20p_tx_st20p_sample_ctx *app) { if (app->tx_handle) { st20p_tx_free(app->tx_handle); app->tx_handle = NULL; @@ -248,8 +237,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -271,7 +259,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -300,7 +288,7 @@ int main(int argc, char **argv) { struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_fwd"; - ops_tx.priv = &app; // app handle register to lib + ops_tx.priv = &app; // app handle register to lib ops_tx.port.num_port = 1; memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -338,8 +326,7 @@ int main(int argc, char **argv) { ret = -ENOMEM; goto error; } - for (uint16_t j = 0; j < app.framebuff_cnt; j++) - app.framebuffs[j] = NULL; + for (uint16_t j = 0; j < app.framebuff_cnt; j++) app.framebuffs[j] = NULL; app.framebuff_producer_idx = 0; app.framebuff_consumer_idx = 0; diff --git a/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c index b161dfaf7..e185e10e1 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_merge_fwd.c @@ -33,8 +33,7 @@ struct merge_fwd_sample_ctx { static int tx_st20p_frame_available(void *priv) { struct merge_fwd_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->tx_wake_mutex); st_pthread_cond_signal(&s->tx_wake_cond); @@ -47,8 +46,7 @@ static int rx_st20p_frame_available(void *priv) { struct rx_ctx *s = priv; struct merge_fwd_sample_ctx *app = s->app; - if (!app->ready) - return -EIO; + if (!app->ready) return -EIO; st_pthread_mutex_lock(&s->rx_wake_mutex); st_pthread_cond_signal(&s->rx_wake_cond); @@ -72,8 +70,7 @@ static void *tx_st20p_fwd_thread(void *args) { frame = st20p_tx_get_frame(tx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->tx_wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->tx_wake_cond, &s->tx_wake_mutex); st_pthread_mutex_unlock(&s->tx_wake_mutex); continue; } @@ -90,16 +87,14 @@ static void *tx_st20p_fwd_thread(void *args) { rx_frame = st20p_rx_get_frame(rx_handle); if (!rx_frame) { /* no frame */ st_pthread_mutex_lock(&rx->rx_wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); + if (!s->stop) st_pthread_cond_wait(&rx->rx_wake_cond, &rx->rx_wake_mutex); st_pthread_mutex_unlock(&rx->rx_wake_mutex); continue; } } if (s->sync_tmstamp) { uint64_t tmstamp = rx_frame->timestamp; - if (!tx_tmstamp) - tx_tmstamp = tmstamp; + if (!tx_tmstamp) tx_tmstamp = tmstamp; if (tx_tmstamp < tmstamp) { err("%s, newer timestamp occurs %" PRIu64 ", frame %" PRIu64 " may have dropped packets\n", @@ -214,8 +209,7 @@ int main(int argc, char **argv) { ops_tx.transport_fmt = ctx.fmt; ops_tx.device = ST_PLUGIN_DEVICE_AUTO; ops_tx.framebuff_cnt = ctx.framebuff_cnt; - if (app.sync_tmstamp) - ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; + if (app.sync_tmstamp) ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; ops_tx.notify_frame_available = tx_st20p_frame_available; st20p_tx_handle tx_handle = st20p_tx_create(ctx.st, &ops_tx); if (!tx_handle) { @@ -271,8 +265,7 @@ int main(int argc, char **argv) { st20_get_pgroup(ctx.fmt, &st20_pg); app.rx[0].fb_offset = 0; app.rx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.rx[2].fb_offset = - (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.rx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.rx[3].fb_offset = app.rx[2].fb_offset + app.rx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; diff --git a/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c b/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c index 9ff6a5728..54db2feab 100644 --- a/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st20p_split_fwd.c @@ -31,8 +31,7 @@ static int tx_st20p_frame_available(void *priv) { struct tx_ctx *s = priv; struct split_fwd_sample_ctx *app = s->app; - if (!app->ready) - return -EIO; + if (!app->ready) return -EIO; st_pthread_mutex_lock(&s->tx_wake_mutex); st_pthread_cond_signal(&s->tx_wake_cond); @@ -44,8 +43,7 @@ static int tx_st20p_frame_available(void *priv) { static int rx_st20p_frame_available(void *priv) { struct split_fwd_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->rx_wake_mutex); st_pthread_cond_signal(&s->rx_wake_cond); @@ -63,8 +61,7 @@ static void *tx_st20p_fwd_thread(void *args) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->rx_wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->rx_wake_cond, &s->rx_wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->rx_wake_cond, &s->rx_wake_mutex); st_pthread_mutex_unlock(&s->rx_wake_mutex); continue; } @@ -78,8 +75,7 @@ static void *tx_st20p_fwd_thread(void *args) { tx_frame = st20p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&tx->tx_wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&tx->tx_wake_cond, &tx->tx_wake_mutex); + if (!s->stop) st_pthread_cond_wait(&tx->tx_wake_cond, &tx->tx_wake_mutex); st_pthread_mutex_unlock(&tx->tx_wake_mutex); continue; } @@ -155,7 +151,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_rx"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -191,8 +187,8 @@ int main(int argc, char **argv) { ops_tx.name = "st20p_fwd"; ops_tx.priv = tx; ops_tx.port.num_port = 1; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; @@ -227,8 +223,7 @@ int main(int argc, char **argv) { st20_get_pgroup(ctx.fmt, &st20_pg); app.tx[0].fb_offset = 0; app.tx[1].fb_offset = (ctx.width / 2) * st20_pg.size / st20_pg.coverage; - app.tx[2].fb_offset = - (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; + app.tx[2].fb_offset = (ctx.width / 2) * ctx.height * st20_pg.size / st20_pg.coverage; app.tx[3].fb_offset = app.tx[2].fb_offset + app.tx[1].fb_offset; app.fb_size = ctx.width * ctx.height * st20_pg.size / st20_pg.coverage; diff --git a/app/sample/fwd/rx_st20p_tx_st22p_fwd.c b/app/sample/fwd/rx_st20p_tx_st22p_fwd.c index b9fc8ac5b..f0c5c7e5d 100644 --- a/app/sample/fwd/rx_st20p_tx_st22p_fwd.c +++ b/app/sample/fwd/rx_st20p_tx_st22p_fwd.c @@ -26,8 +26,7 @@ struct rx_st20p_tx_st22p_sample_ctx { }; static int st22_fwd_open_logo(struct st_sample_context *ctx, - struct rx_st20p_tx_st22p_sample_ctx *s, - char *file) { + struct rx_st20p_tx_st22p_sample_ctx *s, char *file) { FILE *fp_logo = st_fopen(file, "rb"); if (!fp_logo) { err("%s, open %s fail\n", __func__, file); @@ -64,8 +63,7 @@ static int st22_fwd_open_logo(struct st_sample_context *ctx, static int tx_st22p_frame_available(void *priv) { struct rx_st20p_tx_st22p_sample_ctx *s = priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -75,11 +73,9 @@ static int tx_st22p_frame_available(void *priv) { } static int rx_st20p_frame_available(void *priv) { - struct rx_st20p_tx_st22p_sample_ctx *s = - (struct rx_st20p_tx_st22p_sample_ctx *)priv; + struct rx_st20p_tx_st22p_sample_ctx *s = (struct rx_st20p_tx_st22p_sample_ctx *)priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); st_pthread_cond_signal(&s->wake_cond); @@ -94,8 +90,8 @@ static void fwd_st22_consume_frame(struct rx_st20p_tx_st22p_sample_ctx *s, struct st_frame *tx_frame; if (frame->data_size != s->framebuff_size) { - err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, - s->idx, frame->data_size, s->framebuff_size); + err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, s->idx, + frame->data_size, s->framebuff_size); return; } @@ -103,8 +99,7 @@ static void fwd_st22_consume_frame(struct rx_st20p_tx_st22p_sample_ctx *s, tx_frame = st22p_tx_get_frame(tx_handle); if (!tx_frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -128,8 +123,7 @@ static void *st20_fwd_st22_thread(void *arg) { frame = st20p_rx_get_frame(rx_handle); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -142,8 +136,7 @@ static void *st20_fwd_st22_thread(void *arg) { return NULL; } -static int -rx_st20p_tx_st22p_free_app(struct rx_st20p_tx_st22p_sample_ctx *app) { +static int rx_st20p_tx_st22p_free_app(struct rx_st20p_tx_st22p_sample_ctx *app) { if (app->tx_handle) { st22p_tx_free(app->tx_handle); app->tx_handle = NULL; @@ -170,8 +163,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -192,7 +184,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = &app; // app handle register to lib + ops_rx.priv = &app; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -221,7 +213,7 @@ int main(int argc, char **argv) { struct st22p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st22_fwd"; - ops_tx.priv = &app; // app handle register to lib + ops_tx.priv = &app; // app handle register to lib ops_tx.port.num_port = 1; memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.fwd_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); diff --git a/app/sample/legacy/rx_st20_tx_st20_fwd.c b/app/sample/legacy/rx_st20_tx_st20_fwd.c index 2cd6642cd..3b9e129b4 100644 --- a/app/sample/legacy/rx_st20_tx_st20_fwd.c +++ b/app/sample/legacy/rx_st20_tx_st20_fwd.c @@ -36,8 +36,7 @@ struct rx_st20_tx_st20_sample_ctx { }; static int st20_fwd_open_logo(struct st_sample_context *ctx, - struct rx_st20_tx_st20_sample_ctx *s, - char *file) { + struct rx_st20_tx_st20_sample_ctx *s, char *file) { FILE *fp_logo = st_fopen(file, "rb"); if (!fp_logo) { err("%s, open %s fail\n", __func__, file); @@ -71,8 +70,8 @@ static int st20_fwd_open_logo(struct st_sample_context *ctx, return 0; } -static int rx_st20_enqueue_frame(struct rx_st20_tx_st20_sample_ctx *s, - void *frame, size_t size) { +static int rx_st20_enqueue_frame(struct rx_st20_tx_st20_sample_ctx *s, void *frame, + size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; @@ -85,19 +84,15 @@ static int rx_st20_enqueue_frame(struct rx_st20_tx_st20_sample_ctx *s, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int rx_st20_frame_ready(void *priv, void *frame, - struct st20_rx_frame_meta *meta) { - struct rx_st20_tx_st20_sample_ctx *s = - (struct rx_st20_tx_st20_sample_ctx *)priv; +static int rx_st20_frame_ready(void *priv, void *frame, struct st20_rx_frame_meta *meta) { + struct rx_st20_tx_st20_sample_ctx *s = (struct rx_st20_tx_st20_sample_ctx *)priv; - if (!s->ready) - return -EIO; + if (!s->ready) return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -137,8 +132,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->tx_framebuff_consumer_idx = consumer_idx; } else { /* not ready */ @@ -169,8 +163,8 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, s->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -178,15 +172,15 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, return ret; } -static void rx_fwd_consume_frame(struct rx_st20_tx_st20_sample_ctx *s, - void *frame, size_t frame_size) { +static void rx_fwd_consume_frame(struct rx_st20_tx_st20_sample_ctx *s, void *frame, + size_t frame_size) { uint16_t producer_idx; struct st_tx_frame *framebuff; struct st_frame tx_frame; if (frame_size != s->framebuff_size) { - err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, - s->idx, frame_size, s->framebuff_size); + err("%s(%d), mismatch frame size %" PRIu64 " %" PRIu64 "\n", __func__, s->idx, + frame_size, s->framebuff_size); return; } @@ -223,8 +217,7 @@ static void rx_fwd_consume_frame(struct rx_st20_tx_st20_sample_ctx *s, framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->tx_framebuff_producer_idx = producer_idx; s->fb_fwd++; @@ -242,8 +235,7 @@ static void *fwd_thread(void *arg) { rx_framebuff = &s->framebuffs[consumer_idx]; if (!rx_framebuff->frame) { /* no ready frame */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -255,8 +247,7 @@ static void *fwd_thread(void *arg) { /* point to next */ rx_framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -299,8 +290,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = fwd_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -326,13 +316,12 @@ int main(int argc, char **argv) { ret = -EIO; goto error; } - for (uint16_t j = 0; j < app.framebuff_cnt; j++) - app.framebuffs[j].frame = NULL; + for (uint16_t j = 0; j < app.framebuff_cnt; j++) app.framebuffs[j].frame = NULL; app.framebuff_producer_idx = 0; app.framebuff_consumer_idx = 0; - app.tx_framebuffs = (struct st_tx_frame *)malloc(sizeof(*app.tx_framebuffs) * - app.framebuff_cnt); + app.tx_framebuffs = + (struct st_tx_frame *)malloc(sizeof(*app.tx_framebuffs) * app.framebuff_cnt); if (!app.tx_framebuffs) { err("%s, tx framebuffs ctx malloc fail\n", __func__); ret = -EIO; @@ -348,12 +337,10 @@ int main(int argc, char **argv) { ops_rx.name = "st20_fwd"; ops_rx.priv = &app; ops_rx.num_port = 1; - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - ops_rx.udp_port[MTL_SESSION_PORT_P] = - ctx.udp_port; // user config the udp port. + ops_rx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_FRAME_LEVEL; ops_rx.width = ctx.width; @@ -391,8 +378,7 @@ int main(int argc, char **argv) { ops_tx.interlaced = ctx.interlaced; ops_tx.fmt = ctx.fmt; ops_tx.payload_type = ctx.payload_type; - if (app.zero_copy) - ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; + if (app.zero_copy) ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; ops_tx.framebuff_cnt = app.framebuff_cnt; ops_tx.get_next_frame = tx_video_next_frame; ops_tx.notify_frame_done = tx_video_frame_done; diff --git a/app/sample/legacy/rx_st22_video_sample.c b/app/sample/legacy/rx_st22_video_sample.c index 654d2b832..50047c8bb 100644 --- a/app/sample/legacy/rx_st22_video_sample.c +++ b/app/sample/legacy/rx_st22_video_sample.c @@ -20,8 +20,7 @@ struct rx_st22_sample_ctx { struct st_rx_frame *framebuffs; }; -static int rx_st22_enqueue_frame(struct rx_st22_sample_ctx *s, void *frame, - size_t size) { +static int rx_st22_enqueue_frame(struct rx_st22_sample_ctx *s, void *frame, size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; @@ -34,18 +33,15 @@ static int rx_st22_enqueue_frame(struct rx_st22_sample_ctx *s, void *frame, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static int rx_st22_frame_ready(void *priv, void *frame, - struct st22_rx_frame_meta *meta) { +static int rx_st22_frame_ready(void *priv, void *frame, struct st22_rx_frame_meta *meta) { struct rx_st22_sample_ctx *s = (struct rx_st22_sample_ctx *)priv; - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); int ret = rx_st22_enqueue_frame(s, frame, meta->frame_total_size); @@ -62,8 +58,8 @@ static int rx_st22_frame_ready(void *priv, void *frame, return 0; } -static void st22_decode_frame(struct rx_st22_sample_ctx *s, - void *codestream_addr, size_t codestream_size) { +static void st22_decode_frame(struct rx_st22_sample_ctx *s, void *codestream_addr, + size_t codestream_size) { MTL_MAY_UNUSED(codestream_addr); MTL_MAY_UNUSED(codestream_size); @@ -87,8 +83,7 @@ static void *st22_decode_thread(void *arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -101,8 +96,7 @@ static void *st22_decode_thread(void *arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -119,8 +113,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -136,8 +129,7 @@ int main(int argc, char **argv) { // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = - (struct rx_st22_sample_ctx *)malloc(sizeof(struct rx_st22_sample_ctx)); + app[i] = (struct rx_st22_sample_ctx *)malloc(sizeof(struct rx_st22_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -148,8 +140,8 @@ int main(int argc, char **argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = (struct st_rx_frame *)malloc( - sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = + (struct st_rx_frame *)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -163,7 +155,7 @@ int main(int argc, char **argv) { struct st22_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st22_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -193,8 +185,7 @@ int main(int argc, char **argv) { app[i]->handle = rx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->decode_thread, NULL, st22_decode_thread, - app[i]); + ret = pthread_create(&app[i]->decode_thread, NULL, st22_decode_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -219,8 +210,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_decoded <= 0) { - err("%s(%d), error, no decoded frames %d\n", __func__, i, - app[i]->fb_decoded); + err("%s(%d), error, no decoded frames %d\n", __func__, i, app[i]->fb_decoded); ret = -EIO; } } @@ -228,14 +218,11 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st22_rx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st22_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) - free(app[i]->framebuffs); + if (app[i]->framebuffs) free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/legacy/rx_video_sample.c b/app/sample/legacy/rx_video_sample.c index 2945d7f5e..faee35b46 100644 --- a/app/sample/legacy/rx_video_sample.c +++ b/app/sample/legacy/rx_video_sample.c @@ -23,8 +23,7 @@ struct rv_sample_context { struct st20_ext_frame *ext_frames; }; -static int rx_video_enqueue_frame(struct rv_sample_context *s, void *frame, - size_t size) { +static int rx_video_enqueue_frame(struct rv_sample_context *s, void *frame, size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; @@ -37,8 +36,7 @@ static int rx_video_enqueue_frame(struct rv_sample_context *s, void *frame, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } @@ -47,16 +45,14 @@ static int rx_video_frame_ready(void *priv, void *frame, struct st20_rx_frame_meta *meta) { struct rv_sample_context *s = (struct rv_sample_context *)priv; - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; if (meta->user_meta) { const struct st_frame_user_meta *user_meta = meta->user_meta; if (meta->user_meta_size != sizeof(*user_meta)) { err("%s(%d), user_meta_size wrong\n", __func__, s->idx); } - info("%s(%d), user_meta %d %s\n", __func__, s->idx, user_meta->idx, - user_meta->dummy); + info("%s(%d), user_meta %d %s\n", __func__, s->idx, user_meta->idx, user_meta->dummy); } /* incomplete frame */ @@ -104,8 +100,7 @@ static void *rx_video_frame_thread(void *arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -118,8 +113,7 @@ static void *rx_video_frame_thread(void *arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -135,8 +129,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -151,8 +144,7 @@ int main(int argc, char **argv) { struct rv_sample_context *app[session_num]; // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = - (struct rv_sample_context *)malloc(sizeof(struct rv_sample_context)); + app[i] = (struct rv_sample_context *)malloc(sizeof(struct rv_sample_context)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -163,8 +155,8 @@ int main(int argc, char **argv) { app[i]->framebuff_cnt = ctx.framebuff_cnt; st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - app[i]->framebuffs = (struct st_rx_frame *)malloc( - sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = + (struct st_rx_frame *)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -178,14 +170,14 @@ int main(int argc, char **argv) { struct st20_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20_rx"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_rx.udp_port[MTL_SESSION_PORT_P] = - ctx.udp_port + i * 2; // user config the udp port. + ctx.udp_port + i * 2; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_FRAME_LEVEL; ops_rx.width = ctx.width; @@ -200,15 +192,14 @@ int main(int argc, char **argv) { ops_rx.notify_frame_ready = rx_video_frame_ready; if (ops_rx.ext_frames) { - app[i]->ext_frames = (struct st20_ext_frame *)malloc( - sizeof(*app[i]->ext_frames) * app[i]->framebuff_cnt); + app[i]->ext_frames = (struct st20_ext_frame *)malloc(sizeof(*app[i]->ext_frames) * + app[i]->framebuff_cnt); if (!app[i]->ext_frames) { err("%s(%d), ext_frames malloc fail\n", __func__, i); ret = -ENOMEM; goto error; } - size_t framebuff_size = - st20_frame_size(ops_rx.fmt, ops_rx.width, ops_rx.height); + size_t framebuff_size = st20_frame_size(ops_rx.fmt, ops_rx.width, ops_rx.height); size_t fb_size = framebuff_size * app[i]->framebuff_cnt; /* alloc enough memory to hold framebuffers and map to iova */ mtl_dma_mem_handle dma_mem = mtl_dma_mem_alloc(ctx.st, fb_size); @@ -220,10 +211,8 @@ int main(int argc, char **argv) { app[i]->dma_mem = dma_mem; for (int j = 0; j < app[i]->framebuff_cnt; ++j) { - app[i]->ext_frames[j].buf_addr = - mtl_dma_mem_addr(dma_mem) + j * framebuff_size; - app[i]->ext_frames[j].buf_iova = - mtl_dma_mem_iova(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_addr = mtl_dma_mem_addr(dma_mem) + j * framebuff_size; + app[i]->ext_frames[j].buf_iova = mtl_dma_mem_iova(dma_mem) + j * framebuff_size; app[i]->ext_frames[j].buf_len = framebuff_size; } ops_rx.ext_frames = app[i]->ext_frames; @@ -238,8 +227,7 @@ int main(int argc, char **argv) { app[i]->handle = rx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, - app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -264,8 +252,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); ret = -EIO; } } @@ -273,19 +260,14 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20_rx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->dma_mem) - mtl_dma_mem_free(ctx.st, app[i]->dma_mem); - if (app[i]->framebuffs) - free(app[i]->framebuffs); - if (app[i]->ext_frames) - free(app[i]->ext_frames); + if (app[i]->dma_mem) mtl_dma_mem_free(ctx.st, app[i]->dma_mem); + if (app[i]->framebuffs) free(app[i]->framebuffs); + if (app[i]->ext_frames) free(app[i]->ext_frames); free(app[i]); } diff --git a/app/sample/legacy/tx_st22_video_sample.c b/app/sample/legacy/tx_st22_video_sample.c index 34a5b8f7a..b60e94e60 100644 --- a/app/sample/legacy/tx_st22_video_sample.c +++ b/app/sample/legacy/tx_st22_video_sample.c @@ -38,8 +38,7 @@ static int tx_st22_next_frame(void *priv, uint16_t *next_frame_idx, meta->codestream_size = framebuff->size; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ @@ -66,8 +65,8 @@ static int tx_st22_frame_done(void *priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -75,9 +74,8 @@ static int tx_st22_frame_done(void *priv, uint16_t frame_idx, return ret; } -static void st22_encode_frame(struct tx_st22_sample_ctx *s, - void *codestream_addr, size_t max_codestream_size, - size_t *codestream_size) { +static void st22_encode_frame(struct tx_st22_sample_ctx *s, void *codestream_addr, + size_t max_codestream_size, size_t *codestream_size) { MTL_MAY_UNUSED(codestream_addr); MTL_MAY_UNUSED(max_codestream_size); @@ -98,8 +96,7 @@ static void *st22_encode_thread(void *arg) { framebuff = &s->framebuffs[producer_idx]; if (ST_TX_FRAME_FREE != framebuff->stat) { /* not in free */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -115,8 +112,7 @@ static void *st22_encode_thread(void *arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -133,8 +129,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -150,8 +145,7 @@ int main(int argc, char **argv) { // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = - (struct tx_st22_sample_ctx *)malloc(sizeof(struct tx_st22_sample_ctx)); + app[i] = (struct tx_st22_sample_ctx *)malloc(sizeof(struct tx_st22_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -163,8 +157,8 @@ int main(int argc, char **argv) { st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = (struct st_tx_frame *)malloc( - sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = + (struct st_tx_frame *)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -177,7 +171,7 @@ int main(int argc, char **argv) { struct st22_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st22_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -208,8 +202,7 @@ int main(int argc, char **argv) { app[i]->handle = tx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->encode_thread, NULL, st22_encode_thread, - app[i]); + ret = pthread_create(&app[i]->encode_thread, NULL, st22_encode_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -242,15 +235,12 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st22_tx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st22_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) - free(app[i]->framebuffs); + if (app[i]->framebuffs) free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/legacy/tx_video_sample.c b/app/sample/legacy/tx_video_sample.c index 8c67fa060..addda0cc0 100644 --- a/app/sample/legacy/tx_video_sample.c +++ b/app/sample/legacy/tx_video_sample.c @@ -35,8 +35,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, struct st_tx_frame *framebuff = &s->framebuffs[consumer_idx]; MTL_MAY_UNUSED(meta); - if (!s->handle) - return -EIO; /* not ready */ + if (!s->handle) return -EIO; /* not ready */ st_pthread_mutex_lock(&s->wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { @@ -46,8 +45,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; if (s->has_user_meta) { s->meta.idx = s->fb_send; @@ -71,8 +69,7 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, struct st_tx_frame *framebuff = &s->framebuffs[frame_idx]; MTL_MAY_UNUSED(meta); - if (!s->handle) - return -EIO; /* not ready */ + if (!s->handle) return -EIO; /* not ready */ st_pthread_mutex_lock(&s->wake_mutex); if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { @@ -82,8 +79,8 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -113,8 +110,7 @@ static void *tx_video_frame_thread(void *arg) { framebuff = &s->framebuffs[producer_idx]; if (ST_TX_FRAME_FREE != framebuff->stat) { /* not in free */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -123,8 +119,8 @@ static void *tx_video_frame_thread(void *arg) { struct st20_ext_frame ext_frame; ext_frame.buf_addr = mtl_dma_mem_addr(s->dma_mem) + producer_idx * s->framebuff_size; - ext_frame.buf_iova = mtl_dma_mem_iova(s->dma_mem) + - (mtl_iova_t)producer_idx * s->framebuff_size; + ext_frame.buf_iova = + mtl_dma_mem_iova(s->dma_mem) + (mtl_iova_t)producer_idx * s->framebuff_size; ext_frame.buf_len = s->framebuff_size; st20_tx_set_ext_frame(s->handle, producer_idx, &ext_frame); } else { @@ -136,8 +132,7 @@ static void *tx_video_frame_thread(void *arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -153,8 +148,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -172,8 +166,7 @@ int main(int argc, char **argv) { // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = - (struct tv_sample_context *)malloc(sizeof(struct tv_sample_context)); + app[i] = (struct tv_sample_context *)malloc(sizeof(struct tv_sample_context)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -188,8 +181,8 @@ int main(int argc, char **argv) { app[i]->has_user_meta = true; } app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = (struct st_tx_frame *)malloc( - sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = + (struct st_tx_frame *)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -202,15 +195,14 @@ int main(int argc, char **argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_tx"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - if (ctx.ext_frame) - ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; - ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port + if (ctx.ext_frame) ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; + ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port ops_tx.pacing = ST21_PACING_NARROW; ops_tx.packing = ctx.packing; ops_tx.type = ST20_TYPE_FRAME_LEVEL; @@ -256,8 +248,7 @@ int main(int argc, char **argv) { app[i]->handle = tx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->app_thread, NULL, tx_video_frame_thread, - app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, tx_video_frame_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -290,17 +281,13 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20_tx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->dma_mem) - mtl_dma_mem_free(ctx.st, app[i]->dma_mem); - if (app[i]->framebuffs) - free(app[i]->framebuffs); + if (app[i]->dma_mem) mtl_dma_mem_free(ctx.st, app[i]->dma_mem); + if (app[i]->framebuffs) free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/low_level/rx_rtp_video_sample.c b/app/sample/low_level/rx_rtp_video_sample.c index 801cc944e..3d77b54fa 100644 --- a/app/sample/low_level/rx_rtp_video_sample.c +++ b/app/sample/low_level/rx_rtp_video_sample.c @@ -35,8 +35,7 @@ static void *app_rx_video_rtp_thread(void *arg) { if (!mbuf) { /* no buffer */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -46,8 +45,7 @@ static void *app_rx_video_rtp_thread(void *arg) { /* handle the rtp packet, should not handle the heavy work, if the * st20_rx_get_mbuf is not called timely, the rtp queue in the lib will be * full and rtp will be enqueued fail in the lib, packet will be dropped*/ - if (hdr->base.marker) - s->fb_rec++; + if (hdr->base.marker) s->fb_rec++; /* free to lib */ st20_rx_put_mbuf(s->handle, mbuf); } @@ -62,8 +60,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -79,8 +76,7 @@ int main(int argc, char **argv) { // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = - (struct rv_rtp_sample_ctx *)malloc(sizeof(struct rv_rtp_sample_ctx)); + app[i] = (struct rv_rtp_sample_ctx *)malloc(sizeof(struct rv_rtp_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); return -1; @@ -93,7 +89,7 @@ int main(int argc, char **argv) { struct st20_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -115,8 +111,7 @@ int main(int argc, char **argv) { goto error; } app[i]->handle = rx_handle[i]; - ret = pthread_create(&app[i]->app_thread, NULL, app_rx_video_rtp_thread, - app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, app_rx_video_rtp_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -141,8 +136,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); ret = -EIO; } } @@ -150,10 +144,8 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20_rx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/sample/low_level/rx_slice_video_sample.c b/app/sample/low_level/rx_slice_video_sample.c index 67b332778..29736a417 100644 --- a/app/sample/low_level/rx_slice_video_sample.c +++ b/app/sample/low_level/rx_slice_video_sample.c @@ -35,8 +35,7 @@ static int rx_video_enqueue_frame(struct rv_slice_sample_ctx *s, void *frame, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } @@ -47,8 +46,7 @@ static int rx_video_slice_ready(void *priv, void *frame, MTL_MAY_UNUSED(frame); MTL_MAY_UNUSED(meta); - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; // frame_recv_lines in meta indicate the ready lines for current frame // add the slice handling logic here @@ -61,8 +59,7 @@ static int rx_video_frame_ready(void *priv, void *frame, struct st20_rx_frame_meta *meta) { struct rv_slice_sample_ctx *s = (struct rv_slice_sample_ctx *)priv; - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -109,8 +106,7 @@ static void *rx_video_frame_thread(void *arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -123,8 +119,7 @@ static void *rx_video_frame_thread(void *arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -140,8 +135,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -157,8 +151,7 @@ int main(int argc, char **argv) { // create and register rx session for (int i = 0; i < session_num; i++) { - app[i] = (struct rv_slice_sample_ctx *)malloc( - sizeof(struct rv_slice_sample_ctx)); + app[i] = (struct rv_slice_sample_ctx *)malloc(sizeof(struct rv_slice_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -169,8 +162,8 @@ int main(int argc, char **argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = (struct st_rx_frame *)malloc( - sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = + (struct st_rx_frame *)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -184,14 +177,14 @@ int main(int argc, char **argv) { struct st20_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.num_port = 1; memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_rx.udp_port[MTL_SESSION_PORT_P] = - ctx.udp_port + i * 2; // user config the udp port. + ctx.udp_port + i * 2; // user config the udp port. ops_rx.pacing = ST21_PACING_NARROW; ops_rx.type = ST20_TYPE_SLICE_LEVEL; ops_rx.width = ctx.width; @@ -215,8 +208,7 @@ int main(int argc, char **argv) { app[i]->handle = rx_handle[i]; app[i]->stop = false; - ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, - app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, rx_video_frame_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -241,8 +233,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_rec <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_rec); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_rec); ret = -EIO; } } @@ -250,14 +241,11 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20_rx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20_rx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) - free(app[i]->framebuffs); + if (app[i]->framebuffs) free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/low_level/tx_rtp_video_sample.c b/app/sample/low_level/tx_rtp_video_sample.c index b8b0791af..8da2b9428 100644 --- a/app/sample/low_level/tx_rtp_video_sample.c +++ b/app/sample/low_level/tx_rtp_video_sample.c @@ -30,8 +30,7 @@ static int notify_rtp_done(void *priv) { } static int app_tx_build_rtp_packet(struct tv_rtp_sample_ctx *s, - struct st20_rfc4175_rtp_hdr *rtp, - uint16_t *pkt_len) { + struct st20_rfc4175_rtp_hdr *rtp, uint16_t *pkt_len) { uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); /* update hdr */ @@ -86,14 +85,12 @@ static void *app_tx_rtp_thread(void *arg) { if (mbuf) { st_pthread_mutex_unlock(&s->wake_mutex); } else { - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } } - app_tx_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr *)usrptr, - &mbuf_len); + app_tx_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr *)usrptr, &mbuf_len); st20_tx_put_mbuf(s->handle, mbuf, mbuf_len); } @@ -107,8 +104,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -124,8 +120,7 @@ int main(int argc, char **argv) { // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = - (struct tv_rtp_sample_ctx *)malloc(sizeof(struct tv_rtp_sample_ctx)); + app[i] = (struct tv_rtp_sample_ctx *)malloc(sizeof(struct tv_rtp_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -139,7 +134,7 @@ int main(int argc, char **argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -153,9 +148,8 @@ int main(int argc, char **argv) { ops_tx.fps = ctx.fps; ops_tx.fmt = ctx.fmt; ops_tx.payload_type = ctx.payload_type; - ops_tx.rtp_ring_size = - 1024; // the rtp ring size between app and lib. app is the - // producer, lib is the consumer, should be 2^n + ops_tx.rtp_ring_size = 1024; // the rtp ring size between app and lib. app is the + // producer, lib is the consumer, should be 2^n // app register non-block func, app could get the rtp tx done ops_tx.notify_rtp_done = notify_rtp_done; @@ -210,10 +204,8 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20_tx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/sample/low_level/tx_slice_video_sample.c b/app/sample/low_level/tx_slice_video_sample.c index 8e88f55c9..a1121b4fc 100644 --- a/app/sample/low_level/tx_slice_video_sample.c +++ b/app/sample/low_level/tx_slice_video_sample.c @@ -40,8 +40,7 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ @@ -68,8 +67,8 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -93,8 +92,7 @@ static int tx_video_frame_lines_ready(void *priv, uint16_t frame_idx, } static void tx_video_build_slice(struct tv_slice_sample_ctx *s, - struct st_tx_frame *framebuff, - void *frame_addr) { + struct st_tx_frame *framebuff, void *frame_addr) { int lines_build = 0; int slices = (s->height / s->lines_per_slice) + 1; MTL_MAY_UNUSED(frame_addr); @@ -114,8 +112,7 @@ static void tx_video_build_slice(struct tv_slice_sample_ctx *s, st_pthread_mutex_lock(&s->wake_mutex); lines_build += s->lines_per_slice; - if (lines_build > s->height) - lines_build = s->height; + if (lines_build > s->height) lines_build = s->height; framebuff->lines_ready = lines_build; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -134,17 +131,15 @@ static void *tx_video_slice_thread(void *arg) { consumer_idx = s->framebuff_consumer_idx; framebuff = &s->framebuffs[producer_idx]; /* limit the producer to simulate the slice timing */ - if ((producer_idx != consumer_idx) || - (ST_TX_FRAME_FREE != framebuff->stat)) { + if ((producer_idx != consumer_idx) || (ST_TX_FRAME_FREE != framebuff->stat)) { /* not in free */ - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } - dbg("%s(%d), producer_idx %d consumer_idx %d\n", __func__, s->idx, - producer_idx, consumer_idx); + dbg("%s(%d), producer_idx %d consumer_idx %d\n", __func__, s->idx, producer_idx, + consumer_idx); void *frame_addr = st20_tx_get_framebuffer(s->handle, producer_idx); framebuff->size = s->framebuff_size; @@ -153,8 +148,7 @@ static void *tx_video_slice_thread(void *arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); @@ -172,8 +166,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -189,8 +182,7 @@ int main(int argc, char **argv) { // create and register tx session for (int i = 0; i < session_num; i++) { - app[i] = (struct tv_slice_sample_ctx *)malloc( - sizeof(struct tv_slice_sample_ctx)); + app[i] = (struct tv_slice_sample_ctx *)malloc(sizeof(struct tv_slice_sample_ctx)); if (!app[i]) { err("%s(%d), app context malloc fail\n", __func__, i); ret = -ENOMEM; @@ -201,8 +193,8 @@ int main(int argc, char **argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); app[i]->framebuff_cnt = ctx.framebuff_cnt; - app[i]->framebuffs = (struct st_tx_frame *)malloc( - sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); + app[i]->framebuffs = + (struct st_tx_frame *)malloc(sizeof(*app[i]->framebuffs) * app[i]->framebuff_cnt); if (!app[i]->framebuffs) { err("%s(%d), framebuffs ctx malloc fail\n", __func__, i); ret = -ENOMEM; @@ -216,13 +208,13 @@ int main(int argc, char **argv) { struct st20_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20_tx"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.num_port = 1; memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); - ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port + ops_tx.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; // udp port ops_tx.pacing = ST21_PACING_NARROW; ops_tx.type = ST20_TYPE_SLICE_LEVEL; ops_tx.width = ctx.width; @@ -249,8 +241,7 @@ int main(int argc, char **argv) { app[i]->framebuff_size = st20_tx_get_framebuffer_size(tx_handle[i]); app[i]->height = ops_tx.height; app[i]->lines_per_slice = app[i]->height / 30; - ret = pthread_create(&app[i]->app_thread, NULL, tx_video_slice_thread, - app[i]); + ret = pthread_create(&app[i]->app_thread, NULL, tx_video_slice_thread, app[i]); if (ret < 0) { err("%s(%d), app_thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -283,15 +274,12 @@ int main(int argc, char **argv) { error: // release session for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; - if (app[i]->handle) - st20_tx_free(app[i]->handle); + if (!app[i]) continue; + if (app[i]->handle) st20_tx_free(app[i]->handle); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); - if (app[i]->framebuffs) - free(app[i]->framebuffs); + if (app[i]->framebuffs) free(app[i]->framebuffs); free(app[i]); } diff --git a/app/sample/msvc/imtl_sample/imtl_sample.cpp b/app/sample/msvc/imtl_sample/imtl_sample.cpp index 15e52ed28..8319c307c 100644 --- a/app/sample/msvc/imtl_sample/imtl_sample.cpp +++ b/app/sample/msvc/imtl_sample/imtl_sample.cpp @@ -22,18 +22,16 @@ static mtl_handle g_st = NULL; void signalHandler(int signum) { std::cout << "SIGINT received - exiting!\n"; switch (signum) { - case SIGINT: - stop = true; - if (g_st != NULL) - mtl_abort(g_st); - break; + case SIGINT: + stop = true; + if (g_st != NULL) mtl_abort(g_st); + break; } } int main() { int ret = 0; - std::cout << "Starting MTL sample..." << std::endl - << mtl_version() << std::endl; + std::cout << "Starting MTL sample..." << std::endl << mtl_version() << std::endl; std::signal(SIGINT, signalHandler); @@ -121,8 +119,7 @@ int main() { cv.notify_one(); frame_thread.join(); - if (tx_handle) - st20p_tx_free(tx_handle); + if (tx_handle) st20p_tx_free(tx_handle); /* uninit mtl */ if (st != NULL) { diff --git a/app/sample/rdma/rdma_rx.c b/app/sample/rdma/rdma_rx.c index 376500f53..6153cd921 100644 --- a/app/sample/rdma/rdma_rx.c +++ b/app/sample/rdma/rdma_rx.c @@ -99,16 +99,13 @@ int main(int argc, char **argv) { } out: - if (rx) - mtl_rdma_rx_free(rx); + if (rx) mtl_rdma_rx_free(rx); for (int i = 0; i < 3; i++) { - if (buffers[i]) - free(buffers[i]); + if (buffers[i]) free(buffers[i]); } - if (mrh) - mtl_rdma_uinit(mrh); + if (mrh) mtl_rdma_uinit(mrh); return 0; } \ No newline at end of file diff --git a/app/sample/rdma/rdma_tx.c b/app/sample/rdma/rdma_tx.c index 5f70b4d28..eb5a2afa5 100644 --- a/app/sample/rdma/rdma_tx.c +++ b/app/sample/rdma/rdma_tx.c @@ -93,8 +93,8 @@ int main(int argc, char **argv) { } meta[meta_idx] = buffer_acked; - snprintf((char *)buffer->addr, buffer->capacity, - "Hello, RDMA! id %d acked %d", i, meta[meta_idx]); + snprintf((char *)buffer->addr, buffer->capacity, "Hello, RDMA! id %d acked %d", i, + meta[meta_idx]); buffer->size = strlen((char *)buffer->addr) + 1; buffer->user_meta = &meta[meta_idx]; buffer->user_meta_size = sizeof(int); @@ -118,16 +118,13 @@ int main(int argc, char **argv) { out: - if (tx) - mtl_rdma_tx_free(tx); + if (tx) mtl_rdma_tx_free(tx); for (int i = 0; i < 3; i++) { - if (buffers[i]) - free(buffers[i]); + if (buffers[i]) free(buffers[i]); } - if (mrh) - mtl_rdma_uinit(mrh); + if (mrh) mtl_rdma_uinit(mrh); return ret; } \ No newline at end of file diff --git a/app/sample/rdma/rdma_video_rx.c b/app/sample/rdma/rdma_video_rx.c index 920de90d5..141b97201 100644 --- a/app/sample/rdma/rdma_video_rx.c +++ b/app/sample/rdma/rdma_video_rx.c @@ -55,9 +55,8 @@ int sdl_init(size_t width, size_t height) { return -1; } - window = - SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); if (!window) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -69,8 +68,8 @@ int sdl_init(size_t width, size_t height) { return -1; } - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, - SDL_TEXTUREACCESS_STREAMING, width, height); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, SDL_TEXTUREACCESS_STREAMING, + width, height); if (!texture) { printf("Texture could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -82,19 +81,16 @@ int sdl_init(size_t width, size_t height) { void sdl_display_frame(void *frame, size_t width, size_t height) { (void)(height); SDL_UpdateTexture(texture, NULL, frame, - width * 2); // Assuming UYVY (2 bytes per pixel) + width * 2); // Assuming UYVY (2 bytes per pixel) SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } void sdl_cleanup() { - if (texture) - SDL_DestroyTexture(texture); - if (renderer) - SDL_DestroyRenderer(renderer); - if (window) - SDL_DestroyWindow(window); + if (texture) SDL_DestroyTexture(texture); + if (renderer) SDL_DestroyRenderer(renderer); + if (window) SDL_DestroyWindow(window); SDL_Quit(); } #endif @@ -215,16 +211,13 @@ int main(int argc, char **argv) { printf("Received %d frames\n", frames_consumed); out: - if (rx) - mtl_rdma_rx_free(rx); + if (rx) mtl_rdma_rx_free(rx); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) - munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); } - if (mrh) - mtl_rdma_uinit(mrh); + if (mrh) mtl_rdma_uinit(mrh); #ifdef APP_HAS_SDL2 sdl_cleanup(); diff --git a/app/sample/rdma/rdma_video_rx_multi.c b/app/sample/rdma/rdma_video_rx_multi.c index dac5efecb..bb682fe56 100644 --- a/app/sample/rdma/rdma_video_rx_multi.c +++ b/app/sample/rdma/rdma_video_rx_multi.c @@ -55,9 +55,8 @@ int sdl_init(size_t width, size_t height) { return -1; } - window = - SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); + window = SDL_CreateWindow("RDMA Frame Display", SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, 640, 360, SDL_WINDOW_SHOWN); if (!window) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -69,8 +68,8 @@ int sdl_init(size_t width, size_t height) { return -1; } - texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, - SDL_TEXTUREACCESS_STREAMING, width, height); + texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_UYVY, SDL_TEXTUREACCESS_STREAMING, + width, height); if (!texture) { printf("Texture could not be created! SDL_Error: %s\n", SDL_GetError()); return -1; @@ -82,19 +81,16 @@ int sdl_init(size_t width, size_t height) { void sdl_display_frame(void *frame, size_t width, size_t height) { (void)(height); SDL_UpdateTexture(texture, NULL, frame, - width * 2); // Assuming UYVY (2 bytes per pixel) + width * 2); // Assuming UYVY (2 bytes per pixel) SDL_RenderClear(renderer); SDL_RenderCopy(renderer, texture, NULL, NULL); SDL_RenderPresent(renderer); } void sdl_cleanup() { - if (texture) - SDL_DestroyTexture(texture); - if (renderer) - SDL_DestroyRenderer(renderer); - if (window) - SDL_DestroyWindow(window); + if (texture) SDL_DestroyTexture(texture); + if (renderer) SDL_DestroyRenderer(renderer); + if (window) SDL_DestroyWindow(window); SDL_Quit(); } #endif @@ -183,8 +179,7 @@ int main(int argc, char **argv) { struct mtl_rdma_buffer *buffer = NULL; struct mtl_rdma_buffer *buffer1 = NULL; while (keep_running) { - if (!buffer) - buffer = mtl_rdma_rx_get_buffer(rx0); + if (!buffer) buffer = mtl_rdma_rx_get_buffer(rx0); if (!buffer) { /* wait for buffer ready */ pthread_mutex_lock(&mtx); @@ -192,8 +187,7 @@ int main(int argc, char **argv) { pthread_mutex_unlock(&mtx); continue; } - if (!buffer1) - buffer1 = mtl_rdma_rx_get_buffer(rx1); + if (!buffer1) buffer1 = mtl_rdma_rx_get_buffer(rx1); if (!buffer1) { /* wait for buffer ready */ pthread_mutex_lock(&mtx); @@ -254,18 +248,14 @@ int main(int argc, char **argv) { printf("Received %d frames\n", frames_consumed); out: - if (rx0) - mtl_rdma_rx_free(rx0); - if (rx1) - mtl_rdma_rx_free(rx1); + if (rx0) mtl_rdma_rx_free(rx0); + if (rx1) mtl_rdma_rx_free(rx1); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) - munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); } - if (mrh) - mtl_rdma_uinit(mrh); + if (mrh) mtl_rdma_uinit(mrh); #ifdef APP_HAS_SDL2 sdl_cleanup(); diff --git a/app/sample/rdma/rdma_video_tx.c b/app/sample/rdma/rdma_video_tx.c index 8d77b60a2..5f58a417a 100644 --- a/app/sample/rdma/rdma_video_tx.c +++ b/app/sample/rdma/rdma_video_tx.c @@ -32,9 +32,8 @@ static void control_fps(struct timespec *start_time) { clock_gettime(CLOCK_MONOTONIC, &end_time); - elapsed_time = - (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + - (end_time.tv_nsec - start_time->tv_nsec); + elapsed_time = (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + + (end_time.tv_nsec - start_time->tv_nsec); time_to_wait = DESIRED_FRAME_DURATION - elapsed_time; if (time_to_wait > 0) { @@ -158,8 +157,7 @@ int main(int argc, char **argv) { struct timespec now; clock_gettime(CLOCK_REALTIME, &now); - uint64_t send_time_ns = - ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; + uint64_t send_time_ns = ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; buffer->size = frame_size; buffer->user_meta = &send_time_ns; @@ -179,16 +177,13 @@ int main(int argc, char **argv) { out: - if (tx) - mtl_rdma_tx_free(tx); + if (tx) mtl_rdma_tx_free(tx); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) - munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); } - if (mrh) - mtl_rdma_uinit(mrh); + if (mrh) mtl_rdma_uinit(mrh); return ret; } \ No newline at end of file diff --git a/app/sample/rdma/rdma_video_tx_multi.c b/app/sample/rdma/rdma_video_tx_multi.c index 5c67a804a..cf1957ada 100644 --- a/app/sample/rdma/rdma_video_tx_multi.c +++ b/app/sample/rdma/rdma_video_tx_multi.c @@ -32,9 +32,8 @@ static void control_fps(struct timespec *start_time) { clock_gettime(CLOCK_MONOTONIC, &end_time); - elapsed_time = - (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + - (end_time.tv_nsec - start_time->tv_nsec); + elapsed_time = (end_time.tv_sec - start_time->tv_sec) * NANOSECONDS_IN_SECOND + + (end_time.tv_nsec - start_time->tv_nsec); time_to_wait = DESIRED_FRAME_DURATION - elapsed_time; if (time_to_wait > 0) { @@ -151,8 +150,7 @@ int main(int argc, char **argv) { struct mtl_rdma_buffer *buffer = NULL; struct mtl_rdma_buffer *buffer1 = NULL; while (keep_running) { - if (!buffer) - buffer = mtl_rdma_tx_get_buffer(tx0); + if (!buffer) buffer = mtl_rdma_tx_get_buffer(tx0); if (!buffer) { /* wait for buffer done */ pthread_mutex_lock(&mtx); @@ -160,8 +158,7 @@ int main(int argc, char **argv) { pthread_mutex_unlock(&mtx); continue; } - if (!buffer1) - buffer1 = mtl_rdma_tx_get_buffer(tx1); + if (!buffer1) buffer1 = mtl_rdma_tx_get_buffer(tx1); if (!buffer1) { /* wait for buffer done */ pthread_mutex_lock(&mtx); @@ -184,8 +181,7 @@ int main(int argc, char **argv) { struct timespec now; clock_gettime(CLOCK_REALTIME, &now); - uint64_t send_time_ns = - ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; + uint64_t send_time_ns = ((uint64_t)now.tv_sec * NANOSECONDS_IN_SECOND) + now.tv_nsec; buffer->size = frame_size / 2; buffer->user_meta = &send_time_ns; @@ -218,18 +214,14 @@ int main(int argc, char **argv) { out: - if (tx0) - mtl_rdma_tx_free(tx0); - if (tx1) - mtl_rdma_tx_free(tx1); + if (tx0) mtl_rdma_tx_free(tx0); + if (tx1) mtl_rdma_tx_free(tx1); for (int i = 0; i < 3; i++) { - if (buffers[i] && buffers[i] != MAP_FAILED) - munmap(buffers[i], frame_size); + if (buffers[i] && buffers[i] != MAP_FAILED) munmap(buffers[i], frame_size); } - if (mrh) - mtl_rdma_uinit(mrh); + if (mrh) mtl_rdma_uinit(mrh); return ret; } \ No newline at end of file diff --git a/app/sample/rx_st20_pipeline_sample.c b/app/sample/rx_st20_pipeline_sample.c index df23816bb..dab9b6a38 100644 --- a/app/sample/rx_st20_pipeline_sample.c +++ b/app/sample/rx_st20_pipeline_sample.c @@ -35,8 +35,7 @@ static int rx_st20p_close_source(struct rx_st20p_sample_ctx *s) { return 0; } -static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, - const char *file) { +static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -66,8 +65,8 @@ static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, fb_cnt, file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, + file, m, f_size); return 0; } @@ -75,11 +74,9 @@ static int rx_st20p_open_source(struct rx_st20p_sample_ctx *s, static void rx_st20p_consume_frame(struct rx_st20p_sample_ctx *s, struct st_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) - return; /* no dump */ + if (s->dst_fd < 0) return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) - s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; } @@ -120,8 +117,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -151,7 +147,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = ctx.param.num_ports; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -159,8 +155,8 @@ int main(int argc, char **argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], - ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -198,8 +194,7 @@ int main(int argc, char **argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -214,8 +209,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st20p_rx_wake_block(app[i]->handle); + if (app[i]->handle) st20p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -225,8 +219,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); ret = -EIO; } } @@ -234,8 +227,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st20p_rx_free(app[i]->handle); + if (app[i]->handle) st20p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st20p_auto_detect_sample.c b/app/sample/rx_st20p_auto_detect_sample.c index f8e586e74..664273bb6 100644 --- a/app/sample/rx_st20p_auto_detect_sample.c +++ b/app/sample/rx_st20p_auto_detect_sample.c @@ -36,8 +36,7 @@ static int rx_st20p_close_source(struct rx_st20p_auto_detect_ctx *s) { return 0; } -static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx *s, - const char *file) { +static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx *s, const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -67,8 +66,8 @@ static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx *s, s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, fb_cnt, file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, + file, m, f_size); return 0; } @@ -76,11 +75,9 @@ static int rx_st20p_open_source(struct rx_st20p_auto_detect_ctx *s, static void rx_st20p_consume_frame(struct rx_st20p_auto_detect_ctx *s, struct st_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) - return; /* no dump */ + if (s->dst_fd < 0) return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) - s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr[0], s->frame_size); s->dst_cursor += s->frame_size; } @@ -114,8 +111,7 @@ static void *rx_st20p_frame_thread(void *arg) { return NULL; } -static int rx_st20p_notify_detected(void *priv, - const struct st20_detect_meta *meta, +static int rx_st20p_notify_detected(void *priv, const struct st20_detect_meta *meta, struct st20_detect_reply *reply) { struct rx_st20p_auto_detect_ctx *s = priv; MTL_MAY_UNUSED(meta); @@ -137,8 +133,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -169,7 +164,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = ctx.param.num_ports; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -177,8 +172,8 @@ int main(int argc, char **argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], - ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -208,8 +203,7 @@ int main(int argc, char **argv) { } app[i]->handle = rx_handle; - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -224,8 +218,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st20p_rx_wake_block(app[i]->handle); + if (app[i]->handle) st20p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -235,8 +228,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); ret = -EIO; } } @@ -244,8 +236,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st20p_rx_free(app[i]->handle); + if (app[i]->handle) st20p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st20p_timing_parser_sample.c b/app/sample/rx_st20p_timing_parser_sample.c index c8cd6bc30..643b2b5d5 100644 --- a/app/sample/rx_st20p_timing_parser_sample.c +++ b/app/sample/rx_st20p_timing_parser_sample.c @@ -63,35 +63,29 @@ static void rx_st20p_tp_stat_init(struct rx_tp_stat *stat) { } static void rx_st20p_tp_stat_print(struct rx_timing_parser_sample_ctx *s, - enum mtl_session_port port, - struct rx_tp_stat *stat) { + enum mtl_session_port port, struct rx_tp_stat *stat) { int idx = s->idx; - info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, - port, stat->compliant_result[ST_RX_TP_COMPLIANT_NARROW], + info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, port, + stat->compliant_result[ST_RX_TP_COMPLIANT_NARROW], stat->compliant_result[ST_RX_TP_COMPLIANT_WIDE], stat->compliant_result[ST_RX_TP_COMPLIANT_FAILED]); - info("%s(%d), CINST MIN %d MAX %d!\n", __func__, idx, stat->cinst_min, - stat->cinst_max); - info("%s(%d), VRX MIN %d MAX %d!\n", __func__, idx, stat->vrx_min, - stat->vrx_max); - info("%s(%d), IPT MIN %d MAX %d!\n", __func__, idx, stat->ipt_min, - stat->ipt_max); - info("%s(%d), FPT MIN %d MAX %d!\n", __func__, idx, stat->fpt_min, - stat->fpt_max); + info("%s(%d), CINST MIN %d MAX %d!\n", __func__, idx, stat->cinst_min, stat->cinst_max); + info("%s(%d), VRX MIN %d MAX %d!\n", __func__, idx, stat->vrx_min, stat->vrx_max); + info("%s(%d), IPT MIN %d MAX %d!\n", __func__, idx, stat->ipt_min, stat->ipt_max); + info("%s(%d), FPT MIN %d MAX %d!\n", __func__, idx, stat->fpt_min, stat->fpt_max); info("%s(%d), LATENCY MIN %d MAX %d!\n", __func__, idx, stat->latency_min, stat->latency_max); - info("%s(%d), RTP OFFSET MIN %d MAX %d!\n", __func__, idx, - stat->rtp_offset_min, stat->rtp_offset_max); - info("%s(%d), RTP TS DELTA MIN %d MAX %d!\n", __func__, idx, - stat->rtp_ts_delta_min, stat->rtp_ts_delta_max); + info("%s(%d), RTP OFFSET MIN %d MAX %d!\n", __func__, idx, stat->rtp_offset_min, + stat->rtp_offset_max); + info("%s(%d), RTP TS DELTA MIN %d MAX %d!\n", __func__, idx, stat->rtp_ts_delta_min, + stat->rtp_ts_delta_max); } static int rx_st20p_tp_consume(struct rx_timing_parser_sample_ctx *s, - enum mtl_session_port port, - struct st20_rx_tp_meta *tp) { + enum mtl_session_port port, struct st20_rx_tp_meta *tp) { if (tp->compliant != ST_RX_TP_COMPLIANT_NARROW) { - dbg("%s(%d), compliant failed %d cause: %s, frame idx %d\n", __func__, - s->idx, tp->compliant, tp->failed_cause, s->fb_recv); + dbg("%s(%d), compliant failed %d cause: %s, frame idx %d\n", __func__, s->idx, + tp->compliant, tp->failed_cause, s->fb_recv); } /* update stat */ @@ -134,10 +128,11 @@ static void *rx_st20p_tp_thread(void *arg) { ret = st20p_rx_timing_parser_critical(handle, &s->pass); if (ret >= 0) { s->pass_get = true; - info("%s(%d), pass critical, cinst narrow %d wide %d, vrx narrow %d " - "wide %d\n", - __func__, idx, s->pass.cinst_max_narrow, s->pass.cinst_max_wide, - s->pass.vrx_max_narrow, s->pass.vrx_max_wide); + info( + "%s(%d), pass critical, cinst narrow %d wide %d, vrx narrow %d " + "wide %d\n", + __func__, idx, s->pass.cinst_max_narrow, s->pass.cinst_max_wide, + s->pass.vrx_max_narrow, s->pass.vrx_max_wide); } } rx_st20p_tp_consume(s, MTL_SESSION_PORT_P, frame->tp[MTL_SESSION_PORT_P]); @@ -159,8 +154,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable hw offload timestamp */ ctx.param.flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; @@ -196,7 +190,7 @@ int main(int argc, char **argv) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st20p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = app[i]->num_port; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -204,8 +198,8 @@ int main(int argc, char **argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], - ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -236,8 +230,7 @@ int main(int argc, char **argv) { } app[i]->handle = rx_handle; - ret = - pthread_create(&app[i]->frame_thread, NULL, rx_st20p_tp_thread, app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st20p_tp_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -266,8 +259,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st20p_rx_wake_block(app[i]->handle); + if (app[i]->handle) st20p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); } @@ -275,8 +267,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); ret = -EIO; } } @@ -284,8 +275,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st20p_rx_free(app[i]->handle); + if (app[i]->handle) st20p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st22_pipeline_sample.c b/app/sample/rx_st22_pipeline_sample.c index c22786500..50b482d62 100644 --- a/app/sample/rx_st22_pipeline_sample.c +++ b/app/sample/rx_st22_pipeline_sample.c @@ -33,8 +33,7 @@ static int rx_st22p_close_source(struct rx_st22p_sample_ctx *s) { return 0; } -static int rx_st22p_open_source(struct rx_st22p_sample_ctx *s, - const char *file) { +static int rx_st22p_open_source(struct rx_st22p_sample_ctx *s, const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 3; @@ -64,8 +63,8 @@ static int rx_st22p_open_source(struct rx_st22p_sample_ctx *s, s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, fb_cnt, file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, + file, m, f_size); return 0; } @@ -73,11 +72,9 @@ static int rx_st22p_open_source(struct rx_st22p_sample_ctx *s, static void rx_st22p_consume_frame(struct rx_st22p_sample_ctx *s, struct st_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) - return; /* no dump */ + if (s->dst_fd < 0) return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) - s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; uint8_t planes = st_frame_fmt_planes(frame->fmt); uint8_t *dst = s->dst_cursor; @@ -116,8 +113,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -146,7 +142,7 @@ int main(int argc, char **argv) { struct st22p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st22p_sample"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = 1; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -188,8 +184,7 @@ int main(int argc, char **argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st22p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st22p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -204,8 +199,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st22p_rx_wake_block(app[i]->handle); + if (app[i]->handle) st22p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -215,8 +209,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); ret = -EIO; } } @@ -224,8 +217,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st22p_rx_free(app[i]->handle); + if (app[i]->handle) st22p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/rx_st30_pipeline_sample.c b/app/sample/rx_st30_pipeline_sample.c index 9f302d2c1..42bb89ad3 100644 --- a/app/sample/rx_st30_pipeline_sample.c +++ b/app/sample/rx_st30_pipeline_sample.c @@ -35,8 +35,7 @@ static int rx_st30p_close_source(struct rx_st30p_sample_ctx *s) { return 0; } -static int rx_st30p_open_source(struct rx_st30p_sample_ctx *s, - const char *file) { +static int rx_st30p_open_source(struct rx_st30p_sample_ctx *s, const char *file) { int fd, ret, idx = s->idx; off_t f_size; int fb_cnt = 1000 * 10; /* dump 10s */ @@ -66,8 +65,8 @@ static int rx_st30p_open_source(struct rx_st30p_sample_ctx *s, s->dst_cursor = m; s->dst_end = m + f_size; s->dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, fb_cnt, file, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, fb_cnt, + file, m, f_size); return 0; } @@ -75,11 +74,9 @@ static int rx_st30p_open_source(struct rx_st30p_sample_ctx *s, static void rx_st30p_consume_frame(struct rx_st30p_sample_ctx *s, struct st30_frame *frame) { s->fb_recv++; - if (s->dst_fd < 0) - return; /* no dump */ + if (s->dst_fd < 0) return; /* no dump */ - if (s->dst_cursor + s->frame_size > s->dst_end) - s->dst_cursor = s->dst_begin; + if (s->dst_cursor + s->frame_size > s->dst_end) s->dst_cursor = s->dst_begin; mtl_memcpy(s->dst_cursor, frame->addr, s->frame_size); s->dst_cursor += s->frame_size; } @@ -112,8 +109,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = rx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -143,7 +139,7 @@ int main(int argc, char **argv) { struct st30p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "st30p_test"; - ops_rx.priv = app[i]; // app handle register to lib + ops_rx.priv = app[i]; // app handle register to lib ops_rx.port.num_port = ctx.param.num_ports; memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx.rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); @@ -151,8 +147,8 @@ int main(int argc, char **argv) { ctx.param.port[MTL_PORT_P]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ctx.audio_udp_port + i * 2; if (ops_rx.port.num_port > 1) { - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], - ctx.rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_R], ctx.rx_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_R] = ctx.audio_udp_port + i * 2; @@ -171,9 +167,8 @@ int main(int argc, char **argv) { ops_rx.ptime = ctx.audio_ptime; /* set frame size to 10ms time */ - int framebuff_size = - st30_calculate_framebuff_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, - ops_rx.channel, 10 * NS_PER_MS, NULL); + int framebuff_size = st30_calculate_framebuff_size( + ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel, 10 * NS_PER_MS, NULL); ops_rx.framebuff_size = framebuff_size; st30p_rx_handle rx_handle = st30p_rx_create(ctx.st, &ops_rx); @@ -193,8 +188,7 @@ int main(int argc, char **argv) { } } - ret = pthread_create(&app[i]->frame_thread, NULL, rx_st30p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, rx_st30p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -209,8 +203,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st30p_rx_wake_block(app[i]->handle); + if (app[i]->handle) st30p_rx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), received frames %d\n", __func__, i, app[i]->fb_recv); @@ -220,8 +213,7 @@ int main(int argc, char **argv) { // check result for (int i = 0; i < session_num; i++) { if (app[i]->fb_recv <= 0) { - err("%s(%d), error, no received frames %d\n", __func__, i, - app[i]->fb_recv); + err("%s(%d), error, no received frames %d\n", __func__, i, app[i]->fb_recv); ret = -EIO; } } @@ -229,8 +221,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st30p_rx_free(app[i]->handle); + if (app[i]->handle) st30p_rx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/sample_util.c b/app/sample/sample_util.c index 5d2cddeb2..6fe3c426b 100644 --- a/app/sample/sample_util.c +++ b/app/sample/sample_util.c @@ -151,328 +151,324 @@ static struct option sample_args_options[] = { {0, 0, 0, 0}}; -static int sample_args_parse_tx_mac(struct st_sample_context *ctx, - char *mac_str, enum mtl_port port) { +static int sample_args_parse_tx_mac(struct st_sample_context *ctx, char *mac_str, + enum mtl_port port) { int ret; uint8_t *mac; - if (!mac_str) - return -EIO; + if (!mac_str) return -EIO; dbg("%s, tx dst mac %s\n", __func__, mac_str); mac = &ctx->tx_dst_mac[port][0]; - ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], - &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); - if (ret < 0) - return ret; + ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], &mac[1], + &mac[2], &mac[3], &mac[4], &mac[5]); + if (ret < 0) return ret; ctx->has_tx_dst_mac[port] = true; return 0; } -static int _sample_parse_args(struct st_sample_context *ctx, int argc, - char **argv) { +static int _sample_parse_args(struct st_sample_context *ctx, int argc, char **argv) { int cmd = -1, optIdx = 0; struct mtl_init_params *p = &ctx->param; while (1) { cmd = getopt_long_only(argc, argv, "hv", sample_args_options, &optIdx); - if (cmd == -1) - break; + if (cmd == -1) break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case SAMPLE_ARG_P_PORT: - snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); - p->num_ports++; - break; - case SAMPLE_ARG_R_PORT: - snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); - p->num_ports++; - break; - case SAMPLE_ARG_DMA_PORT: - snprintf(p->dma_dev_port[0], sizeof(p->dma_dev_port[0]), "%s", optarg); - p->num_dma_dev_port = 1; - break; - case SAMPLE_ARG_P_SIP: - inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); - break; - case SAMPLE_ARG_R_SIP: - inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); - break; - case SAMPLE_ARG_UDP_PORT: - ctx->udp_port = atoi(optarg); - ctx->audio_udp_port = atoi(optarg); - break; - case SAMPLE_ARG_PAYLOAD_TYPE: - ctx->payload_type = atoi(optarg); - ctx->audio_payload_type = atoi(optarg); - break; - case SAMPLE_ARG_FPS: { - enum st_fps fps = st_name_to_fps(optarg); - if (fps < ST_FPS_MAX) { - ctx->fps = fps; - } else { - err("%s, unknown fps name %s\n", __func__, optarg); - } - break; - } - case SAMPLE_ARG_INTERLACED: - ctx->interlaced = true; - break; - case SAMPLE_ARG_P_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); - break; - case SAMPLE_ARG_P_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); - break; - case SAMPLE_ARG_P_FWD_IP: - inet_pton(AF_INET, optarg, ctx->fwd_dip_addr[MTL_PORT_P]); - break; - case SAMPLE_ARG_P_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); - break; - case SAMPLE_ARG_P_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); - break; - case SAMPLE_ARG_R_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); - break; - case SAMPLE_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case SAMPLE_ARG_DEV_AUTO_START: - p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; - break; - case SAMPLE_ARG_SHARED_TX_QUEUES: - p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - break; - case SAMPLE_ARG_SHARED_RX_QUEUES: - p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - break; - case SAMPLE_ARG_PTP_TSC: - p->flags |= MTL_FLAG_PTP_SOURCE_TSC; - break; - case SAMPLE_ARG_LIB_PTP: - p->flags |= MTL_FLAG_PTP_ENABLE; - break; - case SAMPLE_ARG_UDP_LCORE: - p->flags |= MTL_FLAG_UDP_LCORE; - break; - case SAMPLE_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; port++) - p->net_proto[port] = MTL_PROTO_DHCP; - break; - case SAMPLE_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case SAMPLE_ARG_PACING_WAY: - if (!strcmp(optarg, "auto")) - p->pacing = ST21_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - p->pacing = ST21_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsn")) - p->pacing = ST21_TX_PACING_WAY_TSN; - else if (!strcmp(optarg, "tsc")) - p->pacing = ST21_TX_PACING_WAY_TSC; - else if (!strcmp(optarg, "tsc_narrow")) - p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; - else if (!strcmp(optarg, "ptp")) - p->pacing = ST21_TX_PACING_WAY_PTP; - else if (!strcmp(optarg, "be")) - p->pacing = ST21_TX_PACING_WAY_BE; - else - err("%s, unknow pacing way %s\n", __func__, optarg); - break; - case SAMPLE_ARG_NB_TX_DESC: - p->nb_tx_desc = atoi(optarg); - break; - case SAMPLE_ARG_NB_RX_DESC: - p->nb_rx_desc = atoi(optarg); - break; - case SAMPLE_ARG_RX_BURST_SZ: - ctx->rx_burst_size = atoi(optarg); - break; - case SAMPLE_ARG_QUEUES_CNT: - for (int i = 0; i < MTL_PORT_MAX; i++) { - p->rx_queues_cnt[i] = atoi(optarg); - p->tx_queues_cnt[i] = p->rx_queues_cnt[i]; + case SAMPLE_ARG_P_PORT: + snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); + p->num_ports++; + break; + case SAMPLE_ARG_R_PORT: + snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); + p->num_ports++; + break; + case SAMPLE_ARG_DMA_PORT: + snprintf(p->dma_dev_port[0], sizeof(p->dma_dev_port[0]), "%s", optarg); + p->num_dma_dev_port = 1; + break; + case SAMPLE_ARG_P_SIP: + inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); + break; + case SAMPLE_ARG_R_SIP: + inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); + break; + case SAMPLE_ARG_UDP_PORT: + ctx->udp_port = atoi(optarg); + ctx->audio_udp_port = atoi(optarg); + break; + case SAMPLE_ARG_PAYLOAD_TYPE: + ctx->payload_type = atoi(optarg); + ctx->audio_payload_type = atoi(optarg); + break; + case SAMPLE_ARG_FPS: { + enum st_fps fps = st_name_to_fps(optarg); + if (fps < ST_FPS_MAX) { + ctx->fps = fps; + } else { + err("%s, unknown fps name %s\n", __func__, optarg); + } + break; } - break; - case SAMPLE_ARG_P_TX_DST_MAC: - sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); - break; - case SAMPLE_ARG_R_TX_DST_MAC: - sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); - break; - case SAMPLE_ARG_TX_URL: - snprintf(ctx->tx_url, sizeof(ctx->tx_url), "%s", optarg); - snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); - break; - case SAMPLE_ARG_RX_URL: - snprintf(ctx->rx_url, sizeof(ctx->rx_url), "%s", optarg); - snprintf(ctx->rx_audio_url, sizeof(ctx->rx_audio_url), "%s", optarg); - break; - case SAMPLE_ARG_AUDIO_FMT: - if (!strcmp(optarg, "pcm8")) - ctx->audio_fmt = ST30_FMT_PCM8; - else if (!strcmp(optarg, "pcm16")) - ctx->audio_fmt = ST30_FMT_PCM16; - else if (!strcmp(optarg, "pcm24")) - ctx->audio_fmt = ST30_FMT_PCM24; - else if (!strcmp(optarg, "am824")) - ctx->audio_fmt = ST31_FMT_AM824; - else - err("%s, unknow audio_fmt %s\n", __func__, optarg); - break; - case SAMPLE_ARG_AUDIO_CHANNEL: - ctx->audio_channel = atoi(optarg); - break; - case SAMPLE_ARG_AUDIO_SAMPLING: - if (!strcmp(optarg, "48k")) - ctx->audio_sampling = ST30_SAMPLING_48K; - else if (!strcmp(optarg, "96k")) - ctx->audio_sampling = ST30_SAMPLING_96K; - else if (!strcmp(optarg, "44k")) - ctx->audio_sampling = ST31_SAMPLING_44K; - else - err("%s, unknow audio_sampling %s\n", __func__, optarg); - break; - case SAMPLE_ARG_AUDIO_PTIME: - if (!strcmp(optarg, "1ms")) { - ctx->audio_ptime = ST30_PTIME_1MS; - } else if (!strcmp(optarg, "125us")) { - ctx->audio_ptime = ST30_PTIME_125US; + case SAMPLE_ARG_INTERLACED: + ctx->interlaced = true; + break; + case SAMPLE_ARG_P_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); + break; + case SAMPLE_ARG_P_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); + break; + case SAMPLE_ARG_P_FWD_IP: + inet_pton(AF_INET, optarg, ctx->fwd_dip_addr[MTL_PORT_P]); + break; + case SAMPLE_ARG_P_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); + break; + case SAMPLE_ARG_P_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); + break; + case SAMPLE_ARG_R_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); + break; + case SAMPLE_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case SAMPLE_ARG_DEV_AUTO_START: + p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; + break; + case SAMPLE_ARG_SHARED_TX_QUEUES: + p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + break; + case SAMPLE_ARG_SHARED_RX_QUEUES: + p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + break; + case SAMPLE_ARG_PTP_TSC: + p->flags |= MTL_FLAG_PTP_SOURCE_TSC; + break; + case SAMPLE_ARG_LIB_PTP: + p->flags |= MTL_FLAG_PTP_ENABLE; + break; + case SAMPLE_ARG_UDP_LCORE: + p->flags |= MTL_FLAG_UDP_LCORE; + break; + case SAMPLE_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; port++) + p->net_proto[port] = MTL_PROTO_DHCP; + break; + case SAMPLE_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case SAMPLE_ARG_PACING_WAY: + if (!strcmp(optarg, "auto")) + p->pacing = ST21_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + p->pacing = ST21_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsn")) + p->pacing = ST21_TX_PACING_WAY_TSN; + else if (!strcmp(optarg, "tsc")) + p->pacing = ST21_TX_PACING_WAY_TSC; + else if (!strcmp(optarg, "tsc_narrow")) + p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; + else if (!strcmp(optarg, "ptp")) + p->pacing = ST21_TX_PACING_WAY_PTP; + else if (!strcmp(optarg, "be")) + p->pacing = ST21_TX_PACING_WAY_BE; + else + err("%s, unknow pacing way %s\n", __func__, optarg); + break; + case SAMPLE_ARG_NB_TX_DESC: + p->nb_tx_desc = atoi(optarg); + break; + case SAMPLE_ARG_NB_RX_DESC: + p->nb_rx_desc = atoi(optarg); + break; + case SAMPLE_ARG_RX_BURST_SZ: + ctx->rx_burst_size = atoi(optarg); + break; + case SAMPLE_ARG_QUEUES_CNT: for (int i = 0; i < MTL_PORT_MAX; i++) { - p->tx_queues_cnt[i] += 2; + p->rx_queues_cnt[i] = atoi(optarg); + p->tx_queues_cnt[i] = p->rx_queues_cnt[i]; + } + break; + case SAMPLE_ARG_P_TX_DST_MAC: + sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); + break; + case SAMPLE_ARG_R_TX_DST_MAC: + sample_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); + break; + case SAMPLE_ARG_TX_URL: + snprintf(ctx->tx_url, sizeof(ctx->tx_url), "%s", optarg); + snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); + break; + case SAMPLE_ARG_RX_URL: + snprintf(ctx->rx_url, sizeof(ctx->rx_url), "%s", optarg); + snprintf(ctx->rx_audio_url, sizeof(ctx->rx_audio_url), "%s", optarg); + break; + case SAMPLE_ARG_AUDIO_FMT: + if (!strcmp(optarg, "pcm8")) + ctx->audio_fmt = ST30_FMT_PCM8; + else if (!strcmp(optarg, "pcm16")) + ctx->audio_fmt = ST30_FMT_PCM16; + else if (!strcmp(optarg, "pcm24")) + ctx->audio_fmt = ST30_FMT_PCM24; + else if (!strcmp(optarg, "am824")) + ctx->audio_fmt = ST31_FMT_AM824; + else + err("%s, unknow audio_fmt %s\n", __func__, optarg); + break; + case SAMPLE_ARG_AUDIO_CHANNEL: + ctx->audio_channel = atoi(optarg); + break; + case SAMPLE_ARG_AUDIO_SAMPLING: + if (!strcmp(optarg, "48k")) + ctx->audio_sampling = ST30_SAMPLING_48K; + else if (!strcmp(optarg, "96k")) + ctx->audio_sampling = ST30_SAMPLING_96K; + else if (!strcmp(optarg, "44k")) + ctx->audio_sampling = ST31_SAMPLING_44K; + else + err("%s, unknow audio_sampling %s\n", __func__, optarg); + break; + case SAMPLE_ARG_AUDIO_PTIME: + if (!strcmp(optarg, "1ms")) { + ctx->audio_ptime = ST30_PTIME_1MS; + } else if (!strcmp(optarg, "125us")) { + ctx->audio_ptime = ST30_PTIME_125US; + for (int i = 0; i < MTL_PORT_MAX; i++) { + p->tx_queues_cnt[i] += 2; + } + } else { + err("%s, unknow audio_ptime %s\n", __func__, optarg); + } + break; + case SAMPLE_ARG_LOGO_URL: + snprintf(ctx->logo_url, sizeof(ctx->rx_url), "%s", optarg); + break; + case SAMPLE_ARG_WIDTH: + ctx->width = atoi(optarg); + break; + case SAMPLE_ARG_HEIGHT: + ctx->height = atoi(optarg); + break; + case SAMPLE_ARG_SESSIONS_CNT: + ctx->sessions = atoi(optarg); + break; + case SAMPLE_ARG_EXT_FRAME: + ctx->ext_frame = true; + break; + case SAMPLE_ARG_ST22_CODEC: + ctx->st22p_codec = st_name_to_codec(optarg); + break; + case SAMPLE_ARG_PIPELINE_FMT: { + enum st_frame_fmt fmt = st_frame_name_to_fmt(optarg); + if (fmt < ST_FRAME_FMT_MAX) { + ctx->input_fmt = fmt; + ctx->output_fmt = fmt; + } else { + err("%s, unknown fmt %s\n", __func__, optarg); } - } else { - err("%s, unknow audio_ptime %s\n", __func__, optarg); + break; } - break; - case SAMPLE_ARG_LOGO_URL: - snprintf(ctx->logo_url, sizeof(ctx->rx_url), "%s", optarg); - break; - case SAMPLE_ARG_WIDTH: - ctx->width = atoi(optarg); - break; - case SAMPLE_ARG_HEIGHT: - ctx->height = atoi(optarg); - break; - case SAMPLE_ARG_SESSIONS_CNT: - ctx->sessions = atoi(optarg); - break; - case SAMPLE_ARG_EXT_FRAME: - ctx->ext_frame = true; - break; - case SAMPLE_ARG_ST22_CODEC: - ctx->st22p_codec = st_name_to_codec(optarg); - break; - case SAMPLE_ARG_PIPELINE_FMT: { - enum st_frame_fmt fmt = st_frame_name_to_fmt(optarg); - if (fmt < ST_FRAME_FMT_MAX) { - ctx->input_fmt = fmt; - ctx->output_fmt = fmt; - } else { - err("%s, unknown fmt %s\n", __func__, optarg); + case SAMPLE_ARG_TRANSPORT_FMT: { + enum st20_fmt fmt = st20_name_to_fmt(optarg); + if (fmt < ST20_FMT_MAX) { + ctx->fmt = fmt; + } else { + err("%s, unknown fmt %s\n", __func__, optarg); + } + break; } - break; - } - case SAMPLE_ARG_TRANSPORT_FMT: { - enum st20_fmt fmt = st20_name_to_fmt(optarg); - if (fmt < ST20_FMT_MAX) { - ctx->fmt = fmt; - } else { - err("%s, unknown fmt %s\n", __func__, optarg); - } - break; - } - case SAMPLE_ARG_PACKING: - if (!strcmp(optarg, "bpm")) - ctx->packing = ST20_PACKING_BPM; - else if (!strcmp(optarg, "gpm")) - ctx->packing = ST20_PACKING_GPM; - else if (!strcmp(optarg, "gpm_sl")) - ctx->packing = ST20_PACKING_GPM_SL; - else - err("%s, unknown codec %s\n", __func__, optarg); - break; - case SAMPLE_ARG_UDP_MODE: - if (!strcmp(optarg, "default")) - ctx->udp_mode = SAMPLE_UDP_DEFAULT; - else if (!strcmp(optarg, "transport")) - ctx->udp_mode = SAMPLE_UDP_TRANSPORT; - else if (!strcmp(optarg, "transport_poll")) - ctx->udp_mode = SAMPLE_UDP_TRANSPORT_POLL; - else if (!strcmp(optarg, "transport_unify_poll")) - ctx->udp_mode = SAMPLE_UDP_TRANSPORT_UNIFY_POLL; - else - err("%s, unknow udp_mode %s\n", __func__, optarg); - break; - case SAMPLE_ARG_UDP_TX_BPS_G: - ctx->udp_tx_bps = ((uint64_t)atoi(optarg)) * 1024 * 1024 * 1024; - break; - case SAMPLE_ARG_UDP_LEN: - ctx->udp_len = atoi(optarg); - break; - case SAMPLE_ARG_GDDR_PA: - ctx->gddr_pa = strtol(optarg, NULL, 0); - break; - case SAMPLE_ARG_RX_DUMP: - ctx->rx_dump = true; - break; - case SAMPLE_ARG_USER_META: - ctx->has_user_meta = true; - break; - case SAMPLE_ARG_USE_CPU_COPY: - ctx->use_cpu_copy = true; - break; - case SAMPLE_ARG_PROFILING_GDDR: - ctx->profiling_gddr = true; - break; - case SAMPLE_ARG_PERF_FRAMES: - ctx->perf_frames = atoi(optarg); - break; - case SAMPLE_ARG_PERF_FB_CNT: - ctx->perf_fb_cnt = atoi(optarg); - break; - case SAMPLE_ARG_MULTI_INC_ADDR: - ctx->multi_inc_addr = true; - break; - case SAMPLE_ARG_LCORES: - p->lcores = optarg; - break; - case '?': - break; - default: - break; + case SAMPLE_ARG_PACKING: + if (!strcmp(optarg, "bpm")) + ctx->packing = ST20_PACKING_BPM; + else if (!strcmp(optarg, "gpm")) + ctx->packing = ST20_PACKING_GPM; + else if (!strcmp(optarg, "gpm_sl")) + ctx->packing = ST20_PACKING_GPM_SL; + else + err("%s, unknown codec %s\n", __func__, optarg); + break; + case SAMPLE_ARG_UDP_MODE: + if (!strcmp(optarg, "default")) + ctx->udp_mode = SAMPLE_UDP_DEFAULT; + else if (!strcmp(optarg, "transport")) + ctx->udp_mode = SAMPLE_UDP_TRANSPORT; + else if (!strcmp(optarg, "transport_poll")) + ctx->udp_mode = SAMPLE_UDP_TRANSPORT_POLL; + else if (!strcmp(optarg, "transport_unify_poll")) + ctx->udp_mode = SAMPLE_UDP_TRANSPORT_UNIFY_POLL; + else + err("%s, unknow udp_mode %s\n", __func__, optarg); + break; + case SAMPLE_ARG_UDP_TX_BPS_G: + ctx->udp_tx_bps = ((uint64_t)atoi(optarg)) * 1024 * 1024 * 1024; + break; + case SAMPLE_ARG_UDP_LEN: + ctx->udp_len = atoi(optarg); + break; + case SAMPLE_ARG_GDDR_PA: + ctx->gddr_pa = strtol(optarg, NULL, 0); + break; + case SAMPLE_ARG_RX_DUMP: + ctx->rx_dump = true; + break; + case SAMPLE_ARG_USER_META: + ctx->has_user_meta = true; + break; + case SAMPLE_ARG_USE_CPU_COPY: + ctx->use_cpu_copy = true; + break; + case SAMPLE_ARG_PROFILING_GDDR: + ctx->profiling_gddr = true; + break; + case SAMPLE_ARG_PERF_FRAMES: + ctx->perf_frames = atoi(optarg); + break; + case SAMPLE_ARG_PERF_FB_CNT: + ctx->perf_fb_cnt = atoi(optarg); + break; + case SAMPLE_ARG_MULTI_INC_ADDR: + ctx->multi_inc_addr = true; + break; + case SAMPLE_ARG_LCORES: + p->lcores = optarg; + break; + case '?': + break; + default: + break; } }; @@ -485,13 +481,11 @@ static void sample_sig_handler(int signo) { info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - ctx->exit = true; - if (ctx->st) - mtl_abort(ctx->st); - if (ctx->sig_handler) - ctx->sig_handler(signo); - break; + case SIGINT: /* Interrupt from keyboard */ + ctx->exit = true; + if (ctx->st) mtl_abort(ctx->st); + if (ctx->sig_handler) ctx->sig_handler(signo); + break; } return; @@ -507,8 +501,8 @@ static int sample_set_afxdp(struct st_sample_context *ctx) { return 0; } -int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, - bool tx, bool rx, bool unicast) { +int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, bool tx, + bool rx, bool unicast) { struct mtl_init_params *p = &ctx->param; g_sample_ctx = ctx; @@ -545,8 +539,7 @@ int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, snprintf(p->dma_dev_port[0], MTL_PORT_MAX_LEN, "%s", "0000:80:04.0"); - if (!ctx->sessions) - ctx->sessions = 1; + if (!ctx->sessions) ctx->sessions = 1; ctx->framebuff_cnt = 3; ctx->width = 1920; ctx->height = 1080; @@ -582,13 +575,10 @@ int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, _sample_parse_args(ctx, argc, argv); /* always enable 1 port */ - if (!p->num_ports) - p->num_ports = 1; + if (!p->num_ports) p->num_ports = 1; - if (tx && !p->tx_queues_cnt[0]) - sample_tx_queue_cnt_set(ctx, ctx->sessions); - if (rx && !p->rx_queues_cnt[0]) - sample_rx_queue_cnt_set(ctx, ctx->sessions); + if (tx && !p->tx_queues_cnt[0]) sample_tx_queue_cnt_set(ctx, ctx->sessions); + if (rx && !p->rx_queues_cnt[0]) sample_rx_queue_cnt_set(ctx, ctx->sessions); sample_set_afxdp(ctx); return 0; @@ -602,13 +592,11 @@ int rx_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv) { return sample_parse_args(ctx, argc, argv, false, true, false); }; -int fwd_sample_parse_args(struct st_sample_context *ctx, int argc, - char **argv) { +int fwd_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv) { return sample_parse_args(ctx, argc, argv, true, true, false); }; -int dma_sample_parse_args(struct st_sample_context *ctx, int argc, - char **argv) { +int dma_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv) { /* init sample(st) dev */ sample_parse_args(ctx, argc, argv, false, false, false); /* enable dma port */ @@ -636,8 +624,7 @@ int sample_rx_queue_cnt_set(struct st_sample_context *ctx, uint16_t cnt) { return 0; } -void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be *data, - int w, int h) { +void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be *data, int w, int h) { int pg_size = w * h / 2; uint16_t cb, y0, cr, y1; /* 10 bit */ @@ -665,8 +652,7 @@ void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be *data, } } -void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be *data, - int w, int h) { +void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be *data, int w, int h) { int pg_size = w * h / 2; uint16_t cb, y0, cr, y1; /* 12 bit */ diff --git a/app/sample/sample_util.h b/app/sample/sample_util.h index 5a81e46ad..56420e7cf 100644 --- a/app/sample/sample_util.h +++ b/app/sample/sample_util.h @@ -27,26 +27,26 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #define ST_SAMPLE_URL_MAX_LEN (256) @@ -144,8 +144,8 @@ struct st_frame_user_meta { char dummy[512]; }; -int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, - bool tx, bool rx, bool unicast); +int sample_parse_args(struct st_sample_context *ctx, int argc, char **argv, bool tx, + bool rx, bool unicast); int tx_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv); @@ -155,11 +155,9 @@ int fwd_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv); int dma_sample_parse_args(struct st_sample_context *ctx, int argc, char **argv); -void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be *data, - int w, int h); +void fill_rfc4175_422_10_pg2_data(struct st20_rfc4175_422_10_pg2_be *data, int w, int h); -void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be *data, - int w, int h); +void fill_rfc4175_422_12_pg2_data(struct st20_rfc4175_422_12_pg2_be *data, int w, int h); /* Monotonic time (in nanoseconds) since some unspecified starting point. */ static inline uint64_t sample_get_monotonic_time() { diff --git a/app/sample/tx_st20_pipeline_sample.c b/app/sample/tx_st20_pipeline_sample.c index 2033d9954..7f7f00029 100644 --- a/app/sample/tx_st20_pipeline_sample.c +++ b/app/sample/tx_st20_pipeline_sample.c @@ -59,8 +59,8 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx *s, char *file) { return -EIO; } if (i.st_size % s->frame_size) { - err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", - __func__, file, s->frame_size); + err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", __func__, file, + s->frame_size); close(fd); return -EIO; } @@ -79,21 +79,16 @@ static int tx_st20p_open_source(struct tx_st20p_sample_ctx *s, char *file) { s->source_begin = mtl_hp_zmalloc(s->st, fbs_size, MTL_PORT_P); if (!s->source_begin) { err("%s, source malloc on hugepage fail\n", __func__); - if (m) - munmap(m, i.st_size); - if (fd >= 0) - close(fd); + if (m) munmap(m, i.st_size); + if (fd >= 0) close(fd); return -EIO; } s->frame_cursor = s->source_begin; - if (m) - mtl_memcpy(s->source_begin, m, fbs_size); + if (m) mtl_memcpy(s->source_begin, m, fbs_size); s->source_end = s->source_begin + fbs_size; - if (m) - munmap(m, i.st_size); - if (fd >= 0) - close(fd); + if (m) munmap(m, i.st_size); + if (fd >= 0) close(fd); return 0; } @@ -107,8 +102,7 @@ static int tx_st20p_frame_done(void *priv, struct st_frame *frame) { return 0; } -static void tx_st20p_build_frame(struct tx_st20p_sample_ctx *s, - struct st_frame *frame) { +static void tx_st20p_build_frame(struct tx_st20p_sample_ctx *s, struct st_frame *frame) { uint8_t *src = s->frame_cursor; mtl_memcpy(frame->addr[0], src, s->frame_size); @@ -127,8 +121,7 @@ static void *tx_st20p_frame_thread(void *arg) { continue; } - if (s->source_begin) - tx_st20p_build_frame(s, frame); + if (s->source_begin) tx_st20p_build_frame(s, frame); if (s->has_user_meta) { s->meta.idx = s->fb_send; frame->user_meta = &s->meta; @@ -156,8 +149,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -183,24 +175,23 @@ int main(int argc, char **argv) { app[i]->idx = i; app[i]->stop = false; if (ctx.has_user_meta) { - snprintf(app[i]->meta.dummy, sizeof(app[i]->meta.dummy), "st20p_tx_%d", - i); + snprintf(app[i]->meta.dummy, sizeof(app[i]->meta.dummy), "st20p_tx_%d", i); app[i]->has_user_meta = true; } struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st20p_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], - ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -239,8 +230,7 @@ int main(int argc, char **argv) { goto error; } - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st20p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -255,8 +245,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st20p_tx_wake_block(app[i]->handle); + if (app[i]->handle) st20p_tx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), sent frames %d(done %d)\n", __func__, i, app[i]->fb_send, app[i]->fb_send_done); @@ -275,8 +264,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st20p_tx_free(app[i]->handle); + if (app[i]->handle) st20p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/tx_st22_pipeline_sample.c b/app/sample/tx_st22_pipeline_sample.c index 710dcf826..f7b1f05d3 100644 --- a/app/sample/tx_st22_pipeline_sample.c +++ b/app/sample/tx_st22_pipeline_sample.c @@ -122,8 +122,7 @@ static int tx_st22p_open_source(struct st_sample_context *ctx, return 0; } -static void tx_st22p_build_frame(struct tx_st22p_sample_ctx *s, - struct st_frame *frame) { +static void tx_st22p_build_frame(struct tx_st22p_sample_ctx *s, struct st_frame *frame) { if (s->frame_cursor + s->frame_size > s->source_end) { s->frame_cursor = s->source_begin; } @@ -132,8 +131,8 @@ static void tx_st22p_build_frame(struct tx_st22p_sample_ctx *s, uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint8_t plane = 0; plane < planes; plane++) { size_t plane_sz = st_frame_plane_size(frame, plane); - dbg("%s(%d), src frame, plane %u size %" PRIu64 " addr %p\n", __func__, - s->idx, plane, plane_sz, frame->addr[plane]); + dbg("%s(%d), src frame, plane %u size %" PRIu64 " addr %p\n", __func__, s->idx, plane, + plane_sz, frame->addr[plane]); dbg("%s(%d), plane %u src addr %p\n", __func__, s->idx, plane, src); mtl_memcpy(frame->addr[plane], src, plane_sz); src += plane_sz; @@ -159,8 +158,7 @@ static void *tx_st22p_frame_thread(void *arg) { warn("%s(%d), get frame time out\n", __func__, s->idx); continue; } - if (s->source_begin) - tx_st22p_build_frame(s, frame); + if (s->source_begin) tx_st22p_build_frame(s, frame); st22p_tx_put_frame(handle, frame); s->fb_send++; } @@ -177,8 +175,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -207,16 +204,16 @@ int main(int argc, char **argv) { struct st22p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st22p_sample"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], - ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.udp_port + i * 2; @@ -238,8 +235,7 @@ int main(int argc, char **argv) { ops_tx.quality = ST22_QUALITY_MODE_QUALITY; ops_tx.codec_thread_cnt = 2; ops_tx.codestream_size = ops_tx.width * ops_tx.height * bpp / 8; - if (ops_tx.interlaced) - ops_tx.codestream_size /= 2; + if (ops_tx.interlaced) ops_tx.codestream_size /= 2; ops_tx.framebuff_cnt = ctx.framebuff_cnt; ops_tx.flags = ST22P_TX_FLAG_BLOCK_GET; @@ -254,8 +250,7 @@ int main(int argc, char **argv) { app[i]->frame_size = st22p_tx_frame_size(tx_handle); ret = tx_st22p_open_source(&ctx, app[i], ctx.tx_url); - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st22p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st22p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -270,8 +265,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st22p_tx_wake_block(app[i]->handle); + if (app[i]->handle) st22p_tx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), sent frames %d\n", __func__, i, app[i]->fb_send); @@ -289,8 +283,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st22p_tx_free(app[i]->handle); + if (app[i]->handle) st22p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/sample/tx_st30_pipeline_sample.c b/app/sample/tx_st30_pipeline_sample.c index 7912aa57b..8ad985fec 100644 --- a/app/sample/tx_st30_pipeline_sample.c +++ b/app/sample/tx_st30_pipeline_sample.c @@ -56,8 +56,8 @@ static int tx_st30p_open_source(struct tx_st30p_sample_ctx *s, char *file) { return -EIO; } if (i.st_size % s->frame_size) { - err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", - __func__, file, s->frame_size); + err("%s, %s file size should be multiple of frame size %" PRIu64 "\n", __func__, file, + s->frame_size); close(fd); return -EIO; } @@ -75,21 +75,16 @@ static int tx_st30p_open_source(struct tx_st30p_sample_ctx *s, char *file) { s->source_begin = mtl_hp_zmalloc(s->st, fbs_size, MTL_PORT_P); if (!s->source_begin) { err("%s, source malloc on hugepage fail\n", __func__); - if (m) - munmap(m, i.st_size); - if (fd >= 0) - close(fd); + if (m) munmap(m, i.st_size); + if (fd >= 0) close(fd); return -EIO; } s->frame_cursor = s->source_begin; - if (m) - mtl_memcpy(s->source_begin, m, fbs_size); + if (m) mtl_memcpy(s->source_begin, m, fbs_size); s->source_end = s->source_begin + fbs_size; - if (m) - munmap(m, i.st_size); - if (fd >= 0) - close(fd); + if (m) munmap(m, i.st_size); + if (fd >= 0) close(fd); return 0; } @@ -123,8 +118,7 @@ static void *tx_st30p_frame_thread(void *arg) { continue; } - if (s->source_begin) - tx_st30p_build_frame(s, frame); + if (s->source_begin) tx_st30p_build_frame(s, frame); st30p_tx_put_frame(handle, frame); /* point to next frame */ @@ -147,8 +141,7 @@ int main(int argc, char **argv) { /* init sample(st) dev */ memset(&ctx, 0, sizeof(ctx)); ret = tx_sample_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* enable auto start/stop */ ctx.param.flags |= MTL_FLAG_DEV_AUTO_START_STOP; @@ -177,16 +170,16 @@ int main(int argc, char **argv) { struct st30p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "st30p_test"; - ops_tx.priv = app[i]; // app handle register to lib + ops_tx.priv = app[i]; // app handle register to lib ops_tx.port.num_port = ctx.param.num_ports; - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx.tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx.tx_dip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ctx.audio_udp_port + i * 2; if (ops_tx.port.num_port > 1) { - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], - ctx.tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_R], ctx.tx_dip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx.param.port[MTL_PORT_R]); ops_tx.port.udp_port[MTL_SESSION_PORT_R] = ctx.audio_udp_port + i * 2; @@ -206,9 +199,8 @@ int main(int argc, char **argv) { ops_tx.ptime = ctx.audio_ptime; /* set frame size to 10ms time */ - int framebuff_size = - st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, - ops_tx.channel, 10 * NS_PER_MS, NULL); + int framebuff_size = st30_calculate_framebuff_size( + ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel, 10 * NS_PER_MS, NULL); ops_tx.framebuff_size = framebuff_size; st30p_tx_handle tx_handle = st30p_tx_create(ctx.st, &ops_tx); @@ -225,11 +217,10 @@ int main(int argc, char **argv) { err("%s(%d), open source fail\n", __func__, i); goto error; } - info("%s(%d), frame_size %" PRId64 ", tx url %s\n", __func__, i, - app[i]->frame_size, ctx.tx_audio_url); + info("%s(%d), frame_size %" PRId64 ", tx url %s\n", __func__, i, app[i]->frame_size, + ctx.tx_audio_url); - ret = pthread_create(&app[i]->frame_thread, NULL, tx_st30p_frame_thread, - app[i]); + ret = pthread_create(&app[i]->frame_thread, NULL, tx_st30p_frame_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); ret = -EIO; @@ -244,8 +235,7 @@ int main(int argc, char **argv) { // stop app thread for (int i = 0; i < session_num; i++) { app[i]->stop = true; - if (app[i]->handle) - st30p_tx_wake_block(app[i]->handle); + if (app[i]->handle) st30p_tx_wake_block(app[i]->handle); pthread_join(app[i]->frame_thread, NULL); info("%s(%d), sent frames %d(done %d)\n", __func__, i, app[i]->fb_send, app[i]->fb_send_done); @@ -264,8 +254,7 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { if (app[i]) { - if (app[i]->handle) - st30p_tx_free(app[i]->handle); + if (app[i]->handle) st30p_tx_free(app[i]->handle); free(app[i]); } } diff --git a/app/src/app_base.h b/app/src/app_base.h index 8a1949ec6..a8d07c0bf 100644 --- a/app/src/app_base.h +++ b/app/src/app_base.h @@ -45,7 +45,7 @@ #define ST_APP_DEFAULT_FB_CNT (3) -#define ST_APP_EXPECT_NEAR(val, expect, delta) \ +#define ST_APP_EXPECT_NEAR(val, expect, delta) \ ((val > (expect - delta)) && (val < (expect + delta))) #ifndef NS_PER_S @@ -141,9 +141,9 @@ struct st_app_tx_video_session { /* rtp mode info */ bool st20_rtp_input; - int st20_pkts_in_line; /* GPM only, number of packets per each line, 4 for - 1080p */ - int st20_bytes_in_line; /* bytes per line, 4800 for 1080p yuv422 10bit */ + int st20_pkts_in_line; /* GPM only, number of packets per each line, 4 for + 1080p */ + int st20_bytes_in_line; /* bytes per line, 4800 for 1080p yuv422 10bit */ uint32_t st20_pkt_data_len; /* data len(byte) for each pkt, 1200 for 1080p yuv422 10bit */ struct st20_rfc4175_rtp_hdr st20_rtp_base; @@ -622,9 +622,8 @@ struct st_app_context { struct st_app_tx_st30p_session *tx_st30p_sessions; int tx_st30p_session_cnt; - uint8_t rx_ip_addr[MTL_PORT_MAX][MTL_IP_ADDR_LEN]; /* rx IP */ - uint8_t rx_mcast_sip_addr[MTL_PORT_MAX] - [MTL_IP_ADDR_LEN]; /* rx multicast source IP */ + uint8_t rx_ip_addr[MTL_PORT_MAX][MTL_IP_ADDR_LEN]; /* rx IP */ + uint8_t rx_mcast_sip_addr[MTL_PORT_MAX][MTL_IP_ADDR_LEN]; /* rx multicast source IP */ struct st_app_rx_video_session *rx_video_sessions; int rx_video_session_cnt; @@ -666,16 +665,19 @@ struct st_app_context { int utc_offset; }; -static inline void *st_app_malloc(size_t sz) { return malloc(sz); } +static inline void *st_app_malloc(size_t sz) { + return malloc(sz); +} static inline void *st_app_zmalloc(size_t sz) { void *p = malloc(sz); - if (p) - memset(p, 0x0, sz); + if (p) memset(p, 0x0, sz); return p; } -static inline void st_app_free(void *p) { free(p); } +static inline void st_app_free(void *p) { + free(p); +} static inline uint64_t st_timespec_to_ns(const struct timespec *ts) { return ((uint64_t)ts->tv_sec * NS_PER_S) + ts->tv_nsec; diff --git a/app/src/app_platform.h b/app/src/app_platform.h index 889455003..7a3357308 100644 --- a/app/src/app_platform.h +++ b/app/src/app_platform.h @@ -110,8 +110,7 @@ static inline int st_pthread_cond_init(pthread_cond_t *cond, return pthread_cond_init(cond, cond_attr); } -static inline int st_pthread_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex) { +static inline int st_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } @@ -143,8 +142,8 @@ static inline void st_pause(void) { #endif } -static inline void -st_usleep(useconds_t usec) { // windows usleep function precision is only 1~15ms +static inline void st_usleep( + useconds_t usec) { // windows usleep function precision is only 1~15ms #ifdef WINDOWSENV LARGE_INTEGER delay; HANDLE delay_timer_handle = NULL; diff --git a/app/src/args.c b/app/src/args.c index 7b34dd152..3e7c9cb4f 100644 --- a/app/src/args.c +++ b/app/src/args.c @@ -175,32 +175,24 @@ static struct option st_app_args_options[] = { {"r_rx_mcast_sip", required_argument, 0, ST_ARG_R_RX_MCAST_SIP}, {"tx_video_url", required_argument, 0, ST_ARG_TX_VIDEO_URL}, - {"tx_video_sessions_count", required_argument, 0, - ST_ARG_TX_VIDEO_SESSIONS_CNT}, - {"tx_video_rtp_ring_size", required_argument, 0, - ST_ARG_TX_VIDEO_RTP_RING_SIZE}, + {"tx_video_sessions_count", required_argument, 0, ST_ARG_TX_VIDEO_SESSIONS_CNT}, + {"tx_video_rtp_ring_size", required_argument, 0, ST_ARG_TX_VIDEO_RTP_RING_SIZE}, {"tx_audio_url", required_argument, 0, ST_ARG_TX_AUDIO_URL}, - {"tx_audio_sessions_count", required_argument, 0, - ST_ARG_TX_AUDIO_SESSIONS_CNT}, - {"tx_audio_rtp_ring_size", required_argument, 0, - ST_ARG_TX_AUDIO_RTP_RING_SIZE}, + {"tx_audio_sessions_count", required_argument, 0, ST_ARG_TX_AUDIO_SESSIONS_CNT}, + {"tx_audio_rtp_ring_size", required_argument, 0, ST_ARG_TX_AUDIO_RTP_RING_SIZE}, {"tx_anc_url", required_argument, 0, ST_ARG_TX_ANC_URL}, {"tx_anc_sessions_count", required_argument, 0, ST_ARG_TX_ANC_SESSIONS_CNT}, {"tx_anc_rtp_ring_size", required_argument, 0, ST_ARG_TX_ANC_RTP_RING_SIZE}, {"tx_st22_sessions_count", required_argument, 0, ST22_ARG_TX_SESSIONS_CNT}, {"tx_st22_url", required_argument, 0, ST22_ARG_TX_URL}, - {"rx_video_sessions_count", required_argument, 0, - ST_ARG_RX_VIDEO_SESSIONS_CNT}, + {"rx_video_sessions_count", required_argument, 0, ST_ARG_RX_VIDEO_SESSIONS_CNT}, {"rx_video_file_frames", required_argument, 0, ST_ARG_RX_VIDEO_FILE_FRAMES}, {"rx_video_fb_cnt", required_argument, 0, ST_ARG_RX_VIDEO_FB_CNT}, - {"rx_video_rtp_ring_size", required_argument, 0, - ST_ARG_RX_VIDEO_RTP_RING_SIZE}, + {"rx_video_rtp_ring_size", required_argument, 0, ST_ARG_RX_VIDEO_RTP_RING_SIZE}, {"rx_video_multi_thread", no_argument, 0, ST_ARG_RX_VIDEO_MULTI_THREADS}, - {"rx_audio_sessions_count", required_argument, 0, - ST_ARG_RX_AUDIO_SESSIONS_CNT}, - {"rx_audio_rtp_ring_size", required_argument, 0, - ST_ARG_RX_AUDIO_RTP_RING_SIZE}, + {"rx_audio_sessions_count", required_argument, 0, ST_ARG_RX_AUDIO_SESSIONS_CNT}, + {"rx_audio_rtp_ring_size", required_argument, 0, ST_ARG_RX_AUDIO_RTP_RING_SIZE}, {"rx_audio_dump_time_s", required_argument, 0, ST_ARG_RX_AUDIO_DUMP_TIME_S}, {"rx_anc_sessions_count", required_argument, 0, ST_ARG_RX_ANC_SESSIONS_CNT}, {"rx_st22_sessions_count", required_argument, 0, ST22_ARG_RX_SESSIONS_CNT}, @@ -302,8 +294,7 @@ static struct option st_app_args_options[] = { {0, 0, 0, 0}}; static int app_args_parse_lcores(struct mtl_init_params *p, char *list) { - if (!list) - return -EIO; + if (!list) return -EIO; dbg("%s, lcore list %s\n", __func__, list); p->lcores = list; @@ -315,23 +306,20 @@ static int app_args_parse_tx_mac(struct st_app_context *ctx, char *mac_str, int ret; uint8_t *mac; - if (!mac_str) - return -EIO; + if (!mac_str) return -EIO; dbg("%s, tx dst mac %s\n", __func__, mac_str); mac = &ctx->tx_dst_mac[port][0]; - ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], - &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); - if (ret < 0) - return ret; + ret = sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[0], &mac[1], + &mac[2], &mac[3], &mac[4], &mac[5]); + if (ret < 0) return ret; ctx->has_tx_dst_mac[port] = true; return 0; } static int app_args_dma_dev(struct mtl_init_params *p, char *in_dev) { - if (!in_dev) - return -EIO; + if (!in_dev) return -EIO; char devs[128] = {0}; snprintf(devs, 128 - 1, "%s", in_dev); @@ -339,8 +327,7 @@ static int app_args_dma_dev(struct mtl_init_params *p, char *in_dev) { char *next_dev = strtok(devs, ","); while (next_dev && (p->num_dma_dev_port < MTL_DMA_DEV_MAX)) { dbg("next_dev: %s\n", next_dev); - snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", - next_dev); + snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", next_dev); p->num_dma_dev_port++; next_dev = strtok(NULL, ","); } @@ -375,14 +362,10 @@ static int app_args_json(struct st_app_context *ctx, struct mtl_init_params *p, ctx->rx_st30p_session_cnt = ctx->json_ctx->rx_st30p_session_cnt; ctx->rx_st20r_session_cnt = ctx->json_ctx->rx_st20r_session_cnt; for (int i = 0; i < ctx->json_ctx->num_interfaces; ++i) { - snprintf(p->port[i], sizeof(p->port[i]), "%s", - ctx->json_ctx->interfaces[i].name); - memcpy(p->sip_addr[i], ctx->json_ctx->interfaces[i].ip_addr, - sizeof(p->sip_addr[i])); - memcpy(p->netmask[i], ctx->json_ctx->interfaces[i].netmask, - sizeof(p->netmask[i])); - memcpy(p->gateway[i], ctx->json_ctx->interfaces[i].gateway, - sizeof(p->gateway[i])); + snprintf(p->port[i], sizeof(p->port[i]), "%s", ctx->json_ctx->interfaces[i].name); + memcpy(p->sip_addr[i], ctx->json_ctx->interfaces[i].ip_addr, sizeof(p->sip_addr[i])); + memcpy(p->netmask[i], ctx->json_ctx->interfaces[i].netmask, sizeof(p->netmask[i])); + memcpy(p->gateway[i], ctx->json_ctx->interfaces[i].gateway, sizeof(p->gateway[i])); p->net_proto[i] = ctx->json_ctx->interfaces[i].net_proto; p->tx_queues_cnt[i] = ctx->json_ctx->interfaces[i].tx_queues_cnt; p->rx_queues_cnt[i] = ctx->json_ctx->interfaces[i].rx_queues_cnt; @@ -393,23 +376,16 @@ static int app_args_json(struct st_app_context *ctx, struct mtl_init_params *p, ctx->json_ctx->sch_quota * st20_1080p59_yuv422_10bit_bandwidth_mps(); } if (ctx->json_ctx->tx_audio_sessions_max_per_sch) { - p->tx_audio_sessions_max_per_sch = - ctx->json_ctx->tx_audio_sessions_max_per_sch; + p->tx_audio_sessions_max_per_sch = ctx->json_ctx->tx_audio_sessions_max_per_sch; } if (ctx->json_ctx->rx_audio_sessions_max_per_sch) { - p->rx_audio_sessions_max_per_sch = - ctx->json_ctx->rx_audio_sessions_max_per_sch; + p->rx_audio_sessions_max_per_sch = ctx->json_ctx->rx_audio_sessions_max_per_sch; } - if (ctx->json_ctx->shared_tx_queues) - p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - if (ctx->json_ctx->shared_rx_queues) - p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - if (ctx->json_ctx->tx_no_chain) - p->flags |= MTL_FLAG_TX_NO_CHAIN; - if (ctx->json_ctx->rss_mode) - p->rss_mode = ctx->json_ctx->rss_mode; - if (ctx->json_ctx->log_file) - st_set_mtl_log_file(ctx, ctx->json_ctx->log_file); + if (ctx->json_ctx->shared_tx_queues) p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + if (ctx->json_ctx->shared_rx_queues) p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + if (ctx->json_ctx->tx_no_chain) p->flags |= MTL_FLAG_TX_NO_CHAIN; + if (ctx->json_ctx->rss_mode) p->rss_mode = ctx->json_ctx->rss_mode; + if (ctx->json_ctx->log_file) st_set_mtl_log_file(ctx, ctx->json_ctx->log_file); info("%s, json_file %s succ\n", __func__, json_file); return 0; @@ -426,8 +402,7 @@ static void log_prefix_time_ms(char *buf, size_t sz) { snprintf(buf, sz, "%s.%u, ", time_s_buf, (uint32_t)(ts.tv_nsec / NS_PER_MS)); } -static void log_user_printer(enum mtl_log_level level, const char *format, - ...) { +static void log_user_printer(enum mtl_log_level level, const char *format, ...) { MTL_MAY_UNUSED(level); va_list args; @@ -439,16 +414,14 @@ static void log_user_printer(enum mtl_log_level level, const char *format, va_end(args); } -static int app_args_parse_port(struct st_app_context *ctx, - struct mtl_init_params *p, char *str, - enum mtl_port port) { +static int app_args_parse_port(struct st_app_context *ctx, struct mtl_init_params *p, + char *str, enum mtl_port port) { st_json_context_t *json_ctx = ctx->json_ctx; if (json_ctx) { int json_num_interfaces = json_ctx->num_interfaces; st_json_interface_t *json_interfaces = &json_ctx->interfaces[port]; if (port < json_num_interfaces) { - info("%s, override json interface for port: %d to %s\n", __func__, port, - str); + info("%s, override json interface for port: %d to %s\n", __func__, port, str); snprintf(json_interfaces->name, sizeof(json_interfaces->name), "%s", str); snprintf(p->port[port], sizeof(p->port[port]), "%s", str); } @@ -460,479 +433,477 @@ static int app_args_parse_port(struct st_app_context *ctx, return 0; } -int st_app_parse_args(struct st_app_context *ctx, struct mtl_init_params *p, - int argc, char **argv) { +int st_app_parse_args(struct st_app_context *ctx, struct mtl_init_params *p, int argc, + char **argv) { int cmd = -1, optIdx = 0; int nb; while (1) { cmd = getopt_long_only(argc, argv, "hv", st_app_args_options, &optIdx); - if (cmd == -1) - break; + if (cmd == -1) break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case ST_ARG_P_PORT: - app_args_parse_port(ctx, p, optarg, MTL_PORT_P); - break; - case ST_ARG_R_PORT: - app_args_parse_port(ctx, p, optarg, MTL_PORT_R); - break; - case ST_ARG_P_SIP: - inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); - break; - case ST_ARG_R_SIP: - inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); - break; - case ST_ARG_P_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); - break; - case ST_ARG_R_TX_IP: - inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); - break; - case ST_ARG_P_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); - break; - case ST_ARG_R_RX_IP: - inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); - break; - case ST_ARG_P_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); - break; - case ST_ARG_R_NETMASK: - inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); - break; - case ST_ARG_P_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); - break; - case ST_ARG_R_GATEWAY: - inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); - break; - case ST_ARG_P_RX_MCAST_SIP: - inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_P]); - break; - case ST_ARG_R_RX_MCAST_SIP: - inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_R]); - break; - case ST_ARG_TX_VIDEO_URL: - snprintf(ctx->tx_video_url, sizeof(ctx->tx_video_url), "%s", optarg); - break; - case ST_ARG_TX_VIDEO_RTP_RING_SIZE: - ctx->tx_video_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_TX_VIDEO_SESSIONS_CNT: - ctx->tx_video_session_cnt = atoi(optarg); - break; - case ST_ARG_TX_AUDIO_URL: - snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); - break; - case ST_ARG_TX_AUDIO_SESSIONS_CNT: - ctx->tx_audio_session_cnt = atoi(optarg); - break; - case ST_ARG_TX_AUDIO_RTP_RING_SIZE: - ctx->tx_audio_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_TX_ANC_URL: - snprintf(ctx->tx_anc_url, sizeof(ctx->tx_anc_url), "%s", optarg); - break; - case ST_ARG_TX_ANC_RTP_RING_SIZE: - ctx->tx_anc_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_TX_ANC_SESSIONS_CNT: - ctx->tx_anc_session_cnt = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_SESSIONS_CNT: - ctx->rx_video_session_cnt = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_FILE_FRAMES: - ctx->rx_video_file_frames = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_FB_CNT: - ctx->rx_video_fb_cnt = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_RTP_RING_SIZE: - ctx->rx_video_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_RX_VIDEO_MULTI_THREADS: - ctx->rx_video_multi_thread = true; - break; - case ST_ARG_RX_AUDIO_SESSIONS_CNT: - ctx->rx_audio_session_cnt = atoi(optarg); - break; - case ST_ARG_RX_AUDIO_RTP_RING_SIZE: - ctx->rx_audio_rtp_ring_size = atoi(optarg); - break; - case ST_ARG_RX_AUDIO_DUMP_TIME_S: - ctx->rx_audio_dump_time_s = atoi(optarg); - break; - case ST_ARG_RX_ANC_SESSIONS_CNT: - ctx->rx_anc_session_cnt = atoi(optarg); - break; - case ST22_ARG_TX_SESSIONS_CNT: - ctx->tx_st22_session_cnt = atoi(optarg); - break; - case ST22_ARG_TX_URL: - snprintf(ctx->tx_st22_url, sizeof(ctx->tx_st22_url), "%s", optarg); - break; - case ST22_ARG_RX_SESSIONS_CNT: - ctx->rx_st22_session_cnt = atoi(optarg); - break; - case ST_ARG_HDR_SPLIT: - ctx->enable_hdr_split = true; - break; - case ST_ARG_PACING_WAY: - if (!strcmp(optarg, "auto")) - p->pacing = ST21_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - p->pacing = ST21_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsn")) - p->pacing = ST21_TX_PACING_WAY_TSN; - else if (!strcmp(optarg, "tsc")) + case ST_ARG_P_PORT: + app_args_parse_port(ctx, p, optarg, MTL_PORT_P); + break; + case ST_ARG_R_PORT: + app_args_parse_port(ctx, p, optarg, MTL_PORT_R); + break; + case ST_ARG_P_SIP: + inet_pton(AF_INET, optarg, mtl_p_sip_addr(p)); + break; + case ST_ARG_R_SIP: + inet_pton(AF_INET, optarg, mtl_r_sip_addr(p)); + break; + case ST_ARG_P_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_P]); + break; + case ST_ARG_R_TX_IP: + inet_pton(AF_INET, optarg, ctx->tx_dip_addr[MTL_PORT_R]); + break; + case ST_ARG_P_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_P]); + break; + case ST_ARG_R_RX_IP: + inet_pton(AF_INET, optarg, ctx->rx_ip_addr[MTL_PORT_R]); + break; + case ST_ARG_P_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_P]); + break; + case ST_ARG_R_NETMASK: + inet_pton(AF_INET, optarg, p->netmask[MTL_PORT_R]); + break; + case ST_ARG_P_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_P]); + break; + case ST_ARG_R_GATEWAY: + inet_pton(AF_INET, optarg, p->gateway[MTL_PORT_R]); + break; + case ST_ARG_P_RX_MCAST_SIP: + inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_P]); + break; + case ST_ARG_R_RX_MCAST_SIP: + inet_pton(AF_INET, optarg, ctx->rx_mcast_sip_addr[MTL_PORT_R]); + break; + case ST_ARG_TX_VIDEO_URL: + snprintf(ctx->tx_video_url, sizeof(ctx->tx_video_url), "%s", optarg); + break; + case ST_ARG_TX_VIDEO_RTP_RING_SIZE: + ctx->tx_video_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_TX_VIDEO_SESSIONS_CNT: + ctx->tx_video_session_cnt = atoi(optarg); + break; + case ST_ARG_TX_AUDIO_URL: + snprintf(ctx->tx_audio_url, sizeof(ctx->tx_audio_url), "%s", optarg); + break; + case ST_ARG_TX_AUDIO_SESSIONS_CNT: + ctx->tx_audio_session_cnt = atoi(optarg); + break; + case ST_ARG_TX_AUDIO_RTP_RING_SIZE: + ctx->tx_audio_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_TX_ANC_URL: + snprintf(ctx->tx_anc_url, sizeof(ctx->tx_anc_url), "%s", optarg); + break; + case ST_ARG_TX_ANC_RTP_RING_SIZE: + ctx->tx_anc_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_TX_ANC_SESSIONS_CNT: + ctx->tx_anc_session_cnt = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_SESSIONS_CNT: + ctx->rx_video_session_cnt = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_FILE_FRAMES: + ctx->rx_video_file_frames = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_FB_CNT: + ctx->rx_video_fb_cnt = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_RTP_RING_SIZE: + ctx->rx_video_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_RX_VIDEO_MULTI_THREADS: + ctx->rx_video_multi_thread = true; + break; + case ST_ARG_RX_AUDIO_SESSIONS_CNT: + ctx->rx_audio_session_cnt = atoi(optarg); + break; + case ST_ARG_RX_AUDIO_RTP_RING_SIZE: + ctx->rx_audio_rtp_ring_size = atoi(optarg); + break; + case ST_ARG_RX_AUDIO_DUMP_TIME_S: + ctx->rx_audio_dump_time_s = atoi(optarg); + break; + case ST_ARG_RX_ANC_SESSIONS_CNT: + ctx->rx_anc_session_cnt = atoi(optarg); + break; + case ST22_ARG_TX_SESSIONS_CNT: + ctx->tx_st22_session_cnt = atoi(optarg); + break; + case ST22_ARG_TX_URL: + snprintf(ctx->tx_st22_url, sizeof(ctx->tx_st22_url), "%s", optarg); + break; + case ST22_ARG_RX_SESSIONS_CNT: + ctx->rx_st22_session_cnt = atoi(optarg); + break; + case ST_ARG_HDR_SPLIT: + ctx->enable_hdr_split = true; + break; + case ST_ARG_PACING_WAY: + if (!strcmp(optarg, "auto")) + p->pacing = ST21_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + p->pacing = ST21_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsn")) + p->pacing = ST21_TX_PACING_WAY_TSN; + else if (!strcmp(optarg, "tsc")) + p->pacing = ST21_TX_PACING_WAY_TSC; + else if (!strcmp(optarg, "tsc_narrow")) + p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; + else if (!strcmp(optarg, "ptp")) + p->pacing = ST21_TX_PACING_WAY_PTP; + else if (!strcmp(optarg, "be")) + p->pacing = ST21_TX_PACING_WAY_BE; + else + err("%s, unknow pacing way %s\n", __func__, optarg); + break; + case ST_ARG_START_VRX: + ctx->tx_start_vrx = atoi(optarg); + break; + case ST_ARG_PAD_INTERVAL: + ctx->tx_pad_interval = atoi(optarg); + break; + case ST_ARG_NO_PAD_STATIC: + ctx->tx_no_static_pad = true; + break; + case ST_ARG_TIMESTAMP_FIRST_PKT: + ctx->tx_ts_first_pkt = true; + break; + case ST_ARG_TIMESTAMP_EPOCH: + ctx->tx_ts_epoch = true; + break; + case ST_ARG_TIMESTAMP_DELTA_US: + ctx->tx_ts_delta_us = atoi(optarg); + break; + case ST_ARG_NO_BULK: + ctx->tx_no_bulk = true; + break; + case ST_ARG_TX_DISPLAY: + ctx->tx_display = true; + break; + case ST_ARG_RX_DISPLAY: + ctx->rx_display = true; + break; + case ST_ARG_DISABLE_MIGRATE: + p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; + p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; + break; + case ST_ARG_BIND_NUMA: + p->flags |= MTL_FLAG_BIND_NUMA; + break; + case ST_ARG_NOT_BIND_NUMA: + p->flags |= MTL_FLAG_NOT_BIND_NUMA; + break; + case ST_ARG_FORCE_NUMA: + for (int port = 0; port < MTL_PORT_MAX; port++) { + p->port_params[port].flags |= MTL_PORT_FLAG_FORCE_NUMA; + p->port_params[port].socket_id = atoi(optarg); + } + break; + case ST_ARG_FORCE_TX_VIDEO_NUMA: + ctx->force_tx_video_numa = atoi(optarg); + break; + case ST_ARG_FORCE_RX_VIDEO_NUMA: + ctx->force_rx_video_numa = atoi(optarg); + break; + case ST_ARG_FORCE_TX_AUDIO_NUMA: + ctx->force_tx_audio_numa = atoi(optarg); + break; + case ST_ARG_FORCE_RX_AUDIO_NUMA: + ctx->force_rx_audio_numa = atoi(optarg); + break; + case ST_ARG_SHAPING: + if (!strcmp(optarg, "narrow")) + ctx->tx_pacing_type = ST21_PACING_NARROW; + else if (!strcmp(optarg, "wide")) + ctx->tx_pacing_type = ST21_PACING_WIDE; + else if (!strcmp(optarg, "linear")) + ctx->tx_pacing_type = ST21_PACING_LINEAR; + else + err("%s, unknow shaping way %s\n", __func__, optarg); + break; + case ST_ARG_CONFIG_FILE: + app_args_json(ctx, p, optarg); + break; + case ST_ARG_PTP_UNICAST_ADDR: + p->flags |= MTL_FLAG_PTP_UNICAST_ADDR; + break; + case ST_ARG_CNI_THREAD: + p->flags |= MTL_FLAG_CNI_THREAD; + break; + case ST_ARG_CNI_TASKLET: + p->flags |= MTL_FLAG_CNI_TASKLET; + break; + case ST_ARG_TEST_TIME: + ctx->test_time_s = atoi(optarg); + break; + case ST_ARG_RX_TIMING_PARSER_STAT: + ctx->enable_timing_parser = true; + p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; + break; + case ST_ARG_RX_TIMING_PARSER_META: + ctx->enable_timing_parser_meta = true; + p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; + break; + case ST_ARG_RX_BURST_SZ: + ctx->rx_burst_size = atoi(optarg); + break; + case ST_ARG_RX_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + break; + case ST_ARG_TX_MONO_POOL: + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case ST_ARG_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case ST_ARG_RX_POOL_DATA_SIZE: + p->rx_pool_data_size = atoi(optarg); + break; + case ST_ARG_RX_SEPARATE_VIDEO_LCORE: + p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; + break; + case ST_ARG_RX_MIX_VIDEO_LCORE: + p->flags &= ~MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; + break; + case ST_ARG_DEDICATE_SYS_LCORE: + p->flags |= MTL_FLAG_DEDICATED_SYS_LCORE; + break; + case ST_ARG_TSC_PACING: p->pacing = ST21_TX_PACING_WAY_TSC; - else if (!strcmp(optarg, "tsc_narrow")) - p->pacing = ST21_TX_PACING_WAY_TSC_NARROW; - else if (!strcmp(optarg, "ptp")) - p->pacing = ST21_TX_PACING_WAY_PTP; - else if (!strcmp(optarg, "be")) - p->pacing = ST21_TX_PACING_WAY_BE; - else - err("%s, unknow pacing way %s\n", __func__, optarg); - break; - case ST_ARG_START_VRX: - ctx->tx_start_vrx = atoi(optarg); - break; - case ST_ARG_PAD_INTERVAL: - ctx->tx_pad_interval = atoi(optarg); - break; - case ST_ARG_NO_PAD_STATIC: - ctx->tx_no_static_pad = true; - break; - case ST_ARG_TIMESTAMP_FIRST_PKT: - ctx->tx_ts_first_pkt = true; - break; - case ST_ARG_TIMESTAMP_EPOCH: - ctx->tx_ts_epoch = true; - break; - case ST_ARG_TIMESTAMP_DELTA_US: - ctx->tx_ts_delta_us = atoi(optarg); - break; - case ST_ARG_NO_BULK: - ctx->tx_no_bulk = true; - break; - case ST_ARG_TX_DISPLAY: - ctx->tx_display = true; - break; - case ST_ARG_RX_DISPLAY: - ctx->rx_display = true; - break; - case ST_ARG_DISABLE_MIGRATE: - p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; - p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; - break; - case ST_ARG_BIND_NUMA: - p->flags |= MTL_FLAG_BIND_NUMA; - break; - case ST_ARG_NOT_BIND_NUMA: - p->flags |= MTL_FLAG_NOT_BIND_NUMA; - break; - case ST_ARG_FORCE_NUMA: - for (int port = 0; port < MTL_PORT_MAX; port++) { - p->port_params[port].flags |= MTL_PORT_FLAG_FORCE_NUMA; - p->port_params[port].socket_id = atoi(optarg); - } - break; - case ST_ARG_FORCE_TX_VIDEO_NUMA: - ctx->force_tx_video_numa = atoi(optarg); - break; - case ST_ARG_FORCE_RX_VIDEO_NUMA: - ctx->force_rx_video_numa = atoi(optarg); - break; - case ST_ARG_FORCE_TX_AUDIO_NUMA: - ctx->force_tx_audio_numa = atoi(optarg); - break; - case ST_ARG_FORCE_RX_AUDIO_NUMA: - ctx->force_rx_audio_numa = atoi(optarg); - break; - case ST_ARG_SHAPING: - if (!strcmp(optarg, "narrow")) - ctx->tx_pacing_type = ST21_PACING_NARROW; - else if (!strcmp(optarg, "wide")) - ctx->tx_pacing_type = ST21_PACING_WIDE; - else if (!strcmp(optarg, "linear")) - ctx->tx_pacing_type = ST21_PACING_LINEAR; - else - err("%s, unknow shaping way %s\n", __func__, optarg); - break; - case ST_ARG_CONFIG_FILE: - app_args_json(ctx, p, optarg); - break; - case ST_ARG_PTP_UNICAST_ADDR: - p->flags |= MTL_FLAG_PTP_UNICAST_ADDR; - break; - case ST_ARG_CNI_THREAD: - p->flags |= MTL_FLAG_CNI_THREAD; - break; - case ST_ARG_CNI_TASKLET: - p->flags |= MTL_FLAG_CNI_TASKLET; - break; - case ST_ARG_TEST_TIME: - ctx->test_time_s = atoi(optarg); - break; - case ST_ARG_RX_TIMING_PARSER_STAT: - ctx->enable_timing_parser = true; - p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; - break; - case ST_ARG_RX_TIMING_PARSER_META: - ctx->enable_timing_parser_meta = true; - p->flags |= MTL_FLAG_ENABLE_HW_TIMESTAMP; - break; - case ST_ARG_RX_BURST_SZ: - ctx->rx_burst_size = atoi(optarg); - break; - case ST_ARG_RX_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - break; - case ST_ARG_TX_MONO_POOL: - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case ST_ARG_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case ST_ARG_RX_POOL_DATA_SIZE: - p->rx_pool_data_size = atoi(optarg); - break; - case ST_ARG_RX_SEPARATE_VIDEO_LCORE: - p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; - break; - case ST_ARG_RX_MIX_VIDEO_LCORE: - p->flags &= ~MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; - break; - case ST_ARG_DEDICATE_SYS_LCORE: - p->flags |= MTL_FLAG_DEDICATED_SYS_LCORE; - break; - case ST_ARG_TSC_PACING: - p->pacing = ST21_TX_PACING_WAY_TSC; - break; - case ST_ARG_USER_LCORES: - app_args_parse_lcores(p, optarg); - break; - case ST_ARG_SCH_DATA_QUOTA: - p->data_quota_mbs_per_sch = atoi(optarg); - break; - case ST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ - nb = atoi(optarg); - if (nb > 0 && nb < 100) { - p->data_quota_mbs_per_sch = - nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); - } - break; - case ST_ARG_P_TX_DST_MAC: - app_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); - break; - case ST_ARG_R_TX_DST_MAC: - app_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); - break; - case ST_ARG_NIC_RX_PROMISCUOUS: - p->flags |= MTL_FLAG_NIC_RX_PROMISCUOUS; - break; - case ST_ARG_LIB_PTP: - p->flags |= MTL_FLAG_PTP_ENABLE; - p->ptp_get_time_fn = NULL; /* clear the user ptp func */ - break; - case ST_ARG_LIB_PTP_SYNC_SYS: - p->flags |= MTL_FLAG_PTP_ENABLE; /* enable built-in ptp */ - p->ptp_get_time_fn = NULL; /* clear the user ptp func */ - ctx->ptp_systime_sync = true; - break; - case ST_ARG_LIB_PHC2SYS: - p->flags |= MTL_FLAG_PHC2SYS_ENABLE; - break; - case ST_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - app_set_log_level(p->log_level); - break; - case ST_ARG_LOG_FILE: - st_set_mtl_log_file(ctx, optarg); - break; - case ST_ARG_LOG_TIME_MS: - mtl_set_log_prefix_formatter(log_prefix_time_ms); - break; - case ST_ARG_LOG_PRINTER: - mtl_set_log_printer(log_user_printer); - break; - case ST_ARG_NB_TX_DESC: - p->nb_tx_desc = atoi(optarg); - break; - case ST_ARG_NB_RX_DESC: - p->nb_rx_desc = atoi(optarg); - break; - case ST_ARG_DMA_DEV: - app_args_dma_dev(p, optarg); - break; - case ST_ARG_PCAPNG_DUMP: - ctx->pcapng_max_pkts = atoi(optarg); - break; - case ST_ARG_RUNTIME_SESSION: - ctx->runtime_session = true; - break; - case ST_ARG_TTF_FILE: - snprintf(ctx->ttf_file, sizeof(ctx->ttf_file), "%s", optarg); - break; - case ST_ARG_AF_XDP_ZC_DISABLE: - p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; - break; - case ST_ARG_TASKLET_TIME: - p->flags |= MTL_FLAG_TASKLET_TIME_MEASURE; - break; - case ST_ARG_UTC_OFFSET: - ctx->utc_offset = atoi(optarg); - break; - case ST_ARG_NO_SYSTEM_RX_QUEUES: - p->flags |= MTL_FLAG_DISABLE_SYSTEM_RX_QUEUES; - break; - case ST_ARG_TX_COPY_ONCE: - ctx->tx_copy_once = true; - break; - case ST_ARG_TASKLET_SLEEP: - p->flags |= MTL_FLAG_TASKLET_SLEEP; - break; - case ST_ARG_TASKLET_SLEEP_US: - ctx->var_para.sch_force_sleep_us = atoi(optarg); - break; - case ST_ARG_TASKLET_THREAD: - p->flags |= MTL_FLAG_TASKLET_THREAD; - break; - case ST_ARG_APP_BIND_THREAD: - ctx->app_bind_lcore = false; - break; - case ST_ARG_APP_BIND_LCORE: - ctx->app_bind_lcore = true; - break; - case ST_ARG_RXTX_SIMD_512: - p->flags |= MTL_FLAG_RXTX_SIMD_512; - break; - case ST_ARG_PTP_PI: - p->flags |= MTL_FLAG_PTP_PI; - break; - case ST_ARG_PTP_KP: - p->kp = strtod(optarg, NULL); - break; - case ST_ARG_PTP_KI: - p->ki = strtod(optarg, NULL); - break; - case ST_ARG_PTP_TSC: - p->flags |= MTL_FLAG_PTP_SOURCE_TSC; - break; - case ST_ARG_RANDOM_SRC_PORT: - p->flags |= MTL_FLAG_RANDOM_SRC_PORT; - break; - case ST_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case ST_ARG_TX_NO_CHAIN: - p->flags |= MTL_FLAG_TX_NO_CHAIN; - break; - case ST_ARG_TX_NO_BURST_CHECK: - p->flags |= MTL_FLAG_TX_NO_BURST_CHK; - break; - case ST_ARG_MULTI_SRC_PORT: - p->flags |= MTL_FLAG_MULTI_SRC_PORT; - break; - case ST_ARG_AUDIO_BUILD_PACING: - ctx->tx_audio_build_pacing = true; - break; - case ST_ARG_AUDIO_DEDICATE_QUEUE: - ctx->tx_audio_dedicate_queue = true; - break; - case ST_ARG_AUDIO_TX_PACING: - if (!strcmp(optarg, "auto")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsc")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; - else - err("%s, unknow audio tx pacing %s\n", __func__, optarg); - break; - case ST_ARG_AUDIO_RL_ACCURACY_US: - ctx->tx_audio_rl_accuracy_us = atoi(optarg); - break; - case ST_ARG_AUDIO_RL_OFFSET_US: - ctx->tx_audio_rl_offset_us = atoi(optarg); - break; - case ST_ARG_AUDIO_FIFO_SIZE: - ctx->tx_audio_fifo_size = atoi(optarg); - break; - case ST_ARG_ANC_DEDICATE_QUEUE: - ctx->tx_anc_dedicate_queue = true; - break; - case ST_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; ++port) - p->net_proto[port] = MTL_PROTO_DHCP; - break; - case ST_ARG_IOVA_MODE: - if (!strcmp(optarg, "va")) - p->iova_mode = MTL_IOVA_MODE_VA; - else if (!strcmp(optarg, "pa")) - p->iova_mode = MTL_IOVA_MODE_PA; - else - err("%s, unknow iova mode %s\n", __func__, optarg); - break; - case ST_ARG_SHARED_TX_QUEUES: - p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - break; - case ST_ARG_SHARED_RX_QUEUES: - p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - break; - case ST_ARG_RX_USE_CNI: - p->flags |= MTL_FLAG_RX_USE_CNI; - break; - case ST_ARG_RX_UDP_PORT_ONLY: - p->flags |= MTL_FLAG_RX_UDP_PORT_ONLY; - break; - case ST_ARG_VIRTIO_USER: - p->flags |= MTL_FLAG_VIRTIO_USER; - break; - case ST_ARG_VIDEO_SHA_CHECK: - ctx->video_sha_check = true; - break; - case ST_ARG_ARP_TIMEOUT_S: - p->arp_timeout_s = atoi(optarg); - break; - case ST_ARG_RSS_SCH_NB: - for (enum mtl_port port = MTL_PORT_P; port < MTL_PORT_MAX; port++) { - p->rss_sch_nb[port] = atoi(optarg); - } - break; - case ST_ARG_ALLOW_ACROSS_NUMA_CORE: - p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; - break; - case ST_ARG_NO_MULTICAST: - p->flags |= MTL_FLAG_NO_MULTICAST; - break; - case '?': - break; - default: - break; + break; + case ST_ARG_USER_LCORES: + app_args_parse_lcores(p, optarg); + break; + case ST_ARG_SCH_DATA_QUOTA: + p->data_quota_mbs_per_sch = atoi(optarg); + break; + case ST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ + nb = atoi(optarg); + if (nb > 0 && nb < 100) { + p->data_quota_mbs_per_sch = nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); + } + break; + case ST_ARG_P_TX_DST_MAC: + app_args_parse_tx_mac(ctx, optarg, MTL_PORT_P); + break; + case ST_ARG_R_TX_DST_MAC: + app_args_parse_tx_mac(ctx, optarg, MTL_PORT_R); + break; + case ST_ARG_NIC_RX_PROMISCUOUS: + p->flags |= MTL_FLAG_NIC_RX_PROMISCUOUS; + break; + case ST_ARG_LIB_PTP: + p->flags |= MTL_FLAG_PTP_ENABLE; + p->ptp_get_time_fn = NULL; /* clear the user ptp func */ + break; + case ST_ARG_LIB_PTP_SYNC_SYS: + p->flags |= MTL_FLAG_PTP_ENABLE; /* enable built-in ptp */ + p->ptp_get_time_fn = NULL; /* clear the user ptp func */ + ctx->ptp_systime_sync = true; + break; + case ST_ARG_LIB_PHC2SYS: + p->flags |= MTL_FLAG_PHC2SYS_ENABLE; + break; + case ST_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + app_set_log_level(p->log_level); + break; + case ST_ARG_LOG_FILE: + st_set_mtl_log_file(ctx, optarg); + break; + case ST_ARG_LOG_TIME_MS: + mtl_set_log_prefix_formatter(log_prefix_time_ms); + break; + case ST_ARG_LOG_PRINTER: + mtl_set_log_printer(log_user_printer); + break; + case ST_ARG_NB_TX_DESC: + p->nb_tx_desc = atoi(optarg); + break; + case ST_ARG_NB_RX_DESC: + p->nb_rx_desc = atoi(optarg); + break; + case ST_ARG_DMA_DEV: + app_args_dma_dev(p, optarg); + break; + case ST_ARG_PCAPNG_DUMP: + ctx->pcapng_max_pkts = atoi(optarg); + break; + case ST_ARG_RUNTIME_SESSION: + ctx->runtime_session = true; + break; + case ST_ARG_TTF_FILE: + snprintf(ctx->ttf_file, sizeof(ctx->ttf_file), "%s", optarg); + break; + case ST_ARG_AF_XDP_ZC_DISABLE: + p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; + break; + case ST_ARG_TASKLET_TIME: + p->flags |= MTL_FLAG_TASKLET_TIME_MEASURE; + break; + case ST_ARG_UTC_OFFSET: + ctx->utc_offset = atoi(optarg); + break; + case ST_ARG_NO_SYSTEM_RX_QUEUES: + p->flags |= MTL_FLAG_DISABLE_SYSTEM_RX_QUEUES; + break; + case ST_ARG_TX_COPY_ONCE: + ctx->tx_copy_once = true; + break; + case ST_ARG_TASKLET_SLEEP: + p->flags |= MTL_FLAG_TASKLET_SLEEP; + break; + case ST_ARG_TASKLET_SLEEP_US: + ctx->var_para.sch_force_sleep_us = atoi(optarg); + break; + case ST_ARG_TASKLET_THREAD: + p->flags |= MTL_FLAG_TASKLET_THREAD; + break; + case ST_ARG_APP_BIND_THREAD: + ctx->app_bind_lcore = false; + break; + case ST_ARG_APP_BIND_LCORE: + ctx->app_bind_lcore = true; + break; + case ST_ARG_RXTX_SIMD_512: + p->flags |= MTL_FLAG_RXTX_SIMD_512; + break; + case ST_ARG_PTP_PI: + p->flags |= MTL_FLAG_PTP_PI; + break; + case ST_ARG_PTP_KP: + p->kp = strtod(optarg, NULL); + break; + case ST_ARG_PTP_KI: + p->ki = strtod(optarg, NULL); + break; + case ST_ARG_PTP_TSC: + p->flags |= MTL_FLAG_PTP_SOURCE_TSC; + break; + case ST_ARG_RANDOM_SRC_PORT: + p->flags |= MTL_FLAG_RANDOM_SRC_PORT; + break; + case ST_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case ST_ARG_TX_NO_CHAIN: + p->flags |= MTL_FLAG_TX_NO_CHAIN; + break; + case ST_ARG_TX_NO_BURST_CHECK: + p->flags |= MTL_FLAG_TX_NO_BURST_CHK; + break; + case ST_ARG_MULTI_SRC_PORT: + p->flags |= MTL_FLAG_MULTI_SRC_PORT; + break; + case ST_ARG_AUDIO_BUILD_PACING: + ctx->tx_audio_build_pacing = true; + break; + case ST_ARG_AUDIO_DEDICATE_QUEUE: + ctx->tx_audio_dedicate_queue = true; + break; + case ST_ARG_AUDIO_TX_PACING: + if (!strcmp(optarg, "auto")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsc")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; + else + err("%s, unknow audio tx pacing %s\n", __func__, optarg); + break; + case ST_ARG_AUDIO_RL_ACCURACY_US: + ctx->tx_audio_rl_accuracy_us = atoi(optarg); + break; + case ST_ARG_AUDIO_RL_OFFSET_US: + ctx->tx_audio_rl_offset_us = atoi(optarg); + break; + case ST_ARG_AUDIO_FIFO_SIZE: + ctx->tx_audio_fifo_size = atoi(optarg); + break; + case ST_ARG_ANC_DEDICATE_QUEUE: + ctx->tx_anc_dedicate_queue = true; + break; + case ST_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; ++port) + p->net_proto[port] = MTL_PROTO_DHCP; + break; + case ST_ARG_IOVA_MODE: + if (!strcmp(optarg, "va")) + p->iova_mode = MTL_IOVA_MODE_VA; + else if (!strcmp(optarg, "pa")) + p->iova_mode = MTL_IOVA_MODE_PA; + else + err("%s, unknow iova mode %s\n", __func__, optarg); + break; + case ST_ARG_SHARED_TX_QUEUES: + p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + break; + case ST_ARG_SHARED_RX_QUEUES: + p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + break; + case ST_ARG_RX_USE_CNI: + p->flags |= MTL_FLAG_RX_USE_CNI; + break; + case ST_ARG_RX_UDP_PORT_ONLY: + p->flags |= MTL_FLAG_RX_UDP_PORT_ONLY; + break; + case ST_ARG_VIRTIO_USER: + p->flags |= MTL_FLAG_VIRTIO_USER; + break; + case ST_ARG_VIDEO_SHA_CHECK: + ctx->video_sha_check = true; + break; + case ST_ARG_ARP_TIMEOUT_S: + p->arp_timeout_s = atoi(optarg); + break; + case ST_ARG_RSS_SCH_NB: + for (enum mtl_port port = MTL_PORT_P; port < MTL_PORT_MAX; port++) { + p->rss_sch_nb[port] = atoi(optarg); + } + break; + case ST_ARG_ALLOW_ACROSS_NUMA_CORE: + p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; + break; + case ST_ARG_NO_MULTICAST: + p->flags |= MTL_FLAG_NO_MULTICAST; + break; + case '?': + break; + default: + break; } }; diff --git a/app/src/args.h b/app/src/args.h index ba2ddf9f8..7477bd399 100644 --- a/app/src/args.h +++ b/app/src/args.h @@ -7,7 +7,7 @@ #ifndef _ST_APP_ARGS_HEAD_H_ #define _ST_APP_ARGS_HEAD_H_ -int st_app_parse_args(struct st_app_context *ctx, struct mtl_init_params *p, - int argc, char **argv); +int st_app_parse_args(struct st_app_context *ctx, struct mtl_init_params *p, int argc, + char **argv); #endif diff --git a/app/src/experimental/rx_st20r_app.c b/app/src/experimental/rx_st20r_app.c index fb0245709..7fa9c7a51 100644 --- a/app/src/experimental/rx_st20r_app.c +++ b/app/src/experimental/rx_st20r_app.c @@ -4,8 +4,8 @@ #include "rx_st20r_app.h" -static int app_rx_st20r_enqueue_frame(struct st_app_rx_video_session *s, - void *frame, size_t size) { +static int app_rx_st20r_enqueue_frame(struct st_app_rx_video_session *s, void *frame, + size_t size) { uint16_t producer_idx = s->framebuff_producer_idx; struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; @@ -18,14 +18,13 @@ static int app_rx_st20r_enqueue_frame(struct st_app_rx_video_session *s, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static void app_rx_st20r_consume_frame(struct st_app_rx_video_session *s, - void *frame, size_t frame_size) { +static void app_rx_st20r_consume_frame(struct st_app_rx_video_session *s, void *frame, + size_t frame_size) { struct st_display *d = s->display; if (d && d->front_frame) { @@ -33,8 +32,7 @@ static void app_rx_st20r_consume_frame(struct st_app_rx_video_session *s, if (s->st20_pg.fmt == ST20_FMT_YUV_422_8BIT) mtl_memcpy(d->front_frame, frame, d->front_frame_size); else if (s->st20_pg.fmt == ST20_FMT_YUV_422_10BIT) - st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, - s->height); + st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, s->height); else /* fmt mismatch*/ { st_pthread_mutex_unlock(&d->display_frame_mutex); return; @@ -47,8 +45,8 @@ static void app_rx_st20r_consume_frame(struct st_app_rx_video_session *s, } else { if (s->st20_dst_cursor + frame_size > s->st20_dst_end) s->st20_dst_cursor = s->st20_dst_begin; - dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, - s->st20_dst_cursor, frame, frame_size); + dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, s->st20_dst_cursor, + frame, frame_size); mtl_memcpy(s->st20_dst_cursor, frame, frame_size); s->st20_dst_cursor += frame_size; } @@ -81,8 +79,7 @@ static void *app_rx_st20r_frame_thread(void *arg) { st_pthread_mutex_lock(&s->st20_wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->st20_wake_mutex); } @@ -106,8 +103,7 @@ static int app_rx_st20r_open_source(struct st_app_rx_video_session *s) { off_t f_size; /* user do not require fb save to file */ - if (s->st20_dst_fb_cnt < 1) - return 0; + if (s->st20_dst_fb_cnt < 1) return 0; fd = st_open_mode(s->st20_dst_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -134,8 +130,8 @@ static int app_rx_st20r_open_source(struct st_app_rx_video_session *s) { s->st20_dst_cursor = m; s->st20_dst_end = m + f_size; s->st20_dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, + s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); return 0; } @@ -144,8 +140,7 @@ static int app_rx_st20r_init_frame_thread(struct st_app_rx_video_session *s) { int ret, idx = s->idx; /* user do not require fb save to file or display */ - if (s->st20_dst_fb_cnt < 1 && s->display == NULL) - return 0; + if (s->st20_dst_fb_cnt < 1 && s->display == NULL) return 0; ret = pthread_create(&s->st20_app_thread, NULL, app_rx_st20r_frame_thread, s); if (ret < 0) { @@ -165,8 +160,7 @@ static int app_rx_st20r_frame_ready(void *priv, void *frame, struct st_app_rx_video_session *s = priv; int ret; - if (!s->st20r_handle) - return -EIO; + if (!s->st20r_handle) return -EIO; /* incomplete frame */ if (!st_is_frame_complete(meta->status)) { @@ -237,8 +231,7 @@ static int app_rx_st20r_uinit(struct st_app_rx_video_session *s) { if (s->st20r_handle) { ret = st20rc_rx_free(s->st20r_handle); - if (ret < 0) - err("%s(%d), st20rc_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st20rc_rx_free fail %d\n", __func__, idx, ret); s->st20r_handle = NULL; } app_rx_st20r_close_source(s); @@ -250,8 +243,7 @@ static int app_rx_st20r_uinit(struct st_app_rx_video_session *s) { return 0; } -static int app_rx_st20r_init(struct st_app_context *ctx, - st_json_video_session_t *video, +static int app_rx_st20r_init(struct st_app_context *ctx, st_json_video_session_t *video, struct st_app_rx_video_session *s) { int idx = s->idx, ret; struct st20rc_rx_ops ops; @@ -267,61 +259,54 @@ static int app_rx_st20r_init(struct st_app_context *ctx, video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], - video ? video->base.mcast_src_ip[MTL_PORT_P] - : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy( + ops.mcast_sip_addr[MTL_SESSION_PORT_P], + video ? video->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = - video ? video->base.udp_port : (10000 + s->idx); + video ? video->base.inf[MTL_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = video ? video->base.udp_port : (10000 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], - video ? video->base.mcast_src_ip[MTL_PORT_R] - : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = - video ? video->base.udp_port : (10000 + s->idx); + memcpy( + ops.mcast_sip_addr[MTL_SESSION_PORT_R], + video ? video->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf( + ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = video ? video->base.udp_port : (10000 + s->idx); } ops.pacing = ST21_PACING_NARROW; ops.flags = ST20RC_RX_FLAG_DMA_OFFLOAD; ops.width = video ? st_app_get_width(video->info.video_format) : 1920; ops.height = video ? st_app_get_height(video->info.video_format) : 1080; ops.fps = video ? st_app_get_fps(video->info.video_format) : ST_FPS_P59_94; - ops.interlaced = - video ? st_app_get_interlaced(video->info.video_format) : false; + ops.interlaced = video ? st_app_get_interlaced(video->info.video_format) : false; ops.fmt = video ? video->info.pg_format : ST20_FMT_YUV_422_10BIT; - ops.payload_type = - video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.payload_type = video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.notify_frame_ready = app_rx_st20r_frame_ready; ops.framebuff_cnt = s->framebuff_cnt; - if (ctx->enable_hdr_split) - ops.flags |= ST20RC_RX_FLAG_HDR_SPLIT; + if (ctx->enable_hdr_split) ops.flags |= ST20RC_RX_FLAG_HDR_SPLIT; st_pthread_mutex_init(&s->st20_wake_mutex, NULL); st_pthread_cond_init(&s->st20_wake_cond, NULL); if (mtl_pmd_by_port_name(ops.port[MTL_SESSION_PORT_P]) != MTL_PMD_DPDK_USER) { - snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d.yuv", idx, - ops.width, ops.height); + snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d.yuv", idx, ops.width, + ops.height); } else { uint32_t soc = 0, b = 0, d = 0, f = 0; sscanf(ops.port[MTL_SESSION_PORT_P], "%x:%x:%x.%x", &soc, &b, &d, &f); snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, - "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, - ops.height, soc, b, d, f); + "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, ops.height, soc, b, + d, f); } ret = st20_get_pgroup(ops.fmt, &s->st20_pg); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->width = ops.width; s->height = ops.height; @@ -333,10 +318,9 @@ static int app_rx_st20r_init(struct st_app_context *ctx, s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * - s->framebuff_cnt); - if (!s->framebuffs) - return -ENOMEM; + s->framebuffs = + (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); + if (!s->framebuffs) return -ENOMEM; for (int j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].frame = NULL; } @@ -392,8 +376,7 @@ static int app_rx_st20r_stat(struct st_app_rx_video_session *s) { info("%s(%d), fps %f, %d frame received\n", __func__, s->idx, framerate, s->stat_frame_received); if (s->measure_latency && s->stat_frame_received) { - double latency_ms = - (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -406,17 +389,14 @@ static int app_rx_st20r_stat(struct st_app_rx_video_session *s) { static int app_rx_st20r_result(struct st_app_rx_video_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) - return -EINVAL; + if (!s->stat_frame_total_received) return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) - ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } @@ -431,13 +411,11 @@ int st_app_rx_st20r_sessions_init(struct st_app_context *ctx) { int ret, i; struct st_app_rx_video_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) - fb_cnt = 3; + if (fb_cnt <= 0) fb_cnt = 3; ctx->rx_st20r_sessions = (struct st_app_rx_video_session *)st_app_zmalloc( sizeof(*ctx->rx_st20r_sessions) * ctx->rx_st20r_session_cnt); - if (!ctx->rx_st20r_sessions) - return -ENOMEM; + if (!ctx->rx_st20r_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; s->idx = i; @@ -460,8 +438,7 @@ int st_app_rx_st20r_sessions_init(struct st_app_context *ctx) { int st_app_rx_st20r_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_rx_video_session *s; - if (!ctx->rx_st20r_sessions) - return 0; + if (!ctx->rx_st20r_sessions) return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; app_rx_st20r_uinit(s); @@ -474,8 +451,7 @@ int st_app_rx_st20r_sessions_uinit(struct st_app_context *ctx) { int st_app_rx_st20r_sessions_stat(struct st_app_context *ctx) { int i; struct st_app_rx_video_session *s; - if (!ctx->rx_st20r_sessions) - return 0; + if (!ctx->rx_st20r_sessions) return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; @@ -489,8 +465,7 @@ int st_app_rx_st20r_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_video_session *s; - if (!ctx->rx_st20r_sessions) - return 0; + if (!ctx->rx_st20r_sessions) return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; @@ -504,8 +479,7 @@ int st_app_rx_st20r_sessions_pcap(struct st_app_context *ctx) { int i; struct st_app_rx_video_session *s; - if (!ctx->rx_st20r_sessions) - return 0; + if (!ctx->rx_st20r_sessions) return 0; for (i = 0; i < ctx->rx_st20r_session_cnt; i++) { s = &ctx->rx_st20r_sessions[i]; diff --git a/app/src/fmt.c b/app/src/fmt.c index 0edeae16a..cd3272d82 100644 --- a/app/src/fmt.c +++ b/app/src/fmt.c @@ -20,12 +20,9 @@ int user_get_pgroup(enum user_pg_fmt fmt, struct user_pgroup *pg) { return -1; } -void convert_uyvy10b_to_uyvy8b(uint8_t *yuv_8b, uint8_t const *yuv_10b, - int pg_count) { - struct st20_rfc4175_422_8_pg2_le *pg_8 = - (struct st20_rfc4175_422_8_pg2_le *)yuv_8b; - struct st20_rfc4175_422_10_pg2_be *pg_10 = - (struct st20_rfc4175_422_10_pg2_be *)yuv_10b; +void convert_uyvy10b_to_uyvy8b(uint8_t *yuv_8b, uint8_t const *yuv_10b, int pg_count) { + struct st20_rfc4175_422_8_pg2_le *pg_8 = (struct st20_rfc4175_422_8_pg2_le *)yuv_8b; + struct st20_rfc4175_422_10_pg2_be *pg_10 = (struct st20_rfc4175_422_10_pg2_be *)yuv_10b; st20_rfc4175_422be10_to_422le8(pg_10, pg_8, pg_count, 2); } diff --git a/app/src/fmt.h b/app/src/fmt.h index 4525e8d39..8ef150d0a 100644 --- a/app/src/fmt.h +++ b/app/src/fmt.h @@ -41,7 +41,6 @@ static const struct user_pgroup user_pgroups[] = { int user_get_pgroup(enum user_pg_fmt fmt, struct user_pgroup *pg); -void convert_uyvy10b_to_uyvy8b(uint8_t *yuv_8b, uint8_t const *yuv_10b, - int pg_count); +void convert_uyvy10b_to_uyvy8b(uint8_t *yuv_8b, uint8_t const *yuv_10b, int pg_count); #endif \ No newline at end of file diff --git a/app/src/legacy/rx_audio_app.c b/app/src/legacy/rx_audio_app.c index 7f06f801a..da4e3f97d 100644 --- a/app/src/legacy/rx_audio_app.c +++ b/app/src/legacy/rx_audio_app.c @@ -19,8 +19,7 @@ static int app_rx_audio_open_dump(struct st_app_rx_audio_session *s) { off_t f_size; /* user do not require dump to file */ - if (s->st30_dump_time_s < 1) - return 0; + if (s->st30_dump_time_s < 1) return 0; fd = st_open_mode(s->st30_dump_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -55,8 +54,7 @@ static int app_rx_audio_open_dump(struct st_app_rx_audio_session *s) { static int app_rx_audio_close_source(struct st_app_rx_audio_session *session) { if (session->st30_ref_fd >= 0) { - munmap(session->st30_ref_begin, - session->st30_ref_end - session->st30_ref_begin); + munmap(session->st30_ref_begin, session->st30_ref_end - session->st30_ref_begin); close(session->st30_ref_fd); session->st30_ref_fd = -1; } @@ -95,9 +93,8 @@ static int app_rx_audio_open_ref(struct st_app_rx_audio_session *session) { return 0; } -static int -app_rx_audio_compare_with_ref(struct st_app_rx_audio_session *session, - void *frame) { +static int app_rx_audio_compare_with_ref(struct st_app_rx_audio_session *session, + void *frame) { int ret = -1; bool rewind = false; int count = 0; @@ -108,8 +105,7 @@ app_rx_audio_compare_with_ref(struct st_app_rx_audio_session *session, /* calculate new reference frame */ session->st30_ref_cursor += session->st30_frame_size; if ((session->st30_ref_cursor >= session->st30_ref_end) || - ((session->st30_ref_end - session->st30_ref_cursor) < - session->st30_frame_size)) { + ((session->st30_ref_end - session->st30_ref_cursor) < session->st30_frame_size)) { session->st30_ref_cursor = session->st30_ref_begin; } @@ -122,8 +118,8 @@ app_rx_audio_compare_with_ref(struct st_app_rx_audio_session *session, } if (session->st30_ref_cursor == old_ref) { if (ret) { - info("%s(%d), bad audio, stop referencing for current frame\n", - __func__, session->idx); + info("%s(%d), bad audio, stop referencing for current frame\n", __func__, + session->idx); session->st30_ref_err++; if (session->st30_ref_err > 100) { err("%s(%d), too many bad audio err, stop referencing\n", __func__, @@ -152,8 +148,7 @@ static int app_rx_audio_handle_rtp(struct st_app_rx_audio_session *s, if (!s->stat_frame_first_rx_time) s->stat_frame_first_rx_time = st_app_get_monotonic_time(); - if (s->st30_ref_fd > 0) - app_rx_audio_compare_with_ref(s, payload); + if (s->st30_ref_fd > 0) app_rx_audio_compare_with_ref(s, payload); return 0; } @@ -209,21 +204,19 @@ static int app_rx_audio_frame_ready(void *priv, void *frame, struct st_app_rx_audio_session *s = priv; MTL_MAY_UNUSED(meta); - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; s->stat_frame_total_received++; if (!s->stat_frame_first_rx_time) s->stat_frame_first_rx_time = st_app_get_monotonic_time(); - if (s->st30_ref_fd > 0) - app_rx_audio_compare_with_ref(s, frame); + if (s->st30_ref_fd > 0) app_rx_audio_compare_with_ref(s, frame); if (s->st30_dump_fd > 0) { if (s->st30_dump_cursor + s->st30_frame_size > s->st30_dump_end) s->st30_dump_cursor = s->st30_dump_begin; - dbg("%s(%d), dst %p src %p size %d\n", __func__, s->idx, - s->st30_dump_cursor, frame, s->st30_frame_size); + dbg("%s(%d), dst %p src %p size %d\n", __func__, s->idx, s->st30_dump_cursor, frame, + s->st30_frame_size); mtl_memcpy(s->st30_dump_cursor, frame, s->st30_frame_size); s->st30_dump_cursor += s->st30_frame_size; } @@ -243,18 +236,17 @@ static int app_rx_audio_rtp_ready(void *priv) { return 0; } -static int app_rx_audio_timing_parser_result(void *priv, - enum mtl_session_port port, +static int app_rx_audio_timing_parser_result(void *priv, enum mtl_session_port port, struct st30_rx_tp_meta *tp) { struct st_app_rx_audio_session *s = priv; s->stat_compliant_result[tp->compliant]++; s->ipt_max = ST_MAX(s->ipt_max, tp->ipt_max); if (tp->compliant != ST_RX_TP_COMPLIANT_NARROW) { - warn("%s(%d,%d), compliant %d, failed cause %s, pkts_cnt %u\n", __func__, - s->idx, port, tp->compliant, tp->failed_cause, tp->pkts_cnt); - warn("%s(%d,%d), tsdf %dus, ipt(ns) min %d max %d avg %f\n", __func__, - s->idx, port, tp->tsdf, tp->ipt_min, tp->ipt_max, tp->ipt_avg); + warn("%s(%d,%d), compliant %d, failed cause %s, pkts_cnt %u\n", __func__, s->idx, + port, tp->compliant, tp->failed_cause, tp->pkts_cnt); + warn("%s(%d,%d), tsdf %dus, ipt(ns) min %d max %d avg %f\n", __func__, s->idx, port, + tp->tsdf, tp->ipt_min, tp->ipt_max, tp->ipt_avg); dbg("%s(%d,%d), dpvr(us) min %d max %d avg %f\n", __func__, s->idx, port, tp->dpvr_min, tp->dpvr_max, tp->dpvr_avg); } @@ -279,8 +271,7 @@ static int app_rx_audio_uinit(struct st_app_rx_audio_session *s) { if (s->handle) { ret = st30_rx_free(s->handle); - if (ret < 0) - err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } app_rx_audio_close_source(s); @@ -292,17 +283,14 @@ static int app_rx_audio_uinit(struct st_app_rx_audio_session *s) { static int app_rx_audio_result(struct st_app_rx_audio_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) - return -EINVAL; + if (!s->stat_frame_total_received) return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) - ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } @@ -312,12 +300,10 @@ static int app_rx_audio_stat(struct st_app_rx_audio_session *s) { if (s->enable_timing_parser_meta) { if ((s->stat_dump_cnt % 6) == 0) { /* report every 1 min */ - warn("%s(%d), COMPLIANT NARROW %d WIDE %d FAILED %d, ipt max %fus\n", - __func__, s->idx, - s->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], + warn("%s(%d), COMPLIANT NARROW %d WIDE %d FAILED %d, ipt max %fus\n", __func__, + s->idx, s->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], s->stat_compliant_result[ST_RX_TP_COMPLIANT_WIDE], - s->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED], - (float)s->ipt_max / 1000); + s->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED], (float)s->ipt_max / 1000); memset(s->stat_compliant_result, 0, sizeof(s->stat_compliant_result)); s->ipt_max = 0; } @@ -325,8 +311,7 @@ static int app_rx_audio_stat(struct st_app_rx_audio_session *s) { return 0; } -static int app_rx_audio_init(struct st_app_context *ctx, - st_json_audio_session_t *audio, +static int app_rx_audio_init(struct st_app_context *ctx, st_json_audio_session_t *audio, struct st_app_rx_audio_session *s) { int idx = s->idx, ret; struct st30_rx_ops ops; @@ -342,41 +327,36 @@ static int app_rx_audio_init(struct st_app_context *ctx, audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], - audio ? audio->base.mcast_src_ip[MTL_PORT_P] - : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = - audio ? audio->base.udp_port : (10100 + s->idx); + memcpy( + ops.mcast_sip_addr[MTL_SESSION_PORT_P], + audio ? audio->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf( + ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + audio ? audio->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = audio ? audio->base.udp_port : (10100 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], - audio ? audio->base.mcast_src_ip[MTL_PORT_R] - : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy( + ops.mcast_sip_addr[MTL_SESSION_PORT_R], + audio ? audio->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = - audio ? audio->base.udp_port : (10100 + s->idx); + audio ? audio->base.inf[MTL_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = audio ? audio->base.udp_port : (10100 + s->idx); } ops.notify_frame_ready = app_rx_audio_frame_ready; ops.notify_rtp_ready = app_rx_audio_rtp_ready; ops.type = audio ? audio->info.type : ST30_TYPE_FRAME_LEVEL; ops.fmt = audio ? audio->info.audio_format : ST30_FMT_PCM16; - ops.payload_type = - audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.payload_type = audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; ops.channel = audio ? audio->info.audio_channel : 2; ops.sampling = audio ? audio->info.audio_sampling : ST30_SAMPLING_48K; ops.ptime = audio ? audio->info.audio_ptime : ST30_PTIME_1MS; - s->pkt_len = - st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); + s->pkt_len = st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); if (s->pkt_len < 0) { err("%s(%d), st30_get_packet_size fail\n", __func__, idx); app_rx_audio_uinit(s); @@ -391,17 +371,13 @@ static int app_rx_audio_init(struct st_app_context *ctx, } s->st30_frame_size = pkt_per_frame * s->pkt_len; - s->expect_fps = - (double)NS_PER_S / st30_get_packet_time(ops.ptime) / pkt_per_frame; + s->expect_fps = (double)NS_PER_S / st30_get_packet_time(ops.ptime) / pkt_per_frame; ops.framebuff_size = s->st30_frame_size; ops.framebuff_cnt = s->framebuff_cnt; - ops.rtp_ring_size = - ctx->rx_audio_rtp_ring_size ? ctx->rx_audio_rtp_ring_size : 16; - if (audio && audio->enable_rtcp) - ops.flags |= ST30_RX_FLAG_ENABLE_RTCP; - if (ctx->enable_timing_parser) - ops.flags |= ST30_RX_FLAG_TIMING_PARSER_STAT; + ops.rtp_ring_size = ctx->rx_audio_rtp_ring_size ? ctx->rx_audio_rtp_ring_size : 16; + if (audio && audio->enable_rtcp) ops.flags |= ST30_RX_FLAG_ENABLE_RTCP; + if (ctx->enable_timing_parser) ops.flags |= ST30_RX_FLAG_TIMING_PARSER_STAT; if (ctx->enable_timing_parser_meta) { ops.notify_timing_parser_result = app_rx_audio_timing_parser_result; ops.flags |= ST30_RX_FLAG_TIMING_PARSER_META; @@ -427,9 +403,9 @@ static int app_rx_audio_init(struct st_app_context *ctx, } /* dump */ - snprintf(s->st30_dump_url, ST_APP_URL_MAX_LEN, "st_audio_app%d_%d_%d_c%u.pcm", - idx, st30_get_sample_rate(ops.sampling), - st30_get_sample_size(ops.fmt) * 8, ops.channel); + snprintf(s->st30_dump_url, ST_APP_URL_MAX_LEN, "st_audio_app%d_%d_%d_c%u.pcm", idx, + st30_get_sample_rate(ops.sampling), st30_get_sample_size(ops.fmt) * 8, + ops.channel); ret = app_rx_audio_open_dump(s); if (ret < 0) { err("%s(%d), app_rx_audio_open_dump fail %d\n", __func__, idx, ret); @@ -448,8 +424,8 @@ static int app_rx_audio_init(struct st_app_context *ctx, ret = app_rx_audio_init_rtp_thread(s); } if (ret < 0) { - err("%s(%d), app_rx_audio_init_thread fail %d, type %d\n", __func__, idx, - ret, ops.type); + err("%s(%d), app_rx_audio_init_thread fail %d, type %d\n", __func__, idx, ret, + ops.type); app_rx_audio_uinit(s); return -EIO; } @@ -462,8 +438,7 @@ int st_app_rx_audio_sessions_init(struct st_app_context *ctx) { struct st_app_rx_audio_session *s; ctx->rx_audio_sessions = (struct st_app_rx_audio_session *)st_app_zmalloc( sizeof(struct st_app_rx_audio_session) * ctx->rx_audio_session_cnt); - if (!ctx->rx_audio_sessions) - return -ENOMEM; + if (!ctx->rx_audio_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; s->idx = i; @@ -486,8 +461,7 @@ int st_app_rx_audio_sessions_init(struct st_app_context *ctx) { int st_app_rx_audio_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_rx_audio_session *s; - if (!ctx->rx_audio_sessions) - return 0; + if (!ctx->rx_audio_sessions) return 0; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; @@ -502,8 +476,7 @@ int st_app_rx_audio_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_audio_session *s; - if (!ctx->rx_audio_sessions) - return 0; + if (!ctx->rx_audio_sessions) return 0; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; ret += app_rx_audio_result(s); @@ -516,8 +489,7 @@ int st_app_rx_audio_sessions_stat(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_audio_session *s; - if (!ctx->rx_audio_sessions) - return 0; + if (!ctx->rx_audio_sessions) return 0; for (i = 0; i < ctx->rx_audio_session_cnt; i++) { s = &ctx->rx_audio_sessions[i]; ret += app_rx_audio_stat(s); diff --git a/app/src/legacy/rx_st22_app.c b/app/src/legacy/rx_st22_app.c index 94bdc8b00..044c97118 100644 --- a/app/src/legacy/rx_st22_app.c +++ b/app/src/legacy/rx_st22_app.c @@ -19,8 +19,7 @@ static int app_rx_st22_open_source(struct st22_app_rx_session *s) { off_t f_size; /* user do not require fb save to file */ - if (s->st22_dst_fb_cnt <= 1) - return 0; + if (s->st22_dst_fb_cnt <= 1) return 0; fd = st_open_mode(s->st22_dst_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -47,8 +46,8 @@ static int app_rx_st22_open_source(struct st22_app_rx_session *s) { s->st22_dst_cursor = m; s->st22_dst_end = m + f_size; s->st22_dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, s->st22_dst_fb_cnt, s->st22_dst_url, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, + s->st22_dst_fb_cnt, s->st22_dst_url, m, f_size); return 0; } @@ -66,8 +65,7 @@ static int app_rx_st22_enqueue_frame(struct st22_app_rx_session *s, void *frame, framebuff->size = size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } @@ -76,8 +74,7 @@ static int app_rx_st22_frame_ready(void *priv, void *frame, struct st22_rx_frame_meta *meta) { struct st22_app_rx_session *s = (struct st22_app_rx_session *)priv; - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; st_pthread_mutex_lock(&s->wake_mutex); int ret = app_rx_st22_enqueue_frame(s, frame, meta->frame_total_size); @@ -94,8 +91,7 @@ static int app_rx_st22_frame_ready(void *priv, void *frame, return 0; } -static void app_rx_st22_decode_frame(struct st22_app_rx_session *s, - void *codestream_addr, +static void app_rx_st22_decode_frame(struct st22_app_rx_session *s, void *codestream_addr, size_t codestream_size) { if (s->st22_dst_cursor + codestream_size > s->st22_dst_end) s->st22_dst_cursor = s->st22_dst_begin; @@ -119,8 +115,7 @@ static void *app_rx_st22_decode_thread(void *arg) { framebuff = &s->framebuffs[consumer_idx]; if (!framebuff->frame) { /* no ready frame */ - if (!s->st22_app_thread_stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->st22_app_thread_stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -133,8 +128,7 @@ static void *app_rx_st22_decode_thread(void *arg) { st_pthread_mutex_lock(&s->wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -161,8 +155,7 @@ static int app_rx_st22_uinit(struct st22_app_rx_session *s) { if (s->handle) { ret = st22_rx_free(s->handle); - if (ret < 0) - err("%s(%d), st22_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st22_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } app_rx_st22_close_source(s); @@ -175,8 +168,8 @@ static int app_rx_st22_uinit(struct st22_app_rx_session *s) { return 0; } -static int app_rx_st22_init(struct st_app_context *ctx, - struct st22_app_rx_session *s, int bpp) { +static int app_rx_st22_init(struct st_app_context *ctx, struct st22_app_rx_session *s, + int bpp) { int idx = s->idx, ret; struct st22_rx_ops ops; char name[32]; @@ -191,25 +184,23 @@ static int app_rx_st22_init(struct st_app_context *ctx, uint32_t soc = 0, b = 0, d = 0, f = 0; sscanf(ctx->para.port[MTL_PORT_P], "%x:%x:%x.%x", &soc, &b, &d, &f); snprintf(s->st22_dst_url, ST_APP_URL_MAX_LEN, - "st22_app%d_%d_%d_%02x_%02x_%02x_%02x.raw", idx, s->width, s->height, - soc, b, d, f); + "st22_app%d_%d_%d_%02x_%02x_%02x_%02x.raw", idx, s->width, s->height, soc, b, + d, f); snprintf(name, 32, "app_rx_st22_%d", idx); ops.name = name; ops.priv = s; ops.num_port = ctx->para.num_ports; - memcpy(ops.ip_addr[MTL_SESSION_PORT_P], ctx->rx_ip_addr[MTL_PORT_P], + memcpy(ops.ip_addr[MTL_SESSION_PORT_P], ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], ctx->rx_mcast_sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], - ctx->rx_mcast_sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops.udp_port[MTL_SESSION_PORT_P] = 15000 + s->idx; if (ops.num_port > 1) { - memcpy(ops.ip_addr[MTL_SESSION_PORT_R], ctx->rx_ip_addr[MTL_PORT_R], + memcpy(ops.ip_addr[MTL_SESSION_PORT_R], ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], ctx->rx_mcast_sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], - ctx->rx_mcast_sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops.udp_port[MTL_SESSION_PORT_R] = 15000 + s->idx; @@ -228,10 +219,9 @@ static int app_rx_st22_init(struct st_app_context *ctx, s->framebuff_cnt = ops.framebuff_cnt; s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * - s->framebuff_cnt); - if (!s->framebuffs) - return -ENOMEM; + s->framebuffs = + (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); + if (!s->framebuffs) return -ENOMEM; for (uint16_t j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].frame = NULL; } @@ -274,8 +264,7 @@ int st22_app_rx_sessions_init(struct st_app_context *ctx) { struct st22_app_rx_session *s; ctx->rx_st22_sessions = (struct st22_app_rx_session *)st_app_zmalloc( sizeof(struct st22_app_rx_session) * ctx->rx_st22_session_cnt); - if (!ctx->rx_st22_sessions) - return -ENOMEM; + if (!ctx->rx_st22_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_st22_session_cnt; i++) { s = &ctx->rx_st22_sessions[i]; s->idx = i; @@ -295,8 +284,7 @@ int st22_app_rx_sessions_init(struct st_app_context *ctx) { int st22_app_rx_sessions_uinit(struct st_app_context *ctx) { int i; struct st22_app_rx_session *s; - if (!ctx->rx_st22_sessions) - return 0; + if (!ctx->rx_st22_sessions) return 0; for (i = 0; i < ctx->rx_st22_session_cnt; i++) { s = &ctx->rx_st22_sessions[i]; app_rx_st22_uinit(s); diff --git a/app/src/legacy/rx_video_app.c b/app/src/legacy/rx_video_app.c index 87bb3d6da..6c78c1993 100644 --- a/app/src/legacy/rx_video_app.c +++ b/app/src/legacy/rx_video_app.c @@ -23,8 +23,7 @@ static inline bool app_rx_video_is_frame_type(enum st20_type type) { return false; } -static int app_rx_video_enqueue_frame(struct st_app_rx_video_session *s, - void *frame, +static int app_rx_video_enqueue_frame(struct st_app_rx_video_session *s, void *frame, struct st20_rx_frame_meta *meta) { uint16_t producer_idx = s->framebuff_producer_idx; struct st_rx_frame *framebuff = &s->framebuffs[producer_idx]; @@ -47,14 +46,13 @@ static int app_rx_video_enqueue_frame(struct st_app_rx_video_session *s, framebuff->size = meta->frame_total_size; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; return 0; } -static void app_rx_video_consume_frame(struct st_app_rx_video_session *s, - void *frame, size_t frame_size) { +static void app_rx_video_consume_frame(struct st_app_rx_video_session *s, void *frame, + size_t frame_size) { struct st_display *d = s->display; if (d && d->front_frame) { @@ -63,8 +61,7 @@ static void app_rx_video_consume_frame(struct st_app_rx_video_session *s, s->user_pg.fmt == USER_FMT_YUV_422_8BIT) mtl_memcpy(d->front_frame, frame, d->front_frame_size); else if (s->st20_pg.fmt == ST20_FMT_YUV_422_10BIT) - st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, - s->height); + st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, s->height); else /* fmt mismatch*/ { st_pthread_mutex_unlock(&d->display_frame_mutex); return; @@ -77,8 +74,8 @@ static void app_rx_video_consume_frame(struct st_app_rx_video_session *s, } else if (s->st20_dst_fd > 0) { if (s->st20_dst_cursor + frame_size > s->st20_dst_end) s->st20_dst_cursor = s->st20_dst_begin; - dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, - s->st20_dst_cursor, frame, frame_size); + dbg("%s(%d), dst %p src %p size %" PRIu64 "\n", __func__, s->idx, s->st20_dst_cursor, + frame, frame_size); mtl_memcpy(s->st20_dst_cursor, frame, frame_size); s->st20_dst_cursor += frame_size; } @@ -110,8 +107,7 @@ static void *app_rx_video_frame_thread(void *arg) { uint8_t shas[SHA256_DIGEST_LENGTH]; st_sha256((unsigned char *)framebuff->frame, framebuff->size, shas); if (memcmp(shas, framebuff->shas, sizeof(shas))) { - err("%s(%d), sha check fail for frame idx %d\n", __func__, idx, - consumer_idx); + err("%s(%d), sha check fail for frame idx %d\n", __func__, idx, consumer_idx); st_sha_dump("user meta sha:", framebuff->shas); st_sha_dump("frame sha:", shas); } @@ -121,8 +117,7 @@ static void *app_rx_video_frame_thread(void *arg) { st_pthread_mutex_lock(&s->st20_wake_mutex); framebuff->frame = NULL; consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; st_pthread_mutex_unlock(&s->st20_wake_mutex); } @@ -156,16 +151,14 @@ static int app_rx_video_handle_rtp(struct st_app_rx_video_session *s, s->st20_dst_cursor = s->st20_dst_begin; } - if (s->st20_dst_fd < 0) - return 0; + if (s->st20_dst_fd < 0) return 0; frame = s->st20_dst_cursor; payload = (uint8_t *)hdr + sizeof(*hdr); row_number = ntohs(hdr->row_number); row_offset = ntohs(hdr->row_offset); row_length = ntohs(hdr->row_length); - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, - row_length); + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, row_length); if (row_offset & ST20_SRD_OFFSET_CONTINUATION) { /* additional Sample Row Data */ row_offset &= ~ST20_SRD_OFFSET_CONTINUATION; @@ -178,8 +171,8 @@ static int app_rx_video_handle_rtp(struct st_app_rx_video_session *s, } /* copy the payload to target frame */ - uint32_t offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * - s->st20_pg.size; + uint32_t offset = + (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; if ((offset + row_length) > s->st20_frame_size) { err("%s(%d: invalid offset %u frame size %d\n", __func__, idx, offset, s->st20_frame_size); @@ -195,13 +188,12 @@ static int app_rx_video_handle_rtp(struct st_app_rx_video_session *s, row2_number &= ~ST20_SECOND_FIELD; } - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, - row2_length); - uint32_t offset2 = (row2_number * s->width + row2_offset) / - s->st20_pg.coverage * s->st20_pg.size; + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, row2_length); + uint32_t offset2 = + (row2_number * s->width + row2_offset) / s->st20_pg.coverage * s->st20_pg.size; if ((offset2 + row2_length) > s->st20_frame_size) { - err("%s(%d: invalid offset %u frame size %d for extra hdr\n", __func__, - idx, offset2, s->st20_frame_size); + err("%s(%d: invalid offset %u frame size %d for extra hdr\n", __func__, idx, + offset2, s->st20_frame_size); return -EIO; } mtl_memcpy(frame + offset2, payload + row_length, row2_length); @@ -256,8 +248,7 @@ static int app_rx_video_open_source(struct st_app_rx_video_session *s) { off_t f_size; /* user do not require fb save to file */ - if (s->st20_dst_fb_cnt < 1) - return 0; + if (s->st20_dst_fb_cnt < 1) return 0; fd = st_open_mode(s->st20_dst_url, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (fd < 0) { @@ -284,8 +275,8 @@ static int app_rx_video_open_source(struct st_app_rx_video_session *s) { s->st20_dst_cursor = m; s->st20_dst_end = m + f_size; s->st20_dst_fd = fd; - info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, - idx, s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); + info("%s(%d), save %d framebuffers to file %s(%p,%" PRIu64 ")\n", __func__, idx, + s->st20_dst_fb_cnt, s->st20_dst_url, m, f_size); return 0; } @@ -294,8 +285,7 @@ static int app_rx_video_init_frame_thread(struct st_app_rx_video_session *s) { int ret, idx = s->idx; /* user do not require fb save to file or display */ - if (s->st20_dst_fb_cnt < 1 && !s->display && !s->sha_check) - return 0; + if (s->st20_dst_fb_cnt < 1 && !s->display && !s->sha_check) return 0; ret = pthread_create(&s->st20_app_thread, NULL, app_rx_video_frame_thread, s); if (ret < 0) { @@ -327,21 +317,18 @@ static int app_rx_video_frame_ready(void *priv, void *frame, struct st_app_rx_video_session *s = priv; int ret, idx = s->idx; - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; if (s->num_port > 1) { dbg("%s(%d): pkts_total %u, pkts per port P %u R %u\n", __func__, idx, meta->pkts_total, meta->pkts_recv[MTL_SESSION_PORT_P], meta->pkts_recv[MTL_SESSION_PORT_R]); if (meta->pkts_recv[MTL_SESSION_PORT_P] < (meta->pkts_total / 2)) - warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", - __func__, idx, meta->pkts_recv[MTL_SESSION_PORT_P], - meta->pkts_total); + warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", __func__, idx, + meta->pkts_recv[MTL_SESSION_PORT_P], meta->pkts_total); if (meta->pkts_recv[MTL_SESSION_PORT_R] < (meta->pkts_total / 2)) - warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", - __func__, idx, meta->pkts_recv[MTL_SESSION_PORT_R], - meta->pkts_total); + warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", __func__, idx, + meta->pkts_recv[MTL_SESSION_PORT_R], meta->pkts_total); } /* incomplete frame */ @@ -397,18 +384,16 @@ static int app_rx_video_slice_ready(void *priv, void *frame, size_t frame_ready_size; MTL_MAY_UNUSED(frame); - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; frame_ready_size = meta->frame_recv_lines * s->width * s->st20_pg.size / s->st20_pg.coverage; - dbg("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " \n", __func__, - idx, meta->frame_recv_lines, frame_ready_size, meta->frame_recv_size); + dbg("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " \n", __func__, idx, + meta->frame_recv_lines, frame_ready_size, meta->frame_recv_size); if (meta->frame_recv_size < frame_ready_size) { - err("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " error\n", - __func__, idx, meta->frame_recv_lines, frame_ready_size, - meta->frame_recv_size); + err("%s(%d), lines %u ready %" PRIu64 " recv_size %" PRIu64 " error\n", __func__, idx, + meta->frame_recv_lines, frame_ready_size, meta->frame_recv_size); } return 0; @@ -424,17 +409,14 @@ static int app_rx_video_rtp_ready(void *priv) { return 0; } -static int app_rx_video_detected(void *priv, - const struct st20_detect_meta *meta, +static int app_rx_video_detected(void *priv, const struct st20_detect_meta *meta, struct st20_detect_reply *reply) { struct st_app_rx_video_session *s = priv; - if (s->slice) - reply->slice_lines = meta->height / 32; + if (s->slice) reply->slice_lines = meta->height / 32; if (s->user_pg.fmt != USER_FMT_MAX) { int ret = user_get_pgroup(s->user_pg.fmt, &s->user_pg); - if (ret < 0) - return ret; + if (ret < 0) return ret; reply->uframe_size = meta->width * meta->height * s->user_pg.size / s->user_pg.coverage; } @@ -465,8 +447,7 @@ static int app_rx_video_uinit(struct st_app_rx_video_session *s) { if (s->handle) { ret = st20_rx_free(s->handle); - if (ret < 0) - err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } app_rx_video_close_source(s); @@ -486,13 +467,11 @@ static int app_rx_video_io_stat(struct st_app_rx_video_session *s) { int ret; struct st20_rx_port_status stats; - if (!s->handle) - return 0; + if (!s->handle) return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20_rx_get_port_stats(s->handle, port, &stats); - if (ret < 0) - return ret; + if (ret < 0) return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -504,8 +483,7 @@ static int app_rx_video_io_stat(struct st_app_rx_video_session *s) { return 0; } -static int app_rx_video_init(struct st_app_context *ctx, - st_json_video_session_t *video, +static int app_rx_video_init(struct st_app_context *ctx, st_json_video_session_t *video, struct st_app_rx_video_session *s) { int idx = s->idx, ret; struct st20_rx_ops ops; @@ -524,29 +502,27 @@ static int app_rx_video_init(struct st_app_context *ctx, video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], - video ? video->base.mcast_src_ip[MTL_PORT_P] - : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = - video ? video->base.udp_port : (10000 + s->idx); + memcpy( + ops.mcast_sip_addr[MTL_SESSION_PORT_P], + video ? video->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf( + ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = video ? video->base.udp_port : (10000 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], - video ? video->base.mcast_src_ip[MTL_PORT_R] - : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = - video ? video->base.udp_port : (10000 + s->idx); + memcpy( + ops.mcast_sip_addr[MTL_SESSION_PORT_R], + video ? video->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf( + ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = video ? video->base.udp_port : (10000 + s->idx); } ops.pacing = ST21_PACING_NARROW; if (ctx->rx_video_rtp_ring_size > 0) @@ -565,10 +541,8 @@ static int app_rx_video_init(struct st_app_context *ctx, ops.fps = video ? st_app_get_fps(video->info.video_format) : ST_FPS_P59_94; } ops.fmt = video ? video->info.pg_format : ST20_FMT_YUV_422_10BIT; - ops.payload_type = - video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; - ops.interlaced = - video ? st_app_get_interlaced(video->info.video_format) : false; + ops.payload_type = video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.interlaced = video ? st_app_get_interlaced(video->info.video_format) : false; ops.notify_frame_ready = app_rx_video_frame_ready; ops.slice_lines = ops.height / 32; ops.notify_slice_ready = app_rx_video_slice_ready; @@ -576,24 +550,20 @@ static int app_rx_video_init(struct st_app_context *ctx, ops.notify_detected = app_rx_video_detected; ops.framebuff_cnt = s->framebuff_cnt; ops.rtp_ring_size = ctx->rx_video_rtp_ring_size; - if (!ops.rtp_ring_size) - ops.rtp_ring_size = 1024; + if (!ops.rtp_ring_size) ops.rtp_ring_size = 1024; if (ops.type == ST20_TYPE_SLICE_LEVEL) { ops.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; s->slice = true; } else { s->slice = false; } - if (ctx->enable_hdr_split) - ops.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (ctx->enable_hdr_split) ops.flags |= ST20_RX_FLAG_HDR_SPLIT; if (video && video->enable_rtcp) { ops.flags |= ST20_RX_FLAG_ENABLE_RTCP; ops.rtcp.nack_interval_us = 250; } - if (ctx->enable_timing_parser) - ops.flags |= ST20_RX_FLAG_TIMING_PARSER_STAT; - if (ctx->rx_video_multi_thread) - ops.flags |= ST20_RX_FLAG_USE_MULTI_THREADS; + if (ctx->enable_timing_parser) ops.flags |= ST20_RX_FLAG_TIMING_PARSER_STAT; + if (ctx->rx_video_multi_thread) ops.flags |= ST20_RX_FLAG_USE_MULTI_THREADS; ops.rx_burst_size = ctx->rx_burst_size; if (ctx->force_rx_video_numa >= 0) { ops.flags |= ST20_RX_FLAG_FORCE_NUMA; @@ -604,25 +574,22 @@ static int app_rx_video_init(struct st_app_context *ctx, st_pthread_cond_init(&s->st20_wake_cond, NULL); if (mtl_pmd_by_port_name(ops.port[MTL_SESSION_PORT_P]) != MTL_PMD_DPDK_USER) { - snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d_%s.yuv", idx, - ops.width, ops.height, ops.port[MTL_SESSION_PORT_P]); + snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, "st_app%d_%d_%d_%s.yuv", idx, ops.width, + ops.height, ops.port[MTL_SESSION_PORT_P]); } else { uint32_t soc = 0, b = 0, d = 0, f = 0; sscanf(ops.port[MTL_SESSION_PORT_P], "%x:%x:%x.%x", &soc, &b, &d, &f); snprintf(s->st20_dst_url, ST_APP_URL_MAX_LEN, - "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, - ops.height, soc, b, d, f); + "st_app%d_%d_%d_%02x_%02x_%02x-%02x.yuv", idx, ops.width, ops.height, soc, b, + d, f); } ret = st20_get_pgroup(ops.fmt, &s->st20_pg); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->user_pg.fmt = video ? video->user_pg_format : USER_FMT_MAX; if (s->user_pg.fmt != USER_FMT_MAX) { ret = user_get_pgroup(s->user_pg.fmt, &s->user_pg); - if (ret < 0) - return ret; - ops.uframe_size = - ops.width * ops.height * s->user_pg.size / s->user_pg.coverage; + if (ret < 0) return ret; + ops.uframe_size = ops.width * ops.height * s->user_pg.size / s->user_pg.coverage; ops.uframe_pg_callback = pg_convert_callback; } @@ -637,10 +604,9 @@ static int app_rx_video_init(struct st_app_context *ctx, s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * - s->framebuff_cnt); - if (!s->framebuffs) - return -ENOMEM; + s->framebuffs = + (struct st_rx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); + if (!s->framebuffs) return -ENOMEM; for (int j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].frame = NULL; } @@ -684,8 +650,8 @@ static int app_rx_video_init(struct st_app_context *ctx, ret = -EINVAL; } if (ret < 0) { - err("%s(%d), app_rx_video_init_thread fail %d, type %d\n", __func__, idx, - ret, ops.type); + err("%s(%d), app_rx_video_init_thread fail %d, type %d\n", __func__, idx, ret, + ops.type); app_rx_video_uinit(s); return -EIO; } @@ -705,8 +671,7 @@ static int app_rx_video_stat(struct st_app_rx_video_session *s) { s->stat_frame_received); #endif if (s->measure_latency && s->stat_frame_received) { - double latency_ms = - (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -719,24 +684,20 @@ static int app_rx_video_stat(struct st_app_rx_video_session *s) { static int app_rx_video_result(struct st_app_rx_video_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) - return -EINVAL; + if (!s->stat_frame_total_received) return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) - ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } static int app_rx_video_pcap(struct st_app_rx_video_session *s) { - if (s->pcapng_max_pkts) - st20_rx_pcapng_dump(s->handle, s->pcapng_max_pkts, false, NULL); + if (s->pcapng_max_pkts) st20_rx_pcapng_dump(s->handle, s->pcapng_max_pkts, false, NULL); return 0; } @@ -744,13 +705,11 @@ int st_app_rx_video_sessions_init(struct st_app_context *ctx) { int ret, i; struct st_app_rx_video_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) - fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; ctx->rx_video_sessions = (struct st_app_rx_video_session *)st_app_zmalloc( sizeof(struct st_app_rx_video_session) * ctx->rx_video_session_cnt); - if (!ctx->rx_video_sessions) - return -ENOMEM; + if (!ctx->rx_video_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; s->idx = i; @@ -773,8 +732,7 @@ int st_app_rx_video_sessions_init(struct st_app_context *ctx) { int st_app_rx_video_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_rx_video_session *s; - if (!ctx->rx_video_sessions) - return 0; + if (!ctx->rx_video_sessions) return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; app_rx_video_uinit(s); @@ -787,8 +745,7 @@ int st_app_rx_video_sessions_uinit(struct st_app_context *ctx) { int st_app_rx_video_sessions_stat(struct st_app_context *ctx) { int i; struct st_app_rx_video_session *s; - if (!ctx->rx_video_sessions) - return 0; + if (!ctx->rx_video_sessions) return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; @@ -802,8 +759,7 @@ int st_app_rx_video_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_video_session *s; - if (!ctx->rx_video_sessions) - return 0; + if (!ctx->rx_video_sessions) return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; @@ -817,8 +773,7 @@ int st_app_rx_video_sessions_pcap(struct st_app_context *ctx) { int i; struct st_app_rx_video_session *s; - if (!ctx->rx_video_sessions) - return 0; + if (!ctx->rx_video_sessions) return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; @@ -831,8 +786,7 @@ int st_app_rx_video_sessions_pcap(struct st_app_context *ctx) { int st_app_rx_videos_io_stat(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_video_session *s; - if (!ctx->rx_video_sessions) - return 0; + if (!ctx->rx_video_sessions) return 0; for (i = 0; i < ctx->rx_video_session_cnt; i++) { s = &ctx->rx_video_sessions[i]; diff --git a/app/src/legacy/tx_audio_app.c b/app/src/legacy/tx_audio_app.c index 127eb21e5..f35d416ad 100644 --- a/app/src/legacy/tx_audio_app.c +++ b/app/src/legacy/tx_audio_app.c @@ -14,22 +14,19 @@ static int app_tx_audio_next_frame(void *priv, uint16_t *next_frame_idx, st_pthread_mutex_lock(&s->st30_wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { - dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", - __func__, s->idx, consumer_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, - st30_get_sample_rate(s->sampling))); + dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, + s->idx, consumer_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, st30_get_sample_rate(s->sampling))); ret = 0; framebuff->stat = ST_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, - framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); ret = -EIO; } st_pthread_cond_signal(&s->st30_wake_cond); @@ -48,14 +45,13 @@ static int app_tx_audio_frame_done(void *priv, uint16_t frame_idx, if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { ret = 0; framebuff->stat = ST_TX_FRAME_FREE; - dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", - __func__, s->idx, frame_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, - st30_get_sample_rate(s->sampling))); + dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, + s->idx, frame_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, st30_get_sample_rate(s->sampling))); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->st30_wake_cond); st_pthread_mutex_unlock(&s->st30_wake_mutex); @@ -74,8 +70,8 @@ static int app_tx_audio_rtp_done(void *priv) { return 0; } -static void app_tx_audio_build_frame(struct st_app_tx_audio_session *s, - void *frame, size_t frame_size) { +static void app_tx_audio_build_frame(struct st_app_tx_audio_session *s, void *frame, + size_t frame_size) { uint8_t *src = s->st30_frame_cursor; uint8_t *dst = frame; @@ -118,8 +114,7 @@ static void *app_tx_audio_frame_thread(void *arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->st30_wake_mutex); } @@ -164,8 +159,8 @@ static void *app_tx_audio_pcap_thread(void *arg) { if (ntohs(eth_hdr->ether_type) == ETHERTYPE_IP) { ip_hdr = (struct ip *)(packet + sizeof(struct ether_header)); if (ip_hdr->ip_p == IPPROTO_UDP) { - udp_hdr = (struct udphdr *)(packet + sizeof(struct ether_header) + - sizeof(struct ip)); + udp_hdr = + (struct udphdr *)(packet + sizeof(struct ether_header) + sizeof(struct ip)); udp_data_len = ntohs(udp_hdr->len) - sizeof(struct udphdr); mtl_memcpy(usrptr, packet + sizeof(struct ether_header) + sizeof(struct ip) + @@ -179,8 +174,7 @@ static void *app_tx_audio_pcap_thread(void *arg) { /* open capture file for offline processing */ s->st30_pcap = pcap_open_offline(s->st30_source_url, err_buf); if (s->st30_pcap == NULL) { - err("pcap_open_offline %s() failed: %s\n:", s->st30_source_url, - err_buf); + err("pcap_open_offline %s() failed: %s\n:", s->st30_source_url, err_buf); return NULL; } } @@ -192,8 +186,8 @@ static void *app_tx_audio_pcap_thread(void *arg) { return NULL; } -static void app_tx_audio_build_rtp(struct st_app_tx_audio_session *s, - void *usrptr, uint16_t *mbuf_len) { +static void app_tx_audio_build_rtp(struct st_app_tx_audio_session *s, void *usrptr, + uint16_t *mbuf_len) { /* generate one anc rtp for test purpose */ struct st_rfc3550_rtp_hdr *rtp = (struct st_rfc3550_rtp_hdr *)usrptr; uint8_t *payload = (uint8_t *)&rtp[1]; @@ -269,8 +263,7 @@ static int app_tx_audio_open_source(struct st_app_tx_audio_session *s) { return -EIO; } - uint8_t *m = - mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st30_source_fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st30_source_fd, 0); if (MAP_FAILED != m) { s->st30_source_begin = m; @@ -320,14 +313,11 @@ static int app_tx_audio_start_source(struct st_app_tx_audio_session *s) { s->st30_app_thread_stop = false; if (s->st30_pcap_input) - ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_pcap_thread, - (void *)s); + ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_pcap_thread, (void *)s); else if (s->st30_rtp_input) - ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_rtp_thread, - (void *)s); + ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_rtp_thread, (void *)s); else - ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_frame_thread, - (void *)s); + ret = pthread_create(&s->st30_app_thread, NULL, app_tx_audio_frame_thread, (void *)s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); @@ -348,8 +338,7 @@ static void app_tx_audio_stop_source(struct st_app_tx_audio_session *s) { st_pthread_mutex_lock(&s->st30_wake_mutex); st_pthread_cond_signal(&s->st30_wake_cond); st_pthread_mutex_unlock(&s->st30_wake_mutex); - if (s->st30_app_thread) - (void)pthread_join(s->st30_app_thread, NULL); + if (s->st30_app_thread) (void)pthread_join(s->st30_app_thread, NULL); } } @@ -360,8 +349,7 @@ static int app_tx_audio_uinit(struct st_app_tx_audio_session *s) { if (s->handle) { ret = st30_tx_free(s->handle); - if (ret < 0) - err("%s(%d), st30_tx_free fail %d\n", __func__, s->idx, ret); + if (ret < 0) err("%s(%d), st30_tx_free fail %d\n", __func__, s->idx, ret); s->handle = NULL; } @@ -376,8 +364,7 @@ static int app_tx_audio_uinit(struct st_app_tx_audio_session *s) { return 0; } -static int app_tx_audio_init(struct st_app_context *ctx, - st_json_audio_session_t *audio, +static int app_tx_audio_init(struct st_app_context *ctx, st_json_audio_session_t *audio, struct st_app_tx_audio_session *s) { int idx = s->idx, ret; struct st30_tx_ops ops; @@ -388,8 +375,8 @@ static int app_tx_audio_init(struct st_app_context *ctx, s->framebuff_cnt = 2; s->st30_seq_id = 1; - s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * - s->framebuff_cnt); + s->framebuffs = + (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); if (!s->framebuffs) { return -ENOMEM; } @@ -413,36 +400,31 @@ static int app_tx_audio_init(struct st_app_context *ctx, audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = - audio ? audio->base.udp_port : (10100 + s->idx); + snprintf( + ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + audio ? audio->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = audio ? audio->base.udp_port : (10100 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); ops.flags |= ST30_TX_FLAG_USER_P_MAC; } - if (ctx->tx_audio_build_pacing) - ops.flags |= ST30_TX_FLAG_BUILD_PACING; - if (ctx->tx_audio_dedicate_queue) - ops.flags |= ST30_TX_FLAG_DEDICATE_QUEUE; + if (ctx->tx_audio_build_pacing) ops.flags |= ST30_TX_FLAG_BUILD_PACING; + if (ctx->tx_audio_dedicate_queue) ops.flags |= ST30_TX_FLAG_DEDICATE_QUEUE; ops.pacing_way = ctx->tx_audio_pacing_way; - if (ctx->tx_audio_fifo_size) - ops.fifo_size = ctx->tx_audio_fifo_size; + if (ctx->tx_audio_fifo_size) ops.fifo_size = ctx->tx_audio_fifo_size; if (ops.num_port > 1) { memcpy(ops.dip_addr[MTL_SESSION_PORT_R], audio ? st_json_ip(ctx, &audio->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - audio ? audio->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = - audio ? audio->base.udp_port : (10100 + s->idx); + snprintf( + ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + audio ? audio->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = audio ? audio->base.udp_port : (10100 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], - ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], + MTL_MAC_ADDR_LEN); ops.flags |= ST30_TX_FLAG_USER_R_MAC; } } @@ -455,8 +437,7 @@ static int app_tx_audio_init(struct st_app_context *ctx, ops.sampling = audio ? audio->info.audio_sampling : ST30_SAMPLING_48K; ops.ptime = audio ? audio->info.audio_ptime : ST30_PTIME_1MS; s->sampling = ops.sampling; - s->pkt_len = - st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); + s->pkt_len = st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); if (s->pkt_len < 0) { err("%s(%d), st30_get_packet_size fail\n", __func__, idx); app_tx_audio_uinit(s); @@ -472,8 +453,7 @@ static int app_tx_audio_init(struct st_app_context *ctx, s->st30_frame_size = pkt_per_frame * s->pkt_len; ops.framebuff_size = s->st30_frame_size; - ops.payload_type = - audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.payload_type = audio ? audio->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; s->st30_pcap_input = false; ops.type = audio ? audio->info.type : ST30_TYPE_FRAME_LEVEL; @@ -492,8 +472,7 @@ static int app_tx_audio_init(struct st_app_context *ctx, else ops.rtp_ring_size = 16; } - if (audio && audio->enable_rtcp) - ops.flags |= ST30_TX_FLAG_ENABLE_RTCP; + if (audio && audio->enable_rtcp) ops.flags |= ST30_TX_FLAG_ENABLE_RTCP; ops.rl_accuracy_ns = ctx->tx_audio_rl_accuracy_us * 1000; ops.rl_offset_ns = ctx->tx_audio_rl_offset_us * 1000; @@ -520,8 +499,7 @@ static int app_tx_audio_init(struct st_app_context *ctx, ret = app_tx_audio_start_source(s); if (ret < 0) { - err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, - ret); + err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, ret); app_tx_audio_uinit(s); return ret; } @@ -531,8 +509,7 @@ static int app_tx_audio_init(struct st_app_context *ctx, int st_app_tx_audio_sessions_stop(struct st_app_context *ctx) { struct st_app_tx_audio_session *s; - if (!ctx->tx_audio_sessions) - return 0; + if (!ctx->tx_audio_sessions) return 0; for (int i = 0; i < ctx->tx_audio_session_cnt; i++) { s = &ctx->tx_audio_sessions[i]; app_tx_audio_stop_source(s); @@ -546,8 +523,7 @@ int st_app_tx_audio_sessions_init(struct st_app_context *ctx) { struct st_app_tx_audio_session *s; ctx->tx_audio_sessions = (struct st_app_tx_audio_session *)st_app_zmalloc( sizeof(struct st_app_tx_audio_session) * ctx->tx_audio_session_cnt); - if (!ctx->tx_audio_sessions) - return -ENOMEM; + if (!ctx->tx_audio_sessions) return -ENOMEM; for (int i = 0; i < ctx->tx_audio_session_cnt; i++) { s = &ctx->tx_audio_sessions[i]; @@ -566,8 +542,7 @@ int st_app_tx_audio_sessions_init(struct st_app_context *ctx) { int st_app_tx_audio_sessions_uinit(struct st_app_context *ctx) { struct st_app_tx_audio_session *s; - if (!ctx->tx_audio_sessions) - return 0; + if (!ctx->tx_audio_sessions) return 0; for (int i = 0; i < ctx->tx_audio_session_cnt; i++) { s = &ctx->tx_audio_sessions[i]; diff --git a/app/src/legacy/tx_st22_app.c b/app/src/legacy/tx_st22_app.c index 0fd746c2b..7547aaf74 100644 --- a/app/src/legacy/tx_st22_app.c +++ b/app/src/legacy/tx_st22_app.c @@ -21,14 +21,12 @@ static int app_tx_st22_next_frame(void *priv, uint16_t *next_frame_idx, meta->codestream_size = framebuff->size; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ ret = -EIO; - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, - framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -51,8 +49,8 @@ static int app_tx_st22_frame_done(void *priv, uint16_t frame_idx, s->fb_send++; } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->wake_cond); st_pthread_mutex_unlock(&s->wake_mutex); @@ -60,10 +58,8 @@ static int app_tx_st22_frame_done(void *priv, uint16_t frame_idx, return ret; } -static void app_tx_st22_build_frame(struct st22_app_tx_session *s, - void *codestream_addr, - size_t max_codestream_size, - size_t *codestream_size) { +static void app_tx_st22_build_frame(struct st22_app_tx_session *s, void *codestream_addr, + size_t max_codestream_size, size_t *codestream_size) { uint8_t *src = s->st22_frame_cursor; uint8_t *dst = codestream_addr; int framesize = s->bytes_per_frame; @@ -94,8 +90,7 @@ static void *app_tx_st22_frame_thread(void *arg) { framebuff = &s->framebuffs[producer_idx]; if (ST_TX_FRAME_FREE != framebuff->stat) { /* not in free */ - if (!s->st22_app_thread_stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->st22_app_thread_stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -111,8 +106,7 @@ static void *app_tx_st22_frame_thread(void *arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->wake_mutex); } @@ -177,8 +171,8 @@ static int app_tx_st22_open_source(struct st22_app_tx_session *s) { return -EIO; } if (i.st_size < s->bytes_per_frame) { - err("%s, %s file size small then a frame %" PRIu64 "\n", __func__, - s->st22_source_url, s->bytes_per_frame); + err("%s, %s file size small then a frame %" PRIu64 "\n", __func__, s->st22_source_url, + s->bytes_per_frame); close(fd); return -EIO; } @@ -204,8 +198,7 @@ static int app_tx_st22_handle_free(struct st22_app_tx_session *s) { if (s->handle) { ret = st22_tx_free(s->handle); - if (ret < 0) - err("%s(%d), st22_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st22_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -228,8 +221,8 @@ static int app_tx_st22_uinit(struct st22_app_tx_session *s) { return 0; } -static int app_tx_st22_init(struct st_app_context *ctx, - struct st22_app_tx_session *s, int bpp) { +static int app_tx_st22_init(struct st_app_context *ctx, struct st22_app_tx_session *s, + int bpp) { int idx = s->idx, ret; struct st22_tx_ops ops; char name[32]; @@ -249,8 +242,7 @@ static int app_tx_st22_init(struct st_app_context *ctx, ops.name = name; ops.priv = s; ops.num_port = ctx->para.num_ports; - memcpy(ops.dip_addr[MTL_SESSION_PORT_P], ctx->tx_dip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(ops.dip_addr[MTL_SESSION_PORT_P], ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops.udp_port[MTL_SESSION_PORT_P] = 15000 + s->idx; @@ -266,8 +258,8 @@ static int app_tx_st22_init(struct st_app_context *ctx, ctx->para.port[MTL_PORT_R]); ops.udp_port[MTL_SESSION_PORT_R] = 15000 + s->idx; if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], - ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], + MTL_MAC_ADDR_LEN); ops.flags |= ST22_TX_FLAG_USER_R_MAC; } } @@ -281,16 +273,14 @@ static int app_tx_st22_init(struct st_app_context *ctx, ops.framebuff_max_size = s->bytes_per_frame; ops.get_next_frame = app_tx_st22_next_frame; ops.notify_frame_done = app_tx_st22_frame_done; - if (ctx->tx_no_bulk) - ops.flags |= ST22_TX_FLAG_DISABLE_BULK; + if (ctx->tx_no_bulk) ops.flags |= ST22_TX_FLAG_DISABLE_BULK; s->framebuff_cnt = ops.framebuff_cnt; s->framebuff_producer_idx = 0; s->framebuff_consumer_idx = 0; - s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * - s->framebuff_cnt); - if (!s->framebuffs) - return -ENOMEM; + s->framebuffs = + (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); + if (!s->framebuffs) return -ENOMEM; for (uint16_t j = 0; j < s->framebuff_cnt; j++) { s->framebuffs[j].stat = ST_TX_FRAME_FREE; } @@ -321,8 +311,7 @@ static int app_tx_st22_init(struct st_app_context *ctx, return ret; } - info("%s(%d), bytes_per_frame %" PRIu64 "\n", __func__, idx, - s->bytes_per_frame); + info("%s(%d), bytes_per_frame %" PRIu64 "\n", __func__, idx, s->bytes_per_frame); return 0; } @@ -331,8 +320,7 @@ int st22_app_tx_sessions_init(struct st_app_context *ctx) { struct st22_app_tx_session *s; ctx->tx_st22_sessions = (struct st22_app_tx_session *)st_app_zmalloc( sizeof(struct st22_app_tx_session) * ctx->tx_st22_session_cnt); - if (!ctx->tx_st22_sessions) - return -ENOMEM; + if (!ctx->tx_st22_sessions) return -ENOMEM; for (i = 0; i < ctx->tx_st22_session_cnt; i++) { s = &ctx->tx_st22_sessions[i]; s->idx = i; @@ -348,8 +336,7 @@ int st22_app_tx_sessions_init(struct st_app_context *ctx) { int st22_app_tx_sessions_stop(struct st_app_context *ctx) { struct st22_app_tx_session *s; - if (!ctx->tx_st22_sessions) - return 0; + if (!ctx->tx_st22_sessions) return 0; for (int i = 0; i < ctx->tx_st22_session_cnt; i++) { s = &ctx->tx_st22_sessions[i]; app_tx_st22_stop_source(s); @@ -361,8 +348,7 @@ int st22_app_tx_sessions_stop(struct st_app_context *ctx) { int st22_app_tx_sessions_uinit(struct st_app_context *ctx) { int i; struct st22_app_tx_session *s; - if (!ctx->tx_st22_sessions) - return 0; + if (!ctx->tx_st22_sessions) return 0; for (i = 0; i < ctx->tx_st22_session_cnt; i++) { s = &ctx->tx_st22_sessions[i]; s->idx = i; diff --git a/app/src/legacy/tx_video_app.c b/app/src/legacy/tx_video_app.c index c0f61d33c..52685553f 100644 --- a/app/src/legacy/tx_video_app.c +++ b/app/src/legacy/tx_video_app.c @@ -4,8 +4,7 @@ #include "tx_video_app.h" -static int app_tx_video_notify_event(void *priv, enum st_event event, - void *args) { +static int app_tx_video_notify_event(void *priv, enum st_event event, void *args) { struct st_app_tx_video_session *s = priv; if (event == ST_EVENT_VSYNC) { struct st10_vsync_meta *meta = args; @@ -19,8 +18,7 @@ static int app_tx_video_notify_event(void *priv, enum st_event event, return 0; } -static void app_tx_video_display_frame(struct st_app_tx_video_session *s, - void *frame) { +static void app_tx_video_display_frame(struct st_app_tx_video_session *s, void *frame) { struct st_display *d = s->display; if (d && d->front_frame) { @@ -28,8 +26,7 @@ static void app_tx_video_display_frame(struct st_app_tx_video_session *s, if (s->st20_pg.fmt == ST20_FMT_YUV_422_8BIT) mtl_memcpy(d->front_frame, frame, d->front_frame_size); else if (s->st20_pg.fmt == ST20_FMT_YUV_422_10BIT) - st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, - s->height); + st20_rfc4175_422be10_to_422le8(frame, d->front_frame, s->width, s->height); else /* fmt mismatch*/ { st_pthread_mutex_unlock(&d->display_frame_mutex); return; @@ -52,10 +49,9 @@ static int app_tx_video_next_frame(void *priv, uint16_t *next_frame_idx, st_pthread_mutex_lock(&s->st20_wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { - dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", - __func__, s->idx, consumer_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, - ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, + s->idx, consumer_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); ret = 0; framebuff->stat = ST_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = consumer_idx; @@ -66,14 +62,12 @@ static int app_tx_video_next_frame(void *priv, uint16_t *next_frame_idx, } /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ ret = -EIO; - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, - framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); } st_pthread_cond_signal(&s->st20_wake_cond); st_pthread_mutex_unlock(&s->st20_wake_mutex); @@ -92,14 +86,13 @@ static int app_tx_video_frame_done(void *priv, uint16_t frame_idx, if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { ret = 0; framebuff->stat = ST_TX_FRAME_FREE; - dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", - __func__, s->idx, frame_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, - ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, + s->idx, frame_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->st20_wake_cond); st_pthread_mutex_unlock(&s->st20_wake_mutex); @@ -142,8 +135,7 @@ static void app_tx_video_thread_bind(struct st_app_tx_video_session *s) { } } -static void app_tx_video_check_lcore(struct st_app_tx_video_session *s, - bool rtp) { +static void app_tx_video_check_lcore(struct st_app_tx_video_session *s, bool rtp) { int sch_idx = st20_tx_get_sch_idx(s->handle); if (s->ctx->app_bind_lcore && (s->handle_sch_idx != sch_idx)) { @@ -158,8 +150,8 @@ static void app_tx_video_check_lcore(struct st_app_tx_video_session *s, } } -static void app_tx_video_build_frame(struct st_app_tx_video_session *s, - void *frame, size_t frame_size) { +static void app_tx_video_build_frame(struct st_app_tx_video_session *s, void *frame, + size_t frame_size) { uint8_t *src = s->st20_frame_cursor; if (!s->ctx->tx_copy_once || !s->st20_frames_copied) { @@ -176,8 +168,7 @@ static void app_tx_video_build_frame(struct st_app_tx_video_session *s, } static void app_tx_video_build_slice(struct st_app_tx_video_session *s, - struct st_tx_frame *framebuff, - void *frame_addr) { + struct st_tx_frame *framebuff, void *frame_addr) { int lines_build = 0; int bytes_per_slice = framebuff->size / s->height * s->lines_per_slice; int frame_size = framebuff->size; @@ -206,8 +197,7 @@ static void app_tx_video_build_slice(struct st_app_tx_video_session *s, while (lines_build < s->height) { int lines = s->lines_per_slice; - if ((lines_build + lines) > s->height) - lines = s->height - lines_build; + if ((lines_build + lines) > s->height) lines = s->height - lines_build; int bytes_slice = framebuff->size / s->height * lines; lines_build += lines; @@ -251,8 +241,7 @@ static void *app_tx_video_frame_thread(void *arg) { app_tx_video_build_frame(s, frame_addr, s->st20_frame_size); } if (s->sha_check) { - st_sha256((unsigned char *)frame_addr, s->st20_frame_size, - framebuff->shas); + st_sha256((unsigned char *)frame_addr, s->st20_frame_size, framebuff->shas); // st_sha_dump("frame sha:", framebuff->shas); } @@ -262,8 +251,7 @@ static void *app_tx_video_frame_thread(void *arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; if (s->interlaced) { s->second_field = !s->second_field; @@ -318,11 +306,10 @@ static void *app_tx_video_pcap_thread(void *arg) { if (ntohs(eth_hdr->ether_type) == ETHERTYPE_IP) { ip_hdr = (struct ip *)(packet + sizeof(struct ether_header)); if (ip_hdr->ip_p == IPPROTO_UDP) { - udp_hdr = (struct udphdr *)(packet + sizeof(struct ether_header) + - sizeof(struct ip)); + udp_hdr = + (struct udphdr *)(packet + sizeof(struct ether_header) + sizeof(struct ip)); udp_data_len = ntohs(udp_hdr->len) - sizeof(struct udphdr); - dbg("%s(%d), packet %p udp_data_len %u\n", __func__, idx, packet, - udp_data_len); + dbg("%s(%d), packet %p udp_data_len %u\n", __func__, idx, packet, udp_data_len); mtl_memcpy(usrptr, packet + sizeof(struct ether_header) + sizeof(struct ip) + sizeof(struct udphdr), @@ -335,8 +322,7 @@ static void *app_tx_video_pcap_thread(void *arg) { /* open capture file for offline processing */ s->st20_pcap = pcap_open_offline(s->st20_source_url, err_buf); if (s->st20_pcap == NULL) { - err("pcap_open_offline %s() failed: %s\n:", s->st20_source_url, - err_buf); + err("pcap_open_offline %s() failed: %s\n:", s->st20_source_url, err_buf); return NULL; } } @@ -368,33 +354,30 @@ static int app_tx_video_init_rtp(struct st_app_tx_video_session *s, s->st20_pkt_idx = 0; s->st20_seq_id = 1; int height = ops->height; - if (ops->interlaced) - height = height >> 1; + if (ops->interlaced) height = height >> 1; if (ops->packing == ST20_PACKING_GPM_SL) { /* calculate pkts in line for rtp */ size_t bytes_in_pkt = MTL_PKT_MAX_RTP_BYTES - sizeof(*rtp); s->st20_pkts_in_line = (s->st20_bytes_in_line / bytes_in_pkt) + 1; s->st20_total_pkts = height * s->st20_pkts_in_line; - int pixels_in_pkts = - (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; + int pixels_in_pkts = (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; s->st20_pkt_data_len = (pixels_in_pkts + s->st20_pg.coverage - 1) / s->st20_pg.coverage * s->st20_pg.size; info("%s(%d), %d pkts(%d) in line\n", __func__, idx, s->st20_pkts_in_line, s->st20_pkt_data_len); } else if (ops->packing == ST20_PACKING_BPM) { s->st20_pkt_data_len = 1260; - int pixels_in_pkts = - s->st20_pkt_data_len * s->st20_pg.coverage / s->st20_pg.size; + int pixels_in_pkts = s->st20_pkt_data_len * s->st20_pg.coverage / s->st20_pg.size; s->st20_total_pkts = ceil((double)ops->width * height / pixels_in_pkts); info("%s(%d), %d pkts(%d) in frame\n", __func__, idx, s->st20_total_pkts, s->st20_pkt_data_len); } else if (ops->packing == ST20_PACKING_GPM) { - int max_data_len = MTL_PKT_MAX_RTP_BYTES - sizeof(*rtp) - - sizeof(struct st20_rfc4175_extra_rtp_hdr); + int max_data_len = + MTL_PKT_MAX_RTP_BYTES - sizeof(*rtp) - sizeof(struct st20_rfc4175_extra_rtp_hdr); int pg_per_pkt = max_data_len / s->st20_pg.size; - s->st20_total_pkts = (ceil)((double)ops->width * height / - (s->st20_pg.coverage * pg_per_pkt)); + s->st20_total_pkts = + (ceil)((double)ops->width * height / (s->st20_pg.coverage * pg_per_pkt)); s->st20_pkt_data_len = pg_per_pkt * s->st20_pg.size; } else { err("%s(%d), invalid packing mode: %d\n", __func__, idx, ops->packing); @@ -429,18 +412,14 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session *s, if (s->single_line) { row_number = s->st20_pkt_idx / s->st20_pkts_in_line; - int pixels_in_pkt = - s->st20_pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; + int pixels_in_pkt = s->st20_pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; row_offset = pixels_in_pkt * (s->st20_pkt_idx % s->st20_pkts_in_line); - offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * - s->st20_pg.size; + offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; } else { offset = s->st20_pkt_data_len * s->st20_pkt_idx; row_number = offset / s->st20_bytes_in_line; - row_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / - s->st20_pg.size; - if ((offset + s->st20_pkt_data_len > - (row_number + 1) * s->st20_bytes_in_line) && + row_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; + if ((offset + s->st20_pkt_data_len > (row_number + 1) * s->st20_bytes_in_line) && (offset + s->st20_pkt_data_len < s->st20_frame_size)) { e_rtp = (struct st20_rfc4175_extra_rtp_hdr *)payload; payload += sizeof(*e_rtp); @@ -460,10 +439,9 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session *s, rtp->seq_number_ext = htons((uint16_t)(s->st20_seq_id >> 16)); s->st20_seq_id++; - int temp = - s->single_line - ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (s->st20_frame_size - offset); + int temp = s->single_line + ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (s->st20_frame_size - offset); uint16_t data_len = s->st20_pkt_data_len > temp ? temp : s->st20_pkt_data_len; rtp->row_length = htons(data_len); *pkt_len = data_len + sizeof(*rtp); @@ -492,8 +470,8 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session *s, data_len); else mtl_memcpy(payload, - frame + (2 * row_number * s->width + row_offset) / - s->st20_pg.coverage * s->st20_pg.size, + frame + (2 * row_number * s->width + row_offset) / s->st20_pg.coverage * + s->st20_pg.size, data_len); } @@ -508,13 +486,11 @@ static int app_tx_video_build_rtp_packet(struct st_app_tx_video_session *s, s->st20_frame_done_cnt++; if (!s->stat_frame_first_tx_time) s->stat_frame_first_tx_time = st_app_get_monotonic_time(); - int frame_size = - s->interlaced ? s->st20_frame_size * 2 : s->st20_frame_size; + int frame_size = s->interlaced ? s->st20_frame_size * 2 : s->st20_frame_size; if (!s->interlaced) { s->st20_frame_cursor += frame_size; } else { - if (s->st20_second_field) - s->st20_frame_cursor += frame_size; + if (s->st20_second_field) s->st20_frame_cursor += frame_size; s->st20_second_field = !s->st20_second_field; } if ((s->st20_frame_cursor + frame_size) > s->st20_source_end) @@ -552,8 +528,7 @@ static void *app_tx_video_rtp_thread(void *arg) { } /* build the rtp pkt */ - app_tx_video_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr *)usrptr, - &mbuf_len); + app_tx_video_build_rtp_packet(s, (struct st20_rfc4175_rtp_hdr *)usrptr, &mbuf_len); st20_tx_put_mbuf(s->handle, mbuf, mbuf_len); @@ -581,8 +556,8 @@ static int app_tx_video_open_source(struct st_app_tx_video_session *s) { return -EIO; } if (i.st_size < s->st20_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, - s->st20_source_url, s->st20_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, s->st20_source_url, + s->st20_frame_size); close(fd); return -EIO; } @@ -626,13 +601,11 @@ static int app_tx_video_start_source(struct st_app_tx_video_session *s) { int idx = s->idx; if (s->st20_pcap_input) - ret = - pthread_create(&s->st20_app_thread, NULL, app_tx_video_pcap_thread, s); + ret = pthread_create(&s->st20_app_thread, NULL, app_tx_video_pcap_thread, s); else if (s->st20_rtp_input) ret = pthread_create(&s->st20_app_thread, NULL, app_tx_video_rtp_thread, s); else - ret = - pthread_create(&s->st20_app_thread, NULL, app_tx_video_frame_thread, s); + ret = pthread_create(&s->st20_app_thread, NULL, app_tx_video_frame_thread, s); if (ret < 0) { err("%s(%d), st20_app_thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -682,8 +655,7 @@ static int app_tx_video_handle_free(struct st_app_tx_video_session *s) { if (s->handle) { ret = st20_tx_free(s->handle); - if (ret < 0) - err("%s(%d), st20_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st20_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -713,17 +685,14 @@ static int app_tx_video_uinit(struct st_app_tx_video_session *s) { static int app_tx_video_result(struct st_app_tx_video_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_tx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_tx_time) / NS_PER_S; double framerate = s->st20_frame_done_cnt / time_sec; - if (!s->st20_frame_done_cnt) - return -EINVAL; + if (!s->st20_frame_done_cnt) return -EINVAL; critical("%s(%d), %s, fps %f, %d frames send\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) - ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" + : "FAILED", framerate, s->st20_frame_done_cnt); return 0; } @@ -736,13 +705,11 @@ static int app_tx_video_io_stat(struct st_app_tx_video_session *s) { int ret; struct st20_tx_port_status stats; - if (!s->handle) - return 0; + if (!s->handle) return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20_tx_get_port_stats(s->handle, port, &stats); - if (ret < 0) - return ret; + if (ret < 0) return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -754,8 +721,7 @@ static int app_tx_video_io_stat(struct st_app_tx_video_session *s) { return 0; } -static int app_tx_video_init(struct st_app_context *ctx, - st_json_video_session_t *video, +static int app_tx_video_init(struct st_app_context *ctx, st_json_video_session_t *video, struct st_app_tx_video_session *s) { int idx = s->idx, ret; struct st20_tx_ops ops; @@ -776,11 +742,10 @@ static int app_tx_video_init(struct st_app_context *ctx, video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = - video ? video->base.udp_port : (10000 + s->idx); + snprintf( + ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = video ? video->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -791,14 +756,13 @@ static int app_tx_video_init(struct st_app_context *ctx, video ? st_json_ip(ctx, &video->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - video ? video->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = - video ? video->base.udp_port : (10000 + s->idx); + snprintf( + ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + video ? video->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = video ? video->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], - ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], + MTL_MAC_ADDR_LEN); ops.flags |= ST20_TX_FLAG_USER_R_MAC; } } @@ -811,29 +775,22 @@ static int app_tx_video_init(struct st_app_context *ctx, ops.height = video ? st_app_get_height(video->info.video_format) : 1080; ops.fps = video ? st_app_get_fps(video->info.video_format) : ST_FPS_P59_94; ops.fmt = video ? video->info.pg_format : ST20_FMT_YUV_422_10BIT; - ops.interlaced = - video ? st_app_get_interlaced(video->info.video_format) : false; + ops.interlaced = video ? st_app_get_interlaced(video->info.video_format) : false; ops.get_next_frame = app_tx_video_next_frame; ops.notify_frame_done = app_tx_video_frame_done; ops.query_frame_lines_ready = app_tx_video_frame_lines_ready; ops.notify_rtp_done = app_tx_video_rtp_done; ops.notify_event = app_tx_video_notify_event; ops.framebuff_cnt = 2; - ops.payload_type = - video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.payload_type = video ? video->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.start_vrx = ctx->tx_start_vrx; ops.pad_interval = ctx->tx_pad_interval; ops.rtp_timestamp_delta_us = ctx->tx_ts_delta_us; - if (s->enable_vsync) - ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; - if (ctx->tx_no_static_pad) - ops.flags |= ST20_TX_FLAG_DISABLE_STATIC_PAD_P; - if (ctx->tx_ts_first_pkt) - ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; - if (ctx->tx_ts_epoch) - ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH; - if (ctx->tx_no_bulk) - ops.flags |= ST20_TX_FLAG_DISABLE_BULK; + if (s->enable_vsync) ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; + if (ctx->tx_no_static_pad) ops.flags |= ST20_TX_FLAG_DISABLE_STATIC_PAD_P; + if (ctx->tx_ts_first_pkt) ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; + if (ctx->tx_ts_epoch) ops.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH; + if (ctx->tx_no_bulk) ops.flags |= ST20_TX_FLAG_DISABLE_BULK; if (ctx->force_tx_video_numa >= 0) { ops.flags |= ST20_TX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_tx_video_numa; @@ -845,8 +802,7 @@ static int app_tx_video_init(struct st_app_context *ctx, } ret = st20_get_pgroup(ops.fmt, &s->st20_pg); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->width = ops.width; s->height = ops.height; if (ops.interlaced) { @@ -868,8 +824,8 @@ static int app_tx_video_init(struct st_app_context *ctx, s->lines_per_slice = ops.height / 30; s->st20_source_fd = -1; - s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * - s->framebuff_cnt); + s->framebuffs = + (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); if (!s->framebuffs) { return -ENOMEM; } @@ -909,13 +865,11 @@ static int app_tx_video_init(struct st_app_context *ctx, s->handle_sch_idx = st20_tx_get_sch_idx(handle); unsigned int lcore; bool rtp = false; - if (ops.type == ST20_TYPE_RTP_LEVEL) - rtp = true; + if (ops.type == ST20_TYPE_RTP_LEVEL) rtp = true; if (ctx->app_bind_lcore) { ret = st_app_video_get_lcore(ctx, s->handle_sch_idx, rtp, &lcore); - if (ret >= 0) - s->lcore = lcore; + if (ret >= 0) s->lcore = lcore; } ret = app_tx_video_open_source(s); @@ -950,8 +904,7 @@ int st_app_tx_video_sessions_init(struct st_app_context *ctx) { struct st_app_tx_video_session *s; ctx->tx_video_sessions = (struct st_app_tx_video_session *)st_app_zmalloc( sizeof(struct st_app_tx_video_session) * ctx->tx_video_session_cnt); - if (!ctx->tx_video_sessions) - return -ENOMEM; + if (!ctx->tx_video_sessions) return -ENOMEM; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; s->idx = i; @@ -969,8 +922,7 @@ int st_app_tx_video_sessions_init(struct st_app_context *ctx) { int st_app_tx_video_sessions_stop(struct st_app_context *ctx) { struct st_app_tx_video_session *s; - if (!ctx->tx_video_sessions) - return 0; + if (!ctx->tx_video_sessions) return 0; for (int i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; app_tx_video_stop_source(s); @@ -982,8 +934,7 @@ int st_app_tx_video_sessions_stop(struct st_app_context *ctx) { int st_app_tx_video_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_tx_video_session *s; - if (!ctx->tx_video_sessions) - return 0; + if (!ctx->tx_video_sessions) return 0; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; app_tx_video_uinit(s); @@ -996,8 +947,7 @@ int st_app_tx_video_sessions_uinit(struct st_app_context *ctx) { int st_app_tx_video_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_tx_video_session *s; - if (!ctx->tx_video_sessions) - return 0; + if (!ctx->tx_video_sessions) return 0; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; @@ -1010,8 +960,7 @@ int st_app_tx_video_sessions_result(struct st_app_context *ctx) { int st_app_tx_videos_io_stat(struct st_app_context *ctx) { int i, ret = 0; struct st_app_tx_video_session *s; - if (!ctx->tx_video_sessions) - return 0; + if (!ctx->tx_video_sessions) return 0; for (i = 0; i < ctx->tx_video_session_cnt; i++) { s = &ctx->tx_video_sessions[i]; diff --git a/app/src/log.h b/app/src/log.h index 4c9ade9c9..4a3f644cc 100644 --- a/app/src/log.h +++ b/app/src/log.h @@ -13,39 +13,34 @@ enum mtl_log_level app_get_log_level(void); /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_DEBUG) \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_DEBUG) printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_INFO) \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_INFO) printf(__VA_ARGS__); \ } while (0) -#define notce(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_NOTICE) \ - printf(__VA_ARGS__); \ +#define notce(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_NOTICE) printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_WARNING) \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_WARNING) printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - if (app_get_log_level() <= MTL_LOG_LEVEL_ERR) \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + if (app_get_log_level() <= MTL_LOG_LEVEL_ERR) printf(__VA_ARGS__); \ } while (0) -#define critical(...) \ - do { \ - printf(__VA_ARGS__); \ +#define critical(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif diff --git a/app/src/parse_json.c b/app/src/parse_json.c index be34a1f02..90c16650f 100644 --- a/app/src/parse_json.c +++ b/app/src/parse_json.c @@ -7,19 +7,16 @@ #include "app_base.h" #include "log.h" -#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ +#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ (JSON_C_VERSION_NUM < ((0 << 16) | (10 << 8) | 0)) -static inline json_object *st_json_object_object_get(json_object *obj, - const char *key) { +static inline json_object *st_json_object_object_get(json_object *obj, const char *key) { return json_object_object_get(obj, key); } #else -static inline json_object *st_json_object_object_get(json_object *obj, - const char *key) { +static inline json_object *st_json_object_object_get(json_object *obj, const char *key) { json_object *value; int ret = json_object_object_get_ex(obj, key, &value); - if (ret) - return value; + if (ret) return value; dbg("%s, can not get object with key: %s!\n", __func__, key); return NULL; } @@ -457,12 +454,12 @@ static const struct st_video_fmt_desc st_video_fmt_descs[] = { #define VNAME(name) (#name) -#define REQUIRED_ITEM(string) \ - do { \ - if (string == NULL) { \ - err("%s, can not parse %s\n", __func__, VNAME(string)); \ - return -ST_JSON_PARSE_FAIL; \ - } \ +#define REQUIRED_ITEM(string) \ + do { \ + if (string == NULL) { \ + err("%s, can not parse %s\n", __func__, VNAME(string)); \ + return -ST_JSON_PARSE_FAIL; \ + } \ } while (0) /* 7 bits payload type define in RFC3550 */ @@ -485,10 +482,8 @@ static int st_json_parse_interfaces(json_object *interface_obj, REQUIRED_ITEM(name); snprintf(interface->name, sizeof(interface->name), "%s", name); - const char *ip = - json_object_get_string(st_json_object_object_get(interface_obj, "ip")); - if (ip) - inet_pton(AF_INET, ip, interface->ip_addr); + const char *ip = json_object_get_string(st_json_object_object_get(interface_obj, "ip")); + if (ip) inet_pton(AF_INET, ip, interface->ip_addr); json_object *obj = st_json_object_object_get(interface_obj, "netmask"); if (obj) { @@ -532,10 +527,8 @@ static int st_json_parse_interfaces(json_object *interface_obj, return ST_JSON_SUCCESS; } -static int parse_base_udp_port(json_object *obj, st_json_session_base_t *base, - int idx) { - int start_port = - json_object_get_int(st_json_object_object_get(obj, "start_port")); +static int parse_base_udp_port(json_object *obj, st_json_session_base_t *base, int idx) { + int start_port = json_object_get_int(st_json_object_object_get(obj, "start_port")); if (start_port <= 0 || start_port > 65535) { err("%s, invalid start port %d\n", __func__, start_port); return -ST_JSON_NOT_VALID; @@ -545,10 +538,8 @@ static int parse_base_udp_port(json_object *obj, st_json_session_base_t *base, return ST_JSON_SUCCESS; } -static int parse_base_payload_type(json_object *obj, - st_json_session_base_t *base) { - json_object *payload_type_object = - st_json_object_object_get(obj, "payload_type"); +static int parse_base_payload_type(json_object *obj, st_json_session_base_t *base) { + json_object *payload_type_object = st_json_object_object_get(obj, "payload_type"); if (payload_type_object) { base->payload_type = json_object_get_int(payload_type_object); if (!st_json_is_valid_payload_type(base->payload_type)) { @@ -562,10 +553,8 @@ static int parse_base_payload_type(json_object *obj, return ST_JSON_SUCCESS; } -static int parse_video_type(json_object *video_obj, - st_json_video_session_t *video) { - const char *type = - json_object_get_string(st_json_object_object_get(video_obj, "type")); +static int parse_video_type(json_object *video_obj, st_json_video_session_t *video) { + const char *type = json_object_get_string(st_json_object_object_get(video_obj, "type")); REQUIRED_ITEM(type); if (strcmp(type, "frame") == 0) { video->info.type = ST20_TYPE_FRAME_LEVEL; @@ -580,8 +569,7 @@ static int parse_video_type(json_object *video_obj, return ST_JSON_SUCCESS; } -static int parse_video_pacing(json_object *video_obj, - st_json_video_session_t *video) { +static int parse_video_pacing(json_object *video_obj, st_json_video_session_t *video) { const char *pacing = json_object_get_string(st_json_object_object_get(video_obj, "pacing")); REQUIRED_ITEM(pacing); @@ -600,8 +588,7 @@ static int parse_video_pacing(json_object *video_obj, return ST_JSON_SUCCESS; } -static int parse_video_packing(json_object *video_obj, - st_json_video_session_t *video) { +static int parse_video_packing(json_object *video_obj, st_json_video_session_t *video) { const char *packing = json_object_get_string(st_json_object_object_get(video_obj, "packing")); if (packing) { @@ -621,8 +608,7 @@ static int parse_video_packing(json_object *video_obj, return ST_JSON_SUCCESS; } -static int parse_video_tr_offset(json_object *video_obj, - st_json_video_session_t *video) { +static int parse_video_tr_offset(json_object *video_obj, st_json_video_session_t *video) { const char *tr_offset = json_object_get_string(st_json_object_object_get(video_obj, "tr_offset")); REQUIRED_ITEM(tr_offset); @@ -637,10 +623,9 @@ static int parse_video_tr_offset(json_object *video_obj, return ST_JSON_SUCCESS; } -static int parse_video_format(json_object *video_obj, - st_json_video_session_t *video) { - const char *video_format = json_object_get_string( - st_json_object_object_get(video_obj, "video_format")); +static int parse_video_format(json_object *video_obj, st_json_video_session_t *video) { + const char *video_format = + json_object_get_string(st_json_object_object_get(video_obj, "video_format")); REQUIRED_ITEM(video_format); int i; for (i = 0; i < ARRAY_SIZE(st_video_fmt_descs); i++) { @@ -653,8 +638,7 @@ static int parse_video_format(json_object *video_obj, return -ST_JSON_NOT_VALID; } -static int parse_video_pg_format(json_object *video_obj, - st_json_video_session_t *video) { +static int parse_video_pg_format(json_object *video_obj, st_json_video_session_t *video) { const char *pg_format = json_object_get_string(st_json_object_object_get(video_obj, "pg_format")); REQUIRED_ITEM(pg_format); @@ -702,8 +686,7 @@ static int parse_video_pg_format(json_object *video_obj, } static int parse_url(json_object *obj, const char *name, char *url) { - const char *url_src = - json_object_get_string(st_json_object_object_get(obj, name)); + const char *url_src = json_object_get_string(st_json_object_object_get(obj, name)); REQUIRED_ITEM(url_src); snprintf(url, ST_APP_URL_MAX_LEN, "%s", url_src); return -ST_JSON_SUCCESS; @@ -719,8 +702,7 @@ static int st_json_parse_tx_video(int idx, json_object *video_obj, /* parse udp port */ ret = parse_base_udp_port(video_obj, &video->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(video_obj, &video->base); @@ -731,46 +713,39 @@ static int st_json_parse_tx_video(int idx, json_object *video_obj, /* parse video type */ ret = parse_video_type(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse video pacing */ ret = parse_video_pacing(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse video packing mode */ ret = parse_video_packing(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse tr offset */ ret = parse_video_tr_offset(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse video format */ ret = parse_video_format(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse pixel group format */ ret = parse_video_pg_format(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse video url */ ret = parse_url(video_obj, "video_url", video->info.video_url); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse display option */ video->display = json_object_get_boolean(st_json_object_object_get(video_obj, "display")); /* parse enable rtcp */ - video->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(video_obj, "enable_rtcp")); + video->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(video_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -785,8 +760,7 @@ static int st_json_parse_rx_video(int idx, json_object *video_obj, /* parse udp port */ ret = parse_base_udp_port(video_obj, &video->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(video_obj, &video->base); @@ -797,33 +771,28 @@ static int st_json_parse_rx_video(int idx, json_object *video_obj, /* parse video type */ ret = parse_video_type(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse video pacing */ ret = parse_video_pacing(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse tr offset */ ret = parse_video_tr_offset(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse video format */ ret = parse_video_format(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse pixel group format */ ret = parse_video_pg_format(video_obj, video); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse user pixel group format */ video->user_pg_format = USER_FMT_MAX; - const char *user_pg_format = json_object_get_string( - st_json_object_object_get(video_obj, "user_pg_format")); + const char *user_pg_format = + json_object_get_string(st_json_object_object_get(video_obj, "user_pg_format")); if (user_pg_format != NULL) { if (strcmp(user_pg_format, "YUV_422_8bit") == 0) { video->user_pg_format = USER_FMT_YUV_422_8BIT; @@ -838,20 +807,18 @@ static int st_json_parse_rx_video(int idx, json_object *video_obj, json_object_get_boolean(st_json_object_object_get(video_obj, "display")); /* parse measure_latency option */ - video->measure_latency = json_object_get_boolean( - st_json_object_object_get(video_obj, "measure_latency")); + video->measure_latency = + json_object_get_boolean(st_json_object_object_get(video_obj, "measure_latency")); /* parse enable rtcp */ - video->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(video_obj, "enable_rtcp")); + video->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(video_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int parse_audio_type(json_object *audio_obj, - st_json_audio_info_t *audio) { - const char *type = - json_object_get_string(st_json_object_object_get(audio_obj, "type")); +static int parse_audio_type(json_object *audio_obj, st_json_audio_info_t *audio) { + const char *type = json_object_get_string(st_json_object_object_get(audio_obj, "type")); REQUIRED_ITEM(type); if (strcmp(type, "frame") == 0) { audio->type = ST30_TYPE_FRAME_LEVEL; @@ -864,10 +831,9 @@ static int parse_audio_type(json_object *audio_obj, return ST_JSON_SUCCESS; } -static int parse_audio_format(json_object *audio_obj, - st_json_audio_info_t *audio) { - const char *audio_format = json_object_get_string( - st_json_object_object_get(audio_obj, "audio_format")); +static int parse_audio_format(json_object *audio_obj, st_json_audio_info_t *audio) { + const char *audio_format = + json_object_get_string(st_json_object_object_get(audio_obj, "audio_format")); REQUIRED_ITEM(audio_format); if (strcmp(audio_format, "PCM8") == 0) { audio->audio_format = ST30_FMT_PCM8; @@ -884,8 +850,7 @@ static int parse_audio_format(json_object *audio_obj, return ST_JSON_SUCCESS; } -static int parse_audio_channel(json_object *audio_obj, - st_json_audio_info_t *audio) { +static int parse_audio_channel(json_object *audio_obj, st_json_audio_info_t *audio) { json_object *audio_channel_array = st_json_object_object_get(audio_obj, "audio_channel"); if (audio_channel_array == NULL || @@ -895,8 +860,7 @@ static int parse_audio_channel(json_object *audio_obj, } audio->audio_channel = 0; /* reset channel number*/ for (int i = 0; i < json_object_array_length(audio_channel_array); ++i) { - json_object *channel_obj = - json_object_array_get_idx(audio_channel_array, i); + json_object *channel_obj = json_object_array_get_idx(audio_channel_array, i); const char *channel = json_object_get_string(channel_obj); REQUIRED_ITEM(channel); if (strcmp(channel, "M") == 0) { @@ -916,8 +880,7 @@ static int parse_audio_channel(json_object *audio_obj, channel[2] >= '0' && channel[2] <= '9' && channel[3] == '\0') { int num_channel = (channel[1] - '0') * 10 + (channel[2] - '0'); if (num_channel < 1 || num_channel > 64) { - err("%s, audio undefined channel number out of range %s\n", __func__, - channel); + err("%s, audio undefined channel number out of range %s\n", __func__, channel); return -ST_JSON_NOT_VALID; } audio->audio_channel += num_channel; @@ -929,10 +892,9 @@ static int parse_audio_channel(json_object *audio_obj, return ST_JSON_SUCCESS; } -static int parse_audio_sampling(json_object *audio_obj, - st_json_audio_info_t *audio) { - const char *audio_sampling = json_object_get_string( - st_json_object_object_get(audio_obj, "audio_sampling")); +static int parse_audio_sampling(json_object *audio_obj, st_json_audio_info_t *audio) { + const char *audio_sampling = + json_object_get_string(st_json_object_object_get(audio_obj, "audio_sampling")); REQUIRED_ITEM(audio_sampling); if (strcmp(audio_sampling, "48kHz") == 0) { audio->audio_sampling = ST30_SAMPLING_48K; @@ -947,10 +909,9 @@ static int parse_audio_sampling(json_object *audio_obj, return ST_JSON_SUCCESS; } -static int parse_audio_ptime(json_object *audio_obj, - st_json_audio_info_t *audio) { - const char *audio_ptime = json_object_get_string( - st_json_object_object_get(audio_obj, "audio_ptime")); +static int parse_audio_ptime(json_object *audio_obj, st_json_audio_info_t *audio) { + const char *audio_ptime = + json_object_get_string(st_json_object_object_get(audio_obj, "audio_ptime")); if (audio_ptime) { if (strcmp(audio_ptime, "1") == 0) { audio->audio_ptime = ST30_PTIME_1MS; @@ -992,8 +953,7 @@ static int st_json_parse_tx_audio(int idx, json_object *audio_obj, /* parse udp port */ ret = parse_base_udp_port(audio_obj, &audio->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(audio_obj, &audio->base); @@ -1004,37 +964,31 @@ static int st_json_parse_tx_audio(int idx, json_object *audio_obj, /* parse audio type */ ret = parse_audio_type(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio format */ ret = parse_audio_format(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio channel */ ret = parse_audio_channel(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio sampling */ ret = parse_audio_sampling(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio packet time */ ret = parse_audio_ptime(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio url */ ret = parse_url(audio_obj, "audio_url", audio->info.audio_url); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse enable rtcp */ - audio->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(audio_obj, "enable_rtcp")); + audio->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(audio_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -1049,8 +1003,7 @@ static int st_json_parse_st30p(int idx, json_object *st30p_obj, /* parse udp port */ ret = parse_base_udp_port(st30p_obj, &st30p->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(st30p_obj, &st30p->base); @@ -1061,23 +1014,19 @@ static int st_json_parse_st30p(int idx, json_object *st30p_obj, /* parse audio format */ ret = parse_audio_format(st30p_obj, &st30p->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio channel */ ret = parse_audio_channel(st30p_obj, &st30p->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio sampling */ ret = parse_audio_sampling(st30p_obj, &st30p->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio packet time */ ret = parse_audio_ptime(st30p_obj, &st30p->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio url */ ret = parse_url(st30p_obj, "audio_url", st30p->info.audio_url); @@ -1091,8 +1040,8 @@ static int st_json_parse_st30p(int idx, json_object *st30p_obj, } /* parse enable rtcp */ - st30p->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(st30p_obj, "enable_rtcp")); + st30p->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(st30p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -1107,8 +1056,7 @@ static int st_json_parse_rx_audio(int idx, json_object *audio_obj, /* parse udp port */ ret = parse_base_udp_port(audio_obj, &audio->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(audio_obj, &audio->base); @@ -1119,28 +1067,23 @@ static int st_json_parse_rx_audio(int idx, json_object *audio_obj, /* parse audio type */ ret = parse_audio_type(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio format */ ret = parse_audio_format(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio channel */ ret = parse_audio_channel(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio sampling */ ret = parse_audio_sampling(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio packet time */ ret = parse_audio_ptime(audio_obj, &audio->info); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse audio url */ ret = parse_url(audio_obj, "audio_url", audio->info.audio_url); @@ -1149,8 +1092,8 @@ static int st_json_parse_rx_audio(int idx, json_object *audio_obj, } /* parse enable rtcp */ - audio->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(audio_obj, "enable_rtcp")); + audio->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(audio_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -1165,8 +1108,7 @@ static int st_json_parse_tx_anc(int idx, json_object *anc_obj, /* parse udp port */ ret = parse_base_udp_port(anc_obj, &anc->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(anc_obj, &anc->base); @@ -1176,8 +1118,7 @@ static int st_json_parse_tx_anc(int idx, json_object *anc_obj, } /* parse anc type */ - const char *type = - json_object_get_string(st_json_object_object_get(anc_obj, "type")); + const char *type = json_object_get_string(st_json_object_object_get(anc_obj, "type")); REQUIRED_ITEM(type); if (strcmp(type, "frame") == 0) { anc->info.type = ST40_TYPE_FRAME_LEVEL; @@ -1188,8 +1129,8 @@ static int st_json_parse_tx_anc(int idx, json_object *anc_obj, return -ST_JSON_NOT_VALID; } /* parse anc format */ - const char *anc_format = json_object_get_string( - st_json_object_object_get(anc_obj, "ancillary_format")); + const char *anc_format = + json_object_get_string(st_json_object_object_get(anc_obj, "ancillary_format")); REQUIRED_ITEM(anc_format); if (strcmp(anc_format, "closed_caption") == 0) { anc->info.anc_format = ANC_FORMAT_CLOSED_CAPTION; @@ -1199,8 +1140,8 @@ static int st_json_parse_tx_anc(int idx, json_object *anc_obj, } /* parse anc fps */ - const char *anc_fps = json_object_get_string( - st_json_object_object_get(anc_obj, "ancillary_fps")); + const char *anc_fps = + json_object_get_string(st_json_object_object_get(anc_obj, "ancillary_fps")); REQUIRED_ITEM(anc_fps); if (strcmp(anc_fps, "p59") == 0) { anc->info.anc_fps = ST_FPS_P59_94; @@ -1230,20 +1171,18 @@ static int st_json_parse_tx_anc(int idx, json_object *anc_obj, } /* parse anc interlaced */ - json_object *anc_interlaced = - st_json_object_object_get(anc_obj, "interlaced"); + json_object *anc_interlaced = st_json_object_object_get(anc_obj, "interlaced"); if (anc_interlaced) { anc->info.interlaced = json_object_get_boolean(anc_interlaced); } /* parse anc url */ ret = parse_url(anc_obj, "ancillary_url", anc->info.anc_url); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse enable rtcp */ - anc->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(anc_obj, "enable_rtcp")); + anc->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(anc_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -1258,8 +1197,7 @@ static int st_json_parse_rx_anc(int idx, json_object *anc_obj, /* parse udp port */ ret = parse_base_udp_port(anc_obj, &anc->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(anc_obj, &anc->base); @@ -1269,23 +1207,20 @@ static int st_json_parse_rx_anc(int idx, json_object *anc_obj, } /* parse anc interlaced */ - json_object *anc_interlaced = - st_json_object_object_get(anc_obj, "interlaced"); + json_object *anc_interlaced = st_json_object_object_get(anc_obj, "interlaced"); if (anc_interlaced) { anc->info.interlaced = json_object_get_boolean(anc_interlaced); } /* parse enable rtcp */ - anc->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(anc_obj, "enable_rtcp")); + anc->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(anc_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int parse_st22p_width(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { - int width = - json_object_get_int(st_json_object_object_get(st22p_obj, "width")); +static int parse_st22p_width(json_object *st22p_obj, st_json_st22p_session_t *st22p) { + int width = json_object_get_int(st_json_object_object_get(st22p_obj, "width")); if (width <= 0) { err("%s, invalid width %d\n", __func__, width); return -ST_JSON_NOT_VALID; @@ -1294,10 +1229,8 @@ static int parse_st22p_width(json_object *st22p_obj, return ST_JSON_SUCCESS; } -static int parse_st22p_height(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { - int height = - json_object_get_int(st_json_object_object_get(st22p_obj, "height")); +static int parse_st22p_height(json_object *st22p_obj, st_json_st22p_session_t *st22p) { + int height = json_object_get_int(st_json_object_object_get(st22p_obj, "height")); if (height <= 0) { err("%s, invalid height %d\n", __func__, height); return -ST_JSON_NOT_VALID; @@ -1306,10 +1239,8 @@ static int parse_st22p_height(json_object *st22p_obj, return ST_JSON_SUCCESS; } -static int parse_st22p_fps(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { - const char *fps = - json_object_get_string(st_json_object_object_get(st22p_obj, "fps")); +static int parse_st22p_fps(json_object *st22p_obj, st_json_st22p_session_t *st22p) { + const char *fps = json_object_get_string(st_json_object_object_get(st22p_obj, "fps")); REQUIRED_ITEM(fps); if (strcmp(fps, "p59") == 0) { st22p->info.fps = ST_FPS_P59_94; @@ -1340,17 +1271,14 @@ static int parse_st22p_fps(json_object *st22p_obj, return ST_JSON_SUCCESS; } -static int parse_st22p_interlace(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { +static int parse_st22p_interlace(json_object *st22p_obj, st_json_st22p_session_t *st22p) { json_object *obj = st_json_object_object_get(st22p_obj, "interlaced"); - if (!obj) - return ST_JSON_SUCCESS; + if (!obj) return ST_JSON_SUCCESS; st22p->info.interlaced = json_object_get_boolean(obj); return ST_JSON_SUCCESS; } -static int parse_st22p_pack_type(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { +static int parse_st22p_pack_type(json_object *st22p_obj, st_json_st22p_session_t *st22p) { const char *pack_type = json_object_get_string(st_json_object_object_get(st22p_obj, "pack_type")); REQUIRED_ITEM(pack_type); @@ -1365,8 +1293,7 @@ static int parse_st22p_pack_type(json_object *st22p_obj, return ST_JSON_SUCCESS; } -static int parse_st22p_codec(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { +static int parse_st22p_codec(json_object *st22p_obj, st_json_st22p_session_t *st22p) { const char *codec = json_object_get_string(st_json_object_object_get(st22p_obj, "codec")); REQUIRED_ITEM(codec); @@ -1387,8 +1314,7 @@ static int parse_st22p_codec(json_object *st22p_obj, return ST_JSON_SUCCESS; } -static int parse_st22p_device(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { +static int parse_st22p_device(json_object *st22p_obj, st_json_st22p_session_t *st22p) { const char *device = json_object_get_string(st_json_object_object_get(st22p_obj, "device")); REQUIRED_ITEM(device); @@ -1407,8 +1333,7 @@ static int parse_st22p_device(json_object *st22p_obj, return ST_JSON_SUCCESS; } -static int parse_st22p_quality(json_object *st22p_obj, - st_json_st22p_session_t *st22p) { +static int parse_st22p_quality(json_object *st22p_obj, st_json_st22p_session_t *st22p) { const char *quality = json_object_get_string(st_json_object_object_get(st22p_obj, "quality")); if (quality) { @@ -1426,8 +1351,7 @@ static int parse_st22p_quality(json_object *st22p_obj, return ST_JSON_SUCCESS; } -static int parse_st22p_format(json_object *st22p_obj, - st_json_st22p_session_t *st22p, +static int parse_st22p_format(json_object *st22p_obj, st_json_st22p_session_t *st22p, const char *format_name) { const char *format = json_object_get_string(st_json_object_object_get(st22p_obj, format_name)); @@ -1503,8 +1427,7 @@ static int st_json_parse_tx_st22p(int idx, json_object *st22p_obj, /* parse udp port */ ret = parse_base_udp_port(st22p_obj, &st22p->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(st22p_obj, &st22p->base); @@ -1515,65 +1438,55 @@ static int st_json_parse_tx_st22p(int idx, json_object *st22p_obj, /* parse width */ ret = parse_st22p_width(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse height */ ret = parse_st22p_height(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse fps */ ret = parse_st22p_fps(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse interlace */ ret = parse_st22p_interlace(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse pack_type */ ret = parse_st22p_pack_type(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse codec */ ret = parse_st22p_codec(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse device */ ret = parse_st22p_device(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse quality */ ret = parse_st22p_quality(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse input format */ ret = parse_st22p_format(st22p_obj, st22p, "input_format"); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse st22p url */ ret = parse_url(st22p_obj, "st22p_url", st22p->info.st22p_url); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse codec_thread_count option */ - st22p->info.codec_thread_count = json_object_get_int( - st_json_object_object_get(st22p_obj, "codec_thread_count")); + st22p->info.codec_thread_count = + json_object_get_int(st_json_object_object_get(st22p_obj, "codec_thread_count")); /* parse display option */ st22p->display = json_object_get_boolean(st_json_object_object_get(st22p_obj, "display")); /* parse enable rtcp */ - st22p->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(st22p_obj, "enable_rtcp")); + st22p->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(st22p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -1588,8 +1501,7 @@ static int st_json_parse_rx_st22p(int idx, json_object *st22p_obj, /* parse udp port */ ret = parse_base_udp_port(st22p_obj, &st22p->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(st22p_obj, &st22p->base); @@ -1600,72 +1512,61 @@ static int st_json_parse_rx_st22p(int idx, json_object *st22p_obj, /* parse width */ ret = parse_st22p_width(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse height */ ret = parse_st22p_height(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse fps */ ret = parse_st22p_fps(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse interlace */ ret = parse_st22p_interlace(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse pack_type */ ret = parse_st22p_pack_type(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse codec */ ret = parse_st22p_codec(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse device */ ret = parse_st22p_device(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse quality */ ret = parse_st22p_quality(st22p_obj, st22p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse output format */ ret = parse_st22p_format(st22p_obj, st22p, "output_format"); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse display option */ st22p->display = json_object_get_boolean(st_json_object_object_get(st22p_obj, "display")); /* parse measure_latency option */ - st22p->measure_latency = json_object_get_boolean( - st_json_object_object_get(st22p_obj, "measure_latency")); + st22p->measure_latency = + json_object_get_boolean(st_json_object_object_get(st22p_obj, "measure_latency")); /* parse codec_thread_count option */ - st22p->info.codec_thread_count = json_object_get_int( - st_json_object_object_get(st22p_obj, "codec_thread_count")); + st22p->info.codec_thread_count = + json_object_get_int(st_json_object_object_get(st22p_obj, "codec_thread_count")); /* parse enable rtcp */ - st22p->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(st22p_obj, "enable_rtcp")); + st22p->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(st22p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } -static int parse_st20p_width(json_object *st20p_obj, - st_json_st20p_session_t *st20p) { - int width = - json_object_get_int(st_json_object_object_get(st20p_obj, "width")); +static int parse_st20p_width(json_object *st20p_obj, st_json_st20p_session_t *st20p) { + int width = json_object_get_int(st_json_object_object_get(st20p_obj, "width")); if (width <= 0) { err("%s, invalid width %d\n", __func__, width); return -ST_JSON_NOT_VALID; @@ -1674,10 +1575,8 @@ static int parse_st20p_width(json_object *st20p_obj, return ST_JSON_SUCCESS; } -static int parse_st20p_height(json_object *st20p_obj, - st_json_st20p_session_t *st20p) { - int height = - json_object_get_int(st_json_object_object_get(st20p_obj, "height")); +static int parse_st20p_height(json_object *st20p_obj, st_json_st20p_session_t *st20p) { + int height = json_object_get_int(st_json_object_object_get(st20p_obj, "height")); if (height <= 0) { err("%s, invalid height %d\n", __func__, height); return -ST_JSON_NOT_VALID; @@ -1686,10 +1585,8 @@ static int parse_st20p_height(json_object *st20p_obj, return ST_JSON_SUCCESS; } -static int parse_st20p_fps(json_object *st20p_obj, - st_json_st20p_session_t *st20p) { - const char *fps = - json_object_get_string(st_json_object_object_get(st20p_obj, "fps")); +static int parse_st20p_fps(json_object *st20p_obj, st_json_st20p_session_t *st20p) { + const char *fps = json_object_get_string(st_json_object_object_get(st20p_obj, "fps")); REQUIRED_ITEM(fps); if (strcmp(fps, "p59") == 0) { st20p->info.fps = ST_FPS_P59_94; @@ -1720,17 +1617,14 @@ static int parse_st20p_fps(json_object *st20p_obj, return ST_JSON_SUCCESS; } -static int parse_st20p_interlace(json_object *st20p_obj, - st_json_st20p_session_t *st20p) { +static int parse_st20p_interlace(json_object *st20p_obj, st_json_st20p_session_t *st20p) { json_object *obj = st_json_object_object_get(st20p_obj, "interlaced"); - if (!obj) - return ST_JSON_SUCCESS; + if (!obj) return ST_JSON_SUCCESS; st20p->info.interlaced = json_object_get_boolean(obj); return ST_JSON_SUCCESS; } -static int parse_st20p_device(json_object *st20p_obj, - st_json_st20p_session_t *st20p) { +static int parse_st20p_device(json_object *st20p_obj, st_json_st20p_session_t *st20p) { const char *device = json_object_get_string(st_json_object_object_get(st20p_obj, "device")); REQUIRED_ITEM(device); @@ -1749,8 +1643,7 @@ static int parse_st20p_device(json_object *st20p_obj, return ST_JSON_SUCCESS; } -static int parse_st20p_pacing(json_object *st20p_obj, - st_json_st20p_session_t *st20p) { +static int parse_st20p_pacing(json_object *st20p_obj, st_json_st20p_session_t *st20p) { const char *pacing = json_object_get_string(st_json_object_object_get(st20p_obj, "pacing")); if (!pacing) { @@ -1772,8 +1665,7 @@ static int parse_st20p_pacing(json_object *st20p_obj, return ST_JSON_SUCCESS; } -static int parse_st20p_packing(json_object *st20p_obj, - st_json_st20p_session_t *st20p) { +static int parse_st20p_packing(json_object *st20p_obj, st_json_st20p_session_t *st20p) { const char *packing = json_object_get_string(st_json_object_object_get(st20p_obj, "packing")); if (packing) { @@ -1793,8 +1685,7 @@ static int parse_st20p_packing(json_object *st20p_obj, return ST_JSON_SUCCESS; } -static int parse_st20p_format(json_object *st20p_obj, - st_json_st20p_session_t *st20p, +static int parse_st20p_format(json_object *st20p_obj, st_json_st20p_session_t *st20p, const char *format_name) { const char *format = json_object_get_string(st_json_object_object_get(st20p_obj, format_name)); @@ -1852,8 +1743,8 @@ static int parse_st20p_format(json_object *st20p_obj, static int parse_st20p_transport_format(json_object *st20p_obj, st_json_st20p_session_t *st20p) { - const char *t_format = json_object_get_string( - st_json_object_object_get(st20p_obj, "transport_format")); + const char *t_format = + json_object_get_string(st_json_object_object_get(st20p_obj, "transport_format")); REQUIRED_ITEM(t_format); if (strcmp(t_format, "YUV_422_10bit") == 0) { st20p->info.transport_format = ST20_FMT_YUV_422_10BIT; @@ -1908,8 +1799,7 @@ static int st_json_parse_tx_st20p(int idx, json_object *st20p_obj, /* parse udp port */ ret = parse_base_udp_port(st20p_obj, &st20p->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(st20p_obj, &st20p->base); @@ -1920,61 +1810,51 @@ static int st_json_parse_tx_st20p(int idx, json_object *st20p_obj, /* parse width */ ret = parse_st20p_width(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse height */ ret = parse_st20p_height(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse fps */ ret = parse_st20p_fps(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse interlace */ ret = parse_st20p_interlace(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse device */ ret = parse_st20p_device(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse input format */ ret = parse_st20p_format(st20p_obj, st20p, "input_format"); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse transport pacing */ ret = parse_st20p_pacing(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse transport packing */ ret = parse_st20p_packing(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse transport format */ ret = parse_st20p_transport_format(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse st20p url */ ret = parse_url(st20p_obj, "st20p_url", st20p->info.st20p_url); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse display option */ st20p->display = json_object_get_boolean(st_json_object_object_get(st20p_obj, "display")); /* parse enable rtcp */ - st20p->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(st20p_obj, "enable_rtcp")); + st20p->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(st20p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -1989,8 +1869,7 @@ static int st_json_parse_rx_st20p(int idx, json_object *st20p_obj, /* parse udp port */ ret = parse_base_udp_port(st20p_obj, &st20p->base, idx); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse payload type */ ret = parse_base_payload_type(st20p_obj, &st20p->base); @@ -2001,60 +1880,51 @@ static int st_json_parse_rx_st20p(int idx, json_object *st20p_obj, /* parse width */ ret = parse_st20p_width(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse height */ ret = parse_st20p_height(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse fps */ ret = parse_st20p_fps(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse interlace */ ret = parse_st20p_interlace(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse device */ ret = parse_st20p_device(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse transport pacing */ ret = parse_st20p_pacing(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse transport packing */ ret = parse_st20p_packing(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse output format */ ret = parse_st20p_format(st20p_obj, st20p, "output_format"); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse transport format */ ret = parse_st20p_transport_format(st20p_obj, st20p); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* parse display option */ st20p->display = json_object_get_boolean(st_json_object_object_get(st20p_obj, "display")); /* parse measure_latency option */ - st20p->measure_latency = json_object_get_boolean( - st_json_object_object_get(st20p_obj, "measure_latency")); + st20p->measure_latency = + json_object_get_boolean(st_json_object_object_get(st20p_obj, "measure_latency")); /* parse enable rtcp */ - st20p->enable_rtcp = json_object_get_boolean( - st_json_object_object_get(st20p_obj, "enable_rtcp")); + st20p->enable_rtcp = + json_object_get_boolean(st_json_object_object_get(st20p_obj, "enable_rtcp")); return ST_JSON_SUCCESS; } @@ -2062,12 +1932,10 @@ static int st_json_parse_rx_st20p(int idx, json_object *st20p_obj, static int parse_session_num(json_object *group, const char *name) { int num = 0; json_object *session_array = st_json_object_object_get(group, name); - if (session_array != NULL && - json_object_get_type(session_array) == json_type_array) { + if (session_array != NULL && json_object_get_type(session_array) == json_type_array) { for (int j = 0; j < json_object_array_length(session_array); ++j) { json_object *session = json_object_array_get_idx(session_array, j); - int replicas = - json_object_get_int(st_json_object_object_get(session, "replicas")); + int replicas = json_object_get_int(st_json_object_object_get(session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); return -ST_JSON_NOT_VALID; @@ -2080,8 +1948,7 @@ static int parse_session_num(json_object *group, const char *name) { static const char *local_ip_prefix = "local:"; -static int parse_session_ip(const char *str_ip, - struct st_json_session_base *base, +static int parse_session_ip(const char *str_ip, struct st_json_session_base *base, enum mtl_session_port port) { int ret; @@ -2104,8 +1971,7 @@ static int parse_session_ip(const char *str_ip, return 0; } -static int parse_mcast_src_ip(const char *str_ip, - struct st_json_session_base *base, +static int parse_mcast_src_ip(const char *str_ip, struct st_json_session_base *base, enum mtl_session_port port) { int ret; @@ -2189,8 +2055,7 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { json_object *root_object = json_object_from_file(filename); if (root_object == NULL) { - err("%s, can not parse json file %s, please check the format\n", __func__, - filename); + err("%s, can not parse json file %s, please check the format\n", __func__, filename); return -ST_JSON_PARSE_FAIL; } @@ -2230,15 +2095,12 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse shared queues */ obj = st_json_object_object_get(root_object, "shared_tx_queues"); - if (obj != NULL) - ctx->shared_tx_queues = json_object_get_boolean(obj); + if (obj != NULL) ctx->shared_tx_queues = json_object_get_boolean(obj); obj = st_json_object_object_get(root_object, "shared_rx_queues"); - if (obj != NULL) - ctx->shared_rx_queues = json_object_get_boolean(obj); + if (obj != NULL) ctx->shared_rx_queues = json_object_get_boolean(obj); /* if disable the chain for tx */ obj = st_json_object_object_get(root_object, "tx_no_chain"); - if (obj != NULL) - ctx->tx_no_chain = json_object_get_boolean(obj); + if (obj != NULL) ctx->tx_no_chain = json_object_get_boolean(obj); /* rss */ obj = st_json_object_object_get(root_object, "rss_mode"); if (obj != NULL) { @@ -2262,8 +2124,7 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } /* parse interfaces for system */ - json_object *interfaces_array = - st_json_object_object_get(root_object, "interfaces"); + json_object *interfaces_array = st_json_object_object_get(root_object, "interfaces"); if (interfaces_array == NULL || json_object_get_type(interfaces_array) != json_type_array) { err("%s, can not parse interfaces\n", __func__); @@ -2276,27 +2137,24 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { ret = -ST_JSON_NOT_VALID; goto error; } - ctx->interfaces = (st_json_interface_t *)st_app_zmalloc( - num_interfaces * sizeof(st_json_interface_t)); + ctx->interfaces = + (st_json_interface_t *)st_app_zmalloc(num_interfaces * sizeof(st_json_interface_t)); if (!ctx->interfaces) { err("%s, failed to allocate interfaces\n", __func__); ret = -ST_JSON_NULL; goto error; } for (int i = 0; i < num_interfaces; ++i) { - ret = st_json_parse_interfaces( - json_object_array_get_idx(interfaces_array, i), &ctx->interfaces[i]); - if (ret) - goto error; + ret = st_json_parse_interfaces(json_object_array_get_idx(interfaces_array, i), + &ctx->interfaces[i]); + if (ret) goto error; } ctx->num_interfaces = num_interfaces; ctx->has_display = false; /* parse tx sessions */ - json_object *tx_group_array = - st_json_object_object_get(root_object, "tx_sessions"); - if (tx_group_array != NULL && - json_object_get_type(tx_group_array) == json_type_array) { + json_object *tx_group_array = st_json_object_object_get(root_object, "tx_sessions"); + if (tx_group_array != NULL && json_object_get_type(tx_group_array) == json_type_array) { /* parse session numbers for array allocation */ for (int i = 0; i < json_object_array_length(tx_group_array); ++i) { json_object *tx_group = json_object_array_get_idx(tx_group_array, i); @@ -2308,33 +2166,27 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { int num = 0; /* parse tx video sessions */ num = parse_session_num(tx_group, "video"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->tx_video_session_cnt += num; /* parse tx audio sessions */ num = parse_session_num(tx_group, "audio"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->tx_audio_session_cnt += num; /* parse tx ancillary sessions */ num = parse_session_num(tx_group, "ancillary"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->tx_anc_session_cnt += num; /* parse tx st22p sessions */ num = parse_session_num(tx_group, "st22p"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->tx_st22p_session_cnt += num; /* parse tx st20p sessions */ num = parse_session_num(tx_group, "st20p"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->tx_st20p_session_cnt += num; /* parse tx st30p sessions */ num = parse_session_num(tx_group, "st30p"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->tx_st30p_session_cnt += num; } @@ -2402,8 +2254,7 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { json_object *dip_p = NULL; json_object *dip_r = NULL; json_object *dip_array = st_json_object_object_get(tx_group, "dip"); - if (dip_array != NULL && - json_object_get_type(dip_array) == json_type_array) { + if (dip_array != NULL && json_object_get_type(dip_array) == json_type_array) { int len = json_object_array_length(dip_array); if (len < 1 || len > MTL_PORT_MAX) { err("%s, wrong dip number\n", __func__); @@ -2423,27 +2274,23 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse interface */ int inf_p, inf_r = 0; - json_object *interface_array = - st_json_object_object_get(tx_group, "interface"); + json_object *interface_array = st_json_object_object_get(tx_group, "interface"); if (interface_array != NULL && json_object_get_type(interface_array) == json_type_array) { int len = json_object_array_length(interface_array); if (len != num_inf) { - err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, - len); + err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, len); ret = -ST_JSON_NOT_VALID; goto error; } - inf_p = - json_object_get_int(json_object_array_get_idx(interface_array, 0)); + inf_p = json_object_get_int(json_object_array_get_idx(interface_array, 0)); if (inf_p < 0 || inf_p > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; goto error; } if (len == 2) { - inf_r = json_object_get_int( - json_object_array_get_idx(interface_array, 1)); + inf_r = json_object_get_int(json_object_array_get_idx(interface_array, 1)); if (inf_r < 0 || inf_r > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; @@ -2458,13 +2305,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse tx video sessions */ json_object *video_array = st_json_object_object_get(tx_group, "video"); - if (video_array != NULL && - json_object_get_type(video_array) == json_type_array) { + if (video_array != NULL && json_object_get_type(video_array) == json_type_array) { for (int j = 0; j < json_object_array_length(video_array); ++j) { - json_object *video_session = - json_object_array_get_idx(video_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(video_session, "replicas")); + json_object *video_session = json_object_array_get_idx(video_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(video_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2472,26 +2317,21 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_video_sessions[num_video].base, - MTL_SESSION_PORT_P); - ctx->tx_video_sessions[num_video].base.inf[0] = - &ctx->interfaces[inf_p]; + &ctx->tx_video_sessions[num_video].base, MTL_SESSION_PORT_P); + ctx->tx_video_sessions[num_video].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_video_sessions[num_video].base, MTL_SESSION_PORT_R); - ctx->tx_video_sessions[num_video].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->tx_video_sessions[num_video].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_video_sessions[num_video].base.num_inf = num_inf; ret = st_json_parse_tx_video(k, video_session, &ctx->tx_video_sessions[num_video]); - if (ret) - goto error; - if (ctx->tx_video_sessions[num_video].display) - ctx->has_display = true; + if (ret) goto error; + if (ctx->tx_video_sessions[num_video].display) ctx->has_display = true; num_video++; } } @@ -2499,13 +2339,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse tx audio sessions */ json_object *audio_array = st_json_object_object_get(tx_group, "audio"); - if (audio_array != NULL && - json_object_get_type(audio_array) == json_type_array) { + if (audio_array != NULL && json_object_get_type(audio_array) == json_type_array) { for (int j = 0; j < json_object_array_length(audio_array); ++j) { - json_object *audio_session = - json_object_array_get_idx(audio_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(audio_session, "replicas")); + json_object *audio_session = json_object_array_get_idx(audio_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(audio_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2513,24 +2351,20 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_audio_sessions[num_audio].base, - MTL_SESSION_PORT_P); - ctx->tx_audio_sessions[num_audio].base.inf[0] = - &ctx->interfaces[inf_p]; + &ctx->tx_audio_sessions[num_audio].base, MTL_SESSION_PORT_P); + ctx->tx_audio_sessions[num_audio].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_audio_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_audio_sessions[num_audio].base, MTL_SESSION_PORT_R); - ctx->tx_audio_sessions[num_audio].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->tx_audio_sessions[num_audio].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_audio_sessions_cnt++; } ctx->tx_audio_sessions[num_audio].base.num_inf = num_inf; ret = st_json_parse_tx_audio(k, audio_session, &ctx->tx_audio_sessions[num_audio]); - if (ret) - goto error; + if (ret) goto error; num_audio++; } } @@ -2538,12 +2372,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse tx ancillary sessions */ json_object *anc_array = st_json_object_object_get(tx_group, "ancillary"); - if (anc_array != NULL && - json_object_get_type(anc_array) == json_type_array) { + if (anc_array != NULL && json_object_get_type(anc_array) == json_type_array) { for (int j = 0; j < json_object_array_length(anc_array); ++j) { json_object *anc_session = json_object_array_get_idx(anc_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(anc_session, "replicas")); + int replicas = + json_object_get_int(st_json_object_object_get(anc_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2551,23 +2384,18 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_anc_sessions[num_anc].base, - MTL_SESSION_PORT_P); + &ctx->tx_anc_sessions[num_anc].base, MTL_SESSION_PORT_P); ctx->tx_anc_sessions[num_anc].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_anc_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), - &ctx->tx_anc_sessions[num_anc].base, - MTL_SESSION_PORT_R); - ctx->tx_anc_sessions[num_anc].base.inf[1] = - &ctx->interfaces[inf_r]; + &ctx->tx_anc_sessions[num_anc].base, MTL_SESSION_PORT_R); + ctx->tx_anc_sessions[num_anc].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_anc_sessions_cnt++; } ctx->tx_anc_sessions[num_anc].base.num_inf = num_inf; - ret = st_json_parse_tx_anc(k, anc_session, - &ctx->tx_anc_sessions[num_anc]); - if (ret) - goto error; + ret = st_json_parse_tx_anc(k, anc_session, &ctx->tx_anc_sessions[num_anc]); + if (ret) goto error; num_anc++; } } @@ -2575,13 +2403,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse tx st22p sessions */ json_object *st22p_array = st_json_object_object_get(tx_group, "st22p"); - if (st22p_array != NULL && - json_object_get_type(st22p_array) == json_type_array) { + if (st22p_array != NULL && json_object_get_type(st22p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st22p_array); ++j) { - json_object *st22p_session = - json_object_array_get_idx(st22p_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(st22p_session, "replicas")); + json_object *st22p_session = json_object_array_get_idx(st22p_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(st22p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2589,26 +2415,21 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_st22p_sessions[num_st22p].base, - MTL_SESSION_PORT_P); - ctx->tx_st22p_sessions[num_st22p].base.inf[0] = - &ctx->interfaces[inf_p]; + &ctx->tx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_P); + ctx->tx_st22p_sessions[num_st22p].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_R); - ctx->tx_st22p_sessions[num_st22p].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->tx_st22p_sessions[num_st22p].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_st22p_sessions[num_st22p].base.num_inf = num_inf; ret = st_json_parse_tx_st22p(k, st22p_session, &ctx->tx_st22p_sessions[num_st22p]); - if (ret) - goto error; - if (ctx->tx_st22p_sessions[num_st22p].display) - ctx->has_display = true; + if (ret) goto error; + if (ctx->tx_st22p_sessions[num_st22p].display) ctx->has_display = true; num_st22p++; } } @@ -2616,13 +2437,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse tx st20p sessions */ json_object *st20p_array = st_json_object_object_get(tx_group, "st20p"); - if (st20p_array != NULL && - json_object_get_type(st20p_array) == json_type_array) { + if (st20p_array != NULL && json_object_get_type(st20p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st20p_array); ++j) { - json_object *st20p_session = - json_object_array_get_idx(st20p_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(st20p_session, "replicas")); + json_object *st20p_session = json_object_array_get_idx(st20p_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(st20p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2630,26 +2449,21 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_st20p_sessions[num_st20p].base, - MTL_SESSION_PORT_P); - ctx->tx_st20p_sessions[num_st20p].base.inf[0] = - &ctx->interfaces[inf_p]; + &ctx->tx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_P); + ctx->tx_st20p_sessions[num_st20p].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_R); - ctx->tx_st20p_sessions[num_st20p].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->tx_st20p_sessions[num_st20p].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_st20p_sessions[num_st20p].base.num_inf = num_inf; ret = st_json_parse_tx_st20p(k, st20p_session, &ctx->tx_st20p_sessions[num_st20p]); - if (ret) - goto error; - if (ctx->tx_st20p_sessions[num_st20p].display) - ctx->has_display = true; + if (ret) goto error; + if (ctx->tx_st20p_sessions[num_st20p].display) ctx->has_display = true; num_st20p++; } } @@ -2657,39 +2471,32 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse tx st30p sessions */ json_object *st30p_array = st_json_object_object_get(tx_group, "st30p"); - if (st30p_array != NULL && - json_object_get_type(st30p_array) == json_type_array) { + if (st30p_array != NULL && json_object_get_type(st30p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st30p_array); ++j) { - json_object *st30p_session = - json_object_array_get_idx(st30p_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(st30p_session, "replicas")); + json_object *st30p_session = json_object_array_get_idx(st30p_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(st30p_session, "replicas")); if (replicas < 0) { - err("%s, invalid replicas number: %d for st30p\n", __func__, - replicas); + err("%s, invalid replicas number: %d for st30p\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; goto error; } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(dip_p), - &ctx->tx_st30p_sessions[num_st30p].base, - MTL_SESSION_PORT_P); - ctx->tx_st30p_sessions[num_st30p].base.inf[0] = - &ctx->interfaces[inf_p]; + &ctx->tx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_P); + ctx->tx_st30p_sessions[num_st30p].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].tx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(dip_r), &ctx->tx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_R); - ctx->tx_st30p_sessions[num_st30p].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->tx_st30p_sessions[num_st30p].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].tx_video_sessions_cnt++; } ctx->tx_st30p_sessions[num_st30p].base.num_inf = num_inf; - ret = st_json_parse_st30p( - k, st30p_session, &ctx->tx_st30p_sessions[num_st30p], false); - if (ret) - goto error; + ret = st_json_parse_st30p(k, st30p_session, + &ctx->tx_st30p_sessions[num_st30p], false); + if (ret) goto error; num_st30p++; } } @@ -2698,10 +2505,8 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } /* parse rx sessions */ - json_object *rx_group_array = - st_json_object_object_get(root_object, "rx_sessions"); - if (rx_group_array != NULL && - json_object_get_type(rx_group_array) == json_type_array) { + json_object *rx_group_array = st_json_object_object_get(root_object, "rx_sessions"); + if (rx_group_array != NULL && json_object_get_type(rx_group_array) == json_type_array) { /* parse session numbers for array allocation */ for (int i = 0; i < json_object_array_length(rx_group_array); ++i) { json_object *rx_group = json_object_array_get_idx(rx_group_array, i); @@ -2713,38 +2518,31 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { int num = 0; /* parse rx video sessions */ num = parse_session_num(rx_group, "video"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->rx_video_session_cnt += num; /* parse rx audio sessions */ num = parse_session_num(rx_group, "audio"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->rx_audio_session_cnt += num; /* parse rx ancillary sessions */ num = parse_session_num(rx_group, "ancillary"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->rx_anc_session_cnt += num; /* parse rx st22p sessions */ num = parse_session_num(rx_group, "st22p"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->rx_st22p_session_cnt += num; /* parse rx st20p sessions */ num = parse_session_num(rx_group, "st20p"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->rx_st20p_session_cnt += num; /* parse rx st20r sessions */ num = parse_session_num(rx_group, "st20r"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->rx_st20r_session_cnt += num; /* parse rx st30p sessions */ num = parse_session_num(rx_group, "st30p"); - if (num < 0) - goto error; + if (num < 0) goto error; ctx->rx_st30p_session_cnt += num; } @@ -2824,8 +2622,7 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { json_object *mcast_src_ip_r = NULL; json_object *mcast_src_ip_array = /* mcast_src_ip field is optional */ st_json_object_object_get(rx_group, "mcast_src_ip"); - if (ip_array != NULL && - json_object_get_type(ip_array) == json_type_array) { + if (ip_array != NULL && json_object_get_type(ip_array) == json_type_array) { int len = json_object_array_length(ip_array); if (len < 1 || len > MTL_SESSION_PORT_MAX) { err("%s, wrong dip number\n", __func__); @@ -2858,27 +2655,23 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse interface */ int inf_p, inf_r = 0; - json_object *interface_array = - st_json_object_object_get(rx_group, "interface"); + json_object *interface_array = st_json_object_object_get(rx_group, "interface"); if (interface_array != NULL && json_object_get_type(interface_array) == json_type_array) { int len = json_object_array_length(interface_array); if (len != num_inf) { - err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, - len); + err("%s, %d dip arrays but %d interface arrays\n", __func__, num_inf, len); ret = -ST_JSON_NOT_VALID; goto error; } - inf_p = - json_object_get_int(json_object_array_get_idx(interface_array, 0)); + inf_p = json_object_get_int(json_object_array_get_idx(interface_array, 0)); if (inf_p < 0 || inf_p > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; goto error; } if (len == 2) { - inf_r = json_object_get_int( - json_object_array_get_idx(interface_array, 1)); + inf_r = json_object_get_int(json_object_array_get_idx(interface_array, 1)); if (inf_r < 0 || inf_r > num_interfaces) { err("%s, wrong interface index\n", __func__); ret = -ST_JSON_NOT_VALID; @@ -2893,13 +2686,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse rx video sessions */ json_object *video_array = st_json_object_object_get(rx_group, "video"); - if (video_array != NULL && - json_object_get_type(video_array) == json_type_array) { + if (video_array != NULL && json_object_get_type(video_array) == json_type_array) { for (int j = 0; j < json_object_array_length(video_array); ++j) { - json_object *video_session = - json_object_array_get_idx(video_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(video_session, "replicas")); + json_object *video_session = json_object_array_get_idx(video_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(video_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2907,14 +2698,12 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_video_sessions[num_video].base, - MTL_SESSION_PORT_P); + &ctx->rx_video_sessions[num_video].base, MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_video_sessions[num_video].base, MTL_SESSION_PORT_P); - ctx->rx_video_sessions[num_video].base.inf[0] = - &ctx->interfaces[inf_p]; + ctx->rx_video_sessions[num_video].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2924,17 +2713,14 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_video_sessions[num_video].base, MTL_SESSION_PORT_R); - ctx->rx_video_sessions[num_video].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->rx_video_sessions[num_video].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_video_sessions[num_video].base.num_inf = num_inf; ret = st_json_parse_rx_video(k, video_session, &ctx->rx_video_sessions[num_video]); - if (ret) - goto error; - if (ctx->rx_video_sessions[num_video].display) - ctx->has_display = true; + if (ret) goto error; + if (ctx->rx_video_sessions[num_video].display) ctx->has_display = true; num_video++; } } @@ -2942,13 +2728,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse rx audio sessions */ json_object *audio_array = st_json_object_object_get(rx_group, "audio"); - if (audio_array != NULL && - json_object_get_type(audio_array) == json_type_array) { + if (audio_array != NULL && json_object_get_type(audio_array) == json_type_array) { for (int j = 0; j < json_object_array_length(audio_array); ++j) { - json_object *audio_session = - json_object_array_get_idx(audio_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(audio_session, "replicas")); + json_object *audio_session = json_object_array_get_idx(audio_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(audio_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -2956,14 +2740,12 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_audio_sessions[num_audio].base, - MTL_SESSION_PORT_P); + &ctx->rx_audio_sessions[num_audio].base, MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_audio_sessions[num_audio].base, MTL_SESSION_PORT_P); - ctx->rx_audio_sessions[num_audio].base.inf[0] = - &ctx->interfaces[inf_p]; + ctx->rx_audio_sessions[num_audio].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_audio_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -2973,15 +2755,13 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_audio_sessions[num_audio].base, MTL_SESSION_PORT_R); - ctx->rx_audio_sessions[num_audio].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->rx_audio_sessions[num_audio].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_audio_sessions_cnt++; } ctx->rx_audio_sessions[num_audio].base.num_inf = num_inf; ret = st_json_parse_rx_audio(k, audio_session, &ctx->rx_audio_sessions[num_audio]); - if (ret) - goto error; + if (ret) goto error; num_audio++; } } @@ -2989,12 +2769,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse rx ancillary sessions */ json_object *anc_array = st_json_object_object_get(rx_group, "ancillary"); - if (anc_array != NULL && - json_object_get_type(anc_array) == json_type_array) { + if (anc_array != NULL && json_object_get_type(anc_array) == json_type_array) { for (int j = 0; j < json_object_array_length(anc_array); ++j) { json_object *anc_session = json_object_array_get_idx(anc_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(anc_session, "replicas")); + int replicas = + json_object_get_int(st_json_object_object_get(anc_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -3002,31 +2781,25 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_anc_sessions[num_anc].base, - MTL_SESSION_PORT_P); + &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), - &ctx->rx_anc_sessions[num_anc].base, - MTL_SESSION_PORT_P); + &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_P); ctx->rx_anc_sessions[num_anc].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_anc_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), - &ctx->rx_anc_sessions[num_anc].base, - MTL_SESSION_PORT_R); + &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_R); if (mcast_src_ip_r) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_anc_sessions[num_anc].base, MTL_SESSION_PORT_R); - ctx->rx_anc_sessions[num_anc].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->rx_anc_sessions[num_anc].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_anc_sessions_cnt++; } ctx->rx_anc_sessions[num_anc].base.num_inf = num_inf; - ret = st_json_parse_rx_anc(k, anc_session, - &ctx->rx_anc_sessions[num_anc]); - if (ret) - goto error; + ret = st_json_parse_rx_anc(k, anc_session, &ctx->rx_anc_sessions[num_anc]); + if (ret) goto error; num_anc++; } } @@ -3034,13 +2807,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse rx st22p sessions */ json_object *st22p_array = st_json_object_object_get(rx_group, "st22p"); - if (st22p_array != NULL && - json_object_get_type(st22p_array) == json_type_array) { + if (st22p_array != NULL && json_object_get_type(st22p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st22p_array); ++j) { - json_object *st22p_session = - json_object_array_get_idx(st22p_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(st22p_session, "replicas")); + json_object *st22p_session = json_object_array_get_idx(st22p_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(st22p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -3048,14 +2819,12 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st22p_sessions[num_st22p].base, - MTL_SESSION_PORT_P); + &ctx->rx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_P); - ctx->rx_st22p_sessions[num_st22p].base.inf[0] = - &ctx->interfaces[inf_p]; + ctx->rx_st22p_sessions[num_st22p].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -3065,17 +2834,14 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st22p_sessions[num_st22p].base, MTL_SESSION_PORT_R); - ctx->rx_st22p_sessions[num_st22p].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->rx_st22p_sessions[num_st22p].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st22p_sessions[num_st22p].base.num_inf = num_inf; ret = st_json_parse_rx_st22p(k, st22p_session, &ctx->rx_st22p_sessions[num_st22p]); - if (ret) - goto error; - if (ctx->rx_st22p_sessions[num_st22p].display) - ctx->has_display = true; + if (ret) goto error; + if (ctx->rx_st22p_sessions[num_st22p].display) ctx->has_display = true; num_st22p++; } } @@ -3083,13 +2849,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse rx st20p sessions */ json_object *st20p_array = st_json_object_object_get(rx_group, "st20p"); - if (st20p_array != NULL && - json_object_get_type(st20p_array) == json_type_array) { + if (st20p_array != NULL && json_object_get_type(st20p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st20p_array); ++j) { - json_object *st20p_session = - json_object_array_get_idx(st20p_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(st20p_session, "replicas")); + json_object *st20p_session = json_object_array_get_idx(st20p_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(st20p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -3097,14 +2861,12 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st20p_sessions[num_st20p].base, - MTL_SESSION_PORT_P); + &ctx->rx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_P); - ctx->rx_st20p_sessions[num_st20p].base.inf[0] = - &ctx->interfaces[inf_p]; + ctx->rx_st20p_sessions[num_st20p].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -3114,17 +2876,14 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st20p_sessions[num_st20p].base, MTL_SESSION_PORT_R); - ctx->rx_st20p_sessions[num_st20p].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->rx_st20p_sessions[num_st20p].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st20p_sessions[num_st20p].base.num_inf = num_inf; ret = st_json_parse_rx_st20p(k, st20p_session, &ctx->rx_st20p_sessions[num_st20p]); - if (ret) - goto error; - if (ctx->rx_st20p_sessions[num_st20p].display) - ctx->has_display = true; + if (ret) goto error; + if (ctx->rx_st20p_sessions[num_st20p].display) ctx->has_display = true; num_st20p++; } } @@ -3132,13 +2891,11 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse rx st30p sessions */ json_object *st30p_array = st_json_object_object_get(rx_group, "st30p"); - if (st30p_array != NULL && - json_object_get_type(st30p_array) == json_type_array) { + if (st30p_array != NULL && json_object_get_type(st30p_array) == json_type_array) { for (int j = 0; j < json_object_array_length(st30p_array); ++j) { - json_object *st30p_session = - json_object_array_get_idx(st30p_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(st30p_session, "replicas")); + json_object *st30p_session = json_object_array_get_idx(st30p_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(st30p_session, "replicas")); if (replicas < 0) { err("%s, invalid replicas number: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; @@ -3146,14 +2903,12 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st30p_sessions[num_st30p].base, - MTL_SESSION_PORT_P); + &ctx->rx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_P); - ctx->rx_st30p_sessions[num_st30p].base.inf[0] = - &ctx->interfaces[inf_p]; + ctx->rx_st30p_sessions[num_st30p].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -3163,15 +2918,13 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st30p_sessions[num_st30p].base, MTL_SESSION_PORT_R); - ctx->rx_st30p_sessions[num_st30p].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->rx_st30p_sessions[num_st30p].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st30p_sessions[num_st30p].base.num_inf = num_inf; ret = st_json_parse_st30p(k, st30p_session, &ctx->rx_st30p_sessions[num_st30p], true); - if (ret) - goto error; + if (ret) goto error; num_st30p++; } } @@ -3179,34 +2932,29 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { /* parse rx st20r sessions */ json_object *st20r_array = st_json_object_object_get(rx_group, "st20r"); - if (st20r_array != NULL && - json_object_get_type(st20r_array) == json_type_array) { + if (st20r_array != NULL && json_object_get_type(st20r_array) == json_type_array) { if (num_inf != 2) { err("%s, invalid num_inf number for st20r: %d\n", __func__, num_inf); ret = -ST_JSON_NOT_VALID; goto error; } for (int j = 0; j < json_object_array_length(st20r_array); ++j) { - json_object *st20r_session = - json_object_array_get_idx(st20r_array, j); - int replicas = json_object_get_int( - st_json_object_object_get(st20r_session, "replicas")); + json_object *st20r_session = json_object_array_get_idx(st20r_array, j); + int replicas = + json_object_get_int(st_json_object_object_get(st20r_session, "replicas")); if (replicas < 0) { - err("%s, invalid replicas number for st20r: %d\n", __func__, - replicas); + err("%s, invalid replicas number for st20r: %d\n", __func__, replicas); ret = -ST_JSON_NOT_VALID; goto error; } for (int k = 0; k < replicas; ++k) { parse_session_ip(json_object_get_string(ip_p), - &ctx->rx_st20r_sessions[num_st20r].base, - MTL_SESSION_PORT_P); + &ctx->rx_st20r_sessions[num_st20r].base, MTL_SESSION_PORT_P); if (mcast_src_ip_p) parse_mcast_src_ip(json_object_get_string(mcast_src_ip_p), &ctx->rx_st20r_sessions[num_st20r].base, MTL_SESSION_PORT_P); - ctx->rx_st20r_sessions[num_st20r].base.inf[0] = - &ctx->interfaces[inf_p]; + ctx->rx_st20r_sessions[num_st20r].base.inf[0] = &ctx->interfaces[inf_p]; ctx->interfaces[inf_p].rx_video_sessions_cnt++; if (num_inf == 2) { parse_session_ip(json_object_get_string(ip_r), @@ -3216,17 +2964,14 @@ int st_app_parse_json(st_json_context_t *ctx, const char *filename) { parse_mcast_src_ip(json_object_get_string(mcast_src_ip_r), &ctx->rx_st20r_sessions[num_st20r].base, MTL_SESSION_PORT_R); - ctx->rx_st20r_sessions[num_st20r].base.inf[1] = - &ctx->interfaces[inf_r]; + ctx->rx_st20r_sessions[num_st20r].base.inf[1] = &ctx->interfaces[inf_r]; ctx->interfaces[inf_r].rx_video_sessions_cnt++; } ctx->rx_st20r_sessions[num_st20r].base.num_inf = num_inf; ret = st_json_parse_rx_video(k, st20r_session, &ctx->rx_st20r_sessions[num_st20r]); - if (ret) - goto error; - if (ctx->rx_st20r_sessions[num_st20r].display) - ctx->has_display = true; + if (ret) goto error; + if (ctx->rx_st20r_sessions[num_st20r].display) ctx->has_display = true; num_st20r++; } } @@ -3284,21 +3029,20 @@ uint32_t st_app_get_height(enum video_format fmt) { bool st_app_get_interlaced(enum video_format fmt) { switch (fmt) { - case VIDEO_FORMAT_480I_59FPS: - case VIDEO_FORMAT_576I_50FPS: - case VIDEO_FORMAT_1080I_59FPS: - case VIDEO_FORMAT_1080I_50FPS: - return true; - default: - return false; + case VIDEO_FORMAT_480I_59FPS: + case VIDEO_FORMAT_576I_50FPS: + case VIDEO_FORMAT_1080I_59FPS: + case VIDEO_FORMAT_1080I_50FPS: + return true; + default: + return false; } } uint8_t *st_json_ip(struct st_app_context *ctx, st_json_session_base_t *base, enum mtl_session_port port) { if (base->type[port] == ST_JSON_IP_LOCAL_IF) { - mtl_port_ip_info(ctx->st, base->local[port], base->local_ip[port], NULL, - NULL); + mtl_port_ip_info(ctx->st, base->local[port], base->local_ip[port], NULL, NULL); return base->local_ip[port]; } else { return base->ip[port]; diff --git a/app/src/player.c b/app/src/player.c index 82c470ec9..fe8052a67 100644 --- a/app/src/player.c +++ b/app/src/player.c @@ -62,9 +62,9 @@ static void destroy_display_context(struct st_display *d) { } static int create_display_context(struct st_display *d) { - d->window = SDL_CreateWindow( - d->name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, d->window_w, - d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + d->window = + SDL_CreateWindow(d->name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + d->window_w, d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (d->window == NULL) { err("%s, create window fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -78,8 +78,8 @@ static int create_display_context(struct st_display *d) { return -EIO; } - d->texture = SDL_CreateTexture( - d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, d->pixel_w, d->pixel_h); + d->texture = SDL_CreateTexture(d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, + d->pixel_w, d->pixel_h); if (d->texture == NULL) { err("%s, create texture fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -127,8 +127,7 @@ static void *display_thread_func(void *arg) { sprintf(text, "FPS:\t%.2f", d->fps); SDL_Color Red = {255, 0, 0}; SDL_Surface *surfaceMessage = TTF_RenderText_Solid(d->font, text, Red); - SDL_Texture *Message = - SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); + SDL_Texture *Message = SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); SDL_RenderCopy(d->renderer, Message, NULL, &d->msg_rect); SDL_FreeSurface(surfaceMessage); @@ -142,8 +141,7 @@ static void *display_thread_func(void *arg) { SDL_Event event; while (SDL_PollEvent(&event)) { dbg("%s, SDL event: %d\n", __func__, event.type); - if (event.type == SDL_QUIT) - d->display_thread_stop = true; + if (event.type == SDL_QUIT) d->display_thread_stop = true; } #endif } @@ -152,8 +150,7 @@ static void *display_thread_func(void *arg) { } int st_app_uinit_display(struct st_display *d) { - if (!d) - return 0; + if (!d) return 0; d->display_thread_stop = true; if (d->display_thread) { @@ -190,8 +187,7 @@ int st_app_init_display(struct st_display *d, char *name, int width, int height, int ret; MTL_MAY_UNUSED(font); - if (!d) - return -ENOMEM; + if (!d) return -ENOMEM; snprintf(d->name, 32, "%s", name); d->window_w = SCREEN_WIDTH; d->window_h = SCREEN_HEIGHT; @@ -232,7 +228,6 @@ int st_app_init_display(struct st_display *d, char *name, int width, int height, return ret; } - info("%s(%s), succ, pixel width: %d, height: %d\n", __func__, name, width, - height); + info("%s(%s), succ, pixel width: %d, height: %d\n", __func__, name, width, height); return 0; } diff --git a/app/src/player.h b/app/src/player.h index 5cba4f8a2..e816aa3a7 100644 --- a/app/src/player.h +++ b/app/src/player.h @@ -28,8 +28,8 @@ static inline int st_app_player_init(struct st_app_context *ctx) { warn("%s, not support as build without SDL2\n", __func__); return -ENOTSUP; } -static inline int st_app_init_display(struct st_display *d, char *name, - int width, int height, char *font) { +static inline int st_app_init_display(struct st_display *d, char *name, int width, + int height, char *font) { MTL_MAY_UNUSED(d); MTL_MAY_UNUSED(name); MTL_MAY_UNUSED(width); diff --git a/app/src/rx_ancillary_app.c b/app/src/rx_ancillary_app.c index ba2df9832..e2b0b9ee6 100644 --- a/app/src/rx_ancillary_app.c +++ b/app/src/rx_ancillary_app.c @@ -4,8 +4,7 @@ #include "rx_ancillary_app.h" -static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session *s, - void *usrptr) { +static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session *s, void *usrptr) { struct st40_rfc8331_rtp_hdr *hdr = (struct st40_rfc8331_rtp_hdr *)usrptr; struct st40_rfc8331_payload_hdr *payload_hdr = (struct st40_rfc8331_payload_hdr *)(&hdr[1]); @@ -14,10 +13,8 @@ static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session *s, dbg("%s(%d), anc_count %d\n", __func__, s->idx, anc_count); for (idx = 0; idx < anc_count; idx++) { - payload_hdr->swaped_first_hdr_chunk = - ntohl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = - ntohl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = ntohl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = ntohl(payload_hdr->swaped_second_hdr_chunk); if (!st40_check_parity_bits(payload_hdr->second_hdr_chunk.did) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.sdid) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.data_count)) { @@ -28,13 +25,10 @@ static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session *s, // verify checksum uint16_t checksum = 0; - checksum = - st40_get_udw(udw_size + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = - htonl(payload_hdr->swaped_second_hdr_chunk); + checksum = st40_get_udw(udw_size + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); if (checksum != - st40_calc_checksum(3 + udw_size, - (uint8_t *)&payload_hdr->second_hdr_chunk)) { + st40_calc_checksum(3 + udw_size, (uint8_t *)&payload_hdr->second_hdr_chunk)) { err("%s(%d), anc frame checksum error\n", __func__, s->idx); return; } @@ -43,23 +37,20 @@ static void app_rx_anc_handle_rtp(struct st_app_rx_anc_session *s, uint16_t data; for (int i = 0; i < udw_size; i++) { data = st40_get_udw(i + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); - if (!st40_check_parity_bits(data)) - err("anc udw checkParityBits error\n"); + if (!st40_check_parity_bits(data)) err("anc udw checkParityBits error\n"); dbg("%c", data & 0xff); } dbg("\n"); #endif - total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = - (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + - total_size; // Full size of one ANC - payload_hdr = (struct st40_rfc8331_payload_hdr *)((uint8_t *)payload_hdr + - payload_len); + total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = + sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC + payload_hdr = + (struct st40_rfc8331_payload_hdr *)((uint8_t *)payload_hdr + payload_len); } s->stat_frame_total_received++; @@ -116,8 +107,7 @@ static int app_rx_anc_uinit(struct st_app_rx_anc_session *s) { } if (s->handle) { ret = st40_rx_free(s->handle); - if (ret < 0) - err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } st_pthread_mutex_destroy(&s->st40_wake_mutex); @@ -126,8 +116,7 @@ static int app_rx_anc_uinit(struct st_app_rx_anc_session *s) { return 0; } -static int app_rx_anc_init(struct st_app_context *ctx, - st_json_ancillary_session_t *anc, +static int app_rx_anc_init(struct st_app_context *ctx, st_json_ancillary_session_t *anc, struct st_app_rx_anc_session *s) { int idx = s->idx, ret; struct st40_rx_ops ops; @@ -139,41 +128,33 @@ static int app_rx_anc_init(struct st_app_context *ctx, ops.name = name; ops.priv = s; ops.num_port = anc ? anc->base.num_inf : ctx->para.num_ports; - memcpy(ops.ip_addr[MTL_SESSION_PORT_P], - anc ? st_json_ip(ctx, &anc->base, MTL_SESSION_PORT_P) - : ctx->rx_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy( + ops.ip_addr[MTL_SESSION_PORT_P], + anc ? st_json_ip(ctx, &anc->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_P], - anc ? anc->base.mcast_src_ip[MTL_PORT_P] - : ctx->rx_mcast_sip_addr[MTL_PORT_P], + anc ? anc->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = - anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = anc ? anc->base.udp_port : (10200 + s->idx); if (ops.num_port > 1) { memcpy(ops.ip_addr[MTL_SESSION_PORT_R], anc ? st_json_ip(ctx, &anc->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); memcpy(ops.mcast_sip_addr[MTL_SESSION_PORT_R], - anc ? anc->base.mcast_src_ip[MTL_PORT_R] - : ctx->rx_mcast_sip_addr[MTL_PORT_R], + anc ? anc->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = - anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = anc ? anc->base.udp_port : (10200 + s->idx); } ops.rtp_ring_size = 1024; - ops.payload_type = - anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; + ops.payload_type = anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; ops.interlaced = anc ? anc->info.interlaced : false; ops.notify_rtp_ready = app_rx_anc_rtp_ready; - if (anc && anc->enable_rtcp) - ops.flags |= ST40_RX_FLAG_ENABLE_RTCP; + if (anc && anc->enable_rtcp) ops.flags |= ST40_RX_FLAG_ENABLE_RTCP; st_pthread_mutex_init(&s->st40_wake_mutex, NULL); st_pthread_cond_init(&s->st40_wake_cond, NULL); @@ -202,8 +183,7 @@ static bool app_rx_anc_fps_check(double framerate) { for (enum st_fps fps = 0; fps < ST_FPS_MAX; fps++) { expect = st_frame_rate(fps); - if (ST_APP_EXPECT_NEAR(framerate, expect, expect * 0.05)) - return true; + if (ST_APP_EXPECT_NEAR(framerate, expect, expect * 0.05)) return true; } return false; @@ -212,12 +192,10 @@ static bool app_rx_anc_fps_check(double framerate) { static int app_rx_anc_result(struct st_app_rx_anc_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) - return -EINVAL; + if (!s->stat_frame_total_received) return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, app_rx_anc_fps_check(framerate) ? "OK" : "FAILED", framerate, @@ -230,14 +208,13 @@ int st_app_rx_anc_sessions_init(struct st_app_context *ctx) { struct st_app_rx_anc_session *s; ctx->rx_anc_sessions = (struct st_app_rx_anc_session *)st_app_zmalloc( sizeof(struct st_app_rx_anc_session) * ctx->rx_anc_session_cnt); - if (!ctx->rx_anc_sessions) - return -ENOMEM; + if (!ctx->rx_anc_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_anc_session_cnt; i++) { s = &ctx->rx_anc_sessions[i]; s->idx = i; - ret = app_rx_anc_init( - ctx, ctx->json_ctx ? &ctx->json_ctx->rx_anc_sessions[i] : NULL, s); + ret = app_rx_anc_init(ctx, ctx->json_ctx ? &ctx->json_ctx->rx_anc_sessions[i] : NULL, + s); if (ret < 0) { err("%s(%d), app_rx_anc_session_init fail %d\n", __func__, i, ret); return ret; @@ -250,8 +227,7 @@ int st_app_rx_anc_sessions_init(struct st_app_context *ctx) { int st_app_rx_anc_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_rx_anc_session *s; - if (!ctx->rx_anc_sessions) - return 0; + if (!ctx->rx_anc_sessions) return 0; for (i = 0; i < ctx->rx_anc_session_cnt; i++) { s = &ctx->rx_anc_sessions[i]; app_rx_anc_uinit(s); @@ -263,8 +239,7 @@ int st_app_rx_anc_sessions_uinit(struct st_app_context *ctx) { int st_app_rx_anc_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_anc_session *s; - if (!ctx->rx_anc_sessions) - return 0; + if (!ctx->rx_anc_sessions) return 0; for (i = 0; i < ctx->rx_anc_session_cnt; i++) { s = &ctx->rx_anc_sessions[i]; diff --git a/app/src/rx_st20p_app.c b/app/src/rx_st20p_app.c index be3542c75..3a2f43ce3 100644 --- a/app/src/rx_st20p_app.c +++ b/app/src/rx_st20p_app.c @@ -14,18 +14,15 @@ static void app_rx_st20p_consume_frame(struct st_app_rx_st20p_session *s, frame->pkts_total, frame->pkts_recv[MTL_SESSION_PORT_P], frame->pkts_recv[MTL_SESSION_PORT_R]); if (frame->pkts_recv[MTL_SESSION_PORT_P] < (frame->pkts_total / 2)) - warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", - __func__, idx, frame->pkts_recv[MTL_SESSION_PORT_P], - frame->pkts_total); + warn("%s(%d): P port only receive %u pkts while total pkts is %u\n", __func__, idx, + frame->pkts_recv[MTL_SESSION_PORT_P], frame->pkts_total); if (frame->pkts_recv[MTL_SESSION_PORT_R] < (frame->pkts_total / 2)) - warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", - __func__, idx, frame->pkts_recv[MTL_SESSION_PORT_R], - frame->pkts_total); + warn("%s(%d): R port only receive %u pkts while total pkts is %u\n", __func__, idx, + frame->pkts_recv[MTL_SESSION_PORT_R], frame->pkts_total); } if (frame->interlaced) { - dbg("%s(%d), %s field\n", __func__, s->idx, - frame->second_field ? "second" : "first"); + dbg("%s(%d), %s field\n", __func__, s->idx, frame->second_field ? "second" : "first"); } if (d && d->front_frame) { @@ -84,11 +81,9 @@ static void *app_rx_st20p_frame_thread(void *arg) { err("%s(%d), invalid user meta size %" PRId64 "\n", __func__, idx, frame->user_meta_size); } else { - st_sha256((unsigned char *)frame->addr[0], - st_frame_plane_size(frame, 0), shas); + st_sha256((unsigned char *)frame->addr[0], st_frame_plane_size(frame, 0), shas); if (memcmp(shas, frame->user_meta, sizeof(shas))) { - err("%s(%d), sha check fail for frame %p\n", __func__, idx, - frame->addr); + err("%s(%d), sha check fail for frame %p\n", __func__, idx, frame->addr); st_sha_dump("user meta sha:", frame->user_meta); st_sha_dump("frame sha:", shas); } @@ -107,8 +102,7 @@ static void *app_rx_st20p_frame_thread(void *arg) { static int app_rx_st20p_init_frame_thread(struct st_app_rx_st20p_session *s) { int ret, idx = s->idx; - ret = - pthread_create(&s->st20p_app_thread, NULL, app_rx_st20p_frame_thread, s); + ret = pthread_create(&s->st20p_app_thread, NULL, app_rx_st20p_frame_thread, s); if (ret < 0) { err("%s(%d), st20p_app_thread create fail %d\n", __func__, ret, idx); return -EIO; @@ -134,15 +128,13 @@ static int app_rx_st20p_uinit(struct st_app_rx_st20p_session *s) { if (s->st20p_app_thread_stop) { /* wake up the thread */ info("%s(%d), wait app thread stop\n", __func__, idx); - if (s->handle) - st20p_rx_wake_block(s->handle); + if (s->handle) st20p_rx_wake_block(s->handle); pthread_join(s->st20p_app_thread, NULL); } if (s->handle) { ret = st20p_rx_free(s->handle); - if (ret < 0) - err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -157,13 +149,11 @@ static int app_rx_st20p_io_stat(struct st_app_rx_st20p_session *s) { int ret; struct st20_rx_port_status stats; - if (!s->handle) - return 0; + if (!s->handle) return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20p_rx_get_port_stats(s->handle, port, &stats); - if (ret < 0) - return ret; + if (ret < 0) return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -195,27 +185,26 @@ static int app_rx_st20p_init(struct st_app_context *ctx, st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], - st20p ? st20p->base.mcast_src_ip[MTL_PORT_P] - : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = - st20p ? st20p->base.udp_port : (10000 + s->idx); + memcpy( + ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], + st20p ? st20p->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf( + ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = st20p ? st20p->base.udp_port : (10000 + s->idx); if (ops.port.num_port > 1) { memcpy(ops.port.ip_addr[MTL_SESSION_PORT_R], st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], - st20p ? st20p->base.mcast_src_ip[MTL_PORT_R] - : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); + memcpy( + ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], + st20p ? st20p->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf( + ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st20p ? st20p->base.udp_port : (10000 + s->idx); } @@ -224,24 +213,18 @@ static int app_rx_st20p_init(struct st_app_context *ctx, ops.height = st20p ? st20p->info.height : 1080; ops.fps = st20p ? st20p->info.fps : ST_FPS_P59_94; ops.interlaced = st20p ? st20p->info.interlaced : false; - ops.output_fmt = - st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; - ops.transport_fmt = - st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; - ops.port.payload_type = - st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.output_fmt = st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.transport_fmt = st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; + ops.port.payload_type = st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.device = st20p ? st20p->info.device : ST_PLUGIN_DEVICE_AUTO; ops.flags |= ST20P_RX_FLAG_BLOCK_GET; ops.rx_burst_size = ctx->rx_burst_size; ops.framebuff_cnt = s->framebuff_cnt; /* always try to enable DMA offload */ ops.flags |= ST20P_RX_FLAG_DMA_OFFLOAD; - if (st20p && st20p->enable_rtcp) - ops.flags |= ST20P_RX_FLAG_ENABLE_RTCP; - if (ctx->enable_timing_parser) - ops.flags |= ST20P_RX_FLAG_TIMING_PARSER_STAT; - if (ctx->rx_video_multi_thread) - ops.flags |= ST20P_RX_FLAG_USE_MULTI_THREADS; + if (st20p && st20p->enable_rtcp) ops.flags |= ST20P_RX_FLAG_ENABLE_RTCP; + if (ctx->enable_timing_parser) ops.flags |= ST20P_RX_FLAG_TIMING_PARSER_STAT; + if (ctx->rx_video_multi_thread) ops.flags |= ST20P_RX_FLAG_USE_MULTI_THREADS; if (ctx->force_rx_video_numa >= 0) { ops.flags |= ST20P_RX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_rx_video_numa; @@ -302,8 +285,7 @@ static int app_rx_st20p_stat(struct st_app_rx_st20p_session *s) { s->stat_frame_received); #endif if (s->measure_latency && s->stat_frame_received) { - double latency_ms = - (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -316,17 +298,14 @@ static int app_rx_st20p_stat(struct st_app_rx_st20p_session *s) { static int app_rx_st20p_result(struct st_app_rx_st20p_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) - return -EINVAL; + if (!s->stat_frame_total_received) return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) - ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } @@ -341,15 +320,12 @@ int st_app_rx_st20p_sessions_init(struct st_app_context *ctx) { int ret = 0, i = 0; struct st_app_rx_st20p_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) - fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; - dbg("%s(%d), rx_st20p_session_cnt %d\n", __func__, i, - ctx->rx_st20p_session_cnt); + dbg("%s(%d), rx_st20p_session_cnt %d\n", __func__, i, ctx->rx_st20p_session_cnt); ctx->rx_st20p_sessions = (struct st_app_rx_st20p_session *)st_app_zmalloc( sizeof(struct st_app_rx_st20p_session) * ctx->rx_st20p_session_cnt); - if (!ctx->rx_st20p_sessions) - return -ENOMEM; + if (!ctx->rx_st20p_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; s->idx = i; @@ -370,8 +346,7 @@ int st_app_rx_st20p_sessions_init(struct st_app_context *ctx) { int st_app_rx_st20p_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_rx_st20p_session *s; - if (!ctx->rx_st20p_sessions) - return 0; + if (!ctx->rx_st20p_sessions) return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; app_rx_st20p_uinit(s); @@ -384,8 +359,7 @@ int st_app_rx_st20p_sessions_uinit(struct st_app_context *ctx) { int st_app_rx_st20p_sessions_stat(struct st_app_context *ctx) { int i; struct st_app_rx_st20p_session *s; - if (!ctx->rx_st20p_sessions) - return 0; + if (!ctx->rx_st20p_sessions) return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; @@ -399,8 +373,7 @@ int st_app_rx_st20p_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_st20p_session *s; - if (!ctx->rx_st20p_sessions) - return 0; + if (!ctx->rx_st20p_sessions) return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; @@ -414,8 +387,7 @@ int st_app_rx_st20p_sessions_pcap(struct st_app_context *ctx) { int i; struct st_app_rx_st20p_session *s; - if (!ctx->rx_st20p_sessions) - return 0; + if (!ctx->rx_st20p_sessions) return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; @@ -428,8 +400,7 @@ int st_app_rx_st20p_sessions_pcap(struct st_app_context *ctx) { int st_app_rx_st20p_io_stat(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_st20p_session *s; - if (!ctx->rx_st20p_sessions) - return 0; + if (!ctx->rx_st20p_sessions) return 0; for (i = 0; i < ctx->rx_st20p_session_cnt; i++) { s = &ctx->rx_st20p_sessions[i]; diff --git a/app/src/rx_st22p_app.c b/app/src/rx_st22p_app.c index ae67b6f45..c255bb285 100644 --- a/app/src/rx_st22p_app.c +++ b/app/src/rx_st22p_app.c @@ -9,8 +9,7 @@ static void app_rx_st22p_consume_frame(struct st_app_rx_st22p_session *s, struct st_display *d = s->display; if (frame->interlaced) { - dbg("%s(%d), %s field\n", __func__, s->idx, - frame->second_field ? "second" : "first"); + dbg("%s(%d), %s field\n", __func__, s->idx, frame->second_field ? "second" : "first"); } if (d && d->front_frame) { @@ -75,8 +74,7 @@ static void *app_rx_st22p_frame_thread(void *arg) { static int app_rx_st22p_init_frame_thread(struct st_app_rx_st22p_session *s) { int ret, idx = s->idx; - ret = - pthread_create(&s->st22p_app_thread, NULL, app_rx_st22p_frame_thread, s); + ret = pthread_create(&s->st22p_app_thread, NULL, app_rx_st22p_frame_thread, s); if (ret < 0) { err("%s(%d), st22p_app_thread create fail %d\n", __func__, ret, idx); return -EIO; @@ -101,15 +99,13 @@ static int app_rx_st22p_uinit(struct st_app_rx_st22p_session *s) { s->st22p_app_thread_stop = true; if (s->st22p_app_thread_stop) { info("%s(%d), wait app thread stop\n", __func__, idx); - if (s->handle) - st22p_rx_wake_block(s->handle); + if (s->handle) st22p_rx_wake_block(s->handle); pthread_join(s->st22p_app_thread, NULL); } if (s->handle) { ret = st22p_rx_free(s->handle); - if (ret < 0) - err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st20_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -133,27 +129,26 @@ static int app_rx_st22p_init(struct st_app_context *ctx, st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], - st22p ? st22p->base.mcast_src_ip[MTL_PORT_P] - : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = - st22p ? st22p->base.udp_port : (10000 + s->idx); + memcpy( + ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], + st22p ? st22p->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf( + ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = st22p ? st22p->base.udp_port : (10000 + s->idx); if (ops.port.num_port > 1) { memcpy(ops.port.ip_addr[MTL_SESSION_PORT_R], st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], - st22p ? st22p->base.mcast_src_ip[MTL_PORT_R] - : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); + memcpy( + ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], + st22p ? st22p->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf( + ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st22p ? st22p->base.udp_port : (10000 + s->idx); } @@ -162,10 +157,8 @@ static int app_rx_st22p_init(struct st_app_context *ctx, ops.height = st22p ? st22p->info.height : 1080; ops.fps = st22p ? st22p->info.fps : ST_FPS_P59_94; ops.interlaced = st22p ? st22p->info.interlaced : false; - ops.output_fmt = - st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; - ops.port.payload_type = - st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; + ops.output_fmt = st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.port.payload_type = st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; ops.pack_type = st22p ? st22p->info.pack_type : ST22_PACK_CODESTREAM; ops.codec = st22p ? st22p->info.codec : ST22_CODEC_JPEGXS; ops.device = st22p ? st22p->info.device : ST_PLUGIN_DEVICE_AUTO; @@ -173,8 +166,7 @@ static int app_rx_st22p_init(struct st_app_context *ctx, ops.max_codestream_size = 0; ops.flags |= ST22P_RX_FLAG_BLOCK_GET; ops.framebuff_cnt = s->framebuff_cnt; - if (st22p && st22p->enable_rtcp) - ops.flags |= ST22P_RX_FLAG_ENABLE_RTCP; + if (st22p && st22p->enable_rtcp) ops.flags |= ST22P_RX_FLAG_ENABLE_RTCP; if (ctx->force_rx_video_numa >= 0) { ops.flags |= ST22P_RX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_rx_video_numa; @@ -234,8 +226,7 @@ static int app_rx_st22p_stat(struct st_app_rx_st22p_session *s) { s->stat_frame_received); #endif if (s->measure_latency && s->stat_frame_received) { - double latency_ms = - (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; + double latency_ms = (double)s->stat_latency_us_sum / s->stat_frame_received / 1000; info("%s(%d), avrage latency %fms\n", __func__, s->idx, latency_ms); s->stat_latency_us_sum = 0; } @@ -248,17 +239,14 @@ static int app_rx_st22p_stat(struct st_app_rx_st22p_session *s) { static int app_rx_st22p_result(struct st_app_rx_st22p_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) - return -EINVAL; + if (!s->stat_frame_total_received) return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) - ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } @@ -273,15 +261,12 @@ int st_app_rx_st22p_sessions_init(struct st_app_context *ctx) { int ret = 0, i = 0; struct st_app_rx_st22p_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) - fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; - dbg("%s(%d), rx_st22p_session_cnt %d\n", __func__, i, - ctx->rx_st22p_session_cnt); + dbg("%s(%d), rx_st22p_session_cnt %d\n", __func__, i, ctx->rx_st22p_session_cnt); ctx->rx_st22p_sessions = (struct st_app_rx_st22p_session *)st_app_zmalloc( sizeof(struct st_app_rx_st22p_session) * ctx->rx_st22p_session_cnt); - if (!ctx->rx_st22p_sessions) - return -ENOMEM; + if (!ctx->rx_st22p_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; s->idx = i; @@ -302,8 +287,7 @@ int st_app_rx_st22p_sessions_init(struct st_app_context *ctx) { int st_app_rx_st22p_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_rx_st22p_session *s; - if (!ctx->rx_st22p_sessions) - return 0; + if (!ctx->rx_st22p_sessions) return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; app_rx_st22p_uinit(s); @@ -316,8 +300,7 @@ int st_app_rx_st22p_sessions_uinit(struct st_app_context *ctx) { int st_app_rx_st22p_sessions_stat(struct st_app_context *ctx) { int i; struct st_app_rx_st22p_session *s; - if (!ctx->rx_st22p_sessions) - return 0; + if (!ctx->rx_st22p_sessions) return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; @@ -331,8 +314,7 @@ int st_app_rx_st22p_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_st22p_session *s; - if (!ctx->rx_st22p_sessions) - return 0; + if (!ctx->rx_st22p_sessions) return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; @@ -346,8 +328,7 @@ int st_app_rx_st22p_sessions_pcap(struct st_app_context *ctx) { int i; struct st_app_rx_st22p_session *s; - if (!ctx->rx_st22p_sessions) - return 0; + if (!ctx->rx_st22p_sessions) return 0; for (i = 0; i < ctx->rx_st22p_session_cnt; i++) { s = &ctx->rx_st22p_sessions[i]; diff --git a/app/src/rx_st30p_app.c b/app/src/rx_st30p_app.c index 9f86e053e..2896417d7 100644 --- a/app/src/rx_st30p_app.c +++ b/app/src/rx_st30p_app.c @@ -39,8 +39,7 @@ static void *app_rx_st30p_frame_thread(void *arg) { static int app_rx_st30p_init_frame_thread(struct st_app_rx_st30p_session *s) { int ret, idx = s->idx; - ret = - pthread_create(&s->st30p_app_thread, NULL, app_rx_st30p_frame_thread, s); + ret = pthread_create(&s->st30p_app_thread, NULL, app_rx_st30p_frame_thread, s); if (ret < 0) { err("%s(%d), st30p_app_thread create fail %d\n", __func__, ret, idx); return -EIO; @@ -60,15 +59,13 @@ static int app_rx_st30p_uinit(struct st_app_rx_st30p_session *s) { if (s->st30p_app_thread_stop) { /* wake up the thread */ info("%s(%d), wait app thread stop\n", __func__, idx); - if (s->handle) - st30p_rx_wake_block(s->handle); + if (s->handle) st30p_rx_wake_block(s->handle); pthread_join(s->st30p_app_thread, NULL); } if (s->handle) { ret = st30p_rx_free(s->handle); - if (ret < 0) - err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st30_rx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -94,32 +91,30 @@ static int app_rx_st30p_init(struct st_app_context *ctx, st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_P) : ctx->rx_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], - st30p ? st30p->base.mcast_src_ip[MTL_PORT_P] - : ctx->rx_mcast_sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = - st30p ? st30p->base.udp_port : (10000 + s->idx); + memcpy( + ops.port.mcast_sip_addr[MTL_SESSION_PORT_P], + st30p ? st30p->base.mcast_src_ip[MTL_PORT_P] : ctx->rx_mcast_sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); + snprintf( + ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = st30p ? st30p->base.udp_port : (10000 + s->idx); if (ops.port.num_port > 1) { memcpy(ops.port.ip_addr[MTL_SESSION_PORT_R], st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_R) : ctx->rx_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - memcpy(ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], - st30p ? st30p->base.mcast_src_ip[MTL_PORT_R] - : ctx->rx_mcast_sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); + memcpy( + ops.port.mcast_sip_addr[MTL_SESSION_PORT_R], + st30p ? st30p->base.mcast_src_ip[MTL_PORT_R] : ctx->rx_mcast_sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); + snprintf( + ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st30p ? st30p->base.udp_port : (10000 + s->idx); } - ops.port.payload_type = - st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.port.payload_type = st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; ops.fmt = st30p ? st30p->info.audio_format : ST30_FMT_PCM24; ops.channel = st30p ? st30p->info.audio_channel : 2; @@ -127,8 +122,7 @@ static int app_rx_st30p_init(struct st_app_context *ctx, ops.ptime = st30p ? st30p->info.audio_ptime : ST30_PTIME_1MS; /* set frame size to 10ms time */ int framebuff_size = st30_calculate_framebuff_size( - ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, - &s->expect_fps); + ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, &s->expect_fps); ops.framebuff_size = framebuff_size; ops.flags |= ST30P_RX_FLAG_BLOCK_GET; @@ -181,17 +175,14 @@ static int app_rx_st30p_stat(struct st_app_rx_st30p_session *s) { static int app_rx_st30p_result(struct st_app_rx_st30p_session *s) { int idx = s->idx; uint64_t cur_time_ns = st_app_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - s->stat_frame_first_rx_time) / NS_PER_S; double framerate = s->stat_frame_total_received / time_sec; - if (!s->stat_frame_total_received) - return -EINVAL; + if (!s->stat_frame_total_received) return -EINVAL; critical("%s(%d), %s, fps %f, %d frame received\n", __func__, idx, - ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) - ? "OK" - : "FAILED", + ST_APP_EXPECT_NEAR(framerate, s->expect_fps, s->expect_fps * 0.05) ? "OK" + : "FAILED", framerate, s->stat_frame_total_received); return 0; } @@ -200,15 +191,12 @@ int st_app_rx_st30p_sessions_init(struct st_app_context *ctx) { int ret = 0, i = 0; struct st_app_rx_st30p_session *s; int fb_cnt = ctx->rx_video_fb_cnt; - if (fb_cnt <= 0) - fb_cnt = ST_APP_DEFAULT_FB_CNT; + if (fb_cnt <= 0) fb_cnt = ST_APP_DEFAULT_FB_CNT; - dbg("%s(%d), rx_st30p_session_cnt %d\n", __func__, i, - ctx->rx_st30p_session_cnt); + dbg("%s(%d), rx_st30p_session_cnt %d\n", __func__, i, ctx->rx_st30p_session_cnt); ctx->rx_st30p_sessions = (struct st_app_rx_st30p_session *)st_app_zmalloc( sizeof(struct st_app_rx_st30p_session) * ctx->rx_st30p_session_cnt); - if (!ctx->rx_st30p_sessions) - return -ENOMEM; + if (!ctx->rx_st30p_sessions) return -ENOMEM; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; s->idx = i; @@ -229,8 +217,7 @@ int st_app_rx_st30p_sessions_init(struct st_app_context *ctx) { int st_app_rx_st30p_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_rx_st30p_session *s; - if (!ctx->rx_st30p_sessions) - return 0; + if (!ctx->rx_st30p_sessions) return 0; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; app_rx_st30p_uinit(s); @@ -243,8 +230,7 @@ int st_app_rx_st30p_sessions_uinit(struct st_app_context *ctx) { int st_app_rx_st30p_sessions_stat(struct st_app_context *ctx) { int i; struct st_app_rx_st30p_session *s; - if (!ctx->rx_st30p_sessions) - return 0; + if (!ctx->rx_st30p_sessions) return 0; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; @@ -258,8 +244,7 @@ int st_app_rx_st30p_sessions_result(struct st_app_context *ctx) { int i, ret = 0; struct st_app_rx_st30p_session *s; - if (!ctx->rx_st30p_sessions) - return 0; + if (!ctx->rx_st30p_sessions) return 0; for (i = 0; i < ctx->rx_st30p_session_cnt; i++) { s = &ctx->rx_st30p_sessions[i]; diff --git a/app/src/rxtx_app.c b/app/src/rxtx_app.c index ce1479172..74164ea8e 100644 --- a/app/src/rxtx_app.c +++ b/app/src/rxtx_app.c @@ -39,19 +39,16 @@ static int app_dump_io_stat(struct st_app_context *ctx) { double tx_rate_m, rx_rate_m; ret = mtl_get_fix_info(ctx->st, &fix); - if (ret < 0) - return ret; + if (ret < 0) return ret; for (uint8_t port = 0; port < fix.num_ports; port++) { ret = mtl_get_port_stats(ctx->st, port, &stats); - if (ret < 0) - return ret; + if (ret < 0) return ret; tx_rate_m = (double)stats.tx_bytes * 8 / time_sec / MTL_STAT_M_UNIT; rx_rate_m = (double)stats.rx_bytes * 8 / time_sec / MTL_STAT_M_UNIT; - info("%s(%u), tx %f Mb/s rx %f Mb/s\n", __func__, port, tx_rate_m, - rx_rate_m); - if (stats.rx_hw_dropped_packets || stats.rx_err_packets || - stats.rx_nombuf_packets || stats.tx_err_packets) { + info("%s(%u), tx %f Mb/s rx %f Mb/s\n", __func__, port, tx_rate_m, rx_rate_m); + if (stats.rx_hw_dropped_packets || stats.rx_err_packets || stats.rx_nombuf_packets || + stats.tx_err_packets) { warn("%s(%u), hw drop %" PRIu64 " rx err %" PRIu64 " no mbuf %" PRIu64 " tx err %" PRIu64 "\n", __func__, port, stats.rx_hw_dropped_packets, stats.rx_err_packets, @@ -77,8 +74,7 @@ static int app_dump_ptp_sync_stat(struct st_app_context *ctx) { static void app_stat(void *priv) { struct st_app_context *ctx = priv; - if (ctx->stop) - return; + if (ctx->stop) return; if (ctx->mtl_log_stream) { app_dump_io_stat(ctx); @@ -102,11 +98,9 @@ static void app_stat(void *priv) { ctx->last_stat_time_ns = st_app_get_monotonic_time(); } -static void app_ptp_sync_notify(void *priv, - struct mtl_ptp_sync_notify_meta *meta) { +static void app_ptp_sync_notify(void *priv, struct mtl_ptp_sync_notify_meta *meta) { struct st_app_context *ctx = priv; - if (!ctx->ptp_systime_sync) - return; + if (!ctx->ptp_systime_sync) return; /* sync raw ptp to sys time */ uint64_t to_ns = mtl_ptp_read_time_raw(ctx->st); @@ -120,10 +114,8 @@ static void app_ptp_sync_notify(void *priv, int64_t delta = to_ns - from_ns; ctx->ptp_sync_cnt++; ctx->ptp_sync_delta_sum += delta; - if (delta > ctx->ptp_sync_delta_max) - ctx->ptp_sync_delta_max = delta; - if (delta < ctx->ptp_sync_delta_min) - ctx->ptp_sync_delta_min = delta; + if (delta > ctx->ptp_sync_delta_max) ctx->ptp_sync_delta_max = delta; + if (delta < ctx->ptp_sync_delta_min) ctx->ptp_sync_delta_min = delta; /* sample just offset the system time delta, better to calibrate as phc2sys * way which adjust the time frequency also */ @@ -131,22 +123,26 @@ static void app_ptp_sync_notify(void *priv, to_ts.tv_sec -= meta->master_utc_offset; /* utc offset */ ret = st_set_real_time(&to_ts); if (ret < 0) { - err("%s, set real time to %" PRIu64 " fail, delta %" PRId64 "\n", __func__, - to_ns, delta); + err("%s, set real time to %" PRIu64 " fail, delta %" PRId64 "\n", __func__, to_ns, + delta); if (ret == -EPERM) err("%s, please add capability to the app: sudo setcap 'cap_sys_time+ep' " "\n", __func__); } - dbg("%s, from_ns %" PRIu64 " to_ns %" PRIu64 " delta %" PRId64 " done\n", - __func__, from_ns, to_ns, delta); + dbg("%s, from_ns %" PRIu64 " to_ns %" PRIu64 " delta %" PRId64 " done\n", __func__, + from_ns, to_ns, delta); return; } -void app_set_log_level(enum mtl_log_level level) { app_log_level = level; } +void app_set_log_level(enum mtl_log_level level) { + app_log_level = level; +} -enum mtl_log_level app_get_log_level(void) { return app_log_level; } +enum mtl_log_level app_get_log_level(void) { + return app_log_level; +} static uint64_t app_ptp_from_tai_time(void *priv) { struct st_app_context *ctx = priv; @@ -156,8 +152,7 @@ static uint64_t app_ptp_from_tai_time(void *priv) { return ((uint64_t)spec.tv_sec * NS_PER_S) + spec.tv_nsec; } -static void user_param_init(struct st_app_context *ctx, - struct mtl_init_params *p) { +static void user_param_init(struct st_app_context *ctx, struct mtl_init_params *p) { memset(p, 0x0, sizeof(*p)); p->pmd[MTL_PORT_P] = MTL_PMD_DPDK_USER; @@ -190,11 +185,9 @@ static void st_app_ctx_init(struct st_app_context *ctx) { ctx->tx_anc_session_cnt = 0; snprintf(ctx->tx_st22_url, sizeof(ctx->tx_st22_url), "%s", "test.raw"); ctx->tx_st22_session_cnt = 0; - snprintf(ctx->tx_st22p_url, sizeof(ctx->tx_st22p_url), "%s", - "test_rfc4175.yuv"); + snprintf(ctx->tx_st22p_url, sizeof(ctx->tx_st22p_url), "%s", "test_rfc4175.yuv"); ctx->tx_st22p_session_cnt = 0; - snprintf(ctx->tx_st20p_url, sizeof(ctx->tx_st20p_url), "%s", - "test_rfc4175.yuv"); + snprintf(ctx->tx_st20p_url, sizeof(ctx->tx_st20p_url), "%s", "test_rfc4175.yuv"); ctx->tx_st20p_session_cnt = 0; /* rx */ @@ -241,17 +234,14 @@ int st_app_video_get_lcore(struct st_app_context *ctx, int sch_idx, bool rtp, if (rtp) { if (ctx->rtp_lcore[sch_idx] < 0) { ret = mtl_get_lcore(ctx->st, &video_lcore); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx->rtp_lcore[sch_idx] = video_lcore; - info("%s, new rtp lcore %d for sch idx %d\n", __func__, video_lcore, - sch_idx); + info("%s, new rtp lcore %d for sch idx %d\n", __func__, video_lcore, sch_idx); } } else { if (ctx->lcore[sch_idx] < 0) { ret = mtl_get_lcore(ctx->st, &video_lcore); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx->lcore[sch_idx] = video_lcore; info("%s, new lcore %d for sch idx %d\n", __func__, video_lcore, sch_idx); } @@ -292,8 +282,7 @@ static void st_app_ctx_free(struct st_app_context *ctx) { st22_app_rx_sessions_uinit(ctx); if (ctx->runtime_session) { - if (ctx->st) - mtl_stop(ctx->st); + if (ctx->st) mtl_stop(ctx->st); } if (ctx->json_ctx) { @@ -348,11 +337,10 @@ static void st_app_sig_handler(int signo) { info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - if (ctx->st) - mtl_abort(ctx->st); - ctx->stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + if (ctx->st) mtl_abort(ctx->st); + ctx->stop = true; + break; } return; @@ -404,31 +392,28 @@ int main(int argc, char **argv) { if (!ctx->para.tx_queues_cnt[i]) { if (ctx->json_ctx) { /* get from the assigned sessions on each interface */ - ctx->para.tx_queues_cnt[i] = st_tx_sessions_queue_cnt( - ctx->json_ctx->interfaces[i].tx_video_sessions_cnt, - ctx->json_ctx->interfaces[i].tx_audio_sessions_cnt, - ctx->json_ctx->interfaces[i].tx_anc_sessions_cnt); + ctx->para.tx_queues_cnt[i] = + st_tx_sessions_queue_cnt(ctx->json_ctx->interfaces[i].tx_video_sessions_cnt, + ctx->json_ctx->interfaces[i].tx_audio_sessions_cnt, + ctx->json_ctx->interfaces[i].tx_anc_sessions_cnt); } else { ctx->para.tx_queues_cnt[i] = st_tx_sessions_queue_cnt( - tx_st20_sessions, ctx->tx_audio_session_cnt, - ctx->tx_anc_session_cnt); + tx_st20_sessions, ctx->tx_audio_session_cnt, ctx->tx_anc_session_cnt); } - if (ctx->para.tx_queues_cnt[i] && - (ctx->para.pmd[i] == MTL_PMD_DPDK_USER)) { + if (ctx->para.tx_queues_cnt[i] && (ctx->para.pmd[i] == MTL_PMD_DPDK_USER)) { ctx->para.tx_queues_cnt[i] += 4; /* add extra 4 queues for recovery */ } } if (!ctx->para.rx_queues_cnt[i]) { if (ctx->json_ctx) { /* get from the assigned sessions on each interface */ - ctx->para.rx_queues_cnt[i] = st_rx_sessions_queue_cnt( - ctx->json_ctx->interfaces[i].rx_video_sessions_cnt, - ctx->json_ctx->interfaces[i].rx_audio_sessions_cnt, - ctx->json_ctx->interfaces[i].rx_anc_sessions_cnt); + ctx->para.rx_queues_cnt[i] = + st_rx_sessions_queue_cnt(ctx->json_ctx->interfaces[i].rx_video_sessions_cnt, + ctx->json_ctx->interfaces[i].rx_audio_sessions_cnt, + ctx->json_ctx->interfaces[i].rx_anc_sessions_cnt); } else { ctx->para.rx_queues_cnt[i] = st_rx_sessions_queue_cnt( - rx_st20_sessions, ctx->rx_audio_session_cnt, - ctx->rx_anc_session_cnt); + rx_st20_sessions, ctx->rx_audio_session_cnt, ctx->rx_anc_session_cnt); } } } @@ -438,8 +423,7 @@ int main(int argc, char **argv) { ctx->para.nb_rx_hdr_split_queues = ctx->rx_video_session_cnt; } - if (ctx->ptp_systime_sync) - ctx->para.ptp_sync_notify = app_ptp_sync_notify; + if (ctx->ptp_systime_sync) ctx->para.ptp_sync_notify = app_ptp_sync_notify; ctx->st = mtl_init(&ctx->para); if (!ctx->st) { @@ -598,8 +582,7 @@ int main(int argc, char **argv) { while (!ctx->stop) { sleep(1); run_time_s++; - if (test_time_s && (run_time_s > test_time_s)) - break; + if (test_time_s && (run_time_s > test_time_s)) break; if (ctx->pcapng_max_pkts && (run_time_s == 10)) { /* trigger pcap dump if */ st_app_pcap(ctx); } @@ -608,8 +591,7 @@ int main(int argc, char **argv) { if (!ctx->runtime_session) { /* stop st first */ - if (ctx->st) - mtl_stop(ctx->st); + if (ctx->st) mtl_stop(ctx->st); } ret = st_app_result(ctx); @@ -642,8 +624,7 @@ int st_set_mtl_log_file(struct st_app_context *ctx, const char *file) { } void st_sha_dump(const char *tag, const unsigned char *sha) { - if (tag) - info("%s, ", tag); + if (tag) info("%s, ", tag); for (size_t i = 0; i < SHA256_DIGEST_LENGTH; i++) { info("0x%02x ", sha[i]); } diff --git a/app/src/tx_ancillary_app.c b/app/src/tx_ancillary_app.c index d61d8eac5..45be3be1f 100644 --- a/app/src/tx_ancillary_app.c +++ b/app/src/tx_ancillary_app.c @@ -14,22 +14,19 @@ static int app_tx_anc_next_frame(void *priv, uint16_t *next_frame_idx, st_pthread_mutex_lock(&s->st40_wake_mutex); if (ST_TX_FRAME_READY == framebuff->stat) { - dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", - __func__, s->idx, consumer_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, - ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), next frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, + s->idx, consumer_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); ret = 0; framebuff->stat = ST_TX_FRAME_IN_TRANSMITTING; *next_frame_idx = consumer_idx; /* point to next */ consumer_idx++; - if (consumer_idx >= s->framebuff_cnt) - consumer_idx = 0; + if (consumer_idx >= s->framebuff_cnt) consumer_idx = 0; s->framebuff_consumer_idx = consumer_idx; } else { /* not ready */ - dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, - framebuff->stat); + dbg("%s(%d), idx %u err stat %d\n", __func__, s->idx, consumer_idx, framebuff->stat); ret = -EIO; } st_pthread_cond_signal(&s->st40_wake_cond); @@ -48,14 +45,13 @@ static int app_tx_anc_frame_done(void *priv, uint16_t frame_idx, if (ST_TX_FRAME_IN_TRANSMITTING == framebuff->stat) { ret = 0; framebuff->stat = ST_TX_FRAME_FREE; - dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", - __func__, s->idx, frame_idx, meta->epoch, - st10_get_tai(meta->tfmt, meta->timestamp, - ST10_VIDEO_SAMPLING_RATE_90K)); + dbg("%s(%d), done frame idx %u, epoch %" PRIu64 ", tai %" PRIu64 "\n", __func__, + s->idx, frame_idx, meta->epoch, + st10_get_tai(meta->tfmt, meta->timestamp, ST10_VIDEO_SAMPLING_RATE_90K)); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, s->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, s->idx, framebuff->stat, + frame_idx); } st_pthread_cond_signal(&s->st40_wake_cond); st_pthread_mutex_unlock(&s->st40_wake_mutex); @@ -116,8 +112,7 @@ static void *app_tx_anc_frame_thread(void *arg) { } st_pthread_mutex_unlock(&s->st40_wake_mutex); - struct st40_frame *frame_addr = - st40_tx_get_framebuffer(s->handle, producer_idx); + struct st40_frame *frame_addr = st40_tx_get_framebuffer(s->handle, producer_idx); app_tx_anc_build_frame(s, frame_addr); st_pthread_mutex_lock(&s->st40_wake_mutex); @@ -125,8 +120,7 @@ static void *app_tx_anc_frame_thread(void *arg) { framebuff->stat = ST_TX_FRAME_READY; /* point to next */ producer_idx++; - if (producer_idx >= s->framebuff_cnt) - producer_idx = 0; + if (producer_idx >= s->framebuff_cnt) producer_idx = 0; s->framebuff_producer_idx = producer_idx; st_pthread_mutex_unlock(&s->st40_wake_mutex); } @@ -171,8 +165,8 @@ static void *app_tx_anc_pcap_thread(void *arg) { if (ntohs(eth_hdr->ether_type) == ETHERTYPE_IP) { ip_hdr = (struct ip *)(packet + sizeof(struct ether_header)); if (ip_hdr->ip_p == IPPROTO_UDP) { - udp_hdr = (struct udphdr *)(packet + sizeof(struct ether_header) + - sizeof(struct ip)); + udp_hdr = + (struct udphdr *)(packet + sizeof(struct ether_header) + sizeof(struct ip)); udp_data_len = ntohs(udp_hdr->len) - sizeof(struct udphdr); mtl_memcpy(usrptr, packet + sizeof(struct ether_header) + sizeof(struct ip) + @@ -186,8 +180,7 @@ static void *app_tx_anc_pcap_thread(void *arg) { /* open capture file for offline processing */ s->st40_pcap = pcap_open_offline(s->st40_source_url, err_buf); if (s->st40_pcap == NULL) { - err("pcap_open_offline %s() failed: %s\n:", s->st40_source_url, - err_buf); + err("pcap_open_offline %s() failed: %s\n:", s->st40_source_url, err_buf); return NULL; } } @@ -232,27 +225,21 @@ static void app_tx_anc_build_rtp(struct st_app_tx_anc_session *s, void *usrptr, payload_hdr->second_hdr_chunk.did = st40_add_parity_bits(0x43); payload_hdr->second_hdr_chunk.sdid = st40_add_parity_bits(0x02); payload_hdr->second_hdr_chunk.data_count = st40_add_parity_bits(udw_size); - payload_hdr->swaped_first_hdr_chunk = - htonl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = - htonl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = htonl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); for (int i = 0; i < udw_size; i++) { st40_set_udw(i + 3, st40_add_parity_bits(s->st40_frame_cursor[i]), (uint8_t *)&payload_hdr->second_hdr_chunk); } - check_sum = st40_calc_checksum(3 + udw_size, - (uint8_t *)&payload_hdr->second_hdr_chunk); - st40_set_udw(udw_size + 3, check_sum, - (uint8_t *)&payload_hdr->second_hdr_chunk); - total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = - (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + - total_size; // Full size of one ANC + check_sum = st40_calc_checksum(3 + udw_size, (uint8_t *)&payload_hdr->second_hdr_chunk); + st40_set_udw(udw_size + 3, check_sum, (uint8_t *)&payload_hdr->second_hdr_chunk); + total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = + sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC *mbuf_len = payload_len + sizeof(struct st40_rfc8331_rtp_hdr); hdr->length = htons(payload_len); s->st40_frame_cursor += udw_size; @@ -308,8 +295,7 @@ static int app_tx_anc_open_source(struct st_app_tx_anc_session *s) { return -EIO; } - uint8_t *m = - mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st40_source_fd, 0); + uint8_t *m = mmap(NULL, i.st_size, PROT_READ, MAP_SHARED, s->st40_source_fd, 0); if (MAP_FAILED != m) { s->st40_source_begin = m; @@ -359,14 +345,11 @@ static int app_tx_anc_start_source(struct st_app_tx_anc_session *s) { s->st40_app_thread_stop = false; if (s->st40_pcap_input) - ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_pcap_thread, - (void *)s); + ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_pcap_thread, (void *)s); else if (s->st40_rtp_input) - ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_rtp_thread, - (void *)s); + ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_rtp_thread, (void *)s); else - ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_frame_thread, - (void *)s); + ret = pthread_create(&s->st40_app_thread, NULL, app_tx_anc_frame_thread, (void *)s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -386,8 +369,7 @@ static void app_tx_anc_stop_source(struct st_app_tx_anc_session *s) { st_pthread_mutex_lock(&s->st40_wake_mutex); st_pthread_cond_signal(&s->st40_wake_cond); st_pthread_mutex_unlock(&s->st40_wake_mutex); - if (s->st40_app_thread) - (void)pthread_join(s->st40_app_thread, NULL); + if (s->st40_app_thread) (void)pthread_join(s->st40_app_thread, NULL); } } @@ -398,8 +380,7 @@ int app_tx_anc_uinit(struct st_app_tx_anc_session *s) { if (s->handle) { ret = st40_tx_free(s->handle); - if (ret < 0) - err("%s(%d), st_tx_anc_session_free fail %d\n", __func__, s->idx, ret); + if (ret < 0) err("%s(%d), st_tx_anc_session_free fail %d\n", __func__, s->idx, ret); s->handle = NULL; } @@ -416,8 +397,7 @@ int app_tx_anc_uinit(struct st_app_tx_anc_session *s) { return 0; } -static int app_tx_anc_init(struct st_app_context *ctx, - st_json_ancillary_session_t *anc, +static int app_tx_anc_init(struct st_app_context *ctx, st_json_ancillary_session_t *anc, struct st_app_tx_anc_session *s) { int idx = s->idx, ret; struct st40_tx_ops ops; @@ -428,8 +408,8 @@ static int app_tx_anc_init(struct st_app_context *ctx, s->framebuff_cnt = 2; s->st40_seq_id = 1; - s->framebuffs = (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * - s->framebuff_cnt); + s->framebuffs = + (struct st_tx_frame *)st_app_zmalloc(sizeof(*s->framebuffs) * s->framebuff_cnt); if (!s->framebuffs) { return -ENOMEM; } @@ -451,10 +431,8 @@ static int app_tx_anc_init(struct st_app_context *ctx, : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.udp_port[MTL_SESSION_PORT_P] = - anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.udp_port[MTL_SESSION_PORT_P] = anc ? anc->base.udp_port : (10200 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -466,13 +444,11 @@ static int app_tx_anc_init(struct st_app_context *ctx, : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); snprintf(ops.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - anc ? anc->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); - ops.udp_port[MTL_SESSION_PORT_R] = - anc ? anc->base.udp_port : (10200 + s->idx); + anc ? anc->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); + ops.udp_port[MTL_SESSION_PORT_R] = anc ? anc->base.udp_port : (10200 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], - ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], + MTL_MAC_ADDR_LEN); ops.flags |= ST40_TX_FLAG_USER_R_MAC; } } @@ -484,8 +460,7 @@ static int app_tx_anc_init(struct st_app_context *ctx, s->st40_pcap_input = false; ops.type = anc ? anc->info.type : ST40_TYPE_FRAME_LEVEL; ops.interlaced = anc ? anc->info.interlaced : false; - ops.payload_type = - anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; + ops.payload_type = anc ? anc->base.payload_type : ST_APP_PAYLOAD_TYPE_ANCILLARY; /* select rtp type for pcap file or tx_video_rtp_ring_size */ if (strstr(s->st40_source_url, ".pcap")) { ops.type = ST40_TYPE_RTP_LEVEL; @@ -501,10 +476,8 @@ static int app_tx_anc_init(struct st_app_context *ctx, else ops.rtp_ring_size = 16; } - if (anc && anc->enable_rtcp) - ops.flags |= ST40_TX_FLAG_ENABLE_RTCP; - if (ctx->tx_anc_dedicate_queue) - ops.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; + if (anc && anc->enable_rtcp) ops.flags |= ST40_TX_FLAG_ENABLE_RTCP; + if (ctx->tx_anc_dedicate_queue) ops.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; handle = st40_tx_create(ctx->st, &ops); if (!handle) { @@ -526,8 +499,7 @@ static int app_tx_anc_init(struct st_app_context *ctx, ret = app_tx_anc_start_source(s); if (ret < 0) { - err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, - ret); + err("%s(%d), app_tx_audio_session_start_source fail %d\n", __func__, idx, ret); app_tx_anc_uinit(s); return ret; } @@ -537,8 +509,7 @@ static int app_tx_anc_init(struct st_app_context *ctx, int st_app_tx_anc_sessions_stop(struct st_app_context *ctx) { struct st_app_tx_anc_session *s; - if (!ctx->tx_anc_sessions) - return 0; + if (!ctx->tx_anc_sessions) return 0; for (int i = 0; i < ctx->tx_anc_session_cnt; i++) { s = &ctx->tx_anc_sessions[i]; app_tx_anc_stop_source(s); @@ -552,14 +523,13 @@ int st_app_tx_anc_sessions_init(struct st_app_context *ctx) { struct st_app_tx_anc_session *s; ctx->tx_anc_sessions = (struct st_app_tx_anc_session *)st_app_zmalloc( sizeof(struct st_app_tx_anc_session) * ctx->tx_anc_session_cnt); - if (!ctx->tx_anc_sessions) - return -ENOMEM; + if (!ctx->tx_anc_sessions) return -ENOMEM; for (int i = 0; i < ctx->tx_anc_session_cnt; i++) { s = &ctx->tx_anc_sessions[i]; s->idx = i; - ret = app_tx_anc_init( - ctx, ctx->json_ctx ? &ctx->json_ctx->tx_anc_sessions[i] : NULL, s); + ret = app_tx_anc_init(ctx, ctx->json_ctx ? &ctx->json_ctx->tx_anc_sessions[i] : NULL, + s); if (ret < 0) { err("%s(%d), app_tx_anc_session_init fail %d\n", __func__, i, ret); return ret; @@ -571,8 +541,7 @@ int st_app_tx_anc_sessions_init(struct st_app_context *ctx) { int st_app_tx_anc_sessions_uinit(struct st_app_context *ctx) { struct st_app_tx_anc_session *s; - if (!ctx->tx_anc_sessions) - return 0; + if (!ctx->tx_anc_sessions) return 0; for (int i = 0; i < ctx->tx_anc_session_cnt; i++) { s = &ctx->tx_anc_sessions[i]; diff --git a/app/src/tx_st20p_app.c b/app/src/tx_st20p_app.c index 4a785144d..a3c210a5f 100644 --- a/app/src/tx_st20p_app.c +++ b/app/src/tx_st20p_app.c @@ -27,8 +27,7 @@ static void app_tx_st20p_display_frame(struct st_app_tx_st20p_session *s, } } -static int app_tx_st20p_notify_event(void *priv, enum st_event event, - void *args) { +static int app_tx_st20p_notify_event(void *priv, enum st_event event, void *args) { struct st_app_tx_st20p_session *s = priv; if (event == ST_EVENT_VSYNC) { struct st10_vsync_meta *meta = args; @@ -43,8 +42,7 @@ static int app_tx_st20p_notify_event(void *priv, enum st_event event, } static void app_tx_st20p_build_frame(struct st_app_tx_st20p_session *s, - struct st_frame *frame, - size_t frame_size) { + struct st_frame *frame, size_t frame_size) { uint8_t *src = s->st20p_frame_cursor; if (!s->ctx->tx_copy_once || !s->st20p_frames_copied) { @@ -76,8 +74,7 @@ static void *app_tx_st20p_frame_thread(void *arg) { } app_tx_st20p_build_frame(s, frame, s->st20p_frame_size); if (s->sha_check) { - st_sha256((unsigned char *)frame->addr[0], st_frame_plane_size(frame, 0), - shas); + st_sha256((unsigned char *)frame->addr[0], st_frame_plane_size(frame, 0), shas); frame->user_meta = shas; frame->user_meta_size = sizeof(shas); } @@ -104,8 +101,8 @@ static int app_tx_st20p_open_source(struct st_app_tx_st20p_session *s) { return -EIO; } if (i.st_size < s->st20p_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, - s->st20p_source_url, s->st20p_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, s->st20p_source_url, + s->st20p_frame_size); close(fd); return -EIO; } @@ -138,8 +135,7 @@ static int app_tx_st20p_start_source(struct st_app_tx_st20p_session *s) { int ret = -EINVAL; int idx = s->idx; - ret = - pthread_create(&s->st20p_app_thread, NULL, app_tx_st20p_frame_thread, s); + ret = pthread_create(&s->st20p_app_thread, NULL, app_tx_st20p_frame_thread, s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -157,8 +153,7 @@ static void app_tx_st20p_stop_source(struct st_app_tx_st20p_session *s) { s->st20p_app_thread_stop = true; if (s->st20p_app_thread) { info("%s(%d), wait app thread stop\n", __func__, s->idx); - if (s->handle) - st20p_tx_wake_block(s->handle); + if (s->handle) st20p_tx_wake_block(s->handle); pthread_join(s->st20p_app_thread, NULL); s->st20p_app_thread = 0; } @@ -184,8 +179,7 @@ static int app_tx_st20p_handle_free(struct st_app_tx_st20p_session *s) { if (s->handle) { ret = st20p_tx_free(s->handle); - if (ret < 0) - err("%s(%d), st20p_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st20p_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -213,13 +207,11 @@ static int app_tx_st20p_io_stat(struct st_app_tx_st20p_session *s) { int ret; struct st20_tx_port_status stats; - if (!s->handle) - return 0; + if (!s->handle) return 0; for (uint8_t port = 0; port < s->num_port; port++) { ret = st20p_tx_get_port_stats(s->handle, port, &stats); - if (ret < 0) - return ret; + if (ret < 0) return ret; tx_rate_m = (double)stats.bytes * 8 / time_sec / MTL_STAT_M_UNIT; fps = (double)stats.frames / time_sec; @@ -231,8 +223,7 @@ static int app_tx_st20p_io_stat(struct st_app_tx_st20p_session *s) { return 0; } -static int app_tx_st20p_init(struct st_app_context *ctx, - st_json_st20p_session_t *st20p, +static int app_tx_st20p_init(struct st_app_context *ctx, st_json_st20p_session_t *st20p, struct st_app_tx_st20p_session *s) { int idx = s->idx, ret; struct st20p_tx_ops ops; @@ -252,11 +243,10 @@ static int app_tx_st20p_init(struct st_app_context *ctx, st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = - st20p ? st20p->base.udp_port : (10000 + s->idx); + snprintf( + ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = st20p ? st20p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -267,33 +257,28 @@ static int app_tx_st20p_init(struct st_app_context *ctx, st20p ? st_json_ip(ctx, &st20p->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); + snprintf( + ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st20p ? st20p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st20p ? st20p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], - ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], + MTL_MAC_ADDR_LEN); ops.flags |= ST20P_TX_FLAG_USER_R_MAC; } } - ops.port.payload_type = - st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; + ops.port.payload_type = st20p ? st20p->base.payload_type : ST_APP_PAYLOAD_TYPE_VIDEO; ops.width = st20p ? st20p->info.width : 1920; ops.height = st20p ? st20p->info.height : 1080; ops.fps = st20p ? st20p->info.fps : ST_FPS_P59_94; ops.interlaced = st20p ? st20p->info.interlaced : false; - ops.input_fmt = - st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; - ops.transport_pacing = - st20p ? st20p->info.transport_pacing : ST21_PACING_NARROW; + ops.input_fmt = st20p ? st20p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.transport_pacing = st20p ? st20p->info.transport_pacing : ST21_PACING_NARROW; if (ctx->tx_pacing_type) /* override if args has pacing defined */ ops.transport_pacing = ctx->tx_pacing_type; - ops.transport_packing = - st20p ? st20p->info.transport_packing : ST20_PACKING_BPM; - ops.transport_fmt = - st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; + ops.transport_packing = st20p ? st20p->info.transport_packing : ST20_PACKING_BPM; + ops.transport_fmt = st20p ? st20p->info.transport_format : ST20_FMT_YUV_422_10BIT; ops.device = st20p ? st20p->info.device : ST_PLUGIN_DEVICE_AUTO; ops.framebuff_cnt = 2; ops.flags |= ST20P_TX_FLAG_BLOCK_GET; @@ -301,16 +286,11 @@ static int app_tx_st20p_init(struct st_app_context *ctx, ops.pad_interval = ctx->tx_pad_interval; ops.rtp_timestamp_delta_us = ctx->tx_ts_delta_us; ops.notify_event = app_tx_st20p_notify_event; - if (ctx->tx_no_static_pad) - ops.flags |= ST20P_TX_FLAG_DISABLE_STATIC_PAD_P; - if (st20p && st20p->enable_rtcp) - ops.flags |= ST20P_TX_FLAG_ENABLE_RTCP; - if (ctx->tx_ts_first_pkt) - ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; - if (ctx->tx_ts_epoch) - ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH; - if (ctx->tx_no_bulk) - ops.flags |= ST20P_TX_FLAG_DISABLE_BULK; + if (ctx->tx_no_static_pad) ops.flags |= ST20P_TX_FLAG_DISABLE_STATIC_PAD_P; + if (st20p && st20p->enable_rtcp) ops.flags |= ST20P_TX_FLAG_ENABLE_RTCP; + if (ctx->tx_ts_first_pkt) ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; + if (ctx->tx_ts_epoch) ops.flags |= ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH; + if (ctx->tx_no_bulk) ops.flags |= ST20P_TX_FLAG_DISABLE_BULK; if (ctx->force_tx_video_numa >= 0) { ops.flags |= ST20P_TX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_tx_video_numa; @@ -371,8 +351,7 @@ int st_app_tx_st20p_sessions_init(struct st_app_context *ctx) { struct st_app_tx_st20p_session *s; ctx->tx_st20p_sessions = (struct st_app_tx_st20p_session *)st_app_zmalloc( sizeof(struct st_app_tx_st20p_session) * ctx->tx_st20p_session_cnt); - if (!ctx->tx_st20p_sessions) - return -ENOMEM; + if (!ctx->tx_st20p_sessions) return -ENOMEM; for (i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; s->idx = i; @@ -389,8 +368,7 @@ int st_app_tx_st20p_sessions_init(struct st_app_context *ctx) { int st_app_tx_st20p_sessions_stop(struct st_app_context *ctx) { struct st_app_tx_st20p_session *s; - if (!ctx->tx_st20p_sessions) - return 0; + if (!ctx->tx_st20p_sessions) return 0; for (int i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; app_tx_st20p_stop_source(s); @@ -402,8 +380,7 @@ int st_app_tx_st20p_sessions_stop(struct st_app_context *ctx) { int st_app_tx_st20p_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_tx_st20p_session *s; - if (!ctx->tx_st20p_sessions) - return 0; + if (!ctx->tx_st20p_sessions) return 0; for (i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; app_tx_st20p_uinit(s); @@ -416,8 +393,7 @@ int st_app_tx_st20p_sessions_uinit(struct st_app_context *ctx) { int st_app_tx_st20p_io_stat(struct st_app_context *ctx) { int i, ret = 0; struct st_app_tx_st20p_session *s; - if (!ctx->tx_st20p_sessions) - return 0; + if (!ctx->tx_st20p_sessions) return 0; for (i = 0; i < ctx->tx_st20p_session_cnt; i++) { s = &ctx->tx_st20p_sessions[i]; diff --git a/app/src/tx_st22p_app.c b/app/src/tx_st22p_app.c index 02d8d399c..763c1690b 100644 --- a/app/src/tx_st22p_app.c +++ b/app/src/tx_st22p_app.c @@ -39,8 +39,7 @@ static void app_tx_st22p_build_frame(struct st_app_tx_st22p_session *s, s->st22p_frame_cursor += s->st22p_frame_size; if (frame->interlaced) { - dbg("%s(%d), %s field\n", __func__, s->idx, - frame->second_field ? "second" : "first"); + dbg("%s(%d), %s field\n", __func__, s->idx, frame->second_field ? "second" : "first"); } app_tx_st22p_display_frame(s, frame); @@ -83,8 +82,8 @@ static int app_tx_st22p_open_source(struct st_app_tx_st22p_session *s) { return -EIO; } if (i.st_size < s->st22p_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, - s->st22p_source_url, s->st22p_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, s->st22p_source_url, + s->st22p_frame_size); close(fd); return -EIO; } @@ -117,8 +116,7 @@ static int app_tx_st22p_start_source(struct st_app_tx_st22p_session *s) { int ret = -EINVAL; int idx = s->idx; - ret = - pthread_create(&s->st22p_app_thread, NULL, app_tx_st22p_frame_thread, s); + ret = pthread_create(&s->st22p_app_thread, NULL, app_tx_st22p_frame_thread, s); if (ret < 0) { err("%s(%d), thread create fail err = %d\n", __func__, idx, ret); return ret; @@ -137,8 +135,7 @@ static void app_tx_st22p_stop_source(struct st_app_tx_st22p_session *s) { /* wake up the thread */ if (s->st22p_app_thread) { info("%s(%d), wait app thread stop\n", __func__, s->idx); - if (s->handle) - st22p_tx_wake_block(s->handle); + if (s->handle) st22p_tx_wake_block(s->handle); pthread_join(s->st22p_app_thread, NULL); s->st22p_app_thread = 0; } @@ -164,8 +161,7 @@ static int app_tx_st22p_handle_free(struct st_app_tx_st22p_session *s) { if (s->handle) { ret = st22p_tx_free(s->handle); - if (ret < 0) - err("%s(%d), st22p_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st22p_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -185,8 +181,7 @@ static int app_tx_st22p_uinit(struct st_app_tx_st22p_session *s) { return 0; } -static int app_tx_st22p_init(struct st_app_context *ctx, - st_json_st22p_session_t *st22p, +static int app_tx_st22p_init(struct st_app_context *ctx, st_json_st22p_session_t *st22p, struct st_app_tx_st22p_session *s) { int idx = s->idx, ret; struct st22p_tx_ops ops; @@ -202,11 +197,10 @@ static int app_tx_st22p_init(struct st_app_context *ctx, st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = - st22p ? st22p->base.udp_port : (10000 + s->idx); + snprintf( + ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = st22p ? st22p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -217,39 +211,34 @@ static int app_tx_st22p_init(struct st_app_context *ctx, st22p ? st_json_ip(ctx, &st22p->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); + snprintf( + ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st22p ? st22p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st22p ? st22p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], - ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], + MTL_MAC_ADDR_LEN); ops.flags |= ST22P_TX_FLAG_USER_R_MAC; } } - ops.port.payload_type = - st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; + ops.port.payload_type = st22p ? st22p->base.payload_type : ST_APP_PAYLOAD_TYPE_ST22; ops.width = st22p ? st22p->info.width : 1920; ops.height = st22p ? st22p->info.height : 1080; ops.fps = st22p ? st22p->info.fps : ST_FPS_P59_94; ops.interlaced = st22p ? st22p->info.interlaced : false; - ops.input_fmt = - st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; + ops.input_fmt = st22p ? st22p->info.format : ST_FRAME_FMT_YUV422RFC4175PG2BE10; ops.pack_type = st22p ? st22p->info.pack_type : ST22_PACK_CODESTREAM; ops.codec = st22p ? st22p->info.codec : ST22_CODEC_JPEGXS; ops.device = st22p ? st22p->info.device : ST_PLUGIN_DEVICE_AUTO; ops.quality = st22p ? st22p->info.quality : ST22_QUALITY_MODE_SPEED; ops.codec_thread_cnt = st22p ? st22p->info.codec_thread_count : 0; ops.codestream_size = ops.width * ops.height * 3 / 8; - if (ops.interlaced) - ops.codestream_size /= 2; /* the size is for each field */ + if (ops.interlaced) ops.codestream_size /= 2; /* the size is for each field */ ops.framebuff_cnt = 2; ops.flags |= ST22P_TX_FLAG_BLOCK_GET; - if (st22p && st22p->enable_rtcp) - ops.flags |= ST22P_TX_FLAG_ENABLE_RTCP; - if (ctx->tx_no_bulk) - ops.flags |= ST22P_TX_FLAG_DISABLE_BULK; + if (st22p && st22p->enable_rtcp) ops.flags |= ST22P_TX_FLAG_ENABLE_RTCP; + if (ctx->tx_no_bulk) ops.flags |= ST22P_TX_FLAG_DISABLE_BULK; if (ctx->force_tx_video_numa >= 0) { ops.flags |= ST22P_TX_FLAG_FORCE_NUMA; ops.socket_id = ctx->force_tx_video_numa; @@ -309,8 +298,7 @@ int st_app_tx_st22p_sessions_init(struct st_app_context *ctx) { struct st_app_tx_st22p_session *s; ctx->tx_st22p_sessions = (struct st_app_tx_st22p_session *)st_app_zmalloc( sizeof(struct st_app_tx_st22p_session) * ctx->tx_st22p_session_cnt); - if (!ctx->tx_st22p_sessions) - return -ENOMEM; + if (!ctx->tx_st22p_sessions) return -ENOMEM; for (i = 0; i < ctx->tx_st22p_session_cnt; i++) { s = &ctx->tx_st22p_sessions[i]; s->idx = i; @@ -327,8 +315,7 @@ int st_app_tx_st22p_sessions_init(struct st_app_context *ctx) { int st_app_tx_st22p_sessions_stop(struct st_app_context *ctx) { struct st_app_tx_st22p_session *s; - if (!ctx->tx_st22p_sessions) - return 0; + if (!ctx->tx_st22p_sessions) return 0; for (int i = 0; i < ctx->tx_st22p_session_cnt; i++) { s = &ctx->tx_st22p_sessions[i]; app_tx_st22p_stop_source(s); @@ -340,8 +327,7 @@ int st_app_tx_st22p_sessions_stop(struct st_app_context *ctx) { int st_app_tx_st22p_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_tx_st22p_session *s; - if (!ctx->tx_st22p_sessions) - return 0; + if (!ctx->tx_st22p_sessions) return 0; for (i = 0; i < ctx->tx_st22p_session_cnt; i++) { s = &ctx->tx_st22p_sessions[i]; app_tx_st22p_uinit(s); diff --git a/app/src/tx_st30p_app.c b/app/src/tx_st30p_app.c index f261bae29..ecec33862 100644 --- a/app/src/tx_st30p_app.c +++ b/app/src/tx_st30p_app.c @@ -5,8 +5,7 @@ #include "tx_st30p_app.h" static void app_tx_st30p_build_frame(struct st_app_tx_st30p_session *s, - struct st30_frame *frame, - size_t frame_size) { + struct st30_frame *frame, size_t frame_size) { uint8_t *src = s->st30p_frame_cursor; mtl_memcpy(frame->addr, src, frame_size); @@ -56,8 +55,8 @@ static int app_tx_st30p_open_source(struct st_app_tx_st30p_session *s) { return -EIO; } if (i.st_size < s->st30p_frame_size) { - err("%s, %s file size small then a frame %d\n", __func__, - s->st30p_source_url, s->st30p_frame_size); + err("%s, %s file size small then a frame %d\n", __func__, s->st30p_source_url, + s->st30p_frame_size); close(fd); return -EIO; } @@ -90,8 +89,7 @@ static int app_tx_st30p_start_source(struct st_app_tx_st30p_session *s) { int ret = -EINVAL; int idx = s->idx; - ret = - pthread_create(&s->st30p_app_thread, NULL, app_tx_st30p_frame_thread, s); + ret = pthread_create(&s->st30p_app_thread, NULL, app_tx_st30p_frame_thread, s); if (ret < 0) { err("%s(%d), thread create fail ret %d\n", __func__, idx, ret); return ret; @@ -109,8 +107,7 @@ static void app_tx_st30p_stop_source(struct st_app_tx_st30p_session *s) { s->st30p_app_thread_stop = true; if (s->st30p_app_thread) { info("%s(%d), wait app thread stop\n", __func__, s->idx); - if (s->handle) - st30p_tx_wake_block(s->handle); + if (s->handle) st30p_tx_wake_block(s->handle); pthread_join(s->st30p_app_thread, NULL); s->st30p_app_thread = 0; } @@ -136,8 +133,7 @@ static int app_tx_st30p_handle_free(struct st_app_tx_st30p_session *s) { if (s->handle) { ret = st30p_tx_free(s->handle); - if (ret < 0) - err("%s(%d), st30p_tx_free fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), st30p_tx_free fail %d\n", __func__, idx, ret); s->handle = NULL; } @@ -151,8 +147,7 @@ static int app_tx_st30p_uinit(struct st_app_tx_st30p_session *s) { return 0; } -static int app_tx_st30p_init(struct st_app_context *ctx, - st_json_st30p_session_t *st30p, +static int app_tx_st30p_init(struct st_app_context *ctx, st_json_st30p_session_t *st30p, struct st_app_tx_st30p_session *s) { int idx = s->idx, ret; struct st30p_tx_ops ops; @@ -171,11 +166,10 @@ static int app_tx_st30p_init(struct st_app_context *ctx, st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_P) : ctx->tx_dip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name - : ctx->para.port[MTL_PORT_P]); - ops.port.udp_port[MTL_SESSION_PORT_P] = - st30p ? st30p->base.udp_port : (10000 + s->idx); + snprintf( + ops.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_P]->name : ctx->para.port[MTL_PORT_P]); + ops.port.udp_port[MTL_SESSION_PORT_P] = st30p ? st30p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_P]) { memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_P][0], ctx->tx_dst_mac[MTL_PORT_P], MTL_MAC_ADDR_LEN); @@ -186,27 +180,25 @@ static int app_tx_st30p_init(struct st_app_context *ctx, st30p ? st_json_ip(ctx, &st30p->base, MTL_SESSION_PORT_R) : ctx->tx_dip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); - snprintf(ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", - st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name - : ctx->para.port[MTL_PORT_R]); + snprintf( + ops.port.port[MTL_SESSION_PORT_R], MTL_PORT_MAX_LEN, "%s", + st30p ? st30p->base.inf[MTL_SESSION_PORT_R]->name : ctx->para.port[MTL_PORT_R]); ops.port.udp_port[MTL_SESSION_PORT_R] = st30p ? st30p->base.udp_port : (10000 + s->idx); if (ctx->has_tx_dst_mac[MTL_PORT_R]) { - memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], - ctx->tx_dst_mac[MTL_PORT_R], MTL_MAC_ADDR_LEN); + memcpy(&ops.tx_dst_mac[MTL_SESSION_PORT_R][0], ctx->tx_dst_mac[MTL_PORT_R], + MTL_MAC_ADDR_LEN); ops.flags |= ST30P_TX_FLAG_USER_R_MAC; } } - ops.port.payload_type = - st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; + ops.port.payload_type = st30p ? st30p->base.payload_type : ST_APP_PAYLOAD_TYPE_AUDIO; ops.fmt = st30p ? st30p->info.audio_format : ST30_FMT_PCM24; ops.channel = st30p ? st30p->info.audio_channel : 2; ops.sampling = st30p ? st30p->info.audio_sampling : ST30_SAMPLING_48K; ops.ptime = st30p ? st30p->info.audio_ptime : ST30_PTIME_1MS; /* set frame size to 10ms time */ int framebuff_size = st30_calculate_framebuff_size( - ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, - &s->expect_fps); + ops.fmt, ops.ptime, ops.sampling, ops.channel, 10 * NS_PER_MS, &s->expect_fps); ops.framebuff_size = framebuff_size; ops.framebuff_cnt = 3; @@ -219,8 +211,7 @@ static int app_tx_st30p_init(struct st_app_context *ctx, s->framebuff_cnt = ops.framebuff_cnt; s->st30p_source_fd = -1; - if (ctx->tx_audio_dedicate_queue) - ops.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; + if (ctx->tx_audio_dedicate_queue) ops.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; if (ctx->force_tx_audio_numa >= 0) { ops.flags |= ST30P_TX_FLAG_FORCE_NUMA; @@ -257,8 +248,7 @@ int st_app_tx_st30p_sessions_init(struct st_app_context *ctx) { struct st_app_tx_st30p_session *s; ctx->tx_st30p_sessions = (struct st_app_tx_st30p_session *)st_app_zmalloc( sizeof(struct st_app_tx_st30p_session) * ctx->tx_st30p_session_cnt); - if (!ctx->tx_st30p_sessions) - return -ENOMEM; + if (!ctx->tx_st30p_sessions) return -ENOMEM; for (i = 0; i < ctx->tx_st30p_session_cnt; i++) { s = &ctx->tx_st30p_sessions[i]; s->idx = i; @@ -275,8 +265,7 @@ int st_app_tx_st30p_sessions_init(struct st_app_context *ctx) { int st_app_tx_st30p_sessions_stop(struct st_app_context *ctx) { struct st_app_tx_st30p_session *s; - if (!ctx->tx_st30p_sessions) - return 0; + if (!ctx->tx_st30p_sessions) return 0; for (int i = 0; i < ctx->tx_st30p_session_cnt; i++) { s = &ctx->tx_st30p_sessions[i]; app_tx_st30p_stop_source(s); @@ -288,8 +277,7 @@ int st_app_tx_st30p_sessions_stop(struct st_app_context *ctx) { int st_app_tx_st30p_sessions_uinit(struct st_app_context *ctx) { int i; struct st_app_tx_st30p_session *s; - if (!ctx->tx_st30p_sessions) - return 0; + if (!ctx->tx_st30p_sessions) return 0; for (i = 0; i < ctx->tx_st30p_session_cnt; i++) { s = &ctx->tx_st30p_sessions[i]; app_tx_st30p_uinit(s); diff --git a/app/tools/convert_app.c b/app/tools/convert_app.c index c4d2dc397..7c12fa47c 100644 --- a/app/tools/convert_app.c +++ b/app/tools/convert_app.c @@ -14,36 +14,36 @@ static enum st_frame_fmt fmt_cvt2frame(enum cvt_frame_fmt fmt) { switch (fmt) { - case CVT_FRAME_FMT_YUV422PLANAR10LE: - return ST_FRAME_FMT_YUV422PLANAR10LE; - case CVT_FRAME_FMT_YUV422PLANAR12LE: - return ST_FRAME_FMT_YUV422PLANAR12LE; - case CVT_FRAME_FMT_V210: - return ST_FRAME_FMT_V210; - case CVT_FRAME_FMT_Y210: - return ST_FRAME_FMT_Y210; - case CVT_FRAME_FMT_YUV444PLANAR10LE: - return ST_FRAME_FMT_YUV444PLANAR10LE; - case CVT_FRAME_FMT_YUV444PLANAR12LE: - return ST_FRAME_FMT_YUV444PLANAR12LE; - case CVT_FRAME_FMT_GBRPLANAR10LE: - return ST_FRAME_FMT_GBRPLANAR10LE; - case CVT_FRAME_FMT_GBRPLANAR12LE: - return ST_FRAME_FMT_GBRPLANAR12LE; - case CVT_FRAME_FMT_YUV422RFC4175PG2BE10: - return ST_FRAME_FMT_YUV422RFC4175PG2BE10; - case CVT_FRAME_FMT_YUV422RFC4175PG2BE12: - return ST_FRAME_FMT_YUV422RFC4175PG2BE12; - case CVT_FRAME_FMT_YUV444RFC4175PG4BE10: - return ST_FRAME_FMT_YUV444RFC4175PG4BE10; - case CVT_FRAME_FMT_YUV444RFC4175PG2BE12: - return ST_FRAME_FMT_YUV444RFC4175PG2BE12; - case CVT_FRAME_FMT_RGBRFC4175PG4BE10: - return ST_FRAME_FMT_RGBRFC4175PG4BE10; - case CVT_FRAME_FMT_RGBRFC4175PG2BE12: - return ST_FRAME_FMT_RGBRFC4175PG2BE12; - default: - break; + case CVT_FRAME_FMT_YUV422PLANAR10LE: + return ST_FRAME_FMT_YUV422PLANAR10LE; + case CVT_FRAME_FMT_YUV422PLANAR12LE: + return ST_FRAME_FMT_YUV422PLANAR12LE; + case CVT_FRAME_FMT_V210: + return ST_FRAME_FMT_V210; + case CVT_FRAME_FMT_Y210: + return ST_FRAME_FMT_Y210; + case CVT_FRAME_FMT_YUV444PLANAR10LE: + return ST_FRAME_FMT_YUV444PLANAR10LE; + case CVT_FRAME_FMT_YUV444PLANAR12LE: + return ST_FRAME_FMT_YUV444PLANAR12LE; + case CVT_FRAME_FMT_GBRPLANAR10LE: + return ST_FRAME_FMT_GBRPLANAR10LE; + case CVT_FRAME_FMT_GBRPLANAR12LE: + return ST_FRAME_FMT_GBRPLANAR12LE; + case CVT_FRAME_FMT_YUV422RFC4175PG2BE10: + return ST_FRAME_FMT_YUV422RFC4175PG2BE10; + case CVT_FRAME_FMT_YUV422RFC4175PG2BE12: + return ST_FRAME_FMT_YUV422RFC4175PG2BE12; + case CVT_FRAME_FMT_YUV444RFC4175PG4BE10: + return ST_FRAME_FMT_YUV444RFC4175PG4BE10; + case CVT_FRAME_FMT_YUV444RFC4175PG2BE12: + return ST_FRAME_FMT_YUV444RFC4175PG2BE12; + case CVT_FRAME_FMT_RGBRFC4175PG4BE10: + return ST_FRAME_FMT_RGBRFC4175PG4BE10; + case CVT_FRAME_FMT_RGBRFC4175PG2BE12: + return ST_FRAME_FMT_RGBRFC4175PG2BE12; + default: + break; } err("%s, unknown fmt %d\n", __func__, fmt); @@ -61,8 +61,7 @@ static int convert(struct conv_app_context *ctx) { void *buf_in = NULL, *buf_out = NULL; int ret = -EIO; - if (!frame_size_in || !frame_size_out) - return -EIO; + if (!frame_size_in || !frame_size_out) return -EIO; fp_in = st_fopen(ctx->file_in, "rb"); if (!fp_in) { @@ -97,8 +96,8 @@ static int convert(struct conv_app_context *ctx) { ret = -EIO; goto out; } - info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s(%d)\n", __func__, - size, frame_num, w, h, ctx->file_in, fmt_in, ctx->file_out, fmt_out); + info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s(%d)\n", __func__, size, + frame_num, w, h, ctx->file_in, fmt_in, ctx->file_out, fmt_out); fseek(fp_in, 0, SEEK_SET); for (int i = 0; i < frame_num; i++) { @@ -137,8 +136,8 @@ static int convert(struct conv_app_context *ctx) { } } else if (fmt_in == CVT_FRAME_FMT_V210) { if (fmt_out == CVT_FRAME_FMT_YUV422RFC4175PG2BE10) { - st20_v210_to_rfc4175_422be10( - buf_in, (struct st20_rfc4175_422_10_pg2_be *)buf_out, w, h); + st20_v210_to_rfc4175_422be10(buf_in, (struct st20_rfc4175_422_10_pg2_be *)buf_out, + w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -146,8 +145,8 @@ static int convert(struct conv_app_context *ctx) { } } else if (fmt_in == CVT_FRAME_FMT_Y210) { if (fmt_out == CVT_FRAME_FMT_YUV422RFC4175PG2BE10) { - st20_y210_to_rfc4175_422be10( - buf_in, (struct st20_rfc4175_422_10_pg2_be *)buf_out, w, h); + st20_y210_to_rfc4175_422be10(buf_in, (struct st20_rfc4175_422_10_pg2_be *)buf_out, + w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -211,14 +210,14 @@ static int convert(struct conv_app_context *ctx) { y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h / 2; - st20_rfc4175_422be10_to_yuv422p10le( - (struct st20_rfc4175_422_10_pg2_be *)buf_in, y, b, r, w, h); + st20_rfc4175_422be10_to_yuv422p10le((struct st20_rfc4175_422_10_pg2_be *)buf_in, + y, b, r, w, h); } else if (fmt_out == CVT_FRAME_FMT_V210) { - st20_rfc4175_422be10_to_v210( - (struct st20_rfc4175_422_10_pg2_be *)buf_in, buf_out, w, h); + st20_rfc4175_422be10_to_v210((struct st20_rfc4175_422_10_pg2_be *)buf_in, buf_out, + w, h); } else if (fmt_out == CVT_FRAME_FMT_Y210) { - st20_rfc4175_422be10_to_y210( - (struct st20_rfc4175_422_10_pg2_be *)buf_in, buf_out, w, h); + st20_rfc4175_422be10_to_y210((struct st20_rfc4175_422_10_pg2_be *)buf_in, buf_out, + w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -230,8 +229,8 @@ static int convert(struct conv_app_context *ctx) { y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h / 2; - st20_rfc4175_422be12_to_yuv422p12le( - (struct st20_rfc4175_422_12_pg2_be *)buf_in, y, b, r, w, h); + st20_rfc4175_422be12_to_yuv422p12le((struct st20_rfc4175_422_12_pg2_be *)buf_in, + y, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -243,8 +242,8 @@ static int convert(struct conv_app_context *ctx) { y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h; - st20_rfc4175_444be10_to_yuv444p10le( - (struct st20_rfc4175_444_10_pg4_be *)buf_in, y, b, r, w, h); + st20_rfc4175_444be10_to_yuv444p10le((struct st20_rfc4175_444_10_pg4_be *)buf_in, + y, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -256,8 +255,8 @@ static int convert(struct conv_app_context *ctx) { y = (uint16_t *)buf_out; b = y + w * h; r = b + w * h; - st20_rfc4175_444be12_to_yuv444p12le( - (struct st20_rfc4175_444_12_pg2_be *)buf_in, y, b, r, w, h); + st20_rfc4175_444be12_to_yuv444p12le((struct st20_rfc4175_444_12_pg2_be *)buf_in, + y, b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -269,8 +268,8 @@ static int convert(struct conv_app_context *ctx) { g = (uint16_t *)buf_out; b = g + w * h; r = b + w * h; - st20_rfc4175_444be10_to_gbrp10le( - (struct st20_rfc4175_444_10_pg4_be *)buf_in, g, b, r, w, h); + st20_rfc4175_444be10_to_gbrp10le((struct st20_rfc4175_444_10_pg4_be *)buf_in, g, + b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -282,8 +281,8 @@ static int convert(struct conv_app_context *ctx) { g = (uint16_t *)buf_out; b = g + w * h; r = b + w * h; - st20_rfc4175_444be12_to_gbrp12le( - (struct st20_rfc4175_444_12_pg2_be *)buf_in, g, b, r, w, h); + st20_rfc4175_444be12_to_gbrp12le((struct st20_rfc4175_444_12_pg2_be *)buf_in, g, + b, r, w, h); } else { err("%s, err fmt in %d out %d\n", __func__, fmt_in, fmt_out); ret = -EIO; @@ -329,8 +328,7 @@ static int frame2field(struct conv_app_context *ctx) { void *buf_in = NULL; int ret = -EIO; - if (!frame_size) - return -EIO; + if (!frame_size) return -EIO; fp_in = st_fopen(ctx->file_in, "rb"); if (!fp_in) { @@ -360,8 +358,8 @@ static int frame2field(struct conv_app_context *ctx) { ret = -EIO; goto out; } - info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s\n", __func__, - size, frame_num, w, h, ctx->file_in, fmt, ctx->file_out); + info("%s, file size:%ld, %d frames(%ux%u), in %s(%d) out %s\n", __func__, size, + frame_num, w, h, ctx->file_in, fmt, ctx->file_out); fseek(fp_in, 0, SEEK_SET); for (int i = 0; i < frame_num; i++) { diff --git a/app/tools/convert_app_args.c b/app/tools/convert_app_args.c index f336f0a90..dd67212da 100644 --- a/app/tools/convert_app_args.c +++ b/app/tools/convert_app_args.c @@ -101,40 +101,39 @@ int conv_app_parse_args(struct conv_app_context *ctx, int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", conv_app_args_options, &optIdx); - if (cmd == -1) - break; + if (cmd == -1) break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case CONV_ARG_FORMAT_IN: - ctx->fmt_in = cvt_parse_fmt(optarg); - break; - case CONV_ARG_FORMAT_OUT: - ctx->fmt_out = cvt_parse_fmt(optarg); - break; - case CONV_ARG_W: - ctx->w = atoi(optarg); - break; - case CONV_ARG_H: - ctx->h = atoi(optarg); - break; - case CONV_ARG_FILE_IN: - snprintf(ctx->file_in, sizeof(ctx->file_in), "%s", optarg); - break; - case CONV_ARG_FILE_OUT: - snprintf(ctx->file_out, sizeof(ctx->file_out), "%s", optarg); - break; - case CONV_ARG_FRAME2FIELD: - ctx->frame2field = true; - break; - case CONV_ARG_HELP: - conv_app_print_app(); - ret = -EIO; - break; - default: - conv_app_print_app(); - ret = -EIO; - break; + case CONV_ARG_FORMAT_IN: + ctx->fmt_in = cvt_parse_fmt(optarg); + break; + case CONV_ARG_FORMAT_OUT: + ctx->fmt_out = cvt_parse_fmt(optarg); + break; + case CONV_ARG_W: + ctx->w = atoi(optarg); + break; + case CONV_ARG_H: + ctx->h = atoi(optarg); + break; + case CONV_ARG_FILE_IN: + snprintf(ctx->file_in, sizeof(ctx->file_in), "%s", optarg); + break; + case CONV_ARG_FILE_OUT: + snprintf(ctx->file_out, sizeof(ctx->file_out), "%s", optarg); + break; + case CONV_ARG_FRAME2FIELD: + ctx->frame2field = true; + break; + case CONV_ARG_HELP: + conv_app_print_app(); + ret = -EIO; + break; + default: + conv_app_print_app(); + ret = -EIO; + break; } }; diff --git a/app/tools/convert_app_base.h b/app/tools/convert_app_base.h index 4bfb085bf..3bf9152b1 100644 --- a/app/tools/convert_app_base.h +++ b/app/tools/convert_app_base.h @@ -70,12 +70,13 @@ struct conv_app_context { static inline void *conv_app_zmalloc(size_t sz) { void *p = malloc(sz); - if (p) - memset(p, 0x0, sz); + if (p) memset(p, 0x0, sz); return p; } -static inline void conv_app_free(void *p) { free(p); } +static inline void conv_app_free(void *p) { + free(p); +} int conv_app_parse_args(struct conv_app_context *ctx, int argc, char **argv); diff --git a/app/tools/lcore_shmem_mgr.c b/app/tools/lcore_shmem_mgr.c index eef571846..f1d4df294 100644 --- a/app/tools/lcore_shmem_mgr.c +++ b/app/tools/lcore_shmem_mgr.c @@ -41,8 +41,7 @@ static void lsm_print_help() { printf("Params:\n"); printf(" --help: Print the help information\n"); printf(" --info: Print lcore shared manager detail info\n"); - printf( - " --clean_pid_auto_check: Clean the dead entries if PID is not active\n"); + printf(" --clean_pid_auto_check: Clean the dead entries if PID is not active\n"); printf(" --clean_lcore : Clean the entry by lcore ID\n"); printf("\n"); @@ -54,41 +53,40 @@ int main(int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", lsm_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; switch (cmd) { - case LSM_ARG_INFO: - mtl_lcore_shm_print(); - break; - case LSM_ARG_CLEAN_PID_AUTO_CHECK: - ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_PID_AUTO_CHECK, NULL, 0); - if (ret > 0) - info("Total %d dead lcores detected and deleted\n", ret); - else if (ret == 0) - info("No dead lcores detected\n"); - else - err("Fail %d to clean shm by auto PID check\n", ret); - break; - case LSM_ARG_CLEAN_LCORE: { - int lcore = atoi(optarg); - if (lcore < 0) { - err("lcore %d is not valid\n", lcore); - return -EIO; + case LSM_ARG_INFO: + mtl_lcore_shm_print(); + break; + case LSM_ARG_CLEAN_PID_AUTO_CHECK: + ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_PID_AUTO_CHECK, NULL, 0); + if (ret > 0) + info("Total %d dead lcores detected and deleted\n", ret); + else if (ret == 0) + info("No dead lcores detected\n"); + else + err("Fail %d to clean shm by auto PID check\n", ret); + break; + case LSM_ARG_CLEAN_LCORE: { + int lcore = atoi(optarg); + if (lcore < 0) { + err("lcore %d is not valid\n", lcore); + return -EIO; + } + struct mtl_lcore_clean_pid_info pid; + pid.lcore = lcore; + ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_LCORE, &pid, sizeof(pid)); + if (ret >= 0) + info("Succ to delete lcore %d\n", lcore); + else + err("Fail %d to delete lcore %d\n", ret, lcore); + break; } - struct mtl_lcore_clean_pid_info pid; - pid.lcore = lcore; - ret = mtl_lcore_shm_clean(MTL_LCORE_CLEAN_LCORE, &pid, sizeof(pid)); - if (ret >= 0) - info("Succ to delete lcore %d\n", lcore); - else - err("Fail %d to delete lcore %d\n", ret, lcore); - break; - } - case LSM_ARG_HELP: - default: - lsm_print_help(); - return -1; + case LSM_ARG_HELP: + default: + lsm_print_help(); + return -1; } } diff --git a/app/tools/log.h b/app/tools/log.h index 9bbe496ee..a7f28cd6e 100644 --- a/app/tools/log.h +++ b/app/tools/log.h @@ -10,22 +10,22 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif diff --git a/app/udp/udp_client_sample.c b/app/udp/udp_client_sample.c index c154b5388..a15066f91 100644 --- a/app/udp/udp_client_sample.c +++ b/app/udp/udp_client_sample.c @@ -49,13 +49,12 @@ static void *udp_client_thread(void *arg) { int idx_pos = udp_len / 2; int send_idx = 0; - info("%s(%d), start socket %p udp len %d\n", __func__, s->idx, socket, - (int)udp_len); + info("%s(%d), start socket %p udp len %d\n", __func__, s->idx, socket, (int)udp_len); while (!s->stop) { send_buf[idx_pos] = send_idx++; - ssize_t send = mudp_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr *)&s->serv_addr, - sizeof(s->serv_addr)); + ssize_t send = + mudp_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -63,8 +62,7 @@ static void *udp_client_thread(void *arg) { s->send_cnt++; s->send_cnt_total++; - ssize_t recv = - mudp_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); + ssize_t recv = mudp_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); if (recv != udp_len) { dbg("%s(%d), only recv %d bytes\n", __func__, s->idx, (int)recv); s->recv_fail_cnt++; @@ -74,8 +72,8 @@ static void *udp_client_thread(void *arg) { char expect_rx_idx = last_rx_idx + 1; last_rx_idx = recv_buf[idx_pos]; if (last_rx_idx != expect_rx_idx) { - err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, - expect_rx_idx, last_rx_idx); + err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, expect_rx_idx, + last_rx_idx); s->recv_err_cnt++; continue; } @@ -98,12 +96,11 @@ static void *udp_client_transport_thread(void *arg) { send_buf[i] = i; } - info("%s(%d), start socket %p, udp len %d\n", __func__, s->idx, socket, - (int)udp_len); + info("%s(%d), start socket %p, udp len %d\n", __func__, s->idx, socket, (int)udp_len); while (!s->stop) { - ssize_t send = mudp_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr *)&s->serv_addr, - sizeof(s->serv_addr)); + ssize_t send = + mudp_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -123,8 +120,8 @@ static void udp_client_status(struct udp_client_sample_ctx *s) { double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, - s->send_cnt, bps_g, s->recv_cnt); + info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, s->send_cnt, bps_g, + s->recv_cnt); s->send_cnt = 0; s->recv_cnt = 0; if (s->recv_fail_cnt) { @@ -143,8 +140,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, true, true); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -175,8 +171,7 @@ int main(int argc, char **argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], - ctx.udp_port + i); + mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], ctx.udp_port + i); app[i]->socket = mudp_socket(ctx.st, AF_INET, SOCK_DGRAM, 0); if (!app[i]->socket) { @@ -184,16 +179,14 @@ int main(int argc, char **argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) - mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mudp_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, - sizeof(tv)); + ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -202,8 +195,7 @@ int main(int argc, char **argv) { if ((ctx.udp_mode == SAMPLE_UDP_TRANSPORT) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL)) - ret = pthread_create(&app[i]->thread, NULL, udp_client_transport_thread, - app[i]); + ret = pthread_create(&app[i]->thread, NULL, udp_client_transport_thread, app[i]); else ret = pthread_create(&app[i]->thread, NULL, udp_client_thread, app[i]); if (ret < 0) { @@ -242,18 +234,15 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; + if (!app[i]) continue; // stop app thread app[i]->stop = true; st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) - pthread_join(app[i]->thread, NULL); + if (app[i]->thread) pthread_join(app[i]->thread, NULL); - if (app[i]->socket) - mudp_close(app[i]->socket); + if (app[i]->socket) mudp_close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/udp/udp_server_sample.c b/app/udp/udp_server_sample.c index c7d9acedb..f5c05a44e 100644 --- a/app/udp/udp_server_sample.c +++ b/app/udp/udp_server_sample.c @@ -63,8 +63,8 @@ static void *udp_server_thread(void *arg) { s->recv_cnt_total++; s->recv_len += recv; dbg("%s(%d), recv %d bytes\n", __func__, s->idx, (int)recv); - ssize_t send = mudp_sendto( - socket, buf, recv, 0, (const struct sockaddr *)&cli_addr, cli_addr_len); + ssize_t send = mudp_sendto(socket, buf, recv, 0, (const struct sockaddr *)&cli_addr, + cli_addr_len); if (send != recv) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -113,8 +113,7 @@ static void *udp_server_transport_poll_thread(void *arg) { info("%s(%d), start socket %p\n", __func__, s->idx, socket); while (!s->stop) { int ret = mudp_poll(fds, 1, 100); - if (ret <= 0) - continue; + if (ret <= 0) continue; ssize_t recv = mudp_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); if (recv < 0) { err("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); @@ -148,11 +147,9 @@ static void *udp_servers_poll_thread(void *arg) { info("%s, start at %p\n", __func__, ctxs); while (!ctxs->stop) { int ret = mudp_poll(fds, apps_cnt, 100); - if (ret <= 0) - continue; + if (ret <= 0) continue; for (int i = 0; i < apps_cnt; i++) { - if (!fds[i].revents) - continue; /* pkt not ready */ + if (!fds[i].revents) continue; /* pkt not ready */ s = ctxs->apps[i]; socket = s->socket; ssize_t recv = mudp_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); @@ -177,8 +174,8 @@ static void udp_server_status(struct udp_server_sample_ctx *s) { double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, - s->send_cnt, s->recv_cnt, bps_g); + info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, s->send_cnt, + s->recv_cnt, bps_g); s->send_cnt = 0; s->recv_cnt = 0; s->recv_len = 0; @@ -191,8 +188,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, true, true); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx.st = mtl_init(&ctx.param); if (!ctx.st) { @@ -239,8 +235,7 @@ int main(int argc, char **argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) - mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) mudp_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mudp_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); mudp_init_sockaddr(&app[i]->client_addr, ctx.rx_ip_addr[MTL_PORT_P], @@ -265,8 +260,7 @@ int main(int argc, char **argv) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, - sizeof(tv)); + ret = mudp_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -278,10 +272,9 @@ int main(int argc, char **argv) { /* multicast addr */ mreq.imr_multiaddr.s_addr = app[i]->client_addr.sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - ret = mudp_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, - &mreq, sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + ret = mudp_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, + sizeof(mreq)); if (ret < 0) { err("%s(%d), join multicast fail %d\n", __func__, i, ret); goto error; @@ -290,16 +283,14 @@ int main(int argc, char **argv) { } if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT) { - ret = pthread_create(&app[i]->thread, NULL, udp_server_transport_thread, - app[i]); + ret = pthread_create(&app[i]->thread, NULL, udp_server_transport_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) { - ret = pthread_create(&app[i]->thread, NULL, - udp_server_transport_poll_thread, app[i]); + ret = + pthread_create(&app[i]->thread, NULL, udp_server_transport_poll_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL) { ctxs.apps[i] = app[i]; if ((i + 1) == session_num) { - ret = - pthread_create(&ctxs.thread, NULL, udp_servers_poll_thread, &ctxs); + ret = pthread_create(&ctxs.thread, NULL, udp_servers_poll_thread, &ctxs); } } else { ret = pthread_create(&app[i]->thread, NULL, udp_server_thread, app[i]); @@ -345,21 +336,18 @@ int main(int argc, char **argv) { st_pthread_mutex_lock(&ctxs.wake_mutex); st_pthread_cond_signal(&ctxs.wake_cond); st_pthread_mutex_unlock(&ctxs.wake_mutex); - if (ctxs.thread) - pthread_join(ctxs.thread, NULL); + if (ctxs.thread) pthread_join(ctxs.thread, NULL); } for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; + if (!app[i]) continue; // stop app thread app[i]->stop = true; dbg("%s(%d), stop thread\n", __func__, i); st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) - pthread_join(app[i]->thread, NULL); + if (app[i]->thread) pthread_join(app[i]->thread, NULL); if (app[i]->socket) { bool mcast = mudp_is_multicast(&app[i]->client_addr); @@ -380,8 +368,7 @@ int main(int argc, char **argv) { st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); } - if (ctxs.apps) - free(ctxs.apps); + if (ctxs.apps) free(ctxs.apps); st_pthread_mutex_destroy(&ctxs.wake_mutex); st_pthread_cond_destroy(&ctxs.wake_cond); /* release sample(st) dev */ diff --git a/app/udp/ufd_client_sample.c b/app/udp/ufd_client_sample.c index 2159a8d2a..274b50e33 100644 --- a/app/udp/ufd_client_sample.c +++ b/app/udp/ufd_client_sample.c @@ -48,13 +48,12 @@ static void *ufd_client_thread(void *arg) { int idx_pos = ufd_len / 2; int send_idx = 0; - info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, - (int)ufd_len); + info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, (int)ufd_len); while (!s->stop) { send_buf[idx_pos] = send_idx++; - ssize_t send = mufd_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr *)&s->serv_addr, - sizeof(s->serv_addr)); + ssize_t send = + mufd_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != ufd_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -62,8 +61,7 @@ static void *ufd_client_thread(void *arg) { s->send_cnt++; s->send_cnt_total++; - ssize_t recv = - mufd_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); + ssize_t recv = mufd_recvfrom(socket, recv_buf, sizeof(recv_buf), 0, NULL, NULL); if (recv != ufd_len) { dbg("%s(%d), only recv %d bytes\n", __func__, s->idx, (int)recv); s->recv_fail_cnt++; @@ -73,8 +71,8 @@ static void *ufd_client_thread(void *arg) { char expect_rx_idx = last_rx_idx + 1; last_rx_idx = recv_buf[idx_pos]; if (last_rx_idx != expect_rx_idx) { - err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, - expect_rx_idx, last_rx_idx); + err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, expect_rx_idx, + last_rx_idx); s->recv_err_cnt++; continue; } @@ -97,12 +95,11 @@ static void *ufd_client_transport_thread(void *arg) { send_buf[i] = i; } - info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, - (int)ufd_len); + info("%s(%d), start socket %d ufd len %d\n", __func__, s->idx, socket, (int)ufd_len); while (!s->stop) { - ssize_t send = mufd_sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr *)&s->serv_addr, - sizeof(s->serv_addr)); + ssize_t send = + mufd_sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != ufd_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -122,8 +119,8 @@ static void ufd_client_status(struct ufd_client_sample_ctx *s) { double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, - s->send_cnt, bps_g, s->recv_cnt); + info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, s->send_cnt, bps_g, + s->recv_cnt); s->send_cnt = 0; s->recv_cnt = 0; if (s->recv_fail_cnt) { @@ -138,9 +135,9 @@ static void ufd_client_status(struct ufd_client_sample_ctx *s) { static void ufd_client_sig_handler(int signo) { switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - mufd_abort(); - break; + case SIGINT: /* Interrupt from keyboard */ + mufd_abort(); + break; } return; @@ -152,8 +149,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, false, true); - if (ret < 0) - return ret; + if (ret < 0) return ret; ufd_override_check(&ctx); @@ -181,8 +177,7 @@ int main(int argc, char **argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - mufd_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], - ctx.udp_port + i); + mufd_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], ctx.udp_port + i); app[i]->socket = mufd_socket(AF_INET, SOCK_DGRAM, 0); if (app[i]->socket < 0) { @@ -190,16 +185,14 @@ int main(int argc, char **argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) - mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mufd_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, - sizeof(tv)); + ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -208,8 +201,7 @@ int main(int argc, char **argv) { if ((ctx.udp_mode == SAMPLE_UDP_TRANSPORT) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL)) - ret = pthread_create(&app[i]->thread, NULL, ufd_client_transport_thread, - app[i]); + ret = pthread_create(&app[i]->thread, NULL, ufd_client_transport_thread, app[i]); else ret = pthread_create(&app[i]->thread, NULL, ufd_client_thread, app[i]); if (ret < 0) { @@ -248,18 +240,15 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; + if (!app[i]) continue; // stop app thread app[i]->stop = true; st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) - pthread_join(app[i]->thread, NULL); + if (app[i]->thread) pthread_join(app[i]->thread, NULL); - if (app[i]->socket >= 0) - mufd_close(app[i]->socket); + if (app[i]->socket >= 0) mufd_close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/udp/ufd_server_sample.c b/app/udp/ufd_server_sample.c index eedf913a8..263cc4d6a 100644 --- a/app/udp/ufd_server_sample.c +++ b/app/udp/ufd_server_sample.c @@ -66,11 +66,10 @@ static void *ufd_server_thread(void *arg) { #ifdef DEBUG uint8_t *ip = (uint8_t *)&cli_addr.sin_addr.s_addr; #endif - dbg("%s(%d), ip %u.%u.%u.%u\n", __func__, s->idx, ip[0], ip[1], ip[2], - ip[3]); + dbg("%s(%d), ip %u.%u.%u.%u\n", __func__, s->idx, ip[0], ip[1], ip[2], ip[3]); - ssize_t send = mufd_sendto( - socket, buf, recv, 0, (const struct sockaddr *)&cli_addr, cli_addr_len); + ssize_t send = mufd_sendto(socket, buf, recv, 0, (const struct sockaddr *)&cli_addr, + cli_addr_len); if (send != recv) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -119,8 +118,7 @@ static void *ufd_server_transport_poll_thread(void *arg) { info("%s(%d), start socket %d\n", __func__, s->idx, socket); while (!s->stop) { int ret = mufd_poll(fds, 1, 100); - if (ret <= 0) - continue; + if (ret <= 0) continue; ssize_t recv = mufd_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); if (recv < 0) { err("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); @@ -154,11 +152,9 @@ static void *ufd_servers_poll_thread(void *arg) { info("%s, start at %p\n", __func__, ctxs); while (!ctxs->stop) { int ret = mufd_poll(fds, apps_cnt, 100); - if (ret <= 0) - continue; + if (ret <= 0) continue; for (int i = 0; i < apps_cnt; i++) { - if (!fds[i].revents) - continue; /* pkt not ready */ + if (!fds[i].revents) continue; /* pkt not ready */ s = ctxs->apps[i]; socket = s->socket; ssize_t recv = mufd_recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); @@ -183,8 +179,8 @@ static void ufd_server_status(struct ufd_server_sample_ctx *s) { double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, - s->send_cnt, s->recv_cnt, bps_g); + info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, s->send_cnt, + s->recv_cnt, bps_g); s->send_cnt = 0; s->recv_cnt = 0; s->recv_len = 0; @@ -192,9 +188,9 @@ static void ufd_server_status(struct ufd_server_sample_ctx *s) { static void ufd_server_sig_handler(int signo) { switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - mufd_abort(); - break; + case SIGINT: /* Interrupt from keyboard */ + mufd_abort(); + break; } return; @@ -207,8 +203,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, false, true, true); - if (ret < 0) - return ret; + if (ret < 0) return ret; ufd_override_check(&ctx); @@ -252,8 +247,7 @@ int main(int argc, char **argv) { ret = -EIO; goto error; } - if (ctx.udp_tx_bps) - mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); + if (ctx.udp_tx_bps) mufd_set_tx_rate(app[i]->socket, ctx.udp_tx_bps); if (ctx.has_tx_dst_mac[MTL_PORT_P]) mufd_set_tx_mac(app[i]->socket, ctx.tx_dst_mac[MTL_PORT_P]); mufd_init_sockaddr(&app[i]->client_addr, ctx.rx_ip_addr[MTL_PORT_P], @@ -277,8 +271,7 @@ int main(int argc, char **argv) { struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; - ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, - sizeof(tv)); + ret = mufd_setsockopt(app[i]->socket, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); if (ret < 0) { err("%s(%d), SO_RCVTIMEO fail %d\n", __func__, i, ret); goto error; @@ -290,10 +283,9 @@ int main(int argc, char **argv) { /* multicast addr */ mreq.imr_multiaddr.s_addr = app[i]->client_addr.sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - ret = mufd_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, - &mreq, sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + ret = mufd_setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, + sizeof(mreq)); if (ret < 0) { err("%s(%d), join multicast fail %d\n", __func__, i, ret); goto error; @@ -302,16 +294,14 @@ int main(int argc, char **argv) { } if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT) { - ret = pthread_create(&app[i]->thread, NULL, ufd_server_transport_thread, - app[i]); + ret = pthread_create(&app[i]->thread, NULL, ufd_server_transport_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) { - ret = pthread_create(&app[i]->thread, NULL, - ufd_server_transport_poll_thread, app[i]); + ret = + pthread_create(&app[i]->thread, NULL, ufd_server_transport_poll_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL) { ctxs.apps[i] = app[i]; if ((i + 1) == session_num) { - ret = - pthread_create(&ctxs.thread, NULL, ufd_servers_poll_thread, &ctxs); + ret = pthread_create(&ctxs.thread, NULL, ufd_servers_poll_thread, &ctxs); } } else { ret = pthread_create(&app[i]->thread, NULL, ufd_server_thread, app[i]); @@ -357,21 +347,18 @@ int main(int argc, char **argv) { st_pthread_mutex_lock(&ctxs.wake_mutex); st_pthread_cond_signal(&ctxs.wake_cond); st_pthread_mutex_unlock(&ctxs.wake_mutex); - if (ctxs.thread) - pthread_join(ctxs.thread, NULL); + if (ctxs.thread) pthread_join(ctxs.thread, NULL); } for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; + if (!app[i]) continue; // stop app thread app[i]->stop = true; dbg("%s(%d), stop thread\n", __func__, i); st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) - pthread_join(app[i]->thread, NULL); + if (app[i]->thread) pthread_join(app[i]->thread, NULL); if (app[i]->socket >= 0) { bool mcast = mudp_is_multicast(&app[i]->client_addr); @@ -392,8 +379,7 @@ int main(int argc, char **argv) { st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); } - if (ctxs.apps) - free(ctxs.apps); + if (ctxs.apps) free(ctxs.apps); st_pthread_mutex_destroy(&ctxs.wake_mutex); st_pthread_cond_destroy(&ctxs.wake_cond); diff --git a/app/udp/usocket_client_sample.c b/app/udp/usocket_client_sample.c index 368ec3ea1..9b2e89550 100644 --- a/app/udp/usocket_client_sample.c +++ b/app/udp/usocket_client_sample.c @@ -49,9 +49,8 @@ static void *usocket_client_thread(void *arg) { (int)udp_len); while (!s->stop) { send_buf[idx_pos] = send_idx++; - ssize_t send = - sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -69,8 +68,8 @@ static void *usocket_client_thread(void *arg) { char expect_rx_idx = last_rx_idx + 1; last_rx_idx = recv_buf[idx_pos]; if (last_rx_idx != expect_rx_idx) { - err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, - expect_rx_idx, last_rx_idx); + err("%s(%d), idx mismatch, expect %u get %u\n", __func__, s->idx, expect_rx_idx, + last_rx_idx); s->recv_err_cnt++; continue; } @@ -96,9 +95,8 @@ static void *usocket_client_transport_thread(void *arg) { info("%s(%d), start socket %d, usocket len %d\n", __func__, s->idx, socket, (int)udp_len); while (!s->stop) { - ssize_t send = - sendto(socket, send_buf, sizeof(send_buf), 0, - (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); + ssize_t send = sendto(socket, send_buf, sizeof(send_buf), 0, + (const struct sockaddr *)&s->serv_addr, sizeof(s->serv_addr)); if (send != udp_len) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -118,8 +116,8 @@ static void usocket_client_status(struct usocket_client_sample_ctx *s) { double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, - s->send_cnt, bps_g, s->recv_cnt); + info("%s(%d), send %d pkts(%fg/s) recv %d pkts\n", __func__, s->idx, s->send_cnt, bps_g, + s->recv_cnt); s->send_cnt = 0; s->recv_cnt = 0; if (s->recv_fail_cnt) { @@ -138,8 +136,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, true, false, true); - if (ret < 0) - return ret; + if (ret < 0) return ret; uint32_t session_num = ctx.sessions; struct usocket_client_sample_ctx *app[session_num]; @@ -163,8 +160,7 @@ int main(int argc, char **argv) { st_pthread_mutex_init(&app[i]->wake_mutex, NULL); st_pthread_cond_init(&app[i]->wake_cond, NULL); - mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], - ctx.udp_port + i); + mudp_init_sockaddr(&app[i]->serv_addr, ctx.tx_dip_addr[MTL_PORT_P], ctx.udp_port + i); app[i]->socket = socket(AF_INET, SOCK_DGRAM, 0); if (app[i]->socket < 0) { @@ -185,11 +181,10 @@ int main(int argc, char **argv) { if ((ctx.udp_mode == SAMPLE_UDP_TRANSPORT) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) || (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL)) - ret = pthread_create(&app[i]->thread, NULL, - usocket_client_transport_thread, app[i]); - else ret = - pthread_create(&app[i]->thread, NULL, usocket_client_thread, app[i]); + pthread_create(&app[i]->thread, NULL, usocket_client_transport_thread, app[i]); + else + ret = pthread_create(&app[i]->thread, NULL, usocket_client_thread, app[i]); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, ret, i); goto error; @@ -226,18 +221,15 @@ int main(int argc, char **argv) { error: for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; + if (!app[i]) continue; // stop app thread app[i]->stop = true; st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) - pthread_join(app[i]->thread, NULL); + if (app[i]->thread) pthread_join(app[i]->thread, NULL); - if (app[i]->socket) - close(app[i]->socket); + if (app[i]->socket) close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); diff --git a/app/udp/usocket_server_sample.c b/app/udp/usocket_server_sample.c index 2f5cf9e8a..9b2f300d7 100644 --- a/app/udp/usocket_server_sample.c +++ b/app/udp/usocket_server_sample.c @@ -49,8 +49,8 @@ static void *usocket_server_thread(void *arg) { info("%s(%d), start socket %d\n", __func__, s->idx, socket); while (!s->stop) { - ssize_t recv = recvfrom(socket, buf, sizeof(buf), 0, - (struct sockaddr *)&cli_addr, &cli_addr_len); + ssize_t recv = recvfrom(socket, buf, sizeof(buf), 0, (struct sockaddr *)&cli_addr, + &cli_addr_len); if (recv < 0) { dbg("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); continue; @@ -59,8 +59,8 @@ static void *usocket_server_thread(void *arg) { s->recv_cnt_total++; s->recv_len += recv; dbg("%s(%d), recv %d bytes\n", __func__, s->idx, (int)recv); - ssize_t send = sendto(socket, buf, recv, 0, - (const struct sockaddr *)&cli_addr, cli_addr_len); + ssize_t send = + sendto(socket, buf, recv, 0, (const struct sockaddr *)&cli_addr, cli_addr_len); if (send != recv) { err("%s(%d), only send %d bytes\n", __func__, s->idx, (int)send); continue; @@ -109,8 +109,7 @@ static void *usocket_server_transport_poll_thread(void *arg) { info("%s(%d), start socket %d\n", __func__, s->idx, socket); while (!s->stop) { int ret = poll(fds, 1, 100); - if (ret <= 0) - continue; + if (ret <= 0) continue; ssize_t recv = recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); if (recv < 0) { err("%s(%d), recv fail %d\n", __func__, s->idx, (int)recv); @@ -143,11 +142,9 @@ static void *usocket_servers_poll_thread(void *arg) { info("%s, start at %p\n", __func__, ctxs); while (!ctxs->stop) { int ret = poll(fds, apps_cnt, 100); - if (ret <= 0) - continue; + if (ret <= 0) continue; for (int i = 0; i < apps_cnt; i++) { - if (!fds[i].revents) - continue; /* pkt not ready */ + if (!fds[i].revents) continue; /* pkt not ready */ s = ctxs->apps[i]; socket = s->socket; ssize_t recv = recvfrom(socket, buf, sizeof(buf), 0, NULL, NULL); @@ -172,8 +169,8 @@ static void usocket_server_status(struct usocket_server_sample_ctx *s) { double bps_g = bps / (1000 * 1000 * 1000); s->last_stat_time = cur_ts; - info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, - s->send_cnt, s->recv_cnt, bps_g); + info("%s(%d), send %d pkts recv %d pkts(%fg/s)\n", __func__, s->idx, s->send_cnt, + s->recv_cnt, bps_g); s->send_cnt = 0; s->recv_cnt = 0; s->recv_len = 0; @@ -186,8 +183,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = sample_parse_args(&ctx, argc, argv, false, true, true); - if (ret < 0) - return ret; + if (ret < 0) return ret; uint32_t session_num = ctx.sessions; struct usocket_server_sample_ctx *app[session_num]; @@ -258,10 +254,9 @@ int main(int argc, char **argv) { /* multicast addr */ mreq.imr_multiaddr.s_addr = app[i]->client_addr.sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - ret = setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, - sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx.param.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + ret = + setsockopt(app[i]->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); if (ret < 0) { err("%s(%d), join multicast fail %d\n", __func__, i, ret); goto error; @@ -270,20 +265,18 @@ int main(int argc, char **argv) { } if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT) { - ret = pthread_create(&app[i]->thread, NULL, - usocket_server_transport_thread, app[i]); + ret = + pthread_create(&app[i]->thread, NULL, usocket_server_transport_thread, app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_POLL) { - ret = pthread_create(&app[i]->thread, NULL, - usocket_server_transport_poll_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, usocket_server_transport_poll_thread, + app[i]); } else if (ctx.udp_mode == SAMPLE_UDP_TRANSPORT_UNIFY_POLL) { ctxs.apps[i] = app[i]; if ((i + 1) == session_num) { - ret = pthread_create(&ctxs.thread, NULL, usocket_servers_poll_thread, - &ctxs); + ret = pthread_create(&ctxs.thread, NULL, usocket_servers_poll_thread, &ctxs); } } else { - ret = - pthread_create(&app[i]->thread, NULL, usocket_server_thread, app[i]); + ret = pthread_create(&app[i]->thread, NULL, usocket_server_thread, app[i]); } if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); @@ -326,30 +319,25 @@ int main(int argc, char **argv) { st_pthread_mutex_lock(&ctxs.wake_mutex); st_pthread_cond_signal(&ctxs.wake_cond); st_pthread_mutex_unlock(&ctxs.wake_mutex); - if (ctxs.thread) - pthread_join(ctxs.thread, NULL); + if (ctxs.thread) pthread_join(ctxs.thread, NULL); } for (int i = 0; i < session_num; i++) { - if (!app[i]) - continue; + if (!app[i]) continue; // stop app thread app[i]->stop = true; dbg("%s(%d), stop thread\n", __func__, i); st_pthread_mutex_lock(&app[i]->wake_mutex); st_pthread_cond_signal(&app[i]->wake_cond); st_pthread_mutex_unlock(&app[i]->wake_mutex); - if (app[i]->thread) - pthread_join(app[i]->thread, NULL); + if (app[i]->thread) pthread_join(app[i]->thread, NULL); - if (app[i]->socket > 0) - close(app[i]->socket); + if (app[i]->socket > 0) close(app[i]->socket); st_pthread_mutex_destroy(&app[i]->wake_mutex); st_pthread_cond_destroy(&app[i]->wake_cond); free(app[i]); } - if (ctxs.apps) - free(ctxs.apps); + if (ctxs.apps) free(ctxs.apps); st_pthread_mutex_destroy(&ctxs.wake_mutex); st_pthread_cond_destroy(&ctxs.wake_cond); /* release sample(st) dev */ diff --git a/app/v4l2_to_ip/v4l2_to_ip.c b/app/v4l2_to_ip/v4l2_to_ip.c index 3c9de5623..4847e4a06 100644 --- a/app/v4l2_to_ip/v4l2_to_ip.c +++ b/app/v4l2_to_ip/v4l2_to_ip.c @@ -59,8 +59,7 @@ #ifndef VIDIOC_IPU_GET_DRIVER_VERSION #define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */ -#define VIDIOC_IPU_GET_DRIVER_VERSION \ - _IOWR('v', BASE_VIDIOC_PRIVATE + 3, uint32_t) +#define VIDIOC_IPU_GET_DRIVER_VERSION _IOWR('v', BASE_VIDIOC_PRIVATE + 3, uint32_t) #endif #define V4L2_FMT_WIDTH (1920) @@ -230,8 +229,7 @@ static struct st_v4l2_tx_context *g_st_v4l2_tx = NULL; /*function dec*/ -int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, - const cpu_set_t *cpuset); +int pthread_setaffinity_np(pthread_t thread, size_t cpusetsize, const cpu_set_t *cpuset); /*code*/ @@ -240,27 +238,22 @@ static int video_set_realtime(pthread_t thread, int priority, int cpu) { struct sched_param sp; int err, policy; - if (priority < 0) - return -1; + if (priority < 0) return -1; err = pthread_getschedparam(thread, &policy, &sp); - if (err) - return -1; + if (err) return -1; sp.sched_priority = priority; err = pthread_setschedparam(thread, SCHED_FIFO, &sp); - if (err) - return -1; + if (err) return -1; - if (cpu < 0) - return -1; + if (cpu < 0) return -1; CPU_ZERO(&cpuset); CPU_SET(cpu, &cpuset); err = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset); - if (err) - return -1; + if (err) return -1; return 0; } @@ -314,9 +307,9 @@ static int create_display_context(struct st_display *d) { char title[32]; sprintf(title, "v4l2-display-%d", d->idx); - d->window = SDL_CreateWindow( - title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, d->window_w, - d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + d->window = + SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + d->window_w, d->window_h, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (d->window == NULL) { printf("%s, create window fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -330,8 +323,8 @@ static int create_display_context(struct st_display *d) { return -EIO; } - d->texture = SDL_CreateTexture( - d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, d->pixel_w, d->pixel_h); + d->texture = SDL_CreateTexture(d->renderer, d->fmt, SDL_TEXTUREACCESS_STREAMING, + d->pixel_w, d->pixel_h); if (d->texture == NULL) { printf("%s, create texture fail: %s\n", __func__, SDL_GetError()); destroy_display_context(d); @@ -383,8 +376,7 @@ static void *display_thread_func(void *arg) { sprintf(text, "FPS:\t%.2f", d->fps); SDL_Color Red = {255, 0, 0}; SDL_Surface *surfaceMessage = TTF_RenderText_Solid(d->font, text, Red); - SDL_Texture *Message = - SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); + SDL_Texture *Message = SDL_CreateTextureFromSurface(d->renderer, surfaceMessage); SDL_RenderCopy(d->renderer, Message, NULL, &d->msg_rect); SDL_FreeSurface(surfaceMessage); @@ -395,8 +387,7 @@ static void *display_thread_func(void *arg) { SDL_RenderPresent(d->renderer); #ifdef WINDOWSENV while (SDL_PollEvent(&event)) { - if (event.type == SDL_QUIT) - d->display_thread_stop = true; + if (event.type == SDL_QUIT) d->display_thread_stop = true; } #endif } @@ -404,21 +395,18 @@ static void *display_thread_func(void *arg) { return NULL; } -static int -display_thread_create(struct st_v4l2_tx_video_session *tx_video_session, - unsigned int priority, unsigned int cpu) { +static int display_thread_create(struct st_v4l2_tx_video_session *tx_video_session, + unsigned int priority, unsigned int cpu) { int ret = 0; if (pthread_create(&(tx_video_session->display.display_thread), NULL, display_thread_func, &(tx_video_session->display))) { - printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), - errno); + printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), errno); ret = -EIO; return ret; } - if (video_set_realtime(tx_video_session->display.display_thread, priority, - cpu) < 0) { + if (video_set_realtime(tx_video_session->display.display_thread, priority, cpu) < 0) { printf("%s video_set_realtime Failed\n", __func__); ret = -EIO; return ret; @@ -427,9 +415,8 @@ display_thread_create(struct st_v4l2_tx_video_session *tx_video_session, return ret; } -static void -display_consume_frame(struct st_v4l2_tx_video_session *tx_video_session, - void *frame) { +static void display_consume_frame(struct st_v4l2_tx_video_session *tx_video_session, + void *frame) { struct st_display *display = &(tx_video_session->display); if (display->front_frame) { @@ -445,8 +432,7 @@ display_consume_frame(struct st_v4l2_tx_video_session *tx_video_session, } static int app_uinit_display(struct st_display *d) { - if (!d) - return 0; + if (!d) return 0; int idx = d->idx; d->display_thread_stop = true; @@ -479,11 +465,10 @@ static int app_uinit_display(struct st_display *d) { return 0; } -static int app_init_display(struct st_display *d, int idx, int width, - int height, char *font) { +static int app_init_display(struct st_display *d, int idx, int width, int height, + char *font) { int ret; - if (!d) - return -ENOMEM; + if (!d) return -ENOMEM; MTL_MAY_UNUSED(font); d->idx = idx; @@ -495,8 +480,7 @@ static int app_init_display(struct st_display *d, int idx, int width, #ifdef APP_HAS_SDL2_TTF d->font = TTF_OpenFont(font, 40); if (!d->font) - printf("%s, open font fail, won't show info: %s\n", __func__, - TTF_GetError()); + printf("%s, open font fail, won't show info: %s\n", __func__, TTF_GetError()); #endif if (d->fmt == SDL_PIXELFORMAT_UYVY) { d->front_frame_size = width * height * 2; @@ -634,13 +618,11 @@ static struct v4l2_format_info { // { "Y210", V4L2_PIX_FMT_Y210, 1 }, }; -static const struct v4l2_format_info * -v4l2_format_by_fourcc(unsigned int fourcc) { +static const struct v4l2_format_info *v4l2_format_by_fourcc(unsigned int fourcc) { unsigned int i; for (i = 0; i < ARRAY_SIZE(pixel_formats); ++i) { - if (pixel_formats[i].fourcc == fourcc) - return &pixel_formats[i]; + if (pixel_formats[i].fourcc == fourcc) return &pixel_formats[i]; } return NULL; @@ -652,8 +634,7 @@ static const char *v4l2_format_name(unsigned int fourcc) { unsigned int i; info = v4l2_format_by_fourcc(fourcc); - if (info) - return info->name; + if (info) return info->name; for (i = 0; i < 4; ++i) { name[i] = fourcc & 0xff; @@ -684,8 +665,7 @@ static const char *v4l2_field_name(enum v4l2_field field) { unsigned int i; for (i = 0; i < ARRAY_SIZE(fields); ++i) { - if (fields[i].field == field) - return fields[i].name; + if (fields[i].field == field) return fields[i].name; } return "unknown"; @@ -703,7 +683,9 @@ static void video_init(struct device *dev) { dev->type = (enum v4l2_buf_type) - 1; } -static bool video_has_fd(struct device *dev) { return dev->fd != -1; } +static bool video_has_fd(struct device *dev) { + return dev->fd != -1; +} static int video_open(struct device *dev, const char *devname) { if (video_has_fd(dev)) { @@ -713,8 +695,7 @@ static int video_open(struct device *dev, const char *devname) { dev->fd = open(devname, O_RDWR); if (dev->fd < 0) { - printf("Error opening device %s: %s (%d).\n", devname, strerror(errno), - errno); + printf("Error opening device %s: %s (%d).\n", devname, strerror(errno), errno); return dev->fd; } @@ -730,8 +711,7 @@ static int do_print_ipu_version(struct device *dev) { int ret; ret = ioctl(dev->fd, VIDIOC_IPU_GET_DRIVER_VERSION, &version); - if (ret < 0) - return 0; + if (ret < 0) return 0; printf("IPU driver version: %d.%d\n", version >> 16, version & 0xFFFF); @@ -745,20 +725,16 @@ static int video_querycap(struct device *dev, unsigned int *capabilities) { memset(&cap, 0, sizeof cap); ret = ioctl(dev->fd, VIDIOC_QUERYCAP, &cap); - if (ret < 0) - return 0; + if (ret < 0) return 0; - caps = cap.capabilities & V4L2_CAP_DEVICE_CAPS ? cap.device_caps - : cap.capabilities; + caps = cap.capabilities & V4L2_CAP_DEVICE_CAPS ? cap.device_caps : cap.capabilities; - printf("Device `%s' on `%s' is a video %s (%s mplanes) device.\n", cap.card, - cap.bus_info, - caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_CAPTURE) - ? "capture" - : "output", - caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE) - ? "with" - : "without"); + printf( + "Device `%s' on `%s' is a video %s (%s mplanes) device.\n", cap.card, cap.bus_info, + caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_CAPTURE) ? "capture" + : "output", + caps & (V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE) ? "with" + : "without"); *capabilities = caps; @@ -785,12 +761,10 @@ static int cap_get_buf_type(unsigned int capabilities) { static void video_close(struct device *dev) { unsigned int i; - for (i = 0; i < dev->num_planes; i++) - free(dev->pattern[i]); + for (i = 0; i < dev->num_planes; i++) free(dev->pattern[i]); free(dev->buffers); - if (dev->opened) - close(dev->fd); + if (dev->opened) close(dev->fd); } static void video_log_status(struct device *dev) { @@ -816,12 +790,10 @@ static int video_get_format(struct device *dev) { dev->num_planes = v_fmt.fmt.pix_mp.num_planes; for (i = 0; i < v_fmt.fmt.pix_mp.num_planes; i++) { - dev->plane_fmt[i].bytesperline = - v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline; - dev->plane_fmt[i].sizeimage = - v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline - ? v_fmt.fmt.pix_mp.plane_fmt[i].sizeimage - : 0; + dev->plane_fmt[i].bytesperline = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline; + dev->plane_fmt[i].sizeimage = v_fmt.fmt.pix_mp.plane_fmt[i].bytesperline + ? v_fmt.fmt.pix_mp.plane_fmt[i].sizeimage + : 0; } } else { dev->width = v_fmt.fmt.pix.width; @@ -874,19 +846,18 @@ static int video_set_format(struct device *dev, unsigned int w, unsigned int h, ret = ioctl(dev->fd, VIDIOC_S_FMT, &fmt); if (ret < 0) { - printf("Failed to configure video format: %s (%d).\n", strerror(errno), - errno); + printf("Failed to configure video format: %s (%d).\n", strerror(errno), errno); return ret; } if (video_is_mplane(dev)) { - printf("Video attributes, pixel format: %s (%08x), resolution: %ux%u " - "field: %s, number " - "of planes: %u\n", - v4l2_format_name(fmt.fmt.pix_mp.pixelformat), - fmt.fmt.pix_mp.pixelformat, fmt.fmt.pix_mp.width, - fmt.fmt.pix_mp.height, v4l2_field_name(fmt.fmt.pix_mp.field), - fmt.fmt.pix_mp.num_planes); + printf( + "Video attributes, pixel format: %s (%08x), resolution: %ux%u " + "field: %s, number " + "of planes: %u\n", + v4l2_format_name(fmt.fmt.pix_mp.pixelformat), fmt.fmt.pix_mp.pixelformat, + fmt.fmt.pix_mp.width, fmt.fmt.pix_mp.height, + v4l2_field_name(fmt.fmt.pix_mp.field), fmt.fmt.pix_mp.num_planes); for (i = 0; i < fmt.fmt.pix_mp.num_planes; i++) { printf("Plane %d attributes, stride: %u, buffer size: %u\n", i, @@ -894,12 +865,13 @@ static int video_set_format(struct device *dev, unsigned int w, unsigned int h, fmt.fmt.pix_mp.plane_fmt[i].sizeimage); } } else { - printf("Video attributes, pixel format: %s (%08x), resolution: %ux%u, " - "stride: %u, " - "field: %s buffer size %u\n", - v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat, - fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline, - v4l2_field_name(fmt.fmt.pix.field), fmt.fmt.pix.sizeimage); + printf( + "Video attributes, pixel format: %s (%08x), resolution: %ux%u, " + "stride: %u, " + "field: %s buffer size %u\n", + v4l2_format_name(fmt.fmt.pix.pixelformat), fmt.fmt.pix.pixelformat, + fmt.fmt.pix.width, fmt.fmt.pix.height, fmt.fmt.pix.bytesperline, + v4l2_field_name(fmt.fmt.pix.field), fmt.fmt.pix.sizeimage); } return 0; @@ -920,19 +892,17 @@ static int video_buffer_mmap(struct device *dev, struct buffer *buffer, offset = v4l2buf->m.offset; } - buffer->mem[i] = - mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, dev->fd, offset); + buffer->mem[i] = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED, dev->fd, offset); if (buffer->mem[i] == MAP_FAILED) { - printf("Unable to map buffer %u/%u: %s (%d)\n", buffer->idx, i, - strerror(errno), errno); + printf("Unable to map buffer %u/%u: %s (%d)\n", buffer->idx, i, strerror(errno), + errno); return -1; } buffer->size[i] = length; buffer->padding[i] = 0; - printf("Buffer %u/%u mapped at address %p.\n", buffer->idx, i, - buffer->mem[i]); + printf("Buffer %u/%u mapped at address %p.\n", buffer->idx, i, buffer->mem[i]); } return 0; @@ -945,8 +915,8 @@ static int video_buffer_munmap(struct device *dev, struct buffer *buffer) { for (i = 0; i < dev->num_planes; i++) { ret = munmap(buffer->mem[i], buffer->size[i]); if (ret < 0) { - printf("Unable to unmap buffer %u/%u: %s (%d)\n", buffer->idx, i, - strerror(errno), errno); + printf("Unable to unmap buffer %u/%u: %s (%d)\n", buffer->idx, i, strerror(errno), + errno); } buffer->mem[i] = NULL; @@ -956,8 +926,7 @@ static int video_buffer_munmap(struct device *dev, struct buffer *buffer) { } static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer, - struct v4l2_buffer *v4l2buf, - unsigned int offset, + struct v4l2_buffer *v4l2buf, unsigned int offset, unsigned int padding) { int page_size = getpagesize(); unsigned int length; @@ -970,8 +939,8 @@ static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer, else length = v4l2buf->length; - ret = posix_memalign(&buffer->mem[i], page_size, - length + offset + padding + page_size); + ret = + posix_memalign(&buffer->mem[i], page_size, length + offset + padding + page_size); if (ret < 0) { printf("Unable to allocate buffer %u/%u (%d)\n", buffer->idx, i, ret); return -ENOMEM; @@ -981,15 +950,14 @@ static int video_buffer_alloc_userptr(struct device *dev, struct buffer *buffer, buffer->size[i] = length; buffer->padding[i] = padding; - printf("Buffer %u/%u allocated at address %p length %u page %u.\n", - buffer->idx, i, buffer->mem[i], length, page_size); + printf("Buffer %u/%u allocated at address %p length %u page %u.\n", buffer->idx, i, + buffer->mem[i], length, page_size); } return 0; } -static void video_buffer_free_userptr(struct device *dev, - struct buffer *buffer) { +static void video_buffer_free_userptr(struct device *dev, struct buffer *buffer) { unsigned int i; for (i = 0; i < dev->num_planes; i++) { @@ -998,35 +966,34 @@ static void video_buffer_free_userptr(struct device *dev, } } -static void get_ts_flags(uint32_t flags, const char **ts_type, - const char **ts_source) { +static void get_ts_flags(uint32_t flags, const char **ts_type, const char **ts_source) { switch (flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) { - case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN: - *ts_type = "unk"; - break; - case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC: - *ts_type = "mono"; - break; - case V4L2_BUF_FLAG_TIMESTAMP_COPY: - *ts_type = "copy"; - break; - default: - *ts_type = "inv"; + case V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN: + *ts_type = "unk"; + break; + case V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC: + *ts_type = "mono"; + break; + case V4L2_BUF_FLAG_TIMESTAMP_COPY: + *ts_type = "copy"; + break; + default: + *ts_type = "inv"; } switch (flags & V4L2_BUF_FLAG_TSTAMP_SRC_MASK) { - case V4L2_BUF_FLAG_TSTAMP_SRC_EOF: - *ts_source = "EoF"; - break; - case V4L2_BUF_FLAG_TSTAMP_SRC_SOE: - *ts_source = "SoE"; - break; - default: - *ts_source = "inv"; + case V4L2_BUF_FLAG_TSTAMP_SRC_EOF: + *ts_source = "EoF"; + break; + case V4L2_BUF_FLAG_TSTAMP_SRC_SOE: + *ts_source = "SoE"; + break; + default: + *ts_source = "inv"; } } -static int video_alloc_buffers(struct device *dev, int nbufs, - unsigned int offset, unsigned int padding) { +static int video_alloc_buffers(struct device *dev, int nbufs, unsigned int offset, + unsigned int padding) { struct v4l2_plane planes[VIDEO_MAX_PLANES]; struct v4l2_requestbuffers rb; struct v4l2_buffer buf; @@ -1048,8 +1015,7 @@ static int video_alloc_buffers(struct device *dev, int nbufs, printf("%u buffers requested.\n", rb.count); buffers = malloc(rb.count * sizeof buffers[0]); - if (buffers == NULL) - return -ENOMEM; + if (buffers == NULL) return -ENOMEM; /* Map the buffers. */ for (i = 0; i < rb.count; ++i) { @@ -1066,8 +1032,7 @@ static int video_alloc_buffers(struct device *dev, int nbufs, ret = ioctl(dev->fd, VIDIOC_QUERYBUF, &buf); if (ret < 0) { - printf("Unable to query buffer %u: %s (%d).\n", i, strerror(errno), - errno); + printf("Unable to query buffer %u: %s (%d).\n", i, strerror(errno), errno); return ret; } get_ts_flags(buf.flags, &ts_type, &ts_source); @@ -1077,20 +1042,19 @@ static int video_alloc_buffers(struct device *dev, int nbufs, buffers[i].idx = i; switch (dev->memtype) { - case V4L2_MEMORY_MMAP: - ret = video_buffer_mmap(dev, &buffers[i], &buf); - break; + case V4L2_MEMORY_MMAP: + ret = video_buffer_mmap(dev, &buffers[i], &buf); + break; - case V4L2_MEMORY_USERPTR: - ret = video_buffer_alloc_userptr(dev, &buffers[i], &buf, offset, padding); - break; + case V4L2_MEMORY_USERPTR: + ret = video_buffer_alloc_userptr(dev, &buffers[i], &buf, offset, padding); + break; - default: - break; + default: + break; } - if (ret < 0) - return ret; + if (ret < 0) return ret; } dev->timestamp_type = buf.flags & V4L2_BUF_FLAG_TIMESTAMP_MASK; @@ -1104,21 +1068,19 @@ static int video_free_buffers(struct device *dev) { unsigned int i; int ret; - if (dev->nbufs == 0) - return 0; + if (dev->nbufs == 0) return 0; for (i = 0; i < dev->nbufs; ++i) { switch (dev->memtype) { - case V4L2_MEMORY_MMAP: - ret = video_buffer_munmap(dev, &dev->buffers[i]); - if (ret < 0) - return ret; - break; - case V4L2_MEMORY_USERPTR: - video_buffer_free_userptr(dev, &dev->buffers[i]); - break; - default: - break; + case V4L2_MEMORY_MMAP: + ret = video_buffer_munmap(dev, &dev->buffers[i]); + if (ret < 0) return ret; + break; + case V4L2_MEMORY_USERPTR: + video_buffer_free_userptr(dev, &dev->buffers[i]); + break; + default: + break; } } @@ -1142,8 +1104,7 @@ static int video_free_buffers(struct device *dev) { return 0; } -static int video_queue_buffer(struct device *dev, int index, - enum buffer_fill_mode fill) { +static int video_queue_buffer(struct device *dev, int index, enum buffer_fill_mode fill) { struct v4l2_buffer buf; struct v4l2_plane planes[VIDEO_MAX_PLANES]; int ret; @@ -1193,21 +1154,18 @@ static int video_queue_buffer(struct device *dev, int index, else buf.bytesused = dev->patternsize[i]; - memcpy(dev->buffers[buf.index].mem[i], dev->pattern[i], - dev->patternsize[i]); + memcpy(dev->buffers[buf.index].mem[i], dev->pattern[i], dev->patternsize[i]); } else { if (fill & BUFFER_FILL_FRAME) - memset(dev->buffers[buf.index].mem[i], 0x55, - dev->buffers[index].size[i]); + memset(dev->buffers[buf.index].mem[i], 0x55, dev->buffers[index].size[i]); if (fill & BUFFER_FILL_PADDING) - memset(dev->buffers[buf.index].mem[i] + dev->buffers[index].size[i], - 0x55, dev->buffers[index].padding[i]); + memset(dev->buffers[buf.index].mem[i] + dev->buffers[index].size[i], 0x55, + dev->buffers[index].padding[i]); } } ret = ioctl(dev->fd, VIDIOC_QBUF, &buf); - if (ret < 0) - printf("Unable to queue buffer: %s (%d).\n", strerror(errno), errno); + if (ret < 0) printf("Unable to queue buffer: %s (%d).\n", strerror(errno), errno); return ret; } @@ -1253,8 +1211,7 @@ static int video_load_test_pattern(struct device *dev, const char *filename) { if (filename != NULL) { ret = read(fd, dev->pattern[plane], size); if (ret != (int)size && dev->plane_fmt[plane].bytesperline != 0) { - printf("Test pattern file size %u doesn't match image size %u\n", ret, - size); + printf("Test pattern file size %u doesn't match image size %u\n", ret, size); ret = -EINVAL; goto done; } @@ -1263,17 +1220,17 @@ static int video_load_test_pattern(struct device *dev, const char *filename) { unsigned int i; if (dev->plane_fmt[plane].bytesperline == 0) { - printf("Compressed format detected for plane %u and no test pattern " - "filename " - "given.\n" - "The test pattern can't be generated automatically.\n", - plane); + printf( + "Compressed format detected for plane %u and no test pattern " + "filename " + "given.\n" + "The test pattern can't be generated automatically.\n", + plane); ret = -EINVAL; goto done; } - for (i = 0; i < dev->plane_fmt[plane].sizeimage; ++i) - *data++ = i; + for (i = 0; i < dev->plane_fmt[plane].sizeimage; ++i) *data++ = i; } dev->patternsize[plane] = size; @@ -1282,42 +1239,36 @@ static int video_load_test_pattern(struct device *dev, const char *filename) { ret = 0; done: - if (fd != -1) - close(fd); + if (fd != -1) close(fd); return ret; } -static int video_prepare_capture(struct device *dev, int nbufs, - unsigned int offset, const char *filename, - enum buffer_fill_mode fill) { +static int video_prepare_capture(struct device *dev, int nbufs, unsigned int offset, + const char *filename, enum buffer_fill_mode fill) { unsigned int padding; int ret; /* Allocate and map buffers. */ padding = (fill & BUFFER_FILL_PADDING) ? 4096 : 0; - if ((ret = video_alloc_buffers(dev, nbufs, offset, padding)) < 0) - return ret; + if ((ret = video_alloc_buffers(dev, nbufs, offset, padding)) < 0) return ret; if (video_is_output(dev)) { ret = video_load_test_pattern(dev, filename); - if (ret < 0) - return ret; + if (ret < 0) return ret; } return 0; } -static int video_queue_all_buffers(struct device *dev, - enum buffer_fill_mode fill) { +static int video_queue_all_buffers(struct device *dev, enum buffer_fill_mode fill) { unsigned int i; int ret; /* Queue the buffers. */ for (i = 0; i < dev->nbufs; ++i) { ret = video_queue_buffer(dev, i, fill); - if (ret < 0) - return ret; + if (ret < 0) return ret; } return 0; @@ -1334,12 +1285,10 @@ static int tx_video_next_frame(void *priv, uint16_t *next_frame_idx, pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); - if (TX_FRAME_READY == - framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status) { + if (TX_FRAME_READY == framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status) { // printf("%s(%d), next frame idx %u\n", __func__, s->idx, consumer_idx); ret = 0; - framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status = - TX_FRAME_TRANSMITTING; + framebuff_ctl->buffs[framebuff_ctl->transmit_idx].status = TX_FRAME_TRANSMITTING; *next_frame_idx = framebuff_ctl->transmit_idx; clock_gettime(CLOCK_MONOTONIC, @@ -1370,15 +1319,14 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, if (frame_idx != framebuff_ctl->receive_idx) { ret = -EIO; - printf("%s, receive_idx %d != frame_done %d\n", __func__, - framebuff_ctl->receive_idx, frame_idx); + printf("%s, receive_idx %d != frame_done %d\n", __func__, framebuff_ctl->receive_idx, + frame_idx); return ret; } pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); - if (TX_FRAME_TRANSMITTING != - framebuff_ctl->buffs[framebuff_ctl->receive_idx].status) { + if (TX_FRAME_TRANSMITTING != framebuff_ctl->buffs[framebuff_ctl->receive_idx].status) { ret = -EIO; printf("%s, receive status %d != TRASNSMIT\n", __func__, framebuff_ctl->buffs[framebuff_ctl->receive_idx].status); @@ -1399,8 +1347,7 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, tx_video_session->st20_frame_done_cnt++; - ret = - video_queue_buffer(&(st_v4l2_tx->dev), frame_idx, st_v4l2_tx->fill_mode); + ret = video_queue_buffer(&(st_v4l2_tx->dev), frame_idx, st_v4l2_tx->fill_mode); if (ret < 0) { printf("%s Unable to requeue buffer: %d\n", __func__, ret); } @@ -1409,8 +1356,7 @@ static int tx_video_frame_done(void *priv, uint16_t frame_idx, } static void tx_video_debug_output(void) { - struct st_v4l2_tx_video_session *tx_video_session = - g_st_v4l2_tx->tx_video_sessions; + struct st_v4l2_tx_video_session *tx_video_session = g_st_v4l2_tx->tx_video_sessions; for (int i = 0; i < tx_video_session->framebuff_ctl.cnt; i++) { printf("time %ld.%06ld %ld.%06ld %ld.%06ld\n", @@ -1434,21 +1380,20 @@ static void tx_video_sig_handler(int signo) { printf("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - if (g_st_v4l2_tx->st) { - mtl_abort(g_st_v4l2_tx->st); - } - g_st_v4l2_tx->stop = true; + case SIGINT: /* Interrupt from keyboard */ + if (g_st_v4l2_tx->st) { + mtl_abort(g_st_v4l2_tx->st); + } + g_st_v4l2_tx->stop = true; - tx_video_debug_output(); + tx_video_debug_output(); - break; + break; } } -static int -tx_video_verify_buffer(struct st_v4l2_tx_video_session *tx_video_session, - struct v4l2_buffer *buf) { +static int tx_video_verify_buffer(struct st_v4l2_tx_video_session *tx_video_session, + struct v4l2_buffer *buf) { struct st_v4l2_tx_context *st_v4l2_tx = tx_video_session->ctx; struct device *dev = &(st_v4l2_tx->dev); unsigned int length; @@ -1466,8 +1411,7 @@ tx_video_verify_buffer(struct st_v4l2_tx_video_session *tx_video_session, return -1; } - if (dev->plane_fmt[0].sizeimage != - (length + dev->plane_fmt[0].bytesperline)) { + if (dev->plane_fmt[0].sizeimage != (length + dev->plane_fmt[0].bytesperline)) { printf("%s bytes used %u != image size %u\n", __func__, length, dev->plane_fmt[0].sizeimage); return -1; @@ -1478,9 +1422,8 @@ tx_video_verify_buffer(struct st_v4l2_tx_video_session *tx_video_session, return 0; } -static int -tx_video_copy_frame(struct st_v4l2_tx_video_session *tx_video_session, - struct v4l2_buffer *buf) { +static int tx_video_copy_frame(struct st_v4l2_tx_video_session *tx_video_session, + struct v4l2_buffer *buf) { struct st_v4l2_tx_context *st_v4l2_tx = tx_video_session->ctx; struct device *dev = &(st_v4l2_tx->dev); struct tx_frame_buff_ct *framebuff_ctl = &(tx_video_session->framebuff_ctl); @@ -1492,13 +1435,11 @@ tx_video_copy_frame(struct st_v4l2_tx_video_session *tx_video_session, pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); if (buf->index != framebuff_ctl->ready_idx) { /* out of order*/ - printf("%s(%d), ready idx out of order\n", __func__, - framebuff_ctl->ready_idx); + printf("%s(%d), ready idx out of order\n", __func__, framebuff_ctl->ready_idx); pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); return -1; } - if (TX_FRAME_RECEIVING != - framebuff_ctl->buffs[framebuff_ctl->ready_idx].status) { + if (TX_FRAME_RECEIVING != framebuff_ctl->buffs[framebuff_ctl->ready_idx].status) { /* buff full */ printf("%s(%d), buff full\n", __func__, framebuff_ctl->ready_idx); pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); @@ -1507,16 +1448,15 @@ tx_video_copy_frame(struct st_v4l2_tx_video_session *tx_video_session, pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); if (tx_video_session->ops_tx.flags & ST20_TX_FLAG_EXT_FRAME) { - st20_tx_set_ext_frame( - tx_video_session->handle, framebuff_ctl->ready_idx, - &tx_video_session->ext_frames[framebuff_ctl->ready_idx]); + st20_tx_set_ext_frame(tx_video_session->handle, framebuff_ctl->ready_idx, + &tx_video_session->ext_frames[framebuff_ctl->ready_idx]); display_consume_frame( tx_video_session, tx_video_session->ext_frames[framebuff_ctl->ready_idx].buf_addr); } else { - frame_addr = st20_tx_get_framebuffer(tx_video_session->handle, - framebuff_ctl->ready_idx); + frame_addr = + st20_tx_get_framebuffer(tx_video_session->handle, framebuff_ctl->ready_idx); for (i = 0; i < dev->num_planes; i++) { data = dev->buffers[buf->index].mem[i]; @@ -1532,19 +1472,16 @@ tx_video_copy_frame(struct st_v4l2_tx_video_session *tx_video_session, } } - if (data) - memcpy(frame_addr, data, length); + if (data) memcpy(frame_addr, data, length); } pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); framebuff_ctl->buffs[framebuff_ctl->ready_idx].status = TX_FRAME_READY; - framebuff_ctl->buffs[framebuff_ctl->ready_idx].size = - tx_video_session->framebuff_size; + framebuff_ctl->buffs[framebuff_ctl->ready_idx].size = tx_video_session->framebuff_size; clock_gettime(CLOCK_MONOTONIC, &(framebuff_ctl->buffs[framebuff_ctl->ready_idx].app_ts)); - framebuff_ctl->buffs[framebuff_ctl->ready_idx].v4l2_ts.tv_sec = - buf->timestamp.tv_sec; + framebuff_ctl->buffs[framebuff_ctl->ready_idx].v4l2_ts.tv_sec = buf->timestamp.tv_sec; framebuff_ctl->buffs[framebuff_ctl->ready_idx].v4l2_ts.tv_nsec = buf->timestamp.tv_usec * 1000; framebuff_ctl->buffs[framebuff_ctl->ready_idx].st20_ts.tv_sec = 0; @@ -1594,8 +1531,7 @@ static void *tx_video_thread_capture(void *arg) { ret = ioctl(st_v4l2_tx->dev.fd, VIDIOC_DQBUF, &buf); if (ret < 0) { - printf("%s Unable to dequeue buffer: %s (%d).\n", __func__, - strerror(errno), errno); + printf("%s Unable to dequeue buffer: %s (%d).\n", __func__, strerror(errno), errno); break; } @@ -1605,8 +1541,8 @@ static void *tx_video_thread_capture(void *arg) { break; } - fps = (buf.timestamp.tv_sec - last.tv_sec) * 1000000 + - buf.timestamp.tv_usec - last.tv_usec; + fps = (buf.timestamp.tv_sec - last.tv_sec) * 1000000 + buf.timestamp.tv_usec - + last.tv_usec; fps = fps ? 1000000.0 / fps : 0.0; /* printf("%u (%u) [%c] %s %u %u %ld.%06ld %.3f fps \n", i, buf.index, @@ -1627,15 +1563,13 @@ static void *tx_video_thread_capture(void *arg) { pthread_mutex_lock(&(framebuff_ctl->wake_mutex)); if (buf.index != framebuff_ctl->ready_idx) { /* out of order*/ - printf("%s(%d), ready idx out of order\n", __func__, - framebuff_ctl->ready_idx); + printf("%s(%d), ready idx out of order\n", __func__, framebuff_ctl->ready_idx); pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); ret = -1; break; } - framebuff_ctl->buffs[framebuff_ctl->ready_idx].status = - TX_FRAME_RECEIVING; + framebuff_ctl->buffs[framebuff_ctl->ready_idx].status = TX_FRAME_RECEIVING; framebuff_ctl->ready_idx++; if (framebuff_ctl->ready_idx >= framebuff_ctl->cnt) { framebuff_ctl->ready_idx = 0; @@ -1644,8 +1578,7 @@ static void *tx_video_thread_capture(void *arg) { framebuff_ctl->transmit_idx = framebuff_ctl->ready_idx; pthread_mutex_unlock(&(framebuff_ctl->wake_mutex)); - ret = video_queue_buffer(&(st_v4l2_tx->dev), buf.index, - st_v4l2_tx->fill_mode); + ret = video_queue_buffer(&(st_v4l2_tx->dev), buf.index, st_v4l2_tx->fill_mode); if (ret < 0) { printf("%s Unable to requeue buffer: %d\n", __func__, ret); break; @@ -1665,21 +1598,18 @@ static void *tx_video_thread_capture(void *arg) { return NULL; } -static int -tx_video_thread_create(struct st_v4l2_tx_video_session *tx_video_session, - unsigned int priority, unsigned int cpu) { +static int tx_video_thread_create(struct st_v4l2_tx_video_session *tx_video_session, + unsigned int priority, unsigned int cpu) { int ret = 0; - if (pthread_create(&(tx_video_session->st20_app_thread), NULL, - tx_video_thread_capture, tx_video_session)) { - printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), - errno); + if (pthread_create(&(tx_video_session->st20_app_thread), NULL, tx_video_thread_capture, + tx_video_session)) { + printf("%s pthread_create Failed: %s (%d)\n", __func__, strerror(errno), errno); ret = -EIO; return ret; } - if (video_set_realtime(tx_video_session->st20_app_thread, priority, cpu) < - 0) { + if (video_set_realtime(tx_video_session->st20_app_thread, priority, cpu) < 0) { printf("%s video_set_realtime Failed\n", __func__); ret = -EIO; return ret; @@ -1763,53 +1693,51 @@ int main(int argc, char *argv[]) { opterr = 0; while ((c = getopt_long(argc, argv, "c::hn::p:m:se", opts, NULL)) != -1) { switch (c) { - case 'c': - nframes = atoi(optarg); - break; + case 'c': + nframes = atoi(optarg); + break; - case 'h': - usage(argv[0]); - return 0; + case 'h': + usage(argv[0]); + return 0; - case 'n': - nbufs = atoi(optarg); - if (nbufs > V4L_BUFFERS_MAX) - nbufs = V4L_BUFFERS_MAX; - break; + case 'n': + nbufs = atoi(optarg); + if (nbufs > V4L_BUFFERS_MAX) nbufs = V4L_BUFFERS_MAX; + break; - case 'p': - strcpy(port, optarg); - break; + case 'p': + strcpy(port, optarg); + break; - case 'm': - strcpy(dst_mac, optarg); - break; + case 'm': + strcpy(dst_mac, optarg); + break; - case 's': - show = true; - break; + case 's': + show = true; + break; - case 'e': - ptp = true; - break; + case 'e': + ptp = true; + break; - case 't': - tsn = true; - break; + case 't': + tsn = true; + break; - case OPT_LOG_STATUS: - do_log_status = 1; - break; + case OPT_LOG_STATUS: + do_log_status = 1; + break; - default: - printf("%s Invalid option -%c\n", __func__, c); - printf("%s Run %s -h for help.\n", __func__, argv[0]); - return 1; + default: + printf("%s Invalid option -%c\n", __func__, c); + printf("%s Run %s -h for help.\n", __func__, argv[0]); + return 1; } } - st_v4l2_tx = - (struct st_v4l2_tx_context *)malloc(sizeof(struct st_v4l2_tx_context)); + st_v4l2_tx = (struct st_v4l2_tx_context *)malloc(sizeof(struct st_v4l2_tx_context)); if (!st_v4l2_tx) { printf("%s struct application malloc fail\n", __func__); return -EIO; @@ -1867,8 +1795,8 @@ int main(int argc, char *argv[]) { video_log_status(&(st_v4l2_tx->dev)); } - if (video_set_format(&(st_v4l2_tx->dev), width, height, V4L2_PIX_FMT_UYVY, 0, - 0, V4L2_FIELD_ANY, 0) < 0) { + if (video_set_format(&(st_v4l2_tx->dev), width, height, V4L2_PIX_FMT_UYVY, 0, 0, + V4L2_FIELD_ANY, 0) < 0) { video_close(&(st_v4l2_tx->dev)); free(st_v4l2_tx); return -EIO; @@ -1911,10 +1839,9 @@ int main(int argc, char *argv[]) { st_v4l2_tx->param.num_ports = 1; st_v4l2_tx->param.pmd[MTL_PORT_P] = TX_VIDEO_PMD; strncpy(st_v4l2_tx->param.port[MTL_PORT_P], port, MTL_PORT_MAX_LEN); - memcpy(st_v4l2_tx->param.sip_addr[MTL_PORT_P], g_tx_video_local_ip, - MTL_IP_ADDR_LEN); + memcpy(st_v4l2_tx->param.sip_addr[MTL_PORT_P], g_tx_video_local_ip, MTL_IP_ADDR_LEN); st_v4l2_tx->param.flags = - MTL_FLAG_BIND_NUMA | MTL_FLAG_TX_VIDEO_MIGRATE; // default bind to numa + MTL_FLAG_BIND_NUMA | MTL_FLAG_TX_VIDEO_MIGRATE; // default bind to numa if (ptp == true) { st_v4l2_tx->param.flags |= MTL_FLAG_PTP_ENABLE; } @@ -1925,9 +1852,8 @@ int main(int argc, char *argv[]) { } else { st_v4l2_tx->param.pacing = ST21_TX_PACING_WAY_AUTO; } - st_v4l2_tx->param.log_level = - MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING - st_v4l2_tx->param.priv = NULL; // usr ctx pointer + st_v4l2_tx->param.log_level = MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING + st_v4l2_tx->param.priv = NULL; // usr ctx pointer // if not registed, the internal ptp source will be used st_v4l2_tx->param.ptp_get_time_fn = NULL; st_v4l2_tx->param.tx_queues_cnt[0] = session_num; @@ -1948,16 +1874,14 @@ int main(int argc, char *argv[]) { tx_video_session = (struct st_v4l2_tx_video_session *)malloc( sizeof(struct st_v4l2_tx_video_session) * session_num); if (!tx_video_session) { - printf("%s struct st_v4l2_tx_video_session is not correctly malloc", - __func__); + printf("%s struct st_v4l2_tx_video_session is not correctly malloc", __func__); mtl_uninit(st_v4l2_tx->st); video_free_buffers(&(st_v4l2_tx->dev)); video_close(&(st_v4l2_tx->dev)); free(st_v4l2_tx); return -EIO; } - memset(tx_video_session, 0, - sizeof(struct st_v4l2_tx_video_session) * session_num); + memset(tx_video_session, 0, sizeof(struct st_v4l2_tx_video_session) * session_num); if (show) { ret = app_player_init(); @@ -2001,8 +1925,7 @@ int main(int argc, char *argv[]) { // init ops tx_video_session->ops_tx.name = "v4l2_st20_tx"; - tx_video_session->ops_tx.priv = - tx_video_session; // app handle register to lib + tx_video_session->ops_tx.priv = tx_video_session; // app handle register to lib tx_video_session->ops_tx.num_port = 1; // tx src ip like 239.0.0.1 @@ -2015,8 +1938,7 @@ int main(int argc, char *argv[]) { tx_video_session->ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; } - tx_video_session->ops_tx.udp_port[MTL_PORT_P] = - TX_VIDEO_UDP_PORT + i; // udp port + tx_video_session->ops_tx.udp_port[MTL_PORT_P] = TX_VIDEO_UDP_PORT + i; // udp port tx_video_session->ops_tx.pacing = ST21_PACING_NARROW; tx_video_session->ops_tx.type = ST20_TYPE_FRAME_LEVEL; tx_video_session->ops_tx.width = st_v4l2_tx->dev.width; @@ -2045,8 +1967,7 @@ int main(int argc, char *argv[]) { if (tx_video_session->ops_tx.flags & ST20_TX_FLAG_EXT_FRAME) { if (st_v4l2_tx->dev.buffers->size[0] < tx_video_session->framebuff_size) { printf("%s[%d] buffers->size %d < framebuff_size %d\n", __func__, i, - st_v4l2_tx->dev.buffers->size[0], - tx_video_session->framebuff_size); + st_v4l2_tx->dev.buffers->size[0], tx_video_session->framebuff_size); ret = -EIO; goto error; } @@ -2058,19 +1979,17 @@ int main(int argc, char *argv[]) { goto error; } - tx_video_session->ext_frames = (struct st20_ext_frame *)malloc( - sizeof(struct st20_ext_frame) * nbufs); + tx_video_session->ext_frames = + (struct st20_ext_frame *)malloc(sizeof(struct st20_ext_frame) * nbufs); if (!tx_video_session->ext_frames) { printf("%s[%d], ext_frames malloc fail\n", __func__, i); ret = -EIO; goto error; } - memset(tx_video_session->ext_frames, 0, - sizeof(struct st20_ext_frame) * nbufs); + memset(tx_video_session->ext_frames, 0, sizeof(struct st20_ext_frame) * nbufs); for (int j = 0; j < nbufs; ++j) { - tx_video_session->ext_frames[j].buf_addr = - st_v4l2_tx->dev.buffers[j].mem[0]; + tx_video_session->ext_frames[j].buf_addr = st_v4l2_tx->dev.buffers[j].mem[0]; pg_size = mtl_page_size(st_v4l2_tx->st); map_size = tx_video_session->framebuff_size; map_size += (pg_size - tx_video_session->framebuff_size % pg_size); @@ -2086,9 +2005,8 @@ int main(int argc, char *argv[]) { } if (st_v4l2_tx->has_sdl) { - ret = app_init_display(&(tx_video_session->display), i, - st_v4l2_tx->dev.width, st_v4l2_tx->dev.height, - st_v4l2_tx->ttf_file); + ret = app_init_display(&(tx_video_session->display), i, st_v4l2_tx->dev.width, + st_v4l2_tx->dev.height, st_v4l2_tx->ttf_file); if (ret < 0) { printf("%s(%d), app_init_display fail %d\n", __func__, i, ret); goto error; @@ -2120,8 +2038,7 @@ int main(int argc, char *argv[]) { /*task create*/ for (int i = 0; i < session_num; i++) { tx_video_session = &(st_v4l2_tx->tx_video_sessions[i]); - ret = tx_video_thread_create(tx_video_session, v4l2_thread_priority, - v4l2_thread_cpu); + ret = tx_video_thread_create(tx_video_session, v4l2_thread_priority, v4l2_thread_cpu); if (ret < 0) { printf("%s video thread create fail %d.\n", __func__, ret); goto error; @@ -2175,8 +2092,7 @@ int main(int argc, char *argv[]) { for (int j = 0; j < nbufs; ++j) { if ((tx_video_session->ext_frames[j].buf_iova != MTL_BAD_IOVA) && (tx_video_session->ext_frames[j].buf_iova != 0)) { - ret = mtl_dma_unmap(st_v4l2_tx->st, - tx_video_session->ext_frames[j].buf_addr, + ret = mtl_dma_unmap(st_v4l2_tx->st, tx_video_session->ext_frames[j].buf_addr, tx_video_session->ext_frames[j].buf_iova, tx_video_session->ext_frames[j].buf_len); if (0 != ret) { diff --git a/ecosystem/ffmpeg_plugin/mtl_common.c b/ecosystem/ffmpeg_plugin/mtl_common.c index 32af160de..f4dacb8bb 100644 --- a/ecosystem/ffmpeg_plugin/mtl_common.c +++ b/ecosystem/ffmpeg_plugin/mtl_common.c @@ -28,31 +28,28 @@ enum st_fps framerate_to_st_fps(AVRational framerate) { return st_frame_rate_to_st_fps(fps); } -mtl_handle mtl_dev_get(AVFormatContext *ctx, const struct StDevArgs *args, - int *idx) { +mtl_handle mtl_dev_get(AVFormatContext *ctx, const struct StDevArgs *args, int *idx) { struct mtl_init_params p; mtl_handle handle = NULL; if (g_mtl_shared_handle) { *idx = g_mtl_ref_cnt; g_mtl_ref_cnt++; - info(ctx, "%s, shared handle %p ref cnt %d\n", __func__, - g_mtl_shared_handle, g_mtl_ref_cnt); + info(ctx, "%s, shared handle %p ref cnt %d\n", __func__, g_mtl_shared_handle, + g_mtl_ref_cnt); return g_mtl_shared_handle; } memset(&p, 0, sizeof(p)); for (int i = 0; i < MTL_PORT_MAX; i++) { - if (!args->port[i]) - break; + if (!args->port[i]) break; snprintf(p.port[i], sizeof(p.port[i]), "%s", args->port[i]); p.pmd[i] = mtl_pmd_by_port_name(p.port[i]); if (args->sip[i]) { int ret = inet_pton(AF_INET, args->sip[i], p.sip_addr[i]); if (ret != 1) { - err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, - args->sip[i]); + err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, args->sip[i]); return NULL; } } @@ -65,7 +62,7 @@ mtl_handle mtl_dev_get(AVFormatContext *ctx, const struct StDevArgs *args, p.flags |= MTL_FLAG_RX_VIDEO_MIGRATE; p.flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; p.flags |= MTL_FLAG_BIND_NUMA; - p.log_level = MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING + p.log_level = MTL_LOG_LEVEL_INFO; // log level. ERROR, INFO, WARNING if (args->dma_dev) { char devs[128] = {0}; @@ -114,20 +111,17 @@ int mtl_instance_put(AVFormatContext *ctx, mtl_handle handle) { } int mtl_parse_rx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, - const StRxSessionPortArgs *args, - struct st_rx_port *port) { + const StRxSessionPortArgs *args, struct st_rx_port *port) { for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { /* if no special port in StRxSessionPortArgs, get from StDevArgs */ - if (!args->port[i] && !devArgs->port[i]) - break; + if (!args->port[i] && !devArgs->port[i]) break; dbg(ctx, "%s, port on %d\n", __func__, i); snprintf(port->port[i], sizeof(port->port[i]), "%s", args->port[i] ? args->port[i] : devArgs->port[i]); if (args->sip[i]) { int ret = inet_pton(AF_INET, args->sip[i], port->ip_addr[i]); if (ret != 1) { - err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, - args->sip[i]); + err(ctx, "%s, %d sip %s is not valid ip address\n", __func__, i, args->sip[i]); return AVERROR(EINVAL); } } @@ -148,20 +142,17 @@ int mtl_parse_rx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, } int mtl_parse_tx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, - const StTxSessionPortArgs *args, - struct st_tx_port *port) { + const StTxSessionPortArgs *args, struct st_tx_port *port) { for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { /* if no special port in StTxSessionPortArgs, get from StDevArgs */ - if (!args->port[i] && !devArgs->port[i]) - break; + if (!args->port[i] && !devArgs->port[i]) break; dbg(ctx, "%s, port on %d\n", __func__, i); snprintf(port->port[i], sizeof(port->port[i]), "%s", args->port[i] ? args->port[i] : devArgs->port[i]); if (args->dip[i]) { int ret = inet_pton(AF_INET, args->dip[i], port->dip_addr[i]); if (ret != 1) { - err(ctx, "%s, %d dip %s is not valid ip address\n", __func__, i, - args->dip[i]); + err(ctx, "%s, %d dip %s is not valid ip address\n", __func__, i, args->dip[i]); return AVERROR(EINVAL); } } @@ -183,16 +174,16 @@ int mtl_parse_tx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, int mtl_parse_st30_sample_rate(enum st30_sampling *sample_rate, int value) { switch (value) { - case 48000: - *sample_rate = ST30_SAMPLING_48K; - return 0; - case 96000: - *sample_rate = ST30_SAMPLING_96K; - return 0; - case 44100: - *sample_rate = ST31_SAMPLING_44K; - return 0; - default: - return AVERROR(EINVAL); + case 48000: + *sample_rate = ST30_SAMPLING_48K; + return 0; + case 96000: + *sample_rate = ST30_SAMPLING_96K; + return 0; + case 44100: + *sample_rate = ST31_SAMPLING_44K; + return 0; + default: + return AVERROR(EINVAL); } } diff --git a/ecosystem/ffmpeg_plugin/mtl_common.h b/ecosystem/ffmpeg_plugin/mtl_common.h index 7ba481949..187b9e4ae 100644 --- a/ecosystem/ffmpeg_plugin/mtl_common.h +++ b/ecosystem/ffmpeg_plugin/mtl_common.h @@ -51,26 +51,26 @@ /* log define */ #ifdef DEBUG -#define dbg(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); \ +#define dbg(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_DEBUG, __VA_ARGS__); \ } while (0) #else -#define dbg(ctx, ...) \ - do { \ +#define dbg(ctx, ...) \ + do { \ } while (0) #endif -#define info(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_INFO, __VA_ARGS__); \ +#define info(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_INFO, __VA_ARGS__); \ } while (0) -#define warn(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_WARNING, __VA_ARGS__); \ +#define warn(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_WARNING, __VA_ARGS__); \ } while (0) -#define err(ctx, ...) \ - do { \ - av_log(ctx, AV_LOG_ERROR, __VA_ARGS__); \ +#define err(ctx, ...) \ + do { \ + av_log(ctx, AV_LOG_ERROR, __VA_ARGS__); \ } while (0) #ifndef NS_PER_MS @@ -81,74 +81,56 @@ #define NS_PER_S (1000 * NS_PER_MS) #endif -#define MTL_RX_DEV_ARGS \ - {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ - AV_OPT_TYPE_STRING, {.str = NULL}, .flags = DEC}, \ - {"p_sip", \ - "mtl local ip", \ - OFFSET(devArgs.sip[MTL_PORT_P]), \ - AV_OPT_TYPE_STRING, \ - {.str = NULL}, \ - .flags = DEC}, \ - { \ - "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ - {.str = NULL}, .flags = DEC \ +#define MTL_RX_DEV_ARGS \ + {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ + AV_OPT_TYPE_STRING, {.str = NULL}, .flags = DEC}, \ + {"p_sip", "mtl local ip", OFFSET(devArgs.sip[MTL_PORT_P]), AV_OPT_TYPE_STRING, \ + {.str = NULL}, .flags = DEC}, \ + { \ + "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ + {.str = NULL}, .flags = DEC \ } -#define MTL_RX_PORT_ARGS \ - { \ - "p_rx_ip", \ - "p rx ip", \ - OFFSET(portArgs.sip[MTL_SESSION_PORT_P]), \ - AV_OPT_TYPE_STRING, \ - {.str = NULL}, \ - .flags = DEC}, \ - {"udp_port", \ - "UDP port", \ - OFFSET(portArgs.udp_port), \ - AV_OPT_TYPE_INT, \ - {.i64 = 20000}, \ - -1, \ - INT_MAX, \ - DEC}, \ - { \ - "payload_type", "payload type", OFFSET(portArgs.payload_type), \ - AV_OPT_TYPE_INT, {.i64 = 112}, -1, INT_MAX, DEC \ +#define MTL_RX_PORT_ARGS \ + {"p_rx_ip", "p rx ip", OFFSET(portArgs.sip[MTL_SESSION_PORT_P]), \ + AV_OPT_TYPE_STRING, {.str = NULL}, .flags = DEC}, \ + {"udp_port", \ + "UDP port", \ + OFFSET(portArgs.udp_port), \ + AV_OPT_TYPE_INT, \ + {.i64 = 20000}, \ + -1, \ + INT_MAX, \ + DEC}, \ + { \ + "payload_type", "payload type", OFFSET(portArgs.payload_type), AV_OPT_TYPE_INT, \ + {.i64 = 112}, -1, INT_MAX, DEC \ } -#define MTL_TX_DEV_ARGS \ - {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ - AV_OPT_TYPE_STRING, {.str = NULL}, .flags = ENC}, \ - {"p_sip", \ - "mtl local ip", \ - OFFSET(devArgs.sip[MTL_PORT_P]), \ - AV_OPT_TYPE_STRING, \ - {.str = NULL}, \ - .flags = ENC}, \ - { \ - "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ - {.str = NULL}, .flags = ENC \ +#define MTL_TX_DEV_ARGS \ + {"p_port", "mtl p port", OFFSET(devArgs.port[MTL_PORT_P]), \ + AV_OPT_TYPE_STRING, {.str = NULL}, .flags = ENC}, \ + {"p_sip", "mtl local ip", OFFSET(devArgs.sip[MTL_PORT_P]), AV_OPT_TYPE_STRING, \ + {.str = NULL}, .flags = ENC}, \ + { \ + "dma_dev", "mtl dma dev", OFFSET(devArgs.dma_dev), AV_OPT_TYPE_STRING, \ + {.str = NULL}, .flags = ENC \ } -#define MTL_TX_PORT_ARGS \ - { \ - "p_tx_ip", \ - "p tx ip", \ - OFFSET(portArgs.dip[MTL_SESSION_PORT_P]), \ - AV_OPT_TYPE_STRING, \ - {.str = NULL}, \ - .flags = ENC}, \ - {"udp_port", \ - "UDP port", \ - OFFSET(portArgs.udp_port), \ - AV_OPT_TYPE_INT, \ - {.i64 = 20000}, \ - -1, \ - INT_MAX, \ - ENC}, \ - { \ - "payload_type", "payload type", OFFSET(portArgs.payload_type), \ - AV_OPT_TYPE_INT, {.i64 = 112}, -1, INT_MAX, ENC \ +#define MTL_TX_PORT_ARGS \ + {"p_tx_ip", "p tx ip", OFFSET(portArgs.dip[MTL_SESSION_PORT_P]), \ + AV_OPT_TYPE_STRING, {.str = NULL}, .flags = ENC}, \ + {"udp_port", \ + "UDP port", \ + OFFSET(portArgs.udp_port), \ + AV_OPT_TYPE_INT, \ + {.i64 = 20000}, \ + -1, \ + INT_MAX, \ + ENC}, \ + { \ + "payload_type", "payload type", OFFSET(portArgs.payload_type), AV_OPT_TYPE_INT, \ + {.i64 = 112}, -1, INT_MAX, ENC \ } typedef struct StDevArgs { @@ -181,8 +163,7 @@ typedef struct StFpsDecs { enum st_fps framerate_to_st_fps(AVRational framerate); -mtl_handle mtl_dev_get(AVFormatContext *ctx, const struct StDevArgs *args, - int *idx); +mtl_handle mtl_dev_get(AVFormatContext *ctx, const struct StDevArgs *args, int *idx); int mtl_instance_put(AVFormatContext *ctx, mtl_handle handle); int mtl_parse_rx_port(AVFormatContext *ctx, const struct StDevArgs *devArgs, diff --git a/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c b/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c index c912f7aae..817d14a70 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st20p_rx.c @@ -58,8 +58,7 @@ static int mtl_st20p_read_close(AVFormatContext *ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -94,31 +93,28 @@ static int mtl_st20p_read_header(AVFormatContext *ctx) { ops_rx.height = s->height; ops_rx.fps = framerate_to_st_fps(s->framerate); if (ops_rx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, - av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); return AVERROR(EINVAL); } /* transport_fmt is hardcode now */ pix_fmt = s->pixel_format; pix_fmt_desc = av_pix_fmt_desc_get(pix_fmt); switch (pix_fmt) { - case AV_PIX_FMT_YUV422P10LE: - ops_rx.transport_fmt = ST20_FMT_YUV_422_10BIT; - ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - break; - case AV_PIX_FMT_RGB24: - ops_rx.transport_fmt = ST20_FMT_RGB_8BIT; - ops_rx.output_fmt = ST_FRAME_FMT_RGB8; - break; - default: - err(ctx, "%s, unsupported pixel format: %s\n", __func__, - pix_fmt_desc->name); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_rx.transport_fmt = ST20_FMT_YUV_422_10BIT; + ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + break; + case AV_PIX_FMT_RGB24: + ops_rx.transport_fmt = ST20_FMT_RGB_8BIT; + ops_rx.output_fmt = ST_FRAME_FMT_RGB8; + break; + default: + err(ctx, "%s, unsupported pixel format: %s\n", __func__, pix_fmt_desc->name); + return AVERROR(EINVAL); } img_buf_size = av_image_get_buffer_size(pix_fmt, s->width, s->height, 1); if (img_buf_size < 0) { - err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, - img_buf_size); + err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, img_buf_size); return img_buf_size; } dbg(ctx, "%s, img_buf_size: %d\n", __func__, img_buf_size); @@ -147,7 +143,7 @@ static int mtl_st20p_read_header(AVFormatContext *ctx) { av_rescale_q(ctx->packet_size, (AVRational){8, 1}, st->time_base); ops_rx.name = "st20p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_rx.framebuff_cnt = s->fb_cnt; @@ -168,13 +164,11 @@ static int mtl_st20p_read_header(AVFormatContext *ctx) { } if (s->timeout_sec) - st20p_rx_set_block_timeout(s->rx_handle, - s->timeout_sec * (uint64_t)NS_PER_S); + st20p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); img_buf_size = st20p_rx_frame_size(s->rx_handle); if (img_buf_size != ctx->packet_size) { - err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, - ctx->packet_size); + err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, ctx->packet_size); mtl_st20p_read_close(ctx); return AVERROR(EIO); } @@ -204,10 +198,8 @@ static int mtl_st20p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { */ for (int i = 1; i <= s->session_init_retry; i++) { frame = st20p_rx_get_frame(s->rx_handle); - if (frame) - break; - info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, - i); + if (frame) break; + info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, i); } } else frame = st20p_rx_get_frame(s->rx_handle); @@ -218,8 +210,7 @@ static int mtl_st20p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { } dbg(ctx, "%s(%d), st20p_rx_get_frame: %p\n", __func__, s->idx, frame); if (frame->data_size != ctx->packet_size) { - err(ctx, - "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", + err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", __func__, s->idx, frame->data_size, ctx->packet_size); st20p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); @@ -329,7 +320,7 @@ FFInputFormat ff_mtl_st20p_demuxer = { .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .p.priv_class = &mtl_st20p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st20p_demuxer = #else @@ -347,4 +338,4 @@ AVInputFormat ff_mtl_st20p_demuxer = .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .priv_class = &mtl_st20p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 diff --git a/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c b/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c index 6bbc98a30..74285cdd6 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st20p_tx.c @@ -57,8 +57,7 @@ static int mtl_st20p_write_close(AVFormatContext *ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -83,8 +82,7 @@ static int mtl_st20p_write_header(AVFormatContext *ctx) { s->framerate = ctx->streams[0]->avg_frame_rate; ops_tx.fps = framerate_to_st_fps(s->framerate); if (ops_tx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, - av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); return AVERROR(EINVAL); } @@ -92,21 +90,21 @@ static int mtl_st20p_write_header(AVFormatContext *ctx) { /* transport_fmt is hardcode now */ switch (s->pixel_format) { - case AV_PIX_FMT_YUV422P10LE: - ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - ops_tx.transport_fmt = ST20_FMT_YUV_422_10BIT; - break; - case AV_PIX_FMT_RGB24: - ops_tx.input_fmt = ST_FRAME_FMT_RGB8; - ops_tx.transport_fmt = ST20_FMT_RGB_8BIT; - break; - default: - err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + ops_tx.transport_fmt = ST20_FMT_YUV_422_10BIT; + break; + case AV_PIX_FMT_RGB24: + ops_tx.input_fmt = ST_FRAME_FMT_RGB8; + ops_tx.transport_fmt = ST20_FMT_RGB_8BIT; + break; + default: + err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); + return AVERROR(EINVAL); } ops_tx.name = "st20p_ffmpge"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_tx.framebuff_cnt = s->fb_cnt; @@ -142,8 +140,8 @@ static int mtl_st20p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { struct st_frame *frame; if (pkt->size != s->frame_size) { - err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, - s->idx, pkt->size, s->frame_size); + err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, s->idx, + pkt->size, s->frame_size); return AVERROR(EIO); } @@ -159,8 +157,7 @@ static int mtl_st20p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { st20p_tx_put_frame(s->tx_handle, frame); s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } diff --git a/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c b/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c index 7ec877ab3..f481b022d 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st22p_rx.c @@ -60,8 +60,7 @@ static int mtl_st22p_read_close(AVFormatContext *ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -109,8 +108,7 @@ static int mtl_st22p_read_header(AVFormatContext *ctx) { ops_rx.height = s->height; ops_rx.fps = framerate_to_st_fps(s->framerate); if (ops_rx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, - av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); return AVERROR(EINVAL); } @@ -118,22 +116,20 @@ static int mtl_st22p_read_header(AVFormatContext *ctx) { pix_fmt = s->pixel_format; pix_fmt_desc = av_pix_fmt_desc_get(pix_fmt); switch (pix_fmt) { - case AV_PIX_FMT_YUV422P10LE: - ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - break; - case AV_PIX_FMT_RGB24: - ops_rx.output_fmt = ST_FRAME_FMT_RGB8; - break; - default: - err(ctx, "%s, unsupported pixel format: %s\n", __func__, - pix_fmt_desc->name); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_rx.output_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + break; + case AV_PIX_FMT_RGB24: + ops_rx.output_fmt = ST_FRAME_FMT_RGB8; + break; + default: + err(ctx, "%s, unsupported pixel format: %s\n", __func__, pix_fmt_desc->name); + return AVERROR(EINVAL); } img_buf_size = av_image_get_buffer_size(pix_fmt, s->width, s->height, 1); if (img_buf_size < 0) { - err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, - img_buf_size); + err(ctx, "%s, av_image_get_buffer_size failed with %d\n", __func__, img_buf_size); return img_buf_size; } dbg(ctx, "%s, img_buf_size: %d\n", __func__, img_buf_size); @@ -167,7 +163,7 @@ static int mtl_st22p_read_header(AVFormatContext *ctx) { } ops_rx.name = "st22p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.device = ST_PLUGIN_DEVICE_AUTO; ops_rx.framebuff_cnt = s->fb_cnt; ops_rx.codec_thread_cnt = s->codec_thread_cnt; @@ -180,13 +176,11 @@ static int mtl_st22p_read_header(AVFormatContext *ctx) { } if (s->timeout_sec) - st22p_rx_set_block_timeout(s->rx_handle, - s->timeout_sec * (uint64_t)NS_PER_S); + st22p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); img_buf_size = st22p_rx_frame_size(s->rx_handle); if (img_buf_size != ctx->packet_size) { - err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, - ctx->packet_size); + err(ctx, "%s, frame size mismatch %d:%u\n", __func__, img_buf_size, ctx->packet_size); mtl_st22p_read_close(ctx); return AVERROR(EIO); } @@ -259,8 +253,7 @@ static int mtl_st22_read_header(AVFormatContext *ctx) { ops_rx.height = s->height; ops_rx.fps = framerate_to_st_fps(s->framerate); if (ops_rx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, - av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); return AVERROR(EINVAL); } @@ -273,7 +266,7 @@ static int mtl_st22_read_header(AVFormatContext *ctx) { } ops_rx.name = "st22p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.device = ST_PLUGIN_DEVICE_AUTO; ops_rx.framebuff_cnt = s->fb_cnt; @@ -285,8 +278,7 @@ static int mtl_st22_read_header(AVFormatContext *ctx) { } if (s->timeout_sec) - st22p_rx_set_block_timeout(s->rx_handle, - s->timeout_sec * (uint64_t)NS_PER_S); + st22p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); img_buf_size = st22p_rx_frame_size(s->rx_handle); dbg(ctx, "%s, img_buf_size: %d\n", __func__, img_buf_size); @@ -314,8 +306,8 @@ static int mtl_st22_read_header(AVFormatContext *ctx) { return AVERROR(EIO); } - info(ctx, "%s(%d), rx handle %p, max packet_size %u\n", __func__, s->idx, - s->rx_handle, ctx->packet_size); + info(ctx, "%s(%d), rx handle %p, max packet_size %u\n", __func__, s->idx, s->rx_handle, + ctx->packet_size); return 0; } @@ -333,10 +325,8 @@ static int mtl_st22p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { */ for (int i = 1; i <= s->session_init_retry; i++) { frame = st22p_rx_get_frame(s->rx_handle); - if (frame) - break; - info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, - i); + if (frame) break; + info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, i); } } else frame = st22p_rx_get_frame(s->rx_handle); @@ -347,8 +337,7 @@ static int mtl_st22p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { } dbg(ctx, "%s(%d), st22p_rx_get_frame: %p\n", __func__, s->idx, frame); if (frame->data_size != ctx->packet_size) { - err(ctx, - "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", + err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", __func__, s->idx, frame->data_size, ctx->packet_size); st22p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); @@ -382,8 +371,8 @@ static int mtl_st22_read_packet(AVFormatContext *ctx, AVPacket *pkt) { } dbg(ctx, "%s(%d), st22p_rx_get_frame: %p\n", __func__, s->idx, frame); if (frame->data_size > ctx->packet_size) { - err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (max %u)\n", - __func__, s->idx, frame->data_size, ctx->packet_size); + err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (max %u)\n", __func__, + s->idx, frame->data_size, ctx->packet_size); st22p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); } @@ -398,8 +387,8 @@ static int mtl_st22_read_packet(AVFormatContext *ctx, AVPacket *pkt) { st22p_rx_put_frame(s->rx_handle, frame); pkt->pts = pkt->dts = s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 ", size %d\n", __func__, s->idx, - pkt->pts, pkt->size); + dbg(ctx, "%s(%d), frame counter %" PRId64 ", size %d\n", __func__, s->idx, pkt->pts, + pkt->size); return 0; } @@ -506,7 +495,7 @@ const FFInputFormat ff_mtl_st22p_demuxer = { .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .p.priv_class = &mtl_st22p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st22p_demuxer = #else @@ -524,7 +513,7 @@ AVInputFormat ff_mtl_st22p_demuxer = .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .priv_class = &mtl_st22p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 #ifdef MTL_FFMPEG_7_0 const FFInputFormat ff_mtl_st22_demuxer = { @@ -539,7 +528,7 @@ const FFInputFormat ff_mtl_st22_demuxer = { .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .p.priv_class = &mtl_st22p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st22_demuxer = #else @@ -557,4 +546,4 @@ AVInputFormat ff_mtl_st22_demuxer = .raw_codec_id = AV_CODEC_ID_RAWVIDEO, .priv_class = &mtl_st22p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 diff --git a/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c b/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c index bb15025f7..b472d0ad0 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st22p_tx.c @@ -60,8 +60,7 @@ static int mtl_st22p_write_close(AVFormatContext *ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -100,30 +99,29 @@ static int mtl_st22p_write_header(AVFormatContext *ctx) { s->framerate = ctx->streams[0]->avg_frame_rate; ops_tx.fps = framerate_to_st_fps(s->framerate); if (ops_tx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, - av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); return AVERROR(EINVAL); } s->pixel_format = ctx->streams[0]->codecpar->format; /* transport_fmt is hardcode now */ switch (s->pixel_format) { - case AV_PIX_FMT_YUV422P10LE: - ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; - break; - case AV_PIX_FMT_RGB24: - ops_tx.input_fmt = ST_FRAME_FMT_RGB8; - break; - case AV_PIX_FMT_YUV420P: - ops_tx.input_fmt = ST_FRAME_FMT_YUV420PLANAR8; - break; - default: - err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); - return AVERROR(EINVAL); + case AV_PIX_FMT_YUV422P10LE: + ops_tx.input_fmt = ST_FRAME_FMT_YUV422PLANAR10LE; + break; + case AV_PIX_FMT_RGB24: + ops_tx.input_fmt = ST_FRAME_FMT_RGB8; + break; + case AV_PIX_FMT_YUV420P: + ops_tx.input_fmt = ST_FRAME_FMT_YUV420PLANAR8; + break; + default: + err(ctx, "%s, unsupported pixel format: %d\n", __func__, s->pixel_format); + return AVERROR(EINVAL); } ops_tx.name = "st22p_ffmpeg"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_tx.framebuff_cnt = s->fb_cnt; @@ -200,15 +198,14 @@ static int mtl_st22_write_header(AVFormatContext *ctx) { s->framerate = ctx->streams[0]->avg_frame_rate; ops_tx.fps = framerate_to_st_fps(s->framerate); if (ops_tx.fps == ST_FPS_MAX) { - err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, - av_q2d(s->framerate)); + err(ctx, "%s, frame rate %0.2f is not supported\n", __func__, av_q2d(s->framerate)); return AVERROR(EINVAL); } s->pixel_format = ctx->streams[0]->codecpar->format; ops_tx.name = "st22_ffmpeg"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.device = ST_PLUGIN_DEVICE_AUTO; dbg(ctx, "%s, fb_cnt: %d\n", __func__, s->fb_cnt); ops_tx.framebuff_cnt = s->fb_cnt; @@ -245,8 +242,8 @@ static int mtl_st22p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { struct st_frame *frame; if (pkt->size != s->frame_size) { - err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, - s->idx, pkt->size, s->frame_size); + err(ctx, "%s(%d), unexpected pkt size: %d (%d expected)\n", __func__, s->idx, + pkt->size, s->frame_size); return AVERROR(EIO); } @@ -262,8 +259,7 @@ static int mtl_st22p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { st22p_tx_put_frame(s->tx_handle, frame); s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -272,8 +268,8 @@ static int mtl_st22_write_packet(AVFormatContext *ctx, AVPacket *pkt) { struct st_frame *frame; if (pkt->size > s->frame_size) { - err(ctx, "%s(%d), invalid pkt size: %d (max %d)\n", __func__, s->idx, - pkt->size, s->frame_size); + err(ctx, "%s(%d), invalid pkt size: %d (max %d)\n", __func__, s->idx, pkt->size, + s->frame_size); return AVERROR(EIO); } @@ -289,8 +285,7 @@ static int mtl_st22_write_packet(AVFormatContext *ctx, AVPacket *pkt) { st22p_tx_put_frame(s->tx_handle, frame); s->frame_counter++; - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -309,14 +304,7 @@ static const AVOption mtl_st22p_tx_options[] = { 3, 8, ENC}, - {"bpp", - "bit per pixel", - OFFSET(bpp), - AV_OPT_TYPE_FLOAT, - {.dbl = 3.0}, - 0.1, - 8.0, - ENC}, + {"bpp", "bit per pixel", OFFSET(bpp), AV_OPT_TYPE_FLOAT, {.dbl = 3.0}, 0.1, 8.0, ENC}, {"codec_thread_cnt", "Codec threads count", OFFSET(codec_thread_cnt), diff --git a/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c b/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c index 2f46f2e4d..492b26eae 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st30p_rx.c @@ -64,8 +64,7 @@ static int mtl_st30p_read_close(AVFormatContext *ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -124,9 +123,8 @@ static int mtl_st30p_read_header(AVFormatContext *ctx) { err(ctx, "%s, invalid sample_rate: %d\n", __func__, s->sample_rate); return ret; } - frame_buf_size = - st30_calculate_framebuff_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, - ops_rx.channel, 10 * NS_PER_MS, NULL); + frame_buf_size = st30_calculate_framebuff_size( + ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel, 10 * NS_PER_MS, NULL); ctx->packet_size = frame_buf_size; st = avformat_new_stream(ctx, NULL); @@ -148,7 +146,7 @@ static int mtl_st30p_read_header(AVFormatContext *ctx) { avpriv_set_pts_info(st, 64, 1, 100); ops_rx.name = "st30p_rx_ffmpeg"; - ops_rx.priv = s; // Handle of priv_data registered to lib + ops_rx.priv = s; // Handle of priv_data registered to lib ops_rx.framebuff_cnt = s->fb_cnt; /* set frame size to 10ms time */ ops_rx.framebuff_size = frame_buf_size; @@ -168,8 +166,7 @@ static int mtl_st30p_read_header(AVFormatContext *ctx) { } if (s->timeout_sec) - st30p_rx_set_block_timeout(s->rx_handle, - s->timeout_sec * (uint64_t)NS_PER_S); + st30p_rx_set_block_timeout(s->rx_handle, s->timeout_sec * (uint64_t)NS_PER_S); frame_buf_size = st30p_rx_frame_size(s->rx_handle); if (frame_buf_size != ctx->packet_size) { @@ -204,10 +201,8 @@ static int mtl_st30p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { */ for (int i = 1; i <= s->session_init_retry; i++) { frame = st30p_rx_get_frame(s->rx_handle); - if (frame) - break; - info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, - i); + if (frame) break; + info(ctx, "%s(%d) session initialization retry %d\n", __func__, s->idx, i); } } else frame = st30p_rx_get_frame(s->rx_handle); @@ -218,8 +213,7 @@ static int mtl_st30p_read_packet(AVFormatContext *ctx, AVPacket *pkt) { } dbg(ctx, "%s, st30p_rx_get_frame: %p\n", __func__, frame); if (frame->data_size != ctx->packet_size) { - err(ctx, - "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", + err(ctx, "%s(%d), unexpected frame size received: %" PRId64 " (%u expected)\n", __func__, s->idx, frame->data_size, ctx->packet_size); st30p_rx_put_frame(s->rx_handle, frame); return AVERROR(EIO); @@ -323,7 +317,7 @@ const FFInputFormat ff_mtl_st30p_demuxer = { .p.extensions = "mtl", .p.priv_class = &mtl_st30p_demuxer_class, }; -#else // MTL_FFMPEG_7_0 +#else // MTL_FFMPEG_7_0 #ifndef MTL_FFMPEG_4_4 const AVInputFormat ff_mtl_st30p_demuxer = #else @@ -340,4 +334,4 @@ AVInputFormat ff_mtl_st30p_demuxer = .extensions = "mtl", .priv_class = &mtl_st30p_demuxer_class, }; -#endif // MTL_FFMPEG_7_0 +#endif // MTL_FFMPEG_7_0 diff --git a/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c b/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c index eff321017..c34606c2c 100644 --- a/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c +++ b/ecosystem/ffmpeg_plugin/mtl_st30p_tx.c @@ -65,8 +65,7 @@ static int mtl_st30p_write_close(AVFormatContext *ctx) { s->dev_handle = NULL; } - info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + info(ctx, "%s(%d), frame_counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } @@ -77,8 +76,7 @@ static int mtl_st30p_write_header(AVFormatContext *ctx) { AVCodecParameters *codecpar = ctx->streams[0]->codecpar; if (codecpar->codec_type != AVMEDIA_TYPE_AUDIO) { - err(ctx, "%s, codec_type %d is not audio\n", __func__, - codecpar->codec_type); + err(ctx, "%s, codec_type %d is not audio\n", __func__, codecpar->codec_type); return AVERROR(EINVAL); } @@ -128,12 +126,11 @@ static int mtl_st30p_write_header(AVFormatContext *ctx) { return AVERROR(EINVAL); } - s->frame_size = - st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, - ops_tx.channel, 10 * NS_PER_MS, NULL); + s->frame_size = st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, + ops_tx.channel, 10 * NS_PER_MS, NULL); ops_tx.name = "st30p_ffmpeg"; - ops_tx.priv = s; // Handle of priv_data registered to lib + ops_tx.priv = s; // Handle of priv_data registered to lib ops_tx.framebuff_cnt = s->fb_cnt; ops_tx.framebuff_size = s->frame_size; @@ -186,13 +183,12 @@ static int mtl_st30p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { return AVERROR(EIO); } - dbg(ctx, "%s(%d), pkt size %d frame size %d\n", __func__, s->idx, size, - s->frame_size); + dbg(ctx, "%s(%d), pkt size %d frame size %d\n", __func__, s->idx, size, s->frame_size); while (size > 0) { int left = s->frame_size - s->filled; uint8_t *cur = (uint8_t *)frame->addr + s->filled; - dbg(ctx, "%s(%d), size %d left %d filled %d\n", __func__, s->idx, size, - left, s->filled); + dbg(ctx, "%s(%d), size %d left %d filled %d\n", __func__, s->idx, size, left, + s->filled); if (size < left) { mtl_memcpy(cur, data, size); @@ -206,8 +202,7 @@ static int mtl_st30p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { s->last_frame = NULL; frame = mtl_st30p_fetch_frame(ctx, s); if (!frame) { - info(ctx, "%s(%d), fetch frame timeout, size %d\n", __func__, s->idx, - size); + info(ctx, "%s(%d), fetch frame timeout, size %d\n", __func__, s->idx, size); return AVERROR(EIO); } data += left; @@ -216,8 +211,7 @@ static int mtl_st30p_write_packet(AVFormatContext *ctx, AVPacket *pkt) { } } - dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, - s->frame_counter); + dbg(ctx, "%s(%d), frame counter %" PRId64 "\n", __func__, s->idx, s->frame_counter); return 0; } diff --git a/ecosystem/obs_mtl/linux-mtl/linux-mtl.c b/ecosystem/obs_mtl/linux-mtl/linux-mtl.c index 247a2d248..8d57d59c8 100644 --- a/ecosystem/obs_mtl/linux-mtl/linux-mtl.c +++ b/ecosystem/obs_mtl/linux-mtl/linux-mtl.c @@ -31,36 +31,36 @@ bool obs_module_load(void) { enum st_frame_fmt obs_to_mtl_format(enum video_format fmt) { switch (fmt) { - case VIDEO_FORMAT_UYVY: /* UYVY can be converted from YUV422BE10 */ - return ST_FRAME_FMT_UYVY; - case VIDEO_FORMAT_NV12: - case VIDEO_FORMAT_I420: - return ST_FRAME_FMT_YUV420CUSTOM8; - case VIDEO_FORMAT_YUY2: - case VIDEO_FORMAT_YVYU: - return ST_FRAME_FMT_YUV422CUSTOM8; - default: - return ST_FRAME_FMT_MAX; + case VIDEO_FORMAT_UYVY: /* UYVY can be converted from YUV422BE10 */ + return ST_FRAME_FMT_UYVY; + case VIDEO_FORMAT_NV12: + case VIDEO_FORMAT_I420: + return ST_FRAME_FMT_YUV420CUSTOM8; + case VIDEO_FORMAT_YUY2: + case VIDEO_FORMAT_YVYU: + return ST_FRAME_FMT_YUV422CUSTOM8; + default: + return ST_FRAME_FMT_MAX; } } enum st_fps obs_to_mtl_fps(uint32_t fps_num, uint32_t fps_den) { switch (fps_num) { - case 30000: - return ST_FPS_P29_97; - case 60000: - return ST_FPS_P59_94; - case 30: - return ST_FPS_P30; - case 60: - return ST_FPS_P60; - case 25: - return ST_FPS_P25; - case 24: - return ST_FPS_P24; - case 50: - return ST_FPS_P50; - default: - return ST_FPS_MAX; + case 30000: + return ST_FPS_P29_97; + case 60000: + return ST_FPS_P59_94; + case 30: + return ST_FPS_P30; + case 60: + return ST_FPS_P60; + case 25: + return ST_FPS_P25; + case 24: + return ST_FPS_P24; + case 50: + return ST_FPS_P50; + default: + return ST_FPS_MAX; } } \ No newline at end of file diff --git a/ecosystem/obs_mtl/linux-mtl/linux-mtl.h b/ecosystem/obs_mtl/linux-mtl/linux-mtl.h index b64ac0fff..273bf6358 100644 --- a/ecosystem/obs_mtl/linux-mtl/linux-mtl.h +++ b/ecosystem/obs_mtl/linux-mtl/linux-mtl.h @@ -18,7 +18,7 @@ #include #include -#define timeval2ns(tv) \ +#define timeval2ns(tv) \ (((uint64_t)tv.tv_sec * 1000000000) + ((uint64_t)tv.tv_usec * 1000)) #define blog(level, msg, ...) blog(level, "mtl-input: " msg, ##__VA_ARGS__) diff --git a/ecosystem/obs_mtl/linux-mtl/mtl-input.c b/ecosystem/obs_mtl/linux-mtl/mtl-input.c index aae4448eb..179d99065 100644 --- a/ecosystem/obs_mtl/linux-mtl/mtl-input.c +++ b/ecosystem/obs_mtl/linux-mtl/mtl-input.c @@ -46,8 +46,7 @@ static void mtl_input_update(void *vptr, obs_data_t *settings); /** * Prepare the frame for obs */ -static void mtl_prep_obs_frame(struct mtl_rx_session *s, - struct obs_source_frame *frame, +static void mtl_prep_obs_frame(struct mtl_rx_session *s, struct obs_source_frame *frame, size_t *plane_offsets) { memset(frame, 0, sizeof(struct obs_source_frame)); memset(plane_offsets, 0, sizeof(size_t) * MAX_AV_PLANES); @@ -57,39 +56,37 @@ static void mtl_prep_obs_frame(struct mtl_rx_session *s, frame->width = s->width; frame->height = s->height; frame->format = format; - video_format_get_parameters(VIDEO_CS_DEFAULT, VIDEO_RANGE_DEFAULT, - frame->color_matrix, frame->color_range_min, - frame->color_range_max); + video_format_get_parameters(VIDEO_CS_DEFAULT, VIDEO_RANGE_DEFAULT, frame->color_matrix, + frame->color_range_min, frame->color_range_max); switch (format) { - case VIDEO_FORMAT_I420: - frame->linesize[0] = s->width; - frame->linesize[1] = s->width / 2; - frame->linesize[2] = s->width / 2; - plane_offsets[1] = s->width * s->height; - plane_offsets[2] = s->width * s->height * 5 / 4; - break; - case VIDEO_FORMAT_NV12: - frame->linesize[0] = s->width; - frame->linesize[1] = s->width; - plane_offsets[1] = s->width * s->height; - break; - case VIDEO_FORMAT_UYVY: - case VIDEO_FORMAT_YUY2: - case VIDEO_FORMAT_YVYU: - frame->linesize[0] = s->width * 2; - break; - default: - frame->linesize[0] = s->width * 2; - break; + case VIDEO_FORMAT_I420: + frame->linesize[0] = s->width; + frame->linesize[1] = s->width / 2; + frame->linesize[2] = s->width / 2; + plane_offsets[1] = s->width * s->height; + plane_offsets[2] = s->width * s->height * 5 / 4; + break; + case VIDEO_FORMAT_NV12: + frame->linesize[0] = s->width; + frame->linesize[1] = s->width; + plane_offsets[1] = s->width * s->height; + break; + case VIDEO_FORMAT_UYVY: + case VIDEO_FORMAT_YUY2: + case VIDEO_FORMAT_YVYU: + frame->linesize[0] = s->width * 2; + break; + default: + frame->linesize[0] = s->width * 2; + break; } } static int notify_frame_available(void *priv) { MTL_RX_SESSION(priv); - if (!s->handle) - return -EIO; + if (!s->handle) return -EIO; pthread_mutex_lock(&s->wake_mutex); pthread_cond_signal(&s->wake_cond); @@ -121,8 +118,7 @@ static void *mtl_thread(void *vptr) { frame = st20p_rx_get_frame(handle); if (!frame) { /* no frame */ pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) pthread_cond_wait(&s->wake_cond, &s->wake_mutex); pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -171,22 +167,19 @@ static void mtl_input_defaults(obs_data_t *settings) { * @param ignore ignore this property * @param enable enable/disable all properties */ -static void mtl_props_set_enabled(obs_properties_t *props, - obs_property_t *ignore, bool enable) { - if (!props) - return; +static void mtl_props_set_enabled(obs_properties_t *props, obs_property_t *ignore, + bool enable) { + if (!props) return; for (obs_property_t *prop = obs_properties_first(props); prop != NULL; obs_property_next(&prop)) { - if (prop == ignore) - continue; + if (prop == ignore) continue; obs_property_set_enabled(prop, enable); } } -static bool on_start_clicked(obs_properties_t *ps, obs_property_t *p, - void *vptr) { +static bool on_start_clicked(obs_properties_t *ps, obs_property_t *p, void *vptr) { MTL_RX_SESSION(vptr); mtl_input_init(s); @@ -201,8 +194,7 @@ static bool on_start_clicked(obs_properties_t *ps, obs_property_t *p, return true; } -static bool on_stop_clicked(obs_properties_t *ps, obs_property_t *p, - void *vptr) { +static bool on_stop_clicked(obs_properties_t *ps, obs_property_t *p, void *vptr) { MTL_RX_SESSION(vptr); mtl_input_terminate(s); @@ -222,27 +214,21 @@ static obs_properties_t *mtl_input_properties(void *vptr) { obs_properties_t *props = obs_properties_create(); - obs_properties_add_text(props, "port", obs_module_text("Port"), - OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "port", obs_module_text("Port"), OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), - OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), - OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), OBS_TEXT_DEFAULT); obs_properties_add_text(props, "ip", obs_module_text("IP"), OBS_TEXT_DEFAULT); - obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, - 65536, 1); - obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), - 0, 255, 1); - obs_properties_add_int(props, "framebuffer_cnt", - obs_module_text("FramebuffCnt"), 2, 128, 1); - obs_properties_add_int(props, "width", obs_module_text("Width"), 1, 65535, 1); - obs_properties_add_int(props, "height", obs_module_text("Height"), 1, 65535, + obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, 65536, 1); + obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), 0, 255, 1); - obs_property_t *fps_list = - obs_properties_add_list(props, "fps", obs_module_text("FPS"), - OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); + obs_properties_add_int(props, "framebuffer_cnt", obs_module_text("FramebuffCnt"), 2, + 128, 1); + obs_properties_add_int(props, "width", obs_module_text("Width"), 1, 65535, 1); + obs_properties_add_int(props, "height", obs_module_text("Height"), 1, 65535, 1); + obs_property_t *fps_list = obs_properties_add_list( + props, "fps", obs_module_text("FPS"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(fps_list, obs_module_text("23.98"), ST_FPS_P23_98); obs_property_list_add_int(fps_list, obs_module_text("24"), ST_FPS_P24); obs_property_list_add_int(fps_list, obs_module_text("25"), ST_FPS_P25); @@ -252,13 +238,12 @@ static obs_properties_t *mtl_input_properties(void *vptr) { obs_property_list_add_int(fps_list, obs_module_text("59.94"), ST_FPS_P59_94); obs_property_list_add_int(fps_list, obs_module_text("60"), ST_FPS_P60); obs_property_list_add_int(fps_list, obs_module_text("100"), ST_FPS_P100); - obs_property_list_add_int(fps_list, obs_module_text("119.88"), - ST_FPS_P119_88); + obs_property_list_add_int(fps_list, obs_module_text("119.88"), ST_FPS_P119_88); obs_property_list_add_int(fps_list, obs_module_text("120"), ST_FPS_P120); - obs_property_t *t_fmt_list = obs_properties_add_list( - props, "t_fmt", obs_module_text("TransportFormat"), OBS_COMBO_TYPE_LIST, - OBS_COMBO_FORMAT_INT); + obs_property_t *t_fmt_list = + obs_properties_add_list(props, "t_fmt", obs_module_text("TransportFormat"), + OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_10bit"), ST20_FMT_YUV_422_10BIT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_8bit"), @@ -269,16 +254,11 @@ static obs_properties_t *mtl_input_properties(void *vptr) { obs_property_t *v_fmt_list = obs_properties_add_list(props, "v_fmt", obs_module_text("VideoFormat"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); - obs_property_list_add_int(v_fmt_list, obs_module_text("UYVY"), - VIDEO_FORMAT_UYVY); - obs_property_list_add_int(v_fmt_list, obs_module_text("YUY2"), - VIDEO_FORMAT_YUY2); - obs_property_list_add_int(v_fmt_list, obs_module_text("YVYU"), - VIDEO_FORMAT_YVYU); - obs_property_list_add_int(v_fmt_list, obs_module_text("I420"), - VIDEO_FORMAT_I420); - obs_property_list_add_int(v_fmt_list, obs_module_text("NV12"), - VIDEO_FORMAT_NV12); + obs_property_list_add_int(v_fmt_list, obs_module_text("UYVY"), VIDEO_FORMAT_UYVY); + obs_property_list_add_int(v_fmt_list, obs_module_text("YUY2"), VIDEO_FORMAT_YUY2); + obs_property_list_add_int(v_fmt_list, obs_module_text("YVYU"), VIDEO_FORMAT_YVYU); + obs_property_list_add_int(v_fmt_list, obs_module_text("I420"), VIDEO_FORMAT_I420); + obs_property_list_add_int(v_fmt_list, obs_module_text("NV12"), VIDEO_FORMAT_NV12); obs_property_t *log_level_list = obs_properties_add_list(props, "log_level", obs_module_text("LogLevel"), @@ -289,10 +269,8 @@ static obs_properties_t *mtl_input_properties(void *vptr) { obs_property_list_add_int(log_level_list, "WARNING", MTL_LOG_LEVEL_WARNING); obs_property_list_add_int(log_level_list, "DEBUG", MTL_LOG_LEVEL_DEBUG); - obs_properties_add_button(props, "start", obs_module_text("Start"), - on_start_clicked); - obs_properties_add_button(props, "stop", obs_module_text("Stop"), - on_stop_clicked); + obs_properties_add_button(props, "start", obs_module_text("Start"), on_start_clicked); + obs_properties_add_button(props, "stop", obs_module_text("Stop"), on_stop_clicked); obs_property_t *stop = obs_properties_get(props, "stop"); obs_property_set_enabled(stop, false); @@ -329,8 +307,7 @@ static void mtl_input_terminate(struct mtl_rx_session *s) { static void mtl_input_destroy(void *vptr) { MTL_RX_SESSION(vptr); - if (!s) - return; + if (!s) return; mtl_input_terminate(s); @@ -345,9 +322,9 @@ static void mtl_input_init(struct mtl_rx_session *s) { snprintf(param.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); inet_pton(AF_INET, s->sip, param.sip_addr[MTL_PORT_P]); param.pmd[MTL_PORT_P] = MTL_PMD_DPDK_USER; - param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa - param.log_level = s->log_level; // mtl lib log level - param.priv = s; // usr ctx pointer + param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa + param.log_level = s->log_level; // mtl lib log level + param.priv = s; // usr ctx pointer // user register ptp func, if not register, the internal ptp will be used param.ptp_get_time_fn = NULL; param.tx_queues_cnt[MTL_PORT_P] = 0; @@ -365,11 +342,11 @@ static void mtl_input_init(struct mtl_rx_session *s) { struct st20p_rx_ops ops_rx; memset(&ops_rx, 0, sizeof(ops_rx)); ops_rx.name = "mtl-input"; - ops_rx.priv = s; // app handle register to lib + ops_rx.priv = s; // app handle register to lib ops_rx.port.num_port = 1; inet_pton(AF_INET, s->ip, ops_rx.port.ip_addr[MTL_PORT_P]); snprintf(ops_rx.port.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); - ops_rx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. + ops_rx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. ops_rx.width = s->width; ops_rx.height = s->height; ops_rx.fps = s->fps; diff --git a/ecosystem/obs_mtl/linux-mtl/mtl-output.c b/ecosystem/obs_mtl/linux-mtl/mtl-output.c index 176e677e3..d034a372d 100644 --- a/ecosystem/obs_mtl/linux-mtl/mtl-output.c +++ b/ecosystem/obs_mtl/linux-mtl/mtl-output.c @@ -60,25 +60,21 @@ static obs_properties_t *mtl_output_properties(void *vptr) { obs_properties_t *props = obs_properties_create(); - obs_properties_add_text(props, "port", obs_module_text("Port"), - OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "port", obs_module_text("Port"), OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), - OBS_TEXT_DEFAULT); - obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), - OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "lcores", obs_module_text("Lcores"), OBS_TEXT_DEFAULT); + obs_properties_add_text(props, "sip", obs_module_text("InterfaceIP"), OBS_TEXT_DEFAULT); obs_properties_add_text(props, "ip", obs_module_text("IP"), OBS_TEXT_DEFAULT); - obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, - 65536, 1); - obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), - 0, 255, 1); - obs_properties_add_int(props, "framebuffer_cnt", - obs_module_text("FramebuffCnt"), 2, 128, 1); + obs_properties_add_int(props, "udp_port", obs_module_text("UdpPort"), 1000, 65536, 1); + obs_properties_add_int(props, "payload_type", obs_module_text("PayloadType"), 0, 255, + 1); + obs_properties_add_int(props, "framebuffer_cnt", obs_module_text("FramebuffCnt"), 2, + 128, 1); - obs_property_t *t_fmt_list = obs_properties_add_list( - props, "t_fmt", obs_module_text("TransportFormat"), OBS_COMBO_TYPE_LIST, - OBS_COMBO_FORMAT_INT); + obs_property_t *t_fmt_list = + obs_properties_add_list(props, "t_fmt", obs_module_text("TransportFormat"), + OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_10bit"), ST20_FMT_YUV_422_10BIT); obs_property_list_add_int(t_fmt_list, obs_module_text("YUV422_8bit"), @@ -120,8 +116,7 @@ static void mtl_output_terminate(struct mtl_tx_session *s) { static void mtl_output_destroy(void *vptr) { MTL_TX_SESSION(vptr); - if (!s) - return; + if (!s) return; mtl_output_terminate(s); @@ -136,9 +131,9 @@ static void mtl_output_init(struct mtl_tx_session *s) { snprintf(param.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); inet_pton(AF_INET, s->sip, param.sip_addr[MTL_PORT_P]); param.pmd[MTL_PORT_P] = MTL_PMD_DPDK_USER; - param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa - param.log_level = s->log_level; // mtl lib log level - param.priv = s; // usr ctx pointer + param.flags = MTL_FLAG_BIND_NUMA; // default bind to numa + param.log_level = s->log_level; // mtl lib log level + param.priv = s; // usr ctx pointer // user register ptp func, if not register, the internal ptp will be used param.ptp_get_time_fn = NULL; param.tx_queues_cnt[MTL_PORT_P] = 1; @@ -159,11 +154,11 @@ static void mtl_output_init(struct mtl_tx_session *s) { struct st20p_tx_ops ops_tx; memset(&ops_tx, 0, sizeof(ops_tx)); ops_tx.name = "mtl-input"; - ops_tx.priv = s; // app handle register to lib + ops_tx.priv = s; // app handle register to lib ops_tx.port.num_port = 1; inet_pton(AF_INET, s->ip, ops_tx.port.dip_addr[MTL_PORT_P]); snprintf(ops_tx.port.port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", s->port); - ops_tx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. + ops_tx.port.udp_port[MTL_PORT_P] = s->udp_port; // user config the udp port. ops_tx.width = vo_info->width; ops_tx.height = vo_info->height; ops_tx.fps = obs_to_mtl_fps(vo_info->fps_num, vo_info->fps_den); @@ -217,15 +212,12 @@ static void mtl_output_video_frame(void *vptr, struct video_data *obs_frame) { struct st_frame *frame; size_t data_size = 0; frame = st20p_tx_get_frame(handle); - if (!frame) - return; + if (!frame) return; uint8_t planes = st_frame_fmt_planes(frame->fmt); - for (uint8_t plane = 0; plane < planes; - plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ size_t plane_size = - st_frame_least_linesize(frame->fmt, frame->width, plane) * - frame->height; + st_frame_least_linesize(frame->fmt, frame->width, plane) * frame->height; mtl_memcpy(frame->addr[plane], obs_frame->data[plane], plane_size); data_size += plane_size; } diff --git a/format-coding.sh b/format-coding.sh index 5f3b51def..640307e3a 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -8,10 +8,16 @@ set -e +# copy .clang-format to the cwd for linting process +cp .github/linters/.clang-format .clang-format + echo "clang-format check" find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' \ - ! -name 'vmlinux.h' -exec clang-format -i --style=file ".github/linters/.clang-format" --verbose {} + + ! -name 'vmlinux.h' ! -name '.clang-format' \ + -exec clang-format-17 --verbose -i {} + +# clean-up the copied .clang-format +rm -rf .clang-format # CONFIG=".github/linters/.pyproject.toml" # black --config "$CONFIG" python/ # isort --settings-path "$CONFIG" python/ diff --git a/include/experimental/st20_combined_api.h b/include/experimental/st20_combined_api.h index 0ba39564d..cd1062cdc 100644 --- a/include/experimental/st20_combined_api.h +++ b/include/experimental/st20_combined_api.h @@ -70,9 +70,8 @@ struct st20rc_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t - sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** num of ports this session attached to, must be 2 */ uint8_t num_port; @@ -124,8 +123,7 @@ struct st20rc_rx_ops { * And only non-block method can be used in this callback as it run from lcore * tasklet routine. */ - int (*notify_frame_ready)(void *priv, void *frame, - struct st20_rx_frame_meta *meta); + int (*notify_frame_ready)(void *priv, void *frame, struct st20_rx_frame_meta *meta); /** * event callback, lib will call this when there is some event happened. * Only non-block method can be used in this callback as it run from lcore @@ -210,8 +208,8 @@ int st20rc_rx_get_framebuffer_count(st20rc_rx_handle handle); * - 0: Success, rx st2110-20(redundant) session pcapng dump succ. * - <0: Error code of the rx st2110-20(redundant) session pcapng dump. */ -int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta); +int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta); #if defined(__cplusplus) } diff --git a/include/mtl_api.h b/include/mtl_api.h index 4bc2eee2d..ada36d25b 100644 --- a/include/mtl_api.h +++ b/include/mtl_api.h @@ -34,7 +34,7 @@ extern "C" { #endif #ifdef _MSC_VER -#define MTL_PACK(__Declaration__) \ +#define MTL_PACK(__Declaration__) \ __pragma(pack(push, 1)) __Declaration__ __pragma(pack(pop)) #endif @@ -45,7 +45,7 @@ extern "C" { /** * All version numbers in one to compare with ST_VERSION_NUM() */ -#define MTL_VERSION \ +#define MTL_VERSION \ MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR, MTL_VERSION_LAST) /** @@ -204,8 +204,7 @@ enum mtl_log_level { typedef void (*mtl_log_prefix_formatter_t)(char *buf, size_t buf_sz); /* log printer, similar to printf */ -typedef void (*mtl_log_printer_t)(enum mtl_log_level level, const char *format, - ...); +typedef void (*mtl_log_printer_t)(enum mtl_log_level level, const char *format, ...); /** * Poll mode driver type, not change the enum value any more if one PMD type is @@ -701,8 +700,7 @@ struct mtl_init_params { #ifdef __MTL_LIB_BUILD__ uint16_t tx_sessions_cnt_max; #else - uint16_t - tx_sessions_cnt_max __mtl_deprecated_msg("Use tx_queues_cnt instead"); + uint16_t tx_sessions_cnt_max __mtl_deprecated_msg("Use tx_queues_cnt instead"); #endif /** * deprecated for MTL_TRANSPORT_ST2110. @@ -714,8 +712,7 @@ struct mtl_init_params { #ifdef __MTL_LIB_BUILD__ uint16_t rx_sessions_cnt_max; #else - uint16_t - rx_sessions_cnt_max __mtl_deprecated_msg("Use rx_queues_cnt instead"); + uint16_t rx_sessions_cnt_max __mtl_deprecated_msg("Use rx_queues_cnt instead"); #endif }; @@ -807,8 +804,7 @@ int mtl_get_var_info(mtl_handle mt, struct mtl_var_info *info); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, - struct mtl_port_status *stats); +int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status *stats); /** * Reset the general statistics(I/O) for a MTL port. @@ -837,40 +833,33 @@ int mtl_reset_port_stats(mtl_handle mt, enum mtl_port port); int mtl_get_numa_id(mtl_handle mt, enum mtl_port port); /** Helper to set the port for struct mtl_init_params */ -int mtl_para_port_set(struct mtl_init_params *p, enum mtl_port port, - char *name); +int mtl_para_port_set(struct mtl_init_params *p, enum mtl_port port, char *name); /** Helper to set the sip for struct mtl_init_params */ int mtl_para_sip_set(struct mtl_init_params *p, enum mtl_port port, char *ip); /** Helper to set the gateway for struct mtl_init_params */ -int mtl_para_gateway_set(struct mtl_init_params *p, enum mtl_port port, - char *gateway); +int mtl_para_gateway_set(struct mtl_init_params *p, enum mtl_port port, char *gateway); /** Helper to set the netmask for struct mtl_init_params */ -int mtl_para_netmask_set(struct mtl_init_params *p, enum mtl_port port, - char *netmask); +int mtl_para_netmask_set(struct mtl_init_params *p, enum mtl_port port, char *netmask); /** Helper to set the dma dev port for struct mtl_init_params */ -int mtl_para_dma_port_set(struct mtl_init_params *p, enum mtl_port port, - char *name); +int mtl_para_dma_port_set(struct mtl_init_params *p, enum mtl_port port, char *name); /** Helper to set the tx queues number for struct mtl_init_params */ static inline void mtl_para_tx_queues_cnt_set(struct mtl_init_params *p, - enum mtl_port port, - uint16_t cnt) { + enum mtl_port port, uint16_t cnt) { p->tx_queues_cnt[port] = cnt; } /** Helper to set the rx queues number for struct mtl_init_params */ static inline void mtl_para_rx_queues_cnt_set(struct mtl_init_params *p, - enum mtl_port port, - uint16_t cnt) { + enum mtl_port port, uint16_t cnt) { p->rx_queues_cnt[port] = cnt; } /** Helper to set the PMD type for struct mtl_init_params */ -static inline void mtl_para_pmd_set(struct mtl_init_params *p, - enum mtl_port port, enum mtl_pmd_type pmd) { +static inline void mtl_para_pmd_set(struct mtl_init_params *p, enum mtl_port port, + enum mtl_pmd_type pmd) { p->pmd[port] = pmd; } /** Helper to get the port from struct mtl_init_params */ -static inline char *mtl_para_port_get(struct mtl_init_params *p, - enum mtl_port port) { +static inline char *mtl_para_port_get(struct mtl_init_params *p, enum mtl_port port) { return p->port[port]; } @@ -1295,8 +1284,7 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void *vaddr, size_t size); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_dma_unmap(mtl_handle mt, const void *vaddr, mtl_iova_t iova, - size_t size); +int mtl_dma_unmap(mtl_handle mt, const void *vaddr, mtl_iova_t iova, size_t size); /** * Allocate memory block more than required and map valid data to IOVA. @@ -1368,8 +1356,7 @@ mtl_iova_t mtl_dma_mem_iova(mtl_dma_mem_handle handle); * - NULL on error. * - Otherwise, the handle to the st user dma dev. */ -mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, - enum mtl_port port); +mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, enum mtl_port port); /** * Free the st user dma dev. @@ -1513,10 +1500,8 @@ enum mtl_iova_mode mtl_iova_mode_get(mtl_handle mt); * - 0: Success. * - <0: Error code. */ -int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, - uint8_t ip[MTL_IP_ADDR_LEN], - uint8_t netmask[MTL_IP_ADDR_LEN], - uint8_t gateway[MTL_IP_ADDR_LEN]); +int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, uint8_t ip[MTL_IP_ADDR_LEN], + uint8_t netmask[MTL_IP_ADDR_LEN], uint8_t gateway[MTL_IP_ADDR_LEN]); /** * Check if the pmd of one mtl port is dpdk based or not. @@ -1612,8 +1597,7 @@ int mtl_thread_setname(pthread_t tid, const char *name); * The aligned size. */ static inline size_t mtl_size_page_align(size_t sz, size_t pg_sz) { - if (sz % pg_sz) - sz += pg_sz - (sz % pg_sz); + if (sz % pg_sz) sz += pg_sz - (sz % pg_sz); return sz; } diff --git a/include/mtl_lcore_shm_api.h b/include/mtl_lcore_shm_api.h index a7a2adbb4..1c4d9bbb1 100644 --- a/include/mtl_lcore_shm_api.h +++ b/include/mtl_lcore_shm_api.h @@ -56,8 +56,7 @@ int mtl_lcore_shm_print(void); * - 0 if successful. * - <0: Error code if fail. */ -int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void *args, - size_t args_sz); +int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void *args, size_t args_sz); #if defined(__cplusplus) } diff --git a/include/mtl_sch_api.h b/include/mtl_sch_api.h index 6e86df85a..bd8979ec7 100644 --- a/include/mtl_sch_api.h +++ b/include/mtl_sch_api.h @@ -127,9 +127,8 @@ int mtl_sch_free(mtl_sch_handle sch); * - NULL on error. * - Otherwise, the handle to the tasklet. */ -mtl_tasklet_handle -mtl_sch_register_tasklet(struct mtl_sch_impl *sch, - struct mtl_tasklet_ops *tasklet_ops); +mtl_tasklet_handle mtl_sch_register_tasklet(struct mtl_sch_impl *sch, + struct mtl_tasklet_ops *tasklet_ops); /** * Unregister the tasklet from the bind sch. One tasklet can be unregistered at diff --git a/include/mudp_api.h b/include/mudp_api.h index 0e22f97ec..3940b2de7 100644 --- a/include/mudp_api.h +++ b/include/mudp_api.h @@ -184,8 +184,7 @@ ssize_t mudp_recvfrom(mudp_handle ut, void *buf, size_t len, int flags, * - >0: the number of bytes received. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -static inline ssize_t mudp_recv(mudp_handle ut, void *buf, size_t len, - int flags) { +static inline ssize_t mudp_recv(mudp_handle ut, void *buf, size_t len, int flags) { return mudp_recvfrom(ut, buf, len, flags, NULL, NULL); } @@ -470,8 +469,7 @@ int mudp_tx_valid_ip(mudp_handle ut, uint8_t dip[MTL_IP_ADDR_LEN]); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void *priv), - void *priv); +int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void *priv), void *priv); /** * Create a udp transport socket on a PCIE port. @@ -501,8 +499,7 @@ mudp_handle mudp_socket_port(mtl_handle mt, int domain, int type, int protocol, * @param port * UDP port. */ -static void inline mudp_init_sockaddr_any(struct sockaddr_in *saddr, - uint16_t port) { +static void inline mudp_init_sockaddr_any(struct sockaddr_in *saddr, uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; saddr->sin_addr.s_addr = INADDR_ANY; @@ -520,8 +517,7 @@ static void inline mudp_init_sockaddr_any(struct sockaddr_in *saddr, * UDP port. */ static void inline mudp_init_sockaddr(struct sockaddr_in *saddr, - uint8_t ip[MTL_IP_ADDR_LEN], - uint16_t port) { + uint8_t ip[MTL_IP_ADDR_LEN], uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; memcpy(&saddr->sin_addr.s_addr, ip, MTL_IP_ADDR_LEN); diff --git a/include/mudp_sockfd_api.h b/include/mudp_sockfd_api.h index 378613088..d0aea7c61 100644 --- a/include/mudp_sockfd_api.h +++ b/include/mudp_sockfd_api.h @@ -205,8 +205,7 @@ ssize_t mufd_recvmsg(int sockfd, struct msghdr *msg, int flags); * - 0: Success. * - <0: Error code. -1 is returned, and errno is set appropriately. */ -int mufd_getsockopt(int sockfd, int level, int optname, void *optval, - socklen_t *optlen); +int mufd_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); /** * setsockopt on the udp transport socket. @@ -328,8 +327,7 @@ uint64_t mufd_get_tx_rate(int sockfd); * - <0: Error code. */ int mufd_port_ip_info(enum mtl_port port, uint8_t ip[MTL_IP_ADDR_LEN], - uint8_t netmask[MTL_IP_ADDR_LEN], - uint8_t gateway[MTL_IP_ADDR_LEN]); + uint8_t netmask[MTL_IP_ADDR_LEN], uint8_t gateway[MTL_IP_ADDR_LEN]); /** * Create a sockfd udp transport socket on one PCIE port. @@ -356,8 +354,7 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port); * @param port * UDP port. */ -static void inline mufd_init_sockaddr_any(struct sockaddr_in *saddr, - uint16_t port) { +static void inline mufd_init_sockaddr_any(struct sockaddr_in *saddr, uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; saddr->sin_addr.s_addr = INADDR_ANY; @@ -375,8 +372,7 @@ static void inline mufd_init_sockaddr_any(struct sockaddr_in *saddr, * UDP port. */ static void inline mufd_init_sockaddr(struct sockaddr_in *saddr, - uint8_t ip[MTL_IP_ADDR_LEN], - uint16_t port) { + uint8_t ip[MTL_IP_ADDR_LEN], uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; memcpy(&saddr->sin_addr.s_addr, ip, MTL_IP_ADDR_LEN); diff --git a/include/mudp_win.h b/include/mudp_win.h index 5655c47b6..488e86aa6 100644 --- a/include/mudp_win.h +++ b/include/mudp_win.h @@ -57,20 +57,18 @@ struct cmsghdr { int cmsg_type; }; -#define CMSGDATA_ALIGN(length) \ +#define CMSGDATA_ALIGN(length) \ (((length) + MAX_NATURAL_ALIGNMENT - 1) & (~(MAX_NATURAL_ALIGNMENT - 1))) -#define CMSG_FIRSTHDR(msg) \ - (((msg)->msg_controllen >= sizeof(struct cmsghdr)) ? (msg)->msg_control \ - : NULL) +#define CMSG_FIRSTHDR(msg) \ + (((msg)->msg_controllen >= sizeof(struct cmsghdr)) ? (msg)->msg_control : NULL) #define CMSG_LEN(length) (CMSGDATA_ALIGN(sizeof(struct cmsghdr)) + length) #ifdef CMSG_DATA #undef CMSG_DATA #endif -#define CMSG_DATA(cmsg) \ - ((PUCHAR)(cmsg) + CMSGDATA_ALIGN(sizeof(struct cmsghdr))) +#define CMSG_DATA(cmsg) ((PUCHAR)(cmsg) + CMSGDATA_ALIGN(sizeof(struct cmsghdr))) #ifndef SOCK_NONBLOCK #define SOCK_NONBLOCK (0x800) diff --git a/include/st20_api.h b/include/st20_api.h index a465ba798..4fe5459e6 100644 --- a/include/st20_api.h +++ b/include/st20_api.h @@ -1459,9 +1459,8 @@ struct st20_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t - sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -1530,8 +1529,7 @@ struct st20_rx_ops { * then. And only non-block method can be used in this callback as it run from * lcore tasklet routine. */ - int (*notify_frame_ready)(void *priv, void *frame, - struct st20_rx_frame_meta *meta); + int (*notify_frame_ready)(void *priv, void *frame, struct st20_rx_frame_meta *meta); /** * Optional. the ST20_TYPE_FRAME_LEVEL external frame buffer info array, @@ -1573,8 +1571,7 @@ struct st20_rx_ops { * And only non-block method can be used in this callback as it run from lcore * tasklet routine. */ - int (*uframe_pg_callback)(void *priv, void *frame, - struct st20_rx_uframe_pg_meta *meta); + int (*uframe_pg_callback)(void *priv, void *frame, struct st20_rx_uframe_pg_meta *meta); /** * Optional for ST20_TYPE_FRAME_LEVEL/ST20_TYPE_SLICE_LEVEL with * ST20_RX_FLAG_AUTO_DETECT. The callback when lib detected video format. And @@ -1599,8 +1596,7 @@ struct st20_rx_ops { * And only non-block method can be used in this callback as it run from lcore * tasklet routine. */ - int (*notify_slice_ready)(void *priv, void *frame, - struct st20_rx_slice_meta *meta); + int (*notify_slice_ready)(void *priv, void *frame, struct st20_rx_slice_meta *meta); /** Mandatory for ST20_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ @@ -1625,9 +1621,8 @@ struct st22_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t - sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -1696,8 +1691,7 @@ struct st22_rx_ops { * ST22_TYPE_FRAME_LEVEL. And only non-block method can be used in this * callback as it run from lcore tasklet routine. */ - int (*notify_frame_ready)(void *priv, void *frame, - struct st22_rx_frame_meta *meta); + int (*notify_frame_ready)(void *priv, void *frame, struct st22_rx_frame_meta *meta); /** * Optional. The event callback when there is some event(vsync or others) @@ -1787,8 +1781,7 @@ int st20_tx_free(st20_tx_handle handle); * - 0: Success, tx st2110-20(video) session destination update succ. * - <0: Error code of the rx st2110-20(video) session destination update. */ -int st20_tx_update_destination(st20_tx_handle handle, - struct st_tx_dest_info *dst); +int st20_tx_update_destination(st20_tx_handle handle, struct st_tx_dest_info *dst); /** * Set the frame virtual address and iova from user for the tx st2110-20(video) @@ -1961,8 +1954,8 @@ size_t st20_frame_size(enum st20_fmt fmt, uint32_t width, uint32_t height); * - 0 if successful. * - <0: Error code if fail. */ -int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, - enum st_fps fps, bool interlaced, uint64_t *bps); +int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, enum st_fps fps, + bool interlaced, uint64_t *bps); /** * Inline function returning bandwidth(mega per second) for 1080 p59 yuv422 @@ -1972,8 +1965,7 @@ int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, */ static inline uint64_t st20_1080p59_yuv422_10bit_bandwidth_mps(void) { uint64_t bps; - st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, - false, &bps); + st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, false, &bps); return bps / 1000 / 1000; } @@ -2005,8 +1997,7 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops); * - <0: Error code of the rx st2110-22(compressed video) session destination * update. */ -int st22_tx_update_destination(st22_tx_handle handle, - struct st_tx_dest_info *dst); +int st22_tx_update_destination(st22_tx_handle handle, struct st_tx_dest_info *dst); /** * Free the tx st2110-22(compressed video) session. @@ -2131,8 +2122,8 @@ int st20_rx_get_sch_idx(st20_rx_handle handle); * - 0: Success, rx st2110-20(video) session pcapng dump succ. * - <0: Error code of the rx st2110-20(video) session pcapng dump. */ -int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta); +int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta); /** * Free the rx st2110-20(video) session. @@ -2243,8 +2234,7 @@ bool st20_rx_dma_enabled(st20_rx_handle handle); * - 0: Success. * - <0: Error code. */ -int st20_rx_timing_parser_critical(st20_rx_handle handle, - struct st20_rx_tp_pass *pass); +int st20_rx_timing_parser_critical(st20_rx_handle handle, struct st20_rx_tp_pass *pass); /** * Retrieve the general statistics(I/O) for one rx st2110-20(video) session @@ -2332,8 +2322,8 @@ int st22_rx_get_sch_idx(st22_rx_handle handle); * - 0: Success, rx st2110-22 session pcapng dump succ. * - <0: Error code of the rx st2110-22 session pcapng dump. */ -int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta); +int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta); /** * Free the rx st2110-22(compressed video) session. diff --git a/include/st30_api.h b/include/st30_api.h index 3897f4b17..058a36b79 100644 --- a/include/st30_api.h +++ b/include/st30_api.h @@ -441,9 +441,8 @@ struct st30_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t - sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -501,8 +500,7 @@ struct st30_rx_ops { * then. And only non-block method can be used in this callback as it run from * lcore tasklet routine. */ - int (*notify_frame_ready)(void *priv, void *frame, - struct st30_rx_frame_meta *meta); + int (*notify_frame_ready)(void *priv, void *frame, struct st30_rx_frame_meta *meta); /** Mandatory for ST30_TYPE_RTP_LEVEL. rtp ring queue size, must be power of 2 */ @@ -573,8 +571,7 @@ int st30_tx_free(st30_tx_handle handle); * - 0: Success, tx st2110-30(audio) session destination update succ. * - <0: Error code of the rx st2110-30(audio) session destination update. */ -int st30_tx_update_destination(st30_tx_handle handle, - struct st_tx_dest_info *dst); +int st30_tx_update_destination(st30_tx_handle handle, struct st_tx_dest_info *dst); /** * Get the framebuffer pointer from the tx st2110-30(audio) session. diff --git a/include/st30_pipeline_api.h b/include/st30_pipeline_api.h index e7f734181..3f66a8ae6 100644 --- a/include/st30_pipeline_api.h +++ b/include/st30_pipeline_api.h @@ -166,8 +166,7 @@ int st30p_tx_free(st30p_tx_handle handle); st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops *ops); /** Online update the destination info for the tx st2110-30(pipeline) session. */ -int st30p_tx_update_destination(st30p_tx_handle handle, - struct st_tx_dest_info *dst); +int st30p_tx_update_destination(st30p_tx_handle handle, struct st_tx_dest_info *dst); /** Wake up the block wait on st30p_tx_get_frame if ST30P_TX_FLAG_BLOCK_GET is * enabled.*/ int st30p_tx_wake_block(st30p_tx_handle handle); diff --git a/include/st40_api.h b/include/st40_api.h index 381b23765..0301bee31 100644 --- a/include/st40_api.h +++ b/include/st40_api.h @@ -321,9 +321,8 @@ struct st40_rx_ops { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t - sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -398,8 +397,7 @@ int st40_tx_free(st40_tx_handle handle); * - 0: Success, tx st2110-40(ancillary) session destination update succ. * - <0: Error code of the rx st2110-40(ancillary) session destination update. */ -int st40_tx_update_destination(st40_tx_handle handle, - struct st_tx_dest_info *dst); +int st40_tx_update_destination(st40_tx_handle handle, struct st_tx_dest_info *dst); /** * Get the framebuffer pointer from the tx st2110-40(ancillary) session. diff --git a/include/st_api.h b/include/st_api.h index a6488b4bf..9ae00035e 100644 --- a/include/st_api.h +++ b/include/st_api.h @@ -159,9 +159,8 @@ struct st_rx_source_info { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t - sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** UDP port number */ uint16_t udp_port[MTL_SESSION_PORT_MAX]; @@ -262,8 +261,7 @@ int st_get_var_info(mtl_handle mt, struct st_var_info *info); * Complete or not. */ static inline bool st_is_frame_complete(enum st_frame_status status) { - if ((status == ST_FRAME_STATUS_COMPLETE) || - (status == ST_FRAME_STATUS_RECONSTRUCTED)) + if ((status == ST_FRAME_STATUS_COMPLETE) || (status == ST_FRAME_STATUS_RECONSTRUCTED)) return true; else return false; @@ -338,11 +336,9 @@ uint64_t st10_media_clk_to_ns(uint32_t media_ts, uint32_t sampling_rate); * @return * time in nanoseconds since the TAI epoch. */ -static inline uint64_t st10_get_tai(enum st10_timestamp_fmt tfmt, - uint64_t timestamp, +static inline uint64_t st10_get_tai(enum st10_timestamp_fmt tfmt, uint64_t timestamp, uint32_t sampling_rate) { - if (tfmt == ST10_TIMESTAMP_FMT_TAI) - return timestamp; + if (tfmt == ST10_TIMESTAMP_FMT_TAI) return timestamp; return st10_media_clk_to_ns((uint32_t)timestamp, sampling_rate); } @@ -361,10 +357,8 @@ static inline uint64_t st10_get_tai(enum st10_timestamp_fmt tfmt, * sampling_rate. */ static inline uint32_t st10_get_media_clk(enum st10_timestamp_fmt tfmt, - uint64_t timestamp, - uint32_t sampling_rate) { - if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) - return (uint32_t)timestamp; + uint64_t timestamp, uint32_t sampling_rate) { + if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) return (uint32_t)timestamp; return st10_tai_to_media_clk(timestamp, sampling_rate); } @@ -384,10 +378,8 @@ static inline uint16_t st_tx_sessions_queue_cnt(uint16_t st20_sessions, uint16_t st30_sessions, uint16_t st40_sessions) { uint16_t queues = st20_sessions; - if (st30_sessions) - queues++; - if (st40_sessions) - queues++; + if (st30_sessions) queues++; + if (st40_sessions) queues++; return queues; } diff --git a/include/st_convert_api.h b/include/st_convert_api.h index 9198b37d3..fa89f7d6b 100644 --- a/include/st_convert_api.h +++ b/include/st_convert_api.h @@ -38,24 +38,22 @@ extern "C" { * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_be *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p10le_simd(pg, y, b, r, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_yuv422p10le( + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p10le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** helper to call st20_rfc4175_422be10_to_yuv422p10le with mtl_cpuva_t type for * python binding */ -static inline int -st20_rfc4175_422be10_to_yuv422p10le_cpuva(mtl_cpuva_t pg_be, mtl_cpuva_t y, - mtl_cpuva_t b, mtl_cpuva_t r, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p10le( - (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint16_t *)y, (uint16_t *)b, - (uint16_t *)r, w, h); +static inline int st20_rfc4175_422be10_to_yuv422p10le_cpuva(mtl_cpuva_t pg_be, + mtl_cpuva_t y, mtl_cpuva_t b, + mtl_cpuva_t r, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p10le((struct st20_rfc4175_422_10_pg2_be *)pg_be, + (uint16_t *)y, (uint16_t *)b, (uint16_t *)r, + w, h); } /** @@ -73,12 +71,10 @@ st20_rfc4175_422be10_to_yuv422p10le_cpuva(mtl_cpuva_t pg_be, mtl_cpuva_t y, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_422le10(struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_422le10( + struct st20_rfc4175_422_10_pg2_be *pg_be, struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -97,21 +93,19 @@ st20_rfc4175_422be10_to_422le10(struct st20_rfc4175_422_10_pg2_be *pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_v210(struct st20_rfc4175_422_10_pg2_be *pg_be, - uint8_t *pg_v210, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_v210_simd(pg_be, pg_v210, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_v210(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_v210_simd(pg_be, pg_v210, w, h, MTL_SIMD_LEVEL_MAX); } /** helper to call st20_rfc4175_422be10_to_v210 with mtl_cpuva_t type for python * binding */ static inline int st20_rfc4175_422be10_to_v210_cpuva(mtl_cpuva_t pg_be, - mtl_cpuva_t pg_v210, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_v210( - (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint8_t *)pg_v210, w, h); + mtl_cpuva_t pg_v210, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_v210((struct st20_rfc4175_422_10_pg2_be *)pg_be, + (uint8_t *)pg_v210, w, h); } /** @@ -130,12 +124,10 @@ static inline int st20_rfc4175_422be10_to_v210_cpuva(mtl_cpuva_t pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_422le8(struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_422le8_simd(pg_10, pg_8, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_422le8(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_422le8_simd(pg_10, pg_8, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -157,12 +149,10 @@ st20_rfc4175_422be10_to_422le8(struct st20_rfc4175_422_10_pg2_be *pg_10, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_yuv422p8(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p8_simd(pg, y, b, r, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_yuv422p8(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p8_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -184,12 +174,10 @@ st20_rfc4175_422be10_to_yuv422p8(struct st20_rfc4175_422_10_pg2_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_yuv420p8(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_yuv420p8_simd(pg, y, b, r, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_yuv420p8(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_yuv420p8_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -211,12 +199,10 @@ st20_rfc4175_422be10_to_yuv420p8(struct st20_rfc4175_422_10_pg2_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_be *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be12_to_yuv422p12le_simd(pg, y, b, r, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be12_to_yuv422p12le( + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be12_to_yuv422p12le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -234,12 +220,10 @@ st20_rfc4175_422be12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be12_to_422le12(struct st20_rfc4175_422_12_pg2_be *pg_be, - struct st20_rfc4175_422_12_pg2_le *pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_422be12_to_422le12_simd(pg_be, pg_le, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be12_to_422le12( + struct st20_rfc4175_422_12_pg2_be *pg_be, struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_422be12_to_422le12_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -261,12 +245,10 @@ st20_rfc4175_422be12_to_422le12(struct st20_rfc4175_422_12_pg2_be *pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444be10_to_yuv444p10le(struct st20_rfc4175_444_10_pg4_be *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be10_to_444p10le_simd(pg, y, b, r, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444be10_to_yuv444p10le( + struct st20_rfc4175_444_10_pg4_be *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be10_to_444p10le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -288,12 +270,10 @@ st20_rfc4175_444be10_to_yuv444p10le(struct st20_rfc4175_444_10_pg4_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444be10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_be *pg, - uint16_t *g, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be10_to_444p10le_simd(pg, g, r, b, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444be10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_be *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be10_to_444p10le_simd(pg, g, r, b, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -311,12 +291,10 @@ st20_rfc4175_444be10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444be10_to_444le10(struct st20_rfc4175_444_10_pg4_be *pg_be, - struct st20_rfc4175_444_10_pg4_le *pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be10_to_444le10_simd(pg_be, pg_le, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444be10_to_444le10( + struct st20_rfc4175_444_10_pg4_be *pg_be, struct st20_rfc4175_444_10_pg4_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be10_to_444le10_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -338,12 +316,10 @@ st20_rfc4175_444be10_to_444le10(struct st20_rfc4175_444_10_pg4_be *pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444be12_to_yuv444p12le(struct st20_rfc4175_444_12_pg2_be *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be12_to_444p12le_simd(pg, y, b, r, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444be12_to_yuv444p12le( + struct st20_rfc4175_444_12_pg2_be *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be12_to_444p12le_simd(pg, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -365,12 +341,10 @@ st20_rfc4175_444be12_to_yuv444p12le(struct st20_rfc4175_444_12_pg2_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444be12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_be *pg, - uint16_t *g, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be12_to_444p12le_simd(pg, g, r, b, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444be12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_be *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be12_to_444p12le_simd(pg, g, r, b, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -388,12 +362,10 @@ st20_rfc4175_444be12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444be12_to_444le12(struct st20_rfc4175_444_12_pg2_be *pg_be, - struct st20_rfc4175_444_12_pg2_le *pg_le, - uint32_t w, uint32_t h) { - return st20_rfc4175_444be12_to_444le12_simd(pg_be, pg_le, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444be12_to_444le12( + struct st20_rfc4175_444_12_pg2_be *pg_be, struct st20_rfc4175_444_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { + return st20_rfc4175_444be12_to_444le12_simd(pg_be, pg_le, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -415,12 +387,10 @@ st20_rfc4175_444be12_to_444le12(struct st20_rfc4175_444_12_pg2_be *pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_yuv422p10le_to_rfc4175_422be10(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, - uint32_t w, uint32_t h) { - return st20_yuv422p10le_to_rfc4175_422be10_simd(y, b, r, pg, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_yuv422p10le_to_rfc4175_422be10( + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_yuv422p10le_to_rfc4175_422be10_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -439,12 +409,10 @@ st20_yuv422p10le_to_rfc4175_422be10(uint16_t *y, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_v210_to_rfc4175_422be10(uint8_t *pg_v210, - struct st20_rfc4175_422_10_pg2_be *pg_be, - uint32_t w, uint32_t h) { - return st20_v210_to_rfc4175_422be10_simd(pg_v210, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_v210_to_rfc4175_422be10(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_v210_to_rfc4175_422be10_simd(pg_v210, pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -462,12 +430,10 @@ st20_v210_to_rfc4175_422be10(uint8_t *pg_v210, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422le10_to_422be10(struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422le10_to_422be10( + struct st20_rfc4175_422_10_pg2_le *pg_le, struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -490,8 +456,8 @@ st20_rfc4175_422le10_to_422be10(struct st20_rfc4175_422_10_pg2_le *pg_le, * - <0: Error code if convert fail. */ int st20_yuv422p10le_to_rfc4175_422le10(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_le *pg, - uint32_t w, uint32_t h); + struct st20_rfc4175_422_10_pg2_le *pg, uint32_t w, + uint32_t h); /** * Convert rfc4175_422le10 to yuv422p10le. @@ -513,8 +479,8 @@ int st20_yuv422p10le_to_rfc4175_422le10(uint16_t *y, uint16_t *b, uint16_t *r, * - <0: Error code if convert fail. */ int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h); + uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h); /** * Convert rfc4175_422le10 to v210 with required SIMD level. @@ -534,8 +500,7 @@ int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le *pg, */ static inline int st20_rfc4175_422le10_to_v210(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, uint32_t h) { - return st20_rfc4175_422le10_to_v210_simd(pg_le, pg_v210, w, h, - MTL_SIMD_LEVEL_MAX); + return st20_rfc4175_422le10_to_v210_simd(pg_le, pg_v210, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -554,11 +519,10 @@ static inline int st20_rfc4175_422le10_to_v210(uint8_t *pg_le, uint8_t *pg_v210, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_y210(struct st20_rfc4175_422_10_pg2_be *pg_be, - uint16_t *pg_y210, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_y210_simd(pg_be, pg_y210, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_y210(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint16_t *pg_y210, uint32_t w, + uint32_t h) { + return st20_rfc4175_422be10_to_y210_simd(pg_be, pg_y210, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -577,12 +541,10 @@ st20_rfc4175_422be10_to_y210(struct st20_rfc4175_422_10_pg2_be *pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_y210_to_rfc4175_422be10(uint16_t *pg_y210, - struct st20_rfc4175_422_10_pg2_be *pg_be, - uint32_t w, uint32_t h) { - return st20_y210_to_rfc4175_422be10_simd(pg_y210, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_y210_to_rfc4175_422be10(uint16_t *pg_y210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_y210_to_rfc4175_422be10_simd(pg_y210, pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -622,12 +584,10 @@ int st20_v210_to_rfc4175_422le10(uint8_t *pg_v210, uint8_t *pg_le, uint32_t w, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_yuv422p12le_to_rfc4175_422be12(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_12_pg2_be *pg, - uint32_t w, uint32_t h) { - return st20_yuv422p12le_to_rfc4175_422be12_simd(y, b, r, pg, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_yuv422p12le_to_rfc4175_422be12( + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_422_12_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_yuv422p12le_to_rfc4175_422be12_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -645,12 +605,10 @@ st20_yuv422p12le_to_rfc4175_422be12(uint16_t *y, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422le12_to_422be12(struct st20_rfc4175_422_12_pg2_le *pg_le, - struct st20_rfc4175_422_12_pg2_be *pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422le12_to_422be12( + struct st20_rfc4175_422_12_pg2_le *pg_le, struct st20_rfc4175_422_12_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -673,8 +631,8 @@ st20_rfc4175_422le12_to_422be12(struct st20_rfc4175_422_12_pg2_le *pg_le, * - <0: Error code if convert fail. */ int st20_yuv422p12le_to_rfc4175_422le12(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_12_pg2_le *pg, - uint32_t w, uint32_t h); + struct st20_rfc4175_422_12_pg2_le *pg, uint32_t w, + uint32_t h); /** * Convert rfc4175_422le12 to yuv422p12le. @@ -696,8 +654,8 @@ int st20_yuv422p12le_to_rfc4175_422le12(uint16_t *y, uint16_t *b, uint16_t *r, * - <0: Error code if convert fail. */ int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h); + uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h); /** * Convert yuv444p10le to rfc4175_444be10. @@ -718,12 +676,10 @@ int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_yuv444p10le_to_rfc4175_444be10(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_10_pg4_be *pg, - uint32_t w, uint32_t h) { - return st20_444p10le_to_rfc4175_444be10_simd(y, b, r, pg, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_yuv444p10le_to_rfc4175_444be10( + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_444_10_pg4_be *pg, + uint32_t w, uint32_t h) { + return st20_444p10le_to_rfc4175_444be10_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -741,12 +697,10 @@ st20_yuv444p10le_to_rfc4175_444be10(uint16_t *y, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444le10_to_444be10(struct st20_rfc4175_444_10_pg4_le *pg_le, - struct st20_rfc4175_444_10_pg4_be *pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444le10_to_444be10( + struct st20_rfc4175_444_10_pg4_le *pg_le, struct st20_rfc4175_444_10_pg4_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -768,10 +722,9 @@ st20_rfc4175_444le10_to_444be10(struct st20_rfc4175_444_10_pg4_le *pg_le, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_yuv444p10le_to_rfc4175_444le10(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_10_pg4_le *pg, - uint32_t w, uint32_t h) { +static inline int st20_yuv444p10le_to_rfc4175_444le10( + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_444_10_pg4_le *pg, + uint32_t w, uint32_t h) { return st20_444p10le_to_rfc4175_444le10(y, b, r, pg, w, h); } @@ -794,10 +747,9 @@ st20_yuv444p10le_to_rfc4175_444le10(uint16_t *y, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444le10_to_yuv444p10le(struct st20_rfc4175_444_10_pg4_le *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { +static inline int st20_rfc4175_444le10_to_yuv444p10le( + struct st20_rfc4175_444_10_pg4_le *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le10_to_444p10le(pg, y, b, r, w, h); } @@ -820,12 +772,10 @@ st20_rfc4175_444le10_to_yuv444p10le(struct st20_rfc4175_444_10_pg4_le *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_gbrp10le_to_rfc4175_444be10(uint16_t *g, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_10_pg4_be *pg, - uint32_t w, uint32_t h) { - return st20_444p10le_to_rfc4175_444be10_simd(g, r, b, pg, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_gbrp10le_to_rfc4175_444be10(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_10_pg4_be *pg, + uint32_t w, uint32_t h) { + return st20_444p10le_to_rfc4175_444be10_simd(g, r, b, pg, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -847,10 +797,9 @@ st20_gbrp10le_to_rfc4175_444be10(uint16_t *g, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_gbrp10le_to_rfc4175_444le10(uint16_t *g, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_10_pg4_le *pg, - uint32_t w, uint32_t h) { +static inline int st20_gbrp10le_to_rfc4175_444le10(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_10_pg4_le *pg, + uint32_t w, uint32_t h) { return st20_444p10le_to_rfc4175_444le10(g, r, b, pg, w, h); } @@ -873,10 +822,9 @@ st20_gbrp10le_to_rfc4175_444le10(uint16_t *g, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444le10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_le *pg, - uint16_t *g, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { +static inline int st20_rfc4175_444le10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_le *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le10_to_444p10le(pg, g, r, b, w, h); } @@ -899,12 +847,10 @@ st20_rfc4175_444le10_to_gbrp10le(struct st20_rfc4175_444_10_pg4_le *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_yuv444p12le_to_rfc4175_444be12(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_12_pg2_be *pg, - uint32_t w, uint32_t h) { - return st20_444p12le_to_rfc4175_444be12_simd(y, b, r, pg, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_yuv444p12le_to_rfc4175_444be12( + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_444_12_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_444p12le_to_rfc4175_444be12_simd(y, b, r, pg, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -922,12 +868,10 @@ st20_yuv444p12le_to_rfc4175_444be12(uint16_t *y, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444le12_to_444be12(struct st20_rfc4175_444_12_pg2_le *pg_le, - struct st20_rfc4175_444_12_pg2_be *pg_be, - uint32_t w, uint32_t h) { - return st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_444le12_to_444be12( + struct st20_rfc4175_444_12_pg2_le *pg_le, struct st20_rfc4175_444_12_pg2_be *pg_be, + uint32_t w, uint32_t h) { + return st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -949,10 +893,9 @@ st20_rfc4175_444le12_to_444be12(struct st20_rfc4175_444_12_pg2_le *pg_le, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_yuv444p12le_to_rfc4175_444le12(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_12_pg2_le *pg, - uint32_t w, uint32_t h) { +static inline int st20_yuv444p12le_to_rfc4175_444le12( + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_444_12_pg2_le *pg, + uint32_t w, uint32_t h) { return st20_444p12le_to_rfc4175_444le12(y, b, r, pg, w, h); } @@ -975,10 +918,9 @@ st20_yuv444p12le_to_rfc4175_444le12(uint16_t *y, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444le12_to_yuv444p12le(struct st20_rfc4175_444_12_pg2_le *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { +static inline int st20_rfc4175_444le12_to_yuv444p12le( + struct st20_rfc4175_444_12_pg2_le *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le12_to_444p12le(pg, y, b, r, w, h); } @@ -1001,12 +943,10 @@ st20_rfc4175_444le12_to_yuv444p12le(struct st20_rfc4175_444_12_pg2_le *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_gbrp12le_to_rfc4175_444be12(uint16_t *g, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_12_pg2_be *pg, - uint32_t w, uint32_t h) { - return st20_444p12le_to_rfc4175_444be12_simd(g, r, b, pg, w, h, - MTL_SIMD_LEVEL_MAX); +static inline int st20_gbrp12le_to_rfc4175_444be12(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_12_pg2_be *pg, + uint32_t w, uint32_t h) { + return st20_444p12le_to_rfc4175_444be12_simd(g, r, b, pg, w, h, MTL_SIMD_LEVEL_MAX); } /** @@ -1028,10 +968,9 @@ st20_gbrp12le_to_rfc4175_444be12(uint16_t *g, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_gbrp12le_to_rfc4175_444le12(uint16_t *g, uint16_t *b, uint16_t *r, - struct st20_rfc4175_444_12_pg2_le *pg, - uint32_t w, uint32_t h) { +static inline int st20_gbrp12le_to_rfc4175_444le12(uint16_t *g, uint16_t *b, uint16_t *r, + struct st20_rfc4175_444_12_pg2_le *pg, + uint32_t w, uint32_t h) { return st20_444p12le_to_rfc4175_444le12(g, r, b, pg, w, h); } @@ -1054,10 +993,9 @@ st20_gbrp12le_to_rfc4175_444le12(uint16_t *g, uint16_t *b, uint16_t *r, * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_444le12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_le *pg, - uint16_t *g, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { +static inline int st20_rfc4175_444le12_to_gbrp12le(struct st20_rfc4175_444_12_pg2_le *pg, + uint16_t *g, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { return st20_rfc4175_444le12_to_444p12le(pg, g, r, b, w, h); } diff --git a/include/st_convert_internal.h b/include/st_convert_internal.h index 8c649a9b4..173a7fe01 100644 --- a/include/st_convert_internal.h +++ b/include/st_convert_internal.h @@ -43,9 +43,10 @@ extern "C" { * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_yuv422p10le_simd( - struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be10_to_yuv422p10le_simd(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to yuv422p10le with required SIMD level and DMA @@ -75,17 +76,18 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_yuv422p10le_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be10_to_yuv422p10le_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, + uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level); /* the SIMD level version of st20_rfc4175_422be10_to_yuv422p10le_2way */ int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, - uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, - uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, - int decimator, enum mtl_simd_level level); + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, uint16_t *b_full, + uint16_t *r_full, uint32_t w, uint32_t h, uint16_t *y_decimated, + uint16_t *b_decimated, uint16_t *r_decimated, int decimator, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to rfc4175_422le10 with required SIMD level. @@ -105,10 +107,10 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le10_simd( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to rfc4175_422le10 with required SIMD level and DMA @@ -134,10 +136,12 @@ int st20_rfc4175_422be10_to_422le10_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le10_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le10_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to v210 with required SIMD level. @@ -182,10 +186,10 @@ int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_v210_simd_2way( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210_full, uint32_t w, - uint32_t h, uint8_t *pg_v210_decimated, int decimator, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_v210_simd_2way(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210_full, uint32_t w, uint32_t h, + uint8_t *pg_v210_decimated, int decimator, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to v210 with required SIMD level and DMA helper. @@ -211,10 +215,11 @@ int st20_rfc4175_422be10_to_v210_simd_2way( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_v210_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_v210_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to rfc4175_422le8(packed UYVY) with required SIMD @@ -234,10 +239,10 @@ int st20_rfc4175_422be10_to_v210_simd_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le8_simd( - struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le8_simd(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to rfc4175_422le8 packed UYVY with required SIMD @@ -262,10 +267,12 @@ int st20_rfc4175_422be10_to_422le8_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_422le8_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_10, - mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be10_to_422le8_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be10 to yuv422p8 with required SIMD level. @@ -290,9 +297,8 @@ int st20_rfc4175_422be10_to_422le8_simd_dma( * - <0: Error code if convert fail. */ int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h, - enum mtl_simd_level level); + uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be10 to yuv420p8 with required SIMD level. @@ -317,9 +323,8 @@ int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, * - <0: Error code if convert fail. */ int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h, - enum mtl_simd_level level); + uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be12 to yuv422p12le with required SIMD level. @@ -343,9 +348,10 @@ int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_yuv422p12le_simd( - struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be12_to_yuv422p12le_simd(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be12 to yuv422p12le with required SIMD level and DMA @@ -375,10 +381,11 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_yuv422p12le_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be12_to_yuv422p12le_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, + uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be12 to rfc4175_422le12 with required SIMD level. @@ -398,10 +405,10 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_422le12_simd( - struct st20_rfc4175_422_12_pg2_be *pg_be, - struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be12_to_422le12_simd(struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422be12 to rfc4175_422le12 with required SIMD level and DMA @@ -427,10 +434,12 @@ int st20_rfc4175_422be12_to_422le12_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be12_to_422le12_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422be12_to_422le12_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_444be10 to yuv444p10le/gbrp10le with required SIMD level. @@ -455,8 +464,8 @@ int st20_rfc4175_422be12_to_422le12_simd_dma( * - <0: Error code if convert fail. */ int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h, + uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + uint32_t w, uint32_t h, enum mtl_simd_level level); /** @@ -477,10 +486,10 @@ int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444be10_to_444le10_simd( - struct st20_rfc4175_444_10_pg4_be *pg_be, - struct st20_rfc4175_444_10_pg4_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444be10_to_444le10_simd(struct st20_rfc4175_444_10_pg4_be *pg_be, + struct st20_rfc4175_444_10_pg4_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_444be12 to yuv444p12le/gbrp12le with required SIMD level. @@ -505,8 +514,8 @@ int st20_rfc4175_444be10_to_444le10_simd( * - <0: Error code if convert fail. */ int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h, + uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + uint32_t w, uint32_t h, enum mtl_simd_level level); /** @@ -527,10 +536,10 @@ int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444be12_to_444le12_simd( - struct st20_rfc4175_444_12_pg2_be *pg_be, - struct st20_rfc4175_444_12_pg2_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444be12_to_444le12_simd(struct st20_rfc4175_444_12_pg2_be *pg_be, + struct st20_rfc4175_444_12_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv422p10le to rfc4175_422be10 with required SIMD level. @@ -554,10 +563,10 @@ int st20_rfc4175_444be12_to_444le12_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_yuv422p10le_to_rfc4175_422be10_simd( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_yuv422p10le_to_rfc4175_422be10_simd(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv422p10le to rfc4175_422be10 with required SIMD level and DMA @@ -590,10 +599,9 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd( * - <0: Error code if convert fail. */ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, - mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, - enum mtl_simd_level level); + mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, mtl_iova_t b_iova, + uint16_t *r, mtl_iova_t r_iova, struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert v210 to rfc4175_422be10 with required SIMD level. @@ -615,8 +623,7 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( */ int st20_v210_to_rfc4175_422be10_simd(uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); + uint32_t w, uint32_t h, enum mtl_simd_level level); /** * Convert v210 to rfc4175_422be10 with required SIMD level and DMA helper. @@ -640,10 +647,11 @@ int st20_v210_to_rfc4175_422be10_simd(uint8_t *pg_v210, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_v210_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_v210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint8_t *pg_v210, + mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv422p12le to rfc4175_422be12 with required SIMD level. @@ -667,10 +675,10 @@ int st20_v210_to_rfc4175_422be10_simd_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_yuv422p12le_to_rfc4175_422be12_simd( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_12_pg2_be *pg, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_yuv422p12le_to_rfc4175_422be12_simd(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_be *pg, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv444p10le or gbrp10le to rfc4175_444be10 with required SIMD level. @@ -694,8 +702,7 @@ int st20_yuv422p12le_to_rfc4175_422be12_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, +int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, struct st20_rfc4175_444_10_pg4_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level); @@ -722,8 +729,7 @@ int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, +int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, struct st20_rfc4175_444_12_pg2_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level); @@ -746,10 +752,10 @@ int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le10_to_422be10_simd( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422le10 to rfc4175_422be10 with required SIMD level and DMA @@ -775,10 +781,12 @@ int st20_rfc4175_422le10_to_422be10_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le10_to_422be10_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le *pg_le, - mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h, enum mtl_simd_level level); +int st20_rfc4175_422le10_to_422be10_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422le10 to v210 with required SIMD level. @@ -798,9 +806,8 @@ int st20_rfc4175_422le10_to_422be10_simd_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le10_to_v210_simd(uint8_t *pg_le, uint8_t *pg_v210, - uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422le10_to_v210_simd(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, + uint32_t h, enum mtl_simd_level level); /** * Convert rfc4175_422be10 to y210 with required SIMD level. @@ -848,10 +855,11 @@ int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422be10_to_y210_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422be10_to_y210_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert y210 to rfc4175_422be10 with required SIMD level. @@ -873,8 +881,7 @@ int st20_rfc4175_422be10_to_y210_simd_dma( */ int st20_y210_to_rfc4175_422be10_simd(uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level); + uint32_t w, uint32_t h, enum mtl_simd_level level); /** * Convert y210 to rfc4175_422be10 with required SIMD level and DMA helper. @@ -898,10 +905,11 @@ int st20_y210_to_rfc4175_422be10_simd(uint16_t *pg_y210, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_y210_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_y210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint16_t *pg_y210, + mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_422le12 to rfc4175_422be12 with required SIMD level. @@ -921,10 +929,10 @@ int st20_y210_to_rfc4175_422be10_simd_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_422le12_to_422be12_simd( - struct st20_rfc4175_422_12_pg2_le *pg_le, - struct st20_rfc4175_422_12_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_422le12_to_422be12_simd(struct st20_rfc4175_422_12_pg2_le *pg_le, + struct st20_rfc4175_422_12_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert rfc4175_444le10 to rfc4175_444be10 with required SIMD level. @@ -944,10 +952,10 @@ int st20_rfc4175_422le12_to_422be12_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le10_to_444be10_simd( - struct st20_rfc4175_444_10_pg4_le *pg_le, - struct st20_rfc4175_444_10_pg4_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444le10_to_444be10_simd(struct st20_rfc4175_444_10_pg4_le *pg_le, + struct st20_rfc4175_444_10_pg4_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv444p10le or gbrp10le to rfc4175_444le10. * @@ -967,10 +975,9 @@ int st20_rfc4175_444le10_to_444be10_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, - struct st20_rfc4175_444_10_pg4_le *pg, - uint32_t w, uint32_t h); +int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_le *pg, uint32_t w, + uint32_t h); /** * Convert rfc4175_444le10 to yuv444p10le or gbrp10le. @@ -991,9 +998,9 @@ int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h); +int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, uint16_t *y_g, + uint16_t *b_r, uint16_t *r_b, uint32_t w, + uint32_t h); /** * Convert rfc4175_444le12 to rfc4175_444be12 with required SIMD level. @@ -1013,10 +1020,10 @@ int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le12_to_444be12_simd( - struct st20_rfc4175_444_12_pg2_le *pg_le, - struct st20_rfc4175_444_12_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level); +int st20_rfc4175_444le12_to_444be12_simd(struct st20_rfc4175_444_12_pg2_le *pg_le, + struct st20_rfc4175_444_12_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level); /** * Convert yuv444p12le or gbrp12le to rfc4175_444le12. * @@ -1036,10 +1043,9 @@ int st20_rfc4175_444le12_to_444be12_simd( * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, - struct st20_rfc4175_444_12_pg2_le *pg, - uint32_t w, uint32_t h); +int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_le *pg, uint32_t w, + uint32_t h); /** * Convert rfc4175_444le12 to yuv444p12le or gbrp12le. @@ -1060,9 +1066,9 @@ int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, * - 0 if successful. * - <0: Error code if convert fail. */ -int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h); +int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, uint16_t *y_g, + uint16_t *b_r, uint16_t *r_b, uint32_t w, + uint32_t h); /** * Convert rfc4175_422be10 to yuv422p10le with the max optimized SIMD level and @@ -1090,11 +1096,10 @@ int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_yuv422p10le_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_yuv422p10le_simd_dma( - udma, pg_be, pg_be_iova, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, mtl_iova_t pg_be_iova, + uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_yuv422p10le_simd_dma(udma, pg_be, pg_be_iova, y, b, r, w, + h, MTL_SIMD_LEVEL_MAX); } /** @@ -1119,11 +1124,10 @@ static inline int st20_rfc4175_422be10_to_yuv422p10le_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_422le10_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_422le10_simd_dma( - udma, pg_be, pg_be_iova, pg_le, w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_422le10_simd_dma(udma, pg_be, pg_be_iova, pg_le, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1148,10 +1152,10 @@ static inline int st20_rfc4175_422be10_to_422le10_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_v210_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_v210_simd_dma(udma, pg_be, pg_be_iova, pg_v210, - w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, mtl_iova_t pg_be_iova, + uint8_t *pg_v210, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_v210_simd_dma(udma, pg_be, pg_be_iova, pg_v210, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1176,11 +1180,10 @@ static inline int st20_rfc4175_422be10_to_v210_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_422le8_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_10, - mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be10_to_422le8_simd_dma(udma, pg_10, pg_10_iova, pg_8, - w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_10, mtl_iova_t pg_10_iova, + struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_422le8_simd_dma(udma, pg_10, pg_10_iova, pg_8, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1209,11 +1212,10 @@ static inline int st20_rfc4175_422be10_to_422le8_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be12_to_yuv422p12le_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be12_to_yuv422p12le_simd_dma( - udma, pg_be, pg_be_iova, y, b, r, w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, mtl_iova_t pg_be_iova, + uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { + return st20_rfc4175_422be12_to_yuv422p12le_simd_dma(udma, pg_be, pg_be_iova, y, b, r, w, + h, MTL_SIMD_LEVEL_MAX); } /** @@ -1238,11 +1240,10 @@ static inline int st20_rfc4175_422be12_to_yuv422p12le_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be12_to_422le12_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, - uint32_t h) { - return st20_rfc4175_422be12_to_422le12_simd_dma( - udma, pg_be, pg_be_iova, pg_le, w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h) { + return st20_rfc4175_422be12_to_422le12_simd_dma(udma, pg_be, pg_be_iova, pg_le, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1273,9 +1274,9 @@ static inline int st20_rfc4175_422be12_to_422le12_dma( * - <0: Error code if convert fail. */ static inline int st20_yuv422p10le_to_rfc4175_422be10_dma( - mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, - mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { + mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, mtl_iova_t b_iova, + uint16_t *r, mtl_iova_t r_iova, struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, + uint32_t h) { return st20_yuv422p10le_to_rfc4175_422be10_simd_dma( udma, y, y_iova, b, b_iova, r, r_iova, pg, w, h, MTL_SIMD_LEVEL_MAX); } @@ -1303,8 +1304,8 @@ static inline int st20_yuv422p10le_to_rfc4175_422be10_dma( static inline int st20_v210_to_rfc4175_422be10_dma( mtl_udma_handle udma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { - return st20_v210_to_rfc4175_422be10_simd_dma(udma, pg_v210, pg_v210_iova, - pg_be, w, h, MTL_SIMD_LEVEL_MAX); + return st20_v210_to_rfc4175_422be10_simd_dma(udma, pg_v210, pg_v210_iova, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1329,11 +1330,10 @@ static inline int st20_v210_to_rfc4175_422be10_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422le10_to_422be10_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le *pg_le, - mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h) { - return st20_rfc4175_422le10_to_422be10_simd_dma( - udma, pg_le, pg_le_iova, pg_be, w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le *pg_le, mtl_iova_t pg_le_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { + return st20_rfc4175_422le10_to_422be10_simd_dma(udma, pg_le, pg_le_iova, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1358,10 +1358,10 @@ static inline int st20_rfc4175_422le10_to_422be10_dma( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_y210_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h) { - return st20_rfc4175_422be10_to_y210_simd_dma(udma, pg_be, pg_be_iova, pg_y210, - w, h, MTL_SIMD_LEVEL_MAX); + mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, mtl_iova_t pg_be_iova, + uint16_t *pg_y210, uint32_t w, uint32_t h) { + return st20_rfc4175_422be10_to_y210_simd_dma(udma, pg_be, pg_be_iova, pg_y210, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1387,8 +1387,8 @@ static inline int st20_rfc4175_422be10_to_y210_dma( static inline int st20_y210_to_rfc4175_422be10_dma( mtl_udma_handle udma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { - return st20_y210_to_rfc4175_422be10_simd_dma(udma, pg_y210, pg_y210_iova, - pg_be, w, h, MTL_SIMD_LEVEL_MAX); + return st20_y210_to_rfc4175_422be10_simd_dma(udma, pg_y210, pg_y210_iova, pg_be, w, h, + MTL_SIMD_LEVEL_MAX); } /** @@ -1414,23 +1414,23 @@ static inline int st20_y210_to_rfc4175_422be10_dma( * - 0 if successful. * - <0: Error code if convert fail. */ -static inline int -st20_rfc4175_422be10_to_v210_2way(struct st20_rfc4175_422_10_pg2_be *pg_be, - uint8_t *pg_v210_full, uint32_t w, uint32_t h, - uint8_t *pg_v210_decimated, int decimator) { - return st20_rfc4175_422be10_to_v210_simd_2way(pg_be, pg_v210_full, w, h, - pg_v210_decimated, decimator, - MTL_SIMD_LEVEL_MAX); +static inline int st20_rfc4175_422be10_to_v210_2way( + struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210_full, uint32_t w, + uint32_t h, uint8_t *pg_v210_decimated, int decimator) { + return st20_rfc4175_422be10_to_v210_simd_2way( + pg_be, pg_v210_full, w, h, pg_v210_decimated, decimator, MTL_SIMD_LEVEL_MAX); } /** helper to call st20_rfc4175_422be10_to_v210_2way with mtl_cpuva_t type for * python binding */ -static inline int st20_rfc4175_422be10_to_v210_2way_cpuva( - mtl_cpuva_t pg_be, mtl_cpuva_t pg_v210_full, uint32_t w, uint32_t h, - mtl_cpuva_t pg_v210_decimated, int decimator) { - return st20_rfc4175_422be10_to_v210_2way( - (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint8_t *)pg_v210_full, w, h, - (uint8_t *)pg_v210_decimated, decimator); +static inline int st20_rfc4175_422be10_to_v210_2way_cpuva(mtl_cpuva_t pg_be, + mtl_cpuva_t pg_v210_full, + uint32_t w, uint32_t h, + mtl_cpuva_t pg_v210_decimated, + int decimator) { + return st20_rfc4175_422be10_to_v210_2way((struct st20_rfc4175_422_10_pg2_be *)pg_be, + (uint8_t *)pg_v210_full, w, h, + (uint8_t *)pg_v210_decimated, decimator); } /** @@ -1465,25 +1465,24 @@ static inline int st20_rfc4175_422be10_to_v210_2way_cpuva( * - <0: Error code if convert fail. */ static inline int st20_rfc4175_422be10_to_yuv422p10le_2way( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, - uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, - uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, - int decimator) { + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, uint16_t *b_full, + uint16_t *r_full, uint32_t w, uint32_t h, uint16_t *y_decimated, + uint16_t *b_decimated, uint16_t *r_decimated, int decimator) { return st20_rfc4175_422be10_to_yuv422p10le_simd_2way( - pg_be, y_full, b_full, r_full, w, h, y_decimated, b_decimated, - r_decimated, decimator, MTL_SIMD_LEVEL_MAX); + pg_be, y_full, b_full, r_full, w, h, y_decimated, b_decimated, r_decimated, + decimator, MTL_SIMD_LEVEL_MAX); } /** helper to call st20_rfc4175_422be10_to_yuv422p10le_2way with mtl_cpuva_t * type for python binding */ static inline int st20_rfc4175_422be10_to_yuv422p10le_2way_cpuva( - mtl_cpuva_t pg_be, mtl_cpuva_t y_full, mtl_cpuva_t b_full, - mtl_cpuva_t r_full, uint32_t w, uint32_t h, mtl_cpuva_t y_decimated, - mtl_cpuva_t b_decimated, mtl_cpuva_t r_decimated, int decimator) { + mtl_cpuva_t pg_be, mtl_cpuva_t y_full, mtl_cpuva_t b_full, mtl_cpuva_t r_full, + uint32_t w, uint32_t h, mtl_cpuva_t y_decimated, mtl_cpuva_t b_decimated, + mtl_cpuva_t r_decimated, int decimator) { return st20_rfc4175_422be10_to_yuv422p10le_2way( - (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint16_t *)y_full, - (uint16_t *)b_full, (uint16_t *)r_full, w, h, (uint16_t *)y_decimated, - (uint16_t *)b_decimated, (uint16_t *)r_decimated, decimator); + (struct st20_rfc4175_422_10_pg2_be *)pg_be, (uint16_t *)y_full, (uint16_t *)b_full, + (uint16_t *)r_full, w, h, (uint16_t *)y_decimated, (uint16_t *)b_decimated, + (uint16_t *)r_decimated, decimator); } #if defined(__cplusplus) diff --git a/include/st_pipeline_api.h b/include/st_pipeline_api.h index f2cd2af2f..03a2491da 100644 --- a/include/st_pipeline_api.h +++ b/include/st_pipeline_api.h @@ -209,8 +209,7 @@ enum st_frame_fmt { /** ST format cap of ST_FRAME_FMT_UYVY */ #define ST_FMT_CAP_UYVY (MTL_BIT64(ST_FRAME_FMT_UYVY)) /** ST format cap of ST_FRAME_FMT_YUV422RFC4175PG2BE10 */ -#define ST_FMT_CAP_YUV422RFC4175PG2BE10 \ - (MTL_BIT64(ST_FRAME_FMT_YUV422RFC4175PG2BE10)) +#define ST_FMT_CAP_YUV422RFC4175PG2BE10 (MTL_BIT64(ST_FRAME_FMT_YUV422RFC4175PG2BE10)) /** ST format cap of ST_FRAME_FMT_ARGB */ #define ST_FMT_CAP_ARGB (MTL_BIT64(ST_FRAME_FMT_ARGB)) @@ -224,15 +223,13 @@ enum st_frame_fmt { #define ST_FMT_CAP_JPEGXS_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_JPEGXS_CODESTREAM)) /** ST format cap of ST_FRAME_FMT_H264_CBR_CODESTREAM, used in the st22_plugin * caps */ -#define ST_FMT_CAP_H264_CBR_CODESTREAM \ - (MTL_BIT64(ST_FRAME_FMT_H264_CBR_CODESTREAM)) +#define ST_FMT_CAP_H264_CBR_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H264_CBR_CODESTREAM)) /** ST format cap of ST_FRAME_FMT_H264_CODESTREAM, used in the st22_plugin caps */ #define ST_FMT_CAP_H264_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H264_CODESTREAM)) /** ST format cap of ST_FRAME_FMT_H265_CBR_CODESTREAM, used in the st22_plugin * caps */ -#define ST_FMT_CAP_H265_CBR_CODESTREAM \ - (MTL_BIT64(ST_FRAME_FMT_H265_CBR_CODESTREAM)) +#define ST_FMT_CAP_H265_CBR_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H265_CBR_CODESTREAM)) /** ST format cap of ST_FRAME_FMT_H265_CODESTREAM, used in the st22_plugin caps */ #define ST_FMT_CAP_H265_CODESTREAM (MTL_BIT64(ST_FRAME_FMT_H265_CODESTREAM)) @@ -781,8 +778,7 @@ struct st20_converter_dev { /** supported output format for convert, ST_FMT_CAP_* */ uint64_t output_fmt_caps; /** create session function */ - st20_convert_priv (*create_session)(void *priv, - st20p_convert_session session_p, + st20_convert_priv (*create_session)(void *priv, st20p_convert_session session_p, struct st20_converter_create_req *req); /** Callback when frame available in the lib. */ int (*notify_frame_available)(st20_convert_priv convert_priv); @@ -826,9 +822,8 @@ struct st_rx_port { /** Mandatory. multicast IP address or sender IP for unicast */ uint8_t ip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN]; /** deprecated, use ip_addr instead, sip_addr is confused */ - uint8_t - sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( - "Use ip_addr instead"); + uint8_t sip_addr[MTL_SESSION_PORT_MAX][MTL_IP_ADDR_LEN] __mtl_deprecated_msg( + "Use ip_addr instead"); }; /** Mandatory. 1 or 2, num of ports this session attached to */ uint8_t num_port; @@ -1192,8 +1187,7 @@ int st22_encoder_unregister(st22_encoder_dev_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st22_encode_frame_meta * -st22_encoder_get_frame(st22p_encode_session session); +struct st22_encode_frame_meta *st22_encoder_get_frame(st22p_encode_session session); /** * Wake up the block wait on st22_encoder_get_frame if @@ -1219,8 +1213,7 @@ int st22_encoder_wake_block(st22p_encode_session session); * - 0: Success. * - <0: Error code. */ -int st22_encoder_set_block_timeout(st22p_encode_session session, - uint64_t timedwait_ns); +int st22_encoder_set_block_timeout(st22p_encode_session session, uint64_t timedwait_ns); /** * Put back the frame which get by st22_encoder_get_frame to the tx @@ -1274,8 +1267,7 @@ int st22_decoder_unregister(st22_decoder_dev_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st22_decode_frame_meta * -st22_decoder_get_frame(st22p_decode_session session); +struct st22_decode_frame_meta *st22_decoder_get_frame(st22p_decode_session session); /** * Wake up the block wait on st22_decoder_get_frame if @@ -1301,8 +1293,7 @@ int st22_decoder_wake_block(st22p_decode_session session); * - 0: Success. * - <0: Error code. */ -int st22_decoder_set_block_timeout(st22p_decode_session session, - uint64_t timedwait_ns); +int st22_decoder_set_block_timeout(st22p_decode_session session, uint64_t timedwait_ns); /** * Put back the frame which get by st22_decoder_get_frame to the rx @@ -1332,8 +1323,8 @@ int st22_decoder_put_frame(st22p_decode_session session, * - NULL: fail. * - Others: the handle to the convert dev */ -st20_converter_dev_handle -st20_converter_register(mtl_handle mt, struct st20_converter_dev *dev); +st20_converter_dev_handle st20_converter_register(mtl_handle mt, + struct st20_converter_dev *dev); /** * Unregister one st20 converter. @@ -1356,8 +1347,7 @@ int st20_converter_unregister(st20_converter_dev_handle handle); * - NULL if no available frame in the session. * - Otherwise, the frame pointer. */ -struct st20_convert_frame_meta * -st20_converter_get_frame(st20p_convert_session session); +struct st20_convert_frame_meta *st20_converter_get_frame(st20p_convert_session session); /** * Put back the frame which get by st20_converter_get_frame to the rx @@ -1518,8 +1508,7 @@ size_t st22p_tx_frame_size(st22p_tx_handle handle); * - 0: Success. * - <0: Error code. */ -int st22p_tx_update_destination(st22p_tx_handle handle, - struct st_tx_dest_info *dst); +int st22p_tx_update_destination(st22p_tx_handle handle, struct st_tx_dest_info *dst); /** * Wake up the block wait on st22p_tx_get_frame if ST22P_TX_FLAG_BLOCK_GET is @@ -1639,8 +1628,8 @@ size_t st22p_rx_frame_size(st22p_rx_handle handle); * - 0: Success, rx st2110-22 pipeline session pcapng dump succ. * - <0: Error code of the rx st2110-22 pipeline session pcapng dump. */ -int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta); +int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta); /** * Get the queue meta attached to rx st2110-22 pipeline session. @@ -1666,8 +1655,7 @@ int st22p_rx_get_queue_meta(st22p_rx_handle handle, struct st_queue_meta *meta); * - 0: Success. * - <0: Error code. */ -int st22p_rx_update_source(st22p_rx_handle handle, - struct st_rx_source_info *src); +int st22p_rx_update_source(st22p_rx_handle handle, struct st_rx_source_info *src); /** * Wake up the block wait on st22p_rx_get_frame if ST22P_RX_FLAG_BLOCK_GET is @@ -1828,8 +1816,7 @@ int st20p_tx_get_port_stats(st20p_tx_handle handle, enum mtl_session_port port, * - >=0 succ. * - <0: Error code. */ -int st20p_tx_reset_port_stats(st20p_tx_handle handle, - enum mtl_session_port port); +int st20p_tx_reset_port_stats(st20p_tx_handle handle, enum mtl_session_port port); /** * Online update the destination info for the tx st2110-20(pipeline) session. @@ -1842,8 +1829,7 @@ int st20p_tx_reset_port_stats(st20p_tx_handle handle, * - 0: Success. * - <0: Error code. */ -int st20p_tx_update_destination(st20p_tx_handle handle, - struct st_tx_dest_info *dst); +int st20p_tx_update_destination(st20p_tx_handle handle, struct st_tx_dest_info *dst); /** * Wake up the block wait on st20p_tx_get_frame if ST20P_TX_FLAG_BLOCK_GET is @@ -1963,8 +1949,8 @@ size_t st20p_rx_frame_size(st20p_rx_handle handle); * - 0: Success, rx st2110-20 pipeline session pcapng dump succ. * - <0: Error code of the rx st2110-20 pipeline session pcapng dump. */ -int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta); +int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta); /** * Get the queue meta attached to rx st2110-20 pipeline session. @@ -2019,8 +2005,7 @@ int st20p_rx_get_port_stats(st20p_rx_handle handle, enum mtl_session_port port, * - >=0 succ. * - <0: Error code. */ -int st20p_rx_reset_port_stats(st20p_rx_handle handle, - enum mtl_session_port port); +int st20p_rx_reset_port_stats(st20p_rx_handle handle, enum mtl_session_port port); /** * Online update the source info for the rx st2110-20(pipeline) session. @@ -2033,8 +2018,7 @@ int st20p_rx_reset_port_stats(st20p_rx_handle handle, * - 0: Success. * - <0: Error code. */ -int st20p_rx_update_source(st20p_rx_handle handle, - struct st_rx_source_info *src); +int st20p_rx_update_source(st20p_rx_handle handle, struct st_rx_source_info *src); /** * Get the timing parser pass critical to rx st2110-20(pipeline) session. @@ -2048,8 +2032,7 @@ int st20p_rx_update_source(st20p_rx_handle handle, * - 0: Success. * - <0: Error code. */ -int st20p_rx_timing_parser_critical(st20p_rx_handle handle, - struct st20_rx_tp_pass *pass); +int st20p_rx_timing_parser_critical(st20p_rx_handle handle, struct st20_rx_tp_pass *pass); /** * Wake up the block wait on st20p_rx_get_frame if ST20P_RX_FLAG_BLOCK_GET is @@ -2118,8 +2101,7 @@ int st_frame_downsample(struct st_frame *src, struct st_frame *dst, int idx); * > 0 if successful. * 0: Fail. */ -size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, - uint8_t plane); +size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, uint8_t plane); /** * Calculate the frame size per the format, w and h @@ -2185,8 +2167,7 @@ uint8_t st_frame_fmt_planes(enum st_frame_fmt fmt); /** helper to know if it's a codestream fmt */ static inline bool st_frame_fmt_is_codestream(enum st_frame_fmt fmt) { - if (fmt >= ST_FRAME_FMT_CODESTREAM_START && - fmt <= ST_FRAME_FMT_CODESTREAM_END) + if (fmt >= ST_FRAME_FMT_CODESTREAM_START && fmt <= ST_FRAME_FMT_CODESTREAM_END) return true; else return false; @@ -2242,8 +2223,7 @@ bool st_frame_fmt_equal_transport(enum st_frame_fmt fmt, enum st20_fmt tfmt); * - 0 if successful. * - <0: Error code if put fail. */ -int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, - uint32_t y); +int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, uint32_t y); /** * Helper to get st frame plane size @@ -2255,15 +2235,12 @@ int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, * @return * size */ -static inline size_t st_frame_plane_size(struct st_frame *frame, - uint8_t plane) { +static inline size_t st_frame_plane_size(struct st_frame *frame, uint8_t plane) { /* no line size for codestream */ - if (st_frame_fmt_is_codestream(frame->fmt)) - return frame->data_size; + if (st_frame_fmt_is_codestream(frame->fmt)) return frame->data_size; size_t sz = frame->linesize[plane] * frame->height; - if (frame->interlaced) - sz /= 2; + if (frame->interlaced) sz /= 2; return sz; } @@ -2278,31 +2255,26 @@ static inline size_t st_frame_plane_size(struct st_frame *frame, */ static inline uint32_t st_frame_data_height(struct st_frame *frame) { uint32_t h = frame->height; - if (frame->interlaced) - h /= 2; + if (frame->interlaced) h /= 2; return h; } /** Helper to set the port for struct st_rx_port */ -int st_rxp_para_port_set(struct st_rx_port *p, enum mtl_session_port port, - char *name); +int st_rxp_para_port_set(struct st_rx_port *p, enum mtl_session_port port, char *name); /** Helper to set the ip for struct st_rx_port */ int st_rxp_para_ip_set(struct st_rx_port *p, enum mtl_port port, char *ip); /** Helper to set the udp port number for struct st_rx_port */ -static inline void st_rxp_para_udp_port_set(struct st_rx_port *p, - enum mtl_port port, +static inline void st_rxp_para_udp_port_set(struct st_rx_port *p, enum mtl_port port, uint16_t udp_port) { p->udp_port[port] = udp_port; } /** Helper to set the port for struct st_tx_port */ -int st_txp_para_port_set(struct st_tx_port *p, enum mtl_session_port port, - char *name); +int st_txp_para_port_set(struct st_tx_port *p, enum mtl_session_port port, char *name); /** Helper to set the dip for struct st_tx_port */ int st_txp_para_dip_set(struct st_tx_port *p, enum mtl_port port, char *ip); /** Helper to set the udp port number for struct st_tx_port */ -static inline void st_txp_para_udp_port_set(struct st_tx_port *p, - enum mtl_port port, +static inline void st_txp_para_udp_port_set(struct st_tx_port *p, enum mtl_port port, uint16_t udp_port) { p->udp_port[port] = udp_port; } @@ -2312,8 +2284,7 @@ static inline void *st_frame_addr(struct st_frame *frame, uint8_t plane) { return frame->addr[plane]; } /** Helper to get the frame addr(mtl_cpuva_t) from struct st_frame */ -static inline mtl_cpuva_t st_frame_addr_cpuva(struct st_frame *frame, - uint8_t plane) { +static inline mtl_cpuva_t st_frame_addr_cpuva(struct st_frame *frame, uint8_t plane) { return (mtl_cpuva_t)frame->addr[plane]; } /** Helper to get the frame iova from struct st_frame */ @@ -2321,19 +2292,19 @@ static inline mtl_iova_t st_frame_iova(struct st_frame *frame, uint8_t plane) { return frame->iova[plane]; } /** Helper to get the frame tp meta from struct st_frame */ -static inline struct st20_rx_tp_meta * -st_frame_tp_meta(struct st_frame *frame, enum mtl_session_port port) { +static inline struct st20_rx_tp_meta *st_frame_tp_meta(struct st_frame *frame, + enum mtl_session_port port) { return frame->tp[port]; } /** request to create a plain memory by rte malloc to hold the frame buffer */ -struct st_frame *st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, - uint32_t w, uint32_t h, bool interlaced); +struct st_frame *st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, uint32_t w, + uint32_t h, bool interlaced); /** free the frame created by st_frame_create */ int st_frame_free(struct st_frame *frame); /** request to create a plain memory by libc malloc */ -struct st_frame *st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, - uint32_t h, bool interlaced); +struct st_frame *st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, uint32_t h, + bool interlaced); /** merge two fields to one full frame */ int st_field_merge(const struct st_frame *first, const struct st_frame *second, diff --git a/ld_preload/preload_platform.h b/ld_preload/preload_platform.h index c6edfd6eb..2950949bc 100644 --- a/ld_preload/preload_platform.h +++ b/ld_preload/preload_platform.h @@ -19,7 +19,9 @@ #ifdef WINDOWSENV typedef unsigned long int nfds_t; -static inline pid_t getpid() { return GetCurrentProcessId(); } +static inline pid_t getpid() { + return GetCurrentProcessId(); +} #endif #endif diff --git a/ld_preload/udp/udp_preload.c b/ld_preload/udp/udp_preload.c index 7eadfc40c..8a92143d3 100644 --- a/ld_preload/udp/udp_preload.c +++ b/ld_preload/udp/udp_preload.c @@ -7,23 +7,27 @@ #include /* call original libc function */ -#define LIBC_FN(__name, ...) \ - ({ \ - typeof(libc_fn.__name(__VA_ARGS__)) ret; \ - if (!libc_fn.__name) { \ - upl_resolve_libc_fn(&libc_fn); \ - } \ - ret = libc_fn.__name(__VA_ARGS__); \ - ret; \ +#define LIBC_FN(__name, ...) \ + ({ \ + typeof(libc_fn.__name(__VA_ARGS__)) ret; \ + if (!libc_fn.__name) { \ + upl_resolve_libc_fn(&libc_fn); \ + } \ + ret = libc_fn.__name(__VA_ARGS__); \ + ret; \ }) static struct upl_functions libc_fn; static struct upl_ctx *g_upl_ctx; -static inline struct upl_ctx *upl_get_ctx(void) { return g_upl_ctx; } +static inline struct upl_ctx *upl_get_ctx(void) { + return g_upl_ctx; +} -static inline void upl_set_ctx(struct upl_ctx *ctx) { g_upl_ctx = ctx; } +static inline void upl_set_ctx(struct upl_ctx *ctx) { + g_upl_ctx = ctx; +} static inline int upl_set_upl_entry(struct upl_ctx *ctx, int kfd, void *upl) { if (ctx->upl_entires[kfd]) { @@ -43,24 +47,20 @@ static inline int upl_clear_upl_entry(struct upl_ctx *ctx, int kfd) { return 0; } -static inline struct upl_ufd_entry *upl_get_ufd_entry(struct upl_ctx *ctx, - int kfd) { +static inline struct upl_ufd_entry *upl_get_ufd_entry(struct upl_ctx *ctx, int kfd) { struct upl_ufd_entry *entry = upl_get_upl_entry(ctx, kfd); if (entry && entry->base.upl_type != UPL_ENTRY_UFD) { - dbg("%s(%d), entry %p error type %d\n", __func__, kfd, entry, - entry->base.upl_type); + dbg("%s(%d), entry %p error type %d\n", __func__, kfd, entry, entry->base.upl_type); return NULL; } dbg("%s(%d), ufd entry %p\n", __func__, kfd, entry); return entry; } -static inline struct upl_efd_entry *upl_get_efd_entry(struct upl_ctx *ctx, - int kfd) { +static inline struct upl_efd_entry *upl_get_efd_entry(struct upl_ctx *ctx, int kfd) { struct upl_efd_entry *entry = upl_get_upl_entry(ctx, kfd); if (entry && entry->base.upl_type != UPL_ENTRY_EPOLL) { - err("%s(%d), entry %p error type %d\n", __func__, kfd, entry, - entry->base.upl_type); + err("%s(%d), entry %p error type %d\n", __func__, kfd, entry, entry->base.upl_type); return NULL; } dbg("%s(%d), efd entry %p\n", __func__, kfd, entry); @@ -91,8 +91,7 @@ static int upl_uinit_ctx(struct upl_ctx *ctx) { if (ctx->upl_entires) { for (int i = 0; i < ctx->upl_entires_nb; i++) { struct upl_base_entry *entry = upl_get_upl_entry(ctx, i); - if (!entry) - continue; + if (!entry) continue; if (ctx->child && !entry->child) continue; /* child only check the fd created by child */ warn("%s, upl still active on %d, upl type %s\n", __func__, i, @@ -109,13 +108,13 @@ static int upl_uinit_ctx(struct upl_ctx *ctx) { } static int upl_resolve_libc_fn(struct upl_functions *fns) { -#define UPL_LIBC_FN(__name) \ - do { \ - fns->__name = dlsym(RTLD_NEXT, #__name); \ - if (!fns->__name) { \ - err("%s, dlsym %s fail\n", __func__, #__name); \ - UPL_ERR_RET(EIO); \ - } \ +#define UPL_LIBC_FN(__name) \ + do { \ + fns->__name = dlsym(RTLD_NEXT, #__name); \ + if (!fns->__name) { \ + err("%s, dlsym %s fail\n", __func__, #__name); \ + UPL_ERR_RET(EIO); \ + } \ } while (0) UPL_LIBC_FN(socket); @@ -155,8 +154,7 @@ static struct upl_ctx *upl_create_ctx(bool child) { ctx->log_level = MTL_LOG_LEVEL_INFO; ctx->upl_entires_nb = 1024 * 10; /* max fd we support */ - ctx->upl_entires = - upl_zmalloc(sizeof(*ctx->upl_entires) * ctx->upl_entires_nb); + ctx->upl_entires = upl_zmalloc(sizeof(*ctx->upl_entires) * ctx->upl_entires_nb); if (!ctx->upl_entires) { err("%s, upl_entires malloc fail, nb %d\n", __func__, ctx->upl_entires_nb); upl_uinit_ctx(ctx); @@ -171,8 +169,8 @@ static struct upl_ctx *upl_create_ctx(bool child) { memcpy(ctx->upl_entires, parent->upl_entires, sizeof(*ctx->upl_entires) * ctx->upl_entires_nb); } - info("%s, succ %s pid %u ctx %p\n", __func__, child ? "child" : "parent", - ctx->pid, ctx); + info("%s, succ %s pid %u ctx %p\n", __func__, child ? "child" : "parent", ctx->pid, + ctx); upl_set_ctx(ctx); return ctx; @@ -211,8 +209,7 @@ static void __attribute__((constructor)) upl_init() { static void __attribute__((destructor)) upl_uinit() { struct upl_ctx *ctx = upl_get_ctx(); - if (ctx) - upl_uinit_ctx(ctx); + if (ctx) upl_uinit_ctx(ctx); } static int upl_stat_dump(void *priv) { @@ -220,26 +217,26 @@ static int upl_stat_dump(void *priv) { int kfd = entry->kfd; if (entry->stat_tx_ufd_cnt || entry->stat_rx_ufd_cnt) { - notice("%s(%d), ufd pkt tx %d rx %d\n", __func__, kfd, - entry->stat_tx_ufd_cnt, entry->stat_rx_ufd_cnt); + notice("%s(%d), ufd pkt tx %d rx %d\n", __func__, kfd, entry->stat_tx_ufd_cnt, + entry->stat_rx_ufd_cnt); entry->stat_tx_ufd_cnt = 0; entry->stat_rx_ufd_cnt = 0; } if (entry->stat_tx_kfd_cnt || entry->stat_rx_kfd_cnt) { - notice("%s(%d), kfd pkt tx %d rx %d\n", __func__, kfd, - entry->stat_tx_kfd_cnt, entry->stat_rx_kfd_cnt); + notice("%s(%d), kfd pkt tx %d rx %d\n", __func__, kfd, entry->stat_tx_kfd_cnt, + entry->stat_rx_kfd_cnt); entry->stat_tx_kfd_cnt = 0; entry->stat_rx_kfd_cnt = 0; } if (entry->stat_epoll_cnt || entry->stat_epoll_revents_cnt) { - notice("%s(%d), epoll %d revents %d\n", __func__, kfd, - entry->stat_epoll_cnt, entry->stat_epoll_revents_cnt); + notice("%s(%d), epoll %d revents %d\n", __func__, kfd, entry->stat_epoll_cnt, + entry->stat_epoll_revents_cnt); entry->stat_epoll_cnt = 0; entry->stat_epoll_revents_cnt = 0; } if (entry->stat_select_cnt || entry->stat_select_revents_cnt) { - notice("%s(%d), select %d revents %d\n", __func__, kfd, - entry->stat_select_cnt, entry->stat_select_revents_cnt); + notice("%s(%d), select %d revents %d\n", __func__, kfd, entry->stat_select_cnt, + entry->stat_select_revents_cnt); entry->stat_select_cnt = 0; entry->stat_select_revents_cnt = 0; } @@ -292,22 +289,19 @@ static inline bool upl_epoll_has_ufd(struct upl_efd_entry *efd_entry) { } static int upl_efd_ctl_add(struct upl_ctx *ctx, struct upl_efd_entry *efd, - struct upl_ufd_entry *ufd, - struct epoll_event *event) { + struct upl_ufd_entry *ufd, struct epoll_event *event) { struct upl_efd_fd_item *item = upl_zmalloc(sizeof(*item)); if (!item) { err("%s, malloc fail\n", __func__); UPL_ERR_RET(ENOMEM); } - if (event) - item->event = *event; + if (event) item->event = *event; item->ufd = ufd; dbg("%s, efd %p ufd %p\n", __func__, efd, ufd); pthread_mutex_lock(&efd->mutex); /* todo: how to update ufd for child efd */ - if (!ctx->child) - ufd->efd = efd->efd; + if (!ctx->child) ufd->efd = efd->efd; TAILQ_INSERT_TAIL(&efd->fds, item, next); efd->fds_cnt++; pthread_mutex_unlock(&efd->mutex); @@ -327,8 +321,7 @@ static int upl_efd_ctl_del(struct upl_ctx *ctx, struct upl_efd_entry *efd, /* found the matched item, remove it */ TAILQ_REMOVE(&efd->fds, item, next); /* todo: how to update ufd for child efd */ - if (!ctx->child) - ufd->efd = -1; + if (!ctx->child) ufd->efd = -1; efd->fds_cnt--; pthread_mutex_unlock(&efd->mutex); upl_free(item); @@ -371,8 +364,7 @@ static int upl_efd_epoll_query(void *priv) { /* timeout to zero for query */ if (entry->sigmask) - ret = LIBC_FN(epoll_pwait, efd, entry->events, entry->maxevents, 0, - entry->sigmask); + ret = LIBC_FN(epoll_pwait, efd, entry->events, entry->maxevents, 0, entry->sigmask); else ret = LIBC_FN(epoll_wait, efd, entry->events, entry->maxevents, 0); if (ret != 0) { /* event on kfd */ @@ -396,12 +388,11 @@ static int upl_select_query(void *priv) { /* timeout to zero for query */ if (select_ctx->sigmask) - ret = LIBC_FN(pselect, select_ctx->nfds, select_ctx->readfds, - select_ctx->writefds, select_ctx->exceptfds, &zero_spec, - select_ctx->sigmask); + ret = LIBC_FN(pselect, select_ctx->nfds, select_ctx->readfds, select_ctx->writefds, + select_ctx->exceptfds, &zero_spec, select_ctx->sigmask); else - ret = LIBC_FN(select, select_ctx->nfds, select_ctx->readfds, - select_ctx->writefds, select_ctx->exceptfds, &zero); + ret = LIBC_FN(select, select_ctx->nfds, select_ctx->readfds, select_ctx->writefds, + select_ctx->exceptfds, &zero); dbg("%s, ret %d\n", __func__, ret); return ret; } @@ -415,8 +406,7 @@ static int upl_poll_query(void *priv) { struct timespec zero; zero.tv_sec = 0; zero.tv_nsec = 0; - ret = - LIBC_FN(ppoll, poll_ctx->fds, poll_ctx->nfds, &zero, poll_ctx->sigmask); + ret = LIBC_FN(ppoll, poll_ctx->fds, poll_ctx->nfds, &zero, poll_ctx->sigmask); } else { ret = LIBC_FN(poll, poll_ctx->fds, poll_ctx->nfds, 0); } @@ -425,9 +415,8 @@ static int upl_poll_query(void *priv) { } /* reuse mufd_poll now */ -static int upl_efd_epoll_pwait(struct upl_efd_entry *entry, - struct epoll_event *events, int maxevents, - int timeout_ms, const sigset_t *sigmask) { +static int upl_efd_epoll_pwait(struct upl_efd_entry *entry, struct epoll_event *events, + int maxevents, int timeout_ms, const sigset_t *sigmask) { int efd = entry->efd; const int fds_cnt = entry->fds_cnt; struct upl_efd_fd_item *item; @@ -437,13 +426,12 @@ static int upl_efd_epoll_pwait(struct upl_efd_entry *entry, int kfd_cnt = atomic_load(&entry->kfd_cnt); int ret; - dbg("%s(%d), timeout_ms %d maxevents %d kfd_cnt %d\n", __func__, efd, - timeout_ms, maxevents, kfd_cnt); + dbg("%s(%d), timeout_ms %d maxevents %d kfd_cnt %d\n", __func__, efd, timeout_ms, + maxevents, kfd_cnt); pthread_mutex_lock(&entry->mutex); TAILQ_FOREACH(item, &entry->fds, next) { if (p_fds_cnt >= fds_cnt) { - err("%s(%d), wrong p_fds_cnt %d fds_cnt %d\n", __func__, efd, p_fds_cnt, - fds_cnt); + err("%s(%d), wrong p_fds_cnt %d fds_cnt %d\n", __func__, efd, p_fds_cnt, fds_cnt); pthread_mutex_unlock(&entry->mutex); UPL_ERR_RET(EIO); } @@ -460,25 +448,20 @@ static int upl_efd_epoll_pwait(struct upl_efd_entry *entry, entry->events = events; entry->maxevents = maxevents; entry->sigmask = sigmask; - ret = mufd_poll_query(p_fds, p_fds_cnt, timeout_ms, upl_efd_epoll_query, - entry); + ret = mufd_poll_query(p_fds, p_fds_cnt, timeout_ms, upl_efd_epoll_query, entry); } else { ret = mufd_poll(p_fds, p_fds_cnt, timeout_ms); } - if (ret <= 0) - return ret; + if (ret <= 0) return ret; /* event on the kfd */ - if (entry->kfd_ret > 0) - return entry->kfd_ret; + if (entry->kfd_ret > 0) return entry->kfd_ret; int ready = 0; for (int i = 0; i < p_fds_cnt; i++) { - if (!p_fds[i].revents) - continue; + if (!p_fds[i].revents) continue; item = efd_items[i]; - dbg("%s, revents on ufd %d kfd %d\n", __func__, p_fds[i].fd, - item->ufd->kfd); + dbg("%s, revents on ufd %d kfd %d\n", __func__, p_fds[i].fd, item->ufd->kfd); events[ready] = efd_items[i]->event; ready++; item->ufd->stat_epoll_revents_cnt++; @@ -487,11 +470,9 @@ static int upl_efd_epoll_pwait(struct upl_efd_entry *entry, return ready; } -static int upl_pselect(struct upl_ctx *ctx, int nfds, fd_set *readfds, - fd_set *writefds, fd_set *exceptfds, - struct timeval *timeout, - const struct timespec *timeout_spec, - const sigset_t *sigmask) { +static int upl_pselect(struct upl_ctx *ctx, int nfds, fd_set *readfds, fd_set *writefds, + fd_set *exceptfds, struct timeval *timeout, + const struct timespec *timeout_spec, const sigset_t *sigmask) { dbg("%s, nfds %d\n", __func__, nfds); if (nfds <= 0 || nfds > FD_SETSIZE) { @@ -504,8 +485,7 @@ static int upl_pselect(struct upl_ctx *ctx, int nfds, fd_set *readfds, int poll_ufds_cnt = 0; /* split fd with kernel and mtl */ for (int i = 0; i < nfds; i++) { - if (!upl_is_ufd_entry(ctx, i)) - continue; + if (!upl_is_ufd_entry(ctx, i)) continue; if (readfds && FD_ISSET(i, readfds)) { FD_CLR(i, readfds); /* clear the readfds to kernel since it's a ufd */ struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, i); @@ -528,8 +508,7 @@ static int upl_pselect(struct upl_ctx *ctx, int nfds, fd_set *readfds, if (!poll_ufds_cnt) { if (sigmask) - return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout_spec, - sigmask); + return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout_spec, sigmask); else return LIBC_FN(select, nfds, readfds, writefds, exceptfds, timeout); } @@ -550,15 +529,13 @@ static int upl_pselect(struct upl_ctx *ctx, int nfds, fd_set *readfds, timeout_ms = timeout_spec->tv_sec * 1000 + timeout_spec->tv_nsec / 1000000; } else timeout_ms = 1000 * 2; /* wa: when timeout is NULL */ - int ret = mufd_poll_query(poll_ufds, poll_ufds_cnt, timeout_ms, - upl_select_query, &priv); - if (ret < 0) - return ret; + int ret = + mufd_poll_query(poll_ufds, poll_ufds_cnt, timeout_ms, upl_select_query, &priv); + if (ret < 0) return ret; FD_ZERO(readfds); for (nfds_t i = 0; i < poll_ufds_cnt; i++) { - if (!poll_ufds[i].revents) - continue; + if (!poll_ufds[i].revents) continue; int kfd = poll_ufds_kfd[i]; struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, kfd); dbg("%s(%d), revents on ufd %d kfd %d\n", __func__, kfd, entry->ufd); @@ -568,9 +545,8 @@ static int upl_pselect(struct upl_ctx *ctx, int nfds, fd_set *readfds, return ret; } -static int upl_ppoll(struct upl_ctx *ctx, struct pollfd *fds, nfds_t nfds, - int timeout, const struct timespec *tmo_p, - const sigset_t *sigmask) { +static int upl_ppoll(struct upl_ctx *ctx, struct pollfd *fds, nfds_t nfds, int timeout, + const struct timespec *tmo_p, const sigset_t *sigmask) { if (nfds <= 0) { err("%s, invalid nfds %" PRIu64 "\n", __func__, nfds); UPL_ERR_RET(EIO); @@ -619,8 +595,7 @@ static int upl_ppoll(struct upl_ctx *ctx, struct pollfd *fds, nfds_t nfds, priv.tmo_p = tmo_p; priv.sigmask = sigmask; /* wa to fix end loop in userspace issue */ - if (timeout < 0) - timeout = 1000 * 2; + if (timeout < 0) timeout = 1000 * 2; int ret; if (kfds_cnt) @@ -628,8 +603,7 @@ static int upl_ppoll(struct upl_ctx *ctx, struct pollfd *fds, nfds_t nfds, else ret = mufd_poll(ufds, ufds_cnt, timeout); dbg("%s, mufd_poll ret %d timeout %d\n", __func__, ret, timeout); - if (ret <= 0) - return ret; + if (ret <= 0) return ret; /* check if any ufd ready */ for (nfds_t i = 0; i < ufds_cnt; i++) { @@ -639,16 +613,14 @@ static int upl_ppoll(struct upl_ctx *ctx, struct pollfd *fds, nfds_t nfds, struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, kfd); entry->stat_poll_revents_cnt++; fds[pos].revents = ufds[i].revents; - dbg("%s(%d), revents %d on ufd %d\n", __func__, kfd, fds[pos].revents, - entry->ufd); + dbg("%s(%d), revents %d on ufd %d\n", __func__, kfd, fds[pos].revents, entry->ufd); if (entry->kfd != fds[pos].fd) { - err("%s(%d), not match with entry ufd %d kfd %d\n", __func__, kfd, - entry->ufd, entry->kfd); + err("%s(%d), not match with entry ufd %d kfd %d\n", __func__, kfd, entry->ufd, + entry->kfd); } } } - if (!kfds_cnt) - return ret; + if (!kfds_cnt) return ret; /* check if any kfd ready */ for (nfds_t i = 0; i < kfds_cnt; i++) { @@ -688,26 +660,24 @@ int socket(int domain, int type, int protocol) { int kfd; int ret; - if (!ctx) - return LIBC_FN(socket, domain, type, protocol); + if (!ctx) return LIBC_FN(socket, domain, type, protocol); kfd = LIBC_FN(socket, domain, type, protocol); - dbg("%s, kfd %d for domain %d type %d protocol %d\n", __func__, kfd, domain, - type, protocol); + dbg("%s, kfd %d for domain %d type %d protocol %d\n", __func__, kfd, domain, type, + protocol); if (kfd < 0) { - err("%s, create kfd fail %d for domain %d type %d protocol %d\n", __func__, - kfd, domain, type, protocol); + err("%s, create kfd fail %d for domain %d type %d protocol %d\n", __func__, kfd, + domain, type, protocol); return kfd; } if (kfd > ctx->upl_entires_nb) { - err("%s, kfd %d too big, consider enlarge entires space %d\n", __func__, - kfd, ctx->upl_entires_nb); + err("%s, kfd %d too big, consider enlarge entires space %d\n", __func__, kfd, + ctx->upl_entires_nb); return kfd; } ret = mufd_socket_check(domain, type, protocol); - if (ret < 0) - return kfd; /* not support by mufd */ + if (ret < 0) return kfd; /* not support by mufd */ if (ctx->child) { err("%s, kfd %d, child not allow to create a ufd, domain %d type %d " @@ -718,8 +688,8 @@ int socket(int domain, int type, int protocol) { int ufd = mufd_socket(domain, type, protocol); if (ufd < 0) { - err("%s, create ufd fail %d for domain %d type %d protocol %d\n", __func__, - ufd, domain, type, protocol); + err("%s, create ufd fail %d for domain %d type %d protocol %d\n", __func__, ufd, + domain, type, protocol); return kfd; /* return kfd for fallback path */ } @@ -746,20 +716,18 @@ int socket(int domain, int type, int protocol) { } upl_set_upl_entry(ctx, kfd, entry); - info("%s, ufd %d kfd %d for domain %d type %d protocol %d\n", __func__, ufd, - kfd, domain, type, protocol); + info("%s, ufd %d kfd %d for domain %d type %d protocol %d\n", __func__, ufd, kfd, + domain, type, protocol); return kfd; } int close(int fd) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(close, fd); + if (!ctx) return LIBC_FN(close, fd); dbg("%s(%d), start\n", __func__, fd); struct upl_base_entry *entry = upl_get_upl_entry(ctx, fd); - if (!entry) - return LIBC_FN(close, fd); + if (!entry) return LIBC_FN(close, fd); if (entry->upl_type == UPL_ENTRY_UFD) { struct upl_ufd_entry *ufd_entry = (struct upl_ufd_entry *)entry; @@ -788,22 +756,18 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { info("%s(%d), port %u\n", __func__, sockfd, htons(addr_in->sin_port)); #endif struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(bind, sockfd, addr, addrlen); + if (!ctx) return LIBC_FN(bind, sockfd, addr, addrlen); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry) - return LIBC_FN(bind, sockfd, addr, addrlen); + if (!entry) return LIBC_FN(bind, sockfd, addr, addrlen); int ufd = entry->ufd; int ret = mufd_bind(ufd, addr, addrlen); - if (ret >= 0) - return ret; /* mufd bind succ */ + if (ret >= 0) return ret; /* mufd bind succ */ /* try kernel fallback path */ ret = LIBC_FN(bind, sockfd, addr, addrlen); - if (ret < 0) - return ret; + if (ret < 0) return ret; entry->bind_kfd = true; info("%s(%d), mufd bind fail, fall back to libc\n", __func__, sockfd); return 0; @@ -812,13 +776,11 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); + if (!ctx) return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); dbg("%s(%d), len %" PRIu64 "\n", __func__, sockfd, len); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry) - return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); + if (!entry) return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); /* ufd only support ipv4 now */ const struct sockaddr_in *addr_in = (struct sockaddr_in *)dest_addr; @@ -827,8 +789,8 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, if (mufd_tx_valid_ip(ufd, ip) < 0) { /* fallback to kfd if it's not in ufd address scope */ - dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, - ip[0], ip[1], ip[2], ip[3]); + dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], + ip[2], ip[3]); entry->stat_tx_kfd_cnt++; return LIBC_FN(sendto, sockfd, buf, len, flags, dest_addr, addrlen); } else { @@ -839,13 +801,11 @@ ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(sendmsg, sockfd, msg, flags); + if (!ctx) return LIBC_FN(sendmsg, sockfd, msg, flags); dbg("%s(%d), start\n", __func__, sockfd); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry || !msg->msg_name) - return LIBC_FN(sendmsg, sockfd, msg, flags); + if (!entry || !msg->msg_name) return LIBC_FN(sendmsg, sockfd, msg, flags); if (!msg->msg_name || msg->msg_namelen < sizeof(struct sockaddr_in)) { warn("%s(%d), no msg_name or msg_namelen not valid\n", __func__, sockfd); @@ -855,14 +815,13 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) { /* ufd only support ipv4 now */ const struct sockaddr_in *addr_in = (struct sockaddr_in *)msg->msg_name; uint8_t *ip = (uint8_t *)&addr_in->sin_addr.s_addr; - dbg("%s(%d), dst ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], ip[2], - ip[3]); + dbg("%s(%d), dst ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], ip[2], ip[3]); int ufd = entry->ufd; if (mufd_tx_valid_ip(ufd, ip) < 0) { /* fallback to kfd if it's not in ufd address scope */ - dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, - ip[0], ip[1], ip[2], ip[3]); + dbg("%s(%d), fallback to kernel for ip %u.%u.%u.%u\n", __func__, sockfd, ip[0], ip[1], + ip[2], ip[3]); entry->stat_tx_kfd_cnt++; return LIBC_FN(sendmsg, sockfd, msg, flags); } else { @@ -873,13 +832,11 @@ ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags) { ssize_t send(int sockfd, const void *buf, size_t len, int flags) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(send, sockfd, buf, len, flags); + if (!ctx) return LIBC_FN(send, sockfd, buf, len, flags); dbg("%s(%d), len %" PRIu64 "\n", __func__, sockfd, len); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); - if (!entry) - return LIBC_FN(send, sockfd, buf, len, flags); + if (!entry) return LIBC_FN(send, sockfd, buf, len, flags); err("%s(%d), not support ufd now\n", __func__, sockfd); UPL_ERR_RET(ENOTSUP); @@ -887,8 +844,7 @@ ssize_t send(int sockfd, const void *buf, size_t len, int flags) { int poll(struct pollfd *fds, nfds_t nfds, int timeout) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(poll, fds, nfds, timeout); + if (!ctx) return LIBC_FN(poll, fds, nfds, timeout); return upl_ppoll(ctx, fds, nfds, timeout, NULL, NULL); } @@ -896,46 +852,37 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) { int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(ppoll, fds, nfds, tmo_p, sigmask); + if (!ctx) return LIBC_FN(ppoll, fds, nfds, tmo_p, sigmask); - int timeout = - (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * 1000 + tmo_p->tv_nsec / 1000000); + int timeout = (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * 1000 + tmo_p->tv_nsec / 1000000); return upl_ppoll(ctx, fds, nfds, timeout, tmo_p, sigmask); } int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(select, nfds, readfds, writefds, exceptfds, timeout); + if (!ctx) return LIBC_FN(select, nfds, readfds, writefds, exceptfds, timeout); - return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, timeout, NULL, - NULL); + return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, timeout, NULL, NULL); } int pselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout, const sigset_t *sigmask) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout, - sigmask); + if (!ctx) return LIBC_FN(pselect, nfds, readfds, writefds, exceptfds, timeout, sigmask); - return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, NULL, timeout, - sigmask); + return upl_pselect(ctx, nfds, readfds, writefds, exceptfds, NULL, timeout, sigmask); } -ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, - struct sockaddr *src_addr, socklen_t *addrlen) { +ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, + socklen_t *addrlen) { dbg("%s(%d), start\n", __func__, sockfd); struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(recvfrom, sockfd, buf, len, flags, src_addr, addrlen); + if (!ctx) return LIBC_FN(recvfrom, sockfd, buf, len, flags, src_addr, addrlen); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) { - if (entry) - entry->stat_rx_kfd_cnt++; + if (entry) entry->stat_rx_kfd_cnt++; return LIBC_FN(recvfrom, sockfd, buf, len, flags, src_addr, addrlen); } else { entry->stat_rx_ufd_cnt++; @@ -945,13 +892,11 @@ ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags, ssize_t recv(int sockfd, void *buf, size_t len, int flags) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(recv, sockfd, buf, len, flags); + if (!ctx) return LIBC_FN(recv, sockfd, buf, len, flags); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) { - if (entry) - entry->stat_rx_kfd_cnt++; + if (entry) entry->stat_rx_kfd_cnt++; return LIBC_FN(recv, sockfd, buf, len, flags); } else { entry->stat_rx_ufd_cnt++; @@ -961,13 +906,11 @@ ssize_t recv(int sockfd, void *buf, size_t len, int flags) { ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(recvmsg, sockfd, msg, flags); + if (!ctx) return LIBC_FN(recvmsg, sockfd, msg, flags); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) { - if (entry) - entry->stat_rx_kfd_cnt++; + if (entry) entry->stat_rx_kfd_cnt++; return LIBC_FN(recvmsg, sockfd, msg, flags); } else { entry->stat_rx_ufd_cnt++; @@ -975,11 +918,9 @@ ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags) { } } -int getsockopt(int sockfd, int level, int optname, void *optval, - socklen_t *optlen) { +int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(getsockopt, sockfd, level, optname, optval, optlen); + if (!ctx) return LIBC_FN(getsockopt, sockfd, level, optname, optval, optlen); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) @@ -988,11 +929,9 @@ int getsockopt(int sockfd, int level, int optname, void *optval, return mufd_getsockopt(entry->ufd, level, optname, optval, optlen); } -int setsockopt(int sockfd, int level, int optname, const void *optval, - socklen_t optlen) { +int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(setsockopt, sockfd, level, optname, optval, optlen); + if (!ctx) return LIBC_FN(setsockopt, sockfd, level, optname, optval, optlen); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) @@ -1003,8 +942,7 @@ int setsockopt(int sockfd, int level, int optname, const void *optval, int fcntl(int sockfd, int cmd, va_list args) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(fcntl, sockfd, cmd, args); + if (!ctx) return LIBC_FN(fcntl, sockfd, cmd, args); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) @@ -1015,8 +953,7 @@ int fcntl(int sockfd, int cmd, va_list args) { int fcntl64(int sockfd, int cmd, va_list args) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(fcntl64, sockfd, cmd, args); + if (!ctx) return LIBC_FN(fcntl64, sockfd, cmd, args); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) @@ -1027,8 +964,7 @@ int fcntl64(int sockfd, int cmd, va_list args) { int ioctl(int sockfd, unsigned long cmd, va_list args) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(ioctl, sockfd, cmd, args); + if (!ctx) return LIBC_FN(ioctl, sockfd, cmd, args); struct upl_ufd_entry *entry = upl_get_ufd_entry(ctx, sockfd); if (!entry || entry->bind_kfd) @@ -1039,12 +975,10 @@ int ioctl(int sockfd, unsigned long cmd, va_list args) { int epoll_create(int size) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(epoll_create, size); + if (!ctx) return LIBC_FN(epoll_create, size); int efd = LIBC_FN(epoll_create, size); - if (efd < 0) - return efd; + if (efd < 0) return efd; dbg("%s(%d), size %d\n", __func__, efd, size); upl_epoll_create(ctx, efd); @@ -1053,12 +987,10 @@ int epoll_create(int size) { int epoll_create1(int flags) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(epoll_create1, flags); + if (!ctx) return LIBC_FN(epoll_create1, flags); int efd = LIBC_FN(epoll_create1, flags); - if (efd < 0) - return efd; + if (efd < 0) return efd; dbg("%s(%d), flags 0x%x\n", __func__, efd, flags); upl_epoll_create(ctx, efd); @@ -1067,20 +999,17 @@ int epoll_create1(int flags) { int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(epoll_ctl, epfd, op, fd, event); + if (!ctx) return LIBC_FN(epoll_ctl, epfd, op, fd, event); dbg("%s(%d), op %d fd %d\n", __func__, epfd, op, fd); struct upl_efd_entry *efd = upl_get_efd_entry(ctx, epfd); - if (!efd) - return LIBC_FN(epoll_ctl, epfd, op, fd, event); + if (!efd) return LIBC_FN(epoll_ctl, epfd, op, fd, event); /* if it's a ufd entry */ struct upl_ufd_entry *ufd = upl_get_ufd_entry(ctx, fd); if (!ufd || ufd->bind_kfd) { int ret = LIBC_FN(epoll_ctl, epfd, op, fd, event); - if (ret < 0) - return ret; + if (ret < 0) return ret; dbg("%s(%d), op %d for fd %d succ with libc\n", __func__, epfd, op, fd); if (op == EPOLL_CTL_ADD) { atomic_fetch_add(&efd->kfd_cnt, 1); @@ -1103,11 +1032,9 @@ int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event) { } } -int epoll_wait(int epfd, struct epoll_event *events, int maxevents, - int timeout) { +int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(epoll_wait, epfd, events, maxevents, timeout); + if (!ctx) return LIBC_FN(epoll_wait, epfd, events, maxevents, timeout); struct upl_efd_entry *efd = upl_get_efd_entry(ctx, epfd); if (!efd || !upl_epoll_has_ufd(efd)) @@ -1115,16 +1042,14 @@ int epoll_wait(int epfd, struct epoll_event *events, int maxevents, dbg("%s(%d), timeout %d maxevents %d\n", __func__, epfd, timeout, maxevents); /* wa to fix end loop in userspace issue */ - if (timeout < 0) - timeout = 1000 * 2; + if (timeout < 0) timeout = 1000 * 2; return upl_efd_epoll_pwait(efd, events, maxevents, timeout, NULL); } -int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, - int timeout, const sigset_t *sigmask) { +int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, int timeout, + const sigset_t *sigmask) { struct upl_ctx *ctx = upl_get_ctx(); - if (!ctx) - return LIBC_FN(epoll_pwait, epfd, events, maxevents, timeout, sigmask); + if (!ctx) return LIBC_FN(epoll_pwait, epfd, events, maxevents, timeout, sigmask); struct upl_efd_entry *efd = upl_get_efd_entry(ctx, epfd); if (!efd || !upl_epoll_has_ufd(efd)) @@ -1133,8 +1058,7 @@ int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, int kfd_cnt = atomic_load(&efd->kfd_cnt); info("%s(%d), timeout %d, kfd_cnt %d\n", __func__, epfd, timeout, kfd_cnt); /* wa to fix end loop in userspace issue */ - if (timeout < 0) - timeout = 1000 * 2; + if (timeout < 0) timeout = 1000 * 2; return upl_efd_epoll_pwait(efd, events, maxevents, timeout, sigmask); } diff --git a/ld_preload/udp/udp_preload.h b/ld_preload/udp/udp_preload.h index 3f5165fc2..f49977db3 100644 --- a/ld_preload/udp/udp_preload.h +++ b/ld_preload/udp/udp_preload.h @@ -29,55 +29,53 @@ enum mtl_log_level upl_get_log_level(void); /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_DEBUG) \ - printf("UPL: " __VA_ARGS__); \ +#define dbg(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_DEBUG) printf("UPL: " __VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_INFO) \ - printf("UPL: " __VA_ARGS__); \ +#define info(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_INFO) printf("UPL: " __VA_ARGS__); \ } while (0) -#define notice(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_NOTICE) \ - printf("UPL: "__VA_ARGS__); \ +#define notice(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_NOTICE) printf("UPL: "__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_WARNING) \ - printf("UPL: Warn: "__VA_ARGS__); \ +#define warn(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_WARNING) printf("UPL: Warn: "__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - if (upl_get_log_level() <= MTL_LOG_LEVEL_ERR) \ - printf("UPL: Error: "__VA_ARGS__); \ +#define err(...) \ + do { \ + if (upl_get_log_level() <= MTL_LOG_LEVEL_ERR) printf("UPL: Error: "__VA_ARGS__); \ } while (0) /* On error, -1 is returned, and errno is set appropriately. */ -#define UPL_ERR_RET(code) \ - do { \ - errno = code; \ - return -1; \ +#define UPL_ERR_RET(code) \ + do { \ + errno = code; \ + return -1; \ } while (0) /* child only can't use rte malloc */ -static inline void *upl_malloc(size_t sz) { return malloc(sz); } +static inline void *upl_malloc(size_t sz) { + return malloc(sz); +} static inline void *upl_zmalloc(size_t sz) { void *p = malloc(sz); - if (p) - memset(p, 0x0, sz); + if (p) memset(p, 0x0, sz); return p; } -static inline void upl_free(void *p) { free(p); } +static inline void upl_free(void *p) { + free(p); +} struct upl_functions { int (*socket)(int domain, int type, int protocol); @@ -98,8 +96,7 @@ struct upl_functions { struct sockaddr *src_addr, socklen_t *addrlen); ssize_t (*recv)(int sockfd, void *buf, size_t len, int flags); ssize_t (*recvmsg)(int sockfd, struct msghdr *msg, int flags); - int (*getsockopt)(int sockfd, int level, int optname, void *optval, - socklen_t *optlen); + int (*getsockopt)(int sockfd, int level, int optname, void *optval, socklen_t *optlen); int (*setsockopt)(int sockfd, int level, int optname, const void *optval, socklen_t optlen); int (*fcntl)(int sockfd, int cmd, va_list args); @@ -109,10 +106,9 @@ struct upl_functions { int (*epoll_create)(int size); int (*epoll_create1)(int flags); int (*epoll_ctl)(int epfd, int op, int fd, struct epoll_event *event); - int (*epoll_wait)(int epfd, struct epoll_event *events, int maxevents, - int timeout); - int (*epoll_pwait)(int epfd, struct epoll_event *events, int maxevents, - int timeout, const sigset_t *sigmask); + int (*epoll_wait)(int epfd, struct epoll_event *events, int maxevents, int timeout); + int (*epoll_pwait)(int epfd, struct epoll_event *events, int maxevents, int timeout, + const sigset_t *sigmask); }; enum upl_entry_type { diff --git a/lib/src/datapath/mt_dp_socket.c b/lib/src/datapath/mt_dp_socket.c index 16c58640a..68092cdc6 100644 --- a/lib/src/datapath/mt_dp_socket.c +++ b/lib/src/datapath/mt_dp_socket.c @@ -41,8 +41,7 @@ static inline int tx_socket_verify_mbuf(struct rte_mbuf *m) { return 0; } -static int tx_socket_send_mbuf(struct mt_tx_socket_thread *t, - struct rte_mbuf *m) { +static int tx_socket_send_mbuf(struct mt_tx_socket_thread *t, struct rte_mbuf *m) { struct mt_tx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; int fd = t->fd, ret; @@ -64,18 +63,17 @@ static int tx_socket_send_mbuf(struct mt_tx_socket_thread *t, struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; struct rte_udp_hdr *udp = &hdr->udp; - mudp_init_sockaddr(&send_addr, (uint8_t *)&ipv4->dst_addr, - ntohs(udp->dst_port)); + mudp_init_sockaddr(&send_addr, (uint8_t *)&ipv4->dst_addr, ntohs(udp->dst_port)); t->stat_tx_try++; /* nonblocking */ ssize_t send = sendto(fd, payload, payload_len, MSG_DONTWAIT, (const struct sockaddr *)&send_addr, sizeof(send_addr)); - dbg("%s(%d,%d), len %" PRId64 " send %" PRId64 "\n", __func__, port, fd, - payload_len, send); + dbg("%s(%d,%d), len %" PRId64 " send %" PRId64 "\n", __func__, port, fd, payload_len, + send); if (send != payload_len) { - dbg("%s(%d,%d), sendto fail, len %" PRId64 " send %" PRId64 "\n", __func__, - port, fd, payload_len, send); + dbg("%s(%d,%d), sendto fail, len %" PRId64 " send %" PRId64 "\n", __func__, port, fd, + payload_len, send); return -EBUSY; } if (stats) { @@ -88,8 +86,7 @@ static int tx_socket_send_mbuf(struct mt_tx_socket_thread *t, } static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread *t, - struct rte_mbuf **tx_pkts, - uint16_t nb_pkts) { + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { uint16_t tx = 0; struct mt_tx_socket_entry *entry = t->parent; enum mtl_port port = entry->port; @@ -107,17 +104,14 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread *t, struct rte_mbuf *m = tx_pkts[i]; ret = tx_socket_verify_mbuf(m); if (ret < 0) { - err("%s(%d,%d), unsupported mbuf %p ret %d\n", __func__, port, fd, m, - ret); + err("%s(%d,%d), unsupported mbuf %p ret %d\n", __func__, port, fd, m, ret); return tx; } t->stat_tx_try++; uint16_t payload_len = m->data_len - sizeof(struct mt_udp_hdr); - void *payload = - rte_pktmbuf_mtod_offset(m, void *, sizeof(struct mt_udp_hdr)); - dbg("%s(%d,%d), mbuf %u payload_len %u\n", __func__, port, fd, i, - payload_len); + void *payload = rte_pktmbuf_mtod_offset(m, void *, sizeof(struct mt_udp_hdr)); + dbg("%s(%d,%d), mbuf %u payload_len %u\n", __func__, port, fd, i, payload_len); if (payload_len == gso_sz) { iovs[gso_cnt].iov_base = payload; @@ -128,8 +122,8 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread *t, msg->msg_iovlen = gso_cnt; write = sendmsg(fd, msg, MSG_DONTWAIT); if (write != (gso_sz * gso_cnt)) { - dbg("%s(%d,%d), sendmsg 1 fail, len %u send %" PRId64 "\n", __func__, - port, fd, gso_sz * gso_cnt, write); + dbg("%s(%d,%d), sendmsg 1 fail, len %u send %" PRId64 "\n", __func__, port, fd, + gso_sz * gso_cnt, write); return tx; } tx += gso_cnt; @@ -145,8 +139,8 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread *t, write = sendto(fd, payload, payload_len, MSG_DONTWAIT, &t->send_addr, sizeof(t->send_addr)); if (write != payload_len) { - dbg("%s(%d,%d), sendto fail, len %u send %" PRId64 "\n", __func__, port, - fd, payload_len, write); + dbg("%s(%d,%d), sendto fail, len %u send %" PRId64 "\n", __func__, port, fd, + payload_len, write); return tx; } tx++; @@ -162,12 +156,12 @@ static uint16_t tx_socket_send_mbuf_gso(struct mt_tx_socket_thread *t, msg->msg_iovlen = gso_cnt; write = sendmsg(fd, msg, MSG_DONTWAIT); if (write != (gso_sz * gso_cnt)) { - dbg("%s(%d,%d), sendmsg fail, len %u send %" PRId64 "\n", __func__, port, - fd, gso_sz * gso_cnt, write); + dbg("%s(%d,%d), sendmsg fail, len %u send %" PRId64 "\n", __func__, port, fd, + gso_sz * gso_cnt, write); return tx; } - dbg("%s(%d,%d), sendmsg succ, len %u send %" PRId64 "\n", __func__, port, - fd, gso_sz * gso_cnt, write); + dbg("%s(%d,%d), sendmsg succ, len %u send %" PRId64 "\n", __func__, port, fd, + gso_sz * gso_cnt, write); tx += gso_cnt; if (stats) { stats->tx_packets += gso_cnt; @@ -190,8 +184,7 @@ static void *tx_socket_thread_loop(void *arg) { info("%s(%d,%d), start\n", __func__, port, t->fd); while (rte_atomic32_read(&t->stop_thread) == 0) { ret = rte_ring_mc_dequeue(entry->ring, (void **)&m); - if (ret < 0) - continue; + if (ret < 0) continue; do { ret = tx_socket_send_mbuf(t, m); } while ((ret < 0) && (rte_atomic32_read(&t->stop_thread) == 0)); @@ -226,14 +219,12 @@ static int tx_socket_init_thread_data(struct mt_tx_socket_thread *t) { const char *if_name = mt_kernel_if_name(entry->parent, port); ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, if_name, strlen(if_name)); if (ret < 0) { - err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, idx, - if_name, ret); + err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, idx, if_name, ret); return ret; } if (entry->gso_sz) { - mudp_init_sockaddr(&t->send_addr, entry->flow.dip_addr, - entry->flow.dst_port); + mudp_init_sockaddr(&t->send_addr, entry->flow.dip_addr, entry->flow.dst_port); t->msg.msg_namelen = sizeof(t->send_addr); t->msg.msg_name = &t->send_addr; @@ -261,8 +252,7 @@ static int tx_socket_init_threads(struct mt_tx_socket_entry *entry) { for (int i = 1; i < entry->threads; i++) { struct mt_tx_socket_thread *t = &entry->threads_data[i]; ret = tx_socket_init_thread_data(t); - if (ret < 0) - return ret; + if (ret < 0) return ret; } /* create the ring, multi producer single consumer */ @@ -273,8 +263,8 @@ static int tx_socket_init_threads(struct mt_tx_socket_entry *entry) { entry->port, idx); flags = RING_F_SC_DEQ; count = mt_if_nb_rx_desc(entry->parent, entry->port); - ring = rte_ring_create(ring_name, count, - mt_socket_id(entry->parent, entry->port), flags); + ring = + rte_ring_create(ring_name, count, mt_socket_id(entry->parent, entry->port), flags); if (!ring) { err("%s(%d), ring create fail\n", __func__, idx); return -EIO; @@ -288,8 +278,7 @@ static int tx_socket_init_threads(struct mt_tx_socket_entry *entry) { rte_atomic32_set(&t->stop_thread, 0); ret = pthread_create(&t->tid, NULL, tx_socket_thread_loop, t); if (ret < 0) { - err("%s(%d), thread create fail %d for thread %d\n", __func__, idx, ret, - i); + err("%s(%d), thread create fail %d for thread %d\n", __func__, idx, ret, i); return ret; } } @@ -305,8 +294,8 @@ static int tx_socket_stat_dump(void *priv) { struct mt_tx_socket_thread *t = &entry->threads_data[i]; int fd = t->fd; - info("%s(%d,%d), tx pkt %d gso %d try %d on thread %d\n", __func__, port, - fd, t->stat_tx_pkt, t->stat_tx_gso, t->stat_tx_try, i); + info("%s(%d,%d), tx pkt %d gso %d try %d on thread %d\n", __func__, port, fd, + t->stat_tx_pkt, t->stat_tx_gso, t->stat_tx_try, i); t->stat_tx_pkt = 0; t->stat_tx_gso = 0; t->stat_tx_try = 0; @@ -357,8 +346,7 @@ struct mt_tx_socket_entry *mt_tx_socket_get(struct mtl_main_impl *impl, if (entry->threads > 1) { ret = tx_socket_init_threads(entry); if (ret < 0) { - err("%s(%d), init %d threads fail %d\n", __func__, port, entry->threads, - ret); + err("%s(%d), init %d threads fail %d\n", __func__, port, entry->threads, ret); mt_tx_socket_put(entry); return NULL; } @@ -373,9 +361,9 @@ struct mt_tx_socket_entry *mt_tx_socket_get(struct mtl_main_impl *impl, entry->stat_registered = true; uint8_t *ip = flow->dip_addr; - info("%s(%d), fd %d ip %u.%u.%u.%u, port %u, threads %u gso_sz %u\n", - __func__, port, entry->threads_data[0].fd, ip[0], ip[1], ip[2], ip[3], - flow->dst_port, entry->threads, entry->gso_sz); + info("%s(%d), fd %d ip %u.%u.%u.%u, port %u, threads %u gso_sz %u\n", __func__, port, + entry->threads_data[0].fd, ip[0], ip[1], ip[2], ip[3], flow->dst_port, + entry->threads, entry->gso_sz); return entry; } @@ -421,14 +409,14 @@ int mt_tx_socket_put(struct mt_tx_socket_entry *entry) { return 0; } -uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { uint16_t tx = 0; int ret; if (entry->ring) { - unsigned int n = rte_ring_sp_enqueue_bulk(entry->ring, (void **)&tx_pkts[0], - nb_pkts, NULL); + unsigned int n = + rte_ring_sp_enqueue_bulk(entry->ring, (void **)&tx_pkts[0], nb_pkts, NULL); // tx_socket_dequeue(&entry->threads_data[0]); return n; } @@ -439,8 +427,7 @@ uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, for (tx = 0; tx < nb_pkts; tx++) { struct rte_mbuf *m = tx_pkts[tx]; ret = tx_socket_send_mbuf(&entry->threads_data[0], m); - if (ret < 0) - break; + if (ret < 0) break; } } @@ -448,8 +435,7 @@ uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, return tx; } -static int rx_socket_init_fd(struct mt_rx_socket_entry *entry, int fd, - bool reuse) { +static int rx_socket_init_fd(struct mt_rx_socket_entry *entry, int fd, bool reuse) { int ret; enum mtl_port port = entry->port; struct mtl_main_impl *impl = entry->parent; @@ -476,8 +462,7 @@ static int rx_socket_init_fd(struct mt_rx_socket_entry *entry, int fd, info("%s(%d,%d), SO_BINDTODEVICE to %s\n", __func__, port, fd, if_name); ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, if_name, strlen(if_name)); if (ret < 0) { - err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, fd, - if_name, ret); + err("%s(%d,%d), SO_BINDTODEVICE to %s fail %d\n", __func__, port, fd, if_name, ret); return ret; } @@ -489,8 +474,7 @@ static int rx_socket_init_fd(struct mt_rx_socket_entry *entry, int fd, mudp_init_sockaddr(&bind_addr, mt_sip_addr(impl, port), flow->dst_port); ret = bind(fd, (const struct sockaddr *)&bind_addr, sizeof(bind_addr)); if (ret < 0) { - err("%s(%d,%d), bind to port %u fail %d\n", __func__, port, fd, - flow->dst_port, ret); + err("%s(%d,%d), bind to port %u fail %d\n", __func__, port, fd, flow->dst_port, ret); return ret; } @@ -530,8 +514,8 @@ static struct rte_mbuf *rx_socket_recv_mbuf(struct mt_rx_socket_thread *t) { socklen_t addr_in_len = sizeof(addr_in); t->stat_rx_try++; - ssize_t len = recvfrom(fd, payload, entry->pool_element_sz, MSG_DONTWAIT, - &addr_in, &addr_in_len); + ssize_t len = + recvfrom(fd, payload, entry->pool_element_sz, MSG_DONTWAIT, &addr_in, &addr_in_len); if (len <= 0) { return NULL; } @@ -566,12 +550,10 @@ static void *rx_socket_thread_loop(void *arg) { info("%s(%d,%d), start thread %d\n", __func__, port, fd, idx); while (rte_atomic32_read(&t->stop_thread) == 0) { m = rx_socket_recv_mbuf(t); - if (!m) - continue; + if (!m) continue; while (rte_atomic32_read(&t->stop_thread) == 0) { ret = rte_ring_mp_enqueue(entry->ring, m); - if (ret >= 0) - break; /* succ */ + if (ret >= 0) break; /* succ */ } } info("%s(%d,%d), stop thread %d\n", __func__, port, fd, idx); @@ -588,12 +570,10 @@ static int rx_socket_init_threads(struct mt_rx_socket_entry *entry) { char ring_name[64]; struct rte_ring *ring; unsigned int flags, count; - snprintf(ring_name, sizeof(ring_name), "%sRP%dFD%d", MT_RX_DP_SOCKET_PREFIX, - port, fd); + snprintf(ring_name, sizeof(ring_name), "%sRP%dFD%d", MT_RX_DP_SOCKET_PREFIX, port, fd); flags = RING_F_SP_ENQ; count = mt_if_nb_tx_desc(entry->parent, port); - ring = rte_ring_create(ring_name, count, mt_socket_id(entry->parent, port), - flags); + ring = rte_ring_create(ring_name, count, mt_socket_id(entry->parent, port), flags); if (!ring) { err("%s(%d,%d), ring create fail\n", __func__, port, fd); return -EIO; @@ -607,8 +587,7 @@ static int rx_socket_init_threads(struct mt_rx_socket_entry *entry) { rte_atomic32_set(&t->stop_thread, 0); ret = pthread_create(&t->tid, NULL, rx_socket_thread_loop, t); if (ret < 0) { - err("%s(%d,%d), thread create fail %d for thread %d\n", __func__, port, - fd, ret, i); + err("%s(%d,%d), thread create fail %d for thread %d\n", __func__, port, fd, ret, i); return ret; } } @@ -624,8 +603,8 @@ static int rx_socket_stat_dump(void *priv) { for (int i = 0; i < entry->threads; i++) { struct mt_rx_socket_thread *t = &entry->threads_data[i]; - info("%s(%d,%d), rx pkt %d try %d on thread %d\n", __func__, port, fd, - t->stat_rx_pkt, t->stat_rx_try, i); + info("%s(%d,%d), rx pkt %d try %d on thread %d\n", __func__, port, fd, t->stat_rx_pkt, + t->stat_rx_try, i); t->stat_rx_pkt = 0; t->stat_rx_try = 0; } @@ -691,12 +670,10 @@ struct mt_rx_socket_entry *mt_rx_socket_get(struct mtl_main_impl *impl, /* Create mempool to hold the rx queue mbufs. */ unsigned int mbuf_elements = mt_if_nb_rx_desc(impl, port) + 1024; char pool_name[ST_MAX_NAME_LEN]; - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dF%d_MBUF", MT_RX_DP_SOCKET_PREFIX, - port, fd); + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dF%d_MBUF", MT_RX_DP_SOCKET_PREFIX, port, fd); /* no priv */ - entry->pool = - mt_mempool_create(impl, port, pool_name, mbuf_elements, - MT_MBUF_CACHE_SIZE, 0, entry->pool_element_sz); + entry->pool = mt_mempool_create(impl, port, pool_name, mbuf_elements, + MT_MBUF_CACHE_SIZE, 0, entry->pool_element_sz); if (!entry->pool) { err("%s(%d), mempool %s create fail\n", __func__, port, pool_name); mt_rx_socket_put(entry); @@ -706,8 +683,8 @@ struct mt_rx_socket_entry *mt_rx_socket_get(struct mtl_main_impl *impl, if (entry->threads > 1) { ret = rx_socket_init_threads(entry); if (ret < 0) { - err("%s(%d,%d), init %d threads fail %d\n", __func__, port, fd, - entry->threads, ret); + err("%s(%d,%d), init %d threads fail %d\n", __func__, port, fd, entry->threads, + ret); mt_rx_socket_put(entry); return NULL; } @@ -722,8 +699,8 @@ struct mt_rx_socket_entry *mt_rx_socket_get(struct mtl_main_impl *impl, entry->stat_registered = true; uint8_t *ip = flow->dip_addr; - info("%s(%d), fd %d ip %u.%u.%u.%u port %u threads %d\n", __func__, port, fd, - ip[0], ip[1], ip[2], ip[3], flow->dst_port, entry->threads); + info("%s(%d), fd %d ip %u.%u.%u.%u port %u threads %d\n", __func__, port, fd, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, entry->threads); return entry; } @@ -773,20 +750,18 @@ int mt_rx_socket_put(struct mt_rx_socket_entry *entry) { return 0; } -uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, - struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { +uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts) { uint16_t rx = 0; struct mt_rx_socket_thread *t = &entry->threads_data[0]; if (entry->ring) { - return rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, - NULL); + return rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); } for (rx = 0; rx < nb_pkts; rx++) { struct rte_mbuf *pkt = rx_socket_recv_mbuf(t); - if (!pkt) - break; + if (!pkt) break; rx_pkts[rx] = pkt; } @@ -808,8 +783,8 @@ int mt_tx_socket_put(struct mt_tx_socket_entry *entry) { return 0; } -uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); err("%s(%d), not support on this platform\n", __func__, entry->port); rte_pktmbuf_free_bulk(tx_pkts, nb_pkts); @@ -830,8 +805,8 @@ int mt_rx_socket_put(struct mt_rx_socket_entry *entry) { return 0; } -uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, - struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { +uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(rx_pkts); MTL_MAY_UNUSED(nb_pkts); diff --git a/lib/src/datapath/mt_dp_socket.h b/lib/src/datapath/mt_dp_socket.h index 495a651f3..c21d5f062 100644 --- a/lib/src/datapath/mt_dp_socket.h +++ b/lib/src/datapath/mt_dp_socket.h @@ -8,23 +8,21 @@ #include "../mt_main.h" struct mt_tx_socket_entry *mt_tx_socket_get(struct mtl_main_impl *impl, - enum mtl_port port, - struct mt_txq_flow *flow); + enum mtl_port port, struct mt_txq_flow *flow); int mt_tx_socket_put(struct mt_tx_socket_entry *entry); static inline uint16_t mt_tx_socket_queue_id(struct mt_tx_socket_entry *entry) { return entry->threads_data[0].fd; } -uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts); +uint16_t mt_tx_socket_burst(struct mt_tx_socket_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts); struct mt_rx_socket_entry *mt_rx_socket_get(struct mtl_main_impl *impl, - enum mtl_port port, - struct mt_rxq_flow *flow); + enum mtl_port port, struct mt_rxq_flow *flow); int mt_rx_socket_put(struct mt_rx_socket_entry *entry); static inline uint16_t mt_rx_socket_queue_id(struct mt_rx_socket_entry *entry) { return entry->fd; } -uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, - struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); +uint16_t mt_rx_socket_burst(struct mt_rx_socket_entry *entry, struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts); #endif diff --git a/lib/src/datapath/mt_queue.c b/lib/src/datapath/mt_queue.c index 9e9d35a3a..4b74d09b4 100644 --- a/lib/src/datapath/mt_queue.c +++ b/lib/src/datapath/mt_queue.c @@ -13,44 +13,37 @@ #include "mt_shared_queue.h" #include "mt_shared_rss.h" -static uint16_t rx_socket_burst(struct mt_rxq_entry *entry, - struct rte_mbuf **rx_pkts, +static uint16_t rx_socket_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rx_socket_burst(entry->rx_socket_q, rx_pkts, nb_pkts); } -static uint16_t rx_xdp_burst(struct mt_rxq_entry *entry, - struct rte_mbuf **rx_pkts, +static uint16_t rx_xdp_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rx_xdp_burst(entry->rx_xdp_q, rx_pkts, nb_pkts); } -static uint16_t rx_rdma_burst(struct mt_rxq_entry *entry, - struct rte_mbuf **rx_pkts, +static uint16_t rx_rdma_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rx_rdma_burst(entry->rx_rdma_q, rx_pkts, nb_pkts); } -static uint16_t rx_srss_burst(struct mt_rxq_entry *entry, - struct rte_mbuf **rx_pkts, +static uint16_t rx_srss_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_srss_burst(entry->srss, rx_pkts, nb_pkts); } -static uint16_t rx_rsq_burst(struct mt_rxq_entry *entry, - struct rte_mbuf **rx_pkts, +static uint16_t rx_rsq_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_rsq_burst(entry->rsq, rx_pkts, nb_pkts); } -static uint16_t rx_csq_burst(struct mt_rxq_entry *entry, - struct rte_mbuf **rx_pkts, +static uint16_t rx_csq_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_csq_burst(entry->csq, rx_pkts, nb_pkts); } -static uint16_t rx_dpdk_burst(struct mt_rxq_entry *entry, - struct rte_mbuf **rx_pkts, +static uint16_t rx_dpdk_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { return mt_dpdk_rx_burst(entry->rxq, rx_pkts, nb_pkts); } @@ -66,47 +59,39 @@ struct mt_rxq_entry *mt_rxq_get(struct mtl_main_impl *impl, enum mtl_port port, entry->parent = impl; dbg("%s(%d), flags 0x%x\n", __func__, port, flow->flags); - if (mt_pmd_is_kernel_socket(impl, port) || - (flow->flags & MT_RXQ_FLOW_F_FORCE_SOCKET)) { + if (mt_pmd_is_kernel_socket(impl, port) || (flow->flags & MT_RXQ_FLOW_F_FORCE_SOCKET)) { entry->rx_socket_q = mt_rx_socket_get(impl, port, flow); - if (!entry->rx_socket_q) - goto fail; + if (!entry->rx_socket_q) goto fail; entry->queue_id = mt_rx_socket_queue_id(entry->rx_socket_q); entry->burst = rx_socket_burst; } else if (mt_has_srss(impl, port)) { entry->srss = mt_srss_get(impl, port, flow); - if (!entry->srss) - goto fail; + if (!entry->srss) goto fail; entry->queue_id = mt_srss_queue_id(entry->srss); entry->burst = rx_srss_burst; } else if (mt_user_shared_rxq(impl, port)) { entry->rsq = mt_rsq_get(impl, port, flow); - if (!entry->rsq) - goto fail; + if (!entry->rsq) goto fail; entry->queue_id = mt_rsq_queue_id(entry->rsq); entry->burst = rx_rsq_burst; } else if (mt_pmd_is_native_af_xdp(impl, port)) { entry->rx_xdp_q = mt_rx_xdp_get(impl, port, flow, NULL); - if (!entry->rx_xdp_q) - goto fail; + if (!entry->rx_xdp_q) goto fail; entry->queue_id = mt_rx_xdp_queue_id(entry->rx_xdp_q); entry->burst = rx_xdp_burst; } else if (mt_pmd_is_rdma_ud(impl, port)) { entry->rx_rdma_q = mt_rx_rdma_get(impl, port, flow, NULL); - if (!entry->rx_rdma_q) - goto fail; + if (!entry->rx_rdma_q) goto fail; entry->queue_id = mt_rx_rdma_queue_id(entry->rx_rdma_q); entry->burst = rx_rdma_burst; } else if (flow->flags & MT_RXQ_FLOW_F_FORCE_CNI) { entry->csq = mt_csq_get(impl, port, flow); - if (!entry->csq) - goto fail; + if (!entry->csq) goto fail; entry->queue_id = mt_csq_queue_id(entry->csq); entry->burst = rx_csq_burst; } else { entry->rxq = mt_dev_get_rx_queue(impl, port, flow); - if (!entry->rxq) - goto fail; + if (!entry->rxq) goto fail; entry->queue_id = mt_dev_rx_queue_id(entry->rxq); entry->burst = rx_dpdk_burst; } @@ -156,28 +141,28 @@ uint16_t mt_rxq_burst(struct mt_rxq_entry *entry, struct rte_mbuf **rx_pkts, return entry->burst(entry, rx_pkts, nb_pkts); } -static uint16_t tx_socket_burst(struct mt_txq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +static uint16_t tx_socket_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return mt_tx_socket_burst(entry->tx_socket_q, tx_pkts, nb_pkts); } -static uint16_t tx_xdp_burst(struct mt_txq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +static uint16_t tx_xdp_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return mt_tx_xdp_burst(entry->tx_xdp_q, tx_pkts, nb_pkts); } -static uint16_t tx_rdma_burst(struct mt_txq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +static uint16_t tx_rdma_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return mt_tx_rdma_burst(entry->tx_rdma_q, tx_pkts, nb_pkts); } -static uint16_t tx_tsq_burst(struct mt_txq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +static uint16_t tx_tsq_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return mt_tsq_burst(entry->tsq, tx_pkts, nb_pkts); } -static uint16_t tx_dpdk_burst(struct mt_txq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +static uint16_t tx_dpdk_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return mt_dpdk_tx_burst(entry->txq, tx_pkts, nb_pkts); } @@ -192,35 +177,29 @@ struct mt_txq_entry *mt_txq_get(struct mtl_main_impl *impl, enum mtl_port port, entry->parent = impl; dbg("%s(%d), flags 0x%x\n", __func__, port, flow->flags); - if (mt_pmd_is_kernel_socket(impl, port) || - (flow->flags & MT_TXQ_FLOW_F_FORCE_SOCKET)) { + if (mt_pmd_is_kernel_socket(impl, port) || (flow->flags & MT_TXQ_FLOW_F_FORCE_SOCKET)) { entry->tx_socket_q = mt_tx_socket_get(impl, port, flow); - if (!entry->tx_socket_q) - goto fail; + if (!entry->tx_socket_q) goto fail; entry->queue_id = mt_tx_socket_queue_id(entry->tx_socket_q); entry->burst = tx_socket_burst; } else if (mt_user_shared_txq(impl, port)) { entry->tsq = mt_tsq_get(impl, port, flow); - if (!entry->tsq) - goto fail; + if (!entry->tsq) goto fail; entry->queue_id = mt_tsq_queue_id(entry->tsq); entry->burst = tx_tsq_burst; } else if (mt_pmd_is_native_af_xdp(impl, port)) { entry->tx_xdp_q = mt_tx_xdp_get(impl, port, flow, NULL); - if (!entry->tx_xdp_q) - goto fail; + if (!entry->tx_xdp_q) goto fail; entry->queue_id = mt_tx_xdp_queue_id(entry->tx_xdp_q); entry->burst = tx_xdp_burst; } else if (mt_pmd_is_rdma_ud(impl, port)) { entry->tx_rdma_q = mt_tx_rdma_get(impl, port, flow, NULL); - if (!entry->tx_rdma_q) - goto fail; + if (!entry->tx_rdma_q) goto fail; entry->queue_id = mt_tx_rdma_queue_id(entry->tx_rdma_q); entry->burst = tx_rdma_burst; } else { entry->txq = mt_dev_get_tx_queue(impl, port, flow); - if (!entry->txq) - goto fail; + if (!entry->txq) goto fail; entry->queue_id = mt_dev_tx_queue_id(entry->txq); entry->burst = tx_dpdk_burst; } @@ -258,18 +237,14 @@ int mt_txq_put(struct mt_txq_entry *entry) { } int mt_txq_fatal_error(struct mt_txq_entry *entry) { - if (entry->txq) - mt_dev_tx_queue_fatal_error(entry->parent, entry->txq); - if (entry->tsq) - mt_tsq_fatal_error(entry->tsq); + if (entry->txq) mt_dev_tx_queue_fatal_error(entry->parent, entry->txq); + if (entry->tsq) mt_tsq_fatal_error(entry->tsq); return 0; } int mt_txq_done_cleanup(struct mt_txq_entry *entry) { - if (entry->txq) - mt_dev_tx_done_cleanup(entry->parent, entry->txq); - if (entry->tsq) - mt_tsq_done_cleanup(entry->tsq); + if (entry->txq) mt_dev_tx_done_cleanup(entry->parent, entry->txq); + if (entry->tsq) mt_tsq_done_cleanup(entry->tsq); return 0; } @@ -296,9 +271,8 @@ uint16_t mt_txq_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, return entry->burst(entry, tx_pkts, nb_pkts); } -uint16_t mt_txq_burst_busy(struct mt_txq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts, - int timeout_ms) { +uint16_t mt_txq_burst_busy(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts, int timeout_ms) { uint16_t sent = 0; struct mtl_main_impl *impl = entry->parent; uint64_t start_ts = mt_get_tsc(impl); @@ -308,8 +282,7 @@ uint16_t mt_txq_burst_busy(struct mt_txq_entry *entry, if (timeout_ms > 0) { int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (ms > timeout_ms) { - warn("%s(%u), fail as timeout to %d ms\n", __func__, entry->queue_id, - timeout_ms); + warn("%s(%u), fail as timeout to %d ms\n", __func__, entry->queue_id, timeout_ms); return sent; } } @@ -357,8 +330,7 @@ int mt_dp_queue_init(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { dp = impl->dp[i]; /* no sys tx queue */ - if (mt_drv_no_sys_txq(impl, i)) - continue; + if (mt_drv_no_sys_txq(impl, i)) continue; struct mt_txq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -382,8 +354,7 @@ int mt_dp_queue_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { struct mt_dp_impl *dp = impl->dp[i]; - if (!dp) - continue; + if (!dp) continue; if (dp->txq_sys_entry) { mt_txq_flush(dp->txq_sys_entry, mt_get_pad(impl, i)); @@ -400,8 +371,7 @@ int mt_dp_queue_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { struct mt_dp_impl *dp = impl->dp[i]; - if (!dp) - continue; + if (!dp) continue; mt_rte_free(dp); impl->dp[i] = NULL; diff --git a/lib/src/datapath/mt_queue.h b/lib/src/datapath/mt_queue.h index d468ca34d..7a267c486 100644 --- a/lib/src/datapath/mt_queue.h +++ b/lib/src/datapath/mt_queue.h @@ -41,7 +41,7 @@ struct mt_txq_entry { struct mt_tsq_entry *tsq; struct mt_tx_socket_entry *tx_socket_q; struct mt_tx_xdp_entry *tx_xdp_q; - struct mt_tx_rdma_entry *tx_rdma_q; // TODO: remove this when rdma is ready + struct mt_tx_rdma_entry *tx_rdma_q; // TODO: remove this when rdma is ready uint16_t (*burst)(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); @@ -60,9 +60,8 @@ static inline struct rte_mempool *mt_txq_mempool(struct mt_txq_entry *entry) { } uint16_t mt_txq_burst(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -uint16_t mt_txq_burst_busy(struct mt_txq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts, - int timeout_ms); +uint16_t mt_txq_burst_busy(struct mt_txq_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts, int timeout_ms); int mt_txq_flush(struct mt_txq_entry *entry, struct rte_mbuf *pad); int mt_txq_put(struct mt_txq_entry *entry); int mt_txq_fatal_error(struct mt_txq_entry *entry); diff --git a/lib/src/datapath/mt_shared_queue.c b/lib/src/datapath/mt_shared_queue.c index 41e45b5e0..e3e3b1e71 100644 --- a/lib/src/datapath/mt_shared_queue.c +++ b/lib/src/datapath/mt_shared_queue.c @@ -43,12 +43,10 @@ static int rsq_stat_dump(void *priv) { for (uint16_t q = 0; q < rsq->nb_rsq_queues; q++) { s = &rsq->rsq_queues[q]; - if (!rsq_try_lock(s)) - continue; + if (!rsq_try_lock(s)) continue; if (s->stat_pkts_recv) { - notice("%s(%d,%u), entries %d, pkt recv %d deliver %d\n", __func__, port, - q, rte_atomic32_read(&s->entry_cnt), s->stat_pkts_recv, - s->stat_pkts_deliver); + notice("%s(%d,%u), entries %d, pkt recv %d deliver %d\n", __func__, port, q, + rte_atomic32_read(&s->entry_cnt), s->stat_pkts_recv, s->stat_pkts_deliver); s->stat_pkts_recv = 0; s->stat_pkts_deliver = 0; @@ -126,8 +124,8 @@ static int rsq_init(struct mtl_main_impl *impl, struct mt_rsq_impl *rsq) { int soc_id = mt_socket_id(impl, port); struct mt_rsq_queue *rsq_queue; - rsq->rsq_queues = mt_rte_zmalloc_socket( - sizeof(*rsq->rsq_queues) * rsq->nb_rsq_queues, soc_id); + rsq->rsq_queues = + mt_rte_zmalloc_socket(sizeof(*rsq->rsq_queues) * rsq->nb_rsq_queues, soc_id); if (!rsq->rsq_queues) { err("%s(%d), rsq_queues alloc fail\n", __func__, port); return -ENOMEM; @@ -155,14 +153,13 @@ static uint32_t rsq_flow_hash(struct mt_rxq_flow *flow) { struct rte_ipv4_tuple tuple; uint32_t len; - if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) - return 0; + if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) return 0; len = RTE_THASH_V4_L4_LEN; - tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], - flow->dip_addr[2], flow->dip_addr[3]); - tuple.dst_addr = RTE_IPV4(flow->sip_addr[0], flow->sip_addr[1], - flow->sip_addr[2], flow->sip_addr[3]); + tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], + flow->dip_addr[3]); + tuple.dst_addr = RTE_IPV4(flow->sip_addr[0], flow->sip_addr[1], flow->sip_addr[2], + flow->sip_addr[3]); tuple.dport = flow->dst_port; tuple.sport = tuple.dport; return mt_softrss((uint32_t *)&tuple, len); @@ -233,8 +230,7 @@ struct mt_rsq_entry *mt_rsq_get(struct mtl_main_impl *impl, enum mtl_port port, return NULL; } - if (mt_pmd_is_dpdk_af_packet(impl, port) && - mt_is_multicast_ip(flow->dip_addr)) { + if (mt_pmd_is_dpdk_af_packet(impl, port) && mt_is_multicast_ip(flow->dip_addr)) { /* join multicast group, will drop automatically when socket fd closed */ entry->mcast_fd = mt_socket_get_multicast_fd(impl, port, flow); if (entry->mcast_fd < 0) { @@ -249,13 +245,12 @@ struct mt_rsq_entry *mt_rsq_get(struct mtl_main_impl *impl, enum mtl_port port, MT_TAILQ_INSERT_HEAD(&rsq_queue->head, entry, next); rte_atomic32_inc(&rsq_queue->entry_cnt); rsq_queue->entry_idx++; - if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) - rsq_queue->cni_entry = entry; + if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) rsq_queue->cni_entry = entry; rsq_unlock(rsq_queue); uint8_t *ip = flow->dip_addr; - info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u, on %d\n", __func__, port, - q, ip[0], ip[1], ip[2], ip[3], flow->dst_port, hash, idx); + info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u, on %d\n", __func__, port, q, ip[0], + ip[1], ip[2], ip[3], flow->dst_port, hash, idx); return entry; } @@ -276,8 +271,7 @@ static inline void rsq_entry_pkts_enqueue(struct mt_rsq_entry *entry, struct rte_mbuf **pkts, const uint16_t nb_pkts) { /* use bulk version */ - unsigned int n = - rte_ring_sp_enqueue_bulk(entry->ring, (void **)pkts, nb_pkts, NULL); + unsigned int n = rte_ring_sp_enqueue_bulk(entry->ring, (void **)pkts, nb_pkts, NULL); entry->stat_enqueue_cnt += n; if (n == 0) { rte_pktmbuf_free_bulk(pkts, nb_pkts); @@ -285,13 +279,12 @@ static inline void rsq_entry_pkts_enqueue(struct mt_rsq_entry *entry, } } -#define UPDATE_ENTRY() \ - do { \ - if (matched_pkts_nb) \ - rsq_entry_pkts_enqueue(last_rsq_entry, &matched_pkts[0], \ - matched_pkts_nb); \ - last_rsq_entry = rsq_entry; \ - matched_pkts_nb = 0; \ +#define UPDATE_ENTRY() \ + do { \ + if (matched_pkts_nb) \ + rsq_entry_pkts_enqueue(last_rsq_entry, &matched_pkts[0], matched_pkts_nb); \ + last_rsq_entry = rsq_entry; \ + matched_pkts_nb = 0; \ } while (0) static int rsq_rx(struct mt_rsq_queue *rsq_queue) { @@ -308,8 +301,7 @@ static int rsq_rx(struct mt_rsq_queue *rsq_queue) { rx = mt_rx_xdp_burst(rsq_queue->xdp, pkts, MT_SQ_BURST_SIZE); else rx = rte_eth_rx_burst(rsq_queue->port_id, q, pkts, MT_SQ_BURST_SIZE); - if (rx) - dbg("%s(%u), rx pkts %u\n", __func__, q, rx); + if (rx) dbg("%s(%u), rx pkts %u\n", __func__, q, rx); rsq_queue->stat_pkts_recv += rx; for (uint16_t i = 0; i < rx; i++) { @@ -322,16 +314,14 @@ static int rsq_rx(struct mt_rsq_queue *rsq_queue) { MT_TAILQ_FOREACH(rsq_entry, &rsq_queue->head, next) { bool matched = mt_udp_matched(&rsq_entry->flow, hdr); if (matched) { - if (rsq_entry != last_rsq_entry) - UPDATE_ENTRY(); + if (rsq_entry != last_rsq_entry) UPDATE_ENTRY(); matched_pkts[matched_pkts_nb++] = pkts[i]; break; } } if (!rsq_entry) { /* no match, redirect to cni */ UPDATE_ENTRY(); - if (rsq_queue->cni_entry) - rsq_entry_pkts_enqueue(rsq_queue->cni_entry, &pkts[i], 1); + if (rsq_queue->cni_entry) rsq_entry_pkts_enqueue(rsq_queue->cni_entry, &pkts[i], 1); } } if (matched_pkts_nb) @@ -346,12 +336,10 @@ uint16_t mt_rsq_burst(struct mt_rsq_entry *entry, struct rte_mbuf **rx_pkts, uint16_t q = entry->queue_id; struct mt_rsq_queue *rsq_queue = &rsqm->rsq_queues[q]; - if (!rsq_try_lock(rsq_queue)) - return 0; + if (!rsq_try_lock(rsq_queue)) return 0; rsq_rx(rsq_queue); rsq_unlock(rsq_queue); - uint16_t n = - rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); + uint16_t n = rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); entry->stat_dequeue_cnt += n; return n; @@ -362,10 +350,8 @@ int mt_rsq_init(struct mtl_main_impl *impl) { int ret; for (int i = 0; i < num_ports; i++) { - if (!mt_user_shared_rxq(impl, i)) - continue; - impl->rsq[i] = - mt_rte_zmalloc_socket(sizeof(*impl->rsq[i]), mt_socket_id(impl, i)); + if (!mt_user_shared_rxq(impl, i)) continue; + impl->rsq[i] = mt_rte_zmalloc_socket(sizeof(*impl->rsq[i]), mt_socket_id(impl, i)); if (!impl->rsq[i]) { err("%s(%d), rsq malloc fail\n", __func__, i); mt_rsq_uinit(impl); @@ -374,9 +360,8 @@ int mt_rsq_init(struct mtl_main_impl *impl) { impl->rsq[i]->parent = impl; impl->rsq[i]->port = i; impl->rsq[i]->nb_rsq_queues = mt_if(impl, i)->nb_rx_q; - impl->rsq[i]->queue_mode = mt_pmd_is_native_af_xdp(impl, i) - ? MT_QUEUE_MODE_XDP - : MT_QUEUE_MODE_DPDK; + impl->rsq[i]->queue_mode = + mt_pmd_is_native_af_xdp(impl, i) ? MT_QUEUE_MODE_XDP : MT_QUEUE_MODE_DPDK; ret = rsq_init(impl, impl->rsq[i]); if (ret < 0) { err("%s(%d), rsq init fail\n", __func__, i); @@ -426,8 +411,7 @@ static int tsq_stat_dump(void *priv) { for (uint16_t q = 0; q < tsq->nb_tsq_queues; q++) { s = &tsq->tsq_queues[q]; - if (!tsq_try_lock(s)) - continue; + if (!tsq_try_lock(s)) continue; if (s->stat_pkts_send) { notice("%s(%d,%u), entries %d, pkt send %d\n", __func__, tsq->port, q, rte_atomic32_read(&s->entry_cnt), s->stat_pkts_send); @@ -482,8 +466,8 @@ static int tsq_init(struct mtl_main_impl *impl, struct mt_tsq_impl *tsq) { int soc_id = mt_socket_id(impl, port); struct mt_tsq_queue *tsq_queue; - tsq->tsq_queues = mt_rte_zmalloc_socket( - sizeof(*tsq->tsq_queues) * tsq->nb_tsq_queues, soc_id); + tsq->tsq_queues = + mt_rte_zmalloc_socket(sizeof(*tsq->tsq_queues) * tsq->nb_tsq_queues, soc_id); if (!tsq->tsq_queues) { err("%s(%d), tsq_queues alloc fail\n", __func__, port); return -ENOMEM; @@ -511,12 +495,11 @@ static uint32_t tsq_flow_hash(struct mt_txq_flow *flow) { struct rte_ipv4_tuple tuple; uint32_t len; - if (flow->flags & MT_TXQ_FLOW_F_SYS_QUEUE) - return 0; + if (flow->flags & MT_TXQ_FLOW_F_SYS_QUEUE) return 0; len = RTE_THASH_V4_L4_LEN; - tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], - flow->dip_addr[2], flow->dip_addr[3]); + tuple.src_addr = RTE_IPV4(flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], + flow->dip_addr[3]); tuple.dst_addr = tuple.src_addr; tuple.sport = flow->dst_port; tuple.dport = flow->dst_port; @@ -547,8 +530,7 @@ struct mt_tsq_entry *mt_tsq_get(struct mtl_main_impl *impl, enum mtl_port port, if (tsq_queue->fatal_error) { /* loop to find a valid queue*/ for (q_b = 1; q_b < tsqm->nb_tsq_queues; q_b++) { tsq_queue = &tsqm->tsq_queues[q_b]; - if (!tsq_queue->fatal_error) - break; + if (!tsq_queue->fatal_error) break; } } @@ -557,8 +539,7 @@ struct mt_tsq_entry *mt_tsq_get(struct mtl_main_impl *impl, enum mtl_port port, return NULL; } - warn("%s(%d), q %u is fatal error, use %u instead\n", __func__, port, q, - q_b); + warn("%s(%d), q %u is fatal error, use %u instead\n", __func__, port, q, q_b); q = q_b; tsq_queue = &tsqm->tsq_queues[q]; } @@ -576,9 +557,9 @@ struct mt_tsq_entry *mt_tsq_get(struct mtl_main_impl *impl, enum mtl_port port, if (!tsq_queue->tx_pool) { char pool_name[32]; snprintf(pool_name, 32, "TSQ_P%dQ%u", port, q); - struct rte_mempool *pool = mt_mempool_create( - impl, port, pool_name, mt_if_nb_tx_desc(impl, port) + 512, - MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); + struct rte_mempool *pool = + mt_mempool_create(impl, port, pool_name, mt_if_nb_tx_desc(impl, port) + 512, + MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); if (!pool) { err("%s(%d:%u), mempool create fail\n", __func__, port, q); tsq_unlock(tsq_queue); @@ -611,8 +592,8 @@ struct mt_tsq_entry *mt_tsq_get(struct mtl_main_impl *impl, enum mtl_port port, entry->tx_pool = tsq_queue->tx_pool; uint8_t *ip = flow->dip_addr; - info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u\n", __func__, port, q, - ip[0], ip[1], ip[2], ip[3], flow->dst_port, hash); + info("%s(%d), q %u ip %u.%u.%u.%u, port %u hash %u\n", __func__, port, q, ip[0], ip[1], + ip[2], ip[3], flow->dst_port, hash); return entry; } @@ -637,8 +618,7 @@ int mt_tsq_fatal_error(struct mt_tsq_entry *entry) { tsq_queue->fatal_error = true; tsq_unlock(tsq_queue); - err("%s(%d), q %d masked as fatal error\n", __func__, tsqm->port, - tsq_queue->queue_id); + err("%s(%d), q %d masked as fatal error\n", __func__, tsqm->port, tsq_queue->queue_id); return 0; } @@ -663,18 +643,15 @@ uint16_t mt_tsq_burst(struct mt_tsq_entry *entry, struct rte_mbuf **tx_pkts, if (tsq_queue->xdp) tx = mt_tx_xdp_burst(tsq_queue->xdp, tx_pkts, nb_pkts); else - tx = rte_eth_tx_burst(tsq_queue->port_id, tsq_queue->queue_id, tx_pkts, - nb_pkts); + tx = rte_eth_tx_burst(tsq_queue->port_id, tsq_queue->queue_id, tx_pkts, nb_pkts); tsq_queue->stat_pkts_send += tx; rte_spinlock_unlock(&tsq_queue->tx_mutex); return tx; } -uint16_t mt_tsq_burst_busy(struct mtl_main_impl *impl, - struct mt_tsq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts, - int timeout_ms) { +uint16_t mt_tsq_burst_busy(struct mtl_main_impl *impl, struct mt_tsq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, int timeout_ms) { uint16_t sent = 0; uint64_t start_ts = mt_get_tsc(impl); @@ -683,8 +660,8 @@ uint16_t mt_tsq_burst_busy(struct mtl_main_impl *impl, if (timeout_ms > 0) { int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (ms > timeout_ms) { - warn("%s(%u), fail as timeout to %d ms\n", __func__, - mt_tsq_queue_id(entry), timeout_ms); + warn("%s(%u), fail as timeout to %d ms\n", __func__, mt_tsq_queue_id(entry), + timeout_ms); return sent; } } @@ -706,8 +683,7 @@ int mt_tsq_flush(struct mtl_main_impl *impl, struct mt_tsq_entry *entry, struct rte_mbuf *pads[1]; pads[0] = pad; - info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, - burst_pkts); + info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, burst_pkts); for (int i = 0; i < burst_pkts; i++) { rte_mbuf_refcnt_update(pad, 1); mt_tsq_burst_busy(impl, entry, &pads[0], 1, 10); @@ -721,10 +697,8 @@ int mt_tsq_init(struct mtl_main_impl *impl) { int ret; for (int i = 0; i < num_ports; i++) { - if (!mt_user_shared_txq(impl, i)) - continue; - impl->tsq[i] = - mt_rte_zmalloc_socket(sizeof(*impl->tsq[i]), mt_socket_id(impl, i)); + if (!mt_user_shared_txq(impl, i)) continue; + impl->tsq[i] = mt_rte_zmalloc_socket(sizeof(*impl->tsq[i]), mt_socket_id(impl, i)); if (!impl->tsq[i]) { err("%s(%d), tsq malloc fail\n", __func__, i); mt_tsq_uinit(impl); @@ -733,9 +707,8 @@ int mt_tsq_init(struct mtl_main_impl *impl) { impl->tsq[i]->parent = impl; impl->tsq[i]->port = i; impl->tsq[i]->nb_tsq_queues = mt_if(impl, i)->nb_tx_q; - impl->tsq[i]->queue_mode = mt_pmd_is_native_af_xdp(impl, i) - ? MT_QUEUE_MODE_XDP - : MT_QUEUE_MODE_DPDK; + impl->tsq[i]->queue_mode = + mt_pmd_is_native_af_xdp(impl, i) ? MT_QUEUE_MODE_XDP : MT_QUEUE_MODE_DPDK; ret = tsq_init(impl, impl->tsq[i]); if (ret < 0) { err("%s(%d), tsq init fail\n", __func__, i); diff --git a/lib/src/datapath/mt_shared_queue.h b/lib/src/datapath/mt_shared_queue.h index 5d5ceca4b..ed37a22a4 100644 --- a/lib/src/datapath/mt_shared_queue.h +++ b/lib/src/datapath/mt_shared_queue.h @@ -32,10 +32,8 @@ static inline struct rte_mempool *mt_tsq_mempool(struct mt_tsq_entry *entry) { } uint16_t mt_tsq_burst(struct mt_tsq_entry *entry, struct rte_mbuf **tx_pkts, uint16_t nb_pkts); -uint16_t mt_tsq_burst_busy(struct mtl_main_impl *impl, - struct mt_tsq_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts, - int timeout_ms); +uint16_t mt_tsq_burst_busy(struct mtl_main_impl *impl, struct mt_tsq_entry *entry, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts, int timeout_ms); int mt_tsq_flush(struct mtl_main_impl *impl, struct mt_tsq_entry *entry, struct rte_mbuf *pad); int mt_tsq_put(struct mt_tsq_entry *entry); diff --git a/lib/src/datapath/mt_shared_rss.c b/lib/src/datapath/mt_shared_rss.c index e113ffa3a..b4f90f694 100644 --- a/lib/src/datapath/mt_shared_rss.c +++ b/lib/src/datapath/mt_shared_rss.c @@ -13,8 +13,8 @@ #define MT_SRSS_BURST_SIZE (128) #define MT_SRSS_RING_PREFIX "SR_" -static inline struct mt_srss_list * -srss_list_by_udp_port(struct mt_srss_impl *srss, uint16_t port) { +static inline struct mt_srss_list *srss_list_by_udp_port(struct mt_srss_impl *srss, + uint16_t port) { int l_idx = port % srss->lists_sz; return &srss->lists[l_idx]; } @@ -37,8 +37,7 @@ static inline void srss_entry_pkts_enqueue(struct mt_srss_entry *entry, struct rte_mbuf **pkts, const uint16_t nb_pkts) { /* use bulk version */ - unsigned int n = - rte_ring_mp_enqueue_bulk(entry->ring, (void **)pkts, nb_pkts, NULL); + unsigned int n = rte_ring_mp_enqueue_bulk(entry->ring, (void **)pkts, nb_pkts, NULL); entry->stat_enqueue_cnt += n; if (n == 0) { rte_pktmbuf_free_bulk(pkts, nb_pkts); @@ -46,29 +45,27 @@ static inline void srss_entry_pkts_enqueue(struct mt_srss_entry *entry, } } -#define UPDATE_ENTRY() \ - do { \ - if (matched_pkts_nb) \ - srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], \ - matched_pkts_nb); \ - last_srss_entry = srss_entry; \ - matched_pkts_nb = 0; \ +#define UPDATE_ENTRY() \ + do { \ + if (matched_pkts_nb) \ + srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], matched_pkts_nb); \ + last_srss_entry = srss_entry; \ + matched_pkts_nb = 0; \ } while (0) -#define CNI_ENQUEUE() \ - do { \ - if (srss->cni_entry) \ - srss_entry_pkts_enqueue(srss->cni_entry, &pkts[i], 1); \ - else \ - rte_pktmbuf_free(pkts[i]); \ +#define CNI_ENQUEUE() \ + do { \ + if (srss->cni_entry) \ + srss_entry_pkts_enqueue(srss->cni_entry, &pkts[i], 1); \ + else \ + rte_pktmbuf_free(pkts[i]); \ } while (0) -#define UPDATE_LIST() \ - do { \ - if (last_list) \ - srss_list_unlock(last_list); \ - srss_list_lock(list); \ - last_list = list; \ +#define UPDATE_LIST() \ + do { \ + if (last_list) srss_list_unlock(last_list); \ + srss_list_lock(list); \ + last_list = list; \ } while (0) static int srss_sch_tasklet_handler(void *priv) { @@ -88,11 +85,10 @@ static int srss_sch_tasklet_handler(void *priv) { if (srss->xdps) { rx = mt_rx_xdp_burst(srss->xdps[queue], pkts, MT_SRSS_BURST_SIZE); } else { - rx = rte_eth_rx_burst(mt_port_id(impl, srss->port), queue, pkts, - MT_SRSS_BURST_SIZE); + rx = + rte_eth_rx_burst(mt_port_id(impl, srss->port), queue, pkts, MT_SRSS_BURST_SIZE); } - if (!rx) - continue; + if (!rx) continue; srss_sch->stat_pkts_rx += rx; last_srss_entry = NULL; @@ -122,8 +118,7 @@ static int srss_sch_tasklet_handler(void *priv) { MT_TAILQ_FOREACH(srss_entry, head, next) { bool matched = mt_udp_matched(&srss_entry->flow, hdr); if (matched) { - if (srss_entry != last_srss_entry) - UPDATE_ENTRY(); + if (srss_entry != last_srss_entry) UPDATE_ENTRY(); matched_pkts[matched_pkts_nb++] = pkts[i]; break; } @@ -135,12 +130,10 @@ static int srss_sch_tasklet_handler(void *priv) { } } if (matched_pkts_nb) - srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], - matched_pkts_nb); + srss_entry_pkts_enqueue(last_srss_entry, &matched_pkts[0], matched_pkts_nb); } - if (last_list) - srss_list_unlock(last_list); + if (last_list) srss_list_unlock(last_list); return 0; } @@ -226,8 +219,8 @@ static int srss_stat(void *priv) { struct mt_srss_entrys_list *head = &list->entrys_list; MT_TAILQ_FOREACH(entry, head, next) { idx = entry->idx; - notice("%s(%d,%d,%d), enqueue %u dequeue %u\n", __func__, port, l_idx, - idx, entry->stat_enqueue_cnt, entry->stat_dequeue_cnt); + notice("%s(%d,%d,%d), enqueue %u dequeue %u\n", __func__, port, l_idx, idx, + entry->stat_enqueue_cnt, entry->stat_dequeue_cnt); entry->stat_enqueue_cnt = 0; entry->stat_dequeue_cnt = 0; if (entry->stat_enqueue_fail_cnt) { @@ -242,8 +235,7 @@ static int srss_stat(void *priv) { for (int s_idx = 0; s_idx < srss->schs_cnt; s_idx++) { struct mt_srss_sch *srss_sch = &srss->schs[s_idx]; - notice("%s(%d,%d), pkts rx %u\n", __func__, port, s_idx, - srss_sch->stat_pkts_rx); + notice("%s(%d,%d), pkts rx %u\n", __func__, port, s_idx, srss_sch->stat_pkts_rx); srss_sch->stat_pkts_rx = 0; } @@ -252,8 +244,7 @@ static int srss_stat(void *priv) { static int srss_uinit_xdp(struct mt_srss_impl *srss) { struct mt_rx_xdp_entry **xdps = srss->xdps; - if (!xdps) - return 0; + if (!xdps) return 0; for (uint16_t queue = 0; queue < srss->nb_rx_q; queue++) { if (xdps[queue]) { @@ -300,8 +291,7 @@ static int srss_init_xdp(struct mt_srss_impl *srss) { return 0; } -struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow) { struct mt_srss_impl *srss = impl->srss[port]; int idx = srss->entry_idx; @@ -323,8 +313,8 @@ struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, if (entry->flow.dst_port == flow->dst_port && *(uint32_t *)entry->flow.dip_addr == *(uint32_t *)flow->dip_addr) { err("%s(%d,%d), already has entry %u.%u.%u.%u:%u\n", __func__, port, idx, - flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], - flow->dip_addr[3], flow->dst_port); + flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], flow->dip_addr[3], + flow->dst_port); srss_list_unlock(list); return NULL; } @@ -340,8 +330,8 @@ struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, /* ring create */ char ring_name[32]; snprintf(ring_name, 32, "%sP%d_%d", MT_SRSS_RING_PREFIX, port, idx); - entry->ring = rte_ring_create(ring_name, 512, mt_socket_id(impl, MTL_PORT_P), - RING_F_SC_DEQ); + entry->ring = + rte_ring_create(ring_name, 512, mt_socket_id(impl, MTL_PORT_P), RING_F_SC_DEQ); if (!entry->ring) { err("%s(%d,%d), ring create fail\n", __func__, port, idx); mt_rte_free(entry); @@ -354,14 +344,13 @@ struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, srss_list_lock(list); MT_TAILQ_INSERT_TAIL(head, entry, next); - if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) - srss->cni_entry = entry; + if (flow->flags & MT_RXQ_FLOW_F_SYS_QUEUE) srss->cni_entry = entry; srss->entry_idx++; srss_list_unlock(list); info("%s(%d), entry %u.%u.%u.%u:(dst)%u on %d of list %d\n", __func__, port, - flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], - flow->dip_addr[3], flow->dst_port, idx, list->idx); + flow->dip_addr[0], flow->dip_addr[1], flow->dip_addr[2], flow->dip_addr[3], + flow->dst_port, idx, list->idx); return entry; } @@ -413,11 +402,10 @@ int mt_srss_init(struct mtl_main_impl *impl) { int ret; for (int port = 0; port < num_ports; port++) { - if (!mt_has_srss(impl, port)) - continue; + if (!mt_has_srss(impl, port)) continue; - impl->srss[port] = mt_rte_zmalloc_socket(sizeof(*impl->srss[port]), - mt_socket_id(impl, port)); + impl->srss[port] = + mt_rte_zmalloc_socket(sizeof(*impl->srss[port]), mt_socket_id(impl, port)); if (!impl->srss[port]) { err("%s(%d), srss malloc fail\n", __func__, port); mt_srss_uinit(impl); @@ -427,8 +415,8 @@ int mt_srss_init(struct mtl_main_impl *impl) { srss->port = port; srss->parent = impl; - srss->queue_mode = mt_pmd_is_native_af_xdp(impl, port) ? MT_QUEUE_MODE_XDP - : MT_QUEUE_MODE_DPDK; + srss->queue_mode = + mt_pmd_is_native_af_xdp(impl, port) ? MT_QUEUE_MODE_XDP : MT_QUEUE_MODE_DPDK; srss->nb_rx_q = mt_if(impl, port)->nb_rx_q; srss->lists_sz = 64 - 1; /* use odd count for better distribution */ @@ -457,10 +445,8 @@ int mt_srss_init(struct mtl_main_impl *impl) { } srss->schs_cnt = p->rss_sch_nb[port]; - if (!srss->schs_cnt) - srss->schs_cnt = 1; - if (srss->schs_cnt > srss->nb_rx_q) - srss->schs_cnt = srss->nb_rx_q; + if (!srss->schs_cnt) srss->schs_cnt = 1; + if (srss->schs_cnt > srss->nb_rx_q) srss->schs_cnt = srss->nb_rx_q; srss->schs = mt_rte_zmalloc_socket(sizeof(*srss->schs) * srss->schs_cnt, mt_socket_id(impl, port)); if (!srss->schs) { @@ -479,8 +465,7 @@ int mt_srss_init(struct mtl_main_impl *impl) { srss_sch->quota_mps = 0; srss_sch->q_start = q_idx; uint16_t q_end = srss_sch->q_start + q_per_sch; - if (s_idx < q_remaining) - q_end++; + if (s_idx < q_remaining) q_end++; srss_sch->q_end = q_end; q_idx = q_end; @@ -508,8 +493,8 @@ int mt_srss_init(struct mtl_main_impl *impl) { } sch_mask &= ~(MTL_BIT64(sch->idx)); - info("%s(%d), sch %d with queues start %u end %u\n", __func__, port, - s_idx, srss_sch->q_start, srss_sch->q_end); + info("%s(%d), sch %d with queues start %u end %u\n", __func__, port, s_idx, + srss_sch->q_start, srss_sch->q_end); } rte_atomic32_set(&srss->stop_thread, 0); @@ -533,8 +518,7 @@ int mt_srss_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { struct mt_srss_impl *srss = impl->srss[i]; - if (!srss) - continue; + if (!srss) continue; mt_stat_unregister(impl, srss_stat, srss); srss_traffic_thread_stop(srss); @@ -563,8 +547,8 @@ int mt_srss_uinit(struct mtl_main_impl *impl) { struct mt_srss_entrys_list *head = &list->entrys_list; struct mt_srss_entry *entry; while ((entry = MT_TAILQ_FIRST(head))) { - warn("%s(%d), still has entry %p on list_heads %d\n", __func__, i, - entry, l_idx); + warn("%s(%d), still has entry %p on list_heads %d\n", __func__, i, entry, + l_idx); MT_TAILQ_REMOVE(head, entry, next); mt_rte_free(entry); } diff --git a/lib/src/datapath/mt_shared_rss.h b/lib/src/datapath/mt_shared_rss.h index b4026457b..09ebbc1af 100644 --- a/lib/src/datapath/mt_shared_rss.h +++ b/lib/src/datapath/mt_shared_rss.h @@ -11,16 +11,14 @@ int mt_srss_init(struct mtl_main_impl *impl); int mt_srss_uinit(struct mtl_main_impl *impl); -struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, - enum mtl_port port, struct mt_rxq_flow *flow); +struct mt_srss_entry *mt_srss_get(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_rxq_flow *flow); static inline uint16_t mt_srss_queue_id(struct mt_srss_entry *entry) { return entry->idx; /* use dummy id*/ } static inline uint16_t mt_srss_burst(struct mt_srss_entry *entry, - struct rte_mbuf **rx_pkts, - const uint16_t nb_pkts) { - uint16_t n = - rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); + struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { + uint16_t n = rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); entry->stat_dequeue_cnt += n; return n; } diff --git a/lib/src/dev/mt_af_xdp.c b/lib/src/dev/mt_af_xdp.c index fda82e0e5..e468648f6 100644 --- a/lib/src/dev/mt_af_xdp.c +++ b/lib/src/dev/mt_af_xdp.c @@ -89,14 +89,14 @@ struct mt_xdp_priv { bool has_ctrl; }; -static int xdp_queue_tx_max_rate(struct mt_xdp_priv *xdp, - struct mt_xdp_queue *xq, uint32_t rate_kbps) { +static int xdp_queue_tx_max_rate(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq, + uint32_t rate_kbps) { enum mtl_port port = xq->port; const char *if_name = mt_kernel_if_name(xdp->parent, port); char path[128]; - snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", - if_name, xq->q); + snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", if_name, + xq->q); int ret = mt_sysfs_write_uint32(path, rate_kbps | MTL_BIT32(31)); info("%s(%d), write %u to %s ret %d\n", __func__, port, rate_kbps, path, ret); return ret; @@ -106,26 +106,25 @@ static int xdp_queue_tx_stat(struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 - " free %" PRIu64 " wakeup %" PRIu64 "\n", - __func__, port, q, xq->stat_tx_pkts, xq->stat_tx_bytes, - xq->stat_tx_submit, xq->stat_tx_free, xq->stat_tx_wakeup); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 " free %" PRIu64 + " wakeup %" PRIu64 "\n", + __func__, port, q, xq->stat_tx_pkts, xq->stat_tx_bytes, xq->stat_tx_submit, + xq->stat_tx_free, xq->stat_tx_wakeup); xq->stat_tx_pkts = 0; xq->stat_tx_bytes = 0; xq->stat_tx_submit = 0; xq->stat_tx_free = 0; xq->stat_tx_wakeup = 0; if (xq->stat_tx_copy) { - notice("%s(%d,%u), pkts copy %" PRIu64 "\n", __func__, port, q, - xq->stat_tx_copy); + notice("%s(%d,%u), pkts copy %" PRIu64 "\n", __func__, port, q, xq->stat_tx_copy); xq->stat_tx_copy = 0; } uint32_t ring_sz = xq->umem_ring_size; uint32_t cons_avail = xsk_cons_nb_avail(&xq->tx_cons, ring_sz); uint32_t prod_free = xsk_prod_nb_free(&xq->tx_prod, ring_sz); - notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, - cons_avail, prod_free); + notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, cons_avail, + prod_free); if (xq->stat_tx_mbuf_alloc_fail) { warn("%s(%d,%u), mbuf alloc fail %" PRIu64 "\n", __func__, port, q, @@ -154,9 +153,8 @@ static int xdp_queue_rx_stat(struct mt_xdp_queue *xq) { enum mtl_port port = xq->port; uint16_t q = xq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", - __func__, port, q, xq->stat_rx_pkts, xq->stat_rx_bytes, - xq->stat_rx_burst); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", __func__, + port, q, xq->stat_rx_pkts, xq->stat_rx_bytes, xq->stat_rx_burst); xq->stat_rx_pkts = 0; xq->stat_rx_bytes = 0; xq->stat_rx_burst = 0; @@ -164,8 +162,8 @@ static int xdp_queue_rx_stat(struct mt_xdp_queue *xq) { uint32_t ring_sz = xq->umem_ring_size; uint32_t cons_avail = xsk_cons_nb_avail(&xq->rx_cons, ring_sz); uint32_t prod_free = xsk_prod_nb_free(&xq->rx_prod, ring_sz); - notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, - cons_avail, prod_free); + notice("%s(%d,%u), cons_avail %u prod_free %u\n", __func__, port, q, cons_avail, + prod_free); if (xq->stat_rx_mbuf_alloc_fail) { warn("%s(%d,%u), mbuf alloc fail %" PRIu64 "\n", __func__, port, q, @@ -192,10 +190,8 @@ static int xdp_stat_dump(void *priv) { for (uint16_t i = 0; i < xdp->queues_cnt; i++) { struct mt_xdp_queue *xq = &xdp->queues_info[i]; - if (xq->tx_entry) - xdp_queue_tx_stat(xq); - if (xq->rx_entry) - xdp_queue_rx_stat(xq); + if (xq->tx_entry) xdp_queue_tx_stat(xq); + if (xq->rx_entry) xdp_queue_rx_stat(xq); } return 0; @@ -258,8 +254,7 @@ static int xdp_parse_drv_name(struct mt_xdp_priv *xdp) { char drv_path[128]; char link_path[128]; - snprintf(drv_path, sizeof(drv_path), "/sys/class/net/%s/device/driver", - if_name); + snprintf(drv_path, sizeof(drv_path), "/sys/class/net/%s/device/driver", if_name); ssize_t len = readlink(drv_path, link_path, sizeof(link_path)); if (len < 0) { warn("%s(%d), readlink fail for %s\n", __func__, port, if_name); @@ -288,8 +283,7 @@ static int xdp_parse_pacing_ice(struct mt_xdp_priv *xdp) { uint32_t rate = MTL_BIT32(31); char path[128]; - snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", - if_name, 1); + snprintf(path, sizeof(path), "/sys/class/net/%s/queues/tx-%u/tx_maxrate", if_name, 1); int ret = mt_sysfs_write_uint32(path, rate); info("%s(%d), rl feature %s\n", __func__, port, ret < 0 ? "no" : "yes"); if (ret >= 0) { @@ -319,16 +313,14 @@ static int xdp_umem_init(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq) { rte_pktmbuf_priv_size(pool) + RTE_PKTMBUF_HEADROOM; base_addr = mt_mempool_mem_addr(pool); - aligned_base_addr = - (void *)((uint64_t)base_addr & ~(mtl_page_size(xdp->parent) - 1)); + aligned_base_addr = (void *)((uint64_t)base_addr & ~(mtl_page_size(xdp->parent) - 1)); umem_size = mt_mempool_mem_size(pool) + base_addr - aligned_base_addr; - dbg("%s(%d), base_addr %p umem_size %" PRIu64 "\n", __func__, port, - aligned_base_addr, umem_size); + dbg("%s(%d), base_addr %p umem_size %" PRIu64 "\n", __func__, port, aligned_base_addr, + umem_size); ret = xsk_umem__create(&xq->umem, aligned_base_addr, umem_size, &xq->rx_prod, &xq->tx_cons, &cfg); if (ret < 0) { - err("%s(%d,%u), umem create fail %d %s\n", __func__, port, q, ret, - strerror(errno)); + err("%s(%d,%u), umem create fail %d %s\n", __func__, port, q, ret, strerror(errno)); if (ret == -EPERM) err("%s(%d,%u), please add capability for the app: sudo setcap " "'cap_net_raw+ep' " @@ -338,13 +330,13 @@ static int xdp_umem_init(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq) { } xq->umem_buffer = aligned_base_addr; - info("%s(%d,%u), umem %p buffer %p size %" PRIu64 "\n", __func__, port, q, - xq->umem, xq->umem_buffer, umem_size); + info("%s(%d,%u), umem %p buffer %p size %" PRIu64 "\n", __func__, port, q, xq->umem, + xq->umem_buffer, umem_size); return 0; } -static inline int xdp_rx_prod_reserve(struct mt_xdp_queue *xq, - struct rte_mbuf **mbufs, uint16_t sz) { +static inline int xdp_rx_prod_reserve(struct mt_xdp_queue *xq, struct rte_mbuf **mbufs, + uint16_t sz) { enum mtl_port port = xq->port; uint16_t q = xq->q; uint32_t idx = 0; @@ -362,8 +354,7 @@ static inline int xdp_rx_prod_reserve(struct mt_xdp_queue *xq, uint64_t addr; fq_addr = xsk_ring_prod__fill_addr(pq, idx++); - addr = (uint64_t)mbufs[i] - (uint64_t)xq->umem_buffer - - xq->mbuf_pool->header_size; + addr = (uint64_t)mbufs[i] - (uint64_t)xq->umem_buffer - xq->mbuf_pool->header_size; *fq_addr = addr; } @@ -393,15 +384,13 @@ static int xdp_rx_prod_init(struct mt_xdp_queue *xq) { return 0; } -static int xdp_socket_update_xskmap(struct mtl_main_impl *impl, - struct mt_xdp_queue *xq, +static int xdp_socket_update_xskmap(struct mtl_main_impl *impl, struct mt_xdp_queue *xq, const char *ifname) { enum mtl_port port = xq->port; uint16_t q = xq->q; int ret; - int xsks_map_fd = - mt_instance_request_xsks_map_fd(impl, if_nametoindex(ifname)); + int xsks_map_fd = mt_instance_request_xsks_map_fd(impl, if_nametoindex(ifname)); if (xsks_map_fd < 0) { err("%s(%d,%u), get xsks_map_fd fail\n", __func__, port, q); @@ -441,16 +430,15 @@ static int xdp_socket_init(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq) { /* first try zero copy mode */ cfg.bind_flags |= XDP_ZEROCOPY; /* force zero copy mode */ - ret = xsk_socket__create(&xq->socket, if_name, q, xq->umem, &xq->rx_cons, - &xq->tx_prod, &cfg); + ret = xsk_socket__create(&xq->socket, if_name, q, xq->umem, &xq->rx_cons, &xq->tx_prod, + &cfg); if (ret < 0) { if (ret == -EPERM) { - err("%s(%d,%u), please run with mtl manager or root user\n", __func__, - port, q); + err("%s(%d,%u), please run with mtl manager or root user\n", __func__, port, q); return ret; } - warn("%s(%d,%u), xsk create with zero copy fail %d(%s), try copy mode\n", - __func__, port, q, ret, strerror(ret)); + warn("%s(%d,%u), xsk create with zero copy fail %d(%s), try copy mode\n", __func__, + port, q, ret, strerror(ret)); } else { xdp->flags |= XDP_F_ZERO_COPY; } @@ -463,19 +451,16 @@ static int xdp_socket_init(struct mt_xdp_priv *xdp, struct mt_xdp_queue *xq) { &xq->tx_prod, &cfg); if (ret < 0) { if (ret == -EPERM) { - err("%s(%d,%u), please run with mtl manager or root user\n", __func__, - port, q); + err("%s(%d,%u), please run with mtl manager or root user\n", __func__, port, q); } - err("%s(%d,%u), xsk create fail %d(%s)\n", __func__, port, q, ret, - strerror(ret)); + err("%s(%d,%u), xsk create fail %d(%s)\n", __func__, port, q, ret, strerror(ret)); return ret; } } xq->socket_fd = xsk_socket__fd(xq->socket); - if (xdp->has_ctrl) - return xdp_socket_update_xskmap(impl, xq, if_name); + if (xdp->has_ctrl) return xdp_socket_update_xskmap(impl, xq, if_name); return 0; } @@ -520,8 +505,8 @@ static void xdp_tx_poll_done(struct mt_xdp_queue *xq) { addr = xsk_umem__extract_addr(addr); struct rte_mbuf *m = (struct rte_mbuf *)xsk_umem__get_data( xq->umem_buffer, addr + xq->mbuf_pool->header_size); - dbg("%s(%d, %u), free mbuf %p addr 0x%" PRIu64 "\n", __func__, xq->port, - xq->q, m, addr); + dbg("%s(%d, %u), free mbuf %p addr 0x%" PRIu64 "\n", __func__, xq->port, xq->q, m, + addr); rte_pktmbuf_free(m); } xq->stat_tx_free += n; @@ -561,8 +546,7 @@ static uint16_t xdp_tx(struct mtl_main_impl *impl, struct mt_xdp_queue *xq, struct mtl_port_status *stats = mt_if(impl, port)->dev_stats_sw; uint64_t tx_bytes = 0; - xdp_tx_check_free( - xq); /* do we need check free threshold for every tx burst */ + xdp_tx_check_free(xq); /* do we need check free threshold for every tx burst */ uint32_t prod_free = xsk_prod_nb_free(&xq->tx_prod, xq->umem_ring_size); if (prod_free < xq->tx_full_thresh) { /* tx_prod is full */ @@ -589,10 +573,10 @@ static uint16_t xdp_tx(struct mtl_main_impl *impl, struct mt_xdp_queue *xq, } struct xdp_desc *desc = xsk_ring_prod__tx_desc(pd, idx); desc->len = m->pkt_len; - uint64_t addr = (uint64_t)local - (uint64_t)xq->umem_buffer - - xq->mbuf_pool->header_size; - uint64_t offset = rte_pktmbuf_mtod(local, uint64_t) - (uint64_t)local + - xq->mbuf_pool->header_size; + uint64_t addr = + (uint64_t)local - (uint64_t)xq->umem_buffer - xq->mbuf_pool->header_size; + uint64_t offset = + rte_pktmbuf_mtod(local, uint64_t) - (uint64_t)local + xq->mbuf_pool->header_size; void *pkt = xsk_umem__get_data(xq->umem_buffer, addr + offset); offset = offset << XSK_UNALIGNED_BUF_OFFSET_SHIFT; desc->addr = addr | offset; @@ -608,8 +592,8 @@ static uint16_t xdp_tx(struct mtl_main_impl *impl, struct mt_xdp_queue *xq, tx_bytes += desc->len; rte_pktmbuf_free(m); - dbg("%s(%d, %u), tx local mbuf %p umem pkt %p addr 0x%" PRIu64 "\n", - __func__, port, q, local, pkt, addr); + dbg("%s(%d, %u), tx local mbuf %p umem pkt %p addr 0x%" PRIu64 "\n", __func__, port, + q, local, pkt, addr); xq->stat_tx_copy++; tx++; } @@ -632,8 +616,7 @@ static uint16_t xdp_tx(struct mtl_main_impl *impl, struct mt_xdp_queue *xq, return tx; } -static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry *entry, - struct rte_mbuf *pkt) { +static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry *entry, struct rte_mbuf *pkt) { enum mtl_port port = entry->port; struct mt_xdp_queue *xq = entry->xq; uint16_t q = entry->queue_id; @@ -652,8 +635,7 @@ static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry *entry, } if (ipv4->next_proto_id != IPPROTO_UDP) { - dbg("%s(%d, %u), wrong next_proto_id %u\n", __func__, port, q, - ipv4->next_proto_id); + dbg("%s(%d, %u), wrong next_proto_id %u\n", __func__, port, q, ipv4->next_proto_id); return false; } @@ -661,8 +643,8 @@ static bool xdp_rx_check_pkt(struct mt_rx_xdp_entry *entry, uint16_t dst_port = ntohs(udp->dst_port); if (dst_port != entry->flow.dst_port) { xq->stat_rx_pkt_err_udp_port++; - dbg("%s(%d, %u), wrong dst_port %u expect %u\n", __func__, port, q, - dst_port, entry->flow.dst_port); + dbg("%s(%d, %u), wrong dst_port %u expect %u\n", __func__, port, q, dst_port, + entry->flow.dst_port); return false; } } @@ -681,8 +663,7 @@ static uint16_t xdp_rx(struct mt_rx_xdp_entry *entry, struct rte_mbuf **rx_pkts, uint64_t rx_bytes = 0; uint32_t idx = 0; uint32_t rx = xsk_ring_cons__peek(rx_cons, nb_pkts, &idx); - if (!rx) - return 0; + if (!rx) return 0; xq->stat_rx_burst++; @@ -707,10 +688,9 @@ static uint16_t xdp_rx(struct mt_rx_xdp_entry *entry, struct rte_mbuf **rx_pkts, len = desc->len; offset = xsk_umem__extract_offset(addr); addr = xsk_umem__extract_addr(addr); - struct rte_mbuf *pkt = - xsk_umem__get_data(xq->umem_buffer, addr + mp->header_size); - pkt->data_off = offset - sizeof(struct rte_mbuf) - - rte_pktmbuf_priv_size(mp) - mp->header_size; + struct rte_mbuf *pkt = xsk_umem__get_data(xq->umem_buffer, addr + mp->header_size); + pkt->data_off = + offset - sizeof(struct rte_mbuf) - rte_pktmbuf_priv_size(mp) - mp->header_size; rte_pktmbuf_pkt_len(pkt) = len; rte_pktmbuf_data_len(pkt) = len; if (entry->skip_all_check || xdp_rx_check_pkt(entry, pkt)) { @@ -755,8 +735,7 @@ int mt_dev_xdp_init(struct mt_interface *inf) { return -EIO; } - struct mt_xdp_priv *xdp = - mt_rte_zmalloc_socket(sizeof(*xdp), mt_socket_id(impl, port)); + struct mt_xdp_priv *xdp = mt_rte_zmalloc_socket(sizeof(*xdp), mt_socket_id(impl, port)); if (!xdp) { err("%s(%d), xdp malloc fail\n", __func__, port); return -ENOMEM; @@ -770,8 +749,8 @@ int mt_dev_xdp_init(struct mt_interface *inf) { xdp_parse_drv_name(xdp); - xdp->queues_info = mt_rte_zmalloc_socket( - sizeof(*xdp->queues_info) * xdp->queues_cnt, mt_socket_id(impl, port)); + xdp->queues_info = mt_rte_zmalloc_socket(sizeof(*xdp->queues_info) * xdp->queues_cnt, + mt_socket_id(impl, port)); if (!xdp->queues_info) { err("%s(%d), xdp queues_info malloc fail\n", __func__, port); xdp_free(xdp); @@ -813,8 +792,7 @@ int mt_dev_xdp_init(struct mt_interface *inf) { return ret; } - if (0 == strncmp(xdp->drv, "ice", sizeof("ice"))) - xdp_parse_pacing_ice(xdp); + if (0 == strncmp(xdp->drv, "ice", sizeof("ice"))) xdp_parse_pacing_ice(xdp); inf->port_id = inf->port; inf->xdp = xdp; @@ -825,8 +803,7 @@ int mt_dev_xdp_init(struct mt_interface *inf) { int mt_dev_xdp_uinit(struct mt_interface *inf) { struct mt_xdp_priv *xdp = inf->xdp; - if (!xdp) - return 0; + if (!xdp) return 0; struct mtl_main_impl *impl = inf->parent; mt_stat_unregister(impl, xdp_stat_dump, xdp); @@ -837,8 +814,7 @@ int mt_dev_xdp_uinit(struct mt_interface *inf) { return 0; } -struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_txq_flow *flow, struct mt_tx_xdp_get_args *args) { if (!mt_pmd_is_native_af_xdp(impl, port)) { @@ -901,8 +877,8 @@ struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, } uint8_t *ip = flow->dip_addr; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], + ip[3], flow->dst_port, entry->queue_id); return entry; } @@ -924,16 +900,16 @@ int mt_tx_xdp_put(struct mt_tx_xdp_entry *entry) { xdp_queue_tx_stat(xq); xq->tx_entry = NULL; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], + ip[2], ip[3], flow->dst_port, entry->queue_id); } mt_rte_free(entry); return 0; } -uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return xdp_tx(entry->parent, entry->xq, tx_pkts, nb_pkts); } @@ -942,8 +918,7 @@ static inline int xdp_socket_update_dp(struct mtl_main_impl *impl, int ifindex, return mt_instance_update_udp_dp_filter(impl, ifindex, dp, add); } -struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow, struct mt_rx_xdp_get_args *args) { if (!mt_pmd_is_native_af_xdp(impl, port)) { @@ -1010,8 +985,7 @@ struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, mt_rx_xdp_put(entry); return NULL; } - if (xdp->has_ctrl && - !xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, true)) + if (xdp->has_ctrl && !xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, true)) entry->skip_all_check = true; else entry->skip_all_check = false; @@ -1030,8 +1004,8 @@ struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, entry->mcast_fd = mcast_fd; uint8_t *ip = flow->dip_addr; - info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], - ip[2], ip[3], flow->dst_port); + info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], ip[2], + ip[3], flow->dst_port); return entry; } @@ -1051,20 +1025,19 @@ int mt_rx_xdp_put(struct mt_rx_xdp_entry *entry) { if (entry->flow_rsp) { mt_rx_flow_free(impl, port, entry->flow_rsp); entry->flow_rsp = NULL; - if (xdp->has_ctrl) - xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, false); + if (xdp->has_ctrl) xdp_socket_update_dp(impl, xdp->ifindex, flow->dst_port, false); } if (xq) { xdp_queue_rx_stat(xq); xq->rx_entry = NULL; } - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], + ip[3], flow->dst_port, entry->queue_id); mt_rte_free(entry); return 0; } -uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry *entry, - struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { +uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry *entry, struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts) { return xdp_rx(entry, rx_pkts, nb_pkts); } diff --git a/lib/src/dev/mt_af_xdp.h b/lib/src/dev/mt_af_xdp.h index 05dc8581e..5aae6e63a 100644 --- a/lib/src/dev/mt_af_xdp.h +++ b/lib/src/dev/mt_af_xdp.h @@ -24,21 +24,19 @@ struct mt_rx_xdp_get_args { int mt_dev_xdp_init(struct mt_interface *inf); int mt_dev_xdp_uinit(struct mt_interface *inf); -struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_txq_flow *flow, struct mt_tx_xdp_get_args *args); int mt_tx_xdp_put(struct mt_tx_xdp_entry *entry); -uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts); +uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts); -struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow, struct mt_rx_xdp_get_args *args); int mt_rx_xdp_put(struct mt_rx_xdp_entry *entry); -uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry *entry, - struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); +uint16_t mt_rx_xdp_burst(struct mt_rx_xdp_entry *entry, struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts); #else #include "../mt_log.h" @@ -53,9 +51,10 @@ static inline int mt_dev_xdp_uinit(struct mt_interface *inf) { return -ENOTSUP; } -static inline struct mt_tx_xdp_entry * -mt_tx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_txq_flow *flow, struct mt_tx_xdp_get_args *args) { +static inline struct mt_tx_xdp_entry *mt_tx_xdp_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow, + struct mt_tx_xdp_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); @@ -69,17 +68,17 @@ static inline int mt_tx_xdp_put(struct mt_tx_xdp_entry *entry) { } static inline uint16_t mt_tx_xdp_burst(struct mt_tx_xdp_entry *entry, - struct rte_mbuf **tx_pkts, - uint16_t nb_pkts) { + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(tx_pkts); MTL_MAY_UNUSED(nb_pkts); return 0; } -static inline struct mt_rx_xdp_entry * -mt_rx_xdp_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_rxq_flow *flow, struct mt_rx_xdp_get_args *args) { +static inline struct mt_rx_xdp_entry *mt_rx_xdp_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow, + struct mt_rx_xdp_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); diff --git a/lib/src/dev/mt_dev.c b/lib/src/dev/mt_dev.c index 8cf9cd384..c61c93abb 100644 --- a/lib/src/dev/mt_dev.c +++ b/lib/src/dev/mt_dev.c @@ -79,50 +79,45 @@ static const struct mt_dev_driver_info dev_drvs[] = { .port_type = MT_PORT_DPDK_AF_XDP, .drv_type = MT_DRV_DPDK_AF_XDP, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | - MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_KERNEL_BASED, + .flags = MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | + MT_DRV_F_KERNEL_BASED, }, { .name = "net_af_packet", .port_type = MT_PORT_DPDK_AF_PKT, .drv_type = MT_DRV_DPDK_AF_PKT, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | - MT_DRV_F_RX_NO_FLOW | MT_DRV_F_KERNEL_BASED | - MT_DRV_F_MCAST_IN_DP, + .flags = MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_RX_NO_FLOW | + MT_DRV_F_KERNEL_BASED | MT_DRV_F_MCAST_IN_DP, }, { .name = "kernel_socket", .port_type = MT_PORT_KERNEL_SOCKET, .drv_type = MT_DRV_KERNEL_SOCKET, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | - MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_NO_FLOW | - MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, + .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | + MT_DRV_F_RX_NO_FLOW | MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, }, { .name = "native_af_xdp", .port_type = MT_PORT_NATIVE_AF_XDP, .drv_type = MT_DRV_NATIVE_AF_XDP, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | - MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | - MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, + .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | + MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED, }, { .name = "rdma", .port_type = MT_PORT_RDMA_UD, .drv_type = MT_DRV_IRDMA, .flow_type = MT_FLOW_ALL, - .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | - MT_DRV_F_USE_KERNEL_CTL | MT_DRV_F_RX_POOL_COMMON | - MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED | + .flags = MT_DRV_F_NOT_DPDK_PMD | MT_DRV_F_NO_CNI | MT_DRV_F_USE_KERNEL_CTL | + MT_DRV_F_RX_POOL_COMMON | MT_DRV_F_MCAST_IN_DP | MT_DRV_F_KERNEL_BASED | MT_DRV_F_NO_SYS_TX_QUEUE, }, }; -static int parse_driver_info(const char *driver, - struct mt_dev_driver_info *drv_info) { +static int parse_driver_info(const char *driver, struct mt_dev_driver_info *drv_info) { for (int i = 0; i < MTL_ARRAY_SIZE(dev_drvs); i++) { if (!strcmp(dev_drvs[i].name, driver)) { *drv_info = dev_drvs[i]; @@ -130,12 +125,9 @@ static int parse_driver_info(const char *driver, } } - warn("%s, unknown nic driver %s, use the default drv info\n", __func__, - driver); - warn("%s, use the default drv info, please add one item in dev_drvs array\n", - __func__); - *drv_info = - dev_drvs[0]; /* the default is always the first one in the arrays */ + warn("%s, unknown nic driver %s, use the default drv info\n", __func__, driver); + warn("%s, use the default drv info, please add one item in dev_drvs array\n", __func__); + *drv_info = dev_drvs[0]; /* the default is always the first one in the arrays */ return 0; } @@ -177,8 +169,7 @@ static inline void diff_and_update(uint64_t *new, uint64_t *old) { *old = temp; } -static void stat_update_dpdk(struct mtl_port_status *sum, - struct rte_eth_stats *update, +static void stat_update_dpdk(struct mtl_port_status *sum, struct rte_eth_stats *update, enum mt_driver_type drv_type) { sum->rx_packets += update->ipackets; sum->tx_packets += update->opackets; @@ -186,8 +177,7 @@ static void stat_update_dpdk(struct mtl_port_status *sum, sum->tx_bytes += update->obytes; sum->rx_err_packets += update->ierrors; /* iavf wrong report the tx error */ - if (drv_type != MT_DRV_IAVF) - sum->tx_err_packets += update->oerrors; + if (drv_type != MT_DRV_IAVF) sum->tx_err_packets += update->oerrors; sum->rx_hw_dropped_packets += update->imissed; sum->rx_nombuf_packets += update->rx_nombuf; } @@ -217,8 +207,7 @@ static int dev_inf_get_stat_dpdk(struct mt_interface *inf) { diff_and_update(&stats.obytes, &dev_stats_not_reset->tx_bytes); diff_and_update(&stats.ierrors, &dev_stats_not_reset->rx_err_packets); diff_and_update(&stats.oerrors, &dev_stats_not_reset->tx_err_packets); - diff_and_update(&stats.imissed, - &dev_stats_not_reset->rx_hw_dropped_packets); + diff_and_update(&stats.imissed, &dev_stats_not_reset->rx_hw_dropped_packets); diff_and_update(&stats.rx_nombuf, &dev_stats_not_reset->rx_nombuf_packets); } @@ -238,8 +227,7 @@ static int dev_inf_get_stat_dpdk(struct mt_interface *inf) { return 0; } -static void stat_update_sw(struct mtl_port_status *sum, - struct mtl_port_status *update) { +static void stat_update_sw(struct mtl_port_status *sum, struct mtl_port_status *update) { sum->rx_packets += update->rx_packets; sum->tx_packets += update->tx_packets; sum->rx_bytes += update->rx_bytes; @@ -286,19 +274,16 @@ static int dev_inf_stat(void *pri) { stats_sum = &inf->stats_sum; double dump_period_s = mt_stat_dump_period_s(impl); - double orate_m = - (double)stats_sum->tx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; - double irate_m = - (double)stats_sum->rx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; + double orate_m = (double)stats_sum->tx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; + double irate_m = (double)stats_sum->rx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT; notice("DEV(%d): Avr rate, tx: %f Mb/s, rx: %f Mb/s, pkts, tx: %" PRIu64 ", rx: %" PRIu64 "\n", port, orate_m, irate_m, stats_sum->tx_packets, stats_sum->rx_packets); if (stats_sum->rx_hw_dropped_packets || stats_sum->rx_err_packets || stats_sum->rx_nombuf_packets || stats_sum->tx_err_packets) { - err("DEV(%d): Status: rx_hw_dropped_packets %" PRIu64 - " rx_err_packets %" PRIu64 " rx_nombuf_packets %" PRIu64 - " tx_err_packets %" PRIu64 "\n", + err("DEV(%d): Status: rx_hw_dropped_packets %" PRIu64 " rx_err_packets %" PRIu64 + " rx_nombuf_packets %" PRIu64 " tx_err_packets %" PRIu64 "\n", port, stats_sum->rx_hw_dropped_packets, stats_sum->rx_err_packets, stats_sum->rx_nombuf_packets, stats_sum->tx_err_packets); dev_eth_xstat(port_id); @@ -328,8 +313,7 @@ static void *dev_eal_init_thread(void *arg) { return NULL; } -static int dev_eal_init(struct mtl_init_params *p, - struct mt_kport_info *kport_info) { +static int dev_eal_init(struct mtl_init_params *p, struct mt_kport_info *kport_info) { char *argv[MT_EAL_MAX_ARGS]; int argc, ret; int num_ports = RTE_MIN(p->num_ports, MTL_PORT_MAX); @@ -360,24 +344,19 @@ static int dev_eal_init(struct mtl_init_params *p, pmd = p->pmd[i]; if (pmd == MTL_PMD_KERNEL_SOCKET) { const char *if_name = mt_kernel_port2if(p->port[i]); - if (!if_name) - return -EINVAL; - snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "kernel_socket_%d", - i); + if (!if_name) return -EINVAL; + snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "kernel_socket_%d", i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); continue; } else if (pmd == MTL_PMD_NATIVE_AF_XDP) { const char *if_name = mt_native_afxdp_port2if(p->port[i]); - if (!if_name) - return -EINVAL; - snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "native_af_xdp_%d", - i); + if (!if_name) return -EINVAL; + snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "native_af_xdp_%d", i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); continue; } else if (pmd == MTL_PMD_RDMA_UD) { const char *if_name = mt_rdma_ud_port2if(p->port[i]); - if (!if_name) - return -EINVAL; + if (!if_name) return -EINVAL; snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "rdma_%d", i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); continue; @@ -401,24 +380,21 @@ static int dev_eal_init(struct mtl_init_params *p, uint16_t queue_pair_cnt = RTE_MAX(p->tx_queues_cnt[i], p->rx_queues_cnt[i]); if (p->pmd[i] == MTL_PMD_DPDK_AF_XDP) { const char *if_name = mt_dpdk_afxdp_port2if(p->port[i]); - if (!if_name) - return -EINVAL; + if (!if_name) return -EINVAL; snprintf(port_param, 2 * MTL_PORT_MAX_LEN, - "net_af_xdp%d,iface=%s,start_queue=%u,queue_count=%u", i, - if_name, MT_DPDK_AF_XDP_START_QUEUE, queue_pair_cnt); + "net_af_xdp%d,iface=%s,start_queue=%u,queue_count=%u", i, if_name, + MT_DPDK_AF_XDP_START_QUEUE, queue_pair_cnt); /* save kport info */ snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "net_af_xdp%d", i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); } else if (p->pmd[i] == MTL_PMD_DPDK_AF_PACKET) { const char *if_name = mt_dpdk_afpkt_port2if(p->port[i]); - if (!if_name) - return -EINVAL; + if (!if_name) return -EINVAL; snprintf(port_param, 2 * MTL_PORT_MAX_LEN, - "eth_af_packet%d,iface=%s,framesz=2048,blocksz=4096,qpairs=%u", - i, if_name, queue_pair_cnt + 1); + "eth_af_packet%d,iface=%s,framesz=2048,blocksz=4096,qpairs=%u", i, if_name, + queue_pair_cnt + 1); /* save kport info */ - snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "eth_af_packet%d", - i); + snprintf(kport_info->dpdk_port[i], MTL_PORT_MAX_LEN, "eth_af_packet%d", i); snprintf(kport_info->kernel_if[i], MTL_PORT_MAX_LEN, "%s", if_name); } else { snprintf(port_param, 2 * MTL_PORT_MAX_LEN, "%s", p->port[i]); @@ -528,8 +504,7 @@ static int dev_eal_init(struct mtl_init_params *p, info("%s, wait eal_init_thread done\n", __func__); pthread_join(eal_init_thread, NULL); ret = i_args.result; - if (ret < 0) - return ret; + if (ret < 0) return ret; eal_initted = true; @@ -546,8 +521,7 @@ int dev_rx_runtime_queue_start(struct mtl_main_impl *impl, enum mtl_port port) { if (rx_queue->active) { ret = rte_eth_dev_rx_queue_start(inf->port_id, q); if (ret < 0) - err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, - ret); + err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, ret); } } @@ -555,8 +529,7 @@ int dev_rx_runtime_queue_start(struct mtl_main_impl *impl, enum mtl_port port) { } /* flush all the old bufs in the rx queue already */ -static int dev_flush_rx_queue(struct mt_interface *inf, - struct mt_rx_queue *queue) { +static int dev_flush_rx_queue(struct mt_interface *inf, struct mt_rx_queue *queue) { int mbuf_size = 128; int loop = inf->nb_rx_desc / mbuf_size; struct rte_mbuf *mbuf[mbuf_size]; @@ -564,8 +537,7 @@ static int dev_flush_rx_queue(struct mt_interface *inf, for (int i = 0; i < loop; i++) { rv = mt_dpdk_rx_burst(queue, &mbuf[0], mbuf_size); - if (!rv) - break; + if (!rv) break; rte_pktmbuf_free_bulk(&mbuf[0], rv); } @@ -577,16 +549,14 @@ static int dev_flush_rx_queue(struct mt_interface *inf, #define ST_DEFAULT_NODE_ID 246 #define ST_DEFAULT_RL_BPS (1024 * 1024 * 1024 / 8) /* 1g bit per second */ -static int dev_rl_init_root(struct mt_interface *inf, - uint32_t shaper_profile_id) { +static int dev_rl_init_root(struct mt_interface *inf, uint32_t shaper_profile_id) { uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; int ret; struct rte_tm_error error; struct rte_tm_node_params np; - if (inf->tx_rl_root_active) - return 0; + if (inf->tx_rl_root_active) return 0; memset(&error, 0, sizeof(error)); memset(&np, 0, sizeof(np)); @@ -602,8 +572,8 @@ static int dev_rl_init_root(struct mt_interface *inf, } /* nonleaf node based on root */ - ret = rte_tm_node_add(port_id, ST_DEFAULT_NODE_ID, ST_ROOT_NODE_ID, 0, 1, 1, - &np, &error); + ret = + rte_tm_node_add(port_id, ST_DEFAULT_NODE_ID, ST_ROOT_NODE_ID, 0, 1, 1, &np, &error); if (ret < 0) { err("%s(%d), node add error: (%d)%s\n", __func__, port, ret, mt_string_safe(error.message)); @@ -614,8 +584,7 @@ static int dev_rl_init_root(struct mt_interface *inf, return 0; } -static struct mt_rl_shaper *dev_rl_shaper_add(struct mt_interface *inf, - uint64_t bps) { +static struct mt_rl_shaper *dev_rl_shaper_add(struct mt_interface *inf, uint64_t bps) { struct mt_rl_shaper *shapers = &inf->tx_rl_shapers[0]; uint16_t port_id = inf->port_id; enum mtl_port port = inf->port; @@ -627,8 +596,7 @@ static struct mt_rl_shaper *dev_rl_shaper_add(struct mt_interface *inf, memset(&error, 0, sizeof(error)); for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (shapers[i].rl_bps) - continue; + if (shapers[i].rl_bps) continue; shaper_profile_id = ST_SHAPER_PROFILE_ID + i; @@ -661,13 +629,11 @@ static struct mt_rl_shaper *dev_rl_shaper_add(struct mt_interface *inf, return NULL; } -static struct mt_rl_shaper *dev_rl_shaper_get(struct mt_interface *inf, - uint64_t bps) { +static struct mt_rl_shaper *dev_rl_shaper_get(struct mt_interface *inf, uint64_t bps) { struct mt_rl_shaper *shapers = &inf->tx_rl_shapers[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (bps == shapers[i].rl_bps) - return &shapers[i]; + if (bps == shapers[i].rl_bps) return &shapers[i]; } return dev_rl_shaper_add(inf, bps); @@ -736,8 +702,7 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface *inf, uint16_t queue, } /* not changed */ - if (bps == tx_queue->bps) - return 0; + if (bps == tx_queue->bps) return 0; /* delete old queue node */ if (tx_queue->rl_shapers_mapping >= 0) { @@ -760,16 +725,15 @@ static int dev_tx_queue_set_rl_rate(struct mt_interface *inf, uint16_t queue, qp.shaper_profile_id = shaper->shaper_profile_id; qp.leaf.cman = RTE_TM_CMAN_TAIL_DROP; qp.leaf.wred.wred_profile_id = RTE_TM_WRED_PROFILE_ID_NONE; - ret = rte_tm_node_add(port_id, queue, ST_DEFAULT_NODE_ID, 0, 1, 2, &qp, - &error); + ret = rte_tm_node_add(port_id, queue, ST_DEFAULT_NODE_ID, 0, 1, 2, &qp, &error); if (ret < 0) { err("%s(%d), q %d add fail %d(%s)\n", __func__, port, queue, ret, mt_string_safe(error.message)); return ret; } tx_queue->rl_shapers_mapping = shaper->idx; - info("%s(%d), q %d link to shaper id %d(%" PRIu64 ")\n", __func__, port, - queue, shaper->shaper_profile_id, shaper->rl_bps); + info("%s(%d), q %d link to shaper id %d(%" PRIu64 ")\n", __func__, port, queue, + shaper->shaper_profile_id, shaper->rl_bps); } mt_pthread_mutex_lock(&inf->vf_cmd_mutex); @@ -798,8 +762,7 @@ static int dev_stop_port(struct mt_interface *inf) { if (!(inf->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD)) { ret = rte_eth_dev_stop(port_id); - if (ret < 0) - err("%s(%d), rte_eth_dev_stop fail %d\n", __func__, port, ret); + if (ret < 0) err("%s(%d), rte_eth_dev_stop fail %d\n", __func__, port, ret); } inf->status &= ~MT_IF_STAT_PORT_STARTED; @@ -819,8 +782,7 @@ static int dev_close_port(struct mt_interface *inf) { if (!(inf->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD)) { ret = rte_eth_dev_close(port_id); - if (ret < 0) - err("%s(%d), rte_eth_dev_close fail %d\n", __func__, port, ret); + if (ret < 0) err("%s(%d), rte_eth_dev_close fail %d\n", __func__, port, ret); } inf->status &= ~MT_IF_STAT_PORT_CONFIGURED; @@ -886,8 +848,8 @@ static int dev_start_timesync(struct mt_interface *inf) { info("%s(%d), init ptp time %s, i %d\n", __func__, port, date_time, i); break; } - dbg("%s(%d), tv_sec %" PRIu64 " tv_nsec %" PRIu64 ", i %d\n", __func__, - port, spec.tv_sec, spec.tv_nsec, i); + dbg("%s(%d), tv_sec %" PRIu64 " tv_nsec %" PRIu64 ", i %d\n", __func__, port, + spec.tv_sec, spec.tv_nsec, i); mt_sleep_ms(10); } if (i >= max_retry) { @@ -941,9 +903,8 @@ static int dev_config_port(struct mt_interface *inf) { inf->nb_tx_desc = nb_tx_desc; inf->nb_rx_desc = nb_rx_desc; inf->status |= MT_IF_STAT_PORT_CONFIGURED; - info( - "%s(%d), not dpdk based tx_q(%d with %d desc) rx_q (%d with %d desc)\n", - __func__, port, nb_tx_q, nb_tx_desc, nb_rx_q, nb_rx_desc); + info("%s(%d), not dpdk based tx_q(%d with %d desc) rx_q (%d with %d desc)\n", + __func__, port, nb_tx_q, nb_tx_desc, nb_rx_q, nb_rx_desc); return 0; } @@ -985,10 +946,9 @@ static int dev_config_port(struct mt_interface *inf) { err("%s(%d), not support rss_mode %d\n", __func__, port, inf->rss_mode); return -EIO; } - if (rss_conf->rss_hf != - (inf->dev_info.flow_type_rss_offloads & rss_conf->rss_hf)) { - err("%s(%d), not support rss offload %" PRIx64 ", mode %d\n", __func__, - port, rss_conf->rss_hf, inf->rss_mode); + if (rss_conf->rss_hf != (inf->dev_info.flow_type_rss_offloads & rss_conf->rss_hf)) { + err("%s(%d), not support rss offload %" PRIx64 ", mode %d\n", __func__, port, + rss_conf->rss_hf, inf->rss_mode); return -EIO; } port_conf.rxmode.mq_mode = RTE_ETH_MQ_RX_RSS; @@ -1004,22 +964,18 @@ static int dev_config_port(struct mt_interface *inf) { port_conf = dev_port_conf; ret = rte_eth_dev_configure(inf->virtio_port_id, 1, 1, &port_conf); if (ret < 0) { - err("%s(%d), rte_eth_dev_configure virtio port fail %d\n", __func__, port, - ret); + err("%s(%d), rte_eth_dev_configure virtio port fail %d\n", __func__, port, ret); return ret; } } /* apply if user has rx_tx_desc config */ - if (p->nb_tx_desc) - nb_tx_desc = p->nb_tx_desc; - if (p->nb_rx_desc) - nb_rx_desc = p->nb_rx_desc; + if (p->nb_tx_desc) nb_tx_desc = p->nb_tx_desc; + if (p->nb_rx_desc) nb_rx_desc = p->nb_rx_desc; ret = rte_eth_dev_adjust_nb_rx_tx_desc(port_id, &nb_rx_desc, &nb_tx_desc); if (ret < 0) { - err("%s(%d), rte_eth_dev_adjust_nb_rx_tx_desc fail %d\n", __func__, port, - ret); + err("%s(%d), rte_eth_dev_adjust_nb_rx_tx_desc fail %d\n", __func__, port, ret); return ret; } inf->nb_tx_desc = nb_tx_desc; @@ -1030,10 +986,10 @@ static int dev_config_port(struct mt_interface *inf) { uint32_t set_ptypes[16]; uint32_t ptype_mask = RTE_PTYPE_L2_ETHER_TIMESYNC | RTE_PTYPE_L2_ETHER_ARP | RTE_PTYPE_L2_ETHER_VLAN | RTE_PTYPE_L2_ETHER_QINQ | - RTE_PTYPE_L4_ICMP | RTE_PTYPE_L3_IPV4 | - RTE_PTYPE_L4_UDP | RTE_PTYPE_L4_FRAG; - int num_ptypes = rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, ptypes, - RTE_DIM(ptypes)); + RTE_PTYPE_L4_ICMP | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP | + RTE_PTYPE_L4_FRAG; + int num_ptypes = + rte_eth_dev_get_supported_ptypes(port_id, ptype_mask, ptypes, RTE_DIM(ptypes)); for (int i = 0; i < num_ptypes; i++) { set_ptypes[i] = ptypes[i]; } @@ -1044,13 +1000,13 @@ static int dev_config_port(struct mt_interface *inf) { return ret; } } else { - warn("%s(%d), failed to setup all ptype, only %d supported\n", __func__, - port, num_ptypes); + warn("%s(%d), failed to setup all ptype, only %d supported\n", __func__, port, + num_ptypes); } inf->status |= MT_IF_STAT_PORT_CONFIGURED; - info("%s(%d), tx_q(%d with %d desc) rx_q (%d with %d desc)\n", __func__, port, - nb_tx_q, nb_tx_desc, nb_rx_q, nb_rx_desc); + info("%s(%d), tx_q(%d with %d desc) rx_q (%d with %d desc)\n", __func__, port, nb_tx_q, + nb_tx_desc, nb_rx_q, nb_rx_desc); return 0; } @@ -1061,13 +1017,12 @@ static bool dev_pkt_valid(struct mt_interface *inf, uint16_t queue, enum mtl_port port = inf->port; if ((pkt_len <= 16) || (pkt_len > MTL_MTU_MAX_BYTES)) { - err("%s(%d:%u), invalid pkt_len %u at %p\n", __func__, port, queue, pkt_len, - pkt); + err("%s(%d:%u), invalid pkt_len %u at %p\n", __func__, port, queue, pkt_len, pkt); return false; } if (pkt->nb_segs > 2) { - err("%s(%d:%u), invalid nb_segs %u at %p\n", __func__, port, queue, - pkt->nb_segs, pkt); + err("%s(%d:%u), invalid nb_segs %u at %p\n", __func__, port, queue, pkt->nb_segs, + pkt); return false; } @@ -1075,9 +1030,8 @@ static bool dev_pkt_valid(struct mt_interface *inf, uint16_t queue, } #endif -static uint16_t dev_tx_pkt_check(uint16_t port, uint16_t queue, - struct rte_mbuf **pkts, uint16_t nb_pkts, - void *priv) { +static uint16_t dev_tx_pkt_check(uint16_t port, uint16_t queue, struct rte_mbuf **pkts, + uint16_t nb_pkts, void *priv) { struct mt_interface *inf = priv; MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(nb_pkts); @@ -1127,8 +1081,7 @@ static int dev_start_port(struct mt_interface *inf) { return 0; } - if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) - rx_deferred_start = 1; + if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) rx_deferred_start = 1; rx_port_conf.rx_deferred_start = rx_deferred_start; struct rte_mempool *mbuf_pool; @@ -1174,30 +1127,29 @@ static int dev_start_port(struct mt_interface *inf) { rx_port_conf.rx_nseg = 2; rx_port_conf.rx_seg = rx_usegs; - ret = rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, - &rx_port_conf, NULL); + ret = + rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, &rx_port_conf, NULL); #else err("%s, no hdr split support for this dpdk build\n", __func__); return -ENOTSUP; #endif } else { - ret = rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, - &rx_port_conf, mbuf_pool); + ret = rte_eth_rx_queue_setup(port_id, q, nb_rx_desc, socket_id, &rx_port_conf, + mbuf_pool); } if (ret < 0) { - err("%s(%d), rte_eth_rx_queue_setup fail %d for queue %d\n", __func__, - port, ret, q); + err("%s(%d), rte_eth_rx_queue_setup fail %d for queue %d\n", __func__, port, ret, + q); return ret; } } for (uint16_t q = 0; q < nb_tx_q; q++) { tx_port_conf = inf->dev_info.default_txconf; - ret = rte_eth_tx_queue_setup(port_id, q, nb_tx_desc, socket_id, - &tx_port_conf); + ret = rte_eth_tx_queue_setup(port_id, q, nb_tx_desc, socket_id, &tx_port_conf); if (ret < 0) { - err("%s(%d), rte_eth_tx_queue_setup fail %d for queue %d\n", __func__, - port, ret, q); + err("%s(%d), rte_eth_tx_queue_setup fail %d for queue %d\n", __func__, port, ret, + q); return ret; } } @@ -1217,23 +1169,21 @@ static int dev_start_port(struct mt_interface *inf) { if (mt_has_virtio_user(impl, port)) { mbuf_pool = inf->rx_queues[0].mbuf_pool ? inf->rx_queues[0].mbuf_pool : mt_sys_rx_mempool(impl, port); - ret = rte_eth_rx_queue_setup(inf->virtio_port_id, 0, 0, socket_id, NULL, - mbuf_pool); + ret = rte_eth_rx_queue_setup(inf->virtio_port_id, 0, 0, socket_id, NULL, mbuf_pool); if (ret < 0) { - err("%s(%d), rte_eth_rx_queue_setup fail %d for virtio port\n", __func__, - port, ret); + err("%s(%d), rte_eth_rx_queue_setup fail %d for virtio port\n", __func__, port, + ret); return ret; } ret = rte_eth_tx_queue_setup(inf->virtio_port_id, 0, 0, socket_id, NULL); if (ret < 0) { - err("%s(%d), rte_eth_tx_queue_setup fail %d for virtio port\n", __func__, - port, ret); + err("%s(%d), rte_eth_tx_queue_setup fail %d for virtio port\n", __func__, port, + ret); return ret; } ret = rte_eth_dev_start(inf->virtio_port_id); if (ret < 0) { - err("%s(%d), rte_eth_dev_start virtio port fail %d\n", __func__, port, - ret); + err("%s(%d), rte_eth_dev_start virtio port fail %d\n", __func__, port, ret); return ret; } } @@ -1263,8 +1213,7 @@ static int dev_if_uinit_rx_queues(struct mt_interface *inf) { enum mtl_port port = inf->port; struct mt_rx_queue *rx_queue; - if (!inf->rx_queues) - return 0; + if (!inf->rx_queues) return 0; for (uint16_t q = 0; q < inf->nb_rx_q; q++) { rx_queue = &inf->rx_queues[q]; @@ -1293,16 +1242,13 @@ static int dev_if_uinit_rx_queues(struct mt_interface *inf) { return 0; } -static int dev_if_init_rx_queues(struct mtl_main_impl *impl, - struct mt_interface *inf) { - if (!inf->nb_rx_q) - return 0; +static int dev_if_init_rx_queues(struct mtl_main_impl *impl, struct mt_interface *inf) { + if (!inf->nb_rx_q) return 0; struct mt_rx_queue *rx_queues = mt_rte_zmalloc_socket(sizeof(*rx_queues) * inf->nb_rx_q, inf->socket_id); if (!rx_queues) { - err("%s(%d), rx_queues zmalloc fail, queues %u\n", __func__, inf->port, - inf->nb_rx_q); + err("%s(%d), rx_queues zmalloc fail, queues %u\n", __func__, inf->port, inf->nb_rx_q); return -ENOMEM; } @@ -1315,8 +1261,8 @@ static int dev_if_init_rx_queues(struct mtl_main_impl *impl, /* Create mempool to hold the rx queue mbufs. */ unsigned int mbuf_elements = inf->nb_rx_desc + 1024; char pool_name[ST_MAX_NAME_LEN]; - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_MBUF", - MT_RX_MEMPOOL_PREFIX, inf->port, q); + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_MBUF", MT_RX_MEMPOOL_PREFIX, + inf->port, q); struct rte_mempool *mbuf_pool = NULL; if (inf->drv_info.flags & MT_DRV_F_RX_POOL_COMMON) { @@ -1325,8 +1271,7 @@ static int dev_if_init_rx_queues(struct mtl_main_impl *impl, MT_MBUF_CACHE_SIZE, 0, 2048); } else { if (q < inf->system_rx_queues_end) - mbuf_pool = mt_mempool_create_common(impl, inf->port, pool_name, - mbuf_elements); + mbuf_pool = mt_mempool_create_common(impl, inf->port, pool_name, mbuf_elements); else { uint16_t data_room_sz = ST_PKT_MAX_ETHER_BYTES; /* to avoid igc/igxbe nic split mbuf */ @@ -1335,9 +1280,9 @@ static int dev_if_init_rx_queues(struct mtl_main_impl *impl, data_room_sz = MT_MBUF_DEFAULT_DATA_SIZE; if (impl->rx_pool_data_size) /* user suggested data room size */ data_room_sz = impl->rx_pool_data_size; - mbuf_pool = mt_mempool_create( - impl, inf->port, pool_name, mbuf_elements, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), data_room_sz); + mbuf_pool = mt_mempool_create(impl, inf->port, pool_name, mbuf_elements, + MT_MBUF_CACHE_SIZE, + sizeof(struct mt_muf_priv_data), data_room_sz); } } if (!mbuf_pool) { @@ -1348,18 +1293,17 @@ static int dev_if_init_rx_queues(struct mtl_main_impl *impl, rx_queues[q].mbuf_elements = mbuf_elements; /* hdr split payload mbuf */ - if ((q >= inf->system_rx_queues_end) && - (q < inf->hdr_split_rx_queues_end)) { + if ((q >= inf->system_rx_queues_end) && (q < inf->hdr_split_rx_queues_end)) { if (!mt_if_has_hdr_split(impl, inf->port)) { err("%s(%d), no hdr split feature\n", __func__, inf->port); dev_if_uinit_rx_queues(inf); return -EIO; } - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_PAYLOAD", - MT_RX_MEMPOOL_PREFIX, inf->port, q); - mbuf_pool = mt_mempool_create( - impl, inf->port, pool_name, mbuf_elements, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), ST_PKT_MAX_ETHER_BYTES); + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%dQ%d_PAYLOAD", MT_RX_MEMPOOL_PREFIX, + inf->port, q); + mbuf_pool = mt_mempool_create(impl, inf->port, pool_name, mbuf_elements, + MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), + ST_PKT_MAX_ETHER_BYTES); if (!mbuf_pool) { dev_if_uinit_rx_queues(inf); return -ENOMEM; @@ -1378,8 +1322,7 @@ static int dev_if_uinit_tx_queues(struct mt_interface *inf) { enum mtl_port port = inf->port; struct mt_tx_queue *tx_queue; - if (!inf->tx_queues) - return 0; + if (!inf->tx_queues) return 0; for (uint16_t q = 0; q < inf->nb_tx_q; q++) { tx_queue = &inf->tx_queues[q]; @@ -1395,14 +1338,12 @@ static int dev_if_uinit_tx_queues(struct mt_interface *inf) { } static int dev_if_init_tx_queues(struct mt_interface *inf) { - if (!inf->nb_tx_q) - return 0; + if (!inf->nb_tx_q) return 0; struct mt_tx_queue *tx_queues = mt_rte_zmalloc_socket(sizeof(*tx_queues) * inf->nb_tx_q, inf->socket_id); if (!tx_queues) { - err("%s(%d), tx_queues %u malloc alloc\n", __func__, inf->port, - inf->nb_tx_q); + err("%s(%d), tx_queues %u malloc alloc\n", __func__, inf->port, inf->nb_tx_q); return -ENOMEM; } @@ -1457,8 +1398,7 @@ static int dev_if_init_pacing(struct mt_interface *inf) { ret = dev_init_ratelimit_all(inf); } else { ret = dev_tx_queue_set_rl_rate(inf, 0, ST_DEFAULT_RL_BPS); - if (ret >= 0) - dev_tx_queue_set_rl_rate(inf, 0, 0); + if (ret >= 0) dev_tx_queue_set_rl_rate(inf, 0, 0); } if (ret < 0) { /* fallback to tsc if no rl */ if (auto_detect) { @@ -1488,11 +1428,10 @@ static int dev_if_init_virtio_user(struct mt_interface *inf) { snprintf(name, sizeof(name), "virtio_user%u", (uint8_t)port_id); /* to limit name length, assume port_id < 255 */ - snprintf( - args, sizeof(args), - "path=/dev/" - "vhost-net,queues=1,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, - 1024, name, RTE_ETHER_ADDR_BYTES(&addr)); + snprintf(args, sizeof(args), + "path=/dev/" + "vhost-net,queues=1,queue_size=%u,iface=%s,mac=" RTE_ETHER_ADDR_PRT_FMT, + 1024, name, RTE_ETHER_ADDR_BYTES(&addr)); ret = rte_eal_hotplug_add("vdev", name, args); if (ret < 0) { @@ -1508,8 +1447,7 @@ static int dev_if_init_virtio_user(struct mt_interface *inf) { } inf->virtio_port_id = virtio_port_id; - ret = mt_socket_set_if_ip(name, mt_sip_addr(impl, port), - mt_sip_netmask(impl, port)); + ret = mt_socket_set_if_ip(name, mt_sip_addr(impl, port), mt_sip_netmask(impl, port)); if (ret < 0) { err("%s(%d), cannot set interface ip\n", __func__, port); return ret; @@ -1534,8 +1472,7 @@ static int dev_if_init_virtio_user(struct mt_interface *inf) { #endif } -static uint64_t ptp_from_real_time(struct mtl_main_impl *impl, - enum mtl_port port) { +static uint64_t ptp_from_real_time(struct mtl_main_impl *impl, enum mtl_port port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); return mt_get_real_time(); @@ -1554,8 +1491,7 @@ static uint64_t ptp_from_tsc(struct mtl_main_impl *impl, enum mtl_port port) { return inf->real_time_base + tsc - inf->tsc_time_base; } -struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, enum mtl_port port, struct mt_txq_flow *flow) { struct mt_interface *inf = mt_if(impl, port); uint64_t bytes_per_sec = flow->bytes_per_sec; @@ -1563,8 +1499,8 @@ struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, int ret; if (mt_user_shared_txq(impl, port)) { - err("%s(%d), conflict with shared tx queue mode, use tsq api instead\n", - __func__, port); + err("%s(%d), conflict with shared tx queue mode, use tsq api instead\n", __func__, + port); return NULL; } @@ -1580,17 +1516,14 @@ struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, */ if (flow->flags & MT_TXQ_FLOW_F_LAUNCH_TIME) { /* If require LaunchTime based pacing, queue 0 is the only choice. */ - if (q != 0) - break; + if (q != 0) break; } else { /* If not require LaunchTime based pacing, queue 0 is invisible. */ - if (q == 0) - continue; + if (q == 0) continue; } } tx_queue = &inf->tx_queues[q]; - if (tx_queue->active || tx_queue->fatal_error) - continue; + if (tx_queue->active || tx_queue->fatal_error) continue; if (inf->tx_pacing_way == ST21_TX_PACING_WAY_RL) { ret = dev_tx_queue_set_rl_rate(inf, q, bytes_per_sec); @@ -1615,50 +1548,43 @@ struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, return NULL; } -struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow) { struct mt_interface *inf = mt_if(impl, port); int ret; struct mt_rx_queue *rx_queue; if (mt_has_srss(impl, port)) { - err("%s(%d), conflict with srss mode, use srss api instead\n", __func__, - port); + err("%s(%d), conflict with srss mode, use srss api instead\n", __func__, port); return NULL; } if (mt_user_shared_rxq(impl, port)) { - err("%s(%d), conflict with shared rx queue mode, use rsq api instead\n", - __func__, port); + err("%s(%d), conflict with shared rx queue mode, use rsq api instead\n", __func__, + port); return NULL; } mt_pthread_mutex_lock(&inf->rx_queues_mutex); for (uint16_t q = 0; q < inf->nb_rx_q; q++) { rx_queue = &inf->rx_queues[q]; - if (rx_queue->active) - continue; + if (rx_queue->active) continue; if (flow && (flow->flags & MT_RXQ_FLOW_F_HDR_SPLIT)) { /* continue if not hdr split queue */ - if (!mt_if_hdr_split_pool(inf, q)) - continue; + if (!mt_if_hdr_split_pool(inf, q)) continue; #ifdef ST_HAS_DPDK_HDR_SPLIT if (flow->hdr_split_mbuf_cb) { - ret = rte_eth_hdrs_set_mbuf_callback(inf->port_id, q, - flow->hdr_split_mbuf_cb_priv, - flow->hdr_split_mbuf_cb); + ret = rte_eth_hdrs_set_mbuf_callback( + inf->port_id, q, flow->hdr_split_mbuf_cb_priv, flow->hdr_split_mbuf_cb); if (ret < 0) { - err("%s(%d), hdrs callback fail %d for queue %d\n", __func__, port, - ret, q); + err("%s(%d), hdrs callback fail %d for queue %d\n", __func__, port, ret, q); mt_pthread_mutex_unlock(&inf->rx_queues_mutex); return NULL; } } #endif } else { /* continue if hdr split queue */ - if (mt_if_hdr_split_pool(inf, q)) - continue; + if (mt_if_hdr_split_pool(inf, q)) continue; } /* free the dummy flow if any */ @@ -1681,8 +1607,7 @@ struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) { ret = rte_eth_dev_rx_queue_start(inf->port_id, q); if (ret < 0) { - err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, - ret); + err("%s(%d), start runtime rx queue %d fail %d\n", __func__, port, q, ret); if (rx_queue->flow_rsp) { mt_rx_flow_free(impl, port, rx_queue->flow_rsp); rx_queue->flow_rsp = NULL; @@ -1697,8 +1622,8 @@ struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, dev_flush_rx_queue(inf, rx_queue); if (flow) { uint8_t *ip = flow->dip_addr; - info("%s(%d), q %u ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], - ip[1], ip[2], ip[3], flow->dst_port); + info("%s(%d), q %u ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], + ip[2], ip[3], flow->dst_port); } else { info("%s(%d), q %u\n", __func__, port, q); } @@ -1710,8 +1635,7 @@ struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, return NULL; } -uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, - struct mt_tx_queue *queue, +uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, struct mt_tx_queue *queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts, int timeout_ms) { uint16_t sent = 0; @@ -1722,8 +1646,8 @@ uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, if (timeout_ms > 0) { int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (ms > timeout_ms) { - warn("%s(%u), fail as timeout to %d ms\n", __func__, - mt_dev_tx_queue_id(queue), timeout_ms); + warn("%s(%u), fail as timeout to %d ms\n", __func__, mt_dev_tx_queue_id(queue), + timeout_ms); return sent; } } @@ -1733,8 +1657,8 @@ uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, return sent; } -int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, - struct mt_tx_queue *queue, struct rte_mbuf *pad) { +int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, struct mt_tx_queue *queue, + struct rte_mbuf *pad) { enum mtl_port port = queue->port; uint16_t queue_id = queue->queue_id; @@ -1744,8 +1668,7 @@ int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, struct rte_mbuf *pads[1]; pads[0] = pad; - info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, - burst_pkts); + info("%s(%d), queue %u burst_pkts %d\n", __func__, port, queue_id, burst_pkts); for (int i = 0; i < burst_pkts; i++) { rte_mbuf_refcnt_update(pad, 1); mt_dpdk_tx_burst_busy(impl, queue, &pads[0], 1, 1); @@ -1754,8 +1677,7 @@ int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, return 0; } -int mt_dev_tx_done_cleanup(struct mtl_main_impl *impl, - struct mt_tx_queue *queue) { +int mt_dev_tx_done_cleanup(struct mtl_main_impl *impl, struct mt_tx_queue *queue) { uint16_t port_id = queue->port_id; uint16_t queue_id = queue->queue_id; MTL_MAY_UNUSED(impl); @@ -1789,8 +1711,7 @@ int mt_dev_put_tx_queue(struct mtl_main_impl *impl, struct mt_tx_queue *queue) { return 0; } -int mt_dev_tx_queue_fatal_error(struct mtl_main_impl *impl, - struct mt_tx_queue *queue) { +int mt_dev_tx_queue_fatal_error(struct mtl_main_impl *impl, struct mt_tx_queue *queue) { enum mtl_port port = queue->port; struct mt_interface *inf = mt_if(impl, port); struct mt_tx_queue *tx_queue; @@ -1828,8 +1749,7 @@ int mt_dev_set_tx_bps(struct mtl_main_impl *impl, struct mt_tx_queue *queue, } if (inf->tx_pacing_way != ST21_TX_PACING_WAY_RL) { - err("%s(%d,%u), pacing %d is not rl\n", __func__, port, queue_id, - inf->tx_pacing_way); + err("%s(%d,%u), pacing %d is not rl\n", __func__, port, queue_id, inf->tx_pacing_way); return -ENOTSUP; } @@ -1871,8 +1791,7 @@ int mt_dev_put_rx_queue(struct mtl_main_impl *impl, struct mt_rx_queue *queue) { if (inf->feature & MT_IF_FEATURE_RUNTIME_RX_QUEUE) { ret = rte_eth_dev_rx_queue_stop(inf->port_id, queue_id); if (ret < 0) - err("%s(%d), stop runtime rx queue %d fail %d\n", __func__, port, - queue_id, ret); + err("%s(%d), stop runtime rx queue %d fail %d\n", __func__, port, queue_id, ret); } rx_queue->active = false; @@ -1897,8 +1816,7 @@ int mt_dev_create(struct mtl_main_impl *impl) { if ((mt_user_ptp_service(impl) || mt_user_hw_timestamp(impl)) && (port_type == MT_PORT_PF)) { ret = dev_start_timesync(inf); - if (ret >= 0) - inf->feature |= MT_IF_FEATURE_TIMESYNC; + if (ret >= 0) inf->feature |= MT_IF_FEATURE_TIMESYNC; } #endif @@ -1915,8 +1833,7 @@ int mt_dev_create(struct mtl_main_impl *impl) { } ret = dev_detect_link(inf); /* some port can only detect link after start */ if (ret < 0) { - err("%s(%d), dev_detect_link fail %d retry %d\n", __func__, i, ret, - detect_retry); + err("%s(%d), dev_detect_link fail %d retry %d\n", __func__, i, ret, detect_retry); if (detect_retry < 3) { detect_retry++; rte_eth_dev_reset(inf->port_id); @@ -1934,8 +1851,7 @@ int mt_dev_create(struct mtl_main_impl *impl) { if ((mt_user_ptp_service(impl) || mt_user_hw_timestamp(impl)) && (port_type == MT_PORT_PF) && !(inf->feature & MT_IF_FEATURE_TIMESYNC)) { ret = dev_start_timesync(inf); - if (ret >= 0) - inf->feature |= MT_IF_FEATURE_TIMESYNC; + if (ret >= 0) inf->feature |= MT_IF_FEATURE_TIMESYNC; } ret = dev_if_init_pacing(inf); @@ -1945,8 +1861,8 @@ int mt_dev_create(struct mtl_main_impl *impl) { } if (inf->drv_info.flags & MT_DRV_F_NO_STATUS_RESET) { - inf->dev_stats_not_reset = mt_rte_zmalloc_socket( - sizeof(*inf->dev_stats_not_reset), inf->socket_id); + inf->dev_stats_not_reset = + mt_rte_zmalloc_socket(sizeof(*inf->dev_stats_not_reset), inf->socket_id); if (!inf->dev_stats_not_reset) { err("%s(%d), malloc dev_stats_not_reset fail\n", __func__, i); ret = -ENOMEM; @@ -1985,9 +1901,8 @@ int mt_dev_create(struct mtl_main_impl *impl) { } /* create system sch */ - enum mt_sch_type type = mt_user_dedicated_sys_lcore(impl) - ? MT_SCH_TYPE_SYSTEM - : MT_SCH_TYPE_DEFAULT; + enum mt_sch_type type = + mt_user_dedicated_sys_lcore(impl) ? MT_SCH_TYPE_SYSTEM : MT_SCH_TYPE_DEFAULT; impl->main_sch = mt_sch_get(impl, 0, type, MT_SCH_MASK_ALL); if (!impl->main_sch) { err("%s, get sch fail\n", __func__); @@ -1998,8 +1913,7 @@ int mt_dev_create(struct mtl_main_impl *impl) { return 0; err_exit: - if (impl->main_sch) - mt_sch_put(impl->main_sch, 0); + if (impl->main_sch) mt_sch_put(impl->main_sch, 0); for (int i = num_ports - 1; i >= 0; i--) { inf = mt_if(impl, i); @@ -2057,8 +1971,7 @@ int mt_dev_get_socket_id(const char *port) { int ret = rte_eth_dev_get_port_by_name(port, &port_id); if (ret < 0) { err("%s, failed to get port for %s\n", __func__, port); - err("%s, please make sure the driver of %s is configured rightly\n", - __func__, port); + err("%s, please make sure the driver of %s is configured rightly\n", __func__, port); return ret; } int soc_id; @@ -2076,8 +1989,8 @@ int mt_dev_init(struct mtl_init_params *p, struct mt_kport_info *kport_info) { #if RTE_VERSION >= RTE_VERSION_NUM(23, 7, 0, 0) /* introduce from 23.07 */ if (p->memzone_max) { rte_memzone_max_set(p->memzone_max); - info("%s, user preferred memzone_max %u, now %" PRIu64 "\n", __func__, - p->memzone_max, rte_memzone_max_get()); + info("%s, user preferred memzone_max %u, now %" PRIu64 "\n", __func__, p->memzone_max, + rte_memzone_max_get()); } #endif @@ -2130,13 +2043,11 @@ int mt_dev_if_uinit(struct mtl_main_impl *impl) { if (inf->tx_mbuf_pool) { ret = mt_mempool_free(inf->tx_mbuf_pool); - if (ret >= 0) - inf->tx_mbuf_pool = NULL; + if (ret >= 0) inf->tx_mbuf_pool = NULL; } if (inf->rx_mbuf_pool) { ret = mt_mempool_free(inf->rx_mbuf_pool); - if (ret >= 0) - inf->rx_mbuf_pool = NULL; + if (ret >= 0) inf->rx_mbuf_pool = NULL; } mt_pthread_mutex_destroy(&inf->tx_queues_mutex); @@ -2225,16 +2136,14 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { inf->net_proto = p->net_proto[i]; inf->rss_mode = p->rss_mode; /* enable rss if no flow support */ - if (inf->drv_info.flow_type == MT_FLOW_NONE && - inf->rss_mode == MTL_RSS_MODE_NONE) { + if (inf->drv_info.flow_type == MT_FLOW_NONE && inf->rss_mode == MTL_RSS_MODE_NONE) { inf->rss_mode = MTL_RSS_MODE_L3_L4; /* default l3_l4 */ } - info("%s(%d), user request queues tx %u rx %u\n", __func__, i, - p->tx_queues_cnt[i], p->rx_queues_cnt[i]); + info("%s(%d), user request queues tx %u rx %u\n", __func__, i, p->tx_queues_cnt[i], + p->rx_queues_cnt[i]); uint16_t queue_pair_cnt = RTE_MAX(p->tx_queues_cnt[i], p->rx_queues_cnt[i]); - if (!queue_pair_cnt) - queue_pair_cnt = 1; /* at least 1 queue pair */ + if (!queue_pair_cnt) queue_pair_cnt = 1; /* at least 1 queue pair */ /* set max tx/rx queues */ if (mt_pmd_is_kernel_socket(impl, i)) { inf->nb_tx_q = p->tx_queues_cnt[i]; @@ -2287,8 +2196,8 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { inf->hdr_split_rx_queues_end = inf->system_rx_queues_end + p->nb_rx_hdr_split_queues; } - dbg("%s(%d), tx_queues %u dev max tx queues %u\n", __func__, i, - inf->nb_tx_q, dev_info->max_tx_queues); + dbg("%s(%d), tx_queues %u dev max tx queues %u\n", __func__, i, inf->nb_tx_q, + dev_info->max_tx_queues); if (!(inf->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD)) { /* max tx/rx queues don't exceed dev limit */ inf->nb_tx_q = RTE_MIN(inf->nb_tx_q, dev_info->max_tx_queues); @@ -2299,8 +2208,7 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { inf->nb_tx_q = RTE_MAX(inf->nb_tx_q, inf->nb_rx_q); inf->nb_rx_q = inf->nb_tx_q; } - dbg("%s(%d), tx_queues %u rx queues %u\n", __func__, i, inf->nb_tx_q, - inf->nb_rx_q); + dbg("%s(%d), tx_queues %u rx queues %u\n", __func__, i, inf->nb_tx_q, inf->nb_rx_q); /* feature detect */ if (dev_info->dev_capa & RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP) @@ -2323,8 +2231,7 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { #endif /* Disable checksum calculation for RDMA UD backend */ - if (mt_pmd_is_rdma_ud(impl, i)) - inf->feature |= MT_IF_FEATURE_TX_OFFLOAD_IPV4_CKSUM; + if (mt_pmd_is_rdma_ud(impl, i)) inf->feature |= MT_IF_FEATURE_TX_OFFLOAD_IPV4_CKSUM; #if RTE_VERSION >= RTE_VERSION_NUM(23, 3, 0, 0) /* Detect LaunchTime capability */ @@ -2334,23 +2241,20 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { int *dev_tx_timestamp_dynfield_offset_ptr = dev_info->default_txconf.reserved_ptrs[1]; - uint64_t *dev_tx_timestamp_dynflag_ptr = - dev_info->default_txconf.reserved_ptrs[0]; - ret = rte_mbuf_dyn_tx_timestamp_register( - dev_tx_timestamp_dynfield_offset_ptr, dev_tx_timestamp_dynflag_ptr); + uint64_t *dev_tx_timestamp_dynflag_ptr = dev_info->default_txconf.reserved_ptrs[0]; + ret = rte_mbuf_dyn_tx_timestamp_register(dev_tx_timestamp_dynfield_offset_ptr, + dev_tx_timestamp_dynflag_ptr); if (ret < 0) { err("%s, rte_mbuf_dyn_tx_timestamp_register fail\n", __func__); return ret; } ret = rte_mbuf_dynflag_lookup(RTE_MBUF_DYNFLAG_TX_TIMESTAMP_NAME, NULL); - if (ret < 0) - return ret; + if (ret < 0) return ret; inf->tx_launch_time_flag = 1ULL << ret; ret = rte_mbuf_dynfield_lookup(RTE_MBUF_DYNFIELD_TIMESTAMP_NAME, NULL); - if (ret < 0) - return ret; + if (ret < 0) return ret; inf->tx_dynfield_offset = ret; } #endif @@ -2368,9 +2272,10 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { err("%s, rte_mbuf_dyn_rx_timestamp_register fail\n", __func__); return ret; } - info("%s, rte_mbuf_dyn_rx_timestamp_register: mbuf dynfield offset: " - "%d\n", - __func__, impl->dynfield_offset); + info( + "%s, rte_mbuf_dyn_rx_timestamp_register: mbuf dynfield offset: " + "%d\n", + __func__, impl->dynfield_offset); } inf->feature |= MT_IF_FEATURE_RX_OFFLOAD_TIMESTAMP; } @@ -2410,8 +2315,7 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { mbuf_elements = 1024; /* append as rx queues */ mbuf_elements += inf->nb_rx_q * inf->nb_rx_desc; - snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%d_SYS", MT_RX_MEMPOOL_PREFIX, - i); + snprintf(pool_name, ST_MAX_NAME_LEN, "%sP%d_SYS", MT_RX_MEMPOOL_PREFIX, i); mbuf_pool = mt_mempool_create_common(impl, i, pool_name, mbuf_elements); if (!mbuf_pool) { mt_dev_if_uinit(impl); @@ -2445,8 +2349,8 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { return -ENOMEM; } - inf->pad = mt_build_pad(impl, mt_sys_tx_mempool(impl, i), i, - RTE_ETHER_TYPE_IPV4, 1024); + inf->pad = + mt_build_pad(impl, mt_sys_tx_mempool(impl, i), i, RTE_ETHER_TYPE_IPV4, 1024); if (!inf->pad) { err("%s(%d), pad alloc fail\n", __func__, i); mt_dev_if_uinit(impl); @@ -2483,21 +2387,19 @@ int mt_dev_if_init(struct mtl_main_impl *impl) { __func__, i, dev_info->dev_capa, dev_info->tx_offload_capa, dev_info->rx_offload_capa, dev_info->tx_queue_offload_capa, dev_info->rx_queue_offload_capa, dev_info->flow_type_rss_offloads); - info("%s(%d), system_rx_queues_end %d hdr_split_rx_queues_end %d\n", - __func__, i, inf->system_rx_queues_end, inf->hdr_split_rx_queues_end); + info("%s(%d), system_rx_queues_end %d hdr_split_rx_queues_end %d\n", __func__, i, + inf->system_rx_queues_end, inf->hdr_split_rx_queues_end); uint8_t *ip = p->sip_addr[i]; info("%s(%d), sip: %u.%u.%u.%u\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); uint8_t *nm = p->netmask[i]; - info("%s(%d), netmask: %u.%u.%u.%u\n", __func__, i, nm[0], nm[1], nm[2], - nm[3]); + info("%s(%d), netmask: %u.%u.%u.%u\n", __func__, i, nm[0], nm[1], nm[2], nm[3]); uint8_t *gw = p->gateway[i]; - info("%s(%d), gateway: %u.%u.%u.%u\n", __func__, i, gw[0], gw[1], gw[2], - gw[3]); + info("%s(%d), gateway: %u.%u.%u.%u\n", __func__, i, gw[0], gw[1], gw[2], gw[3]); struct rte_ether_addr mac; mt_macaddr_get(impl, i, &mac); - info("%s(%d), mac: %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, i, - mac.addr_bytes[0], mac.addr_bytes[1], mac.addr_bytes[2], - mac.addr_bytes[3], mac.addr_bytes[4], mac.addr_bytes[5]); + info("%s(%d), mac: %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, i, mac.addr_bytes[0], + mac.addr_bytes[1], mac.addr_bytes[2], mac.addr_bytes[3], mac.addr_bytes[4], + mac.addr_bytes[5]); } return 0; @@ -2518,11 +2420,9 @@ int mt_dev_if_pre_uinit(struct mtl_main_impl *impl) { if (mt_has_virtio_user(impl, i)) { inf->virtio_port_active = false; int ret = rte_eth_dev_stop(inf->virtio_port_id); - if (ret < 0) - warn("%s(%d), stop virtio port fail %d\n", __func__, i, ret); + if (ret < 0) warn("%s(%d), stop virtio port fail %d\n", __func__, i, ret); ret = rte_eth_dev_close(inf->virtio_port_id); - if (ret < 0) - warn("%s(%d), close virtio port fail %d\n", __func__, i, ret); + if (ret < 0) warn("%s(%d), close virtio port fail %d\n", __func__, i, ret); } } @@ -2583,8 +2483,7 @@ int mt_read_admin_port_stats(struct mtl_main_impl *impl, enum mtl_port port, return 0; } -int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, - struct mtl_port_status *stats) { +int mtl_get_port_stats(mtl_handle mt, enum mtl_port port, struct mtl_port_status *stats) { struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { diff --git a/lib/src/dev/mt_dev.h b/lib/src/dev/mt_dev.h index 5b9453ebe..5def4e0a1 100644 --- a/lib/src/dev/mt_dev.h +++ b/lib/src/dev/mt_dev.h @@ -30,33 +30,27 @@ int mt_dev_free(struct mtl_main_impl *impl); int mt_dev_start(struct mtl_main_impl *impl); int mt_dev_stop(struct mtl_main_impl *impl); -struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_tx_queue *mt_dev_get_tx_queue(struct mtl_main_impl *impl, enum mtl_port port, struct mt_txq_flow *flow); int mt_dev_put_tx_queue(struct mtl_main_impl *impl, struct mt_tx_queue *queue); static inline uint16_t mt_dev_tx_queue_id(struct mt_tx_queue *queue) { return queue->queue_id; } -int mt_dev_tx_queue_fatal_error(struct mtl_main_impl *impl, - struct mt_tx_queue *queue); +int mt_dev_tx_queue_fatal_error(struct mtl_main_impl *impl, struct mt_tx_queue *queue); int mt_dev_set_tx_bps(struct mtl_main_impl *impl, struct mt_tx_queue *queue, uint64_t bytes_per_sec); -int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, - struct mt_tx_queue *queue, struct rte_mbuf *pad); -int mt_dev_tx_done_cleanup(struct mtl_main_impl *impl, - struct mt_tx_queue *queue); +int mt_dpdk_flush_tx_queue(struct mtl_main_impl *impl, struct mt_tx_queue *queue, + struct rte_mbuf *pad); +int mt_dev_tx_done_cleanup(struct mtl_main_impl *impl, struct mt_tx_queue *queue); static inline uint16_t mt_dpdk_tx_burst(struct mt_tx_queue *queue, - struct rte_mbuf **tx_pkts, - uint16_t nb_pkts) { + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { return rte_eth_tx_burst(queue->port_id, queue->queue_id, tx_pkts, nb_pkts); } -uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, - struct mt_tx_queue *queue, +uint16_t mt_dpdk_tx_burst_busy(struct mtl_main_impl *impl, struct mt_tx_queue *queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts, int timeout_ms); -struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_rx_queue *mt_dev_get_rx_queue(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow); int mt_dev_put_rx_queue(struct mtl_main_impl *impl, struct mt_rx_queue *queue); static inline uint16_t mt_dev_rx_queue_id(struct mt_rx_queue *queue) { diff --git a/lib/src/dev/mt_rdma_ud.c b/lib/src/dev/mt_rdma_ud.c index 8756988f2..80c41fcd6 100644 --- a/lib/src/dev/mt_rdma_ud.c +++ b/lib/src/dev/mt_rdma_ud.c @@ -95,14 +95,12 @@ struct mt_rdma_priv { pthread_mutex_t queues_lock; }; -static inline uint32_t rdma_flow_hash(uint8_t *sip, uint8_t *dip, - uint16_t sport, uint16_t dport) { +static inline uint32_t rdma_flow_hash(uint8_t *sip, uint8_t *dip, uint16_t sport, + uint16_t dport) { struct rte_ipv4_tuple tuple = {}; - if (sip) - tuple.src_addr = RTE_IPV4(sip[0], sip[1], sip[2], sip[3]); - if (dip) - tuple.dst_addr = RTE_IPV4(dip[0], dip[1], dip[2], dip[3]); + if (sip) tuple.src_addr = RTE_IPV4(sip[0], sip[1], sip[2], sip[3]); + if (dip) tuple.dst_addr = RTE_IPV4(dip[0], dip[1], dip[2], dip[3]); tuple.sport = sport; tuple.dport = dport; return mt_softrss((uint32_t *)&tuple, RTE_THASH_V4_L4_LEN); @@ -112,10 +110,10 @@ static int rdma_tx_queue_stat(struct mt_rdma_tx_queue *txq) { enum mtl_port port = txq->port; uint16_t q = txq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 - " free %" PRIu64 "\n", - __func__, port, q, txq->stat_tx_pkts, txq->stat_tx_bytes, - txq->stat_tx_submit, txq->stat_tx_free); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " submit %" PRIu64 " free %" PRIu64 + "\n", + __func__, port, q, txq->stat_tx_pkts, txq->stat_tx_bytes, txq->stat_tx_submit, + txq->stat_tx_free); txq->stat_tx_pkts = 0; txq->stat_tx_bytes = 0; txq->stat_tx_submit = 0; @@ -148,9 +146,8 @@ static int rdma_rx_queue_stat(struct mt_rdma_rx_queue *rxq) { enum mtl_port port = rxq->port; uint16_t q = rxq->q; - notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", - __func__, port, q, rxq->stat_rx_pkts, rxq->stat_rx_bytes, - rxq->stat_rx_burst); + notice("%s(%d,%u), pkts %" PRIu64 " bytes %" PRIu64 " burst %" PRIu64 "\n", __func__, + port, q, rxq->stat_rx_pkts, rxq->stat_rx_bytes, rxq->stat_rx_burst); rxq->stat_rx_pkts = 0; rxq->stat_rx_bytes = 0; rxq->stat_rx_burst = 0; @@ -166,8 +163,7 @@ static int rdma_rx_queue_stat(struct mt_rdma_rx_queue *rxq) { rxq->stat_rx_post_recv_fail = 0; } if (rxq->stat_rx_pkt_invalid) { - err("%s(%d,%u), invalid pkt %u\n", __func__, port, q, - rxq->stat_rx_pkt_invalid); + err("%s(%d,%u), invalid pkt %u\n", __func__, port, q, rxq->stat_rx_pkt_invalid); rxq->stat_rx_pkt_invalid = 0; } @@ -179,14 +175,12 @@ static int rdma_stat_dump(void *priv) { for (uint16_t i = 0; i < rdma->tx_queues_cnt; i++) { struct mt_rdma_tx_queue *txq = &rdma->tx_queues[i]; - if (txq->tx_entry) - rdma_tx_queue_stat(txq); + if (txq->tx_entry) rdma_tx_queue_stat(txq); } for (uint16_t i = 0; i < rdma->rx_queues_cnt; i++) { struct mt_rdma_rx_queue *rxq = &rdma->rx_queues[i]; - if (rxq->rx_entry) - rdma_rx_queue_stat(rxq); + if (rxq->rx_entry) rdma_rx_queue_stat(rxq); } return 0; @@ -224,8 +218,8 @@ static int rdma_free(struct mt_rdma_priv *rdma) { return 0; } -static int rdma_rx_post_recv(struct mt_rdma_rx_queue *rxq, - struct rte_mbuf **mbufs, uint16_t sz) { +static int rdma_rx_post_recv(struct mt_rdma_rx_queue *rxq, struct rte_mbuf **mbufs, + uint16_t sz) { enum mtl_port port = rxq->port; uint16_t q = rxq->q; int ret; @@ -239,8 +233,8 @@ static int rdma_rx_post_recv(struct mt_rdma_rx_queue *rxq, ret = rdma_post_recv(rxq->cma_id, m, addr, rxq->recv_len, rxq->recv_mr); if (ret) { rxq->stat_rx_post_recv_fail++; - err("%s(%d,%u), rdma_post_recv %u fail %d, addr %p, len %" PRIu64 "\n", - __func__, port, q, i, ret, addr, rxq->recv_len); + err("%s(%d,%u), rdma_post_recv %u fail %d, addr %p, len %" PRIu64 "\n", __func__, + port, q, i, ret, addr, rxq->recv_len); return ret; } } @@ -249,8 +243,7 @@ static int rdma_rx_post_recv(struct mt_rdma_rx_queue *rxq, } static void rdma_tx_poll_done(struct mt_rdma_tx_queue *txq) { - if (!txq->connected) - return; + if (!txq->connected) return; struct ibv_cq *cq = txq->cq; struct ibv_wc wc[128]; int n = 0; @@ -272,11 +265,9 @@ static void rdma_tx_poll_done(struct mt_rdma_tx_queue *txq) { } while (n > 0); } -static uint16_t rdma_tx(struct mtl_main_impl *impl, - struct mt_rdma_tx_queue *txq, struct rte_mbuf **tx_pkts, - uint16_t nb_pkts) { - if (!txq->connected) - return 0; +static uint16_t rdma_tx(struct mtl_main_impl *impl, struct mt_rdma_tx_queue *txq, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { + if (!txq->connected) return 0; int ret = 0; enum mtl_port port = txq->port; uint16_t q = txq->q; @@ -298,8 +289,7 @@ static uint16_t rdma_tx(struct mtl_main_impl *impl, for (uint16_t i = 0; i < nb_pkts; i++) { m = tx_pkts[i]; /* l2/l3/l4 headers are not used in data path */ - sge[0].addr = - rte_pktmbuf_mtod_offset(m, uint64_t, sizeof(struct mt_udp_hdr)); + sge[0].addr = rte_pktmbuf_mtod_offset(m, uint64_t, sizeof(struct mt_udp_hdr)); sge[0].length = m->data_len - sizeof(struct mt_udp_hdr); sge[0].lkey = txq->send_mrs[0]->lkey; @@ -311,8 +301,8 @@ static uint16_t rdma_tx(struct mtl_main_impl *impl, sge[1].addr = (uint64_t)n->buf_addr; sge[1].length = n->buf_len; sge[1].lkey = txq->send_mrs[mr_idx]->lkey; - dbg("%s(%d, %u), ext buffer %p len %u mr_lkey %u\n", __func__, port, q, - n->buf_addr, n->buf_len, sge[1].lkey); + dbg("%s(%d, %u), ext buffer %p len %u mr_lkey %u\n", __func__, port, q, n->buf_addr, + n->buf_len, sge[1].lkey); } wr.wr_id = (uintptr_t)m; @@ -356,10 +346,9 @@ static uint16_t rdma_tx(struct mtl_main_impl *impl, return tx; } -static uint16_t rdma_rx(struct mt_rx_rdma_entry *entry, - struct rte_mbuf **rx_pkts, uint16_t nb_pkts) { - if (!entry->rxq->connected) - return 0; +static uint16_t rdma_rx(struct mt_rx_rdma_entry *entry, struct rte_mbuf **rx_pkts, + uint16_t nb_pkts) { + if (!entry->rxq->connected) return 0; struct mt_rdma_rx_queue *rxq = entry->rxq; enum mtl_port port = entry->port; // uint16_t q = rxq->q; @@ -368,8 +357,7 @@ static uint16_t rdma_rx(struct mt_rx_rdma_entry *entry, uint64_t rx_bytes = 0; struct ibv_wc wc[nb_pkts]; int rx = ibv_poll_cq(rxq->cq, nb_pkts, wc); - if (rx <= 0) - return 0; + if (rx <= 0) return 0; rxq->stat_rx_burst++; @@ -392,8 +380,8 @@ static uint16_t rdma_rx(struct mt_rx_rdma_entry *entry, } uint32_t flow_hash = ntohl(wc[i].imm_data); if (flow_hash != rxq->flow_hash) { - dbg("%s(%d, %u), flow_hash mismatch %u %u\n", __func__, port, q, - flow_hash, rxq->flow_hash); + dbg("%s(%d, %u), flow_hash mismatch %u %u\n", __func__, port, q, flow_hash, + rxq->flow_hash); rxq->stat_rx_pkt_invalid++; rte_pktmbuf_free(pkt); continue; @@ -441,9 +429,8 @@ int mt_dev_rdma_init(struct mt_interface *inf) { rdma->rx_queues_cnt = inf->nb_rx_q; mt_pthread_mutex_init(&rdma->queues_lock, NULL); if (rdma->tx_queues_cnt) { - rdma->tx_queues = - mt_rte_zmalloc_socket(sizeof(*rdma->tx_queues) * rdma->tx_queues_cnt, - mt_socket_id(impl, port)); + rdma->tx_queues = mt_rte_zmalloc_socket( + sizeof(*rdma->tx_queues) * rdma->tx_queues_cnt, mt_socket_id(impl, port)); if (!rdma->tx_queues) { err("%s(%d), rdma tx_queues malloc fail\n", __func__, port); rdma_free(rdma); @@ -451,9 +438,8 @@ int mt_dev_rdma_init(struct mt_interface *inf) { } } if (rdma->rx_queues_cnt) { - rdma->rx_queues = - mt_rte_zmalloc_socket(sizeof(*rdma->rx_queues) * rdma->rx_queues_cnt, - mt_socket_id(impl, port)); + rdma->rx_queues = mt_rte_zmalloc_socket( + sizeof(*rdma->rx_queues) * rdma->rx_queues_cnt, mt_socket_id(impl, port)); if (!rdma->rx_queues) { err("%s(%d), rdma rx_queues malloc fail\n", __func__, port); rdma_free(rdma); @@ -497,8 +483,7 @@ int mt_dev_rdma_init(struct mt_interface *inf) { int mt_dev_rdma_uinit(struct mt_interface *inf) { struct mt_rdma_priv *rdma = inf->rdma; - if (!rdma) - return 0; + if (!rdma) return 0; struct mtl_main_impl *impl = inf->parent; mt_stat_unregister(impl, rdma_stat_dump, rdma); @@ -572,8 +557,8 @@ static int rdma_tx_mrs_init(struct mt_rdma_tx_queue *txq) { return -EIO; } - struct ibv_mr **mrs = mt_rte_zmalloc_socket(num_mrs * sizeof(struct ibv_mr *), - mt_socket_id(impl, port)); + struct ibv_mr **mrs = + mt_rte_zmalloc_socket(num_mrs * sizeof(struct ibv_mr *), mt_socket_id(impl, port)); if (!mrs) { err("%s(%d, %u), mrs malloc fail\n", __func__, port, q); return -ENOMEM; @@ -584,15 +569,15 @@ static int rdma_tx_mrs_init(struct mt_rdma_tx_queue *txq) { size_t sz = txq->send_mrs_sizes[i]; struct ibv_mr *mr = ibv_reg_mr(txq->pd, buffer, sz, IBV_ACCESS_LOCAL_WRITE); if (!mr) { - err("%s(%d, %u), ibv_reg_mr fail, buffer %p size %" PRIu64 "\n", __func__, - port, q, buffer, sz); + err("%s(%d, %u), ibv_reg_mr fail, buffer %p size %" PRIu64 "\n", __func__, port, q, + buffer, sz); txq->num_mrs = i; rdma_tx_mrs_uinit(txq); return -EIO; } mrs[i] = mr; - dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", - __func__, port, q, buffers[i], sizes[i], mr->lkey); + dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", __func__, + port, q, buffers[i], sizes[i], mr->lkey); } txq->send_mrs = mrs; @@ -606,11 +591,9 @@ static int rdma_tx_queue_uinit(struct mt_rdma_tx_queue *txq) { if (txq->multicast && txq->cma_id && txq->rai) rdma_leave_multicast(txq->cma_id, txq->rai->ai_dst_addr); MT_SAFE_FREE(txq->ah, ibv_destroy_ah); - if (txq->cma_id && txq->cma_id->qp) - rdma_destroy_qp(txq->cma_id); + if (txq->cma_id && txq->cma_id->qp) rdma_destroy_qp(txq->cma_id); MT_SAFE_FREE(txq->cq, ibv_destroy_cq); - if (txq->cma_id && !txq->cma_id->pd) - MT_SAFE_FREE(txq->pd, ibv_dealloc_pd); + if (txq->cma_id && !txq->cma_id->pd) MT_SAFE_FREE(txq->pd, ibv_dealloc_pd); MT_SAFE_FREE(txq->rai, rdma_freeaddrinfo); MT_SAFE_FREE(txq->cma_id, rdma_destroy_id); MT_SAFE_FREE(txq->ec, rdma_destroy_event_channel); @@ -682,69 +665,67 @@ static void *rdma_tx_connect_thread(void *arg) { ret = rdma_get_cm_event(txq->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_ADDR_RESOLVED: - if (!txq->multicast) { - ret = rdma_resolve_route(txq->cma_id, 2000); - if (ret) { - err("%s(%d, %u), rdma_resolve_route fail\n", __func__, port, q); - goto connect_err; + case RDMA_CM_EVENT_ADDR_RESOLVED: + if (!txq->multicast) { + ret = rdma_resolve_route(txq->cma_id, 2000); + if (ret) { + err("%s(%d, %u), rdma_resolve_route fail\n", __func__, port, q); + goto connect_err; + } + } else { + ret = rdma_tx_queue_post_init(txq); + if (ret) { + err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, q); + goto connect_err; + } + struct rdma_cm_join_mc_attr_ex attr = { + .addr = txq->rai->ai_dst_addr, + .comp_mask = + RDMA_CM_JOIN_MC_ATTR_ADDRESS | RDMA_CM_JOIN_MC_ATTR_JOIN_FLAGS, + .join_flags = RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER, + }; + ret = rdma_join_multicast_ex(txq->cma_id, &attr, NULL); + if (ret) { + err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); + goto connect_err; + } } - } else { + break; + case RDMA_CM_EVENT_ROUTE_RESOLVED: ret = rdma_tx_queue_post_init(txq); if (ret) { - err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, - q); + err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, q); goto connect_err; } - struct rdma_cm_join_mc_attr_ex attr = { - .addr = txq->rai->ai_dst_addr, - .comp_mask = RDMA_CM_JOIN_MC_ATTR_ADDRESS | - RDMA_CM_JOIN_MC_ATTR_JOIN_FLAGS, - .join_flags = RDMA_MC_JOIN_FLAG_SENDONLY_FULLMEMBER, + struct rdma_conn_param conn_param = { + .private_data = txq->rai->ai_connect, + .private_data_len = txq->rai->ai_connect_len, }; - ret = rdma_join_multicast_ex(txq->cma_id, &attr, NULL); + ret = rdma_connect(txq->cma_id, &conn_param); if (ret) { - err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); + err("%s(%d, %u), rdma connect fail %d\n", __func__, port, q, ret); goto connect_err; } - } - break; - case RDMA_CM_EVENT_ROUTE_RESOLVED: - ret = rdma_tx_queue_post_init(txq); - if (ret) { - err("%s(%d, %u), rdma_tx_queue_post_init fail\n", __func__, port, - q); - goto connect_err; - } - struct rdma_conn_param conn_param = { - .private_data = txq->rai->ai_connect, - .private_data_len = txq->rai->ai_connect_len, - }; - ret = rdma_connect(txq->cma_id, &conn_param); - if (ret) { - err("%s(%d, %u), rdma connect fail %d\n", __func__, port, q, ret); - goto connect_err; - } - break; - case RDMA_CM_EVENT_ESTABLISHED: - case RDMA_CM_EVENT_MULTICAST_JOIN: - txq->remote_qpn = event->param.ud.qp_num; - txq->remote_qkey = event->param.ud.qkey; - txq->ah = ibv_create_ah(txq->pd, &event->param.ud.ah_attr); - if (!txq->ah) { - err("%s(%d, %u), ibv_create_ah fail\n", __func__, port, q); + break; + case RDMA_CM_EVENT_ESTABLISHED: + case RDMA_CM_EVENT_MULTICAST_JOIN: + txq->remote_qpn = event->param.ud.qp_num; + txq->remote_qkey = event->param.ud.qkey; + txq->ah = ibv_create_ah(txq->pd, &event->param.ud.ah_attr); + if (!txq->ah) { + err("%s(%d, %u), ibv_create_ah fail\n", __func__, port, q); + goto connect_err; + } + if (txq->multicast) + info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); + else + info("%s(%d, %u), rdma connected\n", __func__, port, q); + txq->connected = true; + break; + default: + err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, q, + rdma_event_str(event->event), event->status); goto connect_err; - } - if (txq->multicast) - info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); - else - info("%s(%d, %u), rdma connected\n", __func__, port, q); - txq->connected = true; - break; - default: - err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, - q, rdma_event_str(event->event), event->status); - goto connect_err; } rdma_ack_cm_event(event); } @@ -788,8 +769,7 @@ static int rdma_tx_queue_init(struct mt_rdma_tx_queue *txq) { hints.ai_port_space = RDMA_PS_UDP; hints.ai_flags = RAI_PASSIVE; char ip[16]; - snprintf(ip, 16, "%d.%d.%d.%d", txq->sip[0], txq->sip[1], txq->sip[2], - txq->sip[3]); + snprintf(ip, 16, "%d.%d.%d.%d", txq->sip[0], txq->sip[1], txq->sip[2], txq->sip[3]); ret = rdma_getaddrinfo(ip, NULL, &hints, &local_rai); if (ret) { err("%s(%d, %u), rdma_getaddrinfo fail %d\n", __func__, port, q, ret); @@ -828,8 +808,8 @@ static int rdma_tx_queue_init(struct mt_rdma_tx_queue *txq) { info("%s(%d, %u), flow hash %u\n", __func__, port, q, txq->flow_hash); /* resolve rx/multicast addr */ - ret = rdma_resolve_addr(txq->cma_id, remote_rai->ai_src_addr, - remote_rai->ai_dst_addr, 2000); + ret = rdma_resolve_addr(txq->cma_id, remote_rai->ai_src_addr, remote_rai->ai_dst_addr, + 2000); if (ret) { err("%s(%d, %u), rdma_resolve_addr fail %d\n", __func__, port, q, ret); rdma_tx_queue_uinit(txq); @@ -858,14 +838,13 @@ static int rdma_rx_mr_init(struct mt_rdma_rx_queue *rxq) { RTE_PKTMBUF_HEADROOM - sizeof(struct mt_udp_hdr); base_addr = mt_mempool_mem_addr(pool); mr_size = mt_mempool_mem_size(pool); - rxq->recv_mr = - ibv_reg_mr(rxq->pd, base_addr, mr_size, IBV_ACCESS_LOCAL_WRITE); + rxq->recv_mr = ibv_reg_mr(rxq->pd, base_addr, mr_size, IBV_ACCESS_LOCAL_WRITE); if (!rxq->recv_mr) { err("%s(%d, %u), ibv_reg_mr fail\n", __func__, rxq->port, rxq->q); return -ENOMEM; } - dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", - __func__, rxq->port, rxq->q, base_addr, mr_size, rxq->recv_mr->lkey); + dbg("%s(%d, %u), mr registered, buffer %p size %" PRIu64 " mr_lkey %u\n", __func__, + rxq->port, rxq->q, base_addr, mr_size, rxq->recv_mr->lkey); return 0; } @@ -875,11 +854,9 @@ static int rdma_rx_queue_uinit(struct mt_rdma_rx_queue *rxq) { if (rxq->multicast && rxq->cma_id && rxq->rai) rdma_leave_multicast(rxq->cma_id, rxq->rai->ai_dst_addr); MT_SAFE_FREE(rxq->recv_mr, ibv_dereg_mr); - if (rxq->cma_id && rxq->cma_id->qp) - rdma_destroy_qp(rxq->cma_id); + if (rxq->cma_id && rxq->cma_id->qp) rdma_destroy_qp(rxq->cma_id); MT_SAFE_FREE(rxq->cq, ibv_destroy_cq); - if (!rxq->multicast) - MT_SAFE_FREE(rxq->pd, ibv_dealloc_pd); + if (!rxq->multicast) MT_SAFE_FREE(rxq->pd, ibv_dealloc_pd); MT_SAFE_FREE(rxq->rai, rdma_freeaddrinfo); MT_SAFE_FREE(rxq->listen_id, rdma_destroy_id); MT_SAFE_FREE(rxq->ec, rdma_destroy_event_channel); @@ -967,47 +944,45 @@ static void *rdma_rx_connect_thread(void *arg) { ret = rdma_get_cm_event(rxq->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_CONNECT_REQUEST: - rxq->cma_id = event->id; - ret = rdma_rx_queue_post_init(rxq); - if (ret) { - err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, - q); - goto connect_err; - } - struct rdma_conn_param conn_param = { - .qp_num = event->id->qp->qp_num, - }; - ret = rdma_accept(event->id, &conn_param); - if (ret) { - err("%s(%d, %u), rdma_accept fail %d\n", __func__, port, q, ret); - goto connect_err; - } - info("%s(%d, %u), rdma connected\n", __func__, port, q); - rxq->connected = true; - break; - case RDMA_CM_EVENT_ADDR_RESOLVED: - rxq->cma_id = event->id; - ret = rdma_rx_queue_post_init(rxq); - if (ret) { - err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, - q); - goto connect_err; - } - ret = rdma_join_multicast(rxq->cma_id, rxq->rai->ai_dst_addr, NULL); - if (ret) { - err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); + case RDMA_CM_EVENT_CONNECT_REQUEST: + rxq->cma_id = event->id; + ret = rdma_rx_queue_post_init(rxq); + if (ret) { + err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, q); + goto connect_err; + } + struct rdma_conn_param conn_param = { + .qp_num = event->id->qp->qp_num, + }; + ret = rdma_accept(event->id, &conn_param); + if (ret) { + err("%s(%d, %u), rdma_accept fail %d\n", __func__, port, q, ret); + goto connect_err; + } + info("%s(%d, %u), rdma connected\n", __func__, port, q); + rxq->connected = true; + break; + case RDMA_CM_EVENT_ADDR_RESOLVED: + rxq->cma_id = event->id; + ret = rdma_rx_queue_post_init(rxq); + if (ret) { + err("%s(%d, %u), rdma_rx_queue_post_init fail\n", __func__, port, q); + goto connect_err; + } + ret = rdma_join_multicast(rxq->cma_id, rxq->rai->ai_dst_addr, NULL); + if (ret) { + err("%s(%d, %u), rdma_join_multicast fail\n", __func__, port, q); + goto connect_err; + } + break; + case RDMA_CM_EVENT_MULTICAST_JOIN: + info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); + rxq->connected = true; + break; + default: + err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, q, + rdma_event_str(event->event), event->status); goto connect_err; - } - break; - case RDMA_CM_EVENT_MULTICAST_JOIN: - info("%s(%d, %u), rdma multicast connected\n", __func__, port, q); - rxq->connected = true; - break; - default: - err("%s(%d, %u), unexpected event: %s, error: %d\n", __func__, port, - q, rdma_event_str(event->event), event->status); - goto connect_err; } rdma_ack_cm_event(event); } @@ -1049,8 +1024,7 @@ static int rdma_rx_queue_init(struct mt_rdma_rx_queue *rxq) { .ai_flags = RAI_PASSIVE, }; char ip[16]; - snprintf(ip, 16, "%d.%d.%d.%d", rxq->sip[0], rxq->sip[1], rxq->sip[2], - rxq->sip[3]); + snprintf(ip, 16, "%d.%d.%d.%d", rxq->sip[0], rxq->sip[1], rxq->sip[2], rxq->sip[3]); char dport[6]; snprintf(dport, 6, "%d", rxq->rx_entry->flow.dst_port); struct rdma_addrinfo *local_rai; @@ -1120,8 +1094,7 @@ static int rdma_rx_queue_init(struct mt_rdma_rx_queue *rxq) { return 0; } -struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_txq_flow *flow, struct mt_tx_rdma_get_args *args) { MTL_MAY_UNUSED(args); @@ -1162,8 +1135,7 @@ struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, entry->txq = txq; entry->queue_id = txq->q; - if (rdma_tx_mrs_pre_init(txq, flow->mrs_bufs, flow->mrs_sizes, - flow->num_mrs)) { + if (rdma_tx_mrs_pre_init(txq, flow->mrs_bufs, flow->mrs_sizes, flow->num_mrs)) { err("%s(%d), rdma_tx_mrs_init fail\n", __func__, port); mt_tx_rdma_put(entry); return NULL; @@ -1176,14 +1148,13 @@ struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, } uint8_t *ip = flow->dip_addr; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], + ip[3], flow->dst_port, entry->queue_id); return entry; } static void rdma_tx_queue_flush(struct mt_rdma_tx_queue *txq) { - if (!txq->cma_id || !txq->cma_id->qp) - return; + if (!txq->cma_id || !txq->cma_id->qp) return; struct ibv_qp_attr qp_attr = {.qp_state = IBV_QPS_ERR}; ibv_modify_qp(txq->cma_id->qp, &qp_attr, IBV_QP_STATE); rdma_tx_poll_done(txq); @@ -1203,21 +1174,20 @@ int mt_tx_rdma_put(struct mt_tx_rdma_entry *entry) { rdma_tx_queue_uinit(txq); txq->tx_entry = NULL; - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], + ip[2], ip[3], flow->dst_port, entry->queue_id); } mt_rte_free(entry); return 0; } -uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { +uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { return rdma_tx(entry->parent, entry->txq, tx_pkts, nb_pkts); } -struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow, struct mt_rx_rdma_get_args *args) { if (!mt_pmd_is_rdma_ud(impl, port)) { @@ -1267,14 +1237,13 @@ struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, } uint8_t *ip = flow->dip_addr; - info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], - ip[2], ip[3], flow->dst_port); + info("%s(%d,%u), ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], ip[1], ip[2], + ip[3], flow->dst_port); return entry; } static void rdma_queue_rx_flush(struct mt_rdma_rx_queue *rxq) { - if (!rxq->qp) - return; + if (!rxq->qp) return; struct ibv_qp_attr qp_attr = {.qp_state = IBV_QPS_ERR}; ibv_modify_qp(rxq->qp, &qp_attr, IBV_QP_STATE); struct ibv_wc wc[32]; @@ -1302,13 +1271,13 @@ int mt_rx_rdma_put(struct mt_rx_rdma_entry *entry) { rdma_rx_queue_uinit(rxq); rxq->rx_entry = NULL; } - info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], - ip[1], ip[2], ip[3], flow->dst_port, entry->queue_id); + info("%s(%d), ip %u.%u.%u.%u, port %u, queue %u\n", __func__, port, ip[0], ip[1], ip[2], + ip[3], flow->dst_port, entry->queue_id); mt_rte_free(entry); return 0; } -uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry *entry, - struct rte_mbuf **rx_pkts, const uint16_t nb_pkts) { +uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry *entry, struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts) { return rdma_rx(entry, rx_pkts, nb_pkts); } diff --git a/lib/src/dev/mt_rdma_ud.h b/lib/src/dev/mt_rdma_ud.h index a39870809..f23eaa9c6 100644 --- a/lib/src/dev/mt_rdma_ud.h +++ b/lib/src/dev/mt_rdma_ud.h @@ -20,21 +20,19 @@ struct mt_rx_rdma_get_args { int mt_dev_rdma_init(struct mt_interface *inf); int mt_dev_rdma_uinit(struct mt_interface *inf); -struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_txq_flow *flow, struct mt_tx_rdma_get_args *args); int mt_tx_rdma_put(struct mt_tx_rdma_entry *entry); -uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts); +uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts); -struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, - enum mtl_port port, +struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow, struct mt_rx_rdma_get_args *args); int mt_rx_rdma_put(struct mt_rx_rdma_entry *entry); -uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry *entry, - struct rte_mbuf **rx_pkts, const uint16_t nb_pkts); +uint16_t mt_rx_rdma_burst(struct mt_rx_rdma_entry *entry, struct rte_mbuf **rx_pkts, + const uint16_t nb_pkts); #else #include "../mt_log.h" @@ -49,9 +47,10 @@ static inline int mt_dev_rdma_uinit(struct mt_interface *inf) { return -ENOTSUP; } -static inline struct mt_tx_rdma_entry * -mt_tx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_txq_flow *flow, struct mt_tx_rdma_get_args *args) { +static inline struct mt_tx_rdma_entry *mt_tx_rdma_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_txq_flow *flow, + struct mt_tx_rdma_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); @@ -65,17 +64,17 @@ static inline int mt_tx_rdma_put(struct mt_tx_rdma_entry *entry) { } static inline uint16_t mt_tx_rdma_burst(struct mt_tx_rdma_entry *entry, - struct rte_mbuf **tx_pkts, - uint16_t nb_pkts) { + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { MTL_MAY_UNUSED(entry); MTL_MAY_UNUSED(tx_pkts); MTL_MAY_UNUSED(nb_pkts); return 0; } -static inline struct mt_rx_rdma_entry * -mt_rx_rdma_get(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_rxq_flow *flow, struct mt_rx_rdma_get_args *args) { +static inline struct mt_rx_rdma_entry *mt_rx_rdma_get(struct mtl_main_impl *impl, + enum mtl_port port, + struct mt_rxq_flow *flow, + struct mt_rx_rdma_get_args *args) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow); diff --git a/lib/src/mt_admin.c b/lib/src/mt_admin.c index 8f6ea53ff..a38da22bb 100644 --- a/lib/src/mt_admin.c +++ b/lib/src/mt_admin.c @@ -22,8 +22,7 @@ static int admin_cal_cpu_busy(struct mtl_main_impl *impl) { for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) - continue; + if (!mt_sch_started(sch)) continue; /* cal tx video cpu */ tx_mgr = &sch->tx_video_mgr; @@ -58,8 +57,7 @@ static int admin_clear_cpu_busy(struct mtl_main_impl *impl) { for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) - continue; + if (!mt_sch_started(sch)) continue; /* cal tx video cpu */ tx_mgr = &sch->tx_video_mgr; @@ -120,8 +118,7 @@ static int tx_video_migrate_to(struct st_tx_video_session_impl *s, int i; /* find one empty slot in the new sch */ for (i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { - if (!tx_video_session_get_empty(to_tx_mgr, i)) - continue; + if (!tx_video_session_get_empty(to_tx_mgr, i)) continue; /* remove from old sch */ from_tx_mgr->sessions[from_idx] = NULL; /* migrate resource */ @@ -150,18 +147,15 @@ static int admin_tx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { struct mtl_sch_impl *sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) - continue; - if (!mt_sch_has_busy(sch)) - continue; + if (!mt_sch_started(sch)) continue; + if (!mt_sch_has_busy(sch)) continue; /* check if any busy session in this cpu */ struct st_tx_video_session_impl *busy_s_in_sch = NULL; struct st_tx_video_sessions_mgr *tx_mgr = &sch->tx_video_mgr; for (int j = 0; j < tx_mgr->max_idx; j++) { struct st_tx_video_session_impl *tx_s = tx_video_session_get(tx_mgr, j); - if (!tx_s) - continue; + if (!tx_s) continue; if (tx_video_session_is_cpu_busy(tx_s)) { busy_s_in_sch = tx_s; /* last one as the busy one */ } @@ -175,22 +169,18 @@ static int admin_tx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { } } - if (!busy_s) - return 0; /* no busy session */ + if (!busy_s) return 0; /* no busy session */ int quota_mbs = tx_video_quota_mbs(busy_s); if (quota_mbs >= from_sch->data_quota_mbs_total) { return 0; /* only one video session in this sch */ } - dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, - busy_s->idx); - struct mtl_sch_impl *to_sch = - mt_sch_get_by_socket(impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, - mt_sch_socket_id(from_sch)); + dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); + struct mtl_sch_impl *to_sch = mt_sch_get_by_socket( + impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, mt_sch_socket_id(from_sch)); if (!to_sch) { - err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, - busy_s->idx); + err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); return -EIO; } @@ -200,8 +190,7 @@ static int admin_tx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { ret = tx_video_migrate_to(busy_s, from_sch, to_sch); if (ret < 0) { - err("%s, session(%d,%d) migrate to fail\n", __func__, from_sch->idx, - busy_s->idx); + err("%s, session(%d,%d) migrate to fail\n", __func__, from_sch->idx, busy_s->idx); mt_sch_put(to_sch, quota_mbs); /* put back new sch */ return ret; } @@ -246,8 +235,7 @@ static int rx_video_migrate_to(struct mtl_main_impl *impl, int i; /* find one empty slot in the new sch */ for (i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { - if (!rx_video_session_get_empty(to_rx_mgr, i)) - continue; + if (!rx_video_session_get_empty(to_rx_mgr, i)) continue; /* remove from old sch */ from_rx_mgr->sessions[from_idx] = NULL; /* migrate resource */ @@ -276,20 +264,16 @@ static int admin_rx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { struct mtl_sch_impl *sch = mt_sch_instance(impl, sch_idx); - if (!mt_sch_started(sch)) - continue; - if (!mt_sch_has_busy(sch)) - continue; + if (!mt_sch_started(sch)) continue; + if (!mt_sch_has_busy(sch)) continue; /* check if any busy session in this cpu */ struct st_rx_video_session_impl *busy_s_in_sch = NULL; struct st_rx_video_sessions_mgr *rx_mgr = &sch->rx_video_mgr; for (int j = 0; j < rx_mgr->max_idx; j++) { struct st_rx_video_session_impl *rx_s = rx_video_session_get(rx_mgr, j); - if (!rx_s) - continue; - if (rx_video_session_can_migrate(rx_s) && - rx_video_session_is_cpu_busy(rx_s)) { + if (!rx_s) continue; + if (rx_video_session_can_migrate(rx_s) && rx_video_session_is_cpu_busy(rx_s)) { busy_s_in_sch = rx_s; /* last one as the busy one */ } rx_video_session_put(rx_mgr, j); @@ -302,22 +286,18 @@ static int admin_rx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { } } - if (!busy_s) - return 0; /* no busy session */ + if (!busy_s) return 0; /* no busy session */ int quota_mbs = rx_video_quota_mbs(busy_s); if (quota_mbs >= from_sch->data_quota_mbs_total) { return 0; /* only one video session in this sch */ } - dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, - busy_s->idx); - struct mtl_sch_impl *to_sch = - mt_sch_get_by_socket(impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, - mt_sch_socket_id(from_sch)); + dbg("%s, find one busy session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); + struct mtl_sch_impl *to_sch = mt_sch_get_by_socket( + impl, quota_mbs, from_sch->type, MT_SCH_MASK_ALL, mt_sch_socket_id(from_sch)); if (!to_sch) { - err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, - busy_s->idx); + err("%s, no idle sch for session(%d,%d)\n", __func__, from_sch->idx, busy_s->idx); return -EIO; } @@ -327,8 +307,7 @@ static int admin_rx_video_migrate(struct mtl_main_impl *impl, bool *migrated) { ret = rx_video_migrate_to(impl, busy_s, from_sch, to_sch); if (ret < 0) { - err("%s, session(%d,%d) migrate fail\n", __func__, from_sch->idx, - busy_s->idx); + err("%s, session(%d,%d) migrate fail\n", __func__, from_sch->idx, busy_s->idx); mt_sch_put(to_sch, quota_mbs); /* put back new sch */ return ret; } @@ -367,8 +346,7 @@ static int admin_func(struct mtl_main_impl *impl) { admin_rx_video_migrate(impl, &migrated); } - if (migrated) - admin_clear_cpu_busy(impl); + if (migrated) admin_clear_cpu_busy(impl); rte_eal_alarm_set(admin->period_us, admin_alarm_handler, impl); @@ -388,8 +366,7 @@ static void *admin_thread(void *arg) { mt_pthread_cond_wait(&admin->admin_wake_cond, &admin->admin_wake_mutex); mt_pthread_mutex_unlock(&admin->admin_wake_mutex); - if (!rte_atomic32_read(&admin->admin_stop)) - admin_func(impl); + if (!rte_atomic32_read(&admin->admin_stop)) admin_func(impl); } info("%s, stop\n", __func__); @@ -405,8 +382,7 @@ int mt_admin_init(struct mtl_main_impl *impl) { rte_atomic32_set(&admin->admin_stop, 0); int ret = pthread_create(&admin->admin_tid, NULL, admin_thread, impl); - if (ret < 0) - return ret; + if (ret < 0) return ret; mtl_thread_setname(admin->admin_tid, "mtl_admin"); rte_eal_alarm_set(admin->period_us, admin_alarm_handler, impl); diff --git a/lib/src/mt_arp.c b/lib/src/mt_arp.c index 99504bc2d..c3c7c150d 100644 --- a/lib/src/mt_arp.c +++ b/lib/src/mt_arp.c @@ -43,11 +43,9 @@ static bool arp_is_valid_hdr(struct rte_arp_hdr *hdr) { return true; } -static int arp_receive_request(struct mtl_main_impl *impl, - struct rte_arp_hdr *request, +static int arp_receive_request(struct mtl_main_impl *impl, struct rte_arp_hdr *request, enum mtl_port port) { - if (!arp_is_valid_hdr(request)) - return -EINVAL; + if (!arp_is_valid_hdr(request)) return -EINVAL; if (request->arp_data.arp_tip != *(uint32_t *)mt_sip_addr(impl, port)) { dbg("%s(%d), not our arp\n", __func__, port); @@ -66,14 +64,14 @@ static int arp_receive_request(struct mtl_main_impl *impl, struct rte_ether_hdr *eth = rte_pktmbuf_mtod(rpl_pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); rte_ether_addr_copy(&request->arp_data.arp_sha, mt_eth_d_addr(eth)); - eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL + eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL - struct rte_arp_hdr *arp = rte_pktmbuf_mtod_offset( - rpl_pkt, struct rte_arp_hdr *, sizeof(struct rte_ether_hdr)); + struct rte_arp_hdr *arp = rte_pktmbuf_mtod_offset(rpl_pkt, struct rte_arp_hdr *, + sizeof(struct rte_ether_hdr)); arp->arp_hardware = htons(RTE_ARP_HRD_ETHER); - arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol - arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC - arp->arp_plen = 4; // size of fo IP + arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol + arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC + arp->arp_plen = 4; // size of fo IP arp->arp_opcode = htons(RTE_ARP_OP_REPLY); rte_ether_addr_copy(&request->arp_data.arp_sha, &arp->arp_data.arp_tha); arp->arp_data.arp_tip = request->arp_data.arp_sip; @@ -88,15 +86,13 @@ static int arp_receive_request(struct mtl_main_impl *impl, } uint8_t *ip = (uint8_t *)&request->arp_data.arp_sip; - info_once("%s(%d), send to %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3]); + info_once("%s(%d), send to %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); return 0; } -static int arp_receive_reply(struct mtl_main_impl *impl, - struct rte_arp_hdr *reply, enum mtl_port port) { - if (!arp_is_valid_hdr(reply)) - return -EINVAL; +static int arp_receive_reply(struct mtl_main_impl *impl, struct rte_arp_hdr *reply, + enum mtl_port port) { + if (!arp_is_valid_hdr(reply)) return -EINVAL; if (reply->arp_data.arp_tip != *(uint32_t *)mt_sip_addr(impl, port)) { dbg("%s(%d), not our arp\n", __func__, port); @@ -105,11 +101,11 @@ static int arp_receive_reply(struct mtl_main_impl *impl, uint8_t *ip = (uint8_t *)&reply->arp_data.arp_sip; uint8_t *addr_bytes = reply->arp_data.arp_sha.addr_bytes; - info_once("%s(%d), from %d.%d.%d.%d, mac: " - "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", - __func__, port, ip[0], ip[1], ip[2], ip[3], addr_bytes[0], - addr_bytes[1], addr_bytes[2], addr_bytes[3], addr_bytes[4], - addr_bytes[5]); + info_once( + "%s(%d), from %d.%d.%d.%d, mac: " + "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", + __func__, port, ip[0], ip[1], ip[2], ip[3], addr_bytes[0], addr_bytes[1], + addr_bytes[2], addr_bytes[3], addr_bytes[4], addr_bytes[5]); struct mt_arp_impl *arp_impl = get_arp(impl, port); struct mt_arp_entry *entry = NULL; @@ -120,27 +116,24 @@ static int arp_receive_reply(struct mtl_main_impl *impl, for (i = 0; i < MT_ARP_ENTRY_MAX; i++) { entry = &arp_impl->entries[i]; - if (entry->ip == reply->arp_data.arp_sip) - break; + if (entry->ip == reply->arp_data.arp_sip) break; } if (i >= MT_ARP_ENTRY_MAX) { - err_once("%s(%d), not our arp request, from %d.%d.%d.%d\n", __func__, port, - ip[0], ip[1], ip[2], ip[3]); + err_once("%s(%d), not our arp request, from %d.%d.%d.%d\n", __func__, port, ip[0], + ip[1], ip[2], ip[3]); mt_pthread_mutex_unlock(&arp_impl->mutex); return -EINVAL; } /* save to arp table */ - memcpy(entry->ea.addr_bytes, reply->arp_data.arp_sha.addr_bytes, - RTE_ETHER_ADDR_LEN); + memcpy(entry->ea.addr_bytes, reply->arp_data.arp_sha.addr_bytes, RTE_ETHER_ADDR_LEN); rte_atomic32_set(&entry->mac_ready, 1); mt_pthread_mutex_unlock(&arp_impl->mutex); return 0; } -static int arp_send_req(struct mtl_main_impl *impl, enum mtl_port port, - uint32_t ip) { +static int arp_send_req(struct mtl_main_impl *impl, enum mtl_port port, uint32_t ip) { struct rte_mbuf *req_pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); if (!req_pkt) { err("%s(%d), req_pkt malloc fail\n", __func__, port); @@ -153,13 +146,13 @@ static int arp_send_req(struct mtl_main_impl *impl, enum mtl_port port, struct rte_ether_hdr *eth = rte_pktmbuf_mtod(req_pkt, struct rte_ether_hdr *); mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); memset(mt_eth_d_addr(eth), 0xFF, RTE_ETHER_ADDR_LEN); - eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL - struct rte_arp_hdr *arp = rte_pktmbuf_mtod_offset( - req_pkt, struct rte_arp_hdr *, sizeof(struct rte_ether_hdr)); + eth->ether_type = htons(RTE_ETHER_TYPE_ARP); // ARP_PROTOCOL + struct rte_arp_hdr *arp = rte_pktmbuf_mtod_offset(req_pkt, struct rte_arp_hdr *, + sizeof(struct rte_ether_hdr)); arp->arp_hardware = htons(RTE_ARP_HRD_ETHER); - arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol - arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC - arp->arp_plen = 4; // size of fo IP + arp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4); // IP protocol + arp->arp_hlen = RTE_ETHER_ADDR_LEN; // size of MAC + arp->arp_plen = 4; // size of fo IP arp->arp_opcode = htons(RTE_ARP_OP_REQUEST); arp->arp_data.arp_tip = ip; arp->arp_data.arp_sip = *(uint32_t *)mt_sip_addr(impl, port); @@ -177,15 +170,14 @@ static int arp_send_req(struct mtl_main_impl *impl, enum mtl_port port, return 0; } -static int arp_get_result(struct mt_arp_impl *arp_impl, - struct mt_arp_entry *entry, int timeout_ms) { +static int arp_get_result(struct mt_arp_impl *arp_impl, struct mt_arp_entry *entry, + int timeout_ms) { enum mtl_port port = arp_impl->port; int retry = 0; int max_retry = 0; int sleep_interval_ms = 500; - if (timeout_ms) - max_retry = (timeout_ms / sleep_interval_ms) + 1; + if (timeout_ms) max_retry = (timeout_ms / sleep_interval_ms) + 1; /* wait the arp result */ while (!rte_atomic32_read(&entry->mac_ready)) { @@ -195,8 +187,7 @@ static int arp_get_result(struct mt_arp_impl *arp_impl, } if (retry >= max_retry) { if (max_retry) /* log only if not zero timeout */ - err("%s(%d), cache fail as timeout to %d ms\n", __func__, port, - timeout_ms); + err("%s(%d), cache fail as timeout to %d ms\n", __func__, port, timeout_ms); return -EIO; } mt_sleep_ms(sleep_interval_ms); @@ -204,8 +195,8 @@ static int arp_get_result(struct mt_arp_impl *arp_impl, if (0 == (retry % 10)) { uint8_t ip[MTL_IP_ADDR_LEN]; mt_u32_to_ip(entry->ip, ip); - info("%s(%d), cache waiting arp from %d.%d.%d.%d\n", __func__, port, - ip[0], ip[1], ip[2], ip[3]); + info("%s(%d), cache waiting arp from %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], + ip[2], ip[3]); } } @@ -261,20 +252,18 @@ static int arp_start_arp_timer(struct mt_arp_impl *arp_impl) { int mt_arp_parse(struct mtl_main_impl *impl, struct rte_arp_hdr *hdr, enum mtl_port port) { switch (ntohs(hdr->arp_opcode)) { - case RTE_ARP_OP_REQUEST: - return arp_receive_request(impl, hdr, port); - case RTE_ARP_OP_REPLY: - return arp_receive_reply(impl, hdr, port); - default: - err("%s, mt_arp_parse %04x unimplemented\n", __func__, - ntohs(hdr->arp_opcode)); - return -EINVAL; + case RTE_ARP_OP_REQUEST: + return arp_receive_request(impl, hdr, port); + case RTE_ARP_OP_REPLY: + return arp_receive_reply(impl, hdr, port); + default: + err("%s, mt_arp_parse %04x unimplemented\n", __func__, ntohs(hdr->arp_opcode)); + return -EINVAL; } } -static int mt_arp_cni_get_mac(struct mtl_main_impl *impl, - struct rte_ether_addr *ea, enum mtl_port port, - uint32_t ip, int timeout_ms) { +static int mt_arp_cni_get_mac(struct mtl_main_impl *impl, struct rte_ether_addr *ea, + enum mtl_port port, uint32_t ip, int timeout_ms) { struct mt_arp_impl *arp_impl = get_arp(impl, port); struct mt_arp_entry *entry = NULL; int ret; @@ -295,8 +284,7 @@ static int mt_arp_cni_get_mac(struct mtl_main_impl *impl, entry = &arp_impl->entries[i]; /* find a empty slot */ - if (entry->ip == 0) - break; + if (entry->ip == 0) break; } if (i >= MT_ARP_ENTRY_MAX) { warn("%s(%d), reset arp\n", __func__, port); @@ -311,13 +299,12 @@ static int mt_arp_cni_get_mac(struct mtl_main_impl *impl, uint8_t addr[MTL_IP_ADDR_LEN]; mt_u32_to_ip(ip, addr); - info("%s(%d), %d.%d.%d.%d alloc at %d\n", __func__, port, addr[0], addr[1], - addr[2], addr[3], i); + info("%s(%d), %d.%d.%d.%d alloc at %d\n", __func__, port, addr[0], addr[1], addr[2], + addr[3], i); /* arp and wait the reply */ - arp_send_req(impl, port, ip); /* send the first arp request packet */ - arp_start_arp_timer( - arp_impl); /* start the timer to monitor if send arp again */ + arp_send_req(impl, port, ip); /* send the first arp request packet */ + arp_start_arp_timer(arp_impl); /* start the timer to monitor if send arp again */ get_result: /* wait the arp result */ @@ -334,8 +321,7 @@ int mt_arp_init(struct mtl_main_impl *impl) { int socket = mt_socket_id(impl, MTL_PORT_P); for (int i = 0; i < num_ports; i++) { - if (mt_has_virtio_user(impl, i)) - continue; /* use kernel path */ + if (mt_has_virtio_user(impl, i)) continue; /* use kernel path */ struct mt_arp_impl *arp = mt_rte_zmalloc_socket(sizeof(*arp), socket); if (!arp) { err("%s(%d), arp malloc fail\n", __func__, i); @@ -359,8 +345,7 @@ int mt_arp_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { struct mt_arp_impl *arp = get_arp(impl, i); - if (!arp) - continue; + if (!arp) continue; mt_pthread_mutex_destroy(&arp->mutex); @@ -373,15 +358,13 @@ int mt_arp_uinit(struct mtl_main_impl *impl) { } int mt_arp_get_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr *ea, enum mtl_port port, - int timeout_ms) { + struct rte_ether_addr *ea, enum mtl_port port, int timeout_ms) { int ret; - dbg("%s(%d), start to get mac for ip %d.%d.%d.%d\n", __func__, port, dip[0], - dip[1], dip[2], dip[3]); + dbg("%s(%d), start to get mac for ip %d.%d.%d.%d\n", __func__, port, dip[0], dip[1], + dip[2], dip[3]); if (mt_drv_use_kernel_ctl(impl, port) || mt_has_virtio_user(impl, port)) { - ret = mt_socket_get_mac(impl, mt_kernel_if_name(impl, port), dip, ea, - timeout_ms); + ret = mt_socket_get_mac(impl, mt_kernel_if_name(impl, port), dip, ea, timeout_ms); if (ret < 0) { dbg("%s(%d), failed to get mac from socket %d\n", __func__, port, ret); return ret; diff --git a/lib/src/mt_arp.h b/lib/src/mt_arp.h index e51c592d6..b7a4a18a9 100644 --- a/lib/src/mt_arp.h +++ b/lib/src/mt_arp.h @@ -7,14 +7,12 @@ #include "mt_main.h" -int mt_arp_parse(struct mtl_main_impl *impl, struct rte_arp_hdr *hdr, - enum mtl_port port); +int mt_arp_parse(struct mtl_main_impl *impl, struct rte_arp_hdr *hdr, enum mtl_port port); int mt_arp_init(struct mtl_main_impl *impl); int mt_arp_uinit(struct mtl_main_impl *impl); int mt_arp_get_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr *ea, enum mtl_port port, - int timeout_ms); + struct rte_ether_addr *ea, enum mtl_port port, int timeout_ms); #endif diff --git a/lib/src/mt_cni.c b/lib/src/mt_cni.c index 039721700..38cdec3d4 100644 --- a/lib/src/mt_cni.c +++ b/lib/src/mt_cni.c @@ -56,14 +56,14 @@ static void cni_udp_detect_dump(struct mt_cni_entry *cni, uint32_t udp_port = entry->tuple[2]; uint16_t src_port = ntohs((uint16_t)udp_port); uint16_t dst_port = ntohs((uint16_t)(udp_port >> 16)); - info("%s(%d), sip: %d.%d.%d.%d, dip: %d.%d.%d.%d, src_port %u dst_port %d, " - "pkt %d\n", - __func__, cni->port, sip[0], sip[1], sip[2], sip[3], dip[0], dip[1], - dip[2], dip[3], src_port, dst_port, entry->pkt_cnt); + info( + "%s(%d), sip: %d.%d.%d.%d, dip: %d.%d.%d.%d, src_port %u dst_port %d, " + "pkt %d\n", + __func__, cni->port, sip[0], sip[1], sip[2], sip[3], dip[0], dip[1], dip[2], dip[3], + src_port, dst_port, entry->pkt_cnt); } -static int cni_udp_detect_analyses(struct mt_cni_entry *cni, - struct mt_udp_hdr *hdr) { +static int cni_udp_detect_analyses(struct mt_cni_entry *cni, struct mt_udp_hdr *hdr) { enum mtl_port port = cni->port; uint32_t tuple[3]; struct mt_cni_udp_detect_entry *entry; @@ -72,8 +72,8 @@ static int cni_udp_detect_analyses(struct mt_cni_entry *cni, if (!mt_is_multicast_ip(dip) && memcmp(mt_sip_addr(cni->impl, port), dip, MTL_IP_ADDR_LEN)) { - dbg("%s(%d), not our ip %u.%u.%u.%u\n", __func__, port, dip[0], dip[1], - dip[2], dip[3]); + dbg("%s(%d), not our ip %u.%u.%u.%u\n", __func__, port, dip[0], dip[1], dip[2], + dip[3]); return -EINVAL; } @@ -131,8 +131,7 @@ static int cni_burst_to_kernel(struct mt_cni_entry *cni, struct rte_mbuf *m) { struct mtl_main_impl *impl = cni->impl; enum mtl_port port = cni->port; struct mt_interface *inf = mt_if(impl, port); - if (!inf->virtio_port_active) - return 0; + if (!inf->virtio_port_active) return 0; cni->virtio_rx_cnt++; int ret = rte_eth_tx_burst(inf->virtio_port_id, 0, &m, 1); @@ -149,13 +148,11 @@ static int cni_burst_from_kernel(struct mt_cni_entry *cni) { struct mtl_main_impl *impl = cni->impl; enum mtl_port port = cni->port; struct mt_interface *inf = mt_if(impl, port); - if (!inf->virtio_port_active) - return 0; + if (!inf->virtio_port_active) return 0; struct rte_mbuf *pkts[ST_CNI_RX_BURST_SIZE]; - uint16_t revd = - rte_eth_rx_burst(inf->virtio_port_id, 0, pkts, ST_CNI_RX_BURST_SIZE); + uint16_t revd = rte_eth_rx_burst(inf->virtio_port_id, 0, pkts, ST_CNI_RX_BURST_SIZE); if (revd > 0) { cni->virtio_tx_cnt += revd; uint16_t sent = mt_sys_queue_tx_burst(impl, port, pkts, revd); @@ -230,54 +227,53 @@ static int cni_rx_handle(struct mt_cni_entry *cni, struct rte_mbuf *m) { dbg("%s(%d), ether_type 0x%x\n", __func__, port, ether_type); switch (ether_type) { - case RTE_ETHER_TYPE_1588: - ptp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, hdr_offset); - mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L2, m->timesync, NULL); - break; - case RTE_ETHER_TYPE_ARP: - if (mt_has_virtio_user(impl, port)) { - /* use kernel implementation */ - cni_burst_to_kernel(cni, m); - } else { - /* use internal implementation */ - arp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_arp_hdr *, hdr_offset); - mt_arp_parse(impl, arp_hdr, port); - } - break; - case RTE_ETHER_TYPE_IPV4: - ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, hdr_offset); - hdr_offset += ipv4_hdr->ihl * 4; /* may have ip option field */ - if (ipv4_hdr->next_proto_id == IPPROTO_UDP) { - udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *, hdr_offset); - hdr_offset += sizeof(struct rte_udp_hdr); - src_port = ntohs(udp_hdr->src_port); - if (ptp && (src_port == MT_PTP_UDP_EVENT_PORT || - src_port == MT_PTP_UDP_GEN_PORT)) { /* ptp pkt*/ - dbg("%s(%d), ptp msg src_port %u\n", __func__, port, src_port); - ptp_hdr = - rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, hdr_offset); - mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L4, m->timesync, - (struct mt_ipv4_udp *)ipv4_hdr); - } else if (dhcp && src_port == MT_DHCP_UDP_SERVER_PORT) { /* dhcp pkt */ - dhcp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_dhcp_hdr *, hdr_offset); - mt_dhcp_parse(impl, dhcp_hdr, port); + case RTE_ETHER_TYPE_1588: + ptp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, hdr_offset); + mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L2, m->timesync, NULL); + break; + case RTE_ETHER_TYPE_ARP: + if (mt_has_virtio_user(impl, port)) { + /* use kernel implementation */ + cni_burst_to_kernel(cni, m); } else { - cni_udp_handle(cni, m); + /* use internal implementation */ + arp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_arp_hdr *, hdr_offset); + mt_arp_parse(impl, arp_hdr, port); } - } else if (ipv4_hdr->next_proto_id == IPPROTO_IGMP) { - struct mcast_mb_query_v3 *mb_query = - rte_pktmbuf_mtod_offset(m, struct mcast_mb_query_v3 *, hdr_offset); - mt_mcast_parse(impl, mb_query, port); - } else { - /* ipv4 packets other than UDP/IGMP fallback to kernel */ + break; + case RTE_ETHER_TYPE_IPV4: + ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, hdr_offset); + hdr_offset += ipv4_hdr->ihl * 4; /* may have ip option field */ + if (ipv4_hdr->next_proto_id == IPPROTO_UDP) { + udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *, hdr_offset); + hdr_offset += sizeof(struct rte_udp_hdr); + src_port = ntohs(udp_hdr->src_port); + if (ptp && (src_port == MT_PTP_UDP_EVENT_PORT || + src_port == MT_PTP_UDP_GEN_PORT)) { /* ptp pkt*/ + dbg("%s(%d), ptp msg src_port %u\n", __func__, port, src_port); + ptp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, hdr_offset); + mt_ptp_parse(ptp, ptp_hdr, vlan, MT_PTP_L4, m->timesync, + (struct mt_ipv4_udp *)ipv4_hdr); + } else if (dhcp && src_port == MT_DHCP_UDP_SERVER_PORT) { /* dhcp pkt */ + dhcp_hdr = rte_pktmbuf_mtod_offset(m, struct mt_dhcp_hdr *, hdr_offset); + mt_dhcp_parse(impl, dhcp_hdr, port); + } else { + cni_udp_handle(cni, m); + } + } else if (ipv4_hdr->next_proto_id == IPPROTO_IGMP) { + struct mcast_mb_query_v3 *mb_query = + rte_pktmbuf_mtod_offset(m, struct mcast_mb_query_v3 *, hdr_offset); + mt_mcast_parse(impl, mb_query, port); + } else { + /* ipv4 packets other than UDP/IGMP fallback to kernel */ + cni_burst_to_kernel(cni, m); + } + break; + default: + // dbg("%s(%d), unknown ether_type %d\n", __func__, port, ether_type); + /* unknown eth packets fallback to kernel */ cni_burst_to_kernel(cni, m); - } - break; - default: - // dbg("%s(%d), unknown ether_type %d\n", __func__, port, ether_type); - /* unknown eth packets fallback to kernel */ - cni_burst_to_kernel(cni, m); - break; + break; } cni->eth_rx_bytes += m->pkt_len; @@ -288,8 +284,7 @@ static int cni_stop_pcap(struct mt_cni_entry *cni) { enum mtl_port port = cni->port; struct mt_rx_pcap *pcap = &cni->pcap; - if (!pcap->pcap) - return 0; + if (!pcap->pcap) return 0; info("%s(%d), dumped %u packets to %s, dropped %u packets\n", __func__, port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); @@ -309,18 +304,16 @@ static int cni_start_pcap(struct mt_cni_entry *cni, uint32_t max_dump_packets) { return -EIO; } - snprintf(pcap->file_name, sizeof(pcap->file_name), "cni_p%d_%u_XXXXXX.pcapng", - port, max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), "cni_p%d_%u_XXXXXX.pcapng", port, + max_dump_packets); int fd = mt_mkstemps(pcap->file_name, strlen(".pcapng")); if (fd < 0) { - err("%s(%d), failed to create pcap file %s\n", __func__, port, - pcap->file_name); + err("%s(%d), failed to create pcap file %s\n", __func__, port, pcap->file_name); return -EIO; } pcap->pcap = mt_pcap_open(cni->impl, port, fd); if (!pcap->pcap) { - err("%s(%d), failed to open pcap file %s\n", __func__, port, - pcap->file_name); + err("%s(%d), failed to open pcap file %s\n", __func__, port, pcap->file_name); close(fd); return -EIO; } @@ -333,8 +326,7 @@ static int cni_start_pcap(struct mt_cni_entry *cni, uint32_t max_dump_packets) { return 0; } -static int cni_dump_pcap(struct mt_cni_entry *cni, struct rte_mbuf **mbufs, - uint16_t nb) { +static int cni_dump_pcap(struct mt_cni_entry *cni, struct rte_mbuf **mbufs, uint16_t nb) { enum mtl_port port = cni->port; struct mt_rx_pcap *pcap = &cni->pcap; uint16_t dump = mt_pcap_dump(cni->impl, port, pcap->pcap, mbufs, nb); @@ -352,8 +344,7 @@ static int cni_traffic(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { cni = cni_get_entry(impl, i); - if (!cni->rxq) - continue; + if (!cni->rxq) continue; struct mt_rx_pcap *pcap = &cni->pcap; /* if any pcap progress */ @@ -386,8 +377,7 @@ static int cni_traffic(struct mtl_main_impl *impl) { } } - for (uint16_t ri = 0; ri < rx; ri++) - cni_rx_handle(cni, pkts_rx[ri]); + for (uint16_t ri = 0; ri < rx; ri++) cni_rx_handle(cni, pkts_rx[ri]); mt_free_mbufs(&pkts_rx[0], rx); done = false; } @@ -406,16 +396,14 @@ static void *cni_traffic_thread(void *arg) { info("%s, start\n", __func__); while (rte_atomic32_read(&cni->stop_thread) == 0) { ret = cni_traffic(impl); - if (MTL_TASKLET_ALL_DONE == ret) - mt_sleep_ms(cni->thread_sleep_ms); + if (MTL_TASKLET_ALL_DONE == ret) mt_sleep_ms(cni->thread_sleep_ms); } info("%s, stop\n", __func__); return NULL; } -static int cni_traffic_thread_start(struct mtl_main_impl *impl, - struct mt_cni_impl *cni) { +static int cni_traffic_thread_start(struct mtl_main_impl *impl, struct mt_cni_impl *cni) { int ret; if (cni->tid) { @@ -448,8 +436,7 @@ static int cni_tasklet_start(void *priv) { struct mt_cni_impl *cni = mt_get_cni(impl); /* tasklet will take over the cni thread */ - if (cni->lcore_tasklet) - cni_traffic_thread_stop(cni); + if (cni->lcore_tasklet) cni_traffic_thread_stop(cni); return 0; } @@ -458,8 +445,7 @@ static int cni_tasklet_stop(void *priv) { struct mtl_main_impl *impl = priv; struct mt_cni_impl *cni = mt_get_cni(impl); - if (cni->lcore_tasklet) - cni_traffic_thread_start(impl, cni); + if (cni->lcore_tasklet) cni_traffic_thread_start(impl, cni); return 0; } @@ -501,8 +487,7 @@ static int cni_queues_init(struct mtl_main_impl *impl) { inf = mt_if(impl, i); /* continue if no cni */ - if (inf->drv_info.flags & MT_DRV_F_NO_CNI) - continue; + if (inf->drv_info.flags & MT_DRV_F_NO_CNI) continue; struct mt_rxq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -521,15 +506,13 @@ static int cni_queues_init(struct mtl_main_impl *impl) { static bool cni_need_tasklet(struct mt_cni_impl *cni_impl) { struct mtl_main_impl *impl = cni_impl->parent; - if (!impl) - return false; + if (!impl) return false; struct mt_cni_entry *cni; int num_ports = mt_num_ports(impl); for (int i = 0; i < num_ports; i++) { cni = &cni_impl->entries[i]; - if (cni->rxq) - return true; + if (cni->rxq) return true; } /* no cni in all ports */ @@ -545,8 +528,7 @@ static int cni_stat(void *priv) { for (int i = 0; i < num_ports; i++) { cni = &cni_impl->entries[i]; - if (!cni->rxq) - continue; /* no cni */ + if (!cni->rxq) continue; /* no cni */ notice("CNI(%d): eth_rx_rate %f Mb/s, eth_rx_cnt %u\n", i, (double)cni->eth_rx_bytes * 8 / dump_period_s / MTL_STAT_M_UNIT, @@ -555,9 +537,8 @@ static int cni_stat(void *priv) { cni->eth_rx_bytes = 0; if (cni->virtio_rx_cnt || cni->virtio_tx_cnt) { - notice("CNI(%d): virtio pkts(all:fail) rx %u:%u, tx %u:%u\n", i, - cni->virtio_rx_cnt, cni->virtio_rx_fail_cnt, cni->virtio_tx_cnt, - cni->virtio_tx_fail_cnt); + notice("CNI(%d): virtio pkts(all:fail) rx %u:%u, tx %u:%u\n", i, cni->virtio_rx_cnt, + cni->virtio_rx_fail_cnt, cni->virtio_tx_cnt, cni->virtio_tx_fail_cnt); cni->virtio_rx_cnt = 0; cni->virtio_rx_fail_cnt = 0; cni->virtio_tx_cnt = 0; @@ -622,8 +603,7 @@ int mt_cni_init(struct mtl_main_impl *impl) { } ret = mt_tap_init(impl); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (cni_impl->lcore_tasklet) { struct mtl_tasklet_ops ops; @@ -705,12 +685,10 @@ int mt_cni_start(struct mtl_main_impl *impl) { struct mt_cni_impl *cni = mt_get_cni(impl); int ret; - if (!cni_need_tasklet(cni)) - return 0; + if (!cni_need_tasklet(cni)) return 0; ret = cni_traffic_thread_start(impl, cni); - if (ret < 0) - return ret; + if (ret < 0) return ret; return 0; } @@ -763,8 +741,8 @@ struct mt_csq_entry *mt_csq_get(struct mtl_main_impl *impl, enum mtl_port port, mt_get_cni(impl)->thread_sleep_ms = 0; uint8_t *ip = flow->dip_addr; - info("%s(%d), ip %u.%u.%u.%u port %u on %d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3], flow->dst_port, idx); + info("%s(%d), ip %u.%u.%u.%u port %u on %d\n", __func__, port, ip[0], ip[1], ip[2], + ip[3], flow->dst_port, idx); return entry; } @@ -781,8 +759,7 @@ int mt_csq_put(struct mt_csq_entry *entry) { uint16_t mt_csq_burst(struct mt_csq_entry *entry, struct rte_mbuf **rx_pkts, uint16_t nb_pkts) { - uint16_t n = - rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); + uint16_t n = rte_ring_sc_dequeue_burst(entry->ring, (void **)rx_pkts, nb_pkts, NULL); entry->stat_dequeue_cnt += n; return n; } diff --git a/lib/src/mt_config.c b/lib/src/mt_config.c index b6cb9d10e..131e8f5f8 100644 --- a/lib/src/mt_config.c +++ b/lib/src/mt_config.c @@ -6,8 +6,7 @@ #include "mt_log.h" -static int config_parse_plugins(struct mtl_main_impl *impl, - json_object *plugins_array) { +static int config_parse_plugins(struct mtl_main_impl *impl, json_object *plugins_array) { if (json_object_get_type(plugins_array) != json_type_array) { err("%s, type not array\n", __func__); return -EIO; @@ -17,22 +16,17 @@ static int config_parse_plugins(struct mtl_main_impl *impl, dbg("%s, num_plugins %d\n", __func__, num_plugins); for (int i = 0; i < num_plugins; i++) { json_object *plugin_obj = json_object_array_get_idx(plugins_array, i); - if (!plugin_obj) - continue; + if (!plugin_obj) continue; json_object *obj; obj = mt_json_object_get(plugin_obj, "enabled"); - if (obj && !json_object_get_boolean(obj)) - continue; + if (obj && !json_object_get_boolean(obj)) continue; const char *name = NULL; obj = mt_json_object_get(plugin_obj, "name"); - if (obj) - name = json_object_get_string(obj); + if (obj) name = json_object_get_string(obj); const char *path = NULL; obj = mt_json_object_get(plugin_obj, "path"); - if (obj) - path = json_object_get_string(obj); - if (!name || !path) - continue; + if (obj) path = json_object_get_string(obj); + if (!name || !path) continue; st_plugin_register(impl, path); } @@ -45,13 +39,11 @@ static int config_parse_json(struct mtl_main_impl *impl, const char *filename) { warn("%s, open json file %s fail\n", __func__, filename); return -EIO; } - info("%s, parse %s with json-c version: %s\n", __func__, filename, - json_c_version()); + info("%s, parse %s with json-c version: %s\n", __func__, filename, json_c_version()); /* parse plugins for system */ json_object *plugins_array = mt_json_object_get(root_object, "plugins"); - if (plugins_array) - config_parse_plugins(impl, plugins_array); + if (plugins_array) config_parse_plugins(impl, plugins_array); json_object_put(root_object); return 0; diff --git a/lib/src/mt_dhcp.c b/lib/src/mt_dhcp.c index 832c74a2b..44fe20716 100644 --- a/lib/src/mt_dhcp.c +++ b/lib/src/mt_dhcp.c @@ -83,8 +83,7 @@ static int dhcp_send_discover(struct mtl_main_impl *impl, enum mtl_port port) { dhcp->hlen = DHCP_HLEN_ETHERNET; dhcp->xid = htonl(dhcp_impl->xid); dhcp->magic_cookie = htonl(DHCP_MAGIC_COOKIE); - rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, - sizeof(eth->src_addr.addr_bytes)); + rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, sizeof(eth->src_addr.addr_bytes)); options = dhcp->options; *options++ = DHCP_OPTION_MESSAGE_TYPE; *options++ = 1; @@ -172,8 +171,7 @@ static int dhcp_send_request(struct mtl_main_impl *impl, enum mtl_port port) { if (dhcp_impl->status == MT_DHCP_STATUS_RENEWING || dhcp_impl->status == MT_DHCP_STATUS_REBINDING) dhcp->ciaddr = htonl(*(uint32_t *)dhcp_impl->ip); - rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, - sizeof(eth->src_addr.addr_bytes)); + rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, sizeof(eth->src_addr.addr_bytes)); options = dhcp->options; *options++ = DHCP_OPTION_MESSAGE_TYPE; *options++ = 1; @@ -225,8 +223,8 @@ static int dhcp_send_request(struct mtl_main_impl *impl, enum mtl_port port) { return 0; } -static int dhcp_recv_offer(struct mtl_main_impl *impl, - struct mt_dhcp_hdr *offer, enum mtl_port port) { +static int dhcp_recv_offer(struct mtl_main_impl *impl, struct mt_dhcp_hdr *offer, + enum mtl_port port) { struct mt_dhcp_impl *dhcp_impl = mt_get_dhcp(impl, port); mt_pthread_mutex_lock(&dhcp_impl->mutex); if (dhcp_impl->status != MT_DHCP_STATUS_DISCOVERING) { @@ -320,22 +318,21 @@ static int dhcp_recv_ack(struct mtl_main_impl *impl, struct mt_dhcp_hdr *ack, ret = rte_eal_alarm_set(t1 * US_PER_S, dhcp_renew_handler, dhcp_impl); if (ret < 0) { - err("%s(%d), start renew timer fail %d, t1 %lf\n", __func__, - dhcp_impl->port, ret, t1); + err("%s(%d), start renew timer fail %d, t1 %lf\n", __func__, dhcp_impl->port, ret, + t1); return ret; } ret = rte_eal_alarm_set(t2 * US_PER_S, dhcp_rebind_handler, dhcp_impl); if (ret < 0) { - err("%s(%d), start rebind timer fail %d, t2 %lf\n", __func__, - dhcp_impl->port, ret, t2); + err("%s(%d), start rebind timer fail %d, t2 %lf\n", __func__, dhcp_impl->port, ret, + t2); return ret; } ret = rte_eal_alarm_set(t * US_PER_S, dhcp_lease_handler, dhcp_impl); if (ret < 0) { - err("%s(%d), start lease timer fail %d, t %lf\n", __func__, dhcp_impl->port, - ret, t); + err("%s(%d), start lease timer fail %d, t %lf\n", __func__, dhcp_impl->port, ret, t); return ret; } @@ -399,8 +396,7 @@ static int dhcp_send_release(struct mtl_main_impl *impl, enum mtl_port port) { dhcp->xid = rand(); dhcp->magic_cookie = htonl(DHCP_MAGIC_COOKIE); dhcp->ciaddr = htonl(*(uint32_t *)dhcp_impl->ip); - rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, - sizeof(eth->src_addr.addr_bytes)); + rte_memcpy(dhcp->chaddr, eth->src_addr.addr_bytes, sizeof(eth->src_addr.addr_bytes)); options = dhcp->options; *options++ = DHCP_OPTION_MESSAGE_TYPE; *options++ = 1; @@ -467,19 +463,19 @@ int mt_dhcp_parse(struct mtl_main_impl *impl, struct mt_dhcp_hdr *hdr, } switch (options[2]) { - case DHCP_MESSAGE_TYPE_OFFER: - dhcp_recv_offer(impl, hdr, port); - break; - case DHCP_MESSAGE_TYPE_ACK: - dhcp_recv_ack(impl, hdr, port); - break; - case DHCP_MESSAGE_TYPE_NAK: - /* restart the cycle */ - dhcp_send_discover(impl, port); - break; - default: - err("%s(%d), invalid dhcp message type %u\n", __func__, port, options[2]); - return -EINVAL; + case DHCP_MESSAGE_TYPE_OFFER: + dhcp_recv_offer(impl, hdr, port); + break; + case DHCP_MESSAGE_TYPE_ACK: + dhcp_recv_ack(impl, hdr, port); + break; + case DHCP_MESSAGE_TYPE_NAK: + /* restart the cycle */ + dhcp_send_discover(impl, port); + break; + default: + err("%s(%d), invalid dhcp message type %u\n", __func__, port, options[2]); + return -EINVAL; } return 0; @@ -527,8 +523,7 @@ int mt_dhcp_init(struct mtl_main_impl *impl) { int num_dhcp = 0; for (int i = 0; i < num_ports; i++) { - if (mt_if(impl, i)->net_proto != MTL_PROTO_DHCP) - continue; + if (mt_if(impl, i)->net_proto != MTL_PROTO_DHCP) continue; struct mt_dhcp_impl *dhcp = mt_rte_zmalloc_socket(sizeof(*dhcp), socket); if (!dhcp) { err("%s(%d), dhcp malloc fail\n", __func__, i); @@ -556,10 +551,8 @@ int mt_dhcp_init(struct mtl_main_impl *impl) { while (--max_retry) { done = 0; for (int i = 0; i < num_ports; i++) - if (impl->dhcp[i] && impl->dhcp[i]->status == MT_DHCP_STATUS_BOUND) - done++; - if (done == num_dhcp) - break; + if (impl->dhcp[i] && impl->dhcp[i]->status == MT_DHCP_STATUS_BOUND) done++; + if (done == num_dhcp) break; mt_sleep_ms(100); } if (done != num_dhcp) { @@ -580,8 +573,7 @@ int mt_dhcp_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { struct mt_dhcp_impl *dhcp = mt_get_dhcp(impl, i); - if (!dhcp) - continue; + if (!dhcp) continue; /* send release to server */ dhcp_send_release(impl, i); diff --git a/lib/src/mt_dma.c b/lib/src/mt_dma.c index 5810a7333..1c0634ee7 100644 --- a/lib/src/mt_dma.c +++ b/lib/src/mt_dma.c @@ -26,36 +26,30 @@ int mt_map_add(struct mtl_main_impl *impl, struct mt_map_item *item) { /* first check if any conflict with exist mapping */ for (int i = 0; i < MT_MAP_MAX_ITEMS; i++) { i_item = mgr->items[i]; - if (!i_item) - continue; + if (!i_item) continue; i_start = i_item->vaddr; i_end = i_start + i_item->size; if ((start >= i_start) && (start < i_end)) { - err("%s, invalid start %p i_start %p i_end %p\n", __func__, start, - i_start, i_end); + err("%s, invalid start %p i_start %p i_end %p\n", __func__, start, i_start, i_end); mt_pthread_mutex_unlock(&mgr->mutex); return -EINVAL; } if ((end > i_start) && (end <= i_end)) { - err("%s, invalid end %p i_start %p i_end %p\n", __func__, end, i_start, - i_end); + err("%s, invalid end %p i_start %p i_end %p\n", __func__, end, i_start, i_end); mt_pthread_mutex_unlock(&mgr->mutex); return -EINVAL; } /* simply set iova_base to max iova in previous item */ iova_end = i_item->iova + i_item->size; - if (iova_end > iova_base) - iova_base = iova_end; + if (iova_end > iova_base) iova_base = iova_end; } item->iova = iova_base; /* find empty slot and insert */ for (int i = 0; i < MT_MAP_MAX_ITEMS; i++) { i_item = mgr->items[i]; - if (i_item) - continue; - i_item = - mt_rte_zmalloc_socket(sizeof(*i_item), mt_socket_id(impl, MTL_PORT_P)); + if (i_item) continue; + i_item = mt_rte_zmalloc_socket(sizeof(*i_item), mt_socket_id(impl, MTL_PORT_P)); if (!i_item) { err("%s, i_item malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->mutex); @@ -64,8 +58,8 @@ int mt_map_add(struct mtl_main_impl *impl, struct mt_map_item *item) { *i_item = *item; mgr->items[i] = i_item; mt_pthread_mutex_unlock(&mgr->mutex); - info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, - end, i_item->iova); + info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, end, + i_item->iova); return 0; } @@ -87,13 +81,12 @@ int mt_map_remove(struct mtl_main_impl *impl, struct mt_map_item *item) { /* find slot and delete */ for (int i = 0; i < MT_MAP_MAX_ITEMS; i++) { i_item = mgr->items[i]; - if (!i_item) - continue; + if (!i_item) continue; i_start = i_item->vaddr; i_end = i_start + i_item->size; if ((start == i_start) && (end == i_end) && (item->iova == i_item->iova)) { - info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, - end, i_item->iova); + info("%s(%d), start %p end %p iova 0x%" PRIx64 "\n", __func__, i, start, end, + i_item->iova); mt_rte_free(i_item); mgr->items[i] = NULL; mt_pthread_mutex_unlock(&mgr->mutex); @@ -101,8 +94,8 @@ int mt_map_remove(struct mtl_main_impl *impl, struct mt_map_item *item) { } } - err("%s, unknown items start %p end %p iova %" PRIx64 "\n", __func__, start, - end, item->iova); + err("%s, unknown items start %p end %p iova %" PRIx64 "\n", __func__, start, end, + item->iova); mt_pthread_mutex_unlock(&mgr->mutex); return -EIO; } @@ -137,9 +130,8 @@ int mt_map_uinit(struct mtl_main_impl *impl) { #if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0) #include -static int dma_copy_test(struct mtl_main_impl *impl, - struct mtl_dma_lender_dev *dev, uint32_t off, - uint32_t len) { +static int dma_copy_test(struct mtl_main_impl *impl, struct mtl_dma_lender_dev *dev, + uint32_t off, uint32_t len) { void *dst = NULL, *src = NULL; int idx = mt_dma_dev_id(dev); int ret = -EIO; @@ -187,10 +179,8 @@ static int dma_copy_test(struct mtl_main_impl *impl, } exit: - if (dst) - mt_rte_free(dst); - if (src) - mt_rte_free(src); + if (dst) mt_rte_free(dst); + if (src) mt_rte_free(src); return ret; } @@ -272,8 +262,7 @@ static int dma_hw_stop(struct mt_dma_dev *dev) { int ret, idx = dev->idx; ret = rte_dma_stop(dev_id); - if (ret < 0) - err("%s(%d), rte_dma_stop fail %d\n", __func__, idx, ret); + if (ret < 0) err("%s(%d), rte_dma_stop fail %d\n", __func__, idx, ret); return 0; } @@ -291,9 +280,8 @@ static int dma_stat(void *priv) { avg_nb_inflight = dev->stat_inflight_sum / dev->stat_commit_sum; dev->stat_inflight_sum = 0; dev->stat_commit_sum = 0; - notice("DMA(%d), s %" PRIu64 " c %" PRIu64 " e %" PRIu64 " avg q %" PRIu64 - "\n", - idx, stats.submitted, stats.completed, stats.errors, avg_nb_inflight); + notice("DMA(%d), s %" PRIu64 " c %" PRIu64 " e %" PRIu64 " avg q %" PRIu64 "\n", idx, + stats.submitted, stats.completed, stats.errors, avg_nb_inflight); return 0; } @@ -309,8 +297,7 @@ static int dma_sw_init(struct mtl_main_impl *impl, struct mt_dma_dev *dev) { snprintf(ring_name, 32, "%sD%d", MT_DMA_BORROW_RING_PREFIX, idx); flags = RING_F_SP_ENQ | RING_F_SC_DEQ; count = dev->nb_desc; - ring = - rte_ring_create(ring_name, count, mt_socket_id(impl, MTL_PORT_P), flags); + ring = rte_ring_create(ring_name, count, mt_socket_id(impl, MTL_PORT_P), flags); if (!ring) { err("%s(%d), rte_ring_create fail\n", __func__, idx); return -ENOMEM; @@ -319,9 +306,8 @@ static int dma_sw_init(struct mtl_main_impl *impl, struct mt_dma_dev *dev) { #else dev->inflight_enqueue_idx = 0; dev->inflight_dequeue_idx = 0; - dev->inflight_mbufs = - mt_rte_zmalloc_socket(sizeof(*dev->inflight_mbufs) * dev->nb_desc, - mt_socket_id(impl, MTL_PORT_P)); + dev->inflight_mbufs = mt_rte_zmalloc_socket(sizeof(*dev->inflight_mbufs) * dev->nb_desc, + mt_socket_id(impl, MTL_PORT_P)); if (!dev->inflight_mbufs) { err("%s(%d), inflight_mbufs alloc fail\n", __func__, idx); return -ENOMEM; @@ -384,20 +370,17 @@ struct mtl_dma_lender_dev *mt_dma_request_dev(struct mtl_main_impl *impl, struct mtl_dma_lender_dev *lender_dev; int idx, ret; - if (!mgr->num_dma_dev) - return NULL; + if (!mgr->num_dma_dev) return NULL; uint16_t nb_desc = req->nb_desc; - if (!nb_desc) - nb_desc = 128; + if (!nb_desc) nb_desc = 128; mt_pthread_mutex_lock(&mgr->mutex); /* first try to find a shared dma */ for (idx = 0; idx < MTL_DMA_DEV_MAX; idx++) { dev = &mgr->devs[idx]; if (dev->active && (dev->sch_idx == req->sch_idx) && - (dev->soc_id == req->socket_id) && - (dev->nb_session < dev->max_shared)) { + (dev->soc_id == req->socket_id) && (dev->nb_session < dev->max_shared)) { for (int render = 0; render < dev->max_shared; render++) { lender_dev = &dev->lenders[render]; if (!lender_dev->active) { @@ -452,8 +435,7 @@ struct mtl_dma_lender_dev *mt_dma_request_dev(struct mtl_main_impl *impl, return NULL; } -int mt_dma_free_dev(struct mtl_main_impl *impl, - struct mtl_dma_lender_dev *dev) { +int mt_dma_free_dev(struct mtl_main_impl *impl, struct mtl_dma_lender_dev *dev) { struct mt_dma_dev *dma_dev = dev->parent; int idx = dev->lender_id; int dma_idx = dma_dev->idx; @@ -473,8 +455,7 @@ int mt_dma_free_dev(struct mtl_main_impl *impl, rte_atomic32_dec(&mgr->num_dma_dev_active); } - info("%s(%d,%d), nb_session now %u\n", __func__, dma_idx, idx, - dma_dev->nb_session); + info("%s(%d,%d), nb_session now %u\n", __func__, dma_idx, idx, dma_dev->nb_session); return 0; } @@ -484,8 +465,8 @@ int mt_dma_copy(struct mtl_dma_lender_dev *dev, rte_iova_t dst, rte_iova_t src, return rte_dma_copy(dma_dev->dev_id, 0, src, dst, length, 0); } -int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, - uint64_t pattern, uint32_t length) { +int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, uint64_t pattern, + uint32_t length) { struct mt_dma_dev *dma_dev = dev->parent; return rte_dma_fill(dma_dev->dev_id, 0, pattern, dst, length, 0); } @@ -559,17 +540,15 @@ int mt_dma_init(struct mtl_main_impl *impl) { idx = 0; RTE_DMA_FOREACH_DEV(dev_id) { rte_dma_info_get(dev_id, &dev_info); - if (!mt_is_valid_socket(impl, dev_info.numa_node)) - continue; + if (!mt_is_valid_socket(impl, dev_info.numa_node)) continue; dev = &mgr->devs[idx]; dev->dev_id = dev_id; dev->soc_id = dev_info.numa_node; dev->usable = true; dev->nb_session = 0; - info("%s(%d), dma dev id %u name %s capa 0x%" PRIx64 - " numa %d desc %u:%u\n", - __func__, idx, dev_id, dev_info.dev_name, dev_info.dev_capa, - dev_info.numa_node, dev_info.min_desc, dev_info.max_desc); + info("%s(%d), dma dev id %u name %s capa 0x%" PRIx64 " numa %d desc %u:%u\n", + __func__, idx, dev_id, dev_info.dev_name, dev_info.dev_capa, dev_info.numa_node, + dev_info.min_desc, dev_info.max_desc); for (int render = 0; render < MT_DMA_MAX_SESSIONS; render++) { lender_dev = &dev->lenders[render]; lender_dev->parent = dev; @@ -612,14 +591,15 @@ int mt_dma_init(struct mtl_main_impl *impl) { return -EINVAL; } -int mt_dma_uinit(struct mtl_main_impl *impl) { return -EINVAL; } +int mt_dma_uinit(struct mtl_main_impl *impl) { + return -EINVAL; +} struct mtl_dma_lender_dev *mt_dma_request_dev(struct mtl_main_impl *impl, struct mt_dma_request_req *req) { return NULL; } -int mt_dma_free_dev(struct mtl_main_impl *impl, - struct mtl_dma_lender_dev *dev) { +int mt_dma_free_dev(struct mtl_main_impl *impl, struct mtl_dma_lender_dev *dev) { return -EINVAL; } int mt_dma_borrow_mbuf(struct mtl_dma_lender_dev *dev, struct rte_mbuf *mbuf) { @@ -632,15 +612,19 @@ int mt_dma_copy(struct mtl_dma_lender_dev *dev, rte_iova_t dst, rte_iova_t src, uint32_t length) { return -EINVAL; } -int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, - uint64_t pattern, uint32_t length) { +int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, uint64_t pattern, + uint32_t length) { + return -EINVAL; +} +int mt_dma_submit(struct mtl_dma_lender_dev *dev) { return -EINVAL; } -int mt_dma_submit(struct mtl_dma_lender_dev *dev) { return -EINVAL; } uint16_t mt_dma_completed(struct mtl_dma_lender_dev *dev, uint16_t nb_cpls, uint16_t *last_idx, bool *has_error) { return 0; } -bool mt_dma_full(struct mtl_dma_lender_dev *dev) { return true; } +bool mt_dma_full(struct mtl_dma_lender_dev *dev) { + return true; +} #endif diff --git a/lib/src/mt_dma.h b/lib/src/mt_dma.h index 921f27db1..0acd07a8d 100644 --- a/lib/src/mt_dma.h +++ b/lib/src/mt_dma.h @@ -34,15 +34,14 @@ bool mt_dma_full(struct mtl_dma_lender_dev *dev); int mt_dma_copy(struct mtl_dma_lender_dev *dev, rte_iova_t dst, rte_iova_t src, uint32_t length); -int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, - uint64_t pattern, uint32_t length); +int mt_dma_fill(struct mtl_dma_lender_dev *dev, rte_iova_t dst, uint64_t pattern, + uint32_t length); int mt_dma_submit(struct mtl_dma_lender_dev *dev); uint16_t mt_dma_completed(struct mtl_dma_lender_dev *dev, uint16_t nb_cpls, uint16_t *last_idx, bool *has_error); -static inline void mt_dma_copy_busy(struct mtl_dma_lender_dev *dev, - rte_iova_t dst, rte_iova_t src, - uint32_t length) { +static inline void mt_dma_copy_busy(struct mtl_dma_lender_dev *dev, rte_iova_t dst, + rte_iova_t src, uint32_t length) { int ret; do { ret = mt_dma_copy(dev, dst, src, length); diff --git a/lib/src/mt_flow.c b/lib/src/mt_flow.c index 7017d0370..0e6991b9f 100644 --- a/lib/src/mt_flow.c +++ b/lib/src/mt_flow.c @@ -16,8 +16,7 @@ static inline void rx_flow_unlock(struct mt_flow_impl *flow) { mt_pthread_mutex_unlock(&flow->mutex); } -static struct rte_flow *rte_rx_flow_create_raw(struct mt_interface *inf, - uint16_t q, +static struct rte_flow *rte_rx_flow_create_raw(struct mt_interface *inf, uint16_t q, struct mt_rxq_flow *flow) { struct rte_flow_error error; struct rte_flow *r_flow; @@ -30,12 +29,14 @@ static struct rte_flow *rte_rx_flow_create_raw(struct mt_interface *inf, struct rte_flow_action_queue to_queue = {0}; uint16_t port_id = inf->port_id; - char pkt_buf[] = "00000000000100000000000208004500003000000000001100000101010" - "10202020200001B3A001C00" - "008000000000000000000000000000000000000000"; - char msk_buf[] = "00000000000000000000000000000000000000000000000000000000000" - "0000000000000FFFF000000" - "000000000000000000000000000000000000000000"; + char pkt_buf[] = + "00000000000100000000000208004500003000000000001100000101010" + "10202020200001B3A001C00" + "008000000000000000000000000000000000000000"; + char msk_buf[] = + "00000000000000000000000000000000000000000000000000000000000" + "0000000000000FFFF000000" + "000000000000000000000000000000000000000000"; MTL_MAY_UNUSED(flow); attr.ingress = 1; @@ -96,19 +97,15 @@ static struct rte_flow *rte_rx_flow_create(struct mt_interface *inf, uint16_t q, memset(&error, 0, sizeof(error)); /* drv not support ip flow */ - if (inf->drv_info.flow_type == MT_FLOW_NO_IP) - has_ip_flow = false; + if (inf->drv_info.flow_type == MT_FLOW_NO_IP) has_ip_flow = false; /* no ip flow requested */ - if (flow->flags & MT_RXQ_FLOW_F_NO_IP) - has_ip_flow = false; + if (flow->flags & MT_RXQ_FLOW_F_NO_IP) has_ip_flow = false; /* no port flow requested */ - if (flow->flags & MT_RXQ_FLOW_F_NO_PORT) - has_port_flow = false; + if (flow->flags & MT_RXQ_FLOW_F_NO_PORT) has_port_flow = false; if (mt_get_user_params(inf->parent)->flags & MTL_FLAG_RX_UDP_PORT_ONLY) { if (has_ip_flow) { - info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, - port); + info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, port); has_ip_flow = false; } } @@ -175,8 +172,8 @@ static struct rte_flow *rte_rx_flow_create(struct mt_interface *inf, uint16_t q, ret = rte_flow_validate(port_id, &attr, pattern, action, &error); if (ret < 0) { - err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port, - ret, q, mt_string_safe(error.message)); + err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port, ret, q, + mt_string_safe(error.message)); return NULL; } @@ -191,16 +188,16 @@ static struct rte_flow *rte_rx_flow_create(struct mt_interface *inf, uint16_t q, if (has_ip_flow) { uint8_t *ip = flow->dip_addr; - info("%s(%d), queue %u succ, ip %u.%u.%u.%u port %u\n", __func__, port, q, - ip[0], ip[1], ip[2], ip[3], flow->dst_port); + info("%s(%d), queue %u succ, ip %u.%u.%u.%u port %u\n", __func__, port, q, ip[0], + ip[1], ip[2], ip[3], flow->dst_port); } else { info("%s(%d), queue %u succ, port %u\n", __func__, port, q, flow->dst_port); } return r_flow; } -static struct mt_rx_flow_rsp * -rx_flow_create(struct mt_interface *inf, uint16_t q, struct mt_rxq_flow *flow) { +static struct mt_rx_flow_rsp *rx_flow_create(struct mt_interface *inf, uint16_t q, + struct mt_rxq_flow *flow) { int ret; enum mtl_port port = inf->port; struct mtl_main_impl *impl = inf->parent; @@ -211,15 +208,13 @@ rx_flow_create(struct mt_interface *inf, uint16_t q, struct mt_rxq_flow *flow) { return NULL; } - struct mt_rx_flow_rsp *rsp = - mt_rte_zmalloc_socket(sizeof(*rsp), inf->socket_id); + struct mt_rx_flow_rsp *rsp = mt_rte_zmalloc_socket(sizeof(*rsp), inf->socket_id); rsp->flow_id = -1; rsp->queue_id = q; rsp->dst_port = flow->dst_port; /* no flow if MT_DRV_F_RX_NO_FLOW */ - if (inf->drv_info.flags & MT_DRV_F_RX_NO_FLOW) - return rsp; + if (inf->drv_info.flags & MT_DRV_F_RX_NO_FLOW) return rsp; if (mt_drv_use_kernel_ctl(impl, port)) { ret = mt_socket_add_flow(impl, port, q, flow); @@ -234,16 +229,15 @@ rx_flow_create(struct mt_interface *inf, uint16_t q, struct mt_rxq_flow *flow) { r_flow = rte_rx_flow_create(inf, q, flow); if (!r_flow) { - err("%s(%d), create flow fail for queue %d, ip %u.%u.%u.%u port %u\n", - __func__, port, q, ip[0], ip[1], ip[2], ip[3], flow->dst_port); + err("%s(%d), create flow fail for queue %d, ip %u.%u.%u.%u port %u\n", __func__, + port, q, ip[0], ip[1], ip[2], ip[3], flow->dst_port); mt_rte_free(rsp); return NULL; } rsp->flow = r_flow; /* WA to avoid iavf_flow_create fail in 1000+ mudp close at same time */ - if (inf->drv_info.drv_type == MT_DRV_IAVF) - mt_sleep_ms(5); + if (inf->drv_info.drv_type == MT_DRV_IAVF) mt_sleep_ms(5); } return rsp; @@ -278,21 +272,18 @@ static int rx_flow_free(struct mt_interface *inf, struct mt_rx_flow_rsp *rsp) { } mt_rte_free(rsp); /* WA to avoid iavf_flow_destroy fail in 1000+ mudp close at same time */ - if (inf->drv_info.drv_type == MT_DRV_IAVF) - mt_sleep_ms(1); + if (inf->drv_info.drv_type == MT_DRV_IAVF) mt_sleep_ms(1); return 0; } -struct mt_rx_flow_rsp *mt_rx_flow_create(struct mtl_main_impl *impl, - enum mtl_port port, uint16_t q, - struct mt_rxq_flow *flow) { +struct mt_rx_flow_rsp *mt_rx_flow_create(struct mtl_main_impl *impl, enum mtl_port port, + uint16_t q, struct mt_rxq_flow *flow) { struct mt_interface *inf = mt_if(impl, port); struct mt_rx_flow_rsp *rsp; struct mt_flow_impl *flow_impl = impl->flow[port]; if (!mt_drv_kernel_based(impl, port) && q >= inf->nb_rx_q) { - err("%s(%d), invalid q %u max allowed %u\n", __func__, port, q, - inf->nb_rx_q); + err("%s(%d), invalid q %u max allowed %u\n", __func__, port, q, inf->nb_rx_q); return NULL; } @@ -315,8 +306,7 @@ int mt_flow_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { struct mt_flow_impl *flow = impl->flow[i]; - if (!flow) - continue; + if (!flow) continue; mt_pthread_mutex_destroy(&flow->mutex); mt_rte_free(flow); diff --git a/lib/src/mt_flow.h b/lib/src/mt_flow.h index 9d36e6499..70333436c 100644 --- a/lib/src/mt_flow.h +++ b/lib/src/mt_flow.h @@ -10,9 +10,8 @@ int mt_flow_init(struct mtl_main_impl *impl); int mt_flow_uinit(struct mtl_main_impl *impl); -struct mt_rx_flow_rsp *mt_rx_flow_create(struct mtl_main_impl *impl, - enum mtl_port port, uint16_t q, - struct mt_rxq_flow *flow); +struct mt_rx_flow_rsp *mt_rx_flow_create(struct mtl_main_impl *impl, enum mtl_port port, + uint16_t q, struct mt_rxq_flow *flow); int mt_rx_flow_free(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rx_flow_rsp *rsp); diff --git a/lib/src/mt_instance.c b/lib/src/mt_instance.c index f791a93d7..cb4bfee38 100644 --- a/lib/src/mt_instance.c +++ b/lib/src/mt_instance.c @@ -55,8 +55,7 @@ int mt_instance_get_lcore(struct mtl_main_impl *impl, uint16_t lcore_id) { return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); } -int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, - unsigned int ifindex) { +int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, unsigned int ifindex) { int ret; int xsks_map_fd = -1; int sock = impl->instance_fd; @@ -104,23 +103,21 @@ int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, xsks_map_fd = *(int *)CMSG_DATA(cmsg); if (xsks_map_fd < 0) { - err("%s(%u), get xsks_map_fd fail, %s\n", __func__, ifindex, - strerror(errno)); + err("%s(%u), get xsks_map_fd fail, %s\n", __func__, ifindex, strerror(errno)); return errno; } return xsks_map_fd; } -int mt_instance_update_udp_dp_filter(struct mtl_main_impl *impl, - unsigned int ifindex, uint16_t dst_port, - bool add) { +int mt_instance_update_udp_dp_filter(struct mtl_main_impl *impl, unsigned int ifindex, + uint16_t dst_port, bool add) { int sock = impl->instance_fd; mtl_message_t msg; msg.header.magic = htonl(MTL_MANAGER_MAGIC); - msg.header.type = add ? htonl(MTL_MSG_TYPE_ADD_UDP_DP_FILTER) - : htonl(MTL_MSG_TYPE_DEL_UDP_DP_FILTER); + msg.header.type = + add ? htonl(MTL_MSG_TYPE_ADD_UDP_DP_FILTER) : htonl(MTL_MSG_TYPE_DEL_UDP_DP_FILTER); msg.body.udp_dp_filter_msg.ifindex = htonl(ifindex); msg.body.udp_dp_filter_msg.port = htons(dst_port); msg.header.body_len = htonl(sizeof(mtl_udp_dp_filter_message_t)); @@ -137,8 +134,7 @@ int mt_instance_get_queue(struct mtl_main_impl *impl, unsigned int ifindex) { msg.body.if_msg.ifindex = htonl(ifindex); msg.header.body_len = htonl(sizeof(mtl_if_message_t)); - return instance_send_and_receive_message(sock, &msg, - MTL_MSG_TYPE_IF_QUEUE_ID); + return instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_IF_QUEUE_ID); } int mt_instance_put_queue(struct mtl_main_impl *impl, unsigned int ifindex, @@ -157,8 +153,7 @@ int mt_instance_put_queue(struct mtl_main_impl *impl, unsigned int ifindex, int mt_instance_add_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, - uint32_t dst_ip, uint16_t src_port, - uint16_t dst_port) { + uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) { int sock = impl->instance_fd; mtl_message_t msg; @@ -203,8 +198,7 @@ int mt_instance_init(struct mtl_main_impl *impl, struct mtl_init_params *p) { strncpy(addr.sun_path, MTL_MANAGER_SOCK_PATH, sizeof(addr.sun_path) - 1); int ret = connect(sock, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { - warn("%s, connect to manager fail, assume single instance mode\n", - __func__); + warn("%s, connect to manager fail, assume single instance mode\n", __func__); close(sock); return ret; } @@ -237,8 +231,7 @@ int mt_instance_init(struct mtl_main_impl *impl, struct mtl_init_params *p) { } reg_msg->num_if = htons(num_xdp_if); - int response = - instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); + int response = instance_send_and_receive_message(sock, &msg, MTL_MSG_TYPE_RESPONSE); if (response != 0) { err("%s, register fail\n", __func__); close(sock); @@ -254,8 +247,7 @@ int mt_instance_init(struct mtl_main_impl *impl, struct mtl_init_params *p) { int mt_instance_uinit(struct mtl_main_impl *impl) { int sock = impl->instance_fd; - if (sock <= 0) - return -EIO; + if (sock <= 0) return -EIO; return close(sock); } @@ -305,8 +297,7 @@ int mt_instance_put_lcore(struct mtl_main_impl *impl, uint16_t lcore_id) { return -ENOTSUP; } -int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, - unsigned int ifindex) { +int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, unsigned int ifindex) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(ifindex); return -ENOTSUP; @@ -328,8 +319,7 @@ int mt_instance_put_queue(struct mtl_main_impl *impl, unsigned int ifindex, int mt_instance_add_flow(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, - uint32_t dst_ip, uint16_t src_port, - uint16_t dst_port) { + uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(ifindex); MTL_MAY_UNUSED(queue_id); @@ -349,6 +339,8 @@ int mt_instance_del_flow(struct mtl_main_impl *impl, unsigned int ifindex, return -ENOTSUP; } -bool mtl_is_manager_alive(void) { return false; } +bool mtl_is_manager_alive(void) { + return false; +} #endif \ No newline at end of file diff --git a/lib/src/mt_instance.h b/lib/src/mt_instance.h index ff8b0c5cd..db2cb00ac 100644 --- a/lib/src/mt_instance.h +++ b/lib/src/mt_instance.h @@ -12,11 +12,9 @@ int mt_instance_uinit(struct mtl_main_impl *impl); int mt_instance_get_lcore(struct mtl_main_impl *impl, uint16_t lcore_id); int mt_instance_put_lcore(struct mtl_main_impl *impl, uint16_t lcore_id); -int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, - unsigned int ifindex); -int mt_instance_update_udp_dp_filter(struct mtl_main_impl *impl, - unsigned int ifindex, uint16_t dst_port, - bool add); +int mt_instance_request_xsks_map_fd(struct mtl_main_impl *impl, unsigned int ifindex); +int mt_instance_update_udp_dp_filter(struct mtl_main_impl *impl, unsigned int ifindex, + uint16_t dst_port, bool add); int mt_instance_get_queue(struct mtl_main_impl *impl, unsigned int ifindex); int mt_instance_put_queue(struct mtl_main_impl *impl, unsigned int ifindex, uint16_t queue_id); diff --git a/lib/src/mt_log.c b/lib/src/mt_log.c index 08de0109a..0911db357 100644 --- a/lib/src/mt_log.c +++ b/lib/src/mt_log.c @@ -41,10 +41,11 @@ int mtl_set_log_printer(mtl_log_printer_t f) { return 0; } -mtl_log_printer_t mt_get_log_printer(void) { return g_mt_log_printer; } +mtl_log_printer_t mt_get_log_printer(void) { + return g_mt_log_printer; +} -static void log_usdt_printer(enum mtl_log_level level, const char *format, - ...) { +static void log_usdt_printer(enum mtl_log_level level, const char *format, ...) { char msg[256]; va_list args; MTL_MAY_UNUSED(level); @@ -56,7 +57,9 @@ static void log_usdt_printer(enum mtl_log_level level, const char *format, MT_USDT_SYS_LOG_MSG(level, msg); } -mtl_log_printer_t mt_get_usdt_log_printer(void) { return log_usdt_printer; } +mtl_log_printer_t mt_get_usdt_log_printer(void) { + return log_usdt_printer; +} static enum mtl_log_level g_mt_log_level = MTL_LOG_LEVEL_INFO; @@ -65,7 +68,9 @@ int mt_set_log_global_level(enum mtl_log_level level) { return 0; } -enum mtl_log_level mt_get_log_global_level(void) { return g_mt_log_level; } +enum mtl_log_level mt_get_log_global_level(void) { + return g_mt_log_level; +} int mtl_set_log_level(mtl_handle mt, enum mtl_log_level level) { struct mtl_main_impl *impl = mt; @@ -77,31 +82,30 @@ int mtl_set_log_level(mtl_handle mt, enum mtl_log_level level) { } dbg("%s, set log level %d\n", __func__, level); - if (level == mtl_get_log_level(mt)) - return 0; + if (level == mtl_get_log_level(mt)) return 0; switch (level) { - case MTL_LOG_LEVEL_DEBUG: - rte_level = RTE_LOG_DEBUG; - break; - case MTL_LOG_LEVEL_INFO: - rte_level = RTE_LOG_INFO; - break; - case MTL_LOG_LEVEL_NOTICE: - rte_level = RTE_LOG_NOTICE; - break; - case MTL_LOG_LEVEL_WARNING: - rte_level = RTE_LOG_WARNING; - break; - case MTL_LOG_LEVEL_ERR: - rte_level = RTE_LOG_ERR; - break; - case MTL_LOG_LEVEL_CRIT: - rte_level = RTE_LOG_CRIT; - break; - default: - err("%s, invalid level %d\n", __func__, level); - return -EINVAL; + case MTL_LOG_LEVEL_DEBUG: + rte_level = RTE_LOG_DEBUG; + break; + case MTL_LOG_LEVEL_INFO: + rte_level = RTE_LOG_INFO; + break; + case MTL_LOG_LEVEL_NOTICE: + rte_level = RTE_LOG_NOTICE; + break; + case MTL_LOG_LEVEL_WARNING: + rte_level = RTE_LOG_WARNING; + break; + case MTL_LOG_LEVEL_ERR: + rte_level = RTE_LOG_ERR; + break; + case MTL_LOG_LEVEL_CRIT: + rte_level = RTE_LOG_CRIT; + break; + default: + err("%s, invalid level %d\n", __func__, level); + return -EINVAL; } rte_log_set_global_level(rte_level); @@ -123,4 +127,6 @@ enum mtl_log_level mtl_get_log_level(mtl_handle mt) { return mt_get_user_params(impl)->log_level; } -int mtl_openlog_stream(FILE *f) { return rte_openlog_stream(f); } +int mtl_openlog_stream(FILE *f) { + return rte_openlog_stream(f); +} diff --git a/lib/src/mt_log.h b/lib/src/mt_log.h index cd25aeb43..800238ff0 100644 --- a/lib/src/mt_log.h +++ b/lib/src/mt_log.h @@ -41,84 +41,84 @@ mtl_log_printer_t mt_get_usdt_log_printer(void); /* Debug-level messages */ #ifdef DEBUG -#define dbg(...) \ - do { \ - MT_LOG(DEBUG, MT, __VA_ARGS__); \ +#define dbg(...) \ + do { \ + MT_LOG(DEBUG, MT, __VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif /* Informational */ -#define info(...) \ - do { \ - MT_LOG(INFO, MTL, __VA_ARGS__); \ +#define info(...) \ + do { \ + MT_LOG(INFO, MTL, __VA_ARGS__); \ } while (0) -#define info_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(INFO, MTL, __VA_ARGS__); \ - once = false; \ - } \ +#define info_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(INFO, MTL, __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Normal but significant condition. */ -#define notice(...) \ - do { \ - MT_LOG(NOTICE, MTL, __VA_ARGS__); \ +#define notice(...) \ + do { \ + MT_LOG(NOTICE, MTL, __VA_ARGS__); \ } while (0) -#define notice_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(NOTICE, MTL, __VA_ARGS__); \ - once = false; \ - } \ +#define notice_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(NOTICE, MTL, __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Warning conditions. */ -#define warn(...) \ - do { \ - MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ +#define warn(...) \ + do { \ + MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ } while (0) -#define warn_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ - once = false; \ - } \ +#define warn_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(WARNING, MTL, "Warn: " __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Error conditions. */ -#define err(...) \ - do { \ - MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ +#define err(...) \ + do { \ + MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ } while (0) -#define err_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ - once = false; \ - } \ +#define err_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(ERR, MTL, "Error: " __VA_ARGS__); \ + once = false; \ + } \ } while (0) /* Critical conditions */ -#define critical(...) \ - do { \ - MT_LOG(CRIT, MTL, __VA_ARGS__); \ +#define critical(...) \ + do { \ + MT_LOG(CRIT, MTL, __VA_ARGS__); \ } while (0) -#define critical_once(...) \ - do { \ - static bool once = true; \ - if (once) { \ - MT_LOG(CRIT, MTL, __VA_ARGS__); \ - once = false; \ - } \ +#define critical_once(...) \ + do { \ + static bool once = true; \ + if (once) { \ + MT_LOG(CRIT, MTL, __VA_ARGS__); \ + once = false; \ + } \ } while (0) #endif diff --git a/lib/src/mt_main.c b/lib/src/mt_main.c index 02847a4a1..58f5dc388 100644 --- a/lib/src/mt_main.c +++ b/lib/src/mt_main.c @@ -29,8 +29,7 @@ enum mtl_port mt_port_by_id(struct mtl_main_impl *impl, uint16_t port_id) { int i; for (i = 0; i < num_ports; i++) { - if (port_id == mt_port_id(impl, i)) - return i; + if (port_id == mt_port_id(impl, i)) return i; } err("%s, invalid port_id %d\n", __func__, port_id); @@ -38,23 +37,21 @@ enum mtl_port mt_port_by_id(struct mtl_main_impl *impl, uint16_t port_id) { } int mt_dst_ip_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr *ea, enum mtl_port port, - int timeout_ms) { + struct rte_ether_addr *ea, enum mtl_port port, int timeout_ms) { int ret; if (mt_is_multicast_ip(dip)) { mt_mcast_ip_to_mac(dip, ea); ret = 0; - } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), - mt_sip_netmask(impl, port))) { + } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), mt_sip_netmask(impl, port))) { ret = mt_arp_get_mac(impl, dip, ea, port, timeout_ms); } else { uint8_t *gateway = mt_sip_gateway(impl, port); if (mt_ip_to_u32(gateway)) { ret = mt_arp_get_mac(impl, gateway, ea, port, timeout_ms); } else { - err("%s(%d), ip %d.%d.%d.%d is wan but no gateway support\n", __func__, - port, dip[0], dip[1], dip[2], dip[3]); + err("%s(%d), ip %d.%d.%d.%d is wan but no gateway support\n", __func__, port, + dip[0], dip[1], dip[2], dip[3]); return -EIO; } } @@ -62,26 +59,23 @@ int mt_dst_ip_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], dbg("%s(%d), ip: %d.%d.%d.%d, mac: " "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", __func__, port, dip[0], dip[1], dip[2], dip[3], ea->addr_bytes[0], - ea->addr_bytes[1], ea->addr_bytes[2], ea->addr_bytes[3], - ea->addr_bytes[4], ea->addr_bytes[5]); + ea->addr_bytes[1], ea->addr_bytes[2], ea->addr_bytes[3], ea->addr_bytes[4], + ea->addr_bytes[5]); return ret; } uint8_t *mt_sip_addr(struct mtl_main_impl *impl, enum mtl_port port) { - if (mt_dhcp_service_active(impl, port)) - return mt_dhcp_get_ip(impl, port); + if (mt_dhcp_service_active(impl, port)) return mt_dhcp_get_ip(impl, port); return mt_get_user_params(impl)->sip_addr[port]; } uint8_t *mt_sip_netmask(struct mtl_main_impl *impl, enum mtl_port port) { - if (mt_dhcp_service_active(impl, port)) - return mt_dhcp_get_netmask(impl, port); + if (mt_dhcp_service_active(impl, port)) return mt_dhcp_get_netmask(impl, port); return mt_get_user_params(impl)->netmask[port]; } uint8_t *mt_sip_gateway(struct mtl_main_impl *impl, enum mtl_port port) { - if (mt_dhcp_service_active(impl, port)) - return mt_dhcp_get_gateway(impl, port); + if (mt_dhcp_service_active(impl, port)) return mt_dhcp_get_gateway(impl, port); return mt_get_user_params(impl)->gateway[port]; } @@ -90,8 +84,7 @@ bool mt_is_valid_socket(struct mtl_main_impl *impl, int soc_id) { int i; for (i = 0; i < num_ports; i++) { - if (soc_id == mt_socket_id(impl, i)) - return true; + if (soc_id == mt_socket_id(impl, i)) return true; } err("%s, invalid soc_id %d\n", __func__, soc_id); @@ -263,8 +256,7 @@ static int mt_main_free(struct mtl_main_impl *impl) { bool mt_sessions_time_measure(struct mtl_main_impl *impl) { bool enabled = mt_user_tasklet_time_measure(impl); - if (MT_USDT_SESSIONS_TIME_MEASURE_ENABLED()) - enabled = true; + if (MT_USDT_SESSIONS_TIME_MEASURE_ENABLED()) enabled = true; return enabled; } @@ -297,8 +289,7 @@ static int mt_user_params_check(struct mtl_init_params *p) { else if_name = mt_dpdk_afxdp_port2if(p->port[i]); if (!if_name) { - err("%s(%d), get afxdp if name fail from %s\n", __func__, i, - p->port[i]); + err("%s(%d), get afxdp if name fail from %s\n", __func__, i, p->port[i]); return -EINVAL; } } @@ -306,8 +297,7 @@ static int mt_user_params_check(struct mtl_init_params *p) { if (pmd == MTL_PMD_DPDK_AF_PACKET) { if_name = mt_dpdk_afpkt_port2if(p->port[i]); if (!if_name) { - err("%s(%d), get afpkt if name fail from %s\n", __func__, i, - p->port[i]); + err("%s(%d), get afpkt if name fail from %s\n", __func__, i, p->port[i]); return -EINVAL; } } @@ -315,8 +305,7 @@ static int mt_user_params_check(struct mtl_init_params *p) { if (pmd == MTL_PMD_KERNEL_SOCKET) { if_name = mt_kernel_port2if(p->port[i]); if (!if_name) { - err("%s(%d), get kernel socket if name fail from %s\n", __func__, i, - p->port[i]); + err("%s(%d), get kernel socket if name fail from %s\n", __func__, i, p->port[i]); return -EINVAL; } } @@ -331,8 +320,7 @@ static int mt_user_params_check(struct mtl_init_params *p) { ip = p->sip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], - ip[2], ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -343,22 +331,19 @@ static int mt_user_params_check(struct mtl_init_params *p) { if (0 == strncmp(p->port[i], p->port[j], MTL_PORT_MAX_LEN)) { if (!strncmp(p->port[i], "kernel:lo", MTL_PORT_MAX_LEN)) { /* duplicated kernel:lo for test purpose */ - warn("%s, same name %s for port %d and %d\n", __func__, p->port[i], - i, j); + warn("%s, same name %s for port %d and %d\n", __func__, p->port[i], i, j); } else { - err("%s, same name %s for port %d and %d\n", __func__, p->port[i], - i, j); + err("%s, same name %s for port %d and %d\n", __func__, p->port[i], i, j); return -EINVAL; } } /* check if duplicate ip */ - if ((p->net_proto[i] == MTL_PROTO_STATIC) && - (p->pmd[i] == MTL_PMD_DPDK_USER) && + if ((p->net_proto[i] == MTL_PROTO_STATIC) && (p->pmd[i] == MTL_PMD_DPDK_USER) && (p->pmd[j] == MTL_PMD_DPDK_USER)) { if (0 == memcmp(p->sip_addr[i], p->sip_addr[j], MTL_IP_ADDR_LEN)) { ip = p->sip_addr[j]; - err("%s, same ip %d.%d.%d.%d for port %d and %d\n", __func__, ip[0], - ip[1], ip[2], ip[3], i, j); + err("%s, same ip %d.%d.%d.%d for port %d and %d\n", __func__, ip[0], ip[1], + ip[2], ip[3], i, j); return -EINVAL; } } @@ -447,8 +432,7 @@ mtl_handle mtl_init(struct mtl_init_params *p) { socket[i] = mt_dev_get_socket_id(p->port[i]); } if (socket[i] < 0) { - err("%s(%d), get socket fail %d for pmd %d\n", __func__, i, socket[i], - p->pmd[i]); + err("%s(%d), get socket fail %d for pmd %d\n", __func__, i, socket[i], p->pmd[i]); #ifndef WINDOWSENV if (pmd == MTL_PMD_DPDK_USER) { err("Run \"dpdk-devbind.py -s | grep Ethernet\" to check if other port " @@ -467,8 +451,7 @@ mtl_handle mtl_init(struct mtl_init_params *p) { #ifndef WINDOWSENV int numa_nodes = 0; - if (numa_available() >= 0) - numa_nodes = numa_max_node() + 1; + if (numa_available() >= 0) numa_nodes = numa_max_node() + 1; if (!(p->flags & MTL_FLAG_NOT_BIND_PROCESS_NUMA) && (numa_nodes > 1)) { /* bind current thread and its children to socket node */ struct bitmask *mask = numa_bitmask_alloc(numa_nodes); @@ -586,12 +569,10 @@ mtl_handle mtl_init(struct mtl_init_params *p) { impl->rx_pool_data_size = p->rx_pool_data_size; info("%s, new rx_pool_data_size %u\n", __func__, impl->rx_pool_data_size); } else { - warn("%s, invalid rx_pool_data_size %u\n", __func__, - p->rx_pool_data_size); + warn("%s, invalid rx_pool_data_size %u\n", __func__, p->rx_pool_data_size); } } - impl->sch_schedule_ns = - 200 * NS_PER_US; /* max schedule ns for mt_sleep_ms(0) */ + impl->sch_schedule_ns = 200 * NS_PER_US; /* max schedule ns for mt_sleep_ms(0) */ if (p->arp_timeout_s) impl->arp_timeout_ms = p->arp_timeout_s * MS_PER_S; @@ -635,8 +616,7 @@ mtl_handle mtl_init(struct mtl_init_params *p) { } if (p->flags & MTL_FLAG_NOT_BIND_NUMA) { - warn("%s, performance may limited as possible across numa access\n", - __func__); + warn("%s, performance may limited as possible across numa access\n", __func__); } info("%s, succ, tsc_hz %" PRIu64 "\n", __func__, impl->tsc_hz); @@ -645,8 +625,7 @@ mtl_handle mtl_init(struct mtl_init_params *p) { return impl; err_exit: - if (impl) - mtl_uninit(impl); + if (impl) mtl_uninit(impl); return NULL; } @@ -700,8 +679,7 @@ int mtl_stop(mtl_handle mt) { return -EIO; } - if (mt_user_auto_start_stop(impl)) - return 0; + if (mt_user_auto_start_stop(impl)) return 0; return _mt_stop(impl); } @@ -853,8 +831,7 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void *vaddr, size_t size) { item.size = size; item.iova = MTL_BAD_IOVA; /* let map to find one suitable iova for us */ ret = mt_map_add(impl, &item); - if (ret < 0) - return MTL_BAD_IOVA; + if (ret < 0) return MTL_BAD_IOVA; iova = item.iova; if (!mt_drv_dpdk_based(impl, MTL_PORT_P)) { @@ -863,14 +840,13 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void *vaddr, size_t size) { ret = rte_extmem_register((void *)vaddr, size, NULL, 0, page_size); if (ret < 0) { - err("%s, fail(%d,%s) to register extmem %p\n", __func__, ret, - rte_strerror(rte_errno), vaddr); + err("%s, fail(%d,%s) to register extmem %p\n", __func__, ret, rte_strerror(rte_errno), + vaddr); goto fail_extmem; } /* only map for MTL_PORT_P now */ - ret = rte_dev_dma_map(mt_port_device(impl, MTL_PORT_P), (void *)vaddr, iova, - size); + ret = rte_dev_dma_map(mt_port_device(impl, MTL_PORT_P), (void *)vaddr, iova, size); if (ret < 0) { err("%s, dma map fail(%d,%s) for add(%p,%" PRIu64 ")\n", __func__, ret, rte_strerror(rte_errno), vaddr, size); @@ -886,8 +862,7 @@ mtl_iova_t mtl_dma_map(mtl_handle mt, const void *vaddr, size_t size) { return MTL_BAD_IOVA; } -int mtl_dma_unmap(mtl_handle mt, const void *vaddr, mtl_iova_t iova, - size_t size) { +int mtl_dma_unmap(mtl_handle mt, const void *vaddr, mtl_iova_t iova, size_t size) { struct mtl_main_impl *impl = mt; int ret; size_t page_size = mtl_page_size(impl); @@ -917,16 +892,14 @@ int mtl_dma_unmap(mtl_handle mt, const void *vaddr, mtl_iova_t iova, item.size = size; item.iova = iova; ret = mt_map_remove(impl, &item); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (!mt_drv_dpdk_based(impl, MTL_PORT_P)) { return 0; } /* only unmap for MTL_PORT_P now */ - ret = rte_dev_dma_unmap(mt_port_device(impl, MTL_PORT_P), (void *)vaddr, iova, - size); + ret = rte_dev_dma_unmap(mt_port_device(impl, MTL_PORT_P), (void *)vaddr, iova, size); if (ret < 0) { err("%s, dma unmap fail(%d,%s) for add(%p,%" PRIu64 ")\n", __func__, ret, rte_strerror(rte_errno), vaddr, size); @@ -1003,12 +976,11 @@ mtl_iova_t mtl_dma_mem_iova(mtl_dma_mem_handle handle) { const char *mtl_version(void) { static char version[128]; - if (version[0] != 0) - return version; + if (version[0] != 0) return version; snprintf(version, sizeof(version), "%d.%d.%d.%s %s %s %s", MTL_VERSION_MAJOR, - MTL_VERSION_MINOR, MTL_VERSION_LAST, MTL_VERSION_EXTRA, - __TIMESTAMP__, __MTL_GIT__, MTL_COMPILER); + MTL_VERSION_MINOR, MTL_VERSION_LAST, MTL_VERSION_EXTRA, __TIMESTAMP__, + __MTL_GIT__, MTL_COMPILER); return version; } @@ -1090,8 +1062,7 @@ int mtl_sch_enable_sleep(mtl_handle mt, int sch_idx, bool enable) { } mt_sch_enable_allow_sleep(sch, enable); - info("%s(%d), %s allow sleep\n", __func__, sch_idx, - enable ? "enable" : "disable"); + info("%s(%d), %s allow sleep\n", __func__, sch_idx, enable ? "enable" : "disable"); return 0; } @@ -1145,8 +1116,7 @@ uint64_t mtl_ptp_read_time_raw(mtl_handle mt) { return mt_get_ptp_time(impl, port); } -mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, - enum mtl_port port) { +mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, enum mtl_port port) { struct mtl_main_impl *impl = mt; struct mt_dma_request_req req; @@ -1167,8 +1137,7 @@ mtl_udma_handle mtl_udma_create(mtl_handle mt, uint16_t nb_desc, req.priv = impl; req.drop_mbuf_cb = NULL; struct mtl_dma_lender_dev *dev = mt_dma_request_dev(impl, &req); - if (dev) - dev->type = MT_HANDLE_UDMA; + if (dev) dev->type = MT_HANDLE_UDMA; return dev; } @@ -1250,20 +1219,18 @@ enum mtl_iova_mode mtl_iova_mode_get(mtl_handle mt) { } switch (impl->iova_mode) { - case RTE_IOVA_PA: - return MTL_IOVA_MODE_PA; - case RTE_IOVA_VA: - return MTL_IOVA_MODE_VA; - default: - err("%s, invalid iova_mode %d\n", __func__, impl->iova_mode); - return MTL_IOVA_MODE_MAX; + case RTE_IOVA_PA: + return MTL_IOVA_MODE_PA; + case RTE_IOVA_VA: + return MTL_IOVA_MODE_VA; + default: + err("%s, invalid iova_mode %d\n", __func__, impl->iova_mode); + return MTL_IOVA_MODE_MAX; } } -int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, - uint8_t ip[MTL_IP_ADDR_LEN], - uint8_t netmask[MTL_IP_ADDR_LEN], - uint8_t gateway[MTL_IP_ADDR_LEN]) { +int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, uint8_t ip[MTL_IP_ADDR_LEN], + uint8_t netmask[MTL_IP_ADDR_LEN], uint8_t gateway[MTL_IP_ADDR_LEN]) { struct mtl_main_impl *impl = mt; if (impl->type != MT_HANDLE_MAIN) { @@ -1275,22 +1242,17 @@ int mtl_port_ip_info(mtl_handle mt, enum mtl_port port, return -EINVAL; } - if (ip) - rte_memcpy(ip, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); - if (netmask) - rte_memcpy(netmask, mt_sip_netmask(impl, port), MTL_IP_ADDR_LEN); - if (gateway) - rte_memcpy(gateway, mt_sip_gateway(impl, port), MTL_IP_ADDR_LEN); + if (ip) rte_memcpy(ip, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); + if (netmask) rte_memcpy(netmask, mt_sip_netmask(impl, port), MTL_IP_ADDR_LEN); + if (gateway) rte_memcpy(gateway, mt_sip_gateway(impl, port), MTL_IP_ADDR_LEN); return 0; } enum mtl_simd_level mtl_get_simd_level(void) { if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VBMI2)) return MTL_SIMD_LEVEL_AVX512_VBMI2; - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL)) - return MTL_SIMD_LEVEL_AVX512; - if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2)) - return MTL_SIMD_LEVEL_AVX2; + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL)) return MTL_SIMD_LEVEL_AVX512; + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2)) return MTL_SIMD_LEVEL_AVX2; /* no simd */ return MTL_SIMD_LEVEL_NONE; } @@ -1339,43 +1301,40 @@ int mtl_thread_setname(pthread_t tid, const char *name) { #endif } -void mtl_sleep_us(unsigned int us) { return mt_sleep_us(us); } +void mtl_sleep_us(unsigned int us) { + return mt_sleep_us(us); +} -void mtl_delay_us(unsigned int us) { return mt_delay_us(us); } +void mtl_delay_us(unsigned int us) { + return mt_delay_us(us); +} int mtl_para_sip_set(struct mtl_init_params *p, enum mtl_port port, char *ip) { int ret = inet_pton(AF_INET, ip, p->sip_addr[port]); - if (ret == 1) - return 0; + if (ret == 1) return 0; err("%s, fail to inet_pton for %s\n", __func__, ip); return -EIO; } -int mtl_para_gateway_set(struct mtl_init_params *p, enum mtl_port port, - char *gateway) { +int mtl_para_gateway_set(struct mtl_init_params *p, enum mtl_port port, char *gateway) { int ret = inet_pton(AF_INET, gateway, p->gateway[port]); - if (ret == 1) - return 0; + if (ret == 1) return 0; err("%s, fail to inet_pton for %s\n", __func__, gateway); return -EIO; } -int mtl_para_netmask_set(struct mtl_init_params *p, enum mtl_port port, - char *netmask) { +int mtl_para_netmask_set(struct mtl_init_params *p, enum mtl_port port, char *netmask) { int ret = inet_pton(AF_INET, netmask, p->netmask[port]); - if (ret == 1) - return 0; + if (ret == 1) return 0; err("%s, fail to inet_pton for %s\n", __func__, netmask); return -EIO; } -int mtl_para_port_set(struct mtl_init_params *p, enum mtl_port port, - char *name) { +int mtl_para_port_set(struct mtl_init_params *p, enum mtl_port port, char *name) { return snprintf(p->port[port], MTL_PORT_MAX_LEN, "%s", name); } -int mtl_para_dma_port_set(struct mtl_init_params *p, enum mtl_port port, - char *name) { +int mtl_para_dma_port_set(struct mtl_init_params *p, enum mtl_port port, char *name) { return snprintf(p->dma_dev_port[port], MTL_PORT_MAX_LEN, "%s", name); } diff --git a/lib/src/mt_main.h b/lib/src/mt_main.h index ecca72aa7..c0b45fb64 100644 --- a/lib/src/mt_main.h +++ b/lib/src/mt_main.h @@ -33,10 +33,8 @@ #define MT_TAILQ_FIRST(head) RTE_TAILQ_FIRST(head) #define MT_TAILQ_NEXT(elem, field) RTE_TAILQ_NEXT(elem, field) -#define MT_TAILQ_INSERT_TAIL(head, elem, filed) \ - TAILQ_INSERT_TAIL(head, elem, filed) -#define MT_TAILQ_INSERT_HEAD(head, elem, filed) \ - TAILQ_INSERT_HEAD(head, elem, filed) +#define MT_TAILQ_INSERT_TAIL(head, elem, filed) TAILQ_INSERT_TAIL(head, elem, filed) +#define MT_TAILQ_INSERT_HEAD(head, elem, filed) TAILQ_INSERT_HEAD(head, elem, filed) #define MT_TAILQ_REMOVE(head, elem, filed) TAILQ_REMOVE(head, elem, filed) #define MT_TAILQ_INIT(head) TAILQ_INIT(head) @@ -91,12 +89,12 @@ #define MT_TIMEOUT_INFINITE (INT_MAX) #define MT_TIMEOUT_ZERO (0) -#define MT_SAFE_FREE(obj, free_fn) \ - do { \ - if (obj) { \ - free_fn(obj); \ - obj = NULL; \ - } \ +#define MT_SAFE_FREE(obj, free_fn) \ + do { \ + if (obj) { \ + free_fn(obj); \ + obj = NULL; \ + } \ } while (0) struct mtl_main_impl; /* forward declare */ @@ -1280,8 +1278,7 @@ struct mtl_main_impl { int instance_fd; }; -static inline struct mtl_init_params * -mt_get_user_params(struct mtl_main_impl *impl) { +static inline struct mtl_init_params *mt_get_user_params(struct mtl_main_impl *impl) { return &impl->user_para; } @@ -1293,13 +1290,11 @@ static inline bool mt_is_manager_connected(struct mtl_main_impl *impl) { return impl->instance_fd > 0; } -static inline struct mt_interface *mt_if(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline struct mt_interface *mt_if(struct mtl_main_impl *impl, enum mtl_port port) { return &impl->inf[port]; } -static inline uint16_t mt_port_id(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline uint16_t mt_port_id(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->port_id; } @@ -1318,16 +1313,14 @@ uint8_t *mt_sip_addr(struct mtl_main_impl *impl, enum mtl_port port); uint8_t *mt_sip_netmask(struct mtl_main_impl *impl, enum mtl_port port); uint8_t *mt_sip_gateway(struct mtl_main_impl *impl, enum mtl_port port); int mt_dst_ip_mac(struct mtl_main_impl *impl, uint8_t dip[MTL_IP_ADDR_LEN], - struct rte_ether_addr *ea, enum mtl_port port, - int timeout_ms); + struct rte_ether_addr *ea, enum mtl_port port, int timeout_ms); static inline enum mtl_pmd_type mt_pmd_type(struct mtl_main_impl *impl, enum mtl_port port) { return mt_get_user_params(impl)->pmd[port]; } -static inline bool mt_pmd_is_dpdk_user(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_pmd_is_dpdk_user(struct mtl_main_impl *impl, enum mtl_port port) { if (MTL_PMD_DPDK_USER == mt_get_user_params(impl)->pmd[port]) return true; else @@ -1342,24 +1335,21 @@ static inline bool mt_pmd_is_kernel_based(struct mtl_main_impl *impl, return true; } -static inline bool mt_drv_use_kernel_ctl(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_drv_use_kernel_ctl(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_USE_KERNEL_CTL) return true; else return false; } -static inline bool mt_drv_dpdk_based(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_drv_dpdk_based(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_NOT_DPDK_PMD) return false; else return true; } -static inline bool mt_drv_mcast_in_dp(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_drv_mcast_in_dp(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_MCAST_IN_DP) return true; else @@ -1371,32 +1361,28 @@ static inline const char *mt_kernel_if_name(struct mtl_main_impl *impl, return impl->kport_info.kernel_if[port]; } -static inline bool mt_drv_no_cni(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_drv_no_cni(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_NO_CNI) return true; else return false; } -static inline bool mt_drv_no_sys_txq(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_drv_no_sys_txq(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_NO_SYS_TX_QUEUE) return true; else return false; } -static inline bool mt_drv_kernel_based(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_drv_kernel_based(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->drv_info.flags & MT_DRV_F_KERNEL_BASED) return true; else return false; } -static inline bool mt_pmd_is_dpdk_af_xdp(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_pmd_is_dpdk_af_xdp(struct mtl_main_impl *impl, enum mtl_port port) { if (MTL_PMD_DPDK_AF_XDP == mt_get_user_params(impl)->pmd[port]) return true; else @@ -1427,8 +1413,7 @@ static inline bool mt_pmd_is_native_af_xdp(struct mtl_main_impl *impl, return false; } -static inline bool mt_pmd_is_rdma_ud(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_pmd_is_rdma_ud(struct mtl_main_impl *impl, enum mtl_port port) { if (MTL_PMD_RDMA_UD == mt_get_user_params(impl)->pmd[port]) return true; else @@ -1594,17 +1579,14 @@ static inline bool mt_has_cni(struct mtl_main_impl *impl, enum mtl_port port) { return false; } -static inline bool mt_has_cni_rx(struct mtl_main_impl *impl, - enum mtl_port port) { - if ((mt_get_user_params(impl)->flags & MTL_FLAG_RX_USE_CNI) && - mt_has_cni(impl, port)) +static inline bool mt_has_cni_rx(struct mtl_main_impl *impl, enum mtl_port port) { + if ((mt_get_user_params(impl)->flags & MTL_FLAG_RX_USE_CNI) && mt_has_cni(impl, port)) return true; else return false; } -static inline bool mt_has_virtio_user(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_has_virtio_user(struct mtl_main_impl *impl, enum mtl_port port) { if ((mt_get_user_params(impl)->flags & MTL_FLAG_VIRTIO_USER) && mt_pmd_is_dpdk_user(impl, port)) return true; @@ -1630,8 +1612,7 @@ static inline bool mt_has_srss(struct mtl_main_impl *impl, enum mtl_port port) { } /* if user enable udp lcore mode */ -static inline bool mt_user_udp_lcore(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_user_udp_lcore(struct mtl_main_impl *impl, enum mtl_port port) { MTL_MAY_UNUSED(port); if (mt_get_user_params(impl)->flags & MTL_FLAG_UDP_LCORE) return true; @@ -1656,8 +1637,7 @@ static inline bool mt_user_multi_src_port(struct mtl_main_impl *impl) { } /* if user enable shared tx queue */ -static inline bool mt_user_shared_txq(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_user_shared_txq(struct mtl_main_impl *impl, enum mtl_port port) { MTL_MAY_UNUSED(port); if (mt_get_user_params(impl)->flags & MTL_FLAG_SHARED_TX_QUEUE) return true; @@ -1666,8 +1646,7 @@ static inline bool mt_user_shared_txq(struct mtl_main_impl *impl, } /* if user enable shared rx queue */ -static inline bool mt_user_shared_rxq(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_user_shared_rxq(struct mtl_main_impl *impl, enum mtl_port port) { MTL_MAY_UNUSED(port); if (mt_get_user_params(impl)->flags & MTL_FLAG_SHARED_RX_QUEUE) return true; @@ -1707,8 +1686,7 @@ static inline bool mt_user_tasklet_sleep(struct mtl_main_impl *impl) { return false; } -static inline bool mt_if_has_timesync(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_if_has_timesync(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_TIMESYNC) return true; else @@ -1731,16 +1709,14 @@ static inline bool mt_if_has_offload_ipv4_cksum(struct mtl_main_impl *impl, return false; } -static inline bool mt_if_has_multi_seg(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_if_has_multi_seg(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_TX_MULTI_SEGS) return true; else return false; } -static inline bool mt_if_has_hdr_split(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_if_has_hdr_split(struct mtl_main_impl *impl, enum mtl_port port) { if (mt_if(impl, port)->feature & MT_IF_FEATURE_RXQ_OFFLOAD_BUFFER_SPLIT) return true; else @@ -1752,24 +1728,20 @@ static inline struct rte_mempool *mt_if_hdr_split_pool(struct mt_interface *inf, return inf->rx_queues[q].mbuf_payload_pool; } -static inline uint16_t mt_if_nb_tx_desc(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline uint16_t mt_if_nb_tx_desc(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->nb_tx_desc; } -static inline uint16_t mt_if_nb_rx_desc(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline uint16_t mt_if_nb_rx_desc(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->nb_rx_desc; } -static inline uint16_t mt_if_nb_tx_burst(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline uint16_t mt_if_nb_tx_burst(struct mtl_main_impl *impl, enum mtl_port port) { uint16_t burst_pkts; if (mt_pmd_is_dpdk_af_xdp(impl, port)) { /* same umem for both tx and rx */ - burst_pkts = - RTE_MAX(mt_if_nb_rx_desc(impl, port), mt_if_nb_tx_desc(impl, port)); + burst_pkts = RTE_MAX(mt_if_nb_rx_desc(impl, port), mt_if_nb_tx_desc(impl, port)); } else { burst_pkts = mt_if_nb_tx_desc(impl, port); } @@ -1893,8 +1865,7 @@ static inline uint64_t mt_get_tsc(struct mtl_main_impl *impl) { } /* busy loop until target time reach */ -static inline void mt_tsc_delay_to(struct mtl_main_impl *impl, - uint64_t target) { +static inline void mt_tsc_delay_to(struct mtl_main_impl *impl, uint64_t target) { while (mt_get_tsc(impl) < target) { } } @@ -1914,8 +1885,7 @@ static inline uint64_t mt_get_real_time(void) { return mt_timespec_to_ns(&ts); } -static inline void st_tx_mbuf_set_tsc(struct rte_mbuf *mbuf, - uint64_t time_stamp) { +static inline void st_tx_mbuf_set_tsc(struct rte_mbuf *mbuf, uint64_t time_stamp) { struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->tx_priv.tsc_time_stamp = time_stamp; } @@ -1925,8 +1895,7 @@ static inline uint64_t st_tx_mbuf_get_tsc(struct rte_mbuf *mbuf) { return priv->tx_priv.tsc_time_stamp; } -static inline void st_tx_mbuf_set_ptp(struct rte_mbuf *mbuf, - uint64_t time_stamp) { +static inline void st_tx_mbuf_set_ptp(struct rte_mbuf *mbuf, uint64_t time_stamp) { struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->tx_priv.ptp_time_stamp = time_stamp; } @@ -1956,8 +1925,7 @@ static inline void *st_tx_mbuf_get_priv(struct rte_mbuf *mbuf) { return priv->tx_priv.priv; } -static inline void st_rx_mbuf_set_lender(struct rte_mbuf *mbuf, - uint32_t lender) { +static inline void st_rx_mbuf_set_lender(struct rte_mbuf *mbuf, uint32_t lender) { struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->rx_priv.lender = lender; } @@ -1967,8 +1935,7 @@ static inline uint32_t st_rx_mbuf_get_lender(struct rte_mbuf *mbuf) { return priv->rx_priv.lender; } -static inline void st_rx_mbuf_set_offset(struct rte_mbuf *mbuf, - uint32_t offset) { +static inline void st_rx_mbuf_set_offset(struct rte_mbuf *mbuf, uint32_t offset) { struct mt_muf_priv_data *priv = rte_mbuf_to_priv(mbuf); priv->rx_priv.offset = offset; } @@ -1991,13 +1958,11 @@ static inline uint32_t st_rx_mbuf_get_len(struct rte_mbuf *mbuf) { uint64_t mt_mbuf_time_stamp(struct mtl_main_impl *impl, struct rte_mbuf *mbuf, enum mtl_port port); -static inline uint64_t mt_get_ptp_time(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline uint64_t mt_get_ptp_time(struct mtl_main_impl *impl, enum mtl_port port) { return mt_if(impl, port)->ptp_get_time_fn(impl, port); } -int mt_ptp_wait_stable(struct mtl_main_impl *impl, enum mtl_port port, - int timeout_ms); +int mt_ptp_wait_stable(struct mtl_main_impl *impl, enum mtl_port port, int timeout_ms); uint64_t mt_get_raw_ptp_time(struct mtl_main_impl *impl, enum mtl_port port); @@ -2019,31 +1984,26 @@ static inline struct rte_ether_addr *mt_eth_d_addr(struct rte_ether_hdr *eth) { } #endif -#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ +#if (JSON_C_VERSION_NUM >= ((0 << 16) | (13 << 8) | 0)) || \ (JSON_C_VERSION_NUM < ((0 << 16) | (10 << 8) | 0)) -static inline json_object *mt_json_object_get(json_object *obj, - const char *key) { +static inline json_object *mt_json_object_get(json_object *obj, const char *key) { return json_object_object_get(obj, key); } #else -static inline json_object *mt_json_object_get(json_object *obj, - const char *key) { +static inline json_object *mt_json_object_get(json_object *obj, const char *key) { json_object *value; int ret = json_object_object_get_ex(obj, key, &value); - if (ret) - return value; + if (ret) return value; return NULL; } #endif static inline bool mt_spinlock_lock_timeout(struct mtl_main_impl *impl, - rte_spinlock_t *lock, - int timeout_us) { + rte_spinlock_t *lock, int timeout_us) { uint64_t time = mt_get_tsc(impl); uint64_t end = time + timeout_us * NS_PER_US; while (time < end) { - if (rte_spinlock_trylock(lock)) - return true; + if (rte_spinlock_trylock(lock)) return true; time = mt_get_tsc(impl); } return false; /* timeout */ diff --git a/lib/src/mt_mcast.c b/lib/src/mt_mcast.c index 759883fe4..1f9ad9076 100644 --- a/lib/src/mt_mcast.c +++ b/lib/src/mt_mcast.c @@ -21,25 +21,24 @@ static uint16_t mcast_msg_checksum(enum mcast_msg_type type, void *msg, size_t size = 0; switch (type) { - case MEMBERSHIP_QUERY: - size = sizeof(struct mcast_mb_query_v3); - break; - case MEMBERSHIP_REPORT_V3: - size = mb_report_len; - break; - default: - err("%s, wrong mcast msg type: %d\n", __func__, type); - break; + case MEMBERSHIP_QUERY: + size = sizeof(struct mcast_mb_query_v3); + break; + case MEMBERSHIP_REPORT_V3: + size = mb_report_len; + break; + default: + err("%s, wrong mcast msg type: %d\n", __func__, type); + break; } return mt_rf1071_check_sum(msg, size, true); } /* group record shaping, return record length, refer to RFC3376 - 4.2.4 */ -static inline size_t -mcast_create_group_record_on_query(uint32_t group_addr, - struct mt_mcast_src_list *src_list, - struct mcast_group_record *group_record) { +static inline size_t mcast_create_group_record_on_query( + uint32_t group_addr, struct mt_mcast_src_list *src_list, + struct mcast_group_record *group_record) { uint16_t num_sources = 0; struct mt_mcast_src_entry *src; TAILQ_FOREACH(src, src_list, entries) { @@ -55,15 +54,13 @@ mcast_create_group_record_on_query(uint32_t group_addr, group_record->num_sources = htons(num_sources); group_record->multicast_addr = group_addr; - size_t record_len = - sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); + size_t record_len = sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); return record_len; } -static inline size_t -mcast_create_group_record_join(uint32_t group_addr, uint32_t src_addr, - struct mcast_group_record *group_record) { +static inline size_t mcast_create_group_record_join( + uint32_t group_addr, uint32_t src_addr, struct mcast_group_record *group_record) { uint16_t num_sources = 0; group_record->aux_data_len = 0; group_record->multicast_addr = group_addr; @@ -77,14 +74,12 @@ mcast_create_group_record_join(uint32_t group_addr, uint32_t src_addr, } group_record->num_sources = htons(num_sources); - size_t record_len = - sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); + size_t record_len = sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); return record_len; } -static inline size_t -mcast_create_group_record_leave(uint32_t group_addr, uint32_t src_addr, - struct mcast_group_record *group_record) { +static inline size_t mcast_create_group_record_leave( + uint32_t group_addr, uint32_t src_addr, struct mcast_group_record *group_record) { uint16_t num_sources = 0; group_record->aux_data_len = 0; group_record->multicast_addr = group_addr; @@ -98,18 +93,15 @@ mcast_create_group_record_leave(uint32_t group_addr, uint32_t src_addr, } group_record->num_sources = htons(num_sources); - size_t record_len = - sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); + size_t record_len = sizeof(struct mcast_group_record) + num_sources * sizeof(uint32_t); return record_len; } /* 224.0.0.22 */ -static struct rte_ether_addr const mcast_mac_dst = { - {0x01, 0x00, 0x5e, 0x00, 0x00, 0x16}}; +static struct rte_ether_addr const mcast_mac_dst = {{0x01, 0x00, 0x5e, 0x00, 0x00, 0x16}}; static struct rte_ipv4_hdr *mcast_fill_ipv4(struct mtl_main_impl *impl, - enum mtl_port port, - struct rte_mbuf *pkt) { + enum mtl_port port, struct rte_mbuf *pkt) { struct rte_ether_hdr *eth_hdr; struct rte_ipv4_hdr *ip_hdr; @@ -118,8 +110,7 @@ static struct rte_ipv4_hdr *mcast_fill_ipv4(struct mtl_main_impl *impl, rte_ether_addr_copy(&mcast_mac_dst, mt_eth_d_addr(eth_hdr)); eth_hdr->ether_type = htons(RTE_ETHER_TYPE_IPV4); - ip_hdr = - rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, sizeof(*eth_hdr)); + ip_hdr = rte_pktmbuf_mtod_offset(pkt, struct rte_ipv4_hdr *, sizeof(*eth_hdr)); ip_hdr->version_ihl = (4 << 4) | (sizeof(struct rte_ipv4_hdr) / 4); ip_hdr->time_to_live = 1; ip_hdr->type_of_service = IP_IGMP_DSCP_VALUE; @@ -138,8 +129,7 @@ static struct rte_ipv4_hdr *mcast_fill_ipv4(struct mtl_main_impl *impl, static struct rte_ether_addr const mcast_mac_query = { {0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}}; -int mcast_membership_general_query(struct mtl_main_impl *impl, - enum mtl_port port) { +int mcast_membership_general_query(struct mtl_main_impl *impl, enum mtl_port port) { struct rte_mbuf *pkt; struct rte_ipv4_hdr *ip_hdr; struct mcast_mb_query_v3 *mb_query; @@ -155,8 +145,7 @@ int mcast_membership_general_query(struct mtl_main_impl *impl, ip_hdr = mcast_fill_ipv4(impl, port, pkt); hdr_offset += sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr); - mb_query = - rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_query_v3 *, hdr_offset); + mb_query = rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_query_v3 *, hdr_offset); mb_query->type = MEMBERSHIP_QUERY; mb_query->max_resp_code = 100; mb_query->checksum = 0x00; @@ -217,16 +206,14 @@ static int mcast_membership_report_on_query(struct mtl_main_impl *impl, ip_hdr = mcast_fill_ipv4(impl, port, pkt); hdr_offset += sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr); - mb_report = - rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3 *, hdr_offset); + mb_report = rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3 *, hdr_offset); mb_report->type = MEMBERSHIP_REPORT_V3; mb_report->reserved_1 = 0x00; mb_report->checksum = 0x00; mb_report->reserved_2 = 0x00; mb_report->num_group_records = htons(group_num); hdr_offset += sizeof(struct mcast_mb_report_v3); - uint8_t *group_record_addr = - rte_pktmbuf_mtod_offset(pkt, uint8_t *, hdr_offset); + uint8_t *group_record_addr = rte_pktmbuf_mtod_offset(pkt, uint8_t *, hdr_offset); struct mt_mcast_group_entry *group; TAILQ_FOREACH(group, &mcast->group_list, entries) { @@ -237,8 +224,7 @@ static int mcast_membership_report_on_query(struct mtl_main_impl *impl, mb_report_len += record_len; } - uint16_t checksum = - mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); + uint16_t checksum = mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); if (checksum <= 0) { err("%s(%d), err checksum %d\n", __func__, port, checksum); return -EIO; @@ -255,8 +241,7 @@ static int mcast_membership_report_on_query(struct mtl_main_impl *impl, /* send packet to kernel for capturing */ if (mt_has_virtio_user(impl, port)) { struct mt_interface *inf = mt_if(impl, port); - rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf **)&report_pkt, - 1); + rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf **)&report_pkt, 1); } #endif @@ -267,15 +252,13 @@ static int mcast_membership_report_on_query(struct mtl_main_impl *impl, return -EIO; } - dbg("%s(%d), send pkt, mb_report_len %" PRIu64 "\n", __func__, port, - mb_report_len); + dbg("%s(%d), send pkt, mb_report_len %" PRIu64 "\n", __func__, port, mb_report_len); return 0; } static int mcast_membership_report_on_action(struct mtl_main_impl *impl, - enum mtl_port port, - uint32_t group_addr, + enum mtl_port port, uint32_t group_addr, uint32_t src_addr, enum mcast_action_type action) { struct rte_mbuf *pkt; @@ -294,25 +277,20 @@ static int mcast_membership_report_on_action(struct mtl_main_impl *impl, ip_hdr = mcast_fill_ipv4(impl, port, pkt); hdr_offset += sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr); - mb_report = - rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3 *, hdr_offset); + mb_report = rte_pktmbuf_mtod_offset(pkt, struct mcast_mb_report_v3 *, hdr_offset); mb_report->type = MEMBERSHIP_REPORT_V3; mb_report->reserved_1 = 0x00; mb_report->checksum = 0x00; mb_report->reserved_2 = 0x00; mb_report->num_group_records = htons(1); hdr_offset += sizeof(struct mcast_mb_report_v3); - group_record = - rte_pktmbuf_mtod_offset(pkt, struct mcast_group_record *, hdr_offset); + group_record = rte_pktmbuf_mtod_offset(pkt, struct mcast_group_record *, hdr_offset); if (action == MCAST_JOIN) - mb_report_len += - mcast_create_group_record_join(group_addr, src_addr, group_record); + mb_report_len += mcast_create_group_record_join(group_addr, src_addr, group_record); else - mb_report_len += - mcast_create_group_record_leave(group_addr, src_addr, group_record); + mb_report_len += mcast_create_group_record_leave(group_addr, src_addr, group_record); - uint16_t checksum = - mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); + uint16_t checksum = mcast_msg_checksum(MEMBERSHIP_REPORT_V3, mb_report, mb_report_len); if (checksum <= 0) { err("%s(%d), err checksum %d\n", __func__, checksum, port); return -EIO; @@ -329,8 +307,7 @@ static int mcast_membership_report_on_action(struct mtl_main_impl *impl, /* send packet to kernel for capturing */ if (mt_has_virtio_user(impl, port)) { struct mt_interface *inf = mt_if(impl, port); - rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf **)&report_pkt, - 1); + rte_eth_tx_burst(inf->virtio_port_id, 0, (struct rte_mbuf **)&report_pkt, 1); } #endif /* send membership report twice */ @@ -364,8 +341,7 @@ static void mcast_membership_report_cb(void *param) { for (int port = 0; port < num_ports; port++) { struct mt_mcast_impl *mcast = get_mcast(impl, port); - if (!mcast) - continue; + if (!mcast) continue; if (!mcast->has_external_query) { ret = mcast_membership_report_on_query(impl, port); if (ret < 0) { @@ -374,10 +350,8 @@ static void mcast_membership_report_cb(void *param) { } } - ret = rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, mcast_membership_report_cb, - impl); - if (ret < 0) - err("%s, set igmp alarm fail %d\n", __func__, ret); + ret = rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, mcast_membership_report_cb, impl); + if (ret < 0) err("%s, set igmp alarm fail %d\n", __func__, ret); } static int mcast_addr_pool_extend(struct mt_interface *inf) { @@ -394,10 +368,8 @@ static int mcast_addr_pool_extend(struct mt_interface *inf) { * The previous test guarantees that port->mc_addr_nb is a multiple * of MCAST_POOL_INC. */ - mc_list_size = - sizeof(struct rte_ether_addr) * (inf->mcast_nb + MT_MCAST_POOL_INC); - mc_list = - (struct rte_ether_addr *)realloc(inf->mcast_mac_lists, mc_list_size); + mc_list_size = sizeof(struct rte_ether_addr) * (inf->mcast_nb + MT_MCAST_POOL_INC); + mc_list = (struct rte_ether_addr *)realloc(inf->mcast_mac_lists, mc_list_size); if (mc_list == NULL) { return -ENOMEM; } @@ -409,14 +381,12 @@ static int mcast_addr_pool_extend(struct mt_interface *inf) { static int mcast_addr_pool_append(struct mt_interface *inf, struct rte_ether_addr *mc_addr) { - if (mcast_addr_pool_extend(inf) != 0) - return -1; + if (mcast_addr_pool_extend(inf) != 0) return -1; rte_ether_addr_copy(mc_addr, &inf->mcast_mac_lists[inf->mcast_nb - 1]); return 0; } -static void mcast_addr_pool_remove(struct mt_interface *inf, - uint32_t addr_idx) { +static void mcast_addr_pool_remove(struct mt_interface *inf, uint32_t addr_idx) { inf->mcast_nb--; if (addr_idx == inf->mcast_nb) { /* No need to recompose the set of multicast address. */ @@ -431,8 +401,7 @@ static void mcast_addr_pool_remove(struct mt_interface *inf, sizeof(struct rte_ether_addr) * (inf->mcast_nb - addr_idx)); } -static int mcast_inf_add_mac(struct mt_interface *inf, - struct rte_ether_addr *mcast_mac) { +static int mcast_inf_add_mac(struct mt_interface *inf, struct rte_ether_addr *mcast_mac) { uint16_t port_id = inf->port_id; uint32_t i; @@ -448,8 +417,7 @@ static int mcast_inf_add_mac(struct mt_interface *inf, mcast_addr_pool_append(inf, mcast_mac); if (inf->drv_info.flags & MT_DRV_F_USE_MC_ADDR_LIST) - return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, - inf->mcast_nb); + return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, inf->mcast_nb); else return rte_eth_dev_mac_addr_add(port_id, mcast_mac, 0); } @@ -463,8 +431,7 @@ static int mcast_inf_remove_mac(struct mt_interface *inf, * Search the pool of multicast MAC addresses for the removed address. */ for (i = 0; i < inf->mcast_nb; i++) { - if (rte_is_same_ether_addr(mcast_mac, &inf->mcast_mac_lists[i])) - break; + if (rte_is_same_ether_addr(mcast_mac, &inf->mcast_mac_lists[i])) break; } if (i == inf->mcast_nb) { return 0; @@ -472,15 +439,13 @@ static int mcast_inf_remove_mac(struct mt_interface *inf, mcast_addr_pool_remove(inf, i); if (inf->drv_info.flags & MT_DRV_F_USE_MC_ADDR_LIST) - return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, - inf->mcast_nb); + return rte_eth_dev_set_mc_addr_list(port_id, inf->mcast_mac_lists, inf->mcast_nb); else return rte_eth_dev_mac_addr_remove(port_id, mcast_mac); } /* 224.0.0.1 */ -static struct rte_ether_addr mcast_mac_all = { - {0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}}; +static struct rte_ether_addr mcast_mac_all = {{0x01, 0x00, 0x5e, 0x00, 0x00, 0x01}}; int mt_mcast_init(struct mtl_main_impl *impl) { int num_ports = mt_num_ports(impl); @@ -493,8 +458,7 @@ int mt_mcast_init(struct mtl_main_impl *impl) { } for (int i = 0; i < num_ports; i++) { - if (mt_drv_mcast_in_dp(impl, i)) - continue; + if (mt_drv_mcast_in_dp(impl, i)) continue; struct mt_mcast_impl *mcast = mt_rte_zmalloc_socket(sizeof(*mcast), socket); if (!mcast) { err("%s(%d), mcast malloc fail\n", __func__, i); @@ -517,8 +481,8 @@ int mt_mcast_init(struct mtl_main_impl *impl) { } if (has_mcast) { - int ret = rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, - mcast_membership_report_cb, impl); + int ret = + rte_eal_alarm_set(IGMP_JOIN_GROUP_PERIOD_US, mcast_membership_report_cb, impl); if (ret < 0) err("%s, set igmp alarm fail %d\n", __func__, ret); else @@ -561,8 +525,7 @@ int mt_mcast_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { struct mt_mcast_impl *mcast = get_mcast(impl, i); - if (!mcast) - continue; + if (!mcast) continue; if (!mt_drv_use_kernel_ctl(impl, i)) mcast_inf_remove_mac(mt_if(impl, i), &mcast_mac_all); @@ -581,8 +544,7 @@ int mt_mcast_uinit(struct mtl_main_impl *impl) { if (has_mcast) { int ret = rte_eal_alarm_cancel(mcast_membership_report_cb, impl); - if (ret < 0) - err("%s, alarm cancel fail %d\n", __func__, ret); + if (ret < 0) err("%s, alarm cancel fail %d\n", __func__, ret); } dbg("%s, succ\n", __func__); @@ -590,8 +552,8 @@ int mt_mcast_uinit(struct mtl_main_impl *impl) { } /* add a group address with/without source address to the group ip list */ -int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, - uint32_t source_addr, enum mtl_port port) { +int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, uint32_t source_addr, + enum mtl_port port) { struct mt_mcast_impl *mcast = get_mcast(impl, port); struct rte_ether_addr mcast_mac; struct mt_interface *inf = mt_if(impl, port); @@ -601,8 +563,7 @@ int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, return 0; } - if (mt_drv_mcast_in_dp(impl, port)) - return 0; + if (mt_drv_mcast_in_dp(impl, port)) return 0; if (mcast->group_num >= MT_MCAST_GROUP_MAX) { err("%s(%d), reach max multicast group number!\n", __func__, port); @@ -650,8 +611,7 @@ int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, struct mt_mcast_src_entry *src; TAILQ_FOREACH(src, &group->src_list, entries) { if (src->src_ip == source_addr) { - dbg("%s(%d), already has source ip in the source list\n", __func__, - port); + dbg("%s(%d), already has source ip in the source list\n", __func__, port); src->src_ref_cnt++; found = true; break; @@ -679,18 +639,17 @@ int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, * specified, then join it again with any source is not allowed. */ if (!found) { - int ret = mcast_membership_report_on_action(impl, port, group_addr, - source_addr, MCAST_JOIN); + int ret = mcast_membership_report_on_action(impl, port, group_addr, source_addr, + MCAST_JOIN); if (ret < 0) { err("%s(%d), send membership report fail\n", __func__, port); return ret; } - info("%s(%d), join group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3]); + info("%s(%d), join group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); if (source_addr != 0) { ip = (uint8_t *)&source_addr; - info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3]); + info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], + ip[3]); } } @@ -698,14 +657,13 @@ int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, } /* delete a group address with/without source address from the group ip list */ -int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, - uint32_t source_addr, enum mtl_port port) { +int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, uint32_t source_addr, + enum mtl_port port) { if (mt_user_no_multicast(impl)) { return 0; } - if (mt_drv_mcast_in_dp(impl, port)) - return 0; + if (mt_drv_mcast_in_dp(impl, port)) return 0; struct mt_mcast_impl *mcast = get_mcast(impl, port); int group_num = mcast->group_num; @@ -713,8 +671,7 @@ int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, uint8_t *ip = (uint8_t *)&group_addr; struct rte_ether_addr mcast_mac; - if (group_num == 0) - return 0; + if (group_num == 0) return 0; mt_pthread_mutex_lock(&mcast->group_mutex); /* find existing group */ @@ -776,18 +733,17 @@ int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, /* send leave report */ if (gdelete || sdelete) { - int ret = mcast_membership_report_on_action(impl, port, group_addr, - source_addr, MCAST_LEAVE); + int ret = mcast_membership_report_on_action(impl, port, group_addr, source_addr, + MCAST_LEAVE); if (ret < 0) { err("%s(%d), send leave report failed\n", __func__, port); return ret; } - info("%s(%d), leave group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3]); + info("%s(%d), leave group %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); if (source_addr != 0) { ip = (uint8_t *)&source_addr; - info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3]); + info("%s(%d), with source %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], + ip[3]); } } @@ -797,16 +753,14 @@ int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, int mt_mcast_l2_join(struct mtl_main_impl *impl, struct rte_ether_addr *addr, enum mtl_port port) { struct mt_interface *inf = mt_if(impl, port); - if (mt_drv_use_kernel_ctl(impl, port)) - return 0; + if (mt_drv_use_kernel_ctl(impl, port)) return 0; return mcast_inf_add_mac(inf, addr); } int mt_mcast_l2_leave(struct mtl_main_impl *impl, struct rte_ether_addr *addr, enum mtl_port port) { struct mt_interface *inf = mt_if(impl, port); - if (mt_drv_use_kernel_ctl(impl, port)) - return 0; + if (mt_drv_use_kernel_ctl(impl, port)) return 0; return mcast_inf_remove_mac(inf, addr); } @@ -827,8 +781,8 @@ int mt_mcast_restore(struct mtl_main_impl *impl, enum mtl_port port) { int mt_mcast_parse(struct mtl_main_impl *impl, struct mcast_mb_query_v3 *query, enum mtl_port port) { if (query->type != MEMBERSHIP_QUERY) { - err("%s(%d), invalid type %u, only allow igmp query packet\n", __func__, - port, query->type); + err("%s(%d), invalid type %u, only allow igmp query packet\n", __func__, port, + query->type); return -EIO; } @@ -836,8 +790,7 @@ int mt_mcast_parse(struct mtl_main_impl *impl, struct mcast_mb_query_v3 *query, query->checksum = 0; uint16_t checksum = mcast_msg_checksum(MEMBERSHIP_QUERY, query, 0); if (checksum != query_checksum) { - err("%s(%d), err checksum %d:%d\n", __func__, port, query_checksum, - checksum); + err("%s(%d), err checksum %d:%d\n", __func__, port, query_checksum, checksum); return -EIO; } diff --git a/lib/src/mt_mcast.h b/lib/src/mt_mcast.h index 5e709f02b..9241b8f88 100644 --- a/lib/src/mt_mcast.h +++ b/lib/src/mt_mcast.h @@ -69,10 +69,10 @@ struct mcast_mb_query_v3 { int mt_mcast_init(struct mtl_main_impl *impl); int mt_mcast_uinit(struct mtl_main_impl *impl); -int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, - uint32_t source_addr, enum mtl_port port); -int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, - uint32_t source_addr, enum mtl_port port); +int mt_mcast_join(struct mtl_main_impl *impl, uint32_t group_addr, uint32_t source_addr, + enum mtl_port port); +int mt_mcast_leave(struct mtl_main_impl *impl, uint32_t group_addr, uint32_t source_addr, + enum mtl_port port); int mt_mcast_l2_join(struct mtl_main_impl *impl, struct rte_ether_addr *addr, enum mtl_port port); int mt_mcast_l2_leave(struct mtl_main_impl *impl, struct rte_ether_addr *addr, diff --git a/lib/src/mt_mem.h b/lib/src/mt_mem.h index 517c53ff4..412ea51c2 100644 --- a/lib/src/mt_mem.h +++ b/lib/src/mt_mem.h @@ -10,16 +10,19 @@ #define MT_DPDK_LIB_NAME "MT_DPDK" -static inline void *mt_malloc(size_t sz) { return malloc(sz); } +static inline void *mt_malloc(size_t sz) { + return malloc(sz); +} static inline void *mt_zmalloc(size_t sz) { void *p = malloc(sz); - if (p) - memset(p, 0x0, sz); + if (p) memset(p, 0x0, sz); return p; } -static inline void mt_free(void *p) { free(p); } +static inline void mt_free(void *p) { + free(p); +} #ifdef MTL_HAS_ASAN int mt_asan_init(void); @@ -36,7 +39,9 @@ static inline void *mt_rte_zmalloc_socket(size_t sz, int socket) { return rte_zmalloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); } -static inline void mt_rte_free(void *p) { rte_free(p); } +static inline void mt_rte_free(void *p) { + rte_free(p); +} #endif #endif diff --git a/lib/src/mt_pcap.c b/lib/src/mt_pcap.c index 494525f21..0ce2f9226 100644 --- a/lib/src/mt_pcap.c +++ b/lib/src/mt_pcap.c @@ -22,8 +22,7 @@ int mt_pcap_close(struct mt_pcap *pcap) { return 0; } -struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, - int fd) { +struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, int fd) { int ret; struct mt_pcap *pcap = mt_zmalloc(sizeof(*pcap)); if (!pcap) { @@ -36,8 +35,8 @@ struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, char pool_name[ST_MAX_NAME_LEN]; snprintf(pool_name, sizeof(pool_name), "mt_pcap_p%di%d", port, fd); - pcap->mp = mt_mempool_create(impl, port, pool_name, 512, MT_MBUF_CACHE_SIZE, - 0, rte_pcapng_mbuf_size(pcap->max_len)); + pcap->mp = mt_mempool_create(impl, port, pool_name, 512, MT_MBUF_CACHE_SIZE, 0, + rte_pcapng_mbuf_size(pcap->max_len)); if (!pcap->mp) { err("%s(%d,%d), failed to create mempool\n", __func__, port, fd); mt_pcap_close(pcap); @@ -53,8 +52,7 @@ struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, #if RTE_VERSION >= RTE_VERSION_NUM(23, 3, 0, 0) /* add all port interfaces */ for (int i = 0; i < mt_num_ports(impl); i++) { - ret = rte_pcapng_add_interface(pcap->pcapng, mt_port_id(impl, i), NULL, - NULL, NULL); + ret = rte_pcapng_add_interface(pcap->pcapng, mt_port_id(impl, i), NULL, NULL, NULL); if (ret < 0) { warn("%s(%d), add interface fail %d on port %d\n", __func__, fd, ret, i); } @@ -66,8 +64,7 @@ struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, } uint16_t mt_pcap_dump(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_pcap *pcap, struct rte_mbuf **mbufs, - uint16_t nb) { + struct mt_pcap *pcap, struct rte_mbuf **mbufs, uint16_t nb) { struct rte_mbuf *pcapng_mbuf[nb]; int pcapng_mbuf_cnt = 0; uint16_t port_id = mt_port_id(impl, port); @@ -86,8 +83,7 @@ uint16_t mt_pcap_dump(struct mtl_main_impl *impl, enum mtl_port port, pcapng_mbuf[pcapng_mbuf_cnt++] = mc; } - ssize_t len = - rte_pcapng_write_packets(pcap->pcapng, pcapng_mbuf, pcapng_mbuf_cnt); + ssize_t len = rte_pcapng_write_packets(pcap->pcapng, pcapng_mbuf, pcapng_mbuf_cnt); if (len <= 0) { warn("%s(%d,%d), write packet fail\n", __func__, port, pcap->fd); } diff --git a/lib/src/mt_pcap.h b/lib/src/mt_pcap.h index 57e3e0c10..fb1fd8ae4 100644 --- a/lib/src/mt_pcap.h +++ b/lib/src/mt_pcap.h @@ -23,15 +23,13 @@ struct mt_pcap { }; /* note: fd will be be closed in mt_pcap_close if the open succ */ -struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, - int fd); +struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, int fd); int mt_pcap_close(struct mt_pcap *pcap); uint16_t mt_pcap_dump(struct mtl_main_impl *impl, enum mtl_port port, - struct mt_pcap *pcap, struct rte_mbuf **mbufs, - uint16_t nb); + struct mt_pcap *pcap, struct rte_mbuf **mbufs, uint16_t nb); #else -static inline struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, - enum mtl_port port, int fd) { +static inline struct mt_pcap *mt_pcap_open(struct mtl_main_impl *impl, enum mtl_port port, + int fd) { MTL_MAY_UNUSED(impl); err("%s(%d,%d), no pcap support for this build\n", __func__, port, fd); return NULL; @@ -42,9 +40,9 @@ static inline int mt_pcap_close(struct mt_pcap *pcap) { return -ENOTSUP; } -static inline uint16_t mt_pcap_dump(struct mtl_main_impl *impl, - enum mtl_port port, struct mt_pcap *pcap, - struct rte_mbuf **mbufs, uint16_t nb) { +static inline uint16_t mt_pcap_dump(struct mtl_main_impl *impl, enum mtl_port port, + struct mt_pcap *pcap, struct rte_mbuf **mbufs, + uint16_t nb) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(pcap); diff --git a/lib/src/mt_platform.h b/lib/src/mt_platform.h index 017b3167d..c8edcbe85 100644 --- a/lib/src/mt_platform.h +++ b/lib/src/mt_platform.h @@ -98,13 +98,11 @@ static inline int mt_pthread_cond_init(pthread_cond_t *cond, return pthread_cond_init(cond, cond_attr); } -static inline int mt_pthread_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex) { +static inline int mt_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } -static inline int mt_pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, +static inline int mt_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *time) { return pthread_cond_timedwait(cond, mutex, time); } @@ -149,7 +147,7 @@ static inline bool mt_socket_match(int cpu_socket, int dev_socket) { #ifdef WINDOWSENV MTL_MAY_UNUSED(cpu_socket); MTL_MAY_UNUSED(dev_socket); - return true; // windows cpu socket always 0 + return true; // windows cpu socket always 0 #else return (cpu_socket == dev_socket); #endif diff --git a/lib/src/mt_ptp.c b/lib/src/mt_ptp.c index 7cc71901c..002bcfa10 100644 --- a/lib/src/mt_ptp.c +++ b/lib/src/mt_ptp.c @@ -31,13 +31,11 @@ ((1 == ntohl(1)) ? (x) : ((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32)) // clang-format on -typedef BOOL(WINAPI *PGSTAP)(PDWORD64 lpTimeAdjustment, - PDWORD64 lpTimeIncrement, +typedef BOOL(WINAPI *PGSTAP)(PDWORD64 lpTimeAdjustment, PDWORD64 lpTimeIncrement, PBOOL lpTimeAdjustmentDisabled); static PGSTAP win_get_systime_adj; -typedef BOOL(WINAPI *PSSTAP)(DWORD64 dwTimeAdjustment, - BOOL bTimeAdjustmentDisabled); +typedef BOOL(WINAPI *PSSTAP)(DWORD64 dwTimeAdjustment, BOOL bTimeAdjustmentDisabled); static PSSTAP win_set_systime_adj; #endif @@ -57,8 +55,7 @@ static inline char *ptp_mode_str(enum mt_ptp_l_mode mode) { } static inline uint64_t ptp_net_tmstamp_to_ns(struct mt_ptp_tmstamp *ts) { - uint64_t sec = - (uint64_t)ntohl(ts->sec_lsb) + ((uint64_t)ntohs(ts->sec_msb) << 32); + uint64_t sec = (uint64_t)ntohl(ts->sec_lsb) + ((uint64_t)ntohs(ts->sec_msb) << 32); return (sec * NS_PER_S) + ntohl(ts->ns); } @@ -81,8 +78,7 @@ static inline uint64_t ptp_no_timesync_time(struct mt_ptp_impl *ptp) { return tsc + ptp->no_timesync_delta; } -static inline void ptp_no_timesync_adjust(struct mt_ptp_impl *ptp, - int64_t delta) { +static inline void ptp_no_timesync_adjust(struct mt_ptp_impl *ptp, int64_t delta) { ptp->no_timesync_delta += delta; } @@ -92,8 +88,7 @@ static inline uint64_t ptp_timesync_read_time_no_lock(struct mt_ptp_impl *ptp) { int ret; struct timespec spec; - if (ptp->no_timesync) - return ptp_no_timesync_time(ptp); + if (ptp->no_timesync) return ptp_no_timesync_time(ptp); memset(&spec, 0, sizeof(spec)); @@ -112,8 +107,7 @@ static inline uint64_t ptp_timesync_read_time(struct mt_ptp_impl *ptp) { int ret; struct timespec spec; - if (ptp->no_timesync) - return ptp_no_timesync_time(ptp); + if (ptp->no_timesync) return ptp_no_timesync_time(ptp); memset(&spec, 0, sizeof(spec)); @@ -128,39 +122,39 @@ static inline uint64_t ptp_timesync_read_time(struct mt_ptp_impl *ptp) { return mt_timespec_to_ns(&spec); } -static inline double pi_sample(struct mt_pi_servo *s, double offset, - double local_ts, enum servo_state *state) { +static inline double pi_sample(struct mt_pi_servo *s, double offset, double local_ts, + enum servo_state *state) { double ppb = 0.0; switch (s->count) { - case 0: - s->offset[0] = offset; - s->local[0] = local_ts; - *state = UNLOCKED; - s->count = 1; - break; - case 1: - s->offset[1] = offset; - s->local[1] = local_ts; - *state = UNLOCKED; - s->count = 2; - break; - case 2: - s->drift += (s->offset[1] - s->offset[0]) / (s->local[1] - s->local[0]); - *state = UNLOCKED; - s->count = 3; - break; - case 3: - *state = JUMP; + case 0: + s->offset[0] = offset; + s->local[0] = local_ts; + *state = UNLOCKED; + s->count = 1; + break; + case 1: + s->offset[1] = offset; + s->local[1] = local_ts; + *state = UNLOCKED; + s->count = 2; + break; + case 2: + s->drift += (s->offset[1] - s->offset[0]) / (s->local[1] - s->local[0]); + *state = UNLOCKED; + s->count = 3; + break; + case 3: + *state = JUMP; #ifndef WINDOWSENV /* windows always adj offset since adj freq not ready */ - s->count = 4; + s->count = 4; #endif - break; - case 4: - s->drift += 0.7 * offset; - ppb = 0.3 * offset + s->drift; - *state = LOCKED; - break; + break; + case 4: + s->drift += 0.7 * offset; + ppb = 0.3 * offset + s->drift; + *state = LOCKED; + break; } return ppb; @@ -219,8 +213,8 @@ static void ptp_adj_system_clock_freq(struct mt_ptp_impl *ptp, double ppb) { if (ptp->phc2sys.realtime_nominal_tick) { adjfreq.modes |= ADJ_TICK; - adjfreq.tick = round(ppb / 1e3 / ptp->phc2sys.realtime_hz) + - ptp->phc2sys.realtime_nominal_tick; + adjfreq.tick = + round(ppb / 1e3 / ptp->phc2sys.realtime_hz) + ptp->phc2sys.realtime_nominal_tick; ppb -= 1e3 * ptp->phc2sys.realtime_hz * (adjfreq.tick - ptp->phc2sys.realtime_nominal_tick); } @@ -283,32 +277,29 @@ static void phc2sys_adjust(struct mt_ptp_impl *ptp) { dbg("%s(%d), state %d\n", __func__, ptp->port, state); switch (state) { - case UNLOCKED: - break; - case JUMP: - ptp_adj_system_clock_time(ptp, -offset); - dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 - " adjust time.\n", - __func__, ptp->port_id, offset, shortest_delay); - break; - case LOCKED: - ptp_adj_system_clock_freq(ptp, -ppb); - dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 - " adjust freq %lf ppb.\n", - __func__, ptp->port_id, offset, shortest_delay, ppb); - break; + case UNLOCKED: + break; + case JUMP: + ptp_adj_system_clock_time(ptp, -offset); + dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 " adjust time.\n", + __func__, ptp->port_id, offset, shortest_delay); + break; + case LOCKED: + ptp_adj_system_clock_freq(ptp, -ppb); + dbg("%s(%d), CLOCK_REALTIME offset %" PRId64 ", delay %" PRIu64 + " adjust freq %lf ppb.\n", + __func__, ptp->port_id, offset, shortest_delay, ppb); + break; } - ptp->phc2sys.stat_delta_max = - RTE_MAX(labs(offset), ptp->phc2sys.stat_delta_max); + ptp->phc2sys.stat_delta_max = RTE_MAX(labs(offset), ptp->phc2sys.stat_delta_max); if (!ptp->phc2sys.locked) { /* * Be considered as synchronized while the max delta is continuously below * 300ns. */ - if (ptp->phc2sys.stat_delta_max < 300 && - ptp->phc2sys.stat_delta_max > 0) { + if (ptp->phc2sys.stat_delta_max < 300 && ptp->phc2sys.stat_delta_max > 0) { if (ptp->phc2sys.stat_sync_keep > 100) ptp->phc2sys.locked = true; else @@ -318,20 +309,17 @@ static void phc2sys_adjust(struct mt_ptp_impl *ptp) { } } } else { - err("%s(%d), PHC or system time retrieving failed.\n", __func__, - ptp->port_id); + err("%s(%d), PHC or system time retrieving failed.\n", __func__, ptp->port_id); } } -static inline int ptp_timesync_read_tx_time(struct mt_ptp_impl *ptp, - uint64_t *tai) { +static inline int ptp_timesync_read_tx_time(struct mt_ptp_impl *ptp, uint64_t *tai) { uint16_t port_id = ptp->port_id; int ret; struct timespec spec; if (ptp->no_timesync) { - if (tai) - *tai = ptp_no_timesync_time(ptp); + if (tai) *tai = ptp_no_timesync_time(ptp); return 0; } @@ -341,23 +329,20 @@ static inline int ptp_timesync_read_tx_time(struct mt_ptp_impl *ptp, ret = rte_eth_timesync_read_tx_timestamp(port_id, &spec); ptp_timesync_unlock(ptp); - if (ret < 0) - dbg("%s(%d), err %d\n", __func__, port, ret); - if (tai) - *tai = mt_timespec_to_ns(&spec); + if (ret < 0) dbg("%s(%d), err %d\n", __func__, port, ret); + if (tai) *tai = mt_timespec_to_ns(&spec); return ret; } -static inline int ptp_timesync_read_rx_time(struct mt_ptp_impl *ptp, - uint32_t flags, uint64_t *tai) { +static inline int ptp_timesync_read_rx_time(struct mt_ptp_impl *ptp, uint32_t flags, + uint64_t *tai) { enum mtl_port port = ptp->port; uint16_t port_id = ptp->port_id; int ret; struct timespec spec; if (ptp->no_timesync) { - if (tai) - *tai = ptp_no_timesync_time(ptp); + if (tai) *tai = ptp_no_timesync_time(ptp); return 0; } @@ -367,15 +352,12 @@ static inline int ptp_timesync_read_rx_time(struct mt_ptp_impl *ptp, ret = rte_eth_timesync_read_rx_timestamp(port_id, &spec, flags); ptp_timesync_unlock(ptp); - if (ret < 0) - err("%s(%d), err %d\n", __func__, port, ret); - if (tai) - *tai = mt_timespec_to_ns(&spec); + if (ret < 0) err("%s(%d), err %d\n", __func__, port, ret); + if (tai) *tai = mt_timespec_to_ns(&spec); return ret; } -static inline int ptp_timesync_adjust_time(struct mt_ptp_impl *ptp, - int64_t delta) { +static inline int ptp_timesync_adjust_time(struct mt_ptp_impl *ptp, int64_t delta) { int ret; if (ptp->no_timesync) { @@ -404,8 +386,7 @@ static inline int ptp_timesync_adjust_freq(struct mt_ptp_impl *ptp, int64_t ppm, ret = rte_eth_timesync_adjust_freq(ptp->port_id, ppm); ptp_timesync_unlock(ptp); - if (ret) - ptp_timesync_adjust_time(ptp, delta); + if (ret) ptp_timesync_adjust_time(ptp, delta); return ret; } @@ -425,14 +406,13 @@ static uint64_t ptp_from_eth(struct mtl_main_impl *impl, enum mtl_port port) { static void ptp_print_port_id(enum mtl_port port, struct mt_ptp_port_id *pid) { uint8_t *id = &pid->clock_identity.id[0]; - info("mt_ptp_port_id(%d), port_number: %04x, clk_id: " - "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - port, pid->port_number, id[0], id[1], id[2], id[3], id[4], id[5], id[6], - id[7]); + info( + "mt_ptp_port_id(%d), port_number: %04x, clk_id: " + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + port, pid->port_number, id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7]); } -static inline bool ptp_port_id_equal(struct mt_ptp_port_id *s, - struct mt_ptp_port_id *t) { +static inline bool ptp_port_id_equal(struct mt_ptp_port_id *s, struct mt_ptp_port_id *t) { if (!memcmp(s, t, sizeof(struct mt_ptp_port_id))) return true; else @@ -468,25 +448,19 @@ static void ptp_update_coefficient(struct mt_ptp_impl *ptp, int64_t error) { ptp->integral += (error + ptp->prev_error) / 2; ptp->prev_error = error; double offset = ptp->kp * error + ptp->ki * ptp->integral; - if (ptp->t2_mode == MT_PTP_L4) - offset /= 4; /* where sync interval is 0.25s for l4 */ + if (ptp->t2_mode == MT_PTP_L4) offset /= 4; /* where sync interval is 0.25s for l4 */ ptp->coefficient += RTE_MIN(RTE_MAX(offset, -1e-7), 1e-7); - dbg("%s(%d), error %" PRId64 ", offset %.15lf\n", __func__, ptp->port, error, - offset); + dbg("%s(%d), error %" PRId64 ", offset %.15lf\n", __func__, ptp->port, error, offset); } static void ptp_calculate_coefficient(struct mt_ptp_impl *ptp, int64_t delta) { - if (delta > 1000 * 1000) - return; + if (delta > 1000 * 1000) return; uint64_t ts_s = ptp_get_raw_time(ptp); uint64_t ts_m = ts_s + delta; - double coefficient = - (double)(ts_m - ptp->last_sync_ts) / (ts_s - ptp->last_sync_ts); + double coefficient = (double)(ts_m - ptp->last_sync_ts) / (ts_s - ptp->last_sync_ts); ptp->coefficient_result_sum += coefficient; - ptp->coefficient_result_min = - RTE_MIN(coefficient, ptp->coefficient_result_min); - ptp->coefficient_result_max = - RTE_MAX(coefficient, ptp->coefficient_result_max); + ptp->coefficient_result_min = RTE_MIN(coefficient, ptp->coefficient_result_min); + ptp->coefficient_result_max = RTE_MAX(coefficient, ptp->coefficient_result_max); ptp->coefficient_result_cnt++; if (ptp->coefficient - 1.0 < 1e-15) /* store first result */ ptp->coefficient = coefficient; @@ -498,12 +472,11 @@ static void ptp_calculate_coefficient(struct mt_ptp_impl *ptp, int64_t delta) { ptp_coefficient_result_reset(ptp); } ptp->last_sync_ts = ts_m; - dbg("%s(%d), delta %" PRId64 ", co %.15lf, ptp %" PRIu64 "\n", __func__, - ptp->port, delta, ptp->coefficient, ts_m); + dbg("%s(%d), delta %" PRId64 ", co %.15lf, ptp %" PRIu64 "\n", __func__, ptp->port, + delta, ptp->coefficient, ts_m); } -static void ptp_adjust_delta(struct mt_ptp_impl *ptp, int64_t delta, - bool error_correct) { +static void ptp_adjust_delta(struct mt_ptp_impl *ptp, int64_t delta, bool error_correct) { MTL_MAY_UNUSED(error_correct); #ifdef MTL_HAS_DPDK_TIMESYNC_ADJUST_FREQ @@ -515,47 +488,44 @@ static void ptp_adjust_delta(struct mt_ptp_impl *ptp, int64_t delta, ppb = pi_sample(&ptp->servo, -1 * delta, ptp->t2, &state); switch (state) { - case UNLOCKED: - break; - case JUMP: - if (!ptp_timesync_adjust_time(ptp, delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 - " adjust time.\n", - __func__, ptp->port_id, delta, ptp->path_delay); - else - err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); - break; - case LOCKED: - if (!ptp_timesync_adjust_freq(ptp, -1 * (long)(ppb * 65.536), delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 - " adjust freq.\n", - __func__, ptp->port_id, delta, ptp->path_delay); - else - err("%s(%d), PHC freqency adjust failed.\n", __func__, ptp->port_id); - break; + case UNLOCKED: + break; + case JUMP: + if (!ptp_timesync_adjust_time(ptp, delta)) + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 + " adjust time.\n", + __func__, ptp->port_id, delta, ptp->path_delay); + else + err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); + break; + case LOCKED: + if (!ptp_timesync_adjust_freq(ptp, -1 * (long)(ppb * 65.536), delta)) + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 + " adjust freq.\n", + __func__, ptp->port_id, delta, ptp->path_delay); + else + err("%s(%d), PHC freqency adjust failed.\n", __func__, ptp->port_id); + break; } phc2sys_adjust(ptp); } } else { if (!ptp_timesync_adjust_time(ptp, delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 - " adjust time.\n", + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 " adjust time.\n", __func__, ptp->port_id, delta, ptp->path_delay); else err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); } #else if (!ptp_timesync_adjust_time(ptp, delta)) - dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 - " adjust time.\n", + dbg("%s(%d), master offset: %" PRId64 " path delay: %" PRId64 " adjust time.\n", __func__, ptp->port_id, delta, ptp->path_delay); else err("%s(%d), PHC time adjust failed.\n", __func__, ptp->port_id); - if (ptp->phc2sys_active) - phc2sys_adjust(ptp); + if (ptp->phc2sys_active) phc2sys_adjust(ptp); #endif - dbg("%s(%d), delta %" PRId64 ", ptp %" PRIu64 "\n", __func__, ptp->port, - delta, ptp_get_raw_time(ptp)); + dbg("%s(%d), delta %" PRId64 ", ptp %" PRIu64 "\n", __func__, ptp->port, delta, + ptp_get_raw_time(ptp)); ptp->ptp_delta += delta; if (5 == ptp->delta_result_cnt) /* clear the first 5 results */ @@ -595,8 +565,7 @@ static void ptp_delay_req_read_tx_time_handler(void *param) { if (ret >= 0) { ptp->t3 = tx_ns; } else { - if (!ptp->t4) - rte_eal_alarm_set(5, ptp_delay_req_read_tx_time_handler, ptp); + if (!ptp->t4) rte_eal_alarm_set(5, ptp_delay_req_read_tx_time_handler, ptp); } } @@ -638,8 +607,7 @@ static int ptp_sync_expect_result(struct mt_ptp_impl *ptp) { ptp_calculate_coefficient(ptp, ptp->expect_result_avg); } } - if (ptp->expect_result_avg) - ptp_adjust_delta(ptp, ptp->expect_result_avg, true); + if (ptp->expect_result_avg) ptp_adjust_delta(ptp, ptp->expect_result_avg, true); return 0; } @@ -651,8 +619,7 @@ static void ptp_monitor_handler(void *param) { ptp_sync_expect_result(ptp); if (expect_result_period_us) { - dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, - expect_result_period_us); + dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, expect_result_period_us); rte_eal_alarm_set(expect_result_period_us, ptp_monitor_handler, ptp); } } @@ -667,8 +634,7 @@ static void ptp_sync_timeout_handler(void *param) { ptp_sync_expect_result(ptp); if (expect_result_period_us) { - dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, - expect_result_period_us); + dbg("%s(%d), next timer %" PRIu64 "\n", __func__, ptp->port, expect_result_period_us); rte_eal_alarm_set(expect_result_period_us, ptp_monitor_handler, ptp); } } @@ -678,10 +644,10 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { int64_t t2_t1_delta = ((int64_t)ptp->t2 - ptp->t1); int64_t t4_t3_delta = ((int64_t)ptp->t4 - ptp->t3); - dbg("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 "\n", - __func__, ptp->port, ptp->t1, ptp->t2, ptp->t3, ptp->t4); - dbg("%s(%d), t2-t1 delta %" PRId64 " t4-t3 delta %" PRIu64 "\n", __func__, - ptp->port, t2_t1_delta, t4_t3_delta); + dbg("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 "\n", __func__, + ptp->port, ptp->t1, ptp->t2, ptp->t3, ptp->t4); + dbg("%s(%d), t2-t1 delta %" PRId64 " t4-t3 delta %" PRIu64 "\n", __func__, ptp->port, + t2_t1_delta, t4_t3_delta); if (ptp->calibrate_t2_t3) { /* max 1us delta */ int32_t max_diff = 1000; @@ -690,8 +656,7 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { t2_t1_delta > (ptp->expect_t2_t1_delta_avg + max_diff)) { ptp->t2_t1_delta_continuous_err++; if (ptp->t2_t1_delta_continuous_err > 20) { - err("%s(%d), t2_t1_delta %" PRId64 - ", reset as too many continuous errors\n", + err("%s(%d), t2_t1_delta %" PRId64 ", reset as too many continuous errors\n", __func__, ptp->port, t2_t1_delta); } t2_t1_delta = ptp->expect_t2_t1_delta_avg; @@ -712,8 +677,7 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { t4_t3_delta > (ptp->expect_t4_t3_delta_avg + max_diff)) { ptp->t4_t3_delta_continuous_err++; if (ptp->t4_t3_delta_continuous_err > 20) { - err("%s(%d), t4_t3_delta %" PRId64 - ", reset as too many continuous errors\n", + err("%s(%d), t4_t3_delta %" PRId64 ", reset as too many continuous errors\n", __func__, ptp->port, t4_t3_delta); } t4_t3_delta = ptp->expect_t4_t3_delta_avg; @@ -744,18 +708,15 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { rte_eal_alarm_cancel(ptp_sync_timeout_handler, ptp); rte_eal_alarm_cancel(ptp_monitor_handler, ptp); if (ptp->delta_result_cnt) { - expect_delta = - abs(ptp->expect_result_avg) * (RTE_MIN(ptp->delta_result_err + 2, 5)); + expect_delta = abs(ptp->expect_result_avg) * (RTE_MIN(ptp->delta_result_err + 2, 5)); if (!expect_delta) { expect_delta = ptp->delta_result_sum / ptp->delta_result_cnt * 2; expect_delta = RTE_MAX(expect_delta, 100 * 1000); /* min 100us */ } if (abs_delta > expect_delta) { #if MT_PTP_PRINT_ERR_RESULT - err("%s(%d), error abs_delta %" PRIu64 "\n", __func__, ptp->port, - abs_delta); - err("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 - "\n", + err("%s(%d), error abs_delta %" PRIu64 "\n", __func__, ptp->port, abs_delta); + err("%s(%d), t1 %" PRIu64 " t2 %" PRIu64 " t3 %" PRIu64 " t4 %" PRIu64 "\n", __func__, ptp->port, ptp->t1, ptp->t2, ptp->t3, ptp->t4); #endif ptp_t_result_clear(ptp); @@ -763,14 +724,12 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { ptp->delta_result_err++; ptp->stat_result_err++; if (ptp->delta_result_err > 10) { - dbg("%s(%d), reset the result as too many errors\n", __func__, - ptp->port); + dbg("%s(%d), reset the result as too many errors\n", __func__, ptp->port); ptp_result_reset(ptp); } ptp_sync_expect_result(ptp); #ifdef MTL_HAS_DPDK_TIMESYNC_ADJUST_FREQ - if (!ptp->phc2sys_active) - return -EIO; + if (!ptp->phc2sys_active) return -EIO; #else return -EIO; #endif @@ -782,13 +741,10 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { int64_t correct_delta = ((int64_t)ptp->t4 - ptp_correct_ts(ptp, ptp->t3)) - ((int64_t)ptp_correct_ts(ptp, ptp->t2) - ptp->t1); correct_delta /= 2; - dbg("%s(%d), correct_delta %" PRId64 "\n", __func__, ptp->port, - correct_delta); + dbg("%s(%d), correct_delta %" PRId64 "\n", __func__, ptp->port, correct_delta); /* update correct delta and path delay result */ - ptp->stat_correct_delta_min = - RTE_MIN(correct_delta, ptp->stat_correct_delta_min); - ptp->stat_correct_delta_max = - RTE_MAX(correct_delta, ptp->stat_correct_delta_max); + ptp->stat_correct_delta_min = RTE_MIN(correct_delta, ptp->stat_correct_delta_min); + ptp->stat_correct_delta_max = RTE_MAX(correct_delta, ptp->stat_correct_delta_max); ptp->stat_correct_delta_cnt++; ptp->stat_correct_delta_sum += labs(correct_delta); ptp->stat_path_delay_min = RTE_MIN(path_delay, ptp->stat_path_delay_min); @@ -830,8 +786,7 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { ptp->expect_t4_t3_delta_sum += t4_t3_delta; ptp->expect_result_sum += delta; if (ptp->expect_result_cnt >= 10) { - ptp->expect_result_avg = - ptp->expect_result_sum / ptp->expect_result_cnt; + ptp->expect_result_avg = ptp->expect_result_sum / ptp->expect_result_cnt; ptp->expect_correct_result_avg = ptp->expect_correct_result_sum / ptp->expect_result_cnt; ptp->expect_t2_t1_delta_avg = @@ -844,9 +799,8 @@ static int ptp_parse_result(struct mt_ptp_impl *ptp) { dbg("%s(%d), expect result avg %d(correct: %d), t2_t1_delta %d, " "t4_t3_delta %d, " "period %fs\n", - __func__, ptp->port, ptp->expect_result_avg, - ptp->expect_correct_result_avg, ptp->expect_t2_t1_delta_avg, - ptp->expect_t4_t3_delta_avg, + __func__, ptp->port, ptp->expect_result_avg, ptp->expect_correct_result_avg, + ptp->expect_t2_t1_delta_avg, ptp->expect_t4_t3_delta_avg, (float)ptp->expect_result_period_ns / NS_PER_S); ptp_expect_result_clear(ptp); } @@ -864,8 +818,7 @@ static void ptp_delay_req_task(struct mt_ptp_impl *ptp) { struct mt_ptp_sync_msg *msg; uint64_t tx_ns = 0; - if (ptp->t3) - return; /* t3 already sent */ + if (ptp->t3) return; /* t3 already sent */ struct rte_mbuf *m = rte_pktmbuf_alloc(ptp->mbuf_pool); if (!m) { @@ -972,8 +925,8 @@ static void ptp_delay_req_task(struct mt_ptp_impl *ptp) { uint64_t delta = ptp_ns - tx_ns; #define TX_MAX_DELTA (1 * 1000 * 1000) /* 1ms */ if (unlikely(delta > TX_MAX_DELTA)) { - err("%s(%d), tx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, - tx_ns, delta); + err("%s(%d), tx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, tx_ns, + delta); ptp->stat_tx_sync_err++; } #endif @@ -982,9 +935,8 @@ static void ptp_delay_req_task(struct mt_ptp_impl *ptp) { #else ptp->t3 = ptp_get_raw_time(ptp); #endif - dbg("%s(%d), t3 %" PRIu64 ", seq %d, max_retry %d, ptp %" PRIu64 "\n", - __func__, port, ptp->t3, ptp->t3_sequence_id, max_retry, - ptp_get_raw_time(ptp)); + dbg("%s(%d), t3 %" PRIu64 ", seq %d, max_retry %d, ptp %" PRIu64 "\n", __func__, port, + ptp->t3, ptp->t3_sequence_id, max_retry, ptp_get_raw_time(ptp)); MT_USDT_PTP_MSG(ptp->port, 3, ptp->t3); /* all time get */ @@ -1001,9 +953,8 @@ static void ptp_delay_req_handler(void *param) { } #endif -static int ptp_parse_sync(struct mt_ptp_impl *ptp, struct mt_ptp_sync_msg *msg, - bool vlan, enum mt_ptp_l_mode mode, - uint16_t timesync) { +static int ptp_parse_sync(struct mt_ptp_impl *ptp, struct mt_ptp_sync_msg *msg, bool vlan, + enum mt_ptp_l_mode mode, uint16_t timesync) { uint64_t rx_ns = 0; #define RX_MAX_DELTA (1 * 1000 * 1000) /* 1ms */ @@ -1011,8 +962,7 @@ static int ptp_parse_sync(struct mt_ptp_impl *ptp, struct mt_ptp_sync_msg *msg, uint64_t monitor_period_us = ptp->expect_result_period_ns / 1000 / 2; if (monitor_period_us) { - monitor_period_us = - RTE_MAX(monitor_period_us, 100 * 1000 * 1000); /* min 100ms */ + monitor_period_us = RTE_MAX(monitor_period_us, 100 * 1000 * 1000); /* min 100ms */ if (ptp->t2) { /* already has a pending t2 */ ptp_expect_result_clear(ptp); ptp_t_result_clear(ptp); @@ -1035,8 +985,8 @@ static int ptp_parse_sync(struct mt_ptp_impl *ptp, struct mt_ptp_sync_msg *msg, ptp_ns = ptp_timesync_read_time(ptp); delta = ptp_ns - rx_ns; if (unlikely(delta > RX_MAX_DELTA)) { - err("%s(%d), rx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, - rx_ns, delta); + err("%s(%d), rx_ns %" PRIu64 ", delta %" PRIu64 "\n", __func__, ptp->port, rx_ns, + delta); ptp->stat_rx_sync_err++; } #endif @@ -1049,8 +999,8 @@ static int ptp_parse_sync(struct mt_ptp_impl *ptp, struct mt_ptp_sync_msg *msg, ptp->t2_sequence_id = msg->hdr.sequence_id; ptp->t2_vlan = vlan; ptp->t2_mode = mode; - dbg("%s(%d), t2 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, - ptp->t2, ptp->t2_sequence_id, ptp_get_raw_time(ptp)); + dbg("%s(%d), t2 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, ptp->t2, + ptp->t2_sequence_id, ptp_get_raw_time(ptp)); MT_USDT_PTP_MSG(ptp->port, 2, ptp->t2); return 0; @@ -1059,8 +1009,8 @@ static int ptp_parse_sync(struct mt_ptp_impl *ptp, struct mt_ptp_sync_msg *msg, static int ptp_parse_follow_up(struct mt_ptp_impl *ptp, struct mt_ptp_follow_up_msg *msg) { if (msg->hdr.sequence_id != ptp->t2_sequence_id) { - dbg("%s(%d), error sequence id %d %d\n", __func__, ptp->port, - msg->hdr.sequence_id, ptp->t2_sequence_id); + dbg("%s(%d), error sequence id %d %d\n", __func__, ptp->port, msg->hdr.sequence_id, + ptp->t2_sequence_id); return -EINVAL; } ptp->t1 = ptp_net_tmstamp_to_ns(&msg->precise_origin_timestamp) + @@ -1080,10 +1030,8 @@ static int ptp_parse_follow_up(struct mt_ptp_impl *ptp, return 0; } -static int ptp_parse_announce(struct mt_ptp_impl *ptp, - struct mt_ptp_announce_msg *msg, - enum mt_ptp_l_mode mode, - struct mt_ipv4_udp *ipv4_hdr) { +static int ptp_parse_announce(struct mt_ptp_impl *ptp, struct mt_ptp_announce_msg *msg, + enum mt_ptp_l_mode mode, struct mt_ipv4_udp *ipv4_hdr) { enum mtl_port port = ptp->port; if (!ptp->master_initialized) { @@ -1091,21 +1039,19 @@ static int ptp_parse_announce(struct mt_ptp_impl *ptp, ptp->master_utc_offset = ntohs(msg->current_utc_offset); rte_memcpy(&ptp->master_port_id, &msg->hdr.source_port_identity, sizeof(ptp->master_port_id)); - rte_memcpy(&ptp->master_addr.addr_bytes[0], - &ptp->master_port_id.clock_identity.id[0], 3); - rte_memcpy(&ptp->master_addr.addr_bytes[3], - &ptp->master_port_id.clock_identity.id[5], 3); - info("%s(%d), master initialized, mode %s utc_offset %d domain_number %d\n", - __func__, port, ptp_mode_str(mode), ptp->master_utc_offset, - msg->hdr.domain_number); + rte_memcpy(&ptp->master_addr.addr_bytes[0], &ptp->master_port_id.clock_identity.id[0], + 3); + rte_memcpy(&ptp->master_addr.addr_bytes[3], &ptp->master_port_id.clock_identity.id[5], + 3); + info("%s(%d), master initialized, mode %s utc_offset %d domain_number %d\n", __func__, + port, ptp_mode_str(mode), ptp->master_utc_offset, msg->hdr.domain_number); ptp_print_port_id(port, &ptp->master_port_id); if (mode == MT_PTP_L4) { struct mt_ipv4_udp *dst_udp = &ptp->dst_udp; rte_memcpy(dst_udp, ipv4_hdr, sizeof(*dst_udp)); rte_memcpy(&dst_udp->ip.src_addr, &ptp->sip_addr[0], MTL_IP_ADDR_LEN); - rte_memcpy(&dst_udp->ip.dst_addr, &ptp->mcast_group_addr[0], - MTL_IP_ADDR_LEN); + rte_memcpy(&dst_udp->ip.dst_addr, &ptp->mcast_group_addr[0], MTL_IP_ADDR_LEN); dst_udp->ip.total_length = htons(sizeof(struct mt_ipv4_udp) + sizeof(struct mt_ptp_sync_msg)); dst_udp->ip.hdr_checksum = 0; @@ -1145,8 +1091,8 @@ static int ptp_parse_delay_resp(struct mt_ptp_impl *ptp, } ptp->t4 = ptp_net_tmstamp_to_ns(&msg->receive_timestamp) - (be64toh(msg->hdr.correction_field) >> 16); - dbg("%s(%d), t4 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, - ptp->t4, ptp->t3_sequence_id, ptp_get_raw_time(ptp)); + dbg("%s(%d), t4 %" PRIu64 ", seq %d, ptp %" PRIu64 "\n", __func__, ptp->port, ptp->t4, + ptp->t3_sequence_id, ptp_get_raw_time(ptp)); MT_USDT_PTP_MSG(ptp->port, 4, ptp->t4); /* all time get */ @@ -1175,12 +1121,10 @@ static void ptp_stat_clear(struct mt_ptp_impl *ptp) { ptp->stat_result_err = 0; ptp->stat_sync_timeout_err = 0; ptp->stat_sync_cnt = 0; - if (ptp->phc2sys_active) - ptp->phc2sys.stat_delta_max = 0; + if (ptp->phc2sys_active) ptp->phc2sys.stat_delta_max = 0; } -static void ptp_sync_from_user(struct mtl_main_impl *impl, - struct mt_ptp_impl *ptp) { +static void ptp_sync_from_user(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp) { enum mtl_port port = ptp->port; uint64_t target_ns = mt_get_ptp_time(impl, port); uint64_t raw_ns = ptp_get_raw_time(ptp); @@ -1189,17 +1133,15 @@ static void ptp_sync_from_user(struct mtl_main_impl *impl, uint64_t expect_abs_delta = abs(ptp->expect_result_avg) * 2; if (expect_abs_delta) { - if (abs_delta > expect_abs_delta) - delta = ptp->expect_result_avg; + if (abs_delta > expect_abs_delta) delta = ptp->expect_result_avg; } else { if (abs_delta < 10000) { ptp->expect_result_sum += delta; ptp->expect_result_cnt++; if (ptp->expect_result_cnt > 1000) { - ptp->expect_result_avg = - ptp->expect_result_sum / ptp->expect_result_cnt; - info("%s(%d), expect delta %d, sum %d\n", __func__, port, - ptp->expect_result_avg, ptp->expect_result_sum); + ptp->expect_result_avg = ptp->expect_result_sum / ptp->expect_result_cnt; + info("%s(%d), expect delta %d, sum %d\n", __func__, port, ptp->expect_result_avg, + ptp->expect_result_sum); } } } @@ -1236,8 +1178,8 @@ int obtain_systime_privileges() { return -1; } - if (!OpenProcessToken(GetCurrentProcess(), - TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hProcToken)) { + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, + &hProcToken)) { err("%s, failed to open process token. hr=0x%08lx\n", __func__, HRESULT_FROM_WIN32(GetLastError())); return -1; @@ -1253,8 +1195,7 @@ int obtain_systime_privileges() { return -1; } - if (hProcToken) - CloseHandle(hProcToken); + if (hProcToken) CloseHandle(hProcToken); info("%s, succ\n", __func__); return 0; @@ -1271,13 +1212,10 @@ static void phc2sys_init(struct mt_ptp_impl *ptp) { HANDLE hDll; hDll = LoadLibrary("api-ms-win-core-sysinfo-l1-2-4.dll"); - win_get_systime_adj = - (PGSTAP)GetProcAddress(hDll, "GetSystemTimeAdjustmentPrecise"); - win_set_systime_adj = - (PSSTAP)GetProcAddress(hDll, "SetSystemTimeAdjustmentPrecise"); + win_get_systime_adj = (PGSTAP)GetProcAddress(hDll, "GetSystemTimeAdjustmentPrecise"); + win_set_systime_adj = (PSSTAP)GetProcAddress(hDll, "SetSystemTimeAdjustmentPrecise"); - if (obtain_systime_privileges()) - return; + if (obtain_systime_privileges()) return; /* set system internal adj */ if (!(*win_set_systime_adj)(0, TRUE)) { @@ -1305,8 +1243,7 @@ static int ptp_rxq_mbuf_handle(struct mt_ptp_impl *ptp, struct rte_mbuf *m) { hdr_offset = sizeof(struct rte_ether_hdr); ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct mt_ipv4_udp *, hdr_offset); hdr_offset += sizeof(*ipv4_hdr); - hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, - sizeof(struct mt_udp_hdr)); + hdr = rte_pktmbuf_mtod_offset(m, struct mt_ptp_header *, sizeof(struct mt_udp_hdr)); mt_ptp_parse(ptp, hdr, false, MT_PTP_L4, m->timesync, ipv4_hdr); return 0; @@ -1354,7 +1291,7 @@ static int ptp_init(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp, memcpy(&id[0], &mac.addr_bytes[0], 3); memcpy(&id[3], &magic, 2); memcpy(&id[5], &mac.addr_bytes[3], 3); - our_port_id->port_number = htons(port_id); // now always + our_port_id->port_number = htons(port_id); // now always ptp_print_port_id(port_id, our_port_id); rte_memcpy(ip, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); @@ -1370,10 +1307,8 @@ static int ptp_init(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp, ptp->ki = impl->user_para.ki < 1e-15 ? MT_PTP_DEFAULT_KI : impl->user_para.ki; ptp->use_pi = (impl->user_para.flags & MTL_FLAG_PTP_PI); if (ptp->use_pi) - info("%s(%d), use pi controller, kp %e, ki %e\n", __func__, port, ptp->kp, - ptp->ki); - if (mt_user_phc2sys_service(impl) && (MTL_PORT_P == port)) - phc2sys_init(ptp); + info("%s(%d), use pi controller, kp %e, ki %e\n", __func__, port, ptp->kp, ptp->ki); + if (mt_user_phc2sys_service(impl) && (MTL_PORT_P == port)) phc2sys_init(ptp); struct mtl_init_params *p = mt_get_user_params(impl); if (p->flags & MTL_FLAG_PTP_UNICAST_ADDR) { @@ -1382,8 +1317,8 @@ static int ptp_init(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp, } else { ptp->master_addr_mode = MT_PTP_MULTICAST_ADDR; } - ptp->qbv_enabled = ((ST21_TX_PACING_WAY_TSN == p->pacing) && - (MT_DRV_IGC == inf->drv_info.drv_type)); + ptp->qbv_enabled = + ((ST21_TX_PACING_WAY_TSN == p->pacing) && (MT_DRV_IGC == inf->drv_info.drv_type)); ptp->locked = false; ptp->stat_sync_keep = 0; @@ -1396,11 +1331,9 @@ static int ptp_init(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp, ptp->no_timesync = true; warn("%s(%d), ptp running without timesync support\n", __func__, port); } - info("%s(%d), ptp sync from user for hw offload timestamp\n", __func__, - port); + info("%s(%d), ptp sync from user for hw offload timestamp\n", __func__, port); ptp_sync_from_user(impl, ptp); - rte_eal_alarm_set(MT_PTP_TP_SYNC_MS * 1000, ptp_sync_from_user_handler, - ptp); + rte_eal_alarm_set(MT_PTP_TP_SYNC_MS * 1000, ptp_sync_from_user_handler, ptp); ptp->connected = true; ptp->locked = true; ptp->active = true; @@ -1465,8 +1398,7 @@ static int ptp_init(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp, ptp->calibrate_t2_t3 = true; warn("%s(%d), ptp running without timesync support\n", __func__, port); } - info("%s(%d), sip: %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], - ip[3]); + info("%s(%d), sip: %d.%d.%d.%d\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); return 0; } @@ -1480,12 +1412,10 @@ static int ptp_uinit(struct mtl_main_impl *impl, struct mt_ptp_impl *ptp) { rte_eal_alarm_cancel(ptp_sync_timeout_handler, ptp); rte_eal_alarm_cancel(ptp_monitor_handler, ptp); #ifdef MT_PTP_USE_TX_TIME_STAMP - if (ptp->qbv_enabled) - rte_eal_alarm_cancel(ptp_delay_req_read_tx_time_handler, ptp); + if (ptp->qbv_enabled) rte_eal_alarm_cancel(ptp_delay_req_read_tx_time_handler, ptp); #endif - if (!ptp->active) - return 0; + if (!ptp->active) return 0; if (mt_has_cni(impl, port) && !mt_drv_mcast_in_dp(impl, port)) { mt_mcast_l2_leave(impl, &ptp_l2_multicast_eaddr, port); @@ -1514,16 +1444,15 @@ int mt_ptp_parse(struct mt_ptp_impl *ptp, struct mt_ptp_header *hdr, bool vlan, struct mt_ipv4_udp *ipv4_hdr) { enum mtl_port port = ptp->port; - if (!ptp->active) - return 0; + if (!ptp->active) return 0; dbg("%s(%d), message_type %d\n", __func__, port, hdr->message_type); // mt_ptp_print_port_id(port, &hdr->source_port_identity); if (hdr->message_type != PTP_ANNOUNCE) { if (!ptp->master_initialized) { - dbg("%s(%d), master not initialized, message_type %d, mode %s\n", - __func__, port, hdr->message_type, ptp_mode_str(mode)); + dbg("%s(%d), master not initialized, message_type %d, mode %s\n", __func__, port, + hdr->message_type, ptp_mode_str(mode)); return -EINVAL; } if (!ptp_port_id_equal(&hdr->source_port_identity, &ptp->master_port_id)) { @@ -1538,25 +1467,25 @@ int mt_ptp_parse(struct mt_ptp_impl *ptp, struct mt_ptp_header *hdr, bool vlan, } switch (hdr->message_type) { - case PTP_SYNC: - ptp_parse_sync(ptp, (struct mt_ptp_sync_msg *)hdr, vlan, mode, timesync); - break; - case PTP_FOLLOW_UP: - ptp_parse_follow_up(ptp, (struct mt_ptp_follow_up_msg *)hdr); - break; - case PTP_DELAY_RESP: - ptp_parse_delay_resp(ptp, (struct mt_ptp_delay_resp_msg *)hdr); - break; - case PTP_ANNOUNCE: - ptp_parse_announce(ptp, (struct mt_ptp_announce_msg *)hdr, mode, ipv4_hdr); - break; - case PTP_DELAY_REQ: - break; - case PTP_PDELAY_REQ: - break; - default: - err("%s(%d), unknown message_type %d\n", __func__, port, hdr->message_type); - return -EINVAL; + case PTP_SYNC: + ptp_parse_sync(ptp, (struct mt_ptp_sync_msg *)hdr, vlan, mode, timesync); + break; + case PTP_FOLLOW_UP: + ptp_parse_follow_up(ptp, (struct mt_ptp_follow_up_msg *)hdr); + break; + case PTP_DELAY_RESP: + ptp_parse_delay_resp(ptp, (struct mt_ptp_delay_resp_msg *)hdr); + break; + case PTP_ANNOUNCE: + ptp_parse_announce(ptp, (struct mt_ptp_announce_msg *)hdr, mode, ipv4_hdr); + break; + case PTP_DELAY_REQ: + break; + case PTP_PDELAY_REQ: + break; + default: + err("%s(%d), unknown message_type %d\n", __func__, port, hdr->message_type); + return -EINVAL; } /* read to clear rx timesync status */ @@ -1580,25 +1509,22 @@ static int ptp_stat(void *priv) { strftime(date_time, sizeof(date_time), "%Y-%m-%d %H:%M:%S", &t); notice("PTP(%d): time %" PRIu64 ", %s\n", port, ns, date_time); - if (!ptp->active) - return 0; + if (!ptp->active) return 0; if (ptp->stat_delta_cnt) { if (ptp->phc2sys_active) { notice("PTP(%d): system clock offset max %" PRId64 ", %s\n", port, - ptp->phc2sys.stat_delta_max, - ptp->phc2sys.locked ? "locked" : "not locked"); + ptp->phc2sys.stat_delta_max, ptp->phc2sys.locked ? "locked" : "not locked"); } - notice("PTP(%d): delta avg %" PRId64 ", min %" PRId64 ", max %" PRId64 - ", cnt %d\n", + notice("PTP(%d): delta avg %" PRId64 ", min %" PRId64 ", max %" PRId64 ", cnt %d\n", port, ptp->stat_delta_sum / ptp->stat_delta_cnt, ptp->stat_delta_min, ptp->stat_delta_max, ptp->stat_delta_cnt); } else { notice("PTP(%d): not connected\n", port); } if (ptp->stat_correct_delta_cnt) - notice("PTP(%d): correct_delta avg %" PRId64 ", min %" PRId64 - ", max %" PRId64 ", cnt %d\n", + notice("PTP(%d): correct_delta avg %" PRId64 ", min %" PRId64 ", max %" PRId64 + ", cnt %d\n", port, ptp->stat_correct_delta_sum / ptp->stat_correct_delta_cnt, ptp->stat_correct_delta_min, ptp->stat_correct_delta_max, ptp->stat_correct_delta_cnt); @@ -1606,20 +1532,17 @@ static int ptp_stat(void *priv) { notice("PTP(%d): path_delay avg %" PRId64 ", min %" PRId64 ", max %" PRId64 ", cnt %d\n", port, ptp->stat_path_delay_sum / ptp->stat_path_delay_cnt, - ptp->stat_path_delay_min, ptp->stat_path_delay_max, - ptp->stat_path_delay_cnt); - notice("PTP(%d): mode %s, sync cnt %d, expect avg %d:%d@%fs t2_t1_delta %d " - "t4_t3_delta " - "%d\n", - port, ptp_mode_str(ptp->t2_mode), ptp->stat_sync_cnt, - ptp->expect_result_avg, ptp->expect_correct_result_avg, - (float)ptp->expect_result_period_ns / NS_PER_S, - ptp->expect_t2_t1_delta_avg, ptp->expect_t4_t3_delta_avg); + ptp->stat_path_delay_min, ptp->stat_path_delay_max, ptp->stat_path_delay_cnt); + notice( + "PTP(%d): mode %s, sync cnt %d, expect avg %d:%d@%fs t2_t1_delta %d " + "t4_t3_delta " + "%d\n", + port, ptp_mode_str(ptp->t2_mode), ptp->stat_sync_cnt, ptp->expect_result_avg, + ptp->expect_correct_result_avg, (float)ptp->expect_result_period_ns / NS_PER_S, + ptp->expect_t2_t1_delta_avg, ptp->expect_t4_t3_delta_avg); if (ptp->stat_rx_sync_err || ptp->stat_result_err || ptp->stat_tx_sync_err) - notice( - "PTP(%d): rx time error %d, tx time error %d, delta result error %d\n", - port, ptp->stat_rx_sync_err, ptp->stat_tx_sync_err, - ptp->stat_result_err); + notice("PTP(%d): rx time error %d, tx time error %d, delta result error %d\n", port, + ptp->stat_rx_sync_err, ptp->stat_tx_sync_err, ptp->stat_result_err); if (ptp->stat_sync_timeout_err) err("PTP(%d): sync timeout %d\n", port, ptp->stat_sync_timeout_err); @@ -1630,8 +1553,7 @@ static int ptp_stat(void *priv) { ptp->stat_t4_t3_delta_calibrate = 0; } if (ptp->stat_t3_sequence_id_mismatch) { - err("PTP(%d): t3 sequence id mismatch %d\n", port, - ptp->stat_t3_sequence_id_mismatch); + err("PTP(%d): t3 sequence id mismatch %d\n", port, ptp->stat_t3_sequence_id_mismatch); ptp->stat_t3_sequence_id_mismatch = 0; } @@ -1647,8 +1569,7 @@ int mt_ptp_init(struct mtl_main_impl *impl) { for (int i = 0; i < num_port; i++) { /* only probe on the MTL_PORT_P */ - if ((i != MTL_PORT_P) && !mt_if_has_offload_timestamp(impl, i)) - continue; + if ((i != MTL_PORT_P) && !mt_if_has_offload_timestamp(impl, i)) continue; struct mt_ptp_impl *ptp = mt_rte_zmalloc_socket(sizeof(*ptp), socket); if (!ptp) { @@ -1680,8 +1601,7 @@ int mt_ptp_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { ptp = mt_get_ptp(impl, i); - if (!ptp) - continue; + if (!ptp) continue; mt_stat_unregister(impl, ptp_stat, ptp); @@ -1699,8 +1619,8 @@ uint64_t mt_get_raw_ptp_time(struct mtl_main_impl *impl, enum mtl_port port) { return ptp_get_raw_time(mt_get_ptp(impl, port)); } -static uint64_t mbuf_hw_time_stamp(struct mtl_main_impl *impl, - struct rte_mbuf *mbuf, enum mtl_port port) { +static uint64_t mbuf_hw_time_stamp(struct mtl_main_impl *impl, struct rte_mbuf *mbuf, + enum mtl_port port) { struct mt_ptp_impl *ptp = mt_get_ptp(impl, port); uint64_t time_stamp = *RTE_MBUF_DYNFIELD(mbuf, impl->dynfield_offset, rte_mbuf_timestamp_t *); @@ -1716,14 +1636,12 @@ uint64_t mt_mbuf_time_stamp(struct mtl_main_impl *impl, struct rte_mbuf *mbuf, return mtl_ptp_read_time(impl); } -int mt_ptp_wait_stable(struct mtl_main_impl *impl, enum mtl_port port, - int timeout_ms) { +int mt_ptp_wait_stable(struct mtl_main_impl *impl, enum mtl_port port, int timeout_ms) { struct mt_ptp_impl *ptp = mt_get_ptp(impl, port); uint64_t start_ts = mt_get_tsc(impl); int retry = 0; - if (!ptp->active) - return 0; + if (!ptp->active) return 0; while (ptp->delta_result_cnt <= 5) { if (mt_aborted(impl)) { @@ -1740,8 +1658,7 @@ int mt_ptp_wait_stable(struct mtl_main_impl *impl, enum mtl_port port, } retry++; if (0 == (retry % 500)) - info("%s(%d), wait PTP stable, timeout %d ms\n", __func__, port, - timeout_ms); + info("%s(%d), wait PTP stable, timeout %d ms\n", __func__, port, timeout_ms); mt_sleep_ms(10); } diff --git a/lib/src/mt_ptp.h b/lib/src/mt_ptp.h index 6ff44cff5..e5123d771 100644 --- a/lib/src/mt_ptp.h +++ b/lib/src/mt_ptp.h @@ -114,18 +114,15 @@ int mt_ptp_parse(struct mt_ptp_impl *ptp, struct mt_ptp_header *hdr, bool vlan, enum mt_ptp_l_mode mode, uint16_t timesync, struct mt_ipv4_udp *ipv4_hdr); -static inline bool mt_ptp_is_active(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_ptp_is_active(struct mtl_main_impl *impl, enum mtl_port port) { return mt_get_ptp(impl, port)->active; } -static inline bool mt_ptp_is_locked(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_ptp_is_locked(struct mtl_main_impl *impl, enum mtl_port port) { return mt_get_ptp(impl, port)->locked; } -static inline bool mt_ptp_is_connected(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline bool mt_ptp_is_connected(struct mtl_main_impl *impl, enum mtl_port port) { return mt_get_ptp(impl, port)->connected; } diff --git a/lib/src/mt_quirk.h b/lib/src/mt_quirk.h index f9ed1698e..1f415d083 100644 --- a/lib/src/mt_quirk.h +++ b/lib/src/mt_quirk.h @@ -5,9 +5,9 @@ #ifndef _MT_LIB_QUIRK_HEAD_H_ #define _MT_LIB_QUIRK_HEAD_H_ -static inline unsigned int -mt_rte_ring_sc_dequeue_bulk(struct rte_ring *r, void **obj_table, - unsigned int n, unsigned int *available) { +static inline unsigned int mt_rte_ring_sc_dequeue_bulk(struct rte_ring *r, + void **obj_table, unsigned int n, + unsigned int *available) { #if defined(__clang__) /* fix for clang release build */ /* not sure why clang has issue with variable n, probably optimized code * sequence */ diff --git a/lib/src/mt_rtcp.c b/lib/src/mt_rtcp.c index 4628aafc7..e13c59856 100644 --- a/lib/src/mt_rtcp.c +++ b/lib/src/mt_rtcp.c @@ -25,14 +25,12 @@ static int rtp_seq_num_cmp(uint16_t seq0, uint16_t seq1) { } } -int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx *tx, - struct rte_mbuf **mbufs, unsigned int bulk) { - if (!tx->active) - return 0; +int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx *tx, struct rte_mbuf **mbufs, + unsigned int bulk) { + if (!tx->active) return 0; if (mt_u64_fifo_free_count(tx->mbuf_ring) < bulk) { struct rte_mbuf *clean_mbufs[bulk]; - if (mt_u64_fifo_get_bulk(tx->mbuf_ring, (uint64_t *)clean_mbufs, bulk) < - 0) { + if (mt_u64_fifo_get_bulk(tx->mbuf_ring, (uint64_t *)clean_mbufs, bulk) < 0) { err("%s(%s), failed to dequeue mbuf from ring\n", __func__, tx->name); return -EIO; } @@ -44,18 +42,16 @@ int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx *tx, struct st_rfc3550_rtp_hdr *rtp = rte_pktmbuf_mtod_offset( mbufs[0], struct st_rfc3550_rtp_hdr *, sizeof(struct mt_udp_hdr)); uint16_t seq = ntohs(rtp->seq_number); - uint16_t diff = - seq - tx->last_seq_num; /* uint16_t wrap-around should be ok */ + uint16_t diff = seq - tx->last_seq_num; /* uint16_t wrap-around should be ok */ if (diff != 1 && mt_u64_fifo_count(tx->mbuf_ring) != 0) { uint32_t ts = ntohl(rtp->tmstamp); - err("%s(%s), ts 0x%x seq %u out of order, last seq %u\n", __func__, - tx->name, ts, seq, tx->last_seq_num); + err("%s(%s), ts 0x%x seq %u out of order, last seq %u\n", __func__, tx->name, ts, seq, + tx->last_seq_num); return -EIO; } if (mt_u64_fifo_put_bulk(tx->mbuf_ring, (uint64_t *)mbufs, bulk) < 0) { - err("%s(%s), failed to enqueue %u mbuf to ring\n", __func__, tx->name, - bulk); + err("%s(%s), failed to enqueue %u mbuf to ring\n", __func__, tx->name, bulk); return -EIO; } mt_mbuf_refcnt_inc_bulk(mbufs, bulk); @@ -80,8 +76,7 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx *tx, uint16_t seq, MTL_MAY_UNUSED(ts); struct rte_mbuf *head_mbuf = NULL; - if (mt_u64_fifo_read_front(tx->mbuf_ring, (uint64_t *)&head_mbuf) < 0 || - !head_mbuf) { + if (mt_u64_fifo_read_front(tx->mbuf_ring, (uint64_t *)&head_mbuf) < 0 || !head_mbuf) { err("%s(%s), empty ring\n", __func__, tx->name); ret = -EIO; goto rt_exit; @@ -94,18 +89,16 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx *tx, uint16_t seq, int cmp_result = rtp_seq_num_cmp(ring_head_seq, seq); if (cmp_result > 0) { - dbg("%s(%s), ts 0x%x seq %u out of date, ring head %u, you ask late\n", - __func__, tx->name, ts, seq, ring_head_seq); + dbg("%s(%s), ts 0x%x seq %u out of date, ring head %u, you ask late\n", __func__, + tx->name, ts, seq, ring_head_seq); tx->stat_rtp_retransmit_fail_obsolete += bulk; ret = -EIO; goto rt_exit; } uint16_t diff = seq - ring_head_seq; - if (mt_u64_fifo_read_any_bulk(tx->mbuf_ring, (uint64_t *)mbufs, bulk, diff) < - 0) { - dbg("%s(%s), failed to read retransmit mbufs from ring\n", __func__, - tx->name); + if (mt_u64_fifo_read_any_bulk(tx->mbuf_ring, (uint64_t *)mbufs, bulk, diff) < 0) { + dbg("%s(%s), failed to read retransmit mbufs from ring\n", __func__, tx->name); tx->stat_rtp_retransmit_fail_read += bulk; ret = -EIO; goto rt_exit; @@ -113,8 +106,7 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx *tx, uint16_t seq, /* deep copy the mbuf then send */ for (int i = 0; i < bulk; i++) { - struct rte_mbuf *copied = - rte_pktmbuf_copy(mbufs[i], tx->mbuf_pool, 0, UINT32_MAX); + struct rte_mbuf *copied = rte_pktmbuf_copy(mbufs[i], tx->mbuf_pool, 0, UINT32_MAX); if (!copied) { dbg("%s(%s), failed to copy mbuf\n", __func__, tx->name); tx->stat_rtp_retransmit_fail_nobuf += bulk - i; @@ -138,8 +130,7 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx *tx, uint16_t seq, } ret = send; - dbg("%s(%s), ts 0x%x seq %u retransmit %u pkt(s)\n", __func__, tx->name, ts, - seq, send); + dbg("%s(%s), ts 0x%x seq %u retransmit %u pkt(s)\n", __func__, tx->name, ts, seq, send); rt_exit: tx->stat_rtp_retransmit_succ += send; @@ -148,10 +139,8 @@ static int rtcp_tx_retransmit_rtp_packets(struct mt_rtcp_tx *tx, uint16_t seq, return ret; } -int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx *tx, - struct mt_rtcp_hdr *rtcp) { - if (!tx->active) - return 0; +int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx *tx, struct mt_rtcp_hdr *rtcp) { + if (!tx->active) return 0; if (rtcp->flags != 0x80) { err("%s(%s), wrong rtcp flags %u\n", __func__, tx->name, rtcp->flags); return -EIO; @@ -172,8 +161,8 @@ int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx *tx, dbg("%s(%s), nack %u,%u\n", __func__, tx->name, start, follow); if (rtcp_tx_retransmit_rtp_packets(tx, start, follow + 1) < 0) { - dbg("%s(%s), failed to retransmit rtp packets %u,%u\n", __func__, - tx->name, start, follow); + dbg("%s(%s), failed to retransmit rtp packets %u,%u\n", __func__, tx->name, start, + follow); } fci++; @@ -188,18 +177,15 @@ static int rtcp_rx_update_last_cont(struct mt_rtcp_rx *rx) { uint16_t last_seq = rx->last_seq; /* find the last continuous seq */ for (uint16_t i = last_cont + 1; rtp_seq_num_cmp(i, last_seq) <= 0; i++) { - if (!mt_bitmap_test(rx->seq_bitmap, i % rx->seq_window_size)) - break; + if (!mt_bitmap_test(rx->seq_bitmap, i % rx->seq_window_size)) break; rx->last_cont = i; } return 0; } -int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx *rx, - struct st_rfc3550_rtp_hdr *rtp) { - if (!rx->active) - return 0; +int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx *rx, struct st_rfc3550_rtp_hdr *rtp) { + if (!rx->active) return 0; uint16_t seq = ntohs(rtp->seq_number); if (rx->ssrc == 0) { /* first received */ @@ -242,8 +228,7 @@ int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx *rx, } int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx) { - if (!rx->active) - return 0; + if (!rx->active) return 0; struct mtl_main_impl *impl = rx->parent; enum mtl_port port = rx->port; struct rte_mbuf *pkt; @@ -252,8 +237,7 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx) { uint16_t num_fci = 0; uint64_t now = mt_get_tsc(impl); - if (now < rx->nacks_send_time) - return 0; + if (now < rx->nacks_send_time) return 0; rx->nacks_send_time = now + rx->nacks_send_interval; pkt = rte_pktmbuf_alloc(mt_sys_tx_mempool(impl, port)); @@ -279,8 +263,7 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx) { uint16_t start = seq; uint16_t end = rx->last_seq - rx->seq_skip_window; uint16_t miss = 0; - bool end_state = - mt_bitmap_test_and_set(rx->seq_bitmap, end % rx->seq_window_size); + bool end_state = mt_bitmap_test_and_set(rx->seq_bitmap, end % rx->seq_window_size); while (rtp_seq_num_cmp(seq, end) <= 0) { if (!mt_bitmap_test(rx->seq_bitmap, seq % rx->seq_window_size)) { miss++; @@ -303,8 +286,7 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx) { } seq++; } - if (!end_state) - mt_bitmap_test_and_unset(rx->seq_bitmap, end % rx->seq_window_size); + if (!end_state) mt_bitmap_test_and_unset(rx->seq_bitmap, end % rx->seq_window_size); if (num_fci == 0) { rte_pktmbuf_free(pkt); return 0; @@ -317,14 +299,12 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx) { rtcp->ssrc = htonl(rx->ssrc); rte_memcpy(rtcp->name, "IMTL", 4); - pkt->data_len += - sizeof(struct mt_rtcp_hdr) + num_fci * sizeof(struct mt_rtcp_fci); + pkt->data_len += sizeof(struct mt_rtcp_hdr) + num_fci * sizeof(struct mt_rtcp_fci); pkt->pkt_len = pkt->data_len; /* update length */ ipv4->total_length = htons(pkt->pkt_len - sizeof(struct rte_ether_hdr)); - udp->dgram_len = - htons(pkt->pkt_len - sizeof(struct rte_ether_hdr) - sizeof(*ipv4)); + udp->dgram_len = htons(pkt->pkt_len - sizeof(struct rte_ether_hdr) - sizeof(*ipv4)); uint16_t send = mt_sys_queue_tx_burst(impl, port, &pkt, 1); if (send != 1) { @@ -341,19 +321,16 @@ int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx) { static int rtcp_tx_stat(void *priv) { struct mt_rtcp_tx *tx = priv; - notice("%s(%s), rtp sent %u nack recv %u rtp retransmit succ %u\n", __func__, - tx->name, tx->stat_rtp_sent, tx->stat_nack_received, - tx->stat_rtp_retransmit_succ); + notice("%s(%s), rtp sent %u nack recv %u rtp retransmit succ %u\n", __func__, tx->name, + tx->stat_rtp_sent, tx->stat_nack_received, tx->stat_rtp_retransmit_succ); tx->stat_rtp_sent = 0; tx->stat_nack_received = 0; tx->stat_rtp_retransmit_succ = 0; if (tx->stat_rtp_retransmit_fail) { - notice( - "%s(%s), retransmit fail %u no mbuf %u read %u obsolete %u burst %u\n", - __func__, tx->name, tx->stat_rtp_retransmit_fail, - tx->stat_rtp_retransmit_fail_nobuf, tx->stat_rtp_retransmit_fail_read, - tx->stat_rtp_retransmit_fail_obsolete, - tx->stat_rtp_retransmit_fail_burst); + notice("%s(%s), retransmit fail %u no mbuf %u read %u obsolete %u burst %u\n", + __func__, tx->name, tx->stat_rtp_retransmit_fail, + tx->stat_rtp_retransmit_fail_nobuf, tx->stat_rtp_retransmit_fail_read, + tx->stat_rtp_retransmit_fail_obsolete, tx->stat_rtp_retransmit_fail_burst); tx->stat_rtp_retransmit_fail_nobuf = 0; tx->stat_rtp_retransmit_fail_read = 0; tx->stat_rtp_retransmit_fail_obsolete = 0; @@ -385,8 +362,8 @@ struct mt_rtcp_tx *mt_rtcp_tx_create(struct mtl_main_impl *impl, struct mt_rtcp_tx_ops *ops) { const enum mtl_port port = ops->port; const char *name = ops->name; - struct mt_rtcp_tx *tx = mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_tx), - mt_socket_id(impl, port)); + struct mt_rtcp_tx *tx = + mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_tx), mt_socket_id(impl, port)); if (!tx) { err("%s(%s), failed to allocate memory for mt_rtcp_tx\n", __func__, name); return NULL; @@ -396,14 +373,14 @@ struct mt_rtcp_tx *mt_rtcp_tx_create(struct mtl_main_impl *impl, tx->payload_format = ops->payload_format; if (ops->buffer_size < mt_if_nb_tx_desc(impl, port)) { - warn("%s(%s), buffer_size(%u) is small, adjust to nb_tx_desc(%u)\n", - __func__, name, ops->buffer_size, mt_if_nb_tx_desc(impl, port)); + warn("%s(%s), buffer_size(%u) is small, adjust to nb_tx_desc(%u)\n", __func__, name, + ops->buffer_size, mt_if_nb_tx_desc(impl, port)); ops->buffer_size = mt_if_nb_tx_desc(impl, port); } uint32_t n = ops->buffer_size + mt_if_nb_tx_desc(impl, port); - struct rte_mempool *pool = mt_mempool_create( - impl, port, name, n, MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); + struct rte_mempool *pool = + mt_mempool_create(impl, port, name, n, MT_MBUF_CACHE_SIZE, 0, MTL_MTU_MAX_BYTES); if (!pool) { err("%s(%s), failed to create mempool for mt_rtcp_tx\n", __func__, name); mt_rtcp_tx_free(tx); @@ -423,8 +400,7 @@ struct mt_rtcp_tx *mt_rtcp_tx_create(struct mtl_main_impl *impl, } tx->mbuf_queue = q; - struct mt_u64_fifo *ring = - mt_u64_fifo_init(ops->buffer_size, mt_socket_id(impl, port)); + struct mt_u64_fifo *ring = mt_u64_fifo_init(ops->buffer_size, mt_socket_id(impl, port)); if (!ring) { err("%s(%s), failed to create ring for mt_rtcp_tx\n", __func__, name); mt_rtcp_tx_free(tx); @@ -478,8 +454,8 @@ struct mt_rtcp_rx *mt_rtcp_rx_create(struct mtl_main_impl *impl, struct mt_rtcp_rx_ops *ops) { const enum mtl_port port = ops->port; const char *name = ops->name; - struct mt_rtcp_rx *rx = mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_rx), - mt_socket_id(impl, port)); + struct mt_rtcp_rx *rx = + mt_rte_zmalloc_socket(sizeof(struct mt_rtcp_rx), mt_socket_id(impl, port)); if (!rx) { err("%s(%s), failed to allocate memory for mt_rtcp_rx\n", __func__, name); return NULL; @@ -493,8 +469,8 @@ struct mt_rtcp_rx *mt_rtcp_rx_create(struct mtl_main_impl *impl, snprintf(rx->name, sizeof(rx->name) - 1, "%s", name); rte_memcpy(&rx->udp_hdr, ops->udp_hdr, sizeof(rx->udp_hdr)); - uint8_t *seq_bitmap = mt_rte_zmalloc_socket( - sizeof(uint8_t) * ops->seq_bitmap_size, mt_socket_id(impl, port)); + uint8_t *seq_bitmap = mt_rte_zmalloc_socket(sizeof(uint8_t) * ops->seq_bitmap_size, + mt_socket_id(impl, port)); if (!seq_bitmap) { err("%s(%s), failed to allocate memory for seq_bitmap\n", __func__, name); mt_rtcp_rx_free(rx); @@ -518,8 +494,7 @@ void mt_rtcp_rx_free(struct mt_rtcp_rx *rx) { rtcp_rx_stat(rx); - if (rx->seq_bitmap) - mt_rte_free(rx->seq_bitmap); + if (rx->seq_bitmap) mt_rte_free(rx->seq_bitmap); mt_rte_free(rx); } \ No newline at end of file diff --git a/lib/src/mt_rtcp.h b/lib/src/mt_rtcp.h index a3da8e84a..6220cb0f0 100644 --- a/lib/src/mt_rtcp.h +++ b/lib/src/mt_rtcp.h @@ -34,11 +34,11 @@ enum mt_rtp_payload_format { }; struct mt_rtcp_tx_ops { - const char *name; /* short and unique name for each session */ - struct mt_udp_hdr *udp_hdr; /* headers including eth, ipv4 and udp */ - uint32_t ssrc; /* ssrc of rtp session */ - uint16_t buffer_size; /* max number of buffered rtp packets */ - enum mtl_port port; /* port of rtp session */ + const char *name; /* short and unique name for each session */ + struct mt_udp_hdr *udp_hdr; /* headers including eth, ipv4 and udp */ + uint32_t ssrc; /* ssrc of rtp session */ + uint16_t buffer_size; /* max number of buffered rtp packets */ + enum mtl_port port; /* port of rtp session */ enum mt_rtp_payload_format payload_format; /* payload format */ }; @@ -47,10 +47,9 @@ struct mt_rtcp_rx_ops { struct mt_udp_hdr *udp_hdr; /* headers including eth, ipv4 and udp */ uint64_t nacks_send_interval; /* nack sending interval */ enum mtl_port port; /* port of rtp session */ - uint16_t - seq_bitmap_size; /* bitmap size of detecting window, can hold n * 8 seq */ - uint16_t seq_skip_window; /* skip some seq to handle out of order while - detecting */ + uint16_t seq_bitmap_size; /* bitmap size of detecting window, can hold n * 8 seq */ + uint16_t seq_skip_window; /* skip some seq to handle out of order while + detecting */ }; struct mt_rtcp_tx { @@ -110,13 +109,11 @@ struct mt_rtcp_rx *mt_rtcp_rx_create(struct mtl_main_impl *mtl, struct mt_rtcp_rx_ops *ops); void mt_rtcp_rx_free(struct mt_rtcp_rx *rx); -int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx *tx, - struct rte_mbuf **mbufs, unsigned int bulk); -int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx *tx, - struct mt_rtcp_hdr *rtcp); +int mt_rtcp_tx_buffer_rtp_packets(struct mt_rtcp_tx *tx, struct rte_mbuf **mbufs, + unsigned int bulk); +int mt_rtcp_tx_parse_rtcp_packet(struct mt_rtcp_tx *tx, struct mt_rtcp_hdr *rtcp); -int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx *rx, - struct st_rfc3550_rtp_hdr *rtp); +int mt_rtcp_rx_parse_rtp_packet(struct mt_rtcp_rx *rx, struct st_rfc3550_rtp_hdr *rtp); int mt_rtcp_rx_send_nack_packet(struct mt_rtcp_rx *rx); #endif \ No newline at end of file diff --git a/lib/src/mt_sch.c b/lib/src/mt_sch.c index 7b684f2b8..d42822888 100644 --- a/lib/src/mt_sch.c +++ b/lib/src/mt_sch.c @@ -56,8 +56,7 @@ static void sch_sleep_alarm_handler(void *param) { sch_sleep_wakeup(sch); } -static int sch_tasklet_sleep(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { +static int sch_tasklet_sleep(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { /* get sleep us */ uint64_t sleep_us = mt_sch_default_sleep_us(impl); uint64_t force_sleep_us = mt_sch_force_sleep_us(impl); @@ -70,11 +69,9 @@ static int sch_tasklet_sleep(struct mtl_main_impl *impl, } else { for (int i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) - continue; + if (!tasklet) continue; advice_sleep_us = tasklet->ops.advice_sleep_us; - if (advice_sleep_us && (advice_sleep_us < sleep_us)) - sleep_us = advice_sleep_us; + if (advice_sleep_us && (advice_sleep_us < sleep_us)) sleep_us = advice_sleep_us; } } dbg("%s(%d), sleep_us %" PRIu64 "\n", __func__, sch->idx, sleep_us); @@ -87,8 +84,7 @@ static int sch_tasklet_sleep(struct mtl_main_impl *impl, rte_eal_alarm_set(sleep_us, sch_sleep_alarm_handler, sch); mt_pthread_mutex_lock(&sch->sleep_wake_mutex); /* timeout 1s */ - mt_pthread_cond_timedwait_ns(&sch->sleep_wake_cond, &sch->sleep_wake_mutex, - NS_PER_S); + mt_pthread_cond_timedwait_ns(&sch->sleep_wake_cond, &sch->sleep_wake_mutex, NS_PER_S); mt_pthread_mutex_unlock(&sch->sleep_wake_mutex); } uint64_t end = mt_get_tsc(impl); @@ -116,8 +112,7 @@ static int sch_tasklet_sleep(struct mtl_main_impl *impl, static bool sch_tasklet_time_measure(struct mtl_main_impl *impl) { bool enabled = mt_user_tasklet_time_measure(impl); - if (MT_USDT_TASKLET_TIME_MEASURE_ENABLED()) - enabled = true; + if (MT_USDT_TASKLET_TIME_MEASURE_ENABLED()) enabled = true; return enabled; } @@ -140,11 +135,9 @@ static int sch_tasklet_func(struct mtl_sch_impl *sch) { for (i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) - continue; + if (!tasklet) continue; ops = &tasklet->ops; - if (ops->start) - ops->start(ops->priv); + if (ops->start) ops->start(ops->priv); } sch->sleep_ratio_start_ns = mt_get_tsc(impl); @@ -155,14 +148,12 @@ static int sch_tasklet_func(struct mtl_sch_impl *sch) { bool time_measure = sch_tasklet_time_measure(impl); uint64_t tm_sch_tsc_s = 0; /* for sch time_measure */ - if (time_measure) - tm_sch_tsc_s = mt_get_tsc(impl); + if (time_measure) tm_sch_tsc_s = mt_get_tsc(impl); num_tasklet = sch->max_tasklet_idx; for (i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) - continue; + if (!tasklet) continue; if (tasklet->request_exit) { tasklet->ack_exit = true; sch->tasklet[i] = NULL; @@ -172,8 +163,7 @@ static int sch_tasklet_func(struct mtl_sch_impl *sch) { ops = &tasklet->ops; uint64_t tm_tasklet_tsc_s = 0; /* for tasklet time_measure */ - if (time_measure) - tm_tasklet_tsc_s = mt_get_tsc(impl); + if (time_measure) tm_tasklet_tsc_s = mt_get_tsc(impl); pending += ops->handler(ops->priv); if (time_measure) { uint64_t delta_ns = mt_get_tsc(impl) - tm_tasklet_tsc_s; @@ -202,11 +192,9 @@ static int sch_tasklet_func(struct mtl_sch_impl *sch) { num_tasklet = sch->max_tasklet_idx; for (i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) - continue; + if (!tasklet) continue; ops = &tasklet->ops; - if (ops->stop) - ops->stop(ops->priv); + if (ops->stop) ops->stop(ops->priv); } rte_atomic32_set(&sch->stopped, 1); @@ -246,11 +234,10 @@ static int sch_start(struct mtl_sch_impl *sch) { rte_atomic32_set(&sch->stopped, 0); if (!sch->run_in_thread) { - ret = - mt_sch_get_lcore(sch->parent, &sch->lcore, - (sch->type == MT_SCH_TYPE_APP) ? MT_LCORE_TYPE_SCH_USER - : MT_LCORE_TYPE_SCH, - mt_sch_socket_id(sch)); + ret = mt_sch_get_lcore( + sch->parent, &sch->lcore, + (sch->type == MT_SCH_TYPE_APP) ? MT_LCORE_TYPE_SCH_USER : MT_LCORE_TYPE_SCH, + mt_sch_socket_id(sch)); if (ret < 0) { err("%s(%d), get lcore fail %d\n", __func__, idx, ret); sch_unlock(sch); @@ -306,16 +293,14 @@ static int sch_stop(struct mtl_sch_impl *sch) { return 0; } -static struct mtl_sch_impl *sch_request(struct mtl_main_impl *impl, - enum mt_sch_type type, - mt_sch_mask_t mask, - struct mtl_sch_ops *ops, int socket) { +static struct mtl_sch_impl *sch_request(struct mtl_main_impl *impl, enum mt_sch_type type, + mt_sch_mask_t mask, struct mtl_sch_ops *ops, + int socket) { struct mtl_sch_impl *sch; for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { /* mask check */ - if (!(mask & MTL_BIT64(sch_idx))) - continue; + if (!(mask & MTL_BIT64(sch_idx))) continue; sch = mt_sch_instance(impl, sch_idx); @@ -331,11 +316,10 @@ static struct mtl_sch_impl *sch_request(struct mtl_main_impl *impl, sch->nb_tasklets = ops->nb_tasklets; else sch->nb_tasklets = impl->tasklets_nb_per_sch; - sch->tasklet = mt_rte_zmalloc_socket( - sizeof(*sch->tasklet) * sch->nb_tasklets, socket); + sch->tasklet = + mt_rte_zmalloc_socket(sizeof(*sch->tasklet) * sch->nb_tasklets, socket); if (!sch->tasklet) { - err("%s(%d), %u tasklet malloc fail\n", __func__, sch_idx, - sch->nb_tasklets); + err("%s(%d), %u tasklet malloc fail\n", __func__, sch_idx, sch->nb_tasklets); sch_unlock(sch); return NULL; } @@ -345,8 +329,8 @@ static struct mtl_sch_impl *sch_request(struct mtl_main_impl *impl, /* set the socket id */ sch->socket_id = socket; - info("%s(%d), name %s with %u tasklets, type %d socket %d\n", __func__, - sch_idx, sch->name, sch->nb_tasklets, type, sch->socket_id); + info("%s(%d), name %s with %u tasklets, type %d socket %d\n", __func__, sch_idx, + sch->name, sch->nb_tasklets, type, sch->socket_id); return sch; } sch_unlock(sch); @@ -410,8 +394,7 @@ static bool sch_is_capable(struct mtl_sch_impl *sch, int quota_mbs, if (!quota_mbs) { /* zero quota_mbs can be applied to any type */ return true; } - if ((type == MT_SCH_TYPE_RX_VIDEO_ONLY) && - (sch->type == MT_SCH_TYPE_DEFAULT)) { + if ((type == MT_SCH_TYPE_RX_VIDEO_ONLY) && (sch->type == MT_SCH_TYPE_DEFAULT)) { sch_lock(sch); if (!sch->data_quota_mbs_total) { /* change type to rx video only since no quota on this */ @@ -433,13 +416,10 @@ static int sch_stat(void *priv) { struct mt_sch_tasklet_impl *tasklet; int idx = sch->idx; - if (!mt_sch_is_active(sch)) - return 0; + if (!mt_sch_is_active(sch)) return 0; - notice("SCH(%d:%s): tasklets %d, lcore %u(t_pid: %d), avg loop %" PRIu64 - " ns\n", - idx, sch->name, num_tasklet, sch->lcore, sch->t_pid, - mt_sch_avg_ns_loop(sch)); + notice("SCH(%d:%s): tasklets %d, lcore %u(t_pid: %d), avg loop %" PRIu64 " ns\n", idx, + sch->name, num_tasklet, sch->lcore, sch->t_pid, mt_sch_avg_ns_loop(sch)); /* print the stat time info */ struct mt_stat_u64 *stat_time = &sch->stat_time; @@ -452,24 +432,22 @@ static int sch_stat(void *priv) { } for (int i = 0; i < num_tasklet; i++) { tasklet = sch->tasklet[i]; - if (!tasklet) - continue; + if (!tasklet) continue; dbg("SCH(%d): tasklet %s at %d\n", idx, tasklet->name, i); stat_time = &tasklet->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("SCH(%d,%d): tasklet %s, avg %.2fus max %.2fus min %.2fus\n", idx, - i, tasklet->name, (float)avg_ns / NS_PER_US, - (float)stat_time->max / NS_PER_US, + notice("SCH(%d,%d): tasklet %s, avg %.2fus max %.2fus min %.2fus\n", idx, i, + tasklet->name, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } } if (sch->allow_sleep) { - notice("SCH(%d): sleep %fms(ratio:%f), cnt %u, min %" PRIu64 - "us, max %" PRIu64 "us\n", + notice("SCH(%d): sleep %fms(ratio:%f), cnt %u, min %" PRIu64 "us, max %" PRIu64 + "us\n", idx, (double)sch->stat_sleep_ns / NS_PER_MS, sch->sleep_ratio_score, sch->stat_sleep_cnt, sch->stat_sleep_ns_min / NS_PER_US, sch->stat_sleep_ns_max / NS_PER_US); @@ -491,8 +469,7 @@ static int sch_filelock_lock(struct mt_sch_mgr *mgr) { /* sometimes may fail due to user permission, try open read-only */ fd = open(MT_FLOCK_PATH, O_RDONLY); if (fd < 0) { - err("%s, failed to open %s, %s\n", __func__, MT_FLOCK_PATH, - strerror(errno)); + err("%s, failed to open %s, %s\n", __func__, MT_FLOCK_PATH, strerror(errno)); return -EIO; } } @@ -538,16 +515,14 @@ static int sch_lcore_shm_init(struct mt_lcore_mgr *mgr, bool clear_on_first) { } int shm_id = shmget(key, sizeof(*lcore_shm), 0666 | IPC_CREAT); if (shm_id < 0) { - err("%s, can not get shared memory for lcore, %s\n", __func__, - strerror(errno)); + err("%s, can not get shared memory for lcore, %s\n", __func__, strerror(errno)); return -EIO; } mgr->lcore_shm_id = shm_id; lcore_shm = shmat(shm_id, NULL, 0); if (lcore_shm == (void *)-1) { - err("%s, can not attach shared memory for lcore, %s\n", __func__, - strerror(errno)); + err("%s, can not attach shared memory for lcore, %s\n", __func__, strerror(errno)); return -EIO; } @@ -565,8 +540,8 @@ static int sch_lcore_shm_init(struct mt_lcore_mgr *mgr, bool clear_on_first) { } mgr->lcore_shm = lcore_shm; - info("%s, shared memory attached at %p nattch %d shm_id %d key 0x%x\n", - __func__, mgr->lcore_shm, (int)stat.shm_nattch, shm_id, (int)key); + info("%s, shared memory attached at %p nattch %d shm_id %d key 0x%x\n", __func__, + mgr->lcore_shm, (int)stat.shm_nattch, shm_id, (int)key); return 0; } @@ -575,8 +550,7 @@ static int sch_lcore_shm_uinit(struct mt_lcore_mgr *mgr) { if (mgr->lcore_shm) { ret = shmdt(mgr->lcore_shm); - if (ret < 0) - err("%s, shared memory detach failed, %s\n", __func__, strerror(errno)); + if (ret < 0) err("%s, shared memory detach failed, %s\n", __func__, strerror(errno)); mgr->lcore_shm = NULL; } @@ -590,8 +564,7 @@ static int sch_lcore_shm_uinit(struct mt_lcore_mgr *mgr) { notice("%s, remove shared memory as we are the last user\n", __func__); ret = shmctl(mgr->lcore_shm_id, IPC_RMID, NULL); if (ret < 0) { - warn("%s, can not remove shared memory, %s\n", __func__, - strerror(errno)); + warn("%s, can not remove shared memory, %s\n", __func__, strerror(errno)); } } } @@ -601,8 +574,7 @@ static int sch_lcore_shm_uinit(struct mt_lcore_mgr *mgr) { return 0; } -static int sch_uinit_lcores(struct mtl_main_impl *impl, - struct mt_sch_mgr *mgr) { +static int sch_uinit_lcores(struct mtl_main_impl *impl, struct mt_sch_mgr *mgr) { int ret; for (unsigned int lcore = 0; lcore < RTE_MAX_LCORE; lcore++) { @@ -663,8 +635,7 @@ static int sch_init_lcores(struct mt_sch_mgr *mgr) { static inline bool sch_socket_match(int cpu_socket, int dev_socket, bool skip_numa_check) { - if (skip_numa_check) - return true; + if (skip_numa_check) return true; return mt_socket_match(cpu_socket, dev_socket); } @@ -676,8 +647,7 @@ int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); int tried = 0; - if (mt_user_not_bind_numa(impl)) - skip_numa_check = true; + if (mt_user_not_bind_numa(impl)) skip_numa_check = true; again: cur_lcore = 0; @@ -685,8 +655,7 @@ int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, do { cur_lcore = rte_get_next_lcore(cur_lcore, 1, 0); if ((cur_lcore < RTE_MAX_LCORE) && - sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, - skip_numa_check)) { + sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, skip_numa_check)) { ret = mt_instance_get_lcore(impl, cur_lcore); if (ret == 0) { *lcore = cur_lcore; @@ -694,8 +663,8 @@ int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, /* set local lcores info */ mgr->local_lcores_active[cur_lcore] = true; mgr->local_lcores_type[cur_lcore] = type; - info("%s, succ on manager lcore %d for %s socket %d\n", __func__, - cur_lcore, lcore_type_name(type), socket); + info("%s, succ on manager lcore %d for %s socket %d\n", __func__, cur_lcore, + lcore_type_name(type), socket); return 0; } } @@ -718,8 +687,7 @@ int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, shm_entry = &lcore_shm->lcores_info[cur_lcore]; if ((cur_lcore < RTE_MAX_LCORE) && - sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, - skip_numa_check)) { + sch_socket_match(rte_lcore_to_socket_id(cur_lcore), socket, skip_numa_check)) { if (!shm_entry->active) { *lcore = cur_lcore; shm_entry->active = true; @@ -735,8 +703,8 @@ int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, mgr->local_lcores_active[cur_lcore] = true; mgr->local_lcores_type[cur_lcore] = type; ret = sch_filelock_unlock(mgr); - info("%s, succ on shm lcore %d for %s socket %d\n", __func__, - cur_lcore, lcore_type_name(type), socket); + info("%s, succ on shm lcore %d for %s socket %d\n", __func__, cur_lcore, + lcore_type_name(type), socket); if (ret < 0) { err("%s, sch_filelock_unlock fail\n", __func__); return ret; @@ -751,15 +719,16 @@ int mt_sch_get_lcore(struct mtl_main_impl *impl, unsigned int *lcore, } if (!skip_numa_check && mt_user_across_numa_core(impl)) { - warn("%s, can't find available lcore from socket %d, try with other numa " - "cpu\n", - __func__, socket); + warn( + "%s, can't find available lcore from socket %d, try with other numa " + "cpu\n", + __func__, socket); skip_numa_check = true; goto again; } - err("%s, no available lcore, type %s tried %d\n", __func__, - lcore_type_name(type), tried); + err("%s, no available lcore, type %s tried %d\n", __func__, lcore_type_name(type), + tried); return -EIO; } @@ -833,8 +802,7 @@ bool mt_sch_lcore_valid(struct mtl_main_impl *impl, unsigned int lcore) { return -EIO; } - if (mt_is_manager_connected(impl)) - return true; + if (mt_is_manager_connected(impl)) return true; if (!lcore_shm) { err("%s, no lcore shm attached\n", __func__); @@ -860,16 +828,16 @@ int mtl_sch_unregister_tasklet(mtl_tasklet_handle tasklet) { if (mt_sch_started(sch)) { int retry = 0; /* wait sch ack this exit */ - dbg("%s(%d), tasklet %s(%d) runtime unregistered\n", __func__, sch_idx, - tasklet->name, idx); + dbg("%s(%d), tasklet %s(%d) runtime unregistered\n", __func__, sch_idx, tasklet->name, + idx); tasklet->ack_exit = false; tasklet->request_exit = true; do { mt_sleep_ms(1); retry++; if (retry > 1000) { - err("%s(%d), tasklet %s(%d) runtime unregistered timeout\n", __func__, - sch_idx, tasklet->name, idx); + err("%s(%d), tasklet %s(%d) runtime unregistered timeout\n", __func__, sch_idx, + tasklet->name, idx); sch_unlock(sch); return -EIO; } @@ -877,21 +845,18 @@ int mtl_sch_unregister_tasklet(mtl_tasklet_handle tasklet) { info("%s(%d), tasklet %s(%d) unregistered, retry %d\n", __func__, sch_idx, tasklet->name, idx, retry); /* call the stop for runtime path */ - if (tasklet->ops.stop) - tasklet->ops.stop(tasklet->ops.priv); + if (tasklet->ops.stop) tasklet->ops.stop(tasklet->ops.priv); } else { /* safe to directly remove */ sch->tasklet[idx] = NULL; - info("%s(%d), tasklet %s(%d) unregistered\n", __func__, sch_idx, - tasklet->name, idx); + info("%s(%d), tasklet %s(%d) unregistered\n", __func__, sch_idx, tasklet->name, idx); } mt_rte_free(tasklet); int max_idx = 0; for (int i = 0; i < sch->nb_tasklets; i++) { - if (sch->tasklet[i]) - max_idx = i + 1; + if (sch->tasklet[i]) max_idx = i + 1; } sch->max_tasklet_idx = max_idx; @@ -899,9 +864,8 @@ int mtl_sch_unregister_tasklet(mtl_tasklet_handle tasklet) { return 0; } -mtl_tasklet_handle -mtl_sch_register_tasklet(struct mtl_sch_impl *sch, - struct mtl_tasklet_ops *tasklet_ops) { +mtl_tasklet_handle mtl_sch_register_tasklet(struct mtl_sch_impl *sch, + struct mtl_tasklet_ops *tasklet_ops) { int idx = sch->idx; struct mt_sch_tasklet_impl *tasklet; @@ -909,8 +873,7 @@ mtl_sch_register_tasklet(struct mtl_sch_impl *sch, /* find one empty slot in the mgr */ for (int i = 0; i < sch->nb_tasklets; i++) { - if (sch->tasklet[i]) - continue; + if (sch->tasklet[i]) continue; /* find one empty tasklet slot */ tasklet = mt_rte_zmalloc_socket(sizeof(*tasklet), mt_sch_socket_id(sch)); @@ -930,18 +893,16 @@ mtl_sch_register_tasklet(struct mtl_sch_impl *sch, sch->max_tasklet_idx = RTE_MAX(sch->max_tasklet_idx, i + 1); if (mt_sch_started(sch)) { - if (tasklet_ops->start) - tasklet_ops->start(tasklet_ops->priv); + if (tasklet_ops->start) tasklet_ops->start(tasklet_ops->priv); } sch_unlock(sch); - info("%s(%d), tasklet %s registered into slot %d\n", __func__, idx, - tasklet_ops->name, i); + info("%s(%d), tasklet %s registered into slot %d\n", __func__, idx, tasklet_ops->name, + i); return tasklet; } - err("%s(%d), no space on this sch, max %d\n", __func__, idx, - sch->nb_tasklets); + err("%s(%d), no space on this sch, max %d\n", __func__, idx, sch->nb_tasklets); sch_unlock(sch); return NULL; } @@ -957,8 +918,7 @@ int mt_sch_mrg_init(struct mtl_main_impl *impl, int data_quota_mbs_limit) { if (!mt_is_manager_connected(impl)) { ret = sch_init_lcores(mgr); - if (ret < 0) - return ret; + if (ret < 0) return ret; } for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { @@ -1002,8 +962,7 @@ int mt_sch_mrg_uinit(struct mtl_main_impl *impl) { struct mtl_sch_impl *sch; struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); - if (!mt_is_manager_connected(impl)) - sch_uinit_lcores(impl, mgr); + if (!mt_is_manager_connected(impl)) sch_uinit_lcores(impl, mgr); for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); @@ -1048,8 +1007,8 @@ int mt_sch_add_quota(struct mtl_sch_impl *sch, int quota_mbs) { ((sch->data_quota_mbs_total + quota_mbs) <= sch->data_quota_mbs_limit)) { /* find one sch capable with quota */ sch->data_quota_mbs_total += quota_mbs; - info("%s(%d:%d), quota %d total now %d\n", __func__, idx, sch->type, - quota_mbs, sch->data_quota_mbs_total); + info("%s(%d:%d), quota %d total now %d\n", __func__, idx, sch->type, quota_mbs, + sch->data_quota_mbs_total); sch_unlock(sch); return 0; } @@ -1105,9 +1064,9 @@ int mt_sch_put(struct mtl_sch_impl *sch, int quota_mbs) { return 0; } -struct mtl_sch_impl *mt_sch_get_by_socket(struct mtl_main_impl *impl, - int quota_mbs, enum mt_sch_type type, - mt_sch_mask_t mask, int socket) { +struct mtl_sch_impl *mt_sch_get_by_socket(struct mtl_main_impl *impl, int quota_mbs, + enum mt_sch_type type, mt_sch_mask_t mask, + int socket) { int ret, idx; struct mtl_sch_impl *sch; struct mt_sch_mgr *mgr = mt_sch_get_mgr(impl); @@ -1117,21 +1076,17 @@ struct mtl_sch_impl *mt_sch_get_by_socket(struct mtl_main_impl *impl, /* first try to find one sch capable with quota */ for (idx = 0; idx < MT_MAX_SCH_NUM; idx++) { sch = mt_sch_instance(impl, idx); - if (socket != mt_sch_socket_id(sch)) - continue; + if (socket != mt_sch_socket_id(sch)) continue; /* mask check */ - if (!(mask & MTL_BIT64(idx))) - continue; + if (!(mask & MTL_BIT64(idx))) continue; /* active and busy check */ - if (!mt_sch_is_active(sch) || sch->cpu_busy) - continue; + if (!mt_sch_is_active(sch) || sch->cpu_busy) continue; /* quota check */ - if (!sch_is_capable(sch, quota_mbs, type)) - continue; + if (!sch_is_capable(sch, quota_mbs, type)) continue; ret = mt_sch_add_quota(sch, quota_mbs); if (ret >= 0) { - info("%s(%d), succ with quota_mbs %d socket %d\n", __func__, idx, - quota_mbs, socket); + info("%s(%d), succ with quota_mbs %d socket %d\n", __func__, idx, quota_mbs, + socket); rte_atomic32_inc(&sch->ref_cnt); sch_mgr_unlock(mgr); return sch; @@ -1179,8 +1134,7 @@ int mt_sch_start_all(struct mtl_main_impl *impl) { for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); /* not start the app created sch, app should do the mtl_sch_start */ - if (sch->type == MT_SCH_TYPE_APP) - continue; + if (sch->type == MT_SCH_TYPE_APP) continue; if (mt_sch_is_active(sch) && !mt_sch_started(sch)) { ret = sch_start(sch); @@ -1203,8 +1157,7 @@ int mt_sch_stop_all(struct mtl_main_impl *impl) { for (int sch_idx = 0; sch_idx < MT_MAX_SCH_NUM; sch_idx++) { sch = mt_sch_instance(impl, sch_idx); /* not stop the app created sch, app should do the mtl_sch_stop */ - if (sch->type == MT_SCH_TYPE_APP) - continue; + if (sch->type == MT_SCH_TYPE_APP) continue; if (mt_sch_is_active(sch) && mt_sch_started(sch)) { ret = sch_stop(sch); @@ -1223,8 +1176,7 @@ int mtl_lcore_shm_print(void) { struct mt_lcore_shm_entry *shm_entry; int ret = sch_lcore_shm_init(&lcore_mgr, false); - if (ret < 0) - return ret; + if (ret < 0) return ret; struct mt_lcore_shm *lcore_shm = lcore_mgr.lcore_shm; info("%s, MTL used lcores %d\n", __func__, lcore_shm->used); @@ -1235,11 +1187,10 @@ int mtl_lcore_shm_print(void) { for (int i = 0; i < RTE_MAX_LCORE; i++) { shm_entry = &lcore_shm->lcores_info[i]; - if (!shm_entry->active) - continue; + if (!shm_entry->active) continue; struct mt_user_info *u_info = &shm_entry->u_info; - info("%s, lcore %d active by %s@%s, pid: %d(comm: %s) type: %s\n", __func__, - i, u_info->user, u_info->hostname, (int)shm_entry->pid, u_info->comm, + info("%s, lcore %d active by %s@%s, pid: %d(comm: %s) type: %s\n", __func__, i, + u_info->user, u_info->hostname, (int)shm_entry->pid, u_info->comm, lcore_type_name(shm_entry->type)); cpu_ids[found] = i; found++; @@ -1252,14 +1203,14 @@ int mtl_lcore_shm_print(void) { info("%s, collecting cpu usage...\n", __func__); ret = mt_read_cpu_usage(prev, cpu_ids, found); if (ret != found) { - err("%s, read cpu prev usage fail, expect %d but only %d get\n", __func__, - found, ret); + err("%s, read cpu prev usage fail, expect %d but only %d get\n", __func__, found, + ret); } else { mt_sleep_ms(1000 * 1); ret = mt_read_cpu_usage(cur, cpu_ids, found); if (ret != found) { - err("%s, read cpu curr usage fail, expect %d but only %d get\n", - __func__, found, ret); + err("%s, read cpu curr usage fail, expect %d but only %d get\n", __func__, found, + ret); } else { /* print the result */ for (int i = 0; i < found; i++) { @@ -1294,20 +1245,16 @@ static int lcore_shm_clean_auto_pid(struct mt_lcore_mgr *lcore_mgr) { for (int i = 0; i < RTE_MAX_LCORE; i++) { shm_entry = &lcore_shm->lcores_info[i]; - if (!shm_entry->active) - continue; + if (!shm_entry->active) continue; struct mt_user_info *u_info = &shm_entry->u_info; - if (0 != strncmp(u_info->hostname, info.hostname, sizeof(u_info->hostname))) - continue; - if (0 != strncmp(u_info->user, info.user, sizeof(u_info->user))) - continue; + if (0 != strncmp(u_info->hostname, info.hostname, sizeof(u_info->hostname))) continue; + if (0 != strncmp(u_info->user, info.user, sizeof(u_info->user))) continue; /* now check if PID is active with zero signal */ int result = kill(shm_entry->pid, 0); - if (0 == result) - continue; + if (0 == result) continue; clean++; - notice("%s, delete dead lcore %d from the shared mem, PID %d\n", __func__, - i, (int)shm_entry->pid); + notice("%s, delete dead lcore %d from the shared mem, PID %d\n", __func__, i, + (int)shm_entry->pid); } return clean; @@ -1345,27 +1292,25 @@ static int lcore_shm_clean_id(struct mt_lcore_mgr *lcore_mgr, void *args, return 0; } -int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void *args, - size_t args_sz) { +int mtl_lcore_shm_clean(enum mtl_lcore_clean_action action, void *args, size_t args_sz) { struct mt_lcore_mgr lcore_mgr; int ret = sch_lcore_shm_init(&lcore_mgr, false); - if (ret < 0) - return ret; + if (ret < 0) return ret; MTL_MAY_UNUSED(args); MTL_MAY_UNUSED(args_sz); switch (action) { - case MTL_LCORE_CLEAN_PID_AUTO_CHECK: - ret = lcore_shm_clean_auto_pid(&lcore_mgr); - break; - case MTL_LCORE_CLEAN_LCORE: - ret = lcore_shm_clean_id(&lcore_mgr, args, args_sz); - break; - default: - err("%s, unknown action %d\n", __func__, action); - ret = -EINVAL; - break; + case MTL_LCORE_CLEAN_PID_AUTO_CHECK: + ret = lcore_shm_clean_auto_pid(&lcore_mgr); + break; + case MTL_LCORE_CLEAN_LCORE: + ret = lcore_shm_clean_id(&lcore_mgr, args, args_sz); + break; + default: + err("%s, unknown action %d\n", __func__, action); + ret = -EINVAL; + break; } sch_lcore_shm_uinit(&lcore_mgr); @@ -1388,8 +1333,8 @@ mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops *ops) { } /* request sch on the MTL_PORT_P socket */ - struct mtl_sch_impl *sch = sch_request(impl, MT_SCH_TYPE_APP, MT_SCH_MASK_ALL, - ops, mt_socket_id(impl, MTL_PORT_P)); + struct mtl_sch_impl *sch = sch_request(impl, MT_SCH_TYPE_APP, MT_SCH_MASK_ALL, ops, + mt_socket_id(impl, MTL_PORT_P)); if (!sch) { err("%s, sch request fail\n", __func__); return NULL; @@ -1402,8 +1347,7 @@ mtl_sch_handle mtl_sch_create(mtl_handle mt, struct mtl_sch_ops *ops) { int mtl_sch_free(mtl_sch_handle sch) { int idx = sch->idx; /* stop incase user not dp the mtl_sch_stop */ - if (mt_sch_started(sch)) - sch_stop(sch); + if (mt_sch_started(sch)) sch_stop(sch); int ret = sch_free(sch); if (ret < 0) { err("%s(%d), sch free fail %d\n", __func__, idx, ret); diff --git a/lib/src/mt_sch.h b/lib/src/mt_sch.h index 1913c84bd..2f616aa49 100644 --- a/lib/src/mt_sch.h +++ b/lib/src/mt_sch.h @@ -11,8 +11,7 @@ static inline struct mt_sch_mgr *mt_sch_get_mgr(struct mtl_main_impl *impl) { return &impl->sch_mgr; } -static inline struct mtl_sch_impl *mt_sch_instance(struct mtl_main_impl *impl, - int i) { +static inline struct mtl_sch_impl *mt_sch_instance(struct mtl_main_impl *impl, int i) { return &mt_sch_get_mgr(impl)->sch[i]; } @@ -34,8 +33,7 @@ static inline int mt_sch_socket_id(struct mtl_sch_impl *sch) { return sch->socket_id; } -static inline void mt_sch_enable_allow_sleep(struct mtl_sch_impl *sch, - bool enable) { +static inline void mt_sch_enable_allow_sleep(struct mtl_sch_impl *sch, bool enable) { sch->allow_sleep = enable; } @@ -56,13 +54,11 @@ static inline void mt_tasklet_set_sleep(struct mt_sch_tasklet_impl *tasklet, int mt_sch_add_quota(struct mtl_sch_impl *sch, int quota_mbs); -struct mtl_sch_impl *mt_sch_get_by_socket(struct mtl_main_impl *impl, - int quota_mbs, enum mt_sch_type type, - mt_sch_mask_t mask, int socket); -static inline struct mtl_sch_impl *mt_sch_get(struct mtl_main_impl *impl, - int quota_mbs, - enum mt_sch_type type, - mt_sch_mask_t mask) { +struct mtl_sch_impl *mt_sch_get_by_socket(struct mtl_main_impl *impl, int quota_mbs, + enum mt_sch_type type, mt_sch_mask_t mask, + int socket); +static inline struct mtl_sch_impl *mt_sch_get(struct mtl_main_impl *impl, int quota_mbs, + enum mt_sch_type type, mt_sch_mask_t mask) { /* use the default socket of MTL_PORT_P */ return mt_sch_get_by_socket(impl, quota_mbs, type, mask, mt_socket_id(impl, MTL_PORT_P)); diff --git a/lib/src/mt_simd.h b/lib/src/mt_simd.h index 48b731a07..fd8bbabed 100644 --- a/lib/src/mt_simd.h +++ b/lib/src/mt_simd.h @@ -10,12 +10,12 @@ // Push the SIMD compiler flag online to build the code path #if defined(__clang__) /* "clang attribute push" support from clang 9.0 */ -#define MT_TARGET_CODE_START(Target) \ - _Pragma(STRINGIFY(clang attribute push(__attribute__((target(Target))), \ - apply_to = function))) +#define MT_TARGET_CODE_START(Target) \ + _Pragma(STRINGIFY( \ + clang attribute push(__attribute__((target(Target))), apply_to = function))) #define MT_TARGET_CODE_STOP _Pragma("clang attribute pop") #elif defined(__GNUC__) -#define MT_TARGET_CODE_START(Target) \ +#define MT_TARGET_CODE_START(Target) \ _Pragma("GCC push_options") _Pragma(STRINGIFY(GCC target(Target))) #define MT_TARGET_CODE_STOP _Pragma("GCC pop_options") #else @@ -31,13 +31,13 @@ #endif #ifdef MTL_HAS_AVX512 -#define MT_TARGET_CODE_START_AVX512 \ +#define MT_TARGET_CODE_START_AVX512 \ MT_TARGET_CODE_START("avx512f,avx512cd,avx512vl,avx512dq,avx512bw") #endif #ifdef MTL_HAS_AVX512_VBMI2 -#define MT_TARGET_CODE_START_AVX512_VBMI2 \ - MT_TARGET_CODE_START( \ +#define MT_TARGET_CODE_START_AVX512_VBMI2 \ + MT_TARGET_CODE_START( \ "avx512f,avx512cd,avx512vl,avx512dq,avx512bw,avx512vbmi,avx512vbmi2") #endif diff --git a/lib/src/mt_socket.c b/lib/src/mt_socket.c index 7f56af619..ee0f243f0 100644 --- a/lib/src/mt_socket.c +++ b/lib/src/mt_socket.c @@ -29,8 +29,7 @@ int mt_socket_get_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], return ret; } struct sockaddr_in *ipaddr = (struct sockaddr_in *)&ifr.ifr_addr; - if (ip) - memcpy(ip, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); + if (ip) memcpy(ip, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); ret = ioctl(sock, SIOCGIFNETMASK, &ifr); if (ret < 0) { @@ -39,8 +38,7 @@ int mt_socket_get_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], return ret; } ipaddr = (struct sockaddr_in *)&ifr.ifr_addr; - if (netmask) - memcpy(netmask, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); + if (netmask) memcpy(netmask, &ipaddr->sin_addr.s_addr, MTL_IP_ADDR_LEN); close(sock); return 0; @@ -62,8 +60,7 @@ int mt_socket_set_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", if_name); ifr.ifr_addr.sa_family = AF_INET; - memcpy(&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr, ip, - MTL_IP_ADDR_LEN); + memcpy(&((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr, ip, MTL_IP_ADDR_LEN); ret = ioctl(sock, SIOCSIFADDR, &ifr); if (ret < 0) { err("%s, SIOCSIFADDR fail %d for if %s\n", __func__, ret, if_name); @@ -86,8 +83,7 @@ int mt_socket_set_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], return 0; } -int mt_socket_get_if_gateway(const char *if_name, - uint8_t gateway[MTL_IP_ADDR_LEN]) { +int mt_socket_get_if_gateway(const char *if_name, uint8_t gateway[MTL_IP_ADDR_LEN]) { FILE *fp = fopen("/proc/net/route", "r"); char line[100], iface[IF_NAMESIZE], dest[9], gway[9]; @@ -196,8 +192,7 @@ int mt_socket_get_numa(const char *if_name) { dbg("%s, numa_node %d for %s\n", __func__, numa_node, if_name); if (SOCKET_ID_ANY == numa_node) { numa_node = 0; - info("%s, direct soc_id from SOCKET_ID_ANY to 0 for %s\n", __func__, - if_name); + info("%s, direct soc_id from SOCKET_ID_ANY to 0 for %s\n", __func__, if_name); } return numa_node; } @@ -232,8 +227,8 @@ static int socket_arp_get(int sfd, in_addr_t ip, struct rte_ether_addr *ea, dbg("%s, entry has been successfully retrieved\n", __func__); hw_addr = (unsigned char *)arp.arp_ha.sa_data; memcpy(ea->addr_bytes, hw_addr, RTE_ETHER_ADDR_LEN); - dbg("%s, mac addr found : %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, - hw_addr[0], hw_addr[1], hw_addr[2], hw_addr[3], hw_addr[4], hw_addr[5]); + dbg("%s, mac addr found : %02x:%02x:%02x:%02x:%02x:%02x\n", __func__, hw_addr[0], + hw_addr[1], hw_addr[2], hw_addr[3], hw_addr[4], hw_addr[5]); return 0; } @@ -305,13 +300,11 @@ int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, int max_retry = 0; int sleep_interval_ms = 100; - if (timeout_ms) - max_retry = (timeout_ms / sleep_interval_ms) + 1; + if (timeout_ms) max_retry = (timeout_ms / sleep_interval_ms) + 1; ret = socket_query_local_mac(dip, ea); if (ret >= 0) { - dbg("%s: %u.%u.%u.%u is a local ip\n", __func__, dip[0], dip[1], dip[2], - dip[3]); + dbg("%s: %u.%u.%u.%u is a local ip\n", __func__, dip[0], dip[1], dip[2], dip[3]); return 0; } @@ -347,8 +340,8 @@ int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, } retry++; if (0 == (retry % 50)) { - info("%s(%s), waiting arp from %d.%d.%d.%d\n", __func__, if_name, dip[0], - dip[1], dip[2], dip[3]); + info("%s(%s), waiting arp from %d.%d.%d.%d\n", __func__, if_name, dip[0], dip[1], + dip[2], dip[3]); } mt_sleep_ms(sleep_interval_ms); } @@ -357,8 +350,8 @@ int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, return 0; } -int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, - uint16_t queue_id, struct mt_rxq_flow *flow) { +int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, uint16_t queue_id, + struct mt_rxq_flow *flow) { const char *if_name = mt_kernel_if_name(impl, port); bool has_ip_flow = true; @@ -377,13 +370,11 @@ int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, } /* no ip flow requested */ - if (flow->flags & MT_RXQ_FLOW_F_NO_IP) - has_ip_flow = false; + if (flow->flags & MT_RXQ_FLOW_F_NO_IP) has_ip_flow = false; if (mt_get_user_params(impl)->flags & MTL_FLAG_RX_UDP_PORT_ONLY) { if (has_ip_flow) { - info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, - port); + info("%s(%d), no ip flow as MTL_FLAG_RX_UDP_PORT_ONLY is set\n", __func__, port); has_ip_flow = false; } } @@ -402,8 +393,8 @@ int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, if (mt_pmd_is_dpdk_af_xdp(impl, port)) { /* workaround now */ queue_id += MT_DPDK_AF_XDP_START_QUEUE; - int ret = mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), - dport, true); + int ret = + mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), dport, true); if (ret < 0) { err("%s(%d), udp_dp_filter fail %d\n", __func__, port, ret); return ret; @@ -413,8 +404,8 @@ int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, 0x02 /*UDP_V4_FLOW*/, sip, dip, 0, dport); } -int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, - int flow_id, uint16_t dst_port) { +int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, int flow_id, + uint16_t dst_port) { const char *if_name = mt_kernel_if_name(impl, port); if (!mt_is_manager_connected(impl)) { @@ -424,8 +415,7 @@ int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, if (mt_pmd_is_dpdk_af_xdp(impl, port)) { /* workaround now */ - mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), dst_port, - false); + mt_instance_update_udp_dp_filter(impl, if_nametoindex(if_name), dst_port, false); } return mt_instance_del_flow(impl, if_nametoindex(if_name), flow_id); @@ -445,18 +435,15 @@ int mt_socket_fd_join_multicast(struct mtl_main_impl *impl, enum mtl_port port, struct ip_mreq mreq; memset(&mreq, 0, sizeof(mreq)); memcpy(&mreq.imr_multiaddr.s_addr, flow->dip_addr, MTL_IP_ADDR_LEN); - memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), - MTL_IP_ADDR_LEN); + memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); ret = setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); } else { struct ip_mreq_source mreq; memset(&mreq, 0, sizeof(mreq)); memcpy(&mreq.imr_multiaddr.s_addr, flow->dip_addr, MTL_IP_ADDR_LEN); - memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), - MTL_IP_ADDR_LEN); + memcpy(&mreq.imr_interface.s_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); memcpy(&mreq.imr_sourceaddr.s_addr, flow->sip_addr, MTL_IP_ADDR_LEN); - ret = setsockopt(fd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, &mreq, - sizeof(mreq)); + ret = setsockopt(fd, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, &mreq, sizeof(mreq)); } return ret; @@ -479,8 +466,7 @@ int mt_socket_get_multicast_fd(struct mtl_main_impl *impl, enum mtl_port port, } else { /* return the fd */ uint8_t *ip = flow->dip_addr; - info("%s(%d), join %u.%u.%u.%u succ\n", __func__, port, ip[0], ip[1], ip[2], - ip[3]); + info("%s(%d), join %u.%u.%u.%u succ\n", __func__, port, ip[0], ip[1], ip[2], ip[3]); return mcast_fd; } } @@ -494,8 +480,7 @@ int mt_socket_get_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], return -ENOTSUP; } -int mt_socket_get_if_gateway(const char *if_name, - uint8_t gateway[MTL_IP_ADDR_LEN]) { +int mt_socket_get_if_gateway(const char *if_name, uint8_t gateway[MTL_IP_ADDR_LEN]) { MTL_MAY_UNUSED(if_name); MTL_MAY_UNUSED(gateway); return -ENOTSUP; @@ -523,8 +508,8 @@ int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, return -ENOTSUP; } -int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, - uint16_t queue_id, struct mt_rxq_flow *flow) { +int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, uint16_t queue_id, + struct mt_rxq_flow *flow) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(queue_id); @@ -532,8 +517,8 @@ int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, return -ENOTSUP; } -int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, - int flow_id, uint16_t dst_port) { +int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, int flow_id, + uint16_t dst_port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); MTL_MAY_UNUSED(flow_id); diff --git a/lib/src/mt_socket.h b/lib/src/mt_socket.h index 6f4ffbcdd..62486d109 100644 --- a/lib/src/mt_socket.h +++ b/lib/src/mt_socket.h @@ -13,8 +13,7 @@ int mt_socket_get_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], int mt_socket_set_if_ip(const char *if_name, uint8_t ip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]); -int mt_socket_get_if_gateway(const char *if_name, - uint8_t gateway[MTL_IP_ADDR_LEN]); +int mt_socket_get_if_gateway(const char *if_name, uint8_t gateway[MTL_IP_ADDR_LEN]); int mt_socket_get_if_mac(const char *if_name, struct rte_ether_addr *ea); @@ -26,11 +25,11 @@ int mt_socket_get_mac(struct mtl_main_impl *impl, const char *if_name, uint8_t dip[MTL_IP_ADDR_LEN], struct rte_ether_addr *ea, int timeout_ms); -int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, - uint16_t queue_id, struct mt_rxq_flow *flow); +int mt_socket_add_flow(struct mtl_main_impl *impl, enum mtl_port port, uint16_t queue_id, + struct mt_rxq_flow *flow); -int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, - int flow_id, uint16_t dst_port); +int mt_socket_remove_flow(struct mtl_main_impl *impl, enum mtl_port port, int flow_id, + uint16_t dst_port); int mt_socket_fd_join_multicast(struct mtl_main_impl *impl, enum mtl_port port, struct mt_rxq_flow *flow, int fd); diff --git a/lib/src/mt_stat.c b/lib/src/mt_stat.c index abce72733..2acb085c1 100644 --- a/lib/src/mt_stat.c +++ b/lib/src/mt_stat.c @@ -34,7 +34,9 @@ static int _stat_dump(struct mt_stat_mgr *mgr) { notice("STAT: failed to get lock\n"); return -EIO; } - MT_TAILQ_FOREACH(item, &mgr->head, next) { item->cb_func(item->cb_priv); } + MT_TAILQ_FOREACH(item, &mgr->head, next) { + item->cb_func(item->cb_priv); + } stat_unlock(mgr); return 0; @@ -106,8 +108,7 @@ int mt_stat_register(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv, } item->cb_func = cb; item->cb_priv = priv; - if (name) - snprintf(item->name, ST_MAX_NAME_LEN - 1, "%s", name); + if (name) snprintf(item->name, ST_MAX_NAME_LEN - 1, "%s", name); stat_lock(mgr); MT_TAILQ_INSERT_TAIL(&mgr->head, item, next); @@ -117,8 +118,7 @@ int mt_stat_register(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv, return 0; } -int mt_stat_unregister(struct mtl_main_impl *impl, mt_stat_cb_t cb, - void *priv) { +int mt_stat_unregister(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv) { struct mt_stat_mgr *mgr = get_stat_mgr(impl); struct mt_stat_item *item, *tmp_item; @@ -160,8 +160,7 @@ int mt_stat_init(struct mtl_main_impl *impl) { } mtl_thread_setname(mgr->stat_tid, "mtl_stat"); - if (!p->dump_period_s) - p->dump_period_s = MT_STAT_INTERVAL_S_DEFAULT; + if (!p->dump_period_s) p->dump_period_s = MT_STAT_INTERVAL_S_DEFAULT; mgr->dump_period_us = (uint64_t)p->dump_period_s * US_PER_S; rte_eal_alarm_set(mgr->dump_period_us, stat_alarm_handler, mgr); @@ -182,8 +181,7 @@ int mt_stat_uinit(struct mtl_main_impl *impl) { } ret = rte_eal_alarm_cancel(stat_alarm_handler, impl); - if (ret < 0) - err("%s, alarm cancel fail %d\n", __func__, ret); + if (ret < 0) err("%s, alarm cancel fail %d\n", __func__, ret); if (mgr->stat_tid) { rte_atomic32_set(&mgr->stat_stop, 1); stat_wakeup_thread(mgr); diff --git a/lib/src/mt_stat.h b/lib/src/mt_stat.h index 03f74ba2c..d8890acd4 100644 --- a/lib/src/mt_stat.h +++ b/lib/src/mt_stat.h @@ -10,8 +10,7 @@ int mt_stat_init(struct mtl_main_impl *impl); int mt_stat_uinit(struct mtl_main_impl *impl); -int mt_stat_register(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv, - char *name); +int mt_stat_register(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv, char *name); int mt_stat_unregister(struct mtl_main_impl *impl, mt_stat_cb_t cb, void *priv); static inline uint64_t mt_stat_dump_period_us(struct mtl_main_impl *impl) { diff --git a/lib/src/mt_tap.c b/lib/src/mt_tap.c index e9ec5e3ee..f9fc90e0f 100644 --- a/lib/src/mt_tap.c +++ b/lib/src/mt_tap.c @@ -17,8 +17,7 @@ static struct mtl_main_impl *tap_main_impl; static struct rte_ring *tap_tx_ring; -typedef ULONG (*GetAdaptersInfo_type)(PIP_ADAPTER_INFO AdapterInfo, - PULONG SizePointer); +typedef ULONG (*GetAdaptersInfo_type)(PIP_ADAPTER_INFO AdapterInfo, PULONG SizePointer); static GetAdaptersInfo_type GetAdaptersInfo_ptr = NULL; @@ -27,14 +26,12 @@ static inline void tap_set_global_impl(struct mtl_main_impl *impl) { } static inline bool io_active(struct overlapped_io *io) { - return io->iostate == IOSTATE_QUEUED || - io->iostate == IOSTATE_IMMEDIATE_RETURN; + return io->iostate == IOSTATE_QUEUED || io->iostate == IOSTATE_IMMEDIATE_RETURN; } static struct mtl_main_impl *tap_get_global_impl(void) { struct mtl_main_impl *impl = tap_main_impl; - if (!impl) - err("%s, global impl not init\n", __func__); + if (!impl) err("%s, global impl not init\n", __func__); return impl; } @@ -42,8 +39,7 @@ static void tap_rxq_pool_free(struct rte_mbuf *pool) { struct rte_mbuf *mbuf = pool; uint16_t nb_segs = 1; - if (mbuf == NULL) - return; + if (mbuf == NULL) return; while (mbuf->next) { mbuf = mbuf->next; @@ -76,8 +72,7 @@ static int tap_put_mbuf(struct rte_ring *packet_ring, void *mbuf) { return 0; } -static void *tap_get_mbuf(struct rte_ring *packet_ring, void **usrptr, - uint16_t *len) { +static void *tap_get_mbuf(struct rte_ring *packet_ring, void **usrptr, uint16_t *len) { struct rte_mbuf *pkt; int ret; if (!packet_ring) { @@ -91,57 +86,54 @@ static void *tap_get_mbuf(struct rte_ring *packet_ring, void **usrptr, info("%s, tap ring is empty\n", __func__); return NULL; } - if (len) - *len = pkt->data_len; - if (usrptr) - *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, 0); + if (len) *len = pkt->data_len; + if (usrptr) *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, 0); return pkt; } -static int overlapped_result(struct mt_cni_impl *cni, - struct overlapped_io *io) { +static int overlapped_result(struct mt_cni_impl *cni, struct overlapped_io *io) { int ret = -1; BOOL status; struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; switch (io->iostate) { - case IOSTATE_QUEUED: - status = GetOverlappedResult(tap_ctx->tap_handle, &io->overlapped, - &io->size, FALSE); - if (status) { - ret = io->size; - io->status = 0; - io->iostate = IOSTATE_IMMEDIATE_RETURN; - assert(ResetEvent(io->overlapped.hEvent)); - } else { - ret = -1; - if (GetLastError() != ERROR_IO_INCOMPLETE) { - io->iostate = IOSTATE_INITIAL; - io->status = -1; + case IOSTATE_QUEUED: + status = + GetOverlappedResult(tap_ctx->tap_handle, &io->overlapped, &io->size, FALSE); + if (status) { + ret = io->size; + io->status = 0; + io->iostate = IOSTATE_IMMEDIATE_RETURN; assert(ResetEvent(io->overlapped.hEvent)); + } else { + ret = -1; + if (GetLastError() != ERROR_IO_INCOMPLETE) { + io->iostate = IOSTATE_INITIAL; + io->status = -1; + assert(ResetEvent(io->overlapped.hEvent)); + } } - } - break; + break; - case IOSTATE_IMMEDIATE_RETURN: - io->iostate = IOSTATE_INITIAL; - assert(ResetEvent(io->overlapped.hEvent)); - if (io->status) { - SetLastError(io->status); - ret = -1; - } else { - ret = io->size; - } - break; + case IOSTATE_IMMEDIATE_RETURN: + io->iostate = IOSTATE_INITIAL; + assert(ResetEvent(io->overlapped.hEvent)); + if (io->status) { + SetLastError(io->status); + ret = -1; + } else { + ret = io->size; + } + break; - case IOSTATE_INITIAL: - SetLastError(ERROR_INVALID_FUNCTION); - ret = -1; - err("%s : Overlapped result wrong state\n", __func__); - break; + case IOSTATE_INITIAL: + SetLastError(ERROR_INVALID_FUNCTION); + ret = -1; + err("%s : Overlapped result wrong state\n", __func__); + break; - default: - assert(0); + default: + assert(0); } return ret; } @@ -175,8 +167,7 @@ static long readv(struct mt_cni_impl *cni, struct iovec *iov, int count) { rlen = 0; } } - if (rlen <= 0) - return rlen; + if (rlen <= 0) return rlen; total += rlen; iov++; count--; @@ -192,9 +183,8 @@ static long writev(struct mt_cni_impl *cni, struct iovec *iov, int count) { while (count) { wlen = 0; assert(ResetEvent(tap_ctx->writes.overlapped.hEvent)); - status = WriteFile(tap_ctx->tap_handle, (const char *)iov->iov_base, - iov->iov_len, &tap_ctx->writes.size, - &tap_ctx->writes.overlapped); + status = WriteFile(tap_ctx->tap_handle, (const char *)iov->iov_base, iov->iov_len, + &tap_ctx->writes.size, &tap_ctx->writes.overlapped); if (status) { tap_ctx->writes.iostate = IOSTATE_IMMEDIATE_RETURN; assert(SetEvent(tap_ctx->writes.overlapped.hEvent)); @@ -211,8 +201,7 @@ static long writev(struct mt_cni_impl *cni, struct iovec *iov, int count) { tap_ctx->writes.status = err; } } - if (wlen <= 0) - return totallen; + if (wlen <= 0) return totallen; totallen += wlen; iov++; count--; @@ -224,10 +213,8 @@ static uint16_t tap_tx_packet(struct mt_cni_impl *cni, struct rte_mbuf **bufs, uint16_t nb_pkts) { int ret = 0; struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; - if (unlikely(nb_pkts == 0)) - return 0; - if (io_active(&tap_ctx->writes)) - ret = overlapped_result(cni, &tap_ctx->writes); + if (unlikely(nb_pkts == 0)) return 0; + if (io_active(&tap_ctx->writes)) ret = overlapped_result(cni, &tap_ctx->writes); if (tap_ctx->writes.iostate == IOSTATE_INITIAL) { struct rte_mbuf *mbuf = bufs[0]; @@ -253,13 +240,10 @@ static uint16_t tap_rx_packet(struct mt_cni_impl *cni, struct rte_mbuf **bufs, uint16_t num_rx = 0; unsigned long num_rx_bytes = 0; struct tap_rt_context *tap_ctx = (struct tap_rt_context *)cni->tap_context; - if (!nb_pkts) - return 0; - if (io_active(&tap_ctx->reads)) - overlapped_result(cni, &tap_ctx->reads); + if (!nb_pkts) return 0; + if (io_active(&tap_ctx->reads)) overlapped_result(cni, &tap_ctx->reads); - if (tap_ctx->reads.iostate == IOSTATE_INITIAL) - readv(cni, *tap_ctx->iovecs, 1); + if (tap_ctx->reads.iostate == IOSTATE_INITIAL) readv(cni, *tap_ctx->iovecs, 1); len = tap_ctx->reads.size; if (len > 0) { @@ -272,30 +256,25 @@ static uint16_t tap_rx_packet(struct mt_cni_impl *cni, struct rte_mbuf **bufs, while (1) { struct rte_mbuf *buf = rte_pktmbuf_alloc(tap_ctx->mp); if (unlikely(!buf)) { - if (!new_tail || !seg) - goto end; + if (!new_tail || !seg) goto end; seg->next = NULL; tap_rxq_pool_free(mbuf); goto end; } seg = seg ? seg->next : mbuf; - if (tap_ctx->pool == mbuf) - tap_ctx->pool = buf; - if (new_tail) - new_tail->next = buf; + if (tap_ctx->pool == mbuf) tap_ctx->pool = buf; + if (new_tail) new_tail->next = buf; new_tail = buf; new_tail->next = seg->next; (*tap_ctx->iovecs)[mbuf->nb_segs].iov_len = buf->buf_len - data_off; - (*tap_ctx->iovecs)[mbuf->nb_segs].iov_base = - (char *)buf->buf_addr + data_off; + (*tap_ctx->iovecs)[mbuf->nb_segs].iov_base = (char *)buf->buf_addr + data_off; seg->data_len = RTE_MIN(seg->buf_len - data_off, len); seg->data_off = data_off; len -= seg->data_len; - if (len <= 0) - break; + if (len <= 0) break; mbuf->nb_segs++; /* First segment has headroom, not the others */ data_off = 0; @@ -308,8 +287,8 @@ static uint16_t tap_rx_packet(struct mt_cni_impl *cni, struct rte_mbuf **bufs, return num_rx; } -static struct rte_flow *tap_create_flow(struct mt_cni_impl *cni, - uint16_t port_id, uint16_t q) { +static struct rte_flow *tap_create_flow(struct mt_cni_impl *cni, uint16_t port_id, + uint16_t q) { struct rte_flow_attr attr; struct rte_flow_item pattern[4]; struct rte_flow_action action[2]; @@ -342,9 +321,8 @@ static struct rte_flow *tap_create_flow(struct mt_cni_impl *cni, memset(&ipv4_mask.hdr.dst_addr, 0xFF, MTL_IP_ADDR_LEN); rte_memcpy(&ipv4_spec.hdr.dst_addr, tap_ctx->ip_addr, MTL_IP_ADDR_LEN); - info("Flow bind to ip address inet %02x %02x %02x %02x \n", - tap_ctx->ip_addr[0], tap_ctx->ip_addr[1], tap_ctx->ip_addr[2], - tap_ctx->ip_addr[3]); + info("Flow bind to ip address inet %02x %02x %02x %02x \n", tap_ctx->ip_addr[0], + tap_ctx->ip_addr[1], tap_ctx->ip_addr[2], tap_ctx->ip_addr[3]); memset(&attr, 0, sizeof(attr)); attr.ingress = 1; @@ -366,8 +344,8 @@ static struct rte_flow *tap_create_flow(struct mt_cni_impl *cni, ret = rte_flow_validate(port_id, &attr, pattern, action, &error); if (ret < 0) { - err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, - port_id, ret, q, mt_string_safe(error.message)); + err("%s(%d), rte_flow_validate fail %d for queue %d, %s\n", __func__, port_id, ret, q, + mt_string_safe(error.message)); return NULL; } @@ -392,10 +370,10 @@ static struct rte_flow *tap_create_flow(struct mt_cni_impl *cni, "0000000000010000000000020806000108000604000000000000000101010101000" "0000000020" "2020202"); - snprintf(pkt_buf, 12, "%02x%02x%02x%02x%02x%02x", - tap_ctx->mac_addr.addr_bytes[0], tap_ctx->mac_addr.addr_bytes[1], - tap_ctx->mac_addr.addr_bytes[2], tap_ctx->mac_addr.addr_bytes[3], - tap_ctx->mac_addr.addr_bytes[4], tap_ctx->mac_addr.addr_bytes[5]); + snprintf(pkt_buf, 12, "%02x%02x%02x%02x%02x%02x", tap_ctx->mac_addr.addr_bytes[0], + tap_ctx->mac_addr.addr_bytes[1], tap_ctx->mac_addr.addr_bytes[2], + tap_ctx->mac_addr.addr_bytes[3], tap_ctx->mac_addr.addr_bytes[4], + tap_ctx->mac_addr.addr_bytes[5]); info("Flow bind to mac address %12.12s \n", pkt_buf); snprintf(msk_buf, 84, "%s", "FFFFFFFFFFFF000000000000FFFF000000000000000000000000000000000000000" @@ -416,8 +394,8 @@ static struct rte_flow *tap_create_flow(struct mt_cni_impl *cni, r_flow = rte_flow_create(port_id, &attr, pattern, action, &error); if (!r_flow) { - err("%s(%d), rte_flow_create 2 fail for queue %d, %s\n", __func__, port_id, - q, mt_string_safe(error.message)); + err("%s(%d), rte_flow_create 2 fail for queue %d, %s\n", __func__, port_id, q, + mt_string_safe(error.message)); return NULL; } return r_flow; @@ -439,8 +417,7 @@ static int tap_get_ipaddress(struct mt_cni_impl *cni) { return 1; } - GetAdaptersInfo_ptr = - (GetAdaptersInfo_type)((void *)GetProcAddress(library, function)); + GetAdaptersInfo_ptr = (GetAdaptersInfo_type)((void *)GetProcAddress(library, function)); if (GetAdaptersInfo_ptr == NULL) { err("GetProcAddress(\"%s\", \"%s\")\n", library_name, function); return 1; @@ -452,8 +429,7 @@ static int tap_get_ipaddress(struct mt_cni_impl *cni) { return 1; } - if (GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen) == - ERROR_BUFFER_OVERFLOW) { + if (GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { free(pAdapterInfo); pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); if (pAdapterInfo == NULL) { @@ -462,15 +438,13 @@ static int tap_get_ipaddress(struct mt_cni_impl *cni) { } } - if ((dwRetVal = GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen)) == - NO_ERROR) { + if ((dwRetVal = GetAdaptersInfo_ptr(pAdapterInfo, &ulOutBufLen)) == NO_ERROR) { pAdapter = pAdapterInfo; while (pAdapter) { dbg("\tAdapter Name: \t%s\n", pAdapter->AdapterName); if (strcmpi(tap_ctx->tap_name, pAdapter->AdapterName) == 0) { dbg("Found ip address %s\n", pAdapter->IpAddressList.IpAddress.String); - inet_pton(AF_INET, pAdapter->IpAddressList.IpAddress.String, - tap_ctx->ip_addr); + inet_pton(AF_INET, pAdapter->IpAddressList.IpAddress.String, tap_ctx->ip_addr); } dbg("\tAdapter Desc: \t%s\n", pAdapter->Description); dbg("\tIP Address: \t%s\n", pAdapter->IpAddressList.IpAddress.String); @@ -515,8 +489,7 @@ static int tap_bkg_thread(void *arg) { for (i = 0; i < num_ports; i++) { count = rte_ring_count(tap_tx_ring); while (count) { - if (!pkts_tx[0]) - pkts_tx[0] = tap_get_mbuf(tap_tx_ring, &data, &tx); + if (!pkts_tx[0]) pkts_tx[0] = tap_get_mbuf(tap_tx_ring, &data, &tx); if (pkts_tx[0]) { tx = tap_tx_packet(cni, pkts_tx, 1); if (tx > 0) { @@ -551,8 +524,7 @@ static int tap_queues_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < num_ports; i++) { if (cni->tap_tx_q[i]) { struct rte_mbuf *pad = mt_get_pad(impl, i); - if (pad) - mt_txq_flush(cni->tap_tx_q[i], pad); + if (pad) mt_txq_flush(cni->tap_tx_q[i], pad); mt_txq_put(cni->tap_tx_q[i]); cni->tap_tx_q[i] = NULL; } @@ -561,12 +533,9 @@ static int tap_queues_uinit(struct mtl_main_impl *impl) { cni->tap_rx_q[i] = NULL; } } - if (tap_ctx->iovecs) - rte_free(tap_ctx->iovecs); - if (tap_ctx->pool) - tap_rxq_pool_free(tap_ctx->pool); - if (tap_ctx->mp) - mt_mempool_free(tap_ctx->mp); + if (tap_ctx->iovecs) rte_free(tap_ctx->iovecs); + if (tap_ctx->pool) tap_rxq_pool_free(tap_ctx->pool); + if (tap_ctx->mp) mt_mempool_free(tap_ctx->mp); return 0; } @@ -583,8 +552,7 @@ static int configure_tap() { struct rte_mbuf **tmp = &tap_ctx->pool; struct rte_mempool *mbuf_pool = mt_mempool_create( impl, 0, "tap", inf->nb_rx_desc + ST_TX_VIDEO_SESSIONS_RING_SIZE, - MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), - ST_PKT_MAX_ETHER_BYTES); + MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), ST_PKT_MAX_ETHER_BYTES); if (!mbuf_pool) { err("%s tap mempool create fail\n", __func__); return -ENOMEM; @@ -628,42 +596,41 @@ static bool tap_open_device(struct mt_cni_impl *cni, char *path; char tap_device_path[MAX_PATH]; - path = - strrchr(dev_ifx_detail->DevicePath, '\\'); // find the last character '\' - if (path) // remove the character '\' + path = strrchr(dev_ifx_detail->DevicePath, '\\'); // find the last character '\' + if (path) // remove the character '\' path++; else return false; snprintf(tap_ctx->tap_name, sizeof(tap_ctx->tap_name), "%s", path); - snprintf(tap_device_path, sizeof(tap_device_path), "%s%s%s", - USERMODEDEVICEDIR, path, TAP_WIN_SUFFIX); + snprintf(tap_device_path, sizeof(tap_device_path), "%s%s%s", USERMODEDEVICEDIR, path, + TAP_WIN_SUFFIX); info("%s create file path %s\n", __func__, tap_device_path); - tap_ctx->tap_handle = CreateFile( - tap_device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, - FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); + tap_ctx->tap_handle = + CreateFile(tap_device_path, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, + FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); if (tap_ctx->tap_handle == NULL) { err("CreateFile failed on device: %s\n", tap_device_path); return false; } ULONG mtu = 0; DWORD len; - if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMTU, &mtu, - sizeof(mtu), &mtu, sizeof(mtu), &len, NULL)) { + if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMTU, &mtu, sizeof(mtu), &mtu, + sizeof(mtu), &len, NULL)) { info("TAP-Windows MTU=%d\n", (int)mtu); } ULONG info[3]; memset(info, 0, sizeof(info)); - if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPVER, &info, - sizeof(info), &info, sizeof(info), &len, NULL)) { + if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPVER, &info, sizeof(info), + &info, sizeof(info), &len, NULL)) { info("TAP-Windows Driver Version %d.%d %s\n", (int)info[0], (int)info[1], (info[2] ? "(DEBUG)" : "")); } unsigned char mac[6]; memset(mac, 0, sizeof(mac)); - if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMAC, &mac, - sizeof(mac), &mac, sizeof(mac), &len, NULL)) { + if (DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_GET_TAPMAC, &mac, sizeof(mac), &mac, + sizeof(mac), &len, NULL)) { rte_memcpy(tap_ctx->mac_addr.addr_bytes, mac, 6); info("TAP-Windows Mac address %02x-%02x-%02x-%02x-%02x-%02x\n", tap_ctx->mac_addr.addr_bytes[0], tap_ctx->mac_addr.addr_bytes[1], @@ -674,9 +641,10 @@ static bool tap_open_device(struct mt_cni_impl *cni, ULONG status = TRUE; if (!DeviceIoControl(tap_ctx->tap_handle, ST_IOCTL_SET_TAPSTATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL)) { - info("WARNING: The TAP-Windows driver rejected a " - "TAP_WIN_IOCTL_SET_MEDIA_STATUS " - "DeviceIoControl call.\n"); + info( + "WARNING: The TAP-Windows driver rejected a " + "TAP_WIN_IOCTL_SET_MEDIA_STATUS " + "DeviceIoControl call.\n"); } memset(&tap_ctx->writes, 0, sizeof(tap_ctx->writes)); @@ -695,8 +663,7 @@ static bool tap_open_device(struct mt_cni_impl *cni, for (int i = 0; i < num_ports; i++) { if (rte_eth_dev_mac_addr_add(mt_port_id(impl, i), &tap_ctx->mac_addr, 0)) err("%s bind to mac failed \n", __func__); - tap_create_flow(cni, mt_port_id(impl, i), - mt_rxq_queue_id(cni->tap_rx_q[i])); + tap_create_flow(cni, mt_port_id(impl, i), mt_rxq_queue_id(cni->tap_rx_q[i])); } } return true; @@ -710,8 +677,7 @@ static HDEVINFO get_tap_device_information_set(HDEVINFO tapinfo, HDEVINFO tapset; /* obtain the driver interface for this device */ - ret = SetupDiGetDeviceInstanceId(tapinfo, tapdata, tap_id, sizeof(tap_id), - &size); + ret = SetupDiGetDeviceInstanceId(tapinfo, tapdata, tap_id, sizeof(tap_id), &size); if (ret) { dbg("%s tap device id %s\n", __func__, tap_id); tapset = SetupDiGetClassDevs(&GUID_NDIS_LAN_CLASS, tap_id, NULL, @@ -727,8 +693,7 @@ static HDEVINFO get_tap_device_information_set(HDEVINFO tapinfo, } } -static PSP_DEVICE_INTERFACE_DETAIL_DATA -get_tap_device_interface_detail(HDEVINFO tapset) { +static PSP_DEVICE_INTERFACE_DETAIL_DATA get_tap_device_interface_detail(HDEVINFO tapset) { BOOL ret; DWORD size = 0; SP_DEVICE_INTERFACE_DATA tap_interface_data; @@ -741,17 +706,15 @@ get_tap_device_interface_detail(HDEVINFO tapset) { &tap_interface_data); if (ret) { size = 0; - ret = SetupDiGetDeviceInterfaceDetail(tapset, &tap_interface_data, NULL, 0, - &size, NULL); + ret = SetupDiGetDeviceInterfaceDetail(tapset, &tap_interface_data, NULL, 0, &size, + NULL); if (!ret) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { tap_interface_detail = calloc(size, sizeof(char)); if (tap_interface_detail) { - tap_interface_detail->cbSize = - sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); + tap_interface_detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); ret = SetupDiGetDeviceInterfaceDetail(tapset, &tap_interface_data, - tap_interface_detail, size, - NULL, NULL); + tap_interface_detail, size, NULL, NULL); if (!ret) { err("Error get tap interface detail"); free(tap_interface_detail); @@ -793,27 +756,21 @@ static int tap_device_init(struct mt_cni_impl *cni) { device_index++; /* we only want to enumerate net class devices */ memset(sz_buffer, 0, sizeof(sz_buffer)); - SetupDiGetDeviceRegistryProperty(dev_info, &device_info_data, - SPDRP_DEVICEDESC, NULL, (PBYTE)&sz_buffer, - sizeof(sz_buffer), NULL); + SetupDiGetDeviceRegistryProperty(dev_info, &device_info_data, SPDRP_DEVICEDESC, NULL, + (PBYTE)&sz_buffer, sizeof(sz_buffer), NULL); if (strstr(sz_buffer, TAP_WIN_DRIVERNAME) != NULL) { di_set = get_tap_device_information_set(dev_info, &device_info_data); - if (di_set == INVALID_HANDLE_VALUE) - continue; + if (di_set == INVALID_HANDLE_VALUE) continue; dev_ifx_detail = get_tap_device_interface_detail(di_set); if (!dev_ifx_detail) { - if (di_set != INVALID_HANDLE_VALUE) - SetupDiDestroyDeviceInfoList(di_set); + if (di_set != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(di_set); continue; } else { if (tap_open_device(cni, dev_ifx_detail)) { - if (dev_ifx_detail) - free(dev_ifx_detail); - if (di_set != INVALID_HANDLE_VALUE) - SetupDiDestroyDeviceInfoList(di_set); + if (dev_ifx_detail) free(dev_ifx_detail); + if (di_set != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(di_set); - if (dev_info != INVALID_HANDLE_VALUE) - SetupDiDestroyDeviceInfoList(dev_info); + if (dev_info != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(dev_info); break; } @@ -822,8 +779,7 @@ static int tap_device_init(struct mt_cni_impl *cni) { memset(&device_info_data, 0, sizeof(SP_DEVINFO_DATA)); device_info_data.cbSize = sizeof(SP_DEVINFO_DATA); } - if (dev_info != INVALID_HANDLE_VALUE) - SetupDiDestroyDeviceInfoList(dev_info); + if (dev_info != INVALID_HANDLE_VALUE) SetupDiDestroyDeviceInfoList(dev_info); if (tap_ctx->tap_handle) return 0; else @@ -842,16 +798,14 @@ static int tap_device_uninit(struct mtl_main_impl *impl) { mt_free_mbufs(&pkts_rx, 1); pkts_rx = tap_get_mbuf(tap_tx_ring, &data, &tx); } - if (tap_ctx->tap_handle) - CloseHandle(tap_ctx->tap_handle); + if (tap_ctx->tap_handle) CloseHandle(tap_ctx->tap_handle); return 0; } static const struct rte_eth_txconf dev_tx_port_conf = {.tx_rs_thresh = 1, .tx_free_thresh = 1}; -static int tap_queues_init(struct mtl_main_impl *impl, - struct mt_cni_impl *cni) { +static int tap_queues_init(struct mtl_main_impl *impl, struct mt_cni_impl *cni) { int num_ports = mt_num_ports(impl); uint16_t nb_tx_desc; @@ -879,9 +833,8 @@ static int tap_queues_init(struct mtl_main_impl *impl, } nb_tx_desc = mt_if_nb_tx_desc(impl, i); socket_id = rte_eth_dev_socket_id(mt_port_id(impl, i)); - ret = rte_eth_tx_queue_setup(mt_port_id(impl, i), - mt_txq_queue_id(cni->tap_tx_q[i]), nb_tx_desc, - socket_id, &dev_tx_port_conf); + ret = rte_eth_tx_queue_setup(mt_port_id(impl, i), mt_txq_queue_id(cni->tap_tx_q[i]), + nb_tx_desc, socket_id, &dev_tx_port_conf); if (ret < 0) { err("%s(%d), rte_eth_tx_queue_setup fail %d\n", __func__, i, ret); return ret; @@ -941,19 +894,16 @@ int mt_tap_init(struct mtl_main_impl *impl) { cni->tap_context = calloc(sizeof(struct tap_rt_context), sizeof(char)); tap_ctx = (struct tap_rt_context *)cni->tap_context; tap_ctx->flow_control = - true; // if do not need flow control, should set NIC to promiscuous mode + true; // if do not need flow control, should set NIC to promiscuous mode ret = tap_queues_init(impl, cni); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tap_device_init(cni); - if (ret < 0) - return ret; + if (ret < 0) return ret; rte_atomic32_set(&cni->stop_tap, 0); tap_ctx->has_lcore = false; - ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_TAP, - mt_socket_id(impl, MTL_PORT_P)); + ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_TAP, mt_socket_id(impl, MTL_PORT_P)); if (ret < 0) { err("%s, get lcore fail %d\n", __func__, ret); mt_tap_uinit(impl); @@ -983,8 +933,7 @@ int mt_tap_uinit(struct mtl_main_impl *impl) { tap_queues_uinit(impl); tap_device_uninit(impl); tap_set_global_impl(NULL); - if (cni->tap_context) - free(cni->tap_context); + if (cni->tap_context) free(cni->tap_context); info("%s, succ\n", __func__); return 0; } diff --git a/lib/src/mt_tap.h b/lib/src/mt_tap.h index c61d71ef8..46aff32f3 100644 --- a/lib/src/mt_tap.h +++ b/lib/src/mt_tap.h @@ -16,7 +16,7 @@ #define TAP_IOV_DEFAULT_MAX 1024 -#define ST_TAP_CTL_CODE(code) \ +#define ST_TAP_CTL_CODE(code) \ CTL_CODE(FILE_DEVICE_UNKNOWN, code, METHOD_BUFFERED, FILE_ANY_ACCESS) #define ST_IOCTL_GET_TAPMAC ST_TAP_CTL_CODE(1) @@ -44,7 +44,7 @@ enum windows_driver_type { #define IOSTATE_INITIAL 0 #define IOSTATE_QUEUED 1 /* overlapped I/O has been queued */ -#define IOSTATE_IMMEDIATE_RETURN \ +#define IOSTATE_IMMEDIATE_RETURN \ 2 /* I/O function returned immediately without queueing */ struct overlapped_io { @@ -88,8 +88,7 @@ static inline int mt_tap_uinit(struct mtl_main_impl *impl) { MTL_MAY_UNUSED(impl); return 0; } -static inline int mt_tap_handle(struct mtl_main_impl *impl, - enum mtl_port port) { +static inline int mt_tap_handle(struct mtl_main_impl *impl, enum mtl_port port) { MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(port); return -EIO; diff --git a/lib/src/mt_usdt.h b/lib/src/mt_usdt.h index 168e75b4f..cef468556 100644 --- a/lib/src/mt_usdt.h +++ b/lib/src/mt_usdt.h @@ -12,50 +12,46 @@ #include "mt_usdt_provider.h" #define MT_DTRACE_PROBE(provider, probe) DTRACE_PROBE(provider, probe) -#define MT_DTRACE_PROBE1(provider, probe, parm1) \ - DTRACE_PROBE1(provider, probe, parm1) -#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ +#define MT_DTRACE_PROBE1(provider, probe, parm1) DTRACE_PROBE1(provider, probe, parm1) +#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ DTRACE_PROBE2(provider, probe, parm1, parm2) -#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ +#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) -#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ +#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) -#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ +#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) -#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, \ - parm6) \ +#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6) \ DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6) -#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, \ - parm6, parm7) \ - DTRACE_PROBE7(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, \ - parm7) +#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, \ + parm7) \ + DTRACE_PROBE7(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, parm7) #else -#define MT_DTRACE_PROBE(provider, probe) \ - do { \ +#define MT_DTRACE_PROBE(provider, probe) \ + do { \ } while (0) -#define MT_DTRACE_PROBE1(provider, probe, parm1) \ - do { \ +#define MT_DTRACE_PROBE1(provider, probe, parm1) \ + do { \ } while (0) -#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ - do { \ +#define MT_DTRACE_PROBE2(provider, probe, parm1, parm2) \ + do { \ } while (0) -#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ - do { \ +#define MT_DTRACE_PROBE3(provider, probe, parm1, parm2, parm3) \ + do { \ } while (0) -#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ - do { \ +#define MT_DTRACE_PROBE4(provider, probe, parm1, parm2, parm3, parm4) \ + do { \ } while (0) -#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ - do { \ +#define MT_DTRACE_PROBE5(provider, probe, parm1, parm2, parm3, parm4, parm5) \ + do { \ } while (0) -#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, \ - parm6) \ - do { \ +#define MT_DTRACE_PROBE6(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6) \ + do { \ } while (0) -#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, \ - parm6, parm7) \ - do { \ +#define MT_DTRACE_PROB76(provider, probe, parm1, parm2, parm3, parm4, parm5, parm6, \ + parm7) \ + do { \ } while (0) #define SYS_LOG_MSG_ENABLED() (0) @@ -85,189 +81,172 @@ #endif -#define MT_USDT_PTP_MSG(port, stage, value) \ +#define MT_USDT_PTP_MSG(port, stage, value) \ MT_DTRACE_PROBE3(ptp, ptp_msg, port, stage, value) -#define MT_USDT_PTP_RESULT(port, delta, correct) \ +#define MT_USDT_PTP_RESULT(port, delta, correct) \ MT_DTRACE_PROBE3(ptp, ptp_result, port, delta, correct) -#define MT_USDT_SYS_LOG_MSG(level, msg) \ - MT_DTRACE_PROBE2(sys, log_msg, level, msg) +#define MT_USDT_SYS_LOG_MSG(level, msg) MT_DTRACE_PROBE2(sys, log_msg, level, msg) #define MT_USDT_SYS_LOG_MSG_ENABLED() SYS_LOG_MSG_ENABLED() #define MT_SYS_TASKLET_TIME_MEASURE() MT_DTRACE_PROBE(sys, tasklet_time_measure) -#define MT_USDT_TASKLET_TIME_MEASURE_ENABLED() \ - SYS_TASKLET_TIME_MEASURE_ENABLED() +#define MT_USDT_TASKLET_TIME_MEASURE_ENABLED() SYS_TASKLET_TIME_MEASURE_ENABLED() -#define MT_SYS_SESSIONS_TIME_MEASURE() \ - MT_DTRACE_PROBE(sys, sessions_time_measure) -#define MT_USDT_SESSIONS_TIME_MEASURE_ENABLED() \ - SYS_SESSIONS_TIME_MEASURE_ENABLED() +#define MT_SYS_SESSIONS_TIME_MEASURE() MT_DTRACE_PROBE(sys, sessions_time_measure) +#define MT_USDT_SESSIONS_TIME_MEASURE_ENABLED() SYS_SESSIONS_TIME_MEASURE_ENABLED() -#define MT_USDT_CNI_PCAP_DUMP(port, file, pkts) \ +#define MT_USDT_CNI_PCAP_DUMP(port, file, pkts) \ MT_DTRACE_PROBE3(sys, cni_pcap_dump, port, file, pkts) #define MT_USDT_CNI_PCAP_DUMP_ENABLED() SYS_CNI_PCAP_DUMP_ENABLED() -#define MT_USDT_ST20P_TX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST20P_TX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st20p, tx_frame_get, idx, f_idx, va) -#define MT_USDT_ST20P_TX_FRAME_PUT(idx, f_idx, va, stat) \ +#define MT_USDT_ST20P_TX_FRAME_PUT(idx, f_idx, va, stat) \ MT_DTRACE_PROBE4(st20p, tx_frame_put, idx, f_idx, va, stat) -#define MT_USDT_ST20P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ +#define MT_USDT_ST20P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ MT_DTRACE_PROBE3(st20p, tx_frame_done, idx, f_idx, tmstamp) -#define MT_USDT_ST20P_TX_FRAME_NEXT(idx, f_idx) \ +#define MT_USDT_ST20P_TX_FRAME_NEXT(idx, f_idx) \ MT_DTRACE_PROBE2(st20p, tx_frame_next, idx, f_idx) -#define MT_USDT_ST20P_TX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST20P_TX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st20p, tx_frame_dump, idx, file, va, sz) #define MT_USDT_ST20P_TX_FRAME_DUMP_ENABLED() ST20P_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20P_RX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST20P_RX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st20p, rx_frame_get, idx, f_idx, va) -#define MT_USDT_ST20P_RX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST20P_RX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st20p, rx_frame_put, idx, f_idx, va) -#define MT_USDT_ST20P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st20p, rx_frame_available, idx, f_idx, va, tmstamp, \ - data_size) -#define MT_USDT_ST20P_RX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST20P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE5(st20p, rx_frame_available, idx, f_idx, va, tmstamp, data_size) +#define MT_USDT_ST20P_RX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st20p, rx_frame_dump, idx, file, va, sz) #define MT_USDT_ST20P_RX_FRAME_DUMP_ENABLED() ST20P_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30P_TX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST30P_TX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, tx_frame_get, idx, f_idx, va) -#define MT_USDT_ST30P_TX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST30P_TX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, tx_frame_put, idx, f_idx, va) -#define MT_USDT_ST30P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ +#define MT_USDT_ST30P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ MT_DTRACE_PROBE3(st30p, tx_frame_done, idx, f_idx, tmstamp) -#define MT_USDT_ST30P_TX_FRAME_NEXT(idx, f_idx) \ +#define MT_USDT_ST30P_TX_FRAME_NEXT(idx, f_idx) \ MT_DTRACE_PROBE2(st30p, tx_frame_next, idx, f_idx) -#define MT_USDT_ST30P_TX_FRAME_DUMP(idx, file, frames) \ +#define MT_USDT_ST30P_TX_FRAME_DUMP(idx, file, frames) \ MT_DTRACE_PROBE3(st30p, tx_frame_dump, idx, file, frames) #define MT_USDT_ST30P_TX_FRAME_DUMP_ENABLED() ST30P_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30P_RX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST30P_RX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, rx_frame_get, idx, f_idx, va) -#define MT_USDT_ST30P_RX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST30P_RX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st30p, rx_frame_put, idx, f_idx, va) -#define MT_USDT_ST30P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st30p, rx_frame_available, idx, f_idx, va, tmstamp, \ - data_size) -#define MT_USDT_ST30P_RX_FRAME_DUMP(idx, file, frames) \ +#define MT_USDT_ST30P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE5(st30p, rx_frame_available, idx, f_idx, va, tmstamp, data_size) +#define MT_USDT_ST30P_RX_FRAME_DUMP(idx, file, frames) \ MT_DTRACE_PROBE3(st30p, rx_frame_dump, idx, file, frames) #define MT_USDT_ST30P_RX_FRAME_DUMP_ENABLED() ST30P_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp) \ +#define MT_USDT_ST20_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp) \ MT_DTRACE_PROBE5(st20, tx_frame_next, m_idx, s_idx, f_idx, va, tmstamp) -#define MT_USDT_ST20_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST20_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st20, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) -#define MT_USDT_ST20_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST20_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st20, tx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST20_TX_FRAME_DUMP_ENABLED() ST20_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, \ - data_size) \ - MT_DTRACE_PROBE6(st20, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, \ - data_size) -#define MT_USDT_ST20_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST20_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE6(st20, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, data_size) +#define MT_USDT_ST20_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st20, rx_frame_put, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST20_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ +#define MT_USDT_ST20_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ MT_DTRACE_PROBE3(st20, rx_no_framebuffer, m_idx, s_idx, tmstamp) -#define MT_USDT_ST20_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST20_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st20, rx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST20_RX_FRAME_DUMP_ENABLED() ST20_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST20_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ +#define MT_USDT_ST20_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ MT_DTRACE_PROBE5(st20, rx_pcap_dump, m_idx, s_idx, s_port, file, pkts) #define MT_USDT_ST20_RX_PCAP_DUMP_ENABLED() ST20_RX_PCAP_DUMP_ENABLED() -#define MT_USDT_ST20_RX_FRAME_INCOMPLETE(m_idx, s_idx, f_idx, tmstamp, \ - data_size, expect_size) \ - MT_DTRACE_PROBE6(st20, rx_frame_incomplete, m_idx, s_idx, f_idx, tmstamp, \ - data_size, expect_size) +#define MT_USDT_ST20_RX_FRAME_INCOMPLETE(m_idx, s_idx, f_idx, tmstamp, data_size, \ + expect_size) \ + MT_DTRACE_PROBE6(st20, rx_frame_incomplete, m_idx, s_idx, f_idx, tmstamp, data_size, \ + expect_size) -#define MT_USDT_ST30_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST30_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st30, tx_frame_next, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST30_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST30_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st30, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) -#define MT_USDT_ST30_TX_FRAME_DUMP(m_idx, s_idx, file, frames) \ +#define MT_USDT_ST30_TX_FRAME_DUMP(m_idx, s_idx, file, frames) \ MT_DTRACE_PROBE4(st30, tx_frame_dump, m_idx, s_idx, file, frames) #define MT_USDT_ST30_TX_FRAME_DUMP_ENABLED() ST30_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, \ - data_size) \ - MT_DTRACE_PROBE6(st30, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, \ - data_size) -#define MT_USDT_ST30_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST30_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE6(st30, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, data_size) +#define MT_USDT_ST30_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st30, rx_frame_put, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST30_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ +#define MT_USDT_ST30_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ MT_DTRACE_PROBE3(st30, rx_no_framebuffer, m_idx, s_idx, tmstamp) -#define MT_USDT_ST30_RX_FRAME_DUMP(m_idx, s_idx, file, frames) \ +#define MT_USDT_ST30_RX_FRAME_DUMP(m_idx, s_idx, file, frames) \ MT_DTRACE_PROBE4(st30, rx_frame_dump, m_idx, s_idx, file, frames) #define MT_USDT_ST30_RX_FRAME_DUMP_ENABLED() ST30_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST30_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ +#define MT_USDT_ST30_RX_PCAP_DUMP(m_idx, s_idx, s_port, file, pkts) \ MT_DTRACE_PROBE5(st30, rx_pcap_dump, m_idx, s_idx, s_port, file, pkts) #define MT_USDT_ST30_RX_PCAP_DUMP_ENABLED() ST30_RX_PCAP_DUMP_ENABLED() -#define MT_USDT_ST40_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, meta_num, \ - total_udw) \ - MT_DTRACE_PROBE6(st40, tx_frame_next, m_idx, s_idx, f_idx, va, meta_num, \ - total_udw) -#define MT_USDT_ST40_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST40_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, meta_num, total_udw) \ + MT_DTRACE_PROBE6(st40, tx_frame_next, m_idx, s_idx, f_idx, va, meta_num, total_udw) +#define MT_USDT_ST40_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st40, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) #define MT_USDT_ST40_RX_MBUF_AVAILABLE(m_idx, s_idx, mbuf, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st40, rx_mbuf_available, m_idx, s_idx, mbuf, tmstamp, \ - data_size) -#define MT_USDT_ST40_RX_MBUF_PUT(m_idx, s_idx, mbuf) \ + MT_DTRACE_PROBE5(st40, rx_mbuf_available, m_idx, s_idx, mbuf, tmstamp, data_size) +#define MT_USDT_ST40_RX_MBUF_PUT(m_idx, s_idx, mbuf) \ MT_DTRACE_PROBE3(st40, rx_mbuf_put, m_idx, s_idx, mbuf) -#define MT_USDT_ST40_RX_MBUF_ENQUEUE_FAIL(m_idx, s_idx, mbuf, tmstamp) \ +#define MT_USDT_ST40_RX_MBUF_ENQUEUE_FAIL(m_idx, s_idx, mbuf, tmstamp) \ MT_DTRACE_PROBE4(st40, rx_mbuf_enqueue_fail, m_idx, s_idx, mbuf, tmstamp) -#define MT_USDT_ST22_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp, sz) \ +#define MT_USDT_ST22_TX_FRAME_NEXT(m_idx, s_idx, f_idx, va, tmstamp, sz) \ MT_DTRACE_PROBE6(st22, tx_frame_next, m_idx, s_idx, f_idx, va, tmstamp, sz) -#define MT_USDT_ST22_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ +#define MT_USDT_ST22_TX_FRAME_DONE(m_idx, s_idx, f_idx, tmstamp) \ MT_DTRACE_PROBE4(st22, tx_frame_done, m_idx, s_idx, f_idx, tmstamp) -#define MT_USDT_ST22_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST22_TX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st22, tx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST22_TX_FRAME_DUMP_ENABLED() ST22_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, \ - data_size) \ - MT_DTRACE_PROBE6(st22, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, \ - data_size) -#define MT_USDT_ST22_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ +#define MT_USDT_ST22_RX_FRAME_AVAILABLE(m_idx, s_idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE6(st22, rx_frame_available, m_idx, s_idx, f_idx, va, tmstamp, data_size) +#define MT_USDT_ST22_RX_FRAME_PUT(m_idx, s_idx, f_idx, va) \ MT_DTRACE_PROBE4(st22, rx_frame_put, m_idx, s_idx, f_idx, va) -#define MT_USDT_ST22_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ +#define MT_USDT_ST22_RX_NO_FRAMEBUFFER(m_idx, s_idx, tmstamp) \ MT_DTRACE_PROBE3(st22, rx_no_framebuffer, m_idx, s_idx, tmstamp) -#define MT_USDT_ST22_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ +#define MT_USDT_ST22_RX_FRAME_DUMP(m_idx, s_idx, file, va, sz) \ MT_DTRACE_PROBE5(st22, rx_frame_dump, m_idx, s_idx, file, va, sz) #define MT_USDT_ST22_RX_FRAME_DUMP_ENABLED() ST22_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22P_TX_FRAME_GET(idx, f_idx, va) \ +#define MT_USDT_ST22P_TX_FRAME_GET(idx, f_idx, va) \ MT_DTRACE_PROBE3(st22p, tx_frame_get, idx, f_idx, va) -#define MT_USDT_ST22P_TX_FRAME_PUT(idx, f_idx, va, stat, size) \ +#define MT_USDT_ST22P_TX_FRAME_PUT(idx, f_idx, va, stat, size) \ MT_DTRACE_PROBE5(st22p, tx_frame_put, idx, f_idx, va, stat, size) -#define MT_USDT_ST22P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ +#define MT_USDT_ST22P_TX_FRAME_DONE(idx, f_idx, tmstamp) \ MT_DTRACE_PROBE3(st22p, tx_frame_done, idx, f_idx, tmstamp) -#define MT_USDT_ST22P_TX_FRAME_NEXT(idx, f_idx) \ +#define MT_USDT_ST22P_TX_FRAME_NEXT(idx, f_idx) \ MT_DTRACE_PROBE2(st22p, tx_frame_next, idx, f_idx) -#define MT_USDT_ST22P_TX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST22P_TX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st22p, tx_frame_dump, idx, file, va, sz) #define MT_USDT_ST22P_TX_FRAME_DUMP_ENABLED() ST22P_TX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22P_RX_FRAME_GET(idx, f_idx, va, sz) \ +#define MT_USDT_ST22P_RX_FRAME_GET(idx, f_idx, va, sz) \ MT_DTRACE_PROBE4(st22p, rx_frame_get, idx, f_idx, va, sz) -#define MT_USDT_ST22P_RX_FRAME_PUT(idx, f_idx, va) \ +#define MT_USDT_ST22P_RX_FRAME_PUT(idx, f_idx, va) \ MT_DTRACE_PROBE3(st22p, rx_frame_put, idx, f_idx, va) -#define MT_USDT_ST22P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ - MT_DTRACE_PROBE5(st22p, rx_frame_available, idx, f_idx, va, tmstamp, \ - data_size) -#define MT_USDT_ST22P_RX_FRAME_DUMP(idx, file, va, sz) \ +#define MT_USDT_ST22P_RX_FRAME_AVAILABLE(idx, f_idx, va, tmstamp, data_size) \ + MT_DTRACE_PROBE5(st22p, rx_frame_available, idx, f_idx, va, tmstamp, data_size) +#define MT_USDT_ST22P_RX_FRAME_DUMP(idx, file, va, sz) \ MT_DTRACE_PROBE4(st22p, rx_frame_dump, idx, file, va, sz) #define MT_USDT_ST22P_RX_FRAME_DUMP_ENABLED() ST22P_RX_FRAME_DUMP_ENABLED() -#define MT_USDT_ST22P_TX_ENCODE_GET(idx, f_idx, src, dst) \ +#define MT_USDT_ST22P_TX_ENCODE_GET(idx, f_idx, src, dst) \ MT_DTRACE_PROBE4(st22p, tx_encode_get, idx, f_idx, src, dst) -#define MT_USDT_ST22P_TX_ENCODE_PUT(idx, f_idx, src, dst, result, data_size) \ - MT_DTRACE_PROBE6(st22p, tx_encode_put, idx, f_idx, src, dst, result, \ - data_size) -#define MT_USDT_ST22P_RX_DECODE_GET(idx, f_idx, src, dst, data_size) \ +#define MT_USDT_ST22P_TX_ENCODE_PUT(idx, f_idx, src, dst, result, data_size) \ + MT_DTRACE_PROBE6(st22p, tx_encode_put, idx, f_idx, src, dst, result, data_size) +#define MT_USDT_ST22P_RX_DECODE_GET(idx, f_idx, src, dst, data_size) \ MT_DTRACE_PROBE5(st22p, rx_decode_get, idx, f_idx, src, dst, data_size) -#define MT_USDT_ST22P_RX_DECODE_PUT(idx, f_idx, src, dst, result) \ +#define MT_USDT_ST22P_RX_DECODE_PUT(idx, f_idx, src, dst, result) \ MT_DTRACE_PROBE5(st22p, rx_decode_put, idx, f_idx, src, dst, result) #endif diff --git a/lib/src/mt_util.c b/lib/src/mt_util.c index b2b44c618..d71c3ffc6 100644 --- a/lib/src/mt_util.c +++ b/lib/src/mt_util.c @@ -61,22 +61,19 @@ int mt_asan_check(void) { leak_cnt++; } if (leak_cnt) - info("%s, \033[33mfound %d rte_malloc leak(s) in total\033[0m\n", __func__, - leak_cnt); + info("%s, \033[33mfound %d rte_malloc leak(s) in total\033[0m\n", __func__, leak_cnt); mt_pthread_mutex_destroy(&g_bt_mutex); if (g_mt_mempool_create_cnt != 0) { - err("%s, detect not free mempool, leak cnt %d\n", __func__, - g_mt_mempool_create_cnt); + err("%s, detect not free mempool, leak cnt %d\n", __func__, g_mt_mempool_create_cnt); } return 0; } void *mt_rte_malloc_socket(size_t sz, int socket) { - void *p = - rte_malloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); + void *p = rte_malloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); if (p) { /* insert bt_info to list */ struct mt_backtrace_info *bt_info = mt_zmalloc(sizeof(*bt_info)); @@ -95,8 +92,7 @@ void *mt_rte_malloc_socket(size_t sz, int socket) { } void *mt_rte_zmalloc_socket(size_t sz, int socket) { - void *p = - rte_zmalloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); + void *p = rte_zmalloc_socket(MT_DPDK_LIB_NAME, sz, RTE_CACHE_LINE_SIZE, socket); if (p) { /* insert bt_info to list */ struct mt_backtrace_info *bt_info = mt_zmalloc(sizeof(*bt_info)); @@ -118,13 +114,11 @@ void mt_rte_free(void *p) { /* remove bt_info from list */ struct mt_backtrace_info *bt_info, *tmp_bt_info; mt_pthread_mutex_lock(&g_bt_mutex); - for (bt_info = MT_TAILQ_FIRST(&g_bt_head); bt_info != NULL; - bt_info = tmp_bt_info) { + for (bt_info = MT_TAILQ_FIRST(&g_bt_head); bt_info != NULL; bt_info = tmp_bt_info) { tmp_bt_info = MT_TAILQ_NEXT(bt_info, next); if (bt_info->pointer == p) { MT_TAILQ_REMOVE(&g_bt_head, bt_info, next); - if (bt_info->bt_strings) - mt_free(bt_info->bt_strings); + if (bt_info->bt_strings) mt_free(bt_info->bt_strings); mt_free(bt_info); break; } @@ -151,8 +145,7 @@ bool mt_bitmap_test_and_set(uint8_t *bitmap, int idx) { uint8_t bits = bitmap[pos]; /* already set */ - if (bits & (0x1 << off)) - return true; + if (bits & (0x1 << off)) return true; /* set the bit */ bitmap[pos] = bits | (0x1 << off); @@ -165,8 +158,7 @@ bool mt_bitmap_test_and_unset(uint8_t *bitmap, int idx) { uint8_t bits = bitmap[pos]; /* already unset */ - if (!(bits & (0x1 << off))) - return true; + if (!(bits & (0x1 << off))) return true; /* unset the bit */ bitmap[pos] = bits & (UINT8_MAX ^ (0x1 << off)); @@ -178,13 +170,11 @@ int mt_ring_dequeue_clean(struct rte_ring *ring) { struct rte_mbuf *pkt; unsigned int count = rte_ring_count(ring); - if (count) - info("%s, count %d for ring %s\n", __func__, count, ring->name); + if (count) info("%s, count %d for ring %s\n", __func__, count, ring->name); /* dequeue and free all mbufs in the ring */ do { ret = rte_ring_sc_dequeue(ring, (void **)&pkt); - if (ret < 0) - break; + if (ret < 0) break; rte_pktmbuf_free(pkt); } while (1); @@ -223,8 +213,8 @@ enum mtl_port mt_port_by_name(struct mtl_main_impl *impl, const char *name) { return MTL_PORT_MAX; } -int mt_build_port_map(struct mtl_main_impl *impl, char **ports, - enum mtl_port *maps, int num_ports) { +int mt_build_port_map(struct mtl_main_impl *impl, char **ports, enum mtl_port *maps, + int num_ports) { struct mtl_init_params *p = mt_get_user_params(impl); int main_num_ports = p->num_ports; @@ -263,8 +253,7 @@ int mt_pacing_train_result_add(struct mtl_main_impl *impl, enum mtl_port port, struct mt_pacing_train_result *ptr = &mt_if(impl, port)->pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (ptr[i].rl_bps) - continue; + if (ptr[i].rl_bps) continue; ptr[i].rl_bps = rl_bps; ptr[i].pacing_pad_interval = pad_interval; return 0; @@ -274,9 +263,8 @@ int mt_pacing_train_result_add(struct mtl_main_impl *impl, enum mtl_port port, return -ENOMEM; } -int mt_pacing_train_result_search(struct mtl_main_impl *impl, - enum mtl_port port, uint64_t rl_bps, - float *pad_interval) { +int mt_pacing_train_result_search(struct mtl_main_impl *impl, enum mtl_port port, + uint64_t rl_bps, float *pad_interval) { struct mt_pacing_train_result *ptr = &mt_if(impl, port)->pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { @@ -290,15 +278,12 @@ int mt_pacing_train_result_search(struct mtl_main_impl *impl, return -EINVAL; } -int mt_audio_pacing_train_result_add(struct mtl_main_impl *impl, - enum mtl_port port, uint64_t input_bps, - uint64_t profiled_bps) { - struct mt_audio_pacing_train_result *ptr = - &mt_if(impl, port)->audio_pt_results[0]; +int mt_audio_pacing_train_result_add(struct mtl_main_impl *impl, enum mtl_port port, + uint64_t input_bps, uint64_t profiled_bps) { + struct mt_audio_pacing_train_result *ptr = &mt_if(impl, port)->audio_pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { - if (ptr[i].input_bps) - continue; + if (ptr[i].input_bps) continue; ptr[i].input_bps = input_bps; ptr[i].profiled_bps = profiled_bps; return 0; @@ -308,11 +293,9 @@ int mt_audio_pacing_train_result_add(struct mtl_main_impl *impl, return -ENOMEM; } -int mt_audio_pacing_train_result_search(struct mtl_main_impl *impl, - enum mtl_port port, uint64_t input_bps, - uint64_t *profiled_bps) { - struct mt_audio_pacing_train_result *ptr = - &mt_if(impl, port)->audio_pt_results[0]; +int mt_audio_pacing_train_result_search(struct mtl_main_impl *impl, enum mtl_port port, + uint64_t input_bps, uint64_t *profiled_bps) { + struct mt_audio_pacing_train_result *ptr = &mt_if(impl, port)->audio_pt_results[0]; for (int i = 0; i < MT_MAX_RL_ITEMS; i++) { if (input_bps == ptr[i].input_bps) { @@ -340,11 +323,9 @@ void st_video_rtp_dump(enum mtl_port port, int idx, char *tag, extra_rtp = (struct st20_rfc4175_extra_rtp_hdr *)&rtp[1]; } - if (tag) - info("%s(%d,%d), %s\n", __func__, port, idx, tag); + if (tag) info("%s(%d,%d), %s\n", __func__, port, idx, tag); info("tmstamp: 0x%x, seq_id: %u\n", tmstamp, seq_id); - info("line: no %d offset %d len %d\n", line1_number, line1_offset, - line1_length); + info("line: no %d offset %d len %d\n", line1_number, line1_offset, line1_length); if (extra_rtp) { uint16_t line2_number = ntohs(extra_rtp->row_number); uint16_t line2_offset = ntohs(extra_rtp->row_offset); @@ -355,8 +336,7 @@ void st_video_rtp_dump(enum mtl_port port, int idx, char *tag, } } -void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, - struct rte_mbuf *m) { +void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, struct rte_mbuf *m) { struct rte_ether_hdr *eth = rte_pktmbuf_mtod(m, struct rte_ether_hdr *); size_t hdr_offset = sizeof(struct rte_ether_hdr); struct rte_ipv4_hdr *ipv4 = NULL; @@ -365,15 +345,14 @@ void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, uint8_t *mac; uint8_t *ip; - if (tag) - info("%s(%d,%d), %s\n", __func__, port, idx, tag); + if (tag) info("%s(%d,%d), %s\n", __func__, port, idx, tag); info("ether_type 0x%x\n", ether_type); mac = &mt_eth_d_addr(eth)->addr_bytes[0]; - info("d_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], - mac[4], mac[5]); + info("d_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], + mac[5]); mac = &mt_eth_s_addr(eth)->addr_bytes[0]; - info("s_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], - mac[4], mac[5]); + info("s_mac %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], + mac[5]); if (ether_type == RTE_ETHER_TYPE_IPV4) { ipv4 = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, hdr_offset); @@ -389,8 +368,7 @@ void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, info("s_ip %d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); } if (udp) { - info("dst_port %d src_port %d\n", ntohs(udp->dst_port), - ntohs(udp->src_port)); + info("dst_port %d src_port %d\n", ntohs(udp->dst_port), ntohs(udp->src_port)); } } @@ -399,32 +377,30 @@ void mt_mbuf_dump(enum mtl_port port, int idx, char *tag, struct rte_mbuf *m) { rte_pktmbuf_dump(stdout, m, m->data_len); } -void mt_lcore_dump() { rte_lcore_dump(stdout); } +void mt_lcore_dump() { + rte_lcore_dump(stdout); +} void mt_eth_link_dump(uint16_t port_id) { struct rte_eth_link eth_link; rte_eth_link_get_nowait(port_id, ð_link); - critical( - "%s(%d), link_speed %dg link_status %d link_duplex %d link_autoneg %d\n", - __func__, port_id, eth_link.link_speed / 1000, eth_link.link_status, - eth_link.link_duplex, eth_link.link_autoneg); + critical("%s(%d), link_speed %dg link_status %d link_duplex %d link_autoneg %d\n", + __func__, port_id, eth_link.link_speed / 1000, eth_link.link_status, + eth_link.link_duplex, eth_link.link_autoneg); } -void mt_eth_macaddr_dump(enum mtl_port port, char *tag, - struct rte_ether_addr *mac_addr) { - if (tag) - info("%s(%d), %s\n", __func__, port, tag); +void mt_eth_macaddr_dump(enum mtl_port port, char *tag, struct rte_ether_addr *mac_addr) { + if (tag) info("%s(%d), %s\n", __func__, port, tag); uint8_t *addr = &mac_addr->addr_bytes[0]; - info("%02x:%02x:%02x:%02x:%02x:%02x\n", addr[0], addr[1], addr[2], addr[3], - addr[4], addr[5]); + info("%02x:%02x:%02x:%02x:%02x:%02x\n", addr[0], addr[1], addr[2], addr[3], addr[4], + addr[5]); } -struct rte_mbuf *mt_build_pad(struct mtl_main_impl *impl, - struct rte_mempool *mempool, enum mtl_port port, - uint16_t ether_type, uint16_t len) { +struct rte_mbuf *mt_build_pad(struct mtl_main_impl *impl, struct rte_mempool *mempool, + enum mtl_port port, uint16_t ether_type, uint16_t len) { struct rte_ether_addr src_mac; struct rte_mbuf *pad; struct rte_ether_hdr *eth_hdr; @@ -468,16 +444,14 @@ int mt_macaddr_get(struct mtl_main_impl *impl, enum mtl_port port, void *mt_mempool_mem_addr(struct rte_mempool *mp) { struct rte_mempool_memhdr *hdr = STAILQ_FIRST(&mp->mem_list); if (mp->nb_mem_chunks != 1) - err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, - mp->nb_mem_chunks); + err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, mp->nb_mem_chunks); return hdr->addr; } size_t mt_mempool_mem_size(struct rte_mempool *mp) { struct rte_mempool_memhdr *hdr = STAILQ_FIRST(&mp->mem_list); if (mp->nb_mem_chunks != 1) - err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, - mp->nb_mem_chunks); + err("%s(%s), invalid nb_mem_chunks %u\n", __func__, mp->name, mp->nb_mem_chunks); return hdr->len; } @@ -493,16 +467,15 @@ int mt_mempool_dump(struct rte_mempool *mp) { void *end_addr = base_addr + mt_mempool_mem_size(mp); void *last_hdr = NULL; - info("%s(%s), %u mbufs object size %u, memory range: %p to %p\n", __func__, - mp->name, populated_size, mt_mempool_obj_size(mp), base_addr, end_addr); + info("%s(%s), %u mbufs object size %u, memory range: %p to %p\n", __func__, mp->name, + populated_size, mt_mempool_obj_size(mp), base_addr, end_addr); for (uint32_t i = 0; i < populated_size; i++) { mbufs[i] = rte_pktmbuf_alloc(mp); - if (!mbufs[i]) - break; + if (!mbufs[i]) break; mbufs_alloced++; void *hdr = rte_pktmbuf_mtod(mbufs[i], void *); - info("%s(%s), mbuf %u hdr %p step %" PRId64 "\n", __func__, mp->name, i, - hdr, hdr - last_hdr); + info("%s(%s), mbuf %u hdr %p step %" PRId64 "\n", __func__, mp->name, i, hdr, + hdr - last_hdr); last_hdr = hdr; } @@ -510,11 +483,10 @@ int mt_mempool_dump(struct rte_mempool *mp) { return 0; } -struct rte_mempool * -mt_mempool_create_by_ops(struct mtl_main_impl *impl, const char *name, - unsigned int n, unsigned int cache_size, - uint16_t priv_size, uint16_t element_size, - const char *ops_name, int socket_id) { +struct rte_mempool *mt_mempool_create_by_ops(struct mtl_main_impl *impl, const char *name, + unsigned int n, unsigned int cache_size, + uint16_t priv_size, uint16_t element_size, + const char *ops_name, int socket_id) { char name_with_idx[32]; /* 32 is the max length allowed by mempool api, in our lib we use concise names so it won't exceed this length */ @@ -529,30 +501,27 @@ mt_mempool_create_by_ops(struct mtl_main_impl *impl, const char *name, * optimum size (in terms of memory usage) for a mempool * is when n is a power of two minus one: n = (2^q - 1). */ - while (ret - 1 <= n && ret) - ret <<= 1; + while (ret - 1 <= n && ret) ret <<= 1; - dbg("%s(%d), optimize number of elements in the mbuf pool from %d to %d\n ", - __func__, socket_id, n, ret - 1); + dbg("%s(%d), optimize number of elements in the mbuf pool from %d to %d\n ", __func__, + socket_id, n, ret - 1); n = ret - 1; if (cache_size && (element_size % cache_size)) /* align to cache size */ element_size = (element_size / cache_size + 1) * cache_size; - snprintf(name_with_idx, sizeof(name_with_idx), "%s_%d", name, - impl->mempool_idx++); + snprintf(name_with_idx, sizeof(name_with_idx), "%s_%d", name, impl->mempool_idx++); data_room_size = element_size + MT_MBUF_HEADROOM_SIZE; /* include head room */ - mbuf_pool = - rte_pktmbuf_pool_create_by_ops(name_with_idx, n, cache_size, priv_size, - data_room_size, socket_id, ops_name); + mbuf_pool = rte_pktmbuf_pool_create_by_ops(name_with_idx, n, cache_size, priv_size, + data_room_size, socket_id, ops_name); if (!mbuf_pool) { - err("%s(%d), fail(%s) for %s, n %u\n", __func__, socket_id, - rte_strerror(rte_errno), name, n); + err("%s(%d), fail(%s) for %s, n %u\n", __func__, socket_id, rte_strerror(rte_errno), + name, n); } else { size_m = (float)n * (data_room_size + priv_size) / (1024 * 1024); - info("%s(%d), succ at %p size %fm n %u d %u for %s\n", __func__, socket_id, - mbuf_pool, size_m, n, element_size, name_with_idx); + info("%s(%d), succ at %p size %fm n %u d %u for %s\n", __func__, socket_id, mbuf_pool, + size_m, n, element_size, name_with_idx); #ifdef MTL_HAS_ASAN g_mt_mempool_create_cnt++; #endif @@ -566,8 +535,7 @@ int mt_mempool_free(struct rte_mempool *mp) { if (in_use_count) { /* failed to free the mempool, caused by the mbuf is still in nix tx queues? */ - warn("%s, still has %d mbuf in mempool %s\n", __func__, in_use_count, - mp->name); + warn("%s, still has %d mbuf in mempool %s\n", __func__, in_use_count, mp->name); return 0; } @@ -615,8 +583,7 @@ uint16_t mt_rf1071_check_sum(uint8_t *p, size_t len, bool convert) { struct mt_u64_fifo *mt_u64_fifo_init(int size, int soc_id) { struct mt_u64_fifo *fifo = mt_rte_zmalloc_socket(sizeof(*fifo), soc_id); - if (!fifo) - return NULL; + if (!fifo) return NULL; uint64_t *data = mt_rte_zmalloc_socket(sizeof(*data) * size, soc_id); if (!data) { mt_rte_free(fifo); @@ -646,8 +613,7 @@ int mt_u64_fifo_put(struct mt_u64_fifo *fifo, const uint64_t item) { } fifo->data[fifo->write_idx] = item; fifo->write_idx++; - if (fifo->write_idx >= fifo->size) - fifo->write_idx = 0; + if (fifo->write_idx >= fifo->size) fifo->write_idx = 0; fifo->used++; return 0; } @@ -660,14 +626,12 @@ int mt_u64_fifo_get(struct mt_u64_fifo *fifo, uint64_t *item) { } *item = fifo->data[fifo->read_idx]; fifo->read_idx++; - if (fifo->read_idx >= fifo->size) - fifo->read_idx = 0; + if (fifo->read_idx >= fifo->size) fifo->read_idx = 0; fifo->used--; return 0; } -int mt_u64_fifo_put_bulk(struct mt_u64_fifo *fifo, const uint64_t *items, - uint32_t n) { +int mt_u64_fifo_put_bulk(struct mt_u64_fifo *fifo, const uint64_t *items, uint32_t n) { if (fifo->used + n > fifo->size) { dbg("%s, fail as fifo is full(%d)\n", __func__, fifo->size); return -EIO; @@ -676,15 +640,13 @@ int mt_u64_fifo_put_bulk(struct mt_u64_fifo *fifo, const uint64_t *items, for (i = 0; i < n; i++) { fifo->data[fifo->write_idx] = items[i]; fifo->write_idx++; - if (fifo->write_idx >= fifo->size) - fifo->write_idx = 0; + if (fifo->write_idx >= fifo->size) fifo->write_idx = 0; } fifo->used += n; return 0; } -int mt_u64_fifo_get_bulk(struct mt_u64_fifo *fifo, uint64_t *items, - uint32_t n) { +int mt_u64_fifo_get_bulk(struct mt_u64_fifo *fifo, uint64_t *items, uint32_t n) { if (fifo->used < n) { dbg("%s, fail as no enough item\n", __func__); return -EIO; @@ -693,8 +655,7 @@ int mt_u64_fifo_get_bulk(struct mt_u64_fifo *fifo, uint64_t *items, for (i = 0; i < n; i++) { items[i] = fifo->data[fifo->read_idx]; fifo->read_idx++; - if (fifo->read_idx >= fifo->size) - fifo->read_idx = 0; + if (fifo->read_idx >= fifo->size) fifo->read_idx = 0; } fifo->used -= n; return 0; @@ -706,8 +667,7 @@ int mt_u64_fifo_read_back(struct mt_u64_fifo *fifo, uint64_t *item) { return -EIO; } int idx = fifo->write_idx - 1; - if (idx < 0) - idx = fifo->size - 1; + if (idx < 0) idx = fifo->size - 1; *item = fifo->data[idx]; return 0; } @@ -731,14 +691,13 @@ int mt_u64_fifo_read_any(struct mt_u64_fifo *fifo, uint64_t *item, int skip) { return -EIO; } int read_idx = fifo->read_idx + skip; - if (read_idx >= fifo->size) - read_idx -= fifo->size; + if (read_idx >= fifo->size) read_idx -= fifo->size; *item = fifo->data[read_idx]; return 0; } -int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo *fifo, uint64_t *items, - uint32_t n, int skip) { +int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo *fifo, uint64_t *items, uint32_t n, + int skip) { if (fifo->used < n) { dbg("%s, fail as no enough item\n", __func__); return -EIO; @@ -748,14 +707,12 @@ int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo *fifo, uint64_t *items, return -EIO; } int read_idx = fifo->read_idx + skip; - if (read_idx >= fifo->size) - read_idx -= fifo->size; + if (read_idx >= fifo->size) read_idx -= fifo->size; uint32_t i = 0; for (i = 0; i < n; i++) { items[i] = fifo->data[read_idx]; read_idx++; - if (read_idx >= fifo->size) - read_idx = 0; + if (read_idx >= fifo->size) read_idx = 0; } return 0; @@ -773,31 +730,23 @@ int mt_fifo_mbuf_clean(struct mt_u64_fifo *fifo) { return 0; } -struct mt_cvt_dma_ctx *mt_cvt_dma_ctx_init(int fifo_size, int soc_id, - int type_num) { +struct mt_cvt_dma_ctx *mt_cvt_dma_ctx_init(int fifo_size, int soc_id, int type_num) { struct mt_cvt_dma_ctx *ctx = mt_rte_zmalloc_socket(sizeof(*ctx), soc_id); - if (!ctx) - return NULL; + if (!ctx) return NULL; ctx->fifo = mt_u64_fifo_init(fifo_size, soc_id); - if (!ctx->fifo) - goto fail; + if (!ctx->fifo) goto fail; ctx->tran = mt_rte_zmalloc_socket(sizeof(*ctx->tran) * type_num, soc_id); - if (!ctx->tran) - goto fail; + if (!ctx->tran) goto fail; ctx->done = mt_rte_zmalloc_socket(sizeof(*ctx->done) * type_num, soc_id); - if (!ctx->done) - goto fail; + if (!ctx->done) goto fail; return ctx; fail: - if (ctx->fifo) - mt_u64_fifo_uinit(ctx->fifo); - if (ctx->tran) - mt_rte_free(ctx->tran); - if (ctx->done) - mt_rte_free(ctx->done); + if (ctx->fifo) mt_u64_fifo_uinit(ctx->fifo); + if (ctx->tran) mt_rte_free(ctx->tran); + if (ctx->done) mt_rte_free(ctx->done); mt_rte_free(ctx); return NULL; } @@ -812,8 +761,7 @@ int mt_cvt_dma_ctx_uinit(struct mt_cvt_dma_ctx *ctx) { int mt_cvt_dma_ctx_push(struct mt_cvt_dma_ctx *ctx, int type) { int ret = mt_u64_fifo_put(ctx->fifo, type); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx->tran[type]++; dbg("%s, tran %d for type %d\n", __func__, ctx->tran[type], type); return 0; @@ -822,8 +770,7 @@ int mt_cvt_dma_ctx_push(struct mt_cvt_dma_ctx *ctx, int type) { int mt_cvt_dma_ctx_pop(struct mt_cvt_dma_ctx *ctx) { uint64_t type = 0; int ret = mt_u64_fifo_get(ctx->fifo, &type); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx->done[type]++; dbg("%s, done %d for type %" PRIu64 "\n", __func__, ctx->done[type], type); return 0; @@ -855,8 +802,7 @@ int mt_run_cmd(const char *cmd, char *out, size_t out_len) { int mt_ip_addr_check(uint8_t *ip) { for (int i = 0; i < MTL_IP_ADDR_LEN; i++) { - if (ip[i]) - return 0; + if (ip[i]) return 0; } return -EINVAL; @@ -870,16 +816,14 @@ int st_tx_dest_info_check(struct st_tx_dest_info *dst, int num_ports) { ip = dst->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(dst->dip_addr[0], dst->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -895,16 +839,14 @@ int st_rx_source_info_check(struct st_rx_source_info *src, int num_ports) { ip = src->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(src->ip_addr[0], src->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -918,12 +860,10 @@ int st_frame_trans_uinit(struct st_frame_trans *frame) { /* check if it's still shared */ uint16_t sh_info_refcnt = rte_mbuf_ext_refcnt_read(&frame->sh_info); if (sh_info_refcnt) - warn("%s(%d), sh_info still active, refcnt %d\n", __func__, idx, - sh_info_refcnt); + warn("%s(%d), sh_info still active, refcnt %d\n", __func__, idx, sh_info_refcnt); int refcnt = rte_atomic32_read(&frame->refcnt); - if (refcnt) - warn("%s(%d), refcnt not zero %d\n", __func__, idx, refcnt); + if (refcnt) warn("%s(%d), refcnt not zero %d\n", __func__, idx, refcnt); if (frame->addr) { if (frame->flags & ST_FT_FLAG_RTE_MALLOC) { @@ -949,8 +889,7 @@ int st_frame_trans_uinit(struct st_frame_trans *frame) { return 0; } -int st_vsync_calculate(struct mtl_main_impl *impl, - struct st_vsync_info *vsync) { +int st_vsync_calculate(struct mtl_main_impl *impl, struct st_vsync_info *vsync) { uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); uint64_t next_epoch; uint64_t to_next_epochs; @@ -993,16 +932,13 @@ static const char *rdma_ud_port_prefix = "rdma_ud:"; enum mtl_pmd_type mtl_pmd_by_port_name(const char *port) { dbg("%s, port %s\n", __func__, port); - if (strncmp(port, dpdk_afxdp_port_prefix, strlen(dpdk_afxdp_port_prefix)) == - 0) + if (strncmp(port, dpdk_afxdp_port_prefix, strlen(dpdk_afxdp_port_prefix)) == 0) return MTL_PMD_DPDK_AF_XDP; - else if (strncmp(port, dpdk_afpkt_port_prefix, - strlen(dpdk_afpkt_port_prefix)) == 0) + else if (strncmp(port, dpdk_afpkt_port_prefix, strlen(dpdk_afpkt_port_prefix)) == 0) return MTL_PMD_DPDK_AF_PACKET; else if (strncmp(port, kernel_port_prefix, strlen(kernel_port_prefix)) == 0) return MTL_PMD_KERNEL_SOCKET; - else if (strncmp(port, native_afxdp_port_prefix, - strlen(native_afxdp_port_prefix)) == 0) + else if (strncmp(port, native_afxdp_port_prefix, strlen(native_afxdp_port_prefix)) == 0) return MTL_PMD_NATIVE_AF_XDP; else if (strncmp(port, rdma_ud_port_prefix, strlen(rdma_ud_port_prefix)) == 0) return MTL_PMD_RDMA_UD; @@ -1111,12 +1047,11 @@ int mt_read_cpu_usage(struct mt_cpu_usage *usages, int *cpu_ids, int num_cpus) { struct mt_cpu_usage cur; int cpu; int parsed = sscanf(line, - "cpu%d %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 - " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 "", - &cpu, &cur.user, &cur.nice, &cur.system, &cur.idle, - &cur.iowait, &cur.irq, &cur.softirq, &cur.steal); - if (parsed != 9) - continue; + "cpu%d %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 + " %" PRIu64 " %" PRIu64 " %" PRIu64 "", + &cpu, &cur.user, &cur.nice, &cur.system, &cur.idle, &cur.iowait, + &cur.irq, &cur.softirq, &cur.steal); + if (parsed != 9) continue; /* check if match with any input cpus */ for (int i = 0; i < num_cpus; i++) { if (cpu == cpu_ids[i]) { @@ -1133,8 +1068,7 @@ int mt_read_cpu_usage(struct mt_cpu_usage *usages, int *cpu_ids, int num_cpus) { #endif } -double mt_calculate_cpu_usage(struct mt_cpu_usage *prev, - struct mt_cpu_usage *curr) { +double mt_calculate_cpu_usage(struct mt_cpu_usage *prev, struct mt_cpu_usage *curr) { uint64_t prev_idle = prev->idle + prev->iowait; uint64_t curr_idle = curr->idle + curr->iowait; uint64_t prev_total = prev->user + prev->nice + prev->system + prev->idle + diff --git a/lib/src/mt_util.h b/lib/src/mt_util.h index 303bb35b8..e259b24e1 100644 --- a/lib/src/mt_util.h +++ b/lib/src/mt_util.h @@ -23,12 +23,10 @@ static inline bool mt_is_multicast_ip(const uint8_t ip[MTL_IP_ADDR_LEN]) { } /* if it is a local address area */ -static inline bool mt_is_lan_ip(uint8_t ip[MTL_IP_ADDR_LEN], - uint8_t sip[MTL_IP_ADDR_LEN], +static inline bool mt_is_lan_ip(uint8_t ip[MTL_IP_ADDR_LEN], uint8_t sip[MTL_IP_ADDR_LEN], uint8_t netmask[MTL_IP_ADDR_LEN]) { for (int i = 0; i < MTL_IP_ADDR_LEN; i++) { - if ((ip[i] & netmask[i]) != (sip[i] & netmask[i])) - return false; + if ((ip[i] & netmask[i]) != (sip[i] & netmask[i])) return false; } return true; @@ -60,20 +58,17 @@ void mt_mbuf_sanity_check(struct rte_mbuf **mbufs, uint16_t nb, char *tag); int mt_pacing_train_result_add(struct mtl_main_impl *impl, enum mtl_port port, uint64_t rl_bps, float pad_interval); -int mt_pacing_train_result_search(struct mtl_main_impl *impl, - enum mtl_port port, uint64_t rl_bps, - float *pad_interval); +int mt_pacing_train_result_search(struct mtl_main_impl *impl, enum mtl_port port, + uint64_t rl_bps, float *pad_interval); -int mt_audio_pacing_train_result_add(struct mtl_main_impl *impl, - enum mtl_port port, uint64_t input_bps, - uint64_t profiled_bps); -int mt_audio_pacing_train_result_search(struct mtl_main_impl *impl, - enum mtl_port port, uint64_t input_bps, - uint64_t *profiled_bps); +int mt_audio_pacing_train_result_add(struct mtl_main_impl *impl, enum mtl_port port, + uint64_t input_bps, uint64_t profiled_bps); +int mt_audio_pacing_train_result_search(struct mtl_main_impl *impl, enum mtl_port port, + uint64_t input_bps, uint64_t *profiled_bps); enum mtl_port mt_port_by_name(struct mtl_main_impl *impl, const char *name); -int mt_build_port_map(struct mtl_main_impl *impl, char **ports, - enum mtl_port *maps, int num_ports); +int mt_build_port_map(struct mtl_main_impl *impl, char **ports, enum mtl_port *maps, + int num_ports); /* logical session port to main(physical) port */ static inline enum mtl_port mt_port_logic2phy(enum mtl_port *maps, @@ -85,8 +80,7 @@ void st_video_rtp_dump(enum mtl_port port, int idx, char *tag, struct st20_rfc4175_rtp_hdr *rtp); void mt_mbuf_dump(enum mtl_port port, int idx, char *tag, struct rte_mbuf *m); -void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, - struct rte_mbuf *m); +void mt_mbuf_dump_hdr(enum mtl_port port, int idx, char *tag, struct rte_mbuf *m); void mt_lcore_dump(); @@ -101,20 +95,17 @@ static inline bool st_is_valid_payload_type(int payload_type) { return false; } -void mt_eth_macaddr_dump(enum mtl_port port, char *tag, - struct rte_ether_addr *mac_addr); +void mt_eth_macaddr_dump(enum mtl_port port, char *tag, struct rte_ether_addr *mac_addr); -static inline bool st_rx_seq_drop(uint16_t new_id, uint16_t old_id, - uint16_t delta) { +static inline bool st_rx_seq_drop(uint16_t new_id, uint16_t old_id, uint16_t delta) { if ((new_id <= old_id) && ((old_id - new_id) < delta)) return true; else return false; } -struct rte_mbuf *mt_build_pad(struct mtl_main_impl *impl, - struct rte_mempool *mempool, enum mtl_port port, - uint16_t ether_type, uint16_t len); +struct rte_mbuf *mt_build_pad(struct mtl_main_impl *impl, struct rte_mempool *mempool, + enum mtl_port port, uint16_t ether_type, uint16_t len); int mt_macaddr_get(struct mtl_main_impl *impl, enum mtl_port port, struct rte_ether_addr *mac_addr); @@ -122,37 +113,31 @@ int mt_macaddr_get(struct mtl_main_impl *impl, enum mtl_port port, /* default with stack */ #define MT_MEMPOOL_OPS_DEFAULT ("stack") -struct rte_mempool * -mt_mempool_create_by_ops(struct mtl_main_impl *impl, const char *name, - unsigned int n, unsigned int cache_size, - uint16_t priv_size, uint16_t element_size, - const char *ops_name, int socket_id); - -static inline struct rte_mempool * -mt_mempool_create(struct mtl_main_impl *impl, enum mtl_port port, - const char *name, unsigned int n, unsigned int cache_size, - uint16_t priv_size, uint16_t element_size) { - return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, - element_size, MT_MEMPOOL_OPS_DEFAULT, - mt_socket_id(impl, port)); +struct rte_mempool *mt_mempool_create_by_ops(struct mtl_main_impl *impl, const char *name, + unsigned int n, unsigned int cache_size, + uint16_t priv_size, uint16_t element_size, + const char *ops_name, int socket_id); + +static inline struct rte_mempool *mt_mempool_create( + struct mtl_main_impl *impl, enum mtl_port port, const char *name, unsigned int n, + unsigned int cache_size, uint16_t priv_size, uint16_t element_size) { + return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, element_size, + MT_MEMPOOL_OPS_DEFAULT, mt_socket_id(impl, port)); } -static inline struct rte_mempool * -mt_mempool_create_by_socket(struct mtl_main_impl *impl, const char *name, - unsigned int n, unsigned int cache_size, - uint16_t priv_size, uint16_t element_size, - int socket_id) { - return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, - element_size, MT_MEMPOOL_OPS_DEFAULT, - socket_id); +static inline struct rte_mempool *mt_mempool_create_by_socket( + struct mtl_main_impl *impl, const char *name, unsigned int n, unsigned int cache_size, + uint16_t priv_size, uint16_t element_size, int socket_id) { + return mt_mempool_create_by_ops(impl, name, n, cache_size, priv_size, element_size, + MT_MEMPOOL_OPS_DEFAULT, socket_id); } -static inline struct rte_mempool * -mt_mempool_create_common(struct mtl_main_impl *impl, enum mtl_port port, - const char *name, unsigned int n) { +static inline struct rte_mempool *mt_mempool_create_common(struct mtl_main_impl *impl, + enum mtl_port port, + const char *name, + unsigned int n) { return mt_mempool_create(impl, port, name, n, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), - MT_MBUF_DEFAULT_DATA_SIZE); + sizeof(struct mt_muf_priv_data), MT_MBUF_DEFAULT_DATA_SIZE); } int mt_mempool_free(struct rte_mempool *mp); @@ -176,14 +161,13 @@ struct mt_u64_fifo *mt_u64_fifo_init(int size, int soc_id); int mt_u64_fifo_uinit(struct mt_u64_fifo *fifo); int mt_u64_fifo_put(struct mt_u64_fifo *fifo, const uint64_t item); int mt_u64_fifo_get(struct mt_u64_fifo *fifo, uint64_t *item); -int mt_u64_fifo_put_bulk(struct mt_u64_fifo *fifo, const uint64_t *items, - uint32_t n); +int mt_u64_fifo_put_bulk(struct mt_u64_fifo *fifo, const uint64_t *items, uint32_t n); int mt_u64_fifo_get_bulk(struct mt_u64_fifo *fifo, uint64_t *items, uint32_t n); int mt_u64_fifo_read_back(struct mt_u64_fifo *fifo, uint64_t *item); int mt_u64_fifo_read_front(struct mt_u64_fifo *fifo, uint64_t *item); int mt_u64_fifo_read_any(struct mt_u64_fifo *fifo, uint64_t *item, int skip); -int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo *fifo, uint64_t *items, - uint32_t n, int skip); +int mt_u64_fifo_read_any_bulk(struct mt_u64_fifo *fifo, uint64_t *items, uint32_t n, + int skip); static inline int mt_u64_fifo_full(struct mt_u64_fifo *fifo) { return fifo->used == fifo->size; @@ -206,18 +190,15 @@ struct mt_cvt_dma_ctx { int *done; }; -struct mt_cvt_dma_ctx *mt_cvt_dma_ctx_init(int fifo_size, int soc_id, - int type_num); +struct mt_cvt_dma_ctx *mt_cvt_dma_ctx_init(int fifo_size, int soc_id, int type_num); int mt_cvt_dma_ctx_uinit(struct mt_cvt_dma_ctx *ctx); int mt_cvt_dma_ctx_push(struct mt_cvt_dma_ctx *ctx, int type); int mt_cvt_dma_ctx_pop(struct mt_cvt_dma_ctx *ctx); -static inline int mt_cvt_dma_ctx_get_done(struct mt_cvt_dma_ctx *ctx, - int type) { +static inline int mt_cvt_dma_ctx_get_done(struct mt_cvt_dma_ctx *ctx, int type) { return ctx->done[type]; } -static inline int mt_cvt_dma_ctx_get_tran(struct mt_cvt_dma_ctx *ctx, - int type) { +static inline int mt_cvt_dma_ctx_get_tran(struct mt_cvt_dma_ctx *ctx, int type) { return ctx->tran[type]; } @@ -239,8 +220,7 @@ static inline const char *mt_string_safe(const char *msg) { return msg ? msg : "null"; } -static inline void mt_mbuf_refcnt_inc_bulk(struct rte_mbuf **mbufs, - uint16_t nb) { +static inline void mt_mbuf_refcnt_inc_bulk(struct rte_mbuf **mbufs, uint16_t nb) { struct rte_mbuf *m = NULL; for (uint16_t i = 0; i < nb; i++) { m = mbufs[i]; @@ -319,8 +299,7 @@ struct mt_cpu_usage { int mt_read_cpu_usage(struct mt_cpu_usage *usages, int *cpu_ids, int num_cpus); -double mt_calculate_cpu_usage(struct mt_cpu_usage *prev, - struct mt_cpu_usage *curr); +double mt_calculate_cpu_usage(struct mt_cpu_usage *prev, struct mt_cpu_usage *curr); bool mt_file_exists(const char *filename); diff --git a/lib/src/st2110/experimental/st20_redundant_combined_rx.c b/lib/src/st2110/experimental/st20_redundant_combined_rx.c index 2d27c0307..d1e8d748a 100644 --- a/lib/src/st2110/experimental/st20_redundant_combined_rx.c +++ b/lib/src/st2110/experimental/st20_redundant_combined_rx.c @@ -14,8 +14,7 @@ static int rx_st20rc_frame_pop(struct st20rc_rx_ctx *ctx, void *frame) { for (int i = 0; i < ctx->frames_cnt; i++) { rx_frame = &ctx->frames[i]; - if (rx_frame->frame != frame) - continue; + if (rx_frame->frame != frame) continue; /* find the slot */ rx_frame->frame = NULL; return st20_rx_put_framebuff(ctx->transport[rx_frame->port]->handle, frame); @@ -33,15 +32,14 @@ static int rx_st20rc_frame_push(struct st20rc_rx_ctx *ctx, void *frame, for (int i = 0; i < ctx->frames_cnt; i++) { rx_frame = &ctx->frames[i]; - if (rx_frame->frame) - continue; + if (rx_frame->frame) continue; /* find a empty slot, notify user */ rx_frame->frame = frame; rx_frame->port = port; rx_frame->meta = *meta; ret = ctx->ops.notify_frame_ready(ctx->ops.priv, frame, meta); - dbg("%s(%d), notify frame %p(%d:%u) to user, ret %d\n", __func__, ctx->idx, - frame, port, i, ret); + dbg("%s(%d), notify frame %p(%d:%u) to user, ret %d\n", __func__, ctx->idx, frame, + port, i, ret); if (ret < 0) { /* clear the frame */ rx_frame->frame = NULL; @@ -61,8 +59,7 @@ static int rx_st20rc_frame_ready(void *priv, void *frame, enum mtl_session_port port = transport->port; int ret = -EIO; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ dbg("%s(%d), get frame %p at port %d\n", __func__, idx, frame, port); @@ -89,8 +86,7 @@ static int rx_st20rc_frame_ready(void *priv, void *frame, ret = rx_st20rc_frame_push(ctx, frame, port, meta); if (ret >= 0) { ctx->cur_frame_complete = true; - info("%s(%d), push frame %p at r_port %d\n", __func__, idx, frame, - port); + info("%s(%d), push frame %p at r_port %d\n", __func__, idx, frame, port); } } else { ret = -EIO; /* simply drop as frame get already */ @@ -102,8 +98,7 @@ static int rx_st20rc_frame_ready(void *priv, void *frame, mt_pthread_mutex_unlock(&ctx->lock); /* always return 0 to suppress the error log */ - if (ret < 0) - st20_rx_put_framebuff(ctx->transport[port]->handle, frame); + if (ret < 0) st20_rx_put_framebuff(ctx->transport[port]->handle, frame); return 0; } @@ -140,8 +135,7 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx *ctx, return -EIO; } - transport = - mt_rte_zmalloc_socket(sizeof(*transport), mt_socket_id(impl, MTL_PORT_P)); + transport = mt_rte_zmalloc_socket(sizeof(*transport), mt_socket_id(impl, MTL_PORT_P)); if (!transport) { err("%s, transport malloc fail\n", __func__); return -ENOMEM; @@ -154,12 +148,10 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx *ctx, ops_rx.name = ops->name; ops_rx.priv = transport; ops_rx.num_port = 1; - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ops->ip_addr[port], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ops->ip_addr[port], MTL_IP_ADDR_LEN); memcpy(ops_rx.mcast_sip_addr[MTL_SESSION_PORT_P], ops->mcast_sip_addr[port], MTL_IP_ADDR_LEN); - snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", - ops->port[port]); + snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ops->port[port]); ops_rx.udp_port[MTL_SESSION_PORT_P] = ops->udp_port[port]; if (ops->flags & ST20RC_RX_FLAG_DATA_PATH_ONLY) @@ -168,12 +160,9 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx *ctx, ops_rx.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; /* disable migrate since it may migrate the two sessions into one sch */ ops_rx.flags |= ST20_RX_FLAG_DISABLE_MIGRATE; - if (ops->flags & ST20RC_RX_FLAG_DMA_OFFLOAD) - ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; - if (ops->flags & ST20RC_RX_FLAG_HDR_SPLIT) - ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; - if (ops->flags & ST20RC_RX_FLAG_ENABLE_VSYNC) - ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST20RC_RX_FLAG_DMA_OFFLOAD) ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; + if (ops->flags & ST20RC_RX_FLAG_HDR_SPLIT) ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (ops->flags & ST20RC_RX_FLAG_ENABLE_VSYNC) ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; ops_rx.pacing = ops->pacing; ops_rx.width = ops->width; @@ -192,8 +181,7 @@ static int rx_st20rc_create_transport(struct st20rc_rx_ctx *ctx, mt_sch_mask_t sch_mask = MT_SCH_MASK_ALL; if (port == MTL_SESSION_PORT_R) { /* let R port select a different sch */ - int sch_idx = - st20_rx_get_sch_idx(ctx->transport[MTL_SESSION_PORT_P]->handle); + int sch_idx = st20_rx_get_sch_idx(ctx->transport[MTL_SESSION_PORT_P]->handle); if (sch_idx < 0) { err("%s(%d), st20_rx_get_sch_idx fail \n", __func__, idx); rx_st20rc_free_transport(transport); @@ -257,11 +245,10 @@ st20rc_rx_handle st20rc_rx_create(mtl_handle mt, struct st20rc_rx_ops *ops) { err("%s, invalid num_port %u\n", __func__, num_port); return NULL; } - if (0 == memcmp(ops->ip_addr[MTL_SESSION_PORT_P], - ops->ip_addr[MTL_SESSION_PORT_R], MTL_IP_ADDR_LEN)) { + if (0 == memcmp(ops->ip_addr[MTL_SESSION_PORT_P], ops->ip_addr[MTL_SESSION_PORT_R], + MTL_IP_ADDR_LEN)) { uint8_t *ip = ops->ip_addr[MTL_SESSION_PORT_P]; - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return NULL; } if (!ops->notify_frame_ready) { @@ -330,8 +317,7 @@ size_t st20rc_rx_get_framebuffer_size(st20rc_rx_handle handle) { return -EIO; } - return st20_rx_get_framebuffer_size( - ctx->transport[MTL_SESSION_PORT_P]->handle); + return st20_rx_get_framebuffer_size(ctx->transport[MTL_SESSION_PORT_P]->handle); } int st20rc_rx_get_framebuffer_count(st20rc_rx_handle handle) { @@ -342,12 +328,11 @@ int st20rc_rx_get_framebuffer_count(st20rc_rx_handle handle) { return -EIO; } - return st20_rx_get_framebuffer_count( - ctx->transport[MTL_SESSION_PORT_P]->handle); + return st20_rx_get_framebuffer_count(ctx->transport[MTL_SESSION_PORT_P]->handle); } -int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta) { +int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta) { struct st20rc_rx_ctx *ctx = handle; int ret = 0; @@ -356,9 +341,9 @@ int st20rc_rx_pcapng_dump(st20rc_rx_handle handle, uint32_t max_dump_packets, return -EIO; } - ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_P]->handle, - max_dump_packets, sync, meta); - ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_R]->handle, - max_dump_packets, sync, meta); + ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_P]->handle, max_dump_packets, + sync, meta); + ret += st20_rx_pcapng_dump(ctx->transport[MTL_SESSION_PORT_R]->handle, max_dump_packets, + sync, meta); return ret; } diff --git a/lib/src/st2110/pipeline/st20_pipeline_rx.c b/lib/src/st2110/pipeline/st20_pipeline_rx.c index c6264252a..ca4c60953 100644 --- a/lib/src/st2110/pipeline/st20_pipeline_rx.c +++ b/lib/src/st2110/pipeline/st20_pipeline_rx.c @@ -21,8 +21,7 @@ static uint16_t rx_st20p_next_idx(struct st20p_rx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) - next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) next_idx = 0; return next_idx; } @@ -44,9 +43,8 @@ static void rx_st20p_notify_frame_available(struct st20p_rx_ctx *ctx) { } } -static struct st20p_rx_frame * -rx_st20p_next_available(struct st20p_rx_ctx *ctx, uint16_t idx_start, - enum st20p_rx_frame_status desired) { +static struct st20p_rx_frame *rx_st20p_next_available( + struct st20p_rx_ctx *ctx, uint16_t idx_start, enum st20p_rx_frame_status desired) { uint16_t idx = idx_start; struct st20p_rx_frame *framebuff; @@ -79,8 +77,8 @@ static int rx_st20p_packet_convert(void *priv, void *frame, mt_pthread_mutex_lock(&ctx->lock); if (meta->row_number == 0 && meta->row_offset == 0) { /* first packet of frame */ - framebuff = rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, - ST20P_RX_FRAME_FREE); + framebuff = + rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_RX_FRAME_FREE); if (framebuff) { framebuff->stat = ST20P_RX_FRAME_IN_CONVERTING; framebuff->dst.timestamp = meta->timestamp; @@ -90,8 +88,8 @@ static int rx_st20p_packet_convert(void *priv, void *frame, ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { dbg("%s(%d), not this frame, find next one\n", __func__, ctx->idx); - framebuff = rx_st20p_next_available(ctx, framebuff->idx, - ST20P_RX_FRAME_IN_CONVERTING); + framebuff = + rx_st20p_next_available(ctx, framebuff->idx, ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { /* should never happen */ err_once("%s(%d), wrong frame timestamp\n", __func__, ctx->idx); @@ -108,48 +106,37 @@ static int rx_st20p_packet_convert(void *priv, void *frame, mt_pthread_mutex_unlock(&ctx->lock); if (ctx->ops.output_fmt == ST_FRAME_FMT_YUV422PLANAR10LE) { uint8_t *y = (uint8_t *)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + - meta->row_offset * 2; + framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; uint8_t *b = (uint8_t *)framebuff->dst.addr[1] + - framebuff->dst.linesize[1] * meta->row_number + - meta->row_offset; + framebuff->dst.linesize[1] * meta->row_number + meta->row_offset; uint8_t *r = (uint8_t *)framebuff->dst.addr[2] + - framebuff->dst.linesize[2] * meta->row_number + - meta->row_offset; + framebuff->dst.linesize[2] * meta->row_number + meta->row_offset; ret = st20_rfc4175_422be10_to_yuv422p10le(src, (uint16_t *)y, (uint16_t *)b, (uint16_t *)r, meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_Y210) { uint8_t *dst = (uint8_t *)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + - meta->row_offset * 4; + framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 4; ret = st20_rfc4175_422be10_to_y210(src, (uint16_t *)dst, meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_UYVY) { uint8_t *dst = (uint8_t *)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + - meta->row_offset * 2; - ret = st20_rfc4175_422be10_to_422le8( - src, (struct st20_rfc4175_422_8_pg2_le *)dst, meta->pg_cnt, 2); + framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; + ret = st20_rfc4175_422be10_to_422le8(src, (struct st20_rfc4175_422_8_pg2_le *)dst, + meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_YUV422PLANAR8) { uint8_t *y = (uint8_t *)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + - meta->row_offset * 2; + framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; uint8_t *b = (uint8_t *)framebuff->dst.addr[1] + - framebuff->dst.linesize[1] * meta->row_number + - meta->row_offset; + framebuff->dst.linesize[1] * meta->row_number + meta->row_offset; uint8_t *r = (uint8_t *)framebuff->dst.addr[2] + - framebuff->dst.linesize[2] * meta->row_number + - meta->row_offset; + framebuff->dst.linesize[2] * meta->row_number + meta->row_offset; ret = st20_rfc4175_422be10_to_yuv422p8(src, y, b, r, meta->pg_cnt, 2); } else if (ctx->ops.output_fmt == ST_FRAME_FMT_YUV420PLANAR8) { uint8_t *y = (uint8_t *)framebuff->dst.addr[0] + - framebuff->dst.linesize[0] * meta->row_number + - meta->row_offset * 2; + framebuff->dst.linesize[0] * meta->row_number + meta->row_offset * 2; uint8_t *b = (uint8_t *)framebuff->dst.addr[1] + - framebuff->dst.linesize[1] * meta->row_number + - meta->row_offset; + framebuff->dst.linesize[1] * meta->row_number + meta->row_offset; uint8_t *r = (uint8_t *)framebuff->dst.addr[2] + - framebuff->dst.linesize[2] * meta->row_number + - meta->row_offset; + framebuff->dst.linesize[2] * meta->row_number + meta->row_offset; ret = st20_rfc4175_422be10_to_yuv420p8(src, y, b, r, meta->pg_cnt, 2); } @@ -161,8 +148,7 @@ static int rx_st20p_frame_ready(void *priv, void *frame, struct st20p_rx_ctx *ctx = priv; struct st20p_rx_frame *framebuff; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); if (ctx->ops.flags & ST20P_RX_FLAG_PKT_CONVERT) { @@ -170,8 +156,8 @@ static int rx_st20p_frame_ready(void *priv, void *frame, ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { dbg("%s(%d), not this frame, find next one\n", __func__, ctx->idx); - framebuff = rx_st20p_next_available(ctx, framebuff->idx, - ST20P_RX_FRAME_IN_CONVERTING); + framebuff = + rx_st20p_next_available(ctx, framebuff->idx, ST20P_RX_FRAME_IN_CONVERTING); if (framebuff && framebuff->dst.timestamp != meta->timestamp) { /* should never happen */ mt_pthread_mutex_unlock(&ctx->lock); @@ -180,8 +166,8 @@ static int rx_st20p_frame_ready(void *priv, void *frame, } } } else { - framebuff = rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, - ST20P_RX_FRAME_FREE); + framebuff = + rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_RX_FRAME_FREE); } /* not any free frame */ @@ -191,8 +177,8 @@ static int rx_st20p_frame_ready(void *priv, void *frame, return -EBUSY; } - MT_USDT_ST20P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, - meta->rtp_timestamp, meta->frame_recv_size); + MT_USDT_ST20P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, meta->rtp_timestamp, + meta->frame_recv_size); /* query the ext frame for no convert mode */ if (ctx->dynamic_ext_frame && !ctx->derive) { @@ -226,35 +212,27 @@ static int rx_st20p_frame_ready(void *priv, void *frame, framebuff->src.addr[0] = frame; framebuff->src.data_size = meta->frame_total_size; - framebuff->src.second_field = framebuff->dst.second_field = - meta->second_field; + framebuff->src.second_field = framebuff->dst.second_field = meta->second_field; framebuff->src.tfmt = framebuff->dst.tfmt = meta->tfmt; framebuff->src.timestamp = framebuff->dst.timestamp = meta->timestamp; - framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = - meta->rtp_timestamp; + framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp; framebuff->src.status = framebuff->dst.status = meta->status; framebuff->src.pkts_total = framebuff->dst.pkts_total = meta->pkts_total; - for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; - s_port++) { + for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; s_port++) { framebuff->src.pkts_recv[s_port] = framebuff->dst.pkts_recv[s_port] = meta->pkts_recv[s_port]; } /* copy timing parser meta */ - for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; - s_port++) { + for (enum mtl_session_port s_port = 0; s_port < MTL_SESSION_PORT_MAX; s_port++) { framebuff->src.tp[s_port] = framebuff->dst.tp[s_port] = NULL; } - for (enum mtl_session_port s_port = 0; s_port < ctx->ops.port.num_port; - s_port++) { - if (!meta->tp[s_port]) - continue; - mtl_memcpy(&framebuff->tp[s_port], meta->tp[s_port], - sizeof(framebuff->tp[s_port])); - framebuff->src.tp[s_port] = framebuff->dst.tp[s_port] = - &framebuff->tp[s_port]; + for (enum mtl_session_port s_port = 0; s_port < ctx->ops.port.num_port; s_port++) { + if (!meta->tp[s_port]) continue; + mtl_memcpy(&framebuff->tp[s_port], meta->tp[s_port], sizeof(framebuff->tp[s_port])); + framebuff->src.tp[s_port] = framebuff->dst.tp[s_port] = &framebuff->tp[s_port]; } /* check user meta */ @@ -270,8 +248,7 @@ static int rx_st20p_frame_ready(void *priv, void *frame, /* ask app to consume src frame directly */ if (ctx->derive || (ctx->ops.flags & ST20P_RX_FLAG_PKT_CONVERT)) { - if (ctx->derive) - framebuff->dst = framebuff->src; + if (ctx->derive) framebuff->dst = framebuff->src; framebuff->stat = ST20P_RX_FRAME_CONVERTED; /* point to next */ ctx->framebuff_producer_idx = rx_st20p_next_idx(ctx, framebuff->idx); @@ -288,8 +265,7 @@ static int rx_st20p_frame_ready(void *priv, void *frame, dbg("%s(%d), frame %u succ\n", __func__, ctx->idx, framebuff->idx); /* ask convert plugin to consume */ - if (ctx->convert_impl) - st20_convert_notify_frame_ready(ctx->convert_impl); + if (ctx->convert_impl) st20_convert_notify_frame_ready(ctx->convert_impl); /* or ask app to consume with internal converter */ if (ctx->internal_converter) { @@ -299,19 +275,17 @@ static int rx_st20p_frame_ready(void *priv, void *frame, return 0; } -static int rx_st20p_query_ext_frame(void *priv, - struct st20_ext_frame *ext_frame, +static int rx_st20p_query_ext_frame(void *priv, struct st20_ext_frame *ext_frame, struct st20_rx_frame_meta *meta) { struct st20p_rx_ctx *ctx = priv; struct st20p_rx_frame *framebuff; int ret; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, - ST20P_RX_FRAME_FREE); + framebuff = + rx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_RX_FRAME_FREE); /* not any free frame */ if (!framebuff) { rte_atomic32_inc(&ctx->stat_busy); @@ -347,8 +321,7 @@ static int rx_st20p_notify_event(void *priv, enum st_event event, void *args) { return 0; } -static int rx_st20p_notify_detected(void *priv, - const struct st20_detect_meta *meta, +static int rx_st20p_notify_detected(void *priv, const struct st20_detect_meta *meta, struct st20_detect_reply *reply) { struct st20p_rx_ctx *ctx = priv; int idx = ctx->idx; @@ -359,10 +332,9 @@ static int rx_st20p_notify_detected(void *priv, info("%s(%d), init dst buffer now, w %d h %d\n", __func__, idx, meta->width, meta->height); - ctx->dst_size = st_frame_size(ctx->ops.output_fmt, meta->width, meta->height, - meta->interlaced); - if (ctx->derive || ctx->ops.ext_frames || - ctx->ops.flags & ST20P_RX_FLAG_EXT_FRAME) { + ctx->dst_size = + st_frame_size(ctx->ops.output_fmt, meta->width, meta->height, meta->interlaced); + if (ctx->derive || ctx->ops.ext_frames || ctx->ops.flags & ST20P_RX_FLAG_EXT_FRAME) { no_dst_malloc = true; } @@ -376,28 +348,26 @@ static int rx_st20p_notify_detected(void *priv, frames[i].src.height = meta->height; frames[i].src.buffer_size = - st_frame_size(frames[i].src.fmt, frames[i].src.width, - frames[i].src.height, frames[i].src.interlaced); + st_frame_size(frames[i].src.fmt, frames[i].src.width, frames[i].src.height, + frames[i].src.interlaced); frames[i].src.data_size = frames[i].src.buffer_size; /* rfc4175 uses packed format */ - frames[i].src.linesize[0] = RTE_MAX( - ctx->ops.transport_linesize, - st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); + frames[i].src.linesize[0] = + RTE_MAX(ctx->ops.transport_linesize, + st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); - if (no_dst_malloc) - continue; + if (no_dst_malloc) continue; dst = mt_rte_zmalloc_socket(ctx->dst_size, soc_id); if (!dst) { - err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", __func__, - idx, i, ctx->dst_size); + err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", __func__, idx, i, + ctx->dst_size); rx_st20p_uinit_dst_fbs(ctx); return -ENOMEM; } frames[i].dst.buffer_size = ctx->dst_size; frames[i].dst.data_size = ctx->dst_size; /* init plane */ - st_frame_init_plane_single_src(&frames[i].dst, dst, - mtl_hp_virt2iova(ctx->impl, dst)); + st_frame_init_plane_single_src(&frames[i].dst, dst, mtl_hp_virt2iova(ctx->impl, dst)); } if (ctx->ops.notify_detected) { @@ -417,12 +387,11 @@ static struct st20_convert_frame_meta *rx_st20p_convert_get_frame(void *priv) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st20p_next_available(ctx, ctx->framebuff_convert_idx, - ST20P_RX_FRAME_READY); + framebuff = + rx_st20p_next_available(ctx, ctx->framebuff_convert_idx, ST20P_RX_FRAME_READY); /* not any ready frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -438,8 +407,7 @@ static struct st20_convert_frame_meta *rx_st20p_convert_get_frame(void *priv) { return &framebuff->convert_frame; } -static int rx_st20p_convert_put_frame(void *priv, - struct st20_convert_frame_meta *frame, +static int rx_st20p_convert_put_frame(void *priv, struct st20_convert_frame_meta *frame, int result) { struct st20p_rx_ctx *ctx = priv; int idx = ctx->idx; @@ -475,8 +443,7 @@ static int rx_st20p_convert_dump(void *priv) { struct st20p_rx_ctx *ctx = priv; struct st20p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t convert_idx = ctx->framebuff_convert_idx; notice("RX_st20p(%s), cv(%d:%s)\n", ctx->ops_name, convert_idx, @@ -497,8 +464,7 @@ static int rx_st20p_convert_dump(void *priv) { return 0; } -static int rx_st20p_create_transport(struct mtl_main_impl *impl, - struct st20p_rx_ctx *ctx, +static int rx_st20p_create_transport(struct mtl_main_impl *impl, struct st20p_rx_ctx *ctx, struct st20p_rx_ops *ops) { int idx = ctx->idx; struct st20_rx_ops ops_rx; @@ -511,23 +477,18 @@ static int rx_st20p_create_transport(struct mtl_main_impl *impl, ops_rx.num_port = RTE_MIN(ops->port.num_port, MTL_SESSION_PORT_MAX); for (int i = 0; i < ops_rx.num_port; i++) { memcpy(ops_rx.ip_addr[i], ops->port.ip_addr[i], MTL_IP_ADDR_LEN); - memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[i], MTL_PORT_MAX_LEN, "%s", ops->port.port[i]); ops_rx.udp_port[i] = ops->port.udp_port[i]; } if (ops->flags & ST20P_RX_FLAG_DATA_PATH_ONLY) ops_rx.flags |= ST20_RX_FLAG_DATA_PATH_ONLY; - if (ops->flags & ST20P_RX_FLAG_ENABLE_VSYNC) - ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST20P_RX_FLAG_ENABLE_VSYNC) ops_rx.flags |= ST20_RX_FLAG_ENABLE_VSYNC; if (ops->flags & ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME) ops_rx.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; - if (ops->flags & ST20P_RX_FLAG_DMA_OFFLOAD) - ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; - if (ops->flags & ST20P_RX_FLAG_AUTO_DETECT) - ops_rx.flags |= ST20_RX_FLAG_AUTO_DETECT; - if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) - ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (ops->flags & ST20P_RX_FLAG_DMA_OFFLOAD) ops_rx.flags |= ST20_RX_FLAG_DMA_OFFLOAD; + if (ops->flags & ST20P_RX_FLAG_AUTO_DETECT) ops_rx.flags |= ST20_RX_FLAG_AUTO_DETECT; + if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; if (ops->flags & ST20P_RX_FLAG_DISABLE_MIGRATE) ops_rx.flags |= ST20_RX_FLAG_DISABLE_MIGRATE; if (ops->flags & ST20P_RX_FLAG_TIMING_PARSER_STAT) @@ -549,8 +510,7 @@ static int rx_st20p_create_transport(struct mtl_main_impl *impl, return -EIO; } ops_rx.uframe_pg_callback = rx_st20p_packet_convert; - ops_rx.uframe_size = - st20_frame_size(ops->transport_fmt, ops->width, ops->height); + ops_rx.uframe_size = st20_frame_size(ops->transport_fmt, ops->width, ops->height); } if (ops->flags & ST20P_RX_FLAG_ENABLE_RTCP) { ops_rx.flags |= ST20_RX_FLAG_ENABLE_RTCP; @@ -583,10 +543,9 @@ static int rx_st20p_create_transport(struct mtl_main_impl *impl, if (ops->ext_frames) { uint16_t framebuff_cnt = ctx->framebuff_cnt; /* hdr split use continuous frame */ - if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) - framebuff_cnt = 1; - trans_ext_frames = mt_rte_zmalloc_socket( - sizeof(*trans_ext_frames) * framebuff_cnt, ctx->socket_id); + if (ops->flags & ST20P_RX_FLAG_HDR_SPLIT) framebuff_cnt = 1; + trans_ext_frames = mt_rte_zmalloc_socket(sizeof(*trans_ext_frames) * framebuff_cnt, + ctx->socket_id); if (!trans_ext_frames) { err("%s, trans_ext_frames malloc fail\n", __func__); return -ENOMEM; @@ -600,10 +559,8 @@ static int rx_st20p_create_transport(struct mtl_main_impl *impl, } if (ops->query_ext_frame) { if (!(ops->flags & ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME)) { - err("%s, pls enable incomplete frame flag for derive query ext mode\n", - __func__); - if (trans_ext_frames) - mt_rte_free(trans_ext_frames); + err("%s, pls enable incomplete frame flag for derive query ext mode\n", __func__); + if (trans_ext_frames) mt_rte_free(trans_ext_frames); return -EINVAL; } ops_rx.query_ext_frame = rx_st20p_query_ext_frame; @@ -613,8 +570,7 @@ static int rx_st20p_create_transport(struct mtl_main_impl *impl, transport = st20_rx_create(impl, &ops_rx); if (!transport) { err("%s(%d), transport create fail\n", __func__, idx); - if (trans_ext_frames) - mt_rte_free(trans_ext_frames); + if (trans_ext_frames) mt_rte_free(trans_ext_frames); return -EIO; } ctx->transport = transport; @@ -623,15 +579,14 @@ static int rx_st20p_create_transport(struct mtl_main_impl *impl, for (uint16_t i = 0; i < ctx->framebuff_cnt; i++) { frames[i].src.fmt = st_frame_fmt_from_transport(ctx->ops.transport_fmt); frames[i].src.interlaced = ops->interlaced; - frames[i].src.buffer_size = st_frame_size(frames[i].src.fmt, ops->width, - ops->height, ops->interlaced); + frames[i].src.buffer_size = + st_frame_size(frames[i].src.fmt, ops->width, ops->height, ops->interlaced); frames[i].src.data_size = frames[i].src.buffer_size; frames[i].src.width = ops->width; frames[i].src.height = ops->height; frames[i].src.linesize[0] = /* rfc4175 uses packed format */ - RTE_MAX( - ops->transport_linesize, - st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); + RTE_MAX(ops->transport_linesize, + st_frame_least_linesize(frames[i].src.fmt, frames[i].src.width, 0)); frames[i].src.priv = &frames[i]; frames[i].convert_frame.src = &frames[i].src; @@ -639,8 +594,7 @@ static int rx_st20p_create_transport(struct mtl_main_impl *impl, frames[i].convert_frame.priv = &frames[i]; } - if (trans_ext_frames) - mt_rte_free(trans_ext_frames); + if (trans_ext_frames) mt_rte_free(trans_ext_frames); return 0; } @@ -670,8 +624,7 @@ static int rx_st20p_uinit_dst_fbs(struct st20p_rx_ctx *ctx) { return 0; } -static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, - struct st20p_rx_ctx *ctx, +static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, struct st20p_rx_ctx *ctx, struct st20p_rx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; @@ -680,8 +633,7 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, size_t dst_size = ctx->dst_size; bool no_dst_malloc = false; - if (ops->flags & ST20P_RX_FLAG_EXT_FRAME || - ops->flags & ST20P_RX_FLAG_AUTO_DETECT) { + if (ops->flags & ST20P_RX_FLAG_EXT_FRAME || ops->flags & ST20P_RX_FLAG_AUTO_DETECT) { no_dst_malloc = true; } @@ -709,8 +661,7 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, frames[i].dst.iova[plane] = ops->ext_frames[i].iova[plane]; frames[i].dst.linesize[plane] = ops->ext_frames[i].linesize[plane]; } - frames[i].dst.buffer_size = frames[i].dst.data_size = - ops->ext_frames[i].size; + frames[i].dst.buffer_size = frames[i].dst.data_size = ops->ext_frames[i].size; frames[i].dst.opaque = ops->ext_frames[i].opaque; } else if (no_dst_malloc) { for (uint8_t plane = 0; plane < planes; plane++) { @@ -720,8 +671,8 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, } else { dst = mt_rte_zmalloc_socket(dst_size, soc_id); if (!dst) { - err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", - __func__, idx, i, dst_size); + err("%s(%d), dst frame malloc fail at %u, size %" PRIu64 "\n", __func__, idx, i, + dst_size); rx_st20p_uinit_dst_fbs(ctx); return -ENOMEM; } @@ -742,8 +693,7 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, /* init user meta */ frames[i].user_meta_buffer_size = impl->pkt_udp_suggest_max_size - sizeof(struct st20_rfc4175_rtp_hdr); - frames[i].user_meta = - mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); + frames[i].user_meta = mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); if (!frames[i].user_meta) { err("%s(%d), user_meta malloc %" PRIu64 " fail at %d\n", __func__, idx, frames[i].user_meta_buffer_size, i); @@ -751,13 +701,12 @@ static int rx_st20p_init_dst_fbs(struct mtl_main_impl *impl, return -ENOMEM; } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, - dst_size, ops->output_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, dst_size, + ops->output_fmt, ctx->framebuff_cnt); return 0; } -static int rx_st20p_get_converter(struct mtl_main_impl *impl, - struct st20p_rx_ctx *ctx, +static int rx_st20p_get_converter(struct mtl_main_impl *impl, struct st20p_rx_ctx *ctx, struct st20p_rx_ops *ops) { int idx = ctx->idx; struct st20_get_converter_request req; @@ -776,8 +725,7 @@ static int rx_st20p_get_converter(struct mtl_main_impl *impl, req.put_frame = rx_st20p_convert_put_frame; req.dump = rx_st20p_convert_dump; - struct st20_convert_session_impl *convert_impl = - st20_get_converter(impl, &req); + struct st20_convert_session_impl *convert_impl = st20_get_converter(impl, &req); if (req.device == ST_PLUGIN_DEVICE_TEST_INTERNAL || !convert_impl) { struct st_frame_converter *converter = NULL; converter = mt_rte_zmalloc_socket(sizeof(*converter), ctx->socket_id); @@ -786,8 +734,7 @@ static int rx_st20p_get_converter(struct mtl_main_impl *impl, return -ENOMEM; } memset(converter, 0, sizeof(*converter)); - if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, - converter) < 0) { + if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, converter) < 0) { err("%s, get converter fail\n", __func__); mt_rte_free(converter); return -EIO; @@ -805,18 +752,16 @@ static int rx_st20p_stat(void *priv) { struct st20p_rx_ctx *ctx = priv; struct st20p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("RX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, - producer_idx, rx_st20p_stat_name(framebuff[producer_idx].stat), - consumer_idx, rx_st20p_stat_name(framebuff[consumer_idx].stat)); + notice("RX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, + rx_st20p_stat_name(framebuff[producer_idx].stat), consumer_idx, + rx_st20p_stat_name(framebuff[consumer_idx].stat)); notice("RX_st20p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, - ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -824,8 +769,7 @@ static int rx_st20p_stat(void *priv) { return 0; } -static int rx_st20p_usdt_dump_frame(struct st20p_rx_ctx *ctx, - struct st_frame *frame) { +static int rx_st20p_usdt_dump_frame(struct st20p_rx_ctx *ctx, struct st_frame *frame) { int idx = ctx->idx; struct mtl_main_impl *impl = ctx->impl; int fd; @@ -834,8 +778,7 @@ static int rx_st20p_usdt_dump_frame(struct st20p_rx_ctx *ctx, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, - ops->height); + "imtl_usdt_st20prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -879,23 +822,22 @@ struct st_frame *st20p_rx_get_frame(st20p_rx_handle handle) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); if (ctx->internal_converter) { /* convert internal */ - framebuff = rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, - ST20P_RX_FRAME_READY); + framebuff = + rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, ST20P_RX_FRAME_READY); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); st20p_rx_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, - ST20P_RX_FRAME_READY); + framebuff = + rx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, ST20P_RX_FRAME_READY); } /* not any ready frame */ if (!framebuff) { @@ -997,8 +939,7 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops *ops) { if (ops->flags & ST20P_RX_FLAG_EXT_FRAME) { if (!ops->query_ext_frame) { - err("%s, no query_ext_frame query callback for dynamic ext frame mode\n", - __func__); + err("%s, no query_ext_frame query callback for dynamic ext frame mode\n", __func__); return NULL; } } @@ -1006,18 +947,15 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops *ops) { if (auto_detect) { info("%s(%d), auto_detect enabled\n", __func__, idx); } else { - dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, - ops->interlaced); + dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, ops->interlaced); if (!dst_size) { err("%s(%d), get dst size fail\n", __func__, idx); return NULL; } } - enum mtl_port port = - mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20P_RX_FLAG_FORCE_NUMA) { @@ -1034,10 +972,8 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops *ops) { ctx->idx = idx; ctx->socket_id = socket; ctx->ready = false; - ctx->derive = - st_frame_fmt_equal_transport(ops->output_fmt, ops->transport_fmt); - ctx->dynamic_ext_frame = - (ops->flags & ST20P_RX_FLAG_EXT_FRAME) ? true : false; + ctx->derive = st_frame_fmt_equal_transport(ops->output_fmt, ops->transport_fmt); + ctx->dynamic_ext_frame = (ops->flags & ST20P_RX_FLAG_EXT_FRAME) ? true : false; ctx->impl = impl; ctx->type = MT_ST20_HANDLE_PIPELINE_RX; ctx->dst_size = dst_size; @@ -1048,8 +984,7 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops *ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; - if (ops->flags & ST20P_RX_FLAG_BLOCK_GET) - ctx->block_get = true; + if (ops->flags & ST20P_RX_FLAG_BLOCK_GET) ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -1092,8 +1027,7 @@ st20p_rx_handle st20p_rx_create(mtl_handle mt, struct st20p_rx_ops *ops) { ops->flags); st20p_rx_idx++; - if (!ctx->block_get) - rx_st20p_notify_frame_available(ctx); + if (!ctx->block_get) rx_st20p_notify_frame_available(ctx); mt_stat_register(impl, rx_st20p_stat, ctx, ctx->ops_name); @@ -1154,8 +1088,7 @@ void *st20p_rx_get_fb_addr(st20p_rx_handle handle, uint16_t idx) { ctx->framebuff_cnt); return NULL; } - if (ctx->derive) - return ctx->framebuffs[idx].src.addr; + if (ctx->derive) return ctx->framebuffs[idx].src.addr; return ctx->framebuffs[idx].dst.addr; } @@ -1171,8 +1104,8 @@ size_t st20p_rx_frame_size(st20p_rx_handle handle) { return ctx->dst_size; } -int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta) { +int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta) { struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -1184,8 +1117,7 @@ int st20p_rx_pcapng_dump(st20p_rx_handle handle, uint32_t max_dump_packets, return st20_rx_pcapng_dump(ctx->transport, max_dump_packets, sync, meta); } -int st20p_rx_get_queue_meta(st20p_rx_handle handle, - struct st_queue_meta *meta) { +int st20p_rx_get_queue_meta(st20p_rx_handle handle, struct st_queue_meta *meta) { struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -1222,8 +1154,7 @@ int st20p_rx_get_port_stats(st20p_rx_handle handle, enum mtl_session_port port, return st20_rx_get_port_stats(ctx->transport, port, stats); } -int st20p_rx_reset_port_stats(st20p_rx_handle handle, - enum mtl_session_port port) { +int st20p_rx_reset_port_stats(st20p_rx_handle handle, enum mtl_session_port port) { struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -1235,8 +1166,7 @@ int st20p_rx_reset_port_stats(st20p_rx_handle handle, return st20_rx_reset_port_stats(ctx->transport, port); } -int st20p_rx_update_source(st20p_rx_handle handle, - struct st_rx_source_info *src) { +int st20p_rx_update_source(st20p_rx_handle handle, struct st_rx_source_info *src) { struct st20p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -1270,8 +1200,7 @@ int st20p_rx_wake_block(st20p_rx_handle handle) { return 0; } - if (ctx->block_get) - rx_st20p_block_wake(ctx); + if (ctx->block_get) rx_st20p_block_wake(ctx); return 0; } diff --git a/lib/src/st2110/pipeline/st20_pipeline_tx.c b/lib/src/st2110/pipeline/st20_pipeline_tx.c index 8b30b7a8b..e052d15d0 100644 --- a/lib/src/st2110/pipeline/st20_pipeline_tx.c +++ b/lib/src/st2110/pipeline/st20_pipeline_tx.c @@ -19,14 +19,12 @@ static uint16_t tx_st20p_next_idx(struct st20p_tx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) - next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) next_idx = 0; return next_idx; } -static inline struct st_frame * -tx_st20p_user_frame(struct st20p_tx_ctx *ctx, - struct st20p_tx_frame *framebuff) { +static inline struct st_frame *tx_st20p_user_frame(struct st20p_tx_ctx *ctx, + struct st20p_tx_frame *framebuff) { return ctx->derive ? &framebuff->dst : &framebuff->src; } @@ -48,9 +46,8 @@ static void tx_st20p_notify_frame_available(struct st20p_tx_ctx *ctx) { } } -static struct st20p_tx_frame * -tx_st20p_next_available(struct st20p_tx_ctx *ctx, uint16_t idx_start, - enum st20p_tx_frame_status desired) { +static struct st20p_tx_frame *tx_st20p_next_available( + struct st20p_tx_ctx *ctx, uint16_t idx_start, enum st20p_tx_frame_status desired) { uint16_t idx = idx_start; struct st20p_tx_frame *framebuff; @@ -77,12 +74,11 @@ static int tx_st20p_next_frame(void *priv, uint16_t *next_frame_idx, struct st20p_tx_ctx *ctx = priv; struct st20p_tx_frame *framebuff; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, - ST20P_TX_FRAME_CONVERTED); + framebuff = + tx_st20p_next_available(ctx, ctx->framebuff_consumer_idx, ST20P_TX_FRAME_CONVERTED); /* not any converted frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -94,8 +90,7 @@ static int tx_st20p_next_frame(void *priv, uint16_t *next_frame_idx, struct st_frame *frame = tx_st20p_user_frame(ctx, framebuff); meta->second_field = frame->second_field; - if (ctx->ops.flags & - (ST20P_TX_FLAG_USER_PACING | ST20P_TX_FLAG_USER_TIMESTAMP)) { + if (ctx->ops.flags & (ST20P_TX_FLAG_USER_PACING | ST20P_TX_FLAG_USER_TIMESTAMP)) { meta->tfmt = frame->tfmt; meta->timestamp = frame->timestamp; } @@ -124,8 +119,8 @@ static int tx_st20p_frame_done(void *priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, ctx->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, framebuff->stat, + frame_idx); } mt_pthread_mutex_unlock(&ctx->lock); @@ -167,12 +162,11 @@ static struct st20_convert_frame_meta *tx_st20p_convert_get_frame(void *priv) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st20p_next_available(ctx, ctx->framebuff_convert_idx, - ST20P_TX_FRAME_READY); + framebuff = + tx_st20p_next_available(ctx, ctx->framebuff_convert_idx, ST20P_TX_FRAME_READY); /* not any free frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -188,8 +182,7 @@ static struct st20_convert_frame_meta *tx_st20p_convert_get_frame(void *priv) { return &framebuff->convert_frame; } -static int tx_st20p_convert_put_frame(void *priv, - struct st20_convert_frame_meta *frame, +static int tx_st20p_convert_put_frame(void *priv, struct st20_convert_frame_meta *frame, int result) { struct st20p_tx_ctx *ctx = priv; int idx = ctx->idx; @@ -209,8 +202,8 @@ static int tx_st20p_convert_put_frame(void *priv, } if ((result < 0) || (data_size <= 0)) { - dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, - convert_idx, result, data_size); + dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, convert_idx, + result, data_size); framebuff->stat = ST20P_TX_FRAME_FREE; /* notify app can get frame */ tx_st20p_notify_frame_available(ctx); @@ -226,8 +219,7 @@ static int tx_st20p_convert_dump(void *priv) { struct st20p_tx_ctx *ctx = priv; struct st20p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t convert_idx = ctx->framebuff_convert_idx; notice("TX_st20p(%s), cv(%d:%s)\n", ctx->ops_name, convert_idx, @@ -248,8 +240,7 @@ static int tx_st20p_convert_dump(void *priv) { return 0; } -static int tx_st20p_create_transport(struct mtl_main_impl *impl, - struct st20p_tx_ctx *ctx, +static int tx_st20p_create_transport(struct mtl_main_impl *impl, struct st20p_tx_ctx *ctx, struct st20p_tx_ops *ops) { int idx = ctx->idx; struct st20_tx_ops ops_tx; @@ -297,12 +288,10 @@ static int tx_st20p_create_transport(struct mtl_main_impl *impl, ops_tx.notify_event = tx_st20p_notify_event; if (ctx->derive && ops->flags & ST20P_TX_FLAG_EXT_FRAME) ops_tx.flags |= ST20_TX_FLAG_EXT_FRAME; - if (ops->flags & ST20P_TX_FLAG_USER_PACING) - ops_tx.flags |= ST20_TX_FLAG_USER_PACING; + if (ops->flags & ST20P_TX_FLAG_USER_PACING) ops_tx.flags |= ST20_TX_FLAG_USER_PACING; if (ops->flags & ST20P_TX_FLAG_USER_TIMESTAMP) ops_tx.flags |= ST20_TX_FLAG_USER_TIMESTAMP; - if (ops->flags & ST20P_TX_FLAG_ENABLE_VSYNC) - ops_tx.flags |= ST20_TX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST20P_TX_FLAG_ENABLE_VSYNC) ops_tx.flags |= ST20_TX_FLAG_ENABLE_VSYNC; if (ops->flags & ST20P_TX_FLAG_DISABLE_STATIC_PAD_P) ops_tx.flags |= ST20_TX_FLAG_DISABLE_STATIC_PAD_P; if (ops->flags & ST20P_TX_FLAG_ENABLE_RTCP) { @@ -313,8 +302,7 @@ static int tx_st20p_create_transport(struct mtl_main_impl *impl, ops_tx.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT; if (ops->flags & ST20P_TX_FLAG_RTP_TIMESTAMP_EPOCH) ops_tx.flags |= ST20_TX_FLAG_RTP_TIMESTAMP_EPOCH; - if (ops->flags & ST20P_TX_FLAG_DISABLE_BULK) - ops_tx.flags |= ST20_TX_FLAG_DISABLE_BULK; + if (ops->flags & ST20P_TX_FLAG_DISABLE_BULK) ops_tx.flags |= ST20_TX_FLAG_DISABLE_BULK; if (ops->flags & ST20P_TX_FLAG_FORCE_NUMA) { ops_tx.socket_id = ops->socket_id; ops_tx.flags |= ST20_TX_FLAG_FORCE_NUMA; @@ -336,15 +324,14 @@ static int tx_st20p_create_transport(struct mtl_main_impl *impl, } frames[i].dst.fmt = st_frame_fmt_from_transport(ctx->ops.transport_fmt); frames[i].dst.interlaced = ops->interlaced; - frames[i].dst.buffer_size = st_frame_size(frames[i].dst.fmt, ops->width, - ops->height, ops->interlaced); + frames[i].dst.buffer_size = + st_frame_size(frames[i].dst.fmt, ops->width, ops->height, ops->interlaced); frames[i].dst.data_size = frames[i].dst.buffer_size; frames[i].dst.width = ops->width; frames[i].dst.height = ops->height; frames[i].dst.linesize[0] = /* rfc4175 uses packed format */ - RTE_MAX( - ops->transport_linesize, - st_frame_least_linesize(frames[i].dst.fmt, frames[i].dst.width, 0)); + RTE_MAX(ops->transport_linesize, + st_frame_least_linesize(frames[i].dst.fmt, frames[i].dst.width, 0)); frames[i].dst.priv = &frames[i]; frames[i].convert_frame.src = &frames[i].src; @@ -383,8 +370,7 @@ static int tx_st20p_uinit_src_fbs(struct st20p_tx_ctx *ctx) { return 0; } -static int tx_st20p_init_src_fbs(struct mtl_main_impl *impl, - struct st20p_tx_ctx *ctx, +static int tx_st20p_init_src_fbs(struct mtl_main_impl *impl, struct st20p_tx_ctx *ctx, struct st20p_tx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; @@ -438,8 +424,7 @@ static int tx_st20p_init_src_fbs(struct mtl_main_impl *impl, /* init user meta */ frames[i].user_meta_buffer_size = impl->pkt_udp_suggest_max_size - sizeof(struct st20_rfc4175_rtp_hdr); - frames[i].user_meta = - mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); + frames[i].user_meta = mt_rte_zmalloc_socket(frames[i].user_meta_buffer_size, soc_id); if (!frames[i].user_meta) { err("%s(%d), user_meta malloc %" PRIu64 " fail at %d\n", __func__, idx, frames[i].user_meta_buffer_size, i); @@ -447,13 +432,12 @@ static int tx_st20p_init_src_fbs(struct mtl_main_impl *impl, return -ENOMEM; } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, - src_size, ops->transport_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, src_size, + ops->transport_fmt, ctx->framebuff_cnt); return 0; } -static int tx_st20p_get_converter(struct mtl_main_impl *impl, - struct st20p_tx_ctx *ctx, +static int tx_st20p_get_converter(struct mtl_main_impl *impl, struct st20p_tx_ctx *ctx, struct st20p_tx_ops *ops) { int idx = ctx->idx; struct st20_get_converter_request req; @@ -472,8 +456,7 @@ static int tx_st20p_get_converter(struct mtl_main_impl *impl, req.put_frame = tx_st20p_convert_put_frame; req.dump = tx_st20p_convert_dump; - struct st20_convert_session_impl *convert_impl = - st20_get_converter(impl, &req); + struct st20_convert_session_impl *convert_impl = st20_get_converter(impl, &req); if (req.device == ST_PLUGIN_DEVICE_TEST_INTERNAL || !convert_impl) { struct st_frame_converter *converter = NULL; converter = mt_rte_zmalloc_socket(sizeof(*converter), ctx->socket_id); @@ -482,8 +465,7 @@ static int tx_st20p_get_converter(struct mtl_main_impl *impl, return -ENOMEM; } memset(converter, 0, sizeof(*converter)); - if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, - converter) < 0) { + if (st_frame_get_converter(req.req.input_fmt, req.req.output_fmt, converter) < 0) { err("%s, get converter fail\n", __func__); mt_rte_free(converter); return -EIO; @@ -501,18 +483,16 @@ static int tx_st20p_stat(void *priv) { struct st20p_tx_ctx *ctx = priv; struct st20p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("TX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, - producer_idx, tx_st20p_stat_name(framebuff[producer_idx].stat), - consumer_idx, tx_st20p_stat_name(framebuff[consumer_idx].stat)); + notice("TX_st20p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, + tx_st20p_stat_name(framebuff[producer_idx].stat), consumer_idx, + tx_st20p_stat_name(framebuff[consumer_idx].stat)); notice("TX_st20p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, - ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -520,8 +500,7 @@ static int tx_st20p_stat(void *priv) { return 0; } -static int tx_st20p_usdt_dump_frame(struct st20p_tx_ctx *ctx, - struct st_frame *frame) { +static int tx_st20p_usdt_dump_frame(struct st20p_tx_ctx *ctx, struct st_frame *frame) { int idx = ctx->idx; struct mtl_main_impl *impl = ctx->impl; int fd; @@ -530,8 +509,7 @@ static int tx_st20p_usdt_dump_frame(struct st20p_tx_ctx *ctx, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, - ops->height); + "imtl_usdt_st20ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -560,8 +538,7 @@ static void tx_st20p_framebuffs_flush(struct st20p_tx_ctx *ctx) { int retry = 0; while (1) { - if (framebuff->stat == ST20P_TX_FRAME_FREE) - break; + if (framebuff->stat == ST20P_TX_FRAME_FREE) break; if (framebuff->stat == ST20P_TX_FRAME_IN_TRANSMITTING) { /* make sure transport to finish the transmit */ /* WA to use sleep here, todo: add a transport API to query the stat */ @@ -573,8 +550,8 @@ static void tx_st20p_framebuffs_flush(struct st20p_tx_ctx *ctx) { tx_st20p_stat_name(framebuff->stat), retry); retry++; if (retry > 100) { - info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, - i, tx_st20p_stat_name(framebuff->stat), retry); + info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, i, + tx_st20p_stat_name(framebuff->stat), retry); break; } mt_sleep_ms(10); @@ -603,21 +580,20 @@ struct st_frame *st20p_tx_get_frame(st20p_tx_handle handle) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, - ST20P_TX_FRAME_FREE); + framebuff = + tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_TX_FRAME_FREE); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); st20p_tx_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, - ST20P_TX_FRAME_FREE); + framebuff = + tx_st20p_next_available(ctx, ctx->framebuff_producer_idx, ST20P_TX_FRAME_FREE); } /* not any free frame */ if (!framebuff) { @@ -632,8 +608,7 @@ struct st_frame *st20p_tx_get_frame(st20p_tx_handle handle) { dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); struct st_frame *frame = tx_st20p_user_frame(ctx, framebuff); - if (ctx->ops - .interlaced) { /* init second_field but user still can customize */ + if (ctx->ops.interlaced) { /* init second_field but user still can customize */ frame->second_field = ctx->second_field; ctx->second_field = ctx->second_field ? false : true; } @@ -662,16 +637,16 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame *frame) { } if (ctx->ops.flags & ST20P_TX_FLAG_EXT_FRAME) { - err("%s(%d), EXT_FRAME flag enabled, use st20p_tx_put_ext_frame instead\n", - __func__, idx); + err("%s(%d), EXT_FRAME flag enabled, use st20p_tx_put_ext_frame instead\n", __func__, + idx); return -EIO; } framebuff->user_meta_data_size = 0; if (frame->user_meta) { if (frame->user_meta_size > framebuff->user_meta_buffer_size) { - err("%s(%d), frame %u user meta size %" PRId64 " too large\n", __func__, - idx, producer_idx, frame->user_meta_size); + err("%s(%d), frame %u user meta size %" PRId64 " too large\n", __func__, idx, + producer_idx, frame->user_meta_size); framebuff->stat = ST20P_TX_FRAME_FREE; return -EIO; } @@ -682,8 +657,7 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame *frame) { } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = - frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; } if (ctx->internal_converter) { /* convert internal */ @@ -697,8 +671,7 @@ int st20p_tx_put_frame(st20p_tx_handle handle, struct st_frame *frame) { } ctx->stat_put_frame++; - MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], - framebuff->stat); + MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], framebuff->stat); /* check if dump USDT enabled */ if (MT_USDT_ST20P_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -738,8 +711,7 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame *frame, } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = - frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; } uint8_t planes = st_frame_fmt_planes(framebuff->src.fmt); @@ -750,8 +722,7 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame *frame, trans_ext_frame.buf_len = ext_frame->size; ret = st20_tx_set_ext_frame(ctx->transport, producer_idx, &trans_ext_frame); if (ret < 0) { - err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, - producer_idx); + err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, producer_idx); return -EIO; } framebuff->dst.addr[0] = ext_frame->addr[0]; @@ -786,8 +757,7 @@ int st20p_tx_put_ext_frame(st20p_tx_handle handle, struct st_frame *frame, } ctx->stat_put_frame++; - MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], - framebuff->stat); + MT_USDT_ST20P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], framebuff->stat); /* check if dump USDT enabled */ if (MT_USDT_ST20P_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -818,17 +788,14 @@ st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops *ops) { return NULL; } - src_size = - st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); + src_size = st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); if (!src_size) { err("%s(%d), get src size fail\n", __func__, idx); return NULL; } - enum mtl_port port = - mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20P_TX_FLAG_FORCE_NUMA) { @@ -845,8 +812,7 @@ st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops *ops) { ctx->idx = idx; ctx->socket_id = socket; ctx->ready = false; - ctx->derive = - st_frame_fmt_equal_transport(ops->input_fmt, ops->transport_fmt); + ctx->derive = st_frame_fmt_equal_transport(ops->input_fmt, ops->transport_fmt); ctx->impl = impl; ctx->type = MT_ST20_HANDLE_PIPELINE_TX; ctx->src_size = src_size; @@ -903,8 +869,7 @@ st20p_tx_handle st20p_tx_create(mtl_handle mt, struct st20p_tx_ops *ops) { st20p_tx_idx++; /* notify app can get frame */ - if (!ctx->block_get) - tx_st20p_notify_frame_available(ctx); + if (!ctx->block_get) tx_st20p_notify_frame_available(ctx); mt_stat_register(impl, tx_st20p_stat, ctx, ctx->ops_name); @@ -1016,8 +981,7 @@ int st20p_tx_get_port_stats(st20p_tx_handle handle, enum mtl_session_port port, return st20_tx_get_port_stats(ctx->transport, port, stats); } -int st20p_tx_reset_port_stats(st20p_tx_handle handle, - enum mtl_session_port port) { +int st20p_tx_reset_port_stats(st20p_tx_handle handle, enum mtl_session_port port) { struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; @@ -1029,8 +993,7 @@ int st20p_tx_reset_port_stats(st20p_tx_handle handle, return st20_tx_reset_port_stats(ctx->transport, port); } -int st20p_tx_update_destination(st20p_tx_handle handle, - struct st_tx_dest_info *dst) { +int st20p_tx_update_destination(st20p_tx_handle handle, struct st_tx_dest_info *dst) { struct st20p_tx_ctx *ctx = handle; int cidx = ctx->idx; @@ -1051,8 +1014,7 @@ int st20p_tx_wake_block(st20p_tx_handle handle) { return 0; } - if (ctx->block_get) - tx_st20p_block_wake(ctx); + if (ctx->block_get) tx_st20p_block_wake(ctx); return 0; } diff --git a/lib/src/st2110/pipeline/st22_pipeline_rx.c b/lib/src/st2110/pipeline/st22_pipeline_rx.c index d96aef5b7..6f0395556 100644 --- a/lib/src/st2110/pipeline/st22_pipeline_rx.c +++ b/lib/src/st2110/pipeline/st22_pipeline_rx.c @@ -18,8 +18,7 @@ static uint16_t rx_st22p_next_idx(struct st22p_rx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) - next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) next_idx = 0; return next_idx; } @@ -38,16 +37,14 @@ static void rx_st22p_decode_block_wake(struct st22p_rx_ctx *ctx) { } static void rx_st22p_decode_notify_frame_ready(struct st22p_rx_ctx *ctx) { - if (ctx->derive) - return; /* no decoder for derive mode */ + if (ctx->derive) return; /* no decoder for derive mode */ struct st22_decode_session_impl *decoder = ctx->decode_impl; struct st22_decode_dev_impl *dev_impl = decoder->parent; struct st22_decoder_dev *dev = &dev_impl->dev; st22_decode_priv session = decoder->session; - if (dev->notify_frame_available) - dev->notify_frame_available(session); + if (dev->notify_frame_available) dev->notify_frame_available(session); if (ctx->decode_block_get) { /* notify block */ @@ -66,9 +63,8 @@ static void rx_st22p_notify_frame_available(struct st22p_rx_ctx *ctx) { } } -static struct st22p_rx_frame * -rx_st22p_next_available(struct st22p_rx_ctx *ctx, uint16_t idx_start, - enum st22p_rx_frame_status desired) { +static struct st22p_rx_frame *rx_st22p_next_available( + struct st22p_rx_ctx *ctx, uint16_t idx_start, enum st22p_rx_frame_status desired) { uint16_t idx = idx_start; struct st22p_rx_frame *framebuff; @@ -96,12 +92,11 @@ static int rx_st22p_frame_ready(void *priv, void *frame, struct st22p_rx_frame *framebuff; int ret; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st22p_next_available(ctx, ctx->framebuff_producer_idx, - ST22P_RX_FRAME_FREE); + framebuff = + rx_st22p_next_available(ctx, ctx->framebuff_producer_idx, ST22P_RX_FRAME_FREE); /* not any free frame */ if (!framebuff) { rte_atomic32_inc(&ctx->stat_busy); @@ -109,8 +104,8 @@ static int rx_st22p_frame_ready(void *priv, void *frame, return -EBUSY; } - MT_USDT_ST22P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, - meta->rtp_timestamp, meta->frame_total_size); + MT_USDT_ST22P_RX_FRAME_AVAILABLE(ctx->idx, framebuff->idx, frame, meta->rtp_timestamp, + meta->frame_total_size); if (ctx->ext_frame) { struct st_ext_frame ext_frame; @@ -148,16 +143,14 @@ static int rx_st22p_frame_ready(void *priv, void *frame, framebuff->dst.tfmt = meta->tfmt; /* set dst timestamp to same as src? */ framebuff->dst.timestamp = meta->timestamp; - framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = - meta->rtp_timestamp; + framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp; /* if second field */ - framebuff->dst.second_field = framebuff->src.second_field = - meta->second_field; + framebuff->dst.second_field = framebuff->src.second_field = meta->second_field; framebuff->src.pkts_total = framebuff->dst.pkts_total = meta->pkts_total; - for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; - s_port < MTL_SESSION_PORT_MAX; s_port++) { + for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; s_port < MTL_SESSION_PORT_MAX; + s_port++) { framebuff->src.pkts_recv[s_port] = framebuff->dst.pkts_recv[s_port] = meta->pkts_recv[s_port]; } @@ -230,8 +223,7 @@ static struct st22_decode_frame_meta *rx_st22p_decode_get_frame(void *priv) { dbg("%s(%d), not ready %d\n", __func__, idx, ctx->type); if (ctx->decode_block_get) { rx_st22p_decode_get_block_wait(ctx); - if (!ctx->ready) - return NULL; + if (!ctx->ready) return NULL; } return NULL; /* not ready */ } @@ -239,15 +231,15 @@ static struct st22_decode_frame_meta *rx_st22p_decode_get_frame(void *priv) { ctx->stat_decode_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, - ST22P_RX_FRAME_READY); + framebuff = + rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, ST22P_RX_FRAME_READY); if (!framebuff && ctx->decode_block_get) { /* wait here for block mode */ mt_pthread_mutex_unlock(&ctx->lock); rx_st22p_decode_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, - ST22P_RX_FRAME_READY); + framebuff = + rx_st22p_next_available(ctx, ctx->framebuff_decode_idx, ST22P_RX_FRAME_READY); } /* not any ready frame */ if (!framebuff) { @@ -269,8 +261,7 @@ static struct st22_decode_frame_meta *rx_st22p_decode_get_frame(void *priv) { return frame; } -static int rx_st22p_decode_put_frame(void *priv, - struct st22_decode_frame_meta *frame, +static int rx_st22p_decode_put_frame(void *priv, struct st22_decode_frame_meta *frame, int result) { struct st22p_rx_ctx *ctx = priv; int idx = ctx->idx; @@ -309,16 +300,15 @@ static int rx_st22p_decode_dump(void *priv) { struct st22p_rx_ctx *ctx = priv; struct st22p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t decode_idx = ctx->framebuff_decode_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("RX_ST22P(%s), p(%d:%s) d(%d:%s) c(%d:%s)\n", ctx->ops_name, - producer_idx, rx_st22p_stat_name(framebuff[producer_idx].stat), - decode_idx, rx_st22p_stat_name(framebuff[decode_idx].stat), - consumer_idx, rx_st22p_stat_name(framebuff[consumer_idx].stat)); + notice("RX_ST22P(%s), p(%d:%s) d(%d:%s) c(%d:%s)\n", ctx->ops_name, producer_idx, + rx_st22p_stat_name(framebuff[producer_idx].stat), decode_idx, + rx_st22p_stat_name(framebuff[decode_idx].stat), consumer_idx, + rx_st22p_stat_name(framebuff[consumer_idx].stat)); int decode_fail = rte_atomic32_read(&ctx->stat_decode_fail); rte_atomic32_set(&ctx->stat_decode_fail, 0); @@ -333,8 +323,7 @@ static int rx_st22p_decode_dump(void *priv) { } notice("RX_ST22P(%s), frame get try %d succ %d, put %d\n", ctx->ops_name, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, - ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -349,8 +338,7 @@ static int rx_st22p_decode_dump(void *priv) { return 0; } -static int rx_st22p_create_transport(struct mtl_main_impl *impl, - struct st22p_rx_ctx *ctx, +static int rx_st22p_create_transport(struct mtl_main_impl *impl, struct st22p_rx_ctx *ctx, struct st22p_rx_ops *ops) { int idx = ctx->idx; struct st22_rx_ops ops_rx; @@ -362,15 +350,13 @@ static int rx_st22p_create_transport(struct mtl_main_impl *impl, ops_rx.num_port = RTE_MIN(ops->port.num_port, MTL_SESSION_PORT_MAX); for (int i = 0; i < ops_rx.num_port; i++) { memcpy(ops_rx.ip_addr[i], ops->port.ip_addr[i], MTL_IP_ADDR_LEN); - memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[i], MTL_PORT_MAX_LEN, "%s", ops->port.port[i]); ops_rx.udp_port[i] = ops->port.udp_port[i]; } if (ops->flags & ST22P_RX_FLAG_DATA_PATH_ONLY) ops_rx.flags |= ST22_RX_FLAG_DATA_PATH_ONLY; - if (ops->flags & ST22P_RX_FLAG_ENABLE_VSYNC) - ops_rx.flags |= ST22_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22P_RX_FLAG_ENABLE_VSYNC) ops_rx.flags |= ST22_RX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22P_RX_FLAG_ENABLE_RTCP) { ops_rx.flags |= ST22_RX_FLAG_ENABLE_RTCP; ops_rx.rtcp = ops->rtcp; @@ -439,8 +425,7 @@ static int rx_st22p_uinit_dst_fbs(struct st22p_rx_ctx *ctx) { return 0; } -static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx *ctx, - struct st22p_rx_ops *ops) { +static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx *ctx, struct st22p_rx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; struct st22p_rx_frame *frames; @@ -466,8 +451,7 @@ static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx *ctx, frames[i].dst.height = ops->height; frames[i].dst.priv = &frames[i]; - if (ctx->derive) - continue; /* skip the plane init */ + if (ctx->derive) continue; /* skip the plane init */ if (ctx->ext_frame) { /* will use ext frame from user */ uint8_t planes = st_frame_fmt_planes(frames[i].dst.fmt); @@ -496,13 +480,12 @@ static int rx_st22p_init_dst_fbs(struct st22p_rx_ctx *ctx, } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, - dst_size, ops->output_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, dst_size, + ops->output_fmt, ctx->framebuff_cnt); return 0; } -static int rx_st22p_get_decoder(struct mtl_main_impl *impl, - struct st22p_rx_ctx *ctx, +static int rx_st22p_get_decoder(struct mtl_main_impl *impl, struct st22p_rx_ctx *ctx, struct st22p_rx_ops *ops) { int idx = ctx->idx; struct st22_get_decoder_request req; @@ -552,8 +535,7 @@ static int rx_st22p_get_block_wait(struct st22p_rx_ctx *ctx) { return 0; } -static int rx_st22p_usdt_dump_frame(struct st22p_rx_ctx *ctx, - struct st_frame *frame) { +static int rx_st22p_usdt_dump_frame(struct st22p_rx_ctx *ctx, struct st_frame *frame) { int idx = ctx->idx; struct mtl_main_impl *impl = ctx->impl; int fd; @@ -562,8 +544,7 @@ static int rx_st22p_usdt_dump_frame(struct st22p_rx_ctx *ctx, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, - ops->height); + "imtl_usdt_st22prx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -595,21 +576,20 @@ struct st_frame *st22p_rx_get_frame(st22p_rx_handle handle) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, - ST22P_RX_FRAME_DECODED); + framebuff = + rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, ST22P_RX_FRAME_DECODED); if (!framebuff && ctx->block_get) { mt_pthread_mutex_unlock(&ctx->lock); rx_st22p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, - ST22P_RX_FRAME_DECODED); + framebuff = + rx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, ST22P_RX_FRAME_DECODED); } /* not any decoded frame */ if (!framebuff) { @@ -625,8 +605,7 @@ struct st_frame *st22p_rx_get_frame(st22p_rx_handle handle) { dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); ctx->stat_get_frame_succ++; struct st_frame *frame = &framebuff->dst; - MT_USDT_ST22P_RX_FRAME_GET(idx, framebuff->idx, frame->addr[0], - frame->data_size); + MT_USDT_ST22P_RX_FRAME_GET(idx, framebuff->idx, frame->addr[0], frame->data_size); /* check if dump USDT enabled */ if (!ctx->derive && MT_USDT_ST22P_RX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -685,8 +664,7 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops) { if (ops->flags & ST22P_RX_FLAG_EXT_FRAME) { if (!ops->query_ext_frame) { - err("%s, no query_ext_frame query callback for ext frame mode\n", - __func__); + err("%s, no query_ext_frame query callback for ext frame mode\n", __func__); return NULL; } } @@ -697,10 +675,8 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops) { return NULL; } - enum mtl_port port = - mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22P_RX_FLAG_FORCE_NUMA) { @@ -722,8 +698,7 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops) { if (ctx->derive) { dst_size = 0; } else { - dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, - ops->interlaced); + dst_size = st_frame_size(ops->output_fmt, ops->width, ops->height, ops->interlaced); if (!dst_size) { err("%s(%d), get dst size fail\n", __func__, idx); return NULL; @@ -739,12 +714,12 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops) { ctx->dst_size = dst_size; /* use the possible max size */ ctx->max_codestream_size = ops->max_codestream_size; - if (!ctx->max_codestream_size) - ctx->max_codestream_size = dst_size; + if (!ctx->max_codestream_size) ctx->max_codestream_size = dst_size; if (ctx->derive && !ctx->max_codestream_size) { - warn("%s(%d), codestream_size is not set by user in derive mode, use " - "default 1M\n", - __func__, idx); + warn( + "%s(%d), codestream_size is not set by user in derive mode, use " + "default 1M\n", + __func__, idx); ctx->max_codestream_size = 0x100000; } rte_atomic32_set(&ctx->stat_decode_fail, 0); @@ -758,8 +733,7 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; - if (ops->flags & ST22P_RX_FLAG_BLOCK_GET) - ctx->block_get = true; + if (ops->flags & ST22P_RX_FLAG_BLOCK_GET) ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -797,13 +771,12 @@ st22p_rx_handle st22p_rx_create(mtl_handle mt, struct st22p_rx_ops *ops) { /* all ready now */ ctx->ready = true; - notice("%s(%d), codestream fmt %s, output fmt: %s, flags 0x%x\n", __func__, - idx, st_frame_fmt_name(ctx->codestream_fmt), - st_frame_fmt_name(ops->output_fmt), ops->flags); + notice("%s(%d), codestream fmt %s, output fmt: %s, flags 0x%x\n", __func__, idx, + st_frame_fmt_name(ctx->codestream_fmt), st_frame_fmt_name(ops->output_fmt), + ops->flags); st22p_rx_idx++; - if (!ctx->block_get) - rx_st22p_notify_frame_available(ctx); + if (!ctx->block_get) rx_st22p_notify_frame_available(ctx); return ctx; } @@ -876,8 +849,7 @@ size_t st22p_rx_frame_size(st22p_rx_handle handle) { return ctx->dst_size; } -int st22p_rx_get_queue_meta(st22p_rx_handle handle, - struct st_queue_meta *meta) { +int st22p_rx_get_queue_meta(st22p_rx_handle handle, struct st_queue_meta *meta) { struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -889,8 +861,8 @@ int st22p_rx_get_queue_meta(st22p_rx_handle handle, return st22_rx_get_queue_meta(ctx->transport, meta); } -int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta) { +int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta) { struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -902,8 +874,7 @@ int st22p_rx_pcapng_dump(st22p_rx_handle handle, uint32_t max_dump_packets, return st22_rx_pcapng_dump(ctx->transport, max_dump_packets, sync, meta); } -int st22p_rx_update_source(st22p_rx_handle handle, - struct st_rx_source_info *src) { +int st22p_rx_update_source(st22p_rx_handle handle, struct st_rx_source_info *src) { struct st22p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -924,8 +895,7 @@ int st22p_rx_wake_block(st22p_rx_handle handle) { return 0; } - if (ctx->block_get) - rx_st22p_block_wake(ctx); + if (ctx->block_get) rx_st22p_block_wake(ctx); return 0; } diff --git a/lib/src/st2110/pipeline/st22_pipeline_tx.c b/lib/src/st2110/pipeline/st22_pipeline_tx.c index 8840d5482..acf969fdd 100644 --- a/lib/src/st2110/pipeline/st22_pipeline_tx.c +++ b/lib/src/st2110/pipeline/st22_pipeline_tx.c @@ -14,9 +14,8 @@ static const char *tx_st22p_stat_name(enum st22p_tx_frame_status stat) { return st22p_tx_frame_stat_name[stat]; } -static inline struct st_frame * -tx_st22p_user_frame(struct st22p_tx_ctx *ctx, - struct st22p_tx_frame *framebuff) { +static inline struct st_frame *tx_st22p_user_frame(struct st22p_tx_ctx *ctx, + struct st22p_tx_frame *framebuff) { return ctx->derive ? &framebuff->dst : &framebuff->src; } @@ -24,8 +23,7 @@ static uint16_t tx_st22p_next_idx(struct st22p_tx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) - next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) next_idx = 0; return next_idx; } @@ -55,16 +53,14 @@ static void tx_st22p_encode_block_wake(struct st22p_tx_ctx *ctx) { } static void tx_st22p_encode_notify_frame_ready(struct st22p_tx_ctx *ctx) { - if (ctx->derive) - return; /* no encoder for derive mode */ + if (ctx->derive) return; /* no encoder for derive mode */ struct st22_encode_session_impl *encoder = ctx->encode_impl; struct st22_encode_dev_impl *dev_impl = encoder->parent; struct st22_encoder_dev *dev = &dev_impl->dev; st22_encode_priv session = encoder->session; - if (dev->notify_frame_available) - dev->notify_frame_available(session); + if (dev->notify_frame_available) dev->notify_frame_available(session); if (ctx->encode_block_get) { /* notify block */ @@ -72,9 +68,8 @@ static void tx_st22p_encode_notify_frame_ready(struct st22p_tx_ctx *ctx) { } } -static struct st22p_tx_frame * -tx_st22p_next_available(struct st22p_tx_ctx *ctx, uint16_t idx_start, - enum st22p_tx_frame_status desired) { +static struct st22p_tx_frame *tx_st22p_next_available( + struct st22p_tx_ctx *ctx, uint16_t idx_start, enum st22p_tx_frame_status desired) { uint16_t idx = idx_start; struct st22p_tx_frame *framebuff; @@ -101,12 +96,11 @@ static int tx_st22p_next_frame(void *priv, uint16_t *next_frame_idx, struct st22p_tx_ctx *ctx = priv; struct st22p_tx_frame *framebuff; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, - ST22P_TX_FRAME_ENCODED); + framebuff = + tx_st22p_next_available(ctx, ctx->framebuff_consumer_idx, ST22P_TX_FRAME_ENCODED); /* not any encoded frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -118,8 +112,7 @@ static int tx_st22p_next_frame(void *priv, uint16_t *next_frame_idx, struct st_frame *frame = tx_st22p_user_frame(ctx, framebuff); meta->second_field = frame->second_field; - if (ctx->ops.flags & - (ST22P_TX_FLAG_USER_PACING | ST22P_TX_FLAG_USER_TIMESTAMP)) { + if (ctx->ops.flags & (ST22P_TX_FLAG_USER_PACING | ST22P_TX_FLAG_USER_TIMESTAMP)) { meta->tfmt = frame->tfmt; meta->timestamp = frame->timestamp; dbg("%s(%d), frame %u succ timestamp %" PRIu64 "\n", __func__, ctx->idx, @@ -147,8 +140,8 @@ static int tx_st22p_frame_done(void *priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, ctx->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, framebuff->stat, + frame_idx); } mt_pthread_mutex_unlock(&ctx->lock); @@ -156,8 +149,7 @@ static int tx_st22p_frame_done(void *priv, uint16_t frame_idx, framebuff->dst.tfmt = meta->tfmt; framebuff->src.timestamp = meta->timestamp; framebuff->dst.timestamp = meta->timestamp; - framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = - meta->rtp_timestamp; + framebuff->src.rtp_timestamp = framebuff->dst.rtp_timestamp = meta->rtp_timestamp; if (ctx->ops.notify_frame_done) { /* notify app which frame done */ struct st_frame *frame = tx_st22p_user_frame(ctx, framebuff); @@ -218,8 +210,7 @@ static struct st22_encode_frame_meta *tx_st22p_encode_get_frame(void *priv) { dbg("%s(%d), not ready %d\n", __func__, idx, ctx->type); if (ctx->encode_block_get) { tx_st22p_encode_get_block_wait(ctx); - if (!ctx->ready) - return NULL; + if (!ctx->ready) return NULL; } return NULL; /* not ready */ } @@ -227,15 +218,15 @@ static struct st22_encode_frame_meta *tx_st22p_encode_get_frame(void *priv) { ctx->stat_encode_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, - ST22P_TX_FRAME_READY); + framebuff = + tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, ST22P_TX_FRAME_READY); if (!framebuff && ctx->encode_block_get) { /* wait here for block mode */ mt_pthread_mutex_unlock(&ctx->lock); tx_st22p_encode_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, - ST22P_TX_FRAME_READY); + framebuff = + tx_st22p_next_available(ctx, ctx->framebuff_encode_idx, ST22P_TX_FRAME_READY); } /* not any free frame */ if (!framebuff) { @@ -258,11 +249,9 @@ static struct st22_encode_frame_meta *tx_st22p_encode_get_frame(void *priv) { } /* min frame size should be capable of bulk pkts */ -#define ST22_ENCODE_MIN_FRAME_SZ \ - ((ST_SESSION_MAX_BULK + 1) * MTL_PKT_MAX_RTP_BYTES) +#define ST22_ENCODE_MIN_FRAME_SZ ((ST_SESSION_MAX_BULK + 1) * MTL_PKT_MAX_RTP_BYTES) -static int tx_st22p_encode_put_frame(void *priv, - struct st22_encode_frame_meta *frame, +static int tx_st22p_encode_put_frame(void *priv, struct st22_encode_frame_meta *frame, int result) { struct st22p_tx_ctx *ctx = priv; int idx = ctx->idx; @@ -283,10 +272,9 @@ static int tx_st22p_encode_put_frame(void *priv, } ctx->stat_encode_put_frame++; - dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, - encode_idx, result, data_size); - if ((result < 0) || (data_size <= ST22_ENCODE_MIN_FRAME_SZ) || - (data_size > max_size)) { + dbg("%s(%d), frame %u result %d data_size %" PRIu64 "\n", __func__, idx, encode_idx, + result, data_size); + if ((result < 0) || (data_size <= ST22_ENCODE_MIN_FRAME_SZ) || (data_size > max_size)) { warn("%s(%d), invalid frame %u result %d data_size %" PRIu64 ", allowed min %u max %" PRIu64 "\n", __func__, idx, encode_idx, result, data_size, ST22_ENCODE_MIN_FRAME_SZ, @@ -307,16 +295,15 @@ static int tx_st22p_encode_dump(void *priv) { struct st22p_tx_ctx *ctx = priv; struct st22p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t encode_idx = ctx->framebuff_encode_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("TX_ST22P(%s), p(%d:%s) e(%d:%s) c(%d:%s)\n", ctx->ops_name, - producer_idx, tx_st22p_stat_name(framebuff[producer_idx].stat), - encode_idx, tx_st22p_stat_name(framebuff[encode_idx].stat), - consumer_idx, tx_st22p_stat_name(framebuff[consumer_idx].stat)); + notice("TX_ST22P(%s), p(%d:%s) e(%d:%s) c(%d:%s)\n", ctx->ops_name, producer_idx, + tx_st22p_stat_name(framebuff[producer_idx].stat), encode_idx, + tx_st22p_stat_name(framebuff[encode_idx].stat), consumer_idx, + tx_st22p_stat_name(framebuff[consumer_idx].stat)); int encode_fail = rte_atomic32_read(&ctx->stat_encode_fail); rte_atomic32_set(&ctx->stat_encode_fail, 0); @@ -325,8 +312,7 @@ static int tx_st22p_encode_dump(void *priv) { } notice("TX_ST22P(%s), frame get try %d succ %d, put %d\n", ctx->ops_name, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, - ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -341,8 +327,7 @@ static int tx_st22p_encode_dump(void *priv) { return 0; } -static int tx_st22p_create_transport(struct mtl_main_impl *impl, - struct st22p_tx_ctx *ctx, +static int tx_st22p_create_transport(struct mtl_main_impl *impl, struct st22p_tx_ctx *ctx, struct st22p_tx_ops *ops) { int idx = ctx->idx; struct st22_tx_ops ops_tx; @@ -359,29 +344,26 @@ static int tx_st22p_create_transport(struct mtl_main_impl *impl, ops_tx.udp_port[i] = ops->port.udp_port[i]; } if (ops->flags & ST22P_TX_FLAG_USER_P_MAC) { - memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_P][0], - &ops->tx_dst_mac[MTL_PORT_P][0], MTL_MAC_ADDR_LEN); + memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_P][0], &ops->tx_dst_mac[MTL_PORT_P][0], + MTL_MAC_ADDR_LEN); ops_tx.flags |= ST22_TX_FLAG_USER_P_MAC; } if (ops->flags & ST22P_TX_FLAG_USER_R_MAC) { - memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_R][0], - &ops->tx_dst_mac[MTL_PORT_R][0], MTL_MAC_ADDR_LEN); + memcpy(&ops_tx.tx_dst_mac[MTL_SESSION_PORT_R][0], &ops->tx_dst_mac[MTL_PORT_R][0], + MTL_MAC_ADDR_LEN); ops_tx.flags |= ST22_TX_FLAG_USER_R_MAC; } if (ops->flags & ST22P_TX_FLAG_DISABLE_BOXES) ops_tx.flags |= ST22_TX_FLAG_DISABLE_BOXES; - if (ops->flags & ST22P_TX_FLAG_USER_PACING) - ops_tx.flags |= ST22_TX_FLAG_USER_PACING; + if (ops->flags & ST22P_TX_FLAG_USER_PACING) ops_tx.flags |= ST22_TX_FLAG_USER_PACING; if (ops->flags & ST22P_TX_FLAG_USER_TIMESTAMP) ops_tx.flags |= ST22_TX_FLAG_USER_TIMESTAMP; - if (ops->flags & ST22P_TX_FLAG_ENABLE_VSYNC) - ops_tx.flags |= ST22_TX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22P_TX_FLAG_ENABLE_VSYNC) ops_tx.flags |= ST22_TX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22P_TX_FLAG_ENABLE_RTCP) { ops_tx.flags |= ST22_TX_FLAG_ENABLE_RTCP; ops_tx.rtcp = ops->rtcp; } - if (ops->flags & ST22P_TX_FLAG_DISABLE_BULK) - ops_tx.flags |= ST22_TX_FLAG_DISABLE_BULK; + if (ops->flags & ST22P_TX_FLAG_DISABLE_BULK) ops_tx.flags |= ST22_TX_FLAG_DISABLE_BULK; if (ops->flags & ST22P_TX_FLAG_FORCE_NUMA) { ops_tx.socket_id = ops->socket_id; ops_tx.flags |= ST22_TX_FLAG_FORCE_NUMA; @@ -456,8 +438,7 @@ static int tx_st22p_uinit_src_fbs(struct st22p_tx_ctx *ctx) { return 0; } -static int tx_st22p_init_src_fbs(struct st22p_tx_ctx *ctx, - struct st22p_tx_ops *ops) { +static int tx_st22p_init_src_fbs(struct st22p_tx_ctx *ctx, struct st22p_tx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; struct st22p_tx_frame *frames; @@ -483,8 +464,7 @@ static int tx_st22p_init_src_fbs(struct st22p_tx_ctx *ctx, frames[i].src.height = ops->height; frames[i].src.priv = &frames[i]; - if (ctx->derive) - continue; /* skip the plane init */ + if (ctx->derive) continue; /* skip the plane init */ if (ctx->ext_frame) { /* will use ext frame from user */ uint8_t planes = st_frame_fmt_planes(frames[i].src.fmt); @@ -513,13 +493,12 @@ static int tx_st22p_init_src_fbs(struct st22p_tx_ctx *ctx, } } - info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, - src_size, ops->input_fmt, ctx->framebuff_cnt); + info("%s(%d), size %" PRIu64 " fmt %d with %u frames\n", __func__, idx, src_size, + ops->input_fmt, ctx->framebuff_cnt); return 0; } -static int tx_st22p_get_encoder(struct mtl_main_impl *impl, - struct st22p_tx_ctx *ctx, +static int tx_st22p_get_encoder(struct mtl_main_impl *impl, struct st22p_tx_ctx *ctx, struct st22p_tx_ops *ops) { int idx = ctx->idx; struct st22_get_encoder_request req; @@ -575,8 +554,7 @@ static int tx_st22p_get_block_wait(struct st22p_tx_ctx *ctx) { return 0; } -static int tx_st22p_usdt_dump_frame(struct st22p_tx_ctx *ctx, - struct st_frame *frame) { +static int tx_st22p_usdt_dump_frame(struct st22p_tx_ctx *ctx, struct st_frame *frame) { int idx = ctx->idx; struct mtl_main_impl *impl = ctx->impl; int fd; @@ -585,8 +563,7 @@ static int tx_st22p_usdt_dump_frame(struct st22p_tx_ctx *ctx, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, - ops->height); + "imtl_usdt_st22ptx_s%d_%d_%d_XXXXXX.yuv", idx, ops->width, ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -615,8 +592,7 @@ static void tx_st22p_framebuffs_flush(struct st22p_tx_ctx *ctx) { int retry = 0; while (1) { - if (framebuff->stat == ST22P_TX_FRAME_FREE) - break; + if (framebuff->stat == ST22P_TX_FRAME_FREE) break; if (framebuff->stat == ST22P_TX_FRAME_IN_TRANSMITTING) { /* * make sure to wait when the frame is in transmit @@ -630,8 +606,8 @@ static void tx_st22p_framebuffs_flush(struct st22p_tx_ctx *ctx) { tx_st22p_stat_name(framebuff->stat), retry); retry++; if (retry > 100) { - info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, - i, tx_st22p_stat_name(framebuff->stat), retry); + info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, i, + tx_st22p_stat_name(framebuff->stat), retry); break; } mt_sleep_ms(10); @@ -649,21 +625,20 @@ struct st_frame *st22p_tx_get_frame(st22p_tx_handle handle) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, - ST22P_TX_FRAME_FREE); + framebuff = + tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, ST22P_TX_FRAME_FREE); if (!framebuff && ctx->block_get) { mt_pthread_mutex_unlock(&ctx->lock); tx_st22p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, - ST22P_TX_FRAME_FREE); + framebuff = + tx_st22p_next_available(ctx, ctx->framebuff_producer_idx, ST22P_TX_FRAME_FREE); } /* not any free frame */ if (!framebuff) { @@ -677,16 +652,13 @@ struct st_frame *st22p_tx_get_frame(st22p_tx_handle handle) { mt_pthread_mutex_unlock(&ctx->lock); dbg("%s(%d), frame %u succ\n", __func__, idx, framebuff->idx); - if (ctx->ops - .interlaced) { /* init second_field but user still can customize */ - framebuff->dst.second_field = framebuff->src.second_field = - ctx->second_field; + if (ctx->ops.interlaced) { /* init second_field but user still can customize */ + framebuff->dst.second_field = framebuff->src.second_field = ctx->second_field; ctx->second_field = ctx->second_field ? false : true; } ctx->stat_get_frame_succ++; struct st_frame *frame = tx_st22p_user_frame(ctx, framebuff); - dbg("%s(%d), frame %u addr %p\n", __func__, idx, framebuff->idx, - frame->addr[0]); + dbg("%s(%d), frame %u addr %p\n", __func__, idx, framebuff->idx, frame->addr[0]); MT_USDT_ST22P_TX_FRAME_GET(idx, framebuff->idx, frame->addr[0]); return frame; } @@ -709,14 +681,12 @@ int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame *frame) { } if (ctx->ext_frame) { - err("%s(%d), EXT_FRAME enabled, use st22p_tx_put_ext_frame instead\n", - __func__, idx); + err("%s(%d), EXT_FRAME enabled, use st22p_tx_put_ext_frame instead\n", __func__, idx); return -EIO; } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = - frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; } if (ctx->derive) { @@ -727,8 +697,8 @@ int st22p_tx_put_frame(st22p_tx_handle handle, struct st_frame *frame) { } ctx->stat_put_frame++; - MT_USDT_ST22P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], - framebuff->stat, frame->data_size); + MT_USDT_ST22P_TX_FRAME_PUT(idx, framebuff->idx, frame->addr[0], framebuff->stat, + frame->data_size); /* check if dump USDT enabled */ if (!ctx->derive && MT_USDT_ST22P_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ctx->ops.fps) * 5; /* dump every 5s now */ @@ -791,8 +761,7 @@ int st22p_tx_put_ext_frame(st22p_tx_handle handle, struct st_frame *frame, } if (ctx->ops.interlaced) { /* update second_field */ - framebuff->dst.second_field = framebuff->src.second_field = - frame->second_field; + framebuff->dst.second_field = framebuff->src.second_field = frame->second_field; } framebuff->stat = ST22P_TX_FRAME_READY; @@ -825,10 +794,8 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops *ops) { return NULL; } - enum mtl_port port = - mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22P_TX_FLAG_FORCE_NUMA) { @@ -851,14 +818,14 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops *ops) { if (ctx->derive) { src_size = ops->codestream_size; if (!src_size) { - warn("%s(%d), codestream_size is not set by user in derive mode, use " - "default 1M\n", - __func__, idx); + warn( + "%s(%d), codestream_size is not set by user in derive mode, use " + "default 1M\n", + __func__, idx); src_size = 0x100000; } } else { - src_size = - st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); + src_size = st_frame_size(ops->input_fmt, ops->width, ops->height, ops->interlaced); if (!src_size) { err("%s(%d), get source size fail\n", __func__, idx); return NULL; @@ -882,8 +849,7 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops *ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; /* default to 1s */ - if (ops->flags & ST22P_TX_FLAG_BLOCK_GET) - ctx->block_get = true; + if (ops->flags & ST22P_TX_FLAG_BLOCK_GET) ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -921,13 +887,12 @@ st22p_tx_handle st22p_tx_create(mtl_handle mt, struct st22p_tx_ops *ops) { /* all ready now */ ctx->ready = true; - notice("%s(%d), codestream fmt %s, input fmt: %s, flags 0x%x\n", __func__, - idx, st_frame_fmt_name(ctx->codestream_fmt), - st_frame_fmt_name(ops->input_fmt), ops->flags); + notice("%s(%d), codestream fmt %s, input fmt: %s, flags 0x%x\n", __func__, idx, + st_frame_fmt_name(ctx->codestream_fmt), st_frame_fmt_name(ops->input_fmt), + ops->flags); st22p_tx_idx++; - if (!ctx->block_get) - tx_st22p_notify_frame_available(ctx); + if (!ctx->block_get) tx_st22p_notify_frame_available(ctx); return ctx; } @@ -1004,8 +969,7 @@ size_t st22p_tx_frame_size(st22p_tx_handle handle) { return ctx->src_size; } -int st22p_tx_update_destination(st22p_tx_handle handle, - struct st_tx_dest_info *dst) { +int st22p_tx_update_destination(st22p_tx_handle handle, struct st_tx_dest_info *dst) { struct st22p_tx_ctx *ctx = handle; int cidx = ctx->idx; @@ -1026,8 +990,7 @@ int st22p_tx_wake_block(st22p_tx_handle handle) { return 0; } - if (ctx->block_get) - tx_st22p_block_wake(ctx); + if (ctx->block_get) tx_st22p_block_wake(ctx); return 0; } diff --git a/lib/src/st2110/pipeline/st30_pipeline_rx.c b/lib/src/st2110/pipeline/st30_pipeline_rx.c index 3f1f8fc23..a20de65fd 100644 --- a/lib/src/st2110/pipeline/st30_pipeline_rx.c +++ b/lib/src/st2110/pipeline/st30_pipeline_rx.c @@ -21,8 +21,7 @@ static uint16_t rx_st30p_next_idx(struct st30p_rx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) - next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) next_idx = 0; return next_idx; } @@ -44,9 +43,8 @@ static void rx_st30p_notify_frame_available(struct st30p_rx_ctx *ctx) { } } -static struct st30p_rx_frame * -rx_st30p_next_available(struct st30p_rx_ctx *ctx, uint16_t idx_start, - enum st30p_rx_frame_status desired) { +static struct st30p_rx_frame *rx_st30p_next_available( + struct st30p_rx_ctx *ctx, uint16_t idx_start, enum st30p_rx_frame_status desired) { uint16_t idx = idx_start; struct st30p_rx_frame *framebuff; @@ -68,17 +66,15 @@ rx_st30p_next_available(struct st30p_rx_ctx *ctx, uint16_t idx_start, return NULL; } -static int rx_st30p_frame_ready(void *priv, void *addr, - struct st30_rx_frame_meta *meta) { +static int rx_st30p_frame_ready(void *priv, void *addr, struct st30_rx_frame_meta *meta) { struct st30p_rx_ctx *ctx = priv; struct st30p_rx_frame *framebuff; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st30p_next_available(ctx, ctx->framebuff_producer_idx, - ST30P_RX_FRAME_FREE); + framebuff = + rx_st30p_next_available(ctx, ctx->framebuff_producer_idx, ST30P_RX_FRAME_FREE); /* not any free frame */ if (!framebuff) { @@ -98,8 +94,7 @@ static int rx_st30p_frame_ready(void *priv, void *addr, ctx->framebuff_producer_idx = rx_st30p_next_idx(ctx, framebuff->idx); mt_pthread_mutex_unlock(&ctx->lock); - dbg("%s(%d), frame %u(%p) succ\n", __func__, ctx->idx, framebuff->idx, - frame->addr); + dbg("%s(%d), frame %u(%p) succ\n", __func__, ctx->idx, framebuff->idx, frame->addr); /* notify app to a ready frame */ rx_st30p_notify_frame_available(ctx); @@ -108,8 +103,7 @@ static int rx_st30p_frame_ready(void *priv, void *addr, return 0; } -static int rx_st30p_create_transport(struct mtl_main_impl *impl, - struct st30p_rx_ctx *ctx, +static int rx_st30p_create_transport(struct mtl_main_impl *impl, struct st30p_rx_ctx *ctx, struct st30p_rx_ops *ops) { int idx = ctx->idx; struct st30_rx_ops ops_rx; @@ -123,8 +117,7 @@ static int rx_st30p_create_transport(struct mtl_main_impl *impl, ops_rx.ssrc = ops->port.ssrc; for (int i = 0; i < ops_rx.num_port; i++) { memcpy(ops_rx.ip_addr[i], ops->port.ip_addr[i], MTL_IP_ADDR_LEN); - memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], - MTL_IP_ADDR_LEN); + memcpy(ops_rx.mcast_sip_addr[i], ops->port.mcast_sip_addr[i], MTL_IP_ADDR_LEN); snprintf(ops_rx.port[i], MTL_PORT_MAX_LEN, "%s", ops->port.port[i]); ops_rx.udp_port[i] = ops->port.udp_port[i]; } @@ -165,8 +158,7 @@ static int rx_st30p_uinit_fbs(struct st30p_rx_ctx *ctx) { return 0; } -static int rx_st30p_init_fbs(struct st30p_rx_ctx *ctx, - struct st30p_rx_ops *ops) { +static int rx_st30p_init_fbs(struct st30p_rx_ctx *ctx, struct st30p_rx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; struct st30p_rx_frame *frames; @@ -203,25 +195,22 @@ static int rx_st30p_stat(void *priv) { struct st30p_rx_ctx *ctx = priv; struct st30p_rx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("RX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, - producer_idx, rx_st30p_stat_name(framebuff[producer_idx].stat), - consumer_idx, rx_st30p_stat_name(framebuff[consumer_idx].stat)); + notice("RX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, + rx_st30p_stat_name(framebuff[producer_idx].stat), consumer_idx, + rx_st30p_stat_name(framebuff[consumer_idx].stat)); notice("RX_st30p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, - ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; if (ctx->stat_busy) { - warn("RX_st30p(%d), stat_busy %d in rx frame ready\n", ctx->idx, - ctx->stat_busy); + warn("RX_st30p(%d), stat_busy %d in rx frame ready\n", ctx->idx, ctx->stat_busy); ctx->stat_busy = 0; } @@ -243,16 +232,15 @@ static int rx_st30p_usdt_dump_close(struct st30p_rx_ctx *ctx) { int idx = ctx->idx; if (ctx->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, - ctx->usdt_dump_fd, ctx->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, ctx->usdt_dump_fd, + ctx->usdt_dumped_frames); close(ctx->usdt_dump_fd); ctx->usdt_dump_fd = -1; } return 0; } -static int rx_st30p_usdt_dump_frame(struct st30p_rx_ctx *ctx, - struct st30_frame *frame) { +static int rx_st30p_usdt_dump_frame(struct st30p_rx_ctx *ctx, struct st30_frame *frame) { int idx = ctx->idx; int ret; @@ -260,17 +248,16 @@ static int rx_st30p_usdt_dump_frame(struct st30p_rx_ctx *ctx, struct st30p_rx_ops *ops = &ctx->ops; snprintf(ctx->usdt_dump_path, sizeof(ctx->usdt_dump_path), "imtl_usdt_st30prx_s%d_%d_%d_c%u_XXXXXX.pcm", idx, - st30_get_sample_rate(ops->sampling), - st30_get_sample_size(ops->fmt) * 8, ops->channel); + st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, + ops->channel); ret = mt_mkstemps(ctx->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, - ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, ret); return ret; } ctx->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, - ctx->usdt_dump_path, ctx->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, ctx->usdt_dump_path, + ctx->usdt_dump_fd); } /* write frame to dump file */ @@ -281,8 +268,7 @@ static int rx_st30p_usdt_dump_frame(struct st30p_rx_ctx *ctx, ctx->usdt_dumped_frames++; /* logging every 1 sec */ if ((ctx->usdt_dumped_frames % (ctx->frames_per_sec * 1)) == 0) { - MT_USDT_ST30P_RX_FRAME_DUMP(idx, ctx->usdt_dump_path, - ctx->usdt_dumped_frames); + MT_USDT_ST30P_RX_FRAME_DUMP(idx, ctx->usdt_dump_path, ctx->usdt_dumped_frames); } } @@ -300,22 +286,21 @@ struct st30_frame *st30p_rx_get_frame(st30p_rx_handle handle) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, - ST30P_RX_FRAME_READY); + framebuff = + rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, ST30P_RX_FRAME_READY); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); rx_st30p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, - ST30P_RX_FRAME_READY); + framebuff = + rx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, ST30P_RX_FRAME_READY); } /* not any converted frame */ if (!framebuff) { @@ -331,8 +316,7 @@ struct st30_frame *st30p_rx_get_frame(st30p_rx_handle handle) { frame = &framebuff->frame; ctx->stat_get_frame_succ++; MT_USDT_ST30P_RX_FRAME_GET(idx, framebuff->idx, frame->addr); - dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, - frame->addr); + dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, frame->addr); /* check if dump USDT enabled */ if (MT_USDT_ST30P_RX_FRAME_DUMP_ENABLED()) { rx_st30p_usdt_dump_frame(ctx, frame); @@ -414,10 +398,8 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops *ops) { return NULL; } - enum mtl_port port = - mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30P_RX_FLAG_FORCE_NUMA) { @@ -442,8 +424,7 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops *ops) { mt_pthread_mutex_init(&ctx->block_wake_mutex, NULL); mt_pthread_cond_wait_init(&ctx->block_wake_cond); ctx->block_timeout_ns = NS_PER_S; - if (ops->flags & ST30P_RX_FLAG_BLOCK_GET) - ctx->block_get = true; + if (ops->flags & ST30P_RX_FLAG_BLOCK_GET) ctx->block_get = true; /* copy ops */ if (ops->name) { @@ -475,8 +456,7 @@ st30p_rx_handle st30p_rx_create(mtl_handle mt, struct st30p_rx_ops *ops) { notice("%s(%d), flags 0x%x\n", __func__, idx, ops->flags); st30p_rx_idx++; - if (!ctx->block_get) - rx_st30p_notify_frame_available(ctx); + if (!ctx->block_get) rx_st30p_notify_frame_available(ctx); mt_stat_register(impl, rx_st30p_stat, ctx, ctx->ops_name); @@ -495,8 +475,7 @@ size_t st30p_rx_frame_size(st30p_rx_handle handle) { return ctx->ops.framebuff_size; } -int st30p_rx_get_queue_meta(st30p_rx_handle handle, - struct st_queue_meta *meta) { +int st30p_rx_get_queue_meta(st30p_rx_handle handle, struct st_queue_meta *meta) { struct st30p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -508,8 +487,7 @@ int st30p_rx_get_queue_meta(st30p_rx_handle handle, return st30_rx_get_queue_meta(ctx->transport, meta); } -int st30p_rx_update_source(st30p_rx_handle handle, - struct st_rx_source_info *src) { +int st30p_rx_update_source(st30p_rx_handle handle, struct st_rx_source_info *src) { struct st30p_rx_ctx *ctx = handle; int cidx = ctx->idx; @@ -530,8 +508,7 @@ int st30p_rx_wake_block(st30p_rx_handle handle) { return 0; } - if (ctx->block_get) - rx_st30p_block_wake(ctx); + if (ctx->block_get) rx_st30p_block_wake(ctx); return 0; } diff --git a/lib/src/st2110/pipeline/st30_pipeline_tx.c b/lib/src/st2110/pipeline/st30_pipeline_tx.c index 4fe0e2041..7829fe0c1 100644 --- a/lib/src/st2110/pipeline/st30_pipeline_tx.c +++ b/lib/src/st2110/pipeline/st30_pipeline_tx.c @@ -22,8 +22,7 @@ static uint16_t tx_st30p_next_idx(struct st30p_tx_ctx *ctx, uint16_t idx) { /* point to next */ uint16_t next_idx = idx; next_idx++; - if (next_idx >= ctx->framebuff_cnt) - next_idx = 0; + if (next_idx >= ctx->framebuff_cnt) next_idx = 0; return next_idx; } @@ -45,9 +44,8 @@ static void tx_st30p_notify_frame_available(struct st30p_tx_ctx *ctx) { } } -static struct st30p_tx_frame * -tx_st30p_next_available(struct st30p_tx_ctx *ctx, uint16_t idx_start, - enum st30p_tx_frame_status desired) { +static struct st30p_tx_frame *tx_st30p_next_available( + struct st30p_tx_ctx *ctx, uint16_t idx_start, enum st30p_tx_frame_status desired) { uint16_t idx = idx_start; struct st30p_tx_frame *framebuff; @@ -75,12 +73,11 @@ static int tx_st30p_next_frame(void *priv, uint16_t *next_frame_idx, struct st30p_tx_frame *framebuff; MTL_MAY_UNUSED(meta); - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, - ST30P_TX_FRAME_READY); + framebuff = + tx_st30p_next_available(ctx, ctx->framebuff_consumer_idx, ST30P_TX_FRAME_READY); /* not any converted frame */ if (!framebuff) { mt_pthread_mutex_unlock(&ctx->lock); @@ -110,8 +107,8 @@ static int tx_st30p_frame_done(void *priv, uint16_t frame_idx, dbg("%s(%d), done_idx %u\n", __func__, ctx->idx, frame_idx); } else { ret = -EIO; - err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, - framebuff->stat, frame_idx); + err("%s(%d), err status %d for frame %u\n", __func__, ctx->idx, framebuff->stat, + frame_idx); } mt_pthread_mutex_unlock(&ctx->lock); @@ -132,8 +129,7 @@ static int tx_st30p_frame_done(void *priv, uint16_t frame_idx, return ret; } -static int tx_st30p_create_transport(struct mtl_main_impl *impl, - struct st30p_tx_ctx *ctx, +static int tx_st30p_create_transport(struct mtl_main_impl *impl, struct st30p_tx_ctx *ctx, struct st30p_tx_ops *ops) { int idx = ctx->idx; struct st30_tx_ops ops_tx; @@ -216,8 +212,7 @@ static int tx_st30p_uinit_fbs(struct st30p_tx_ctx *ctx) { return 0; } -static int tx_st30p_init_fbs(struct st30p_tx_ctx *ctx, - struct st30p_tx_ops *ops) { +static int tx_st30p_init_fbs(struct st30p_tx_ctx *ctx, struct st30p_tx_ops *ops) { int idx = ctx->idx; int soc_id = ctx->socket_id; struct st30p_tx_frame *frames; @@ -254,18 +249,16 @@ static int tx_st30p_stat(void *priv) { struct st30p_tx_ctx *ctx = priv; struct st30p_tx_frame *framebuff = ctx->framebuffs; - if (!ctx->ready) - return -EBUSY; /* not ready */ + if (!ctx->ready) return -EBUSY; /* not ready */ uint16_t producer_idx = ctx->framebuff_producer_idx; uint16_t consumer_idx = ctx->framebuff_consumer_idx; - notice("TX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, - producer_idx, tx_st30p_stat_name(framebuff[producer_idx].stat), - consumer_idx, tx_st30p_stat_name(framebuff[consumer_idx].stat)); + notice("TX_st30p(%d,%s), p(%d:%s) c(%d:%s)\n", ctx->idx, ctx->ops_name, producer_idx, + tx_st30p_stat_name(framebuff[producer_idx].stat), consumer_idx, + tx_st30p_stat_name(framebuff[consumer_idx].stat)); notice("TX_st30p(%d), frame get try %d succ %d, put %d\n", ctx->idx, - ctx->stat_get_frame_try, ctx->stat_get_frame_succ, - ctx->stat_put_frame); + ctx->stat_get_frame_try, ctx->stat_get_frame_succ, ctx->stat_put_frame); ctx->stat_get_frame_try = 0; ctx->stat_get_frame_succ = 0; ctx->stat_put_frame = 0; @@ -288,16 +281,15 @@ static int tx_st30p_usdt_dump_close(struct st30p_tx_ctx *ctx) { int idx = ctx->idx; if (ctx->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, - ctx->usdt_dump_fd, ctx->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, ctx->usdt_dump_fd, + ctx->usdt_dumped_frames); close(ctx->usdt_dump_fd); ctx->usdt_dump_fd = -1; } return 0; } -static int tx_st30p_usdt_dump_frame(struct st30p_tx_ctx *ctx, - struct st30_frame *frame) { +static int tx_st30p_usdt_dump_frame(struct st30p_tx_ctx *ctx, struct st30_frame *frame) { int idx = ctx->idx; int ret; @@ -305,17 +297,16 @@ static int tx_st30p_usdt_dump_frame(struct st30p_tx_ctx *ctx, struct st30p_tx_ops *ops = &ctx->ops; snprintf(ctx->usdt_dump_path, sizeof(ctx->usdt_dump_path), "imtl_usdt_st30ptx_s%d_%d_%d_c%u_XXXXXX.pcm", idx, - st30_get_sample_rate(ops->sampling), - st30_get_sample_size(ops->fmt) * 8, ops->channel); + st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, + ops->channel); ret = mt_mkstemps(ctx->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, - ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, ctx->usdt_dump_path, ret); return ret; } ctx->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, - ctx->usdt_dump_path, ctx->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, ctx->usdt_dump_path, + ctx->usdt_dump_fd); } /* write frame to dump file */ @@ -326,8 +317,7 @@ static int tx_st30p_usdt_dump_frame(struct st30p_tx_ctx *ctx, ctx->usdt_dumped_frames++; /* logging every 1 sec */ if ((ctx->usdt_dumped_frames % (ctx->frames_per_sec * 1)) == 0) { - MT_USDT_ST30P_TX_FRAME_DUMP(idx, ctx->usdt_dump_path, - ctx->usdt_dumped_frames); + MT_USDT_ST30P_TX_FRAME_DUMP(idx, ctx->usdt_dump_path, ctx->usdt_dumped_frames); } } @@ -341,8 +331,7 @@ static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx *ctx) { int retry = 0; while (1) { - if (framebuff->stat == ST30P_TX_FRAME_FREE) - break; + if (framebuff->stat == ST30P_TX_FRAME_FREE) break; if (framebuff->stat == ST30P_TX_FRAME_IN_TRANSMITTING) { /* make sure transport to finish the transmit */ /* WA to use sleep here, todo: add a transport API to query the stat */ @@ -354,8 +343,8 @@ static void tx_st30p_framebuffs_flush(struct st30p_tx_ctx *ctx) { tx_st30p_stat_name(framebuff->stat), retry); retry++; if (retry > 100) { - info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, - i, tx_st30p_stat_name(framebuff->stat), retry); + info("%s(%d), frame %u are still in %s, retry %d\n", __func__, ctx->idx, i, + tx_st30p_stat_name(framebuff->stat), retry); break; } mt_sleep_ms(10); @@ -373,21 +362,20 @@ struct st30_frame *st30p_tx_get_frame(st30p_tx_handle handle) { return NULL; } - if (!ctx->ready) - return NULL; /* not ready */ + if (!ctx->ready) return NULL; /* not ready */ ctx->stat_get_frame_try++; mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, - ST30P_TX_FRAME_FREE); + framebuff = + tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, ST30P_TX_FRAME_FREE); if (!framebuff && ctx->block_get) { /* wait here */ mt_pthread_mutex_unlock(&ctx->lock); tx_st30p_get_block_wait(ctx); /* get again */ mt_pthread_mutex_lock(&ctx->lock); - framebuff = tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, - ST30P_TX_FRAME_FREE); + framebuff = + tx_st30p_next_available(ctx, ctx->framebuff_producer_idx, ST30P_TX_FRAME_FREE); } /* not any free frame */ if (!framebuff) { @@ -403,8 +391,7 @@ struct st30_frame *st30p_tx_get_frame(st30p_tx_handle handle) { struct st30_frame *frame = &framebuff->frame; ctx->stat_get_frame_succ++; MT_USDT_ST30P_TX_FRAME_GET(idx, framebuff->idx, frame->addr); - dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, - frame->addr); + dbg("%s(%d), frame %u(%p) succ\n", __func__, idx, framebuff->idx, frame->addr); /* check if dump USDT enabled */ if (MT_USDT_ST30P_TX_FRAME_DUMP_ENABLED()) { tx_st30p_usdt_dump_frame(ctx, frame); @@ -488,10 +475,8 @@ st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops *ops) { return NULL; } - enum mtl_port port = - mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + enum mtl_port port = mt_port_by_name(impl, ops->port.port[MTL_SESSION_PORT_P]); + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30P_RX_FLAG_FORCE_NUMA) { @@ -551,16 +536,14 @@ st30p_tx_handle st30p_tx_create(mtl_handle mt, struct st30p_tx_ops *ops) { st30p_tx_idx++; /* notify app can get frame */ - if (!ctx->block_get) - tx_st30p_notify_frame_available(ctx); + if (!ctx->block_get) tx_st30p_notify_frame_available(ctx); mt_stat_register(impl, tx_st30p_stat, ctx, ctx->ops_name); return ctx; } -int st30p_tx_update_destination(st30p_tx_handle handle, - struct st_tx_dest_info *dst) { +int st30p_tx_update_destination(st30p_tx_handle handle, struct st_tx_dest_info *dst) { struct st30p_tx_ctx *ctx = handle; int cidx = ctx->idx; @@ -581,8 +564,7 @@ int st30p_tx_wake_block(st30p_tx_handle handle) { return 0; } - if (ctx->block_get) - tx_st30p_block_wake(ctx); + if (ctx->block_get) tx_st30p_block_wake(ctx); return 0; } diff --git a/lib/src/st2110/pipeline/st_plugin.c b/lib/src/st2110/pipeline/st_plugin.c index 5c29f2240..9cd7f6d4c 100644 --- a/lib/src/st2110/pipeline/st_plugin.c +++ b/lib/src/st2110/pipeline/st_plugin.c @@ -11,14 +11,12 @@ static int st_plugins_dump(void *priv); -static inline struct st_plugin_mgr * -st_get_plugins_mgr(struct mtl_main_impl *impl) { +static inline struct st_plugin_mgr *st_get_plugins_mgr(struct mtl_main_impl *impl) { return &impl->plugin_mgr; } static int st_plugin_free(struct st_dl_plugin_impl *plugin) { - if (plugin->free) - plugin->free(plugin->handle); + if (plugin->free) plugin->free(plugin->handle); if (plugin->dl_handle) { dlclose(plugin->dl_handle); plugin->dl_handle = NULL; @@ -95,9 +93,8 @@ int st22_put_encoder(struct mtl_main_impl *impl, return 0; } -static struct st22_encode_session_impl * -st22_get_encoder_session(struct st22_encode_dev_impl *dev_impl, - struct st22_get_encoder_request *req) { +static struct st22_encode_session_impl *st22_get_encoder_session( + struct st22_encode_dev_impl *dev_impl, struct st22_get_encoder_request *req) { struct st22_encoder_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; struct st22_encoder_create_req *create_req = &req->req; @@ -106,8 +103,7 @@ st22_get_encoder_session(struct st22_encode_dev_impl *dev_impl, for (int i = 0; i < ST_MAX_SESSIONS_PER_ENCODER; i++) { session_impl = &dev_impl->sessions[i]; - if (session_impl->session) - continue; + if (session_impl->session) continue; session = dev->create_session(dev->priv, session_impl, create_req); if (session) { @@ -115,16 +111,16 @@ st22_get_encoder_session(struct st22_encode_dev_impl *dev_impl, session_impl->codestream_max_size = create_req->max_codestream_size; session_impl->req = *req; session_impl->type = MT_ST22_HANDLE_PIPELINE_ENCODE; - info("%s(%d), get one session at %d on dev %s, max codestream size " - "%" PRIu64 "\n", - __func__, idx, i, dev->name, session_impl->codestream_max_size); + info( + "%s(%d), get one session at %d on dev %s, max codestream size " + "%" PRIu64 "\n", + __func__, idx, i, dev->name, session_impl->codestream_max_size); info("%s(%d), input fmt: %s, output fmt: %s\n", __func__, idx, - st_frame_fmt_name(req->req.input_fmt), - st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); return session_impl; } else { - err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, - i, dev->name); + err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, i, + dev->name); return NULL; } } @@ -136,22 +132,18 @@ static bool st22_encoder_is_capable(struct st22_encoder_dev *dev, struct st22_get_encoder_request *req) { enum st_plugin_device plugin_dev = req->device; - if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && - (plugin_dev != dev->target_device)) + if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && (plugin_dev != dev->target_device)) return false; - if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) - return false; + if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) return false; - if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) - return false; + if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) return false; return true; } -struct st22_encode_session_impl * -st22_get_encoder(struct mtl_main_impl *impl, - struct st22_get_encoder_request *req) { +struct st22_encode_session_impl *st22_get_encoder(struct mtl_main_impl *impl, + struct st22_get_encoder_request *req) { struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); struct st22_encoder_dev *dev; struct st22_encode_dev_impl *dev_impl; @@ -160,8 +152,7 @@ st22_get_encoder(struct mtl_main_impl *impl, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_ENCODER_DEV; i++) { dev_impl = mgr->encode_devs[i]; - if (!dev_impl) - continue; + if (!dev_impl) continue; dbg("%s(%d), try to find one dev\n", __func__, i); dev = &mgr->encode_devs[i]->dev; if (!st22_encoder_is_capable(dev, req)) { @@ -180,8 +171,7 @@ st22_get_encoder(struct mtl_main_impl *impl, mt_pthread_mutex_unlock(&mgr->lock); err("%s, fail to get, input fmt: %s, output fmt: %s\n", __func__, - st_frame_fmt_name(req->req.input_fmt), - st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); return NULL; } @@ -203,9 +193,8 @@ int st22_put_decoder(struct mtl_main_impl *impl, return 0; } -static struct st22_decode_session_impl * -st22_get_decoder_session(struct st22_decode_dev_impl *dev_impl, - struct st22_get_decoder_request *req) { +static struct st22_decode_session_impl *st22_get_decoder_session( + struct st22_decode_dev_impl *dev_impl, struct st22_get_decoder_request *req) { struct st22_decoder_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; struct st22_decoder_create_req *create_req = &req->req; @@ -214,23 +203,20 @@ st22_get_decoder_session(struct st22_decode_dev_impl *dev_impl, for (int i = 0; i < ST_MAX_SESSIONS_PER_DECODER; i++) { session_impl = &dev_impl->sessions[i]; - if (session_impl->session) - continue; + if (session_impl->session) continue; session = dev->create_session(dev->priv, session_impl, create_req); if (session) { session_impl->session = session; session_impl->req = *req; session_impl->type = MT_ST22_HANDLE_PIPELINE_DECODE; - info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, - dev->name); + info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, dev->name); info("%s(%d), input fmt: %s, output fmt: %s\n", __func__, idx, - st_frame_fmt_name(req->req.input_fmt), - st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); return session_impl; } else { - err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, - i, dev->name); + err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, i, + dev->name); return NULL; } } @@ -242,22 +228,18 @@ static bool st22_decoder_is_capable(struct st22_decoder_dev *dev, struct st22_get_decoder_request *req) { enum st_plugin_device plugin_dev = req->device; - if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && - (plugin_dev != dev->target_device)) + if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && (plugin_dev != dev->target_device)) return false; - if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) - return false; + if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) return false; - if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) - return false; + if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) return false; return true; } -struct st22_decode_session_impl * -st22_get_decoder(struct mtl_main_impl *impl, - struct st22_get_decoder_request *req) { +struct st22_decode_session_impl *st22_get_decoder(struct mtl_main_impl *impl, + struct st22_get_decoder_request *req) { struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); struct st22_decoder_dev *dev; struct st22_decode_dev_impl *dev_impl; @@ -266,12 +248,10 @@ st22_get_decoder(struct mtl_main_impl *impl, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_DECODER_DEV; i++) { dev_impl = mgr->decode_devs[i]; - if (!dev_impl) - continue; + if (!dev_impl) continue; dbg("%s(%d), try to find one dev\n", __func__, i); dev = &mgr->decode_devs[i]->dev; - if (!st22_decoder_is_capable(dev, req)) - continue; + if (!st22_decoder_is_capable(dev, req)) continue; dbg("%s(%d), try to find one session\n", __func__, i); session_impl = st22_get_decoder_session(dev_impl, req); @@ -284,13 +264,11 @@ st22_get_decoder(struct mtl_main_impl *impl, mt_pthread_mutex_unlock(&mgr->lock); err("%s, fail to get, input fmt: %s, output fmt: %s\n", __func__, - st_frame_fmt_name(req->req.input_fmt), - st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); return NULL; } -int st20_convert_notify_frame_ready( - struct st20_convert_session_impl *converter) { +int st20_convert_notify_frame_ready(struct st20_convert_session_impl *converter) { struct st20_convert_dev_impl *dev_impl = converter->parent; struct st20_converter_dev *dev = &dev_impl->dev; st20_convert_priv session = converter->session; @@ -316,9 +294,8 @@ int st20_put_converter(struct mtl_main_impl *impl, return 0; } -static struct st20_convert_session_impl * -st20_get_converter_session(struct st20_convert_dev_impl *dev_impl, - struct st20_get_converter_request *req) { +static struct st20_convert_session_impl *st20_get_converter_session( + struct st20_convert_dev_impl *dev_impl, struct st20_get_converter_request *req) { struct st20_converter_dev *dev = &dev_impl->dev; int idx = dev_impl->idx; struct st20_converter_create_req *create_req = &req->req; @@ -327,23 +304,20 @@ st20_get_converter_session(struct st20_convert_dev_impl *dev_impl, for (int i = 0; i < ST_MAX_SESSIONS_PER_CONVERTER; i++) { session_impl = &dev_impl->sessions[i]; - if (session_impl->session) - continue; + if (session_impl->session) continue; session = dev->create_session(dev->priv, session_impl, create_req); if (session) { session_impl->session = session; session_impl->req = *req; session_impl->type = MT_ST20_HANDLE_PIPELINE_CONVERT; - info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, - dev->name); + info("%s(%d), get one session at %d on dev %s\n", __func__, idx, i, dev->name); info("%s(%d), input fmt: %s, output fmt: %s\n", __func__, idx, - st_frame_fmt_name(req->req.input_fmt), - st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); return session_impl; } else { - err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, - i, dev->name); + err("%s(%d), fail to create one session at %d on dev %s\n", __func__, idx, i, + dev->name); return NULL; } } @@ -355,22 +329,18 @@ static bool st20_converter_is_capable(struct st20_converter_dev *dev, struct st20_get_converter_request *req) { enum st_plugin_device plugin_dev = req->device; - if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && - (plugin_dev != dev->target_device)) + if ((plugin_dev != ST_PLUGIN_DEVICE_AUTO) && (plugin_dev != dev->target_device)) return false; - if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) - return false; + if (!(MTL_BIT64(req->req.input_fmt) & dev->input_fmt_caps)) return false; - if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) - return false; + if (!(MTL_BIT64(req->req.output_fmt) & dev->output_fmt_caps)) return false; return true; } -struct st20_convert_session_impl * -st20_get_converter(struct mtl_main_impl *impl, - struct st20_get_converter_request *req) { +struct st20_convert_session_impl *st20_get_converter( + struct mtl_main_impl *impl, struct st20_get_converter_request *req) { struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); struct st20_converter_dev *dev; struct st20_convert_dev_impl *dev_impl; @@ -379,12 +349,10 @@ st20_get_converter(struct mtl_main_impl *impl, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_CONVERTER_DEV; i++) { dev_impl = mgr->convert_devs[i]; - if (!dev_impl) - continue; + if (!dev_impl) continue; dbg("%s(%d), try to find one dev\n", __func__, i); dev = &mgr->convert_devs[i]->dev; - if (!st20_converter_is_capable(dev, req)) - continue; + if (!st20_converter_is_capable(dev, req)) continue; dbg("%s(%d), try to find one session\n", __func__, i); session_impl = st20_get_converter_session(dev_impl, req); @@ -397,8 +365,7 @@ st20_get_converter(struct mtl_main_impl *impl, mt_pthread_mutex_unlock(&mgr->lock); info("%s, plugin not found, input fmt: %s, output fmt: %s\n", __func__, - st_frame_fmt_name(req->req.input_fmt), - st_frame_fmt_name(req->req.output_fmt)); + st_frame_fmt_name(req->req.input_fmt), st_frame_fmt_name(req->req.output_fmt)); return NULL; } @@ -406,14 +373,11 @@ static int st22_encode_dev_dump(struct st22_encode_dev_impl *encode) { struct st22_encode_session_impl *session; int ref_cnt = rte_atomic32_read(&encode->ref_cnt); - if (ref_cnt) - notice("ST22 encoder dev: %s with %d sessions\n", encode->name, ref_cnt); + if (ref_cnt) notice("ST22 encoder dev: %s with %d sessions\n", encode->name, ref_cnt); for (int i = 0; i < ST_MAX_SESSIONS_PER_ENCODER; i++) { session = &encode->sessions[i]; - if (!session->session) - continue; - if (session->req.dump) - session->req.dump(session->req.priv); + if (!session->session) continue; + if (session->req.dump) session->req.dump(session->req.priv); } return 0; @@ -423,14 +387,11 @@ static int st22_decode_dev_dump(struct st22_decode_dev_impl *decode) { struct st22_decode_session_impl *session; int ref_cnt = rte_atomic32_read(&decode->ref_cnt); - if (ref_cnt) - notice("ST22 encoder dev: %s with %d sessions\n", decode->name, ref_cnt); + if (ref_cnt) notice("ST22 encoder dev: %s with %d sessions\n", decode->name, ref_cnt); for (int i = 0; i < ST_MAX_SESSIONS_PER_DECODER; i++) { session = &decode->sessions[i]; - if (!session->session) - continue; - if (session->req.dump) - session->req.dump(session->req.priv); + if (!session->session) continue; + if (session->req.dump) session->req.dump(session->req.priv); } return 0; @@ -440,14 +401,11 @@ static int st20_convert_dev_dump(struct st20_convert_dev_impl *convert) { struct st20_convert_session_impl *session; int ref_cnt = rte_atomic32_read(&convert->ref_cnt); - if (ref_cnt) - notice("ST20 convert dev: %s with %d sessions\n", convert->name, ref_cnt); + if (ref_cnt) notice("ST20 convert dev: %s with %d sessions\n", convert->name, ref_cnt); for (int i = 0; i < ST_MAX_SESSIONS_PER_CONVERTER; i++) { session = &convert->sessions[i]; - if (!session->session) - continue; - if (session->req.dump) - session->req.dump(session->req.priv); + if (!session->session) continue; + if (session->req.dump) session->req.dump(session->req.priv); } return 0; @@ -463,20 +421,17 @@ static int st_plugins_dump(void *priv) { mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_ENCODER_DEV; i++) { encode = mgr->encode_devs[i]; - if (!encode) - continue; + if (!encode) continue; st22_encode_dev_dump(encode); } for (int i = 0; i < ST_MAX_DECODER_DEV; i++) { decode = mgr->decode_devs[i]; - if (!decode) - continue; + if (!decode) continue; st22_decode_dev_dump(decode); } for (int i = 0; i < ST_MAX_CONVERTER_DEV; i++) { convert = mgr->convert_devs[i]; - if (!convert) - continue; + if (!convert) continue; st20_convert_dev_dump(convert); } mt_pthread_mutex_unlock(&mgr->lock); @@ -506,8 +461,7 @@ int st22_encoder_unregister(st22_encoder_dev_handle handle) { int ref_cnt = rte_atomic32_read(&dev->ref_cnt); if (ref_cnt) { mt_pthread_mutex_unlock(&mgr->lock); - err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, - ref_cnt); + err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, ref_cnt); return -EBUSY; } mt_rte_free(dev); @@ -539,8 +493,7 @@ int st22_decoder_unregister(st22_decoder_dev_handle handle) { int ref_cnt = rte_atomic32_read(&dev->ref_cnt); if (ref_cnt) { mt_pthread_mutex_unlock(&mgr->lock); - err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, - ref_cnt); + err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, ref_cnt); return -EBUSY; } mt_rte_free(dev); @@ -572,8 +525,7 @@ int st20_converter_unregister(st20_converter_dev_handle handle) { int ref_cnt = rte_atomic32_read(&dev->ref_cnt); if (ref_cnt) { mt_pthread_mutex_unlock(&mgr->lock); - err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, - ref_cnt); + err("%s(%d), %s are busy with ref_cnt %d\n", __func__, idx, dev->name, ref_cnt); return -EBUSY; } mt_rte_free(dev); @@ -605,10 +557,9 @@ st22_encoder_dev_handle st22_encoder_register(mtl_handle mt, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_ENCODER_DEV; i++) { - if (mgr->encode_devs[i]) - continue; - encode_dev = mt_rte_zmalloc_socket(sizeof(*encode_dev), - mt_socket_id(impl, MTL_PORT_P)); + if (mgr->encode_devs[i]) continue; + encode_dev = + mt_rte_zmalloc_socket(sizeof(*encode_dev), mt_socket_id(impl, MTL_PORT_P)); if (!encode_dev) { err("%s, encode_dev malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->lock); @@ -626,8 +577,8 @@ st22_encoder_dev_handle st22_encoder_register(mtl_handle mt, } mgr->encode_devs[i] = encode_dev; mt_pthread_mutex_unlock(&mgr->lock); - info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", - __func__, i, encode_dev->name, dev->target_device, dev->input_fmt_caps, + info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", __func__, + i, encode_dev->name, dev->target_device, dev->input_fmt_caps, dev->output_fmt_caps); return encode_dev; } @@ -659,10 +610,9 @@ st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_DECODER_DEV; i++) { - if (mgr->decode_devs[i]) - continue; - decode_dev = mt_rte_zmalloc_socket(sizeof(*decode_dev), - mt_socket_id(impl, MTL_PORT_P)); + if (mgr->decode_devs[i]) continue; + decode_dev = + mt_rte_zmalloc_socket(sizeof(*decode_dev), mt_socket_id(impl, MTL_PORT_P)); if (!decode_dev) { err("%s, decode_dev malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->lock); @@ -680,8 +630,8 @@ st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, } mgr->decode_devs[i] = decode_dev; mt_pthread_mutex_unlock(&mgr->lock); - info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", - __func__, i, decode_dev->name, dev->target_device, dev->input_fmt_caps, + info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", __func__, + i, decode_dev->name, dev->target_device, dev->input_fmt_caps, dev->output_fmt_caps); return decode_dev; } @@ -691,8 +641,8 @@ st22_decoder_dev_handle st22_decoder_register(mtl_handle mt, return NULL; } -st20_converter_dev_handle -st20_converter_register(mtl_handle mt, struct st20_converter_dev *dev) { +st20_converter_dev_handle st20_converter_register(mtl_handle mt, + struct st20_converter_dev *dev) { struct mtl_main_impl *impl = mt; struct st_plugin_mgr *mgr = st_get_plugins_mgr(impl); struct st20_convert_dev_impl *convert_dev; @@ -717,10 +667,9 @@ st20_converter_register(mtl_handle mt, struct st20_converter_dev *dev) { mt_pthread_mutex_lock(&mgr->lock); for (int i = 0; i < ST_MAX_CONVERTER_DEV; i++) { - if (mgr->convert_devs[i]) - continue; - convert_dev = mt_rte_zmalloc_socket(sizeof(*convert_dev), - mt_socket_id(impl, MTL_PORT_P)); + if (mgr->convert_devs[i]) continue; + convert_dev = + mt_rte_zmalloc_socket(sizeof(*convert_dev), mt_socket_id(impl, MTL_PORT_P)); if (!convert_dev) { err("%s, convert_dev malloc fail\n", __func__); mt_pthread_mutex_unlock(&mgr->lock); @@ -738,9 +687,9 @@ st20_converter_register(mtl_handle mt, struct st20_converter_dev *dev) { } mgr->convert_devs[i] = convert_dev; mt_pthread_mutex_unlock(&mgr->lock); - info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", - __func__, i, convert_dev->name, dev->target_device, - dev->input_fmt_caps, dev->output_fmt_caps); + info("%s(%d), %s registered, device %d cap(0x%" PRIx64 ":0x%" PRIx64 ")\n", __func__, + i, convert_dev->name, dev->target_device, dev->input_fmt_caps, + dev->output_fmt_caps); return convert_dev; } mt_pthread_mutex_unlock(&mgr->lock); @@ -749,13 +698,11 @@ st20_converter_register(mtl_handle mt, struct st20_converter_dev *dev) { return NULL; } -struct st22_encode_frame_meta * -st22_encoder_get_frame(st22p_encode_session session) { +struct st22_encode_frame_meta *st22_encoder_get_frame(st22p_encode_session session) { struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return NULL; } @@ -766,26 +713,22 @@ int st22_encoder_wake_block(st22p_encode_session session) { struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return -EIO; } return session_impl->req.wake_block(session_impl->req.priv); } -int st22_encoder_set_block_timeout(st22p_encode_session session, - uint64_t timedwait_ns) { +int st22_encoder_set_block_timeout(st22p_encode_session session, uint64_t timedwait_ns) { struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return -EIO; } - return session_impl->req.set_block_timeout(session_impl->req.priv, - timedwait_ns); + return session_impl->req.set_block_timeout(session_impl->req.priv, timedwait_ns); } int st22_encoder_put_frame(st22p_encode_session session, @@ -793,21 +736,18 @@ int st22_encoder_put_frame(st22p_encode_session session, struct st22_encode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_ENCODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return -EIO; } return session_impl->req.put_frame(session_impl->req.priv, frame, result); } -struct st22_decode_frame_meta * -st22_decoder_get_frame(st22p_decode_session session) { +struct st22_decode_frame_meta *st22_decoder_get_frame(st22p_decode_session session) { struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return NULL; } @@ -818,26 +758,22 @@ int st22_decoder_wake_block(st22p_decode_session session) { struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return -EIO; } return session_impl->req.wake_block(session_impl->req.priv); } -int st22_decoder_set_block_timeout(st22p_decode_session session, - uint64_t timedwait_ns) { +int st22_decoder_set_block_timeout(st22p_decode_session session, uint64_t timedwait_ns) { struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return -EIO; } - return session_impl->req.set_block_timeout(session_impl->req.priv, - timedwait_ns); + return session_impl->req.set_block_timeout(session_impl->req.priv, timedwait_ns); } int st22_decoder_put_frame(st22p_decode_session session, @@ -845,21 +781,18 @@ int st22_decoder_put_frame(st22p_decode_session session, struct st22_decode_session_impl *session_impl = session; if (session_impl->type != MT_ST22_HANDLE_PIPELINE_DECODE) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return -EIO; } return session_impl->req.put_frame(session_impl->req.priv, frame, result); } -struct st20_convert_frame_meta * -st20_converter_get_frame(st20p_convert_session session) { +struct st20_convert_frame_meta *st20_converter_get_frame(st20p_convert_session session) { struct st20_convert_session_impl *session_impl = session; if (session_impl->type != MT_ST20_HANDLE_PIPELINE_CONVERT) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return NULL; } @@ -867,13 +800,11 @@ st20_converter_get_frame(st20p_convert_session session) { } int st20_converter_put_frame(st20p_convert_session session, - struct st20_convert_frame_meta *frame, - int result) { + struct st20_convert_frame_meta *frame, int result) { struct st20_convert_session_impl *session_impl = session; if (session_impl->type != MT_ST20_HANDLE_PIPELINE_CONVERT) { - err("%s(%d), invalid type %d\n", __func__, session_impl->idx, - session_impl->type); + err("%s(%d), invalid type %d\n", __func__, session_impl->idx, session_impl->type); return -EIO; } @@ -990,10 +921,8 @@ int st_plugin_register(mtl_handle mt, const char *path) { /* add to the plugins */ mt_pthread_mutex_lock(&mgr->plugins_lock); for (int i = 0; i < ST_MAX_DL_PLUGINS; i++) { - if (mgr->plugins[i]) - continue; - plugin = - mt_rte_zmalloc_socket(sizeof(*plugin), mt_socket_id(impl, MTL_PORT_P)); + if (mgr->plugins[i]) continue; + plugin = mt_rte_zmalloc_socket(sizeof(*plugin), mt_socket_id(impl, MTL_PORT_P)); if (!plugin) { mt_pthread_mutex_unlock(&mgr->plugins_lock); dlclose(dl_handle); @@ -1009,8 +938,7 @@ int st_plugin_register(mtl_handle mt, const char *path) { mgr->plugins_nb++; mgr->plugins[i] = plugin; mt_pthread_mutex_unlock(&mgr->plugins_lock); - info("%s(%d), %s registered, version %d\n", __func__, i, path, - meta.version); + info("%s(%d), %s registered, version %d\n", __func__, i, path, meta.version); return 0; } mt_pthread_mutex_unlock(&mgr->plugins_lock); diff --git a/lib/src/st2110/pipeline/st_plugin.h b/lib/src/st2110/pipeline/st_plugin.h index 175187b4a..818e7e815 100644 --- a/lib/src/st2110/pipeline/st_plugin.h +++ b/lib/src/st2110/pipeline/st_plugin.h @@ -7,23 +7,19 @@ #include "../st_main.h" -struct st22_encode_session_impl * -st22_get_encoder(struct mtl_main_impl *impl, - struct st22_get_encoder_request *req); +struct st22_encode_session_impl *st22_get_encoder(struct mtl_main_impl *impl, + struct st22_get_encoder_request *req); int st22_put_encoder(struct mtl_main_impl *impl, struct st22_encode_session_impl *encoder); -struct st22_decode_session_impl * -st22_get_decoder(struct mtl_main_impl *impl, - struct st22_get_decoder_request *req); +struct st22_decode_session_impl *st22_get_decoder(struct mtl_main_impl *impl, + struct st22_get_decoder_request *req); int st22_put_decoder(struct mtl_main_impl *impl, struct st22_decode_session_impl *encoder); -struct st20_convert_session_impl * -st20_get_converter(struct mtl_main_impl *impl, - struct st20_get_converter_request *req); -int st20_convert_notify_frame_ready( - struct st20_convert_session_impl *converter); +struct st20_convert_session_impl *st20_get_converter( + struct mtl_main_impl *impl, struct st20_get_converter_request *req); +int st20_convert_notify_frame_ready(struct st20_convert_session_impl *converter); int st20_put_converter(struct mtl_main_impl *impl, struct st20_convert_session_impl *converter); diff --git a/lib/src/st2110/st_ancillary.c b/lib/src/st2110/st_ancillary.c index 808b03656..fbd256de3 100644 --- a/lib/src/st2110/st_ancillary.c +++ b/lib/src/st2110/st_ancillary.c @@ -42,61 +42,47 @@ static uint16_t parity_tab[] = { // 0 1 2 3 4 5 6 7 8 // 9 A // B C D E F - /* 0 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, - /* 1 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* 2 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* 3 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, - /* 4 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* 5 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, - /* 6 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, - /* 7 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* 8 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* 9 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, - /* A */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, - /* B */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* C */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, - /* D */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* E */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, - 0x0100, 0x0200, 0x0200, 0x0100, 0x0100, 0x0200, - 0x0100, 0x0200, 0x0200, 0x0100, - /* F */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, - 0x0200, 0x0100, 0x0100, 0x0200, 0x0200, 0x0100, - 0x0200, 0x0100, 0x0100, 0x0200, + /* 0 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* 1 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* 2 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* 3 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* 4 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* 5 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* 6 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* 7 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* 8 */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* 9 */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* A */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* B */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* C */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + /* D */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* E */ 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, + 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + /* F */ 0x0200, 0x0100, 0x0100, 0x0200, 0x0100, 0x0200, 0x0200, 0x0100, + 0x0100, 0x0200, 0x0200, 0x0100, 0x0200, 0x0100, 0x0100, 0x0200, }; static inline uint16_t get_parity_bits(uint16_t val) { return parity_tab[val & 0xFF]; } -static uint16_t st_ntohs(uint8_t *data) { return ((data[0] << 8) | (data[1])); } +static uint16_t st_ntohs(uint8_t *data) { + return ((data[0] << 8) | (data[1])); +} static uint16_t get_10bit_udw(int idx, uint8_t *data) { int byte_offset, bit_offset; @@ -109,30 +95,30 @@ static uint16_t get_10bit_udw(int idx, uint8_t *data) { uint16_t udw = 0; switch (bit_offset) { - case 0: { - anc_udw_10_6e_t val10; - val10.val = val; - udw = val10.udw; - break; - } - case 2: { - anc_udw_2e_10_4e_t val10; - val10.val = val; - udw = val10.udw; - break; - } - case 4: { - anc_udw_4e_10_2e_t val10; - val10.val = val; - udw = val10.udw; - break; - } - case 6: { - anc_udw_6e_10_t val10; - val10.val = val; - udw = val10.udw; - break; - } + case 0: { + anc_udw_10_6e_t val10; + val10.val = val; + udw = val10.udw; + break; + } + case 2: { + anc_udw_2e_10_4e_t val10; + val10.val = val; + udw = val10.udw; + break; + } + case 4: { + anc_udw_4e_10_2e_t val10; + val10.val = val; + udw = val10.udw; + break; + } + case 6: { + anc_udw_6e_10_t val10; + val10.val = val; + udw = val10.udw; + break; + } } return udw; } @@ -146,34 +132,34 @@ static void set_10bit_udw(int idx, uint16_t udw, uint8_t *data) { // host to network conversion without load from misaligned address uint16_t val = st_ntohs(data); switch (bit_offset) { - case 0: { - anc_udw_10_6e_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } - case 2: { - anc_udw_2e_10_4e_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } - case 4: { - anc_udw_4e_10_2e_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } - case 6: { - anc_udw_6e_10_t val10; - val10.val = val; - val10.udw = udw; - val = val10.val; - break; - } + case 0: { + anc_udw_10_6e_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } + case 2: { + anc_udw_2e_10_4e_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } + case 4: { + anc_udw_4e_10_2e_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } + case 6: { + anc_udw_6e_10_t val10; + val10.val = val; + val10.udw = udw; + val = val10.val; + break; + } } // host to network conversion without store to misaligned address data[0] = (uint8_t)((val & 0xFF00) >> 8); diff --git a/lib/src/st2110/st_ancillary_transmitter.c b/lib/src/st2110/st_ancillary_transmitter.c index 67db12e84..e72ab0499 100644 --- a/lib/src/st2110/st_ancillary_transmitter.c +++ b/lib/src/st2110/st_ancillary_transmitter.c @@ -30,8 +30,7 @@ static int st_ancillary_trs_tasklet_stop(void *priv) { for (port = 0; port < mt_num_ports(impl); port++) { /* flush all the pkts in the tx ring desc */ - if (mgr->queue[port]) - mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); + if (mgr->queue[port]) mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); if (mgr->ring[port]) { mt_ring_dequeue_clean(mgr->ring[port]); info("%s(%d), port %d, remaining entries %d\n", __func__, idx, port, @@ -49,17 +48,15 @@ static int st_ancillary_trs_tasklet_stop(void *priv) { } /* pacing handled by session itself */ -static int -st_ancillary_trs_session_tasklet(struct st_ancillary_transmitter_impl *trs, - struct st_tx_ancillary_sessions_mgr *mgr, - enum mtl_port port) { +static int st_ancillary_trs_session_tasklet(struct st_ancillary_transmitter_impl *trs, + struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { struct rte_ring *ring = mgr->ring[port]; int ret; uint16_t n; struct rte_mbuf *pkt; - if (!ring) - return 0; + if (!ring) return 0; /* check if any inflight pkts in transmitter */ pkt = trs->inflight[port]; @@ -111,8 +108,7 @@ static int st_ancillary_trs_tasklet_handler(void *priv) { return pending; } -int st_ancillary_transmitter_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, +int st_ancillary_transmitter_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, struct st_tx_ancillary_sessions_mgr *mgr, struct st_ancillary_transmitter_impl *trs) { int idx = sch->idx; @@ -150,8 +146,7 @@ int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl *trs) { } for (int i = 0; i < mt_num_ports(trs->parent); i++) { - info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, - trs->inflight_cnt[i]); + info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, trs->inflight_cnt[i]); } return 0; } diff --git a/lib/src/st2110/st_ancillary_transmitter.h b/lib/src/st2110/st_ancillary_transmitter.h index 54da8d70e..45960f700 100644 --- a/lib/src/st2110/st_ancillary_transmitter.h +++ b/lib/src/st2110/st_ancillary_transmitter.h @@ -7,8 +7,7 @@ #include "st_main.h" -int st_ancillary_transmitter_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, +int st_ancillary_transmitter_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, struct st_tx_ancillary_sessions_mgr *mgr, struct st_ancillary_transmitter_impl *trs); int st_ancillary_transmitter_uinit(struct st_ancillary_transmitter_impl *trs); diff --git a/lib/src/st2110/st_audio_transmitter.c b/lib/src/st2110/st_audio_transmitter.c index b7a6cd1f2..8a330b8ca 100644 --- a/lib/src/st2110/st_audio_transmitter.c +++ b/lib/src/st2110/st_audio_transmitter.c @@ -30,8 +30,7 @@ static int st_audio_trs_tasklet_stop(void *priv) { for (port = 0; port < mt_num_ports(impl); port++) { /* flush all the pkts in the tx ring desc */ - if (mgr->queue[port]) - mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); + if (mgr->queue[port]) mt_txq_flush(mgr->queue[port], mt_get_pad(impl, port)); if (mgr->ring[port]) { mt_ring_dequeue_clean(mgr->ring[port]); info("%s(%d), port %d, remaining entries %d\n", __func__, idx, port, @@ -67,11 +66,9 @@ static uint16_t st_audio_trs_burst_fail(struct mtl_main_impl *impl, static uint16_t st_audio_trs_burst(struct mtl_main_impl *impl, struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port, struct rte_mbuf *pkt) { - if (!mgr->queue[port]) - return 0; + if (!mgr->queue[port]) return 0; uint16_t tx = mt_txq_burst(mgr->queue[port], &pkt, 1); - if (!tx) - return st_audio_trs_burst_fail(impl, mgr, port); + if (!tx) return st_audio_trs_burst_fail(impl, mgr, port); mgr->last_burst_succ_time_tsc[port] = mt_get_tsc(impl); return tx; } @@ -86,8 +83,7 @@ static int st_audio_trs_session_tasklet(struct mtl_main_impl *impl, uint16_t n; struct rte_mbuf *pkt; - if (!ring) - return 0; + if (!ring) return 0; /* check if any inflight pkts in transmitter */ pkt = trs->inflight[port]; @@ -137,8 +133,7 @@ static int st_audio_trs_tasklet_handler(void *priv) { return pending; } -int st_audio_transmitter_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, +int st_audio_transmitter_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, struct st_tx_audio_sessions_mgr *mgr, struct st_audio_transmitter_impl *trs) { int idx = sch->idx; @@ -177,8 +172,7 @@ int st_audio_transmitter_uinit(struct st_audio_transmitter_impl *trs) { } for (int i = 0; i < mt_num_ports(trs->parent); i++) { - info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, - trs->inflight_cnt[i]); + info("%s(%d), succ, inflight %d:%d\n", __func__, idx, i, trs->inflight_cnt[i]); } return 0; } diff --git a/lib/src/st2110/st_audio_transmitter.h b/lib/src/st2110/st_audio_transmitter.h index b2347d10b..72a8824a0 100644 --- a/lib/src/st2110/st_audio_transmitter.h +++ b/lib/src/st2110/st_audio_transmitter.h @@ -7,14 +7,12 @@ #include "st_main.h" -int st_audio_transmitter_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, +int st_audio_transmitter_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, struct st_tx_audio_sessions_mgr *mgr, struct st_audio_transmitter_impl *trs); int st_audio_transmitter_uinit(struct st_audio_transmitter_impl *trs); int st_audio_queue_fatal_error(struct mtl_main_impl *impl, - struct st_tx_audio_sessions_mgr *mgr, - enum mtl_port port); + struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port); #endif diff --git a/lib/src/st2110/st_avx2.c b/lib/src/st2110/st_avx2.c index fbae90ccf..ffe892752 100644 --- a/lib/src/st2110/st_avx2.c +++ b/lib/src/st2110/st_avx2.c @@ -48,9 +48,9 @@ static uint8_t rfc4175_b2l_shuffle_r1_tbl[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422be10_to_422le10_avx2( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_422le10_avx2(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h) { __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)rfc4175_b2l_shuffle_l0_tbl); __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)rfc4175_b2l_shuffle_r0_tbl); __m128i and_l0 = _mm_loadu_si128((__m128i *)rfc4175_b2l_and_l0_tbl); @@ -75,10 +75,8 @@ int st20_rfc4175_422be10_to_422le10_avx2( __m128i input = _mm_loadu_si128((__m128i *)pg_be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i sl_result = - _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); - __m128i sr_result = - _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); + __m128i sl_result = _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); + __m128i sr_result = _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); __m128i sl_result_shuffle = _mm_shuffle_epi8(sl_result, shuffle_l1); __m128i sr_result_shuffle = _mm_shuffle_epi8(sr_result, shuffle_r1); __m128i result = _mm_or_si128(sl_result_shuffle, sr_result_shuffle); @@ -157,9 +155,9 @@ static uint8_t rfc4175_l2b_shuffle_r1_tbl[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422le10_to_422be10_avx2( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { +int st20_rfc4175_422le10_to_422be10_avx2(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)rfc4175_l2b_shuffle_l0_tbl); __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)rfc4175_l2b_shuffle_r0_tbl); __m128i and_l0 = _mm_loadu_si128((__m128i *)rfc4175_l2b_and_l0_tbl); @@ -184,10 +182,8 @@ int st20_rfc4175_422le10_to_422be10_avx2( __m128i input = _mm_loadu_si128((__m128i *)pg_le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i sl_result = - _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); - __m128i sr_result = - _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); + __m128i sl_result = _mm_and_si128(_mm_slli_epi32(shuffle_l0_result, 2), and_l0); + __m128i sr_result = _mm_and_si128(_mm_srli_epi32(shuffle_r0_result, 2), and_r0); __m128i sl_result_shuffle = _mm_shuffle_epi8(sl_result, shuffle_l1); __m128i sr_result_shuffle = _mm_shuffle_epi8(sr_result, shuffle_r1); __m128i result = _mm_or_si128(sl_result_shuffle, sr_result_shuffle); diff --git a/lib/src/st2110/st_avx2.h b/lib/src/st2110/st_avx2.h index f792c1c7f..375ce3d2f 100644 --- a/lib/src/st2110/st_avx2.h +++ b/lib/src/st2110/st_avx2.h @@ -7,12 +7,12 @@ #include "st_main.h" -int st20_rfc4175_422be10_to_422le10_avx2( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx2(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h); -int st20_rfc4175_422le10_to_422be10_avx2( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); +int st20_rfc4175_422le10_to_422be10_avx2(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); #endif \ No newline at end of file diff --git a/lib/src/st2110/st_avx512.c b/lib/src/st2110/st_avx512.c index 43249ed0d..9a1fad62d 100644 --- a/lib/src/st2110/st_avx512.c +++ b/lib/src/st2110/st_avx512.c @@ -33,16 +33,13 @@ static uint32_t be10_to_ple_permute_tbl_512[16] = { 0, 4, 8, 12, 1, 5, 9, 13, 2, 3, 6, 7, 10, 11, 14, 15, }; -int st20_rfc4175_422be10_to_yuv422p10le_avx512( - struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = - _mm_loadu_si128((__m128i *)be10_to_ple_shuffle_tbl_128); +int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + __m128i shuffle_le_mask = _mm_loadu_si128((__m128i *)be10_to_ple_shuffle_tbl_128); __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be10_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = - _mm_loadu_si128((__m128i *)be10_to_ple_and_mask_tbl_128); - __m512i permute_mask = - _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); + __m128i srlv_and_mask = _mm_loadu_si128((__m128i *)be10_to_ple_and_mask_tbl_128); + __m512i permute_mask = _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); @@ -73,19 +70,15 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512( /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = @@ -150,13 +143,10 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = - _mm_loadu_si128((__m128i *)be10_to_ple_shuffle_tbl_128); + __m128i shuffle_le_mask = _mm_loadu_si128((__m128i *)be10_to_ple_shuffle_tbl_128); __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be10_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = - _mm_loadu_si128((__m128i *)be10_to_ple_and_mask_tbl_128); - __m512i permute_mask = - _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); + __m128i srlv_and_mask = _mm_loadu_si128((__m128i *)be10_to_ple_and_mask_tbl_128); + __m512i permute_mask = _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; @@ -171,20 +161,18 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_yuv422p10le_avx512(pg_be, y, b, r, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -195,8 +183,7 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -208,8 +195,7 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *pg = be_cache; @@ -220,8 +206,7 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( for (int j = 0; j < 16; j++) { __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); - __m128i srlv_le_result = - _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); + __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg += 2; } @@ -230,8 +215,7 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( for (int j = 0; j < 4; j++) { /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, * Y7} */ - __m512i input_m512i = - _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + __m512i input_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, * Y7} */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); @@ -241,19 +225,15 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = @@ -299,19 +279,15 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = @@ -411,19 +387,15 @@ static uint8_t be10_to_le_shuffle_r1_tbl_128[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422be10_to_422le10_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { - __m128i shuffle_l0 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l0_tbl_128); - __m128i shuffle_r0 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r0_tbl_128); +int st20_rfc4175_422be10_to_422le10_avx512(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h) { + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l0_tbl_128); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r0_tbl_128); __m128i and_l0 = _mm_loadu_si128((__m128i *)be10_to_and_l0_tbl_128); __m128i and_r0 = _mm_loadu_si128((__m128i *)be10_to_le_and_r0_tbl_128); - __m128i shuffle_l1 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l1_tbl_128); - __m128i shuffle_r1 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r1_tbl_128); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l1_tbl_128); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r1_tbl_128); __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; @@ -434,10 +406,8 @@ int st20_rfc4175_422be10_to_422le10_avx512( __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = - _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = - _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); @@ -474,20 +444,17 @@ int st20_rfc4175_422be10_to_422le10_avx512( return 0; } -int st20_rfc4175_422be10_to_422le10_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, - uint32_t h) { - __m128i shuffle_l0 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l0_tbl_128); - __m128i shuffle_r0 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r0_tbl_128); +int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h) { + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l0_tbl_128); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r0_tbl_128); __m128i and_l0 = _mm_loadu_si128((__m128i *)be10_to_and_l0_tbl_128); __m128i and_r0 = _mm_loadu_si128((__m128i *)be10_to_le_and_r0_tbl_128); - __m128i shuffle_l1 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l1_tbl_128); - __m128i shuffle_r1 = - _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r1_tbl_128); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_l1_tbl_128); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)be10_to_le_shuffle_r1_tbl_128); __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; @@ -502,20 +469,18 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le10_avx512(pg_be, pg_le, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -526,8 +491,7 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -539,8 +503,7 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *be = be_cache; @@ -549,10 +512,8 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma( __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = - _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = - _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); @@ -575,10 +536,8 @@ int st20_rfc4175_422be10_to_422le10_avx512_dma( __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_be); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = - _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = - _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); @@ -630,14 +589,12 @@ static uint8_t be10_to_le8_shuffle1_tbl_128[16] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, /* zeros */ }; -int st20_rfc4175_422be10_to_422le8_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { - __m128i shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); +int st20_rfc4175_422be10_to_422le8_avx512(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h) { + __m128i shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); + __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); @@ -670,15 +627,14 @@ int st20_rfc4175_422be10_to_422le8_avx512( return 0; } -int st20_rfc4175_422be10_to_422le8_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, - mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, - uint32_t h) { - __m128i shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); +int st20_rfc4175_422be10_to_422le8_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h) { + __m128i shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); + __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); @@ -695,20 +651,18 @@ int st20_rfc4175_422be10_to_422le8_avx512_dma( /* two type be(0) or le(1) */ struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be10_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be10_caches); - if (be10_caches) - mt_rte_free(be10_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be10_caches); + if (be10_caches) mt_rte_free(be10_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le8_avx512(pg_10, pg_8, w, h); } rte_iova_t be10_caches_iova = rte_malloc_virt2iova(be10_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be10_cache = be10_caches + (i % caches_num) * cache_pg_cnt; @@ -732,8 +686,7 @@ int st20_rfc4175_422be10_to_422le8_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *be_10 = be10_cache; int batch = cache_pg_cnt / 2; @@ -793,14 +746,12 @@ static uint8_t p8_uyvy2uvyy_mask[16] = { 9, 11, 13, 15, /* y1 */ }; -int st20_rfc4175_422be10_to_yuv422p8_avx512( - struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h) { - __m128i shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); +int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { + __m128i shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); + __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); __m128i uyvy2uvyy_mask = _mm_loadu_si128((__m128i *)p8_uyvy2uvyy_mask); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int pg_cnt = w * h / 2; @@ -866,14 +817,12 @@ int st20_rfc4175_422be10_to_yuv422p8_avx512( return 0; } -int st20_rfc4175_422be10_to_yuv420p8_avx512( - struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h) { - __m128i shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); +int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { + __m128i shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle0_tbl_128); __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_le8_sllv_tbl_128); - __m128i sllv_shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); + __m128i sllv_shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_le8_shuffle1_tbl_128); __m128i uyvy2uvyy_mask = _mm_loadu_si128((__m128i *)p8_uyvy2uvyy_mask); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ @@ -1009,10 +958,9 @@ static uint8_t le10_to_v210_and_tbl_128[16] = { 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, }; -int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, - uint32_t w, uint32_t h) { - __m128i shuffle_r_mask = - _mm_loadu_si128((__m128i *)le10_to_v210_shuffle_r_tbl_128); +int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, + uint32_t h) { + __m128i shuffle_r_mask = _mm_loadu_si128((__m128i *)le10_to_v210_shuffle_r_tbl_128); __m128i srlv_mask = _mm_loadu_si128((__m128i *)le10_to_v210_srlv_tbl_128); __m128i sllv_mask = _mm_loadu_si128((__m128i *)le10_to_v210_sllv_tbl_128); __m128i padding_mask = _mm_loadu_si128((__m128i *)le10_to_v210_and_tbl_128); @@ -1021,8 +969,8 @@ int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, + pg_cnt); return -EINVAL; } @@ -1033,8 +981,7 @@ int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, __m128i shuffle_r_result = _mm_shuffle_epi8(input, shuffle_r_mask); __m128i sllv_result = _mm_sllv_epi32(shuffle_l_result, sllv_mask); __m128i srlv_result = _mm_srlv_epi32(shuffle_r_result, srlv_mask); - __m128i result = - _mm_and_si128(_mm_or_si128(sllv_result, srlv_result), padding_mask); + __m128i result = _mm_and_si128(_mm_or_si128(sllv_result, srlv_result), padding_mask); _mm_store_si128((__m128i *)pg_v210, result); @@ -1079,16 +1026,13 @@ static uint8_t be10_to_v210_and1_tbl_128[16] = { 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, }; -int st20_rfc4175_422be10_to_v210_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, - uint32_t h) { - __m128i shuffle0_mask = - _mm_loadu_si128((__m128i *)be10_to_v210_shuffle0_tbl_128); +int st20_rfc4175_422be10_to_v210_avx512(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h) { + __m128i shuffle0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_shuffle0_tbl_128); __m128i sllv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_sllv0_tbl_128); __m128i srlv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv0_tbl_128); __m128i and0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and0_tbl_128); - __m128i shuffle1_mask = - _mm_loadu_si128((__m128i *)be10_to_v210_shuffle1_tbl_128); + __m128i shuffle1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_shuffle1_tbl_128); __m128i srlv1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv1_tbl_128); __m128i and1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and1_tbl_128); @@ -1096,8 +1040,8 @@ int st20_rfc4175_422be10_to_v210_avx512( int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, + pg_cnt); return -EINVAL; } @@ -1122,16 +1066,15 @@ int st20_rfc4175_422be10_to_v210_avx512( return 0; } -int st20_rfc4175_422be10_to_v210_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h) { - __m128i shuffle0_mask = - _mm_loadu_si128((__m128i *)be10_to_v210_shuffle0_tbl_128); +int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, + uint32_t w, uint32_t h) { + __m128i shuffle0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_shuffle0_tbl_128); __m128i sllv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_sllv0_tbl_128); __m128i srlv0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv0_tbl_128); __m128i and0_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and0_tbl_128); - __m128i shuffle1_mask = - _mm_loadu_si128((__m128i *)be10_to_v210_shuffle1_tbl_128); + __m128i shuffle1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_shuffle1_tbl_128); __m128i srlv1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_srlv1_tbl_128); __m128i and1_mask = _mm_loadu_si128((__m128i *)be10_to_v210_and1_tbl_128); @@ -1139,8 +1082,8 @@ int st20_rfc4175_422be10_to_v210_avx512_dma( int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, + pg_cnt); return -EINVAL; } @@ -1155,20 +1098,18 @@ int st20_rfc4175_422be10_to_v210_avx512_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_v210_avx512(pg_be, pg_v210, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -1179,8 +1120,7 @@ int st20_rfc4175_422be10_to_v210_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -1192,8 +1132,7 @@ int st20_rfc4175_422be10_to_v210_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *be = be_cache; @@ -1261,16 +1200,14 @@ static uint8_t ple_to_be10_shuffle_lo_tbl_128[16] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, }; -int st20_yuv422p10le_to_rfc4175_422be10_avx512( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { +int st20_yuv422p10le_to_rfc4175_422be10_avx512(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h) { uint32_t pg_cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; __m128i sllv_le_mask = _mm_loadu_si128((__m128i *)ple_to_be10_sllv_tbl_128); - __m128i shuffle_hi_mask = - _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_hi_tbl_128); - __m128i shuffle_lo_mask = - _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_lo_tbl_128); + __m128i shuffle_hi_mask = _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_hi_tbl_128); + __m128i shuffle_lo_mask = _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_lo_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ /* each __m128i batch handle 4 __m128i, each __m128i with 2 pg group */ @@ -1300,10 +1237,8 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512( for (int j = 0; j < 4; j++) { /* convert to PGs in __m128i */ __m128i srlv_le_result = _mm_sllv_epi16(src[j], sllv_le_mask); - __m128i shuffle_hi_result = - _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); - __m128i shuffle_lo_result = - _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); + __m128i shuffle_hi_result = _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); + __m128i shuffle_lo_result = _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); __m128i result = _mm_or_si128(shuffle_hi_result, shuffle_lo_result); _mm_mask_storeu_epi8(pg, k, result); pg += 2; @@ -1335,23 +1270,23 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512( return 0; } -int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, - mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { +int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + uint16_t *y, mtl_iova_t y_iova, + uint16_t *b, mtl_iova_t b_iova, + uint16_t *r, mtl_iova_t r_iova, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h) { uint32_t pg_cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; __m128i sllv_le_mask = _mm_loadu_si128((__m128i *)ple_to_be10_sllv_tbl_128); - __m128i shuffle_hi_mask = - _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_hi_tbl_128); - __m128i shuffle_lo_mask = - _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_lo_tbl_128); + __m128i shuffle_hi_mask = _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_hi_tbl_128); + __m128i shuffle_lo_mask = _mm_loadu_si128((__m128i *)ple_to_be10_shuffle_lo_tbl_128); __mmask16 k = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ int caches_num = 4; int le_size_per_pg = (2 + 1 + 1) * sizeof(uint16_t); /* 2y 1b 1r per pg */ - int cache_pg_cnt = (256 * 1024) / le_size_per_pg; /* pg cnt for each cache */ - int align = caches_num * 8; /* align to caches_num and simd */ + int cache_pg_cnt = (256 * 1024) / le_size_per_pg; /* pg cnt for each cache */ + int align = caches_num * 8; /* align to caches_num and simd */ cache_pg_cnt = cache_pg_cnt / align * align; size_t cache_size = cache_pg_cnt * le_size_per_pg; int soc_id = dma->parent->soc_id; @@ -1359,23 +1294,20 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( uint16_t *le_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(3 * caches_num, soc_id, 3); if (!le_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, le_caches); - if (le_caches) - mt_rte_free(le_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + le_caches); + if (le_caches) mt_rte_free(le_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_yuv422p10le_to_rfc4175_422be10_avx512(y, b, r, pg, w, h); } rte_iova_t le_caches_iova = rte_malloc_virt2iova(le_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - uint16_t *le_cache = - le_caches + (i % caches_num) * cache_size / sizeof(*le_cache); + uint16_t *le_cache = le_caches + (i % caches_num) * cache_size / sizeof(*le_cache); dbg("%s, cache batch idx %d le_cache %p\n", __func__, i, le_cache); int max_tran = i + caches_num; @@ -1383,8 +1315,7 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 2); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t cache_iova = - le_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t cache_iova = le_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, cache_iova, y_iova, cache_size / 2); y += (cache_pg_cnt * 2); /* two y in one pg */ @@ -1410,16 +1341,15 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 2) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } int batch = cache_pg_cnt / 8; uint16_t *y_cache = le_cache; uint16_t *b_cache = y_cache + cache_size / 2 / sizeof(uint16_t); uint16_t *r_cache = b_cache + cache_size / 4 / sizeof(uint16_t); - dbg("%s, cache batch idx %d cache y %p b %p r %p\n", __func__, i, y_cache, - b_cache, r_cache); + dbg("%s, cache batch idx %d cache y %p b %p r %p\n", __func__, i, y_cache, b_cache, + r_cache); for (int j = 0; j < batch; j++) { __m128i src_y0 = _mm_loadu_si128((__m128i *)y_cache); /* y0-y7 */ y_cache += 8; @@ -1446,10 +1376,8 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( for (int j = 0; j < 4; j++) { /* convert to PGs in __m128i */ __m128i srlv_le_result = _mm_sllv_epi16(src[j], sllv_le_mask); - __m128i shuffle_hi_result = - _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); - __m128i shuffle_lo_result = - _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); + __m128i shuffle_hi_result = _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); + __m128i shuffle_lo_result = _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); __m128i result = _mm_or_si128(shuffle_hi_result, shuffle_lo_result); _mm_mask_storeu_epi8(pg, k, result); pg += 2; @@ -1488,10 +1416,8 @@ int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( for (int j = 0; j < 4; j++) { /* convert to PGs in __m128i */ __m128i srlv_le_result = _mm_sllv_epi16(src[j], sllv_le_mask); - __m128i shuffle_hi_result = - _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); - __m128i shuffle_lo_result = - _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); + __m128i shuffle_hi_result = _mm_shuffle_epi8(srlv_le_result, shuffle_hi_mask); + __m128i shuffle_lo_result = _mm_shuffle_epi8(srlv_le_result, shuffle_lo_mask); __m128i result = _mm_or_si128(shuffle_hi_result, shuffle_lo_result); _mm_mask_storeu_epi8(pg, k, result); pg += 2; @@ -1679,20 +1605,16 @@ static uint8_t le10_to_be_shuffle_r1_tbl_128[16] = { 0x80, /* zeros */ }; -int st20_rfc4175_422le10_to_422be10_avx512( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { +int st20_rfc4175_422le10_to_422be10_avx512(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ - __m128i shuffle_l0 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l0_tbl_128); - __m128i shuffle_r0 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r0_tbl_128); + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l0_tbl_128); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r0_tbl_128); __m128i and_l0 = _mm_loadu_si128((__m128i *)le10_to_be_and_l0_tbl_128); __m128i and_r0 = _mm_loadu_si128((__m128i *)le10_to_be_and_r0_tbl_128); - __m128i shuffle_l1 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l1_tbl_128); - __m128i shuffle_r1 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r1_tbl_128); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l1_tbl_128); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r1_tbl_128); int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); @@ -1702,10 +1624,8 @@ int st20_rfc4175_422le10_to_422be10_avx512( __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = - _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = - _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); @@ -1744,20 +1664,17 @@ int st20_rfc4175_422le10_to_422be10_avx512( return 0; } -int st20_rfc4175_422le10_to_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, - mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h) { - __m128i shuffle_l0 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l0_tbl_128); - __m128i shuffle_r0 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r0_tbl_128); +int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l0_tbl_128); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r0_tbl_128); __m128i and_l0 = _mm_loadu_si128((__m128i *)le10_to_be_and_l0_tbl_128); __m128i and_r0 = _mm_loadu_si128((__m128i *)le10_to_be_and_r0_tbl_128); - __m128i shuffle_l1 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l1_tbl_128); - __m128i shuffle_r1 = - _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r1_tbl_128); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_l1_tbl_128); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)le10_to_be_shuffle_r1_tbl_128); __mmask16 k = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; @@ -1772,20 +1689,18 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!le_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, le_caches); - if (le_caches) - mt_rte_free(le_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + le_caches); + if (le_caches) mt_rte_free(le_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422le10_to_422be10_avx512(pg_le, pg_be, w, h); } rte_iova_t le_caches_iova = rte_malloc_virt2iova(le_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_le *le_cache = le_caches + (i % caches_num) * cache_pg_cnt; @@ -1796,8 +1711,7 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t le_cache_iova = - le_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t le_cache_iova = le_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, le_cache_iova, pg_le_iova, cache_size); pg_le += cache_pg_cnt; pg_le_iova += cache_size; @@ -1809,8 +1723,7 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_le *le = le_cache; @@ -1819,10 +1732,8 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma( __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = - _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = - _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); @@ -1845,10 +1756,8 @@ int st20_rfc4175_422le10_to_422be10_avx512_dma( __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg_le); __m128i shuffle_l0_result = _mm_shuffle_epi8(input, shuffle_l0); __m128i shuffle_r0_result = _mm_shuffle_epi8(input, shuffle_r0); - __m128i rl_result = - _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); - __m128i rr_result = - _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); + __m128i rl_result = _mm_and_si128(_mm_rol_epi32(shuffle_l0_result, 2), and_l0); + __m128i rr_result = _mm_and_si128(_mm_ror_epi32(shuffle_r0_result, 2), and_r0); __m128i rl_result_shuffle = _mm_shuffle_epi8(rl_result, shuffle_l1); __m128i rr_result_shuffle = _mm_shuffle_epi8(rr_result, shuffle_r1); __m128i result = _mm_or_si128(rl_result_shuffle, rr_result_shuffle); @@ -1923,28 +1832,24 @@ static uint8_t v210_to_be10_and_r_tbl_128[16] = { 0x03, 0xFF, 0x00, 0x3F, 0x0F, 0x03, 0xFF, 0x00, }; -int st20_v210_to_rfc4175_422be10_avx512( - uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h) { - __m128i shuffle_l0 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l0_tbl_128); +int st20_v210_to_rfc4175_422be10_avx512(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l0_tbl_128); __m128i sllv = _mm_loadu_si128((__m128i *)v210_to_be10_sllv_tbl_128); - __m128i shuffle_l1 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l1_tbl_128); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l1_tbl_128); __m128i and_l = _mm_loadu_si128((__m128i *)v210_to_be10_and_l_tbl_128); - __m128i shuffle_r0 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r0_tbl_128); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r0_tbl_128); __m128i srlv = _mm_loadu_si128((__m128i *)v210_to_be10_srlv_tbl_128); - __m128i shuffle_r1 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r1_tbl_128); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r1_tbl_128); __m128i and_r = _mm_loadu_si128((__m128i *)v210_to_be10_and_r_tbl_128); __mmask16 k_store = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, + pg_cnt); return -EINVAL; } @@ -1970,28 +1875,25 @@ int st20_v210_to_rfc4175_422be10_avx512( return 0; } -int st20_v210_to_rfc4175_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { - __m128i shuffle_l0 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l0_tbl_128); +int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + __m128i shuffle_l0 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l0_tbl_128); __m128i sllv = _mm_loadu_si128((__m128i *)v210_to_be10_sllv_tbl_128); - __m128i shuffle_l1 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l1_tbl_128); + __m128i shuffle_l1 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_l1_tbl_128); __m128i and_l = _mm_loadu_si128((__m128i *)v210_to_be10_and_l_tbl_128); - __m128i shuffle_r0 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r0_tbl_128); + __m128i shuffle_r0 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r0_tbl_128); __m128i srlv = _mm_loadu_si128((__m128i *)v210_to_be10_srlv_tbl_128); - __m128i shuffle_r1 = - _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r1_tbl_128); + __m128i shuffle_r1 = _mm_loadu_si128((__m128i *)v210_to_be10_shuffle_r1_tbl_128); __m128i and_r = _mm_loadu_si128((__m128i *)v210_to_be10_and_r_tbl_128); __mmask16 k_store = 0x7FFF; /* each __m128i with 3 pg group, 15 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 3 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 3!\n", __func__, + pg_cnt); return -EINVAL; } @@ -2006,20 +1908,18 @@ int st20_v210_to_rfc4175_422be10_avx512_dma( uint8_t *v210_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!v210_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, v210_caches); - if (v210_caches) - mt_rte_free(v210_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + v210_caches); + if (v210_caches) mt_rte_free(v210_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_v210_to_rfc4175_422be10_avx512(pg_v210, pg_be, w, h); } rte_iova_t v210_caches_iova = rte_malloc_virt2iova(v210_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { uint8_t *v210_cache = v210_caches + (i % caches_num) * cache_size; dbg("%s, cache batch idx %d\n", __func__, i); @@ -2042,8 +1942,7 @@ int st20_v210_to_rfc4175_422be10_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } uint8_t *v210 = v210_cache; @@ -2109,11 +2008,9 @@ static uint16_t be10_to_y210_and_tbl_128[8] = { 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, 0xFFC0, }; -int st20_rfc4175_422be10_to_y210_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *pg_y210, uint32_t w, - uint32_t h) { - __m128i shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_y210_shuffle_tbl_128); +int st20_rfc4175_422be10_to_y210_avx512(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint16_t *pg_y210, uint32_t w, uint32_t h) { + __m128i shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_y210_shuffle_tbl_128); __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_y210_sllv_tbl_128); __m128i and_mask = _mm_loadu_si128((__m128i *)be10_to_y210_and_tbl_128); @@ -2149,11 +2046,11 @@ int st20_rfc4175_422be10_to_y210_avx512( return 0; } -int st20_rfc4175_422be10_to_y210_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h) { - __m128i shuffle_mask = - _mm_loadu_si128((__m128i *)be10_to_y210_shuffle_tbl_128); +int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, + uint32_t w, uint32_t h) { + __m128i shuffle_mask = _mm_loadu_si128((__m128i *)be10_to_y210_shuffle_tbl_128); __m128i sllv_mask = _mm_loadu_si128((__m128i *)be10_to_y210_sllv_tbl_128); __m128i and_mask = _mm_loadu_si128((__m128i *)be10_to_y210_and_tbl_128); @@ -2173,20 +2070,18 @@ int st20_rfc4175_422be10_to_y210_avx512_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_y210_avx512(pg_be, pg_y210, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -2197,8 +2092,7 @@ int st20_rfc4175_422be10_to_y210_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -2210,8 +2104,7 @@ int st20_rfc4175_422be10_to_y210_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *be = be_cache; int batch = cache_pg_cnt / 2; @@ -2278,15 +2171,13 @@ static uint8_t y210_to_be10_shuffle1_tbl_128[16] = { 0, 0, 0, 0, 0, 0, }; -int st20_y210_to_rfc4175_422be10_avx512( - uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h) { - __m128i srlv_mask = _mm_loadu_si128( - (__m128i *)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ - __m128i shuffle0_mask = - _mm_loadu_si128((__m128i *)y210_to_be10_shuffle0_tbl_128); - __m128i shuffle1_mask = - _mm_loadu_si128((__m128i *)y210_to_be10_shuffle1_tbl_128); +int st20_y210_to_rfc4175_422be10_avx512(uint16_t *pg_y210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + __m128i srlv_mask = + _mm_loadu_si128((__m128i *)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ + __m128i shuffle0_mask = _mm_loadu_si128((__m128i *)y210_to_be10_shuffle0_tbl_128); + __m128i shuffle1_mask = _mm_loadu_si128((__m128i *)y210_to_be10_shuffle1_tbl_128); __mmask16 k_store = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ @@ -2296,10 +2187,8 @@ int st20_y210_to_rfc4175_422be10_avx512( for (int i = 0; i < batch; i++) { __m128i input = _mm_loadu_si128((__m128i *)pg_y210); __m128i srlv_result = _mm_srlv_epi16(input, srlv_mask); - __m128i shuffle0_result = - _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); - __m128i shuffle1_result = - _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); + __m128i shuffle0_result = _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); + __m128i shuffle1_result = _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); __m128i result = _mm_or_si128(shuffle0_result, shuffle1_result); _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); @@ -2327,15 +2216,14 @@ int st20_y210_to_rfc4175_422be10_avx512( return 0; } -int st20_y210_to_rfc4175_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { - __m128i srlv_mask = _mm_loadu_si128( - (__m128i *)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ - __m128i shuffle0_mask = - _mm_loadu_si128((__m128i *)y210_to_be10_shuffle0_tbl_128); - __m128i shuffle1_mask = - _mm_loadu_si128((__m128i *)y210_to_be10_shuffle1_tbl_128); +int st20_y210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + uint16_t *pg_y210, mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + __m128i srlv_mask = + _mm_loadu_si128((__m128i *)be10_to_y210_sllv_tbl_128); /* reverse of be to y210 */ + __m128i shuffle0_mask = _mm_loadu_si128((__m128i *)y210_to_be10_shuffle0_tbl_128); + __m128i shuffle1_mask = _mm_loadu_si128((__m128i *)y210_to_be10_shuffle1_tbl_128); __mmask16 k_store = 0x3FF; /* each __m128i with 2 pg group, 10 bytes */ @@ -2344,29 +2232,26 @@ int st20_y210_to_rfc4175_422be10_avx512_dma( int caches_num = 4; int cache_pg_cnt = (256 * 1024) / 8; /* pg cnt for each cache */ - int align = caches_num * 2; /* align to simd pg groups and caches_num */ + int align = caches_num * 2; /* align to simd pg groups and caches_num */ cache_pg_cnt = cache_pg_cnt / align * align; size_t cache_size = cache_pg_cnt * 8; int soc_id = dma->parent->soc_id; - uint16_t *y210_caches = - mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); + uint16_t *y210_caches = mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!y210_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, y210_caches); - if (y210_caches) - mt_rte_free(y210_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + y210_caches); + if (y210_caches) mt_rte_free(y210_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_y210_to_rfc4175_422be10_avx512(pg_y210, pg_be, w, h); } rte_iova_t y210_caches_iova = rte_malloc_virt2iova(y210_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { uint16_t *y210_cache = y210_caches + (i % caches_num) * cache_pg_cnt * 4; dbg("%s, cache batch idx %d\n", __func__, i); @@ -2389,18 +2274,15 @@ int st20_y210_to_rfc4175_422be10_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } uint16_t *y210 = y210_cache; int batch = cache_pg_cnt / 2; for (int j = 0; j < batch; j++) { __m128i input = _mm_loadu_si128((__m128i *)y210); __m128i srlv_result = _mm_srlv_epi16(input, srlv_mask); - __m128i shuffle0_result = - _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); - __m128i shuffle1_result = - _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); + __m128i shuffle0_result = _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); + __m128i shuffle1_result = _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); __m128i result = _mm_or_si128(shuffle0_result, shuffle1_result); _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); @@ -2419,10 +2301,8 @@ int st20_y210_to_rfc4175_422be10_avx512_dma( for (int i = 0; i < batch; i++) { __m128i input = _mm_loadu_si128((__m128i *)pg_y210); __m128i srlv_result = _mm_srlv_epi16(input, srlv_mask); - __m128i shuffle0_result = - _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); - __m128i shuffle1_result = - _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); + __m128i shuffle0_result = _mm_maskz_shuffle_epi8(0x1EF, srlv_result, shuffle0_mask); + __m128i shuffle1_result = _mm_maskz_shuffle_epi8(0x3DE, srlv_result, shuffle1_mask); __m128i result = _mm_or_si128(shuffle0_result, shuffle1_result); _mm_mask_storeu_epi8((__m128i *)pg_be, k_store, result); @@ -2466,9 +2346,9 @@ static uint8_t be12_to_le12_shuffle1_tbl_128[16] = { 0x80, 0x80, 0x80, 0x80, /*zeros*/ }; -int st20_rfc4175_422be12_to_422le12_avx512( - struct st20_rfc4175_422_12_pg2_be *pg_be, - struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h) { +int st20_rfc4175_422be12_to_422le12_avx512(struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { __m128i shuffle0 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle0_tbl_128); __m128i shuffle1 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle1_tbl_128); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ @@ -2516,10 +2396,11 @@ int st20_rfc4175_422be12_to_422le12_avx512( return 0; } -int st20_rfc4175_422be12_to_422le12_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, - uint32_t h) { +int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { __m128i shuffle0 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle0_tbl_128); __m128i shuffle1 = _mm_loadu_si128((__m128i *)be12_to_le12_shuffle1_tbl_128); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ @@ -2536,20 +2417,18 @@ int st20_rfc4175_422be12_to_422le12_avx512_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be12_to_422le12_avx512(pg_be, pg_le, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_12_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -2560,8 +2439,7 @@ int st20_rfc4175_422be12_to_422le12_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -2573,8 +2451,7 @@ int st20_rfc4175_422be12_to_422le12_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_12_pg2_be *be = be_cache; @@ -2654,16 +2531,13 @@ static uint16_t be12_to_ple_and_mask_tbl_128[8] = { 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, }; -int st20_rfc4175_422be12_to_yuv422p12le_avx512( - struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = - _mm_loadu_si128((__m128i *)be12_to_ple_shuffle_tbl_128); +int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { + __m128i shuffle_le_mask = _mm_loadu_si128((__m128i *)be12_to_ple_shuffle_tbl_128); __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be12_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = - _mm_loadu_si128((__m128i *)be12_to_ple_and_mask_tbl_128); - __m512i permute_mask = - _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); + __m128i srlv_and_mask = _mm_loadu_si128((__m128i *)be12_to_ple_and_mask_tbl_128); + __m512i permute_mask = _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ int pg_cnt = w * h / 2; dbg("%s, pg_cnt %d\n", __func__, pg_cnt); @@ -2694,19 +2568,15 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512( /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = @@ -2771,13 +2641,10 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h) { - __m128i shuffle_le_mask = - _mm_loadu_si128((__m128i *)be12_to_ple_shuffle_tbl_128); + __m128i shuffle_le_mask = _mm_loadu_si128((__m128i *)be12_to_ple_shuffle_tbl_128); __m128i srlv_le_mask = _mm_loadu_si128((__m128i *)be12_to_ple_srlv_tbl_128); - __m128i srlv_and_mask = - _mm_loadu_si128((__m128i *)be12_to_ple_and_mask_tbl_128); - __m512i permute_mask = - _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); + __m128i srlv_and_mask = _mm_loadu_si128((__m128i *)be12_to_ple_and_mask_tbl_128); + __m512i permute_mask = _mm512_loadu_si512((__m512i *)be10_to_ple_permute_tbl_512); __mmask16 k = 0xFFF; /* each __m128i with 2 pg group, 12 bytes */ int pg_cnt = w * h / 2; @@ -2792,20 +2659,18 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be12_to_yuv422p12le_avx512(pg_be, y, b, r, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_12_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -2816,8 +2681,7 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -2829,8 +2693,7 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_12_pg2_be *pg = be_cache; @@ -2841,8 +2704,7 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( for (int j = 0; j < 16; j++) { __m128i input = _mm_maskz_loadu_epi8(k, (__m128i *)pg); __m128i shuffle_le_result = _mm_shuffle_epi8(input, shuffle_le_mask); - __m128i srlv_le_result = - _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); + __m128i srlv_le_result = _mm_srlv_epi16(shuffle_le_result, srlv_le_mask); stage_m128i[j] = _mm_and_si128(srlv_le_result, srlv_and_mask); pg += 2; } @@ -2851,8 +2713,7 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( for (int j = 0; j < 4; j++) { /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, * Y7} */ - __m512i input_m512i = - _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); + __m512i input_m512i = _mm512_loadu_si512((__m512i *)&stage_m128i[j * 4]); /* {B0, B1, B2, B3}, {R0, R1, R2, R3}, {Y0, Y1, Y2, Y3}, {Y4, Y5, Y6, * Y7} */ stage_m512i[j] = _mm512_permutexvar_epi32(permute_mask, input_m512i); @@ -2862,19 +2723,15 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = @@ -2920,19 +2777,15 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( /* {B0, R0, Y0, Y1}, {B1, R1, Y2, Y3}, {B2, R2, Y4, Y5}, {B3, R3, Y6, Y7} */ __m512i result_m512i[4]; /* {B0, R0, B1, R1} */ - result_m512i[0] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); + result_m512i[0] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b01000100); /* {Y0, Y1, Y2, Y3} */ - result_m512i[1] = - _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); + result_m512i[1] = _mm512_shuffle_i32x4(stage_m512i[0], stage_m512i[1], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[1]); y += 32; /* {B2, R2, B3, R3} */ - result_m512i[2] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); + result_m512i[2] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b01000100); /* {Y4, Y5, Y6, Y7} */ - result_m512i[3] = - _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); + result_m512i[3] = _mm512_shuffle_i32x4(stage_m512i[2], stage_m512i[3], 0b11101110); _mm512_storeu_si512((__m512i *)y, result_m512i[3]); y += 32; __m512i b_result_m512i = diff --git a/lib/src/st2110/st_avx512.h b/lib/src/st2110/st_avx512.h index e9d202dec..5f8c54720 100644 --- a/lib/src/st2110/st_avx512.h +++ b/lib/src/st2110/st_avx512.h @@ -7,110 +7,116 @@ #include "st_main.h" -int st20_rfc4175_422be10_to_yuv422p10le_avx512( - struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv422p10le_avx512(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le10_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx512(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le8_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le8_avx512(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le8_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, - mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, - uint32_t h); +int st20_rfc4175_422be10_to_422le8_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h); -int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, - uint32_t w, uint32_t h); +int st20_rfc4175_422le10_to_v210_avx512(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, + uint32_t h); -int st20_rfc4175_422be10_to_v210_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, - uint32_t h); +int st20_rfc4175_422be10_to_v210_avx512(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le10_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, - uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h); int st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h); - -int st20_rfc4175_422be10_to_v210_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h); - -int st20_yuv422p10le_to_rfc4175_422be10_avx512( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h); - -int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, - mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h); - -int st20_rfc4175_422le10_to_422be10_avx512( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); - -int st20_rfc4175_422le10_to_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, - mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h); - -int st20_v210_to_rfc4175_422be10_avx512( - uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h); + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h); + +int st20_rfc4175_422be10_to_v210_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, + uint32_t w, uint32_t h); + +int st20_yuv422p10le_to_rfc4175_422be10_avx512(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h); + +int st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + uint16_t *y, mtl_iova_t y_iova, + uint16_t *b, mtl_iova_t b_iova, + uint16_t *r, mtl_iova_t r_iova, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h); + +int st20_rfc4175_422le10_to_422be10_avx512(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); + +int st20_rfc4175_422le10_to_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); + +int st20_v210_to_rfc4175_422be10_avx512(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); -int st20_v210_to_rfc4175_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); +int st20_v210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + uint8_t *pg_v210, mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_y210_avx512( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *pg_y210, uint32_t w, - uint32_t h); +int st20_rfc4175_422be10_to_y210_avx512(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint16_t *pg_y210, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_y210_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_y210_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, + uint32_t w, uint32_t h); -int st20_y210_to_rfc4175_422be10_avx512( - uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h); +int st20_y210_to_rfc4175_422be10_avx512(uint16_t *pg_y210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); -int st20_y210_to_rfc4175_422be10_avx512_dma( - struct mtl_dma_lender_dev *dma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); +int st20_y210_to_rfc4175_422be10_avx512_dma(struct mtl_dma_lender_dev *dma, + uint16_t *pg_y210, mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); -int st20_rfc4175_422be12_to_422le12_avx512( - struct st20_rfc4175_422_12_pg2_be *pg_be, - struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h); +int st20_rfc4175_422be12_to_422le12_avx512(struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h); -int st20_rfc4175_422be12_to_422le12_avx512_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, - uint32_t h); +int st20_rfc4175_422be12_to_422le12_avx512_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h); -int st20_rfc4175_422be12_to_yuv422p12le_avx512( - struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h); +int st20_rfc4175_422be12_to_yuv422p12le_avx512(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h); int st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h); + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_yuv422p8_avx512( - struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv422p8_avx512(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_yuv420p8_avx512( - struct st20_rfc4175_422_10_pg2_be *pg, uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv420p8_avx512(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h); #endif \ No newline at end of file diff --git a/lib/src/st2110/st_avx512_vbmi.c b/lib/src/st2110/st_avx512_vbmi.c index 8a1f02900..6f667649b 100644 --- a/lib/src/st2110/st_avx512_vbmi.c +++ b/lib/src/st2110/st_avx512_vbmi.c @@ -11,22 +11,14 @@ MT_TARGET_CODE_START_AVX512_VBMI2 /* begin st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi */ static uint8_t be10_to_ple_permute_tbl_512[16 * 4] = { - 1, 0, 6, 5, - 1 + 10, 0 + 10, 6 + 10, 5 + 10, /* b0, b1, b2, b3 */ - 1 + 20, 0 + 20, 6 + 20, 5 + 20, - 1 + 30, 0 + 30, 6 + 30, 5 + 30, /* b4, b5, b6, b7 */ - 3, 2, 8, 7, - 3 + 10, 2 + 10, 8 + 10, 7 + 10, /* r0, r1, r2, r3 */ - 3 + 20, 2 + 20, 8 + 20, 7 + 20, - 3 + 30, 2 + 30, 8 + 30, 7 + 30, /* r4, r5, r6, r7 */ - 2, 1, 4, 3, - 7, 6, 9, 8, /* y0 - y3 */ - 2 + 10, 1 + 10, 4 + 10, 3 + 10, - 7 + 10, 6 + 10, 9 + 10, 8 + 10, /* y4 - y7 */ - 2 + 20, 1 + 20, 4 + 20, 3 + 20, - 7 + 20, 6 + 20, 9 + 20, 8 + 20, /* y8 - y11 */ - 2 + 30, 1 + 30, 4 + 30, 3 + 30, - 7 + 30, 6 + 30, 9 + 30, 8 + 30, /* y12 - y15 */ + 1, 0, 6, 5, 1 + 10, 0 + 10, 6 + 10, 5 + 10, /* b0, b1, b2, b3 */ + 1 + 20, 0 + 20, 6 + 20, 5 + 20, 1 + 30, 0 + 30, 6 + 30, 5 + 30, /* b4, b5, b6, b7 */ + 3, 2, 8, 7, 3 + 10, 2 + 10, 8 + 10, 7 + 10, /* r0, r1, r2, r3 */ + 3 + 20, 2 + 20, 8 + 20, 7 + 20, 3 + 30, 2 + 30, 8 + 30, 7 + 30, /* r4, r5, r6, r7 */ + 2, 1, 4, 3, 7, 6, 9, 8, /* y0 - y3 */ + 2 + 10, 1 + 10, 4 + 10, 3 + 10, 7 + 10, 6 + 10, 9 + 10, 8 + 10, /* y4 - y7 */ + 2 + 20, 1 + 20, 4 + 20, 3 + 20, 7 + 20, 6 + 20, 9 + 20, 8 + 20, /* y8 - y11 */ + 2 + 30, 1 + 30, 4 + 30, 3 + 30, 7 + 30, 6 + 30, 9 + 30, 8 + 30, /* y12 - y15 */ }; static uint16_t be10_to_ple_srlv_tbl_512[8 * 4] = { @@ -37,19 +29,15 @@ static uint16_t be10_to_ple_srlv_tbl_512[8 * 4] = { }; static uint16_t be10_to_ple_and_tbl_512[8 * 4] = { - 0x03ff, 0x03ff, 0x03ff, 0x03ff, - 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* b0 - b7 */ - 0x03ff, 0x03ff, 0x03ff, 0x03ff, - 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* r0 - r7 */ - 0x03ff, 0x03ff, 0x03ff, 0x03ff, - 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y0 - y7 */ - 0x03ff, 0x03ff, 0x03ff, 0x03ff, - 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y8 - y15 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* b0 - b7 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* r0 - r7 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y0 - y7 */ + 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, 0x03ff, /* y8 - y15 */ }; -int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { __m512i permute_le_mask = _mm512_loadu_si512(be10_to_ple_permute_tbl_512); __m512i srlv_le_mask = _mm512_loadu_si512(be10_to_ple_srlv_tbl_512); __m512i srlv_and_mask = _mm512_loadu_si512(be10_to_ple_and_tbl_512); @@ -157,21 +145,18 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); - return st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(pg_be, y, b, r, w, - h); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); + return st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(pg_be, y, b, r, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -182,8 +167,7 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -195,18 +179,15 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *pg = be_cache; int batch = cache_pg_cnt / 8; for (int j = 0; j < batch; j++) { __m512i input = _mm512_maskz_loadu_epi8(k, pg); - __m512i permute_le_result = - _mm512_permutexvar_epi8(permute_le_mask, input); - __m512i srlv_le_result = - _mm512_srlv_epi16(permute_le_result, srlv_le_mask); + __m512i permute_le_result = _mm512_permutexvar_epi8(permute_le_mask, input); + __m512i srlv_le_result = _mm512_srlv_epi16(permute_le_result, srlv_le_mask); __m512i stage_m512i = _mm512_and_si512(srlv_le_result, srlv_and_mask); pg += 8; @@ -276,91 +257,57 @@ int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( /* begin st20_rfc4175_422be10_to_422le10_avx512_vbmi */ static uint8_t be10_to_le_permute_l0_tbl_512[64] = { - 1, 0, - 3, 2, /* 4 bytes from pg0 */ - 6, 5, - 8, 7, /* 4 bytes from pg1 */ - 11, 10, - 13, 12, /* 4 bytes from pg2 */ - 0, 5, - 10, 63, /* 5th bytes from pg0,pg1,pg2, and a padding */ - 1 + 15, 0 + 15, - 3 + 15, 2 + 15, /* 4 bytes from pg3 */ - 6 + 15, 5 + 15, - 8 + 15, 7 + 15, /* 4 bytes from pg4 */ - 11 + 15, 10 + 15, - 13 + 15, 12 + 15, /* 4 bytes from pg5 */ - 0 + 15, 5 + 15, - 10 + 15, 63, /* 5th bytes from pg3,pg4,pg5, and a padding */ - 1 + 30, 0 + 30, - 3 + 30, 2 + 30, /* 4 bytes from pg6 */ - 6 + 30, 5 + 30, - 8 + 30, 7 + 30, /* 4 bytes from pg7 */ - 11 + 30, 10 + 30, - 13 + 30, 12 + 30, /* 4 bytes from pg8 */ - 0 + 30, 5 + 30, - 10 + 30, 63, /* 5th bytes from pg6,pg7,pg8, and a padding */ - 1 + 45, 0 + 45, - 3 + 45, 2 + 45, /* 4 bytes from pg9 */ - 6 + 45, 5 + 45, - 8 + 45, 7 + 45, /* 4 bytes from pg10 */ - 11 + 45, 10 + 45, - 13 + 45, 12 + 45, /* 4 bytes from pg11 */ - 0 + 45, 5 + 45, - 10 + 45, 63, /* 5th bytes from pg9,pg10,pg11, and a padding */ + 1, 0, 3, 2, /* 4 bytes from pg0 */ + 6, 5, 8, 7, /* 4 bytes from pg1 */ + 11, 10, 13, 12, /* 4 bytes from pg2 */ + 0, 5, 10, 63, /* 5th bytes from pg0,pg1,pg2, and a padding */ + 1 + 15, 0 + 15, 3 + 15, 2 + 15, /* 4 bytes from pg3 */ + 6 + 15, 5 + 15, 8 + 15, 7 + 15, /* 4 bytes from pg4 */ + 11 + 15, 10 + 15, 13 + 15, 12 + 15, /* 4 bytes from pg5 */ + 0 + 15, 5 + 15, 10 + 15, 63, /* 5th bytes from pg3,pg4,pg5, and a padding */ + 1 + 30, 0 + 30, 3 + 30, 2 + 30, /* 4 bytes from pg6 */ + 6 + 30, 5 + 30, 8 + 30, 7 + 30, /* 4 bytes from pg7 */ + 11 + 30, 10 + 30, 13 + 30, 12 + 30, /* 4 bytes from pg8 */ + 0 + 30, 5 + 30, 10 + 30, 63, /* 5th bytes from pg6,pg7,pg8, and a padding */ + 1 + 45, 0 + 45, 3 + 45, 2 + 45, /* 4 bytes from pg9 */ + 6 + 45, 5 + 45, 8 + 45, 7 + 45, /* 4 bytes from pg10 */ + 11 + 45, 10 + 45, 13 + 45, 12 + 45, /* 4 bytes from pg11 */ + 0 + 45, 5 + 45, 10 + 45, 63, /* 5th bytes from pg9,pg10,pg11, and a padding */ }; static uint8_t be10_to_le_and_l0_tbl_512[64] = { - 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, - 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, - 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, - 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, - 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, - 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, + 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, + 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, + 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, + 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, 0x00, 0xFF, 0xF0, 0x3F, + 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0xFF, 0xF0, 0x3F, 0x00, 0x03, 0x03, 0x03, }; static uint8_t be10_to_le_permute_r0_tbl_512[64] = { - 2, 1, - 4, 3, /* 4 bytes from pg0 */ - 7, 6, - 9, 8, /* 4 bytes from pg1 */ - 12, 11, - 14, 13, /* 4 bytes from pg2 */ - 63, 4, - 9, 14, /* 1st bytes from pg0,pg1,pg2, and a padding */ - 2 + 15, 1 + 15, - 4 + 15, 3 + 15, /* 4 bytes from pg3 */ - 7 + 15, 6 + 15, - 9 + 15, 8 + 15, /* 4 bytes from pg4 */ - 12 + 15, 11 + 15, - 14 + 15, 13 + 15, /* 4 bytes from pg5 */ - 63, 4 + 15, - 9 + 15, 14 + 15, /* 1st bytes from pg3,pg4,pg5, and a padding */ - 2 + 30, 1 + 30, - 4 + 30, 3 + 30, /* 4 bytes from pg6 */ - 7 + 30, 6 + 30, - 9 + 30, 8 + 30, /* 4 bytes from pg7 */ - 12 + 30, 11 + 30, - 14 + 30, 13 + 30, /* 4 bytes from pg8 */ - 63, 4 + 30, - 9 + 30, 14 + 30, /* 1st bytes from pg6,pg7,pg8, and a padding */ - 2 + 45, 1 + 45, - 4 + 45, 3 + 45, /* 4 bytes from pg6 */ - 7 + 45, 6 + 45, - 9 + 45, 8 + 45, /* 4 bytes from pg7 */ - 12 + 45, 11 + 45, - 14 + 45, 13 + 45, /* 4 bytes from pg8 */ - 63, 4 + 45, - 9 + 45, 14 + 45, /* 1st bytes from pg9,pg10,pg11, and a padding */ + 2, 1, 4, 3, /* 4 bytes from pg0 */ + 7, 6, 9, 8, /* 4 bytes from pg1 */ + 12, 11, 14, 13, /* 4 bytes from pg2 */ + 63, 4, 9, 14, /* 1st bytes from pg0,pg1,pg2, and a padding */ + 2 + 15, 1 + 15, 4 + 15, 3 + 15, /* 4 bytes from pg3 */ + 7 + 15, 6 + 15, 9 + 15, 8 + 15, /* 4 bytes from pg4 */ + 12 + 15, 11 + 15, 14 + 15, 13 + 15, /* 4 bytes from pg5 */ + 63, 4 + 15, 9 + 15, 14 + 15, /* 1st bytes from pg3,pg4,pg5, and a padding */ + 2 + 30, 1 + 30, 4 + 30, 3 + 30, /* 4 bytes from pg6 */ + 7 + 30, 6 + 30, 9 + 30, 8 + 30, /* 4 bytes from pg7 */ + 12 + 30, 11 + 30, 14 + 30, 13 + 30, /* 4 bytes from pg8 */ + 63, 4 + 30, 9 + 30, 14 + 30, /* 1st bytes from pg6,pg7,pg8, and a padding */ + 2 + 45, 1 + 45, 4 + 45, 3 + 45, /* 4 bytes from pg6 */ + 7 + 45, 6 + 45, 9 + 45, 8 + 45, /* 4 bytes from pg7 */ + 12 + 45, 11 + 45, 14 + 45, 13 + 45, /* 4 bytes from pg8 */ + 63, 4 + 45, 9 + 45, 14 + 45, /* 1st bytes from pg9,pg10,pg11, and a padding */ }; static uint8_t be10_to_le_and_r0_tbl_512[64] = { - 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, - 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, - 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, - 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, - 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, - 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, + 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, + 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, + 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, + 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0xFC, 0x0F, 0xFF, 0x00, + 0xFC, 0x0F, 0xFF, 0x00, 0xFC, 0x0F, 0xFF, 0x00, 0xC0, 0xC0, 0xC0, 0x00, }; static uint8_t be10_to_le_permute_l1_tbl_512[64] = { @@ -395,19 +342,15 @@ static uint8_t be10_to_le_permute_r1_tbl_512[64] = { 63, 63, 63, 63, /* zeros */ }; -int st20_rfc4175_422be10_to_422le10_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { - __m512i permute_l0 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_l0_tbl_512); - __m512i permute_r0 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_r0_tbl_512); +int st20_rfc4175_422be10_to_422le10_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h) { + __m512i permute_l0 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_l0_tbl_512); + __m512i permute_r0 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_r0_tbl_512); __m512i and_l0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_l0_tbl_512); __m512i and_r0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_r0_tbl_512); - __m512i permute_l1 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_l1_tbl_512); - __m512i permute_r1 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_r1_tbl_512); + __m512i permute_l1 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_l1_tbl_512); + __m512i permute_r1 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; @@ -417,10 +360,8 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi( __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_be); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = - _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = - _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); @@ -461,16 +402,12 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { - __m512i permute_l0 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_l0_tbl_512); - __m512i permute_r0 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_r0_tbl_512); + __m512i permute_l0 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_l0_tbl_512); + __m512i permute_r0 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_r0_tbl_512); __m512i and_l0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_l0_tbl_512); __m512i and_r0 = _mm512_loadu_si512((__m512i *)be10_to_le_and_r0_tbl_512); - __m512i permute_l1 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_l1_tbl_512); - __m512i permute_r1 = - _mm512_loadu_si512((__m512i *)be10_to_le_permute_r1_tbl_512); + __m512i permute_l1 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_l1_tbl_512); + __m512i permute_r1 = _mm512_loadu_si512((__m512i *)be10_to_le_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; @@ -486,20 +423,18 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( /* two type be(0) or le(1) */ struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le10_avx512_vbmi(pg_be, pg_le, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -510,8 +445,7 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -523,8 +457,7 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *be = be_cache; @@ -537,10 +470,8 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); - __m512i rl_result_shuffle = - _mm512_permutexvar_epi8(permute_l1, rl_result); - __m512i rr_result_shuffle = - _mm512_permutexvar_epi8(permute_r1, rr_result); + __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); + __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ @@ -561,10 +492,8 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_be); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = - _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = - _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); @@ -641,13 +570,11 @@ static uint8_t be10_to_le8_multishift_tbl_512[16 * 4] = { 24, 54, 44, 34, /* pg11 */ }; -int st20_rfc4175_422be10_to_422le8_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { - __m512i permute_mask = - _mm512_loadu_si512((__m512i *)be10_to_le8_permute_tbl_512); - __m512i multishift_mask = - _mm512_loadu_si512((__m512i *)be10_to_le8_multishift_tbl_512); +int st20_rfc4175_422be10_to_422le8_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h) { + __m512i permute_mask = _mm512_loadu_si512((__m512i *)be10_to_le8_permute_tbl_512); + __m512i multishift_mask = _mm512_loadu_si512((__m512i *)be10_to_le8_multishift_tbl_512); __mmask16 k_load = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ __mmask32 k_compress = 0xDBDBDBDB; int pg_cnt = w * h / 2; @@ -687,10 +614,8 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { - __m512i permute_mask = - _mm512_loadu_si512((__m512i *)be10_to_le8_permute_tbl_512); - __m512i multishift_mask = - _mm512_loadu_si512((__m512i *)be10_to_le8_multishift_tbl_512); + __m512i permute_mask = _mm512_loadu_si512((__m512i *)be10_to_le8_permute_tbl_512); + __m512i multishift_mask = _mm512_loadu_si512((__m512i *)be10_to_le8_multishift_tbl_512); __mmask16 k_load = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ __mmask32 k_compress = 0xDBDBDBDB; int pg_cnt = w * h / 2; @@ -708,20 +633,18 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( /* two type be(0) or le(1) */ struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be10_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be10_caches); - if (be10_caches) - mt_rte_free(be10_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be10_caches); + if (be10_caches) mt_rte_free(be10_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le8_avx512_vbmi(pg_10, pg_8, w, h); } rte_iova_t be10_caches_iova = rte_malloc_virt2iova(be10_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be10_cache = be10_caches + (i % caches_num) * cache_pg_cnt; @@ -745,8 +668,7 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *be_10 = be10_cache; int batch = cache_pg_cnt / 12; @@ -801,14 +723,14 @@ int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( /* begin st20_rfc4175_422le10_to_v210_avx512_vbmi */ static uint8_t le10_to_v210_permute_tbl_512[16 * 4] = { - 0, 1, 2, 3, 4, 5, 6, 7, 7, - 8, 9, 10, 11, 12, 13, 14, /* pg0-2 */ - 0 + 15, 1 + 15, 2 + 15, 3 + 15, 4 + 15, 5 + 15, 6 + 15, 7 + 15, 7 + 15, - 8 + 15, 9 + 15, 10 + 15, 11 + 15, 12 + 15, 13 + 15, 14 + 15, /* pg3-5 */ - 0 + 30, 1 + 30, 2 + 30, 3 + 30, 4 + 30, 5 + 30, 6 + 30, 7 + 30, 7 + 30, - 8 + 30, 9 + 30, 10 + 30, 11 + 30, 12 + 30, 13 + 30, 14 + 30, /* pg6-8 */ - 0 + 45, 1 + 45, 2 + 45, 3 + 45, 4 + 45, 5 + 45, 6 + 45, 7 + 45, 7 + 45, - 8 + 45, 9 + 45, 10 + 45, 11 + 45, 12 + 45, 13 + 45, 14 + 45, /* pg9-11 */ + 0, 1, 2, 3, 4, 5, 6, 7, + 7, 8, 9, 10, 11, 12, 13, 14, /* pg0-2 */ + 0 + 15, 1 + 15, 2 + 15, 3 + 15, 4 + 15, 5 + 15, 6 + 15, 7 + 15, + 7 + 15, 8 + 15, 9 + 15, 10 + 15, 11 + 15, 12 + 15, 13 + 15, 14 + 15, /* pg3-5 */ + 0 + 30, 1 + 30, 2 + 30, 3 + 30, 4 + 30, 5 + 30, 6 + 30, 7 + 30, + 7 + 30, 8 + 30, 9 + 30, 10 + 30, 11 + 30, 12 + 30, 13 + 30, 14 + 30, /* pg6-8 */ + 0 + 45, 1 + 45, 2 + 45, 3 + 45, 4 + 45, 5 + 45, 6 + 45, 7 + 45, + 7 + 45, 8 + 45, 9 + 45, 10 + 45, 11 + 45, 12 + 45, 13 + 45, 14 + 45, /* pg9-11 */ }; static uint8_t le10_to_v210_multishift_tbl_512[16 * 4] = { @@ -818,28 +740,25 @@ static uint8_t le10_to_v210_multishift_tbl_512[16 * 4] = { 0, 8, 16, 24, 30, 38, 46, 54, 4, 12, 20, 28, 34, 42, 50, 58, }; static uint8_t le10_to_v210_and_tbl_512[16 * 4] = { - 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, - 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, - 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, - 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, - 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, - 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, + 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, + 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, + 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, + 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, + 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF, 0x3F, }; -int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t *pg_le, uint8_t *pg_v210, - uint32_t w, uint32_t h) { - __m512i permute_mask = - _mm512_loadu_si512((__m512i *)le10_to_v210_permute_tbl_512); +int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, + uint32_t h) { + __m512i permute_mask = _mm512_loadu_si512((__m512i *)le10_to_v210_permute_tbl_512); __m512i multishift_mask = _mm512_loadu_si512((__m512i *)le10_to_v210_multishift_tbl_512); - __m512i padding_mask = - _mm512_loadu_si512((__m512i *)le10_to_v210_and_tbl_512); + __m512i padding_mask = _mm512_loadu_si512((__m512i *)le10_to_v210_and_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, + pg_cnt); return -EINVAL; } @@ -863,18 +782,14 @@ int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t *pg_le, uint8_t *pg_v210, /* begin st20_rfc4175_422be10_to_v210_avx512_vbmi */ static uint8_t be10_to_v210_permute0_tbl_512[16 * 4] = { - 1, 0, 3, 2, 4, 3, - 7, 6, 8, 7, 11, 10, - 12, 11, 14, 13, /* pg 0-2 */ - 1 + 15, 0 + 15, 3 + 15, 2 + 15, 4 + 15, 3 + 15, - 7 + 15, 6 + 15, 8 + 15, 7 + 15, 11 + 15, 10 + 15, - 12 + 15, 11 + 15, 14 + 15, 13 + 15, /* pg 3-5 */ - 1 + 30, 0 + 30, 3 + 30, 2 + 30, 4 + 30, 3 + 30, - 7 + 30, 6 + 30, 8 + 30, 7 + 30, 11 + 30, 10 + 30, - 12 + 30, 11 + 30, 14 + 30, 13 + 30, /* pg 6-8 */ - 1 + 45, 0 + 45, 3 + 45, 2 + 45, 4 + 45, 3 + 45, - 7 + 45, 6 + 45, 8 + 45, 7 + 45, 11 + 45, 10 + 45, - 12 + 45, 11 + 45, 14 + 45, 13 + 45, /* pg 9-11 */ + 1, 0, 3, 2, 4, 3, 7, 6, + 8, 7, 11, 10, 12, 11, 14, 13, /* pg 0-2 */ + 1 + 15, 0 + 15, 3 + 15, 2 + 15, 4 + 15, 3 + 15, 7 + 15, 6 + 15, + 8 + 15, 7 + 15, 11 + 15, 10 + 15, 12 + 15, 11 + 15, 14 + 15, 13 + 15, /* pg 3-5 */ + 1 + 30, 0 + 30, 3 + 30, 2 + 30, 4 + 30, 3 + 30, 7 + 30, 6 + 30, + 8 + 30, 7 + 30, 11 + 30, 10 + 30, 12 + 30, 11 + 30, 14 + 30, 13 + 30, /* pg 6-8 */ + 1 + 45, 0 + 45, 3 + 45, 2 + 45, 4 + 45, 3 + 45, 7 + 45, 6 + 45, + 8 + 45, 7 + 45, 11 + 45, 10 + 45, 12 + 45, 11 + 45, 14 + 45, 13 + 45, /* pg 9-11 */ }; static uint8_t be10_to_v210_multishift0_tbl_512[16 * 4] = { 6, 14, 14, 22, 32, 40, 48, 56, 2, 10, 18, 26, 36, 44, 44, 52, /* pg 0-2 */ @@ -883,12 +798,11 @@ static uint8_t be10_to_v210_multishift0_tbl_512[16 * 4] = { 6, 14, 14, 22, 32, 40, 48, 56, 2, 10, 18, 26, 36, 44, 44, 52, /* pg 9-11 */ }; static uint8_t be10_to_v210_and0_tbl_512[16 * 4] = { - 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, - 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, - 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, - 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, - 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, - 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, + 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, + 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, + 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, + 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, + 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, 0xFF, 0x03, 0xF0, 0x3F, }; static uint8_t be10_to_v210_permute1_tbl_512[16 * 4] = { 63, 2, 1, 63, 63, 6, 5, 63, @@ -907,24 +821,20 @@ static uint8_t be10_to_v210_multishift1_tbl_512[16 * 4] = { 0, 10, 18, 0, 0, 44, 52, 0, 0, 6, 14, 0, 0, 40, 48, 0, /* pg 9-11 */ }; static uint8_t be10_to_v210_and1_tbl_512[16 * 4] = { - 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, - 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, - 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, - 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, - 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, - 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, + 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, + 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, + 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, + 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, + 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, 0x00, 0xFC, 0x0F, 0x00, }; -int st20_rfc4175_422be10_to_v210_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, - uint32_t h) { - __m512i permute0_mask = - _mm512_loadu_si512((__m512i *)be10_to_v210_permute0_tbl_512); +int st20_rfc4175_422be10_to_v210_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h) { + __m512i permute0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_permute0_tbl_512); __m512i multishift0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_multishift0_tbl_512); __m512i and0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and0_tbl_512); - __m512i permute1_mask = - _mm512_loadu_si512((__m512i *)be10_to_v210_permute1_tbl_512); + __m512i permute1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_permute1_tbl_512); __m512i multishift1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_multishift1_tbl_512); __m512i and1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and1_tbl_512); @@ -932,8 +842,8 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi( int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, + pg_cnt); return -EINVAL; } @@ -959,16 +869,15 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi( return 0; } -int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h) { - __m512i permute0_mask = - _mm512_loadu_si512((__m512i *)be10_to_v210_permute0_tbl_512); +int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, + uint32_t w, uint32_t h) { + __m512i permute0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_permute0_tbl_512); __m512i multishift0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_multishift0_tbl_512); __m512i and0_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and0_tbl_512); - __m512i permute1_mask = - _mm512_loadu_si512((__m512i *)be10_to_v210_permute1_tbl_512); + __m512i permute1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_permute1_tbl_512); __m512i multishift1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_multishift1_tbl_512); __m512i and1_mask = _mm512_loadu_si512((__m512i *)be10_to_v210_and1_tbl_512); @@ -976,8 +885,8 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, + pg_cnt); return -EINVAL; } @@ -993,20 +902,18 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( /* two type be(0) or le(1) */ struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_v210_avx512_vbmi(pg_be, pg_v210, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -1017,8 +924,7 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -1030,8 +936,7 @@ int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *be = be_cache; @@ -1123,47 +1028,35 @@ static uint16_t ple_to_be10_sllv_tbl_512[8 * 4] = { 0, }; -static uint8_t ple_to_be10_permute_hi_tbl_512[16 * 4] = - { - 1 + (2 * 0), 0 + (2 * 0), 16 + (4 * 0), 32 + (2 * 0), - 18 + (4 * 0), /* pg0 */ - 1 + (2 * 1), 0 + (2 * 1), 16 + (4 * 1), 32 + (2 * 1), - 18 + (4 * 1), /* pg1 */ - 1 + (2 * 2), 0 + (2 * 2), 16 + (4 * 2), 32 + (2 * 2), - 18 + (4 * 2), /* pg2 */ - 1 + (2 * 3), 0 + (2 * 3), 16 + (4 * 3), 32 + (2 * 3), - 18 + (4 * 3), /* pg3 */ - 1 + (2 * 4), 0 + (2 * 4), 48 + (4 * 0), 32 + (2 * 4), - 50 + (4 * 0), /* pg4 */ - 1 + (2 * 5), 0 + (2 * 5), 48 + (4 * 1), 32 + (2 * 5), - 50 + (4 * 1), /* pg5 */ - 1 + (2 * 6), 0 + (2 * 6), 48 + (4 * 2), 32 + (2 * 6), - 50 + (4 * 2), /* pg6 */ - 1 + (2 * 7), 0 + (2 * 7), 48 + (4 * 3), 32 + (2 * 7), - 50 + (4 * 3), /* pg7 */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* 40-48 */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* 49-53 */ - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, /* 54-63 */ +static uint8_t ple_to_be10_permute_hi_tbl_512[16 * 4] = { + 1 + (2 * 0), 0 + (2 * 0), 16 + (4 * 0), 32 + (2 * 0), 18 + (4 * 0), /* pg0 */ + 1 + (2 * 1), 0 + (2 * 1), 16 + (4 * 1), 32 + (2 * 1), 18 + (4 * 1), /* pg1 */ + 1 + (2 * 2), 0 + (2 * 2), 16 + (4 * 2), 32 + (2 * 2), 18 + (4 * 2), /* pg2 */ + 1 + (2 * 3), 0 + (2 * 3), 16 + (4 * 3), 32 + (2 * 3), 18 + (4 * 3), /* pg3 */ + 1 + (2 * 4), 0 + (2 * 4), 48 + (4 * 0), 32 + (2 * 4), 50 + (4 * 0), /* pg4 */ + 1 + (2 * 5), 0 + (2 * 5), 48 + (4 * 1), 32 + (2 * 5), 50 + (4 * 1), /* pg5 */ + 1 + (2 * 6), 0 + (2 * 6), 48 + (4 * 2), 32 + (2 * 6), 50 + (4 * 2), /* pg6 */ + 1 + (2 * 7), 0 + (2 * 7), 48 + (4 * 3), 32 + (2 * 7), 50 + (4 * 3), /* pg7 */ + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, /* 40-48 */ + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, /* 49-53 */ + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, /* 54-63 */ }; static uint8_t ple_to_be10_permute_lo_tbl_512[16 * 4] = { - 0, 17 + (4 * 0), 33 + (2 * 0), 19 + (4 * 0), 0, /* pg0 */ - 0, 17 + (4 * 1), 33 + (2 * 1), 19 + (4 * 1), 0, /* pg1 */ - 0, 17 + (4 * 2), 33 + (2 * 2), 19 + (4 * 2), 0, /* pg2 */ - 0, 17 + (4 * 3), 33 + (2 * 3), 19 + (4 * 3), 0, /* pg3 */ - 0, 49 + (4 * 0), 33 + (2 * 4), 51 + (4 * 0), 0, /* pg4 */ - 0, 49 + (4 * 1), 33 + (2 * 5), 51 + (4 * 1), 0, /* pg5 */ - 0, 49 + (4 * 2), 33 + (2 * 6), 51 + (4 * 2), 0, /* pg6 */ - 0, 49 + (4 * 3), 33 + (2 * 7), 51 + (4 * 3), 0, /* pg7 */ - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, /* 40-48 */ - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, /* 49-53 */ - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, /* 54-63 */ + 0, 17 + (4 * 0), 33 + (2 * 0), 19 + (4 * 0), 0, /* pg0 */ + 0, 17 + (4 * 1), 33 + (2 * 1), 19 + (4 * 1), 0, /* pg1 */ + 0, 17 + (4 * 2), 33 + (2 * 2), 19 + (4 * 2), 0, /* pg2 */ + 0, 17 + (4 * 3), 33 + (2 * 3), 19 + (4 * 3), 0, /* pg3 */ + 0, 49 + (4 * 0), 33 + (2 * 4), 51 + (4 * 0), 0, /* pg4 */ + 0, 49 + (4 * 1), 33 + (2 * 5), 51 + (4 * 1), 0, /* pg5 */ + 0, 49 + (4 * 2), 33 + (2 * 6), 51 + (4 * 2), 0, /* pg6 */ + 0, 49 + (4 * 3), 33 + (2 * 7), 51 + (4 * 3), 0, /* pg7 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40-48 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 49-53 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 54-63 */ }; static uint8_t ple_to_be10_and_lo_tbl_512[16 * 4] = { @@ -1180,9 +1073,9 @@ static uint8_t ple_to_be10_and_lo_tbl_512[16 * 4] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 54-63 */ }; -int st20_yuv422p10le_to_rfc4175_422be10_vbmi( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { +int st20_yuv422p10le_to_rfc4175_422be10_vbmi(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h) { uint32_t pg_cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; __m512i sllv_le_mask = _mm512_loadu_si512(ple_to_be10_sllv_tbl_512); @@ -1212,10 +1105,8 @@ int st20_yuv422p10le_to_rfc4175_422be10_vbmi( /* b0, r0, y0, y1, b1, r1, y2, y3 */ __m512i srlv_le_result = _mm512_sllv_epi16(src, sllv_le_mask); - __m512i permute_hi_result = - _mm512_permutexvar_epi8(permute_hi_mask, srlv_le_result); - __m512i permute_lo_result = - _mm512_permutexvar_epi8(permute_lo_mask, srlv_le_result); + __m512i permute_hi_result = _mm512_permutexvar_epi8(permute_hi_mask, srlv_le_result); + __m512i permute_lo_result = _mm512_permutexvar_epi8(permute_lo_mask, srlv_le_result); permute_lo_result = _mm512_and_si512(permute_lo_result, and_lo_mask); __m512i result = _mm512_or_si512(permute_hi_result, permute_lo_result); _mm512_mask_storeu_epi8(pg, k, result); @@ -1383,19 +1274,15 @@ static uint8_t le10_to_be_permute_r1_tbl_512[64] = { 0x3F, 0x3F, 0x3F, 0x3F, /* zeros */ }; -int st20_rfc4175_422le10_to_422be10_vbmi( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { - __m512i permute_l0 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_l0_tbl_512); - __m512i permute_r0 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_r0_tbl_512); +int st20_rfc4175_422le10_to_422be10_vbmi(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { + __m512i permute_l0 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_l0_tbl_512); + __m512i permute_r0 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_r0_tbl_512); __m512i and_l0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_l0_tbl_512); __m512i and_r0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_r0_tbl_512); - __m512i permute_l1 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_l1_tbl_512); - __m512i permute_r1 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_r1_tbl_512); + __m512i permute_l1 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_l1_tbl_512); + __m512i permute_r1 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; @@ -1405,10 +1292,8 @@ int st20_rfc4175_422le10_to_422be10_vbmi( __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_le); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = - _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = - _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); @@ -1450,16 +1335,12 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { - __m512i permute_l0 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_l0_tbl_512); - __m512i permute_r0 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_r0_tbl_512); + __m512i permute_l0 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_l0_tbl_512); + __m512i permute_r0 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_r0_tbl_512); __m512i and_l0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_l0_tbl_512); __m512i and_r0 = _mm512_loadu_si512((__m512i *)le10_to_be_and_r0_tbl_512); - __m512i permute_l1 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_l1_tbl_512); - __m512i permute_r1 = - _mm512_loadu_si512((__m512i *)le10_to_be_permute_r1_tbl_512); + __m512i permute_l1 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_l1_tbl_512); + __m512i permute_r1 = _mm512_loadu_si512((__m512i *)le10_to_be_permute_r1_tbl_512); __mmask16 k = 0x7FFF; /* each __m512i with 12 pg group, 60 bytes */ int pg_cnt = w * h / 2; @@ -1475,20 +1356,18 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( /* two type be(0) or le(1) */ struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!le_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, le_caches); - if (le_caches) - mt_rte_free(le_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + le_caches); + if (le_caches) mt_rte_free(le_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_rfc4175_422be10_to_422le10_avx512_vbmi(pg_be, pg_le, w, h); } rte_iova_t le_caches_iova = rte_malloc_virt2iova(le_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_le *le_cache = le_caches + (i % caches_num) * cache_pg_cnt; @@ -1499,8 +1378,7 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - le_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = le_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_le_iova, cache_size); pg_le += cache_pg_cnt; pg_le_iova += cache_size; @@ -1512,8 +1390,7 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_le *le = le_cache; @@ -1526,10 +1403,8 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); - __m512i rl_result_shuffle = - _mm512_permutexvar_epi8(permute_l1, rl_result); - __m512i rr_result_shuffle = - _mm512_permutexvar_epi8(permute_r1, rr_result); + __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); + __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); /* store to the first 60 bytes after dest address */ @@ -1550,10 +1425,8 @@ int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( __m512i input = _mm512_maskz_loadu_epi32(k, (__m512i *)pg_le); __m512i permute_l0_result = _mm512_permutexvar_epi8(permute_l0, input); __m512i permute_r0_result = _mm512_permutexvar_epi8(permute_r0, input); - __m512i rl_result = - _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); - __m512i rr_result = - _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); + __m512i rl_result = _mm512_and_si512(_mm512_rol_epi32(permute_l0_result, 2), and_l0); + __m512i rr_result = _mm512_and_si512(_mm512_ror_epi32(permute_r0_result, 2), and_r0); __m512i rl_result_shuffle = _mm512_permutexvar_epi8(permute_l1, rl_result); __m512i rr_result_shuffle = _mm512_permutexvar_epi8(permute_r1, rr_result); __m512i result = _mm512_or_si512(rl_result_shuffle, rr_result_shuffle); @@ -1670,13 +1543,12 @@ static uint8_t v210_to_be10_and_tbl_512[16 * 4] = { 0x00, /* not used */ }; -int st20_v210_to_rfc4175_422be10_avx512_vbmi( - uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h) { +int st20_v210_to_rfc4175_422be10_avx512_vbmi(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { __m512i multishift0_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_multishift0_tbl_512); - __m512i shuffle_mask = - _mm512_loadu_si512((__m512i *)v210_to_be10_shuffle_tbl_512); + __m512i shuffle_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_shuffle_tbl_512); __m512i multishift1_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_multishift1_tbl_512); __m512i and_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_and_tbl_512); @@ -1686,16 +1558,15 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi( int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, + pg_cnt); return -EINVAL; } int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { __m512i input = _mm512_loadu_si512((__m512i *)pg_v210); - __m512i multishift0_result = - _mm512_multishift_epi64_epi8(multishift0_mask, input); + __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, input); __m512i shuffle_result = _mm512_shuffle_epi8(input, shuffle_mask); __m512i multishift1_result = _mm512_multishift_epi64_epi8(multishift1_mask, shuffle_result); @@ -1712,13 +1583,14 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi( return 0; } -int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( - struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { +int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev *dma, + uint8_t *pg_v210, + mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { __m512i multishift0_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_multishift0_tbl_512); - __m512i shuffle_mask = - _mm512_loadu_si512((__m512i *)v210_to_be10_shuffle_tbl_512); + __m512i shuffle_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_shuffle_tbl_512); __m512i multishift1_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_multishift1_tbl_512); __m512i and_mask = _mm512_loadu_si512((__m512i *)v210_to_be10_and_tbl_512); @@ -1728,14 +1600,14 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( int pg_cnt = w * h / 2; if (pg_cnt % 12 != 0) { - err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", - __func__, pg_cnt); + err("%s, invalid pg_cnt %d, pixel group number must be multiple of 12!\n", __func__, + pg_cnt); return -EINVAL; } int caches_num = 4; int cache_3_pg_cnt = (256 * 1024) / 16; /* 3pg cnt for each cache */ - int align = caches_num * 4; /* align to simd pg groups and caches_num */ + int align = caches_num * 4; /* align to simd pg groups and caches_num */ cache_3_pg_cnt = cache_3_pg_cnt / align * align; size_t cache_size = cache_3_pg_cnt * 16; int soc_id = dma->parent->soc_id; @@ -1746,21 +1618,18 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( if (!v210_caches || !ctx) { err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_3_pg_cnt, cache_size, v210_caches); - if (v210_caches) - mt_rte_free(v210_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); + if (v210_caches) mt_rte_free(v210_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); return st20_v210_to_rfc4175_422be10_avx512_vbmi(pg_v210, pg_be, w, h); } rte_iova_t v210_caches_iova = rte_malloc_virt2iova(v210_caches); /* first with caches batch step */ int cache_batch = pg_cnt / (cache_3_pg_cnt * 3); - dbg("%s, pg_cnt %d cache_3_pg_cnt %d caches_num %d cache_batch %d\n", - __func__, pg_cnt, cache_3_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_3_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_3_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { - uint8_t *v210_cache = - v210_caches + (i % caches_num) * (cache_3_pg_cnt * 16); + uint8_t *v210_cache = v210_caches + (i % caches_num) * (cache_3_pg_cnt * 16); dbg("%s, cache batch idx %d\n", __func__, i); int max_tran = i + caches_num; @@ -1781,16 +1650,14 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } uint8_t *v210 = v210_cache; int batch = cache_3_pg_cnt / 4; for (int j = 0; j < batch; j++) { __m512i input = _mm512_loadu_si512((__m512i *)v210); - __m512i multishift0_result = - _mm512_multishift_epi64_epi8(multishift0_mask, input); + __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, input); __m512i shuffle_result = _mm512_shuffle_epi8(input, shuffle_mask); __m512i multishift1_result = _mm512_multishift_epi64_epi8(multishift1_mask, shuffle_result); @@ -1813,8 +1680,7 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( int batch = pg_cnt / 12; for (int i = 0; i < batch; i++) { __m512i input = _mm512_loadu_si512((__m512i *)pg_v210); - __m512i multishift0_result = - _mm512_multishift_epi64_epi8(multishift0_mask, input); + __m512i multishift0_result = _mm512_multishift_epi64_epi8(multishift0_mask, input); __m512i shuffle_result = _mm512_shuffle_epi8(input, shuffle_mask); __m512i multishift1_result = _mm512_multishift_epi64_epi8(multishift1_mask, shuffle_result); @@ -1832,8 +1698,7 @@ int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( } /* end st20_v210_to_rfc4175_422be10_avx512_vbmi */ -int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t *pg_old, - uint8_t *pg_new, +int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t *pg_old, uint8_t *pg_new, uint32_t w, uint32_t h, uint32_t linesize_old, uint32_t linesize_new) { @@ -1867,22 +1732,14 @@ int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t *pg_old, /* begin st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi */ static uint8_t be12_to_ple_permute_tbl_512[16 * 4] = { - 1, 0, 1 + 6, 0 + 6, - 1 + 12, 0 + 12, 1 + 18, 0 + 18, /* b0, b1, b2, b3 */ - 1 + 24, 0 + 24, 1 + 30, 0 + 30, - 1 + 36, 0 + 36, 1 + 42, 0 + 42, /* b4, b5, b6, b7 */ - 4, 3, 4 + 6, 3 + 6, - 4 + 12, 3 + 12, 4 + 18, 3 + 18, /* r0, r1, r2, r3 */ - 4 + 24, 3 + 24, 4 + 30, 3 + 30, - 4 + 36, 3 + 36, 4 + 42, 3 + 42, /* r4, r5, r6, r7 */ - 2, 1, 5, 4, - 2 + 6, 1 + 6, 5 + 6, 4 + 6, /* y0 - y3 */ - 2 + 12, 1 + 12, 5 + 12, 4 + 12, - 2 + 18, 1 + 18, 5 + 18, 4 + 18, /* y4 - y7 */ - 2 + 24, 1 + 24, 5 + 24, 4 + 24, - 2 + 30, 1 + 30, 5 + 30, 4 + 30, /* y8 - y11 */ - 2 + 36, 1 + 36, 5 + 36, 4 + 36, - 2 + 42, 1 + 42, 5 + 42, 4 + 42, /* y12 - y15 */ + 1, 0, 1 + 6, 0 + 6, 1 + 12, 0 + 12, 1 + 18, 0 + 18, /* b0, b1, b2, b3 */ + 1 + 24, 0 + 24, 1 + 30, 0 + 30, 1 + 36, 0 + 36, 1 + 42, 0 + 42, /* b4, b5, b6, b7 */ + 4, 3, 4 + 6, 3 + 6, 4 + 12, 3 + 12, 4 + 18, 3 + 18, /* r0, r1, r2, r3 */ + 4 + 24, 3 + 24, 4 + 30, 3 + 30, 4 + 36, 3 + 36, 4 + 42, 3 + 42, /* r4, r5, r6, r7 */ + 2, 1, 5, 4, 2 + 6, 1 + 6, 5 + 6, 4 + 6, /* y0 - y3 */ + 2 + 12, 1 + 12, 5 + 12, 4 + 12, 2 + 18, 1 + 18, 5 + 18, 4 + 18, /* y4 - y7 */ + 2 + 24, 1 + 24, 5 + 24, 4 + 24, 2 + 30, 1 + 30, 5 + 30, 4 + 30, /* y8 - y11 */ + 2 + 36, 1 + 36, 5 + 36, 4 + 36, 2 + 42, 1 + 42, 5 + 42, 4 + 42, /* y12 - y15 */ }; static uint16_t be12_to_ple_srlv_tbl_512[8 * 4] = { @@ -1893,19 +1750,15 @@ static uint16_t be12_to_ple_srlv_tbl_512[8 * 4] = { }; static uint16_t be12_to_ple_and_tbl_512[8 * 4] = { - 0x0fff, 0x0fff, 0x0fff, 0x0fff, - 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* b0 - b7 */ - 0x0fff, 0x0fff, 0x0fff, 0x0fff, - 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* r0 - r7 */ - 0x0fff, 0x0fff, 0x0fff, 0x0fff, - 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y0 - y7 */ - 0x0fff, 0x0fff, 0x0fff, 0x0fff, - 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y8 - y15 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* b0 - b7 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* r0 - r7 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y0 - y7 */ + 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, /* y8 - y15 */ }; -int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi( - struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h) { +int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { __m512i permute_le_mask = _mm512_loadu_si512(be12_to_ple_permute_tbl_512); __m512i srlv_le_mask = _mm512_loadu_si512(be12_to_ple_srlv_tbl_512); __m512i srlv_and_mask = _mm512_loadu_si512(be12_to_ple_and_tbl_512); @@ -1974,21 +1827,18 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( mt_rte_zmalloc_socket(cache_size * caches_num, soc_id); struct mt_cvt_dma_ctx *ctx = mt_cvt_dma_ctx_init(2 * caches_num, soc_id, 2); if (!be_caches || !ctx) { - err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, - cache_size, be_caches); - if (be_caches) - mt_rte_free(be_caches); - if (ctx) - mt_cvt_dma_ctx_uinit(ctx); - return st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(pg_be, y, b, r, w, - h); + err("%s, alloc cache(%d,%" PRIu64 ") fail, %p\n", __func__, cache_pg_cnt, cache_size, + be_caches); + if (be_caches) mt_rte_free(be_caches); + if (ctx) mt_cvt_dma_ctx_uinit(ctx); + return st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(pg_be, y, b, r, w, h); } rte_iova_t be_caches_iova = rte_malloc_virt2iova(be_caches); /* first with caches batch step */ int cache_batch = pg_cnt / cache_pg_cnt; - dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, - pg_cnt, cache_pg_cnt, caches_num, cache_batch); + dbg("%s, pg_cnt %d cache_pg_cnt %d caches_num %d cache_batch %d\n", __func__, pg_cnt, + cache_pg_cnt, caches_num, cache_batch); for (int i = 0; i < cache_batch; i++) { struct st20_rfc4175_422_10_pg2_be *be_cache = be_caches + (i % caches_num) * cache_pg_cnt; @@ -1999,8 +1849,7 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( int cur_tran = mt_cvt_dma_ctx_get_tran(ctx, 0); /* push max be dma */ while (cur_tran < max_tran) { - rte_iova_t be_cache_iova = - be_caches_iova + (cur_tran % caches_num) * cache_size; + rte_iova_t be_cache_iova = be_caches_iova + (cur_tran % caches_num) * cache_size; mt_dma_copy_busy(dma, be_cache_iova, pg_be_iova, cache_size); pg_be += cache_pg_cnt; pg_be_iova += cache_size; @@ -2012,18 +1861,15 @@ int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( /* wait until current be dma copy done */ while (mt_cvt_dma_ctx_get_done(ctx, 0) < (i + 1)) { uint16_t nb_dq = mt_dma_completed(dma, 1, NULL, NULL); - if (nb_dq) - mt_cvt_dma_ctx_pop(ctx); + if (nb_dq) mt_cvt_dma_ctx_pop(ctx); } struct st20_rfc4175_422_10_pg2_be *pg = be_cache; int batch = cache_pg_cnt / 8; for (int j = 0; j < batch; j++) { __m512i input = _mm512_maskz_loadu_epi8(k, pg); - __m512i permute_le_result = - _mm512_permutexvar_epi8(permute_le_mask, input); - __m512i srlv_le_result = - _mm512_srlv_epi16(permute_le_result, srlv_le_mask); + __m512i permute_le_result = _mm512_permutexvar_epi8(permute_le_mask, input); + __m512i srlv_le_result = _mm512_srlv_epi16(permute_le_result, srlv_le_mask); __m512i stage_m512i = _mm512_and_si512(srlv_le_result, srlv_and_mask); pg += 8; diff --git a/lib/src/st2110/st_avx512_vbmi.h b/lib/src/st2110/st_avx512_vbmi.h index 5cdad5435..9309c0177 100644 --- a/lib/src/st2110/st_avx512_vbmi.h +++ b/lib/src/st2110/st_avx512_vbmi.h @@ -7,29 +7,28 @@ #include "st_main.h" -int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le10_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le10_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_422le8_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_422le8_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h); int st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_10, mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h); -int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t *pg_le, uint8_t *pg_v210, - uint32_t w, uint32_t h); +int st20_rfc4175_422le10_to_v210_avx512_vbmi(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, + uint32_t h); -int st20_rfc4175_422be10_to_v210_avx512_vbmi( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210, uint32_t w, - uint32_t h); +int st20_rfc4175_422be10_to_v210_avx512_vbmi(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210, uint32_t w, uint32_t h); int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, @@ -38,45 +37,45 @@ int st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( int st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h); + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h); -int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma( - struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h); +int st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(struct mtl_dma_lender_dev *dma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, + uint32_t w, uint32_t h); -int st20_yuv422p10le_to_rfc4175_422be10_vbmi( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h); +int st20_yuv422p10le_to_rfc4175_422be10_vbmi(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h); -int st20_rfc4175_422le10_to_422be10_vbmi( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); +int st20_rfc4175_422le10_to_422be10_vbmi(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); int st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_10_pg2_le *pg_le, mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); -int st20_v210_to_rfc4175_422be10_avx512_vbmi( - uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h); +int st20_v210_to_rfc4175_422be10_avx512_vbmi(uint8_t *pg_v210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); -int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( - struct mtl_dma_lender_dev *dma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h); +int st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(struct mtl_dma_lender_dev *dma, + uint8_t *pg_v210, + mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h); -int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi( - struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h); +int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h); int st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi_dma( struct mtl_dma_lender_dev *dma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h); + mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, uint32_t h); -int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t *pg_old, - uint8_t *pg_new, +int st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi(uint8_t *pg_old, uint8_t *pg_new, uint32_t w, uint32_t h, uint32_t linesize_old, uint32_t linesize_new); diff --git a/lib/src/st2110/st_convert.c b/lib/src/st2110/st_convert.c index 73944f535..0eb6943f1 100644 --- a/lib/src/st2110/st_convert.c +++ b/lib/src/st2110/st_convert.c @@ -24,15 +24,13 @@ static bool has_lines_padding(struct st_frame *src, struct st_frame *dst) { planes = st_frame_fmt_planes(src->fmt); for (int plane = 0; plane < planes; plane++) { - if (src->linesize[plane] > - st_frame_least_linesize(src->fmt, src->width, plane)) + if (src->linesize[plane] > st_frame_least_linesize(src->fmt, src->width, plane)) return true; } planes = st_frame_fmt_planes(dst->fmt); for (int plane = 0; plane < planes; plane++) { - if (dst->linesize[plane] > - st_frame_least_linesize(dst->fmt, dst->width, plane)) + if (dst->linesize[plane] > st_frame_least_linesize(dst->fmt, dst->width, plane)) return true; } @@ -66,8 +64,7 @@ static int convert_rfc4175_422be10_to_yuv422p10le(struct st_frame *src, return ret; } -static int convert_rfc4175_422be10_to_422le8(struct st_frame *src, - struct st_frame *dst) { +static int convert_rfc4175_422be10_to_422le8(struct st_frame *src, struct st_frame *dst) { int ret = 0; struct st20_rfc4175_422_10_pg2_be *be10 = NULL; struct st20_rfc4175_422_8_pg2_le *le8 = NULL; @@ -141,8 +138,7 @@ static int convert_rfc4175_422be10_to_yuv420p8(struct st_frame *src, return ret; } -static int convert_rfc4175_422be10_to_v210(struct st_frame *src, - struct st_frame *dst) { +static int convert_rfc4175_422be10_to_v210(struct st_frame *src, struct st_frame *dst) { int ret = 0; struct st20_rfc4175_422_10_pg2_be *be10 = NULL; uint8_t *v210 = NULL; @@ -162,8 +158,7 @@ static int convert_rfc4175_422be10_to_v210(struct st_frame *src, return ret; } -static int convert_rfc4175_422be10_to_y210(struct st_frame *src, - struct st_frame *dst) { +static int convert_rfc4175_422be10_to_y210(struct st_frame *src, struct st_frame *dst) { int ret = 0; struct st20_rfc4175_422_10_pg2_be *be10 = NULL; uint16_t *y210 = NULL; @@ -345,8 +340,7 @@ static int convert_yuv422p10le_to_rfc4175_422be10(struct st_frame *src, return ret; } -static int convert_v210_to_rfc4175_422be10(struct st_frame *src, - struct st_frame *dst) { +static int convert_v210_to_rfc4175_422be10(struct st_frame *src, struct st_frame *dst) { int ret = 0; struct st20_rfc4175_422_10_pg2_be *be10 = NULL; uint8_t *v210 = NULL; @@ -366,8 +360,7 @@ static int convert_v210_to_rfc4175_422be10(struct st_frame *src, return ret; } -static int convert_y210_to_rfc4175_422be10(struct st_frame *src, - struct st_frame *dst) { +static int convert_y210_to_rfc4175_422be10(struct st_frame *src, struct st_frame *dst) { int ret = 0; struct st20_rfc4175_422_10_pg2_be *be10 = NULL; uint16_t *y210 = NULL; @@ -634,8 +627,7 @@ int st_frame_convert(struct st_frame *src, struct st_frame *dst) { return converter.convert_func(src, dst); } -static int field_frame_check(const struct st_frame *field, - const struct st_frame *frame) { +static int field_frame_check(const struct st_frame *field, const struct st_frame *frame) { if (!field->interlaced) { err("%s, field is not field\n", __func__); return -EINVAL; @@ -646,15 +638,13 @@ static int field_frame_check(const struct st_frame *field, return -EINVAL; } if (field->fmt != frame->fmt) { - err("%s, fmt mismatch, field: %d, frame: %d\n", __func__, field->fmt, - frame->fmt); + err("%s, fmt mismatch, field: %d, frame: %d\n", __func__, field->fmt, frame->fmt); return -EINVAL; } return 0; } -static int fields_frame_match(const struct st_frame *first, - const struct st_frame *second, +static int fields_frame_match(const struct st_frame *first, const struct st_frame *second, const struct st_frame *frame) { int ret = field_frame_check(first, frame); if (ret < 0) { @@ -680,14 +670,12 @@ static int fields_frame_match(const struct st_frame *first, int st_field_merge(const struct st_frame *first, const struct st_frame *second, struct st_frame *frame) { int ret = fields_frame_match(first, second, frame); - if (ret < 0) - return ret; + if (ret < 0) return ret; uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint32_t line = 0; line < frame->height; line += 2) { for (uint8_t plane = 0; plane < planes; plane++) { - size_t linesize = - st_frame_least_linesize(frame->fmt, frame->width, plane); + size_t linesize = st_frame_least_linesize(frame->fmt, frame->width, plane); uint32_t field_line = line / 2; /* first line */ void *f_addr = frame->addr[plane] + frame->linesize[plane] * line; @@ -707,14 +695,12 @@ int st_field_merge(const struct st_frame *first, const struct st_frame *second, int st_field_split(const struct st_frame *frame, struct st_frame *first, struct st_frame *second) { int ret = fields_frame_match(first, second, frame); - if (ret < 0) - return ret; + if (ret < 0) return ret; uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint32_t line = 0; line < frame->height; line += 2) { for (uint8_t plane = 0; plane < planes; plane++) { - size_t linesize = - st_frame_least_linesize(frame->fmt, frame->width, plane); + size_t linesize = st_frame_least_linesize(frame->fmt, frame->width, plane); uint32_t field_line = line / 2; /* first line */ void *f_addr = frame->addr[plane] + frame->linesize[plane] * line; @@ -764,20 +750,20 @@ static int downsample_rfc4175_wh_half(struct st_frame *old_frame, uint8_t *dst_start = new_frame->addr[0]; /* check the idx and set src offset */ switch (idx) { - case 0: - break; - case 1: - src_start += st20_pg.size; - break; - case 2: - src_start += src_linesize; - break; - case 3: - src_start += src_linesize + st20_pg.size; - break; - default: - err("%s, wrong sample idx %d\n", __func__, idx); - return -EINVAL; + case 0: + break; + case 1: + src_start += st20_pg.size; + break; + case 2: + src_start += src_linesize; + break; + case 3: + src_start += src_linesize + st20_pg.size; + break; + default: + err("%s, wrong sample idx %d\n", __func__, idx); + return -EINVAL; } #ifdef MTL_HAS_AVX512_VBMI2 @@ -786,8 +772,7 @@ static int downsample_rfc4175_wh_half(struct st_frame *old_frame, dbg("%s, avx512_vbmi way\n", __func__); ret = st20_downsample_rfc4175_422be10_wh_half_avx512_vbmi( src_start, dst_start, width, height, src_linesize, dst_linesize); - if (ret == 0) - return 0; + if (ret == 0) return 0; err("%s, avx512_vbmi way failed %d\n", __func__, ret); } } @@ -815,15 +800,15 @@ int st_frame_downsample(struct st_frame *src, struct st_frame *dst, int idx) { } } - err("%s, downsample not supported, source: %s %ux%u, dest: %s %ux%u\n", - __func__, st_frame_fmt_name(src->fmt), src->width, src->height, - st_frame_fmt_name(dst->fmt), dst->width, dst->height); + err("%s, downsample not supported, source: %s %ux%u, dest: %s %ux%u\n", __func__, + st_frame_fmt_name(src->fmt), src->width, src->height, st_frame_fmt_name(dst->fmt), + dst->width, dst->height); return -EINVAL; } static int st20_yuv422p10le_to_rfc4175_422be10_scalar( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h) { + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -848,10 +833,10 @@ static int st20_yuv422p10le_to_rfc4175_422be10_scalar( return 0; } -int st20_yuv422p10le_to_rfc4175_422be10_simd( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_yuv422p10le_to_rfc4175_422be10_simd(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_10_pg2_be *pg, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -859,12 +844,10 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd( MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_yuv422p10le_to_rfc4175_422be10_avx512(y, b, r, pg, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; err("%s, avx512 ways failed %d\n", __func__, ret); } #endif @@ -874,10 +857,9 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd( } int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, - mtl_iova_t b_iova, uint16_t *r, mtl_iova_t r_iova, - struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, uint32_t h, - enum mtl_simd_level level) { + mtl_udma_handle udma, uint16_t *y, mtl_iova_t y_iova, uint16_t *b, mtl_iova_t b_iova, + uint16_t *r, mtl_iova_t r_iova, struct st20_rfc4175_422_10_pg2_be *pg, uint32_t w, + uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -885,13 +867,11 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_yuv422p10le_to_rfc4175_422be10_avx512_dma( - udma, y, y_iova, b, b_iova, r, r_iova, pg, w, h); - if (ret == 0) - return 0; + ret = st20_yuv422p10le_to_rfc4175_422be10_avx512_dma(udma, y, y_iova, b, b_iova, r, + r_iova, pg, w, h); + if (ret == 0) return 0; err("%s, avx512 ways failed %d\n", __func__, ret); } #endif @@ -901,8 +881,8 @@ int st20_yuv422p10le_to_rfc4175_422be10_simd_dma( } static int st20_rfc4175_422be10_to_yuv422p10le_scalar( - struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h) { + struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -922,9 +902,10 @@ static int st20_rfc4175_422be10_to_yuv422p10le_scalar( return 0; } -int st20_rfc4175_422be10_to_yuv422p10le_simd( - struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_yuv422p10le_simd(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -937,19 +918,16 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd( (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi(pg, y, b, r, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv422p10le_avx512(pg, y, b, r, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -959,10 +937,9 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd( } static int st20_rfc4175_422be10_to_yuv422p10le_scalar_2way( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, - uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, - uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, - int decimator) { + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, uint16_t *b_full, + uint16_t *r_full, uint32_t w, uint32_t h, uint16_t *y_decimated, + uint16_t *b_decimated, uint16_t *r_decimated, int decimator) { uint32_t pg_per_line = w / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; int stride = decimator - 1; @@ -994,10 +971,10 @@ static int st20_rfc4175_422be10_to_yuv422p10le_scalar_2way( } int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, - uint16_t *b_full, uint16_t *r_full, uint32_t w, uint32_t h, - uint16_t *y_decimated, uint16_t *b_decimated, uint16_t *r_decimated, - int decimator, enum mtl_simd_level level) { + struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *y_full, uint16_t *b_full, + uint16_t *r_full, uint32_t w, uint32_t h, uint16_t *y_decimated, + uint16_t *b_decimated, uint16_t *r_decimated, int decimator, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1019,15 +996,16 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_2way( } /* the last option */ - return st20_rfc4175_422be10_to_yuv422p10le_scalar_2way( - pg_be, y_full, b_full, r_full, w, h, y_decimated, b_decimated, - r_decimated, decimator); + return st20_rfc4175_422be10_to_yuv422p10le_scalar_2way(pg_be, y_full, b_full, r_full, w, + h, y_decimated, b_decimated, + r_decimated, decimator); } -int st20_rfc4175_422be10_to_yuv422p10le_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_yuv422p10le_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, + uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1038,22 +1016,19 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_dma( if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma( - udma, pg_be, pg_be_iova, y, b, r, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma(udma, pg_be, pg_be_iova, y, + b, r, w, h); + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_dma( - udma, pg_be, pg_be_iova, y, b, r, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_yuv422p10le_avx512_dma(udma, pg_be, pg_be_iova, y, b, r, + w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1063,8 +1038,8 @@ int st20_rfc4175_422be10_to_yuv422p10le_simd_dma( } int st20_yuv422p10le_to_rfc4175_422le10(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_10_pg2_le *pg, - uint32_t w, uint32_t h) { + struct st20_rfc4175_422_10_pg2_le *pg, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -1090,8 +1065,8 @@ int st20_yuv422p10le_to_rfc4175_422le10(uint16_t *y, uint16_t *b, uint16_t *r, } int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { + uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -1111,9 +1086,9 @@ int st20_rfc4175_422le10_to_yuv422p10le(struct st20_rfc4175_422_10_pg2_le *pg, return 0; } -int st20_rfc4175_422be10_to_422le10_scalar( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_422le10_scalar(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; uint16_t cb, y0, cr, y1; @@ -1139,10 +1114,10 @@ int st20_rfc4175_422be10_to_422le10_scalar( return 0; } -int st20_rfc4175_422be10_to_422le10_simd( - struct st20_rfc4175_422_10_pg2_be *pg_be, - struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_422le10_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1154,19 +1129,16 @@ int st20_rfc4175_422be10_to_422le10_simd( (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_422le10_avx512_vbmi(pg_be, pg_le, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_422le10_avx512(pg_be, pg_le, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1175,8 +1147,7 @@ int st20_rfc4175_422be10_to_422le10_simd( if ((level >= MTL_SIMD_LEVEL_AVX2) && (cpu_level >= MTL_SIMD_LEVEL_AVX2)) { dbg("%s, avx2 ways\n", __func__); ret = st20_rfc4175_422be10_to_422le10_avx2(pg_be, pg_le, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx2 ways failed\n", __func__); } #endif @@ -1185,10 +1156,12 @@ int st20_rfc4175_422be10_to_422le10_simd( return st20_rfc4175_422be10_to_422le10_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422be10_to_422le10_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_10_pg2_le *pg_le, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_422le10_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_10_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1201,22 +1174,18 @@ int st20_rfc4175_422be10_to_422le10_simd_dma( if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma( - dma, pg_be, pg_be_iova, pg_le, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_422le10_avx512_vbmi_dma(dma, pg_be, pg_be_iova, pg_le, + w, h); + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le10_avx512_dma(dma, pg_be, pg_be_iova, - pg_le, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_422le10_avx512_dma(dma, pg_be, pg_be_iova, pg_le, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1225,9 +1194,9 @@ int st20_rfc4175_422be10_to_422le10_simd_dma( return st20_rfc4175_422be10_to_422le10_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422le10_to_422be10_scalar( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h) { +int st20_rfc4175_422le10_to_422be10_scalar(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -1253,10 +1222,10 @@ int st20_rfc4175_422le10_to_422be10_scalar( return 0; } -int st20_rfc4175_422le10_to_422be10_simd( - struct st20_rfc4175_422_10_pg2_le *pg_le, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422le10_to_422be10_simd(struct st20_rfc4175_422_10_pg2_le *pg_le, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1268,19 +1237,16 @@ int st20_rfc4175_422le10_to_422be10_simd( (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422le10_to_422be10_vbmi(pg_le, pg_be, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422le10_to_422be10_avx512(pg_le, pg_be, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1289,8 +1255,7 @@ int st20_rfc4175_422le10_to_422be10_simd( if ((level >= MTL_SIMD_LEVEL_AVX2) && (cpu_level >= MTL_SIMD_LEVEL_AVX2)) { dbg("%s, avx2 ways\n", __func__); ret = st20_rfc4175_422le10_to_422be10_avx2(pg_le, pg_be, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx2 ways failed\n", __func__); } #endif @@ -1299,10 +1264,12 @@ int st20_rfc4175_422le10_to_422be10_simd( return st20_rfc4175_422le10_to_422be10_scalar(pg_le, pg_be, w, h); } -int st20_rfc4175_422le10_to_422be10_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_le *pg_le, - mtl_iova_t pg_le_iova, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422le10_to_422be10_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_le *pg_le, + mtl_iova_t pg_le_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1315,22 +1282,18 @@ int st20_rfc4175_422le10_to_422be10_simd_dma( if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma( - dma, pg_le, pg_le_iova, pg_be, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422le10_to_422be10_avx512_vbmi_dma(dma, pg_le, pg_le_iova, pg_be, + w, h); + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422le10_to_422be10_avx512_dma(dma, pg_le, pg_le_iova, - pg_be, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422le10_to_422be10_avx512_dma(dma, pg_le, pg_le_iova, pg_be, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1339,9 +1302,9 @@ int st20_rfc4175_422le10_to_422be10_simd_dma( return st20_rfc4175_422le10_to_422be10_scalar(pg_le, pg_be, w, h); } -int st20_rfc4175_422be10_to_422le8_scalar( - struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_422le8_scalar(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; for (uint32_t i = 0; i < cnt; i++) { @@ -1354,10 +1317,10 @@ int st20_rfc4175_422be10_to_422le8_scalar( return 0; } -int st20_rfc4175_422be10_to_422le8_simd( - struct st20_rfc4175_422_10_pg2_be *pg_10, - struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_422le8_simd(struct st20_rfc4175_422_10_pg2_be *pg_10, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1369,19 +1332,16 @@ int st20_rfc4175_422be10_to_422le8_simd( (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_422le8_avx512_vbmi(pg_10, pg_8, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_422le8_avx512(pg_10, pg_8, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1390,10 +1350,12 @@ int st20_rfc4175_422be10_to_422le8_simd( return st20_rfc4175_422be10_to_422le8_scalar(pg_10, pg_8, w, h); } -int st20_rfc4175_422be10_to_422le8_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_10, - mtl_iova_t pg_10_iova, struct st20_rfc4175_422_8_pg2_le *pg_8, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_422le8_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_10, + mtl_iova_t pg_10_iova, + struct st20_rfc4175_422_8_pg2_le *pg_8, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1406,22 +1368,18 @@ int st20_rfc4175_422be10_to_422le8_simd_dma( if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma(dma, pg_10, pg_10_iova, - pg_8, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_422le8_avx512_vbmi_dma(dma, pg_10, pg_10_iova, pg_8, w, + h); + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_422le8_avx512_dma(dma, pg_10, pg_10_iova, - pg_8, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_422le8_avx512_dma(dma, pg_10, pg_10_iova, pg_8, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1430,10 +1388,9 @@ int st20_rfc4175_422be10_to_422le8_simd_dma( return st20_rfc4175_422be10_to_422le8_scalar(pg_10, pg_8, w, h); } -static int -st20_rfc4175_422be10_to_yuv422p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h) { +static int st20_rfc4175_422be10_to_yuv422p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ for (uint32_t pg2 = 0; pg2 < cnt; pg2++) { @@ -1448,9 +1405,8 @@ st20_rfc4175_422be10_to_yuv422p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, } int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { + uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1459,12 +1415,10 @@ int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv422p8_avx512(pg, y, b, r, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1473,10 +1427,9 @@ int st20_rfc4175_422be10_to_yuv422p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, return st20_rfc4175_422be10_to_yuv422p8_scalar(pg, y, b, r, w, h); } -static int -st20_rfc4175_422be10_to_yuv420p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h) { +static int st20_rfc4175_422be10_to_yuv420p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, + uint8_t *y, uint8_t *b, uint8_t *r, + uint32_t w, uint32_t h) { uint32_t line_pg_cnt = w / 2; /* two pgs in one convert */ for (uint32_t i = 0; i < (h / 2); i++) { /* 2 lines each loop */ @@ -1500,9 +1453,8 @@ st20_rfc4175_422be10_to_yuv420p8_scalar(struct st20_rfc4175_422_10_pg2_be *pg, } int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, - uint8_t *y, uint8_t *b, uint8_t *r, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { + uint8_t *y, uint8_t *b, uint8_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1511,12 +1463,10 @@ int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_yuv420p8_avx512(pg, y, b, r, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1525,12 +1475,12 @@ int st20_rfc4175_422be10_to_yuv420p8_simd(struct st20_rfc4175_422_10_pg2_be *pg, return st20_rfc4175_422be10_to_yuv420p8_scalar(pg, y, b, r, w, h); } -int st20_rfc4175_422le10_to_v210_scalar(uint8_t *pg_le, uint8_t *pg_v210, - uint32_t w, uint32_t h) { +int st20_rfc4175_422le10_to_v210_scalar(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, + uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", - __func__, pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, + pg_count); return -EINVAL; } @@ -1563,9 +1513,8 @@ int st20_rfc4175_422le10_to_v210_scalar(uint8_t *pg_le, uint8_t *pg_v210, return 0; } -int st20_rfc4175_422le10_to_v210_simd(uint8_t *pg_le, uint8_t *pg_v210, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422le10_to_v210_simd(uint8_t *pg_le, uint8_t *pg_v210, uint32_t w, + uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1577,19 +1526,16 @@ int st20_rfc4175_422le10_to_v210_simd(uint8_t *pg_le, uint8_t *pg_v210, (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422le10_to_v210_avx512_vbmi(pg_le, pg_v210, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422le10_to_v210_avx512(pg_le, pg_v210, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1602,8 +1548,8 @@ int st20_v210_to_rfc4175_422le10(uint8_t *pg_v210, uint8_t *pg_le, uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", - __func__, pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, + pg_count); return -EINVAL; } @@ -1634,12 +1580,12 @@ int st20_v210_to_rfc4175_422le10(uint8_t *pg_v210, uint8_t *pg_le, uint32_t w, return 0; } -int st20_rfc4175_422be10_to_v210_scalar(uint8_t *pg_be, uint8_t *pg_v210, - uint32_t w, uint32_t h) { +int st20_rfc4175_422be10_to_v210_scalar(uint8_t *pg_be, uint8_t *pg_v210, uint32_t w, + uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", - __func__, pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, + pg_count); return -EINVAL; } @@ -1649,15 +1595,13 @@ int st20_rfc4175_422be10_to_v210_scalar(uint8_t *pg_be, uint8_t *pg_v210, int k = i * 16; pg_v210[k] = pg_be[j] << 2 | pg_be[j + 1] >> 6; - pg_v210[k + 1] = - pg_be[j] >> 6 | pg_be[j + 1] << 6 | ((pg_be[j + 2] >> 2) & 0x3C); - pg_v210[k + 2] = - ((pg_be[j + 1] >> 2) & 0x0F) | ((pg_be[j + 3] << 2) & 0xF0); + pg_v210[k + 1] = pg_be[j] >> 6 | pg_be[j + 1] << 6 | ((pg_be[j + 2] >> 2) & 0x3C); + pg_v210[k + 2] = ((pg_be[j + 1] >> 2) & 0x0F) | ((pg_be[j + 3] << 2) & 0xF0); pg_v210[k + 3] = (pg_be[j + 2] << 2 | pg_be[j + 3] >> 6) & 0x3F; pg_v210[k + 4] = pg_be[j + 4]; - pg_v210[k + 5] = (pg_be[j + 5] << 4) | ((pg_be[j + 6] >> 4) & 0x0C) | - (pg_be[j + 3] & 0x03); + pg_v210[k + 5] = + (pg_be[j + 5] << 4) | ((pg_be[j + 6] >> 4) & 0x0C) | (pg_be[j + 3] & 0x03); pg_v210[k + 6] = (pg_be[j + 5] >> 4) | (pg_be[j + 7] & 0xF0); pg_v210[k + 7] = (pg_be[j + 6]) & 0x3F; @@ -1690,19 +1634,16 @@ int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be10_to_v210_avx512_vbmi(pg_be, pg_v210, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_v210_avx512(pg_be, pg_v210, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1711,11 +1652,9 @@ int st20_rfc4175_422be10_to_v210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, return st20_rfc4175_422be10_to_v210_scalar((uint8_t *)pg_be, pg_v210, w, h); } -int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t *pg_be, - uint8_t *pg_v210_full, uint32_t w, - uint32_t h, - uint8_t *pg_v210_decimated, - int decimator) { +int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t *pg_be, uint8_t *pg_v210_full, + uint32_t w, uint32_t h, + uint8_t *pg_v210_decimated, int decimator) { uint32_t line_pg_count = w / 2; uint32_t line_batch = line_pg_count / 3; @@ -1723,21 +1662,19 @@ int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t *pg_be, for (uint32_t line = 0; line < h; line++) { for (uint32_t i = 0; i < line_batch; i++) { pg_v210_full[0] = pg_be[0] << 2 | pg_be[1] >> 6; - pg_v210_full[1] = - pg_be[0] >> 6 | pg_be[1] << 6 | ((pg_be[2] >> 2) & 0x3C); + pg_v210_full[1] = pg_be[0] >> 6 | pg_be[1] << 6 | ((pg_be[2] >> 2) & 0x3C); pg_v210_full[2] = ((pg_be[1] >> 2) & 0x0F) | ((pg_be[3] << 2) & 0xF0); pg_v210_full[3] = (pg_be[2] << 2 | pg_be[3] >> 6) & 0x3F; pg_v210_full[4] = pg_be[4]; - pg_v210_full[5] = - (pg_be[5] << 4) | ((pg_be[6] >> 4) & 0x0C) | (pg_be[3] & 0x03); + pg_v210_full[5] = (pg_be[5] << 4) | ((pg_be[6] >> 4) & 0x0C) | (pg_be[3] & 0x03); pg_v210_full[6] = (pg_be[5] >> 4) | (pg_be[7] & 0xF0); pg_v210_full[7] = (pg_be[6]) & 0x3F; pg_v210_full[8] = (pg_be[7] << 6) | (pg_be[8] >> 2); pg_v210_full[9] = ((pg_be[7] >> 2) & 0x03) | (pg_be[9] << 2); - pg_v210_full[10] = ((pg_be[8] << 2) & 0x0C) | (pg_be[9] >> 6) | - (pg_be[10] << 6) | ((pg_be[11] >> 2) & 0x30); + pg_v210_full[10] = ((pg_be[8] << 2) & 0x0C) | (pg_be[9] >> 6) | (pg_be[10] << 6) | + ((pg_be[11] >> 2) & 0x30); pg_v210_full[11] = (pg_be[10] >> 2); pg_v210_full[12] = (pg_be[12] >> 4) | (pg_be[11] << 4); @@ -1760,10 +1697,10 @@ int st20_rfc4175_422be10_to_v210_scalar_2way(uint8_t *pg_be, return 0; } -int st20_rfc4175_422be10_to_v210_simd_2way( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint8_t *pg_v210_full, uint32_t w, - uint32_t h, uint8_t *pg_v210_decimated, int decimator, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_v210_simd_2way(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint8_t *pg_v210_full, uint32_t w, uint32_t h, + uint8_t *pg_v210_decimated, int decimator, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1792,14 +1729,15 @@ int st20_rfc4175_422be10_to_v210_simd_2way( } /* the last option */ - return st20_rfc4175_422be10_to_v210_scalar_2way( - (uint8_t *)pg_be, pg_v210_full, w, h, pg_v210_decimated, decimator); + return st20_rfc4175_422be10_to_v210_scalar_2way((uint8_t *)pg_be, pg_v210_full, w, h, + pg_v210_decimated, decimator); } -int st20_rfc4175_422be10_to_v210_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint8_t *pg_v210, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_v210_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint8_t *pg_v210, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1812,22 +1750,18 @@ int st20_rfc4175_422be10_to_v210_simd_dma( if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(dma, pg_be, pg_be_iova, - pg_v210, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_v210_avx512_vbmi_dma(dma, pg_be, pg_be_iova, pg_v210, w, + h); + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_v210_avx512_dma(dma, pg_be, pg_be_iova, - pg_v210, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_v210_avx512_dma(dma, pg_be, pg_be_iova, pg_v210, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1840,8 +1774,8 @@ int st20_v210_to_rfc4175_422be10_scalar(uint8_t *v210, uint8_t *be, uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; if (pg_count % 3 != 0) { - err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", - __func__, pg_count); + err("%s, invalid pg_count %d, pixel group number must be multiple of 3!\n", __func__, + pg_count); return -EINVAL; } @@ -1851,23 +1785,20 @@ int st20_v210_to_rfc4175_422be10_scalar(uint8_t *v210, uint8_t *be, uint32_t w, int k = i * 15; be[k + 0] = (v210[j + 1] << 6) | (v210[j + 0] >> 2); - be[k + 1] = - (v210[j + 0] << 6) | ((v210[j + 2] << 2) & 0x3C) | (v210[j + 1] >> 6); + be[k + 1] = (v210[j + 0] << 6) | ((v210[j + 2] << 2) & 0x3C) | (v210[j + 1] >> 6); be[k + 2] = ((v210[j + 1] << 2) & 0xF0) | ((v210[j + 3] >> 2) & 0x0F); - be[k + 3] = - (v210[j + 5] & 0x03) | ((v210[j + 2] >> 2) & 0x3C) | (v210[j + 3] << 6); + be[k + 3] = (v210[j + 5] & 0x03) | ((v210[j + 2] >> 2) & 0x3C) | (v210[j + 3] << 6); be[k + 4] = v210[j + 4]; be[k + 5] = (v210[j + 6] << 4) | (v210[j + 5] >> 4); be[k + 6] = ((v210[j + 5] << 4) & 0xC0) | (v210[j + 7] & 0x3F); - be[k + 7] = - (v210[j + 6] & 0xF0) | ((v210[j + 9] << 2) & 0x0C) | (v210[j + 8] >> 6); + be[k + 7] = (v210[j + 6] & 0xF0) | ((v210[j + 9] << 2) & 0x0C) | (v210[j + 8] >> 6); be[k + 8] = (v210[j + 8] << 2) | ((v210[j + 10] >> 2) & 0x3); be[k + 9] = (v210[j + 10] << 6) | (v210[j + 9] >> 2); be[k + 10] = (v210[j + 11] << 2) | (v210[j + 10] >> 6); - be[k + 11] = ((v210[j + 10] << 2) & 0xC0) | ((v210[j + 13] << 4) & 0x30) | - (v210[j + 12] >> 4); + be[k + 11] = + ((v210[j + 10] << 2) & 0xC0) | ((v210[j + 13] << 4) & 0x30) | (v210[j + 12] >> 4); be[k + 12] = (v210[j + 12] << 4) | (v210[j + 14] & 0x0F); be[k + 13] = (v210[j + 13] & 0xFC) | ((v210[j + 15] >> 4) & 0x03); be[k + 14] = (v210[j + 15] << 4) | (v210[j + 14] >> 4); @@ -1878,8 +1809,7 @@ int st20_v210_to_rfc4175_422be10_scalar(uint8_t *v210, uint8_t *be, uint32_t w, int st20_v210_to_rfc4175_422be10_simd(uint8_t *pg_v210, struct st20_rfc4175_422_10_pg2_be *pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { + uint32_t w, uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1891,19 +1821,16 @@ int st20_v210_to_rfc4175_422be10_simd(uint8_t *pg_v210, (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_v210_to_rfc4175_422be10_avx512_vbmi(pg_v210, pg_be, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_v210_to_rfc4175_422be10_avx512(pg_v210, pg_be, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1912,10 +1839,11 @@ int st20_v210_to_rfc4175_422be10_simd(uint8_t *pg_v210, return st20_v210_to_rfc4175_422be10_scalar(pg_v210, (uint8_t *)pg_be, w, h); } -int st20_v210_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint8_t *pg_v210, mtl_iova_t pg_v210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_v210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint8_t *pg_v210, + mtl_iova_t pg_v210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -1926,22 +1854,19 @@ int st20_v210_to_rfc4175_422be10_simd_dma( if ((level >= MTL_SIMD_LEVEL_AVX512_VBMI2) && (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); - ret = st20_v210_to_rfc4175_422be10_avx512_vbmi_dma( - udma, pg_v210, pg_v210_iova, pg_be, w, h); - if (ret == 0) - return 0; + ret = st20_v210_to_rfc4175_422be10_avx512_vbmi_dma(udma, pg_v210, pg_v210_iova, pg_be, + w, h); + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_v210_to_rfc4175_422be10_avx512_dma(udma, pg_v210, pg_v210_iova, - pg_be, w, h); - if (ret == 0) - return 0; + ret = + st20_v210_to_rfc4175_422be10_avx512_dma(udma, pg_v210, pg_v210_iova, pg_be, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1950,9 +1875,8 @@ int st20_v210_to_rfc4175_422be10_simd_dma( return st20_v210_to_rfc4175_422be10_scalar(pg_v210, (uint8_t *)pg_be, w, h); } -int st20_rfc4175_422be10_to_y210_scalar( - struct st20_rfc4175_422_10_pg2_be *pg_be, uint16_t *pg_y210, uint32_t w, - uint32_t h) { +int st20_rfc4175_422be10_to_y210_scalar(struct st20_rfc4175_422_10_pg2_be *pg_be, + uint16_t *pg_y210, uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; for (uint32_t i = 0; i < pg_count; i++) { @@ -1977,12 +1901,10 @@ int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be10_to_y210_avx512(pg_be, pg_y210, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -1991,10 +1913,11 @@ int st20_rfc4175_422be10_to_y210_simd(struct st20_rfc4175_422_10_pg2_be *pg_be, return st20_rfc4175_422be10_to_y210_scalar(pg_be, pg_y210, w, h); } -int st20_rfc4175_422be10_to_y210_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_10_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *pg_y210, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be10_to_y210_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_10_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *pg_y210, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2004,13 +1927,10 @@ int st20_rfc4175_422be10_to_y210_simd_dma( MTL_MAY_UNUSED(dma); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be10_to_y210_avx512_dma(dma, pg_be, pg_be_iova, - pg_y210, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be10_to_y210_avx512_dma(dma, pg_be, pg_be_iova, pg_y210, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2019,9 +1939,9 @@ int st20_rfc4175_422be10_to_y210_simd_dma( return st20_rfc4175_422be10_to_y210_scalar(pg_be, pg_y210, w, h); } -int st20_y210_to_rfc4175_422be10_scalar( - uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, - uint32_t h) { +int st20_y210_to_rfc4175_422be10_scalar(uint16_t *pg_y210, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h) { uint32_t pg_count = w * h / 2; for (uint32_t i = 0; i < pg_count; i++) { @@ -2043,8 +1963,7 @@ int st20_y210_to_rfc4175_422be10_scalar( int st20_y210_to_rfc4175_422be10_simd(uint16_t *pg_y210, struct st20_rfc4175_422_10_pg2_be *pg_be, - uint32_t w, uint32_t h, - enum mtl_simd_level level) { + uint32_t w, uint32_t h, enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2052,12 +1971,10 @@ int st20_y210_to_rfc4175_422be10_simd(uint16_t *pg_y210, MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_y210_to_rfc4175_422be10_avx512(pg_y210, pg_be, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2066,10 +1983,11 @@ int st20_y210_to_rfc4175_422be10_simd(uint16_t *pg_y210, return st20_y210_to_rfc4175_422be10_scalar(pg_y210, pg_be, w, h); } -int st20_y210_to_rfc4175_422be10_simd_dma( - mtl_udma_handle udma, uint16_t *pg_y210, mtl_iova_t pg_y210_iova, - struct st20_rfc4175_422_10_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_y210_to_rfc4175_422be10_simd_dma(mtl_udma_handle udma, uint16_t *pg_y210, + mtl_iova_t pg_y210_iova, + struct st20_rfc4175_422_10_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2077,13 +1995,11 @@ int st20_y210_to_rfc4175_422be10_simd_dma( MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_y210_to_rfc4175_422be10_avx512_dma(udma, pg_y210, pg_y210_iova, - pg_be, w, h); - if (ret == 0) - return 0; + ret = + st20_y210_to_rfc4175_422be10_avx512_dma(udma, pg_y210, pg_y210_iova, pg_be, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2093,8 +2009,8 @@ int st20_y210_to_rfc4175_422be10_simd_dma( } static int st20_yuv422p12le_to_rfc4175_422be12_scalar( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_12_pg2_be *pg, uint32_t w, uint32_t h) { + uint16_t *y, uint16_t *b, uint16_t *r, struct st20_rfc4175_422_12_pg2_be *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2119,18 +2035,18 @@ static int st20_yuv422p12le_to_rfc4175_422be12_scalar( return 0; } -int st20_yuv422p12le_to_rfc4175_422be12_simd( - uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_12_pg2_be *pg, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_yuv422p12le_to_rfc4175_422be12_simd(uint16_t *y, uint16_t *b, uint16_t *r, + struct st20_rfc4175_422_12_pg2_be *pg, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_yuv422p12le_to_rfc4175_422be12_scalar(y, b, r, pg, w, h); } static int st20_rfc4175_422be12_to_yuv422p12le_scalar( - struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h) { + struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2150,9 +2066,10 @@ static int st20_rfc4175_422be12_to_yuv422p12le_scalar( return 0; } -int st20_rfc4175_422be12_to_yuv422p12le_simd( - struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *y, uint16_t *b, - uint16_t *r, uint32_t w, uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be12_to_yuv422p12le_simd(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *y, uint16_t *b, uint16_t *r, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2164,19 +2081,16 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd( (cpu_level >= MTL_SIMD_LEVEL_AVX512_VBMI2)) { dbg("%s, avx512_vbmi ways\n", __func__); ret = st20_rfc4175_422be12_to_yuv422p12le_avx512_vbmi(pg, y, b, r, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512_vbmi ways failed\n", __func__); } #endif #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be12_to_yuv422p12le_avx512(pg, y, b, r, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2185,10 +2099,11 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd( return st20_rfc4175_422be12_to_yuv422p12le_scalar(pg, y, b, r, w, h); } -int st20_rfc4175_422be12_to_yuv422p12le_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be12_to_yuv422p12le_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, uint16_t *y, + uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h, enum mtl_simd_level level) { struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2198,13 +2113,11 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd_dma( MTL_MAY_UNUSED(dma); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be12_to_yuv422p12le_avx512_dma( - udma, pg_be, pg_be_iova, y, b, r, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be12_to_yuv422p12le_avx512_dma(udma, pg_be, pg_be_iova, y, b, r, + w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2214,8 +2127,8 @@ int st20_rfc4175_422be12_to_yuv422p12le_simd_dma( } int st20_yuv422p12le_to_rfc4175_422le12(uint16_t *y, uint16_t *b, uint16_t *r, - struct st20_rfc4175_422_12_pg2_le *pg, - uint32_t w, uint32_t h) { + struct st20_rfc4175_422_12_pg2_le *pg, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2241,8 +2154,8 @@ int st20_yuv422p12le_to_rfc4175_422le12(uint16_t *y, uint16_t *b, uint16_t *r, } int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le *pg, - uint16_t *y, uint16_t *b, uint16_t *r, - uint32_t w, uint32_t h) { + uint16_t *y, uint16_t *b, uint16_t *r, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2262,9 +2175,9 @@ int st20_rfc4175_422le12_to_yuv422p12le(struct st20_rfc4175_422_12_pg2_le *pg, return 0; } -int st20_rfc4175_422be12_to_422le12_scalar( - struct st20_rfc4175_422_12_pg2_be *pg_be, - struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h) { +int st20_rfc4175_422be12_to_422le12_scalar(struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; uint16_t cb, y0, cr, y1; @@ -2290,10 +2203,10 @@ int st20_rfc4175_422be12_to_422le12_scalar( return 0; } -int st20_rfc4175_422be12_to_422le12_simd( - struct st20_rfc4175_422_12_pg2_be *pg_be, - struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422be12_to_422le12_simd(struct st20_rfc4175_422_12_pg2_be *pg_be, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2301,12 +2214,10 @@ int st20_rfc4175_422be12_to_422le12_simd( MTL_MAY_UNUSED(ret); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); ret = st20_rfc4175_422be12_to_422le12_avx512(pg_be, pg_le, w, h); - if (ret == 0) - return 0; + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2315,10 +2226,12 @@ int st20_rfc4175_422be12_to_422le12_simd( return st20_rfc4175_422be12_to_422le12_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422be12_to_422le12_simd_dma( - mtl_udma_handle udma, struct st20_rfc4175_422_12_pg2_be *pg_be, - mtl_iova_t pg_be_iova, struct st20_rfc4175_422_12_pg2_le *pg_le, uint32_t w, - uint32_t h, enum mtl_simd_level level) { +int st20_rfc4175_422be12_to_422le12_simd_dma(mtl_udma_handle udma, + struct st20_rfc4175_422_12_pg2_be *pg_be, + mtl_iova_t pg_be_iova, + struct st20_rfc4175_422_12_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { struct mtl_dma_lender_dev *dma = udma; enum mtl_simd_level cpu_level = mtl_get_simd_level(); int ret; @@ -2328,13 +2241,10 @@ int st20_rfc4175_422be12_to_422le12_simd_dma( MTL_MAY_UNUSED(dma); #ifdef MTL_HAS_AVX512 - if ((level >= MTL_SIMD_LEVEL_AVX512) && - (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { + if ((level >= MTL_SIMD_LEVEL_AVX512) && (cpu_level >= MTL_SIMD_LEVEL_AVX512)) { dbg("%s, avx512 ways\n", __func__); - ret = st20_rfc4175_422be12_to_422le12_avx512_dma(dma, pg_be, pg_be_iova, - pg_le, w, h); - if (ret == 0) - return 0; + ret = st20_rfc4175_422be12_to_422le12_avx512_dma(dma, pg_be, pg_be_iova, pg_le, w, h); + if (ret == 0) return 0; dbg("%s, avx512 ways failed\n", __func__); } #endif @@ -2343,9 +2253,9 @@ int st20_rfc4175_422be12_to_422le12_simd_dma( return st20_rfc4175_422be12_to_422le12_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_422le12_to_422be12_scalar( - struct st20_rfc4175_422_12_pg2_le *pg_le, - struct st20_rfc4175_422_12_pg2_be *pg_be, uint32_t w, uint32_t h) { +int st20_rfc4175_422le12_to_422be12_scalar(struct st20_rfc4175_422_12_pg2_le *pg_le, + struct st20_rfc4175_422_12_pg2_be *pg_be, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb, y0, cr, y1; @@ -2371,21 +2281,21 @@ int st20_rfc4175_422le12_to_422be12_scalar( return 0; } -int st20_rfc4175_422le12_to_422be12_simd( - struct st20_rfc4175_422_12_pg2_le *pg_le, - struct st20_rfc4175_422_12_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_422le12_to_422be12_simd(struct st20_rfc4175_422_12_pg2_le *pg_le, + struct st20_rfc4175_422_12_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_422le12_to_422be12_scalar(pg_le, pg_be, w, h); } -static int st20_444p10le_to_rfc4175_444be10_scalar( - uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, - struct st20_rfc4175_444_10_pg4_be *pg, uint32_t w, uint32_t h) { +static int st20_444p10le_to_rfc4175_444be10_scalar(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_be *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, - y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = *b_r++; @@ -2432,8 +2342,7 @@ static int st20_444p10le_to_rfc4175_444be10_scalar( return 0; } -int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, +int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, struct st20_rfc4175_444_10_pg4_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level) { @@ -2442,13 +2351,12 @@ int st20_444p10le_to_rfc4175_444be10_simd(uint16_t *y_g, uint16_t *b_r, return st20_444p10le_to_rfc4175_444be10_scalar(y_g, b_r, r_b, pg, w, h); } -static int -st20_rfc4175_444be10_to_444p10le_scalar(struct st20_rfc4175_444_10_pg4_be *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h) { +static int st20_rfc4175_444be10_to_444p10le_scalar(struct st20_rfc4175_444_10_pg4_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, - y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = (pg->Cb_R00 << 2) + pg->Cb_R00_; @@ -2483,21 +2391,19 @@ st20_rfc4175_444be10_to_444p10le_scalar(struct st20_rfc4175_444_10_pg4_be *pg, } int st20_rfc4175_444be10_to_444p10le_simd(struct st20_rfc4175_444_10_pg4_be *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h, + uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + uint32_t w, uint32_t h, enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be10_to_444p10le_scalar(pg, y_g, b_r, r_b, w, h); } -int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, - struct st20_rfc4175_444_10_pg4_le *pg, - uint32_t w, uint32_t h) { +int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + struct st20_rfc4175_444_10_pg4_le *pg, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, - y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = *b_r++; @@ -2544,12 +2450,11 @@ int st20_444p10le_to_rfc4175_444le10(uint16_t *y_g, uint16_t *b_r, return 0; } -int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h) { +int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, uint16_t *y_g, + uint16_t *b_r, uint16_t *r_b, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, - y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = pg->Cb_R00 + (pg->Cb_R00_ << 8); @@ -2583,12 +2488,11 @@ int st20_rfc4175_444le10_to_444p10le(struct st20_rfc4175_444_10_pg4_le *pg, return 0; } -int st20_rfc4175_444be10_to_444le10_scalar( - struct st20_rfc4175_444_10_pg4_be *pg_be, - struct st20_rfc4175_444_10_pg4_le *pg_le, uint32_t w, uint32_t h) { +int st20_rfc4175_444be10_to_444le10_scalar(struct st20_rfc4175_444_10_pg4_be *pg_be, + struct st20_rfc4175_444_10_pg4_le *pg_le, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, - y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = (pg_be->Cb_R00 << 2) + pg_be->Cb_R00_; @@ -2636,21 +2540,20 @@ int st20_rfc4175_444be10_to_444le10_scalar( return 0; } -int st20_rfc4175_444be10_to_444le10_simd( - struct st20_rfc4175_444_10_pg4_be *pg_be, - struct st20_rfc4175_444_10_pg4_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444be10_to_444le10_simd(struct st20_rfc4175_444_10_pg4_be *pg_be, + struct st20_rfc4175_444_10_pg4_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be10_to_444le10_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_444le10_to_444be10_scalar( - struct st20_rfc4175_444_10_pg4_le *pg_le, - struct st20_rfc4175_444_10_pg4_be *pg_be, uint32_t w, uint32_t h) { +int st20_rfc4175_444le10_to_444be10_scalar(struct st20_rfc4175_444_10_pg4_le *pg_le, + struct st20_rfc4175_444_10_pg4_be *pg_be, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 4; /* four pgs in one convert */ - uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, - y_g3, cr_b3; + uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1, cb_r2, y_g2, cr_b2, cb_r3, y_g3, cr_b3; for (uint32_t pg4 = 0; pg4 < cnt; pg4++) { cb_r0 = pg_le->Cb_R00 + (pg_le->Cb_R00_ << 8); @@ -2698,18 +2601,19 @@ int st20_rfc4175_444le10_to_444be10_scalar( return 0; } -int st20_rfc4175_444le10_to_444be10_simd( - struct st20_rfc4175_444_10_pg4_le *pg_le, - struct st20_rfc4175_444_10_pg4_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444le10_to_444be10_simd(struct st20_rfc4175_444_10_pg4_le *pg_le, + struct st20_rfc4175_444_10_pg4_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444le10_to_444be10_scalar(pg_le, pg_be, w, h); } -static int st20_444p12le_to_rfc4175_444be12_scalar( - uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, - struct st20_rfc4175_444_12_pg2_be *pg, uint32_t w, uint32_t h) { +static int st20_444p12le_to_rfc4175_444be12_scalar(uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_be *pg, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2740,8 +2644,7 @@ static int st20_444p12le_to_rfc4175_444be12_scalar( return 0; } -int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, +int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, struct st20_rfc4175_444_12_pg2_be *pg, uint32_t w, uint32_t h, enum mtl_simd_level level) { @@ -2750,10 +2653,10 @@ int st20_444p12le_to_rfc4175_444be12_simd(uint16_t *y_g, uint16_t *b_r, return st20_444p12le_to_rfc4175_444be12_scalar(y_g, b_r, r_b, pg, w, h); } -static int -st20_rfc4175_444be12_to_444p12le_scalar(struct st20_rfc4175_444_12_pg2_be *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h) { +static int st20_rfc4175_444be12_to_444p12le_scalar(struct st20_rfc4175_444_12_pg2_be *pg, + uint16_t *y_g, uint16_t *b_r, + uint16_t *r_b, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2778,18 +2681,17 @@ st20_rfc4175_444be12_to_444p12le_scalar(struct st20_rfc4175_444_12_pg2_be *pg, } int st20_rfc4175_444be12_to_444p12le_simd(struct st20_rfc4175_444_12_pg2_be *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h, + uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + uint32_t w, uint32_t h, enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be12_to_444p12le_scalar(pg, y_g, b_r, r_b, w, h); } -int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, - struct st20_rfc4175_444_12_pg2_le *pg, - uint32_t w, uint32_t h) { +int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, uint16_t *r_b, + struct st20_rfc4175_444_12_pg2_le *pg, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2820,9 +2722,9 @@ int st20_444p12le_to_rfc4175_444le12(uint16_t *y_g, uint16_t *b_r, return 0; } -int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, - uint16_t *y_g, uint16_t *b_r, - uint16_t *r_b, uint32_t w, uint32_t h) { +int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, uint16_t *y_g, + uint16_t *b_r, uint16_t *r_b, uint32_t w, + uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2846,9 +2748,9 @@ int st20_rfc4175_444le12_to_444p12le(struct st20_rfc4175_444_12_pg2_le *pg, return 0; } -int st20_rfc4175_444be12_to_444le12_scalar( - struct st20_rfc4175_444_12_pg2_be *pg_be, - struct st20_rfc4175_444_12_pg2_le *pg_le, uint32_t w, uint32_t h) { +int st20_rfc4175_444be12_to_444le12_scalar(struct st20_rfc4175_444_12_pg2_be *pg_be, + struct st20_rfc4175_444_12_pg2_le *pg_le, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2880,18 +2782,18 @@ int st20_rfc4175_444be12_to_444le12_scalar( return 0; } -int st20_rfc4175_444be12_to_444le12_simd( - struct st20_rfc4175_444_12_pg2_be *pg_be, - struct st20_rfc4175_444_12_pg2_le *pg_le, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444be12_to_444le12_simd(struct st20_rfc4175_444_12_pg2_be *pg_be, + struct st20_rfc4175_444_12_pg2_le *pg_le, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444be12_to_444le12_scalar(pg_be, pg_le, w, h); } -int st20_rfc4175_444le12_to_444be12_scalar( - struct st20_rfc4175_444_12_pg2_le *pg_le, - struct st20_rfc4175_444_12_pg2_be *pg_be, uint32_t w, uint32_t h) { +int st20_rfc4175_444le12_to_444be12_scalar(struct st20_rfc4175_444_12_pg2_le *pg_le, + struct st20_rfc4175_444_12_pg2_be *pg_be, + uint32_t w, uint32_t h) { uint32_t cnt = w * h / 2; /* two pgs in one convert */ uint16_t cb_r0, y_g0, cr_b0, cb_r1, y_g1, cr_b1; @@ -2923,10 +2825,10 @@ int st20_rfc4175_444le12_to_444be12_scalar( return 0; } -int st20_rfc4175_444le12_to_444be12_simd( - struct st20_rfc4175_444_12_pg2_le *pg_le, - struct st20_rfc4175_444_12_pg2_be *pg_be, uint32_t w, uint32_t h, - enum mtl_simd_level level) { +int st20_rfc4175_444le12_to_444be12_simd(struct st20_rfc4175_444_12_pg2_le *pg_le, + struct st20_rfc4175_444_12_pg2_be *pg_be, + uint32_t w, uint32_t h, + enum mtl_simd_level level) { MTL_MAY_UNUSED(level); /* the only option */ return st20_rfc4175_444le12_to_444be12_scalar(pg_le, pg_be, w, h); @@ -3001,8 +2903,7 @@ int st31_aes3_to_am824(struct st31_aes3 *sf_aes3, struct st31_am824 *sf_am824, /* copy audio data */ sf_am824->data[0] = sf_aes3->data_0 | (sf_aes3->data_1 << 4); sf_am824->data[1] = sf_aes3->data_1 >> 4; - sf_am824->data[2] = - (sf_aes3->data_2 << 4) | ((uint16_t)sf_aes3->data_1 >> 12); + sf_am824->data[2] = (sf_aes3->data_2 << 4) | ((uint16_t)sf_aes3->data_1 >> 12); sf_aes3++; sf_am824++; diff --git a/lib/src/st2110/st_fmt.c b/lib/src/st2110/st_fmt.c index 216e067df..d8e02c675 100644 --- a/lib/src/st2110/st_fmt.c +++ b/lib/src/st2110/st_fmt.c @@ -477,8 +477,7 @@ const char *st_tx_pacing_way_name(enum st21_tx_pacing_way way) { return st_pacing_way_names[way]; } -size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, - uint8_t plane) { +size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, uint8_t plane) { size_t linesize = 0; if (st_frame_fmt_planes(fmt) == 1) { @@ -488,49 +487,49 @@ size_t st_frame_least_linesize(enum st_frame_fmt fmt, uint32_t width, linesize = st_frame_size(fmt, width, 1, false); } else { switch (st_frame_fmt_get_sampling(fmt)) { - case ST_FRAME_SAMPLING_422: - switch (plane) { - case 0: - linesize = st_frame_size(fmt, width, 1, false) / 2; + case ST_FRAME_SAMPLING_422: + switch (plane) { + case 0: + linesize = st_frame_size(fmt, width, 1, false) / 2; + break; + case 1: + case 2: + linesize = st_frame_size(fmt, width, 1, false) / 4; + break; + default: + err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); + break; + } break; - case 1: - case 2: - linesize = st_frame_size(fmt, width, 1, false) / 4; + case ST_FRAME_SAMPLING_444: + switch (plane) { + case 0: + case 1: + case 2: + linesize = st_frame_size(fmt, width, 1, false) / 3; + break; + default: + err("%s, invalid plane idx %u for 444 planar fmt\n", __func__, plane); + break; + } break; - default: - err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); - break; - } - break; - case ST_FRAME_SAMPLING_444: - switch (plane) { - case 0: - case 1: - case 2: - linesize = st_frame_size(fmt, width, 1, false) / 3; - break; - default: - err("%s, invalid plane idx %u for 444 planar fmt\n", __func__, plane); - break; - } - break; - case ST_FRAME_SAMPLING_420: - switch (plane) { - case 0: - linesize = st_frame_size(fmt, width, 1, false) * 4 / 6; - break; - case 1: - case 2: - linesize = st_frame_size(fmt, width, 1, false) / 6; + case ST_FRAME_SAMPLING_420: + switch (plane) { + case 0: + linesize = st_frame_size(fmt, width, 1, false) * 4 / 6; + break; + case 1: + case 2: + linesize = st_frame_size(fmt, width, 1, false) / 6; + break; + default: + err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); + break; + } break; default: - err("%s, invalid plane idx %u for 422 planar fmt\n", __func__, plane); + err("%s, invalid sampling for fmt %d\n", __func__, fmt); break; - } - break; - default: - err("%s, invalid sampling for fmt %d\n", __func__, fmt); - break; } } @@ -543,62 +542,61 @@ size_t st_frame_size(enum st_frame_fmt fmt, uint32_t width, uint32_t height, size_t pixels = (size_t)width * height; switch (fmt) { - case ST_FRAME_FMT_YUV422PLANAR10LE: - case ST_FRAME_FMT_YUV422PLANAR12LE: - case ST_FRAME_FMT_Y210: - size = pixels * 2 * 2; /* 10/12bits in two bytes */ - break; - case ST_FRAME_FMT_V210: - if (pixels % 3) { - err("%s, invalid width %u height %u for v210 fmt, not multiple of 3\n", - __func__, width, height); - } else { - size = pixels * 8 / 3; - } - break; - case ST_FRAME_FMT_YUV422PLANAR8: - case ST_FRAME_FMT_YUV422CUSTOM8: - case ST_FRAME_FMT_UYVY: - size = pixels * 2; - break; - case ST_FRAME_FMT_YUV444PLANAR10LE: - case ST_FRAME_FMT_YUV444PLANAR12LE: - case ST_FRAME_FMT_GBRPLANAR10LE: - case ST_FRAME_FMT_GBRPLANAR12LE: - size = pixels * 2 * 3; /* 10bits in two bytes */ - break; - case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - size = st20_frame_size(ST20_FMT_YUV_422_10BIT, width, height); - break; - case ST_FRAME_FMT_YUV422RFC4175PG2BE12: - size = st20_frame_size(ST20_FMT_YUV_422_12BIT, width, height); - break; - case ST_FRAME_FMT_YUV444RFC4175PG4BE10: - case ST_FRAME_FMT_RGBRFC4175PG4BE10: - size = st20_frame_size(ST20_FMT_YUV_444_10BIT, width, height); - break; - case ST_FRAME_FMT_YUV444RFC4175PG2BE12: - case ST_FRAME_FMT_RGBRFC4175PG2BE12: - size = st20_frame_size(ST20_FMT_YUV_444_12BIT, width, height); - break; - case ST_FRAME_FMT_ARGB: - case ST_FRAME_FMT_BGRA: - size = pixels * 4; /* 8 bits ARGB pixel in a 32 bits */ - break; - case ST_FRAME_FMT_RGB8: - size = pixels * 3; /* 8 bits RGB pixel in a 24 bits */ - break; - case ST_FRAME_FMT_YUV420CUSTOM8: - case ST_FRAME_FMT_YUV420PLANAR8: - size = st20_frame_size(ST20_FMT_YUV_420_8BIT, width, height); - break; - default: - err("%s, invalid fmt %d\n", __func__, fmt); - break; + case ST_FRAME_FMT_YUV422PLANAR10LE: + case ST_FRAME_FMT_YUV422PLANAR12LE: + case ST_FRAME_FMT_Y210: + size = pixels * 2 * 2; /* 10/12bits in two bytes */ + break; + case ST_FRAME_FMT_V210: + if (pixels % 3) { + err("%s, invalid width %u height %u for v210 fmt, not multiple of 3\n", __func__, + width, height); + } else { + size = pixels * 8 / 3; + } + break; + case ST_FRAME_FMT_YUV422PLANAR8: + case ST_FRAME_FMT_YUV422CUSTOM8: + case ST_FRAME_FMT_UYVY: + size = pixels * 2; + break; + case ST_FRAME_FMT_YUV444PLANAR10LE: + case ST_FRAME_FMT_YUV444PLANAR12LE: + case ST_FRAME_FMT_GBRPLANAR10LE: + case ST_FRAME_FMT_GBRPLANAR12LE: + size = pixels * 2 * 3; /* 10bits in two bytes */ + break; + case ST_FRAME_FMT_YUV422RFC4175PG2BE10: + size = st20_frame_size(ST20_FMT_YUV_422_10BIT, width, height); + break; + case ST_FRAME_FMT_YUV422RFC4175PG2BE12: + size = st20_frame_size(ST20_FMT_YUV_422_12BIT, width, height); + break; + case ST_FRAME_FMT_YUV444RFC4175PG4BE10: + case ST_FRAME_FMT_RGBRFC4175PG4BE10: + size = st20_frame_size(ST20_FMT_YUV_444_10BIT, width, height); + break; + case ST_FRAME_FMT_YUV444RFC4175PG2BE12: + case ST_FRAME_FMT_RGBRFC4175PG2BE12: + size = st20_frame_size(ST20_FMT_YUV_444_12BIT, width, height); + break; + case ST_FRAME_FMT_ARGB: + case ST_FRAME_FMT_BGRA: + size = pixels * 4; /* 8 bits ARGB pixel in a 32 bits */ + break; + case ST_FRAME_FMT_RGB8: + size = pixels * 3; /* 8 bits RGB pixel in a 24 bits */ + break; + case ST_FRAME_FMT_YUV420CUSTOM8: + case ST_FRAME_FMT_YUV420PLANAR8: + size = st20_frame_size(ST20_FMT_YUV_420_8BIT, width, height); + break; + default: + err("%s, invalid fmt %d\n", __func__, fmt); + break; } - if (interlaced) - size /= 2; /* if all fmt support interlace? */ + if (interlaced) size /= 2; /* if all fmt support interlace? */ return size; } @@ -631,17 +629,16 @@ int st_frame_sanity_check(struct st_frame *frame) { /* check data size */ if (frame->data_size > frame->buffer_size) { - err("%s, frame data size %" PRIu64 " exceeds buffer size %" PRIu64 "\n", - __func__, frame->data_size, frame->buffer_size); + err("%s, frame data size %" PRIu64 " exceeds buffer size %" PRIu64 "\n", __func__, + frame->data_size, frame->buffer_size); return -EINVAL; } /* check data size is enough */ - size_t least_sz = st_frame_size(frame->fmt, frame->width, frame->height, - frame->interlaced); + size_t least_sz = + st_frame_size(frame->fmt, frame->width, frame->height, frame->interlaced); if (frame->data_size < least_sz) { - err("%s, frame data size %" PRIu64 " small then frame least_sz %" PRIu64 - "\n", + err("%s, frame data size %" PRIu64 " small then frame least_sz %" PRIu64 "\n", __func__, frame->data_size, least_sz); return -EINVAL; } @@ -676,8 +673,8 @@ size_t st20_frame_size(enum st20_fmt fmt, uint32_t width, uint32_t height) { size_t size = (size_t)width * height; if (size % pg.coverage) { - err("%s, fmt %d, invalid w %u h %u, not multiple of %u\n", __func__, fmt, - width, height, pg.coverage); + err("%s, fmt %d, invalid w %u h %u, not multiple of %u\n", __func__, fmt, width, + height, pg.coverage); return 0; } @@ -741,10 +738,8 @@ enum st_fps st_frame_rate_to_st_fps(double framerate) { for (i = 0; i < MTL_ARRAY_SIZE(st_fps_timings); i++) { if (framerate == st_fps_timings[i].framerate || - ((framerate >= - st_fps_timings[i].framerate - st_fps_timings[i].lower_limit) && - (framerate <= - st_fps_timings[i].framerate + st_fps_timings[i].upper_limit))) { + ((framerate >= st_fps_timings[i].framerate - st_fps_timings[i].lower_limit) && + (framerate <= st_fps_timings[i].framerate + st_fps_timings[i].upper_limit))) { return st_fps_timings[i].fps; } } @@ -836,69 +831,67 @@ enum st_frame_sampling st_frame_fmt_get_sampling(enum st_frame_fmt fmt) { enum st20_fmt st_frame_fmt_to_transport(enum st_frame_fmt fmt) { switch (fmt) { - case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - return ST20_FMT_YUV_422_10BIT; - case ST_FRAME_FMT_UYVY: - case ST_FRAME_FMT_YUV422CUSTOM8: - return ST20_FMT_YUV_422_8BIT; - case ST_FRAME_FMT_YUV422RFC4175PG2BE12: - return ST20_FMT_YUV_422_12BIT; - case ST_FRAME_FMT_YUV444RFC4175PG4BE10: - return ST20_FMT_YUV_444_10BIT; - case ST_FRAME_FMT_YUV444RFC4175PG2BE12: - return ST20_FMT_YUV_444_12BIT; - case ST_FRAME_FMT_YUV420CUSTOM8: - return ST20_FMT_YUV_420_8BIT; - case ST_FRAME_FMT_RGBRFC4175PG4BE10: - return ST20_FMT_RGB_10BIT; - case ST_FRAME_FMT_RGBRFC4175PG2BE12: - return ST20_FMT_RGB_12BIT; - case ST_FRAME_FMT_RGB8: - return ST20_FMT_RGB_8BIT; - default: - err("%s, invalid fmt %d\n", __func__, fmt); - return ST20_FMT_MAX; + case ST_FRAME_FMT_YUV422RFC4175PG2BE10: + return ST20_FMT_YUV_422_10BIT; + case ST_FRAME_FMT_UYVY: + case ST_FRAME_FMT_YUV422CUSTOM8: + return ST20_FMT_YUV_422_8BIT; + case ST_FRAME_FMT_YUV422RFC4175PG2BE12: + return ST20_FMT_YUV_422_12BIT; + case ST_FRAME_FMT_YUV444RFC4175PG4BE10: + return ST20_FMT_YUV_444_10BIT; + case ST_FRAME_FMT_YUV444RFC4175PG2BE12: + return ST20_FMT_YUV_444_12BIT; + case ST_FRAME_FMT_YUV420CUSTOM8: + return ST20_FMT_YUV_420_8BIT; + case ST_FRAME_FMT_RGBRFC4175PG4BE10: + return ST20_FMT_RGB_10BIT; + case ST_FRAME_FMT_RGBRFC4175PG2BE12: + return ST20_FMT_RGB_12BIT; + case ST_FRAME_FMT_RGB8: + return ST20_FMT_RGB_8BIT; + default: + err("%s, invalid fmt %d\n", __func__, fmt); + return ST20_FMT_MAX; } } enum st_frame_fmt st_frame_fmt_from_transport(enum st20_fmt tfmt) { switch (tfmt) { - case ST20_FMT_YUV_422_10BIT: - return ST_FRAME_FMT_YUV422RFC4175PG2BE10; - case ST20_FMT_YUV_422_8BIT: - return ST_FRAME_FMT_UYVY; - case ST20_FMT_YUV_422_12BIT: - return ST_FRAME_FMT_YUV422RFC4175PG2BE12; - case ST20_FMT_YUV_444_10BIT: - return ST_FRAME_FMT_YUV444RFC4175PG4BE10; - case ST20_FMT_YUV_444_12BIT: - return ST_FRAME_FMT_YUV444RFC4175PG2BE12; - case ST20_FMT_YUV_420_8BIT: - return ST_FRAME_FMT_YUV420CUSTOM8; - case ST20_FMT_RGB_10BIT: - return ST_FRAME_FMT_RGBRFC4175PG4BE10; - case ST20_FMT_RGB_12BIT: - return ST_FRAME_FMT_RGBRFC4175PG2BE12; - case ST20_FMT_RGB_8BIT: - return ST_FRAME_FMT_RGB8; - case ST20_FMT_YUV_422_PLANAR10LE: - return ST_FRAME_FMT_YUV422PLANAR10LE; - case ST20_FMT_V210: - return ST_FRAME_FMT_V210; - default: - err("%s, invalid tfmt %d\n", __func__, tfmt); - return ST_FRAME_FMT_MAX; + case ST20_FMT_YUV_422_10BIT: + return ST_FRAME_FMT_YUV422RFC4175PG2BE10; + case ST20_FMT_YUV_422_8BIT: + return ST_FRAME_FMT_UYVY; + case ST20_FMT_YUV_422_12BIT: + return ST_FRAME_FMT_YUV422RFC4175PG2BE12; + case ST20_FMT_YUV_444_10BIT: + return ST_FRAME_FMT_YUV444RFC4175PG4BE10; + case ST20_FMT_YUV_444_12BIT: + return ST_FRAME_FMT_YUV444RFC4175PG2BE12; + case ST20_FMT_YUV_420_8BIT: + return ST_FRAME_FMT_YUV420CUSTOM8; + case ST20_FMT_RGB_10BIT: + return ST_FRAME_FMT_RGBRFC4175PG4BE10; + case ST20_FMT_RGB_12BIT: + return ST_FRAME_FMT_RGBRFC4175PG2BE12; + case ST20_FMT_RGB_8BIT: + return ST_FRAME_FMT_RGB8; + case ST20_FMT_YUV_422_PLANAR10LE: + return ST_FRAME_FMT_YUV422PLANAR10LE; + case ST20_FMT_V210: + return ST_FRAME_FMT_V210; + default: + err("%s, invalid tfmt %d\n", __func__, tfmt); + return ST_FRAME_FMT_MAX; } } bool st_frame_fmt_equal_transport(enum st_frame_fmt fmt, enum st20_fmt tfmt) { - if (fmt == ST_FRAME_FMT_YUV422CUSTOM8 || fmt == ST_FRAME_FMT_YUV420CUSTOM8) - return true; + if (fmt == ST_FRAME_FMT_YUV422CUSTOM8 || fmt == ST_FRAME_FMT_YUV420CUSTOM8) return true; enum st_frame_fmt to_fmt = st_frame_fmt_from_transport(tfmt); - if (to_fmt == ST_FRAME_FMT_MAX) - return false; + if (to_fmt == ST_FRAME_FMT_MAX) return false; return (fmt == to_fmt) ? true : false; } @@ -915,27 +908,25 @@ uint64_t st10_media_clk_to_ns(uint32_t media_ts, uint32_t sampling_rate) { return ts; } -int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, - uint32_t y) { +int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, uint32_t y) { if (frame->fmt != logo->fmt) { err("%s, mismatch fmt %d %d\n", __func__, frame->fmt, logo->fmt); return -EINVAL; } if (frame->fmt != ST_FRAME_FMT_YUV422RFC4175PG2BE10) { - err("%s, err fmt %d, only ST_FRAME_FMT_YUV422RFC4175PG2BE10\n", __func__, - frame->fmt); + err("%s, err fmt %d, only ST_FRAME_FMT_YUV422RFC4175PG2BE10\n", __func__, frame->fmt); return -EINVAL; } if ((x + logo->width) > frame->width) { - err("%s, err w, x %u logo width %u frame width %u\n", __func__, x, - logo->width, frame->width); + err("%s, err w, x %u logo width %u frame width %u\n", __func__, x, logo->width, + frame->width); return -EINVAL; } if ((y + logo->height) > frame->height) { - err("%s, err h, y %u logo height %u frame height %u\n", __func__, y, - logo->height, frame->height); + err("%s, err h, y %u logo height %u frame height %u\n", __func__, y, logo->height, + frame->height); return -EINVAL; } @@ -949,8 +940,8 @@ int st_draw_logo(struct st_frame *frame, struct st_frame *logo, uint32_t x, return 0; } -int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, - enum st_fps fps, bool interlaced, uint64_t *bps) { +int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, enum st_fps fps, + bool interlaced, uint64_t *bps) { struct st20_pgroup pg; struct st_fps_timing fps_tm; int ret; @@ -960,34 +951,30 @@ int st20_get_bandwidth_bps(int width, int height, enum st20_fmt fmt, memset(&fps_tm, 0, sizeof(fps_tm)); ret = st20_get_pgroup(fmt, &pg); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = st_get_fps_timing(fps, &fps_tm); - if (ret < 0) - return ret; + if (ret < 0) return ret; double reactive = 1080.0 / 1125.0; - traffic = (uint64_t)width * height * 8 * pg.size / pg.coverage * fps_tm.mul / - fps_tm.den; - if (interlaced) - traffic /= 2; + traffic = + (uint64_t)width * height * 8 * pg.size / pg.coverage * fps_tm.mul / fps_tm.den; + if (interlaced) traffic /= 2; traffic = traffic / reactive; *bps = traffic; return 0; } -int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, - enum st_fps fps, uint64_t *bps) { +int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, enum st_fps fps, + uint64_t *bps) { struct st_fps_timing fps_tm; int ret; memset(&fps_tm, 0, sizeof(fps_tm)); ret = st_get_fps_timing(fps, &fps_tm); - if (ret < 0) - return ret; + if (ret < 0) return ret; double reactive = 1080.0 / 1125.0; *bps = (uint64_t)total_pkts * pkt_size * fps_tm.mul / fps_tm.den; @@ -995,16 +982,14 @@ int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, return 0; } -int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, - uint64_t *bps) { +int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, uint64_t *bps) { struct st_fps_timing fps_tm; int ret; memset(&fps_tm, 0, sizeof(fps_tm)); ret = st_get_fps_timing(fps, &fps_tm); - if (ret < 0) - return ret; + if (ret < 0) return ret; double reactive = 1080.0 / 1125.0; *bps = frame_size * fps_tm.mul / fps_tm.den; @@ -1015,149 +1000,149 @@ int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, double st30_get_packet_time(enum st30_ptime ptime) { double packet_time_ns = 0.0; /* in nanoseconds */ switch (ptime) { - case ST30_PTIME_1MS: - packet_time_ns = (double)1000000000.0 * 1 / 1000; - break; - case ST30_PTIME_125US: - packet_time_ns = (double)1000000000.0 * 1 / 8000; - break; - case ST30_PTIME_250US: - packet_time_ns = (double)1000000000.0 * 1 / 4000; - break; - case ST30_PTIME_333US: - packet_time_ns = (double)1000000000.0 * 1 / 3000; - break; - case ST30_PTIME_4MS: - packet_time_ns = (double)1000000000.0 * 4 / 1000; - break; - case ST31_PTIME_80US: - packet_time_ns = (double)1000000000.0 * 1 / 12500; - break; - case ST31_PTIME_1_09MS: - packet_time_ns = (double)1000000000.0 * 48 / 44100; - break; - case ST31_PTIME_0_14MS: - packet_time_ns = (double)1000000000.0 * 6 / 44100; - break; - case ST31_PTIME_0_09MS: - packet_time_ns = (double)1000000000.0 * 4 / 44100; - break; - default: - err("%s, wrong ptime %d\n", __func__, ptime); - return -EINVAL; - } - return packet_time_ns; -} - -int st30_get_sample_size(enum st30_fmt fmt) { - int sample_size = 0; - switch (fmt) { - case ST30_FMT_PCM16: - sample_size = 2; - break; - case ST30_FMT_PCM24: - sample_size = 3; - break; - case ST30_FMT_PCM8: - sample_size = 1; - break; - case ST31_FMT_AM824: - sample_size = 4; - break; - default: - err("%s, wrong fmt %d\n", __func__, fmt); - return -EINVAL; - } - return sample_size; -} - -int st30_get_sample_num(enum st30_ptime ptime, enum st30_sampling sampling) { - int samples = 0; - switch (sampling) { - case ST30_SAMPLING_48K: - switch (ptime) { case ST30_PTIME_1MS: - samples = 48; + packet_time_ns = (double)1000000000.0 * 1 / 1000; break; case ST30_PTIME_125US: - samples = 6; + packet_time_ns = (double)1000000000.0 * 1 / 8000; break; case ST30_PTIME_250US: - samples = 12; + packet_time_ns = (double)1000000000.0 * 1 / 4000; break; case ST30_PTIME_333US: - samples = 16; + packet_time_ns = (double)1000000000.0 * 1 / 3000; break; case ST30_PTIME_4MS: - samples = 192; + packet_time_ns = (double)1000000000.0 * 4 / 1000; break; case ST31_PTIME_80US: - samples = 4; + packet_time_ns = (double)1000000000.0 * 1 / 12500; break; - default: - err("%s, wrong ptime %d for 48k\n", __func__, ptime); - return -EINVAL; - } - break; - case ST30_SAMPLING_96K: - switch (ptime) { - case ST30_PTIME_1MS: - samples = 96; + case ST31_PTIME_1_09MS: + packet_time_ns = (double)1000000000.0 * 48 / 44100; break; - case ST30_PTIME_125US: - samples = 12; + case ST31_PTIME_0_14MS: + packet_time_ns = (double)1000000000.0 * 6 / 44100; break; - case ST30_PTIME_250US: - samples = 24; + case ST31_PTIME_0_09MS: + packet_time_ns = (double)1000000000.0 * 4 / 44100; break; - case ST30_PTIME_333US: - samples = 32; + default: + err("%s, wrong ptime %d\n", __func__, ptime); + return -EINVAL; + } + return packet_time_ns; +} + +int st30_get_sample_size(enum st30_fmt fmt) { + int sample_size = 0; + switch (fmt) { + case ST30_FMT_PCM16: + sample_size = 2; break; - case ST30_PTIME_4MS: - samples = 384; + case ST30_FMT_PCM24: + sample_size = 3; break; - case ST31_PTIME_80US: - samples = 8; + case ST30_FMT_PCM8: + sample_size = 1; + break; + case ST31_FMT_AM824: + sample_size = 4; break; default: - err("%s, wrong ptime %d for 96k\n", __func__, ptime); + err("%s, wrong fmt %d\n", __func__, fmt); return -EINVAL; - } - break; - case ST31_SAMPLING_44K: - switch (ptime) { - case ST31_PTIME_1_09MS: - samples = 48; + } + return sample_size; +} + +int st30_get_sample_num(enum st30_ptime ptime, enum st30_sampling sampling) { + int samples = 0; + switch (sampling) { + case ST30_SAMPLING_48K: + switch (ptime) { + case ST30_PTIME_1MS: + samples = 48; + break; + case ST30_PTIME_125US: + samples = 6; + break; + case ST30_PTIME_250US: + samples = 12; + break; + case ST30_PTIME_333US: + samples = 16; + break; + case ST30_PTIME_4MS: + samples = 192; + break; + case ST31_PTIME_80US: + samples = 4; + break; + default: + err("%s, wrong ptime %d for 48k\n", __func__, ptime); + return -EINVAL; + } break; - case ST31_PTIME_0_14MS: - samples = 6; + case ST30_SAMPLING_96K: + switch (ptime) { + case ST30_PTIME_1MS: + samples = 96; + break; + case ST30_PTIME_125US: + samples = 12; + break; + case ST30_PTIME_250US: + samples = 24; + break; + case ST30_PTIME_333US: + samples = 32; + break; + case ST30_PTIME_4MS: + samples = 384; + break; + case ST31_PTIME_80US: + samples = 8; + break; + default: + err("%s, wrong ptime %d for 96k\n", __func__, ptime); + return -EINVAL; + } break; - case ST31_PTIME_0_09MS: - samples = 4; + case ST31_SAMPLING_44K: + switch (ptime) { + case ST31_PTIME_1_09MS: + samples = 48; + break; + case ST31_PTIME_0_14MS: + samples = 6; + break; + case ST31_PTIME_0_09MS: + samples = 4; + break; + default: + err("%s, wrong ptime %d for 44k\n", __func__, ptime); + return -EINVAL; + } break; default: - err("%s, wrong ptime %d for 44k\n", __func__, ptime); + err("%s, wrong sampling %d\n", __func__, sampling); return -EINVAL; - } - break; - default: - err("%s, wrong sampling %d\n", __func__, sampling); - return -EINVAL; } return samples; } int st30_get_sample_rate(enum st30_sampling sampling) { switch (sampling) { - case ST30_SAMPLING_48K: - return 48000; - case ST30_SAMPLING_96K: - return 96000; - case ST31_SAMPLING_44K: - return 44100; - default: - err("%s, wrong sampling %d\n", __func__, sampling); - return -EINVAL; + case ST30_SAMPLING_48K: + return 48000; + case ST30_SAMPLING_96K: + return 96000; + case ST31_SAMPLING_44K: + return 44100; + default: + err("%s, wrong sampling %d\n", __func__, sampling); + return -EINVAL; } } @@ -1168,13 +1153,11 @@ int st30_get_packet_size(enum st30_fmt fmt, enum st30_ptime ptime, int sample_num; ret = st30_get_sample_size(fmt); - if (ret < 0) - return ret; + if (ret < 0) return ret; sample_size = ret; ret = st30_get_sample_num(ptime, sampling); - if (ret < 0) - return ret; + if (ret < 0) return ret; sample_num = ret; if (!channel) { @@ -1204,29 +1187,25 @@ int st30_calculate_framebuff_size(enum st30_fmt fmt, enum st30_ptime ptime, return framebuff_size; } -void st_frame_init_plane_single_src(struct st_frame *frame, void *addr, - mtl_iova_t iova) { +void st_frame_init_plane_single_src(struct st_frame *frame, void *addr, mtl_iova_t iova) { uint8_t planes = st_frame_fmt_planes(frame->fmt); for (uint8_t plane = 0; plane < planes; plane++) { - frame->linesize[plane] = - st_frame_least_linesize(frame->fmt, frame->width, plane); + frame->linesize[plane] = st_frame_least_linesize(frame->fmt, frame->width, plane); if (plane == 0) { frame->addr[plane] = addr; frame->iova[plane] = iova; } else { - frame->addr[plane] = - frame->addr[plane - 1] + - frame->linesize[plane - 1] * st_frame_data_height(frame); - frame->iova[plane] = - frame->iova[plane - 1] + - frame->linesize[plane - 1] * st_frame_data_height(frame); + frame->addr[plane] = frame->addr[plane - 1] + + frame->linesize[plane - 1] * st_frame_data_height(frame); + frame->iova[plane] = frame->iova[plane - 1] + + frame->linesize[plane - 1] * st_frame_data_height(frame); } } } -struct st_frame *st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, - uint32_t w, uint32_t h, bool interlaced) { +struct st_frame *st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, uint32_t w, + uint32_t h, bool interlaced) { struct mtl_main_impl *impl = mt; int soc_id = mt_socket_id(impl, MTL_PORT_P); struct st_frame *frame = mt_rte_zmalloc_socket(sizeof(*frame), soc_id); @@ -1254,8 +1233,8 @@ struct st_frame *st_frame_create(mtl_handle mt, enum st_frame_fmt fmt, return frame; } -struct st_frame *st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, - uint32_t h, bool interlaced) { +struct st_frame *st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, uint32_t h, + bool interlaced) { struct st_frame *frame = mt_zmalloc(sizeof(*frame)); if (!frame) { err("%s, frame malloc fail\n", __func__); @@ -1283,8 +1262,7 @@ struct st_frame *st_frame_create_by_malloc(enum st_frame_fmt fmt, uint32_t w, int st_frame_free(struct st_frame *frame) { if (!(frame->flags & ST_FRAME_FLAG_SINGLE_MALLOC)) { - err("%s, frame %p is not created by ST_FRAME_FLAG_SINGLE_MALLOC\n", - __func__, frame); + err("%s, frame %p is not created by ST_FRAME_FLAG_SINGLE_MALLOC\n", __func__, frame); return -EINVAL; } if (frame->flags & ST_FRAME_FLAG_RTE_MALLOC) { @@ -1371,8 +1349,7 @@ static const struct cvl_pad_table g_cvl_static_pad_tables[] = { .fps = ST_FPS_P59_94, .packing = ST20_PACKING_BPM, .interlaced = false, - .pad_interval = - 262, /* measured with VERO avg vrx: 7.0, narrow vrx: 9 */ + .pad_interval = 262, /* measured with VERO avg vrx: 7.0, narrow vrx: 9 */ }, { /* 4kp50 gpm */ @@ -1424,17 +1401,14 @@ uint16_t st20_pacing_static_profiling(struct mtl_main_impl *impl, MTL_MAY_UNUSED(impl); MTL_MAY_UNUSED(s_port); - if (s->s_type == MT_ST22_HANDLE_TX_VIDEO) - return 0; /* no for st22 */ + if (s->s_type == MT_ST22_HANDLE_TX_VIDEO) return 0; /* no for st22 */ for (int i = 0; i < MTL_ARRAY_SIZE(g_cvl_static_pad_tables); i++) { refer = &g_cvl_static_pad_tables[i]; if ((ops->fmt == refer->fmt) && (ops->width == refer->width) && (ops->height == refer->height) && (ops->fps == refer->fps) && - (ops->packing == refer->packing) && - (ops->interlaced == refer->interlaced)) { - dbg("%s(%d), reference pad_interval %u\n", __func__, s->idx, - refer->pad_interval); + (ops->packing == refer->packing) && (ops->interlaced == refer->interlaced)) { + dbg("%s(%d), reference pad_interval %u\n", __func__, s->idx, refer->pad_interval); return refer->pad_interval; } } @@ -1442,28 +1416,24 @@ uint16_t st20_pacing_static_profiling(struct mtl_main_impl *impl, return 0; /* not found */ } -int st_rxp_para_port_set(struct st_rx_port *p, enum mtl_session_port port, - char *name) { +int st_rxp_para_port_set(struct st_rx_port *p, enum mtl_session_port port, char *name) { return snprintf(p->port[port], MTL_PORT_MAX_LEN, "%s", name); } int st_rxp_para_ip_set(struct st_rx_port *p, enum mtl_port port, char *ip) { int ret = inet_pton(AF_INET, ip, p->ip_addr[port]); - if (ret == 1) - return 0; + if (ret == 1) return 0; err("%s, fail to inet_pton for %s\n", __func__, ip); return -EIO; } -int st_txp_para_port_set(struct st_tx_port *p, enum mtl_session_port port, - char *name) { +int st_txp_para_port_set(struct st_tx_port *p, enum mtl_session_port port, char *name) { return snprintf(p->port[port], MTL_PORT_MAX_LEN, "%s", name); } int st_txp_para_dip_set(struct st_tx_port *p, enum mtl_port port, char *ip) { int ret = inet_pton(AF_INET, ip, p->dip_addr[port]); - if (ret == 1) - return 0; + if (ret == 1) return 0; err("%s, fail to inet_pton for %s\n", __func__, ip); return -EIO; } diff --git a/lib/src/st2110/st_fmt.h b/lib/src/st2110/st_fmt.h index debf59249..5324f0830 100644 --- a/lib/src/st2110/st_fmt.h +++ b/lib/src/st2110/st_fmt.h @@ -41,14 +41,14 @@ int st_get_fps_timing(enum st_fps fps, struct st_fps_timing *fps_tm); enum st_frame_sampling st_frame_fmt_get_sampling(enum st_frame_fmt fmt); -int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, - enum st_fps fps, uint64_t *bps); +int st22_rtp_bandwidth_bps(uint32_t total_pkts, uint16_t pkt_size, enum st_fps fps, + uint64_t *bps); int st22_frame_bandwidth_bps(size_t frame_size, enum st_fps fps, uint64_t *bps); -static inline void -st20_unpack_pg2be_422le10(struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *cb00, - uint16_t *y00, uint16_t *cr00, uint16_t *y01) { +static inline void st20_unpack_pg2be_422le10(struct st20_rfc4175_422_10_pg2_be *pg, + uint16_t *cb00, uint16_t *y00, + uint16_t *cr00, uint16_t *y01) { uint16_t cb, y0, cr, y1; cb = (pg->Cb00 << 2) + pg->Cb00_; @@ -62,9 +62,9 @@ st20_unpack_pg2be_422le10(struct st20_rfc4175_422_10_pg2_be *pg, uint16_t *cb00, *y01 = y1; } -static inline void -st20_unpack_pg2be_422le12(struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *cb00, - uint16_t *y00, uint16_t *cr00, uint16_t *y01) { +static inline void st20_unpack_pg2be_422le12(struct st20_rfc4175_422_12_pg2_be *pg, + uint16_t *cb00, uint16_t *y00, + uint16_t *cr00, uint16_t *y01) { uint16_t cb, y0, cr, y1; cb = (pg->Cb00 << 4) + pg->Cb00_; @@ -78,8 +78,7 @@ st20_unpack_pg2be_422le12(struct st20_rfc4175_422_12_pg2_be *pg, uint16_t *cb00, *y01 = y1; } -void st_frame_init_plane_single_src(struct st_frame *frame, void *addr, - mtl_iova_t iova); +void st_frame_init_plane_single_src(struct st_frame *frame, void *addr, mtl_iova_t iova); enum st_frame_fmt st_codec_codestream_fmt(enum st22_codec codec); diff --git a/lib/src/st2110/st_header.h b/lib/src/st2110/st_header.h index af021294f..924902141 100644 --- a/lib/src/st2110/st_header.h +++ b/lib/src/st2110/st_header.h @@ -29,10 +29,8 @@ /* max 8 1080p rx(without DMA) session per sch lcore */ #define ST_QUOTA_RX1080P_NO_DMA_PER_SCH (8) -#define ST_SCH_MAX_TX_VIDEO_SESSIONS \ - (60) /* max video tx sessions per sch lcore */ -#define ST_SCH_MAX_RX_VIDEO_SESSIONS \ - (60) /* max video rx sessions per sch lcore */ +#define ST_SCH_MAX_TX_VIDEO_SESSIONS (60) /* max video tx sessions per sch lcore */ +#define ST_SCH_MAX_RX_VIDEO_SESSIONS (60) /* max video rx sessions per sch lcore */ #define ST_SESSION_MAX_BULK (4) #define ST_TX_VIDEO_SESSIONS_RING_SIZE (512) @@ -46,11 +44,9 @@ #define ST_VIDEO_BPM_SIZE (1260) /* max tx/rx audio(st_30) sessions */ -#define ST_SCH_MAX_TX_AUDIO_SESSIONS \ - (512) /* max audio tx sessions per sch lcore */ +#define ST_SCH_MAX_TX_AUDIO_SESSIONS (512) /* max audio tx sessions per sch lcore */ #define ST_TX_AUDIO_SESSIONS_RING_SIZE (ST_SCH_MAX_TX_AUDIO_SESSIONS * 2) -#define ST_SCH_MAX_RX_AUDIO_SESSIONS \ - (512 * 2) /* max audio rx sessions per sch lcore */ +#define ST_SCH_MAX_RX_AUDIO_SESSIONS (512 * 2) /* max audio rx sessions per sch lcore */ /* max tx/rx anc(st_40) sessions */ #define ST_MAX_TX_ANC_SESSIONS (180) @@ -124,13 +120,12 @@ struct st_page_info { /* describe the frame used in transport(both tx and rx) */ struct st_frame_trans { int idx; - void *addr; /* virtual address */ - rte_iova_t iova; /* iova for hw */ - struct st_page_info - *page_table; /* page table for hw, used for IOVA:PA mode */ - uint16_t page_table_len; /* page table len for hw, used for IOVA:PA mode */ - rte_atomic32_t refcnt; /* 0 means it's free */ - void *priv; /* private data for lib */ + void *addr; /* virtual address */ + rte_iova_t iova; /* iova for hw */ + struct st_page_info *page_table; /* page table for hw, used for IOVA:PA mode */ + uint16_t page_table_len; /* page table len for hw, used for IOVA:PA mode */ + rte_atomic32_t refcnt; /* 0 means it's free */ + void *priv; /* private data for lib */ uint32_t flags; /* ST_FT_FLAG_* */ struct rte_mbuf_ext_shared_info sh_info; /* for st20 tx ext shared */ @@ -152,11 +147,11 @@ struct st_frame_trans { /* timing for pacing */ struct st_tx_video_pacing { - double trs; /* in ns for of 2 consecutive packets, T-Frame / N-Packets */ - double tr_offset; /* in ns, tr offset time of each frame */ - uint32_t vrx; /* packets unit, VRX start value of each frame */ - uint32_t warm_pkts; /* packets unit, pkts for RL pacing warm boot */ - double frame_time; /* time of the frame in nanoseconds */ + double trs; /* in ns for of 2 consecutive packets, T-Frame / N-Packets */ + double tr_offset; /* in ns, tr offset time of each frame */ + uint32_t vrx; /* packets unit, VRX start value of each frame */ + uint32_t warm_pkts; /* packets unit, pkts for RL pacing warm boot */ + double frame_time; /* time of the frame in nanoseconds */ double frame_time_sampling; /* time of the frame in sampling(90k) */ /* in ns, idle time at the end of frame, frame_time - tr_offset - (trs * pkts) */ @@ -287,9 +282,9 @@ struct st_tx_video_session_impl { struct st_tx_video_pacing pacing; enum st21_tx_pacing_way pacing_way[MTL_SESSION_PORT_MAX]; - int (*pacing_tasklet_func[MTL_SESSION_PORT_MAX])( - struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, - enum mtl_session_port s_port); + int (*pacing_tasklet_func[MTL_SESSION_PORT_MAX])(struct mtl_main_impl *impl, + struct st_tx_video_session_impl *s, + enum mtl_session_port s_port); struct st_vsync_info vsync; bool second_field; @@ -309,9 +304,8 @@ struct st_tx_video_session_impl { struct rte_mbuf *trs_inflight[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; unsigned int trs_inflight_num[MTL_SESSION_PORT_MAX]; unsigned int trs_inflight_idx[MTL_SESSION_PORT_MAX]; - unsigned int - trs_pad_inflight_num[MTL_SESSION_PORT_MAX]; /* inflight padding */ - int trs_inflight_cnt[MTL_SESSION_PORT_MAX]; /* for stats */ + unsigned int trs_pad_inflight_num[MTL_SESSION_PORT_MAX]; /* inflight padding */ + int trs_inflight_cnt[MTL_SESSION_PORT_MAX]; /* for stats */ struct rte_mbuf *trs_inflight2[MTL_SESSION_PORT_MAX][ST_SESSION_MAX_BULK]; unsigned int trs_inflight_num2[MTL_SESSION_PORT_MAX]; unsigned int trs_inflight_idx2[MTL_SESSION_PORT_MAX]; @@ -377,15 +371,13 @@ struct st_tx_video_session_impl { uint32_t stat_epoch_drop; uint32_t stat_epoch_onward; uint32_t stat_error_user_timestamp; - uint32_t - stat_epoch_troffset_mismatch; /* pacing mismatch the epoch troffset */ + uint32_t stat_epoch_troffset_mismatch; /* pacing mismatch the epoch troffset */ uint32_t stat_trans_troffset_mismatch; /* transmitter mismatch the epoch troffset */ uint32_t stat_trans_recalculate_warmup; uint32_t stat_exceed_frame_time; bool stat_user_busy_first; - uint32_t - stat_user_busy; /* get_next_frame or dequeue_bulk from rtp ring fail */ + uint32_t stat_user_busy; /* get_next_frame or dequeue_bulk from rtp ring fail */ uint32_t stat_lines_not_ready; /* query app lines not ready */ uint32_t stat_vsync_mismatch; uint64_t stat_bytes_tx[MTL_SESSION_PORT_MAX]; @@ -450,8 +442,7 @@ struct st_rx_video_slot_impl { struct st22_rx_frame_meta st22_meta; /* only for st22 frame type */ /* Second field type indicate */ bool second_field; - struct st_rx_video_slot_slice_info - *slice_info; /* for ST20_TYPE_SLICE_LEVEL */ + struct st_rx_video_slot_slice_info *slice_info; /* for ST20_TYPE_SLICE_LEVEL */ /* payload len for codestream packetization mode */ uint16_t st22_payload_length; uint16_t st22_box_hdr_length; @@ -482,8 +473,7 @@ struct st_rx_video_detector { struct st22_rx_video_info { /* app callback */ - int (*notify_frame_ready)(void *priv, void *frame, - struct st22_rx_frame_meta *meta); + int (*notify_frame_ready)(void *priv, void *frame, struct st22_rx_frame_meta *meta); struct st22_rx_frame_meta meta; size_t cur_frame_size; /* size per frame */ @@ -1224,8 +1214,7 @@ struct st22_get_encoder_request { struct st22_encode_frame_meta *(*get_frame)(void *priv); int (*wake_block)(void *priv); int (*set_block_timeout)(void *priv, uint64_t timedwait_ns); - int (*put_frame)(void *priv, struct st22_encode_frame_meta *frame, - int result); + int (*put_frame)(void *priv, struct st22_encode_frame_meta *frame, int result); int (*dump)(void *priv); }; @@ -1237,8 +1226,7 @@ struct st22_get_decoder_request { struct st22_decode_frame_meta *(*get_frame)(void *priv); int (*wake_block)(void *priv); int (*set_block_timeout)(void *priv, uint64_t timedwait_ns); - int (*put_frame)(void *priv, struct st22_decode_frame_meta *frame, - int result); + int (*put_frame)(void *priv, struct st22_decode_frame_meta *frame, int result); int (*dump)(void *priv); }; @@ -1248,8 +1236,7 @@ struct st20_get_converter_request { void *priv; struct st20_convert_frame_meta *(*get_frame)(void *priv); - int (*put_frame)(void *priv, struct st20_convert_frame_meta *frame, - int result); + int (*put_frame)(void *priv, struct st20_convert_frame_meta *frame, int result); int (*dump)(void *priv); }; diff --git a/lib/src/st2110/st_main.h b/lib/src/st2110/st_main.h index d893dbc15..704c0ad6e 100644 --- a/lib/src/st2110/st_main.h +++ b/lib/src/st2110/st_main.h @@ -13,8 +13,8 @@ #include "../mt_simd.h" #include "../mt_util.h" -static inline enum st21_tx_pacing_way -st_tx_pacing_way(struct mtl_main_impl *impl, enum mtl_port port) { +static inline enum st21_tx_pacing_way st_tx_pacing_way(struct mtl_main_impl *impl, + enum mtl_port port) { return mt_if(impl, port)->tx_pacing_way; } diff --git a/lib/src/st2110/st_pkt.h b/lib/src/st2110/st_pkt.h index 25924025a..deffabc0b 100644 --- a/lib/src/st2110/st_pkt.h +++ b/lib/src/st2110/st_pkt.h @@ -60,20 +60,20 @@ struct st_rfc8331_anc_hdr { struct st40_rfc8331_rtp_hdr rtp; /* size: 20 */ } __attribute__((__packed__)) __rte_aligned(2); -#define ST_PKT_VIDEO_HDR_LEN \ +#define ST_PKT_VIDEO_HDR_LEN \ (sizeof(struct st_rfc4175_video_hdr) - sizeof(struct rte_ether_hdr)) -#define ST22_PKT_VIDEO_HDR_LEN \ +#define ST22_PKT_VIDEO_HDR_LEN \ (sizeof(struct st22_rfc9134_video_hdr) - sizeof(struct rte_ether_hdr)) -#define ST_PKT_AUDIO_HDR_LEN \ +#define ST_PKT_AUDIO_HDR_LEN \ (sizeof(struct st_rfc3550_audio_hdr) - sizeof(struct rte_ether_hdr)) -#define ST_PKT_ANC_HDR_LEN \ +#define ST_PKT_ANC_HDR_LEN \ (sizeof(struct st_rfc8331_anc_hdr) - sizeof(struct rte_ether_hdr)) /* standard UDP is 1460 bytes */ -#define ST_PKT_MAX_ETHER_BYTES \ +#define ST_PKT_MAX_ETHER_BYTES \ (1460 + sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr)) #endif diff --git a/lib/src/st2110/st_rx_ancillary_session.c b/lib/src/st2110/st_rx_ancillary_session.c index af6477080..d8391d62e 100644 --- a/lib/src/st2110/st_rx_ancillary_session.c +++ b/lib/src/st2110/st_rx_ancillary_session.c @@ -10,43 +10,35 @@ #include "st_ancillary_transmitter.h" /* call rx_ancillary_session_put always if get successfully */ -static inline struct st_rx_ancillary_session_impl * -rx_ancillary_session_get(struct st_rx_ancillary_sessions_mgr *mgr, int idx) { +static inline struct st_rx_ancillary_session_impl *rx_ancillary_session_get( + struct st_rx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline struct st_rx_ancillary_session_impl * -rx_ancillary_session_try_get(struct st_rx_ancillary_sessions_mgr *mgr, - int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) - return NULL; +static inline struct st_rx_ancillary_session_impl *rx_ancillary_session_try_get( + struct st_rx_ancillary_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline struct st_rx_ancillary_session_impl * -rx_ancillary_session_get_timeout(struct st_rx_ancillary_sessions_mgr *mgr, - int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) - return NULL; +static inline struct st_rx_ancillary_session_impl *rx_ancillary_session_get_timeout( + struct st_rx_ancillary_sessions_mgr *mgr, int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline bool -rx_ancillary_session_get_empty(struct st_rx_ancillary_sessions_mgr *mgr, - int idx) { +static inline bool rx_ancillary_session_get_empty( + struct st_rx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_rx_ancillary_session_impl *s = mgr->sessions[idx]; if (s) { @@ -57,20 +49,18 @@ rx_ancillary_session_get_empty(struct st_rx_ancillary_sessions_mgr *mgr, } } -static inline void -rx_ancillary_session_put(struct st_rx_ancillary_sessions_mgr *mgr, int idx) { +static inline void rx_ancillary_session_put(struct st_rx_ancillary_sessions_mgr *mgr, + int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -static inline uint16_t -rx_ancillary_queue_id(struct st_rx_ancillary_session_impl *s, - enum mtl_session_port s_port) { +static inline uint16_t rx_ancillary_queue_id(struct st_rx_ancillary_session_impl *s, + enum mtl_session_port s_port) { return mt_rxq_queue_id(s->rxq[s_port]); } static int rx_ancillary_session_init(struct st_rx_ancillary_sessions_mgr *mgr, - struct st_rx_ancillary_session_impl *s, - int idx) { + struct st_rx_ancillary_session_impl *s, int idx) { MTL_MAY_UNUSED(mgr); s->idx = idx; return 0; @@ -92,12 +82,12 @@ static int rx_ancillary_sessions_tasklet_stop(void *priv) { return 0; } -static int rx_ancillary_session_handle_pkt( - struct mtl_main_impl *impl, struct st_rx_ancillary_session_impl *s, - struct rte_mbuf *mbuf, enum mtl_session_port s_port) { +static int rx_ancillary_session_handle_pkt(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s, + struct rte_mbuf *mbuf, + enum mtl_session_port s_port) { struct st40_rx_ops *ops = &s->ops; - size_t hdr_offset = - sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); + size_t hdr_offset = sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); struct st_rfc3550_rtp_hdr *rtp = rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr *, hdr_offset); uint16_t seq_id = ntohs(rtp->seq_number); @@ -109,16 +99,16 @@ static int rx_ancillary_session_handle_pkt( uint32_t tmstamp = ntohl(rtp->tmstamp); if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, - s_port, payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, + payload_type, ops->payload_type); s->st40_stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, - ssrc, ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, + ops->ssrc); s->st40_stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } @@ -142,12 +132,10 @@ static int rx_ancillary_session_handle_pkt( } /* set if it is first pkt */ - if (unlikely(s->latest_seq_id == -1)) - s->latest_seq_id = seq_id - 1; + if (unlikely(s->latest_seq_id == -1)) s->latest_seq_id = seq_id - 1; /* drop old packet */ if (st_rx_seq_drop(seq_id, s->latest_seq_id, 5)) { - dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, - seq_id); + dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, seq_id); s->st40_stat_pkts_redundant++; return 0; } @@ -160,8 +148,8 @@ static int rx_ancillary_session_handle_pkt( /* enqueue to packet ring to let app to handle */ int ret = rte_ring_sp_enqueue(s->packet_ring, (void *)mbuf); if (ret < 0) { - err("%s(%d), can not enqueue to the rte ring, packet drop, pkt seq %d\n", - __func__, s->idx, seq_id); + err("%s(%d), can not enqueue to the rte ring, packet drop, pkt seq %d\n", __func__, + s->idx, seq_id); s->st40_stat_pkts_enqueue_fail++; MT_USDT_ST40_RX_MBUF_ENQUEUE_FAIL(s->mgr->idx, s->idx, mbuf, tmstamp); return 0; @@ -177,8 +165,7 @@ static int rx_ancillary_session_handle_pkt( /* get a valid packet */ uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); ops->notify_rtp_ready(ops->priv); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; @@ -207,16 +194,14 @@ static int rx_ancillary_session_handle_mbuf(void *priv, struct rte_mbuf **mbuf, return 0; } -static int -rx_ancillary_session_tasklet(struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_session_tasklet(struct st_rx_ancillary_session_impl *s) { struct rte_mbuf *mbuf[ST_RX_ANCILLARY_BURST_SIZE]; uint16_t rv; int num_port = s->ops.num_port; bool done = true; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rxq[s_port]) - continue; + if (!s->rxq[s_port]) continue; rv = mt_rxq_burst(s->rxq[s_port], &mbuf[0], ST_RX_ANCILLARY_BURST_SIZE); if (rv) { @@ -224,8 +209,7 @@ rx_ancillary_session_tasklet(struct st_rx_ancillary_session_impl *s) { rte_pktmbuf_free_bulk(&mbuf[0], rv); } - if (rv) - done = false; + if (rv) done = false; } return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; @@ -241,10 +225,8 @@ static int rx_ancillary_sessions_tasklet_handler(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_ancillary_session_try_get(mgr, sidx); - if (!s) - continue; - if (time_measure) - tsc_s = mt_get_tsc(impl); + if (!s) continue; + if (time_measure) tsc_s = mt_get_tsc(impl); pending += rx_ancillary_session_tasklet(s); @@ -258,8 +240,7 @@ static int rx_ancillary_sessions_tasklet_handler(void *priv) { return pending; } -static int -rx_ancillary_session_uinit_hw(struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_session_uinit_hw(struct st_rx_ancillary_session_impl *s) { int num_port = s->ops.num_port; for (int i = 0; i < num_port; i++) { @@ -272,9 +253,8 @@ rx_ancillary_session_uinit_hw(struct st_rx_ancillary_session_impl *s) { return 0; } -static int -rx_ancillary_session_init_hw(struct mtl_main_impl *impl, - struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_session_init_hw(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { int idx = s->idx, num_port = s->ops.num_port; struct mt_rxq_flow flow; enum mtl_port port; @@ -293,13 +273,12 @@ rx_ancillary_session_init_hw(struct mtl_main_impl *impl, else rte_memcpy(flow.sip_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); flow.dst_port = s->st40_dst_port[i]; - if (mt_has_cni_rx(impl, port)) - flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; + if (mt_has_cni_rx(impl, port)) flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; /* no flow for data path only */ if (s->ops.flags & ST40_RX_FLAG_DATA_PATH_ONLY) { - info("%s(%d), rxq get without flow for port %d as data path only\n", - __func__, s->idx, i); + info("%s(%d), rxq get without flow for port %d as data path only\n", __func__, + s->idx, i); s->rxq[i] = mt_rxq_get(impl, port, NULL); } else { s->rxq[i] = mt_rxq_get(impl, port, &flow); @@ -316,15 +295,13 @@ rx_ancillary_session_init_hw(struct mtl_main_impl *impl, return 0; } -static int -rx_ancillary_session_uinit_mcast(struct mtl_main_impl *impl, - struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_session_uinit_mcast(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { struct st40_rx_ops *ops = &s->ops; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!s->mcast_joined[i]) - continue; + if (!s->mcast_joined[i]) continue; port = mt_port_logic2phy(s->port_maps, i); mt_mcast_leave(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); @@ -333,16 +310,14 @@ rx_ancillary_session_uinit_mcast(struct mtl_main_impl *impl, return 0; } -static int -rx_ancillary_session_init_mcast(struct mtl_main_impl *impl, - struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_session_init_mcast(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s) { struct st40_rx_ops *ops = &s->ops; int ret; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!mt_is_multicast_ip(ops->ip_addr[i])) - continue; + if (!mt_is_multicast_ip(ops->ip_addr[i])) continue; port = mt_port_logic2phy(s->port_maps, i); if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { info("%s(%d), skip mcast join for port %d\n", __func__, s->idx, i); @@ -350,25 +325,22 @@ rx_ancillary_session_init_mcast(struct mtl_main_impl *impl, } ret = mt_mcast_join(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->mcast_joined[i] = true; } return 0; } -static int -rx_ancillary_session_init_sw(struct st_rx_ancillary_sessions_mgr *mgr, - struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_session_init_sw(struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s) { char ring_name[32]; struct rte_ring *ring; unsigned int flags, count; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_RX_ANCILLARY_PREFIX, mgr_idx, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ops.rtp_ring_size; ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (count <= 0) { @@ -384,8 +356,7 @@ rx_ancillary_session_init_sw(struct st_rx_ancillary_sessions_mgr *mgr, return 0; } -static int -rx_ancillary_session_uinit_sw(struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_session_uinit_sw(struct st_rx_ancillary_session_impl *s) { if (s->packet_ring) { mt_ring_dequeue_clean(s->packet_ring); rte_ring_free(s->packet_ring); @@ -411,11 +382,9 @@ static int rx_ancillary_session_attach(struct mtl_main_impl *impl, int idx = s->idx, num_port = ops->num_port; char *ports[MTL_SESSION_PORT_MAX]; - for (int i = 0; i < num_port; i++) - ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->mgr = mgr; if (ops->name) { @@ -425,8 +394,7 @@ static int rx_ancillary_session_attach(struct mtl_main_impl *impl, } s->ops = *ops; for (int i = 0; i < num_port; i++) { - s->st40_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); + s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); } s->latest_seq_id = -1; @@ -452,15 +420,14 @@ static int rx_ancillary_session_attach(struct mtl_main_impl *impl, ret = rx_ancillary_session_init_mcast(impl, s); if (ret < 0) { - err("%s(%d), rx_ancillary_session_init_mcast fail %d\n", __func__, idx, - ret); + err("%s(%d), rx_ancillary_session_init_mcast fail %d\n", __func__, idx, ret); rx_ancillary_session_uinit(impl, s); return -EIO; } s->attached = true; - info("%s(%d), flags 0x%x pt %u, %s\n", __func__, idx, ops->flags, - ops->payload_type, ops->interlaced ? "interlace" : "progressive"); + info("%s(%d), flags 0x%x pt %u, %s\n", __func__, idx, ops->flags, ops->payload_type, + ops->interlaced ? "interlace" : "progressive"); return 0; } @@ -473,19 +440,17 @@ static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl *s) { rte_atomic32_set(&s->st40_stat_frames_received, 0); - notice("RX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d\n", idx, s->ops_name, - framerate, frames_received, s->st40_stat_pkts_received); + notice("RX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d\n", idx, s->ops_name, framerate, + frames_received, s->st40_stat_pkts_received); s->st40_stat_pkts_received = 0; s->st40_stat_last_time = cur_time_ns; if (s->st40_stat_pkts_redundant) { - notice("RX_ANC_SESSION(%d): redundant pkts %d\n", idx, - s->st40_stat_pkts_redundant); + notice("RX_ANC_SESSION(%d): redundant pkts %d\n", idx, s->st40_stat_pkts_redundant); s->st40_stat_pkts_redundant = 0; } if (s->st40_stat_pkts_dropped) { - notice("RX_ANC_SESSION(%d): dropped pkts %d\n", idx, - s->st40_stat_pkts_dropped); + notice("RX_ANC_SESSION(%d): dropped pkts %d\n", idx, s->st40_stat_pkts_dropped); s->st40_stat_pkts_dropped = 0; } if (s->st40_stat_pkts_out_of_order) { @@ -514,8 +479,8 @@ static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl *s) { s->st40_stat_pkts_enqueue_fail = 0; } if (s->ops.interlaced) { - notice("RX_ANC_SESSION(%d): interlace first field %u second field %u\n", - idx, s->stat_interlace_first_field, s->stat_interlace_second_field); + notice("RX_ANC_SESSION(%d): interlace first field %u second field %u\n", idx, + s->stat_interlace_first_field, s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } @@ -523,15 +488,13 @@ static void rx_ancillary_session_stat(struct st_rx_ancillary_session_impl *s) { struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice( - "RX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", - idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice("RX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", idx, + (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_notify_rtp_us > 8) { - notice("RX_ANC_SESSION(%d): notify rtp max %uus\n", idx, - s->stat_max_notify_rtp_us); + notice("RX_ANC_SESSION(%d): notify rtp max %uus\n", idx, s->stat_max_notify_rtp_us); } s->stat_max_notify_rtp_us = 0; } @@ -544,10 +507,9 @@ static int rx_ancillary_session_detach(struct mtl_main_impl *impl, return 0; } -static int -rx_ancillary_session_update_src(struct mtl_main_impl *impl, - struct st_rx_ancillary_session_impl *s, - struct st_rx_source_info *src) { +static int rx_ancillary_session_update_src(struct mtl_main_impl *impl, + struct st_rx_ancillary_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; struct st40_rx_ops *ops = &s->ops; @@ -560,8 +522,7 @@ rx_ancillary_session_update_src(struct mtl_main_impl *impl, memcpy(ops->ip_addr[i], src->ip_addr[i], MTL_IP_ADDR_LEN); memcpy(ops->mcast_sip_addr[i], src->mcast_sip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = src->udp_port[i]; - s->st40_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); + s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); } /* reset seq id */ s->latest_seq_id = -1; @@ -581,10 +542,9 @@ rx_ancillary_session_update_src(struct mtl_main_impl *impl, return 0; } -static int -rx_ancillary_sessions_mgr_update_src(struct st_rx_ancillary_sessions_mgr *mgr, - struct st_rx_ancillary_session_impl *s, - struct st_rx_source_info *src) { +static int rx_ancillary_sessions_mgr_update_src(struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = rx_ancillary_session_get(mgr, idx); /* get the lock */ @@ -609,8 +569,7 @@ static int st_rx_ancillary_sessions_stat(void *priv) { for (int j = 0; j < mgr->max_idx; j++) { s = rx_ancillary_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) - continue; + if (!s) continue; rx_ancillary_session_stat(s); rx_ancillary_session_put(mgr, j); } @@ -618,10 +577,9 @@ static int st_rx_ancillary_sessions_stat(void *priv) { return 0; } -static int -rx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, - struct st_rx_ancillary_sessions_mgr *mgr) { +static int rx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_rx_ancillary_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; @@ -650,9 +608,8 @@ rx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, return 0; } -static struct st_rx_ancillary_session_impl * -rx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, - struct st40_rx_ops *ops) { +static struct st_rx_ancillary_session_impl *rx_ancillary_sessions_mgr_attach( + struct mtl_sch_impl *sch, struct st40_rx_ops *ops) { struct st_rx_ancillary_sessions_mgr *mgr = &sch->rx_anc_mgr; int midx = mgr->idx; int ret; @@ -661,8 +618,7 @@ rx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, /* find one empty slot in the mgr */ for (int i = 0; i < ST_MAX_RX_ANC_SESSIONS; i++) { - if (!rx_ancillary_session_get_empty(mgr, i)) - continue; + if (!rx_ancillary_session_get_empty(mgr, i)) continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -696,9 +652,8 @@ rx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, return NULL; } -static int -rx_ancillary_sessions_mgr_detach(struct st_rx_ancillary_sessions_mgr *mgr, - struct st_rx_ancillary_session_impl *s) { +static int rx_ancillary_sessions_mgr_detach(struct st_rx_ancillary_sessions_mgr *mgr, + struct st_rx_ancillary_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -717,21 +672,18 @@ rx_ancillary_sessions_mgr_detach(struct st_rx_ancillary_sessions_mgr *mgr, return 0; } -static int -rx_ancillary_sessions_mgr_update(struct st_rx_ancillary_sessions_mgr *mgr) { +static int rx_ancillary_sessions_mgr_update(struct st_rx_ancillary_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_MAX_RX_ANC_SESSIONS; i++) { - if (mgr->sessions[i]) - max_idx = i + 1; + if (mgr->sessions[i]) max_idx = i + 1; } mgr->max_idx = max_idx; return 0; } -static int -rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr *mgr) { +static int rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr *mgr) { int m_idx = mgr->idx; struct st_rx_ancillary_session_impl *s; @@ -744,8 +696,7 @@ rx_ancillary_sessions_mgr_uinit(struct st_rx_ancillary_sessions_mgr *mgr) { for (int i = 0; i < ST_MAX_RX_ANC_SESSIONS; i++) { s = rx_ancillary_session_get(mgr, i); - if (!s) - continue; + if (!s) continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); rx_ancillary_sessions_mgr_detach(mgr, s); @@ -769,16 +720,14 @@ static int rx_ancillary_ops_check(struct st40_rx_ops *ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -802,12 +751,10 @@ static int rx_ancillary_ops_check(struct st40_rx_ops *ops) { return 0; } -static int st_rx_anc_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { +static int st_rx_anc_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { int ret; - if (sch->rx_anc_init) - return 0; + if (sch->rx_anc_init) return 0; /* create rx ancillary context */ ret = rx_ancillary_sessions_mgr_init(impl, sch, &sch->rx_anc_mgr); @@ -821,8 +768,7 @@ static int st_rx_anc_init(struct mtl_main_impl *impl, } int st_rx_ancillary_sessions_sch_uinit(struct mtl_sch_impl *sch) { - if (!sch->rx_anc_init) - return 0; + if (!sch->rx_anc_init) return 0; rx_ancillary_sessions_mgr_uinit(&sch->rx_anc_mgr); @@ -852,8 +798,7 @@ st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops *ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); s_impl = mt_rte_zmalloc_socket(sizeof(*s_impl), socket); @@ -863,8 +808,8 @@ st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops *ops) { } quota_mbs = 0; - sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, - MT_SCH_MASK_ALL, socket); + sch = + mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -903,8 +848,7 @@ st40_rx_handle st40_rx_create(mtl_handle mt, struct st40_rx_ops *ops) { return s_impl; } -int st40_rx_update_source(st40_rx_handle handle, - struct st_rx_source_info *src) { +int st40_rx_update_source(st40_rx_handle handle, struct st_rx_source_info *src) { struct st_rx_ancillary_session_handle_impl *s_impl = handle; struct st_rx_ancillary_session_impl *s; struct mtl_sch_impl *sch; @@ -921,8 +865,7 @@ int st40_rx_update_source(st40_rx_handle handle, sch_idx = sch->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = rx_ancillary_sessions_mgr_update_src(&sch->rx_anc_mgr, s, src); if (ret < 0) { @@ -957,12 +900,10 @@ int st40_rx_free(st40_rx_handle handle) { mt_pthread_mutex_lock(&sch->rx_anc_mgr_mutex); ret = rx_ancillary_sessions_mgr_detach(&sch->rx_anc_mgr, s); mt_pthread_mutex_unlock(&sch->rx_anc_mgr_mutex); - if (ret < 0) - err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -998,8 +939,8 @@ void *st40_rx_get_mbuf(st40_rx_handle handle, void **usrptr, uint16_t *len) { ret = rte_ring_sc_dequeue(packet_ring, (void **)&pkt); if (ret == 0) { - int header_len = sizeof(struct rte_ether_hdr) + - sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr); + int header_len = sizeof(struct rte_ether_hdr) + sizeof(struct rte_ipv4_hdr) + + sizeof(struct rte_udp_hdr); *len = pkt->data_len - header_len; *usrptr = rte_pktmbuf_mtod_offset(pkt, void *, header_len); return (void *)pkt; @@ -1021,8 +962,7 @@ void st40_rx_put_mbuf(st40_rx_handle handle, void *mbuf) { s = s_impl->impl; MTL_MAY_UNUSED(s); - if (pkt) - rte_pktmbuf_free(pkt); + if (pkt) rte_pktmbuf_free(pkt); MT_USDT_ST40_RX_MBUF_PUT(s->mgr->idx, s->idx, mbuf); } diff --git a/lib/src/st2110/st_rx_audio_session.c b/lib/src/st2110/st_rx_audio_session.c index 0d82b3831..77ba94826 100644 --- a/lib/src/st2110/st_rx_audio_session.c +++ b/lib/src/st2110/st_rx_audio_session.c @@ -18,41 +18,35 @@ static inline uint16_t rx_audio_queue_id(struct st_rx_audio_session_impl *s, } /* call rx_audio_session_put always if get successfully */ -static inline struct st_rx_audio_session_impl * -rx_audio_session_get(struct st_rx_audio_sessions_mgr *mgr, int idx) { +static inline struct st_rx_audio_session_impl *rx_audio_session_get( + struct st_rx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_rx_audio_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_audio_session_put always if get successfully */ -static inline struct st_rx_audio_session_impl * -rx_audio_session_get_timeout(struct st_rx_audio_sessions_mgr *mgr, int idx, - int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) - return NULL; +static inline struct st_rx_audio_session_impl *rx_audio_session_get_timeout( + struct st_rx_audio_sessions_mgr *mgr, int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; struct st_rx_audio_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_audio_session_put always if get successfully */ -static inline struct st_rx_audio_session_impl * -rx_audio_session_try_get(struct st_rx_audio_sessions_mgr *mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) - return NULL; +static inline struct st_rx_audio_session_impl *rx_audio_session_try_get( + struct st_rx_audio_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; struct st_rx_audio_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_audio_session_put always if get successfully */ -static inline bool -rx_audio_session_get_empty(struct st_rx_audio_sessions_mgr *mgr, int idx) { +static inline bool rx_audio_session_get_empty(struct st_rx_audio_sessions_mgr *mgr, + int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_rx_audio_session_impl *s = mgr->sessions[idx]; if (s) { @@ -63,13 +57,12 @@ rx_audio_session_get_empty(struct st_rx_audio_sessions_mgr *mgr, int idx) { } } -static inline void rx_audio_session_put(struct st_rx_audio_sessions_mgr *mgr, - int idx) { +static inline void rx_audio_session_put(struct st_rx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -static struct st_frame_trans * -rx_audio_session_get_frame(struct st_rx_audio_session_impl *s) { +static struct st_frame_trans *rx_audio_session_get_frame( + struct st_rx_audio_session_impl *s) { struct st_frame_trans *frame_info; for (int i = 0; i < s->st30_frames_cnt; i++) { @@ -122,8 +115,8 @@ static int rx_audio_session_alloc_frames(struct st_rx_audio_session_impl *s) { struct st_frame_trans *st30_frame; void *frame; - s->st30_frames = mt_rte_zmalloc_socket( - sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); + s->st30_frames = + mt_rte_zmalloc_socket(sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); if (!s->st30_frames) { err("%s(%d), st30_frames alloc fail\n", __func__, idx); return -ENOMEM; @@ -140,8 +133,7 @@ static int rx_audio_session_alloc_frames(struct st_rx_audio_session_impl *s) { frame = mt_rte_zmalloc_socket(size, soc_id); if (!frame) { - err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, size, - i); + err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, size, i); rx_audio_session_free_frames(s); return -ENOMEM; } @@ -172,8 +164,7 @@ static int rx_audio_session_alloc_rtps(struct st_rx_audio_sessions_mgr *mgr, int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_RTP", ST_RX_AUDIO_PREFIX, mgr_idx, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ops.rtp_ring_size; if (count <= 0) { err("%s(%d,%d), invalid rtp_ring_size %d\n", __func__, mgr_idx, idx, count); @@ -205,13 +196,12 @@ static int rx_audio_sessions_tasklet_stop(void *priv) { return 0; } -static int -rx_audio_session_usdt_dump_close(struct st_rx_audio_session_impl *s) { +static int rx_audio_session_usdt_dump_close(struct st_rx_audio_session_impl *s) { int idx = s->idx; if (s->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, - s->usdt_dump_fd, s->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, s->usdt_dump_fd, + s->usdt_dumped_frames); close(s->usdt_dump_fd); s->usdt_dump_fd = -1; } @@ -228,17 +218,16 @@ static int rx_audio_session_usdt_dump_frame(struct st_rx_audio_session_impl *s, struct st30_rx_ops *ops = &s->ops; snprintf(s->usdt_dump_path, sizeof(s->usdt_dump_path), "imtl_usdt_st30rx_m%ds%d_%d_%d_c%u_XXXXXX.pcm", mgr->idx, idx, - st30_get_sample_rate(ops->sampling), - st30_get_sample_size(ops->fmt) * 8, ops->channel); + st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, + ops->channel); ret = mt_mkstemps(s->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, - ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, ret); return ret; } s->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, - s->usdt_dump_path, s->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, s->usdt_dump_path, + s->usdt_dump_fd); } /* write frame to dump file */ @@ -274,35 +263,33 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl *impl, uint32_t pkt_len = mbuf->data_len - sizeof(struct st_rfc3550_audio_hdr); if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, - s_port, payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, + payload_type, ops->payload_type); s->st30_stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, - ssrc, ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, + ops->ssrc); s->st30_stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } } if (pkt_len != s->pkt_len) { - dbg("%s(%d,%d), drop as pkt_len mismatch now %u expect %u\n", __func__, - s->idx, s_port, pkt_len, s->pkt_len); + dbg("%s(%d,%d), drop as pkt_len mismatch now %u expect %u\n", __func__, s->idx, + s_port, pkt_len, s->pkt_len); s->st30_stat_pkts_len_mismatch_dropped++; return -EINVAL; } /* set first seq_id - 1 */ - if (unlikely(s->latest_seq_id == -1)) - s->latest_seq_id = seq_id - 1; + if (unlikely(s->latest_seq_id == -1)) s->latest_seq_id = seq_id - 1; /* drop old packet */ if (st_rx_seq_drop(seq_id, s->latest_seq_id, 5)) { - dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, - seq_id); + dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, seq_id); s->st30_stat_pkts_redundant++; if (s->enable_timing_parser) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); @@ -312,8 +299,8 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl *impl, } if (seq_id != (uint16_t)(s->latest_seq_id + 1)) { s->st30_stat_pkts_out_of_order++; - info("%s(%d,%d), ooo, seq now %u last %d\n", __func__, s->idx, s_port, - seq_id, s->latest_seq_id); + info("%s(%d,%d), ooo, seq now %u last %d\n", __func__, s->idx, s_port, seq_id, + s->latest_seq_id); } /* update seq id */ s->latest_seq_id = seq_id; @@ -322,8 +309,7 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl *impl, if (!s->st30_cur_frame) { s->st30_cur_frame = rx_audio_session_get_frame(s); if (!s->st30_cur_frame) { - dbg("%s(%d,%d), seq %d drop as frame run out\n", __func__, s->idx, s_port, - seq_id); + dbg("%s(%d,%d), seq %d drop as frame run out\n", __func__, s->idx, s_port, seq_id); s->stat_slot_get_frame_fail++; MT_USDT_ST30_RX_NO_FRAMEBUFFER(s->mgr->idx, s->idx, tmstamp); return -EIO; @@ -331,8 +317,8 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl *impl, } uint32_t offset = s->st30_pkt_idx * s->pkt_len; if ((offset + s->pkt_len) > s->st30_frame_size) { - dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, - s->idx, s_port, offset, s->st30_frame_size); + dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, s->idx, s_port, + offset, s->st30_frame_size); s->st30_stat_pkts_dropped++; return -EIO; } @@ -377,8 +363,7 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl *impl, meta->rtp_timestamp = tmstamp; meta->frame_recv_size = s->frame_recv_size; - MT_USDT_ST30_RX_FRAME_AVAILABLE(s->mgr->idx, s->idx, frame->idx, - frame->addr, tmstamp, + MT_USDT_ST30_RX_FRAME_AVAILABLE(s->mgr->idx, s->idx, frame->idx, frame->addr, tmstamp, meta->frame_recv_size); /* check if dump USDT enabled */ if (MT_USDT_ST30_RX_FRAME_DUMP_ENABLED()) { @@ -389,13 +374,11 @@ static int rx_audio_session_handle_frame_pkt(struct mtl_main_impl *impl, /* get a full frame */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); int ret = ops->notify_frame_ready(ops->priv, frame->addr, meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = - RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); } if (ret < 0) { err("%s(%d), notify_frame_ready return fail %d\n", __func__, s->idx, ret); @@ -426,28 +409,26 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl *impl, uint8_t payload_type = rtp->payload_type; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, - s_port, payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, + payload_type, ops->payload_type); s->st30_stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, - ssrc, ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, + ops->ssrc); s->st30_stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } } /* set first seq_id - 1 */ - if (unlikely(s->latest_seq_id == -1)) - s->latest_seq_id = seq_id - 1; + if (unlikely(s->latest_seq_id == -1)) s->latest_seq_id = seq_id - 1; /* drop old packet */ if (st_rx_seq_drop(seq_id, s->latest_seq_id, 5)) { - dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, - seq_id); + dbg("%s(%d,%d), drop as pkt seq %d is old\n", __func__, s->idx, s_port, seq_id); s->st30_stat_pkts_redundant++; return -EIO; } @@ -460,8 +441,7 @@ static int rx_audio_session_handle_rtp_pkt(struct mtl_main_impl *impl, /* enqueue the packet ring to app */ int ret = rte_ring_sp_enqueue(s->st30_rtps_ring, (void *)mbuf); if (ret < 0) { - dbg("%s(%d,%d), drop as rtps ring full, seq id %d\n", __func__, seq_id, - s_port); + dbg("%s(%d,%d), drop as rtps ring full, seq id %d\n", __func__, seq_id, s_port); s->st30_stat_pkts_rtp_ring_full++; return -EIO; } @@ -477,11 +457,10 @@ static int ra_stop_pcap(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port) { struct mt_rx_pcap *pcap = &s->pcap[s_port]; - if (!pcap->pcap) - return 0; + if (!pcap->pcap) return 0; - info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, - s->idx, s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); + info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, s->idx, + s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); MT_USDT_ST30_RX_PCAP_DUMP(s->mgr->idx, s->idx, s_port, pcap->file_name, pcap->dumped_pkts); pcap->required_pkts = 0; @@ -497,8 +476,7 @@ static int rv_stop_pcap_dump(struct st_rx_audio_session_impl *s) { return 0; } -static int ra_start_pcap(struct st_rx_audio_session_impl *s, - enum mtl_session_port s_port, +static int ra_start_pcap(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port, uint32_t max_dump_packets) { int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); @@ -509,8 +487,8 @@ static int ra_start_pcap(struct st_rx_audio_session_impl *s, return -EIO; } - snprintf(pcap->file_name, sizeof(pcap->file_name), - "st30rx_s%dp%d_%u_XXXXXX.pcapng", idx, s_port, max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), "st30rx_s%dp%d_%u_XXXXXX.pcapng", + idx, s_port, max_dump_packets); int fd = mt_mkstemps(pcap->file_name, strlen(".pcapng")); if (fd < 0) { err("%s(%d,%d), failed to create pcap file %s\n", __func__, idx, s_port, @@ -528,14 +506,13 @@ static int ra_start_pcap(struct st_rx_audio_session_impl *s, pcap->dumped_pkts = 0; pcap->dropped_pkts = 0; pcap->required_pkts = max_dump_packets; - info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, - s_port, pcap->file_name, max_dump_packets); + info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, s_port, + pcap->file_name, max_dump_packets); return 0; } -static int ra_dump_pcap(struct st_rx_audio_session_impl *s, - struct rte_mbuf **mbufs, uint16_t nb, - enum mtl_session_port s_port) { +static int ra_dump_pcap(struct st_rx_audio_session_impl *s, struct rte_mbuf **mbufs, + uint16_t nb, enum mtl_session_port s_port) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); struct mt_rx_pcap *pcap = &s->pcap[s_port]; uint16_t dump = mt_pcap_dump(s->mgr->parent, port, pcap->pcap, mbufs, nb); @@ -544,8 +521,7 @@ static int ra_dump_pcap(struct st_rx_audio_session_impl *s, return 0; } -static int rx_audio_session_handle_mbuf(void *priv, struct rte_mbuf **mbuf, - uint16_t nb) { +static int rx_audio_session_handle_mbuf(void *priv, struct rte_mbuf **mbuf, uint16_t nb) { struct st_rx_session_priv *s_priv = priv; struct st_rx_audio_session_impl *s = s_priv->session; struct mtl_main_impl *impl = s_priv->impl; @@ -560,9 +536,7 @@ static int rx_audio_session_handle_mbuf(void *priv, struct rte_mbuf **mbuf, struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->required_pkts) { if (pcap->dumped_pkts < pcap->required_pkts) { - ra_dump_pcap(s, mbuf, - RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), - s_port); + ra_dump_pcap(s, mbuf, RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), s_port); } else { /* got enough packets, stop dumping */ ra_stop_pcap(s, s_port); } @@ -588,8 +562,7 @@ static int rx_audio_session_tasklet(struct st_rx_audio_session_impl *s) { bool done = true; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rxq[s_port]) - continue; + if (!s->rxq[s_port]) continue; struct mt_rx_pcap *pcap = &s->pcap[s_port]; /* if any pcap progress */ @@ -608,14 +581,12 @@ static int rx_audio_session_tasklet(struct st_rx_audio_session_impl *s) { } rv = mt_rxq_burst(s->rxq[s_port], &mbuf[0], ST_RX_AUDIO_BURST_SIZE); - if (!rv) - continue; + if (!rv) continue; rx_audio_session_handle_mbuf(&s->priv[s_port], &mbuf[0], rv); rte_pktmbuf_free_bulk(&mbuf[0], rv); if (s->enable_timing_parser && s->tp) { - if (rv > 1) - s->tp->stat_bursted_cnt[s_port]++; + if (rv > 1) s->tp->stat_bursted_cnt[s_port]++; } done = false; } @@ -633,10 +604,8 @@ static int rx_audio_sessions_tasklet_handler(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_audio_session_try_get(mgr, sidx); - if (!s) - continue; - if (time_measure) - tsc_s = mt_get_tsc(impl); + if (!s) continue; + if (time_measure) tsc_s = mt_get_tsc(impl); pending += rx_audio_session_tasklet(s); @@ -683,13 +652,12 @@ static int rx_audio_session_init_hw(struct mtl_main_impl *impl, else rte_memcpy(flow.sip_addr, mt_sip_addr(impl, port), MTL_IP_ADDR_LEN); flow.dst_port = s->st30_dst_port[i]; - if (mt_has_cni_rx(impl, port)) - flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; + if (mt_has_cni_rx(impl, port)) flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; /* no flow for data path only */ if (s->ops.flags & ST30_RX_FLAG_DATA_PATH_ONLY) { - info("%s(%d), rxq get without flow for port %d as data path only\n", - __func__, s->idx, i); + info("%s(%d), rxq get without flow for port %d as data path only\n", __func__, + s->idx, i); s->rxq[i] = mt_rxq_get(impl, port, NULL); } else { s->rxq[i] = mt_rxq_get(impl, port, &flow); @@ -712,8 +680,7 @@ static int rx_audio_session_uinit_mcast(struct mtl_main_impl *impl, enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!s->mcast_joined[i]) - continue; + if (!s->mcast_joined[i]) continue; port = mt_port_logic2phy(s->port_maps, i); mt_mcast_leave(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); @@ -729,8 +696,7 @@ static int rx_audio_session_init_mcast(struct mtl_main_impl *impl, enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!mt_is_multicast_ip(ops->ip_addr[i])) - continue; + if (!mt_is_multicast_ip(ops->ip_addr[i])) continue; port = mt_port_logic2phy(s->port_maps, i); if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { info("%s(%d), skip mcast join for port %d\n", __func__, s->idx, i); @@ -738,8 +704,7 @@ static int rx_audio_session_init_mcast(struct mtl_main_impl *impl, } ret = mt_mcast_join(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->mcast_joined[i] = true; } @@ -760,18 +725,17 @@ static int rx_audio_session_init_sw(struct st_rx_audio_sessions_mgr *mgr, int ret; switch (st30_type) { - case ST30_TYPE_FRAME_LEVEL: - ret = rx_audio_session_alloc_frames(s); - break; - case ST30_TYPE_RTP_LEVEL: - ret = rx_audio_session_alloc_rtps(mgr, s); - break; - default: - err("%s(%d), error st30_type %d\n", __func__, idx, st30_type); - return -EIO; + case ST30_TYPE_FRAME_LEVEL: + ret = rx_audio_session_alloc_frames(s); + break; + case ST30_TYPE_RTP_LEVEL: + ret = rx_audio_session_alloc_rtps(mgr, s); + break; + default: + err("%s(%d), error st30_type %d\n", __func__, idx, st30_type); + return -EIO; } - if (ret < 0) - return ret; + if (ret < 0) return ret; return 0; } @@ -794,32 +758,26 @@ static int rx_audio_session_attach(struct mtl_main_impl *impl, int idx = s->idx, num_port = ops->num_port; char *ports[MTL_SESSION_PORT_MAX]; - for (int i = 0; i < num_port; i++) - ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->mgr = mgr; if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, - idx); + snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, idx); } s->ops = *ops; for (int i = 0; i < num_port; i++) { - s->st30_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); + s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); } ret = st30_get_packet_size(ops->fmt, ops->ptime, ops->sampling, ops->channel); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->pkt_len = ret; - size_t bytes_in_pkt = - ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); + size_t bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); s->st30_pkt_size = s->pkt_len + sizeof(struct st_rfc3550_audio_hdr); if (s->pkt_len > bytes_in_pkt) { err("%s(%d), invalid pkt_len %d\n", __func__, idx, s->pkt_len); @@ -830,8 +788,8 @@ static int rx_audio_session_attach(struct mtl_main_impl *impl, s->st30_total_pkts = ops->framebuff_size / s->pkt_len; if (ops->framebuff_size % s->pkt_len) { /* todo: add the support? */ - err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, - s->pkt_len, ops->framebuff_size); + err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, s->pkt_len, + ops->framebuff_size); return -EIO; } s->st30_pkt_idx = 0; @@ -852,8 +810,7 @@ static int rx_audio_session_attach(struct mtl_main_impl *impl, } if (ops->flags & ST30_RX_FLAG_TIMING_PARSER_META) { if (!ops->notify_timing_parser_result) { - err("%s(%d), notify_timing_parser_result callback is NULL\n", __func__, - idx); + err("%s(%d), notify_timing_parser_result callback is NULL\n", __func__, idx); return -EIO; } info("%s(%d), enable the timing analyze meta\n", __func__, idx); @@ -894,11 +851,10 @@ static int rx_audio_session_attach(struct mtl_main_impl *impl, s->frames_per_sec = (double)NS_PER_S / st30_get_packet_time(ops->ptime) / s->st30_total_pkts; s->attached = true; - info("%s(%d), fmt %d channel %u sampling %d ptime %d payload_type %u\n", - __func__, idx, ops->fmt, ops->channel, ops->sampling, ops->ptime, - ops->payload_type); - info("%s(%d), pkt_len %u frame_size %" PRId64 ", expect fps %d\n", __func__, - idx, s->pkt_len, s->st30_frame_size, s->frames_per_sec); + info("%s(%d), fmt %d channel %u sampling %d ptime %d payload_type %u\n", __func__, idx, + ops->fmt, ops->channel, ops->sampling, ops->ptime, ops->payload_type); + info("%s(%d), pkt_len %u frame_size %" PRId64 ", expect fps %d\n", __func__, idx, + s->pkt_len, s->st30_frame_size, s->frames_per_sec); return 0; } @@ -934,18 +890,18 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr *mgr, s->st30_stat_pkts_dropped = 0; } if (s->st30_stat_pkts_wrong_pt_dropped) { - notice("RX_AUDIO_SESSION(%d,%d): wrong hdr payload_type dropped pkts %d\n", - m_idx, idx, s->st30_stat_pkts_wrong_pt_dropped); + notice("RX_AUDIO_SESSION(%d,%d): wrong hdr payload_type dropped pkts %d\n", m_idx, + idx, s->st30_stat_pkts_wrong_pt_dropped); s->st30_stat_pkts_wrong_pt_dropped = 0; } if (s->st30_stat_pkts_wrong_ssrc_dropped) { - notice("RX_AUDIO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, - idx, s->st30_stat_pkts_wrong_ssrc_dropped); + notice("RX_AUDIO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, idx, + s->st30_stat_pkts_wrong_ssrc_dropped); s->st30_stat_pkts_wrong_ssrc_dropped = 0; } if (s->st30_stat_pkts_len_mismatch_dropped) { - notice("RX_AUDIO_SESSION(%d,%d): pkt len mismatch dropped pkts %d\n", m_idx, - idx, s->st30_stat_pkts_len_mismatch_dropped); + notice("RX_AUDIO_SESSION(%d,%d): pkt len mismatch dropped pkts %d\n", m_idx, idx, + s->st30_stat_pkts_len_mismatch_dropped); s->st30_stat_pkts_len_mismatch_dropped = 0; } if (s->stat_slot_get_frame_fail) { @@ -957,11 +913,11 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr *mgr, struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("RX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " - "%.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, - (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice( + "RX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_notify_frame_us > 8) { @@ -970,14 +926,12 @@ static void rx_audio_session_stat(struct st_rx_audio_sessions_mgr *mgr, } s->stat_max_notify_frame_us = 0; - if (s->enable_timing_parser_stat) - ra_tp_stat(s); + if (s->enable_timing_parser_stat) ra_tp_stat(s); for (int s_port = 0; s_port < s->ops.num_port; s_port++) { struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->pcap) { - MT_USDT_ST30_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, - pcap->dumped_pkts); + MT_USDT_ST30_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, pcap->dumped_pkts); } } } @@ -1006,8 +960,7 @@ static int rx_audio_session_update_src(struct mtl_main_impl *impl, memcpy(ops->ip_addr[i], src->ip_addr[i], MTL_IP_ADDR_LEN); memcpy(ops->mcast_sip_addr[i], src->mcast_sip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = src->udp_port[i]; - s->st30_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); + s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); } /* reset seq id */ s->latest_seq_id = -1; @@ -1027,10 +980,9 @@ static int rx_audio_session_update_src(struct mtl_main_impl *impl, return 0; } -static int -rx_audio_sessions_mgr_update_src(struct st_rx_audio_sessions_mgr *mgr, - struct st_rx_audio_session_impl *s, - struct st_rx_source_info *src) { +static int rx_audio_sessions_mgr_update_src(struct st_rx_audio_sessions_mgr *mgr, + struct st_rx_audio_session_impl *s, + struct st_rx_source_info *src) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = rx_audio_session_get(mgr, idx); /* get the lock */ @@ -1055,8 +1007,7 @@ static int st_rx_audio_sessions_stat(void *priv) { for (int j = 0; j < mgr->max_idx; j++) { s = rx_audio_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) - continue; + if (!s) continue; rx_audio_session_stat(mgr, s); rx_audio_session_put(mgr, j); } @@ -1102,9 +1053,8 @@ static int rx_audio_session_init(struct st_rx_audio_sessions_mgr *mgr, return 0; } -static struct st_rx_audio_session_impl * -rx_audio_sessions_mgr_attach(struct mtl_sch_impl *sch, - struct st30_rx_ops *ops) { +static struct st_rx_audio_session_impl *rx_audio_sessions_mgr_attach( + struct mtl_sch_impl *sch, struct st30_rx_ops *ops) { struct st_rx_audio_sessions_mgr *mgr = &sch->rx_a_mgr; int midx = mgr->idx; int ret; @@ -1113,8 +1063,7 @@ rx_audio_sessions_mgr_attach(struct mtl_sch_impl *sch, /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_RX_AUDIO_SESSIONS; i++) { - if (!rx_audio_session_get_empty(mgr, i)) - continue; + if (!rx_audio_session_get_empty(mgr, i)) continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -1172,8 +1121,7 @@ static int rx_audio_sessions_mgr_update(struct st_rx_audio_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_SCH_MAX_RX_AUDIO_SESSIONS; i++) { - if (mgr->sessions[i]) - max_idx = i + 1; + if (mgr->sessions[i]) max_idx = i + 1; } mgr->max_idx = max_idx; @@ -1193,8 +1141,7 @@ static int rx_audio_sessions_mgr_uinit(struct st_rx_audio_sessions_mgr *mgr) { for (int i = 0; i < ST_SCH_MAX_RX_AUDIO_SESSIONS; i++) { s = rx_audio_session_get(mgr, i); - if (!s) - continue; + if (!s) continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); rx_audio_sessions_mgr_detach(mgr, s); @@ -1218,16 +1165,14 @@ static int rx_audio_ops_check(struct st30_rx_ops *ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -1265,12 +1210,10 @@ static int rx_audio_ops_check(struct st30_rx_ops *ops) { return 0; } -static int st_rx_audio_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { +static int st_rx_audio_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { int ret; - if (sch->rx_a_init) - return 0; + if (sch->rx_a_init) return 0; /* create rx audio context */ ret = rx_audio_sessions_mgr_init(impl, sch, &sch->rx_a_mgr); @@ -1284,8 +1227,7 @@ static int st_rx_audio_init(struct mtl_main_impl *impl, } int st_rx_audio_sessions_sch_uinit(struct mtl_sch_impl *sch) { - if (!sch->rx_a_init) - return 0; + if (!sch->rx_a_init) return 0; rx_audio_sessions_mgr_uinit(&sch->rx_a_mgr); @@ -1314,8 +1256,7 @@ st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops *ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30_RX_FLAG_FORCE_NUMA) { @@ -1329,10 +1270,9 @@ st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops *ops) { return NULL; } - quota_mbs = impl->main_sch->data_quota_mbs_limit / - impl->rx_audio_sessions_max_per_sch; - sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, - MT_SCH_MASK_ALL, socket); + quota_mbs = impl->main_sch->data_quota_mbs_limit / impl->rx_audio_sessions_max_per_sch; + sch = + mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -1371,8 +1311,7 @@ st30_rx_handle st30_rx_create(mtl_handle mt, struct st30_rx_ops *ops) { return s_impl; } -int st30_rx_update_source(st30_rx_handle handle, - struct st_rx_source_info *src) { +int st30_rx_update_source(st30_rx_handle handle, struct st_rx_source_info *src) { struct st_rx_audio_session_handle_impl *s_impl = handle; struct st_rx_audio_session_impl *s; struct mtl_sch_impl *sch; @@ -1389,8 +1328,7 @@ int st30_rx_update_source(st30_rx_handle handle, sch_idx = sch->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = rx_audio_sessions_mgr_update_src(&sch->rx_a_mgr, s, src); if (ret < 0) { @@ -1425,12 +1363,10 @@ int st30_rx_free(st30_rx_handle handle) { mt_pthread_mutex_lock(&sch->rx_a_mgr_mutex); ret = rx_audio_sessions_mgr_detach(&sch->rx_a_mgr, s); mt_pthread_mutex_unlock(&sch->rx_a_mgr_mutex); - if (ret < 0) - err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -1508,8 +1444,7 @@ void st30_rx_put_mbuf(st30_rx_handle handle, void *mbuf) { if (s_impl->type != MT_HANDLE_RX_AUDIO) err("%s, invalid type %d\n", __func__, s_impl->type); - if (pkt) - rte_pktmbuf_free(pkt); + if (pkt) rte_pktmbuf_free(pkt); } int st30_rx_get_queue_meta(st30_rx_handle handle, struct st_queue_meta *meta) { diff --git a/lib/src/st2110/st_rx_timing_parser.c b/lib/src/st2110/st_rx_timing_parser.c index 48b337618..30982fe6f 100644 --- a/lib/src/st2110/st_rx_timing_parser.c +++ b/lib/src/st2110/st_rx_timing_parser.c @@ -10,9 +10,9 @@ static inline float rv_tp_calculate_avg(uint32_t cnt, int64_t sum) { return cnt ? ((float)sum / cnt) : -1.0f; } -void rv_tp_on_packet(struct st_rx_video_session_impl *s, - enum mtl_session_port s_port, struct st_rv_tp_slot *slot, - uint32_t rtp_tmstamp, uint64_t pkt_time, int pkt_idx) { +void rv_tp_on_packet(struct st_rx_video_session_impl *s, enum mtl_session_port s_port, + struct st_rv_tp_slot *slot, uint32_t rtp_tmstamp, uint64_t pkt_time, + int pkt_idx) { struct st_rx_video_tp *tp = s->tp; uint64_t epoch_tmstamp; double tvd, trs = tp->trs; @@ -30,8 +30,7 @@ void rv_tp_on_packet(struct st_rx_video_session_impl *s, uint64_t tmstamp64 = epochs * s->frame_time_sampling; uint32_t tmstamp32 = tmstamp64; double diff_rtp_ts = (double)rtp_tmstamp - tmstamp32; - double diff_rtp_ts_ns = - diff_rtp_ts * s->frame_time / s->frame_time_sampling; + double diff_rtp_ts_ns = diff_rtp_ts * s->frame_time / s->frame_time_sampling; slot->meta.latency = slot->meta.fpt - diff_rtp_ts_ns; slot->meta.rtp_offset = diff_rtp_ts; if (tp->pre_rtp_tmstamp[s_port]) { @@ -51,8 +50,7 @@ void rv_tp_on_packet(struct st_rx_video_session_impl *s, slot->meta.vrx_max = RTE_MAX(vrx_cur, slot->meta.vrx_max); /* Calculate C-inst */ - int exp_cin_pkts = - ((pkt_time - slot->first_pkt_time) / trs) * ST_TP_CINST_DRAIN_FACTOR; + int exp_cin_pkts = ((pkt_time - slot->first_pkt_time) / trs) * ST_TP_CINST_DRAIN_FACTOR; int cinst = RTE_MAX(0, pkt_idx - exp_cin_pkts); slot->cinst_sum += cinst; slot->meta.cinst_min = RTE_MIN(cinst, slot->meta.cinst_min); @@ -71,8 +69,7 @@ void rv_tp_on_packet(struct st_rx_video_session_impl *s, slot->meta.pkts_cnt++; } -static void rv_tp_compliant_set_cause(struct st20_rx_tp_meta *meta, - char *cause) { +static void rv_tp_compliant_set_cause(struct st20_rx_tp_meta *meta, char *cause) { snprintf(meta->failed_cause, sizeof(meta->failed_cause), "%s", cause); } @@ -141,8 +138,7 @@ static enum st_rx_tp_compliant rv_tp_compliant(struct st_rx_video_tp *tp, } void rv_tp_slot_parse_result(struct st_rx_video_session_impl *s, - enum mtl_session_port s_port, - struct st_rv_tp_slot *slot) { + enum mtl_session_port s_port, struct st_rv_tp_slot *slot) { struct st_rx_video_tp *tp = s->tp; float cinst_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->cinst_sum); float vrx_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->vrx_sum); @@ -151,20 +147,18 @@ void rv_tp_slot_parse_result(struct st_rx_video_session_impl *s, slot->meta.cinst_avg = cinst_avg; slot->meta.vrx_avg = vrx_avg; slot->meta.ipt_avg = ipt_avg; - dbg("%s(%d), Cinst AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, - cinst_avg, slot->cinst_min, slot->cinst_max, - rv_tp_cinst_result(tp, slot)); - dbg("%s(%d), VRX AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, - vrx_avg, slot->vrx_min, slot->vrx_max, rv_tp_vrx_result(tp, slot)); - dbg("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, - s->idx, ipt_avg, slot->ipt_min, slot->ipt_max); + dbg("%s(%d), Cinst AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, cinst_avg, + slot->cinst_min, slot->cinst_max, rv_tp_cinst_result(tp, slot)); + dbg("%s(%d), VRX AVG %.2f MIN %d MAX %d test %s!\n", __func__, s->idx, vrx_avg, + slot->vrx_min, slot->vrx_max, rv_tp_vrx_result(tp, slot)); + dbg("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, s->idx, + ipt_avg, slot->ipt_min, slot->ipt_max); /* parse tp compliant for current frame */ enum st_rx_tp_compliant compliant = rv_tp_compliant(tp, slot); slot->meta.compliant = compliant; - if (!s->enable_timing_parser_stat) - return; + if (!s->enable_timing_parser_stat) return; /* update stat */ struct st_rv_tp_stat *stat = &tp->stat[s_port]; @@ -173,20 +167,14 @@ void rv_tp_slot_parse_result(struct st_rx_video_session_impl *s, stat->stat_compliant_result[compliant]++; stat_slot->vrx_sum += slot->vrx_sum; - stat_slot->meta.vrx_min = - RTE_MIN(stat_slot->meta.vrx_min, slot->meta.vrx_min); - stat_slot->meta.vrx_max = - RTE_MAX(stat_slot->meta.vrx_min, slot->meta.vrx_max); + stat_slot->meta.vrx_min = RTE_MIN(stat_slot->meta.vrx_min, slot->meta.vrx_min); + stat_slot->meta.vrx_max = RTE_MAX(stat_slot->meta.vrx_min, slot->meta.vrx_max); stat_slot->cinst_sum += slot->cinst_sum; - stat_slot->meta.cinst_min = - RTE_MIN(stat_slot->meta.cinst_min, slot->meta.cinst_min); - stat_slot->meta.cinst_max = - RTE_MAX(stat_slot->meta.cinst_max, slot->meta.cinst_max); + stat_slot->meta.cinst_min = RTE_MIN(stat_slot->meta.cinst_min, slot->meta.cinst_min); + stat_slot->meta.cinst_max = RTE_MAX(stat_slot->meta.cinst_max, slot->meta.cinst_max); stat_slot->ipt_sum += slot->ipt_sum; - stat_slot->meta.ipt_min = - RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); - stat_slot->meta.ipt_max = - RTE_MAX(stat_slot->meta.ipt_min, slot->meta.ipt_max); + stat_slot->meta.ipt_min = RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); + stat_slot->meta.ipt_max = RTE_MAX(stat_slot->meta.ipt_min, slot->meta.ipt_max); stat_slot->meta.pkts_cnt += slot->meta.pkts_cnt; stat->stat_fpt_min = RTE_MIN(stat->stat_fpt_min, slot->meta.fpt); @@ -195,10 +183,8 @@ void rv_tp_slot_parse_result(struct st_rx_video_session_impl *s, stat->stat_latency_min = RTE_MIN(stat->stat_latency_min, slot->meta.latency); stat->stat_latency_max = RTE_MAX(stat->stat_latency_max, slot->meta.latency); stat->stat_latency_sum += slot->meta.latency; - stat->stat_rtp_offset_min = - RTE_MIN(stat->stat_rtp_offset_min, slot->meta.rtp_offset); - stat->stat_rtp_offset_max = - RTE_MAX(stat->stat_rtp_offset_max, slot->meta.rtp_offset); + stat->stat_rtp_offset_min = RTE_MIN(stat->stat_rtp_offset_min, slot->meta.rtp_offset); + stat->stat_rtp_offset_max = RTE_MAX(stat->stat_rtp_offset_max, slot->meta.rtp_offset); stat->stat_rtp_offset_sum += slot->meta.rtp_offset; if (slot->meta.rtp_ts_delta) { stat->stat_rtp_ts_delta_min = @@ -232,47 +218,39 @@ static void rv_tp_stat_init(struct st_rx_video_session_impl *s, void rv_tp_stat(struct st_rx_video_session_impl *s) { int idx = s->idx; struct st_rx_video_tp *tp = s->tp; - if (!tp) - return; + if (!tp) return; for (int s_port = 0; s_port < s->ops.num_port; s_port++) { struct st_rv_tp_stat *stat = &tp->stat[s_port]; struct st_rv_tp_slot *stat_slot = &stat->slot; - info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, - s_port, stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], + info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, s_port, + stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_WIDE], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED]); - float cinst_avg = - rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->cinst_sum); - float vrx_avg = - rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->vrx_sum); - float ipt_avg = - rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); + float cinst_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->cinst_sum); + float vrx_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->vrx_sum); + float ipt_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); info("%s(%d), Cinst AVG %.2f MIN %d MAX %d!\n", __func__, idx, cinst_avg, stat_slot->meta.cinst_min, stat_slot->meta.cinst_max); info("%s(%d), VRX AVG %.2f MIN %d MAX %d!\n", __func__, idx, vrx_avg, stat_slot->meta.vrx_min, stat_slot->meta.vrx_max); - info("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, - idx, ipt_avg, stat_slot->meta.ipt_min, stat_slot->meta.ipt_max); - float fpt_avg = - rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_fpt_sum); - info("%s(%d), FPT AVG %.2f MIN %d MAX %d DIFF %d!\n", __func__, idx, - fpt_avg, stat->stat_fpt_min, stat->stat_fpt_max, - stat->stat_fpt_max - stat->stat_fpt_min); - float latency_avg = - rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_latency_sum); - info("%s(%d), LATENCY AVG %.2f MIN %d MAX %d!\n", __func__, idx, - latency_avg, stat->stat_latency_min, stat->stat_latency_max); + info("%s(%d), Inter-packet time(ns) AVG %.2f MIN %d MAX %d!\n", __func__, idx, + ipt_avg, stat_slot->meta.ipt_min, stat_slot->meta.ipt_max); + float fpt_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_fpt_sum); + info("%s(%d), FPT AVG %.2f MIN %d MAX %d DIFF %d!\n", __func__, idx, fpt_avg, + stat->stat_fpt_min, stat->stat_fpt_max, stat->stat_fpt_max - stat->stat_fpt_min); + float latency_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_latency_sum); + info("%s(%d), LATENCY AVG %.2f MIN %d MAX %d!\n", __func__, idx, latency_avg, + stat->stat_latency_min, stat->stat_latency_max); float rtp_offset_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_rtp_offset_sum); - info("%s(%d), RTP OFFSET AVG %.2f MIN %d MAX %d!\n", __func__, idx, - rtp_offset_avg, stat->stat_rtp_offset_min, stat->stat_rtp_offset_max); + info("%s(%d), RTP OFFSET AVG %.2f MIN %d MAX %d!\n", __func__, idx, rtp_offset_avg, + stat->stat_rtp_offset_min, stat->stat_rtp_offset_max); float rtp_ts_delta_avg = rv_tp_calculate_avg(stat->stat_frame_cnt, stat->stat_rtp_ts_delta_sum); info("%s(%d), RTP TS DELTA AVG %.2f MIN %d MAX %d!\n", __func__, idx, - rtp_ts_delta_avg, stat->stat_rtp_ts_delta_min, - stat->stat_rtp_ts_delta_max); + rtp_ts_delta_avg, stat->stat_rtp_ts_delta_min, stat->stat_rtp_ts_delta_max); } rv_tp_stat_init(s, tp); @@ -335,8 +313,8 @@ int rv_tp_init(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { } tp->trs = frame_time * reactive / st20_total_pkts; if (!ops->interlaced) { - tp->pass.tr_offset = ops->height >= 1080 ? frame_time * (43.0 / 1125.0) - : frame_time * (28.0 / 750.0); + tp->pass.tr_offset = + ops->height >= 1080 ? frame_time * (43.0 / 1125.0) : frame_time * (28.0 / 750.0); } else { if (ops->height == 480) { tp->pass.tr_offset = frame_time * (20.0 / 525.0) * 2; @@ -349,18 +327,15 @@ int rv_tp_init(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { tp->pass.cinst_max_narrow = RTE_MAX(4, (double)st20_total_pkts / (43200 * reactive * frame_time_s)); - tp->pass.cinst_max_wide = - RTE_MAX(16, (double)st20_total_pkts / (21600 * frame_time_s)); + tp->pass.cinst_max_wide = RTE_MAX(16, (double)st20_total_pkts / (21600 * frame_time_s)); tp->pass.cinst_min = 0; - tp->pass.vrx_max_narrow = - RTE_MAX(8, st20_total_pkts / (27000 * frame_time_s)); + tp->pass.vrx_max_narrow = RTE_MAX(8, st20_total_pkts / (27000 * frame_time_s)); tp->pass.vrx_max_wide = RTE_MAX(720, st20_total_pkts / (300 * frame_time_s)); tp->pass.vrx_min = 0; tp->pass.latency_max = 1000 * 1000; /* 1000 us */ tp->pass.latency_min = 0; tp->pass.rtp_offset_max = - ceil((double)tp->pass.tr_offset * fps_tm.sampling_clock_rate / NS_PER_S) + - 1; + ceil((double)tp->pass.tr_offset * fps_tm.sampling_clock_rate / NS_PER_S) + 1; tp->pass.rtp_offset_min = -1; int32_t sampling = s->frame_time_sampling; tp->pass.rtp_ts_delta_max = sampling + 1; @@ -370,11 +345,12 @@ int rv_tp_init(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { info("%s[%02d], trs %f tr offset %d sampling %f\n", __func__, idx, tp->trs, tp->pass.tr_offset, s->frame_time_sampling); - info("%s[%02d], cinst_max_narrow %d cinst_max_wide %d vrx_max_narrow %d " - "vrx_max_wide %d " - "rtp_offset_max %d\n", - __func__, idx, tp->pass.cinst_max_narrow, tp->pass.cinst_max_wide, - tp->pass.vrx_max_narrow, tp->pass.vrx_max_wide, tp->pass.rtp_offset_max); + info( + "%s[%02d], cinst_max_narrow %d cinst_max_wide %d vrx_max_narrow %d " + "vrx_max_wide %d " + "rtp_offset_max %d\n", + __func__, idx, tp->pass.cinst_max_narrow, tp->pass.cinst_max_wide, + tp->pass.vrx_max_narrow, tp->pass.vrx_max_wide, tp->pass.rtp_offset_max); return 0; } @@ -389,8 +365,7 @@ static void ra_tp_stat_init(struct st_rx_audio_tp *tp) { } } -static void ra_tp_compliant_set_cause(struct st30_rx_tp_meta *meta, - char *cause) { +static void ra_tp_compliant_set_cause(struct st30_rx_tp_meta *meta, char *cause) { snprintf(meta->failed_cause, sizeof(meta->failed_cause), "%s", cause); } @@ -433,12 +408,11 @@ void ra_tp_slot_parse_result(struct st_rx_audio_session_impl *s, dbg("%s(%d,%d), start\n", __func__, s->idx, s_port); slot->meta.ipt_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->ipt_sum); - slot->meta.dpvr_avg = - rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->dpvr_sum); + slot->meta.dpvr_avg = rv_tp_calculate_avg(slot->meta.pkts_cnt, slot->dpvr_sum); /* calculate tsdf */ - int32_t tsdf = (slot->meta.dpvr_max - slot->dpvr_first) - - (slot->meta.dpvr_min - slot->dpvr_first); + int32_t tsdf = + (slot->meta.dpvr_max - slot->dpvr_first) - (slot->meta.dpvr_min - slot->dpvr_first); slot->meta.tsdf = tsdf; /* parse tp compliant for current frame */ @@ -456,26 +430,20 @@ void ra_tp_slot_parse_result(struct st_rx_audio_session_impl *s, stat->tsdf_cnt++; stat_slot->dpvr_sum += slot->dpvr_sum; - stat_slot->meta.dpvr_min = - RTE_MIN(stat_slot->meta.dpvr_min, slot->meta.dpvr_min); - stat_slot->meta.dpvr_max = - RTE_MAX(stat_slot->meta.dpvr_max, slot->meta.dpvr_max); + stat_slot->meta.dpvr_min = RTE_MIN(stat_slot->meta.dpvr_min, slot->meta.dpvr_min); + stat_slot->meta.dpvr_max = RTE_MAX(stat_slot->meta.dpvr_max, slot->meta.dpvr_max); - if (!stat_slot->dpvr_first) - stat_slot->dpvr_first = slot->dpvr_first; + if (!stat_slot->dpvr_first) stat_slot->dpvr_first = slot->dpvr_first; stat_slot->ipt_sum += slot->ipt_sum; - stat_slot->meta.ipt_min = - RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); - stat_slot->meta.ipt_max = - RTE_MAX(stat_slot->meta.ipt_max, slot->meta.ipt_max); + stat_slot->meta.ipt_min = RTE_MIN(stat_slot->meta.ipt_min, slot->meta.ipt_min); + stat_slot->meta.ipt_max = RTE_MAX(stat_slot->meta.ipt_max, slot->meta.ipt_max); stat_slot->meta.pkts_cnt += slot->meta.pkts_cnt; } -void ra_tp_on_packet(struct st_rx_audio_session_impl *s, - enum mtl_session_port s_port, uint32_t rtp_tmstamp, - uint64_t pkt_time) { +void ra_tp_on_packet(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port, + uint32_t rtp_tmstamp, uint64_t pkt_time) { struct st_rx_audio_tp *tp = s->tp; struct st_ra_tp_slot *slot = &tp->slot[s_port]; @@ -496,8 +464,7 @@ void ra_tp_on_packet(struct st_rx_audio_session_impl *s, slot->meta.dpvr_max = RTE_MAX(dpvr, slot->meta.dpvr_max); slot->dpvr_sum += dpvr; - if (!slot->dpvr_first) - slot->dpvr_first = dpvr; + if (!slot->dpvr_first) slot->dpvr_first = dpvr; if (tp->prev_pkt_time[s_port]) { double ipt = (double)pkt_time - tp->prev_pkt_time[s_port]; @@ -536,11 +503,12 @@ int ra_tp_init(struct mtl_main_impl *impl, struct st_rx_audio_session_impl *s) { tp->last_parse_time = mt_get_tsc(impl); - info("%s(%d), Delta Packet vs RTP Pass Criteria in us, narrow %d wide %d\n", - __func__, idx, tp->dpvr_max_pass_narrow, tp->dpvr_max_pass_wide); - info("%s(%d), Timestamped Delay Factor Pass Criteria in us, narrow %d wide " - "%d\n", - __func__, idx, tp->tsdf_max_pass_narrow, tp->tsdf_max_pass_wide); + info("%s(%d), Delta Packet vs RTP Pass Criteria in us, narrow %d wide %d\n", __func__, + idx, tp->dpvr_max_pass_narrow, tp->dpvr_max_pass_wide); + info( + "%s(%d), Timestamped Delay Factor Pass Criteria in us, narrow %d wide " + "%d\n", + __func__, idx, tp->tsdf_max_pass_narrow, tp->tsdf_max_pass_wide); return 0; } @@ -557,30 +525,26 @@ int ra_tp_uinit(struct st_rx_audio_session_impl *s) { void ra_tp_stat(struct st_rx_audio_session_impl *s) { int idx = s->idx; struct st_rx_audio_tp *tp = s->tp; - if (!tp) - return; + if (!tp) return; for (int s_port = 0; s_port < s->ops.num_port; s_port++) { struct st_ra_tp_stat *stat = &tp->stat[s_port]; struct st_ra_tp_slot *stat_slot = &stat->slot; - info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, - s_port, stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], + info("%s(%d,%d), COMPLIANT NARROW %d WIDE %d FAILED %d!\n", __func__, idx, s_port, + stat->stat_compliant_result[ST_RX_TP_COMPLIANT_NARROW], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_WIDE], stat->stat_compliant_result[ST_RX_TP_COMPLIANT_FAILED]); - float dpvr_avg = - rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->dpvr_sum); - info("%s(%d), dpvr(us) AVG %.2f MIN %d MAX %d, pkt_cnt %u\n", __func__, idx, - dpvr_avg, stat_slot->meta.dpvr_min, stat_slot->meta.dpvr_max, - stat_slot->meta.pkts_cnt); + float dpvr_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->dpvr_sum); + info("%s(%d), dpvr(us) AVG %.2f MIN %d MAX %d, pkt_cnt %u\n", __func__, idx, dpvr_avg, + stat_slot->meta.dpvr_min, stat_slot->meta.dpvr_max, stat_slot->meta.pkts_cnt); /* Maximum Timestamped Delay Factor */ float tsdf_avg = rv_tp_calculate_avg(stat->tsdf_cnt, stat->tsdf_sum); info("%s(%d), tsdf(us) AVG %.2f MIN %d MAX %d\n", __func__, idx, tsdf_avg, stat->tsdf_min, stat->tsdf_max); - float ipt_avg = - rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); + float ipt_avg = rv_tp_calculate_avg(stat_slot->meta.pkts_cnt, stat_slot->ipt_sum); info("%s(%d), ipt(ns) AVG %.2f MIN %d MAX %d\n", __func__, idx, ipt_avg, stat_slot->meta.ipt_min, stat_slot->meta.ipt_max); diff --git a/lib/src/st2110/st_rx_timing_parser.h b/lib/src/st2110/st_rx_timing_parser.h index bda980dfd..a8cb7e498 100644 --- a/lib/src/st2110/st_rx_timing_parser.h +++ b/lib/src/st2110/st_rx_timing_parser.h @@ -12,22 +12,20 @@ int rv_tp_uinit(struct st_rx_video_session_impl *s); void rv_tp_slot_init(struct st_rv_tp_slot *slot); -void rv_tp_on_packet(struct st_rx_video_session_impl *s, - enum mtl_session_port s_port, struct st_rv_tp_slot *slot, - uint32_t rtp_tmstamp, uint64_t pkt_time, int pkt_idx); +void rv_tp_on_packet(struct st_rx_video_session_impl *s, enum mtl_session_port s_port, + struct st_rv_tp_slot *slot, uint32_t rtp_tmstamp, uint64_t pkt_time, + int pkt_idx); void rv_tp_slot_parse_result(struct st_rx_video_session_impl *s, - enum mtl_session_port s_port, - struct st_rv_tp_slot *slot); + enum mtl_session_port s_port, struct st_rv_tp_slot *slot); void rv_tp_stat(struct st_rx_video_session_impl *s); int ra_tp_init(struct mtl_main_impl *impl, struct st_rx_audio_session_impl *s); int ra_tp_uinit(struct st_rx_audio_session_impl *s); -void ra_tp_on_packet(struct st_rx_audio_session_impl *s, - enum mtl_session_port s_port, uint32_t rtp_tmstamp, - uint64_t pkt_time); +void ra_tp_on_packet(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port, + uint32_t rtp_tmstamp, uint64_t pkt_time); void ra_tp_slot_parse_result(struct st_rx_audio_session_impl *s, enum mtl_session_port s_port); diff --git a/lib/src/st2110/st_rx_video_session.c b/lib/src/st2110/st_rx_video_session.c index debd7b861..be93d7cf5 100644 --- a/lib/src/st2110/st_rx_video_session.c +++ b/lib/src/st2110/st_rx_video_session.c @@ -18,8 +18,7 @@ static int rv_init_pkt_handler(struct st_rx_video_session_impl *s); static int rvs_mgr_update(struct st_rx_video_sessions_mgr *mgr); -static inline struct mtl_main_impl * -rv_get_impl(struct st_rx_video_session_impl *s) { +static inline struct mtl_main_impl *rv_get_impl(struct st_rx_video_session_impl *s) { return s->parent->parent; } @@ -46,65 +45,64 @@ static int rv_detector_init(struct st_rx_video_session_impl *s) { return 0; } -static void -rv_detector_calculate_dimension(struct st_rx_video_session_impl *s, - struct st_rx_video_detector *detector, - int max_line_num) { +static void rv_detector_calculate_dimension(struct st_rx_video_session_impl *s, + struct st_rx_video_detector *detector, + int max_line_num) { struct st20_detect_meta *meta = &detector->meta; dbg("%s(%d), interlaced %d, max_line_num %d\n", __func__, s->idx, meta->interlaced ? 1 : 0, max_line_num); if (meta->interlaced) { switch (max_line_num) { - case 539: - meta->height = 1080; - meta->width = 1920; - break; - case 239: - meta->height = 480; - meta->width = 640; - break; - case 359: - meta->height = 720; - meta->width = 1280; - break; - case 1079: - meta->height = 2160; - meta->width = 3840; - break; - case 2159: - meta->height = 4320; - meta->width = 7680; - break; - default: - err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); - break; + case 539: + meta->height = 1080; + meta->width = 1920; + break; + case 239: + meta->height = 480; + meta->width = 640; + break; + case 359: + meta->height = 720; + meta->width = 1280; + break; + case 1079: + meta->height = 2160; + meta->width = 3840; + break; + case 2159: + meta->height = 4320; + meta->width = 7680; + break; + default: + err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); + break; } } else { switch (max_line_num) { - case 1079: - meta->height = 1080; - meta->width = 1920; - break; - case 479: - meta->height = 480; - meta->width = 640; - break; - case 719: - meta->height = 720; - meta->width = 1280; - break; - case 2159: - meta->height = 2160; - meta->width = 3840; - break; - case 4319: - meta->height = 4320; - meta->width = 7680; - break; - default: - err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); - break; + case 1079: + meta->height = 1080; + meta->width = 1920; + break; + case 479: + meta->height = 480; + meta->width = 640; + break; + case 719: + meta->height = 720; + meta->width = 1280; + break; + case 2159: + meta->height = 2160; + meta->width = 3840; + break; + case 4319: + meta->height = 4320; + meta->width = 7680; + break; + default: + err("%s(%d), max_line_num %d\n", __func__, s->idx, max_line_num); + break; } } } @@ -118,53 +116,52 @@ static void rv_detector_calculate_fps(struct st_rx_video_session_impl *s, if (abs(d0 - d1) <= 1) { dbg("%s(%d), d0 = %d, d1 = %d\n", __func__, s->idx, d0, d1); switch (d0) { - case 750: - meta->fps = ST_FPS_P120; - return; - case 751: - meta->fps = ST_FPS_P119_88; - return; - case 900: - meta->fps = ST_FPS_P100; - return; - case 1500: - meta->fps = ST_FPS_P60; - return; - case 1501: - case 1502: - meta->fps = ST_FPS_P59_94; - return; - case 1800: - meta->fps = ST_FPS_P50; - return; - case 3000: - meta->fps = ST_FPS_P30; - return; - case 3003: - meta->fps = ST_FPS_P29_97; - return; - case 3600: - meta->fps = ST_FPS_P25; - return; - case 3750: - meta->fps = ST_FPS_P24; - return; - case 3753: - case 3754: - meta->fps = ST_FPS_P23_98; - return; - default: - err("%s(%d), err d0 %d d1 %d\n", __func__, s->idx, d0, d1); - break; + case 750: + meta->fps = ST_FPS_P120; + return; + case 751: + meta->fps = ST_FPS_P119_88; + return; + case 900: + meta->fps = ST_FPS_P100; + return; + case 1500: + meta->fps = ST_FPS_P60; + return; + case 1501: + case 1502: + meta->fps = ST_FPS_P59_94; + return; + case 1800: + meta->fps = ST_FPS_P50; + return; + case 3000: + meta->fps = ST_FPS_P30; + return; + case 3003: + meta->fps = ST_FPS_P29_97; + return; + case 3600: + meta->fps = ST_FPS_P25; + return; + case 3750: + meta->fps = ST_FPS_P24; + return; + case 3753: + case 3754: + meta->fps = ST_FPS_P23_98; + return; + default: + err("%s(%d), err d0 %d d1 %d\n", __func__, s->idx, d0, d1); + break; } } else { err("%s(%d), err d0 %d d1 %d\n", __func__, s->idx, d0, d1); } } -static void -rv_detector_calculate_n_packet(struct st_rx_video_session_impl *s, - struct st_rx_video_detector *detector) { +static void rv_detector_calculate_n_packet(struct st_rx_video_session_impl *s, + struct st_rx_video_detector *detector) { int total0 = detector->pkt_num[1] - detector->pkt_num[0]; int total1 = detector->pkt_num[2] - detector->pkt_num[1]; @@ -175,8 +172,7 @@ rv_detector_calculate_n_packet(struct st_rx_video_session_impl *s, } } -static void -rv_detector_calculate_packing(struct st_rx_video_detector *detector) { +static void rv_detector_calculate_packing(struct st_rx_video_detector *detector) { struct st20_detect_meta *meta = &detector->meta; if (detector->bpm) @@ -227,8 +223,7 @@ static int rv_put_frame(struct st_rx_video_session_impl *s, static int rv_uinit_hdr_split_frame(struct st_rx_video_session_impl *s) { for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { if (s->hdr_split_info[i].frames) { - if (!s->ops.ext_frames) - mt_rte_free(s->hdr_split_info[i].frames); + if (!s->ops.ext_frames) mt_rte_free(s->hdr_split_info[i].frames); s->hdr_split_info[i].frames = NULL; } } @@ -245,8 +240,7 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl *s) { uint32_t mbufs_total; mbufs_per_frame = frame_size / ST_VIDEO_BPM_SIZE; - if (frame_size % ST_VIDEO_BPM_SIZE) - mbufs_per_frame++; + if (frame_size % ST_VIDEO_BPM_SIZE) mbufs_per_frame++; mbufs_total = mbufs_per_frame * s->st20_frames_cnt; /* extra mbufs since frame may not start from zero pos */ mbufs_total += (mbufs_per_frame - 1); @@ -280,8 +274,8 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl *s) { return -EIO; } if (ext_frame->buf_len < malloc_size) { - err("%s(%d, %d), ext frames size too small, need %" PRIu64 - " but only %" PRIu64 "\n", + err("%s(%d, %d), ext frames size too small, need %" PRIu64 " but only %" PRIu64 + "\n", __func__, idx, i, malloc_size, ext_frame->buf_len); rv_uinit_hdr_split_frame(s); return -EIO; @@ -289,8 +283,8 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl *s) { } else { frames = mt_rte_zmalloc_socket(malloc_size, soc_id); if (!frames) { - err("%s(%d), frames malloc fail for %d, mbufs_total %u\n", __func__, - idx, i, mbufs_total); + err("%s(%d), frames malloc fail for %d, mbufs_total %u\n", __func__, idx, i, + mbufs_total); rv_uinit_hdr_split_frame(s); return -ENOMEM; } @@ -301,9 +295,8 @@ static int rv_init_hdr_split_frame(struct st_rx_video_session_impl *s) { s->hdr_split_info[i].frames_size = frames_size; s->hdr_split_info[i].mbufs_per_frame = mbufs_per_frame; s->hdr_split_info[i].mbufs_total = mbufs_total; - info("%s(%d,%d), frames (%p-%p), mbufs_total %u, iova %" PRIx64 "\n", - __func__, idx, i, frames, frames + frames_size, mbufs_total, - s->hdr_split_info[i].frames_iova); + info("%s(%d,%d), frames (%p-%p), mbufs_total %u, iova %" PRIx64 "\n", __func__, idx, + i, frames, frames + frames_size, mbufs_total, s->hdr_split_info[i].frames_iova); } return 0; @@ -329,8 +322,7 @@ static int rv_free_frames(struct st_rx_video_session_impl *s) { static rte_iova_t rv_frame_get_offset_iova(struct st_rx_video_session_impl *s, struct st_frame_trans *frame_info, size_t offset) { - if (frame_info->page_table_len == 0) - return frame_info->iova + offset; + if (frame_info->page_table_len == 0) return frame_info->iova + offset; void *addr = RTE_PTR_ADD(frame_info->addr, offset); struct st_page_info *page; for (uint16_t i = 0; i < frame_info->page_table_len; i++) { @@ -339,8 +331,8 @@ static rte_iova_t rv_frame_get_offset_iova(struct st_rx_video_session_impl *s, return page->iova + RTE_PTR_DIFF(addr, page->addr); } - err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, - frame_info->idx, offset); + err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, frame_info->idx, + offset); return MTL_BAD_IOVA; } @@ -352,22 +344,19 @@ static int rv_frame_create_page_table(struct st_rx_video_session_impl *s, return -EIO; } size_t hugepage_sz = mseg->hugepage_sz; - info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, - frame_info->idx, hugepage_sz); + info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, frame_info->idx, + hugepage_sz); /* calculate num hugepages */ uint16_t num_pages = - RTE_PTR_DIFF( - RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), - RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / + RTE_PTR_DIFF(RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), + RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / hugepage_sz; int soc_id = s->socket_id; - struct st_page_info *pages = - mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); + struct st_page_info *pages = mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); if (pages == NULL) { - err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, - frame_info->idx); + err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, frame_info->idx); return -ENOMEM; } @@ -381,9 +370,8 @@ static int rv_frame_create_page_table(struct st_rx_video_session_impl *s, void *next_addr = RTE_PTR_ALIGN(RTE_PTR_ADD(addr, 1), hugepage_sz); pages[i].len = RTE_PTR_DIFF(next_addr, addr); addr = next_addr; - info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", - __func__, s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, - pages[i].len); + info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", __func__, + s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, pages[i].len); } frame_info->page_table = pages; frame_info->page_table_len = num_pages; @@ -391,12 +379,10 @@ static int rv_frame_create_page_table(struct st_rx_video_session_impl *s, return 0; } -static inline bool -rv_frame_payload_cross_page(struct st_rx_video_session_impl *s, - struct st_frame_trans *frame_info, size_t offset, - size_t len) { - if (frame_info->page_table_len == 0) - return false; +static inline bool rv_frame_payload_cross_page(struct st_rx_video_session_impl *s, + struct st_frame_trans *frame_info, + size_t offset, size_t len) { + if (frame_info->page_table_len == 0) return false; return ((rv_frame_get_offset_iova(s, frame_info, offset + len - 1) - rv_frame_get_offset_iova(s, frame_info, offset)) != len - 1); } @@ -410,8 +396,8 @@ static int rv_alloc_frames(struct mtl_main_impl *impl, void *frame; int ret; - s->st20_frames = mt_rte_zmalloc_socket( - sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); + s->st20_frames = + mt_rte_zmalloc_socket(sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); if (!s->st20_frames) { err("%s(%d), st20_frames alloc fail\n", __func__, idx); return -ENOMEM; @@ -454,8 +440,8 @@ static int rv_alloc_frames(struct mtl_main_impl *impl, st20_frame->addr = frame; st20_frame->iova = frame_iova; st20_frame->flags = ST_FT_FLAG_EXT; - info("%s(%d), attach external frame %d, addr %p, iova %" PRIu64 "\n", - __func__, idx, i, frame, frame_iova); + info("%s(%d), attach external frame %d, addr %p, iova %" PRIu64 "\n", __func__, idx, + i, frame, frame_iova); } else if (rv_is_dynamic_ext_frame(s)) { st20_frame->iova = 0; /* detect later */ st20_frame->addr = NULL; @@ -463,8 +449,7 @@ static int rv_alloc_frames(struct mtl_main_impl *impl, } else { frame = mt_rte_zmalloc_socket(size, soc_id); if (!frame) { - err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, - size, i); + err("%s(%d), frame malloc %" PRIu64 " fail for %d\n", __func__, idx, size, i); rv_free_frames(s); return -ENOMEM; } @@ -514,8 +499,7 @@ static int rv_alloc_rtps(struct st_rx_video_sessions_mgr *mgr, int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_RTP", ST_RX_VIDEO_PREFIX, mgr_idx, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ops.rtp_ring_size; if (count <= 0) { err("%s(%d,%d), invalid rtp_ring_size %d\n", __func__, mgr_idx, idx, count); @@ -533,24 +517,21 @@ static int rv_alloc_rtps(struct st_rx_video_sessions_mgr *mgr, #ifdef ST_HAS_DPDK_HDR_SPLIT /* run within the context of receiver lcore */ -static int rv_hdrs_mbuf_callback_fn(void *priv, - struct rte_eth_hdrs_mbuf *mbuf) { +static int rv_hdrs_mbuf_callback_fn(void *priv, struct rte_eth_hdrs_mbuf *mbuf) { struct st_rx_video_session_impl *s = priv; - struct st_rx_video_hdr_split_info *hdr_split = - &s->hdr_split_info[MTL_SESSION_PORT_P]; + struct st_rx_video_hdr_split_info *hdr_split = &s->hdr_split_info[MTL_SESSION_PORT_P]; uint32_t alloc_idx = hdr_split->mbuf_alloc_idx; uint32_t cur_frame_mbuf_idx = hdr_split->cur_frame_mbuf_idx; if (cur_frame_mbuf_idx) { - uint32_t next_frame_start_idx = - cur_frame_mbuf_idx + hdr_split->mbufs_per_frame; + uint32_t next_frame_start_idx = cur_frame_mbuf_idx + hdr_split->mbufs_per_frame; if (alloc_idx == next_frame_start_idx) { /* start of next frame, reset if remaining frame space is capable one * frame */ if ((alloc_idx + hdr_split->mbufs_per_frame) >= hdr_split->mbufs_total) { - dbg("%s(%d), idx reset at idx %u, cur_frame_mbuf_idx %u\n", __func__, - s->idx, alloc_idx, cur_frame_mbuf_idx); + dbg("%s(%d), idx reset at idx %u, cur_frame_mbuf_idx %u\n", __func__, s->idx, + alloc_idx, cur_frame_mbuf_idx); /* notify for mismatch frame address */ if (cur_frame_mbuf_idx % hdr_split->mbufs_per_frame) { dbg("%s(%d), idx reset for mismatch frame at idx %u, " @@ -564,8 +545,7 @@ static int rv_hdrs_mbuf_callback_fn(void *priv, uint32_t remaining_mbufs = hdr_split->mbufs_total - alloc_idx; if (remaining_mbufs < hdr_split->mbufs_per_frame) { /* all mbuf ready, start from zero */ - info("%s(%d), alloc idx reset at %u as pool ready\n", __func__, s->idx, - alloc_idx); + info("%s(%d), alloc idx reset at %u as pool ready\n", __func__, s->idx, alloc_idx); alloc_idx = 0; hdr_split->mbuf_pool_ready = true; } @@ -573,8 +553,7 @@ static int rv_hdrs_mbuf_callback_fn(void *priv, mbuf->buf_addr = hdr_split->frames + alloc_idx * ST_VIDEO_BPM_SIZE; mbuf->buf_iova = hdr_split->frames_iova + alloc_idx * ST_VIDEO_BPM_SIZE; - dbg("%s(%d), mbuf alloc idx %u, buf %p\n", __func__, s->idx, alloc_idx, - mbuf->buf_addr); + dbg("%s(%d), mbuf alloc idx %u, buf %p\n", __func__, s->idx, alloc_idx, mbuf->buf_addr); /* point to next alloc_idx */ alloc_idx++; @@ -596,8 +575,7 @@ static inline void rv_slot_init_frame_size(struct st_rx_video_slot_impl *slot) { slot->pkt_lcore_frame_recv_size = 0; } -static inline size_t -rv_slot_get_frame_size(struct st_rx_video_slot_impl *slot) { +static inline size_t rv_slot_get_frame_size(struct st_rx_video_slot_impl *slot) { return slot->frame_recv_size + slot->pkt_lcore_frame_recv_size; } @@ -606,9 +584,8 @@ static inline void rv_slot_add_frame_size(struct st_rx_video_slot_impl *slot, slot->frame_recv_size += size; } -static inline void -rv_slot_pkt_lcore_add_frame_size(struct st_rx_video_slot_impl *slot, - size_t size) { +static inline void rv_slot_pkt_lcore_add_frame_size(struct st_rx_video_slot_impl *slot, + size_t size) { slot->pkt_lcore_frame_recv_size += size; } @@ -617,9 +594,8 @@ void rv_slot_dump(struct st_rx_video_session_impl *s) { for (int i = 0; i < ST_VIDEO_RX_REC_NUM_OFO; i++) { slot = &s->slots[i]; - info("%s(%d), tmstamp %u recv_size %" PRIu64 " pkts_received %u\n", - __func__, i, slot->tmstamp, rv_slot_get_frame_size(slot), - slot->pkts_received); + info("%s(%d), tmstamp %u recv_size %" PRIu64 " pkts_received %u\n", __func__, i, + slot->tmstamp, rv_slot_get_frame_size(slot), slot->pkts_received); } } @@ -674,8 +650,7 @@ static int rv_init_slot(struct st_rx_video_session_impl *s) { slot->seq_id_got = false; frame_bitmap = mt_rte_zmalloc_socket(bitmap_size, soc_id); if (!frame_bitmap) { - err("%s(%d), bitmap malloc %" PRIu64 " fail\n", __func__, idx, - bitmap_size); + err("%s(%d), bitmap malloc %" PRIu64 " fail\n", __func__, idx, bitmap_size); return -ENOMEM; } slot->frame_bitmap = frame_bitmap; @@ -699,40 +674,34 @@ static int rv_init_slot(struct st_rx_video_session_impl *s) { return 0; } -static inline int rv_notify_frame_ready(struct st_rx_video_session_impl *s, - void *frame, +static inline int rv_notify_frame_ready(struct st_rx_video_session_impl *s, void *frame, struct st20_rx_frame_meta *meta) { int ret; uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(s->impl); - if (time_measure) - tsc_start = mt_get_tsc(s->impl); + if (time_measure) tsc_start = mt_get_tsc(s->impl); ret = s->ops.notify_frame_ready(s->ops.priv, frame, meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(s->impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = - RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); } return ret; } -static inline int st22_notify_frame_ready(struct st_rx_video_session_impl *s, - void *frame, +static inline int st22_notify_frame_ready(struct st_rx_video_session_impl *s, void *frame, struct st22_rx_frame_meta *meta) { int ret; uint64_t tsc_start = 0; struct st22_rx_video_info *st22_info = s->st22_info; bool time_measure = mt_sessions_time_measure(s->impl); - if (time_measure) - tsc_start = mt_get_tsc(s->impl); + if (time_measure) tsc_start = mt_get_tsc(s->impl); ret = st22_info->notify_frame_ready(s->ops.priv, frame, meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(s->impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = - RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); } return ret; @@ -749,8 +718,8 @@ static int rv_usdt_dump_frame(struct mtl_main_impl *impl, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20rx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, - ops->width, ops->height); + "imtl_usdt_st20rx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -762,8 +731,7 @@ static int rv_usdt_dump_frame(struct mtl_main_impl *impl, if (n != s->st20_frame_size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST20_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, - n); + MT_USDT_ST20_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -783,8 +751,8 @@ static int rv_st22_usdt_dump_frame(struct mtl_main_impl *impl, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22rx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, - ops->width, ops->height); + "imtl_usdt_st22rx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".raw")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -796,8 +764,7 @@ static int rv_st22_usdt_dump_frame(struct mtl_main_impl *impl, if (n != size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST22_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, - n); + MT_USDT_ST22_RX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -848,8 +815,8 @@ static void rv_frame_notify(struct st_rx_video_session_impl *s, meta->uframe_total_size = s->st20_uframe_size; meta->frame_recv_size = rv_slot_get_frame_size(slot); meta->pkts_total = slot->pkts_received; - for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; - s_port < MTL_SESSION_PORT_MAX; s_port++) { + for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; s_port < MTL_SESSION_PORT_MAX; + s_port++) { meta->pkts_recv[s_port] = slot->pkts_recv_per_port[s_port]; } meta->rtp_timestamp = slot->tmstamp; @@ -862,9 +829,8 @@ static void rv_frame_notify(struct st_rx_video_session_impl *s, meta->user_meta = NULL; } - MT_USDT_ST20_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, - frame->addr, slot->tmstamp, - meta->frame_recv_size); + MT_USDT_ST20_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, frame->addr, + slot->tmstamp, meta->frame_recv_size); /* check if dump USDT enabled */ if (MT_USDT_ST20_RX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -879,8 +845,7 @@ static void rv_frame_notify(struct st_rx_video_session_impl *s, if (meta->frame_recv_size >= s->st20_frame_size) { meta->status = ST_FRAME_STATUS_COMPLETE; if (ops->num_port > 1) { - if ((slot->pkts_recv_per_port[MTL_SESSION_PORT_P] < - slot->pkts_received) && + if ((slot->pkts_recv_per_port[MTL_SESSION_PORT_P] < slot->pkts_received) && (slot->pkts_recv_per_port[MTL_SESSION_PORT_R] < slot->pkts_received)) meta->status = ST_FRAME_STATUS_RECONSTRUCTED; } @@ -900,21 +865,16 @@ static void rv_frame_notify(struct st_rx_video_session_impl *s, double reactive = 1080.0 / 1125.0; s->trs = s->frame_time * reactive / meta->pkts_total; } else { - dbg("%s(%d): frame_recv_size %" PRIu64 ", frame_total_size %" PRIu64 - ", tmstamp %u\n", - __func__, s->idx, meta->frame_recv_size, meta->frame_total_size, - slot->tmstamp); - MT_USDT_ST20_RX_FRAME_INCOMPLETE(s->parent->idx, s->idx, frame->idx, - slot->tmstamp, meta->frame_recv_size, - s->st20_frame_size); + dbg("%s(%d): frame_recv_size %" PRIu64 ", frame_total_size %" PRIu64 ", tmstamp %u\n", + __func__, s->idx, meta->frame_recv_size, meta->frame_total_size, slot->tmstamp); + MT_USDT_ST20_RX_FRAME_INCOMPLETE(s->parent->idx, s->idx, frame->idx, slot->tmstamp, + meta->frame_recv_size, s->st20_frame_size); meta->status = ST_FRAME_STATUS_CORRUPTED; s->stat_frames_dropped++; /* record the miss pkts */ float pd_sz_per_pkt = (float)meta->frame_recv_size / slot->pkts_received; - int miss_pkts = - (s->st20_frame_size - meta->frame_recv_size) / pd_sz_per_pkt; - dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, - miss_pkts); + int miss_pkts = (s->st20_frame_size - meta->frame_recv_size) / pd_sz_per_pkt; + dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, miss_pkts); s->stat_frames_pks_missed += miss_pkts; #if 0 /* for miss pkt detail */ int total_pkts = s->st20_frame_size / pd_sz_per_pkt; @@ -956,14 +916,13 @@ static void rv_st22_frame_notify(struct st_rx_video_session_impl *s, meta->frame_total_size = rv_slot_get_frame_size(slot); meta->status = status; meta->pkts_total = slot->pkts_received; - for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; - s_port < MTL_SESSION_PORT_MAX; s_port++) { + for (enum mtl_session_port s_port = MTL_SESSION_PORT_P; s_port < MTL_SESSION_PORT_MAX; + s_port++) { meta->pkts_recv[s_port] = slot->pkts_recv_per_port[s_port]; } - MT_USDT_ST22_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, - frame->addr, slot->tmstamp, - meta->frame_total_size); + MT_USDT_ST22_RX_FRAME_AVAILABLE(s->parent->idx, s->idx, frame->idx, frame->addr, + slot->tmstamp, meta->frame_total_size); /* check if dump USDT enabled */ if (MT_USDT_ST22_RX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -993,14 +952,11 @@ static void rv_st22_frame_notify(struct st_rx_video_session_impl *s, } else { s->stat_frames_dropped++; /* record the miss pkts */ - float pd_sz_per_pkt = - (float)s->st22_expect_size_per_frame / slot->pkts_received; - int miss_pkts = (s->st22_expect_size_per_frame - meta->frame_total_size) / - pd_sz_per_pkt; - if (miss_pkts < 0) - miss_pkts = 0; - dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, - miss_pkts); + float pd_sz_per_pkt = (float)s->st22_expect_size_per_frame / slot->pkts_received; + int miss_pkts = + (s->st22_expect_size_per_frame - meta->frame_total_size) / pd_sz_per_pkt; + if (miss_pkts < 0) miss_pkts = 0; + dbg("%s(%d), miss pkts %d for current frame\n", __func__, s->idx, miss_pkts); s->stat_frames_pks_missed += miss_pkts; #if 0 /* for miss pkt detail */ int total_pkts = s->st22_expect_size_per_frame / pd_sz_per_pkt; @@ -1055,8 +1011,7 @@ static void rv_slice_add(struct st_rx_video_session_impl *s, slice->offset = offset; slice->size = size; slice_info->extra_slices++; - dbg("%s(%d), slice(%u:%u) add to %d\n", __func__, s->idx, offset, size, - i); + dbg("%s(%d), slice(%u:%u) add to %d\n", __func__, s->idx, offset, size, i); return; } @@ -1086,12 +1041,10 @@ static void rv_slice_add(struct st_rx_video_session_impl *s, merged = true; slice_info->extra_slices--; s->stat_pkts_slice_merged++; - dbg("%s(%d), slice %d(%u:%u) merge to main\n", __func__, s->idx, i, - offset, size); + dbg("%s(%d), slice %d(%u:%u) merge to main\n", __func__, s->idx, i, offset, size); } } - if (merged) - goto repeat_merge; + if (merged) goto repeat_merge; } /* check ready slice */ @@ -1103,9 +1056,9 @@ static void rv_slice_add(struct st_rx_video_session_impl *s, } } -static struct st_rx_video_slot_impl * -rv_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp, - void *hdr_split_pd, bool *exist_ts) { +static struct st_rx_video_slot_impl *rv_slot_by_tmstamp( + struct st_rx_video_session_impl *s, uint32_t tmstamp, void *hdr_split_pd, + bool *exist_ts) { int i, slot_idx; struct st_rx_video_slot_impl *slot; @@ -1172,8 +1125,7 @@ rv_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp, struct st20_ext_frame ext_frame; struct st20_rx_ops *ops = &s->ops; struct st20_rx_frame_meta *meta = &slot->meta; - size_t fb_size = - s->st20_uframe_size ? s->st20_uframe_size : s->st20_fb_size; + size_t fb_size = s->st20_uframe_size ? s->st20_uframe_size : s->st20_fb_size; meta->width = ops->width; meta->height = ops->height; @@ -1191,8 +1143,7 @@ rv_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp, } if (ext_frame.buf_len < fb_size) { s->stat_slot_query_ext_fail++; - err("%s(%d): ext frame size too small, required %" PRIu64 - " but get %" PRIu64 "\n", + err("%s(%d): ext frame size too small, required %" PRIu64 " but get %" PRIu64 "\n", __func__, s->idx, fb_size, ext_frame.buf_len); rte_atomic32_dec(&frame_info->refcnt); return NULL; @@ -1210,16 +1161,15 @@ rv_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp, /* clear bitmap */ memset(slot->frame_bitmap, 0x0, s->st20_frame_bitmap_size); - if (slot->slice_info) - memset(slot->slice_info, 0x0, sizeof(*slot->slice_info)); + if (slot->slice_info) memset(slot->slice_info, 0x0, sizeof(*slot->slice_info)); - dbg("%s(%d): assign slot %d framebuff %p for tmstamp %u\n", __func__, s->idx, - slot_idx, slot->frame->addr, tmstamp); + dbg("%s(%d): assign slot %d framebuff %p for tmstamp %u\n", __func__, s->idx, slot_idx, + slot->frame->addr, tmstamp); return slot; } -static struct st_rx_video_slot_impl * -rv_rtp_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp) { +static struct st_rx_video_slot_impl *rv_rtp_slot_by_tmstamp( + struct st_rx_video_session_impl *s, uint32_t tmstamp) { int i; int slot_idx = 0; struct st_rx_video_slot_impl *slot; @@ -1227,8 +1177,7 @@ rv_rtp_slot_by_tmstamp(struct st_rx_video_session_impl *s, uint32_t tmstamp) { for (i = 0; i < ST_VIDEO_RX_REC_NUM_OFO; i++) { slot = &s->slots[i]; - if (tmstamp == slot->tmstamp) - return slot; + if (tmstamp == slot->tmstamp) return slot; } /* replace the oldest slot*/ @@ -1282,8 +1231,7 @@ static void rv_st22_slot_drop_frame(struct st_rx_video_session_impl* s, } #endif -static int rv_free_dma(struct mtl_main_impl *impl, - struct st_rx_video_session_impl *s) { +static int rv_free_dma(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { if (s->dma_dev) { mt_dma_free_dev(impl, s->dma_dev); s->dma_dev = NULL; @@ -1294,13 +1242,11 @@ static int rv_free_dma(struct mtl_main_impl *impl, static int rv_slice_dma_drop_mbuf(void *priv, struct rte_mbuf *mbuf) { struct st_rx_video_session_impl *s = priv; - rv_slice_add(s, s->dma_slot, st_rx_mbuf_get_offset(mbuf), - st_rx_mbuf_get_len(mbuf)); + rv_slice_add(s, s->dma_slot, st_rx_mbuf_get_offset(mbuf), st_rx_mbuf_get_len(mbuf)); return 0; } -static int rv_init_dma(struct mtl_main_impl *impl, - struct st_rx_video_session_impl *s) { +static int rv_init_dma(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { int idx = s->idx; enum st20_type type = s->ops.type; @@ -1322,8 +1268,8 @@ static int rv_init_dma(struct mtl_main_impl *impl, s->dma_dev = dma_dev; - info("%s(%d), succ, dma %d lender id %u\n", __func__, idx, - mt_dma_dev_id(dma_dev), mt_dma_lender_id(dma_dev)); + info("%s(%d), succ, dma %d lender id %u\n", __func__, idx, mt_dma_dev_id(dma_dev), + mt_dma_lender_id(dma_dev)); return 0; } @@ -1331,11 +1277,10 @@ static int rv_stop_pcap(struct st_rx_video_session_impl *s, enum mtl_session_port s_port) { struct mt_rx_pcap *pcap = &s->pcap[s_port]; - if (!pcap->pcap) - return 0; + if (!pcap->pcap) return 0; - info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, - s->idx, s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); + info("%s(%d,%d), dumped %u packets to %s, dropped %u packets\n", __func__, s->idx, + s_port, pcap->dumped_pkts, pcap->file_name, pcap->dropped_pkts); MT_USDT_ST20_RX_PCAP_DUMP(s->parent->idx, s->idx, s_port, pcap->file_name, pcap->dumped_pkts); pcap->required_pkts = 0; @@ -1344,8 +1289,7 @@ static int rv_stop_pcap(struct st_rx_video_session_impl *s, return 0; } -static int rv_start_pcap(struct st_rx_video_session_impl *s, - enum mtl_session_port s_port, +static int rv_start_pcap(struct st_rx_video_session_impl *s, enum mtl_session_port s_port, uint32_t max_dump_packets, bool sync, struct st_pcap_dump_meta *meta) { int idx = s->idx; @@ -1358,11 +1302,11 @@ static int rv_start_pcap(struct st_rx_video_session_impl *s, } if (s->st22_info) { - snprintf(pcap->file_name, sizeof(pcap->file_name), - "st22rx_s%dp%d_%u_XXXXXX.pcapng", idx, s_port, max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), "st22rx_s%dp%d_%u_XXXXXX.pcapng", + idx, s_port, max_dump_packets); } else { - snprintf(pcap->file_name, sizeof(pcap->file_name), - "st22rx_s%dp%d_%u_XXXXXX.pcapng", idx, s_port, max_dump_packets); + snprintf(pcap->file_name, sizeof(pcap->file_name), "st22rx_s%dp%d_%u_XXXXXX.pcapng", + idx, s_port, max_dump_packets); } int fd = mt_mkstemps(pcap->file_name, strlen(".pcapng")); if (fd < 0) { @@ -1381,15 +1325,14 @@ static int rv_start_pcap(struct st_rx_video_session_impl *s, pcap->dumped_pkts = 0; pcap->dropped_pkts = 0; pcap->required_pkts = max_dump_packets; - info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, - s_port, pcap->file_name, max_dump_packets); + info("%s(%d,%d), pcap %s started, required dump pkts %u\n", __func__, idx, s_port, + pcap->file_name, max_dump_packets); if (sync) { int time_out = 100; /* 100*100ms, 10s */ int i = 0; for (; i < time_out; i++) { - if (!pcap->pcap) - break; + if (!pcap->pcap) break; mt_sleep_ms(100); } if (i >= time_out) { @@ -1413,8 +1356,7 @@ static int rv_start_pcap_dump(struct st_rx_video_session_impl *s, int ret; for (int s_port = 0; s_port < s->ops.num_port; s_port++) { ret = rv_start_pcap(s, s_port, max_dump_packets, sync, meta); - if (ret < 0) - return ret; + if (ret < 0) return ret; } return 0; } @@ -1426,9 +1368,8 @@ static int rv_stop_pcap_dump(struct st_rx_video_session_impl *s) { return 0; } -static int rv_dump_pcap(struct st_rx_video_session_impl *s, - struct rte_mbuf **mbufs, uint16_t nb, - enum mtl_session_port s_port) { +static int rv_dump_pcap(struct st_rx_video_session_impl *s, struct rte_mbuf **mbufs, + uint16_t nb, enum mtl_session_port s_port) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); struct mt_rx_pcap *pcap = &s->pcap[s_port]; uint16_t dump = mt_pcap_dump(s->impl, port, pcap->pcap, mbufs, nb); @@ -1470,10 +1411,9 @@ static inline uint32_t rfc4175_rtp_seq_id(struct st20_rfc4175_rtp_hdr *rtp) { } static inline void rv_tp_pkt_handle(struct st_rx_video_session_impl *s, - struct rte_mbuf *mbuf, - enum mtl_session_port s_port, - struct st_rx_video_slot_impl *slot, - uint32_t tmstamp, int pkt_idx) { + struct rte_mbuf *mbuf, enum mtl_session_port s_port, + struct st_rx_video_slot_impl *slot, uint32_t tmstamp, + int pkt_idx) { struct st_rx_video_tp *tp = s->tp; if (s->cur_succ_burst_cnt > (tp->pass.cinst_max_narrow / 2)) { /* untrusted result */ @@ -1490,8 +1430,8 @@ static inline void rv_tp_pkt_handle(struct st_rx_video_session_impl *s, uint64_t pkt_ns = mt_mbuf_time_stamp(impl, mbuf, port); struct st_rv_tp_slot *tp_slot = &tp->slots[slot->idx][s_port]; - dbg("%s(%d,%d), tmstamp %u pkt_ns %" PRIu64 " pkt_idx %d\n", __func__, s->idx, - s_port, tmstamp, pkt_ns, pkt_idx); + dbg("%s(%d,%d), tmstamp %u pkt_ns %" PRIu64 " pkt_idx %d\n", __func__, s->idx, s_port, + tmstamp, pkt_ns, pkt_idx); rv_tp_on_packet(s, s_port, tp_slot, tmstamp, pkt_ns, pkt_idx); } @@ -1500,8 +1440,7 @@ static inline void *rv_frame_memcpy(void *dst, const void *src, size_t n) { return memcpy(dst, src, n); } -static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, - struct rte_mbuf *mbuf, +static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread) { struct st20_rx_ops *ops = &s->ops; // size_t hdr_offset = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; @@ -1512,10 +1451,8 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, void *payload = &rtp[1]; uint16_t line1_number = ntohs(rtp->row_number); /* 0 to 1079 for 1080p */ bool second_field = (line1_number & ST20_SECOND_FIELD) ? true : false; - if (second_field) - line1_number &= ~ST20_SECOND_FIELD; - uint16_t line1_offset = - ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ + if (second_field) line1_number &= ~ST20_SECOND_FIELD; + uint16_t line1_offset = ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ struct st20_rfc4175_extra_rtp_hdr *extra_rtp = NULL; if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { line1_offset &= ~ST20_SRD_OFFSET_CONTINUATION; @@ -1537,15 +1474,15 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, line1_offset, line1_length); if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, - s_port, payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, + payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->base.ssrc); - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, - ssrc, ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, + ops->ssrc); if (ssrc != ops->ssrc) { s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; @@ -1567,8 +1504,7 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, /* find the target slot by tmstamp */ bool exist_ts = false; - struct st_rx_video_slot_impl *slot = - rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); + struct st_rx_video_slot_impl *slot = rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); if (!slot || !slot->frame) { if (exist_ts) { s->stat_pkts_redundant_dropped++; @@ -1583,8 +1519,7 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, * standard of ST2110 */ if (line1_length & ST20_LEN_USER_META) { line1_length &= ~ST20_LEN_USER_META; - dbg("%s(%d,%d): ST20_LEN_USER_META %u\n", __func__, s->idx, s_port, - line1_length); + dbg("%s(%d,%d): ST20_LEN_USER_META %u\n", __func__, s->idx, s_port, line1_length); if (line1_length <= slot->frame->user_meta_buffer_size) { rte_memcpy(slot->frame->user_meta, payload, line1_length); slot->frame->user_meta_data_size = line1_length; @@ -1604,22 +1539,20 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, offset = line1_number * (uint32_t)s->st20_linesize + line1_offset / s->st20_pg.coverage * s->st20_pg.size; size_t payload_length = line1_length; - if (extra_rtp) - payload_length += ntohs(extra_rtp->row_length); + if (extra_rtp) payload_length += ntohs(extra_rtp->row_length); if ((offset + payload_length) > s->st20_fb_size + s->st20_bytes_in_line - s->st20_linesize) { - dbg("%s(%d,%d): invalid offset %u frame buffer size %" PRIu64 "\n", - __func__, s->idx, s_port, offset, s->st20_fb_size); - dbg("%s, number %u offset %u len %u\n", __func__, line1_number, - line1_offset, line1_length); + dbg("%s(%d,%d): invalid offset %u frame buffer size %" PRIu64 "\n", __func__, s->idx, + s_port, offset, s->st20_fb_size); + dbg("%s, number %u offset %u len %u\n", __func__, line1_number, line1_offset, + line1_length); s->stat_pkts_offset_dropped++; return -EIO; } /* check if valid pkt len */ size_t pkt_payload_len = mbuf->pkt_len - sizeof(struct st_rfc4175_video_hdr); - if (extra_rtp) - pkt_payload_len -= sizeof(*extra_rtp); + if (extra_rtp) pkt_payload_len -= sizeof(*extra_rtp); if (pkt_payload_len != payload_length) { dbg("%s, invalid pkt_payload_len %" PRIu64 " payload_length %" PRIu64 " retransmit %d\n", @@ -1636,16 +1569,16 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, else pkt_idx = seq_id_u32 + (0xFFFFFFFF - slot->seq_id_base_u32) + 1; if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, - s_port, pkt_idx, slot->seq_id_base_u32); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, + pkt_idx, slot->seq_id_base_u32); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, - s_port, pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, s_port, + pkt_idx); s->stat_pkts_redundant_dropped++; slot->pkts_recv_per_port[s_port]++; /* tp for the redundant packet */ @@ -1660,24 +1593,23 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, /* the first pkt should always dispatch to control thread */ if (ctrl_thread) { if (offset % payload_length) { /* GPM_SL packing */ - int bytes_in_pkt = - ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); + int bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); int pkts_in_line = (s->st20_bytes_in_line / bytes_in_pkt) + 1; int pixel_in_pkt = (ops->width + pkts_in_line - 1) / pkts_in_line; pkt_idx = line1_number * pkts_in_line + line1_offset / pixel_in_pkt; - dbg("%s(%d,%d), GPM_SL pkts_in_line %d pixel_in_pkt %d pkt_idx %d\n", - __func__, s->idx, s_port, pkts_in_line, pixel_in_pkt, pkt_idx); + dbg("%s(%d,%d), GPM_SL pkts_in_line %d pixel_in_pkt %d pkt_idx %d\n", __func__, + s->idx, s_port, pkts_in_line, pixel_in_pkt, pkt_idx); } else { pkt_idx = offset / payload_length; } slot->seq_id_base_u32 = seq_id_u32 - pkt_idx; slot->seq_id_got = true; mt_bitmap_test_and_set(bitmap, pkt_idx); - dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, - seq_id_u32, tmstamp); + dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, seq_id_u32, + tmstamp); } else { - dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, - s->idx, s_port, seq_id_u32, line1_number, line1_offset); + dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, s->idx, + s_port, seq_id_u32, line1_number, line1_offset); s->stat_pkts_idx_dropped++; return -EIO; } @@ -1685,8 +1617,7 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, slot->last_pkt_idx = pkt_idx; /* if enable_timing_parser */ - if (s->enable_timing_parser) - rv_tp_pkt_handle(s, mbuf, s_port, slot, tmstamp, pkt_idx); + if (s->enable_timing_parser) rv_tp_pkt_handle(s, mbuf, s_port, slot, tmstamp, pkt_idx); bool dma_copy = false; bool need_copy = true; @@ -1719,15 +1650,12 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, payload + line1_length, payload_length - line1_length); } else if (dma_dev && (payload_length > ST_RX_VIDEO_DMA_MIN_SIZE) && !mt_dma_full(dma_dev) && - !rv_frame_payload_cross_page(s, slot->frame, offset, - payload_length)) { + !rv_frame_payload_cross_page(s, slot->frame, offset, payload_length)) { rte_iova_t payload_iova = rte_pktmbuf_iova_offset(mbuf, sizeof(struct st_rfc4175_video_hdr)); - if (extra_rtp) - payload_iova += sizeof(*extra_rtp); - ret = - mt_dma_copy(dma_dev, rv_frame_get_offset_iova(s, slot->frame, offset), - payload_iova, payload_length); + if (extra_rtp) payload_iova += sizeof(*extra_rtp); + ret = mt_dma_copy(dma_dev, rv_frame_get_offset_iova(s, slot->frame, offset), + payload_iova, payload_length); if (ret < 0) { /* use cpu copy if dma copy fail */ rv_frame_memcpy(slot->frame->addr + offset, payload, payload_length); @@ -1737,8 +1665,7 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, st_rx_mbuf_set_len(mbuf, payload_length); ret = mt_dma_borrow_mbuf(dma_dev, mbuf); if (ret) - err("%s(%d,%d), mbuf copied but not enqueued \n", __func__, s->idx, - s_port); + err("%s(%d,%d), mbuf copied but not enqueued \n", __func__, s->idx, s_port); dma_copy = true; s->stat_pkts_dma++; } @@ -1765,35 +1692,30 @@ static int rv_handle_frame_pkt(struct st_rx_video_session_impl *s, size_t frame_recv_size = rv_slot_get_frame_size(slot); bool end_frame = false; if (dma_dev) { - if (frame_recv_size >= s->st20_frame_size && mt_dma_empty(dma_dev)) - end_frame = true; + if (frame_recv_size >= s->st20_frame_size && mt_dma_empty(dma_dev)) end_frame = true; } else { - if (frame_recv_size >= s->st20_frame_size) - end_frame = true; + if (frame_recv_size >= s->st20_frame_size) end_frame = true; } if (end_frame) { dbg("%s(%d,%d): full frame on %p(%" PRIu64 ")\n", __func__, s->idx, s_port, slot->frame->addr, frame_recv_size); - dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, - slot->tmstamp, slot->idx); + dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, slot->tmstamp, + slot->idx); /* end of frame */ rv_slot_full_frame(s, slot); } - if (dma_copy) - s->dma_copy = true; + if (dma_copy) s->dma_copy = true; return 0; } -static int rv_handle_rtp_pkt(struct st_rx_video_session_impl *s, - struct rte_mbuf *mbuf, +static int rv_handle_rtp_pkt(struct st_rx_video_session_impl *s, struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread) { MTL_MAY_UNUSED(s_port); MTL_MAY_UNUSED(ctrl_thread); struct st20_rx_ops *ops = &s->ops; - size_t hdr_offset = - sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); + size_t hdr_offset = sizeof(struct st_rfc3550_hdr) - sizeof(struct st_rfc3550_rtp_hdr); struct st_rfc3550_rtp_hdr *rtp = rte_pktmbuf_mtod_offset(mbuf, struct st_rfc3550_rtp_hdr *, hdr_offset); uint32_t tmstamp = ntohl(rtp->tmstamp); @@ -1803,16 +1725,16 @@ static int rv_handle_rtp_pkt(struct st_rx_video_session_impl *s, int pkt_idx = -1; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, - s_port, payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, + payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, - ssrc, ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, + ops->ssrc); s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } @@ -1841,15 +1763,14 @@ static int rv_handle_rtp_pkt(struct st_rx_video_session_impl *s, } if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, - s_port, pkt_idx, slot->seq_id_base); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, + pkt_idx, slot->seq_id_base); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, idx, s_port, - pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, idx, s_port, pkt_idx); s->stat_pkts_redundant_dropped++; return 0; } @@ -1865,11 +1786,11 @@ static int rv_handle_rtp_pkt(struct st_rx_video_session_impl *s, s->port_user_stats[MTL_SESSION_PORT_P].frames++; mt_bitmap_test_and_set(bitmap, 0); pkt_idx = 0; - dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, idx, s_port, - seq_id, tmstamp); + dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, idx, s_port, seq_id, + tmstamp); } else { - dbg("%s(%d,%d), drop seq_id %d as base seq id %d not got\n", __func__, - s->idx, s_port, seq_id, slot->seq_id_base); + dbg("%s(%d,%d), drop seq_id %d as base seq id %d not got\n", __func__, s->idx, + s_port, seq_id, slot->seq_id_base); s->stat_pkts_idx_dropped++; return -EIO; } @@ -1879,8 +1800,8 @@ static int rv_handle_rtp_pkt(struct st_rx_video_session_impl *s, /* enqueue the packet ring to app */ int ret = rte_ring_sp_enqueue(s->rtps_ring, (void *)mbuf); if (ret < 0) { - dbg("%s(%d,%d), drop as rtps ring full, pkt_idx %d base %u\n", __func__, - idx, s_port, pkt_idx, slot->seq_id_base); + dbg("%s(%d,%d), drop as rtps ring full, pkt_idx %d base %u\n", __func__, idx, s_port, + pkt_idx, slot->seq_id_base); s->stat_pkts_rtp_ring_full++; return -EIO; } @@ -1917,14 +1838,12 @@ static int rv_parse_st22_boxes(struct st_rx_video_session_impl *s, void *boxes, } if ((jpvs_len + colr_len) > 512) { - err("%s(%d): err jpvs_len %u colr_len %u\n", __func__, s->idx, jpvs_len, - colr_len); + err("%s(%d): err jpvs_len %u colr_len %u\n", __func__, s->idx, jpvs_len, colr_len); return -EIO; } slot->st22_box_hdr_length = jpvs_len + colr_len; - dbg("%s(%d): st22_box_hdr_length %u\n", __func__, s->idx, - slot->st22_box_hdr_length); + dbg("%s(%d): st22_box_hdr_length %u\n", __func__, s->idx, slot->st22_box_hdr_length); if (slot->st22_box_hdr_length) { s->stat_st22_boxes++; @@ -1940,25 +1859,22 @@ static int rv_parse_st22_boxes(struct st_rx_video_session_impl *s, void *boxes, return 0; } -static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, - struct rte_mbuf *mbuf, +static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread) { MTL_MAY_UNUSED(s_port); MTL_MAY_UNUSED(ctrl_thread); struct st20_rx_ops *ops = &s->ops; // size_t hdr_offset = mbuf->l2_len + mbuf->l3_len + mbuf->l4_len; - size_t hdr_offset = sizeof(struct st22_rfc9134_video_hdr) - - sizeof(struct st22_rfc9134_rtp_hdr); + size_t hdr_offset = + sizeof(struct st22_rfc9134_video_hdr) - sizeof(struct st22_rfc9134_rtp_hdr); struct st22_rfc9134_rtp_hdr *rtp = rte_pktmbuf_mtod_offset(mbuf, struct st22_rfc9134_rtp_hdr *, hdr_offset); void *payload = &rtp[1]; - uint16_t payload_length = - mbuf->data_len - sizeof(struct st22_rfc9134_video_hdr); + uint16_t payload_length = mbuf->data_len - sizeof(struct st22_rfc9134_video_hdr); uint32_t tmstamp = ntohl(rtp->base.tmstamp); uint16_t seq_id = ntohs(rtp->base.seq_number); uint8_t payload_type = rtp->base.payload_type; - uint16_t p_counter = - (uint16_t)rtp->p_counter_lo + ((uint16_t)rtp->p_counter_hi << 8); + uint16_t p_counter = (uint16_t)rtp->p_counter_lo + ((uint16_t)rtp->p_counter_hi << 8); uint16_t sep_counter = (uint16_t)rtp->sep_counter_lo + ((uint16_t)rtp->sep_counter_hi << 5); int pkt_counter = p_counter + sep_counter * 2048; @@ -1966,16 +1882,16 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, int ret; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, - s_port, payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, + payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->base.ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, - ssrc, ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, + ops->ssrc); s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } @@ -1995,16 +1911,15 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, } else { if (rtp->interlaced) { s->stat_pkts_wrong_interlace_dropped++; - dbg("%s(%d,%d), rtp interlaced 0x%x set for progressive\n", __func__, - s->idx, s_port, rtp->interlaced); + dbg("%s(%d,%d), rtp interlaced 0x%x set for progressive\n", __func__, s->idx, + s_port, rtp->interlaced); return -EINVAL; } } /* find the target slot by tmstamp */ bool exist_ts = false; - struct st_rx_video_slot_impl *slot = - rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); + struct st_rx_video_slot_impl *slot = rv_slot_by_tmstamp(s, tmstamp, NULL, &exist_ts); if (!slot || !slot->frame) { if (exist_ts) { s->stat_pkts_redundant_dropped++; @@ -2018,10 +1933,10 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, slot->second_field = (rtp->interlaced == 0x3) ? true : false; - dbg("%s(%d,%d), seq_id %d kmode %u trans_order %u\n", __func__, s->idx, - s_port, seq_id, rtp->kmode, rtp->trans_order); - dbg("%s(%d,%d), seq_id %d p_counter %u sep_counter %u\n", __func__, s->idx, - s_port, seq_id, p_counter, sep_counter); + dbg("%s(%d,%d), seq_id %d kmode %u trans_order %u\n", __func__, s->idx, s_port, seq_id, + rtp->kmode, rtp->trans_order); + dbg("%s(%d,%d), seq_id %d p_counter %u sep_counter %u\n", __func__, s->idx, s_port, + seq_id, p_counter, sep_counter); if (slot->seq_id_got) { if (!rtp->base.marker && (payload_length != slot->st22_payload_length)) { @@ -2034,16 +1949,16 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, else pkt_idx = seq_id + (0xFFFF - slot->seq_id_base) + 1; if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, - s_port, pkt_idx, slot->seq_id_base); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, + pkt_idx, slot->seq_id_base); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, - s_port, pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, s_port, + pkt_idx); s->stat_pkts_redundant_dropped++; slot->pkts_recv_per_port[s_port]++; return 0; @@ -2083,12 +1998,11 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, payload += slot->st22_box_hdr_length; payload_length -= slot->st22_box_hdr_length; } else { - offset = - pkt_counter * slot->st22_payload_length - slot->st22_box_hdr_length; + offset = pkt_counter * slot->st22_payload_length - slot->st22_box_hdr_length; } if ((offset + payload_length) > s->st20_frame_size) { - dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, - s->idx, s_port, offset, s->st20_frame_size); + dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, s->idx, s_port, + offset, s->st20_frame_size); s->stat_pkts_offset_dropped++; return -EIO; } @@ -2108,17 +2022,14 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, if (s->st22_expect_frame_size) { size_t rece_frame_size = rv_slot_get_frame_size(slot); - dbg("%s(%d,%d): marker got, frame size %" PRIu64 " %" PRIu64 - ", tmstamp %u\n", - __func__, s->idx, s_port, rece_frame_size, s->st22_expect_frame_size, - tmstamp); + dbg("%s(%d,%d): marker got, frame size %" PRIu64 " %" PRIu64 ", tmstamp %u\n", + __func__, s->idx, s_port, rece_frame_size, s->st22_expect_frame_size, tmstamp); if (s->st22_expect_frame_size == rece_frame_size) { rv_st22_slot_full_frame(s, slot); } else { dbg("%s(%d,%d): still has %" PRIu64 " bytes unarrived pkt before marker, tmstamp %u\n", - __func__, s->idx, s_port, s->st22_expect_frame_size - rece_frame_size, - tmstamp); + __func__, s->idx, s_port, s->st22_expect_frame_size - rece_frame_size, tmstamp); } } @@ -2126,8 +2037,7 @@ static int rv_handle_st22_pkt(struct st_rx_video_session_impl *s, } static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, - struct rte_mbuf *mbuf, - enum mtl_session_port s_port, + struct rte_mbuf *mbuf, enum mtl_session_port s_port, bool ctrl_thread) { MTL_MAY_UNUSED(ctrl_thread); struct st20_rx_ops *ops = &s->ops; @@ -2138,8 +2048,7 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, rte_pktmbuf_mtod_offset(mbuf, struct st20_rfc4175_rtp_hdr *, hdr_offset); void *payload = &rtp[1]; uint16_t line1_number = ntohs(rtp->row_number); /* 0 to 1079 for 1080p */ - uint16_t line1_offset = - ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ + uint16_t line1_offset = ntohs(rtp->row_offset); /* [0, 480, 960, 1440] for 1080p */ struct st20_rfc4175_extra_rtp_hdr *extra_rtp = NULL; if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { line1_offset &= ~ST20_SRD_OFFSET_CONTINUATION; @@ -2155,16 +2064,16 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, struct rte_mbuf *mbuf_next = mbuf->next; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, - s_port, payload_type, ops->payload_type); + dbg("%s(%d,%d), get payload_type %u but expect %u\n", __func__, s->idx, s_port, + payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } if (ops->ssrc) { uint32_t ssrc = ntohl(rtp->base.ssrc); if (ssrc != ops->ssrc) { - dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, - ssrc, ops->ssrc); + dbg("%s(%d,%d), get ssrc %u but expect %u\n", __func__, s->idx, s_port, ssrc, + ops->ssrc); s->stat_pkts_wrong_ssrc_dropped++; return -EINVAL; } @@ -2180,8 +2089,7 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, /* find the target slot by tmstamp */ bool exist_ts = false; - struct st_rx_video_slot_impl *slot = - rv_slot_by_tmstamp(s, tmstamp, payload, &exist_ts); + struct st_rx_video_slot_impl *slot = rv_slot_by_tmstamp(s, tmstamp, payload, &exist_ts); if (!slot || !slot->frame) { if (exist_ts) { s->stat_pkts_redundant_dropped++; @@ -2202,15 +2110,15 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, else pkt_idx = seq_id_u32 + (0xFFFFFFFF - slot->seq_id_base_u32) + 1; if ((pkt_idx < 0) || (pkt_idx >= (s->st20_frame_bitmap_size * 8))) { - dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, - s_port, pkt_idx, slot->seq_id_base_u32); + dbg("%s(%d,%d), drop as invalid pkt_idx %d base %u\n", __func__, s->idx, s_port, + pkt_idx, slot->seq_id_base_u32); s->stat_pkts_idx_oo_bitmap++; return -EIO; } bool is_set = mt_bitmap_test_and_set(bitmap, pkt_idx); if (is_set) { - dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, - s_port, pkt_idx); + dbg("%s(%d,%d), drop as pkt %d already received\n", __func__, s->idx, s_port, + pkt_idx); s->stat_pkts_redundant_dropped++; slot->pkts_recv_per_port[s_port]++; return 0; @@ -2224,11 +2132,11 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, slot->seq_id_got = true; mt_bitmap_test_and_set(bitmap, 0); pkt_idx = 0; - dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, - seq_id_u32, tmstamp); + dbg("%s(%d,%d), seq_id_base %d tmstamp %u\n", __func__, s->idx, s_port, seq_id_u32, + tmstamp); } else { - dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, - s->idx, s_port, seq_id_u32, line1_number, line1_offset); + dbg("%s(%d,%d), drop seq_id %d as base seq id not got, %u %u\n", __func__, s->idx, + s_port, seq_id_u32, line1_number, line1_offset); s->stat_pkts_idx_dropped++; return -EIO; } @@ -2236,16 +2144,15 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, slot->last_pkt_idx = pkt_idx; /* calculate offset */ - uint32_t offset = (line1_number * ops->width + line1_offset) / - s->st20_pg.coverage * s->st20_pg.size; + uint32_t offset = + (line1_number * ops->width + line1_offset) / s->st20_pg.coverage * s->st20_pg.size; size_t payload_length = line1_length; - if (extra_rtp) - payload_length += ntohs(extra_rtp->row_length); + if (extra_rtp) payload_length += ntohs(extra_rtp->row_length); if ((offset + payload_length) > s->st20_frame_size) { - dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, - s->idx, s_port, offset, s->st20_frame_size); - dbg("%s, number %u offset %u len %u\n", __func__, line1_number, - line1_offset, line1_length); + dbg("%s(%d,%d): invalid offset %u frame size %" PRIu64 "\n", __func__, s->idx, s_port, + offset, s->st20_frame_size); + dbg("%s, number %u offset %u len %u\n", __func__, line1_number, line1_offset, + line1_length); s->stat_pkts_offset_dropped++; return -EIO; } @@ -2262,26 +2169,23 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, hdr_split->cur_frame_addr = payload; /* Cut RTE_PKTMBUF_HEADROOM since rte_mbuf_data_iova_default has offset */ hdr_split->cur_frame_mbuf_idx = - (payload - RTE_PKTMBUF_HEADROOM - hdr_split->frames) / - ST_VIDEO_BPM_SIZE; - dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u\n", __func__, s->idx, - s_port, hdr_split->cur_frame_addr, slot->cur_frame_mbuf_idx); + (payload - RTE_PKTMBUF_HEADROOM - hdr_split->frames) / ST_VIDEO_BPM_SIZE; + dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u\n", __func__, s->idx, s_port, + hdr_split->cur_frame_addr, slot->cur_frame_mbuf_idx); if (hdr_split->cur_frame_mbuf_idx % hdr_split->mbufs_per_frame) { s->stat_mismatch_hdr_split_frame++; - dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u mbufs_per_frame %u\n", - __func__, s->idx, s_port, hdr_split->cur_frame_addr, - hdr_split->cur_frame_mbuf_idx, hdr_split->mbufs_per_frame); + dbg("%s(%d,%d), cur_frame_addr %p cur_frame_idx %u mbufs_per_frame %u\n", __func__, + s->idx, s_port, hdr_split->cur_frame_addr, hdr_split->cur_frame_mbuf_idx, + hdr_split->mbufs_per_frame); } } else { - void *expect_payload = - hdr_split->cur_frame_addr + pkt_idx * ST_VIDEO_BPM_SIZE; + void *expect_payload = hdr_split->cur_frame_addr + pkt_idx * ST_VIDEO_BPM_SIZE; if (expect_payload != payload) { - dbg("%s(%d,%d), payload mismatch %p:%p on pkt %d\n", __func__, s->idx, - s_port, payload, expect_payload, pkt_idx); + dbg("%s(%d,%d), payload mismatch %p:%p on pkt %d\n", __func__, s->idx, s_port, + payload, expect_payload, pkt_idx); /* may caused by ooo, imiss, the last pkt(ddp not split for unknow cause) */ - if (marker && - (expect_payload < (hdr_split->frames + hdr_split->frames_size))) { + if (marker && (expect_payload < (hdr_split->frames + hdr_split->frames_size))) { need_copy = true; s->stat_pkts_copy_hdr_split++; } else { /* no way to recover since nic is in writing dram */ @@ -2308,10 +2212,10 @@ static int rv_handle_hdr_split_pkt(struct st_rx_video_session_impl *s, /* check if frame is full */ size_t frame_recv_size = rv_slot_get_frame_size(slot); if (frame_recv_size >= s->st20_frame_size) { - dbg("%s(%d,%d): full frame on %p(%d)\n", __func__, s->idx, s_port, - slot->frame->addr, frame_recv_size); - dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, - slot->tmstamp, slot->idx); + dbg("%s(%d,%d): full frame on %p(%d)\n", __func__, s->idx, s_port, slot->frame->addr, + frame_recv_size); + dbg("%s(%d,%d): tmstamp %u slot %d\n", __func__, s->idx, s_port, slot->tmstamp, + slot->idx); rv_slot_full_frame(s, slot); } @@ -2373,8 +2277,7 @@ static int rv_init_pkt_lcore(struct mtl_main_impl *impl, int mgr_idx = mgr->idx, idx = s->idx, ret; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_RX_VIDEO_PREFIX, mgr_idx, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->rx_burst_size; ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { @@ -2383,8 +2286,7 @@ static int rv_init_pkt_lcore(struct mtl_main_impl *impl, } s->pkt_lcore_ring = ring; - ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_RXV_RING_LCORE, - s->socket_id); + ret = mt_sch_get_lcore(impl, &lcore, MT_LCORE_TYPE_RXV_RING_LCORE, s->socket_id); if (ret < 0) { err("%s(%d,%d), get lcore fail %d\n", __func__, mgr_idx, idx, ret); rv_uinit_pkt_lcore(impl, s); @@ -2410,8 +2312,7 @@ static int rv_init_st22(struct st_rx_video_session_impl *s, struct st22_rx_video_info *st22_info; st22_info = mt_rte_zmalloc_socket(sizeof(*st22_info), s->socket_id); - if (!st22_info) - return -ENOMEM; + if (!st22_info) return -ENOMEM; st22_info->notify_frame_ready = st22_frame_ops->notify_frame_ready; @@ -2431,8 +2332,7 @@ static int rv_uinit_st22(struct st_rx_video_session_impl *s) { return 0; } -static int rv_uinit_sw(struct mtl_main_impl *impl, - struct st_rx_video_session_impl *s) { +static int rv_uinit_sw(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { rv_tp_uinit(s); rv_uinit_pkt_lcore(impl, s); rv_free_dma(impl, s); @@ -2443,10 +2343,8 @@ static int rv_uinit_sw(struct mtl_main_impl *impl, return 0; } -static int rv_init_sw(struct mtl_main_impl *impl, - struct st_rx_video_sessions_mgr *mgr, - struct st_rx_video_session_impl *s, - struct st22_rx_ops *st22_ops) { +static int rv_init_sw(struct mtl_main_impl *impl, struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, struct st22_rx_ops *st22_ops) { struct st20_rx_ops *ops = &s->ops; enum st20_type type = ops->type; int idx = s->idx; @@ -2507,8 +2405,7 @@ static int rv_init_sw(struct mtl_main_impl *impl, pg_meta->fps = ops->fps; pg_meta->frame_total_size = s->st20_frame_size; pg_meta->uframe_total_size = s->st20_uframe_size; - info("%s(%d), uframe size %" PRIu64 "\n", __func__, idx, - s->st20_uframe_size); + info("%s(%d), uframe size %" PRIu64 "\n", __func__, idx, s->st20_uframe_size); } s->has_pkt_lcore = false; @@ -2527,31 +2424,27 @@ static int rv_init_sw(struct mtl_main_impl *impl, if (st20_is_frame_type(type)) { /* for traffic > 40g, two lcore used */ if ((bps / (1000 * 1000)) > (40 * 1000)) { - if (!s->dma_dev) - pkt_handle_lcore = true; + if (!s->dma_dev) pkt_handle_lcore = true; } if (ops->flags & ST20_RX_FLAG_USE_MULTI_THREADS) { - info("%s(%d), user enable ST20_RX_FLAG_USE_MULTI_THREADS\n", __func__, - idx); + info("%s(%d), user enable ST20_RX_FLAG_USE_MULTI_THREADS\n", __func__, idx); pkt_handle_lcore = true; } } /* only one core for hdr split mode */ - if (rv_is_hdr_split(s)) - pkt_handle_lcore = false; + if (rv_is_hdr_split(s)) pkt_handle_lcore = false; if (pkt_handle_lcore) { if (type == ST20_TYPE_SLICE_LEVEL) { - err("%s(%d), additional pkt lcore not support slice type\n", __func__, - idx); + err("%s(%d), additional pkt lcore not support slice type\n", __func__, idx); rv_uinit_sw(impl, s); return -EINVAL; } if (ops->num_port > 1) { - err("%s(%d), additional pkt lcore not support redundant, num_port %u\n", - __func__, idx, ops->num_port); + err("%s(%d), additional pkt lcore not support redundant, num_port %u\n", __func__, + idx, ops->num_port); rv_uinit_sw(impl, s); return -EINVAL; } @@ -2590,38 +2483,32 @@ static int rv_init_sw(struct mtl_main_impl *impl, double sleep_ns = s->trs * 128; s->advice_sleep_us = sleep_ns / NS_PER_US; if (mt_user_tasklet_sleep(impl)) { - info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, - s->advice_sleep_us); + info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, s->advice_sleep_us); } return 0; } -static int rv_handle_detect_err(struct st_rx_video_session_impl *s, - struct rte_mbuf *mbuf, - enum mtl_session_port s_port, - bool ctrl_thread) { +static int rv_handle_detect_err(struct st_rx_video_session_impl *s, struct rte_mbuf *mbuf, + enum mtl_session_port s_port, bool ctrl_thread) { MTL_MAY_UNUSED(ctrl_thread); MTL_MAY_UNUSED(mbuf); - err_once("%s(%d,%d), detect fail, please choose the right format\n", __func__, - s->idx, s_port); + err_once("%s(%d,%d), detect fail, please choose the right format\n", __func__, s->idx, + s_port); return 0; } static int rv_detect_change_status(struct st_rx_video_session_impl *s, enum st20_detect_status new_status) { - if (s->detector.status == new_status) - return 0; + if (s->detector.status == new_status) return 0; s->detector.status = new_status; rv_init_pkt_handler(s); return 0; } -static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, - struct rte_mbuf *mbuf, - enum mtl_session_port s_port, - bool ctrl_thread) { +static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, struct rte_mbuf *mbuf, + enum mtl_session_port s_port, bool ctrl_thread) { int ret; struct st20_rx_ops *ops = &s->ops; struct st_rx_video_detector *detector = &s->detector; @@ -2634,8 +2521,7 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, uint16_t line1_number = ntohs(rtp->row_number); uint16_t line1_offset = ntohs(rtp->row_offset); /* detect field bit */ - if (line1_number & ST20_SECOND_FIELD) - meta->interlaced = true; + if (line1_number & ST20_SECOND_FIELD) meta->interlaced = true; line1_number &= ~ST20_SECOND_FIELD; struct st20_rfc4175_extra_rtp_hdr *extra_rtp = NULL; if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { @@ -2644,19 +2530,16 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, payload += sizeof(*extra_rtp); } uint32_t payload_length = ntohs(rtp->row_length); - if (extra_rtp) - payload_length += ntohs(extra_rtp->row_length); + if (extra_rtp) payload_length += ntohs(extra_rtp->row_length); uint32_t tmstamp = ntohl(rtp->base.tmstamp); uint8_t payload_type = rtp->base.payload_type; MTL_MAY_UNUSED(ctrl_thread); /* only detect on the main port */ - if (MTL_SESSION_PORT_P != s_port) - return 0; + if (MTL_SESSION_PORT_P != s_port) return 0; if (ops->payload_type && (payload_type != ops->payload_type)) { - dbg("%s, payload_type mismatch %d %d\n", __func__, payload_type, - ops->payload_type); + dbg("%s, payload_type mismatch %d %d\n", __func__, payload_type, ops->payload_type); s->stat_pkts_wrong_pt_dropped++; return -EINVAL; } @@ -2669,11 +2552,9 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, } /* detect continuous bit */ - if (extra_rtp) - detector->single_line = false; + if (extra_rtp) detector->single_line = false; /* detect bpm */ - if (payload_length % 180 != 0) - detector->bpm = false; + if (payload_length % 180 != 0) detector->bpm = false; /* on frame/field marker bit */ if (rtp->base.marker) { if (detector->frame_num < 3) { @@ -2690,8 +2571,8 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, if (meta->fps != ST_FPS_MAX && meta->packing != ST20_PACKING_MAX) { if (!meta->height) { rv_detect_change_status(s, ST20_DETECT_STAT_FAIL); - err("%s(%d,%d): st20 failed to detect dimension, max_line: %d\n", - __func__, s->idx, s_port, line1_number); + err("%s(%d,%d): st20 failed to detect dimension, max_line: %d\n", __func__, + s->idx, s_port, line1_number); } else { /* detected */ ops->width = meta->width; ops->height = meta->height; @@ -2702,27 +2583,23 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, struct st20_detect_reply reply = {0}; ret = ops->notify_detected(ops->priv, meta, &reply); if (ret < 0) { - err("%s(%d), notify_detected return fail %d\n", __func__, s->idx, - ret); + err("%s(%d), notify_detected return fail %d\n", __func__, s->idx, ret); rv_detect_change_status(s, ST20_DETECT_STAT_FAIL); return ret; } s->slice_lines = reply.slice_lines; s->st20_uframe_size = reply.uframe_size; - info("%s(%d), detected, slice_lines %u, uframe_size %" PRIu64 "\n", - __func__, s->idx, s->slice_lines, s->st20_uframe_size); + info("%s(%d), detected, slice_lines %u, uframe_size %" PRIu64 "\n", __func__, + s->idx, s->slice_lines, s->st20_uframe_size); } - if (!s->slice_lines) - s->slice_lines = ops->height / 32; + if (!s->slice_lines) s->slice_lines = ops->height / 32; s->slice_size = ops->width * s->slice_lines * s->st20_pg.size / s->st20_pg.coverage; s->st20_frames_cnt = ops->framebuff_cnt; s->st20_frame_size = ops->width * ops->height * s->st20_pg.size / s->st20_pg.coverage; - if (ops->interlaced) - s->st20_frame_size = s->st20_frame_size >> 1; - s->st20_bytes_in_line = - ops->width * s->st20_pg.size / s->st20_pg.coverage; + if (ops->interlaced) s->st20_frame_size = s->st20_frame_size >> 1; + s->st20_bytes_in_line = ops->width * s->st20_pg.size / s->st20_pg.coverage; s->st20_linesize = s->st20_bytes_in_line; if (ops->linesize > s->st20_linesize) s->st20_linesize = ops->linesize; @@ -2731,8 +2608,7 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, return -EINVAL; } s->st20_fb_size = s->st20_linesize * ops->height; - if (ops->interlaced) - s->st20_fb_size = s->st20_fb_size >> 1; + if (ops->interlaced) s->st20_fb_size = s->st20_fb_size >> 1; /* at least 1000 byte for each packet */ s->st20_frame_bitmap_size = s->st20_frame_size / 1000 / 8; /* one line at line 2 packets for all the format */ @@ -2744,14 +2620,12 @@ static int rv_handle_detect_pkt(struct st_rx_video_session_impl *s, rv_detect_change_status(s, ST20_DETECT_STAT_FAIL); return ret; } - rvs_mgr_update( - s->parent); /* update mgr since we has new advice sleep us */ + rvs_mgr_update(s->parent); /* update mgr since we has new advice sleep us */ rv_detect_change_status(s, ST20_DETECT_STAT_SUCCESS); - info("st20 detected(%d,%d): width: %d, height: %d, fps: %f\n", s->idx, - s_port, meta->width, meta->height, st_frame_rate(meta->fps)); - info("st20 detected(%d,%d): packing: %d, field: %s, pkts per %s: %d\n", - s->idx, s_port, meta->packing, - meta->interlaced ? "interlaced" : "progressive", + info("st20 detected(%d,%d): width: %d, height: %d, fps: %f\n", s->idx, s_port, + meta->width, meta->height, st_frame_rate(meta->fps)); + info("st20 detected(%d,%d): packing: %d, field: %s, pkts per %s: %d\n", s->idx, + s_port, meta->packing, meta->interlaced ? "interlaced" : "progressive", meta->interlaced ? "field" : "frame", detector->pkt_per_frame); } } @@ -2795,9 +2669,7 @@ static int rv_handle_mbuf(void *priv, struct rte_mbuf **mbuf, uint16_t nb) { struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->required_pkts) { if (pcap->dumped_pkts < pcap->required_pkts) { - rv_dump_pcap(s, mbuf, - RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), - s_port); + rv_dump_pcap(s, mbuf, RTE_MIN(nb, pcap->required_pkts - pcap->dumped_pkts), s_port); } else { /* got enough packets, stop dumping */ rv_stop_pcap(s, s_port); } @@ -2805,20 +2677,17 @@ static int rv_handle_mbuf(void *priv, struct rte_mbuf **mbuf, uint16_t nb) { if (pkt_ring) { /* first pass to the pkt ring if it has pkt handling lcore */ - unsigned int n = rte_ring_sp_enqueue_bulk(s->pkt_lcore_ring, - (void **)&mbuf[0], nb, NULL); - for (uint16_t i = 0; i < (uint16_t)n; i++) - rte_mbuf_refcnt_update(mbuf[i], 1); + unsigned int n = + rte_ring_sp_enqueue_bulk(s->pkt_lcore_ring, (void **)&mbuf[0], nb, NULL); + for (uint16_t i = 0; i < (uint16_t)n; i++) rte_mbuf_refcnt_update(mbuf[i], 1); nb -= n; /* n is zero or nb */ s->stat_pkts_enqueue_fallback += nb; } - if (!nb) - return 0; + if (!nb) return 0; /* now dispatch the pkts to handler */ for (uint16_t i = 0; i < nb; i++) { - if ((s->ops.flags & ST20_RX_FLAG_SIMULATE_PKT_LOSS) && - rv_simulate_pkt_loss(s)) + if ((s->ops.flags & ST20_RX_FLAG_SIMULATE_PKT_LOSS) && rv_simulate_pkt_loss(s)) continue; if (s->rtcp_rx[s_port]) { struct st_rfc3550_rtp_hdr *rtp = rte_pktmbuf_mtod_offset( @@ -2848,14 +2717,12 @@ static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl *s) { if (s->dma_dev) { rv_dma_dequeue(s); /* check if has pending pkts in dma */ - if (!mt_dma_empty(s->dma_dev)) - done = false; + if (!mt_dma_empty(s->dma_dev)) done = false; } s->dma_copy = false; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rxq[s_port]) - continue; + if (!s->rxq[s_port]) continue; struct mt_rx_pcap *pcap = &s->pcap[s_port]; /* if any pcap progress */ @@ -2878,8 +2745,7 @@ static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl *s) { if (rv) { s->stat_burst_succ_cnt++; s->stat_burst_pkts_sum += rv; - if (rv > s->stat_burst_pkts_max) - s->stat_burst_pkts_max = rv; + if (rv > s->stat_burst_pkts_max) s->stat_burst_pkts_max = rv; if (rv >= (s->rx_burst_size / 2)) { s->in_continuous_burst[s_port] = true; } @@ -2894,8 +2760,7 @@ static int rv_pkt_rx_tasklet(struct st_rx_video_session_impl *s) { } /* submit if any */ - if (s->dma_copy && s->dma_dev) - mt_dma_submit(s->dma_dev); + if (s->dma_copy && s->dma_dev) mt_dma_submit(s->dma_dev); return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } @@ -2913,8 +2778,7 @@ static int rv_uinit_hw(struct st_rx_video_session_impl *s) { return 0; } -static int rv_init_hw(struct mtl_main_impl *impl, - struct st_rx_video_session_impl *s) { +static int rv_init_hw(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { struct st20_rx_ops *ops = &s->ops; int idx = s->idx, num_port = ops->num_port; struct mt_rxq_flow flow; @@ -2930,8 +2794,8 @@ static int rv_init_hw(struct mtl_main_impl *impl, memset(&flow, 0, sizeof(flow)); bps = 0; - st20_get_bandwidth_bps(ops->width, ops->height, ops->fmt, ops->fps, - ops->interlaced, &bps); + st20_get_bandwidth_bps(ops->width, ops->height, ops->fmt, ops->fps, ops->interlaced, + &bps); flow.bytes_per_sec = bps / 8; rte_memcpy(flow.dip_addr, ops->ip_addr[i], MTL_IP_ADDR_LEN); if (mt_is_multicast_ip(flow.dip_addr)) @@ -2950,13 +2814,12 @@ static int rv_init_hw(struct mtl_main_impl *impl, return -ENOTSUP; #endif } - if (mt_has_cni_rx(impl, port)) - flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; + if (mt_has_cni_rx(impl, port)) flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; /* no flow for data path only */ if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { - info("%s(%d), rxq get without flow for port %d as data path only\n", - __func__, s->idx, i); + info("%s(%d), rxq get without flow for port %d as data path only\n", __func__, + s->idx, i); s->rxq[i] = mt_rxq_get(impl, port, NULL); } else { s->rxq[i] = mt_rxq_get(impl, port, &flow); @@ -2978,8 +2841,7 @@ static int rv_uinit_mcast(struct mtl_main_impl *impl, enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!s->mcast_joined[i]) - continue; + if (!s->mcast_joined[i]) continue; port = mt_port_logic2phy(s->port_maps, i); mt_mcast_leave(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); @@ -2988,15 +2850,13 @@ static int rv_uinit_mcast(struct mtl_main_impl *impl, return 0; } -static int rv_init_mcast(struct mtl_main_impl *impl, - struct st_rx_video_session_impl *s) { +static int rv_init_mcast(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { struct st20_rx_ops *ops = &s->ops; int ret; enum mtl_port port; for (int i = 0; i < ops->num_port; i++) { - if (!mt_is_multicast_ip(ops->ip_addr[i])) - continue; + if (!mt_is_multicast_ip(ops->ip_addr[i])) continue; port = mt_port_logic2phy(s->port_maps, i); if (ops->flags & ST20_RX_FLAG_DATA_PATH_ONLY) { info("%s(%d), skip mcast join for port %d\n", __func__, s->idx, i); @@ -3004,8 +2864,7 @@ static int rv_init_mcast(struct mtl_main_impl *impl, } ret = mt_mcast_join(impl, mt_ip_to_u32(ops->ip_addr[i]), mt_ip_to_u32(ops->mcast_sip_addr[i]), port); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->mcast_joined[i] = true; } @@ -3014,8 +2873,7 @@ static int rv_init_mcast(struct mtl_main_impl *impl, static int rv_init_rtcp_uhdr(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s, - enum mtl_session_port s_port, - struct mt_udp_hdr *uhdr) { + enum mtl_session_port s_port, struct mt_udp_hdr *uhdr) { int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); int ret; @@ -3030,15 +2888,14 @@ static int rv_init_rtcp_uhdr(struct mtl_main_impl *impl, /* ether hdr */ ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], - dip[1], dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], + dip[2], dip[3]); return ret; } ret = mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); if (ret < 0) { - err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, - s_port); + err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, s_port); return ret; } eth->ether_type = htons(RTE_ETHER_TYPE_IPV4); @@ -3061,8 +2918,7 @@ static int rv_init_rtcp_uhdr(struct mtl_main_impl *impl, return 0; } -static int rv_init_rtcp(struct mtl_main_impl *impl, - struct st_rx_video_sessions_mgr *mgr, +static int rv_init_rtcp(struct mtl_main_impl *impl, struct st_rx_video_sessions_mgr *mgr, struct st_rx_video_session_impl *s) { int idx = s->idx; int mgr_idx = mgr->idx; @@ -3074,15 +2930,12 @@ static int rv_init_rtcp(struct mtl_main_impl *impl, struct mt_udp_hdr uhdr; memset(&uhdr, 0x0, sizeof(uhdr)); int ret = rv_init_rtcp_uhdr(impl, s, i, &uhdr); - if (ret < 0) - return ret; + if (ret < 0) return ret; char name[MT_RTCP_MAX_NAME_LEN]; - snprintf(name, sizeof(name), ST_RX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, - i); + snprintf(name, sizeof(name), ST_RX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, i); if (!ops->rtcp.nack_interval_us) ops->rtcp.nack_interval_us = 250; /* default 250 us */ - if (!ops->rtcp.seq_bitmap_size) - ops->rtcp.seq_bitmap_size = 64; + if (!ops->rtcp.seq_bitmap_size) ops->rtcp.seq_bitmap_size = 64; struct mt_rtcp_rx_ops rtcp_ops = { .port = port, .name = name, @@ -3093,8 +2946,7 @@ static int rv_init_rtcp(struct mtl_main_impl *impl, }; s->rtcp_rx[i] = mt_rtcp_rx_create(impl, &rtcp_ops); if (!s->rtcp_rx[i]) { - err("%s(%d,%d), mt_rtcp_rx_create fail on port %d\n", __func__, mgr_idx, - idx, i); + err("%s(%d,%d), mt_rtcp_rx_create fail on port %d\n", __func__, mgr_idx, idx, i); return -EIO; } } @@ -3136,8 +2988,7 @@ static int rv_init_pkt_handler(struct st_rx_video_session_impl *s) { return 0; } -static int rv_uinit(struct mtl_main_impl *impl, - struct st_rx_video_session_impl *s) { +static int rv_uinit(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { rv_stop_pcap_dump(s); rv_uinit_mcast(impl, s); rv_uinit_rtcp(s); @@ -3146,20 +2997,17 @@ static int rv_uinit(struct mtl_main_impl *impl, return 0; } -static int rv_attach(struct mtl_main_impl *impl, - struct st_rx_video_sessions_mgr *mgr, - struct st_rx_video_session_impl *s, - struct st20_rx_ops *ops, struct st22_rx_ops *st22_ops) { +static int rv_attach(struct mtl_main_impl *impl, struct st_rx_video_sessions_mgr *mgr, + struct st_rx_video_session_impl *s, struct st20_rx_ops *ops, + struct st22_rx_ops *st22_ops) { int ret; int idx = s->idx, num_port = ops->num_port; char *ports[MTL_SESSION_PORT_MAX]; struct st_fps_timing fps_tm; - for (int i = 0; i < num_port; i++) - ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = st20_get_pgroup(ops->fmt, &s->st20_pg); if (ret < 0) { @@ -3179,8 +3027,7 @@ static int rv_attach(struct mtl_main_impl *impl, s->impl = impl; s->frame_time = (double)1000000000.0 * fps_tm.den / fps_tm.mul; - s->frame_time_sampling = - (double)(fps_tm.sampling_clock_rate) * fps_tm.den / fps_tm.mul; + s->frame_time_sampling = (double)(fps_tm.sampling_clock_rate) * fps_tm.den / fps_tm.mul; s->st20_bytes_in_line = ops->width * s->st20_pg.size / s->st20_pg.coverage; s->st20_linesize = s->st20_bytes_in_line; if (ops->linesize > s->st20_linesize) @@ -3191,24 +3038,19 @@ static int rv_attach(struct mtl_main_impl *impl, } s->st20_fb_size = s->st20_linesize * ops->height; - if (ops->interlaced) - s->st20_fb_size = s->st20_fb_size >> 1; + if (ops->interlaced) s->st20_fb_size = s->st20_fb_size >> 1; s->slice_lines = ops->slice_lines; - if (!s->slice_lines) - s->slice_lines = ops->height / 32; - s->slice_size = - ops->width * s->slice_lines * s->st20_pg.size / s->st20_pg.coverage; + if (!s->slice_lines) s->slice_lines = ops->height / 32; + s->slice_size = ops->width * s->slice_lines * s->st20_pg.size / s->st20_pg.coverage; s->st20_frames_cnt = ops->framebuff_cnt; if (st22_ops) { s->st20_frame_size = st22_ops->framebuff_max_size; s->st20_fb_size = s->st20_frame_size; s->st22_ops_flags = st22_ops->flags; } else - s->st20_frame_size = - ops->width * ops->height * s->st20_pg.size / s->st20_pg.coverage; + s->st20_frame_size = ops->width * ops->height * s->st20_pg.size / s->st20_pg.coverage; s->st20_uframe_size = ops->uframe_size; - if (ops->interlaced) - s->st20_frame_size = s->st20_frame_size >> 1; + if (ops->interlaced) s->st20_frame_size = s->st20_frame_size >> 1; /* at least 800 byte for each packet */ s->st20_frame_bitmap_size = s->st20_frame_size / 800 / 8; /* one line at line 2 packets for all the format */ @@ -3217,13 +3059,11 @@ static int rv_attach(struct mtl_main_impl *impl, if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "RX_VIDEO_M%dS%d", mgr->idx, - idx); + snprintf(s->ops_name, sizeof(s->ops_name), "RX_VIDEO_M%dS%d", mgr->idx, idx); } s->ops = *ops; for (int i = 0; i < num_port; i++) { - s->st20_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); } /* init estimated trs */ @@ -3232,8 +3072,7 @@ static int rv_attach(struct mtl_main_impl *impl, if (ops->rx_burst_size) { s->rx_burst_size = ops->rx_burst_size; - info("%s(%d), user customized rx_burst_size %u\n", __func__, idx, - s->rx_burst_size); + info("%s(%d), user customized rx_burst_size %u\n", __func__, idx, s->rx_burst_size); } else { s->rx_burst_size = 128; } @@ -3242,8 +3081,7 @@ static int rv_attach(struct mtl_main_impl *impl, if (s->ops.flags & ST20_RX_FLAG_SIMULATE_PKT_LOSS) { uint16_t burst_loss_max = 1; float sim_loss_rate = 0.1; - if (ops->rtcp.burst_loss_max) - burst_loss_max = ops->rtcp.burst_loss_max; + if (ops->rtcp.burst_loss_max) burst_loss_max = ops->rtcp.burst_loss_max; if (ops->rtcp.sim_loss_rate > 0.0 && ops->rtcp.sim_loss_rate < 1.0) sim_loss_rate = ops->rtcp.sim_loss_rate; s->burst_loss_max = burst_loss_max; @@ -3339,36 +3177,31 @@ static int rv_attach(struct mtl_main_impl *impl, } s->attached = true; - info("%s(%d), %d frames with size %" PRIu64 "(%" PRIu64 ",%" PRIu64 - "), type %d, %s\n", - __func__, idx, s->st20_frames_cnt, s->st20_frame_size, - s->st20_frame_bitmap_size, s->st20_uframe_size, ops->type, - ops->interlaced ? "interlace" : "progressive"); - info("%s(%d), w %u h %u fmt %s packing %d pt %d flags 0x%x frame time %fms " - "fps %f\n", - __func__, idx, ops->width, ops->height, st20_fmt_name(ops->fmt), - ops->packing, ops->payload_type, ops->flags, s->frame_time / NS_PER_MS, - st_frame_rate(s->ops.fps)); + info("%s(%d), %d frames with size %" PRIu64 "(%" PRIu64 ",%" PRIu64 "), type %d, %s\n", + __func__, idx, s->st20_frames_cnt, s->st20_frame_size, s->st20_frame_bitmap_size, + s->st20_uframe_size, ops->type, ops->interlaced ? "interlace" : "progressive"); + info( + "%s(%d), w %u h %u fmt %s packing %d pt %d flags 0x%x frame time %fms " + "fps %f\n", + __func__, idx, ops->width, ops->height, st20_fmt_name(ops->fmt), ops->packing, + ops->payload_type, ops->flags, s->frame_time / NS_PER_MS, + st_frame_rate(s->ops.fps)); return 0; } -static int rv_poll_vsync(struct mtl_main_impl *impl, - struct st_rx_video_session_impl *s) { +static int rv_poll_vsync(struct mtl_main_impl *impl, struct st_rx_video_session_impl *s) { struct st_vsync_info *vsync = &s->vsync; uint64_t cur_tsc = mt_get_tsc(impl); - if (!vsync->init) - return 0; + if (!vsync->init) return 0; if (cur_tsc > vsync->next_epoch_tsc) { uint64_t tsc_delta = cur_tsc - vsync->next_epoch_tsc; - dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, - vsync->meta.epoch); + dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, vsync->meta.epoch); s->ops.notify_event(s->ops.priv, ST_EVENT_VSYNC, &vsync->meta); st_vsync_calculate(impl, vsync); /* set next vsync */ /* check tsc delta for status */ - if (tsc_delta > NS_PER_MS) - s->stat_vsync_mismatch++; + if (tsc_delta > NS_PER_MS) s->stat_vsync_mismatch++; } return 0; @@ -3376,8 +3209,7 @@ static int rv_poll_vsync(struct mtl_main_impl *impl, static int rv_send_nack(struct st_rx_video_session_impl *s) { for (int i = 0; i < s->ops.num_port; i++) { - if (s->rtcp_rx[i]) - mt_rtcp_rx_send_nack_packet(s->rtcp_rx[i]); + if (s->rtcp_rx[i]) mt_rtcp_rx_send_nack_packet(s->rtcp_rx[i]); } return 0; } @@ -3393,18 +3225,14 @@ static int rvs_pkt_rx_tasklet_handler(void *priv) { for (sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_video_session_try_get(mgr, sidx); - if (!s) - continue; - if (time_measure) - tsc_s = mt_get_tsc(impl); + if (!s) continue; + if (time_measure) tsc_s = mt_get_tsc(impl); pending += rv_pkt_rx_tasklet(s); /* check vsync if it has vsync flag enabled */ - if (s->ops.flags & ST20_RX_FLAG_ENABLE_VSYNC) - rv_poll_vsync(impl, s); - if (s->ops.flags & ST20_RX_FLAG_ENABLE_RTCP) - rv_send_nack(s); + if (s->ops.flags & ST20_RX_FLAG_ENABLE_VSYNC) rv_poll_vsync(impl, s); + if (s->ops.flags & ST20_RX_FLAG_ENABLE_RTCP) rv_send_nack(s); if (time_measure) { uint64_t delta_ns = mt_get_tsc(impl) - tsc_s; @@ -3430,8 +3258,8 @@ void rx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, uint64_t avg_ns_per_loop = mt_sch_avg_ns_loop(sch); /* assume one taskelt can bulk 3 pkts */ s->cpu_busy_score = (double)avg_ns_per_loop / 3 / s->trs * 100.0; - dbg("%s(%d), avg_ns_per_loop %" PRIu64 ", trs %f, busy %f\n", __func__, - s->idx, avg_ns_per_loop, s->trs, s->cpu_busy_score); + dbg("%s(%d), avg_ns_per_loop %" PRIu64 ", trs %f, busy %f\n", __func__, s->idx, + avg_ns_per_loop, s->trs, s->cpu_busy_score); s->stat_cpu_busy_score = s->cpu_busy_score; /* update imiss busy */ @@ -3443,14 +3271,12 @@ void rx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, memset(&stats, 0, sizeof(stats)); mt_read_admin_port_stats(s->impl, port, &stats); if (stats.rx_hw_dropped_packets) { - dbg("%s(%d,%d), incomplete %d and hw_dropped_pkts %" PRIu64 "\n", - __func__, sch->idx, s->idx, incomplete_frame_cnt, - stats.rx_hw_dropped_packets); + dbg("%s(%d,%d), incomplete %d and hw_dropped_pkts %" PRIu64 "\n", __func__, + sch->idx, s->idx, incomplete_frame_cnt, stats.rx_hw_dropped_packets); s->imiss_busy_score += 40.0; } if (s->imiss_busy_score > 95.0) { - notice("%s(%d,%d), imiss busy, incomplete %d and hw_dropped_pkts %" PRIu64 - "\n", + notice("%s(%d,%d), imiss busy, incomplete %d and hw_dropped_pkts %" PRIu64 "\n", __func__, sch->idx, s->idx, incomplete_frame_cnt, stats.rx_hw_dropped_packets); } @@ -3491,15 +3317,14 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, rte_atomic32_set(&s->stat_frames_received, 0); if (s->stat_slices_received) { - notice("RX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d slices %d\n", - m_idx, idx, s->ops_name, framerate, frames_received, - s->stat_pkts_received, s->stat_slices_received); + notice("RX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d slices %d\n", m_idx, idx, + s->ops_name, framerate, frames_received, s->stat_pkts_received, + s->stat_slices_received); } else { notice("RX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d\n", m_idx, idx, s->ops_name, framerate, frames_received, s->stat_pkts_received); } - notice("RX_VIDEO_SESSION(%d,%d): throughput %f Mb/s, cpu busy %f\n", m_idx, - idx, + notice("RX_VIDEO_SESSION(%d,%d): throughput %f Mb/s, cpu busy %f\n", m_idx, idx, (double)s->stat_bytes_received * 8 / dump_period_s / MTL_STAT_M_UNIT, s->stat_cpu_busy_score); s->stat_pkts_received = 0; @@ -3507,22 +3332,22 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, s->stat_slices_received = 0; s->stat_last_time = cur_time_ns; - if (s->stat_frames_dropped || s->stat_pkts_idx_dropped || - s->stat_pkts_offset_dropped) { - notice("RX_VIDEO_SESSION(%d,%d): incomplete frames %d, pkts (idx error: " - "%d, offset " - "error: %d, idx out of bitmap: %d, missed: %d)\n", - m_idx, idx, s->stat_frames_dropped, s->stat_pkts_idx_dropped, - s->stat_pkts_offset_dropped, s->stat_pkts_idx_oo_bitmap, - s->stat_frames_pks_missed); + if (s->stat_frames_dropped || s->stat_pkts_idx_dropped || s->stat_pkts_offset_dropped) { + notice( + "RX_VIDEO_SESSION(%d,%d): incomplete frames %d, pkts (idx error: " + "%d, offset " + "error: %d, idx out of bitmap: %d, missed: %d)\n", + m_idx, idx, s->stat_frames_dropped, s->stat_pkts_idx_dropped, + s->stat_pkts_offset_dropped, s->stat_pkts_idx_oo_bitmap, + s->stat_frames_pks_missed); s->stat_frames_dropped = 0; s->stat_pkts_idx_dropped = 0; s->stat_pkts_idx_oo_bitmap = 0; s->stat_frames_pks_missed = 0; } if (s->stat_pkts_rtp_ring_full) { - notice("RX_VIDEO_SESSION(%d,%d): rtp dropped pkts %d as ring full\n", m_idx, - idx, s->stat_pkts_rtp_ring_full); + notice("RX_VIDEO_SESSION(%d,%d): rtp dropped pkts %d as ring full\n", m_idx, idx, + s->stat_pkts_rtp_ring_full); s->stat_pkts_rtp_ring_full = 0; } if (s->stat_pkts_no_slot) { @@ -3541,18 +3366,18 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, s->stat_pkts_redundant_dropped = 0; } if (s->stat_pkts_wrong_pt_dropped) { - notice("RX_VIDEO_SESSION(%d,%d): wrong hdr payload type dropped pkts %d\n", - m_idx, idx, s->stat_pkts_wrong_pt_dropped); + notice("RX_VIDEO_SESSION(%d,%d): wrong hdr payload type dropped pkts %d\n", m_idx, + idx, s->stat_pkts_wrong_pt_dropped); s->stat_pkts_wrong_pt_dropped = 0; } if (s->stat_pkts_wrong_ssrc_dropped) { - notice("RX_VIDEO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, - idx, s->stat_pkts_wrong_ssrc_dropped); + notice("RX_VIDEO_SESSION(%d,%d): wrong hdr ssrc dropped pkts %d\n", m_idx, idx, + s->stat_pkts_wrong_ssrc_dropped); s->stat_pkts_wrong_ssrc_dropped = 0; } if (s->stat_pkts_wrong_interlace_dropped) { - notice("RX_VIDEO_SESSION(%d,%d): wrong hdr interlace dropped pkts %d\n", - m_idx, idx, s->stat_pkts_wrong_interlace_dropped); + notice("RX_VIDEO_SESSION(%d,%d): wrong hdr interlace dropped pkts %d\n", m_idx, idx, + s->stat_pkts_wrong_interlace_dropped); s->stat_pkts_wrong_interlace_dropped = 0; } if (s->stat_pkts_wrong_len_dropped) { @@ -3561,18 +3386,18 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, s->stat_pkts_wrong_len_dropped = 0; } if (s->stat_pkts_enqueue_fallback) { - notice("RX_VIDEO_SESSION(%d,%d): lcore enqueue fallback pkts %d\n", m_idx, - idx, s->stat_pkts_enqueue_fallback); + notice("RX_VIDEO_SESSION(%d,%d): lcore enqueue fallback pkts %d\n", m_idx, idx, + s->stat_pkts_enqueue_fallback); s->stat_pkts_enqueue_fallback = 0; } if (s->dma_dev) { - notice("RX_VIDEO_SESSION(%d,%d): pkts %d by dma copy, dma busy %f\n", m_idx, - idx, s->stat_pkts_dma, s->dma_busy_score); + notice("RX_VIDEO_SESSION(%d,%d): pkts %d by dma copy, dma busy %f\n", m_idx, idx, + s->stat_pkts_dma, s->dma_busy_score); s->stat_pkts_dma = 0; } if (s->stat_pkts_slice_fail) { - notice("RX_VIDEO_SESSION(%d,%d): pkts %d drop as slice add fail\n", m_idx, - idx, s->stat_pkts_slice_fail); + notice("RX_VIDEO_SESSION(%d,%d): pkts %d drop as slice add fail\n", m_idx, idx, + s->stat_pkts_slice_fail); s->stat_pkts_slice_fail = 0; } if (s->stat_pkts_slice_merged) { @@ -3591,13 +3416,13 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, s->stat_pkts_not_bpm = 0; } if (s->stat_pkts_wrong_payload_hdr_split) { - notice("RX_VIDEO_SESSION(%d,%d): wrong payload hdr split pkts %d\n", m_idx, - idx, s->stat_pkts_wrong_payload_hdr_split); + notice("RX_VIDEO_SESSION(%d,%d): wrong payload hdr split pkts %d\n", m_idx, idx, + s->stat_pkts_wrong_payload_hdr_split); s->stat_pkts_wrong_payload_hdr_split = 0; } if (s->stat_mismatch_hdr_split_frame) { - notice("RX_VIDEO_SESSION(%d,%d): hdr split mismatch frames %d\n", m_idx, - idx, s->stat_mismatch_hdr_split_frame); + notice("RX_VIDEO_SESSION(%d,%d): hdr split mismatch frames %d\n", m_idx, idx, + s->stat_mismatch_hdr_split_frame); s->stat_mismatch_hdr_split_frame = 0; } if (s->stat_pkts_copy_hdr_split) { @@ -3626,8 +3451,8 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, s->stat_pkts_simulate_loss = 0; } if (s->stat_pkts_user_meta) { - notice("RX_VIDEO_SESSION(%d,%d): user meta pkts %d invalid %d\n", m_idx, - idx, s->stat_pkts_user_meta, s->stat_pkts_user_meta_err); + notice("RX_VIDEO_SESSION(%d,%d): user meta pkts %d invalid %d\n", m_idx, idx, + s->stat_pkts_user_meta, s->stat_pkts_user_meta_err); s->stat_pkts_user_meta = 0; s->stat_pkts_user_meta_err = 0; } @@ -3637,16 +3462,14 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, s->stat_pkts_retransmit = 0; } if (s->ops.interlaced) { - notice( - "RX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", - m_idx, idx, s->stat_interlace_first_field, - s->stat_interlace_second_field); + notice("RX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", m_idx, + idx, s->stat_interlace_first_field, s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } if (s->stat_st22_boxes) { - notice("RX_VIDEO_SESSION(%d,%d): st22 video support boxes received %u \n", - m_idx, idx, s->stat_st22_boxes); + notice("RX_VIDEO_SESSION(%d,%d): st22 video support boxes received %u \n", m_idx, idx, + s->stat_st22_boxes); s->stat_st22_boxes = 0; } if (s->stat_burst_succ_cnt) { @@ -3664,17 +3487,16 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, tp->stat_untrusted_pkts); tp->stat_untrusted_pkts = 0; } - if (s->enable_timing_parser_stat) - rv_tp_stat(s); + if (s->enable_timing_parser_stat) rv_tp_stat(s); struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("RX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " - "%.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, - (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice( + "RX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_notify_frame_us > 8) { @@ -3686,8 +3508,7 @@ static void rv_stat(struct st_rx_video_sessions_mgr *mgr, for (int s_port = 0; s_port < s->ops.num_port; s_port++) { struct mt_rx_pcap *pcap = &s->pcap[s_port]; if (pcap->pcap) { - MT_USDT_ST20_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, - pcap->dumped_pkts); + MT_USDT_ST20_RX_PCAP_DUMP(m_idx, idx, s_port, pcap->file_name, pcap->dumped_pkts); } } } @@ -3700,8 +3521,7 @@ static int rvs_pkt_rx_tasklet_start(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = rx_video_session_try_get(mgr, sidx); - if (!s) - continue; + if (!s) continue; /* re-calculate the vsync */ st_vsync_calculate(impl, &s->vsync); rx_video_session_put(mgr, sidx); @@ -3711,8 +3531,7 @@ static int rvs_pkt_rx_tasklet_start(void *priv) { return 0; } -static int rv_detach(struct mtl_main_impl *impl, - struct st_rx_video_sessions_mgr *mgr, +static int rv_detach(struct mtl_main_impl *impl, struct st_rx_video_sessions_mgr *mgr, struct st_rx_video_session_impl *s) { s->attached = false; rv_stat(mgr, s); @@ -3737,8 +3556,7 @@ static int rv_update_src(struct st_rx_video_sessions_mgr *mgr, memcpy(ops->ip_addr[i], src->ip_addr[i], MTL_IP_ADDR_LEN); memcpy(ops->mcast_sip_addr[i], src->mcast_sip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = src->udp_port[i]; - s->st20_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); } ret = rv_init_hw(impl, s); @@ -3834,8 +3652,7 @@ static int rvs_mgr_uinit(struct st_rx_video_sessions_mgr *mgr) { for (int i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { s = rx_video_session_get(mgr, i); - if (!s) - continue; + if (!s) continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); rvs_mgr_detach(mgr, s, i); @@ -3846,9 +3663,9 @@ static int rvs_mgr_uinit(struct st_rx_video_sessions_mgr *mgr) { return 0; } -static struct st_rx_video_session_impl * -rv_mgr_attach(struct mtl_sch_impl *sch, struct st20_rx_ops *ops, - struct st22_rx_ops *st22_ops) { +static struct st_rx_video_session_impl *rv_mgr_attach(struct mtl_sch_impl *sch, + struct st20_rx_ops *ops, + struct st22_rx_ops *st22_ops) { struct st_rx_video_sessions_mgr *mgr = &sch->rx_video_mgr; int midx = mgr->idx; int ret; @@ -3857,8 +3674,7 @@ rv_mgr_attach(struct mtl_sch_impl *sch, struct st20_rx_ops *ops, /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { - if (!rx_video_session_get_empty(mgr, i)) - continue; + if (!rx_video_session_get_empty(mgr, i)) continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -3918,16 +3734,14 @@ static int rvs_mgr_update(struct st_rx_video_sessions_mgr *mgr) { for (int i = 0; i < ST_SCH_MAX_RX_VIDEO_SESSIONS; i++) { s = mgr->sessions[i]; - if (!s) - continue; + if (!s) continue; max_idx = i + 1; sleep_us = RTE_MIN(s->advice_sleep_us, sleep_us); } - dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, - sleep_us, max_idx); + dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, sleep_us, + max_idx); mgr->max_idx = max_idx; - if (mgr->pkt_rx_tasklet) - mt_tasklet_set_sleep(mgr->pkt_rx_tasklet, sleep_us); + if (mgr->pkt_rx_tasklet) mt_tasklet_set_sleep(mgr->pkt_rx_tasklet, sleep_us); return 0; } @@ -3937,8 +3751,7 @@ static int rv_sessions_stat(void *priv) { for (int j = 0; j < mgr->max_idx; j++) { s = rx_video_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) - continue; + if (!s) continue; rv_stat(mgr, s); rx_video_session_put(mgr, j); } @@ -3946,12 +3759,10 @@ static int rv_sessions_stat(void *priv) { return 0; } -int st_rx_video_sessions_sch_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { +int st_rx_video_sessions_sch_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { int ret, idx = sch->idx; - if (sch->rx_video_init) - return 0; + if (sch->rx_video_init) return 0; struct st_rx_video_sessions_mgr *rx_video_mgr = &sch->rx_video_mgr; @@ -3967,10 +3778,8 @@ int st_rx_video_sessions_sch_init(struct mtl_main_impl *impl, return 0; } -int st_rx_video_sessions_sch_uinit(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { - if (!sch->rx_video_init) - return 0; +int st_rx_video_sessions_sch_uinit(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { + if (!sch->rx_video_init) return 0; struct st_rx_video_sessions_mgr *rx_video_mgr = &sch->rx_video_mgr; @@ -3985,8 +3794,7 @@ int st_rx_video_session_migrate(struct mtl_main_impl *impl, struct st_rx_video_sessions_mgr *mgr, struct st_rx_video_session_impl *s, int idx) { rv_init(mgr, s, idx); - if (s->dma_dev) - rv_migrate_dma(impl, s); + if (s->dma_dev) rv_migrate_dma(impl, s); return 0; } @@ -4004,16 +3812,14 @@ static int rv_ops_check(struct st20_rx_ops *ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -4042,8 +3848,7 @@ static int rv_ops_check(struct st20_rx_ops *ops) { } if (ops->query_ext_frame) { if (!(ops->flags & ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME)) { - err("%s, pls enable incomplete frame flag for query ext mode\n", - __func__); + err("%s, pls enable incomplete frame flag for query ext mode\n", __func__); return -EINVAL; } } @@ -4051,8 +3856,7 @@ static int rv_ops_check(struct st20_rx_ops *ops) { if (num_ports > 1) { /* only 1 port allowed since the pkt payload is assigned to frame * directly */ - err("%s, hdr split only support 1 port, num_ports %d\n", __func__, - num_ports); + err("%s, hdr split only support 1 port, num_ports %d\n", __func__, num_ports); return -EINVAL; } } @@ -4107,16 +3911,14 @@ static int rv_st22_ops_check(struct st22_rx_ops *ops) { ip = ops->ip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->ip_addr[0], ops->ip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -4162,8 +3964,7 @@ static int rv_st22_ops_check(struct st22_rx_ops *ops) { } st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, - struct st20_rx_ops *ops, - mt_sch_mask_t sch_mask) { + struct st20_rx_ops *ops, mt_sch_mask_t sch_mask) { struct mtl_sch_impl *sch; struct st_rx_video_session_handle_impl *s_impl; struct st_rx_video_session_impl *s; @@ -4182,8 +3983,7 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, } if (ops->flags & ST20_RX_FLAG_AUTO_DETECT) { - ret = st20_get_bandwidth_bps(1920, 1080, ops->fmt, ST_FPS_P59_94, false, - &bps); + ret = st20_get_bandwidth_bps(1920, 1080, ops->fmt, ST_FPS_P59_94, false, &bps); } else { ret = st20_get_bandwidth_bps(ops->width, ops->height, ops->fmt, ops->fps, ops->interlaced, &bps); @@ -4197,19 +3997,16 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, quota_mbs *= ops->num_port; if (!mt_user_quota_active(impl)) { if (ST20_TYPE_RTP_LEVEL == ops->type) { - quota_mbs = - quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_RTP_PER_SCH; + quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_RTP_PER_SCH; } else { - quota_mbs_wo_dma = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / - ST_QUOTA_RX1080P_NO_DMA_PER_SCH; - quota_mbs = - quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_PER_SCH; + quota_mbs_wo_dma = + quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_NO_DMA_PER_SCH; + quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_RX1080P_PER_SCH; } } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20_RX_FLAG_FORCE_NUMA) { @@ -4223,9 +4020,8 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, return NULL; } - enum mt_sch_type type = mt_user_rxv_separate_sch(impl) - ? MT_SCH_TYPE_RX_VIDEO_ONLY - : MT_SCH_TYPE_DEFAULT; + enum mt_sch_type type = + mt_user_rxv_separate_sch(impl) ? MT_SCH_TYPE_RX_VIDEO_ONLY : MT_SCH_TYPE_DEFAULT; sch = mt_sch_get_by_socket(impl, quota_mbs, type, sch_mask, socket); if (!sch) { mt_rte_free(s_impl); @@ -4253,12 +4049,10 @@ st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, return NULL; } - if (!mt_user_quota_active(impl) && st20_is_frame_type(ops->type) && - !s->dma_dev) { + if (!mt_user_quota_active(impl) && st20_is_frame_type(ops->type) && !s->dma_dev) { int extra_quota_mbs = quota_mbs_wo_dma - quota_mbs; ret = mt_sch_add_quota(sch, extra_quota_mbs); - if (ret >= 0) - quota_mbs += extra_quota_mbs; + if (ret >= 0) quota_mbs += extra_quota_mbs; } /* update mgr status */ @@ -4282,8 +4076,7 @@ st20_rx_handle st20_rx_create(mtl_handle mt, struct st20_rx_ops *ops) { return st20_rx_create_with_mask(mt, ops, MT_SCH_MASK_ALL); } -int st20_rx_update_source(st20_rx_handle handle, - struct st_rx_source_info *src) { +int st20_rx_update_source(st20_rx_handle handle, struct st_rx_source_info *src) { struct st_rx_video_session_handle_impl *s_impl = handle; struct st_rx_video_session_impl *s; int idx, ret; @@ -4297,8 +4090,7 @@ int st20_rx_update_source(st20_rx_handle handle, idx = s->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = rv_mgr_update_src(&s_impl->sch->rx_video_mgr, s, src); if (ret < 0) { @@ -4321,8 +4113,8 @@ int st20_rx_get_sch_idx(st20_rx_handle handle) { return s_impl->sch->idx; } -int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta) { +int st20_rx_pcapng_dump(st20_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta) { struct st_rx_video_session_handle_impl *s_impl = handle; struct st_rx_video_session_impl *s = s_impl->impl; @@ -4352,8 +4144,7 @@ int st20_rx_get_port_stats(st20_rx_handle handle, enum mtl_session_port port, return 0; } -int st20_rx_reset_port_stats(st20_rx_handle handle, - enum mtl_session_port port) { +int st20_rx_reset_port_stats(st20_rx_handle handle, enum mtl_session_port port) { struct st_rx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_RX_VIDEO) { @@ -4393,12 +4184,10 @@ int st20_rx_free(st20_rx_handle handle) { ret = st_rvs_mgr_detach(&sch->rx_video_mgr, s); mt_pthread_mutex_unlock(&sch->rx_video_mgr_mutex); if (ret < 0) - err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, - idx); + err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4502,8 +4291,7 @@ void st20_rx_put_mbuf(st20_rx_handle handle, void *mbuf) { if (s_impl->type != MT_HANDLE_RX_VIDEO) err("%s, invalid type %d\n", __func__, s_impl->type); - if (pkt) - rte_pktmbuf_free(pkt); + if (pkt) rte_pktmbuf_free(pkt); } bool st20_rx_dma_enabled(st20_rx_handle handle) { @@ -4540,8 +4328,7 @@ int st20_rx_get_queue_meta(st20_rx_handle handle, struct st_queue_meta *meta) { return 0; } -int st20_rx_timing_parser_critical(st20_rx_handle handle, - struct st20_rx_tp_pass *pass) { +int st20_rx_timing_parser_critical(st20_rx_handle handle, struct st20_rx_tp_pass *pass) { struct st_rx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_RX_VIDEO) { @@ -4585,8 +4372,8 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops *ops) { } if (ST22_TYPE_RTP_LEVEL == ops->type) { - ret = st20_get_bandwidth_bps(ops->width, ops->height, - ST20_FMT_YUV_422_10BIT, ops->fps, false, &bps); + ret = st20_get_bandwidth_bps(ops->width, ops->height, ST20_FMT_YUV_422_10BIT, + ops->fps, false, &bps); if (ret < 0) { err("%s, get_bandwidth_bps fail\n", __func__); return NULL; @@ -4606,8 +4393,7 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops *ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22_RX_FLAG_FORCE_NUMA) { @@ -4621,9 +4407,8 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops *ops) { return NULL; } - enum mt_sch_type type = mt_user_rxv_separate_sch(impl) - ? MT_SCH_TYPE_RX_VIDEO_ONLY - : MT_SCH_TYPE_DEFAULT; + enum mt_sch_type type = + mt_user_rxv_separate_sch(impl) ? MT_SCH_TYPE_RX_VIDEO_ONLY : MT_SCH_TYPE_DEFAULT; sch = mt_sch_get_by_socket(impl, quota_mbs, type, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); @@ -4654,8 +4439,7 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops *ops) { } if (ops->flags & ST22_RX_FLAG_DATA_PATH_ONLY) st20_ops.flags |= ST20_RX_FLAG_DATA_PATH_ONLY; - if (ops->flags & ST22_RX_FLAG_ENABLE_VSYNC) - st20_ops.flags |= ST20_RX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22_RX_FLAG_ENABLE_VSYNC) st20_ops.flags |= ST20_RX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22_RX_FLAG_RECEIVE_INCOMPLETE_FRAME) st20_ops.flags |= ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; if (ops->flags & ST22_RX_FLAG_ENABLE_RTCP) { @@ -4702,8 +4486,7 @@ st22_rx_handle st22_rx_create(mtl_handle mt, struct st22_rx_ops *ops) { return s_impl; } -int st22_rx_update_source(st22_rx_handle handle, - struct st_rx_source_info *src) { +int st22_rx_update_source(st22_rx_handle handle, struct st_rx_source_info *src) { struct st22_rx_video_session_handle_impl *s_impl = handle; struct st_rx_video_session_impl *s; int idx, ret; @@ -4717,8 +4500,7 @@ int st22_rx_update_source(st22_rx_handle handle, idx = s->idx; ret = st_rx_source_info_check(src, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = rv_mgr_update_src(&s_impl->sch->rx_video_mgr, s, src); if (ret < 0) { @@ -4741,8 +4523,8 @@ int st22_rx_get_sch_idx(st22_rx_handle handle) { return s_impl->sch->idx; } -int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, - bool sync, struct st_pcap_dump_meta *meta) { +int st22_rx_pcapng_dump(st22_rx_handle handle, uint32_t max_dump_packets, bool sync, + struct st_pcap_dump_meta *meta) { struct st22_rx_video_session_handle_impl *s_impl = handle; struct st_rx_video_session_impl *s = s_impl->impl; @@ -4776,12 +4558,10 @@ int st22_rx_free(st22_rx_handle handle) { ret = st_rvs_mgr_detach(&sch->rx_video_mgr, s); mt_pthread_mutex_unlock(&sch->rx_video_mgr_mutex); if (ret < 0) - err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, - idx); + err("%s(%d,%d), st_rx_video_sessions_mgr_detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d,%d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4835,8 +4615,7 @@ void st22_rx_put_mbuf(st22_rx_handle handle, void *mbuf) { if (s_impl->type != MT_ST22_HANDLE_RX_VIDEO) err("%s, invalid type %d\n", __func__, s_impl->type); - if (pkt) - rte_pktmbuf_free(pkt); + if (pkt) rte_pktmbuf_free(pkt); } int st22_rx_put_framebuff(st22_rx_handle handle, void *framebuff) { diff --git a/lib/src/st2110/st_rx_video_session.h b/lib/src/st2110/st_rx_video_session.h index 12d5e8ce2..265d5e5d9 100644 --- a/lib/src/st2110/st_rx_video_session.h +++ b/lib/src/st2110/st_rx_video_session.h @@ -14,48 +14,40 @@ #define ST_RX_VIDEO_PREFIX "RV_" -int st_rx_video_sessions_sch_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch); +int st_rx_video_sessions_sch_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch); -int st_rx_video_sessions_sch_uinit(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch); +int st_rx_video_sessions_sch_uinit(struct mtl_main_impl *impl, struct mtl_sch_impl *sch); /* call rx_video_session_put always if get successfully */ -static inline struct st_rx_video_session_impl * -rx_video_session_get(struct st_rx_video_sessions_mgr *mgr, int idx) { +static inline struct st_rx_video_session_impl *rx_video_session_get( + struct st_rx_video_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_rx_video_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_video_session_put always if get successfully */ -static inline struct st_rx_video_session_impl * -rx_video_session_get_timeout(struct st_rx_video_sessions_mgr *mgr, int idx, - int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) - return NULL; +static inline struct st_rx_video_session_impl *rx_video_session_get_timeout( + struct st_rx_video_sessions_mgr *mgr, int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; struct st_rx_video_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_video_session_put always if get successfully */ -static inline struct st_rx_video_session_impl * -rx_video_session_try_get(struct st_rx_video_sessions_mgr *mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) - return NULL; +static inline struct st_rx_video_session_impl *rx_video_session_try_get( + struct st_rx_video_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; struct st_rx_video_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_video_session_put always if get successfully */ -static inline bool -rx_video_session_get_empty(struct st_rx_video_sessions_mgr *mgr, int idx) { +static inline bool rx_video_session_get_empty(struct st_rx_video_sessions_mgr *mgr, + int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_rx_video_session_impl *s = mgr->sessions[idx]; if (s) { @@ -66,38 +58,30 @@ rx_video_session_get_empty(struct st_rx_video_sessions_mgr *mgr, int idx) { } } -static inline void rx_video_session_put(struct st_rx_video_sessions_mgr *mgr, - int idx) { +static inline void rx_video_session_put(struct st_rx_video_sessions_mgr *mgr, int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } st20_rx_handle st20_rx_create_with_mask(struct mtl_main_impl *impl, - struct st20_rx_ops *ops, - mt_sch_mask_t sch_mask); + struct st20_rx_ops *ops, mt_sch_mask_t sch_mask); void rx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, struct st_rx_video_session_impl *s); void rx_video_session_clear_cpu_busy(struct st_rx_video_session_impl *s); -static inline bool -rx_video_session_is_cpu_busy(struct st_rx_video_session_impl *s) { - if (s->dma_dev && (s->dma_busy_score > 90)) - return true; - if (s->imiss_busy_score > 95.0) - return true; - if (s->cpu_busy_score > 95.0) - return true; +static inline bool rx_video_session_is_cpu_busy(struct st_rx_video_session_impl *s) { + if (s->dma_dev && (s->dma_busy_score > 90)) return true; + if (s->imiss_busy_score > 95.0) return true; + if (s->cpu_busy_score > 95.0) return true; return false; } -static inline float -rx_video_session_get_cpu_busy(struct st_rx_video_session_impl *s) { +static inline float rx_video_session_get_cpu_busy(struct st_rx_video_session_impl *s) { return s->cpu_busy_score; } -static inline bool -rx_video_session_can_migrate(struct st_rx_video_session_impl *s) { +static inline bool rx_video_session_can_migrate(struct st_rx_video_session_impl *s) { if (s->ops.flags & ST20_RX_FLAG_DISABLE_MIGRATE) return false; else diff --git a/lib/src/st2110/st_tx_ancillary_session.c b/lib/src/st2110/st_tx_ancillary_session.c index d5e8d1b8e..ff21ba76c 100644 --- a/lib/src/st2110/st_tx_ancillary_session.c +++ b/lib/src/st2110/st_tx_ancillary_session.c @@ -11,43 +11,35 @@ #include "st_err.h" /* call tx_ancillary_session_put always if get successfully */ -static inline struct st_tx_ancillary_session_impl * -tx_ancillary_session_get(struct st_tx_ancillary_sessions_mgr *mgr, int idx) { +static inline struct st_tx_ancillary_session_impl *tx_ancillary_session_get( + struct st_tx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_ancillary_session_put always if get successfully */ -static inline struct st_tx_ancillary_session_impl * -tx_ancillary_session_try_get(struct st_tx_ancillary_sessions_mgr *mgr, - int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) - return NULL; +static inline struct st_tx_ancillary_session_impl *tx_ancillary_session_try_get( + struct st_tx_ancillary_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_ancillary_session_put always if get successfully */ -static inline struct st_tx_ancillary_session_impl * -tx_ancillary_session_get_timeout(struct st_tx_ancillary_sessions_mgr *mgr, - int idx, int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) - return NULL; +static inline struct st_tx_ancillary_session_impl *tx_ancillary_session_get_timeout( + struct st_tx_ancillary_sessions_mgr *mgr, int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call rx_ancillary_session_put always if get successfully */ -static inline bool -tx_ancillary_session_get_empty(struct st_tx_ancillary_sessions_mgr *mgr, - int idx) { +static inline bool tx_ancillary_session_get_empty( + struct st_tx_ancillary_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_tx_ancillary_session_impl *s = mgr->sessions[idx]; if (s) { @@ -58,20 +50,18 @@ tx_ancillary_session_get_empty(struct st_tx_ancillary_sessions_mgr *mgr, } } -static inline void -tx_ancillary_session_put(struct st_tx_ancillary_sessions_mgr *mgr, int idx) { +static inline void tx_ancillary_session_put(struct st_tx_ancillary_sessions_mgr *mgr, + int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } -static int -tx_ancillary_session_free_frames(struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_free_frames(struct st_tx_ancillary_session_impl *s) { if (s->st40_frames) { struct st_frame_trans *frame; /* dec ref for current frame */ frame = &s->st40_frames[s->st40_frame_idx]; - if (rte_atomic32_read(&frame->refcnt)) - rte_atomic32_dec(&frame->refcnt); + if (rte_atomic32_read(&frame->refcnt)) rte_atomic32_dec(&frame->refcnt); for (int i = 0; i < s->st40_frames_cnt; i++) { frame = &s->st40_frames[i]; @@ -86,8 +76,7 @@ tx_ancillary_session_free_frames(struct st_tx_ancillary_session_impl *s) { return 0; } -static int -tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl *s) { int soc_id = s->socket_id; int idx = s->idx; struct st_frame_trans *frame_info; @@ -97,8 +86,8 @@ tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl *s) { return -EIO; } - s->st40_frames = mt_rte_zmalloc_socket( - sizeof(*s->st40_frames) * s->st40_frames_cnt, soc_id); + s->st40_frames = + mt_rte_zmalloc_socket(sizeof(*s->st40_frames) * s->st40_frames_cnt, soc_id); if (!s->st40_frames) { err("%s(%d), st30_frames malloc fail\n", __func__, idx); return -ENOMEM; @@ -128,9 +117,10 @@ tx_ancillary_session_alloc_frames(struct st_tx_ancillary_session_impl *s) { return 0; } -static int tx_ancillary_session_init_hdr( - struct mtl_main_impl *impl, struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s, enum mtl_session_port s_port) { +static int tx_ancillary_session_init_hdr(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + enum mtl_session_port s_port) { MTL_MAY_UNUSED(mgr); int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); @@ -146,21 +136,17 @@ static int tx_ancillary_session_init_hdr( struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); /* ether hdr */ - if ((s_port == MTL_SESSION_PORT_P) && - (ops->flags & ST40_TX_FLAG_USER_P_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], - RTE_ETHER_ADDR_LEN); + if ((s_port == MTL_SESSION_PORT_P) && (ops->flags & ST40_TX_FLAG_USER_P_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); info("%s, USER_P_TX_MAC\n", __func__); - } else if ((s_port == MTL_SESSION_PORT_R) && - (ops->flags & ST40_TX_FLAG_USER_R_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], - RTE_ETHER_ADDR_LEN); + } else if ((s_port == MTL_SESSION_PORT_R) && (ops->flags & ST40_TX_FLAG_USER_R_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); info("%s, USER_R_TX_MAC\n", __func__); } else { ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, - dip[0], dip[1], dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], + dip[2], dip[3]); return ret; } } @@ -202,18 +188,15 @@ static int tx_ancillary_session_init_hdr( s->st40_seq_id = 0; s->st40_ext_seq_id = 0; - info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], - dip[1], dip[2], dip[3], s->st40_src_port[s_port], - s->st40_dst_port[s_port]); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", - __func__, idx, d_addr->addr_bytes[0], d_addr->addr_bytes[1], - d_addr->addr_bytes[2], d_addr->addr_bytes[3], d_addr->addr_bytes[4], - d_addr->addr_bytes[5], ssrc); + info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], dip[1], + dip[2], dip[3], s->st40_src_port[s_port], s->st40_dst_port[s_port]); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", __func__, idx, + d_addr->addr_bytes[0], d_addr->addr_bytes[1], d_addr->addr_bytes[2], + d_addr->addr_bytes[3], d_addr->addr_bytes[4], d_addr->addr_bytes[5], ssrc); return 0; } -static int -tx_ancillary_session_init_pacing(struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_init_pacing(struct st_tx_ancillary_session_impl *s) { int idx = s->idx; struct st_tx_ancillary_session_pacing *pacing = &s->pacing; double frame_time = (double)1000000000.0 * s->fps_tm.den / s->fps_tm.mul; @@ -222,53 +205,45 @@ tx_ancillary_session_init_pacing(struct st_tx_ancillary_session_impl *s) { pacing->frame_time_sampling = (double)(s->fps_tm.sampling_clock_rate) * s->fps_tm.den / s->fps_tm.mul; pacing->max_onward_epochs = (double)(NS_PER_S * 1) / frame_time; /* 1s */ - dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, - pacing->max_onward_epochs); + dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, pacing->max_onward_epochs); info("%s[%02d], frame_time %f frame_time_sampling %f\n", __func__, idx, pacing->frame_time, pacing->frame_time_sampling); return 0; } -static int -tx_ancillary_session_init_pacing_epoch(struct mtl_main_impl *impl, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_init_pacing_epoch( + struct mtl_main_impl *impl, struct st_tx_ancillary_session_impl *s) { uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); struct st_tx_ancillary_session_pacing *pacing = &s->pacing; pacing->cur_epochs = ptp_time / pacing->frame_time; return 0; } -static inline double -tx_ancillary_pacing_time(struct st_tx_ancillary_session_pacing *pacing, - uint64_t epochs) { +static inline double tx_ancillary_pacing_time( + struct st_tx_ancillary_session_pacing *pacing, uint64_t epochs) { return epochs * pacing->frame_time; } -static inline uint32_t -tx_ancillary_pacing_time_stamp(struct st_tx_ancillary_session_pacing *pacing, - uint64_t epochs) { +static inline uint32_t tx_ancillary_pacing_time_stamp( + struct st_tx_ancillary_session_pacing *pacing, uint64_t epochs) { uint64_t tmstamp64 = epochs * pacing->frame_time_sampling; uint32_t tmstamp32 = tmstamp64; return tmstamp32; } -static uint64_t -tx_ancillary_pacing_required_tai(struct st_tx_ancillary_session_impl *s, - enum st10_timestamp_fmt tfmt, - uint64_t timestamp) { +static uint64_t tx_ancillary_pacing_required_tai(struct st_tx_ancillary_session_impl *s, + enum st10_timestamp_fmt tfmt, + uint64_t timestamp) { uint64_t required_tai = 0; - if (!(s->ops.flags & ST40_TX_FLAG_USER_PACING)) - return 0; - if (!timestamp) - return 0; + if (!(s->ops.flags & ST40_TX_FLAG_USER_PACING)) return 0; + if (!timestamp) return 0; if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (timestamp > 0xFFFFFFFF) { - err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, - timestamp); + err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, timestamp); } required_tai = st10_media_clk_to_ns((uint32_t)timestamp, 90 * 1000); } else { @@ -278,9 +253,10 @@ tx_ancillary_pacing_required_tai(struct st_tx_ancillary_session_impl *s, return required_tai; } -static int tx_ancillary_session_sync_pacing( - struct mtl_main_impl *impl, struct st_tx_ancillary_session_impl *s, - bool sync, uint64_t required_tai, bool second_field) { +static int tx_ancillary_session_sync_pacing(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s, + bool sync, uint64_t required_tai, + bool second_field) { struct st_tx_ancillary_session_pacing *pacing = &s->pacing; double frame_time = pacing->frame_time; /* always use MTL_PORT_P for ptp now */ @@ -293,11 +269,9 @@ static int tx_ancillary_session_sync_pacing( if (required_tai) { uint64_t ptp_epochs = ptp_time / frame_time; epochs = required_tai / frame_time; - dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 - " epochs %" PRIu64 "\n", + dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 " epochs %" PRIu64 "\n", __func__, s->idx, required_tai, ptp_epochs, epochs); - if (epochs < ptp_epochs) - s->stat_error_user_timestamp++; + if (epochs < ptp_epochs) s->stat_error_user_timestamp++; } else { epochs = ptp_time / frame_time; } @@ -314,12 +288,10 @@ static int tx_ancillary_session_sync_pacing( if (interlaced) { if (second_field) { /* align to odd epoch */ - if (!(epochs & 0x1)) - epochs++; + if (!(epochs & 0x1)) epochs++; s->stat_interlace_second_field++; } else { /* align to even epoch */ - if (epochs & 0x1) - epochs++; + if (epochs & 0x1) epochs++; s->stat_interlace_first_field++; } } @@ -331,19 +303,17 @@ static int tx_ancillary_session_sync_pacing( to_epoch = 0; /* send asap */ } - if (epochs > next_epochs) - s->stat_epoch_drop += (epochs - next_epochs); - if (epochs < next_epochs) - s->stat_epoch_onward += (next_epochs - epochs); + if (epochs > next_epochs) s->stat_epoch_drop += (epochs - next_epochs); + if (epochs < next_epochs) s->stat_epoch_onward += (next_epochs - epochs); pacing->cur_epochs = epochs; pacing->cur_epoch_time = tx_ancillary_pacing_time(pacing, epochs); pacing->pacing_time_stamp = tx_ancillary_pacing_time_stamp(pacing, epochs); pacing->rtp_time_stamp = pacing->pacing_time_stamp; pacing->tsc_time_cursor = (double)mt_get_tsc(impl) + to_epoch; - dbg("%s(%d), epochs %" PRIu64 " time_stamp %u time_cursor %f to_epoch %f\n", - __func__, s->idx, pacing->cur_epochs, pacing->pacing_time_stamp, - pacing->tsc_time_cursor, to_epoch); + dbg("%s(%d), epochs %" PRIu64 " time_stamp %u time_cursor %f to_epoch %f\n", __func__, + s->idx, pacing->cur_epochs, pacing->pacing_time_stamp, pacing->tsc_time_cursor, + to_epoch); if (sync) { dbg("%s(%d), delay to epoch_time %f, cur %" PRIu64 "\n", __func__, s->idx, @@ -354,9 +324,8 @@ static int tx_ancillary_session_sync_pacing( return 0; } -static int -tx_ancillary_session_init_next_meta(struct st_tx_ancillary_session_impl *s, - struct st40_tx_frame_meta *meta) { +static int tx_ancillary_session_init_next_meta(struct st_tx_ancillary_session_impl *s, + struct st40_tx_frame_meta *meta) { struct st_tx_ancillary_session_pacing *pacing = &s->pacing; struct st40_tx_ops *ops = &s->ops; @@ -374,8 +343,7 @@ tx_ancillary_session_init_next_meta(struct st_tx_ancillary_session_impl *s, } static int tx_ancillary_session_init(struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s, - int idx) { + struct st_tx_ancillary_session_impl *s, int idx) { MTL_MAY_UNUSED(mgr); s->idx = idx; return 0; @@ -388,8 +356,7 @@ static int tx_ancillary_sessions_tasklet_start(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_ancillary_session_get(mgr, sidx); - if (!s) - continue; + if (!s) continue; tx_ancillary_session_init_pacing_epoch(impl, s); tx_ancillary_session_put(mgr, sidx); @@ -398,9 +365,8 @@ static int tx_ancillary_sessions_tasklet_start(void *priv) { return 0; } -static int -tx_ancillary_session_update_redundant(struct st_tx_ancillary_session_impl *s, - struct rte_mbuf *pkt_r) { +static int tx_ancillary_session_update_redundant(struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt_r) { struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt_r, struct mt_udp_hdr *); struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; struct rte_udp_hdr *udp = &hdr->udp; @@ -419,9 +385,8 @@ tx_ancillary_session_update_redundant(struct st_tx_ancillary_session_impl *s, return 0; } -static int -tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, - struct rte_mbuf *pkt) { +static int tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt) { struct mt_udp_hdr *hdr; struct rte_ipv4_hdr *ipv4; struct rte_udp_hdr *udp; @@ -447,8 +412,7 @@ tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, /* update rtp */ rtp->base.seq_number = htons(s->st40_seq_id); rtp->seq_number_ext = htons(s->st40_ext_seq_id); - if (s->st40_seq_id == 0xFFFF) - s->st40_ext_seq_id++; + if (s->st40_seq_id == 0xFFFF) s->st40_ext_seq_id++; s->st40_seq_id++; rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); @@ -464,8 +428,7 @@ tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, for (idx = s->st40_pkt_idx; idx < anc_count; idx++) { uint16_t udw_size = src->meta[idx].udw_size; total_udw += udw_size; - if ((total_udw * 10 / 8) > s->max_pkt_len) - break; + if ((total_udw * 10 / 8) > s->max_pkt_len) break; struct st40_rfc8331_payload_hdr *pktBuff = (struct st40_rfc8331_payload_hdr *)(payload); pktBuff->first_hdr_chunk.c = src->meta[idx].c; @@ -486,19 +449,17 @@ tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, (uint8_t *)&pktBuff->second_hdr_chunk); } uint16_t checksum = 0; - checksum = - st40_calc_checksum(3 + udw_size, (uint8_t *)&pktBuff->second_hdr_chunk); + checksum = st40_calc_checksum(3 + udw_size, (uint8_t *)&pktBuff->second_hdr_chunk); st40_set_udw(i + 3, checksum, (uint8_t *)&pktBuff->second_hdr_chunk); uint16_t total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = - (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - uint16_t size_to_send = sizeof(struct st40_rfc8331_payload_hdr) - 4 + - total_size; // Full size of one ANC + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + uint16_t size_to_send = + sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC payload = payload + size_to_send; } int payload_size = payload - (uint8_t *)&rtp[1]; @@ -514,8 +475,7 @@ tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, } else { rtp->f = 0b00; } - if (idx == anc_count) - rtp->base.marker = 1; + if (idx == anc_count) rtp->base.marker = 1; dbg("%s(%d), anc_count %d, payload_size %d\n", __func__, s->idx, anc_count, payload_size); @@ -530,9 +490,8 @@ tx_ancillary_session_build_packet(struct st_tx_ancillary_session_impl *s, return idx; } -static int -tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl *s, - struct rte_mbuf *pkt, int anc_idx) { +static int tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt, int anc_idx) { struct st40_rfc8331_rtp_hdr *rtp; rtp = rte_pktmbuf_mtod(pkt, struct st40_rfc8331_rtp_hdr *); @@ -541,8 +500,7 @@ tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl *s, /* update rtp */ rtp->base.seq_number = htons(s->st40_seq_id); rtp->seq_number_ext = htons(s->st40_ext_seq_id); - if (s->st40_seq_id == 0xFFFF) - s->st40_ext_seq_id++; + if (s->st40_seq_id == 0xFFFF) s->st40_ext_seq_id++; s->st40_seq_id++; rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); @@ -558,8 +516,7 @@ tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl *s, for (idx = anc_idx; idx < anc_count; idx++) { uint16_t udw_size = src->meta[idx].udw_size; total_udw += udw_size; - if ((total_udw * 10 / 8) > s->max_pkt_len) - break; + if ((total_udw * 10 / 8) > s->max_pkt_len) break; struct st40_rfc8331_payload_hdr *pktBuff = (struct st40_rfc8331_payload_hdr *)(payload); pktBuff->first_hdr_chunk.c = src->meta[idx].c; @@ -580,19 +537,17 @@ tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl *s, (uint8_t *)&pktBuff->second_hdr_chunk); } uint16_t checksum = 0; - checksum = - st40_calc_checksum(3 + udw_size, (uint8_t *)&pktBuff->second_hdr_chunk); + checksum = st40_calc_checksum(3 + udw_size, (uint8_t *)&pktBuff->second_hdr_chunk); st40_set_udw(i + 3, checksum, (uint8_t *)&pktBuff->second_hdr_chunk); uint16_t total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = - (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - uint16_t size_to_send = sizeof(struct st40_rfc8331_payload_hdr) - 4 + - total_size; // Full size of one ANC + ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + uint16_t size_to_send = + sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC payload = payload + size_to_send; } int payload_size = payload - (uint8_t *)&rtp[1]; @@ -608,17 +563,15 @@ tx_ancillary_session_build_rtp_packet(struct st_tx_ancillary_session_impl *s, } else { rtp->f = 0b00; } - if (idx == anc_count) - rtp->base.marker = 1; + if (idx == anc_count) rtp->base.marker = 1; dbg("%s(%d), anc_count %d, payload_size %d\n", __func__, s->idx, anc_count, payload_size); return idx; } -static int -tx_ancillary_session_rtp_update_packet(struct mtl_main_impl *impl, - struct st_tx_ancillary_session_impl *s, - struct rte_mbuf *pkt) { +static int tx_ancillary_session_rtp_update_packet(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt) { struct mt_udp_hdr *hdr; struct rte_ipv4_hdr *ipv4; struct st_rfc3550_rtp_hdr *rtp; @@ -666,10 +619,11 @@ tx_ancillary_session_rtp_update_packet(struct mtl_main_impl *impl, return 0; } -static int tx_ancillary_session_build_packet_chain( - struct mtl_main_impl *impl, struct st_tx_ancillary_session_impl *s, - struct rte_mbuf *pkt, struct rte_mbuf *pkt_rtp, - enum mtl_session_port s_port) { +static int tx_ancillary_session_build_packet_chain(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s, + struct rte_mbuf *pkt, + struct rte_mbuf *pkt_rtp, + enum mtl_session_port s_port) { struct mt_udp_hdr *hdr; struct rte_ipv4_hdr *ipv4; struct rte_udp_hdr *udp; @@ -697,8 +651,7 @@ static int tx_ancillary_session_build_packet_chain( s->st40_rtp_time = rtp->base.tmstamp; bool second_field = false; if (s->ops.interlaced) { - struct st40_rfc8331_rtp_hdr *rfc8331 = - (struct st40_rfc8331_rtp_hdr *)&udp[1]; + struct st40_rfc8331_rtp_hdr *rfc8331 = (struct st40_rfc8331_rtp_hdr *)&udp[1]; second_field = (rfc8331->f == 0b11) ? true : false; } tx_ancillary_session_sync_pacing(impl, s, false, 0, second_field); @@ -727,17 +680,15 @@ static int tx_ancillary_session_build_packet_chain( } /* rtp packet used twice for redundant path */ - if (s_port == MTL_SESSION_PORT_R) - rte_mbuf_refcnt_update(pkt_rtp, 1); + if (s_port == MTL_SESSION_PORT_R) rte_mbuf_refcnt_update(pkt_rtp, 1); return 0; } -static inline int -tx_ancillary_session_send_pkt(struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s, - enum mtl_session_port s_port, - struct rte_mbuf *pkt) { +static inline int tx_ancillary_session_send_pkt(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + enum mtl_session_port s_port, + struct rte_mbuf *pkt) { int ret; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); struct rte_ring *ring = mgr->ring[port]; @@ -754,10 +705,9 @@ tx_ancillary_session_send_pkt(struct st_tx_ancillary_sessions_mgr *mgr, return ret; } -static int -tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, - struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx; struct st40_tx_ops *ops = &s->ops; struct st_tx_ancillary_session_pacing *pacing = &s->pacing; @@ -812,8 +762,7 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; dbg("%s(%d), frame %d build time out %" PRIu64 " us\n", __func__, idx, - s->st40_frame_idx, - (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); + s->st40_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } s->check_frame_done_time = false; } @@ -822,8 +771,7 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, /* Query next frame buffer idx */ uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); ret = ops->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; @@ -838,8 +786,7 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, struct st_frame_trans *frame = &s->st40_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, - next_frame_idx, refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, refcnt); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -849,19 +796,17 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, dbg("%s(%d), next_frame_idx %d start\n", __func__, idx, next_frame_idx); s->st40_frame_stat = ST40_TX_STAT_SENDING_PKTS; struct st40_frame *src = (struct st40_frame *)frame->addr; - for (int i = 0; i < src->meta_num; i++) - total_udw += src->meta[i].udw_size; + for (int i = 0; i < src->meta_num; i++) total_udw += src->meta[i].udw_size; int total_size = total_udw * 10 / 8; s->st40_pkt_idx = 0; s->st40_total_pkts = total_size / s->max_pkt_len; - if (total_size % s->max_pkt_len) - s->st40_total_pkts++; + if (total_size % s->max_pkt_len) s->st40_total_pkts++; /* how do we split if it need two or more pkts? */ - dbg("%s(%d), st40_total_pkts %d total_udw %d meta_num %u src %p\n", - __func__, idx, s->st40_total_pkts, total_udw, src->meta_num, src); + dbg("%s(%d), st40_total_pkts %d total_udw %d meta_num %u src %p\n", __func__, idx, + s->st40_total_pkts, total_udw, src->meta_num, src); if (s->st40_total_pkts > 1) { - err("%s(%d), frame %u invalid st40_total_pkts %d\n", __func__, idx, - next_frame_idx, s->st40_total_pkts); + err("%s(%d), frame %u invalid st40_total_pkts %d\n", __func__, idx, next_frame_idx, + s->st40_total_pkts); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -874,11 +819,10 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, if (s->calculate_time_cursor) { struct st_frame_trans *frame = &s->st40_frames[s->st40_frame_idx]; /* user timestamp control if any */ - uint64_t required_tai = tx_ancillary_pacing_required_tai( - s, frame->tc_meta.tfmt, frame->tc_meta.timestamp); + uint64_t required_tai = tx_ancillary_pacing_required_tai(s, frame->tc_meta.tfmt, + frame->tc_meta.timestamp); bool second_field = frame->tc_meta.second_field; - tx_ancillary_session_sync_pacing(impl, s, false, required_tai, - second_field); + tx_ancillary_session_sync_pacing(impl, s, false, required_tai, second_field); if (ops->flags & ST40_TX_FLAG_USER_TIMESTAMP && (frame->ta_meta.tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK)) { pacing->rtp_time_stamp = (uint32_t)frame->tc_meta.timestamp; @@ -904,8 +848,8 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, - idx, cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } @@ -928,8 +872,7 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, return MTL_TASKLET_ALL_DONE; } tx_ancillary_session_build_rtp_packet(s, pkt_rtp, s->st40_pkt_idx); - tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, - MTL_SESSION_PORT_P); + tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, MTL_SESSION_PORT_P); if (send_r) { pkt_r = rte_pktmbuf_alloc(hdr_pool_r); @@ -994,15 +937,13 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, struct st40_tx_frame_meta *tc_meta = &frame->tc_meta; uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); /* end of current frame */ if (s->ops.notify_frame_done) ops->notify_frame_done(ops->priv, s->st40_frame_idx, tc_meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = - RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); } rte_atomic32_dec(&frame->refcnt); s->st40_frame_stat = ST40_TX_STAT_WAIT_FRAME; @@ -1017,10 +958,9 @@ tx_ancillary_session_tasklet_frame(struct mtl_main_impl *impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int -tx_ancillary_session_tasklet_rtp(struct mtl_main_impl *impl, - struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_tasklet_rtp(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx; int ret; struct st_tx_ancillary_session_pacing *pacing = &s->pacing; @@ -1074,8 +1014,8 @@ tx_ancillary_session_tasklet_rtp(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, - idx, cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } @@ -1115,8 +1055,7 @@ tx_ancillary_session_tasklet_rtp(struct mtl_main_impl *impl, pkt = pkt_rtp; tx_ancillary_session_rtp_update_packet(impl, s, pkt); } else { - tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, - MTL_SESSION_PORT_P); + tx_ancillary_session_build_packet_chain(impl, s, pkt, pkt_rtp, MTL_SESSION_PORT_P); } st_tx_mbuf_set_idx(pkt, s->st40_pkt_idx); st_tx_mbuf_set_tsc(pkt, pacing->tsc_time_cursor); @@ -1172,10 +1111,8 @@ static int tx_ancillary_sessions_tasklet_handler(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_ancillary_session_try_get(mgr, sidx); - if (!s) - continue; - if (time_measure) - tsc_s = mt_get_tsc(impl); + if (!s) continue; + if (time_measure) tsc_s = mt_get_tsc(impl); s->stat_build_ret_code = 0; if (s->ops.type == ST40_TYPE_FRAME_LEVEL) @@ -1193,9 +1130,8 @@ static int tx_ancillary_sessions_tasklet_handler(void *priv) { return pending; } -static int -tx_ancillary_sessions_mgr_uinit_hw(struct st_tx_ancillary_sessions_mgr *mgr, - enum mtl_port port) { +static int tx_ancillary_sessions_mgr_uinit_hw(struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { if (mgr->ring[port]) { rte_ring_free(mgr->ring[port]); mgr->ring[port] = NULL; @@ -1203,8 +1139,7 @@ tx_ancillary_sessions_mgr_uinit_hw(struct st_tx_ancillary_sessions_mgr *mgr, if (mgr->queue[port]) { struct rte_mbuf *pad = mt_get_pad(mgr->parent, port); /* flush all the pkts in the tx ring desc */ - if (pad) - mt_txq_flush(mgr->queue[port], pad); + if (pad) mt_txq_flush(mgr->queue[port], pad); mt_txq_put(mgr->queue[port]); mgr->queue[port] = NULL; } @@ -1213,17 +1148,15 @@ tx_ancillary_sessions_mgr_uinit_hw(struct st_tx_ancillary_sessions_mgr *mgr, return 0; } -static int -tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl *impl, - struct st_tx_ancillary_sessions_mgr *mgr, - enum mtl_port port) { +static int tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { unsigned int flags, count; struct rte_ring *ring; char ring_name[32]; int mgr_idx = mgr->idx; - if (mgr->queue[port]) - return 0; /* init already */ + if (mgr->queue[port]) return 0; /* init already */ struct mt_txq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -1233,8 +1166,7 @@ tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl *impl, } snprintf(ring_name, 32, "%sM%dP%d", ST_TX_ANCILLARY_PREFIX, mgr_idx, port); - flags = RING_F_MP_HTS_ENQ | - RING_F_SC_DEQ; /* multi-producer and single-consumer */ + flags = RING_F_MP_HTS_ENQ | RING_F_SC_DEQ; /* multi-producer and single-consumer */ count = ST_TX_ANC_SESSIONS_RING_SIZE; ring = rte_ring_create(ring_name, count, mgr->socket_id, flags); if (!ring) { @@ -1249,9 +1181,8 @@ tx_ancillary_sessions_mgr_init_hw(struct mtl_main_impl *impl, return 0; } -static int -tx_ancillary_session_sq_flush_port(struct st_tx_ancillary_sessions_mgr *mgr, - enum mtl_port port) { +static int tx_ancillary_session_sq_flush_port(struct st_tx_ancillary_sessions_mgr *mgr, + enum mtl_port port) { struct mtl_main_impl *impl = mgr->parent; int ret; int burst_pkts = mt_if_nb_tx_desc(impl, port); @@ -1282,27 +1213,23 @@ static int tx_ancillary_session_flush(struct st_tx_ancillary_sessions_mgr *mgr, struct st_tx_ancillary_session_impl *s) { int mgr_idx = mgr->idx, s_idx = s->idx; - if (!s->shared_queue) - return 0; /* skip as not shared queue */ + if (!s->shared_queue) return 0; /* skip as not shared queue */ for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { struct rte_mempool *pool = s->mbuf_mempool_hdr[i]; if (pool && rte_mempool_in_use_count(pool) && rte_atomic32_read(&mgr->transmitter_started)) { info("%s(%d,%d), start to flush port %d\n", __func__, mgr_idx, s_idx, i); - tx_ancillary_session_sq_flush_port(mgr, - mt_port_logic2phy(s->port_maps, i)); + tx_ancillary_session_sq_flush_port(mgr, mt_port_logic2phy(s->port_maps, i)); info("%s(%d,%d), flush port %d end\n", __func__, mgr_idx, s_idx, i); int retry = 100; /* max 1000ms */ while (retry > 0) { retry--; - if (!rte_mempool_in_use_count(pool)) - break; + if (!rte_mempool_in_use_count(pool)) break; mt_sleep_ms(10); } - info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, - retry); + info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, retry); } } @@ -1314,39 +1241,34 @@ int tx_ancillary_session_mempool_free(struct st_tx_ancillary_session_impl *s) { if (s->mbuf_mempool_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_chain); - if (ret >= 0) - s->mbuf_mempool_chain = NULL; + if (ret >= 0) s->mbuf_mempool_chain = NULL; } for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { if (s->mbuf_mempool_hdr[i] && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_hdr[i]); - if (ret >= 0) - s->mbuf_mempool_hdr[i] = NULL; + if (ret >= 0) s->mbuf_mempool_hdr[i] = NULL; } } return 0; } -static bool -tx_ancillary_session_has_chain_buf(struct st_tx_ancillary_session_impl *s) { +static bool tx_ancillary_session_has_chain_buf(struct st_tx_ancillary_session_impl *s) { struct st40_tx_ops *ops = &s->ops; int num_ports = ops->num_port; for (int port = 0; port < num_ports; port++) { - if (!s->eth_has_chain[port]) - return false; + if (!s->eth_has_chain[port]) return false; } /* all ports capable chain */ return true; } -static int -tx_ancillary_session_mempool_init(struct mtl_main_impl *impl, - struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_mempool_init(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { struct st40_tx_ops *ops = &s->ops; int num_port = ops->num_port, idx = s->idx; enum mtl_port port; @@ -1370,14 +1292,13 @@ tx_ancillary_session_mempool_init(struct mtl_main_impl *impl, warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, i); } else { n = mt_if_nb_tx_desc(impl, port) + ST_TX_ANC_SESSIONS_RING_SIZE; - if (ops->type == ST40_TYPE_RTP_LEVEL) - n += ops->rtp_ring_size; + if (ops->type == ST40_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%dP%d_HDR", ST_TX_ANCILLARY_PREFIX, - mgr->idx, idx, i); + snprintf(pool_name, 32, "%sM%dS%dP%d_HDR", ST_TX_ANCILLARY_PREFIX, mgr->idx, idx, + i); struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), hdr_room_size, s->socket_id); + impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), + hdr_room_size, s->socket_id); if (!mbuf_pool) { tx_ancillary_session_mempool_free(s); return -ENOMEM; @@ -1390,8 +1311,7 @@ tx_ancillary_session_mempool_init(struct mtl_main_impl *impl, if (!s->tx_no_chain) { port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); n = mt_if_nb_tx_desc(impl, port) + ST_TX_ANC_SESSIONS_RING_SIZE; - if (ops->type == ST40_TYPE_RTP_LEVEL) - n += ops->rtp_ring_size; + if (ops->type == ST40_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; if (s->tx_mono_pool) { s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port); @@ -1401,11 +1321,10 @@ tx_ancillary_session_mempool_init(struct mtl_main_impl *impl, warn("%s(%d), use previous chain mempool\n", __func__, idx); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_CHAIN", ST_TX_ANCILLARY_PREFIX, - mgr->idx, idx); + snprintf(pool_name, 32, "%sM%dS%d_CHAIN", ST_TX_ANCILLARY_PREFIX, mgr->idx, idx); struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), chain_room_size, s->socket_id); + impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), + chain_room_size, s->socket_id); if (!mbuf_pool) { tx_ancillary_session_mempool_free(s); return -ENOMEM; @@ -1417,17 +1336,15 @@ tx_ancillary_session_mempool_init(struct mtl_main_impl *impl, return 0; } -static int -tx_ancillary_session_init_rtp(struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_init_rtp(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { char ring_name[32]; struct rte_ring *ring; unsigned int flags, count = s->ops.rtp_ring_size; int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_TX_ANCILLARY_PREFIX, mgr_idx, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { err("%s(%d,%d), rte_ring_create fail\n", __func__, mgr_idx, idx); @@ -1439,9 +1356,8 @@ tx_ancillary_session_init_rtp(struct st_tx_ancillary_sessions_mgr *mgr, return 0; } -static int -tx_ancillary_session_uinit_sw(struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_uinit_sw(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx, num_port = s->ops.num_port; for (int port = 0; port < num_port; port++) { @@ -1466,10 +1382,9 @@ tx_ancillary_session_uinit_sw(struct st_tx_ancillary_sessions_mgr *mgr, return 0; } -static int -tx_ancillary_session_init_sw(struct mtl_main_impl *impl, - struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_init_sw(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { struct st40_tx_ops *ops = &s->ops; int idx = s->idx, ret; @@ -1496,9 +1411,8 @@ tx_ancillary_session_init_sw(struct mtl_main_impl *impl, return 0; } -static int -tx_ancillary_session_uinit_queue(struct mtl_main_impl *impl, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_uinit_queue(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s) { MTL_MAY_UNUSED(impl); for (int i = 0; i < s->ops.num_port; i++) { @@ -1513,9 +1427,8 @@ tx_ancillary_session_uinit_queue(struct mtl_main_impl *impl, return 0; } -static int -tx_ancillary_session_init_queue(struct mtl_main_impl *impl, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_session_init_queue(struct mtl_main_impl *impl, + struct st_tx_ancillary_session_impl *s) { int idx = s->idx; enum mtl_port port; uint16_t queue_id; @@ -1550,8 +1463,7 @@ tx_ancillary_session_init_queue(struct mtl_main_impl *impl, return -EIO; } queue_id = mt_txq_queue_id(s->queue[i]); - info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, - queue_id); + info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, queue_id); } return 0; @@ -1573,17 +1485,14 @@ static int tx_ancillary_session_attach(struct mtl_main_impl *impl, char *ports[MTL_SESSION_PORT_MAX]; bool rdma_ud = false; - for (int i = 0; i < num_port; i++) - ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* use dedicated queue for rdma_ud */ for (int i = 0; i < num_port; i++) { enum mtl_port port = mt_port_logic2phy(s->port_maps, i); - if (mt_pmd_is_rdma_ud(impl, port)) - rdma_ud = true; + if (mt_pmd_is_rdma_ud(impl, port)) rdma_ud = true; } s->mgr = mgr; @@ -1596,14 +1505,11 @@ static int tx_ancillary_session_attach(struct mtl_main_impl *impl, /* if disable shared queue */ s->shared_queue = true; - if (ops->flags & ST40_TX_FLAG_DEDICATE_QUEUE) - s->shared_queue = false; - if (rdma_ud) - s->shared_queue = false; + if (ops->flags & ST40_TX_FLAG_DEDICATE_QUEUE) s->shared_queue = false; + if (rdma_ud) s->shared_queue = false; for (int i = 0; i < num_port; i++) { - s->st40_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (10200 + idx * 2); + s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10200 + idx * 2); if (mt_user_random_src_port(impl)) s->st40_src_port[i] = mt_random_port(s->st40_dst_port[i]); else @@ -1623,10 +1529,8 @@ static int tx_ancillary_session_attach(struct mtl_main_impl *impl, } s->tx_mono_pool = mt_user_tx_mono_pool(impl); /* manually disable chain or any port can't support chain */ - s->tx_no_chain = - mt_user_tx_no_chain(impl) || !tx_ancillary_session_has_chain_buf(s); - if (rdma_ud) - s->tx_no_chain = true; + s->tx_no_chain = mt_user_tx_no_chain(impl) || !tx_ancillary_session_has_chain_buf(s); + if (rdma_ud) s->tx_no_chain = true; s->max_pkt_len = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc8331_anc_hdr); s->st40_frames_cnt = ops->framebuff_cnt; @@ -1680,9 +1584,8 @@ static int tx_ancillary_session_attach(struct mtl_main_impl *impl, rte_atomic32_inc(&mgr->transmitter_clients); } - info("%s(%d), type %d flags 0x%x pt %u, %s\n", __func__, idx, ops->type, - ops->flags, ops->payload_type, - ops->interlaced ? "interlace" : "progressive"); + info("%s(%d), type %d flags 0x%x pt %u, %s\n", __func__, idx, ops->type, ops->flags, + ops->payload_type, ops->interlaced ? "interlace" : "progressive"); return 0; } @@ -1696,16 +1599,14 @@ static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl *s) { rte_atomic32_set(&s->st40_stat_frame_cnt, 0); s->stat_last_time = cur_time_ns; - notice("TX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d:%d\n", idx, - s->ops_name, framerate, frame_cnt, - s->st40_stat_pkt_cnt[MTL_SESSION_PORT_P], + notice("TX_ANC_SESSION(%d:%s): fps %f frames %d pkts %d:%d\n", idx, s->ops_name, + framerate, frame_cnt, s->st40_stat_pkt_cnt[MTL_SESSION_PORT_P], s->st40_stat_pkt_cnt[MTL_SESSION_PORT_R]); s->st40_stat_pkt_cnt[MTL_SESSION_PORT_P] = 0; s->st40_stat_pkt_cnt[MTL_SESSION_PORT_R] = 0; if (s->stat_epoch_mismatch) { - notice("TX_ANC_SESSION(%d): st40 epoch mismatch %d\n", idx, - s->stat_epoch_mismatch); + notice("TX_ANC_SESSION(%d): st40 epoch mismatch %d\n", idx, s->stat_epoch_mismatch); s->stat_epoch_mismatch = 0; } if (s->stat_epoch_drop) { @@ -1725,8 +1626,8 @@ static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl *s) { warn("TX_ANC_SESSION(%d): build ret %d\n", idx, s->stat_build_ret_code); } if (s->ops.interlaced) { - notice("TX_ANC_SESSION(%d): interlace first field %u second field %u\n", - idx, s->stat_interlace_first_field, s->stat_interlace_second_field); + notice("TX_ANC_SESSION(%d): interlace first field %u second field %u\n", idx, + s->stat_interlace_first_field, s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } @@ -1740,16 +1641,14 @@ static void tx_ancillary_session_stat(struct st_tx_ancillary_session_impl *s) { struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice( - "TX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", - idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice("TX_ANC_SESSION(%d): tasklet time avg %.2fus max %.2fus min %.2fus\n", idx, + (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_next_frame_us > 8 || s->stat_max_notify_frame_us > 8) { - notice( - "TX_ANC_SESSION(%d): get next frame max %uus, notify done max %uus\n", - idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); + notice("TX_ANC_SESSION(%d): get next frame max %uus, notify done max %uus\n", idx, + s->stat_max_next_frame_us, s->stat_max_notify_frame_us); } s->stat_max_next_frame_us = 0; s->stat_max_notify_frame_us = 0; @@ -1765,9 +1664,10 @@ static int tx_ancillary_session_detach(struct st_tx_ancillary_sessions_mgr *mgr, return 0; } -static int tx_ancillary_session_update_dst( - struct mtl_main_impl *impl, struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s, struct st_tx_dest_info *dest) { +static int tx_ancillary_session_update_dst(struct mtl_main_impl *impl, + struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + struct st_tx_dest_info *dest) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; struct st40_tx_ops *ops = &s->ops; @@ -1776,8 +1676,7 @@ static int tx_ancillary_session_update_dst( for (int i = 0; i < num_port; i++) { memcpy(ops->dip_addr[i], dest->dip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = dest->udp_port[i]; - s->st40_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); + s->st40_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (30000 + idx * 2); s->st40_src_port[i] = (ops->udp_src_port[i]) ? (ops->udp_src_port[i]) : s->st40_dst_port[i]; @@ -1792,10 +1691,9 @@ static int tx_ancillary_session_update_dst( return 0; } -static int -tx_ancillary_sessions_mgr_update_dst(struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s, - struct st_tx_dest_info *dest) { +static int tx_ancillary_sessions_mgr_update_dst(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s, + struct st_tx_dest_info *dest) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = tx_ancillary_session_get(mgr, idx); /* get the lock */ @@ -1820,8 +1718,7 @@ static int st_tx_ancillary_sessions_stat(void *priv) { for (int j = 0; j < mgr->max_idx; j++) { s = tx_ancillary_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) - continue; + if (!s) continue; tx_ancillary_session_stat(s); tx_ancillary_session_put(mgr, j); } @@ -1840,10 +1737,9 @@ static int st_tx_ancillary_sessions_stat(void *priv) { return 0; } -static int -tx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, - struct st_tx_ancillary_sessions_mgr *mgr) { +static int tx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, + struct mtl_sch_impl *sch, + struct st_tx_ancillary_sessions_mgr *mgr) { int idx = sch->idx; struct mtl_tasklet_ops ops; int i; @@ -1875,9 +1771,8 @@ tx_ancillary_sessions_mgr_init(struct mtl_main_impl *impl, return 0; } -static struct st_tx_ancillary_session_impl * -tx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, - struct st40_tx_ops *ops) { +static struct st_tx_ancillary_session_impl *tx_ancillary_sessions_mgr_attach( + struct mtl_sch_impl *sch, struct st40_tx_ops *ops) { struct st_tx_ancillary_sessions_mgr *mgr = &sch->tx_anc_mgr; int midx = mgr->idx; int ret; @@ -1886,8 +1781,7 @@ tx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, /* find one empty slot in the mgr */ for (int i = 0; i < ST_MAX_TX_ANC_SESSIONS; i++) { - if (!tx_ancillary_session_get_empty(mgr, i)) - continue; + if (!tx_ancillary_session_get_empty(mgr, i)) continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -1921,9 +1815,8 @@ tx_ancillary_sessions_mgr_attach(struct mtl_sch_impl *sch, return NULL; } -static int -tx_ancillary_sessions_mgr_detach(struct st_tx_ancillary_sessions_mgr *mgr, - struct st_tx_ancillary_session_impl *s) { +static int tx_ancillary_sessions_mgr_detach(struct st_tx_ancillary_sessions_mgr *mgr, + struct st_tx_ancillary_session_impl *s) { int midx = mgr->idx; int idx = s->idx; @@ -1942,21 +1835,18 @@ tx_ancillary_sessions_mgr_detach(struct st_tx_ancillary_sessions_mgr *mgr, return 0; } -static int -tx_ancillary_sessions_mgr_update(struct st_tx_ancillary_sessions_mgr *mgr) { +static int tx_ancillary_sessions_mgr_update(struct st_tx_ancillary_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_MAX_TX_ANC_SESSIONS; i++) { - if (mgr->sessions[i]) - max_idx = i + 1; + if (mgr->sessions[i]) max_idx = i + 1; } mgr->max_idx = max_idx; return 0; } -static int -tx_ancillary_sessions_mgr_uinit(struct st_tx_ancillary_sessions_mgr *mgr) { +static int tx_ancillary_sessions_mgr_uinit(struct st_tx_ancillary_sessions_mgr *mgr) { int m_idx = mgr->idx; struct mtl_main_impl *impl = mgr->parent; struct st_tx_ancillary_session_impl *s; @@ -1970,8 +1860,7 @@ tx_ancillary_sessions_mgr_uinit(struct st_tx_ancillary_sessions_mgr *mgr) { for (int i = 0; i < ST_MAX_TX_ANC_SESSIONS; i++) { s = tx_ancillary_session_get(mgr, i); - if (!s) - continue; + if (!s) continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); tx_ancillary_sessions_mgr_detach(mgr, s); @@ -1999,16 +1888,14 @@ static int tx_ancillary_ops_check(struct st40_tx_ops *ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -2041,12 +1928,10 @@ static int tx_ancillary_ops_check(struct st40_tx_ops *ops) { return 0; } -static int st_tx_anc_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { +static int st_tx_anc_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { int ret; - if (sch->tx_anc_init) - return 0; + if (sch->tx_anc_init) return 0; /* create tx ancillary context */ ret = tx_ancillary_sessions_mgr_init(impl, sch, &sch->tx_anc_mgr); @@ -2054,8 +1939,7 @@ static int st_tx_anc_init(struct mtl_main_impl *impl, err("%s, tx_ancillary_sessions_mgr_init fail\n", __func__); return ret; } - ret = - st_ancillary_transmitter_init(impl, sch, &sch->tx_anc_mgr, &sch->anc_trs); + ret = st_ancillary_transmitter_init(impl, sch, &sch->tx_anc_mgr, &sch->anc_trs); if (ret < 0) { tx_ancillary_sessions_mgr_uinit(&sch->tx_anc_mgr); err("%s, st_ancillary_transmitter_init fail %d\n", __func__, ret); @@ -2067,8 +1951,7 @@ static int st_tx_anc_init(struct mtl_main_impl *impl, } int st_tx_ancillary_sessions_sch_uinit(struct mtl_sch_impl *sch) { - if (!sch->tx_anc_init) - return 0; + if (!sch->tx_anc_init) return 0; /* free tx ancillary context */ st_ancillary_transmitter_uinit(&sch->anc_trs); @@ -2099,8 +1982,7 @@ st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops *ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); s_impl = mt_rte_zmalloc_socket(sizeof(*s_impl), socket); @@ -2110,8 +1992,8 @@ st40_tx_handle st40_tx_create(mtl_handle mt, struct st40_tx_ops *ops) { } quota_mbs = 0; - sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, - MT_SCH_MASK_ALL, socket); + sch = + mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -2174,9 +2056,8 @@ void *st40_tx_get_mbuf(st40_tx_handle handle, void **usrptr) { return NULL; } - struct rte_mempool *mp = s->tx_no_chain - ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] - : s->mbuf_mempool_chain; + struct rte_mempool *mp = + s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -2201,8 +2082,7 @@ int st40_tx_put_mbuf(st40_tx_handle handle, void *mbuf, uint16_t len) { } if (!mt_rtp_len_valid(len)) { - if (len) - err("%s, invalid len %d\n", __func__, len); + if (len) err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -2216,8 +2096,7 @@ int st40_tx_put_mbuf(st40_tx_handle handle, void *mbuf, uint16_t len) { return -EIO; } - if (s->tx_no_chain) - len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); @@ -2230,8 +2109,7 @@ int st40_tx_put_mbuf(st40_tx_handle handle, void *mbuf, uint16_t len) { return 0; } -int st40_tx_update_destination(st40_tx_handle handle, - struct st_tx_dest_info *dst) { +int st40_tx_update_destination(st40_tx_handle handle, struct st_tx_dest_info *dst) { struct st_tx_ancillary_session_handle_impl *s_impl = handle; struct st_tx_ancillary_session_impl *s; struct mtl_sch_impl *sch; @@ -2248,8 +2126,7 @@ int st40_tx_update_destination(st40_tx_handle handle, sch_idx = sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tx_ancillary_sessions_mgr_update_dst(&sch->tx_anc_mgr, s, dst); if (ret < 0) { @@ -2284,12 +2161,10 @@ int st40_tx_free(st40_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_anc_mgr_mutex); ret = tx_ancillary_sessions_mgr_detach(&sch->tx_anc_mgr, s); mt_pthread_mutex_unlock(&sch->tx_anc_mgr_mutex); - if (ret < 0) - err("%s(%d), tx_ancillary_sessions_mgr_detach fail\n", __func__, idx); + if (ret < 0) err("%s(%d), tx_ancillary_sessions_mgr_detach fail\n", __func__, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); diff --git a/lib/src/st2110/st_tx_audio_session.c b/lib/src/st2110/st_tx_audio_session.c index 8a8a43104..b3c035f44 100644 --- a/lib/src/st2110/st_tx_audio_session.c +++ b/lib/src/st2110/st_tx_audio_session.c @@ -11,41 +11,35 @@ #include "st_err.h" /* call tx_audio_session_put always if get successfully */ -static inline struct st_tx_audio_session_impl * -tx_audio_session_get(struct st_tx_audio_sessions_mgr *mgr, int idx) { +static inline struct st_tx_audio_session_impl *tx_audio_session_get( + struct st_tx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_tx_audio_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_audio_session_put always if get successfully */ -static inline struct st_tx_audio_session_impl * -tx_audio_session_get_timeout(struct st_tx_audio_sessions_mgr *mgr, int idx, - int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) - return NULL; +static inline struct st_tx_audio_session_impl *tx_audio_session_get_timeout( + struct st_tx_audio_sessions_mgr *mgr, int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; struct st_tx_audio_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_audio_session_put always if get successfully */ -static inline struct st_tx_audio_session_impl * -tx_audio_session_try_get(struct st_tx_audio_sessions_mgr *mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) - return NULL; +static inline struct st_tx_audio_session_impl *tx_audio_session_try_get( + struct st_tx_audio_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; struct st_tx_audio_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_audio_session_put always if get successfully */ -static inline bool -tx_audio_session_get_empty(struct st_tx_audio_sessions_mgr *mgr, int idx) { +static inline bool tx_audio_session_get_empty(struct st_tx_audio_sessions_mgr *mgr, + int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_tx_audio_session_impl *s = mgr->sessions[idx]; if (s) { @@ -56,8 +50,7 @@ tx_audio_session_get_empty(struct st_tx_audio_sessions_mgr *mgr, int idx) { } } -static inline void tx_audio_session_put(struct st_tx_audio_sessions_mgr *mgr, - int idx) { +static inline void tx_audio_session_put(struct st_tx_audio_sessions_mgr *mgr, int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } @@ -67,8 +60,7 @@ static int tx_audio_session_free_frames(struct st_tx_audio_session_impl *s) { /* dec ref for current frame */ frame = &s->st30_frames[s->st30_frame_idx]; - if (rte_atomic32_read(&frame->refcnt)) - rte_atomic32_dec(&frame->refcnt); + if (rte_atomic32_read(&frame->refcnt)) rte_atomic32_dec(&frame->refcnt); for (int i = 0; i < s->st30_frames_cnt; i++) { frame = &s->st30_frames[i]; @@ -93,8 +85,8 @@ static int tx_audio_session_alloc_frames(struct st_tx_audio_session_impl *s) { return -EIO; } - s->st30_frames = mt_rte_zmalloc_socket( - sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); + s->st30_frames = + mt_rte_zmalloc_socket(sizeof(*s->st30_frames) * s->st30_frames_cnt, soc_id); if (!s->st30_frames) { err("%s(%d), st30_frames malloc fail\n", __func__, idx); return -ENOMEM; @@ -111,8 +103,7 @@ static int tx_audio_session_alloc_frames(struct st_tx_audio_session_impl *s) { void *frame = mt_rte_zmalloc_socket(s->st30_frame_size, soc_id); if (!frame) { - err("%s(%d), rte_malloc %u fail at %d\n", __func__, idx, - s->st30_frame_size, i); + err("%s(%d), rte_malloc %u fail at %d\n", __func__, idx, s->st30_frame_size, i); tx_audio_session_free_frames(s); return -ENOMEM; } @@ -144,21 +135,17 @@ static int tx_audio_session_init_hdr(struct mtl_main_impl *impl, struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); /* ether hdr */ - if ((s_port == MTL_SESSION_PORT_P) && - (ops->flags & ST30_TX_FLAG_USER_P_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], - RTE_ETHER_ADDR_LEN); + if ((s_port == MTL_SESSION_PORT_P) && (ops->flags & ST30_TX_FLAG_USER_P_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); info("%s, USER_P_TX_MAC\n", __func__); - } else if ((s_port == MTL_SESSION_PORT_R) && - (ops->flags & ST30_TX_FLAG_USER_R_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], - RTE_ETHER_ADDR_LEN); + } else if ((s_port == MTL_SESSION_PORT_R) && (ops->flags & ST30_TX_FLAG_USER_R_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); info("%s, USER_R_TX_MAC\n", __func__); } else { ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, - dip[0], dip[1], dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], + dip[2], dip[3]); return ret; } } @@ -202,13 +189,12 @@ static int tx_audio_session_init_hdr(struct mtl_main_impl *impl, s->st30_seq_id = 0; - info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u payload_type %u\n", __func__, idx, - s_port, dip[0], dip[1], dip[2], dip[3], s->st30_src_port[s_port], - s->st30_dst_port[s_port], rtp->payload_type); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", - __func__, idx, d_addr->addr_bytes[0], d_addr->addr_bytes[1], - d_addr->addr_bytes[2], d_addr->addr_bytes[3], d_addr->addr_bytes[4], - d_addr->addr_bytes[5], ssrc); + info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u payload_type %u\n", __func__, idx, s_port, + dip[0], dip[1], dip[2], dip[3], s->st30_src_port[s_port], s->st30_dst_port[s_port], + rtp->payload_type); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", __func__, idx, + d_addr->addr_bytes[0], d_addr->addr_bytes[1], d_addr->addr_bytes[2], + d_addr->addr_bytes[3], d_addr->addr_bytes[4], d_addr->addr_bytes[5], ssrc); return 0; } @@ -217,8 +203,7 @@ static int tx_audio_session_init_pacing(struct st_tx_audio_session_impl *s) { struct st_tx_audio_session_pacing *pacing = &s->pacing; struct st30_tx_ops *ops = &s->ops; double pkt_time = st30_get_packet_time(ops->ptime); - if (pkt_time < 0) - return -EINVAL; + if (pkt_time < 0) return -EINVAL; pacing->pkt_time_sampling = (double)(s->sample_num * 1000) * 1 / 1000; pacing->trs = pkt_time; @@ -233,24 +218,21 @@ static int tx_audio_session_init_pacing(struct st_tx_audio_session_impl *s) { return 0; } -static int -tx_audio_session_init_pacing_epoch(struct mtl_main_impl *impl, - struct st_tx_audio_session_impl *s) { +static int tx_audio_session_init_pacing_epoch(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s) { uint64_t ptp_time = mt_get_ptp_time(impl, MTL_PORT_P); struct st_tx_audio_session_pacing *pacing = &s->pacing; pacing->cur_epochs = ptp_time / pacing->trs; return 0; } -static inline double -tx_audio_pacing_time(struct st_tx_audio_session_pacing *pacing, - uint64_t epochs) { +static inline double tx_audio_pacing_time(struct st_tx_audio_session_pacing *pacing, + uint64_t epochs) { return epochs * pacing->trs; } -static inline uint32_t -tx_audio_pacing_time_stamp(struct st_tx_audio_session_pacing *pacing, - uint64_t epochs) { +static inline uint32_t tx_audio_pacing_time_stamp( + struct st_tx_audio_session_pacing *pacing, uint64_t epochs) { uint64_t tmstamp64 = epochs * pacing->pkt_time_sampling; uint32_t tmstamp32 = tmstamp64; @@ -262,18 +244,15 @@ static uint64_t tx_audio_pacing_required_tai(struct st_tx_audio_session_impl *s, uint64_t timestamp) { uint64_t required_tai = 0; - if (!(s->ops.flags & ST30_TX_FLAG_USER_PACING)) - return 0; - if (!timestamp) - return 0; + if (!(s->ops.flags & ST30_TX_FLAG_USER_PACING)) return 0; + if (!timestamp) return 0; if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (timestamp > 0xFFFFFFFF) { - err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, - timestamp); + err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, timestamp); } - required_tai = st10_media_clk_to_ns((uint32_t)timestamp, - st30_get_sample_rate(s->ops.sampling)); + required_tai = + st10_media_clk_to_ns((uint32_t)timestamp, st30_get_sample_rate(s->ops.sampling)); } else { required_tai = timestamp; } @@ -282,8 +261,8 @@ static uint64_t tx_audio_pacing_required_tai(struct st_tx_audio_session_impl *s, } static int tx_audio_session_sync_pacing(struct mtl_main_impl *impl, - struct st_tx_audio_session_impl *s, - bool sync, uint64_t required_tai) { + struct st_tx_audio_session_impl *s, bool sync, + uint64_t required_tai) { struct st_tx_audio_session_pacing *pacing = &s->pacing; double pkt_time = pacing->trs; /* always use MTL_PORT_P for ptp now */ @@ -295,11 +274,9 @@ static int tx_audio_session_sync_pacing(struct mtl_main_impl *impl, if (required_tai) { uint64_t ptp_epochs = ptp_time / pkt_time; epochs = required_tai / pkt_time; - dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 - " epochs %" PRIu64 "\n", + dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 " epochs %" PRIu64 "\n", __func__, s->idx, required_tai, ptp_epochs, epochs); - if (epochs < ptp_epochs) - s->stat_error_user_timestamp++; + if (epochs < ptp_epochs) s->stat_error_user_timestamp++; } else { epochs = ptp_time / pkt_time; @@ -328,18 +305,16 @@ static int tx_audio_session_sync_pacing(struct mtl_main_impl *impl, to_epoch = 0; /* send asap */ } - if (epochs > next_epochs) - s->stat_epoch_drop += (epochs - next_epochs); - if (epochs < next_epochs) - s->stat_epoch_onward += (next_epochs - epochs); + if (epochs > next_epochs) s->stat_epoch_drop += (epochs - next_epochs); + if (epochs < next_epochs) s->stat_epoch_onward += (next_epochs - epochs); pacing->cur_epochs = epochs; pacing->cur_epoch_time = tx_audio_pacing_time(pacing, epochs); pacing->pacing_time_stamp = tx_audio_pacing_time_stamp(pacing, epochs); pacing->rtp_time_stamp = pacing->pacing_time_stamp; pacing->tsc_time_cursor = (double)mt_get_tsc(impl) + to_epoch; - dbg("%s(%d), epochs %" PRIu64 ", rtp_time_stamp %u\n", __func__, s->idx, - epochs, pacing->rtp_time_stamp); + dbg("%s(%d), epochs %" PRIu64 ", rtp_time_stamp %u\n", __func__, s->idx, epochs, + pacing->rtp_time_stamp); if (sync) { dbg("%s(%d), delay to epoch_time %f, cur %" PRIu64 "\n", __func__, s->idx, @@ -381,8 +356,7 @@ static int tx_audio_sessions_tasklet_start(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_audio_session_get(mgr, sidx); - if (!s) - continue; + if (!s) continue; tx_audio_session_init_pacing_epoch(impl, s); tx_audio_session_put(mgr, sidx); @@ -490,9 +464,8 @@ static int tx_audio_session_build_rtp_packet(struct st_tx_audio_session_impl *s, return 0; } -static int -tx_audio_session_rtp_update_packet(struct st_tx_audio_session_impl *s, - struct rte_mbuf *pkt) { +static int tx_audio_session_rtp_update_packet(struct st_tx_audio_session_impl *s, + struct rte_mbuf *pkt) { struct mt_udp_hdr *hdr; struct rte_ipv4_hdr *ipv4; struct st_rfc3550_rtp_hdr *rtp; @@ -535,9 +508,10 @@ tx_audio_session_rtp_update_packet(struct st_tx_audio_session_impl *s, return 0; } -static int tx_audio_session_build_packet_chain( - struct st_tx_audio_session_impl *s, struct rte_mbuf *pkt, - struct rte_mbuf *pkt_rtp, enum mtl_session_port s_port) { +static int tx_audio_session_build_packet_chain(struct st_tx_audio_session_impl *s, + struct rte_mbuf *pkt, + struct rte_mbuf *pkt_rtp, + enum mtl_session_port s_port) { struct mt_udp_hdr *hdr; struct rte_ipv4_hdr *ipv4; struct rte_udp_hdr *udp; @@ -591,19 +565,17 @@ static int tx_audio_session_build_packet_chain( } /* rtp packet used twice for redundant path */ - if (s_port == MTL_SESSION_PORT_R) - rte_mbuf_refcnt_update(pkt_rtp, 1); + if (s_port == MTL_SESSION_PORT_R) rte_mbuf_refcnt_update(pkt_rtp, 1); return 0; } -static int -tx_audio_session_usdt_dump_close(struct st_tx_audio_session_impl *s) { +static int tx_audio_session_usdt_dump_close(struct st_tx_audio_session_impl *s) { int idx = s->idx; if (s->usdt_dump_fd >= 0) { - info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, - s->usdt_dump_fd, s->usdt_dumped_frames); + info("%s(%d), close fd %d, dumped frames %d\n", __func__, idx, s->usdt_dump_fd, + s->usdt_dumped_frames); close(s->usdt_dump_fd); s->usdt_dump_fd = -1; } @@ -620,17 +592,16 @@ static int tx_audio_session_usdt_dump_frame(struct st_tx_audio_session_impl *s, struct st30_tx_ops *ops = &s->ops; snprintf(s->usdt_dump_path, sizeof(s->usdt_dump_path), "imtl_usdt_st30tx_m%ds%d_%d_%d_c%u_XXXXXX.pcm", mgr->idx, idx, - st30_get_sample_rate(ops->sampling), - st30_get_sample_size(ops->fmt) * 8, ops->channel); + st30_get_sample_rate(ops->sampling), st30_get_sample_size(ops->fmt) * 8, + ops->channel); ret = mt_mkstemps(s->usdt_dump_path, strlen(".pcm")); if (ret < 0) { - err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, - ret); + err("%s(%d), mkstemps %s fail %d\n", __func__, idx, s->usdt_dump_path, ret); return ret; } s->usdt_dump_fd = ret; - info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, - s->usdt_dump_path, s->usdt_dump_fd); + info("%s(%d), mkstemps succ on %s fd %d\n", __func__, idx, s->usdt_dump_path, + s->usdt_dump_fd); } /* write frame to dump file */ @@ -709,8 +680,7 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; dbg("%s(%d), frame %d build time out %" PRIu64 " us\n", __func__, idx, - s->st30_frame_idx, - (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); + s->st30_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } s->check_frame_done_time = false; } @@ -718,13 +688,11 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, tx_audio_session_init_next_meta(s, &meta); /* Query next frame buffer idx */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); ret = ops->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_next_frame_us = - RTE_MAX(s->stat_max_next_frame_us, delta_us); + s->stat_max_next_frame_us = RTE_MAX(s->stat_max_next_frame_us, delta_us); } if (ret < 0) { /* no frame ready from app */ dbg("%s(%d), get_next_frame fail %d\n", __func__, idx, ret); @@ -735,8 +703,8 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, struct st_frame_trans *frame = &s->st30_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, - next_frame_idx, refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, + refcnt); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -745,8 +713,7 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, s->st30_frame_idx = next_frame_idx; dbg("%s(%d), next_frame_idx %d start\n", __func__, idx, next_frame_idx); s->st30_frame_stat = ST30_TX_STAT_SENDING_PKTS; - MT_USDT_ST30_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, - frame->addr); + MT_USDT_ST30_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, frame->addr); /* check if dump USDT enabled */ if (MT_USDT_ST30_TX_FRAME_DUMP_ENABLED()) { tx_audio_session_usdt_dump_frame(s, frame); @@ -759,8 +726,8 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, if (s->calculate_time_cursor) { struct st_frame_trans *frame = &s->st30_frames[s->st30_frame_idx]; /* user timestamp control if any */ - uint64_t required_tai = tx_audio_pacing_required_tai( - s, frame->ta_meta.tfmt, frame->ta_meta.timestamp); + uint64_t required_tai = + tx_audio_pacing_required_tai(s, frame->ta_meta.tfmt, frame->ta_meta.timestamp); tx_audio_session_sync_pacing(impl, s, false, required_tai); if (ops->flags & ST30_TX_FLAG_USER_TIMESTAMP && (frame->ta_meta.tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK)) { @@ -784,8 +751,8 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", - __func__, idx, cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } } @@ -819,8 +786,7 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_FAIL; return MTL_TASKLET_ALL_DONE; } - tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, - MTL_SESSION_PORT_R); + tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, MTL_SESSION_PORT_R); } } else { tx_audio_session_build_packet(s, pkt); @@ -870,15 +836,13 @@ static int tx_audio_session_tasklet_frame(struct mtl_main_impl *impl, struct st30_tx_frame_meta *ta_meta = &frame->ta_meta; uint64_t tsc_start = 0; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); /* end of current frame */ if (ops->notify_frame_done) ops->notify_frame_done(ops->priv, s->st30_frame_idx, ta_meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = - RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); } rte_atomic32_dec(&frame->refcnt); @@ -941,8 +905,7 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl *impl, } /* sync pacing */ - if (!pacing->tsc_time_cursor) - tx_audio_session_sync_pacing(impl, s, false, 0); + if (!pacing->tsc_time_cursor) tx_audio_session_sync_pacing(impl, s, false, 0); if (s->pacing_in_build) { uint64_t cur_tsc = mt_get_tsc(impl); @@ -956,8 +919,8 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", - __func__, idx, cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } } @@ -1014,8 +977,7 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl *impl, } tx_audio_session_update_redundant(s, pkt_r); } else { - tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, - MTL_SESSION_PORT_R); + tx_audio_session_build_packet_chain(s, pkt_r, pkt_rtp, MTL_SESSION_PORT_R); } st_tx_mbuf_set_tsc(pkt_r, pacing->tsc_time_cursor); s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R]++; @@ -1038,9 +1000,10 @@ static int tx_audio_session_tasklet_rtp(struct mtl_main_impl *impl, return done ? MTL_TASKLET_ALL_DONE : MTL_TASKLET_HAS_PENDING; } -static int tx_audio_session_tasklet_transmit( - struct mtl_main_impl *impl, struct st_tx_audio_sessions_mgr *mgr, - struct st_tx_audio_session_impl *s, int s_port) { +static int tx_audio_session_tasklet_transmit(struct mtl_main_impl *impl, + struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, + int s_port) { int idx = s->idx, ret; struct rte_mbuf *pkt; enum mtl_port t_port = mt_port_logic2phy(s->port_maps, s_port); @@ -1098,8 +1061,8 @@ static int tx_audio_session_tasklet_transmit( return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, - idx, cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } @@ -1167,12 +1130,11 @@ static int tx_audio_session_uinit_rl(struct mtl_main_impl *impl, return 0; } -static inline uint64_t -tx_audio_session_initial_rl_bps(struct st_tx_audio_session_impl *s) { +static inline uint64_t tx_audio_session_initial_rl_bps( + struct st_tx_audio_session_impl *s) { struct st_tx_audio_session_rl_info *rl = &s->rl; - double bps = - (double)(s->st30_pkt_size + rl->pad_pkt_size * rl->pads_per_st30_pkt) * - (double)NS_PER_S / s->pacing.trs; + double bps = (double)(s->st30_pkt_size + rl->pad_pkt_size * rl->pads_per_st30_pkt) * + (double)NS_PER_S / s->pacing.trs; return bps; } @@ -1190,8 +1152,7 @@ static int double_cmp(const void *a, const void *b) { static inline uint64_t tx_audio_session_profiling_rl_bps( struct mtl_main_impl *impl, struct st_tx_audio_session_impl *s, - enum mtl_session_port s_port, uint64_t initial_bytes_per_sec, - int rl_q_idx) { + enum mtl_session_port s_port, uint64_t initial_bytes_per_sec, int rl_q_idx) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); int idx = s->idx; struct st_tx_audio_session_rl_info *rl = &s->rl; @@ -1232,8 +1193,8 @@ static inline uint64_t tx_audio_session_profiling_rl_bps( uint64_t tsc_end = mt_get_tsc(impl); double time_sec = (double)(tsc_end - tsc_start) / NS_PER_S; loop_actual_per_sec[loop] = total / time_sec; - dbg("%s(%d), pkts per second expect %f actual %f\n", __func__, idx, - expect_per_sec, loop_actual_per_sec[loop]); + dbg("%s(%d), pkts per second expect %f actual %f\n", __func__, idx, expect_per_sec, + loop_actual_per_sec[loop]); } /* sort */ qsort(loop_actual_per_sec, loop_cnt, sizeof(double), double_cmp); @@ -1246,12 +1207,12 @@ static inline uint64_t tx_audio_session_profiling_rl_bps( double actual_per_sec = actual_per_sec_sum / entry_in_sum; double ratio = actual_per_sec / expect_per_sec; if (ratio > 1.1 || ratio < 0.9) { - err("%s(%d), fail, expect %f but actual %f\n", __func__, idx, - expect_per_sec, actual_per_sec); + err("%s(%d), fail, expect %f but actual %f\n", __func__, idx, expect_per_sec, + actual_per_sec); return 0; } - info("%s(%d), pkts per second, expect %f actual %f with time %fs\n", __func__, - idx, expect_per_sec, actual_per_sec, + info("%s(%d), pkts per second, expect %f actual %f with time %fs\n", __func__, idx, + expect_per_sec, actual_per_sec, ((double)mt_get_tsc(impl) - train_start_tsc) / NS_PER_S); return initial_bytes_per_sec * expect_per_sec / actual_per_sec; } @@ -1273,8 +1234,7 @@ static int tx_audio_session_init_rl(struct mtl_main_impl *impl, rl->required_accuracy_ns = 40 * NS_PER_US; /* 40us */ } if (s->ops.rl_offset_ns) { - info("%s(%d), user required offset %dns\n", __func__, idx, - s->ops.rl_offset_ns); + info("%s(%d), user required offset %dns\n", __func__, idx, s->ops.rl_offset_ns); } rl->pkts_prepare_warmup = 4; rl->pads_per_st30_pkt = 3; @@ -1287,8 +1247,8 @@ static int tx_audio_session_init_rl(struct mtl_main_impl *impl, port = mt_port_logic2phy(s->port_maps, i); uint64_t initial_bytes_per_sec = tx_audio_session_initial_rl_bps(s); - int profiled = mt_audio_pacing_train_result_search( - impl, port, initial_bytes_per_sec, &profiled_per_sec); + int profiled = mt_audio_pacing_train_result_search(impl, port, initial_bytes_per_sec, + &profiled_per_sec); /* pad pkt */ rl_port->pad = mt_build_pad(impl, mt_sys_tx_mempool(impl, port), port, @@ -1320,17 +1280,15 @@ static int tx_audio_session_init_rl(struct mtl_main_impl *impl, return -EIO; } if ((j == 0) && (profiled < 0)) { /* only profile on the first */ - uint64_t trained = tx_audio_session_profiling_rl_bps( - impl, s, i, initial_bytes_per_sec, j); + uint64_t trained = + tx_audio_session_profiling_rl_bps(impl, s, i, initial_bytes_per_sec, j); if (!trained) { tx_audio_session_uinit_rl(impl, s); return -EIO; } - mt_audio_pacing_train_result_add(impl, port, initial_bytes_per_sec, - trained); - info("%s(%d), trained bytes_per_sec %" PRIu64 "\n", __func__, idx, - trained); + mt_audio_pacing_train_result_add(impl, port, initial_bytes_per_sec, trained); + info("%s(%d), trained bytes_per_sec %" PRIu64 "\n", __func__, idx, trained); int ret = mt_txq_set_tx_bps(rl_port->queue[j], trained); if (ret < 0) { tx_audio_session_uinit_rl(impl, s); @@ -1339,37 +1297,35 @@ static int tx_audio_session_init_rl(struct mtl_main_impl *impl, initial_bytes_per_sec = trained; } queue_id = mt_txq_queue_id(rl_port->queue[j]); - info("%s(%d), port(l:%d,p:%d), queue %d at sync %d\n", __func__, idx, i, - port, queue_id, j); + info("%s(%d), port(l:%d,p:%d), queue %d at sync %d\n", __func__, idx, i, port, + queue_id, j); } } return 0; } -static void -tx_audio_session_rl_switch_queue(struct st_tx_audio_session_rl_port *rl_port) { +static void tx_audio_session_rl_switch_queue( + struct st_tx_audio_session_rl_port *rl_port) { int cur_queue = rl_port->cur_queue; cur_queue++; - if (cur_queue >= ST30_TX_RL_QUEUES_USED) - cur_queue = 0; + if (cur_queue >= ST30_TX_RL_QUEUES_USED) cur_queue = 0; rl_port->cur_queue = cur_queue; } -static void -tx_audio_session_rl_inc_pkt_idx(struct st_tx_audio_session_rl_info *rl, - struct st_tx_audio_session_rl_port *rl_port) { +static void tx_audio_session_rl_inc_pkt_idx(struct st_tx_audio_session_rl_info *rl, + struct st_tx_audio_session_rl_port *rl_port) { rl_port->cur_pkt_idx++; if (rl_port->cur_pkt_idx >= rl->pkts_per_sync) { - dbg("%s(%d,%d), switch to next queue, cur queue %d pkts %d send\n", - __func__, idx, s_port, cur_queue, rl_port->cur_pkt_idx); + dbg("%s(%d,%d), switch to next queue, cur queue %d pkts %d send\n", __func__, idx, + s_port, cur_queue, rl_port->cur_pkt_idx); rl_port->cur_pkt_idx = 0; tx_audio_session_rl_switch_queue(rl_port); } } -static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl *s, - int s_port, struct rte_mbuf *pkt) { +static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl *s, int s_port, + struct rte_mbuf *pkt) { struct st_tx_audio_session_rl_info *rl = &s->rl; struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; int pads_per_st30_pkt = rl->pads_per_st30_pkt; @@ -1393,8 +1349,8 @@ static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl *s, tx = mt_txq_burst(queue, pads, pads_per_st30_pkt); rl_port->stat_pad_pkts_burst += tx; if (tx != pads_per_st30_pkt) { - dbg("%s(%d,%d), sending %u pad pkts only %u succ\n", __func__, s->idx, - s_port, pads_per_st30_pkt, tx); + dbg("%s(%d,%d), sending %u pad pkts only %u succ\n", __func__, s->idx, s_port, + pads_per_st30_pkt, tx); /* save to pad inflight */ rl_port->trs_pad_inflight_num = pads_per_st30_pkt - tx; } else { @@ -1404,9 +1360,8 @@ static uint16_t tx_audio_session_rl_tx_pkt(struct st_tx_audio_session_impl *s, return 1; } -static uint16_t -tx_audio_session_rl_warmup_pkt(struct st_tx_audio_session_impl *s, int s_port, - int pre, int pkts) { +static uint16_t tx_audio_session_rl_warmup_pkt(struct st_tx_audio_session_impl *s, + int s_port, int pre, int pkts) { struct st_tx_audio_session_rl_info *rl = &s->rl; struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; int cur_queue = rl_port->cur_queue; @@ -1438,10 +1393,9 @@ tx_audio_session_rl_warmup_pkt(struct st_tx_audio_session_impl *s, int s_port, return 0; } -static uint16_t -tx_audio_session_rl_first_pkt(struct mtl_main_impl *impl, - struct st_tx_audio_session_impl *s, int s_port, - struct rte_mbuf *pkt) { +static uint16_t tx_audio_session_rl_first_pkt(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s, + int s_port, struct rte_mbuf *pkt) { struct st_tx_audio_session_rl_info *rl = &s->rl; struct st_tx_audio_session_rl_port *rl_port = &rl->port_info[s_port]; uint64_t target_tsc = rl_port->trs_target_tsc + s->ops.rl_offset_ns; @@ -1449,8 +1403,7 @@ tx_audio_session_rl_first_pkt(struct mtl_main_impl *impl, cur_tsc = mt_get_tsc(impl); if (cur_tsc > target_tsc) { /* time already reach */ - dbg("%s(%d,%d), warmup fail, cur %" PRIu64 " target %" PRIu64 - ", burst directly\n", + dbg("%s(%d,%d), warmup fail, cur %" PRIu64 " target %" PRIu64 ", burst directly\n", __func__, s->idx, s_port, cur_tsc, target_tsc); rl_port->trs_target_tsc = 0; /* clear target tsc */ rl_port->stat_mismatch_sync_point++; @@ -1460,22 +1413,20 @@ tx_audio_session_rl_first_pkt(struct mtl_main_impl *impl, return tx_audio_session_rl_tx_pkt(s, s_port, pkt); } - if (rl_port->force_sync_first_tsc) - return 0; + if (rl_port->force_sync_first_tsc) return 0; /* check if we are reaching the warmup stage */ uint32_t delta_tsc = target_tsc - cur_tsc; uint32_t trs = s->pacing.trs; uint32_t delta_pkts = delta_tsc / trs; if (delta_pkts > rl->max_warmup_trs) { - dbg("%s(%d,%d), delta_pkts %u too large\n", __func__, idx, s_port, - delta_pkts); + dbg("%s(%d,%d), delta_pkts %u too large\n", __func__, idx, s_port, delta_pkts); return 0; } uint32_t accuracy = delta_tsc % trs; if (accuracy > rl->required_accuracy_ns) { - dbg("%s(%d,%d), accuracy %u too large, delta_tsc %u trs %u\n", __func__, - idx, s_port, accuracy, delta_tsc, trs); + dbg("%s(%d,%d), accuracy %u too large, delta_tsc %u trs %u\n", __func__, idx, s_port, + accuracy, delta_tsc, trs); return 0; } dbg("%s(%d,%d), accuracy %u succ\n", __func__, idx, s_port, accuracy); @@ -1494,8 +1445,8 @@ tx_audio_session_rl_first_pkt(struct mtl_main_impl *impl, uint32_t delta_tsc_now = target_tsc - mt_get_tsc(impl); uint32_t delta_pkts_now = delta_tsc_now / trs; if (delta_pkts_now < (i - 0)) { - dbg("%s(%d), mismatch delta_pkts_now %d at %d\n", __func__, s->idx, - delta_pkts_now, i); + dbg("%s(%d), mismatch delta_pkts_now %d at %d\n", __func__, s->idx, delta_pkts_now, + i); /* try next sync point */ rl_port->stat_recalculate_warmup++; rl_port->force_sync_first_tsc = true; @@ -1508,10 +1459,9 @@ tx_audio_session_rl_first_pkt(struct mtl_main_impl *impl, return tx_audio_session_rl_tx_pkt(s, s_port, pkt); } -static int -tx_audio_session_tasklet_rl_transmit(struct mtl_main_impl *impl, - struct st_tx_audio_session_impl *s, - int s_port) { +static int tx_audio_session_tasklet_rl_transmit(struct mtl_main_impl *impl, + struct st_tx_audio_session_impl *s, + int s_port) { int ret; struct rte_mbuf *pkt; struct st_tx_audio_session_rl_info *rl = &s->rl; @@ -1583,12 +1533,9 @@ static int tx_audio_sessions_tasklet(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_audio_session_try_get(mgr, sidx); - if (!s) - continue; - if (!s->active) - goto exit; - if (time_measure) - tsc_s = mt_get_tsc(impl); + if (!s) continue; + if (!s->active) goto exit; + if (time_measure) tsc_s = mt_get_tsc(impl); s->stat_build_ret_code = 0; if (s->ops.type == ST30_TYPE_FRAME_LEVEL) @@ -1623,8 +1570,7 @@ static int tx_audio_sessions_mgr_uinit_hw(struct st_tx_audio_sessions_mgr *mgr, if (mgr->queue[port]) { struct rte_mbuf *pad = mt_get_pad(mgr->parent, port); /* flush all the pkts in the tx ring desc */ - if (pad) - mt_txq_flush(mgr->queue[port], pad); + if (pad) mt_txq_flush(mgr->queue[port], pad); mt_txq_put(mgr->queue[port]); mgr->queue[port] = NULL; } @@ -1641,8 +1587,7 @@ static int tx_audio_sessions_mgr_init_hw(struct mtl_main_impl *impl, char ring_name[32]; int mgr_idx = mgr->idx; - if (mgr->queue[port]) - return 0; /* init already */ + if (mgr->queue[port]) return 0; /* init already */ struct mt_txq_flow flow; memset(&flow, 0, sizeof(flow)); @@ -1652,8 +1597,7 @@ static int tx_audio_sessions_mgr_init_hw(struct mtl_main_impl *impl, } snprintf(ring_name, 32, "%sM%dP%d", ST_TX_AUDIO_PREFIX, mgr_idx, port); - flags = RING_F_MP_HTS_ENQ | - RING_F_SC_DEQ; /* multi-producer and single-consumer */ + flags = RING_F_MP_HTS_ENQ | RING_F_SC_DEQ; /* multi-producer and single-consumer */ count = ST_TX_AUDIO_SESSIONS_RING_SIZE; ring = rte_ring_create(ring_name, count, mgr->socket_id, flags); if (!ring) { @@ -1701,8 +1645,7 @@ static int tx_audio_session_sq_flush(struct st_tx_audio_sessions_mgr *mgr, struct st_tx_audio_session_impl *s) { int mgr_idx = mgr->idx, s_idx = s->idx; - if (!s->shared_queue) - return 0; /* skip as not shared queue */ + if (!s->shared_queue) return 0; /* skip as not shared queue */ for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { struct rte_mempool *pool = s->mbuf_mempool_hdr[i]; @@ -1716,12 +1659,10 @@ static int tx_audio_session_sq_flush(struct st_tx_audio_sessions_mgr *mgr, int retry = 100; /* max 1000ms */ while (retry > 0) { retry--; - if (!rte_mempool_in_use_count(pool)) - break; + if (!rte_mempool_in_use_count(pool)) break; mt_sleep_ms(10); } - info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, - retry); + info("%s(%d,%d), check in_use retry %d\n", __func__, mgr_idx, s_idx, retry); } } @@ -1733,15 +1674,13 @@ int tx_audio_session_mempool_free(struct st_tx_audio_session_impl *s) { if (s->mbuf_mempool_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_chain); - if (ret >= 0) - s->mbuf_mempool_chain = NULL; + if (ret >= 0) s->mbuf_mempool_chain = NULL; } for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { if (s->mbuf_mempool_hdr[i] && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_hdr[i]); - if (ret >= 0) - s->mbuf_mempool_hdr[i] = NULL; + if (ret >= 0) s->mbuf_mempool_hdr[i] = NULL; } } @@ -1753,8 +1692,7 @@ static bool tx_audio_session_has_chain_buf(struct st_tx_audio_session_impl *s) { int num_ports = ops->num_port; for (int port = 0; port < num_ports; port++) { - if (!s->eth_has_chain[port]) - return false; + if (!s->eth_has_chain[port]) return false; } /* all ports capable chain */ @@ -1787,14 +1725,13 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl *impl, warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, i); } else { n = mt_if_nb_tx_desc(impl, port) + ST_TX_AUDIO_SESSIONS_RING_SIZE; - if (ops->type == ST30_TYPE_RTP_LEVEL) - n += ops->rtp_ring_size; + if (ops->type == ST30_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_AUDIO_PREFIX, - mgr->idx, idx, i, s->recovery_idx); + snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_AUDIO_PREFIX, mgr->idx, idx, i, + s->recovery_idx); struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), hdr_room_size, s->socket_id); + impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), + hdr_room_size, s->socket_id); if (!mbuf_pool) { tx_audio_session_mempool_free(s); return -ENOMEM; @@ -1807,8 +1744,7 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl *impl, if (!s->tx_no_chain) { port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); n = mt_if_nb_tx_desc(impl, port) + ST_TX_AUDIO_SESSIONS_RING_SIZE; - if (ops->type == ST30_TYPE_RTP_LEVEL) - n += ops->rtp_ring_size; + if (ops->type == ST30_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; if (s->tx_mono_pool) { s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port); @@ -1818,11 +1754,10 @@ static int tx_audio_session_mempool_init(struct mtl_main_impl *impl, warn("%s(%d), use previous chain mempool\n", __func__, idx); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_AUDIO_PREFIX, mgr->idx, - idx, s->recovery_idx); - struct rte_mempool *mbuf_pool = - mt_mempool_create_by_socket(impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, - chain_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_AUDIO_PREFIX, mgr->idx, idx, + s->recovery_idx); + struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( + impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, chain_room_size, s->socket_id); if (!mbuf_pool) { tx_audio_session_mempool_free(s); return -ENOMEM; @@ -1842,8 +1777,7 @@ static int tx_audio_session_init_rtp(struct st_tx_audio_sessions_mgr *mgr, int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_TX_AUDIO_PREFIX, mgr_idx, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { err("%s(%d,%d), rte_ring_create fail\n", __func__, mgr_idx, idx); @@ -1855,8 +1789,7 @@ static int tx_audio_session_init_rtp(struct st_tx_audio_sessions_mgr *mgr, return 0; } -static int -tx_audio_session_uinit_trans_ring(struct st_tx_audio_session_impl *s) { +static int tx_audio_session_uinit_trans_ring(struct st_tx_audio_session_impl *s) { for (int port = 0; port < MTL_SESSION_PORT_MAX; port++) { if (s->trans_ring[port]) { mt_fifo_mbuf_clean(s->trans_ring[port]); @@ -1868,9 +1801,8 @@ tx_audio_session_uinit_trans_ring(struct st_tx_audio_session_impl *s) { return 0; } -static int -tx_audio_session_init_trans_ring(struct st_tx_audio_sessions_mgr *mgr, - struct st_tx_audio_session_impl *s) { +static int tx_audio_session_init_trans_ring(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s) { struct mt_u64_fifo *ring; unsigned int count = ST_TX_AUDIO_SESSIONS_RING_SIZE; int mgr_idx = mgr->idx, idx = s->idx; @@ -1956,8 +1888,7 @@ static int tx_audio_session_init_queue(struct mtl_main_impl *impl, return -EIO; } queue_id = mt_txq_queue_id(s->queue[i]); - info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, - queue_id); + info("%s(%d), port(l:%d,p:%d), queue %d\n", __func__, idx, i, port, queue_id); } return 0; @@ -2050,36 +1981,30 @@ static int tx_audio_session_attach(struct mtl_main_impl *impl, char *ports[MTL_SESSION_PORT_MAX]; bool rdma_ud = false; - for (int i = 0; i < num_port; i++) - ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->mgr = mgr; /* use dedicated queue for rdma_ud */ for (int i = 0; i < num_port; i++) { enum mtl_port port = mt_port_logic2phy(s->port_maps, i); - if (mt_pmd_is_rdma_ud(impl, port)) - rdma_ud = true; + if (mt_pmd_is_rdma_ud(impl, port)) rdma_ud = true; } /* detect pacing */ s->tx_pacing_way = ST30_TX_PACING_WAY_TSC; double pkt_time = st30_get_packet_time(ops->ptime); bool detect_rl = false; - if ((ops->pacing_way == ST30_TX_PACING_WAY_AUTO) && - (pkt_time < (NS_PER_MS / 2))) { + if ((ops->pacing_way == ST30_TX_PACING_WAY_AUTO) && (pkt_time < (NS_PER_MS / 2))) { info("%s(%d), try detect rl as pkt_time %fns\n", __func__, idx, pkt_time); detect_rl = true; } - if ((ops->pacing_way == ST30_TX_PACING_WAY_RL) && - (pkt_time < (NS_PER_MS * 2))) { + if ((ops->pacing_way == ST30_TX_PACING_WAY_RL) && (pkt_time < (NS_PER_MS * 2))) { detect_rl = true; } - if (rdma_ud) - detect_rl = false; /* no rl for rdma_ud */ + if (rdma_ud) detect_rl = false; /* no rl for rdma_ud */ if (detect_rl) { bool cap_rl = true; /* check if all port support rl */ @@ -2088,20 +2013,19 @@ static int tx_audio_session_attach(struct mtl_main_impl *impl, enum st21_tx_pacing_way sys_pacing_way = mt_if(impl, port)->tx_pacing_way; if (sys_pacing_way != ST21_TX_PACING_WAY_RL) { if (ops->pacing_way == ST30_TX_PACING_WAY_AUTO) { - info("%s(%d,%d), the port sys pacing way %d not capable to RL\n", - __func__, idx, port, sys_pacing_way); + info("%s(%d,%d), the port sys pacing way %d not capable to RL\n", __func__, idx, + port, sys_pacing_way); cap_rl = false; break; } else { - err("%s(%d,%d), the port sys pacing way %d not capable to RL\n", - __func__, idx, port, sys_pacing_way); + err("%s(%d,%d), the port sys pacing way %d not capable to RL\n", __func__, idx, + port, sys_pacing_way); return -ENOTSUP; } } } if (cap_rl) { - info("%s(%d), select rl based pacing for pkt_time %fns\n", __func__, idx, - pkt_time); + info("%s(%d), select rl based pacing for pkt_time %fns\n", __func__, idx, pkt_time); s->tx_pacing_way = ST30_TX_PACING_WAY_RL; } } @@ -2109,23 +2033,18 @@ static int tx_audio_session_attach(struct mtl_main_impl *impl, if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, - idx); + snprintf(s->ops_name, sizeof(s->ops_name), "RX_AUDIO_M%dS%d", mgr->idx, idx); } s->ops = *ops; /* if disable shared queue */ s->shared_queue = true; - if (s->tx_pacing_way == ST30_TX_PACING_WAY_RL) - s->shared_queue = false; - if (ops->flags & ST30_TX_FLAG_DEDICATE_QUEUE) - s->shared_queue = false; - if (rdma_ud) - s->shared_queue = false; + if (s->tx_pacing_way == ST30_TX_PACING_WAY_RL) s->shared_queue = false; + if (ops->flags & ST30_TX_FLAG_DEDICATE_QUEUE) s->shared_queue = false; + if (rdma_ud) s->shared_queue = false; for (int i = 0; i < num_port; i++) { - s->st30_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (10100 + idx * 2); + s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10100 + idx * 2); if (mt_user_random_src_port(impl)) s->st30_src_port[i] = mt_random_port(s->st30_dst_port[i]); else @@ -2145,30 +2064,24 @@ static int tx_audio_session_attach(struct mtl_main_impl *impl, } s->tx_mono_pool = mt_user_tx_mono_pool(impl); /* manually disable chain or any port can't support chain */ - s->tx_no_chain = - mt_user_tx_no_chain(impl) || !tx_audio_session_has_chain_buf(s); - if (rdma_ud) - s->tx_no_chain = true; + s->tx_no_chain = mt_user_tx_no_chain(impl) || !tx_audio_session_has_chain_buf(s); + if (rdma_ud) s->tx_no_chain = true; s->st30_frames_cnt = ops->framebuff_cnt; ret = st30_get_sample_size(ops->fmt); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->sample_size = ret; ret = st30_get_sample_num(ops->ptime, ops->sampling); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->sample_num = ret; ret = st30_get_packet_size(ops->fmt, ops->ptime, ops->sampling, ops->channel); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->pkt_len = ret; /* calculate pkts in line*/ - size_t bytes_in_pkt = - ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); + size_t bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc3550_audio_hdr); s->st30_pkt_size = s->pkt_len + sizeof(struct st_rfc3550_audio_hdr); if (s->pkt_len > bytes_in_pkt) { @@ -2179,8 +2092,8 @@ static int tx_audio_session_attach(struct mtl_main_impl *impl, s->st30_total_pkts = ops->framebuff_size / s->pkt_len; if (ops->framebuff_size % s->pkt_len) { /* todo: add the support? */ - err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, - s->pkt_len, ops->framebuff_size); + err("%s(%d), framebuff_size %d not multiple pkt_len %d\n", __func__, idx, s->pkt_len, + ops->framebuff_size); return -EIO; } s->st30_pkt_idx = 0; @@ -2200,8 +2113,7 @@ static int tx_audio_session_attach(struct mtl_main_impl *impl, s->inflight[i] = NULL; s->inflight_cnt[i] = 0; } - if (ops->flags & ST30_TX_FLAG_BUILD_PACING) - s->pacing_in_build = true; + if (ops->flags & ST30_TX_FLAG_BUILD_PACING) s->pacing_in_build = true; s->calculate_time_cursor = true; ret = tx_audio_session_init_pacing(s); if (ret < 0) { @@ -2245,10 +2157,10 @@ static int tx_audio_session_attach(struct mtl_main_impl *impl, s->frames_per_sec = (double)NS_PER_S / s->pacing.trs / s->st30_total_pkts; s->active = true; - info("%s(%d), fmt %d channel %u sampling %d ptime %d pt %u\n", __func__, idx, - ops->fmt, ops->channel, ops->sampling, ops->ptime, ops->payload_type); - info("%s(%d), pkt_len %u frame_size %u frames %u fps %f, pacing_way %s\n", - __func__, idx, s->pkt_len, s->st30_frame_size, s->st30_frames_cnt, + info("%s(%d), fmt %d channel %u sampling %d ptime %d pt %u\n", __func__, idx, ops->fmt, + ops->channel, ops->sampling, ops->ptime, ops->payload_type); + info("%s(%d), pkt_len %u frame_size %u frames %u fps %f, pacing_way %s\n", __func__, + idx, s->pkt_len, s->st30_frame_size, s->st30_frames_cnt, (double)NS_PER_S / s->pacing.trs / s->st30_total_pkts, audio_pacing_way_name(s->tx_pacing_way)); return 0; @@ -2266,8 +2178,7 @@ static int tx_audio_session_update_dst(struct mtl_main_impl *impl, for (int i = 0; i < num_port; i++) { memcpy(ops->dip_addr[i], dst->dip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = dst->udp_port[i]; - s->st30_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); + s->st30_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (20000 + idx * 2); s->st30_src_port[i] = (ops->udp_src_port[i]) ? (ops->udp_src_port[i]) : s->st30_dst_port[i]; @@ -2282,10 +2193,9 @@ static int tx_audio_session_update_dst(struct mtl_main_impl *impl, return 0; } -static int -tx_audio_sessions_mgr_update_dst(struct st_tx_audio_sessions_mgr *mgr, - struct st_tx_audio_session_impl *s, - struct st_tx_dest_info *dst) { +static int tx_audio_sessions_mgr_update_dst(struct st_tx_audio_sessions_mgr *mgr, + struct st_tx_audio_session_impl *s, + struct st_tx_dest_info *dst) { int ret = -EIO, midx = mgr->idx, idx = s->idx; s = tx_audio_session_get(mgr, idx); /* get the lock */ @@ -2316,13 +2226,12 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr *mgr, rte_atomic32_set(&s->st30_stat_frame_cnt, 0); s->stat_last_time = cur_time_ns; - notice("TX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d, pkts %d:%d inflight " - "%d:%d\n", - m_idx, idx, s->ops_name, framerate, frame_cnt, - s->st30_stat_pkt_cnt[MTL_SESSION_PORT_P], - s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R], - s->inflight_cnt[MTL_SESSION_PORT_P], - s->inflight_cnt[MTL_SESSION_PORT_R]); + notice( + "TX_AUDIO_SESSION(%d,%d:%s): fps %f frames %d, pkts %d:%d inflight " + "%d:%d\n", + m_idx, idx, s->ops_name, framerate, frame_cnt, + s->st30_stat_pkt_cnt[MTL_SESSION_PORT_P], s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R], + s->inflight_cnt[MTL_SESSION_PORT_P], s->inflight_cnt[MTL_SESSION_PORT_R]); s->st30_stat_pkt_cnt[MTL_SESSION_PORT_P] = 0; s->st30_stat_pkt_cnt[MTL_SESSION_PORT_R] = 0; @@ -2332,8 +2241,7 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr *mgr, s->stat_epoch_mismatch = 0; } if (s->stat_epoch_drop) { - notice("TX_AUDIO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, - s->stat_epoch_drop); + notice("TX_AUDIO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, s->stat_epoch_drop); s->stat_epoch_drop = 0; } if (s->stat_epoch_onward) { @@ -2342,8 +2250,7 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr *mgr, s->stat_epoch_onward = 0; } if (s->stat_epoch_late) { - notice("TX_AUDIO_SESSION(%d,%d): epoch late %u\n", m_idx, idx, - s->stat_epoch_late); + notice("TX_AUDIO_SESSION(%d,%d): epoch late %u\n", m_idx, idx, s->stat_epoch_late); s->stat_epoch_late = 0; } if (s->stat_exceed_frame_time) { @@ -2373,8 +2280,8 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr *mgr, } if (s->tx_pacing_way == ST30_TX_PACING_WAY_RL) { struct st_tx_audio_session_rl_port *rl_port = &s->rl.port_info[0]; - notice("TX_AUDIO_SESSION(%d,%d): rl pkts %u pads %u warmup %u\n", m_idx, - idx, rl_port->stat_pkts_burst, rl_port->stat_pad_pkts_burst, + notice("TX_AUDIO_SESSION(%d,%d): rl pkts %u pads %u warmup %u\n", m_idx, idx, + rl_port->stat_pkts_burst, rl_port->stat_pad_pkts_burst, rl_port->stat_warmup_pkts_burst); rl_port->stat_pkts_burst = 0; rl_port->stat_pad_pkts_burst = 0; @@ -2390,8 +2297,8 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr *mgr, rl_port->stat_recalculate_warmup = 0; } if (rl_port->stat_hit_backup_cp) { - notice("TX_AUDIO_SESSION(%d,%d): hit backup warmup checkpoint %u\n", - m_idx, idx, rl_port->stat_hit_backup_cp); + notice("TX_AUDIO_SESSION(%d,%d): hit backup warmup checkpoint %u\n", m_idx, idx, + rl_port->stat_hit_backup_cp); rl_port->stat_hit_backup_cp = 0; } } @@ -2399,27 +2306,26 @@ static void tx_audio_session_stat(struct st_tx_audio_sessions_mgr *mgr, struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("TX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " - "%.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, - (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice( + "TX_AUDIO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } struct mt_stat_u64 *stat_tx_delta = &s->stat_tx_delta; if (stat_tx_delta->cnt) { uint64_t avg_ns = stat_tx_delta->sum / stat_tx_delta->cnt; - notice( - "TX_AUDIO_SESSION(%d,%d): tx delta avg %.2fus max %.2fus min %.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, - (float)stat_tx_delta->max / NS_PER_US, - (float)stat_tx_delta->min / NS_PER_US); + notice("TX_AUDIO_SESSION(%d,%d): tx delta avg %.2fus max %.2fus min %.2fus\n", m_idx, + idx, (float)avg_ns / NS_PER_US, (float)stat_tx_delta->max / NS_PER_US, + (float)stat_tx_delta->min / NS_PER_US); mt_stat_u64_init(stat_tx_delta); } if (s->stat_max_next_frame_us > 8 || s->stat_max_notify_frame_us > 8) { - notice("TX_AUDIO_SESSION(%d,%d): get next frame max %uus, notify done max " - "%uus\n", - m_idx, idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); + notice( + "TX_AUDIO_SESSION(%d,%d): get next frame max %uus, notify done max " + "%uus\n", + m_idx, idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); } s->stat_max_next_frame_us = 0; s->stat_max_notify_frame_us = 0; @@ -2442,21 +2348,18 @@ static int st_tx_audio_sessions_stat(void *priv) { for (int j = 0; j < mgr->max_idx; j++) { s = tx_audio_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) - continue; + if (!s) continue; tx_audio_session_stat(mgr, s); tx_audio_session_put(mgr, j); } if (mgr->st30_stat_pkts_burst > 0) { - notice("TX_AUDIO_MGR(%d), pkts burst %d\n", m_idx, - mgr->st30_stat_pkts_burst); + notice("TX_AUDIO_MGR(%d), pkts burst %d\n", m_idx, mgr->st30_stat_pkts_burst); mgr->st30_stat_pkts_burst = 0; } else { int32_t clients = rte_atomic32_read(&mgr->transmitter_clients); if ((clients > 0) && (mgr->max_idx > 0)) { for (int i = 0; i < mt_num_ports(mgr->parent); i++) { - warn("TX_AUDIO_MGR(%d): trs ret %d:%d\n", m_idx, i, - mgr->stat_trs_ret_code[i]); + warn("TX_AUDIO_MGR(%d): trs ret %d:%d\n", m_idx, i, mgr->stat_trs_ret_code[i]); } } } @@ -2509,9 +2412,8 @@ static int tx_audio_sessions_mgr_init(struct mtl_main_impl *impl, return 0; } -static struct st_tx_audio_session_impl * -tx_audio_sessions_mgr_attach(struct mtl_sch_impl *sch, - struct st30_tx_ops *ops) { +static struct st_tx_audio_session_impl *tx_audio_sessions_mgr_attach( + struct mtl_sch_impl *sch, struct st30_tx_ops *ops) { struct st_tx_audio_sessions_mgr *mgr = &sch->tx_a_mgr; int midx = mgr->idx; int ret; @@ -2520,8 +2422,7 @@ tx_audio_sessions_mgr_attach(struct mtl_sch_impl *sch, /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_TX_AUDIO_SESSIONS; i++) { - if (!tx_audio_session_get_empty(mgr, i)) - continue; + if (!tx_audio_session_get_empty(mgr, i)) continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -2579,8 +2480,7 @@ static int tx_audio_sessions_mgr_update(struct st_tx_audio_sessions_mgr *mgr) { int max_idx = 0; for (int i = 0; i < ST_SCH_MAX_TX_AUDIO_SESSIONS; i++) { - if (mgr->sessions[i]) - max_idx = i + 1; + if (mgr->sessions[i]) max_idx = i + 1; } mgr->max_idx = max_idx; @@ -2601,8 +2501,7 @@ static int tx_audio_sessions_mgr_uinit(struct st_tx_audio_sessions_mgr *mgr) { for (int i = 0; i < ST_SCH_MAX_TX_AUDIO_SESSIONS; i++) { s = tx_audio_session_get(mgr, i); - if (!s) - continue; + if (!s) continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); tx_audio_sessions_mgr_detach(mgr, s); @@ -2630,16 +2529,14 @@ static int tx_audio_ops_check(struct st30_tx_ops *ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -2676,12 +2573,10 @@ static int tx_audio_ops_check(struct st30_tx_ops *ops) { return 0; } -static int st_tx_audio_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { +static int st_tx_audio_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { int ret; - if (sch->tx_a_init) - return 0; + if (sch->tx_a_init) return 0; /* create tx audio context */ ret = tx_audio_sessions_mgr_init(impl, sch, &sch->tx_a_mgr); @@ -2701,8 +2596,7 @@ static int st_tx_audio_init(struct mtl_main_impl *impl, } int st_audio_queue_fatal_error(struct mtl_main_impl *impl, - struct st_tx_audio_sessions_mgr *mgr, - enum mtl_port port) { + struct st_tx_audio_sessions_mgr *mgr, enum mtl_port port) { int idx = mgr->idx; int ret; struct st_tx_audio_session_impl *s; @@ -2713,8 +2607,7 @@ int st_audio_queue_fatal_error(struct mtl_main_impl *impl, } /* clean mbuf in the ring as we will free the mempool then */ - if (mgr->ring[port]) - mt_ring_dequeue_clean(mgr->ring[port]); + if (mgr->ring[port]) mt_ring_dequeue_clean(mgr->ring[port]); /* clean the queue done mbuf */ mt_txq_done_cleanup(mgr->queue[port]); @@ -2726,23 +2619,20 @@ int st_audio_queue_fatal_error(struct mtl_main_impl *impl, * pkt */ for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_audio_session_get(mgr, sidx); - if (!s) - continue; + if (!s) continue; /* clear all tx ring buffer */ - if (s->packet_ring) - mt_ring_dequeue_clean(s->packet_ring); + if (s->packet_ring) mt_ring_dequeue_clean(s->packet_ring); for (uint8_t i = 0; i < s->ops.num_port; i++) { - if (s->trans_ring[i]) - mt_fifo_mbuf_clean(s->trans_ring[i]); + if (s->trans_ring[i]) mt_fifo_mbuf_clean(s->trans_ring[i]); } s->recovery_idx++; tx_audio_session_mempool_free(s); ret = tx_audio_session_mempool_init(impl, mgr, s); if (ret < 0) { - err("%s(%d,%d), init mempool fail %d for session %d\n", __func__, idx, - port, ret, sidx); + err("%s(%d,%d), init mempool fail %d for session %d\n", __func__, idx, port, ret, + sidx); s->stat_unrecoverable_error++; s->active = false; /* mark current session to dead */ } else { @@ -2768,8 +2658,7 @@ int st_audio_queue_fatal_error(struct mtl_main_impl *impl, } int st_tx_audio_sessions_sch_uinit(struct mtl_sch_impl *sch) { - if (!sch->tx_a_init) - return 0; + if (!sch->tx_a_init) return 0; /* free tx audio context */ st_audio_transmitter_uinit(&sch->a_trs); @@ -2800,8 +2689,7 @@ st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops *ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST30_TX_FLAG_FORCE_NUMA) { @@ -2815,10 +2703,9 @@ st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops *ops) { return NULL; } - quota_mbs = impl->main_sch->data_quota_mbs_limit / - impl->tx_audio_sessions_max_per_sch; - sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, - MT_SCH_MASK_ALL, socket); + quota_mbs = impl->main_sch->data_quota_mbs_limit / impl->tx_audio_sessions_max_per_sch; + sch = + mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -2856,8 +2743,7 @@ st30_tx_handle st30_tx_create(mtl_handle mt, struct st30_tx_ops *ops) { return s_impl; } -int st30_tx_update_destination(st30_tx_handle handle, - struct st_tx_dest_info *dst) { +int st30_tx_update_destination(st30_tx_handle handle, struct st_tx_dest_info *dst) { struct st_tx_audio_session_handle_impl *s_impl = handle; struct st_tx_audio_session_impl *s; struct mtl_sch_impl *sch; @@ -2874,8 +2760,7 @@ int st30_tx_update_destination(st30_tx_handle handle, sch_idx = sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tx_audio_sessions_mgr_update_dst(&sch->tx_a_mgr, s, dst); if (ret < 0) { @@ -2910,12 +2795,10 @@ int st30_tx_free(st30_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_a_mgr_mutex); ret = tx_audio_sessions_mgr_detach(&sch->tx_a_mgr, s); mt_pthread_mutex_unlock(&sch->tx_a_mgr_mutex); - if (ret < 0) - err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mgr detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -2980,9 +2863,8 @@ void *st30_tx_get_mbuf(st30_tx_handle handle, void **usrptr) { return NULL; } - struct rte_mempool *mp = s->tx_no_chain - ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] - : s->mbuf_mempool_chain; + struct rte_mempool *mp = + s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -3008,8 +2890,7 @@ int st30_tx_put_mbuf(st30_tx_handle handle, void *mbuf, uint16_t len) { } if (!mt_rtp_len_valid(len)) { - if (len) - err("%s, invalid len %d\n", __func__, len); + if (len) err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -3023,8 +2904,7 @@ int st30_tx_put_mbuf(st30_tx_handle handle, void *mbuf, uint16_t len) { return -EIO; } - if (s->tx_no_chain) - len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); diff --git a/lib/src/st2110/st_tx_video_session.c b/lib/src/st2110/st_tx_video_session.c index 900fabf0a..566d79793 100644 --- a/lib/src/st2110/st_tx_video_session.c +++ b/lib/src/st2110/st_tx_video_session.c @@ -14,15 +14,13 @@ #include "st_err.h" #include "st_video_transmitter.h" -static inline double pacing_time(struct st_tx_video_pacing *pacing, - uint64_t epochs) { +static inline double pacing_time(struct st_tx_video_pacing *pacing, uint64_t epochs) { return epochs * pacing->frame_time; } static inline double pacing_first_pkt_time(struct st_tx_video_pacing *pacing, uint64_t epochs) { - return pacing_time(pacing, epochs) + pacing->tr_offset - - (pacing->vrx * pacing->trs); + return pacing_time(pacing, epochs) + pacing->tr_offset - (pacing->vrx * pacing->trs); } /* pacing start time(warmup pkt if has warmup stage) of the frame */ @@ -44,16 +42,14 @@ static inline uint32_t pacing_time_stamp(struct st_tx_video_session_impl *s, } else if (s->ops.flags & ST20_TX_FLAG_RTP_TIMESTAMP_FIRST_PKT) { /* the start of first pkt */ time = pacing_first_pkt_time(pacing, epochs); - if (pacing->warm_pkts) - time -= 3 * pacing->trs; /* deviation for VRX */ + if (pacing->warm_pkts) time -= 3 * pacing->trs; /* deviation for VRX */ } else if (s->ops.rtp_timestamp_delta_us) { int32_t rtp_timestamp_delta_us = s->ops.rtp_timestamp_delta_us; time = pacing_time(pacing, epochs) + (rtp_timestamp_delta_us * NS_PER_US); } else { /* default to the start of first pkt */ time = pacing_first_pkt_time(pacing, epochs); - if (pacing->warm_pkts) - time -= 3 * pacing->trs; /* deviation for VRX */ + if (pacing->warm_pkts) time -= 3 * pacing->trs; /* deviation for VRX */ } tmstamp64 = (time / pacing->frame_time) * pacing->frame_time_sampling; uint32_t tmstamp32 = tmstamp64; @@ -61,9 +57,8 @@ static inline uint32_t pacing_time_stamp(struct st_tx_video_session_impl *s, return tmstamp32; } -static inline void -pacing_set_mbuf_time_stamp(struct rte_mbuf *mbuf, - struct st_tx_video_pacing *pacing) { +static inline void pacing_set_mbuf_time_stamp(struct rte_mbuf *mbuf, + struct st_tx_video_pacing *pacing) { st_tx_mbuf_set_tsc(mbuf, pacing->tsc_time_cursor); st_tx_mbuf_set_ptp(mbuf, pacing->ptp_time_cursor); } @@ -79,20 +74,17 @@ static inline uint64_t tv_rl_bps(struct st_tx_video_session_impl *s) { if (s->ops.interlaced && s->ops.height <= 576) { reactive = (s->ops.height == 480) ? 487.0 / 525.0 : 576.0 / 625.0; } - return (uint64_t)(s->st20_pkt_size * s->st20_total_pkts * 1.0 * - s->fps_tm.mul / s->fps_tm.den / reactive); + return (uint64_t)(s->st20_pkt_size * s->st20_total_pkts * 1.0 * s->fps_tm.mul / + s->fps_tm.den / reactive); } -static void tv_notify_frame_done(struct st_tx_video_session_impl *s, - uint16_t frame_idx) { +static void tv_notify_frame_done(struct st_tx_video_session_impl *s, uint16_t frame_idx) { uint64_t tsc_start = 0; struct mtl_main_impl *impl = s->impl; bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); if (s->st22_info) { - struct st22_tx_frame_meta *tx_st22_meta = - &s->st20_frames[frame_idx].tx_st22_meta; + struct st22_tx_frame_meta *tx_st22_meta = &s->st20_frames[frame_idx].tx_st22_meta; if (s->st22_info->notify_frame_done) s->st22_info->notify_frame_done(s->ops.priv, frame_idx, tx_st22_meta); MT_USDT_ST22_TX_FRAME_DONE(s->mgr->idx, s->idx, frame_idx, @@ -101,13 +93,11 @@ static void tv_notify_frame_done(struct st_tx_video_session_impl *s, struct st20_tx_frame_meta *tv_meta = &s->st20_frames[frame_idx].tv_meta; if (s->ops.notify_frame_done) s->ops.notify_frame_done(s->ops.priv, frame_idx, tv_meta); - MT_USDT_ST20_TX_FRAME_DONE(s->mgr->idx, s->idx, frame_idx, - tv_meta->rtp_timestamp); + MT_USDT_ST20_TX_FRAME_DONE(s->mgr->idx, s->idx, frame_idx, tv_meta->rtp_timestamp); } if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_notify_frame_us = - RTE_MAX(s->stat_max_notify_frame_us, delta_us); + s->stat_max_notify_frame_us = RTE_MAX(s->stat_max_notify_frame_us, delta_us); } } @@ -116,8 +106,7 @@ static void tv_frame_free_cb(void *addr, void *opaque) { struct st_tx_video_session_impl *s = frame_info->priv; int s_idx = s->idx, frame_idx = frame_info->idx; - if ((addr < frame_info->addr) || - (addr >= (frame_info->addr + s->st20_fb_size))) { + if ((addr < frame_info->addr) || (addr >= (frame_info->addr + s->st20_fb_size))) { err("%s(%d), addr %p does not belong to frame %d\n", __func__, s_idx, addr, frame_idx); return; @@ -125,8 +114,8 @@ static void tv_frame_free_cb(void *addr, void *opaque) { int refcnt = rte_atomic32_read(&frame_info->refcnt); if (refcnt != 1) { - warn("%s(%d), frame %d err refcnt %d addr %p\n", __func__, s_idx, frame_idx, - refcnt, addr); + warn("%s(%d), frame %d err refcnt %d addr %p\n", __func__, s_idx, frame_idx, refcnt, + addr); return; } @@ -144,8 +133,7 @@ static void tv_frame_free_cb(void *addr, void *opaque) { static rte_iova_t tv_frame_get_offset_iova(struct st_tx_video_session_impl *s, struct st_frame_trans *frame_info, size_t offset) { - if (frame_info->page_table_len == 0) - return frame_info->iova + offset; + if (frame_info->page_table_len == 0) return frame_info->iova + offset; void *addr = RTE_PTR_ADD(frame_info->addr, offset); struct st_page_info *page; for (uint16_t i = 0; i < frame_info->page_table_len; i++) { @@ -154,8 +142,8 @@ static rte_iova_t tv_frame_get_offset_iova(struct st_tx_video_session_impl *s, return page->iova + RTE_PTR_DIFF(addr, page->addr); } - err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, - frame_info->idx, offset); + err("%s(%d,%d), offset %" PRIu64 " get iova fail\n", __func__, s->idx, frame_info->idx, + offset); return MTL_BAD_IOVA; } @@ -167,21 +155,18 @@ static int tv_frame_create_page_table(struct st_tx_video_session_impl *s, return -EIO; } size_t hugepage_sz = mseg->hugepage_sz; - info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, - frame_info->idx, hugepage_sz); + info("%s(%d,%d), hugepage size %" PRIu64 "\n", __func__, s->idx, frame_info->idx, + hugepage_sz); /* calculate num hugepages */ uint16_t num_pages = - RTE_PTR_DIFF( - RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), - RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / + RTE_PTR_DIFF(RTE_PTR_ALIGN(frame_info->addr + s->st20_fb_size, hugepage_sz), + RTE_PTR_ALIGN_FLOOR(frame_info->addr, hugepage_sz)) / hugepage_sz; int soc_id = s->socket_id; - struct st_page_info *pages = - mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); + struct st_page_info *pages = mt_rte_zmalloc_socket(sizeof(*pages) * num_pages, soc_id); if (pages == NULL) { - err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, - frame_info->idx); + err("%s(%d,%d), pages info malloc fail\n", __func__, s->idx, frame_info->idx); return -ENOMEM; } @@ -195,9 +180,8 @@ static int tv_frame_create_page_table(struct st_tx_video_session_impl *s, void *next_addr = RTE_PTR_ALIGN(RTE_PTR_ADD(addr, 1), hugepage_sz); pages[i].len = RTE_PTR_DIFF(next_addr, addr); addr = next_addr; - info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", - __func__, s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, - pages[i].len); + info("%s(%d,%d), seg %u, va %p, iova 0x%" PRIx64 ", len %" PRIu64 "\n", __func__, + s->idx, frame_info->idx, i, pages[i].addr, pages[i].iova, pages[i].len); } frame_info->page_table = pages; frame_info->page_table_len = num_pages; @@ -205,12 +189,10 @@ static int tv_frame_create_page_table(struct st_tx_video_session_impl *s, return 0; } -static inline bool -tv_frame_payload_cross_page(struct st_tx_video_session_impl *s, - struct st_frame_trans *frame_info, size_t offset, - size_t len) { - if (frame_info->page_table_len == 0) - return false; +static inline bool tv_frame_payload_cross_page(struct st_tx_video_session_impl *s, + struct st_frame_trans *frame_info, + size_t offset, size_t len) { + if (frame_info->page_table_len == 0) return false; return ((tv_frame_get_offset_iova(s, frame_info, offset + len - 1) - tv_frame_get_offset_iova(s, frame_info, offset)) != len - 1); } @@ -222,8 +204,8 @@ static int tv_alloc_frames(struct mtl_main_impl *impl, struct st_frame_trans *frame_info; struct st22_tx_video_info *st22_info = s->st22_info; - s->st20_frames = mt_rte_zmalloc_socket( - sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); + s->st20_frames = + mt_rte_zmalloc_socket(sizeof(*s->st20_frames) * s->st20_frames_cnt, soc_id); if (!s->st20_frames) { err("%s(%d), st20_frames malloc fail\n", __func__, idx); return -ENOMEM; @@ -246,13 +228,12 @@ static int tv_alloc_frames(struct mtl_main_impl *impl, frame_info->iova = 0; frame_info->addr = NULL; frame_info->flags = ST_FT_FLAG_EXT; - info("%s(%d), use external framebuffer, skip allocation\n", __func__, - idx); + info("%s(%d), use external framebuffer, skip allocation\n", __func__, idx); } else { void *frame = mt_rte_zmalloc_socket(s->st20_fb_size, soc_id); if (!frame) { - err("%s(%d), rte_malloc %" PRIu64 " fail at %d\n", __func__, idx, - s->st20_fb_size, i); + err("%s(%d), rte_malloc %" PRIu64 " fail at %d\n", __func__, idx, s->st20_fb_size, + i); return -ENOMEM; } if (st22_info && s->st22_box_hdr_length) { /* copy boxes */ @@ -298,20 +279,17 @@ static int tv_free_frames(struct st_tx_video_session_impl *s) { return 0; } -static int tv_poll_vsync(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s) { +static int tv_poll_vsync(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s) { struct st_vsync_info *vsync = &s->vsync; uint64_t cur_tsc = mt_get_tsc(impl); if (cur_tsc > vsync->next_epoch_tsc) { uint64_t tsc_delta = cur_tsc - vsync->next_epoch_tsc; - dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, - vsync->meta.epoch); + dbg("%s(%d), vsync with epochs %" PRIu64 "\n", __func__, s->idx, vsync->meta.epoch); s->ops.notify_event(s->ops.priv, ST_EVENT_VSYNC, &vsync->meta); st_vsync_calculate(impl, vsync); /* set next vsync */ /* check tsc delta for status */ - if (tsc_delta > NS_PER_MS) - s->stat_vsync_mismatch++; + if (tsc_delta > NS_PER_MS) s->stat_vsync_mismatch++; } return 0; @@ -329,8 +307,7 @@ static int uint64_t_cmp(const void *a, const void *b) { return 0; } -static int tv_train_pacing(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, +static int tv_train_pacing(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); struct rte_mbuf *pad; @@ -364,15 +341,13 @@ static int tv_train_pacing(struct mtl_main_impl *impl, ret = mt_pacing_train_result_search(impl, port, rl_bps, &pad_interval); if (ret >= 0) { s->pacing.pad_interval = pad_interval; - info("%s(%d), use pre-train pad_interval %f\n", __func__, idx, - pad_interval); + info("%s(%d), use pre-train pad_interval %f\n", __func__, idx, pad_interval); return 0; } /* wait ptp and tsc calibrate done */ ret = mt_ptp_wait_stable(impl, MTL_PORT_P, 60 * 3 * MS_PER_S); - if (ret < 0) - return ret; + if (ret < 0) return ret; mt_wait_tsc_stable(impl); train_start_time = mt_get_tsc(impl); @@ -402,8 +377,7 @@ static int tv_train_pacing(struct mtl_main_impl *impl, uint32_t offset = s->st20_pkt_len * i; uint16_t line1_number = offset / s->st20_bytes_in_line; /* last pkt should be treated as normal pkt also */ - if ((offset + s->st20_pkt_len) < - (line1_number + 1) * s->st20_bytes_in_line) { + if ((offset + s->st20_pkt_len) < (line1_number + 1) * s->st20_bytes_in_line) { type = ST20_PKT_TYPE_NORMAL; } else { type = ST20_PKT_TYPE_EXTRA; @@ -425,8 +399,7 @@ static int tv_train_pacing(struct mtl_main_impl *impl, } for (int loop = 0; loop < loop_frame; loop++) { - dbg("%s(%d), frame_time_ns %" PRIu64 "\n", __func__, idx, - frame_times_ns[loop]); + dbg("%s(%d), frame_time_ns %" PRIu64 "\n", __func__, idx, frame_times_ns[loop]); } qsort(frame_times_ns, loop_frame, sizeof(uint64_t), uint64_t_cmp); for (int loop = 0; loop < loop_frame; loop++) { @@ -439,8 +412,7 @@ static int tv_train_pacing(struct mtl_main_impl *impl, frame_times_ns_sum += frame_times_ns[i]; entry_in_sum++; } - double frame_avg_time_sec = - (double)frame_times_ns_sum / entry_in_sum / NS_PER_S; + double frame_avg_time_sec = (double)frame_times_ns_sum / entry_in_sum / NS_PER_S; double pkts_per_sec = s->st20_total_pkts / frame_avg_time_sec; /* parse the pad interval */ @@ -457,8 +429,7 @@ static int tv_train_pacing(struct mtl_main_impl *impl, return -EINVAL; } - pad_interval = - (float)s->st20_total_pkts / (pkts_per_frame - s->st20_total_pkts); + pad_interval = (float)s->st20_total_pkts / (pkts_per_frame - s->st20_total_pkts); if (pad_interval < 32) { err("%s(%d), too small pad_interval %f pkts_per_frame %f, st20_total_pkts " "%d\n", @@ -469,8 +440,8 @@ static int tv_train_pacing(struct mtl_main_impl *impl, s->pacing.pad_interval = pad_interval; mt_pacing_train_result_add(impl, port, rl_bps, pad_interval); train_end_time = mt_get_tsc(impl); - info("%s(%d,%d), trained pad_interval %f pkts_per_frame %f with time %fs\n", - __func__, idx, s_port, pad_interval, pkts_per_frame, + info("%s(%d,%d), trained pad_interval %f pkts_per_frame %f with time %fs\n", __func__, + idx, s_port, pad_interval, pkts_per_frame, (double)(train_end_time - train_start_time) / NS_PER_S); return 0; } @@ -487,8 +458,8 @@ static int tv_init_pacing(struct mtl_main_impl *impl, pacing->reactive = 1080.0 / 1125.0; /* calculate tr offset */ - pacing->tr_offset = s->ops.height >= 1080 ? frame_time * (43.0 / 1125.0) - : frame_time * (28.0 / 750.0); + pacing->tr_offset = + s->ops.height >= 1080 ? frame_time * (43.0 / 1125.0) : frame_time * (28.0 / 750.0); if (s->ops.interlaced) { if (s->ops.height <= 576) pacing->reactive = (s->ops.height == 480) ? 487.0 / 525.0 : 576.0 / 625.0; @@ -505,13 +476,11 @@ static int tv_init_pacing(struct mtl_main_impl *impl, frame_time - pacing->tr_offset - frame_time * pacing->reactive; dbg("%s[%02d], frame_idle_time %f\n", __func__, idx, pacing->frame_idle_time); if (pacing->frame_idle_time < 0) { - warn("%s[%02d], error frame_idle_time %f\n", __func__, idx, - pacing->frame_idle_time); + warn("%s[%02d], error frame_idle_time %f\n", __func__, idx, pacing->frame_idle_time); pacing->frame_idle_time = 0; } pacing->max_onward_epochs = (double)NS_PER_S / frame_time; /* 1s */ - dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, - pacing->max_onward_epochs); + dbg("%s[%02d], max_onward_epochs %u\n", __func__, idx, pacing->max_onward_epochs); /* default VRX compensate as rl accuracy, update later in tv_train_pacing */ pacing->pad_interval = s->st20_total_pkts; @@ -529,11 +498,9 @@ static int tv_init_pacing(struct mtl_main_impl *impl, } if (num_port > 1) { - if (s->pacing_way[MTL_SESSION_PORT_P] != - s->pacing_way[MTL_SESSION_PORT_R]) { + if (s->pacing_way[MTL_SESSION_PORT_P] != s->pacing_way[MTL_SESSION_PORT_R]) { /* currently not support two different pacing? */ - warn("%s(%d), different pacing detected, all set to tsc\n", __func__, - idx); + warn("%s(%d), different pacing detected, all set to tsc\n", __func__, idx); s->pacing_way[MTL_SESSION_PORT_P] = ST21_TX_PACING_WAY_TSC; s->pacing_way[MTL_SESSION_PORT_R] = ST21_TX_PACING_WAY_TSC; } @@ -559,8 +526,7 @@ static int tv_init_pacing(struct mtl_main_impl *impl, pacing->warm_pkts = 8; /* fix me */ pacing->vrx = s->st21_vrx_narrow; } - } else if (s->pacing_way[MTL_SESSION_PORT_P] == - ST21_TX_PACING_WAY_TSC_NARROW) { + } else if (s->pacing_way[MTL_SESSION_PORT_P] == ST21_TX_PACING_WAY_TSC_NARROW) { /* tsc narrow use single bulk for better accuracy */ s->bulk = 1; } else { @@ -574,11 +540,10 @@ static int tv_init_pacing(struct mtl_main_impl *impl, } if (s->ops.start_vrx) { if (s->ops.start_vrx >= pkts_in_tr_offset) { - err("%s[%02d], use start_vrx %u larger than pkts in tr offset %u\n", - __func__, idx, s->ops.start_vrx, pkts_in_tr_offset); + err("%s[%02d], use start_vrx %u larger than pkts in tr offset %u\n", __func__, idx, + s->ops.start_vrx, pkts_in_tr_offset); } else { - info("%s[%02d], use start_vrx %u from user\n", __func__, idx, - s->ops.start_vrx); + info("%s[%02d], use start_vrx %u from user\n", __func__, idx, s->ops.start_vrx); pacing->vrx = s->ops.start_vrx; } } else if (s->ops.pacing == ST21_PACING_WIDE) { @@ -588,17 +553,16 @@ static int tv_init_pacing(struct mtl_main_impl *impl, pacing->warm_pkts = 0; /* no need warmup for wide */ info("%s[%02d], wide pacing\n", __func__, idx); } - info("%s[%02d], trs %f trOffset %f vrx %u warm_pkts %u frame time %fms fps " - "%f\n", - __func__, idx, pacing->trs, pacing->tr_offset, pacing->vrx, - pacing->warm_pkts, pacing->frame_time / NS_PER_MS, - st_frame_rate(s->ops.fps)); + info( + "%s[%02d], trs %f trOffset %f vrx %u warm_pkts %u frame time %fms fps " + "%f\n", + __func__, idx, pacing->trs, pacing->tr_offset, pacing->vrx, pacing->warm_pkts, + pacing->frame_time / NS_PER_MS, st_frame_rate(s->ops.fps)); /* resolve pacing tasklet */ for (int i = 0; i < num_port; i++) { ret = st_video_resolve_pacing_tasklet(s, i); - if (ret < 0) - return ret; + if (ret < 0) return ret; } return 0; @@ -612,9 +576,8 @@ static int tv_init_pacing_epoch(struct mtl_main_impl *impl, return 0; } -static int tv_sync_pacing(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, bool sync, - uint64_t required_tai, bool second_field) { +static int tv_sync_pacing(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, + bool sync, uint64_t required_tai, bool second_field) { int idx = s->idx; struct st_tx_video_pacing *pacing = &s->pacing; double frame_time = pacing->frame_time; @@ -627,17 +590,14 @@ static int tv_sync_pacing(struct mtl_main_impl *impl, if (required_tai) { uint64_t ptp_epochs = ptp_time / frame_time; epochs = required_tai / frame_time; - dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 - " epochs %" PRIu64 "\n", + dbg("%s(%d), required tai %" PRIu64 " ptp_epochs %" PRIu64 " epochs %" PRIu64 "\n", __func__, idx, required_tai, ptp_epochs, epochs); - if (epochs < ptp_epochs) - s->stat_error_user_timestamp++; + if (epochs < ptp_epochs) s->stat_error_user_timestamp++; } else { epochs = ptp_time / frame_time; } - dbg("%s(%d), ptp epochs %" PRIu64 " cur_epochs %" PRIu64 ", ptp_time %" PRIu64 - "ms\n", + dbg("%s(%d), ptp epochs %" PRIu64 " cur_epochs %" PRIu64 ", ptp_time %" PRIu64 "ms\n", __func__, idx, epochs, pacing->cur_epochs, ptp_time / 1000 / 1000); if (epochs <= pacing->cur_epochs) { uint64_t diff = pacing->cur_epochs - epochs; @@ -649,12 +609,10 @@ static int tv_sync_pacing(struct mtl_main_impl *impl, if (interlaced) { if (second_field) { /* align to odd epoch */ - if (!(epochs & 0x1)) - epochs++; + if (!(epochs & 0x1)) epochs++; s->stat_interlace_second_field++; } else { /* align to even epoch */ - if (epochs & 0x1) - epochs++; + if (epochs & 0x1) epochs++; s->stat_interlace_first_field++; } } @@ -666,8 +624,7 @@ static int tv_sync_pacing(struct mtl_main_impl *impl, /* time larger than the next assigned epoch time */ dbg("%s(%d), to_epoch %f, ptp epochs %" PRIu64 " cur_epochs %" PRIu64 ", ptp_time %" PRIu64 "ms\n", - __func__, idx, to_epoch, epochs, pacing->cur_epochs, - ptp_time / 1000 / 1000); + __func__, idx, to_epoch, epochs, pacing->cur_epochs, ptp_time / 1000 / 1000); s->stat_epoch_troffset_mismatch++; epochs++; /* assign to next */ start_time_ptp = pacing_start_time(pacing, epochs); @@ -676,27 +633,25 @@ static int tv_sync_pacing(struct mtl_main_impl *impl, if (to_epoch < 0) { /* should never happen */ - err("%s(%d), error to_epoch %f, ptp_time %" PRIu64 ", epochs %" PRIu64 - " %" PRIu64 "\n", + err("%s(%d), error to_epoch %f, ptp_time %" PRIu64 ", epochs %" PRIu64 " %" PRIu64 + "\n", __func__, idx, to_epoch, ptp_time, epochs, pacing->cur_epochs); to_epoch = 0; } if (epochs > next_epochs) { - dbg("%s(%d), epochs %" PRIu64 " next_epochs %" PRIu64 "\n", __func__, idx, - epochs, next_epochs); + dbg("%s(%d), epochs %" PRIu64 " next_epochs %" PRIu64 "\n", __func__, idx, epochs, + next_epochs); s->stat_epoch_drop += (epochs - next_epochs); } - if (epochs < next_epochs) - s->stat_epoch_onward += (next_epochs - epochs); + if (epochs < next_epochs) s->stat_epoch_onward += (next_epochs - epochs); pacing->cur_epochs = epochs; pacing->cur_epoch_time = pacing_time(pacing, epochs); pacing->rtp_time_stamp = pacing_time_stamp(s, pacing, epochs); dbg("%s(%d), old time_cursor %fms\n", __func__, idx, pacing->tsc_time_cursor / 1000 / 1000); pacing->tsc_time_cursor = (double)mt_get_tsc(impl) + to_epoch; - dbg("%s(%d), epochs %" PRIu64 - " time_stamp %u time_cursor %fms to_epoch %fms\n", + dbg("%s(%d), epochs %" PRIu64 " time_stamp %u time_cursor %fms to_epoch %fms\n", __func__, idx, pacing->cur_epochs, pacing->rtp_time_stamp, pacing->tsc_time_cursor / 1000 / 1000, to_epoch / 1000 / 1000); pacing->ptp_time_cursor = start_time_ptp; @@ -822,8 +777,7 @@ static int tv_init_st22_boxes(struct st_tx_video_session_impl *s) { return 0; } -static int tv_init_hdr(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, +static int tv_init_hdr(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { int idx = s->idx; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); @@ -839,29 +793,24 @@ static int tv_init_hdr(struct mtl_main_impl *impl, struct rte_ether_addr *d_addr = mt_eth_d_addr(eth); /* ether hdr */ - if ((s_port == MTL_SESSION_PORT_P) && - (ops->flags & ST20_TX_FLAG_USER_P_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], - RTE_ETHER_ADDR_LEN); + if ((s_port == MTL_SESSION_PORT_P) && (ops->flags & ST20_TX_FLAG_USER_P_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); info("%s, USER_P_TX_MAC\n", __func__); - } else if ((s_port == MTL_SESSION_PORT_R) && - (ops->flags & ST20_TX_FLAG_USER_R_MAC)) { - rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], - RTE_ETHER_ADDR_LEN); + } else if ((s_port == MTL_SESSION_PORT_R) && (ops->flags & ST20_TX_FLAG_USER_R_MAC)) { + rte_memcpy(d_addr->addr_bytes, &ops->tx_dst_mac[s_port][0], RTE_ETHER_ADDR_LEN); info("%s, USER_R_TX_MAC\n", __func__); } else { ret = mt_dst_ip_mac(impl, dip, d_addr, port, impl->arp_timeout_ms); if (ret < 0) { - err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, - dip[0], dip[1], dip[2], dip[3]); + err("%s(%d), get mac fail %d for %d.%d.%d.%d\n", __func__, idx, ret, dip[0], dip[1], + dip[2], dip[3]); return ret; } } ret = mt_macaddr_get(impl, port, mt_eth_s_addr(eth)); if (ret < 0) { - err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, - s_port); + err("%s(%d), macaddr get fail %d for port %d\n", __func__, idx, ret, s_port); return ret; } eth->ether_type = htons(RTE_ETHER_TYPE_IPV4); @@ -908,13 +857,11 @@ static int tv_init_hdr(struct mtl_main_impl *impl, st22_hdr->f_counter_lo = 0; } - info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], - dip[1], dip[2], dip[3], s->st20_src_port[s_port], - s->st20_dst_port[s_port]); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", - __func__, idx, d_addr->addr_bytes[0], d_addr->addr_bytes[1], - d_addr->addr_bytes[2], d_addr->addr_bytes[3], d_addr->addr_bytes[4], - d_addr->addr_bytes[5], ssrc); + info("%s(%d,%d), ip %u.%u.%u.%u port %u:%u\n", __func__, idx, s_port, dip[0], dip[1], + dip[2], dip[3], s->st20_src_port[s_port], s->st20_dst_port[s_port]); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx, ssrc %u\n", __func__, idx, + d_addr->addr_bytes[0], d_addr->addr_bytes[1], d_addr->addr_bytes[2], + d_addr->addr_bytes[3], d_addr->addr_bytes[4], d_addr->addr_bytes[5], ssrc); return 0; } @@ -933,8 +880,7 @@ static int tv_uinit_rtcp(struct st_tx_video_session_impl *s) { return 0; } -static int tv_init_rtcp(struct mtl_main_impl *impl, - struct st_tx_video_sessions_mgr *mgr, +static int tv_init_rtcp(struct mtl_main_impl *impl, struct st_tx_video_sessions_mgr *mgr, struct st_tx_video_session_impl *s) { int idx = s->idx; int mgr_idx = mgr->idx; @@ -948,15 +894,13 @@ static int tv_init_rtcp(struct mtl_main_impl *impl, memset(&rtcp_ops, 0, sizeof(rtcp_ops)); rtcp_ops.port = port; char name[MT_RTCP_MAX_NAME_LEN]; - snprintf(name, sizeof(name), ST_TX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, - i); + snprintf(name, sizeof(name), ST_TX_VIDEO_PREFIX "M%dS%dP%d", mgr_idx, idx, i); rtcp_ops.name = name; struct mt_udp_hdr hdr; mtl_memcpy(&hdr, &s->s_hdr[i], sizeof(hdr)); hdr.udp.dst_port++; rtcp_ops.udp_hdr = &hdr; - if (!ops->rtcp.buffer_size) - ops->rtcp.buffer_size = ST_TX_VIDEO_RTCP_RING_SIZE; + if (!ops->rtcp.buffer_size) ops->rtcp.buffer_size = ST_TX_VIDEO_RTCP_RING_SIZE; rtcp_ops.buffer_size = ops->rtcp.buffer_size; if (s->st22_info) rtcp_ops.payload_format = MT_RTP_PAYLOAD_FORMAT_RFC9134; @@ -964,8 +908,7 @@ static int tv_init_rtcp(struct mtl_main_impl *impl, rtcp_ops.payload_format = MT_RTP_PAYLOAD_FORMAT_RFC4175; s->rtcp_tx[i] = mt_rtcp_tx_create(impl, &rtcp_ops); if (!s->rtcp_tx[i]) { - err("%s(%d,%d), mt_rtcp_tx_create fail on port %d\n", __func__, mgr_idx, - idx, i); + err("%s(%d,%d), mt_rtcp_tx_create fail on port %d\n", __func__, mgr_idx, idx, i); tv_uinit_rtcp(s); return -EIO; } @@ -1014,8 +957,7 @@ static int tv_build_st20_redundant(struct st_tx_video_session_impl *s, return 0; } -static int tv_build_st20(struct st_tx_video_session_impl *s, - struct rte_mbuf *pkt) { +static int tv_build_st20(struct st_tx_video_session_impl *s, struct rte_mbuf *pkt) { struct st_rfc4175_video_hdr *hdr; struct rte_ipv4_hdr *ipv4; struct rte_udp_hdr *udp; @@ -1036,8 +978,7 @@ static int tv_build_st20(struct st_tx_video_session_impl *s, /* copy the basic hdrs: eth, ip, udp, rtp */ rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_P], sizeof(*hdr)); - if (s->multi_src_port) - udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; /* calculate payload header */ if (single_line) { @@ -1049,30 +990,27 @@ static int tv_build_st20(struct st_tx_video_session_impl *s, } else { offset = s->st20_pkt_len * s->st20_pkt_idx; line1_number = offset / s->st20_bytes_in_line; - line1_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / - s->st20_pg.size; - if ((offset + s->st20_pkt_len > - (line1_number + 1) * s->st20_bytes_in_line) && + line1_offset = + (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; + if ((offset + s->st20_pkt_len > (line1_number + 1) * s->st20_bytes_in_line) && (offset + s->st20_pkt_len < s->st20_frame_size)) - e_rtp = rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr *, - sizeof(*hdr)); + e_rtp = + rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr *, sizeof(*hdr)); } /* update rtp hdr */ - if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) - rtp->base.marker = 1; + if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) rtp->base.marker = 1; rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); rtp->seq_number_ext = htons((uint16_t)(s->st20_seq_id >> 16)); s->st20_seq_id++; - uint16_t field = - frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; + uint16_t field = frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; rtp->row_number = htons(line1_number | field); rtp->row_offset = htons(line1_offset); rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); - uint32_t temp = single_line ? ((ops->width - line1_offset) / - s->st20_pg.coverage * s->st20_pg.size) - : (s->st20_frame_size - offset); + uint32_t temp = + single_line ? ((ops->width - line1_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (s->st20_frame_size - offset); uint16_t left_len = RTE_MIN(s->st20_pkt_len, temp); rtp->row_length = htons(left_len); @@ -1102,14 +1040,12 @@ static int tv_build_st20(struct st_tx_video_session_impl *s, /* cross lines with padding case */ mtl_memcpy(payload, frame_info->addr + offset, line1_length); mtl_memcpy(payload + line1_length, - frame_info->addr + s->st20_linesize * (line1_number + 1), - line2_length); + frame_info->addr + s->st20_linesize * (line1_number + 1), line2_length); } else { mtl_memcpy(payload, frame_info->addr + offset, left_len); } pkt->data_len = sizeof(struct st_rfc4175_video_hdr) + left_len; - if (e_rtp) - pkt->data_len += sizeof(*e_rtp); + if (e_rtp) pkt->data_len += sizeof(*e_rtp); pkt->pkt_len = pkt->data_len; udp->dgram_len = htons(pkt->pkt_len - pkt->l2_len - pkt->l3_len); @@ -1122,8 +1058,7 @@ static int tv_build_st20(struct st_tx_video_session_impl *s, return 0; } -static int tv_build_st20_chain(struct st_tx_video_session_impl *s, - struct rte_mbuf *pkt, +static int tv_build_st20_chain(struct st_tx_video_session_impl *s, struct rte_mbuf *pkt, struct rte_mbuf *pkt_chain) { struct st_rfc4175_video_hdr *hdr; struct rte_ipv4_hdr *ipv4; @@ -1145,8 +1080,7 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl *s, /* copy the hdr: eth, ip, udp, rtp */ rte_memcpy(hdr, &s->s_hdr[MTL_SESSION_PORT_P], sizeof(*hdr)); - if (s->multi_src_port) - udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; if (single_line) { line1_number = s->st20_pkt_idx / s->st20_pkts_in_line; @@ -1157,30 +1091,27 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl *s, } else { offset = s->st20_pkt_len * s->st20_pkt_idx; line1_number = offset / s->st20_bytes_in_line; - line1_offset = (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / - s->st20_pg.size; - if ((offset + s->st20_pkt_len > - (line1_number + 1) * s->st20_bytes_in_line) && + line1_offset = + (offset % s->st20_bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; + if ((offset + s->st20_pkt_len > (line1_number + 1) * s->st20_bytes_in_line) && (offset + s->st20_pkt_len < s->st20_frame_size)) - e_rtp = rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr *, - sizeof(*hdr)); + e_rtp = + rte_pktmbuf_mtod_offset(pkt, struct st20_rfc4175_extra_rtp_hdr *, sizeof(*hdr)); } /* update rtp */ - if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) - rtp->base.marker = 1; + if (s->st20_pkt_idx >= (s->st20_total_pkts - 1)) rtp->base.marker = 1; rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); rtp->seq_number_ext = htons((uint16_t)(s->st20_seq_id >> 16)); s->st20_seq_id++; - uint16_t field = - frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; + uint16_t field = frame_info->tv_meta.second_field ? ST20_SECOND_FIELD : 0x0000; rtp->row_number = htons(line1_number | field); rtp->row_offset = htons(line1_offset); rtp->base.tmstamp = htonl(s->pacing.rtp_time_stamp); - uint32_t temp = single_line ? ((ops->width - line1_offset) / - s->st20_pg.coverage * s->st20_pg.size) - : (s->st20_frame_size - offset); + uint32_t temp = + single_line ? ((ops->width - line1_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (s->st20_frame_size - offset); uint16_t left_len = RTE_MIN(s->st20_pkt_len, temp); rtp->row_length = htons(left_len); @@ -1197,8 +1128,7 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl *s, /* update mbuf */ mt_mbuf_init_ipv4(pkt); pkt->data_len = sizeof(struct st_rfc4175_video_hdr); - if (e_rtp) - pkt->data_len += sizeof(*e_rtp); + if (e_rtp) pkt->data_len += sizeof(*e_rtp); pkt->pkt_len = pkt->data_len; if (!single_line && s->st20_linesize > s->st20_bytes_in_line) @@ -1211,8 +1141,7 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl *s, rte_pktmbuf_free(pkt_chain); pkt_chain = rte_pktmbuf_alloc(s->mbuf_mempool_copy_chain); if (!pkt_chain) { - dbg("%s(%d), pkts chain realloc fail %d\n", __func__, s->idx, - s->st20_pkt_idx); + dbg("%s(%d), pkts chain realloc fail %d\n", __func__, s->idx, s->st20_pkt_idx); s->stat_pkts_chain_realloc_fail++; /* we can do nothing but count */ return -ENOMEM; } @@ -1220,8 +1149,7 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl *s, void *payload = rte_pktmbuf_mtod(pkt_chain, void *); mtl_memcpy(payload, frame_info->addr + offset, line1_length); mtl_memcpy(payload + line1_length, - frame_info->addr + s->st20_linesize * (line1_number + 1), - line2_length); + frame_info->addr + s->st20_linesize * (line1_number + 1), line2_length); } else if (tv_frame_payload_cross_page(s, frame_info, offset, left_len)) { /* do not attach extbuf, copy to data room */ void *payload = rte_pktmbuf_mtod(pkt_chain, void *); @@ -1229,8 +1157,8 @@ static int tv_build_st20_chain(struct st_tx_video_session_impl *s, } else { /* attach payload to chainbuf */ rte_pktmbuf_attach_extbuf(pkt_chain, frame_info->addr + offset, - tv_frame_get_offset_iova(s, frame_info, offset), - left_len, &frame_info->sh_info); + tv_frame_get_offset_iova(s, frame_info, offset), left_len, + &frame_info->sh_info); rte_mbuf_ext_refcnt_update(&frame_info->sh_info, 1); } pkt_chain->data_len = pkt_chain->pkt_len = left_len; @@ -1272,8 +1200,7 @@ static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl *s, /* copy extra if Continuation */ uint16_t line1_offset = ntohs(rtp->row_offset); if (line1_offset & ST20_SRD_OFFSET_CONTINUATION) { - rte_memcpy(&rtp[1], &rtp_base[1], - sizeof(struct st20_rfc4175_extra_rtp_hdr)); + rte_memcpy(&rtp[1], &rtp_base[1], sizeof(struct st20_rfc4175_extra_rtp_hdr)); } /* update mbuf */ @@ -1298,8 +1225,7 @@ static int tv_build_st20_redundant_chain(struct st_tx_video_session_impl *s, return 0; } -static int tv_build_rtp(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, +static int tv_build_rtp(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, struct rte_mbuf *pkt) { struct mt_udp_hdr *hdr; struct rte_ipv4_hdr *ipv4; @@ -1317,16 +1243,14 @@ static int tv_build_rtp(struct mtl_main_impl *impl, rte_memcpy(ipv4, &s->s_hdr[MTL_SESSION_PORT_P].ipv4, sizeof(hdr->ipv4)); rte_memcpy(udp, &s->s_hdr[MTL_SESSION_PORT_P].udp, sizeof(hdr->udp)); - if (s->multi_src_port) - udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; if (rtp->tmstamp != s->st20_rtp_time) { /* start of a new frame */ s->st20_pkt_idx = 0; rte_atomic32_inc(&s->stat_frame_cnt); s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (s->ops.num_port > 1) - s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (s->ops.num_port > 1) s->port_user_stats[MTL_SESSION_PORT_R].frames++; s->st20_rtp_time = rtp->tmstamp; bool second_field = false; if (s->ops.interlaced) { @@ -1339,8 +1263,7 @@ static int tv_build_rtp(struct mtl_main_impl *impl, if (s->ops.flags & ST20_TX_FLAG_USER_TIMESTAMP) { s->pacing.rtp_time_stamp = ntohl(rtp->tmstamp); } - dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, - s->pacing.rtp_time_stamp); + dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, s->pacing.rtp_time_stamp); } /* update rtp time*/ rtp->tmstamp = htonl(s->pacing.rtp_time_stamp); @@ -1359,8 +1282,7 @@ static int tv_build_rtp(struct mtl_main_impl *impl, } static int tv_build_rtp_chain(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, - struct rte_mbuf *pkt, + struct st_tx_video_session_impl *s, struct rte_mbuf *pkt, struct rte_mbuf *pkt_chain) { struct mt_udp_hdr *hdr; struct rte_ipv4_hdr *ipv4; @@ -1377,16 +1299,14 @@ static int tv_build_rtp_chain(struct mtl_main_impl *impl, rte_memcpy(ipv4, &s->s_hdr[MTL_SESSION_PORT_P].ipv4, sizeof(hdr->ipv4)); rte_memcpy(udp, &s->s_hdr[MTL_SESSION_PORT_P].udp, sizeof(hdr->udp)); - if (s->multi_src_port) - udp->src_port += (s->st20_pkt_idx / 128) % 8; + if (s->multi_src_port) udp->src_port += (s->st20_pkt_idx / 128) % 8; if (rtp->tmstamp != s->st20_rtp_time) { /* start of a new frame */ s->st20_pkt_idx = 0; rte_atomic32_inc(&s->stat_frame_cnt); s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (s->ops.num_port > 1) - s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (s->ops.num_port > 1) s->port_user_stats[MTL_SESSION_PORT_R].frames++; s->st20_rtp_time = rtp->tmstamp; bool second_field = false; if (s->ops.interlaced) { @@ -1399,8 +1319,7 @@ static int tv_build_rtp_chain(struct mtl_main_impl *impl, if (s->ops.flags & ST20_TX_FLAG_USER_TIMESTAMP) { s->pacing.rtp_time_stamp = ntohl(rtp->tmstamp); } - dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, - s->pacing.rtp_time_stamp); + dbg("%s(%d), rtp time stamp %u\n", __func__, s->idx, s->pacing.rtp_time_stamp); } /* update rtp time*/ rtp->tmstamp = htonl(s->pacing.rtp_time_stamp); @@ -1458,8 +1377,7 @@ static int tv_build_rtp_redundant_chain(struct st_tx_video_session_impl *s, return 0; } -static int tv_build_st22(struct st_tx_video_session_impl *s, - struct rte_mbuf *pkt) { +static int tv_build_st22(struct st_tx_video_session_impl *s, struct rte_mbuf *pkt) { struct st22_rfc9134_video_hdr *hdr; struct rte_ipv4_hdr *ipv4; struct rte_udp_hdr *udp; @@ -1482,8 +1400,8 @@ static int tv_build_st22(struct st_tx_video_session_impl *s, if (s->st20_pkt_idx >= (st22_info->st22_total_pkts - 1)) { rtp->base.marker = 1; rtp->last_packet = 1; - dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, - s->st20_pkt_idx, s->st22_total_pkts); + dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, s->st20_pkt_idx, + s->st22_total_pkts); } rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); s->st20_seq_id++; @@ -1510,8 +1428,7 @@ static int tv_build_st22(struct st_tx_video_session_impl *s, mt_mbuf_init_ipv4(pkt); uint32_t offset = s->st20_pkt_idx * s->st20_pkt_len; - uint16_t left_len = - RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); + uint16_t left_len = RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); dbg("%s(%d), data len %u on pkt %d(total %d)\n", __func__, s->idx, left_len, s->st20_pkt_idx, s->st22_total_pkts); @@ -1533,8 +1450,7 @@ static int tv_build_st22(struct st_tx_video_session_impl *s, return 0; } -static int tv_build_st22_chain(struct st_tx_video_session_impl *s, - struct rte_mbuf *pkt, +static int tv_build_st22_chain(struct st_tx_video_session_impl *s, struct rte_mbuf *pkt, struct rte_mbuf *pkt_chain) { struct st22_rfc9134_video_hdr *hdr; struct rte_ipv4_hdr *ipv4; @@ -1558,8 +1474,8 @@ static int tv_build_st22_chain(struct st_tx_video_session_impl *s, if (s->st20_pkt_idx >= (st22_info->st22_total_pkts - 1)) { rtp->base.marker = 1; rtp->last_packet = 1; - dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, - s->st20_pkt_idx, s->st22_total_pkts); + dbg("%s(%d), maker on pkt %d(total %d)\n", __func__, s->idx, s->st20_pkt_idx, + s->st22_total_pkts); } rtp->base.seq_number = htons((uint16_t)s->st20_seq_id); s->st20_seq_id++; @@ -1588,8 +1504,7 @@ static int tv_build_st22_chain(struct st_tx_video_session_impl *s, pkt->pkt_len = pkt->data_len; uint32_t offset = s->st20_pkt_idx * s->st20_pkt_len; - uint16_t left_len = - RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); + uint16_t left_len = RTE_MIN(s->st20_pkt_len, st22_info->cur_frame_size - offset); dbg("%s(%d), data len %u on pkt %d(total %d)\n", __func__, s->idx, left_len, s->st20_pkt_idx, s->st22_total_pkts); @@ -1601,8 +1516,8 @@ static int tv_build_st22_chain(struct st_tx_video_session_impl *s, mtl_memcpy(payload, frame_info->addr + offset, left_len); } else { /* attach payload */ rte_pktmbuf_attach_extbuf(pkt_chain, frame_info->addr + offset, - tv_frame_get_offset_iova(s, frame_info, offset), - left_len, &frame_info->sh_info); + tv_frame_get_offset_iova(s, frame_info, offset), left_len, + &frame_info->sh_info); rte_mbuf_ext_refcnt_update(&frame_info->sh_info, 1); } @@ -1665,19 +1580,15 @@ static int tv_build_st22_redundant_chain(struct st_tx_video_session_impl *s, } static uint64_t tv_pacing_required_tai(struct st_tx_video_session_impl *s, - enum st10_timestamp_fmt tfmt, - uint64_t timestamp) { + enum st10_timestamp_fmt tfmt, uint64_t timestamp) { uint64_t required_tai = 0; - if (!(s->ops.flags & ST20_TX_FLAG_USER_PACING)) - return 0; - if (!timestamp) - return 0; + if (!(s->ops.flags & ST20_TX_FLAG_USER_PACING)) return 0; + if (!timestamp) return 0; if (tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (timestamp > 0xFFFFFFFF) { - err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, - timestamp); + err("%s(%d), invalid timestamp %" PRIu64 "\n", __func__, s->idx, timestamp); } required_tai = st10_media_clk_to_ns((uint32_t)timestamp, 90 * 1000); } else { @@ -1694,11 +1605,9 @@ static int tv_tasklet_start(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_video_session_get(mgr, sidx); - if (!s) - continue; + if (!s) continue; /* re-calculate the vsync */ - if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) - st_vsync_calculate(impl, &s->vsync); + if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) st_vsync_calculate(impl, &s->vsync); for (int i = 0; i < s->ops.num_port; i++) { s->last_burst_succ_time_tsc[i] = mt_get_tsc(impl); } @@ -1721,8 +1630,8 @@ static int tv_usdt_dump_frame(struct mtl_main_impl *impl, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st20tx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, - ops->width, ops->height); + "imtl_usdt_st20tx_m%ds%d_%d_%d_XXXXXX.yuv", mgr->idx, idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".yuv")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -1734,8 +1643,7 @@ static int tv_usdt_dump_frame(struct mtl_main_impl *impl, if (n != s->st20_frame_size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST20_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, - n); + MT_USDT_ST20_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -1773,8 +1681,8 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, /* check if any inflight pkts */ if (s->inflight[MTL_SESSION_PORT_P][0]) { - n = rte_ring_sp_enqueue_bulk( - ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], + bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_P][0] = NULL; } else { @@ -1783,8 +1691,8 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, } } if (send_r && s->inflight[MTL_SESSION_PORT_R][0]) { - n = rte_ring_sp_enqueue_bulk( - ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], + bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_R][0] = NULL; } else { @@ -1802,13 +1710,11 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, tv_init_next_meta(s, &meta); /* Query next frame buffer idx */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); ret = ops->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_next_frame_us = - RTE_MAX(s->stat_max_next_frame_us, delta_us); + s->stat_max_next_frame_us = RTE_MAX(s->stat_max_next_frame_us, delta_us); } if (ret < 0) { /* no frame ready from app */ if (s->stat_user_busy_first) { @@ -1823,8 +1729,8 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, struct st_frame_trans *frame = &s->st20_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, - next_frame_idx, refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, + refcnt); s->stat_build_ret_code = -STI_FRAME_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } @@ -1833,8 +1739,8 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, frame->user_meta_data_size = 0; if (meta.user_meta) { if (meta.user_meta_size > frame->user_meta_buffer_size) { - err("%s(%d), frame %u user meta size %" PRId64 " too large\n", - __func__, idx, next_frame_idx, meta.user_meta_size); + err("%s(%d), frame %u user meta size %" PRId64 " too large\n", __func__, idx, + next_frame_idx, meta.user_meta_size); s->stat_build_ret_code = -STI_FRAME_APP_ERR_USER_META; return MTL_TASKLET_ALL_DONE; } @@ -1853,14 +1759,12 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, s->st20_frame_stat = ST21_TX_STAT_SENDING_PKTS; /* user timestamp control if any */ - uint64_t required_tai = - tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); + uint64_t required_tai = tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); bool second_field = frame->tv_meta.second_field; tv_sync_pacing(impl, s, false, required_tai, second_field); if (ops->flags & ST20_TX_FLAG_USER_TIMESTAMP && (frame->tv_meta.tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK)) { - pacing->rtp_time_stamp = - st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); + pacing->rtp_time_stamp = st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); } dbg("%s(%d), rtp time stamp %u\n", __func__, idx, pacing->rtp_time_stamp); frame->tv_meta.tfmt = ST10_TIMESTAMP_FMT_TAI; @@ -1871,8 +1775,8 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, if (ops->interlaced) { s->second_field = second_field ? false : true; } - MT_USDT_ST20_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, - frame->addr, pacing->rtp_time_stamp); + MT_USDT_ST20_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, frame->addr, + pacing->rtp_time_stamp); /* check if dump USDT enabled */ if (MT_USDT_ST20_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -1894,20 +1798,17 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, uint32_t offset = s->st20_pkt_len * (s->st20_pkt_idx + bulk); line_number = offset / s->st20_bytes_in_line + 1; } - if (line_number >= ops->height) - line_number = ops->height - 1; + if (line_number >= ops->height) line_number = ops->height - 1; if (line_number >= s->st20_frame_lines_ready) { struct st20_tx_slice_meta slice_meta; memset(&slice_meta, 0, sizeof(slice_meta)); - ret = ops->query_frame_lines_ready(ops->priv, s->st20_frame_idx, - &slice_meta); - if (ret >= 0) - s->st20_frame_lines_ready = slice_meta.lines_ready; - dbg("%s(%d), need line %u, ready lines %u\n", __func__, s->idx, - ops->height, s->st20_frame_lines_ready); + ret = ops->query_frame_lines_ready(ops->priv, s->st20_frame_idx, &slice_meta); + if (ret >= 0) s->st20_frame_lines_ready = slice_meta.lines_ready; + dbg("%s(%d), need line %u, ready lines %u\n", __func__, s->idx, ops->height, + s->st20_frame_lines_ready); if ((ret < 0) || (line_number >= s->st20_frame_lines_ready)) { - dbg("%s(%d), line %u not ready, ready lines %u\n", __func__, s->idx, - line_number, s->st20_frame_lines_ready); + dbg("%s(%d), line %u not ready, ready lines %u\n", __func__, s->idx, line_number, + s->st20_frame_lines_ready); s->stat_lines_not_ready++; s->stat_build_ret_code = -STI_FRAME_APP_SLICE_NOT_READY; return MTL_TASKLET_ALL_DONE; @@ -1941,8 +1842,7 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, if (ret < 0) { dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret); rte_pktmbuf_free_bulk(pkts, bulk); - if (!s->tx_no_chain) - rte_pktmbuf_free_bulk(pkts_chain, bulk); + if (!s->tx_no_chain) rte_pktmbuf_free_bulk(pkts_chain, bulk); s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL; return MTL_TASKLET_ALL_DONE; } @@ -1952,8 +1852,7 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, st_tx_mbuf_set_priv(pkts[i], &s->st20_frames[s->st20_frame_idx]); if (s->st20_pkt_idx >= s->st20_total_pkts) { s->stat_pkts_dummy++; - if (!s->tx_no_chain) - rte_pktmbuf_free(pkts_chain[i]); + if (!s->tx_no_chain) rte_pktmbuf_free(pkts_chain[i]); st_tx_mbuf_set_idx(pkts[i], ST_TX_DUMMY_PKT_IDX); } else { if (s->tx_no_chain) @@ -1989,8 +1888,7 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, bool done = false; n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&pkts[0], bulk, NULL); if (n == 0) { - for (unsigned int i = 0; i < bulk; i++) - s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; + for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; s->inflight_cnt[MTL_SESSION_PORT_P]++; s->stat_build_ret_code = -STI_FRAME_PKT_ENQUEUE_FAIL; done = true; @@ -2007,14 +1905,13 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, } if (s->st20_pkt_idx >= s->st20_total_pkts) { - dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, - s->st20_frame_idx, s->st20_pkt_idx); + dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, s->st20_frame_idx, + s->st20_pkt_idx); /* end of current frame */ s->st20_frame_stat = ST21_TX_STAT_WAIT_FRAME; s->st20_pkt_idx = 0; s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (send_r) - s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (send_r) s->port_user_stats[MTL_SESSION_PORT_R].frames++; rte_atomic32_inc(&s->stat_frame_cnt); if (s->tx_no_chain) { /* trigger extbuf free cb since mbuf attach not used */ @@ -2026,8 +1923,7 @@ static int tv_tasklet_frame(struct mtl_main_impl *impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; rte_atomic32_inc(&s->cbs_build_timeout); - dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, - s->st20_frame_idx, + dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, s->st20_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } /* point to tsc time of next epoch */ @@ -2043,15 +1939,14 @@ static int tv_tasklet_rtcp(struct st_tx_video_session_impl *s) { int num_port = s->ops.num_port; for (int s_port = 0; s_port < num_port; s_port++) { - if (!s->rtcp_q[s_port]) - continue; + if (!s->rtcp_q[s_port]) continue; rv = mt_rxq_burst(s->rtcp_q[s_port], &mbuf[0], ST_TX_VIDEO_RTCP_BURST_SIZE); if (rv) { for (uint16_t i = 0; i < rv; i++) { // rte_pktmbuf_dump(stdout, mbuf[i], mbuf[i]->pkt_len); - struct mt_rtcp_hdr *rtcp = rte_pktmbuf_mtod_offset( - mbuf[i], struct mt_rtcp_hdr *, sizeof(struct mt_udp_hdr)); + struct mt_rtcp_hdr *rtcp = rte_pktmbuf_mtod_offset(mbuf[i], struct mt_rtcp_hdr *, + sizeof(struct mt_udp_hdr)); mt_rtcp_tx_parse_rtcp_packet(s->rtcp_tx[s_port], rtcp); } rte_pktmbuf_free_bulk(&mbuf[0], rv); @@ -2089,8 +1984,8 @@ static int tv_tasklet_rtp(struct mtl_main_impl *impl, /* check if any inflight pkts */ if (s->inflight[MTL_SESSION_PORT_P][0]) { - n = rte_ring_sp_enqueue_bulk( - ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], + bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_P][0] = NULL; } else { @@ -2099,8 +1994,8 @@ static int tv_tasklet_rtp(struct mtl_main_impl *impl, } } if (send_r && s->inflight[MTL_SESSION_PORT_R][0]) { - n = rte_ring_sp_enqueue_bulk( - ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], + bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_R][0] = false; } else { @@ -2117,11 +2012,9 @@ static int tv_tasklet_rtp(struct mtl_main_impl *impl, unsigned int pkts_bulk = eof ? 1 : bulk; /* bulk one only at end of frame */ if (eof) - dbg("%s(%d), pkts_bulk %d pkt idx %d\n", __func__, idx, pkts_bulk, - s->st20_pkt_idx); + dbg("%s(%d), pkts_bulk %d pkt idx %d\n", __func__, idx, pkts_bulk, s->st20_pkt_idx); - n = mt_rte_ring_sc_dequeue_bulk(s->packet_ring, (void **)&pkts_rtp, pkts_bulk, - NULL); + n = mt_rte_ring_sc_dequeue_bulk(s->packet_ring, (void **)&pkts_rtp, pkts_bulk, NULL); if (n == 0) { if (s->stat_user_busy_first) { s->stat_user_busy++; @@ -2207,8 +2100,7 @@ static int tv_tasklet_rtp(struct mtl_main_impl *impl, bool done = false; n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&pkts[0], bulk, NULL); if (n == 0) { - for (unsigned int i = 0; i < bulk; i++) - s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; + for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; s->inflight_cnt[MTL_SESSION_PORT_P]++; s->stat_build_ret_code = -STI_RTP_PKT_ENQUEUE_FAIL; done = true; @@ -2229,8 +2121,7 @@ static int tv_tasklet_rtp(struct mtl_main_impl *impl, static int tv_st22_usdt_dump_codestream(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, - struct st_frame_trans *frame, - size_t size) { + struct st_frame_trans *frame, size_t size) { struct st_tx_video_sessions_mgr *mgr = s->mgr; int idx = s->idx; int fd; @@ -2239,8 +2130,8 @@ static int tv_st22_usdt_dump_codestream(struct mtl_main_impl *impl, uint64_t tsc_s = mt_get_tsc(impl); snprintf(usdt_dump_path, sizeof(usdt_dump_path), - "imtl_usdt_st22tx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, - ops->width, ops->height); + "imtl_usdt_st22tx_m%ds%d_%d_%d_XXXXXX.raw", mgr->idx, idx, ops->width, + ops->height); fd = mt_mkstemps(usdt_dump_path, strlen(".raw")); if (fd < 0) { err("%s(%d), mkstemps %s fail %d\n", __func__, idx, usdt_dump_path, fd); @@ -2252,8 +2143,7 @@ static int tv_st22_usdt_dump_codestream(struct mtl_main_impl *impl, if (n != size) { warn("%s(%d), write fail %" PRIu64 "\n", __func__, idx, n); } else { - MT_USDT_ST22_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, - n); + MT_USDT_ST22_TX_FRAME_DUMP(mgr->idx, s->idx, usdt_dump_path, frame->addr, n); } info("%s(%d), write %" PRIu64 " to %s(fd:%d), time %fms\n", __func__, idx, n, @@ -2291,8 +2181,8 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, /* check if any inflight pkts */ if (s->inflight[MTL_SESSION_PORT_P][0]) { - n = rte_ring_sp_enqueue_bulk( - ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&s->inflight[MTL_SESSION_PORT_P][0], + bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_P][0] = NULL; } else { @@ -2301,8 +2191,8 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, } } if (send_r && s->inflight[MTL_SESSION_PORT_R][0]) { - n = rte_ring_sp_enqueue_bulk( - ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], bulk, NULL); + n = rte_ring_sp_enqueue_bulk(ring_r, (void **)&s->inflight[MTL_SESSION_PORT_R][0], + bulk, NULL); if (n > 0) { s->inflight[MTL_SESSION_PORT_R][0] = NULL; } else { @@ -2320,13 +2210,11 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, tv_init_st22_next_meta(s, &meta); /* Query next frame buffer idx */ bool time_measure = mt_sessions_time_measure(impl); - if (time_measure) - tsc_start = mt_get_tsc(impl); + if (time_measure) tsc_start = mt_get_tsc(impl); ret = st22_info->get_next_frame(ops->priv, &next_frame_idx, &meta); if (time_measure) { uint32_t delta_us = (mt_get_tsc(impl) - tsc_start) / NS_PER_US; - s->stat_max_next_frame_us = - RTE_MAX(s->stat_max_next_frame_us, delta_us); + s->stat_max_next_frame_us = RTE_MAX(s->stat_max_next_frame_us, delta_us); } if (ret < 0) { /* no frame ready from app */ if (s->stat_user_busy_first) { @@ -2341,16 +2229,15 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, struct st_frame_trans *frame = &s->st20_frames[next_frame_idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, - next_frame_idx, refcnt); + err("%s(%d), frame %u refcnt not zero %d\n", __func__, idx, next_frame_idx, + refcnt); s->stat_build_ret_code = -STI_ST22_APP_ERR_TX_FRAME; return MTL_TASKLET_ALL_DONE; } /* check code stream size */ size_t codestream_size = meta.codestream_size; if ((codestream_size > s->st22_codestream_size) || !codestream_size) { - err("%s(%d), invalid codestream size %" PRIu64 ", allowed %" PRIu64 - "\n", + err("%s(%d), invalid codestream size %" PRIu64 ", allowed %" PRIu64 "\n", __func__, idx, codestream_size, s->st22_codestream_size); tv_notify_frame_done(s, next_frame_idx); s->stat_build_ret_code = -STI_ST22_APP_GET_FRAME_ERR_SIZE; @@ -2363,22 +2250,19 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, rte_atomic32_inc(&frame->refcnt); size_t frame_size = codestream_size + s->st22_box_hdr_length; st22_info->st22_total_pkts = frame_size / s->st20_pkt_len; - if (frame_size % s->st20_pkt_len) - st22_info->st22_total_pkts++; + if (frame_size % s->st20_pkt_len) st22_info->st22_total_pkts++; s->st20_total_pkts = st22_info->st22_total_pkts; st22_info->cur_frame_size = frame_size; s->st20_frame_idx = next_frame_idx; s->st20_frame_stat = ST21_TX_STAT_SENDING_PKTS; /* user timestamp control if any */ - uint64_t required_tai = - tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); + uint64_t required_tai = tv_pacing_required_tai(s, meta.tfmt, meta.timestamp); bool second_field = frame->tx_st22_meta.second_field; tv_sync_pacing_st22(impl, s, false, required_tai, second_field, st22_info->st22_total_pkts); if (ops->flags & ST20_TX_FLAG_USER_TIMESTAMP) { - pacing->rtp_time_stamp = - st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); + pacing->rtp_time_stamp = st10_get_media_clk(meta.tfmt, meta.timestamp, 90 * 1000); } dbg("%s(%d), rtp time stamp %u\n", __func__, idx, pacing->rtp_time_stamp); frame->tx_st22_meta.tfmt = ST10_TIMESTAMP_FMT_TAI; @@ -2389,9 +2273,8 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, if (ops->interlaced) { s->second_field = second_field ? false : true; } - MT_USDT_ST22_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, - frame->addr, pacing->rtp_time_stamp, - codestream_size); + MT_USDT_ST22_TX_FRAME_NEXT(s->mgr->idx, s->idx, next_frame_idx, frame->addr, + pacing->rtp_time_stamp, codestream_size); /* check if dump USDT enabled */ if (MT_USDT_ST22_TX_FRAME_DUMP_ENABLED()) { int period = st_frame_rate(ops->fps) * 5; /* dump every 5s now */ @@ -2402,11 +2285,10 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, } else { s->usdt_frame_cnt = 0; } - dbg("%s(%d), next_frame_idx %d(%d pkts) start\n", __func__, idx, - next_frame_idx, s->st20_total_pkts); - dbg("%s(%d), codestream_size %" PRId64 "(%d st22 pkts) time_stamp %u\n", - __func__, idx, codestream_size, st22_info->st22_total_pkts, - pacing->rtp_time_stamp); + dbg("%s(%d), next_frame_idx %d(%d pkts) start\n", __func__, idx, next_frame_idx, + s->st20_total_pkts); + dbg("%s(%d), codestream_size %" PRId64 "(%d st22 pkts) time_stamp %u\n", __func__, + idx, codestream_size, st22_info->st22_total_pkts, pacing->rtp_time_stamp); return MTL_TASKLET_HAS_PENDING; } else if (ST21_TX_STAT_SENDING_PKTS == s->st20_frame_stat) { uint64_t tsc_time_frame_start = s->pacing.tsc_time_frame_start; @@ -2468,8 +2350,7 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, if (ret < 0) { dbg("%s(%d), pkts_r alloc fail %d\n", __func__, idx, ret); rte_pktmbuf_free_bulk(pkts, bulk); - if (!s->tx_no_chain) - rte_pktmbuf_free_bulk(pkts_chain, bulk); + if (!s->tx_no_chain) rte_pktmbuf_free_bulk(pkts_chain, bulk); s->stat_build_ret_code = -STI_FRAME_PKT_ALLOC_R_FAIL; return MTL_TASKLET_ALL_DONE; } @@ -2479,8 +2360,7 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, if (s->st20_pkt_idx >= st22_info->st22_total_pkts) { dbg("%s(%d), pad on pkt %d\n", __func__, s->idx, s->st20_pkt_idx); s->stat_pkts_dummy++; - if (!s->tx_no_chain) - rte_pktmbuf_free(pkts_chain[i]); + if (!s->tx_no_chain) rte_pktmbuf_free(pkts_chain[i]); st_tx_mbuf_set_idx(pkts[i], ST_TX_DUMMY_PKT_IDX); } else { if (s->tx_no_chain) @@ -2516,8 +2396,7 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, bool done = false; n = rte_ring_sp_enqueue_bulk(ring_p, (void **)&pkts[0], bulk, NULL); if (n == 0) { - for (unsigned int i = 0; i < bulk; i++) - s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; + for (unsigned int i = 0; i < bulk; i++) s->inflight[MTL_SESSION_PORT_P][i] = pkts[i]; s->inflight_cnt[MTL_SESSION_PORT_P]++; s->stat_build_ret_code = -STI_ST22_PKT_ENQUEUE_FAIL; done = true; @@ -2534,14 +2413,13 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, } if (s->st20_pkt_idx >= s->st20_total_pkts) { - dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, - s->st20_frame_idx, s->st20_pkt_idx); + dbg("%s(%d), frame %d done with %d pkts\n", __func__, idx, s->st20_frame_idx, + s->st20_pkt_idx); /* end of current frame */ s->st20_frame_stat = ST21_TX_STAT_WAIT_FRAME; s->st20_pkt_idx = 0; s->port_user_stats[MTL_SESSION_PORT_P].frames++; - if (send_r) - s->port_user_stats[MTL_SESSION_PORT_R].frames++; + if (send_r) s->port_user_stats[MTL_SESSION_PORT_R].frames++; rte_atomic32_inc(&s->stat_frame_cnt); st22_info->frame_idx++; if (s->tx_no_chain) { @@ -2554,8 +2432,7 @@ static int tv_tasklet_st22(struct mtl_main_impl *impl, if (frame_end_time > pacing->tsc_time_cursor) { s->stat_exceed_frame_time++; rte_atomic32_inc(&s->cbs_build_timeout); - dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, - s->st20_frame_idx, + dbg("%s(%d), frame %d build time out %fus\n", __func__, idx, s->st20_frame_idx, (frame_end_time - pacing->tsc_time_cursor) / NS_PER_US); } } @@ -2573,19 +2450,14 @@ static int tvs_tasklet_handler(void *priv) { for (int sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_video_session_try_get(mgr, sidx); - if (!s) - continue; - if (!s->active) - goto exit; + if (!s) continue; + if (!s->active) goto exit; - if (time_measure) - tsc_s = mt_get_tsc(impl); + if (time_measure) tsc_s = mt_get_tsc(impl); - if (s->ops.flags & ST20_TX_FLAG_ENABLE_RTCP) - tv_tasklet_rtcp(s); + if (s->ops.flags & ST20_TX_FLAG_ENABLE_RTCP) tv_tasklet_rtcp(s); /* check vsync if it has vsync enabled */ - if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) - tv_poll_vsync(impl, s); + if (s->ops.flags & ST20_TX_FLAG_ENABLE_VSYNC) tv_poll_vsync(impl, s); s->stat_build_ret_code = 0; if (s->st22_info) @@ -2620,8 +2492,7 @@ static int tv_uinit_hw(struct st_tx_video_session_impl *s) { if (s->queue[i]) { struct rte_mbuf *pad = s->pad[i][ST20_PKT_TYPE_NORMAL]; /* flush all the pkts in the tx ring desc */ - if (pad) - mt_txq_flush(s->queue[i], pad); + if (pad) mt_txq_flush(s->queue[i], pad); mt_txq_put(s->queue[i]); s->queue[i] = NULL; } @@ -2637,8 +2508,7 @@ static int tv_uinit_hw(struct st_tx_video_session_impl *s) { return 0; } -static int tv_init_hw(struct mtl_main_impl *impl, - struct st_tx_video_sessions_mgr *mgr, +static int tv_init_hw(struct mtl_main_impl *impl, struct st_tx_video_sessions_mgr *mgr, struct st_tx_video_session_impl *s) { unsigned int flags, count; struct rte_ring *ring; @@ -2662,8 +2532,7 @@ static int tv_init_hw(struct mtl_main_impl *impl, flow.gso_sz = s->st20_pkt_size - sizeof(struct mt_udp_hdr); #ifdef MTL_HAS_RDMA_BACKEND int num_mrs = 1; - if (!s->tx_no_chain) - num_mrs += s->st20_frames_cnt; + if (!s->tx_no_chain) num_mrs += s->st20_frames_cnt; void *mrs_bufs[num_mrs]; size_t mrs_sizes[num_mrs]; if (mt_pmd_is_rdma_ud(impl, port)) { @@ -2693,33 +2562,30 @@ static int tv_init_hw(struct mtl_main_impl *impl, queue_id = mt_txq_queue_id(s->queue[i]); snprintf(ring_name, 32, "%sM%dS%dP%d", ST_TX_VIDEO_PREFIX, mgr_idx, idx, i); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = s->ring_count; ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { - err("%s(%d,%d), rte_ring_create fail for port %d\n", __func__, mgr_idx, - idx, i); + err("%s(%d,%d), rte_ring_create fail for port %d\n", __func__, mgr_idx, idx, i); tv_uinit_hw(s); return -ENOMEM; } s->ring[i] = ring; - info("%s(%d,%d), port(l:%d,p:%d), queue %d, count %u\n", __func__, mgr_idx, - idx, i, port, queue_id, count); + info("%s(%d,%d), port(l:%d,p:%d), queue %d, count %u\n", __func__, mgr_idx, idx, i, + port, queue_id, count); if (mt_pmd_is_dpdk_af_xdp(impl, port) && s->mbuf_mempool_reuse_rx[i]) { if (s->mbuf_mempool_hdr[i]) { - err("%s(%d,%d), fail to reuse rx, has mempool_hdr for port %d\n", - __func__, mgr_idx, idx, i); + err("%s(%d,%d), fail to reuse rx, has mempool_hdr for port %d\n", __func__, + mgr_idx, idx, i); } else { /* reuse rx mempool for zero copy */ if (mt_user_rx_mono_pool(impl)) s->mbuf_mempool_hdr[i] = mt_sys_rx_mempool(impl, port); else - s->mbuf_mempool_hdr[i] = - mt_if(impl, port)->rx_queues[queue_id].mbuf_pool; - info("%s(%d,%d), reuse rx mempool(%p) for port %d\n", __func__, mgr_idx, - idx, s->mbuf_mempool_hdr[i], i); + s->mbuf_mempool_hdr[i] = mt_if(impl, port)->rx_queues[queue_id].mbuf_pool; + info("%s(%d,%d), reuse rx mempool(%p) for port %d\n", __func__, mgr_idx, idx, + s->mbuf_mempool_hdr[i], i); } } @@ -2730,8 +2596,7 @@ static int tv_init_hw(struct mtl_main_impl *impl, pad_mempool = mt_sys_tx_mempool(impl, port); } for (int j = 0; j < ST20_PKT_TYPE_MAX; j++) { - if (!s->st20_pkt_info[j].number) - continue; + if (!s->st20_pkt_info[j].number) continue; info("%s(%d), type %d number %u size %u\n", __func__, idx, j, s->st20_pkt_info[j].number, s->st20_pkt_info[j].size); pad = mt_build_pad(impl, pad_mempool, port, RTE_ETHER_TYPE_IPV4, @@ -2752,13 +2617,11 @@ static int tv_mempool_free(struct st_tx_video_session_impl *s) { if (s->mbuf_mempool_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_chain); - if (ret >= 0) - s->mbuf_mempool_chain = NULL; + if (ret >= 0) s->mbuf_mempool_chain = NULL; } if (s->mbuf_mempool_copy_chain && !s->tx_mono_pool) { ret = mt_mempool_free(s->mbuf_mempool_copy_chain); - if (ret >= 0) - s->mbuf_mempool_copy_chain = NULL; + if (ret >= 0) s->mbuf_mempool_copy_chain = NULL; } for (int i = 0; i < MTL_SESSION_PORT_MAX; i++) { @@ -2767,8 +2630,7 @@ static int tv_mempool_free(struct st_tx_video_session_impl *s) { ret = mt_mempool_free(s->mbuf_mempool_hdr[i]); else ret = 0; - if (ret >= 0) - s->mbuf_mempool_hdr[i] = NULL; + if (ret >= 0) s->mbuf_mempool_hdr[i] = NULL; } } @@ -2780,8 +2642,7 @@ static bool tv_has_chain_buf(struct st_tx_video_session_impl *s) { int num_ports = ops->num_port; for (int port = 0; port < num_ports; port++) { - if (!s->eth_has_chain[port]) - return false; + if (!s->eth_has_chain[port]) return false; } /* all ports capable chain */ @@ -2794,8 +2655,7 @@ static bool tv_pkts_capable_chain(struct mtl_main_impl *impl, int num_ports = ops->num_port; /* true for rtp type */ - if (!st20_is_frame_type(ops->type)) - return true; + if (!st20_is_frame_type(ops->type)) return true; for (int port = 0; port < num_ports; port++) { enum mtl_port s_port = mt_port_logic2phy(s->port_maps, port); @@ -2803,9 +2663,10 @@ static bool tv_pkts_capable_chain(struct mtl_main_impl *impl, // max_buffer_nb += s->ring_count; /* at least two swap buffer */ if ((s->st20_total_pkts * (s->st20_frames_cnt - 1)) < max_buffer_nb) { - warn("%s(%d), max_buffer_nb %u on s_port %d too large, st20_total_pkts " - "%d\n", - __func__, s->idx, max_buffer_nb, s_port, s->st20_total_pkts); + warn( + "%s(%d), max_buffer_nb %u on s_port %d too large, st20_total_pkts " + "%d\n", + __func__, s->idx, max_buffer_nb, s_port, s->st20_total_pkts); return false; } } @@ -2855,24 +2716,21 @@ static int tv_mempool_init(struct mtl_main_impl *impl, s->mbuf_mempool_hdr[i], i); } else { n = mt_if_nb_tx_desc(impl, port) + s->ring_count; - if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) - n += ops->rtcp.buffer_size; - if (ops->type == ST20_TYPE_RTP_LEVEL) - n += ops->rtp_ring_size; + if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) n += ops->rtcp.buffer_size; + if (ops->type == ST20_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; if (mt_pmd_is_rdma_ud(impl, port)) /* Unlike DPDK, the RDMA UD backend faces delays in freeing mbufs after * send operations, requiring more mempool elements for now. */ n += 2048; if (s->mbuf_mempool_hdr[i]) { - warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, - i); + warn("%s(%d), use previous hdr mempool for port %d\n", __func__, idx, i); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_VIDEO_PREFIX, - mgr->idx, idx, i, s->recovery_idx); + snprintf(pool_name, 32, "%sM%dS%dP%d_HDR_%d", ST_TX_VIDEO_PREFIX, mgr->idx, idx, + i, s->recovery_idx); struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( - impl, pool_name, n, MT_MBUF_CACHE_SIZE, - sizeof(struct mt_muf_priv_data), hdr_room_size, s->socket_id); + impl, pool_name, n, MT_MBUF_CACHE_SIZE, sizeof(struct mt_muf_priv_data), + hdr_room_size, s->socket_id); if (!mbuf_pool) { tv_mempool_free(s); return -ENOMEM; @@ -2886,12 +2744,9 @@ static int tv_mempool_init(struct mtl_main_impl *impl, if (!s->tx_no_chain) { port = mt_port_logic2phy(s->port_maps, MTL_SESSION_PORT_P); n = mt_if_nb_tx_desc(impl, port) + s->ring_count; - if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) - n += ops->rtcp.buffer_size; - if (ops->type == ST20_TYPE_RTP_LEVEL) - n += ops->rtp_ring_size; - if (mt_pmd_is_rdma_ud(impl, port)) - n += 2048; + if (ops->flags & ST20_TX_FLAG_ENABLE_RTCP) n += ops->rtcp.buffer_size; + if (ops->type == ST20_TYPE_RTP_LEVEL) n += ops->rtp_ring_size; + if (mt_pmd_is_rdma_ud(impl, port)) n += 2048; if (s->tx_mono_pool) { s->mbuf_mempool_chain = mt_sys_tx_mempool(impl, port); @@ -2899,11 +2754,10 @@ static int tv_mempool_init(struct mtl_main_impl *impl, s->mbuf_mempool_chain); } else { char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_VIDEO_PREFIX, mgr->idx, - idx, s->recovery_idx); - struct rte_mempool *mbuf_pool = - mt_mempool_create_by_socket(impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, - chain_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%d_CHAIN_%d", ST_TX_VIDEO_PREFIX, mgr->idx, idx, + s->recovery_idx); + struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( + impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, chain_room_size, s->socket_id); if (!mbuf_pool) { tv_mempool_free(s); return -ENOMEM; @@ -2917,11 +2771,10 @@ static int tv_mempool_init(struct mtl_main_impl *impl, chain_room_size = s->st20_pkt_len; n /= s->st20_total_pkts / s->st20_pkt_info[ST20_PKT_TYPE_EXTRA].number; char pool_name[32]; - snprintf(pool_name, 32, "%sM%dS%d_COPY_%d", ST_TX_VIDEO_PREFIX, - mgr->idx, idx, s->recovery_idx); - struct rte_mempool *mbuf_pool = - mt_mempool_create_by_socket(impl, pool_name, n, MT_MBUF_CACHE_SIZE, - 0, chain_room_size, s->socket_id); + snprintf(pool_name, 32, "%sM%dS%d_COPY_%d", ST_TX_VIDEO_PREFIX, mgr->idx, idx, + s->recovery_idx); + struct rte_mempool *mbuf_pool = mt_mempool_create_by_socket( + impl, pool_name, n, MT_MBUF_CACHE_SIZE, 0, chain_room_size, s->socket_id); if (!mbuf_pool) { tv_mempool_free(s); return -ENOMEM; @@ -2942,8 +2795,7 @@ static int tv_init_packet_ring(struct st_tx_video_sessions_mgr *mgr, int mgr_idx = mgr->idx, idx = s->idx; snprintf(ring_name, 32, "%sM%dS%d_PKT", ST_TX_VIDEO_PREFIX, mgr_idx, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ ring = rte_ring_create(ring_name, count, s->socket_id, flags); if (!ring) { err("%s(%d,%d), rte_ring_create fail\n", __func__, mgr_idx, idx); @@ -2998,8 +2850,7 @@ static int tv_init_st22_frame(struct st_tx_video_session_impl *s, struct st22_tx_video_info *st22_info; st22_info = mt_rte_zmalloc_socket(sizeof(*st22_info), s->socket_id); - if (!st22_info) - return -ENOMEM; + if (!st22_info) return -ENOMEM; st22_info->get_next_frame = st22_frame_ops->get_next_frame; st22_info->notify_frame_done = st22_frame_ops->notify_frame_done; @@ -3009,8 +2860,7 @@ static int tv_init_st22_frame(struct st_tx_video_session_impl *s, return 0; } -static int tv_init_sw(struct mtl_main_impl *impl, - struct st_tx_video_sessions_mgr *mgr, +static int tv_init_sw(struct mtl_main_impl *impl, struct st_tx_video_sessions_mgr *mgr, struct st_tx_video_session_impl *s, struct st22_tx_ops *st22_frame_ops) { int idx = s->idx, ret; @@ -3048,10 +2898,8 @@ static int tv_init_sw(struct mtl_main_impl *impl, return 0; } -static int tv_init_pkt(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, - struct st20_tx_ops *ops, - struct st22_tx_ops *st22_frame_ops) { +static int tv_init_pkt(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, + struct st20_tx_ops *ops, struct st22_tx_ops *st22_frame_ops) { int idx = s->idx; uint32_t height = ops->interlaced ? (ops->height >> 1) : ops->height; enum st20_type type = ops->type; @@ -3071,8 +2919,7 @@ static int tv_init_pkt(struct mtl_main_impl *impl, uint32_t align = 128; max_data_len = max_data_len / align * align; s->st20_total_pkts = s->st20_frame_size / max_data_len; - if (s->st20_frame_size % max_data_len) - s->st20_total_pkts++; + if (s->st20_frame_size % max_data_len) s->st20_total_pkts++; s->st20_pkt_len = max_data_len; s->st20_pkt_size = s->st20_pkt_len + sizeof(struct st22_rfc9134_rtp_hdr); /* assume all are normal */ @@ -3087,14 +2934,12 @@ static int tv_init_pkt(struct mtl_main_impl *impl, s->st20_pkt_info[ST20_PKT_TYPE_NORMAL].number = s->st20_total_pkts; } else if (ops->packing == ST20_PACKING_GPM_SL) { /* calculate pkts in line */ - int bytes_in_pkt = - ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); + int bytes_in_pkt = ST_PKT_MAX_ETHER_BYTES - sizeof(struct st_rfc4175_video_hdr); s->st20_pkts_in_line = (s->st20_bytes_in_line / bytes_in_pkt) + 1; - int pixel_in_pkt = - (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; - s->st20_pkt_len = (pixel_in_pkt + s->st20_pg.coverage - 1) / - s->st20_pg.coverage * s->st20_pg.size; + int pixel_in_pkt = (ops->width + s->st20_pkts_in_line - 1) / s->st20_pkts_in_line; + s->st20_pkt_len = + (pixel_in_pkt + s->st20_pg.coverage - 1) / s->st20_pg.coverage * s->st20_pg.size; s->st20_pkt_size = s->st20_pkt_len + sizeof(struct st_rfc4175_video_hdr); s->st20_total_pkts = height * s->st20_pkts_in_line; @@ -3110,8 +2955,8 @@ static int tv_init_pkt(struct mtl_main_impl *impl, dbg("%s(%d), line_last_len: %d\n", __func__, idx, line_last_len); } else if (ops->packing == ST20_PACKING_BPM) { if (ST_VIDEO_BPM_SIZE % s->st20_pg.size) { - err("%s(%d), bpm size 1260 can not be divide by pg size %u\n", __func__, - idx, s->st20_pg.size); + err("%s(%d), bpm size 1260 can not be divide by pg size %u\n", __func__, idx, + s->st20_pg.size); return -EIO; } s->st20_pkt_len = ST_VIDEO_BPM_SIZE; @@ -3147,8 +2992,8 @@ static int tv_init_pkt(struct mtl_main_impl *impl, uint32_t align = s->st20_pg.size * 2; max_data_len = max_data_len / align * align; int pg_per_pkt = max_data_len / s->st20_pg.size; - s->st20_total_pkts = (ceil)((double)ops->width * height / - (s->st20_pg.coverage * pg_per_pkt)); + s->st20_total_pkts = + (ceil)((double)ops->width * height / (s->st20_pg.coverage * pg_per_pkt)); s->st20_pkt_len = pg_per_pkt * s->st20_pg.size; int last_pkt_len = s->st20_frame_size % s->st20_pkt_len; s->st20_pkt_size = s->st20_pkt_len + sizeof(struct st_rfc4175_video_hdr); @@ -3195,20 +3040,16 @@ static int tv_uinit(struct st_tx_video_session_impl *s) { return 0; } -static int tv_attach(struct mtl_main_impl *impl, - struct st_tx_video_sessions_mgr *mgr, - struct st_tx_video_session_impl *s, - struct st20_tx_ops *ops, enum mt_handle_type s_type, - struct st22_tx_ops *st22_frame_ops) { +static int tv_attach(struct mtl_main_impl *impl, struct st_tx_video_sessions_mgr *mgr, + struct st_tx_video_session_impl *s, struct st20_tx_ops *ops, + enum mt_handle_type s_type, struct st22_tx_ops *st22_frame_ops) { int ret; int idx = s->idx, num_port = ops->num_port; char *ports[MTL_SESSION_PORT_MAX]; - for (int i = 0; i < num_port; i++) - ports[i] = ops->port[i]; + for (int i = 0; i < num_port; i++) ports[i] = ops->port[i]; ret = mt_build_port_map(impl, ports, s->port_maps, num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = st20_get_pgroup(ops->fmt, &s->st20_pg); if (ret < 0) { @@ -3248,11 +3089,10 @@ static int tv_attach(struct mtl_main_impl *impl, s->st22_codestream_size = st22_frame_ops->framebuff_max_size; s->st20_frame_size = s->st22_codestream_size + s->st22_box_hdr_length; s->st20_fb_size = s->st20_frame_size; - info("%s(%d), st22 max codestream size %" PRId64 ", box len %u\n", __func__, - idx, s->st22_codestream_size, s->st22_box_hdr_length); + info("%s(%d), st22 max codestream size %" PRId64 ", box len %u\n", __func__, idx, + s->st22_codestream_size, s->st22_box_hdr_length); } else { - s->st20_frame_size = - ops->width * height * s->st20_pg.size / s->st20_pg.coverage; + s->st20_frame_size = ops->width * height * s->st20_pg.size / s->st20_pg.coverage; s->st20_fb_size = s->st20_linesize * height; } s->st20_frames_cnt = ops->framebuff_cnt; @@ -3284,14 +3124,12 @@ static int tv_attach(struct mtl_main_impl *impl, if (ops->name) { snprintf(s->ops_name, sizeof(s->ops_name), "%s", ops->name); } else { - snprintf(s->ops_name, sizeof(s->ops_name), "TX_VIDEO_M%dS%d", mgr->idx, - idx); + snprintf(s->ops_name, sizeof(s->ops_name), "TX_VIDEO_M%dS%d", mgr->idx, idx); } s->ops = *ops; s->s_type = s_type; for (int i = 0; i < num_port; i++) { - s->st20_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); if (mt_user_random_src_port(impl)) s->st20_src_port[i] = mt_random_port(s->st20_dst_port[i]); else @@ -3356,8 +3194,7 @@ static int tv_attach(struct mtl_main_impl *impl, for (int i = 0; i < num_port; i++) { ret = tv_init_hdr(impl, s, i); if (ret < 0) { - err("%s(%d), tx_session_init_hdr fail %d port %d\n", __func__, idx, ret, - i); + err("%s(%d), tx_session_init_hdr fail %d port %d\n", __func__, idx, ret, i); tv_uinit(s); return ret; } @@ -3387,8 +3224,7 @@ static int tv_attach(struct mtl_main_impl *impl, double sleep_ns = s->pacing.trs * 128; s->advice_sleep_us = sleep_ns / NS_PER_US; if (mt_user_tasklet_sleep(impl)) { - info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, - s->advice_sleep_us); + info("%s(%d), advice sleep us %" PRIu64 "\n", __func__, idx, s->advice_sleep_us); } s->stat_lines_not_ready = 0; @@ -3413,13 +3249,11 @@ static int tv_attach(struct mtl_main_impl *impl, tv_init_pacing_epoch(impl, s); s->active = true; - info("%s(%d), len %d(%d) total %d each line %d type %d flags 0x%x, %s\n", - __func__, idx, s->st20_pkt_len, s->st20_pkt_size, s->st20_total_pkts, - s->st20_pkts_in_line, ops->type, ops->flags, - ops->interlaced ? "interlace" : "progressive"); - info("%s(%d), w %u h %u fmt %s packing %d pt %d, pacing way: %s\n", __func__, - idx, ops->width, ops->height, st20_fmt_name(ops->fmt), ops->packing, - ops->payload_type, + info("%s(%d), len %d(%d) total %d each line %d type %d flags 0x%x, %s\n", __func__, idx, + s->st20_pkt_len, s->st20_pkt_size, s->st20_total_pkts, s->st20_pkts_in_line, + ops->type, ops->flags, ops->interlaced ? "interlace" : "progressive"); + info("%s(%d), w %u h %u fmt %s packing %d pt %d, pacing way: %s\n", __func__, idx, + ops->width, ops->height, st20_fmt_name(ops->fmt), ops->packing, ops->payload_type, st_tx_pacing_way_name(s->pacing_way[MTL_SESSION_PORT_P])); return 0; } @@ -3458,18 +3292,16 @@ static void tv_stat(struct st_tx_video_sessions_mgr *mgr, rte_atomic32_set(&s->stat_frame_cnt, 0); - notice("TX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d:%d inflight " - "%d:%d\n", - m_idx, idx, s->ops_name, framerate, frame_cnt, - s->stat_pkts_build[MTL_SESSION_PORT_P], - s->stat_pkts_build[MTL_SESSION_PORT_R], s->trs_inflight_cnt[0], - s->inflight_cnt[0]); - notice("TX_VIDEO_SESSION(%d,%d): throughput %f Mb/s: %f Mb/s, cpu busy %f\n", - m_idx, idx, - (double)s->stat_bytes_tx[MTL_SESSION_PORT_P] * 8 / time_sec / - MTL_STAT_M_UNIT, - (double)s->stat_bytes_tx[MTL_SESSION_PORT_R] * 8 / time_sec / - MTL_STAT_M_UNIT, + notice( + "TX_VIDEO_SESSION(%d,%d:%s): fps %f frames %d pkts %d:%d inflight " + "%d:%d\n", + m_idx, idx, s->ops_name, framerate, frame_cnt, + s->stat_pkts_build[MTL_SESSION_PORT_P], s->stat_pkts_build[MTL_SESSION_PORT_R], + s->trs_inflight_cnt[0], s->inflight_cnt[0]); + notice("TX_VIDEO_SESSION(%d,%d): throughput %f Mb/s: %f Mb/s, cpu busy %f\n", m_idx, + idx, + (double)s->stat_bytes_tx[MTL_SESSION_PORT_P] * 8 / time_sec / MTL_STAT_M_UNIT, + (double)s->stat_bytes_tx[MTL_SESSION_PORT_R] * 8 / time_sec / MTL_STAT_M_UNIT, s->stat_cpu_busy_score); s->stat_last_time = cur_time_ns; s->stat_pkts_build[MTL_SESSION_PORT_P] = 0; @@ -3493,18 +3325,17 @@ static void tv_stat(struct st_tx_video_sessions_mgr *mgr, s->stat_epoch_troffset_mismatch = 0; } if (s->stat_trans_troffset_mismatch) { - notice("TX_VIDEO_SESSION(%d,%d): transmitter mismatch troffset %u\n", m_idx, - idx, s->stat_trans_troffset_mismatch); + notice("TX_VIDEO_SESSION(%d,%d): transmitter mismatch troffset %u\n", m_idx, idx, + s->stat_trans_troffset_mismatch); s->stat_trans_troffset_mismatch = 0; } if (s->stat_trans_recalculate_warmup) { - notice("TX_VIDEO_SESSION(%d,%d): transmitter recalculate warmup %u\n", - m_idx, idx, s->stat_trans_recalculate_warmup); + notice("TX_VIDEO_SESSION(%d,%d): transmitter recalculate warmup %u\n", m_idx, idx, + s->stat_trans_recalculate_warmup); s->stat_trans_recalculate_warmup = 0; } if (s->stat_epoch_drop) { - notice("TX_VIDEO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, - s->stat_epoch_drop); + notice("TX_VIDEO_SESSION(%d,%d): epoch drop %u\n", m_idx, idx, s->stat_epoch_drop); s->stat_epoch_drop = 0; } if (s->stat_epoch_onward) { @@ -3523,13 +3354,13 @@ static void tv_stat(struct st_tx_video_sessions_mgr *mgr, s->stat_error_user_timestamp = 0; } if (s->stat_user_busy) { - notice("TX_VIDEO_SESSION(%d,%d): busy as no ready frame from user %u\n", - m_idx, idx, s->stat_user_busy); + notice("TX_VIDEO_SESSION(%d,%d): busy as no ready frame from user %u\n", m_idx, idx, + s->stat_user_busy); s->stat_user_busy = 0; } if (s->stat_lines_not_ready) { - notice("TX_VIDEO_SESSION(%d,%d): query new lines but app not ready %u\n", - m_idx, idx, s->stat_lines_not_ready); + notice("TX_VIDEO_SESSION(%d,%d): query new lines but app not ready %u\n", m_idx, idx, + s->stat_lines_not_ready); s->stat_lines_not_ready = 0; } if (s->stat_vsync_mismatch) { @@ -3538,15 +3369,14 @@ static void tv_stat(struct st_tx_video_sessions_mgr *mgr, s->stat_vsync_mismatch = 0; } if (s->stat_pkts_chain_realloc_fail) { - notice("TX_VIDEO_SESSION(%d,%d): chain pkt realloc fail cnt %u\n", m_idx, - idx, s->stat_pkts_chain_realloc_fail); + notice("TX_VIDEO_SESSION(%d,%d): chain pkt realloc fail cnt %u\n", m_idx, idx, + s->stat_pkts_chain_realloc_fail); notice("TX_VIDEO_SESSION(%d,%d): SERIOUS MEMORY ISSUE!\n", m_idx, idx); s->stat_pkts_chain_realloc_fail = 0; } if (frame_cnt <= 0) { - warn("TX_VIDEO_SESSION(%d,%d:%s): build ret %d, trs ret %d:%d\n", m_idx, - idx, s->ops_name, s->stat_build_ret_code, - s->stat_trs_ret_code[MTL_SESSION_PORT_P], + warn("TX_VIDEO_SESSION(%d,%d:%s): build ret %d, trs ret %d:%d\n", m_idx, idx, + s->ops_name, s->stat_build_ret_code, s->stat_trs_ret_code[MTL_SESSION_PORT_P], s->stat_trs_ret_code[MTL_SESSION_PORT_R]); } if (s->stat_user_meta_cnt || s->stat_user_meta_pkt_cnt) { @@ -3566,10 +3396,8 @@ static void tv_stat(struct st_tx_video_sessions_mgr *mgr, /* not reset unrecoverable_error */ } if (s->ops.interlaced) { - notice( - "TX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", - m_idx, idx, s->stat_interlace_first_field, - s->stat_interlace_second_field); + notice("TX_VIDEO_SESSION(%d,%d): interlace first field %u second field %u\n", m_idx, + idx, s->stat_interlace_first_field, s->stat_interlace_second_field); s->stat_interlace_first_field = 0; s->stat_interlace_second_field = 0; } @@ -3581,29 +3409,29 @@ static void tv_stat(struct st_tx_video_sessions_mgr *mgr, uint16_t framebuff_cnt = s->ops.framebuff_cnt; for (int i = 0; i < s->st20_frames_cnt; i++) { frame_info = &s->st20_frames[i]; - if (rte_atomic32_read(&frame_info->refcnt)) - frames_in_trans++; + if (rte_atomic32_read(&frame_info->refcnt)) frames_in_trans++; } if ((frames_in_trans > 2) || (frames_in_trans >= framebuff_cnt)) { - notice("TX_VIDEO_SESSION(%d,%d): %d frames are in trans, total %u\n", - m_idx, idx, frames_in_trans, framebuff_cnt); + notice("TX_VIDEO_SESSION(%d,%d): %d frames are in trans, total %u\n", m_idx, idx, + frames_in_trans, framebuff_cnt); } } struct mt_stat_u64 *stat_time = &s->stat_time; if (stat_time->cnt) { uint64_t avg_ns = stat_time->sum / stat_time->cnt; - notice("TX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " - "%.2fus\n", - m_idx, idx, (float)avg_ns / NS_PER_US, - (float)stat_time->max / NS_PER_US, - (float)stat_time->min / NS_PER_US); + notice( + "TX_VIDEO_SESSION(%d,%d): tasklet time avg %.2fus max %.2fus min " + "%.2fus\n", + m_idx, idx, (float)avg_ns / NS_PER_US, (float)stat_time->max / NS_PER_US, + (float)stat_time->min / NS_PER_US); mt_stat_u64_init(stat_time); } if (s->stat_max_next_frame_us > 8 || s->stat_max_notify_frame_us > 8) { - notice("TX_VIDEO_SESSION(%d,%d): get next frame max %uus, notify done max " - "%uus\n", - m_idx, idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); + notice( + "TX_VIDEO_SESSION(%d,%d): get next frame max %uus, notify done max " + "%uus\n", + m_idx, idx, s->stat_max_next_frame_us, s->stat_max_notify_frame_us); } s->stat_max_next_frame_us = 0; s->stat_max_notify_frame_us = 0; @@ -3621,9 +3449,9 @@ static int tv_init(struct st_tx_video_session_impl *s, int idx) { return 0; } -static struct st_tx_video_session_impl * -tv_mgr_attach(struct mtl_sch_impl *sch, struct st20_tx_ops *ops, - enum mt_handle_type s_type, struct st22_tx_ops *st22_frame_ops) { +static struct st_tx_video_session_impl *tv_mgr_attach( + struct mtl_sch_impl *sch, struct st20_tx_ops *ops, enum mt_handle_type s_type, + struct st22_tx_ops *st22_frame_ops) { struct st_tx_video_sessions_mgr *mgr = &sch->tx_video_mgr; int midx = mgr->idx; struct mtl_main_impl *impl = mgr->parent; @@ -3633,8 +3461,7 @@ tv_mgr_attach(struct mtl_sch_impl *sch, struct st20_tx_ops *ops, /* find one empty slot in the mgr */ for (int i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { - if (!tx_video_session_get_empty(mgr, i)) - continue; + if (!tx_video_session_get_empty(mgr, i)) continue; s = mt_rte_zmalloc_socket(sizeof(*s), socket); if (!s) { @@ -3687,8 +3514,7 @@ static int tv_mgr_detach(struct st_tx_video_sessions_mgr *mgr, return 0; } -static int tv_update_dst(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, +static int tv_update_dst(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, struct st_tx_dest_info *dst) { int ret = -EIO; int idx = s->idx, num_port = s->ops.num_port; @@ -3698,8 +3524,7 @@ static int tv_update_dst(struct mtl_main_impl *impl, for (int i = 0; i < num_port; i++) { memcpy(ops->dip_addr[i], dst->dip_addr[i], MTL_IP_ADDR_LEN); ops->udp_port[i] = dst->udp_port[i]; - s->st20_dst_port[i] = - (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); + s->st20_dst_port[i] = (ops->udp_port[i]) ? (ops->udp_port[i]) : (10000 + idx * 2); s->st20_dst_port[i] = (ops->udp_src_port[i]) ? (ops->udp_src_port[i]) : s->st20_dst_port[i]; @@ -3780,8 +3605,7 @@ static int tv_mgr_uinit(struct st_tx_video_sessions_mgr *mgr) { for (int i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { s = tx_video_session_get(mgr, i); - if (!s) - continue; + if (!s) continue; warn("%s(%d), session %d still attached\n", __func__, m_idx, i); tv_mgr_detach(mgr, s); @@ -3800,16 +3624,14 @@ static int tv_mgr_update(struct st_tx_video_sessions_mgr *mgr) { for (int i = 0; i < ST_SCH_MAX_TX_VIDEO_SESSIONS; i++) { s = mgr->sessions[i]; - if (!s) - continue; + if (!s) continue; max_idx = i + 1; sleep_us = RTE_MIN(s->advice_sleep_us, sleep_us); } - dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, - sleep_us, max_idx); + dbg("%s(%d), sleep us %" PRIu64 ", max_idx %d\n", __func__, mgr->idx, sleep_us, + max_idx); mgr->max_idx = max_idx; - if (mgr->tasklet) - mt_tasklet_set_sleep(mgr->tasklet, sleep_us); + if (mgr->tasklet) mt_tasklet_set_sleep(mgr->tasklet, sleep_us); return 0; } @@ -3819,8 +3641,7 @@ static int tv_sessions_stat(void *priv) { for (int j = 0; j < mgr->max_idx; j++) { s = tx_video_session_get_timeout(mgr, j, ST_SESSION_STAT_TIMEOUT_US); - if (!s) - continue; + if (!s) continue; tv_stat(mgr, s); tx_video_session_put(mgr, j); } @@ -3828,12 +3649,10 @@ static int tv_sessions_stat(void *priv) { return 0; } -int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { +int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { int ret, idx = sch->idx; - if (sch->tx_video_init) - return 0; + if (sch->tx_video_init) return 0; /* create tx video context */ struct st_tx_video_sessions_mgr *tx_video_mgr = &sch->tx_video_mgr; @@ -3843,8 +3662,7 @@ int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, return ret; } - ret = st_video_transmitter_init(impl, sch, tx_video_mgr, - &sch->video_transmitter); + ret = st_video_transmitter_init(impl, sch, tx_video_mgr, &sch->video_transmitter); if (ret < 0) { tv_mgr_uinit(tx_video_mgr); err("%s(%d), st_video_transmitter_init fail %d\n", __func__, idx, ret); @@ -3856,10 +3674,8 @@ int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, return 0; } -int st_tx_video_sessions_sch_uinit(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch) { - if (!sch->tx_video_init) - return 0; +int st_tx_video_sessions_sch_uinit(struct mtl_main_impl *impl, struct mtl_sch_impl *sch) { + if (!sch->tx_video_init) return 0; struct st_tx_video_sessions_mgr *tx_video_mgr = &sch->tx_video_mgr; @@ -3891,16 +3707,14 @@ static int tv_ops_check(struct st20_tx_ops *ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -3927,8 +3741,7 @@ static int tv_ops_check(struct st20_tx_ops *ops) { return -EINVAL; } if (ops->rtp_frame_total_pkts <= 0) { - err("%s, invalid rtp_frame_total_pkts %d\n", __func__, - ops->rtp_frame_total_pkts); + err("%s, invalid rtp_frame_total_pkts %d\n", __func__, ops->rtp_frame_total_pkts); return -EINVAL; } if (!mt_rtp_len_valid(ops->rtp_pkt_size)) { @@ -3962,16 +3775,14 @@ static int tv_st22_ops_check(struct st22_tx_ops *ops) { ip = ops->dip_addr[i]; ret = mt_ip_addr_check(ip); if (ret < 0) { - err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], - ip[3]); + err("%s(%d), invalid ip %d.%d.%d.%d\n", __func__, i, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } if (num_ports > 1) { if (0 == memcmp(ops->dip_addr[0], ops->dip_addr[1], MTL_IP_ADDR_LEN)) { - err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], - ip[3]); + err("%s, same %d.%d.%d.%d for both ip\n", __func__, ip[0], ip[1], ip[2], ip[3]); return -EINVAL; } } @@ -4028,8 +3839,7 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, if (!mt_pmd_is_dpdk_user(impl, port)) { err("%s(%d,%d), not dpdk user pmd, nothing to do\n", __func__, s_port, idx); - if (s->ops.notify_event) - s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); + if (s->ops.notify_event) s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); return 0; } @@ -4039,11 +3849,9 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, } /* clear all tx ring buffer */ - if (s->packet_ring) - mt_ring_dequeue_clean(s->packet_ring); + if (s->packet_ring) mt_ring_dequeue_clean(s->packet_ring); for (uint8_t i = 0; i < s->ops.num_port; i++) { - if (s->ring[i]) - mt_ring_dequeue_clean(s->ring[i]); + if (s->ring[i]) mt_ring_dequeue_clean(s->ring[i]); } /* clean the queue done mbuf */ mt_txq_done_cleanup(s->queue[s_port]); @@ -4062,8 +3870,7 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, err("%s(%d,%d), get new txq fail\n", __func__, s_port, idx); s->stat_unrecoverable_error++; s->active = false; /* mark current session to dead */ - if (s->ops.notify_event) - s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); + if (s->ops.notify_event) s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); return -EIO; } uint16_t queue_id = mt_txq_queue_id(s->queue[s_port]); @@ -4090,8 +3897,7 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, err("%s(%d,%d), reset mempool fail\n", __func__, s_port, idx); s->stat_unrecoverable_error++; s->active = false; /* mark current session to dead */ - if (s->ops.notify_event) - s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); + if (s->ops.notify_event) s->ops.notify_event(s->ops.priv, ST_EVENT_FATAL_ERROR, NULL); return ret; } @@ -4106,13 +3912,10 @@ int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, } /* only st20 frame mode has this callback */ -int st20_frame_tx_start(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, - enum mtl_session_port s_port, - struct st_frame_trans *frame) { +int st20_frame_tx_start(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, struct st_frame_trans *frame) { dbg("%s(%d,%d), start trans for frame %p\n", __func__, s->idx, port, frame); - if (!frame->user_meta_data_size) - return 0; + if (!frame->user_meta_data_size) return 0; enum mtl_port port = mt_port_logic2phy(s->port_maps, s_port); /* tx the user meta */ @@ -4151,8 +3954,7 @@ int st20_frame_tx_start(struct mtl_main_impl *impl, void *payload = &rtp[1]; mtl_memcpy(payload, frame->user_meta, frame->user_meta_data_size); - pkt->data_len = - sizeof(struct st_rfc4175_video_hdr) + frame->user_meta_data_size; + pkt->data_len = sizeof(struct st_rfc4175_video_hdr) + frame->user_meta_data_size; pkt->pkt_len = pkt->data_len; udp->dgram_len = htons(pkt->pkt_len - pkt->l2_len - pkt->l3_len); @@ -4195,8 +3997,8 @@ st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops *ops) { return NULL; } int height = ops->interlaced ? (ops->height >> 1) : ops->height; - ret = st20_get_bandwidth_bps(ops->width, height, ops->fmt, ops->fps, - ops->interlaced, &bps); + ret = st20_get_bandwidth_bps(ops->width, height, ops->fmt, ops->fps, ops->interlaced, + &bps); if (ret < 0) { err("%s, st20_get_bandwidth_bps fail\n", __func__); return NULL; @@ -4205,14 +4007,12 @@ st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops *ops) { quota_mbs *= ops->num_port; if (!mt_user_quota_active(impl)) { if (ST20_TYPE_RTP_LEVEL == ops->type) { - quota_mbs = - quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; + quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; } } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST20_TX_FLAG_FORCE_NUMA) { @@ -4226,8 +4026,8 @@ st20_tx_handle st20_tx_create(mtl_handle mt, struct st20_tx_ops *ops) { return NULL; } - sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, - MT_SCH_MASK_ALL, socket); + sch = + mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -4292,8 +4092,7 @@ int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, s_idx = s->idx; if (ext_frame->buf_len < s->st20_fb_size) { - err("%s(%d), ext framebuffer size %" PRIu64 - " can not hold frame, need %" PRIu64 "\n", + err("%s(%d), ext framebuffer size %" PRIu64 " can not hold frame, need %" PRIu64 "\n", __func__, s_idx, ext_frame->buf_len, s->st20_fb_size); return -EIO; } @@ -4304,21 +4103,19 @@ int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, } rte_iova_t iova_addr = ext_frame->buf_iova; if (iova_addr == MTL_BAD_IOVA || iova_addr == 0) { - err("%s(%d), invalid ext frame iova 0x%" PRIx64 "\n", __func__, s_idx, - iova_addr); + err("%s(%d), invalid ext frame iova 0x%" PRIx64 "\n", __func__, s_idx, iova_addr); return -EIO; } for (int i = 0; i < s->st20_frames_cnt; i++) { if (addr == s->st20_frames[i].addr) { - warn_once("%s(%d), buffer %p still in tansport!\n", __func__, s_idx, - addr); + warn_once("%s(%d), buffer %p still in tansport!\n", __func__, s_idx, addr); } } if (idx >= s->st20_frames_cnt) { - err("%s(%d), invalid idx %d, should be in range [0, %d]\n", __func__, s_idx, - idx, s->st20_frames_cnt); + err("%s(%d), invalid idx %d, should be in range [0, %d]\n", __func__, s_idx, idx, + s->st20_frames_cnt); return -EIO; } if (!s->st20_frames) { @@ -4328,8 +4125,7 @@ int st20_tx_set_ext_frame(st20_tx_handle handle, uint16_t idx, struct st_frame_trans *frame = &s->st20_frames[idx]; int refcnt = rte_atomic32_read(&frame->refcnt); if (refcnt) { - err("%s(%d), frame %d are not free, refcnt %d\n", __func__, s_idx, idx, - refcnt); + err("%s(%d), frame %d are not free, refcnt %d\n", __func__, s_idx, idx, refcnt); return -EINVAL; } if (!(frame->flags & ST_FT_FLAG_EXT)) { @@ -4417,9 +4213,8 @@ void *st20_tx_get_mbuf(st20_tx_handle handle, void **usrptr) { return NULL; } - struct rte_mempool *mp = s->tx_no_chain - ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] - : s->mbuf_mempool_chain; + struct rte_mempool *mp = + s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -4439,8 +4234,7 @@ int st20_tx_put_mbuf(st20_tx_handle handle, void *mbuf, uint16_t len) { int idx, ret; if (!mt_rtp_len_valid(len)) { - if (len) - err("%s, invalid len %d\n", __func__, len); + if (len) err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -4461,14 +4255,12 @@ int st20_tx_put_mbuf(st20_tx_handle handle, void *mbuf, uint16_t len) { } if (len > s->rtp_pkt_max_size) { - err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, - s->rtp_pkt_max_size); + err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, s->rtp_pkt_max_size); rte_pktmbuf_free(mbuf); return -EIO; } - if (s->tx_no_chain) - len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); @@ -4510,8 +4302,7 @@ int st20_tx_get_port_stats(st20_tx_handle handle, enum mtl_session_port port, return 0; } -int st20_tx_reset_port_stats(st20_tx_handle handle, - enum mtl_session_port port) { +int st20_tx_reset_port_stats(st20_tx_handle handle, enum mtl_session_port port) { struct st_tx_video_session_handle_impl *s_impl = handle; if (s_impl->type != MT_HANDLE_TX_VIDEO) { @@ -4550,12 +4341,10 @@ int st20_tx_free(st20_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_video_mgr_mutex); ret = tv_mgr_detach(&sch->tx_video_mgr, s); mt_pthread_mutex_unlock(&sch->tx_video_mgr_mutex); - if (ret < 0) - err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4569,8 +4358,7 @@ int st20_tx_free(st20_tx_handle handle) { return 0; } -int st20_tx_update_destination(st20_tx_handle handle, - struct st_tx_dest_info *dst) { +int st20_tx_update_destination(st20_tx_handle handle, struct st_tx_dest_info *dst) { struct st_tx_video_session_handle_impl *s_impl = handle; struct st_tx_video_session_impl *s; int idx, ret, sch_idx; @@ -4585,8 +4373,7 @@ int st20_tx_update_destination(st20_tx_handle handle, sch_idx = s_impl->sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tv_mgr_update_dst(&s_impl->sch->tx_video_mgr, s, dst); if (ret < 0) { @@ -4620,8 +4407,8 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops) { } if (ST22_TYPE_RTP_LEVEL == ops->type) { - ret = st22_rtp_bandwidth_bps(ops->rtp_frame_total_pkts, ops->rtp_pkt_size, - ops->fps, &bps); + ret = st22_rtp_bandwidth_bps(ops->rtp_frame_total_pkts, ops->rtp_pkt_size, ops->fps, + &bps); if (ret < 0) { err("%s, rtp_bandwidth_bps fail\n", __func__); return NULL; @@ -4629,8 +4416,7 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops) { quota_mbs = bps / (1000 * 1000); quota_mbs *= ops->num_port; if (!mt_user_quota_active(impl)) { - quota_mbs = - quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; + quota_mbs = quota_mbs * ST_QUOTA_TX1080P_PER_SCH / ST_QUOTA_TX1080P_RTP_PER_SCH; } } else { ret = st22_frame_bandwidth_bps(ops->framebuff_max_size, ops->fps, &bps); @@ -4643,8 +4429,7 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops) { } enum mtl_port port = mt_port_by_name(impl, ops->port[MTL_SESSION_PORT_P]); - if (port >= MTL_PORT_MAX) - return NULL; + if (port >= MTL_PORT_MAX) return NULL; int socket = mt_socket_id(impl, port); if (ops->flags & ST22_TX_FLAG_FORCE_NUMA) { @@ -4658,8 +4443,8 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops) { return NULL; } - sch = mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, - MT_SCH_MASK_ALL, socket); + sch = + mt_sch_get_by_socket(impl, quota_mbs, MT_SCH_TYPE_DEFAULT, MT_SCH_MASK_ALL, socket); if (!sch) { mt_rte_free(s_impl); err("%s, get sch fail\n", __func__); @@ -4699,18 +4484,15 @@ st22_tx_handle st22_tx_create(mtl_handle mt, struct st22_tx_ops *ops) { st20_ops.flags |= ST20_TX_FLAG_USER_R_MAC; } } - if (ops->flags & ST22_TX_FLAG_USER_PACING) - st20_ops.flags |= ST20_TX_FLAG_USER_PACING; + if (ops->flags & ST22_TX_FLAG_USER_PACING) st20_ops.flags |= ST20_TX_FLAG_USER_PACING; if (ops->flags & ST22_TX_FLAG_USER_TIMESTAMP) st20_ops.flags |= ST20_TX_FLAG_USER_TIMESTAMP; - if (ops->flags & ST22_TX_FLAG_ENABLE_VSYNC) - st20_ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; + if (ops->flags & ST22_TX_FLAG_ENABLE_VSYNC) st20_ops.flags |= ST20_TX_FLAG_ENABLE_VSYNC; if (ops->flags & ST22_TX_FLAG_ENABLE_RTCP) { st20_ops.flags |= ST20_TX_FLAG_ENABLE_RTCP; st20_ops.rtcp = ops->rtcp; } - if (ops->flags & ST22_TX_FLAG_DISABLE_BULK) - st20_ops.flags |= ST20_TX_FLAG_DISABLE_BULK; + if (ops->flags & ST22_TX_FLAG_DISABLE_BULK) st20_ops.flags |= ST20_TX_FLAG_DISABLE_BULK; st20_ops.pacing = ops->pacing; if (ST22_TYPE_RTP_LEVEL == ops->type) st20_ops.type = ST20_TYPE_RTP_LEVEL; @@ -4777,12 +4559,10 @@ int st22_tx_free(st22_tx_handle handle) { mt_pthread_mutex_lock(&sch->tx_video_mgr_mutex); ret = tv_mgr_detach(&sch->tx_video_mgr, s); mt_pthread_mutex_unlock(&sch->tx_video_mgr_mutex); - if (ret < 0) - err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d,%d), st_tx_sessions_mgr_detach fail\n", __func__, sch_idx, idx); ret = mt_sch_put(sch, s_impl->quota_mbs); - if (ret < 0) - err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); + if (ret < 0) err("%s(%d, %d), mt_sch_put fail\n", __func__, sch_idx, idx); mt_rte_free(s_impl); @@ -4796,8 +4576,7 @@ int st22_tx_free(st22_tx_handle handle) { return 0; } -int st22_tx_update_destination(st22_tx_handle handle, - struct st_tx_dest_info *dst) { +int st22_tx_update_destination(st22_tx_handle handle, struct st_tx_dest_info *dst) { struct st22_tx_video_session_handle_impl *s_impl = handle; struct st_tx_video_session_impl *s; int idx, ret, sch_idx; @@ -4812,8 +4591,7 @@ int st22_tx_update_destination(st22_tx_handle handle, sch_idx = s_impl->sch->idx; ret = st_tx_dest_info_check(dst, s->ops.num_port); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = tv_mgr_update_dst(&s_impl->sch->tx_video_mgr, s, dst); if (ret < 0) { @@ -4850,9 +4628,8 @@ void *st22_tx_get_mbuf(st22_tx_handle handle, void **usrptr) { return NULL; } - struct rte_mempool *mp = s->tx_no_chain - ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] - : s->mbuf_mempool_chain; + struct rte_mempool *mp = + s->tx_no_chain ? s->mbuf_mempool_hdr[MTL_SESSION_PORT_P] : s->mbuf_mempool_chain; pkt = rte_pktmbuf_alloc(mp); if (!pkt) { dbg("%s(%d), pkt alloc fail\n", __func__, idx); @@ -4872,8 +4649,7 @@ int st22_tx_put_mbuf(st22_tx_handle handle, void *mbuf, uint16_t len) { int idx, ret; if (!mt_rtp_len_valid(len)) { - if (len) - err("%s, invalid len %d\n", __func__, len); + if (len) err("%s, invalid len %d\n", __func__, len); rte_pktmbuf_free(mbuf); return -EIO; } @@ -4894,14 +4670,12 @@ int st22_tx_put_mbuf(st22_tx_handle handle, void *mbuf, uint16_t len) { } if (len > s->rtp_pkt_max_size) { - err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, - s->rtp_pkt_max_size); + err("%s(%d), invalid len %u, allowed %u\n", __func__, idx, len, s->rtp_pkt_max_size); rte_pktmbuf_free(mbuf); return -EIO; } - if (s->tx_no_chain) - len += sizeof(struct mt_udp_hdr); + if (s->tx_no_chain) len += sizeof(struct mt_udp_hdr); pkt->data_len = pkt->pkt_len = len; ret = rte_ring_sp_enqueue(packet_ring, (void *)pkt); diff --git a/lib/src/st2110/st_tx_video_session.h b/lib/src/st2110/st_tx_video_session.h index a306a54fa..0a9c85f86 100644 --- a/lib/src/st2110/st_tx_video_session.h +++ b/lib/src/st2110/st_tx_video_session.h @@ -12,48 +12,40 @@ #define ST_TX_VIDEO_RTCP_BURST_SIZE (32) #define ST_TX_VIDEO_RTCP_RING_SIZE (1024) -int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch); +int st_tx_video_sessions_sch_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch); -int st_tx_video_sessions_sch_uinit(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch); +int st_tx_video_sessions_sch_uinit(struct mtl_main_impl *impl, struct mtl_sch_impl *sch); /* call tx_video_session_put always if get successfully */ -static inline struct st_tx_video_session_impl * -tx_video_session_get(struct st_tx_video_sessions_mgr *mgr, int idx) { +static inline struct st_tx_video_session_impl *tx_video_session_get( + struct st_tx_video_sessions_mgr *mgr, int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_tx_video_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_video_session_put always if get successfully */ -static inline struct st_tx_video_session_impl * -tx_video_session_try_get(struct st_tx_video_sessions_mgr *mgr, int idx) { - if (!rte_spinlock_trylock(&mgr->mutex[idx])) - return NULL; +static inline struct st_tx_video_session_impl *tx_video_session_try_get( + struct st_tx_video_sessions_mgr *mgr, int idx) { + if (!rte_spinlock_trylock(&mgr->mutex[idx])) return NULL; struct st_tx_video_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_video_session_put always if get successfully */ -static inline struct st_tx_video_session_impl * -tx_video_session_get_timeout(struct st_tx_video_sessions_mgr *mgr, int idx, - int timeout_us) { - if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) - return NULL; +static inline struct st_tx_video_session_impl *tx_video_session_get_timeout( + struct st_tx_video_sessions_mgr *mgr, int idx, int timeout_us) { + if (!mt_spinlock_lock_timeout(mgr->parent, &mgr->mutex[idx], timeout_us)) return NULL; struct st_tx_video_session_impl *s = mgr->sessions[idx]; - if (!s) - rte_spinlock_unlock(&mgr->mutex[idx]); + if (!s) rte_spinlock_unlock(&mgr->mutex[idx]); return s; } /* call tx_video_session_put always if get successfully */ -static inline bool -tx_video_session_get_empty(struct st_tx_video_sessions_mgr *mgr, int idx) { +static inline bool tx_video_session_get_empty(struct st_tx_video_sessions_mgr *mgr, + int idx) { rte_spinlock_lock(&mgr->mutex[idx]); struct st_tx_video_session_impl *s = mgr->sessions[idx]; if (s) { @@ -64,8 +56,7 @@ tx_video_session_get_empty(struct st_tx_video_sessions_mgr *mgr, int idx) { } } -static inline void tx_video_session_put(struct st_tx_video_sessions_mgr *mgr, - int idx) { +static inline void tx_video_session_put(struct st_tx_video_sessions_mgr *mgr, int idx) { rte_spinlock_unlock(&mgr->mutex[idx]); } @@ -73,16 +64,13 @@ void tx_video_session_cal_cpu_busy(struct mtl_sch_impl *sch, struct st_tx_video_session_impl *s); void tx_video_session_clear_cpu_busy(struct st_tx_video_session_impl *s); -static inline bool -tx_video_session_is_cpu_busy(struct st_tx_video_session_impl *s) { - if (s->cpu_busy_score > 95.0) - return true; +static inline bool tx_video_session_is_cpu_busy(struct st_tx_video_session_impl *s) { + if (s->cpu_busy_score > 95.0) return true; return false; } -static inline float -tx_video_session_get_cpu_busy(struct st_tx_video_session_impl *s) { +static inline float tx_video_session_get_cpu_busy(struct st_tx_video_session_impl *s) { return s->cpu_busy_score; } diff --git a/lib/src/st2110/st_video_transmitter.c b/lib/src/st2110/st_video_transmitter.c index 7c330e081..0e050bb0b 100644 --- a/lib/src/st2110/st_video_transmitter.c +++ b/lib/src/st2110/st_video_transmitter.c @@ -31,8 +31,7 @@ static int video_trs_tasklet_stop(void *priv) { static uint16_t video_trs_burst_fail(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, - enum mtl_session_port s_port, - uint16_t nb_pkts) { + enum mtl_session_port s_port, uint16_t nb_pkts) { uint64_t cur_tsc = mt_get_tsc(impl); uint64_t fail_duration = cur_tsc - s->last_burst_succ_time_tsc[s_port]; @@ -50,26 +49,22 @@ static uint16_t video_trs_burst_fail(struct mtl_main_impl *impl, static uint16_t video_trs_burst_pad(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, enum mtl_session_port s_port, - struct rte_mbuf **tx_pkts, - uint16_t nb_pkts) { + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { uint16_t tx = mt_txq_burst(s->queue[s_port], tx_pkts, nb_pkts); - if (!tx) - return video_trs_burst_fail(impl, s, s_port, nb_pkts); + if (!tx) return video_trs_burst_fail(impl, s, s_port, nb_pkts); return tx; } /* for normal pkts, pad should call the video_trs_burst_pad */ static uint16_t video_trs_burst(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, - enum mtl_session_port s_port, - struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { - if (s->rtcp_tx[s_port]) - mt_mbuf_refcnt_inc_bulk(tx_pkts, nb_pkts); + enum mtl_session_port s_port, struct rte_mbuf **tx_pkts, + uint16_t nb_pkts) { + if (s->rtcp_tx[s_port]) mt_mbuf_refcnt_inc_bulk(tx_pkts, nb_pkts); uint16_t tx = mt_txq_burst(s->queue[s_port], tx_pkts, nb_pkts); s->stat_pkts_burst += tx; if (!tx) { - if (s->rtcp_tx[s_port]) - rte_pktmbuf_free_bulk(tx_pkts, nb_pkts); + if (s->rtcp_tx[s_port]) rte_pktmbuf_free_bulk(tx_pkts, nb_pkts); return video_trs_burst_fail(impl, s, s_port, nb_pkts); } @@ -81,8 +76,7 @@ static uint16_t video_trs_burst(struct mtl_main_impl *impl, int pkt_idx = st_tx_mbuf_get_idx(tx_pkts[0]); if (0 == pkt_idx) { struct st_frame_trans *frame = st_tx_mbuf_get_priv(tx_pkts[0]); - if (frame) - st20_frame_tx_start(impl, s, s_port, frame); + if (frame) st20_frame_tx_start(impl, s, s_port, frame); } for (uint16_t i = 0; i < tx; i++) { @@ -140,8 +134,7 @@ static int video_trs_rl_warm_up(struct mtl_main_impl *impl, if (delta_pkts > i) { warm_pkts -= (delta_pkts - i); s->stat_trans_recalculate_warmup++; - dbg("%s(%d), mismatch delta_pkts %d at %d\n", __func__, s->idx, - delta_pkts, i); + dbg("%s(%d), mismatch delta_pkts %d at %d\n", __func__, s->idx, delta_pkts, i); } } @@ -150,8 +143,8 @@ static int video_trs_rl_warm_up(struct mtl_main_impl *impl, static int video_burst_packet(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, - enum mtl_session_port s_port, - struct rte_mbuf **pkts, int bulk, bool use_two) { + enum mtl_session_port s_port, struct rte_mbuf **pkts, + int bulk, bool use_two) { struct st_tx_video_pacing *pacing = &s->pacing; int tx = video_trs_burst(impl, s, s_port, &pkts[0], bulk); int pkt_idx = st_tx_mbuf_get_idx(pkts[0]); @@ -164,25 +157,20 @@ static int video_burst_packet(struct mtl_main_impl *impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) - s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; } else { s->trs_inflight_num2[s_port] = remaining; s->trs_inflight_idx2[s_port] = 0; s->trs_inflight_cnt2[s_port]++; - for (i = 0; i < remaining; i++) - s->trs_inflight2[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) s->trs_inflight2[s_port][i] = pkts[tx + i]; } } /* check if it need insert padding packet */ - if (fmodf(pkt_idx + 1 + pacing->pad_interval / 2, pacing->pad_interval) < - bulk) { + if (fmodf(pkt_idx + 1 + pacing->pad_interval / 2, pacing->pad_interval) < bulk) { rte_mbuf_refcnt_update(s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); - tx = video_trs_burst_pad(impl, s, s_port, - &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); - if (tx < 1) - s->trs_pad_inflight_num[s_port]++; + tx = video_trs_burst_pad(impl, s, s_port, &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); + if (tx < 1) s->trs_pad_inflight_num[s_port]++; } return 0; @@ -190,8 +178,7 @@ static int video_burst_packet(struct mtl_main_impl *impl, static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, - enum mtl_session_port s_port, - int *ret_status) { + enum mtl_session_port s_port, int *ret_status) { unsigned int bulk = s->bulk; struct rte_ring *ring = s->ring[s_port]; int idx = s->idx; @@ -200,10 +187,9 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, /* check if any inflight pkts in transmitter inflight 2 */ if (s->trs_inflight_num2[s_port] > 0) { - tx = - video_trs_burst(impl, s, s_port, - &s->trs_inflight2[s_port][s->trs_inflight_idx2[s_port]], - s->trs_inflight_num2[s_port]); + tx = video_trs_burst(impl, s, s_port, + &s->trs_inflight2[s_port][s->trs_inflight_idx2[s_port]], + s->trs_inflight_num2[s_port]); s->trs_inflight_num2[s_port] -= tx; s->trs_inflight_idx2[s_port] += tx; if (tx > 0) { @@ -225,8 +211,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", - __func__, idx, cur_tsc, target_tsc); + err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } video_trs_rl_warm_up(impl, s, s_port); @@ -237,8 +223,7 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, if (s->trs_pad_inflight_num[s_port] > 0) { dbg("%s(%d), inflight padding pkts %d\n", __func__, idx, s->trs_pad_inflight_num[s_port]); - tx = video_trs_burst_pad(impl, s, s_port, - &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); + tx = video_trs_burst_pad(impl, s, s_port, &s->pad[s_port][ST20_PKT_TYPE_NORMAL], 1); s->trs_pad_inflight_num[s_port] -= tx; if (tx > 0) { return MTL_TASKLET_HAS_PENDING; @@ -280,8 +265,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, */ } } - dbg("%s(%d), pkt_idx %u valid_bulk %d ts %" PRIu64 "\n", __func__, idx, - pkt_idx, valid_bulk, st_tx_mbuf_get_tsc(pkts[0])); + dbg("%s(%d), pkt_idx %u valid_bulk %d ts %" PRIu64 "\n", __func__, idx, pkt_idx, + valid_bulk, st_tx_mbuf_get_tsc(pkts[0])); /* builder always build bulk pkts per enqueue, pkts after dummy are all dummy */ @@ -302,8 +287,8 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, } uint64_t target_tsc = st_tx_mbuf_get_tsc(pkts[valid_bulk]); uint64_t target_ptp = st_tx_mbuf_get_ptp(pkts[valid_bulk]); - dbg("%s(%d), first pkt, ts cur %" PRIu64 " target %" PRIu64 "\n", __func__, - idx, cur_tsc, target_tsc); + dbg("%s(%d), first pkt, ts cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); if (likely(cur_tsc < target_tsc || s->trs_inflight_num2[s_port])) { unsigned int i; uint64_t delta = target_tsc - cur_tsc; @@ -321,8 +306,7 @@ static int _video_trs_rl_tasklet(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc for first pkt cur %" PRIu64 " target %" PRIu64 - "\n", + err("%s(%d), invalid tsc for first pkt cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, cur_tsc, target_tsc); } } else { @@ -361,8 +345,7 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, enum mtl_session_port s_port) { unsigned int bulk = s->bulk; - if (s->pacing_way[s_port] == ST21_TX_PACING_WAY_BE) - bulk = 1; + if (s->pacing_way[s_port] == ST21_TX_PACING_WAY_BE) bulk = 1; struct rte_ring *ring = s->ring[s_port]; int idx = s->idx, tx; unsigned int n; @@ -379,8 +362,8 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", - __func__, idx, cur_tsc, target_tsc); + err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } s->trs_target_tsc[s_port] = 0; @@ -439,14 +422,13 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl *impl, s->trs_inflight_num[s_port] = valid_bulk; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < valid_bulk; i++) - s->trs_inflight[s_port][i] = pkts[i]; + for (i = 0; i < valid_bulk; i++) s->trs_inflight[s_port][i] = pkts[i]; s->stat_trs_ret_code[s_port] = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", - __func__, idx, cur_tsc, target_tsc); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_tsc, target_tsc); } } } @@ -460,8 +442,7 @@ static int video_trs_tsc_tasklet(struct mtl_main_impl *impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) - s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; } return MTL_TASKLET_HAS_PENDING; @@ -529,8 +510,7 @@ static int video_trs_launch_time_tasklet(struct mtl_main_impl *impl, target_ptp = st_tx_mbuf_get_ptp(pkts[i]); /* Put tx timestamp into transmit descriptor */ pkts[i]->ol_flags |= inf->tx_launch_time_flag; - *RTE_MBUF_DYNFIELD(pkts[i], inf->tx_dynfield_offset, uint64_t *) = - target_ptp; + *RTE_MBUF_DYNFIELD(pkts[i], inf->tx_dynfield_offset, uint64_t *) = target_ptp; } tx = video_trs_burst(impl, s, s_port, &pkts[0], valid_bulk); @@ -541,8 +521,7 @@ static int video_trs_launch_time_tasklet(struct mtl_main_impl *impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) - s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; } } @@ -575,8 +554,8 @@ static int video_trs_ptp_tasklet(struct mtl_main_impl *impl, return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", - __func__, idx, cur_ptp, target_ptp); + err("%s(%d), invalid trs tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_ptp, target_ptp); } } s->trs_target_tsc[s_port] = 0; @@ -634,14 +613,13 @@ static int video_trs_ptp_tasklet(struct mtl_main_impl *impl, s->trs_inflight_num[s_port] = valid_bulk; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < valid_bulk; i++) - s->trs_inflight[s_port][i] = pkts[i]; + for (i = 0; i < valid_bulk; i++) s->trs_inflight[s_port][i] = pkts[i]; s->stat_trs_ret_code[s_port] = -STI_TSCTRS_TARGET_TSC_NOT_REACH; return delta < mt_sch_schedule_ns(impl) ? MTL_TASKLET_HAS_PENDING : MTL_TASKLET_ALL_DONE; } else { - err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, - idx, cur_ptp, target_ptp); + err("%s(%d), invalid tsc cur %" PRIu64 " target %" PRIu64 "\n", __func__, idx, + cur_ptp, target_ptp); } } @@ -654,8 +632,7 @@ static int video_trs_ptp_tasklet(struct mtl_main_impl *impl, s->trs_inflight_num[s_port] = remaining; s->trs_inflight_idx[s_port] = 0; s->trs_inflight_cnt[s_port]++; - for (i = 0; i < remaining; i++) - s->trs_inflight[s_port][i] = pkts[tx + i]; + for (i = 0; i < remaining; i++) s->trs_inflight[s_port][i] = pkts[tx + i]; } return MTL_TASKLET_HAS_PENDING; @@ -671,12 +648,10 @@ static int video_trs_tasklet_handler(void *priv) { for (sidx = 0; sidx < mgr->max_idx; sidx++) { s = tx_video_session_try_get(mgr, sidx); - if (!s) - continue; + if (!s) continue; for (s_port = 0; s_port < s->ops.num_port; s_port++) { - if (!s->queue[s_port]) - continue; + if (!s->queue[s_port]) continue; pending += s->pacing_tasklet_func[s_port](impl, s, s_port); } tx_video_session_put(mgr, sidx); @@ -690,29 +665,28 @@ int st_video_resolve_pacing_tasklet(struct st_tx_video_session_impl *s, int idx = s->idx; switch (s->pacing_way[port]) { - case ST21_TX_PACING_WAY_RL: - s->pacing_tasklet_func[port] = video_trs_rl_tasklet; - break; - case ST21_TX_PACING_WAY_TSN: - s->pacing_tasklet_func[port] = video_trs_launch_time_tasklet; - break; - case ST21_TX_PACING_WAY_TSC: - case ST21_TX_PACING_WAY_BE: - case ST21_TX_PACING_WAY_TSC_NARROW: - s->pacing_tasklet_func[port] = video_trs_tsc_tasklet; - break; - case ST21_TX_PACING_WAY_PTP: - s->pacing_tasklet_func[port] = video_trs_ptp_tasklet; - break; - default: - err("%s(%d), unknow pacing %d\n", __func__, idx, s->pacing_way[port]); - return -EIO; + case ST21_TX_PACING_WAY_RL: + s->pacing_tasklet_func[port] = video_trs_rl_tasklet; + break; + case ST21_TX_PACING_WAY_TSN: + s->pacing_tasklet_func[port] = video_trs_launch_time_tasklet; + break; + case ST21_TX_PACING_WAY_TSC: + case ST21_TX_PACING_WAY_BE: + case ST21_TX_PACING_WAY_TSC_NARROW: + s->pacing_tasklet_func[port] = video_trs_tsc_tasklet; + break; + case ST21_TX_PACING_WAY_PTP: + s->pacing_tasklet_func[port] = video_trs_ptp_tasklet; + break; + default: + err("%s(%d), unknow pacing %d\n", __func__, idx, s->pacing_way[port]); + return -EIO; } return 0; } -int st_video_transmitter_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, +int st_video_transmitter_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, struct st_tx_video_sessions_mgr *mgr, struct st_video_transmitter_impl *trs) { int idx = sch->idx; diff --git a/lib/src/st2110/st_video_transmitter.h b/lib/src/st2110/st_video_transmitter.h index 84179b7c3..3bc94e388 100644 --- a/lib/src/st2110/st_video_transmitter.h +++ b/lib/src/st2110/st_video_transmitter.h @@ -7,8 +7,7 @@ #include "st_main.h" -int st_video_transmitter_init(struct mtl_main_impl *impl, - struct mtl_sch_impl *sch, +int st_video_transmitter_init(struct mtl_main_impl *impl, struct mtl_sch_impl *sch, struct st_tx_video_sessions_mgr *mgr, struct st_video_transmitter_impl *trs); int st_video_transmitter_uinit(struct st_video_transmitter_impl *trs); @@ -16,10 +15,8 @@ int st_video_transmitter_uinit(struct st_video_transmitter_impl *trs); int st_video_resolve_pacing_tasklet(struct st_tx_video_session_impl *s, enum mtl_session_port port); -int st20_frame_tx_start(struct mtl_main_impl *impl, - struct st_tx_video_session_impl *s, - enum mtl_session_port s_port, - struct st_frame_trans *frame); +int st20_frame_tx_start(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, + enum mtl_session_port s_port, struct st_frame_trans *frame); int st20_tx_queue_fatal_error(struct mtl_main_impl *impl, struct st_tx_video_session_impl *s, diff --git a/lib/src/udp/udp_main.c b/lib/src/udp/udp_main.c index 80b734503..8c2c75992 100644 --- a/lib/src/udp/udp_main.c +++ b/lib/src/udp/udp_main.c @@ -77,40 +77,34 @@ static int udp_verify_addr(const struct sockaddr_in *addr, socklen_t addrlen) { return 0; } -static int udp_verify_bind_addr(struct mudp_impl *s, - const struct sockaddr_in *addr, +static int udp_verify_bind_addr(struct mudp_impl *s, const struct sockaddr_in *addr, socklen_t addrlen) { int idx = s->idx; int ret; ret = udp_verify_addr(addr, addrlen); - if (ret < 0) - return ret; + if (ret < 0) return ret; - if (!udp_get_flag(s, MUDP_BIND_ADDRESS_CHECK)) - return 0; + if (!udp_get_flag(s, MUDP_BIND_ADDRESS_CHECK)) return 0; /* check if our IP or any IP */ if (addr->sin_addr.s_addr == INADDR_ANY) return 0; /* kernel mcast bind use INADDR_ANY */ /* should we support INADDR_LOOPBACK? */ - if (memcmp(&addr->sin_addr.s_addr, mt_sip_addr(s->parent, s->port), - MTL_IP_ADDR_LEN)) { + if (memcmp(&addr->sin_addr.s_addr, mt_sip_addr(s->parent, s->port), MTL_IP_ADDR_LEN)) { uint8_t *ip = (uint8_t *)&addr->sin_addr.s_addr; - err("%s(%d), invalid bind ip %u.%u.%u.%u\n", __func__, idx, ip[0], ip[1], - ip[2], ip[3]); + err("%s(%d), invalid bind ip %u.%u.%u.%u\n", __func__, idx, ip[0], ip[1], ip[2], + ip[3]); MUDP_ERR_RET(EINVAL); } return 0; } -static int udp_verify_sendto_args(size_t len, int flags, - const struct sockaddr_in *addr, +static int udp_verify_sendto_args(size_t len, int flags, const struct sockaddr_in *addr, socklen_t addrlen) { int ret = udp_verify_addr(addr, addrlen); - if (ret < 0) - return ret; + if (ret < 0) return ret; if ((len <= 0) || (len > MUDP_MAX_GSO_BYTES)) { err("%s, invalid len %" PRIu64 "\n", __func__, len); @@ -124,8 +118,7 @@ static int udp_verify_sendto_args(size_t len, int flags, return 0; } -static int udp_verify_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, - int timeout) { +static int udp_verify_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout) { MTL_MAY_UNUSED(timeout); if (!fds) { @@ -149,8 +142,7 @@ static int udp_verify_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, static int udp_build_tx_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, struct rte_mbuf *pkt, const void *buf, size_t len, - const struct sockaddr_in *addr_in, - int arp_timeout_ms) { + const struct sockaddr_in *addr_in, int arp_timeout_ms) { struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); struct rte_ether_hdr *eth = &hdr->eth; struct rte_ipv4_hdr *ipv4 = &hdr->ipv4; @@ -176,8 +168,8 @@ static int udp_build_tx_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, ret = mt_dst_ip_mac(impl, dip, d_addr, port, arp_timeout_ms); if (ret < 0) { if (arp_timeout_ms) /* log only if not zero timeout */ - err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, - ret, dip[0], dip[1], dip[2], dip[3]); + err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, ret, dip[0], + dip[1], dip[2], dip[3]); s->stat_pkt_arp_fail++; MUDP_ERR_RET(EIO); } @@ -220,27 +212,26 @@ static ssize_t udp_msg_len(const struct msghdr *msg) { static int udp_cmsg_handle(struct mudp_impl *s, const struct msghdr *msg) { struct cmsghdr *cmsg = CMSG_FIRSTHDR(msg); - if (!cmsg) - return 0; + if (!cmsg) return 0; int idx = s->idx; switch (cmsg->cmsg_level) { - case SOL_UDP: - if (cmsg->cmsg_type == UDP_SEGMENT) { - if (cmsg->cmsg_len == CMSG_LEN(sizeof(uint16_t))) { - uint16_t *p_val = (uint16_t *)CMSG_DATA(cmsg); - uint16_t val = *p_val; - dbg("%s(%d), UDP_SEGMENT val %u\n", __func__, idx, val); - s->gso_segment_sz = val; - } else { - err("%s(%d), unknow cmsg_len %" PRId64 " for UDP_SEGMENT\n", __func__, - idx, cmsg->cmsg_len); - MUDP_ERR_RET(EINVAL); + case SOL_UDP: + if (cmsg->cmsg_type == UDP_SEGMENT) { + if (cmsg->cmsg_len == CMSG_LEN(sizeof(uint16_t))) { + uint16_t *p_val = (uint16_t *)CMSG_DATA(cmsg); + uint16_t val = *p_val; + dbg("%s(%d), UDP_SEGMENT val %u\n", __func__, idx, val); + s->gso_segment_sz = val; + } else { + err("%s(%d), unknow cmsg_len %" PRId64 " for UDP_SEGMENT\n", __func__, idx, + cmsg->cmsg_len); + MUDP_ERR_RET(EINVAL); + } } - } - break; - default: - break; + break; + default: + break; } return 0; @@ -249,8 +240,8 @@ static int udp_cmsg_handle(struct mudp_impl *s, const struct msghdr *msg) { static int udp_build_tx_msg_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, struct rte_mbuf **pkts, unsigned int pkts_nb, const struct msghdr *msg, - const struct sockaddr_in *addr_in, - int arp_timeout_ms, size_t sz_per_pkt) { + const struct sockaddr_in *addr_in, int arp_timeout_ms, + size_t sz_per_pkt) { enum mtl_port port = s->port; int idx = s->idx; int ret; @@ -264,8 +255,8 @@ static int udp_build_tx_msg_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, ret = mt_dst_ip_mac(impl, dip, &d_addr, port, arp_timeout_ms); if (ret < 0) { if (arp_timeout_ms) /* log only if not zero timeout */ - err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, - ret, dip[0], dip[1], dip[2], dip[3]); + err("%s(%d), mt_dst_ip_mac fail %d for %u.%u.%u.%u\n", __func__, idx, ret, dip[0], + dip[1], dip[2], dip[3]); s->stat_pkt_arp_fail++; MUDP_ERR_RET(EIO); } @@ -292,8 +283,7 @@ static int udp_build_tx_msg_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, udp->dst_port = addr_in->sin_port; /* pkt mbuf */ mt_mbuf_init_ipv4(pkt); - pkt->packet_type = - RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP; + pkt->packet_type = RTE_PTYPE_L2_ETHER | RTE_PTYPE_L3_IPV4 | RTE_PTYPE_L4_UDP; payloads[i] = &udp[1]; s->stat_pkt_build++; @@ -308,8 +298,7 @@ static int udp_build_tx_msg_pkt(struct mtl_main_impl *impl, struct mudp_impl *s, void *iov = msg->msg_iov[i].iov_base; while (iov_len > 0) { if (pd_len <= 0) { - err("%s(%d), no available payload, pkts_nb %u\n", __func__, idx, - pkts_nb); + err("%s(%d), no available payload, pkts_nb %u\n", __func__, idx, pkts_nb); MUDP_ERR_RET(EIO); } size_t clen = RTE_MIN(pd_len, iov_len); @@ -486,9 +475,8 @@ static int udp_init_txq(struct mtl_main_impl *impl, struct mudp_impl *s, if (!s->tx_pool) { char pool_name[32]; snprintf(pool_name, 32, "%sP%dQ%uS%d_TX", MUDP_PREFIX, port, queue_id, idx); - struct rte_mempool *pool = - mt_mempool_create(impl, port, pool_name, s->element_nb, - MT_MBUF_CACHE_SIZE, 0, s->element_size); + struct rte_mempool *pool = mt_mempool_create(impl, port, pool_name, s->element_nb, + MT_MBUF_CACHE_SIZE, 0, s->element_size); if (!pool) { err("%s(%d), mempool create fail\n", __func__, idx); udp_uinit_txq(impl, s); @@ -546,19 +534,18 @@ static int udp_stat_dump(void *priv) { rte_ring_count(mur_client_ring(s->rxq))); } if (s->stat_rx_msg_cnt) { - notice("%s(%d,%d), rx_msg %u succ %u timeout %u again %u\n", __func__, port, - idx, s->stat_rx_msg_cnt, s->stat_rx_msg_succ_cnt, - s->stat_rx_msg_timeout_cnt, s->stat_rx_msg_again_cnt); + notice("%s(%d,%d), rx_msg %u succ %u timeout %u again %u\n", __func__, port, idx, + s->stat_rx_msg_cnt, s->stat_rx_msg_succ_cnt, s->stat_rx_msg_timeout_cnt, + s->stat_rx_msg_again_cnt); s->stat_rx_msg_cnt = 0; s->stat_rx_msg_succ_cnt = 0; s->stat_rx_msg_timeout_cnt = 0; s->stat_rx_msg_again_cnt = 0; } if (s->stat_poll_cnt) { - notice("%s(%d,%d), poll %u succ %u timeout %u 0-timeout %u query_ret %u\n", - __func__, port, idx, s->stat_poll_cnt, s->stat_poll_succ_cnt, - s->stat_poll_timeout_cnt, s->stat_poll_zero_timeout_cnt, - s->stat_poll_query_ret_cnt); + notice("%s(%d,%d), poll %u succ %u timeout %u 0-timeout %u query_ret %u\n", __func__, + port, idx, s->stat_poll_cnt, s->stat_poll_succ_cnt, s->stat_poll_timeout_cnt, + s->stat_poll_zero_timeout_cnt, s->stat_poll_query_ret_cnt); s->stat_poll_cnt = 0; s->stat_poll_succ_cnt = 0; s->stat_poll_timeout_cnt = 0; @@ -571,23 +558,20 @@ static int udp_stat_dump(void *priv) { s->stat_pkt_dequeue = 0; s->stat_pkt_deliver = 0; } - if (s->rxq) - mur_client_dump(s->rxq); + if (s->rxq) mur_client_dump(s->rxq); if (s->stat_pkt_build) { - notice("%s(%d,%d), pkt build %u tx %u\n", __func__, port, idx, - s->stat_pkt_build, s->stat_pkt_tx); + notice("%s(%d,%d), pkt build %u tx %u\n", __func__, port, idx, s->stat_pkt_build, + s->stat_pkt_tx); s->stat_pkt_build = 0; s->stat_pkt_tx = 0; } if (s->stat_tx_gso_count) { - notice("%s(%d,%d), tx gso count %u\n", __func__, port, idx, - s->stat_tx_gso_count); + notice("%s(%d,%d), tx gso count %u\n", __func__, port, idx, s->stat_tx_gso_count); s->stat_tx_gso_count = 0; } if (s->stat_pkt_arp_fail) { - warn("%s(%d,%d), pkt %u arp fail\n", __func__, port, idx, - s->stat_pkt_arp_fail); + warn("%s(%d,%d), pkt %u arp fail\n", __func__, port, idx, s->stat_pkt_arp_fail); s->stat_pkt_arp_fail = 0; } if (s->stat_tx_retry) { @@ -600,8 +584,7 @@ static int udp_stat_dump(void *priv) { return 0; } -static int udp_get_sndbuf(struct mudp_impl *s, void *optval, - socklen_t *optlen) { +static int udp_get_sndbuf(struct mudp_impl *s, void *optval, socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); @@ -614,8 +597,7 @@ static int udp_get_sndbuf(struct mudp_impl *s, void *optval, return 0; } -static int udp_get_rcvbuf(struct mudp_impl *s, void *optval, - socklen_t *optlen) { +static int udp_get_rcvbuf(struct mudp_impl *s, void *optval, socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); @@ -628,8 +610,7 @@ static int udp_get_rcvbuf(struct mudp_impl *s, void *optval, return 0; } -static int udp_set_sndbuf(struct mudp_impl *s, const void *optval, - socklen_t optlen) { +static int udp_set_sndbuf(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); uint32_t sndbuf_sz; @@ -645,8 +626,7 @@ static int udp_set_sndbuf(struct mudp_impl *s, const void *optval, return 0; } -static int udp_set_rcvbuf(struct mudp_impl *s, const void *optval, - socklen_t optlen) { +static int udp_set_rcvbuf(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(uint32_t); uint32_t rcvbuf_sz; @@ -662,8 +642,7 @@ static int udp_set_rcvbuf(struct mudp_impl *s, const void *optval, return 0; } -static int udp_get_rcvtimeo(struct mudp_impl *s, void *optval, - socklen_t *optlen) { +static int udp_get_rcvtimeo(struct mudp_impl *s, void *optval, socklen_t *optlen) { int idx = s->idx; struct timeval *tv; size_t sz = sizeof(*tv); @@ -681,8 +660,7 @@ static int udp_get_rcvtimeo(struct mudp_impl *s, void *optval, return 0; } -static int udp_set_cookie(struct mudp_impl *s, const void *optval, - socklen_t optlen) { +static int udp_set_cookie(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(uint64_t); uint64_t cookie; @@ -698,8 +676,7 @@ static int udp_set_cookie(struct mudp_impl *s, const void *optval, return 0; } -static int udp_get_cookie(struct mudp_impl *s, void *optval, - socklen_t *optlen) { +static int udp_get_cookie(struct mudp_impl *s, void *optval, socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(uint64_t); @@ -712,8 +689,7 @@ static int udp_get_cookie(struct mudp_impl *s, void *optval, return 0; } -static int udp_set_rcvtimeo(struct mudp_impl *s, const void *optval, - socklen_t optlen) { +static int udp_set_rcvtimeo(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; const struct timeval *tv; size_t sz = sizeof(*tv); @@ -730,8 +706,7 @@ static int udp_set_rcvtimeo(struct mudp_impl *s, const void *optval, return 0; } -static int udp_set_reuse_port(struct mudp_impl *s, const void *optval, - socklen_t optlen) { +static int udp_set_reuse_port(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(int); int reuse_port; @@ -747,8 +722,7 @@ static int udp_set_reuse_port(struct mudp_impl *s, const void *optval, return 0; } -static int udp_get_reuse_port(struct mudp_impl *s, void *optval, - socklen_t *optlen) { +static int udp_get_reuse_port(struct mudp_impl *s, void *optval, socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(int); @@ -761,8 +735,7 @@ static int udp_get_reuse_port(struct mudp_impl *s, void *optval, return 0; } -static int udp_set_reuse_addr(struct mudp_impl *s, const void *optval, - socklen_t optlen) { +static int udp_set_reuse_addr(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; size_t sz = sizeof(int); int reuse_addr; @@ -778,8 +751,7 @@ static int udp_set_reuse_addr(struct mudp_impl *s, const void *optval, return 0; } -static int udp_get_reuse_addr(struct mudp_impl *s, void *optval, - socklen_t *optlen) { +static int udp_get_reuse_addr(struct mudp_impl *s, void *optval, socklen_t *optlen) { int idx = s->idx; size_t sz = sizeof(int); @@ -800,8 +772,8 @@ static int udp_init_mcast(struct mtl_main_impl *impl, struct mudp_impl *s) { err("%s(%d), mcast addrs already init\n", __func__, idx); MUDP_ERR_RET(EIO); } - s->mcast_addrs = mt_rte_zmalloc_socket( - sizeof(*s->mcast_addrs) * s->mcast_addrs_nb, mt_socket_id(impl, port)); + s->mcast_addrs = mt_rte_zmalloc_socket(sizeof(*s->mcast_addrs) * s->mcast_addrs_nb, + mt_socket_id(impl, port)); if (!s->mcast_addrs) { err("%s(%d), mcast addrs malloc fail\n", __func__, idx); MUDP_ERR_RET(ENOMEM); @@ -832,8 +804,7 @@ static int udp_uinit_mcast(struct mudp_impl *s) { return 0; } -static int udp_add_membership(struct mudp_impl *s, const void *optval, - socklen_t optlen) { +static int udp_add_membership(struct mudp_impl *s, const void *optval, socklen_t optlen) { int idx = s->idx; struct mtl_main_impl *impl = s->parent; enum mtl_port port = s->port; @@ -871,8 +842,8 @@ static int udp_add_membership(struct mudp_impl *s, const void *optval, if (!s->mcast_addrs[i]) { s->mcast_addrs[i] = group_addr; added = true; - info("%s(%d), add %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3], i); + info("%s(%d), add %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], ip[2], ip[3], + i); break; } } @@ -913,8 +884,8 @@ static int udp_drop_membership(struct mudp_impl *s, const void *optval, if (s->mcast_addrs[i] == group_addr) { found = true; s->mcast_addrs[i] = 0; - info("%s(%d), drop %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], - ip[2], ip[3], i); + info("%s(%d), drop %d.%d.%d.%d on %d\n", __func__, port, ip[0], ip[1], ip[2], ip[3], + i); break; } } @@ -928,9 +899,8 @@ static int udp_drop_membership(struct mudp_impl *s, const void *optval, return 0; } -static ssize_t udp_rx_dequeue(struct mudp_impl *s, void *buf, size_t len, - int flags, struct sockaddr *src_addr, - socklen_t *addrlen) { +static ssize_t udp_rx_dequeue(struct mudp_impl *s, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen) { int idx = s->idx; int ret; ssize_t copied = 0; @@ -939,8 +909,7 @@ static ssize_t udp_rx_dequeue(struct mudp_impl *s, void *buf, size_t len, /* dequeue pkt from rx ring */ ret = rte_ring_sc_dequeue(mur_client_ring(s->rxq), (void **)&pkt); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->stat_pkt_dequeue++; struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); @@ -962,10 +931,9 @@ static ssize_t udp_rx_dequeue(struct mudp_impl *s, void *buf, size_t len, addr_in.sin_family = AF_INET; addr_in.sin_port = udp->src_port; addr_in.sin_addr.s_addr = ipv4->src_addr; - dbg("%s(%d), dst port %u src port %u\n", __func__, idx, - ntohs(udp->dst_port), ntohs(udp->src_port)); - rte_memcpy((void *)src_addr, &addr_in, - RTE_MIN(*addrlen, sizeof(addr_in))); + dbg("%s(%d), dst port %u src port %u\n", __func__, idx, ntohs(udp->dst_port), + ntohs(udp->src_port)); + rte_memcpy((void *)src_addr, &addr_in, RTE_MIN(*addrlen, sizeof(addr_in))); } } else { err("%s(%d), payload len %" PRIu64 " buf len %" PRIu64 "\n", __func__, idx, @@ -979,17 +947,16 @@ static ssize_t udp_rx_dequeue(struct mudp_impl *s, void *buf, size_t len, static ssize_t udp_rx_ret_timeout(struct mudp_impl *s, int flags) { MTL_MAY_UNUSED(flags); if (s->rx_timeout_us) { - dbg("%s(%d), timeout to %d ms, flags %d\n", __func__, s->idx, - s->rx_timeout_us, flags); + dbg("%s(%d), timeout to %d ms, flags %d\n", __func__, s->idx, s->rx_timeout_us, + flags); MUDP_ERR_RET(ETIMEDOUT); } else { MUDP_ERR_RET(EAGAIN); } } -static ssize_t udp_recvfrom(struct mudp_impl *s, void *buf, size_t len, - int flags, struct sockaddr *src_addr, - socklen_t *addrlen) { +static ssize_t udp_recvfrom(struct mudp_impl *s, void *buf, size_t len, int flags, + struct sockaddr *src_addr, socklen_t *addrlen) { struct mtl_main_impl *impl = s->parent; ssize_t copied = 0; uint16_t rx; @@ -998,8 +965,7 @@ static ssize_t udp_recvfrom(struct mudp_impl *s, void *buf, size_t len, dequeue: /* dequeue pkt from rx ring */ copied = udp_rx_dequeue(s, buf, len, flags, src_addr, addrlen); - if (copied > 0) - return copied; + if (copied > 0) return copied; rx = mur_client_rx(s->rxq); if (rx) { /* dequeue again as rx succ */ @@ -1023,8 +989,7 @@ static ssize_t udp_recvfrom(struct mudp_impl *s, void *buf, size_t len, return udp_rx_ret_timeout(s, flags); } -static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, - int flags) { +static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, int flags) { int idx = s->idx; int ret; ssize_t copied = 0; @@ -1033,8 +998,7 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, /* dequeue pkt from rx ring */ ret = rte_ring_sc_dequeue(mur_client_ring(s->rxq), (void **)&pkt); - if (ret < 0) - return ret; + if (ret < 0) return ret; s->stat_pkt_dequeue++; struct mt_udp_hdr *hdr = rte_pktmbuf_mtod(pkt, struct mt_udp_hdr *); @@ -1052,10 +1016,9 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, addr_in.sin_family = AF_INET; addr_in.sin_port = udp->src_port; addr_in.sin_addr.s_addr = ipv4->src_addr; - dbg("%s(%d), dst port %u src port %u\n", __func__, idx, - ntohs(udp->dst_port), ntohs(udp->src_port)); - rte_memcpy(msg->msg_name, &addr_in, - RTE_MIN(msg->msg_namelen, sizeof(addr_in))); + dbg("%s(%d), dst port %u src port %u\n", __func__, idx, ntohs(udp->dst_port), + ntohs(udp->src_port)); + rte_memcpy(msg->msg_name, &addr_in, RTE_MIN(msg->msg_namelen, sizeof(addr_in))); } if (msg->msg_control) { /* Ancillary data */ @@ -1063,8 +1026,7 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, memset(&chdr, 0, sizeof(chdr)); chdr.cmsg_len = sizeof(chdr); chdr.cmsg_level = ipv4->next_proto_id; - rte_memcpy(msg->msg_control, &chdr, - RTE_MIN(msg->msg_controllen, sizeof(chdr))); + rte_memcpy(msg->msg_control, &chdr, RTE_MIN(msg->msg_controllen, sizeof(chdr))); } if (msg->msg_iov) { /* Vector of data */ @@ -1074,8 +1036,7 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, payload_len -= clen; payload += clen; copied += clen; - if (payload_len <= 0) - break; + if (payload_len <= 0) break; } s->stat_pkt_deliver++; } @@ -1084,8 +1045,7 @@ static ssize_t udp_rx_msg_dequeue(struct mudp_impl *s, struct msghdr *msg, warn("%s(%d), %" PRIu64 " bytes not copied \n", __func__, idx, payload_len); rte_pktmbuf_free(pkt); - dbg("%s(%d), copied %" PRId64 " bytes, flags %d\n", __func__, idx, copied, - flags); + dbg("%s(%d), copied %" PRId64 " bytes, flags %d\n", __func__, idx, copied, flags); return copied; } @@ -1129,8 +1089,7 @@ static ssize_t udp_recvmsg(struct mudp_impl *s, struct msghdr *msg, int flags) { return udp_rx_ret_timeout(s, flags); } -static int udp_fallback_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, - int timeout) { +static int udp_fallback_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout) { struct mudp_impl *s; struct pollfd p_fds[nfds]; int ret; @@ -1232,8 +1191,7 @@ static int udp_poll(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout, int ms = (mt_get_tsc(impl) - start_ts) / NS_PER_MS; if (((ms < timeout) || (timeout < 0)) && udp_alive(s)) { if (s->rx_poll_sleep_us) { - mur_client_timedwait(s->rxq, (timeout - ms) * US_PER_MS, - s->rx_poll_sleep_us); + mur_client_timedwait(s->rxq, (timeout - ms) * US_PER_MS, s->rx_poll_sleep_us); } goto rx_poll; } @@ -1257,8 +1215,7 @@ mudp_handle mudp_socket_port(mtl_handle mt, int domain, int type, int protocol, mudp_idx++; ret = mudp_verify_socket_args(domain, type, protocol); - if (ret < 0) - return NULL; + if (ret < 0) return NULL; /* make sure tsc is ready, mudp_recvfrom will use tsc */ mt_wait_tsc_stable(impl); @@ -1376,15 +1333,13 @@ int mudp_bind(mudp_handle ut, const struct sockaddr *addr, socklen_t addrlen) { if (udp_is_fallback(s)) { ret = bind(s->fallback_fd, addr, addrlen); uint8_t *ip = (uint8_t *)&addr_in->sin_addr.s_addr; - info("%s(%d), fallback fd %d bind ip %u.%u.%u.%u port %u ret %d\n", - __func__, idx, s->fallback_fd, ip[0], ip[1], ip[2], ip[3], - htons(addr_in->sin_port), ret); + info("%s(%d), fallback fd %d bind ip %u.%u.%u.%u port %u ret %d\n", __func__, idx, + s->fallback_fd, ip[0], ip[1], ip[2], ip[3], htons(addr_in->sin_port), ret); return ret; } ret = udp_verify_bind_addr(s, addr_in, addrlen); - if (ret < 0) - return ret; + if (ret < 0) return ret; /* uinit rx if any */ udp_uinit_rxq(s); @@ -1440,12 +1395,10 @@ ssize_t mudp_sendto(mudp_handle ut, const void *buf, size_t len, int flags, size_t sz_per_pkt = s->gso_segment_sz; unsigned int pkts_nb = len / sz_per_pkt; - if (len % sz_per_pkt) - pkts_nb++; + if (len % sz_per_pkt) pkts_nb++; struct rte_mbuf *pkts[pkts_nb]; dbg("%s(%d), pkts_nb %u\n", __func__, idx, pkts_nb); - if (pkts_nb > 1) - s->stat_tx_gso_count++; + if (pkts_nb > 1) s->stat_tx_gso_count++; ret = rte_pktmbuf_alloc_bulk(s->tx_pool, pkts, pkts_nb); if (ret < 0) { @@ -1493,8 +1446,7 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr *msg, int flags) { int ret; #ifndef WINDOWSENV - if (udp_is_fallback(s)) - return sendmsg(s->fallback_fd, msg, flags); + if (udp_is_fallback(s)) return sendmsg(s->fallback_fd, msg, flags); #endif const struct sockaddr_in *addr_in = (struct sockaddr_in *)msg->msg_name; @@ -1520,8 +1472,7 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr *msg, int flags) { size_t sz_per_pkt = s->gso_segment_sz; size_t total_len = udp_msg_len(msg); unsigned int pkts_nb = total_len / sz_per_pkt; - if (total_len % sz_per_pkt) - pkts_nb++; + if (total_len % sz_per_pkt) pkts_nb++; /* Ensure pkts_nb is greater than 0 */ if (pkts_nb == 0) { err("%s(%d): pkts_nb is 0\n", __func__, idx); @@ -1529,10 +1480,8 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr *msg, int flags) { } struct rte_mbuf *pkts[pkts_nb]; - dbg("%s(%d), pkts_nb %u total_len %" PRId64 "\n", __func__, idx, pkts_nb, - total_len); - if (pkts_nb > 1) - s->stat_tx_gso_count++; + dbg("%s(%d), pkts_nb %u total_len %" PRId64 "\n", __func__, idx, pkts_nb, total_len); + if (pkts_nb > 1) s->stat_tx_gso_count++; ret = rte_pktmbuf_alloc_bulk(s->tx_pool, pkts, pkts_nb); if (ret < 0) { @@ -1540,8 +1489,8 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr *msg, int flags) { MUDP_ERR_RET(ENOMEM); } - ret = udp_build_tx_msg_pkt(impl, s, pkts, pkts_nb, msg, addr_in, - arp_timeout_ms, sz_per_pkt); + ret = udp_build_tx_msg_pkt(impl, s, pkts, pkts_nb, msg, addr_in, arp_timeout_ms, + sz_per_pkt); if (ret < 0) { rte_pktmbuf_free_bulk(pkts, pkts_nb); if (arp_timeout_ms) { @@ -1570,8 +1519,7 @@ ssize_t mudp_sendmsg(mudp_handle ut, const struct msghdr *msg, int flags) { int mudp_poll_query(struct mudp_pollfd *fds, mudp_nfds_t nfds, int timeout, int (*query)(void *priv), void *priv) { int ret = udp_verify_poll(fds, nfds, timeout); - if (ret < 0) - return ret; + if (ret < 0) return ret; struct mudp_impl *s = fds[0].fd; @@ -1619,8 +1567,7 @@ ssize_t mudp_recvmsg(mudp_handle ut, struct msghdr *msg, int flags) { int ret; #ifndef WINDOWSENV - if (udp_is_fallback(s)) - return recvmsg(s->fallback_fd, msg, flags); + if (udp_is_fallback(s)) return recvmsg(s->fallback_fd, msg, flags); #endif /* init rxq if not */ @@ -1644,31 +1591,30 @@ int mudp_getsockopt(mudp_handle ut, int level, int optname, void *optval, return getsockopt(s->fallback_fd, level, optname, optval, optlen); switch (level) { - case SOL_SOCKET: { - switch (optname) { - case SO_SNDBUF: - case SO_SNDBUFFORCE: - return udp_get_sndbuf(s, optval, optlen); - case SO_RCVBUF: - case SO_RCVBUFFORCE: - return udp_get_rcvbuf(s, optval, optlen); - case SO_RCVTIMEO: - return udp_get_rcvtimeo(s, optval, optlen); - case SO_COOKIE: - return udp_get_cookie(s, optval, optlen); - case SO_REUSEPORT: - return udp_get_reuse_port(s, optval, optlen); - case SO_REUSEADDR: - return udp_get_reuse_addr(s, optval, optlen); + case SOL_SOCKET: { + switch (optname) { + case SO_SNDBUF: + case SO_SNDBUFFORCE: + return udp_get_sndbuf(s, optval, optlen); + case SO_RCVBUF: + case SO_RCVBUFFORCE: + return udp_get_rcvbuf(s, optval, optlen); + case SO_RCVTIMEO: + return udp_get_rcvtimeo(s, optval, optlen); + case SO_COOKIE: + return udp_get_cookie(s, optval, optlen); + case SO_REUSEPORT: + return udp_get_reuse_port(s, optval, optlen); + case SO_REUSEADDR: + return udp_get_reuse_addr(s, optval, optlen); + default: + err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, optname); + MUDP_ERR_RET(EINVAL); + } + } default: - err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, - optname); + err("%s(%d), unknown level %d\n", __func__, idx, level); MUDP_ERR_RET(EINVAL); - } - } - default: - err("%s(%d), unknown level %d\n", __func__, idx, level); - MUDP_ERR_RET(EINVAL); } return 0; @@ -1683,57 +1629,55 @@ int mudp_setsockopt(mudp_handle ut, int level, int optname, const void *optval, return setsockopt(s->fallback_fd, level, optname, optval, optlen); switch (level) { - case SOL_SOCKET: { - switch (optname) { - case SO_SNDBUF: - case SO_SNDBUFFORCE: - return udp_set_sndbuf(s, optval, optlen); - case SO_RCVBUF: - case SO_RCVBUFFORCE: - return udp_set_rcvbuf(s, optval, optlen); - case SO_RCVTIMEO: - return udp_set_rcvtimeo(s, optval, optlen); - case SO_COOKIE: - return udp_set_cookie(s, optval, optlen); - case SO_REUSEADDR: /* skip now */ - return udp_set_reuse_addr(s, optval, optlen); - case SO_REUSEPORT: - return udp_set_reuse_port(s, optval, optlen); - default: - err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, - optname); - MUDP_ERR_RET(EINVAL); + case SOL_SOCKET: { + switch (optname) { + case SO_SNDBUF: + case SO_SNDBUFFORCE: + return udp_set_sndbuf(s, optval, optlen); + case SO_RCVBUF: + case SO_RCVBUFFORCE: + return udp_set_rcvbuf(s, optval, optlen); + case SO_RCVTIMEO: + return udp_set_rcvtimeo(s, optval, optlen); + case SO_COOKIE: + return udp_set_cookie(s, optval, optlen); + case SO_REUSEADDR: /* skip now */ + return udp_set_reuse_addr(s, optval, optlen); + case SO_REUSEPORT: + return udp_set_reuse_port(s, optval, optlen); + default: + err("%s(%d), unknown optname %d for SOL_SOCKET\n", __func__, idx, optname); + MUDP_ERR_RET(EINVAL); + } } - } - case IPPROTO_IP: { - switch (optname) { - case IP_ADD_MEMBERSHIP: - return udp_add_membership(s, optval, optlen); - case IP_DROP_MEMBERSHIP: - return udp_drop_membership(s, optval, optlen); - case IP_PKTINFO: - info("%s(%d), skip IP_PKTINFO\n", __func__, idx); - return 0; + case IPPROTO_IP: { + switch (optname) { + case IP_ADD_MEMBERSHIP: + return udp_add_membership(s, optval, optlen); + case IP_DROP_MEMBERSHIP: + return udp_drop_membership(s, optval, optlen); + case IP_PKTINFO: + info("%s(%d), skip IP_PKTINFO\n", __func__, idx); + return 0; #ifdef IP_RECVTOS - case IP_RECVTOS: - info("%s(%d), skip IP_RECVTOS\n", __func__, idx); - return 0; + case IP_RECVTOS: + info("%s(%d), skip IP_RECVTOS\n", __func__, idx); + return 0; #endif - case IP_MTU_DISCOVER: - info("%s(%d), skip IP_MTU_DISCOVER\n", __func__, idx); - return 0; - case IP_TOS: - dbg("%s(%d), skip IP_TOS\n", __func__, idx); - return 0; + case IP_MTU_DISCOVER: + info("%s(%d), skip IP_MTU_DISCOVER\n", __func__, idx); + return 0; + case IP_TOS: + dbg("%s(%d), skip IP_TOS\n", __func__, idx); + return 0; + default: + err("%s(%d), unknown optname %d for IPPROTO_IP\n", __func__, idx, optname); + MUDP_ERR_RET(EINVAL); + } + } default: - err("%s(%d), unknown optname %d for IPPROTO_IP\n", __func__, idx, - optname); + err("%s(%d), unknown level %d\n", __func__, idx, level); MUDP_ERR_RET(EINVAL); - } - } - default: - err("%s(%d), unknown level %d\n", __func__, idx, level); - MUDP_ERR_RET(EINVAL); } return 0; @@ -1745,17 +1689,16 @@ int mudp_ioctl(mudp_handle ut, unsigned long cmd, va_list args) { MTL_MAY_UNUSED(args); #ifndef WINDOWSENV - if (udp_is_fallback(s)) - return ioctl(s->fallback_fd, cmd, args); + if (udp_is_fallback(s)) return ioctl(s->fallback_fd, cmd, args); #endif switch (cmd) { - case FIONBIO: - info("%s(%d), skip FIONBIO now\n", __func__, idx); - break; - default: - err("%s(%d), unknown cmd %d\n", __func__, idx, (int)cmd); - MUDP_ERR_RET(EINVAL); + case FIONBIO: + info("%s(%d), skip FIONBIO now\n", __func__, idx); + break; + default: + err("%s(%d), unknown cmd %d\n", __func__, idx, (int)cmd); + MUDP_ERR_RET(EINVAL); } return 0; @@ -1772,8 +1715,8 @@ int mudp_set_tx_mac(mudp_handle ut, uint8_t mac[MTL_MAC_ADDR_LEN]) { rte_memcpy(s->user_mac, mac, MTL_MAC_ADDR_LEN); udp_set_flag(s, MUDP_TX_USER_MAC); - info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", __func__, - idx, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + info("%s(%d), mac: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n", __func__, idx, mac[0], + mac[1], mac[2], mac[3], mac[4], mac[5]); return 0; } @@ -1939,8 +1882,7 @@ int mudp_set_wake_thresh_count(mudp_handle ut, unsigned int count) { } s->wake_thresh_count = count; - if (s->rxq) - mur_client_set_wake_thresh(s->rxq, count); + if (s->rxq) mur_client_set_wake_thresh(s->rxq, count); return 0; } @@ -1954,8 +1896,7 @@ int mudp_set_wake_timeout(mudp_handle ut, unsigned int us) { } s->wake_timeout_us = us; - if (s->rxq) - mur_client_set_wake_timeout(s->rxq, us); + if (s->rxq) mur_client_set_wake_timeout(s->rxq, us); return 0; } @@ -2000,8 +1941,7 @@ int mudp_tx_valid_ip(mudp_handle ut, uint8_t dip[MTL_IP_ADDR_LEN]) { if (mt_is_multicast_ip(dip)) { return 0; - } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), - mt_sip_netmask(impl, port))) { + } else if (mt_is_lan_ip(dip, mt_sip_addr(impl, port), mt_sip_netmask(impl, port))) { return 0; } else if (mt_ip_to_u32(mt_sip_gateway(impl, port))) { return 0; @@ -2010,8 +1950,7 @@ int mudp_tx_valid_ip(mudp_handle ut, uint8_t dip[MTL_IP_ADDR_LEN]) { MUDP_ERR_RET(EINVAL); } -int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void *priv), - void *priv) { +int mudp_register_stat_dump_cb(mudp_handle ut, int (*dump)(void *priv), void *priv) { struct mudp_impl *s = ut; int idx = s->idx; diff --git a/lib/src/udp/udp_main.h b/lib/src/udp/udp_main.h index 727995e28..2083a9988 100644 --- a/lib/src/udp/udp_main.h +++ b/lib/src/udp/udp_main.h @@ -16,10 +16,10 @@ // clang-format on /* On error, -1 is returned, and errno is set appropriately. */ -#define MUDP_ERR_RET(code) \ - do { \ - errno = code; \ - return -1; \ +#define MUDP_ERR_RET(code) \ + do { \ + errno = code; \ + return -1; \ } while (0) /* if bind or not */ diff --git a/lib/src/udp/udp_rxq.c b/lib/src/udp/udp_rxq.c index 6f7b106fc..6f4a188c0 100644 --- a/lib/src/udp/udp_rxq.c +++ b/lib/src/udp/udp_rxq.c @@ -55,8 +55,7 @@ static uint16_t urq_rx_handle(struct mur_queue *q, struct rte_mbuf **pkts, } } - if (!valid_mbuf_cnt) - return 0; + if (!valid_mbuf_cnt) return 0; int clients = q->clients; @@ -70,8 +69,7 @@ static uint16_t urq_rx_handle(struct mur_queue *q, struct rte_mbuf **pkts, if (clients == 1) { struct mur_client *c = MT_TAILQ_FIRST(&q->client_head); c->stat_pkt_rx += valid_mbuf_cnt; - n = rte_ring_sp_enqueue_bulk(c->ring, (void **)&valid_mbuf[0], - valid_mbuf_cnt, NULL); + n = rte_ring_sp_enqueue_bulk(c->ring, (void **)&valid_mbuf[0], valid_mbuf_cnt, NULL); if (!n) { dbg("%s(%d), %u pkts enqueue fail\n", __func__, idx, valid_mbuf_cnt); rte_pktmbuf_free_bulk(&valid_mbuf[0], valid_mbuf_cnt); @@ -105,8 +103,8 @@ static uint16_t urq_rx_handle(struct mur_queue *q, struct rte_mbuf **pkts, if (c_pkts_nb) { /* push last client */ struct mur_client *c = cs[last_c_idx]; c->stat_pkt_rx += c_pkts_nb; - unsigned int e = rte_ring_sp_enqueue_bulk(c->ring, (void **)&c_pkts[0], - c_pkts_nb, NULL); + unsigned int e = + rte_ring_sp_enqueue_bulk(c->ring, (void **)&c_pkts[0], c_pkts_nb, NULL); if (0 == e) { /* enqueue fail */ rte_pktmbuf_free_bulk(c_pkts, c_pkts_nb); c->stat_pkt_rx_enq_fail += c_pkts_nb; @@ -138,8 +136,7 @@ static uint16_t urq_rx(struct mur_queue *q) { uint16_t rx_burst = q->rx_burst_pkts; struct rte_mbuf *pkts[rx_burst]; - if (!urq_try_lock(q)) - return 0; + if (!urq_try_lock(q)) return 0; uint16_t rx = mt_rxq_burst(q->rxq, pkts, rx_burst); urq_unlock(q); @@ -171,15 +168,14 @@ static int urq_mgr_del(struct mudp_rxq_mgr *mgr, struct mur_queue *q) { return -EIO; } -static struct mur_queue *urq_mgr_search(struct mudp_rxq_mgr *mgr, - uint16_t dst_port) { +static struct mur_queue *urq_mgr_search(struct mudp_rxq_mgr *mgr, uint16_t dst_port) { struct mur_queue *q; struct mur_queue *ret = NULL; MT_TAILQ_FOREACH(q, &mgr->head, next) { if (q->dst_port == dst_port) { - info("%s(%d), dst_port %u already on q %p, reuse_port %d\n", __func__, - mgr->port, dst_port, q, q->reuse_port); + info("%s(%d), dst_port %u already on q %p, reuse_port %d\n", __func__, mgr->port, + dst_port, q, q->reuse_port); ret = q; } } @@ -272,8 +268,8 @@ static struct mur_queue *urq_get(struct mudp_rxq_mgr *mgr, q->rxq = mt_rxq_get(impl, port, &flow); if (!q->rxq) { /* wa for e810 pf mode since it doesn't support MT_RXQ_FLOW_F_NO_IP */ - warn("%s(%d,%u), get rxq fail with no ip flow, try cni queue\n", __func__, - port, dst_port); + warn("%s(%d,%u), get rxq fail with no ip flow, try cni queue\n", __func__, port, + dst_port); flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI; q->rxq = mt_rxq_get(impl, port, &flow); if (!q->rxq) { @@ -301,8 +297,7 @@ static struct mur_queue *urq_get(struct mudp_rxq_mgr *mgr, out_unlock_fail: urq_mgr_unlock(mgr); - if (q) - urq_put(q); + if (q) urq_put(q); return NULL; } @@ -352,8 +347,7 @@ static int urc_tasklet_handler(void *priv) { struct mur_client *c = priv; struct mtl_main_impl *impl = c->parent; - if (c->q) - urq_rx(c->q); + if (c->q) urq_rx(c->q); unsigned int count = rte_ring_count(c->ring); if (count > 0) { @@ -368,8 +362,7 @@ static int urc_tasklet_handler(void *priv) { } static int urc_init_tasklet(struct mtl_main_impl *impl, struct mur_client *c) { - if (!mt_user_udp_lcore(impl, c->port)) - return 0; + if (!mt_user_udp_lcore(impl, c->port)) return 0; struct mtl_tasklet_ops ops; char name[32]; @@ -405,8 +398,7 @@ struct mur_client *mur_client_get(struct mur_client_create *create) { return NULL; } - struct mur_client *c = - mt_rte_zmalloc_socket(sizeof(*c), mt_socket_id(impl, port)); + struct mur_client *c = mt_rte_zmalloc_socket(sizeof(*c), mt_socket_id(impl, port)); if (!c) { err("%s(%d,%u), client malloc fail\n", __func__, port, dst_port); urq_put(q); @@ -429,10 +421,9 @@ struct mur_client *mur_client_get(struct mur_client_create *create) { char ring_name[64]; struct rte_ring *ring; unsigned int flags, count; - snprintf(ring_name, sizeof(ring_name), "%sP%dDP%dQ%uC%d", MT_UDP_RXQ_PREFIX, - port, dst_port, q->rxq_id, idx); - flags = - RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ + snprintf(ring_name, sizeof(ring_name), "%sP%dDP%dQ%uC%d", MT_UDP_RXQ_PREFIX, port, + dst_port, q->rxq_id, idx); + flags = RING_F_SP_ENQ | RING_F_SC_DEQ; /* single-producer and single-consumer */ count = create->ring_count; ring = rte_ring_create(ring_name, count, mt_socket_id(impl, port), flags); if (!ring) { @@ -494,18 +485,17 @@ int mur_client_dump(struct mur_client *c) { int idx = c->idx; if (c->stat_pkt_rx) { - notice("%s(%d,%u,%d), pkt rx %u\n", __func__, port, dst_port, idx, - c->stat_pkt_rx); + notice("%s(%d,%u,%d), pkt rx %u\n", __func__, port, dst_port, idx, c->stat_pkt_rx); c->stat_pkt_rx = 0; } if (c->stat_pkt_rx_enq_fail) { - warn("%s(%d,%u,%d), pkt rx %u enqueue fail\n", __func__, port, dst_port, - idx, c->stat_pkt_rx_enq_fail); + warn("%s(%d,%u,%d), pkt rx %u enqueue fail\n", __func__, port, dst_port, idx, + c->stat_pkt_rx_enq_fail); c->stat_pkt_rx_enq_fail = 0; } if (c->stat_timedwait) { - notice("%s(%d,%u,%d), timedwait %u timeout %u\n", __func__, port, dst_port, - idx, c->stat_timedwait, c->stat_timedwait_timeout); + notice("%s(%d,%u,%d), timedwait %u timeout %u\n", __func__, port, dst_port, idx, + c->stat_timedwait, c->stat_timedwait_timeout); c->stat_timedwait = 0; c->stat_timedwait_timeout = 0; } @@ -539,8 +529,7 @@ int mur_client_timedwait(struct mur_client *c, unsigned int timedwait_us, dbg("%s(%u), timedwait ret %d\n", __func__, q->dst_port, ret); mt_pthread_mutex_unlock(&c->lcore_wake_mutex); - if (ret == ETIMEDOUT) - c->stat_timedwait_timeout++; + if (ret == ETIMEDOUT) c->stat_timedwait_timeout++; return ret; } @@ -573,8 +562,7 @@ int mudp_rxq_uinit(struct mtl_main_impl *impl) { for (int i = 0; i < MTL_PORT_MAX; i++) { mgr = impl->mudp_rxq_mgr[i]; - if (!mgr) - continue; + if (!mgr) continue; /* check if any not unregister */ while ((q = MT_TAILQ_FIRST(&mgr->head))) { diff --git a/lib/src/udp/udp_rxq.h b/lib/src/udp/udp_rxq.h index f3a29b377..0bd42f1d8 100644 --- a/lib/src/udp/udp_rxq.h +++ b/lib/src/udp/udp_rxq.h @@ -98,14 +98,12 @@ static inline struct rte_ring *mur_client_ring(struct mur_client *c) { return c->ring; } -static inline int mur_client_set_wake_thresh(struct mur_client *c, - unsigned int count) { +static inline int mur_client_set_wake_thresh(struct mur_client *c, unsigned int count) { c->wake_thresh_count = count; return 0; } -static inline int mur_client_set_wake_timeout(struct mur_client *c, - unsigned int us) { +static inline int mur_client_set_wake_timeout(struct mur_client *c, unsigned int us) { c->wake_timeout_us = us; return 0; } diff --git a/lib/src/udp/ufd_main.c b/lib/src/udp/ufd_main.c index 3bf7274b4..1e0a13328 100644 --- a/lib/src/udp/ufd_main.c +++ b/lib/src/udp/ufd_main.c @@ -64,8 +64,7 @@ static int ufd_free_mt_ctx(struct ufd_mt_ctx *ctx) { if (ctx->slots) { for (int i = 0; i < ufd_max_slot(ctx); i++) { /* check if any not free slot */ - if (!ctx->slots[i]) - continue; + if (!ctx->slots[i]) continue; warn("%s, not close slot on idx %d\n", __func__, i); ufd_free_slot(ctx, ctx->slots[i]); } @@ -145,8 +144,7 @@ static int ufd_parse_json(struct mufd_init_params *init, const char *filename) { err("%s, open json file %s fail\n", __func__, filename); MUDP_ERR_RET(EIO); } - info("%s, parse %s with json-c version: %s\n", __func__, filename, - json_c_version()); + info("%s, parse %s with json-c version: %s\n", __func__, filename, json_c_version()); int ret = -EIO; /* parse interfaces for system */ @@ -164,10 +162,8 @@ static int ufd_parse_json(struct mufd_init_params *init, const char *filename) { goto out; } for (int i = 0; i < num_interfaces; i++) { - ret = ufd_parse_interfaces( - init, json_object_array_get_idx(interfaces_array, i), i); - if (ret < 0) - goto out; + ret = ufd_parse_interfaces(init, json_object_array_get_idx(interfaces_array, i), i); + if (ret < 0) goto out; } struct mtl_init_params *p = &init->mt_params; @@ -280,8 +276,7 @@ static int ufd_parse_json(struct mufd_init_params *init, const char *filename) { int fd_base = json_object_get_int(obj); int limit = INT_MAX / 2; if (fd_base < limit) { - err("%s, invalid fd_base %d, must bigger than %d\n", __func__, fd_base, - limit); + err("%s, invalid fd_base %d, must bigger than %d\n", __func__, fd_base, limit); ret = -EINVAL; goto out; } @@ -423,25 +418,19 @@ static struct ufd_mt_ctx *ufd_create_mt_ctx(void) { if (rt_para) { info("%s, applied override config\n", __func__); p->log_level = rt_para->log_level; - if (rt_para->shared_tx_queue) - p->flags |= MTL_FLAG_SHARED_TX_QUEUE; - if (rt_para->shared_rx_queue) - p->flags |= MTL_FLAG_SHARED_RX_QUEUE; - if (rt_para->rss_mode) - p->rss_mode = rt_para->rss_mode; - if (rt_para->lcore_mode) - p->flags |= MTL_FLAG_UDP_LCORE; + if (rt_para->shared_tx_queue) p->flags |= MTL_FLAG_SHARED_TX_QUEUE; + if (rt_para->shared_rx_queue) p->flags |= MTL_FLAG_SHARED_RX_QUEUE; + if (rt_para->rss_mode) p->rss_mode = rt_para->rss_mode; + if (rt_para->lcore_mode) p->flags |= MTL_FLAG_UDP_LCORE; } } /* assign a default if not set by user */ - if (!ctx->init_params.slots_nb_max) - ctx->init_params.slots_nb_max = 1024; + if (!ctx->init_params.slots_nb_max) ctx->init_params.slots_nb_max = 1024; /* ufd is assigned to top of INT, the bottom fd is used by OS */ if (!ctx->init_params.fd_base) ctx->init_params.fd_base = INT_MAX - ctx->init_params.slots_nb_max * 2; - if (!ctx->init_params.txq_bps) - ctx->init_params.txq_bps = MUDP_DEFAULT_RL_BPS; + if (!ctx->init_params.txq_bps) ctx->init_params.txq_bps = MUDP_DEFAULT_RL_BPS; /* udp lcore and shared queue, set tasklets_nb_per_sch to allow max slots */ if ((p->flags & (MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE)) && @@ -474,8 +463,8 @@ static struct ufd_mt_ctx *ufd_create_mt_ctx(void) { } /* save ctx with dpdk rte memory which can be shared between process */ - struct ufd_mt_ctx *ctx_rte = mt_rte_zmalloc_socket( - sizeof(*ctx_rte), mt_socket_id(ctx->mt, MTL_PORT_P)); + struct ufd_mt_ctx *ctx_rte = + mt_rte_zmalloc_socket(sizeof(*ctx_rte), mt_socket_id(ctx->mt, MTL_PORT_P)); if (!ctx_rte) { err("%s, ctx_rte malloc fail\n", __func__); ufd_free_mt_ctx(ctx); @@ -527,8 +516,7 @@ static inline struct ufd_slot *ufd_fd2slot(int sockfd) { int idx = ufd_fd2idx(ctx, sockfd); struct ufd_slot *slot = ctx->slots[idx]; - if (!slot) - err("%s, invalid sockfd %d\n", __func__, sockfd); + if (!slot) err("%s, invalid sockfd %d\n", __func__, sockfd); return slot; } @@ -538,8 +526,7 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port) { struct ufd_slot *slot = NULL; ret = mudp_verify_socket_args(domain, type, protocol); - if (ret < 0) - return ret; + if (ret < 0) return ret; ctx = ufd_get_mt_ctx(true); if (!ctx) { err("%s, fail to get ufd mt ctx\n", __func__); @@ -553,8 +540,7 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port) { /* find one empty slot */ mt_pthread_mutex_lock(&ctx->slots_lock); for (int i = 0; i < ufd_max_slot(ctx); i++) { - if (ctx->slots[i]) - continue; + if (ctx->slots[i]) continue; /* create a slot */ slot = mt_rte_zmalloc_socket(sizeof(*slot), mt_socket_id(ctx->mt, port)); if (!slot) { @@ -589,8 +575,7 @@ int mufd_socket_port(int domain, int type, int protocol, enum mtl_port port) { if (ctx->init_params.rx_ring_count) mudp_set_rx_ring_count(slot->handle, ctx->init_params.rx_ring_count); if (ctx->init_params.wake_thresh_count) - mudp_set_wake_thresh_count(slot->handle, - ctx->init_params.wake_thresh_count); + mudp_set_wake_thresh_count(slot->handle, ctx->init_params.wake_thresh_count); if (ctx->init_params.wake_timeout_us) mudp_set_wake_timeout(slot->handle, ctx->init_params.wake_timeout_us); /* allow to set zero to disable sleep */ @@ -677,8 +662,7 @@ ssize_t mufd_recvmsg(int sockfd, struct msghdr *msg, int flags) { return mudp_recvmsg(slot->handle, msg, flags); } -int mufd_getsockopt(int sockfd, int level, int optname, void *optval, - socklen_t *optlen) { +int mufd_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen) { struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_getsockopt(slot->handle, level, optname, optval, optlen); } @@ -755,8 +739,7 @@ RTE_FINI_PRIO(mufd_finish_global, BUS) { int mufd_abort(void) { struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(false); - if (ctx) - mtl_abort(ctx->mt); + if (ctx) mtl_abort(ctx->mt); return 0; } @@ -821,22 +804,19 @@ int mufd_get_sessions_max_nb(void) { int mufd_init_context(void) { struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(true); - if (!ctx) - MUDP_ERR_RET(EIO); + if (!ctx) MUDP_ERR_RET(EIO); return 0; } int mufd_base_fd(void) { struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(true); - if (!ctx) - MUDP_ERR_RET(EIO); + if (!ctx) MUDP_ERR_RET(EIO); return ctx->init_params.fd_base; } enum mtl_log_level mufd_log_level(void) { struct ufd_mt_ctx *ctx = ufd_get_mt_ctx(true); - if (!ctx) - return MTL_LOG_LEVEL_INFO; + if (!ctx) return MTL_LOG_LEVEL_INFO; return ctx->init_params.mt_params.log_level; } @@ -898,8 +878,7 @@ int mufd_tx_valid_ip(int sockfd, uint8_t dip[MTL_IP_ADDR_LEN]) { return mudp_tx_valid_ip(slot->handle, dip); } -int mufd_register_stat_dump_cb(int sockfd, int (*dump)(void *priv), - void *priv) { +int mufd_register_stat_dump_cb(int sockfd, int (*dump)(void *priv), void *priv) { struct ufd_slot *slot = ufd_fd2slot(sockfd); return mudp_register_stat_dump_cb(slot->handle, dump, priv); } diff --git a/lib/windows/win_posix.c b/lib/windows/win_posix.c index 0303a8509..0688bd669 100644 --- a/lib/windows/win_posix.c +++ b/lib/windows/win_posix.c @@ -14,9 +14,8 @@ int shmget(key_t key, size_t size, int shmflg) { MTL_MAY_UNUSED(key); MTL_MAY_UNUSED(shmflg); int id = -1; - HANDLE hMapFile = - CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, size >> 32, - size & 0xffffffff, szName); + HANDLE hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, + size >> 32, size & 0xffffffff, szName); if (hMapFile != NULL) { map_info[numberofmapping].maphandle = hMapFile; map_info[numberofmapping].size = size; @@ -29,9 +28,9 @@ int shmget(key_t key, size_t size, int shmflg) { void *shmat(int shmid, const void *shmaddr, int shmflg) { MTL_MAY_UNUSED(shmaddr); MTL_MAY_UNUSED(shmflg); - void *pBuf = MapViewOfFile(map_info[shmid].maphandle, FILE_MAP_ALL_ACCESS, 0, - map_info[shmid].size >> 32, - map_info[shmid].size & 0xffffffff); + void *pBuf = + MapViewOfFile(map_info[shmid].maphandle, FILE_MAP_ALL_ACCESS, 0, + map_info[shmid].size >> 32, map_info[shmid].size & 0xffffffff); return pBuf; } @@ -67,32 +66,29 @@ int clock_gettime(int clk_id, struct timespec *tp) { } ct; switch (clk_id) { - case CLOCK_REALTIME: { - GetSystemTimePreciseAsFileTime(&ct.ft); - t = ct.u64 - DELTA_EPOCH_IN_100NS; - tp->tv_sec = t / POW10_7; - tp->tv_nsec = ((int)(t % POW10_7)) * 100; - return 0; - } + case CLOCK_REALTIME: { + GetSystemTimePreciseAsFileTime(&ct.ft); + t = ct.u64 - DELTA_EPOCH_IN_100NS; + tp->tv_sec = t / POW10_7; + tp->tv_nsec = ((int)(t % POW10_7)) * 100; + return 0; + } - case CLOCK_MONOTONIC: { - if (QueryPerformanceFrequency(&pf) == 0) - return -1; - if (QueryPerformanceCounter(&pc) == 0) - return -1; - tp->tv_sec = pc.QuadPart / pf.QuadPart; - tp->tv_nsec = - (int)(((pc.QuadPart % pf.QuadPart) * POW10_9 + (pf.QuadPart >> 1)) / - pf.QuadPart); - if (tp->tv_nsec >= POW10_9) { - tp->tv_sec++; - tp->tv_nsec -= POW10_9; + case CLOCK_MONOTONIC: { + if (QueryPerformanceFrequency(&pf) == 0) return -1; + if (QueryPerformanceCounter(&pc) == 0) return -1; + tp->tv_sec = pc.QuadPart / pf.QuadPart; + tp->tv_nsec = (int)(((pc.QuadPart % pf.QuadPart) * POW10_9 + (pf.QuadPart >> 1)) / + pf.QuadPart); + if (tp->tv_nsec >= POW10_9) { + tp->tv_sec++; + tp->tv_nsec -= POW10_9; + } + return 0; } - return 0; - } - default: - break; + default: + break; } return -1; diff --git a/lib/windows/win_posix.h b/lib/windows/win_posix.h index a23067bb4..fd47bd7ab 100644 --- a/lib/windows/win_posix.h +++ b/lib/windows/win_posix.h @@ -131,7 +131,7 @@ int shmget(key_t key, size_t size, int shmflg); typedef intptr_t pthread_cond_t; typedef int pthread_condattr_t; -#ifdef __MTL_LIB_BUILD__ // only lib need this typedef +#ifdef __MTL_LIB_BUILD__ // only lib need this typedef typedef rte_cpuset_t cpu_set_t; #endif @@ -146,11 +146,12 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, int pthread_cond_destroy(pthread_cond_t *cv); int pthread_mutex_trylock(pthread_mutex_t *mutex); -int clock_gettime(int clk_id, - struct timespec *tp); /* use precise time for windows */ +int clock_gettime(int clk_id, struct timespec *tp); /* use precise time for windows */ #ifdef __MTL_LIB_BUILD__ -static inline pid_t getpid() { return GetCurrentProcessId(); } +static inline pid_t getpid() { + return GetCurrentProcessId(); +} #endif #endif diff --git a/manager/logging.hpp b/manager/logging.hpp index 83841b2a3..064b2d091 100644 --- a/manager/logging.hpp +++ b/manager/logging.hpp @@ -13,7 +13,7 @@ enum class log_level { DEBUG, INFO, WARNING, ERROR }; class logger { -public: + public: static void log(log_level level, const std::string &message) { if (level >= log_level_min) { print_log_header(level); @@ -21,32 +21,33 @@ class logger { } } - static void set_log_level(log_level level) { log_level_min = level; } + static void set_log_level(log_level level) { + log_level_min = level; + } -private: + private: static log_level log_level_min; static void print_log_header(log_level level) { - auto now = - std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); + auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); const char *level_str = get_log_level_string(level); - std::cout << "[" << std::put_time(std::localtime(&now), "%F %T") << "] [" - << level_str << "] "; + std::cout << "[" << std::put_time(std::localtime(&now), "%F %T") << "] [" << level_str + << "] "; } static const char *get_log_level_string(log_level level) { switch (level) { - case log_level::DEBUG: - return "DEBUG"; - case log_level::INFO: - return "INFO"; - case log_level::WARNING: - return "WARNING"; - case log_level::ERROR: - return "ERROR"; - default: - return "UNKNOWN"; + case log_level::DEBUG: + return "DEBUG"; + case log_level::INFO: + return "INFO"; + case log_level::WARNING: + return "WARNING"; + case log_level::ERROR: + return "ERROR"; + default: + return "UNKNOWN"; } } }; diff --git a/manager/mtl.xdp.c b/manager/mtl.xdp.c index f49fc7485..76c152403 100644 --- a/manager/mtl.xdp.c +++ b/manager/mtl.xdp.c @@ -29,8 +29,7 @@ static int __always_inline lookup_udp4_dp(__u16 dp) { __u8 *value; value = bpf_map_lookup_elem(&udp4_dp_filter, &dp); - if (value && *value != 0) - return 1; + if (value && *value != 0) return 1; return 0; } @@ -45,24 +44,20 @@ int mtl_dp_filter(struct xdp_md *ctx) { nh.pos = data; eth_type = parse_ethhdr(&nh, data_end, ð); - if (eth_type != bpf_htons(ETH_P_IP)) - return XDP_PASS; + if (eth_type != bpf_htons(ETH_P_IP)) return XDP_PASS; struct iphdr *iphdr; int ip_type; ip_type = parse_iphdr(&nh, data_end, &iphdr); - if (ip_type != IPPROTO_UDP) - return XDP_PASS; + if (ip_type != IPPROTO_UDP) return XDP_PASS; struct udphdr *udphdr; int ret; ret = parse_udphdr(&nh, data_end, &udphdr); - if (ret < 0) - return XDP_PASS; + if (ret < 0) return XDP_PASS; __u16 dst_port = bpf_ntohs(udphdr->dest); - if (lookup_udp4_dp(dst_port) == 0) - return XDP_PASS; + if (lookup_udp4_dp(dst_port) == 0) return XDP_PASS; /* go to next program: xsk_def_prog */ return XDP_DROP; diff --git a/manager/mtl_instance.hpp b/manager/mtl_instance.hpp index c4da9b95c..690448a44 100644 --- a/manager/mtl_instance.hpp +++ b/manager/mtl_instance.hpp @@ -21,7 +21,7 @@ #include "mtl_mproto.h" class mtl_instance { -private: + private: const int conn_fd; bool is_registered; int pid; @@ -30,29 +30,26 @@ class mtl_instance { std::unordered_set lcore_ids; std::unordered_map> interfaces; std::unordered_map> if_queue_ids; - std::unordered_map> - if_flow_ids; + std::unordered_map> if_flow_ids; -private: + private: void log(const log_level &level, const std::string &message) const { - logger::log(level, "[Instance " + hostname + ":" + std::to_string(pid) + - "] " + message); + logger::log(level, + "[Instance " + hostname + ":" + std::to_string(pid) + "] " + message); } void handle_message_get_lcore(mtl_lcore_message_t *lcore_msg); void handle_message_put_lcore(mtl_lcore_message_t *lcore_msg); void handle_message_register(mtl_register_message_t *register_msg); void handle_message_if_xsk_map_fd(mtl_if_message_t *if_msg); - void - handle_message_udp_dp_filter(mtl_udp_dp_filter_message_t *udp_dp_filter_msg, - bool add); + void handle_message_udp_dp_filter(mtl_udp_dp_filter_message_t *udp_dp_filter_msg, + bool add); void handle_message_if_get_queue(mtl_if_message_t *if_msg); void handle_message_if_put_queue(mtl_if_message_t *if_msg); void handle_message_if_add_flow(mtl_if_message_t *if_msg); void handle_message_if_del_flow(mtl_if_message_t *if_msg); - int send_response(int response, - mtl_message_type_t type = MTL_MSG_TYPE_RESPONSE) { + int send_response(int response, mtl_message_type_t type = MTL_MSG_TYPE_RESPONSE) { mtl_message_t msg; msg.header.magic = htonl(MTL_MANAGER_MAGIC); msg.header.type = (mtl_message_type_t)htonl(type); @@ -62,14 +59,13 @@ class mtl_instance { } std::shared_ptr get_interface(const unsigned int ifindex); -public: + public: mtl_instance(int conn_fd) - : conn_fd(conn_fd), is_registered(false), pid(-1), uid(-1), - hostname("unknown") {} + : conn_fd(conn_fd), is_registered(false), pid(-1), uid(-1), hostname("unknown") { + } ~mtl_instance() { log(log_level::INFO, "Remove client."); - for (const auto &lcore_id : lcore_ids) - mtl_lcore::get_instance().put_lcore(lcore_id); + for (const auto &lcore_id : lcore_ids) mtl_lcore::get_instance().put_lcore(lcore_id); for (auto &pair : if_queue_ids) { auto interface = get_interface(pair.first); if (interface != nullptr) { @@ -92,16 +88,23 @@ class mtl_instance { close(conn_fd); } - int get_conn_fd() const { return conn_fd; } - int get_pid() const { return pid; } - int get_uid() const { return uid; } - std::string get_hostname() const { return hostname; } + int get_conn_fd() const { + return conn_fd; + } + int get_pid() const { + return pid; + } + int get_uid() const { + return uid; + } + std::string get_hostname() const { + return hostname; + } void handle_message(const char *buf, int len); }; void mtl_instance::handle_message(const char *buf, int len) { - if ((size_t)len < sizeof(mtl_message_t)) - return; + if ((size_t)len < sizeof(mtl_message_t)) return; mtl_message_t *msg = (mtl_message_t *)buf; if (ntohl(msg->header.magic) != MTL_MANAGER_MAGIC) { log(log_level::ERROR, "Invalid magic"); @@ -109,39 +112,39 @@ void mtl_instance::handle_message(const char *buf, int len) { } switch (ntohl(msg->header.type)) { - case MTL_MSG_TYPE_REGISTER: - handle_message_register(&msg->body.register_msg); - break; - case MTL_MSG_TYPE_GET_LCORE: - handle_message_get_lcore(&msg->body.lcore_msg); - break; - case MTL_MSG_TYPE_PUT_LCORE: - handle_message_put_lcore(&msg->body.lcore_msg); - break; - case MTL_MSG_TYPE_IF_XSK_MAP_FD: - handle_message_if_xsk_map_fd(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_ADD_UDP_DP_FILTER: - handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, true); - break; - case MTL_MSG_TYPE_DEL_UDP_DP_FILTER: - handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, false); - break; - case MTL_MSG_TYPE_IF_GET_QUEUE: - handle_message_if_get_queue(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_IF_PUT_QUEUE: - handle_message_if_put_queue(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_IF_ADD_FLOW: - handle_message_if_add_flow(&msg->body.if_msg); - break; - case MTL_MSG_TYPE_IF_DEL_FLOW: - handle_message_if_del_flow(&msg->body.if_msg); - break; - default: - log(log_level::ERROR, "Unknown message type"); - break; + case MTL_MSG_TYPE_REGISTER: + handle_message_register(&msg->body.register_msg); + break; + case MTL_MSG_TYPE_GET_LCORE: + handle_message_get_lcore(&msg->body.lcore_msg); + break; + case MTL_MSG_TYPE_PUT_LCORE: + handle_message_put_lcore(&msg->body.lcore_msg); + break; + case MTL_MSG_TYPE_IF_XSK_MAP_FD: + handle_message_if_xsk_map_fd(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_ADD_UDP_DP_FILTER: + handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, true); + break; + case MTL_MSG_TYPE_DEL_UDP_DP_FILTER: + handle_message_udp_dp_filter(&msg->body.udp_dp_filter_msg, false); + break; + case MTL_MSG_TYPE_IF_GET_QUEUE: + handle_message_if_get_queue(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_IF_PUT_QUEUE: + handle_message_if_put_queue(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_IF_ADD_FLOW: + handle_message_if_add_flow(&msg->body.if_msg); + break; + case MTL_MSG_TYPE_IF_DEL_FLOW: + handle_message_if_del_flow(&msg->body.if_msg); + break; + default: + log(log_level::ERROR, "Unknown message type"); + break; } } @@ -177,8 +180,7 @@ void mtl_instance::handle_message_put_lcore(mtl_lcore_message_t *lcore_msg) { send_response(0); } -void mtl_instance::handle_message_register( - mtl_register_message_t *register_msg) { +void mtl_instance::handle_message_register(mtl_register_message_t *register_msg) { pid = ntohl(register_msg->pid); uid = ntohl(register_msg->uid); hostname = std::string(register_msg->hostname, 64); @@ -187,8 +189,7 @@ void mtl_instance::handle_message_register( unsigned int ifindex = ntohl(register_msg->ifindex[i]); auto interface = get_interface(ifindex); if (interface == nullptr) { - log(log_level::ERROR, - "Could not get interface " + std::to_string(ifindex)); + log(log_level::ERROR, "Could not get interface " + std::to_string(ifindex)); send_response(-1); return; } @@ -200,8 +201,7 @@ void mtl_instance::handle_message_register( send_response(0); } -std::shared_ptr -mtl_instance::get_interface(const unsigned int ifindex) { +std::shared_ptr mtl_instance::get_interface(const unsigned int ifindex) { auto it = interfaces.find(ifindex); if (it != interfaces.end()) { log(log_level::DEBUG, "Returning existing interface."); @@ -211,24 +211,21 @@ mtl_instance::get_interface(const unsigned int ifindex) { auto g_it = g_interfaces.find(ifindex); if (g_it != g_interfaces.end()) { if (auto g_interface = g_it->second.lock()) { - log(log_level::INFO, - "Acquiring global interface " + std::to_string(ifindex)); + log(log_level::INFO, "Acquiring global interface " + std::to_string(ifindex)); interfaces[ifindex] = g_interface; return g_interface; } } /* Interface does not exist, create and initialize it */ - log(log_level::INFO, - "Initializing a new interface " + std::to_string(ifindex)); + log(log_level::INFO, "Initializing a new interface " + std::to_string(ifindex)); try { auto new_interface = std::make_shared(ifindex); g_interfaces[ifindex] = new_interface; interfaces[ifindex] = new_interface; return new_interface; } catch (const std::exception &e) { - log(log_level::ERROR, - "Failed to initialize interface: " + std::string(e.what())); + log(log_level::ERROR, "Failed to initialize interface: " + std::string(e.what())); return nullptr; } } @@ -237,8 +234,7 @@ void mtl_instance::handle_message_if_xsk_map_fd(mtl_if_message_t *if_msg) { int fd = -1; unsigned int ifindex = ntohl(if_msg->ifindex); auto interface = get_interface(ifindex); - if (interface != nullptr) - fd = interface->get_xsks_map_fd(); + if (interface != nullptr) fd = interface->get_xsks_map_fd(); struct msghdr msg = {0}; struct iovec iov[1]; @@ -285,8 +281,7 @@ void mtl_instance::handle_message_if_get_queue(mtl_if_message_t *if_msg) { return; } int ret = interface->get_queue(); - if (ret > 0) - if_queue_ids[ifindex].insert(ret); + if (ret > 0) if_queue_ids[ifindex].insert(ret); send_response(ret, MTL_MSG_TYPE_IF_QUEUE_ID); } @@ -300,8 +295,7 @@ void mtl_instance::handle_message_if_put_queue(mtl_if_message_t *if_msg) { } uint16_t queue_id = ntohs(if_msg->queue_id); int ret = interface->put_queue(queue_id); - if (ret == 0) - if_queue_ids[ifindex].erase(queue_id); + if (ret == 0) if_queue_ids[ifindex].erase(queue_id); send_response(ret); } @@ -313,11 +307,10 @@ void mtl_instance::handle_message_if_add_flow(mtl_if_message_t *if_msg) { send_response(-1); return; } - int ret = interface->add_flow( - ntohs(if_msg->queue_id), ntohl(if_msg->flow_type), ntohl(if_msg->src_ip), - ntohl(if_msg->dst_ip), ntohs(if_msg->src_port), ntohs(if_msg->dst_port)); - if (ret > 0) - if_flow_ids[ifindex].insert(ret); + int ret = interface->add_flow(ntohs(if_msg->queue_id), ntohl(if_msg->flow_type), + ntohl(if_msg->src_ip), ntohl(if_msg->dst_ip), + ntohs(if_msg->src_port), ntohs(if_msg->dst_port)); + if (ret > 0) if_flow_ids[ifindex].insert(ret); send_response(ret, MTL_MSG_TYPE_IF_FLOW_ID); } @@ -331,8 +324,7 @@ void mtl_instance::handle_message_if_del_flow(mtl_if_message_t *if_msg) { } unsigned int flow_id = ntohl(if_msg->flow_id); int ret = interface->del_flow(flow_id); - if (ret == 0) - if_flow_ids[ifindex].erase(flow_id); + if (ret == 0) if_flow_ids[ifindex].erase(flow_id); send_response(ret); } diff --git a/manager/mtl_interface.hpp b/manager/mtl_interface.hpp index 389a9940a..62c3c1760 100644 --- a/manager/mtl_interface.hpp +++ b/manager/mtl_interface.hpp @@ -27,7 +27,7 @@ #define MTL_MAX_QUEUES 64 class mtl_interface { -private: + private: const unsigned int ifindex; uint32_t max_combined; uint32_t combined_count; @@ -40,10 +40,9 @@ class mtl_interface { #endif std::vector queues; -private: + private: void log(const log_level &level, const std::string &message) const { - logger::log(level, - "[Interface " + std::to_string(ifindex) + "] " + message); + logger::log(level, "[Interface " + std::to_string(ifindex) + "] " + message); } int clear_flow_rules(); int parse_combined_info(); @@ -52,7 +51,7 @@ class mtl_interface { void unload_xdp(); #endif -public: + public: mtl_interface(unsigned int ifindex); ~mtl_interface(); @@ -66,8 +65,8 @@ class mtl_interface { int update_udp_dp_filter(uint16_t dst_port, bool add); int get_queue(); int put_queue(uint16_t queue_id); - int add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, - uint32_t dst_ip, uint16_t src_port, uint16_t dst_port); + int add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, uint32_t dst_ip, + uint16_t src_port, uint16_t dst_port); int del_flow(uint32_t flow_id); }; @@ -79,8 +78,7 @@ mtl_interface::mtl_interface(unsigned int ifindex) xsks_map_fd = -1; udp4_dp_filter_fd = -1; xdp_mode = XDP_MODE_UNSPEC; - if (load_xdp() < 0) - throw std::runtime_error("Failed to load XDP program."); + if (load_xdp() < 0) throw std::runtime_error("Failed to load XDP program."); #else throw std::runtime_error("No XDP support for this build"); #endif @@ -126,15 +124,14 @@ int mtl_interface::update_udp_dp_filter(uint16_t dst_port, bool add) { uint8_t value = add ? 1 : 0; int ret = bpf_map_update_elem(udp4_dp_filter_fd, &dst_port, &value, BPF_ANY); if (ret < 0) { - log(log_level::ERROR, "Failed to update udp4_dp_filter map, dst_port: " + - std::to_string(dst_port) + - ", error: " + std::to_string(ret)); + log(log_level::ERROR, + "Failed to update udp4_dp_filter map, dst_port: " + std::to_string(dst_port) + + ", error: " + std::to_string(ret)); return -1; } std::string action = add ? "Added " : "Removed "; - log(log_level::INFO, - action + std::to_string(dst_port) + " in udp4_dp_filter"); + log(log_level::INFO, action + std::to_string(dst_port) + " in udp4_dp_filter"); return 0; #else @@ -267,9 +264,8 @@ int mtl_interface::parse_combined_info() { return 0; } -int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, - uint32_t src_ip, uint32_t dst_ip, uint16_t src_port, - uint16_t dst_port) { +int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, uint32_t src_ip, + uint32_t dst_ip, uint16_t src_port, uint16_t dst_port) { int ret = 0; int free_loc = -1, flow_id = -1; char ifname[IF_NAMESIZE]; @@ -364,8 +360,7 @@ int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, ifr.ifr_data = (caddr_t)&cmd; ret = ioctl(fd, SIOCETHTOOL, &ifr); if (ret < 0) { - log(log_level::ERROR, - "Cannot insert flow rule: " + std::string(strerror(errno))); + log(log_level::ERROR, "Cannot insert flow rule: " + std::string(strerror(errno))); close(fd); return ret; } @@ -373,9 +368,8 @@ int mtl_interface::add_flow(uint16_t queue_id, uint32_t flow_type, close(fd); - log(log_level::INFO, "Successfully inserted flow rule " + - std::to_string(flow_id) + " with queue " + - std::to_string(queue_id)); + log(log_level::INFO, "Successfully inserted flow rule " + std::to_string(flow_id) + + " with queue " + std::to_string(queue_id)); return flow_id; } @@ -402,15 +396,14 @@ int mtl_interface::del_flow(uint32_t flow_id) { ifr.ifr_data = (caddr_t)&cmd; ret = ioctl(fd, SIOCETHTOOL, &ifr); if (ret < 0) { - log(log_level::ERROR, "Cannot delete flow rule " + std::to_string(flow_id) + - " ," + std::string(strerror(errno))); + log(log_level::ERROR, "Cannot delete flow rule " + std::to_string(flow_id) + " ," + + std::string(strerror(errno))); close(fd); return ret; } close(fd); - log(log_level::INFO, - "Successfully deleted flow rule " + std::to_string(flow_id)); + log(log_level::INFO, "Successfully deleted flow rule " + std::to_string(flow_id)); return 0; } @@ -443,16 +436,16 @@ int mtl_interface::load_xdp() { } /* save the filter map fd */ - udp4_dp_filter_fd = bpf_map__fd(bpf_object__find_map_by_name( - xdp_program__bpf_obj(xdp_prog), "udp4_dp_filter")); + udp4_dp_filter_fd = bpf_map__fd( + bpf_object__find_map_by_name(xdp_program__bpf_obj(xdp_prog), "udp4_dp_filter")); if (udp4_dp_filter_fd < 0) { log(log_level::ERROR, "Failed to get udp4_dp_filter map fd."); unload_xdp(); return -1; } - log(log_level::INFO, "Loaded xdp prog succ, udp4_dp_filter_fd: " + - std::to_string(udp4_dp_filter_fd)); + log(log_level::INFO, + "Loaded xdp prog succ, udp4_dp_filter_fd: " + std::to_string(udp4_dp_filter_fd)); return 0; } diff --git a/manager/mtl_lcore.hpp b/manager/mtl_lcore.hpp index e28930e90..edd489ac7 100644 --- a/manager/mtl_lcore.hpp +++ b/manager/mtl_lcore.hpp @@ -11,14 +11,17 @@ #define MTL_MAX_LCORE 128 class mtl_lcore { -private: + private: std::bitset bs; std::mutex bs_mtx; - mtl_lcore() { bs.reset(); } - ~mtl_lcore() {} + mtl_lcore() { + bs.reset(); + } + ~mtl_lcore() { + } -public: + public: mtl_lcore(const mtl_lcore &) = delete; mtl_lcore &operator=(const mtl_lcore &) = delete; @@ -32,8 +35,7 @@ class mtl_lcore { }; int mtl_lcore::get_lcore(uint16_t lcore_id) { - if (lcore_id >= MTL_MAX_LCORE) - return -1; + if (lcore_id >= MTL_MAX_LCORE) return -1; std::lock_guard lock(bs_mtx); if (bs.test(lcore_id)) return -1; @@ -43,8 +45,7 @@ int mtl_lcore::get_lcore(uint16_t lcore_id) { } int mtl_lcore::put_lcore(uint16_t lcore_id) { - if (lcore_id >= MTL_MAX_LCORE) - return -1; + if (lcore_id >= MTL_MAX_LCORE) return -1; std::lock_guard lock(bs_mtx); if (!bs.test(lcore_id)) return -1; diff --git a/manager/mtl_manager.cpp b/manager/mtl_manager.cpp index 885a18cd7..4e8cef96c 100644 --- a/manager/mtl_manager.cpp +++ b/manager/mtl_manager.cpp @@ -23,12 +23,11 @@ static const int MAX_CLIENTS = 10; static const char *mtlm_version(void) { static char version[128]; - if (version[0] != 0) - return version; + if (version[0] != 0) return version; snprintf(version, sizeof(version), "%d.%d.%d.%s %s %s %s", MTLM_VERSION_MAJOR, - MTLM_VERSION_MINOR, MTLM_VERSION_LAST, MTLM_VERSION_EXTRA, - __TIMESTAMP__, __MTLM_GIT__, MTLM_COMPILER); + MTLM_VERSION_MINOR, MTLM_VERSION_LAST, MTLM_VERSION_EXTRA, __TIMESTAMP__, + __MTLM_GIT__, MTLM_COMPILER); return version; } @@ -40,8 +39,7 @@ int main() { std::vector> clients; logger::set_log_level(log_level::INFO); - logger::log(log_level::INFO, - "MTL Manager version: " + std::string(mtlm_version())); + logger::log(log_level::INFO, "MTL Manager version: " + std::string(mtlm_version())); fs::path directory_path(MTL_MANAGER_SOCK_PATH); directory_path.remove_filename(); @@ -49,10 +47,9 @@ int main() { try { fs::create_directory(directory_path); } catch (const std::exception &e) { - logger::log( - log_level::ERROR, - "Failed to create dir:" + std::string(MTL_MANAGER_SOCK_PATH) + - ", please run the application with the appropriate privileges"); + logger::log(log_level::ERROR, + "Failed to create dir:" + std::string(MTL_MANAGER_SOCK_PATH) + + ", please run the application with the appropriate privileges"); return -EIO; } } @@ -96,8 +93,7 @@ int main() { } /* Allow all users to connect (which might be insecure) */ - fs::permissions(MTL_MANAGER_SOCK_PATH, fs::perms::all, - fs::perm_options::replace); + fs::permissions(MTL_MANAGER_SOCK_PATH, fs::perms::all, fs::perm_options::replace); ret = listen(sockfd, MAX_CLIENTS); if (ret < 0) { @@ -160,18 +156,16 @@ int main() { ev.data.fd = client_sockfd; ret = epoll_ctl(epfd, EPOLL_CTL_ADD, client_sockfd, &ev); if (ret < 0) { - logger::log(log_level::ERROR, - "Failed to add client socket fd to epoll."); + logger::log(log_level::ERROR, "Failed to add client socket fd to epoll."); close(client_sockfd); continue; } auto client = std::make_unique(client_sockfd); clients.push_back(std::move(client)); - logger::log(log_level::INFO, "New client connected. fd: " + - std::to_string(client_sockfd)); logger::log(log_level::INFO, - "Total clients: " + std::to_string(clients.size())); + "New client connected. fd: " + std::to_string(client_sockfd)); + logger::log(log_level::INFO, "Total clients: " + std::to_string(clients.size())); } else if (evfd == signal_fd) { /* handle signal */ struct signalfd_siginfo siginfo; ssize_t len = read(signal_fd, &siginfo, sizeof(siginfo)); @@ -185,25 +179,22 @@ int main() { is_running = false; } } else { /* handle client message */ - auto it = - std::find_if(clients.begin(), clients.end(), [&](auto &client) { - return client->get_conn_fd() == evfd; - }); + auto it = std::find_if(clients.begin(), clients.end(), [&](auto &client) { + return client->get_conn_fd() == evfd; + }); if (it != clients.end()) { auto &client = *it; char buf[256]; int len = recv(evfd, buf, sizeof(buf), 0); if (len < 0) { logger::log(log_level::ERROR, - "Failed to receive data from client " + - std::to_string(evfd)); + "Failed to receive data from client " + std::to_string(evfd)); } else if (len == 0) { logger::log(log_level::INFO, "Client " + std::to_string(evfd) + " disconnected."); ret = epoll_ctl(epfd, EPOLL_CTL_DEL, evfd, NULL); if (ret < 0) - logger::log(log_level::WARNING, - "Failed to remove client from epoll."); + logger::log(log_level::WARNING, "Failed to remove client from epoll."); clients.erase(it); logger::log(log_level::INFO, "Total clients: " + std::to_string(clients.size())); @@ -217,12 +208,9 @@ int main() { logger::log(log_level::INFO, "MTL Manager exited."); out: - if (signal_fd >= 0) - close(signal_fd); - if (epfd >= 0) - close(epfd); - if (sockfd >= 0) - close(sockfd); + if (signal_fd >= 0) close(signal_fd); + if (epfd >= 0) close(epfd); + if (sockfd >= 0) close(sockfd); return ret; } \ No newline at end of file diff --git a/plugins/log.h b/plugins/log.h index 847119c7a..a49d6014d 100644 --- a/plugins/log.h +++ b/plugins/log.h @@ -10,26 +10,26 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif \ No newline at end of file diff --git a/plugins/plugin_platform.h b/plugins/plugin_platform.h index 03dbeb881..11a388d39 100644 --- a/plugins/plugin_platform.h +++ b/plugins/plugin_platform.h @@ -39,8 +39,7 @@ static inline int st_pthread_cond_init(pthread_cond_t *cond, return pthread_cond_init(cond, cond_attr); } -static inline int st_pthread_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex) { +static inline int st_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } @@ -60,8 +59,8 @@ static inline uint64_t st_get_monotonic_time() { return ((uint64_t)ts.tv_sec * NS_PER_S) + ts.tv_nsec; } -static inline void -st_usleep(useconds_t usec) { // windows usleep function precision is only 1~15ms +static inline void st_usleep( + useconds_t usec) { // windows usleep function precision is only 1~15ms #ifdef WINDOWSENV LARGE_INTEGER delay; HANDLE delay_timer_handle = NULL; diff --git a/plugins/sample/convert_plugin_sample.c b/plugins/sample/convert_plugin_sample.c index b817ad96f..1321229e2 100644 --- a/plugins/sample/convert_plugin_sample.c +++ b/plugins/sample/convert_plugin_sample.c @@ -18,26 +18,25 @@ static int convert_frame(struct converter_session *s, struct st20_convert_frame_meta *frame) { switch (frame->src->fmt) { - case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - switch (frame->dst->fmt) { - case ST_FRAME_FMT_V210: - st20_rfc4175_422be10_to_v210(frame->src->addr[0], frame->dst->addr[0], - frame->dst->width, frame->dst->height); - break; case ST_FRAME_FMT_YUV422RFC4175PG2BE10: - mtl_memcpy(frame->dst->addr[0], frame->src->addr[0], - frame->dst->data_size); - break; - case ST_FRAME_FMT_UYVY: - st20_rfc4175_422be10_to_422le8(frame->src->addr[0], frame->dst->addr[0], - frame->dst->width, frame->dst->height); + switch (frame->dst->fmt) { + case ST_FRAME_FMT_V210: + st20_rfc4175_422be10_to_v210(frame->src->addr[0], frame->dst->addr[0], + frame->dst->width, frame->dst->height); + break; + case ST_FRAME_FMT_YUV422RFC4175PG2BE10: + mtl_memcpy(frame->dst->addr[0], frame->src->addr[0], frame->dst->data_size); + break; + case ST_FRAME_FMT_UYVY: + st20_rfc4175_422be10_to_422le8(frame->src->addr[0], frame->dst->addr[0], + frame->dst->width, frame->dst->height); + break; + default: + break; + } break; default: break; - } - break; - default: - break; } s->frame_cnt++; return 0; @@ -54,8 +53,7 @@ static void *convert_thread(void *arg) { frame = st20_converter_get_frame(session_p); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -67,19 +65,17 @@ static void *convert_thread(void *arg) { return NULL; } -static st20_convert_priv -converter_create_session(void *priv, st20p_convert_session session_p, - struct st20_converter_create_req *req) { +static st20_convert_priv converter_create_session(void *priv, + st20p_convert_session session_p, + struct st20_converter_create_req *req) { struct convert_ctx *ctx = priv; struct converter_session *session = NULL; int ret; for (int i = 0; i < MAX_COLOR_CONVERT_SESSIONS; i++) { - if (ctx->converter_sessions[i]) - continue; + if (ctx->converter_sessions[i]) continue; session = malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->idx = i; st_pthread_mutex_init(&session->wake_mutex, NULL); @@ -88,8 +84,7 @@ converter_create_session(void *priv, st20p_convert_session session_p, session->req = *req; session->session_p = session_p; - ret = - pthread_create(&session->convert_thread, NULL, convert_thread, session); + ret = pthread_create(&session->convert_thread, NULL, convert_thread, session); if (ret < 0) { info("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -122,8 +117,7 @@ static int converter_free_session(void *priv, st20_convert_priv session) { st_pthread_mutex_destroy(&converter_session->wake_mutex); st_pthread_cond_destroy(&converter_session->wake_cond); - info("%s(%d), total %d convert frames\n", __func__, idx, - converter_session->frame_cnt); + info("%s(%d), total %d convert frames\n", __func__, idx, converter_session->frame_cnt); free(converter_session); ctx->converter_sessions[idx] = NULL; return 0; @@ -144,8 +138,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { struct convert_ctx *ctx; ctx = malloc(sizeof(*ctx)); - if (!ctx) - return NULL; + if (!ctx) return NULL; memset(ctx, 0, sizeof(*ctx)); struct st20_converter_dev c_dev; @@ -153,8 +146,8 @@ st_plugin_priv st_plugin_create(mtl_handle st) { c_dev.name = "color_convert_sample"; c_dev.priv = ctx; c_dev.target_device = ST_PLUGIN_DEVICE_CPU; - c_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_UYVY | - ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; + c_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_UYVY | ST_FMT_CAP_V210 | + ST_FMT_CAP_YUV422RFC4175PG2BE10; c_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_UYVY | ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; c_dev.create_session = converter_create_session; diff --git a/plugins/sample/st22_plugin_sample.c b/plugins/sample/st22_plugin_sample.c index 3cd21b72f..b228a9800 100644 --- a/plugins/sample/st22_plugin_sample.c +++ b/plugins/sample/st22_plugin_sample.c @@ -57,19 +57,16 @@ static void *encode_thread(void *arg) { return NULL; } -static st22_encode_priv -encoder_create_session(void *priv, st22p_encode_session session_p, - struct st22_encoder_create_req *req) { +static st22_encode_priv encoder_create_session(void *priv, st22p_encode_session session_p, + struct st22_encoder_create_req *req) { struct st22_sample_ctx *ctx = priv; struct st22_encoder_session *session = NULL; int ret; for (int i = 0; i < MAX_SAMPLE_ENCODER_SESSIONS; i++) { - if (ctx->encoder_sessions[i]) - continue; + if (ctx->encoder_sessions[i]) continue; session = malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->idx = i; @@ -112,8 +109,7 @@ static int encoder_free_session(void *priv, st22_encode_priv session) { pthread_join(encoder_session->encode_thread, NULL); } - info("%s(%d), total %d encode frames\n", __func__, idx, - encoder_session->frame_cnt); + info("%s(%d), total %d encode frames\n", __func__, idx, encoder_session->frame_cnt); free(encoder_session); ctx->encoder_sessions[idx] = NULL; return 0; @@ -164,19 +160,16 @@ static void *decode_thread(void *arg) { return NULL; } -static st22_decode_priv -decoder_create_session(void *priv, st22p_decode_session session_p, - struct st22_decoder_create_req *req) { +static st22_decode_priv decoder_create_session(void *priv, st22p_decode_session session_p, + struct st22_decoder_create_req *req) { struct st22_sample_ctx *ctx = priv; struct st22_decoder_session *session = NULL; int ret; for (int i = 0; i < MAX_SAMPLE_DECODER_SESSIONS; i++) { - if (ctx->decoder_sessions[i]) - continue; + if (ctx->decoder_sessions[i]) continue; session = malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->idx = i; @@ -194,9 +187,8 @@ decoder_create_session(void *priv, st22p_decode_session session_p, } ctx->decoder_sessions[i] = session; - info("%s(%d), input fmt: %s, output fmt: %s, scan: %s, socket id: %d\n", - __func__, i, st_frame_fmt_name(req->input_fmt), - st_frame_fmt_name(req->output_fmt), + info("%s(%d), input fmt: %s, output fmt: %s, scan: %s, socket id: %d\n", __func__, i, + st_frame_fmt_name(req->input_fmt), st_frame_fmt_name(req->output_fmt), req->interlaced ? "interlaced" : "progressive", req->socket_id); return session; } @@ -217,8 +209,7 @@ static int decoder_free_session(void *priv, st22_decode_priv session) { pthread_join(decoder_session->decode_thread, NULL); } - info("%s(%d), total %d decode frames\n", __func__, idx, - decoder_session->frame_cnt); + info("%s(%d), total %d decode frames\n", __func__, idx, decoder_session->frame_cnt); free(decoder_session); ctx->decoder_sessions[idx] = NULL; return 0; @@ -234,8 +225,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { struct st22_sample_ctx *ctx; ctx = malloc(sizeof(*ctx)); - if (!ctx) - return NULL; + if (!ctx) return NULL; memset(ctx, 0, sizeof(*ctx)); struct st22_decoder_dev d_dev; @@ -243,12 +233,10 @@ st_plugin_priv st_plugin_create(mtl_handle st) { d_dev.name = "st22_decoder_sample"; d_dev.priv = ctx; d_dev.target_device = ST_PLUGIN_DEVICE_CPU; - d_dev.input_fmt_caps = - ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + d_dev.input_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; d_dev.output_fmt_caps = ST_FMT_CAP_ARGB | ST_FMT_CAP_BGRA | ST_FMT_CAP_RGB8; - d_dev.output_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | - ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_V210 | - ST_FMT_CAP_YUV422RFC4175PG2BE10; + d_dev.output_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8 | + ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; d_dev.output_fmt_caps |= ST_FMT_CAP_YUV420PLANAR8; d_dev.create_session = decoder_create_session; d_dev.free_session = decoder_free_session; @@ -267,12 +255,10 @@ st_plugin_priv st_plugin_create(mtl_handle st) { e_dev.target_device = ST_PLUGIN_DEVICE_CPU; e_dev.input_fmt_caps = ST_FMT_CAP_ARGB | ST_FMT_CAP_BGRA | ST_FMT_CAP_RGB8; - e_dev.input_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | - ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_V210 | - ST_FMT_CAP_YUV422RFC4175PG2BE10; + e_dev.input_fmt_caps |= ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8 | + ST_FMT_CAP_V210 | ST_FMT_CAP_YUV422RFC4175PG2BE10; e_dev.input_fmt_caps |= ST_FMT_CAP_YUV420PLANAR8; - e_dev.output_fmt_caps = - ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + e_dev.output_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; e_dev.create_session = encoder_create_session; e_dev.free_session = encoder_free_session; e_dev.notify_frame_available = encoder_frame_available; diff --git a/plugins/st22_avcodec/st22_avcodec_plugin.c b/plugins/st22_avcodec/st22_avcodec_plugin.c index 3fa281157..df4ee3704 100644 --- a/plugins/st22_avcodec/st22_avcodec_plugin.c +++ b/plugins/st22_avcodec/st22_avcodec_plugin.c @@ -46,24 +46,23 @@ static int avcodec_encode_frame(struct st22_avcodec_encoder_session *s, ret = avcodec_send_frame(ctx, f); if (ret < 0) { - err("%s(%d), send frame(%d) fail %s\n", __func__, idx, f_idx, - av_err2str(ret)); + err("%s(%d), send frame(%d) fail %s\n", __func__, idx, f_idx, av_err2str(ret)); return ret; } s->frame_cnt++; ret = avcodec_receive_packet(ctx, p); if (ret < 0) { - dbg("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, - av_err2str(ret), f_idx); + dbg("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, av_err2str(ret), + f_idx); /* log error if not EAGAIN or EOF*/ if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { - err("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, - av_err2str(ret), f_idx); + err("%s(%d), receive packet fail %s on frame %d\n", __func__, idx, av_err2str(ret), + f_idx); } } else { - dbg("%s, receive packet %" PRId64 " size %d on frame %d\n", __func__, - p->pts, p->size, f_idx); + dbg("%s, receive packet %" PRId64 " size %d on frame %d\n", __func__, p->pts, p->size, + f_idx); /* copy codestream */ mtl_memcpy(frame->dst->addr[0] + data_size, p->data, p->size); data_size = p->size; @@ -77,8 +76,8 @@ static int avcodec_encode_frame(struct st22_avcodec_encoder_session *s, } frame->dst->data_size = data_size; - dbg("%s(%d), codestream size %" PRIu64 " on frame %d\n", __func__, idx, - data_size, f_idx); + dbg("%s(%d), codestream size %" PRIu64 " on frame %d\n", __func__, idx, data_size, + f_idx); return data_size > 0 ? 0 : -EIO; } @@ -103,8 +102,7 @@ static void *avcodec_encode_thread(void *arg) { return NULL; } -static int -avcodec_encoder_uinit_session(struct st22_avcodec_encoder_session *session) { +static int avcodec_encoder_uinit_session(struct st22_avcodec_encoder_session *session) { int idx = session->idx; if (session->encode_thread) { @@ -133,9 +131,8 @@ avcodec_encoder_uinit_session(struct st22_avcodec_encoder_session *session) { return 0; } -static int -avcodec_encoder_init_session(struct st22_avcodec_encoder_session *session, - struct st22_encoder_create_req *req) { +static int avcodec_encoder_init_session(struct st22_avcodec_encoder_session *session, + struct st22_encoder_create_req *req) { int idx = session->idx; int ret; @@ -148,8 +145,7 @@ avcodec_encoder_init_session(struct st22_avcodec_encoder_session *session, } else if (req->output_fmt == ST_FRAME_FMT_H264_CODESTREAM) { codec_id = AV_CODEC_ID_H264; } else { - err("%s(%d), invalid codec stream fmt %d\n", __func__, idx, - req->output_fmt); + err("%s(%d), invalid codec stream fmt %d\n", __func__, idx, req->output_fmt); return -EIO; } const AVCodec *codec = avcodec_find_encoder(codec_id); @@ -224,8 +220,7 @@ avcodec_encoder_init_session(struct st22_avcodec_encoder_session *session, } session->codec_pkt = p; - ret = pthread_create(&session->encode_thread, NULL, avcodec_encode_thread, - session); + ret = pthread_create(&session->encode_thread, NULL, avcodec_encode_thread, session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, idx, ret); avcodec_encoder_uinit_session(session); @@ -235,19 +230,16 @@ avcodec_encoder_init_session(struct st22_avcodec_encoder_session *session, return 0; } -static st22_encode_priv -avcodec_encoder_create_session(void *priv, st22p_encode_session session_p, - struct st22_encoder_create_req *req) { +static st22_encode_priv avcodec_encoder_create_session( + void *priv, st22p_encode_session session_p, struct st22_encoder_create_req *req) { struct st22_avcodec_plugin_ctx *ctx = priv; struct st22_avcodec_encoder_session *session = NULL; int ret; for (int i = 0; i < MAX_ST22_AVCODEC_ENCODER_SESSIONS; i++) { - if (ctx->encoder_sessions[i]) - continue; + if (ctx->encoder_sessions[i]) continue; session = malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->idx = i; session->session_p = session_p; @@ -276,8 +268,7 @@ static int avcodec_encoder_free_session(void *priv, st22_encode_priv session) { struct st22_avcodec_encoder_session *encoder_session = session; int idx = encoder_session->idx; - info("%s(%d), total %d encode frames\n", __func__, idx, - encoder_session->frame_cnt); + info("%s(%d), total %d encode frames\n", __func__, idx, encoder_session->frame_cnt); avcodec_encoder_uinit_session(encoder_session); free(encoder_session); @@ -302,23 +293,22 @@ static int avcodec_decode_frame(struct st22_avcodec_decoder_session *s, p->size = src_size; ret = avcodec_send_packet(ctx, p); if (ret < 0) { - err("%s(%d), send pkt(%d) fail %s\n", __func__, idx, f_idx, - av_err2str(ret)); + err("%s(%d), send pkt(%d) fail %s\n", __func__, idx, f_idx, av_err2str(ret)); return ret; } ret = avcodec_receive_frame(ctx, f); if (ret < 0) { - dbg("%s(%d), receive data fail %s on frame %d\n", __func__, idx, - av_err2str(ret), f_idx); + dbg("%s(%d), receive data fail %s on frame %d\n", __func__, idx, av_err2str(ret), + f_idx); /* log error if not EAGAIN or EOF*/ if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) { - err("%s(%d), receive data fail %s on frame %d\n", __func__, idx, - av_err2str(ret), f_idx); + err("%s(%d), receive data fail %s on frame %d\n", __func__, idx, av_err2str(ret), + f_idx); } } else { - dbg("%s, format(%dx%d@%d) on frame %d\n", __func__, f->width, f->height, - f->format, f_idx); + dbg("%s, format(%dx%d@%d) on frame %d\n", __func__, f->width, f->height, f->format, + f_idx); frame_size = dst->data_size; /* copy data to frame */ mtl_memcpy(dst->addr[0], f->data[0], st_frame_plane_size(dst, 0)); @@ -354,8 +344,7 @@ static void *avcodec_decode_thread(void *arg) { return NULL; } -static int -avcodec_decoder_uinit_session(struct st22_avcodec_decoder_session *session) { +static int avcodec_decoder_uinit_session(struct st22_avcodec_decoder_session *session) { int idx = session->idx; if (session->decode_thread) { @@ -389,9 +378,8 @@ avcodec_decoder_uinit_session(struct st22_avcodec_decoder_session *session) { return 0; } -static int -avcodec_decoder_init_session(struct st22_avcodec_decoder_session *session, - struct st22_decoder_create_req *req) { +static int avcodec_decoder_init_session(struct st22_avcodec_decoder_session *session, + struct st22_decoder_create_req *req) { int idx = session->idx; int ret; @@ -467,8 +455,7 @@ avcodec_decoder_init_session(struct st22_avcodec_decoder_session *session, } session->codec_pkt = p; - ret = pthread_create(&session->decode_thread, NULL, avcodec_decode_thread, - session); + ret = pthread_create(&session->decode_thread, NULL, avcodec_decode_thread, session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, idx, ret); avcodec_decoder_uinit_session(session); @@ -478,19 +465,16 @@ avcodec_decoder_init_session(struct st22_avcodec_decoder_session *session, return 0; } -static st22_decode_priv -avcodec_decoder_create_session(void *priv, st22p_decode_session session_p, - struct st22_decoder_create_req *req) { +static st22_decode_priv avcodec_decoder_create_session( + void *priv, st22p_decode_session session_p, struct st22_decoder_create_req *req) { struct st22_avcodec_plugin_ctx *ctx = priv; struct st22_avcodec_decoder_session *session = NULL; int ret; for (int i = 0; i < MAX_ST22_AVCODEC_DECODER_SESSIONS; i++) { - if (ctx->decoder_sessions[i]) - continue; + if (ctx->decoder_sessions[i]) continue; session = malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->idx = i; session->session_p = session_p; @@ -517,8 +501,7 @@ static int avcodec_decoder_free_session(void *priv, st22_decode_priv session) { struct st22_avcodec_decoder_session *decoder_session = session; int idx = decoder_session->idx; - info("%s(%d), total %d decode frames\n", __func__, idx, - decoder_session->frame_cnt); + info("%s(%d), total %d decode frames\n", __func__, idx, decoder_session->frame_cnt); avcodec_decoder_uinit_session(decoder_session); free(decoder_session); @@ -530,8 +513,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { struct st22_avcodec_plugin_ctx *ctx; ctx = malloc(sizeof(*ctx)); - if (!ctx) - return NULL; + if (!ctx) return NULL; memset(ctx, 0, sizeof(*ctx)); struct st22_decoder_dev d_dev; @@ -539,8 +521,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { d_dev.name = "st22_plugin_avcodec_decoder"; d_dev.priv = ctx; d_dev.target_device = ST_PLUGIN_DEVICE_CPU; - d_dev.input_fmt_caps = - ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; + d_dev.input_fmt_caps = ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; d_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_YUV420PLANAR8; d_dev.create_session = avcodec_decoder_create_session; d_dev.free_session = avcodec_decoder_free_session; @@ -557,8 +538,7 @@ st_plugin_priv st_plugin_create(mtl_handle st) { e_dev.priv = ctx; e_dev.target_device = ST_PLUGIN_DEVICE_CPU; e_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR8 | ST_FMT_CAP_YUV420PLANAR8; - e_dev.output_fmt_caps = - ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; + e_dev.output_fmt_caps = ST_FMT_CAP_H264_CODESTREAM | ST_FMT_CAP_H265_CODESTREAM; e_dev.create_session = avcodec_encoder_create_session; e_dev.free_session = avcodec_encoder_free_session; ctx->encoder_dev_handle = st22_encoder_register(st, &e_dev); diff --git a/rdma/mt_rdma.c b/rdma/mt_rdma.c index f7ed21865..3bdab7a2d 100644 --- a/rdma/mt_rdma.c +++ b/rdma/mt_rdma.c @@ -11,7 +11,9 @@ static enum mtl_rdma_log_level rdma_log_level = MTL_RDMA_LOG_LEVEL_INFO; void mt_rdma_set_log_level(enum mtl_rdma_log_level level) { rdma_log_level = level; } -enum mtl_rdma_log_level mt_rdma_get_log_level(void) { return rdma_log_level; } +enum mtl_rdma_log_level mt_rdma_get_log_level(void) { + return rdma_log_level; +} mtl_rdma_handle mtl_rdma_init(struct mtl_rdma_init_params *p) { struct mt_rdma_impl *impl = NULL; diff --git a/rdma/mt_rdma.h b/rdma/mt_rdma.h index b09f63cf2..929b679ba 100644 --- a/rdma/mt_rdma.h +++ b/rdma/mt_rdma.h @@ -22,12 +22,12 @@ #define MT_RDMA_MSG_MAX_SIZE (1024) -#define MT_SAFE_FREE(obj, free_fn) \ - do { \ - if (obj) { \ - free_fn(obj); \ - obj = NULL; \ - } \ +#define MT_SAFE_FREE(obj, free_fn) \ + do { \ + if (obj) { \ + free_fn(obj); \ + obj = NULL; \ + } \ } while (0) void mt_rdma_set_log_level(enum mtl_rdma_log_level level); @@ -35,39 +35,34 @@ enum mtl_rdma_log_level mt_rdma_get_log_level(void); /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_DEBUG) \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_DEBUG) printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_INFO) \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_INFO) printf(__VA_ARGS__); \ } while (0) -#define notce(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_NOTICE) \ - printf(__VA_ARGS__); \ +#define notce(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_NOTICE) printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_WARNING) \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_WARNING) printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_ERR) \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + if (mt_rdma_get_log_level() <= MTL_RDMA_LOG_LEVEL_ERR) printf(__VA_ARGS__); \ } while (0) -#define critical(...) \ - do { \ - printf(__VA_ARGS__); \ +#define critical(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) /* Remote buffer info for RDMA write */ @@ -202,8 +197,7 @@ struct mt_rdma_impl { struct mtl_rdma_init_params para; }; -static inline struct mtl_rdma_init_params * -mt_rdma_get_params(struct mt_rdma_impl *impl) { +static inline struct mtl_rdma_init_params *mt_rdma_get_params(struct mt_rdma_impl *impl) { return &impl->para; } @@ -231,9 +225,8 @@ static inline int mt_rdma_handle_cq_events(struct ibv_comp_channel *cc, return 0; } -static inline int mt_rdma_post_write_imm(struct rdma_cm_id *id, void *context, - void *addr, size_t length, - struct ibv_mr *mr, int flags, +static inline int mt_rdma_post_write_imm(struct rdma_cm_id *id, void *context, void *addr, + size_t length, struct ibv_mr *mr, int flags, uint64_t remote_addr, uint32_t rkey, uint32_t imm_data) { struct ibv_send_wr wr, *bad_wr; diff --git a/rdma/mt_rdma_rx.c b/rdma/mt_rdma_rx.c index 4196f7251..88618436b 100644 --- a/rdma/mt_rdma_rx.c +++ b/rdma/mt_rdma_rx.c @@ -21,8 +21,7 @@ static int rdma_rx_send_buffer_done(struct mt_rdma_rx_ctx *ctx, uint16_t idx) { int ret = rdma_post_send(ctx->id, NULL, &msg, sizeof(msg), NULL, IBV_SEND_INLINE | IBV_SEND_SIGNALED); if (ret) { - err("%s(%s), rdma_post_send failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), rdma_post_send failed: %s\n", __func__, ctx->ops_name, strerror(errno)); pthread_mutex_unlock(&rx_buffer->lock); return -EIO; } @@ -55,9 +54,9 @@ static int rdma_rx_init_mrs(struct mt_rdma_rx_ctx *ctx) { rx_buffer->mr = mr; } - struct ibv_mr *mr = ibv_reg_mr( - ctx->pd, ctx->recv_msgs, ctx->buffer_cnt * sizeof(struct mt_rdma_message), - IBV_ACCESS_LOCAL_WRITE); + struct ibv_mr *mr = ibv_reg_mr(ctx->pd, ctx->recv_msgs, + ctx->buffer_cnt * sizeof(struct mt_rdma_message), + IBV_ACCESS_LOCAL_WRITE); if (!mr) { err("%s(%s), ibv_reg_mr message failed\n", __func__, ctx->ops_name); rdma_rx_uinit_mrs(ctx); @@ -65,8 +64,7 @@ static int rdma_rx_init_mrs(struct mt_rdma_rx_ctx *ctx) { } ctx->recv_msgs_mr = mr; - mr = ibv_reg_mr(ctx->pd, ctx->meta_region, - ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, + mr = ibv_reg_mr(ctx->pd, ctx->meta_region, ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); if (!mr) { err("%s(%s), ibv_reg_mr meta region failed\n", __func__, ctx->ops_name); @@ -129,8 +127,7 @@ static int rdma_rx_alloc_buffers(struct mt_rdma_rx_ctx *ctx) { return 0; } -static int rdma_rx_handle_wc_recv_imm(struct mt_rdma_rx_ctx *ctx, - struct ibv_wc *wc) { +static int rdma_rx_handle_wc_recv_imm(struct mt_rdma_rx_ctx *ctx, struct ibv_wc *wc) { struct mtl_rdma_rx_ops *ops = &ctx->ops; uint16_t idx = ntohl(wc->imm_data) >> 16; dbg("%s(%s), buffer %u write done\n", __func__, ctx->ops_name, idx); @@ -146,15 +143,13 @@ static int rdma_rx_handle_wc_recv_imm(struct mt_rdma_rx_ctx *ctx, rx_buffer->buffer.user_meta_size = ntohl(wc->imm_data) & 0x0000FFFF; rx_buffer->status = MT_RDMA_BUFFER_STATUS_READY; ctx->stat_buffer_received++; - if (ops->notify_buffer_ready) - ops->notify_buffer_ready(ops->priv, &rx_buffer->buffer); + if (ops->notify_buffer_ready) ops->notify_buffer_ready(ops->priv, &rx_buffer->buffer); pthread_mutex_unlock(&rx_buffer->lock); struct mt_rdma_message *msg = (struct mt_rdma_message *)wc->wr_id; int ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, strerror(errno)); return -EIO; } return 0; @@ -170,13 +165,13 @@ static int rdma_rx_handle_wc(struct mt_rdma_rx_ctx *ctx, struct ibv_wc *wc) { } switch (wc->opcode) { - case IBV_WC_RECV_RDMA_WITH_IMM: - return rdma_rx_handle_wc_recv_imm(ctx, wc); - case IBV_WC_SEND: - return 0; /* nothing to do */ - default: - err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); - return -EIO; + case IBV_WC_RECV_RDMA_WITH_IMM: + return rdma_rx_handle_wc_recv_imm(ctx, wc); + case IBV_WC_SEND: + return 0; /* nothing to do */ + default: + err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); + return -EIO; } } @@ -220,10 +215,8 @@ static void *rdma_rx_cq_poll_thread(void *arg) { } while (ibv_poll_cq(cq, 1, &wc)) { - if (ctx->cq_poll_stop) - break; - if (rdma_rx_handle_wc(ctx, &wc)) - goto out; + if (ctx->cq_poll_stop) break; + if (rdma_rx_handle_wc(ctx, &wc)) goto out; ctx->stat_cq_poll_done++; } @@ -249,8 +242,7 @@ static void *rdma_rx_connect_thread(void *arg) { while (!ctx->connect_stop) { ret = poll(&pfd, 1, 200); if (ret < 0) { - err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, strerror(errno)); goto connect_err; } else if (ret == 0) { /* timeout */ @@ -259,110 +251,106 @@ static void *rdma_rx_connect_thread(void *arg) { ret = rdma_get_cm_event(ctx->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_ADDR_RESOLVED: - ret = rdma_resolve_route(ctx->id, 2000); - if (ret) { - err("%s(%s), rdma_resolve_route failed\n", __func__, ctx->ops_name); - goto connect_err; - } - break; - case RDMA_CM_EVENT_ROUTE_RESOLVED: - ctx->pd = ibv_alloc_pd(event->id->verbs); - if (!ctx->pd) { - err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ctx->cc = ibv_create_comp_channel(event->id->verbs); - if (!ctx->cc) { - err("%s(%s), ibv_create_comp_channel failed\n", __func__, - ctx->ops_name); + case RDMA_CM_EVENT_ADDR_RESOLVED: + ret = rdma_resolve_route(ctx->id, 2000); + if (ret) { + err("%s(%s), rdma_resolve_route failed\n", __func__, ctx->ops_name); goto connect_err; } - } - ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); - if (!ctx->cq) { - err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ret = ibv_req_notify_cq(ctx->cq, 0); + break; + case RDMA_CM_EVENT_ROUTE_RESOLVED: + ctx->pd = ibv_alloc_pd(event->id->verbs); + if (!ctx->pd) { + err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); + goto connect_err; + } + if (!ctx->cq_poll_only) { + ctx->cc = ibv_create_comp_channel(event->id->verbs); + if (!ctx->cc) { + err("%s(%s), ibv_create_comp_channel failed\n", __func__, ctx->ops_name); + goto connect_err; + } + } + ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); + if (!ctx->cq) { + err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); + goto connect_err; + } + if (!ctx->cq_poll_only) { + ret = ibv_req_notify_cq(ctx->cq, 0); + if (ret) { + err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); + goto connect_err; + } + } + struct ibv_qp_init_attr init_qp_attr = { + .cap.max_send_wr = ctx->buffer_cnt * 2, + .cap.max_recv_wr = ctx->buffer_cnt * 2, + .cap.max_send_sge = 1, + .cap.max_recv_sge = 1, + .cap.max_inline_data = sizeof(struct mt_rdma_message), + .sq_sig_all = 0, + .send_cq = ctx->cq, + .recv_cq = ctx->cq, + .qp_type = IBV_QPT_RC, + }; + ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); if (ret) { - err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); + err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); goto connect_err; } - } - struct ibv_qp_init_attr init_qp_attr = { - .cap.max_send_wr = ctx->buffer_cnt * 2, - .cap.max_recv_wr = ctx->buffer_cnt * 2, - .cap.max_send_sge = 1, - .cap.max_recv_sge = 1, - .cap.max_inline_data = sizeof(struct mt_rdma_message), - .sq_sig_all = 0, - .send_cq = ctx->cq, - .recv_cq = ctx->cq, - .qp_type = IBV_QPT_RC, - }; - ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); - if (ret) { - err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); - goto connect_err; - } - ctx->qp = event->id->qp; - ret = rdma_rx_init_mrs(ctx); - if (ret) { - err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); - goto connect_err; - } - struct rdma_conn_param conn_param = { - .initiator_depth = 1, - .responder_resources = 1, - .rnr_retry_count = 7 /* infinite retry */, - }; - ret = rdma_connect(event->id, &conn_param); - if (ret) { - err("%s(%s), rdma_connect failed\n", __func__, ctx->ops_name); - goto connect_err; - } - break; - case RDMA_CM_EVENT_ESTABLISHED: - for (uint16_t i = 0; i < ctx->buffer_cnt; i++) { /* start receiving */ - struct mt_rdma_message *msg = &ctx->recv_msgs[i]; - ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), - ctx->recv_msgs_mr); + ctx->qp = event->id->qp; + ret = rdma_rx_init_mrs(ctx); if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); goto connect_err; } - ret = rdma_rx_send_buffer_done(ctx, i); + struct rdma_conn_param conn_param = { + .initiator_depth = 1, + .responder_resources = 1, + .rnr_retry_count = 7 /* infinite retry */, + }; + ret = rdma_connect(event->id, &conn_param); if (ret) { - err("%s(%s), rdma_rx_send_buffer_done failed\n", __func__, - ctx->ops_name); + err("%s(%s), rdma_connect failed\n", __func__, ctx->ops_name); goto connect_err; } - } - ctx->connected = true; - ctx->cq_poll_stop = false; - ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_rx_cq_poll_thread, - ctx); - if (ret) { - err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); + break; + case RDMA_CM_EVENT_ESTABLISHED: + for (uint16_t i = 0; i < ctx->buffer_cnt; i++) { /* start receiving */ + struct mt_rdma_message *msg = &ctx->recv_msgs[i]; + ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); + if (ret) { + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); + goto connect_err; + } + ret = rdma_rx_send_buffer_done(ctx, i); + if (ret) { + err("%s(%s), rdma_rx_send_buffer_done failed\n", __func__, ctx->ops_name); + goto connect_err; + } + } + ctx->connected = true; + ctx->cq_poll_stop = false; + ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_rx_cq_poll_thread, ctx); + if (ret) { + err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); + goto connect_err; + } + info("%s(%s), connected\n", __func__, ctx->ops_name); + break; + case RDMA_CM_EVENT_DISCONNECTED: + info("%s(%s), TX disconnected.\n", __func__, ctx->ops_name); + ctx->connected = false; + ctx->cq_poll_stop = true; + ctx->connect_stop = true; + /* todo: handle resources clearing and notifying */ + break; + default: + err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, + rdma_event_str(event->event), event->status); goto connect_err; - } - info("%s(%s), connected\n", __func__, ctx->ops_name); - break; - case RDMA_CM_EVENT_DISCONNECTED: - info("%s(%s), TX disconnected.\n", __func__, ctx->ops_name); - ctx->connected = false; - ctx->cq_poll_stop = true; - ctx->connect_stop = true; - /* todo: handle resources clearing and notifying */ - break; - default: - err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, - rdma_event_str(event->event), event->status); - goto connect_err; } rdma_ack_cm_event(event); } @@ -398,8 +386,7 @@ struct mtl_rdma_buffer *mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle) { return NULL; } -int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, - struct mtl_rdma_buffer *buffer) { +int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, struct mtl_rdma_buffer *buffer) { struct mt_rdma_rx_ctx *ctx = handle; if (!ctx->connected) { return -EIO; @@ -407,12 +394,10 @@ int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, for (int i = 0; i < ctx->buffer_cnt; i++) { struct mt_rdma_rx_buffer *rx_buffer = &ctx->rx_buffers[i]; - if (&rx_buffer->buffer != buffer) - continue; + if (&rx_buffer->buffer != buffer) continue; pthread_mutex_lock(&rx_buffer->lock); if (rx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION) { - err("%s(%s), buffer %p not in consumption\n", __func__, ctx->ops_name, - buffer); + err("%s(%s), buffer %p not in consumption\n", __func__, ctx->ops_name, buffer); pthread_mutex_unlock(&rx_buffer->lock); return -EIO; } @@ -437,8 +422,8 @@ int mtl_rdma_rx_free(mtl_rdma_rx_handle handle) { ctx->cq_poll_thread = 0; /* print cq poll stat */ - dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, - ctx->ops_name, ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); + dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, ctx->ops_name, + ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); } if (ctx->connect_thread) { @@ -465,8 +450,7 @@ int mtl_rdma_rx_free(mtl_rdma_rx_handle handle) { return 0; } -mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, - struct mtl_rdma_rx_ops *ops) { +mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, struct mtl_rdma_rx_ops *ops) { int ret = 0; struct mt_rdma_rx_ctx *ctx = calloc(1, sizeof(*ctx)); if (!ctx) { diff --git a/rdma/mt_rdma_tx.c b/rdma/mt_rdma_tx.c index a9474adc4..088e48424 100644 --- a/rdma/mt_rdma_tx.c +++ b/rdma/mt_rdma_tx.c @@ -29,19 +29,17 @@ static int rdma_tx_init_mrs(struct mt_rdma_tx_ctx *ctx) { tx_buffer->mr = mr; } - struct ibv_mr *mr = ibv_reg_mr( - ctx->pd, ctx->recv_msgs, ctx->buffer_cnt * sizeof(struct mt_rdma_message), - IBV_ACCESS_LOCAL_WRITE); + struct ibv_mr *mr = ibv_reg_mr(ctx->pd, ctx->recv_msgs, + ctx->buffer_cnt * sizeof(struct mt_rdma_message), + IBV_ACCESS_LOCAL_WRITE); if (!mr) { - err("%s(%s), ibv_reg_mr receive messages failed\n", __func__, - ctx->ops_name); + err("%s(%s), ibv_reg_mr receive messages failed\n", __func__, ctx->ops_name); rdma_tx_uinit_mrs(ctx); return -ENOMEM; } ctx->recv_msgs_mr = mr; - mr = ibv_reg_mr(ctx->pd, ctx->meta_region, - ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, + mr = ibv_reg_mr(ctx->pd, ctx->meta_region, ctx->buffer_cnt * MT_RDMA_MSG_MAX_SIZE, IBV_ACCESS_LOCAL_WRITE | IBV_ACCESS_REMOTE_WRITE); if (!mr) { err("%s(%s), ibv_reg_mr meta region failed\n", __func__, ctx->ops_name); @@ -94,9 +92,8 @@ static int rdma_tx_alloc_buffers(struct mt_rdma_tx_ctx *ctx) { for (int i = 0; i < ctx->buffer_cnt; i++) { struct mt_rdma_tx_buffer *tx_buffer = &ctx->tx_buffers[i]; tx_buffer->idx = i; - tx_buffer->status = - MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION; /* need to receive done form rx to - start */ + tx_buffer->status = MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION; /* need to receive done form + rx to start */ tx_buffer->ref_count = 1; tx_buffer->buffer.addr = ops->buffers[i]; tx_buffer->buffer.capacity = ops->buffer_capacity; @@ -107,76 +104,70 @@ static int rdma_tx_alloc_buffers(struct mt_rdma_tx_ctx *ctx) { return 0; } -static int rdma_tx_handle_wc_recv(struct mt_rdma_tx_ctx *ctx, - struct ibv_wc *wc) { +static int rdma_tx_handle_wc_recv(struct mt_rdma_tx_ctx *ctx, struct ibv_wc *wc) { int ret = 0; uint16_t idx = 0; struct mt_rdma_tx_buffer *tx_buffer = NULL; struct mtl_rdma_tx_ops *ops = &ctx->ops; struct mt_rdma_message *msg = (struct mt_rdma_message *)wc->wr_id; if (msg->magic != MT_RDMA_MSG_MAGIC) { - err("%s(%s), received invalid magic %u\n", __func__, ctx->ops_name, - msg->magic); + err("%s(%s), received invalid magic %u\n", __func__, ctx->ops_name, msg->magic); return -EINVAL; } switch (msg->type) { - case MT_RDMA_MSG_BUFFER_DONE: - idx = msg->buf_done.buf_idx; - dbg("%s(%s), received buffer %u done message, seq %u\n", __func__, - ctx->ops_name, idx, msg->buf_done.seq_num); - tx_buffer = &ctx->tx_buffers[idx]; - pthread_mutex_lock(&tx_buffer->lock); - if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION) { - err("%s(%s), received buffer done message with invalid status %d\n", - __func__, ctx->ops_name, tx_buffer->status); + case MT_RDMA_MSG_BUFFER_DONE: + idx = msg->buf_done.buf_idx; + dbg("%s(%s), received buffer %u done message, seq %u\n", __func__, ctx->ops_name, + idx, msg->buf_done.seq_num); + tx_buffer = &ctx->tx_buffers[idx]; + pthread_mutex_lock(&tx_buffer->lock); + if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION) { + err("%s(%s), received buffer done message with invalid status %d\n", __func__, + ctx->ops_name, tx_buffer->status); + pthread_mutex_unlock(&tx_buffer->lock); + return -EINVAL; + } + tx_buffer->remote_buffer = msg->buf_done.remote_buffer; + tx_buffer->ref_count--; + if (tx_buffer->ref_count == 0) { + tx_buffer->status = MT_RDMA_BUFFER_STATUS_FREE; + if (ops->notify_buffer_done) + ops->notify_buffer_done(ops->priv, &tx_buffer->buffer); + } pthread_mutex_unlock(&tx_buffer->lock); - return -EINVAL; - } - tx_buffer->remote_buffer = msg->buf_done.remote_buffer; - tx_buffer->ref_count--; - if (tx_buffer->ref_count == 0) { - tx_buffer->status = MT_RDMA_BUFFER_STATUS_FREE; - if (ops->notify_buffer_done) - ops->notify_buffer_done(ops->priv, &tx_buffer->buffer); - } - pthread_mutex_unlock(&tx_buffer->lock); - ctx->stat_buffer_acked++; - break; + ctx->stat_buffer_acked++; + break; - default: - err("%s(%s), received unknown message type %d\n", __func__, ctx->ops_name, - msg->type); - return -EIO; + default: + err("%s(%s), received unknown message type %d\n", __func__, ctx->ops_name, + msg->type); + return -EIO; } ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, strerror(errno)); return -EIO; } return 0; } -static int rdma_tx_handle_wc_write(struct mt_rdma_tx_ctx *ctx, - struct ibv_wc *wc) { +static int rdma_tx_handle_wc_write(struct mt_rdma_tx_ctx *ctx, struct ibv_wc *wc) { struct mtl_rdma_tx_ops *ops = &ctx->ops; struct mt_rdma_tx_buffer *tx_buffer = (struct mt_rdma_tx_buffer *)wc->wr_id; pthread_mutex_lock(&tx_buffer->lock); if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_TRANSMISSION) { - err("%s(%s), buffer write done with invalid status %d\n", __func__, - ctx->ops_name, tx_buffer->status); + err("%s(%s), buffer write done with invalid status %d\n", __func__, ctx->ops_name, + tx_buffer->status); pthread_mutex_unlock(&tx_buffer->lock); return -EINVAL; } - dbg("%s(%s), buffer %d write done\n", __func__, ctx->ops_name, - tx_buffer->idx); + dbg("%s(%s), buffer %d write done\n", __func__, ctx->ops_name, tx_buffer->idx); tx_buffer->status = MT_RDMA_BUFFER_STATUS_IN_CONSUMPTION; tx_buffer->ref_count++; - if (ops->notify_buffer_sent) - ops->notify_buffer_sent(ops->priv, &tx_buffer->buffer); + if (ops->notify_buffer_sent) ops->notify_buffer_sent(ops->priv, &tx_buffer->buffer); pthread_mutex_unlock(&tx_buffer->lock); ctx->stat_buffer_sent++; return 0; @@ -192,13 +183,13 @@ static int rdma_tx_handle_wc(struct mt_rdma_tx_ctx *ctx, struct ibv_wc *wc) { } switch (wc->opcode) { - case IBV_WC_RECV: - return rdma_tx_handle_wc_recv(ctx, wc); - case IBV_WC_RDMA_WRITE: - return rdma_tx_handle_wc_write(ctx, wc); - default: - err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); - return -EIO; + case IBV_WC_RECV: + return rdma_tx_handle_wc_recv(ctx, wc); + case IBV_WC_RDMA_WRITE: + return rdma_tx_handle_wc_write(ctx, wc); + default: + err("%s(%s), unexpected opcode: %d\n", __func__, ctx->ops_name, wc->opcode); + return -EIO; } } @@ -242,10 +233,8 @@ static void *rdma_tx_cq_poll_thread(void *arg) { } while (ibv_poll_cq(cq, 1, &wc)) { - if (ctx->cq_poll_stop) - break; - if (rdma_tx_handle_wc(ctx, &wc)) - goto out; + if (ctx->cq_poll_stop) break; + if (rdma_tx_handle_wc(ctx, &wc)) goto out; ctx->stat_cq_poll_done++; } @@ -271,8 +260,7 @@ static void *rdma_tx_connect_thread(void *arg) { while (!ctx->connect_stop) { ret = poll(&pfd, 1, 200); if (ret < 0) { - err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), poll failed: %s\n", __func__, ctx->ops_name, strerror(errno)); goto connect_err; } else if (ret == 0) { /* timeout */ @@ -281,100 +269,97 @@ static void *rdma_tx_connect_thread(void *arg) { ret = rdma_get_cm_event(ctx->ec, &event); if (!ret) { switch (event->event) { - case RDMA_CM_EVENT_CONNECT_REQUEST: - ctx->pd = ibv_alloc_pd(event->id->verbs); - if (!ctx->pd) { - err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ctx->cc = ibv_create_comp_channel(event->id->verbs); - if (!ctx->cc) { - err("%s(%s), ibv_create_comp_channel failed\n", __func__, - ctx->ops_name); + case RDMA_CM_EVENT_CONNECT_REQUEST: + ctx->pd = ibv_alloc_pd(event->id->verbs); + if (!ctx->pd) { + err("%s(%s), ibv_alloc_pd failed\n", __func__, ctx->ops_name); goto connect_err; } - } - ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); - if (!ctx->cq) { - err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); - goto connect_err; - } - if (!ctx->cq_poll_only) { - ret = ibv_req_notify_cq(ctx->cq, 0); + if (!ctx->cq_poll_only) { + ctx->cc = ibv_create_comp_channel(event->id->verbs); + if (!ctx->cc) { + err("%s(%s), ibv_create_comp_channel failed\n", __func__, ctx->ops_name); + goto connect_err; + } + } + ctx->cq = ibv_create_cq(event->id->verbs, 10, ctx, ctx->cc, 0); + if (!ctx->cq) { + err("%s(%s), ibv_create_cq failed\n", __func__, ctx->ops_name); + goto connect_err; + } + if (!ctx->cq_poll_only) { + ret = ibv_req_notify_cq(ctx->cq, 0); + if (ret) { + err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); + goto connect_err; + } + } + struct ibv_qp_init_attr init_qp_attr = { + .cap.max_send_wr = ctx->buffer_cnt * 2, + .cap.max_recv_wr = ctx->buffer_cnt * 2, + .cap.max_send_sge = 1, + .cap.max_recv_sge = 1, + .cap.max_inline_data = sizeof(struct mt_rdma_message), + .sq_sig_all = 0, + .send_cq = ctx->cq, + .recv_cq = ctx->cq, + .qp_type = IBV_QPT_RC, + }; + ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); if (ret) { - err("%s(%s), ibv_req_notify_cq failed\n", __func__, ctx->ops_name); + err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); goto connect_err; } - } - struct ibv_qp_init_attr init_qp_attr = { - .cap.max_send_wr = ctx->buffer_cnt * 2, - .cap.max_recv_wr = ctx->buffer_cnt * 2, - .cap.max_send_sge = 1, - .cap.max_recv_sge = 1, - .cap.max_inline_data = sizeof(struct mt_rdma_message), - .sq_sig_all = 0, - .send_cq = ctx->cq, - .recv_cq = ctx->cq, - .qp_type = IBV_QPT_RC, - }; - ret = rdma_create_qp(event->id, ctx->pd, &init_qp_attr); - if (ret) { - err("%s(%s), rdma_create_qp failed\n", __func__, ctx->ops_name); - goto connect_err; - } - ctx->qp = event->id->qp; + ctx->qp = event->id->qp; - ret = rdma_tx_init_mrs(ctx); - if (ret) { - err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); - goto connect_err; - } - - struct rdma_conn_param conn_param = { - .initiator_depth = 1, - .responder_resources = 1, - .rnr_retry_count = 7, - }; - ret = rdma_accept(event->id, &conn_param); - if (ret) { - err("%s(%s), rdma_accept failed\n", __func__, ctx->ops_name); - goto connect_err; - } - ctx->id = event->id; - break; - case RDMA_CM_EVENT_ESTABLISHED: - for (int i = 0; i < ctx->buffer_cnt; i++) { /* post receive done msg */ - struct mt_rdma_message *msg = &ctx->recv_msgs[i]; - ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), - ctx->recv_msgs_mr); + ret = rdma_tx_init_mrs(ctx); if (ret) { - err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, - strerror(errno)); + err("%s(%s), rdma_tx_init_mrs failed\n", __func__, ctx->ops_name); goto connect_err; } - } - ctx->connected = true; - ctx->cq_poll_stop = false; - ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_tx_cq_poll_thread, - ctx); - if (ret) { - err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); + + struct rdma_conn_param conn_param = { + .initiator_depth = 1, + .responder_resources = 1, + .rnr_retry_count = 7, + }; + ret = rdma_accept(event->id, &conn_param); + if (ret) { + err("%s(%s), rdma_accept failed\n", __func__, ctx->ops_name); + goto connect_err; + } + ctx->id = event->id; + break; + case RDMA_CM_EVENT_ESTABLISHED: + for (int i = 0; i < ctx->buffer_cnt; i++) { /* post receive done msg */ + struct mt_rdma_message *msg = &ctx->recv_msgs[i]; + ret = rdma_post_recv(ctx->id, msg, msg, sizeof(*msg), ctx->recv_msgs_mr); + if (ret) { + err("%s(%s), rdma_post_recv failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); + goto connect_err; + } + } + ctx->connected = true; + ctx->cq_poll_stop = false; + ret = pthread_create(&ctx->cq_poll_thread, NULL, rdma_tx_cq_poll_thread, ctx); + if (ret) { + err("%s(%s), pthread_create failed\n", __func__, ctx->ops_name); + goto connect_err; + } + info("%s(%s), connected\n", __func__, ctx->ops_name); + break; + case RDMA_CM_EVENT_DISCONNECTED: + info("%s(%s), RX disconnected.\n", __func__, ctx->ops_name); + ctx->connected = false; + ctx->cq_poll_stop = true; + ctx->connect_stop = true; + /* todo: handle resources clearing and notifying */ + break; + default: + err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, + rdma_event_str(event->event), event->status); goto connect_err; - } - info("%s(%s), connected\n", __func__, ctx->ops_name); - break; - case RDMA_CM_EVENT_DISCONNECTED: - info("%s(%s), RX disconnected.\n", __func__, ctx->ops_name); - ctx->connected = false; - ctx->cq_poll_stop = true; - ctx->connect_stop = true; - /* todo: handle resources clearing and notifying */ - break; - default: - err("%s(%s), event: %s, error: %d\n", __func__, ctx->ops_name, - rdma_event_str(event->event), event->status); - goto connect_err; } rdma_ack_cm_event(event); } @@ -410,8 +395,7 @@ struct mtl_rdma_buffer *mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle) { return NULL; } -int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, - struct mtl_rdma_buffer *buffer) { +int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, struct mtl_rdma_buffer *buffer) { struct mt_rdma_tx_ctx *ctx = handle; if (!ctx->connected) { return -EIO; @@ -429,23 +413,20 @@ int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, for (int i = 0; i < ctx->buffer_cnt; i++) { struct mt_rdma_tx_buffer *tx_buffer = &ctx->tx_buffers[i]; - if (&tx_buffer->buffer != buffer) - continue; + if (&tx_buffer->buffer != buffer) continue; pthread_mutex_lock(&tx_buffer->lock); if (tx_buffer->status != MT_RDMA_BUFFER_STATUS_IN_PRODUCTION) { - err("%s(%s), buffer %p is not in production\n", __func__, ctx->ops_name, - buffer); + err("%s(%s), buffer %p is not in production\n", __func__, ctx->ops_name, buffer); pthread_mutex_unlock(&tx_buffer->lock); return -EIO; } /* write buffer to rx immediately */ - int ret = - rdma_post_write(ctx->id, tx_buffer, buffer->addr, buffer->size, - tx_buffer->mr, 0, tx_buffer->remote_buffer.remote_addr, - tx_buffer->remote_buffer.remote_key); + int ret = rdma_post_write(ctx->id, tx_buffer, buffer->addr, buffer->size, + tx_buffer->mr, 0, tx_buffer->remote_buffer.remote_addr, + tx_buffer->remote_buffer.remote_key); if (ret) { err("%s(%s), rdma_post_write failed: %s\n", __func__, ctx->ops_name, strerror(errno)); @@ -455,16 +436,15 @@ int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, /* write metadata to rx with imm data */ memcpy(tx_buffer->meta, buffer->user_meta, buffer->user_meta_size); - uint32_t imm_data = htonl((uint32_t)tx_buffer->idx << 16 | - tx_buffer->buffer.user_meta_size); - ret = mt_rdma_post_write_imm( - ctx->id, tx_buffer, tx_buffer->meta, buffer->user_meta_size, - ctx->meta_mr, IBV_SEND_SIGNALED, - tx_buffer->remote_buffer.remote_meta_addr, - tx_buffer->remote_buffer.remote_meta_key, imm_data); + uint32_t imm_data = + htonl((uint32_t)tx_buffer->idx << 16 | tx_buffer->buffer.user_meta_size); + ret = mt_rdma_post_write_imm(ctx->id, tx_buffer, tx_buffer->meta, + buffer->user_meta_size, ctx->meta_mr, IBV_SEND_SIGNALED, + tx_buffer->remote_buffer.remote_meta_addr, + tx_buffer->remote_buffer.remote_meta_key, imm_data); if (ret) { - err("%s(%s), mt_rdma_post_write_imm failed: %s\n", __func__, - ctx->ops_name, strerror(errno)); + err("%s(%s), mt_rdma_post_write_imm failed: %s\n", __func__, ctx->ops_name, + strerror(errno)); pthread_mutex_unlock(&tx_buffer->lock); return -EIO; } @@ -492,8 +472,8 @@ int mtl_rdma_tx_free(mtl_rdma_tx_handle handle) { ctx->cq_poll_thread = 0; /* print cq poll stat */ - dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, - ctx->ops_name, ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); + dbg("%s(%s), cq poll done: %lu, cq poll empty: %lu\n", __func__, ctx->ops_name, + ctx->stat_cq_poll_done, ctx->stat_cq_poll_empty); } if (ctx->connect_thread) { @@ -520,8 +500,7 @@ int mtl_rdma_tx_free(mtl_rdma_tx_handle handle) { return 0; } -mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, - struct mtl_rdma_tx_ops *ops) { +mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, struct mtl_rdma_tx_ops *ops) { int ret = 0; struct mt_rdma_tx_ctx *ctx = calloc(1, sizeof(*ctx)); if (!ctx) { @@ -553,8 +532,7 @@ mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, } ctx->listen_id = listen_id; - struct rdma_addrinfo hints = {.ai_port_space = RDMA_PS_TCP, - .ai_flags = RAI_PASSIVE}; + struct rdma_addrinfo hints = {.ai_port_space = RDMA_PS_TCP, .ai_flags = RAI_PASSIVE}; struct rdma_addrinfo *rai; ret = rdma_getaddrinfo(ops->ip, ops->port, &hints, &rai); if (ret) { diff --git a/rdma/mtl_rdma_api.h b/rdma/mtl_rdma_api.h index 34edaafee..ebdd44e9f 100644 --- a/rdma/mtl_rdma_api.h +++ b/rdma/mtl_rdma_api.h @@ -116,8 +116,7 @@ struct mtl_rdma_tx_ops { * - NULL on error. * - Otherwise, the handle to the TX session. */ -mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, - struct mtl_rdma_tx_ops *ops); +mtl_rdma_tx_handle mtl_rdma_tx_create(mtl_rdma_handle mrh, struct mtl_rdma_tx_ops *ops); /** * Free the TX session. @@ -154,8 +153,7 @@ struct mtl_rdma_buffer *mtl_rdma_tx_get_buffer(mtl_rdma_tx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, - struct mtl_rdma_buffer *buffer); +int mtl_rdma_tx_put_buffer(mtl_rdma_tx_handle handle, struct mtl_rdma_buffer *buffer); /** The structure describing how to create an RX session. */ struct mtl_rdma_rx_ops { @@ -195,8 +193,7 @@ struct mtl_rdma_rx_ops { * - NULL on error. * - Otherwise, the handle to the RX session. */ -mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, - struct mtl_rdma_rx_ops *ops); +mtl_rdma_rx_handle mtl_rdma_rx_create(mtl_rdma_handle mrh, struct mtl_rdma_rx_ops *ops); /** * Free the RX session. @@ -233,8 +230,7 @@ struct mtl_rdma_buffer *mtl_rdma_rx_get_buffer(mtl_rdma_rx_handle handle); * - 0 if successful. * - <0: Error code if put fail. */ -int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, - struct mtl_rdma_buffer *buffer); +int mtl_rdma_rx_put_buffer(mtl_rdma_rx_handle handle, struct mtl_rdma_buffer *buffer); /** MTL RDMA init flag */ enum mtl_rdma_init_flag { diff --git a/tests/src/cvt_test.cpp b/tests/src/cvt_test.cpp index 662fbc5b6..71b0fa383 100644 --- a/tests/src/cvt_test.cpp +++ b/tests/src/cvt_test.cpp @@ -11,10 +11,9 @@ TEST(Cvt, simd_level) { info("simd level by cpu: %d(%s)\n", cpu_level, name); } -static void -test_cvt_rfc4175_422be10_to_yuv422p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be10_to_yuv422p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_be *pg = @@ -26,25 +25,20 @@ test_cvt_rfc4175_422be10_to_yuv422p10le(int w, int h, if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p10_u16) st_test_free(p10_u16); return; } st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_yuv422p10le_simd(pg, p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), w, - h, cvt_level); + ret = st20_rfc4175_422be10_to_yuv422p10le_simd( + pg, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), - pg_2, w, h, back_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -81,8 +75,8 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512) { } TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_vbmi) { - test_cvt_rfc4175_422be10_to_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le(1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_yuv422p10le(722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_yuv422p10le(722, 111, MTL_SIMD_LEVEL_NONE, @@ -96,17 +90,15 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_vbmi) { } } -static void -test_cvt_rfc4175_422be10_to_yuv422p10le_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be10_to_yuv422p10le_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_10_pg2_be *pg = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, - MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_2 = (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); @@ -114,12 +106,9 @@ test_cvt_rfc4175_422be10_to_yuv422p10le_dma(mtl_udma_handle dma, int w, int h, if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - mtl_hp_free(st, pg); - if (pg_2) - st_test_free(pg_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) mtl_hp_free(st, pg); + if (pg_2) st_test_free(pg_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -130,9 +119,8 @@ test_cvt_rfc4175_422be10_to_yuv422p10le_dma(mtl_udma_handle dma, int w, int h, (p10_u16 + w * h * 3 / 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), - pg_2, w, h, back_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -146,11 +134,10 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } @@ -159,11 +146,10 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); mtl_udma_free(dma); } @@ -172,21 +158,20 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); } mtl_udma_free(dma); @@ -196,31 +181,28 @@ TEST(Cvt, rfc4175_422be10_to_yuv422p10le_avx512_vbmi_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_yuv422p10le_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_yuv422p10le_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } -static void -test_cvt_yuv422p10le_to_rfc4175_422be10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_yuv422p10le_to_rfc4175_422be10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_be *pg = @@ -231,12 +213,9 @@ test_cvt_yuv422p10le_to_rfc4175_422be10(int w, int h, if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p10_u16_2) - st_test_free(p10_u16_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (p10_u16_2) st_test_free(p10_u16_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -244,14 +223,12 @@ test_cvt_yuv422p10le_to_rfc4175_422be10(int w, int h, p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), pg, - w, h, cvt_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_yuv422p10le_simd( - pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, - back_level); + pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p10_u16, p10_u16_2, planar_size)); @@ -288,8 +265,8 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512) { } TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_vbmi) { - test_cvt_yuv422p10le_to_rfc4175_422be10( - 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_yuv422p10le_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_yuv422p10le_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_NONE, @@ -303,10 +280,9 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_vbmi) { } } -static void -test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; struct st_tests_context *ctx = st_test_ctx(); @@ -320,12 +296,9 @@ test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p10_u16_2) - st_test_free(p10_u16_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (p10_u16_2) st_test_free(p10_u16_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -340,8 +313,7 @@ test_cvt_yuv422p10le_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_yuv422p10le_simd( - pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, - back_level); + pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 3 / 2), w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p10_u16, p10_u16_2, planar_size)); @@ -355,11 +327,10 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } @@ -368,11 +339,10 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); mtl_udma_free(dma); } @@ -381,21 +351,20 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); } mtl_udma_free(dma); @@ -405,31 +374,28 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422be10_avx512_vbmi_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_yuv422p10le_to_rfc4175_422be10_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_yuv422p10le_to_rfc4175_422be10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } -static void -test_cvt_rfc4175_422le10_to_yuv422p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422le10_to_yuv422p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_le *pg = @@ -441,12 +407,9 @@ test_cvt_rfc4175_422le10_to_yuv422p10le(int w, int h, if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -456,8 +419,8 @@ test_cvt_rfc4175_422le10_to_yuv422p10le(int w, int h, (p10_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422le10( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_2, w, h); + ret = st20_yuv422p10le_to_rfc4175_422le10(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), pg_2, w, h); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -477,10 +440,9 @@ TEST(Cvt, rfc4175_422le10_to_yuv422p10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_yuv422p10le_to_rfc4175_422le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_yuv422p10le_to_rfc4175_422le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_le *pg = @@ -491,12 +453,9 @@ test_cvt_yuv422p10le_to_rfc4175_422le10(int w, int h, if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p10_u16_2) - st_test_free(p10_u16_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (p10_u16_2) st_test_free(p10_u16_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -504,8 +463,8 @@ test_cvt_yuv422p10le_to_rfc4175_422le10(int w, int h, p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - ret = st20_yuv422p10le_to_rfc4175_422le10( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg, w, h); + ret = st20_yuv422p10le_to_rfc4175_422le10(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), pg, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_yuv422p10le(pg, p10_u16_2, (p10_u16_2 + w * h), @@ -529,9 +488,9 @@ TEST(Cvt, yuv422p10le_to_rfc4175_422le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_422be10_to_422le10(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be10_to_422le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -543,12 +502,9 @@ test_cvt_rfc4175_422be10_to_422le10(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -568,8 +524,7 @@ test_cvt_rfc4175_422be10_to_422le10(int w, int h, enum mtl_simd_level cvt_level, } TEST(Cvt, rfc4175_422be10_to_422le10) { - test_cvt_rfc4175_422be10_to_422le10(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_422le10_scalar) { @@ -580,16 +535,12 @@ TEST(Cvt, rfc4175_422be10_to_422le10_scalar) { TEST(Cvt, rfc4175_422be10_to_422le10_avx2) { test_cvt_rfc4175_422be10_to_422le10(1920, 1080, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, - MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422be10_to_422le10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_422le10(w, h, MTL_SIMD_LEVEL_AVX2, - MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422be10_to_422le10(w, h, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); } } @@ -625,17 +576,15 @@ TEST(Cvt, rfc4175_422be10_to_422le10_avx512_vbmi) { } } -static void -test_cvt_rfc4175_422be10_to_422le10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be10_to_422le10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_10_pg2_be *pg_be = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, - MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_le *pg_le = (struct st20_rfc4175_422_10_pg2_le *)st_test_zmalloc(fb_pg2_size); struct st20_rfc4175_422_10_pg2_be *pg_be_2 = @@ -643,19 +592,16 @@ test_cvt_rfc4175_422be10_to_422le10_dma(mtl_udma_handle dma, int w, int h, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - mtl_hp_free(st, pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) mtl_hp_free(st, pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_422le10_simd_dma( - dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_le, w, h, cvt_level); + ret = st20_rfc4175_422be10_to_422le10_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), + pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be_2, w, h, back_level); @@ -672,13 +618,12 @@ TEST(Cvt, rfc4175_422be10_to_422le10_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422be10_to_422le10_dma( - dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } @@ -686,8 +631,7 @@ TEST(Cvt, rfc4175_422be10_to_422le10_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -698,11 +642,10 @@ TEST(Cvt, rfc4175_422be10_to_422le10_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_422le10_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, @@ -722,30 +665,28 @@ TEST(Cvt, rfc4175_422be10_to_422le10_avx512_vbmi_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_422le10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_422le10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_422le10_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); } -static void -test_cvt_rfc4175_422le10_to_422be10(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422le10_to_422be10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_le *pg_le = @@ -757,12 +698,9 @@ test_cvt_rfc4175_422le10_to_422be10(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_le_2) - st_test_free(pg_le_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_le_2) st_test_free(pg_le_2); return; } @@ -782,10 +720,9 @@ test_cvt_rfc4175_422le10_to_422be10(int w, int h, enum mtl_simd_level cvt_level, st_test_free(pg_le_2); } -static void -test_cvt_rfc4175_422le10_to_422be10_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422le10_to_422be10_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_le *pg_le = @@ -797,19 +734,15 @@ test_cvt_rfc4175_422le10_to_422be10_2(int w, int h, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_422be10_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -836,16 +769,12 @@ TEST(Cvt, rfc4175_422le10_to_422be10_scalar) { TEST(Cvt, rfc4175_422le10_to_422be10_avx2) { test_cvt_rfc4175_422le10_to_422be10(1920, 1080, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, - MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX2); - test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422le10_to_422be10(722, 111, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422le10_to_422be10(w, h, MTL_SIMD_LEVEL_AVX2, - MTL_SIMD_LEVEL_AVX2); + test_cvt_rfc4175_422le10_to_422be10(w, h, MTL_SIMD_LEVEL_AVX2, MTL_SIMD_LEVEL_AVX2); } } @@ -881,17 +810,15 @@ TEST(Cvt, rfc4175_422le10_to_422be10_vbmi) { } } -static void -test_cvt_rfc4175_422le10_to_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422le10_to_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_10_pg2_le *pg_le = - (struct st20_rfc4175_422_10_pg2_le *)mtl_hp_zmalloc(st, fb_pg2_size, - MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_le *)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be = (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); struct st20_rfc4175_422_10_pg2_le *pg_le_2 = @@ -899,19 +826,16 @@ test_cvt_rfc4175_422le10_to_422be10_dma(mtl_udma_handle dma, int w, int h, if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - mtl_hp_free(st, pg_le); - if (pg_le_2) - st_test_free(pg_le_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) mtl_hp_free(st, pg_le); + if (pg_le_2) st_test_free(pg_le_2); return; } st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le10_to_422be10_simd_dma( - dma, pg_le, mtl_hp_virt2iova(st, pg_le), pg_be, w, h, cvt_level); + ret = st20_rfc4175_422le10_to_422be10_simd_dma(dma, pg_le, mtl_hp_virt2iova(st, pg_le), + pg_be, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_422le10_simd(pg_be, pg_le_2, w, h, back_level); @@ -928,13 +852,12 @@ TEST(Cvt, rfc4175_422le10_to_422be10_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422le10_to_422be10_dma( - dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } @@ -942,8 +865,7 @@ TEST(Cvt, rfc4175_422le10_to_422be10_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -954,11 +876,10 @@ TEST(Cvt, rfc4175_422le10_to_422be10_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422le10_to_422be10_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, @@ -978,22 +899,20 @@ TEST(Cvt, rfc4175_422le10_to_422be10_avx512_vbmi_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422le10_to_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422le10_to_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422le10_to_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422le10_to_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422le10_to_422be10_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422le10_to_422be10_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); @@ -1033,12 +952,9 @@ static void test_cvt_rfc4175_422be10_to_422le8(int w, int h, if (!pg_10 || !pg_8 || !pg_8_2) { EXPECT_EQ(0, 1); - if (pg_10) - st_test_free(pg_10); - if (pg_8) - st_test_free(pg_8); - if (pg_8_2) - st_test_free(pg_8_2); + if (pg_10) st_test_free(pg_10); + if (pg_8) st_test_free(pg_8); + if (pg_8_2) st_test_free(pg_8_2); return; } @@ -1055,8 +971,7 @@ static void test_cvt_rfc4175_422be10_to_422le8(int w, int h, } TEST(Cvt, rfc4175_422be10_to_422le8) { - test_cvt_rfc4175_422be10_to_422le8(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le8(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_422le8_scalar) { @@ -1096,18 +1011,16 @@ TEST(Cvt, rfc4175_422be10_to_422le8_avx512_vbmi) { } } -static void -test_cvt_rfc4175_422be10_to_422le8_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be10_to_422le8_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size_10 = (size_t)w * h * 5 / 2; size_t fb_pg2_size_8 = (size_t)w * h * 2; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_10_pg2_be *pg_10 = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size_10, - MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size_10, MTL_PORT_P); struct st20_rfc4175_422_8_pg2_le *pg_8 = (struct st20_rfc4175_422_8_pg2_le *)st_test_zmalloc(fb_pg2_size_8); struct st20_rfc4175_422_8_pg2_le *pg_8_2 = @@ -1115,19 +1028,16 @@ test_cvt_rfc4175_422be10_to_422le8_dma(mtl_udma_handle dma, int w, int h, if (!pg_10 || !pg_8 || !pg_8_2) { EXPECT_EQ(0, 1); - if (pg_10) - mtl_hp_free(st, pg_10); - if (pg_8) - st_test_free(pg_8); - if (pg_8_2) - st_test_free(pg_8_2); + if (pg_10) mtl_hp_free(st, pg_10); + if (pg_8) st_test_free(pg_8); + if (pg_8_2) st_test_free(pg_8_2); return; } st_test_rand_data((uint8_t *)pg_8, fb_pg2_size_8, 0); test_cvt_extend_rfc4175_422le8_to_422be10(w, h, pg_8, pg_10); - ret = st20_rfc4175_422be10_to_422le8_simd_dma( - dma, pg_10, mtl_hp_virt2iova(st, pg_10), pg_8_2, w, h, cvt_level); + ret = st20_rfc4175_422be10_to_422le8_simd_dma(dma, pg_10, mtl_hp_virt2iova(st, pg_10), + pg_8_2, w, h, cvt_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_8, pg_8_2, fb_pg2_size_8)); @@ -1141,13 +1051,12 @@ TEST(Cvt, rfc4175_422be10_to_422le8_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422be10_to_422le8_dma( - dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } @@ -1155,8 +1064,7 @@ TEST(Cvt, rfc4175_422be10_to_422le8_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -1167,8 +1075,7 @@ TEST(Cvt, rfc4175_422be10_to_422le8_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -1191,22 +1098,20 @@ TEST(Cvt, rfc4175_422be10_to_422le8_avx512_vbmi_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_422le8_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le8_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le8_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_422le8_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_422le8_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_422le8_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_422le8_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_422le8_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); } mtl_udma_free(dma); @@ -1236,9 +1141,8 @@ static int test_cvt_extend_yuv422p8_to_rfc4175_422be10( return 0; } -static void -test_cvt_rfc4175_422be10_to_yuv422p8(int w, int h, - enum mtl_simd_level cvt_level) { +static void test_cvt_rfc4175_422be10_to_yuv422p8(int w, int h, + enum mtl_simd_level cvt_level) { int ret; size_t fb_pg2_size_10 = (size_t)w * h * 5 / 2; size_t fb_yuv422p8_size = (size_t)w * h * 2; @@ -1249,20 +1153,17 @@ test_cvt_rfc4175_422be10_to_yuv422p8(int w, int h, if (!pg_10 || !p8 || !p8_2) { EXPECT_EQ(0, 1); - if (pg_10) - st_test_free(pg_10); - if (p8) - st_test_free(p8); - if (p8_2) - st_test_free(p8_2); + if (pg_10) st_test_free(pg_10); + if (p8) st_test_free(p8); + if (p8_2) st_test_free(p8_2); return; } st_test_rand_data(p8, fb_yuv422p8_size, 0); - test_cvt_extend_yuv422p8_to_rfc4175_422be10(w, h, p8, p8 + w * h, - p8 + w * h * 3 / 2, pg_10); - ret = st20_rfc4175_422be10_to_yuv422p8_simd( - pg_10, p8_2, p8_2 + w * h, p8_2 + w * h * 3 / 2, w, h, cvt_level); + test_cvt_extend_yuv422p8_to_rfc4175_422be10(w, h, p8, p8 + w * h, p8 + w * h * 3 / 2, + pg_10); + ret = st20_rfc4175_422be10_to_yuv422p8_simd(pg_10, p8_2, p8_2 + w * h, + p8_2 + w * h * 3 / 2, w, h, cvt_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p8, p8_2, fb_yuv422p8_size)); @@ -1318,22 +1219,18 @@ static void test_cvt_rfc4175_422be10_to_yuv420p8(int w, int h) { if (!pg_10 || !p8 || !p8_2) { EXPECT_EQ(0, 1); - if (pg_10) - st_test_free(pg_10); - if (p8) - st_test_free(p8); - if (p8_2) - st_test_free(p8_2); + if (pg_10) st_test_free(pg_10); + if (p8) st_test_free(p8); + if (p8_2) st_test_free(p8_2); return; } st_test_rand_data((uint8_t *)pg_10, fb_pg2_size_10, 0); - ret = st20_rfc4175_422be10_to_yuv420p8_simd( - pg_10, p8, p8 + w * h, p8 + w * h * 5 / 4, w, h, MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_422be10_to_yuv420p8_simd(pg_10, p8, p8 + w * h, p8 + w * h * 5 / 4, + w, h, MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); - ret = st20_rfc4175_422be10_to_yuv420p8_simd(pg_10, p8_2, p8_2 + w * h, - p8_2 + w * h * 5 / 4, w, h, - MTL_SIMD_LEVEL_AVX512); + ret = st20_rfc4175_422be10_to_yuv420p8_simd( + pg_10, p8_2, p8_2 + w * h, p8_2 + w * h * 5 / 4, w, h, MTL_SIMD_LEVEL_AVX512); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p8, p8_2, fb_yuv420p8_size)); @@ -1347,12 +1244,10 @@ TEST(Cvt, rfc4175_422be10_to_yuv420p8) { test_cvt_rfc4175_422be10_to_yuv420p8(1920, 1080); } -static void test_cvt_rfc4175_422le10_to_v210(int w, int h, - enum mtl_simd_level cvt_level, +static void test_cvt_rfc4175_422le10_to_v210(int w, int h, enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = - (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; struct st20_rfc4175_422_10_pg2_le *pg_le = @@ -1363,18 +1258,14 @@ static void test_cvt_rfc4175_422le10_to_v210(int w, int h, if (!pg_le || !pg_le_2 || !pg_v210) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_le_2) - st_test_free(pg_le_2); - if (pg_v210) - st_test_free(pg_v210); + if (pg_le) st_test_free(pg_le); + if (pg_le_2) st_test_free(pg_le_2); + if (pg_v210) st_test_free(pg_v210); return; } st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le, pg_v210, w, h, - cvt_level); + ret = st20_rfc4175_422le10_to_v210_simd((uint8_t *)pg_le, pg_v210, w, h, cvt_level); if (fail_case) EXPECT_NE(0, ret); else @@ -1397,13 +1288,11 @@ static void test_cvt_rfc4175_422le10_to_v210(int w, int h, } TEST(Cvt, rfc4175_422le10_to_v210) { - test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422le10_to_v210_scalar) { - test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422le10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rfc4175_422le10_to_v210_avx512) { @@ -1436,12 +1325,10 @@ TEST(Cvt, rfc4175_422le10_to_v210_avx512_vbmi) { MTL_SIMD_LEVEL_AVX512_VBMI2); } -static void test_cvt_rfc4175_422be10_to_v210(int w, int h, - enum mtl_simd_level cvt_level, +static void test_cvt_rfc4175_422be10_to_v210(int w, int h, enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = - (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -1454,14 +1341,10 @@ static void test_cvt_rfc4175_422be10_to_v210(int w, int h, if (!pg_le || !pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (pg_v210) - st_test_free(pg_v210); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (pg_v210) st_test_free(pg_v210); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -1492,13 +1375,11 @@ static void test_cvt_rfc4175_422be10_to_v210(int w, int h, } TEST(Cvt, rfc4175_422be10_to_v210) { - test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_v210_scalar) { - test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_v210(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rfc4175_422be10_to_v210_avx512) { @@ -1531,20 +1412,17 @@ TEST(Cvt, rfc4175_422be10_to_v210_avx512_vbmi) { MTL_SIMD_LEVEL_AVX512_VBMI2); } -static void -test_cvt_rfc4175_422be10_to_v210_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be10_to_v210_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; - bool fail_case = - (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_10_pg2_be *pg_be = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, - MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be_2 = (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); struct st20_rfc4175_422_10_pg2_le *pg_le = @@ -1553,20 +1431,16 @@ test_cvt_rfc4175_422be10_to_v210_dma(mtl_udma_handle dma, int w, int h, if (!pg_le || !pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - mtl_hp_free(st, pg_be); - if (pg_be_2) - st_test_free(pg_be_2); - if (pg_v210) - st_test_free(pg_v210); - if (pg_le) - st_test_free(pg_le); + if (pg_be) mtl_hp_free(st, pg_be); + if (pg_be_2) st_test_free(pg_be_2); + if (pg_v210) st_test_free(pg_v210); + if (pg_le) st_test_free(pg_le); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_v210_simd_dma( - dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_v210, w, h, cvt_level); + ret = st20_rfc4175_422be10_to_v210_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), + pg_v210, w, h, cvt_level); if (fail_case) EXPECT_NE(0, ret); else @@ -1595,8 +1469,7 @@ TEST(Cvt, rfc4175_422be10_to_v210_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -1608,8 +1481,7 @@ TEST(Cvt, rfc4175_422be10_to_v210_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -1621,8 +1493,7 @@ TEST(Cvt, rfc4175_422be10_to_v210_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -1644,34 +1515,28 @@ TEST(Cvt, rfc4175_422be10_to_v210_avx512_vbmi_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_v210_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); - test_cvt_rfc4175_422be10_to_v210_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_rfc4175_422be10_to_v210_dma(dma, 1921, 1079, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_rfc4175_422be10_to_v210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_v210_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be10_to_v210_dma(dma, 1921, 1079, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); mtl_udma_free(dma); } -static void test_cvt_v210_to_rfc4175_422be10(int w, int h, - enum mtl_simd_level cvt_level, +static void test_cvt_v210_to_rfc4175_422be10(int w, int h, enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = - (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -1682,12 +1547,9 @@ static void test_cvt_v210_to_rfc4175_422be10(int w, int h, if (!pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_v210) - st_test_free(pg_v210); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_v210) st_test_free(pg_v210); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -1716,13 +1578,11 @@ static void test_cvt_v210_to_rfc4175_422be10(int w, int h, } TEST(Cvt, v210_to_rfc4175_422be10) { - test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, v210_to_rfc4175_422be10_scalar) { - test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_v210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } TEST(Cvt, v210_to_rfc4175_422be10_avx512) { @@ -1759,8 +1619,7 @@ static void test_cvt_v210_to_rfc4175_422be10_2(int w, int h, enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; - bool fail_case = - (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -1770,12 +1629,9 @@ static void test_cvt_v210_to_rfc4175_422be10_2(int w, int h, if (!pg_be || !pg_v210 || !pg_v210_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_v210) - st_test_free(pg_v210); - if (pg_v210_2) - st_test_free(pg_v210_2); + if (pg_be) st_test_free(pg_be); + if (pg_v210) st_test_free(pg_v210); + if (pg_v210_2) st_test_free(pg_v210_2); return; } @@ -1804,8 +1660,7 @@ static void test_cvt_v210_to_rfc4175_422be10_2(int w, int h, } TEST(Cvt, v210_to_rfc4175_422be10_2) { - test_cvt_v210_to_rfc4175_422be10_2(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_v210_to_rfc4175_422be10_2(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, v210_to_rfc4175_422be10_2_scalar) { @@ -1843,13 +1698,11 @@ TEST(Cvt, v210_to_rfc4175_422be10_2_vbmi) { MTL_SIMD_LEVEL_AVX512_VBMI2); } -static void -test_cvt_v210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_v210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; - bool fail_case = - (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ + bool fail_case = (w * h % 6); /* do not convert when pg_num is not multiple of 3 */ size_t fb_pg2_size = w * h * 5 / 2; size_t fb_pg2_size_v210 = w * h * 8 / 3; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -1858,17 +1711,13 @@ test_cvt_v210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; - uint8_t *pg_v210 = - (uint8_t *)mtl_hp_zmalloc(st, fb_pg2_size_v210, MTL_PORT_P); + uint8_t *pg_v210 = (uint8_t *)mtl_hp_zmalloc(st, fb_pg2_size_v210, MTL_PORT_P); if (!pg_be || !pg_v210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_v210) - mtl_hp_free(st, pg_v210); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_v210) mtl_hp_free(st, pg_v210); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -1879,8 +1728,8 @@ test_cvt_v210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, else EXPECT_EQ(0, ret); - ret = st20_v210_to_rfc4175_422be10_simd_dma( - dma, pg_v210, mtl_hp_virt2iova(st, pg_v210), pg_be_2, w, h, back_level); + ret = st20_v210_to_rfc4175_422be10_simd_dma(dma, pg_v210, mtl_hp_virt2iova(st, pg_v210), + pg_be_2, w, h, back_level); if (fail_case) EXPECT_NE(0, ret); else @@ -1901,8 +1750,7 @@ TEST(Cvt, v210_to_rfc4175_422be10_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -1914,8 +1762,7 @@ TEST(Cvt, v210_to_rfc4175_422be10_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -1927,8 +1774,7 @@ TEST(Cvt, v210_to_rfc4175_422be10_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -1950,30 +1796,25 @@ TEST(Cvt, v210_to_rfc4175_422be10_vbmi_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_v210_to_rfc4175_422be10_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); - test_cvt_v210_to_rfc4175_422be10_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); - test_cvt_v210_to_rfc4175_422be10_dma(dma, 1921, 1079, - MTL_SIMD_LEVEL_AVX512_VBMI2, + test_cvt_v210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_NONE); + test_cvt_v210_to_rfc4175_422be10_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_v210_to_rfc4175_422be10_dma(dma, 1921, 1079, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); mtl_udma_free(dma); } -static void test_cvt_rfc4175_422be10_to_y210(int w, int h, - enum mtl_simd_level cvt_level, +static void test_cvt_rfc4175_422be10_to_y210(int w, int h, enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; @@ -1986,12 +1827,9 @@ static void test_cvt_rfc4175_422be10_to_y210(int w, int h, if (!pg || !pg_2 || !pg_y210) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (pg_y210) - st_test_free(pg_y210); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (pg_y210) st_test_free(pg_y210); return; } @@ -2011,13 +1849,11 @@ static void test_cvt_rfc4175_422be10_to_y210(int w, int h, } TEST(Cvt, rfc4175_422be10_to_y210) { - test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be10_to_y210_scalar) { - test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_y210(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rfc4175_422be10_to_y210_avx512) { @@ -2025,48 +1861,40 @@ TEST(Cvt, rfc4175_422be10_to_y210_avx512) { MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_y210(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be10_to_y210(w, h, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be10_to_y210(w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); } } -static void -test_cvt_rfc4175_422be10_to_y210_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be10_to_y210_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; size_t fb_pg2_size_y210 = (size_t)w * h * 4; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_10_pg2_be *pg_be = - (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, - MTL_PORT_P); + (struct st20_rfc4175_422_10_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); struct st20_rfc4175_422_10_pg2_be *pg_be_2 = (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); uint16_t *pg_y210 = (uint16_t *)st_test_zmalloc(fb_pg2_size_y210); if (!pg_be || !pg_y210 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - mtl_hp_free(st, pg_be); - if (pg_be_2) - st_test_free(pg_be_2); - if (pg_y210) - st_test_free(pg_y210); + if (pg_be) mtl_hp_free(st, pg_be); + if (pg_be_2) st_test_free(pg_be_2); + if (pg_y210) st_test_free(pg_y210); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be10_to_y210_simd_dma( - dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_y210, w, h, cvt_level); + ret = st20_rfc4175_422be10_to_y210_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), + pg_y210, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_y210_to_rfc4175_422be10(pg_y210, pg_be_2, w, h); @@ -2082,8 +1910,7 @@ TEST(Cvt, rfc4175_422be10_to_y210_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_y210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -2095,8 +1922,7 @@ TEST(Cvt, rfc4175_422be10_to_y210_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_y210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -2108,8 +1934,7 @@ TEST(Cvt, rfc4175_422be10_to_y210_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be10_to_y210_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -2128,8 +1953,7 @@ TEST(Cvt, rfc4175_422be10_to_y210_avx512_dma) { mtl_udma_free(dma); } -static void test_cvt_y210_to_rfc4175_422be10(int w, int h, - enum mtl_simd_level cvt_level, +static void test_cvt_y210_to_rfc4175_422be10(int w, int h, enum mtl_simd_level cvt_level, enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; @@ -2141,12 +1965,9 @@ static void test_cvt_y210_to_rfc4175_422be10(int w, int h, if (!pg || !pg_y210_2 || !pg_y210) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_y210_2) - st_test_free(pg_y210_2); - if (pg_y210) - st_test_free(pg_y210); + if (pg) st_test_free(pg); + if (pg_y210_2) st_test_free(pg_y210_2); + if (pg_y210) st_test_free(pg_y210); return; } @@ -2168,13 +1989,11 @@ static void test_cvt_y210_to_rfc4175_422be10(int w, int h, } TEST(Cvt, y210_to_rfc4175_422be10) { - test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, y210_to_rfc4175_422be10_scalar) { - test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + test_cvt_y210_to_rfc4175_422be10(1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } TEST(Cvt, y210_to_rfc4175_422be10_avx512) { @@ -2182,21 +2001,17 @@ TEST(Cvt, y210_to_rfc4175_422be10_avx512) { MTL_SIMD_LEVEL_AVX512); test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512); - test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_NONE); + test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); + test_cvt_y210_to_rfc4175_422be10(722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_y210_to_rfc4175_422be10(w, h, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + test_cvt_y210_to_rfc4175_422be10(w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); } } -static void -test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 5 / 2; struct st_tests_context *ctx = st_test_ctx(); @@ -2204,19 +2019,15 @@ test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, struct st20_rfc4175_422_10_pg2_be *pg = (struct st20_rfc4175_422_10_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t fb_pg_y210_size = (size_t)w * h * 2 * sizeof(uint16_t); - uint16_t *pg_y210 = - (uint16_t *)mtl_hp_zmalloc(st, fb_pg_y210_size, MTL_PORT_P); + uint16_t *pg_y210 = (uint16_t *)mtl_hp_zmalloc(st, fb_pg_y210_size, MTL_PORT_P); mtl_iova_t pg_y210_iova = mtl_hp_virt2iova(st, pg_y210); uint16_t *pg_y210_2 = (uint16_t *)st_test_zmalloc(fb_pg_y210_size); if (!pg || !pg_y210_2 || !pg_y210) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_y210_2) - st_test_free(pg_y210_2); - if (pg_y210) - st_test_free(pg_y210); + if (pg) st_test_free(pg); + if (pg_y210_2) st_test_free(pg_y210_2); + if (pg_y210) st_test_free(pg_y210); return; } @@ -2224,8 +2035,8 @@ test_cvt_y210_to_rfc4175_422be10_dma(mtl_udma_handle dma, int w, int h, pg_y210[i] = rand() & 0xFFC0; /* only 10 bit */ } - ret = st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210, pg_y210_iova, pg, w, - h, cvt_level); + ret = st20_y210_to_rfc4175_422be10_simd_dma(dma, pg_y210, pg_y210_iova, pg, w, h, + cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be10_to_y210_simd(pg, pg_y210_2, w, h, back_level); @@ -2242,8 +2053,7 @@ TEST(Cvt, y210_to_rfc4175_422be10_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_y210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); @@ -2255,8 +2065,7 @@ TEST(Cvt, y210_to_rfc4175_422be10_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_y210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -2268,8 +2077,7 @@ TEST(Cvt, y210_to_rfc4175_422be10_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_y210_to_rfc4175_422be10_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); @@ -2289,8 +2097,8 @@ TEST(Cvt, y210_to_rfc4175_422be10_avx512_dma) { } static void test_rotate_rfc4175_422be10_422le10_yuv422p10le( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -2304,14 +2112,10 @@ static void test_rotate_rfc4175_422be10_422le10_yuv422p10le( if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p10_u16) - st_test_free(p10_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p10_u16) st_test_free(p10_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -2324,9 +2128,8 @@ static void test_rotate_rfc4175_422be10_422le10_yuv422p10le( (p10_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422be10_simd(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 3 / 2), - pg_be_2, w, h, cvt3_level); + ret = st20_yuv422p10le_to_rfc4175_422be10_simd( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_be_2, w, h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg2_size)); @@ -2339,37 +2142,31 @@ static void test_rotate_rfc4175_422be10_422le10_yuv422p10le( TEST(Cvt, rotate_rfc4175_422be10_422le10_yuv422p10le_avx512) { test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rotate_rfc4175_422be10_422le10_yuv422p10le_vbmi) { + test_rotate_rfc4175_422be10_422le10_yuv422p10le(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); - test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512_VBMI2); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); } TEST(Cvt, rotate_rfc4175_422be10_422le10_yuv422p10le_scalar) { test_rotate_rfc4175_422be10_422le10_yuv422p10le( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } static void test_rotate_rfc4175_422be10_yuv422p10le_422le10( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 5 / 2; struct st20_rfc4175_422_10_pg2_be *pg_be = @@ -2383,26 +2180,21 @@ static void test_rotate_rfc4175_422be10_yuv422p10le_422le10( if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p10_u16) - st_test_free(p10_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p10_u16) st_test_free(p10_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be10_to_yuv422p10le_simd( - pg_be, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h, - cvt1_level); + pg_be, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), w, h, cvt1_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p10le_to_rfc4175_422le10( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 3 / 2), pg_le, w, h); + ret = st20_yuv422p10le_to_rfc4175_422le10(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 3 / 2), pg_le, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le10_to_422be10(pg_le, pg_be_2, w, h); @@ -2418,38 +2210,31 @@ static void test_rotate_rfc4175_422be10_yuv422p10le_422le10( TEST(Cvt, rotate_rfc4175_422be10_yuv422p10le_422le10_avx512) { test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, - MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); } TEST(Cvt, rotate_rfc4175_422be10_yuv422p10le_422le10_vbmi) { + test_rotate_rfc4175_422be10_yuv422p10le_422le10(1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_AVX512_VBMI2); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_NONE); test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_AVX512_VBMI2, - MTL_SIMD_LEVEL_NONE); - test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_AVX512_VBMI2); + 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512_VBMI2); } TEST(Cvt, rotate_rfc4175_422be10_yuv422p10le_422le10_scalar) { test_rotate_rfc4175_422be10_yuv422p10le_422le10( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_422be12_to_yuv422p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be12_to_yuv422p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_be *pg = @@ -2461,25 +2246,20 @@ test_cvt_rfc4175_422be12_to_yuv422p12le(int w, int h, if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p12_u16) st_test_free(p12_u16); return; } st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); - ret = st20_rfc4175_422be12_to_yuv422p12le_simd(pg, p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), w, - h, cvt_level); + ret = st20_rfc4175_422be12_to_yuv422p12le_simd( + pg, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), - pg_2, w, h, back_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -2516,8 +2296,8 @@ TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512) { } TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512_vbmi) { - test_cvt_rfc4175_422be12_to_yuv422p12le( - 1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); + test_cvt_rfc4175_422be12_to_yuv422p12le(1920, 1080, MTL_SIMD_LEVEL_AVX512_VBMI2, + MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be12_to_yuv422p12le(722, 111, MTL_SIMD_LEVEL_AVX512_VBMI2, MTL_SIMD_LEVEL_AVX512_VBMI2); test_cvt_rfc4175_422be12_to_yuv422p12le(722, 111, MTL_SIMD_LEVEL_NONE, @@ -2531,17 +2311,15 @@ TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512_vbmi) { } } -static void -test_cvt_rfc4175_422be12_to_yuv422p12le_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be12_to_yuv422p12le_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_12_pg2_be *pg = - (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, - MTL_PORT_P); + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); struct st20_rfc4175_422_12_pg2_be *pg_2 = (struct st20_rfc4175_422_12_pg2_be *)st_test_zmalloc(fb_pg2_size); size_t planar_size = (size_t)w * h * 2 * sizeof(uint16_t); @@ -2549,12 +2327,9 @@ test_cvt_rfc4175_422be12_to_yuv422p12le_dma(mtl_udma_handle dma, int w, int h, if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - mtl_hp_free(st, pg); - if (pg_2) - st_test_free(pg_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) mtl_hp_free(st, pg); + if (pg_2) st_test_free(pg_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -2565,9 +2340,8 @@ test_cvt_rfc4175_422be12_to_yuv422p12le_dma(mtl_udma_handle dma, int w, int h, (p12_u16 + w * h * 3 / 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), - pg_2, w, h, back_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -2581,11 +2355,10 @@ TEST(Cvt, rfc4175_422be12_to_yuv422p12le_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be12_to_yuv422p12le_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } @@ -2594,11 +2367,10 @@ TEST(Cvt, rfc4175_422be12_to_yuv422p12le_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be12_to_yuv422p12le_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_NONE); mtl_udma_free(dma); } @@ -2607,30 +2379,28 @@ TEST(Cvt, rfc4175_422be12_to_yuv422p12le_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be12_to_yuv422p12le_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be12_to_yuv422p12le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be12_to_yuv422p12le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_AVX512); - test_cvt_rfc4175_422be12_to_yuv422p12le_dma( - dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_NONE); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, + MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_NONE); int w = 2; /* each pg has two pixels */ for (int h = 640; h < (640 + 64); h++) { - test_cvt_rfc4175_422be12_to_yuv422p12le_dma( - dma, w, h, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_yuv422p12le_dma(dma, w, h, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); } mtl_udma_free(dma); } -static void -test_cvt_yuv422p12le_to_rfc4175_422be12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_yuv422p12le_to_rfc4175_422be12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_be *pg = @@ -2641,12 +2411,9 @@ test_cvt_yuv422p12le_to_rfc4175_422be12(int w, int h, if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p12_u16_2) - st_test_free(p12_u16_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (p12_u16_2) st_test_free(p12_u16_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -2654,14 +2421,12 @@ test_cvt_yuv422p12le_to_rfc4175_422be12(int w, int h, p12_u16[i] = rand() & 0xfff; /* only 12 bit */ } - ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), pg, - w, h, cvt_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422be12_to_yuv422p12le_simd( - pg, p12_u16_2, (p12_u16_2 + w * h), (p12_u16_2 + w * h * 3 / 2), w, h, - back_level); + pg, p12_u16_2, (p12_u16_2 + w * h), (p12_u16_2 + w * h * 3 / 2), w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p12_u16, p12_u16_2, planar_size)); @@ -2681,10 +2446,9 @@ TEST(Cvt, yuv422p12le_to_rfc4175_422be12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_422le12_to_yuv422p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422le12_to_yuv422p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_le *pg = @@ -2696,12 +2460,9 @@ test_cvt_rfc4175_422le12_to_yuv422p12le(int w, int h, if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -2711,8 +2472,8 @@ test_cvt_rfc4175_422le12_to_yuv422p12le(int w, int h, (p12_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422le12( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_2, w, h); + ret = st20_yuv422p12le_to_rfc4175_422le12(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), pg_2, w, h); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -2732,10 +2493,9 @@ TEST(Cvt, rfc4175_422le12_to_yuv422p12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_yuv422p12le_to_rfc4175_422le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_yuv422p12le_to_rfc4175_422le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_le *pg = @@ -2746,12 +2506,9 @@ test_cvt_yuv422p12le_to_rfc4175_422le12(int w, int h, if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p12_u16_2) - st_test_free(p12_u16_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (p12_u16_2) st_test_free(p12_u16_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -2759,8 +2516,8 @@ test_cvt_yuv422p12le_to_rfc4175_422le12(int w, int h, p12_u16[i] = rand() & 0xfff; /* only 12 bit */ } - ret = st20_yuv422p12le_to_rfc4175_422le12( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg, w, h); + ret = st20_yuv422p12le_to_rfc4175_422le12(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), pg, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_yuv422p12le(pg, p12_u16_2, (p12_u16_2 + w * h), @@ -2784,9 +2541,9 @@ TEST(Cvt, yuv422p12le_to_rfc4175_422le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_422be12_to_422le12(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be12_to_422le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_be *pg_be = @@ -2798,12 +2555,9 @@ test_cvt_rfc4175_422be12_to_422le12(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -2823,8 +2577,7 @@ test_cvt_rfc4175_422be12_to_422le12(int w, int h, enum mtl_simd_level cvt_level, } TEST(Cvt, rfc4175_422be12_to_422le12) { - test_cvt_rfc4175_422be12_to_422le12(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be12_to_422le12(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_422be12_to_422le12_scalar) { @@ -2848,17 +2601,15 @@ TEST(Cvt, rfc4175_422be12_to_422le12_avx512) { } } -static void -test_cvt_rfc4175_422be12_to_422le12_dma(mtl_udma_handle dma, int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422be12_to_422le12_dma(mtl_udma_handle dma, int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; struct st_tests_context *ctx = st_test_ctx(); mtl_handle st = ctx->handle; struct st20_rfc4175_422_12_pg2_be *pg_be = - (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, - MTL_PORT_P); + (struct st20_rfc4175_422_12_pg2_be *)mtl_hp_zmalloc(st, fb_pg2_size, MTL_PORT_P); struct st20_rfc4175_422_12_pg2_le *pg_le = (struct st20_rfc4175_422_12_pg2_le *)st_test_zmalloc(fb_pg2_size); struct st20_rfc4175_422_12_pg2_be *pg_be_2 = @@ -2866,19 +2617,16 @@ test_cvt_rfc4175_422be12_to_422le12_dma(mtl_udma_handle dma, int w, int h, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - mtl_hp_free(st, pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) mtl_hp_free(st, pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); - ret = st20_rfc4175_422be12_to_422le12_simd_dma( - dma, pg_be, mtl_hp_virt2iova(st, pg_be), pg_le, w, h, cvt_level); + ret = st20_rfc4175_422be12_to_422le12_simd_dma(dma, pg_be, mtl_hp_virt2iova(st, pg_be), + pg_le, w, h, cvt_level); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be_2, w, h, back_level); @@ -2895,13 +2643,12 @@ TEST(Cvt, rfc4175_422be12_to_422le12_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); - test_cvt_rfc4175_422be12_to_422le12_dma( - dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920 * 4, 1080 * 4, MTL_SIMD_LEVEL_MAX, + MTL_SIMD_LEVEL_MAX); mtl_udma_free(dma); } @@ -2909,8 +2656,7 @@ TEST(Cvt, rfc4175_422be12_to_422le12_scalar_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); @@ -2921,11 +2667,10 @@ TEST(Cvt, rfc4175_422be12_to_422le12_avx512_dma) { struct st_tests_context *ctx = st_test_ctx(); mtl_handle handle = ctx->handle; mtl_udma_handle dma = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma) - return; + if (!dma) return; - test_cvt_rfc4175_422be12_to_422le12_dma( - dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); + test_cvt_rfc4175_422be12_to_422le12_dma(dma, 1920, 1080, MTL_SIMD_LEVEL_AVX512, + MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be12_to_422le12_dma(dma, 722, 111, MTL_SIMD_LEVEL_AVX512, MTL_SIMD_LEVEL_AVX512); test_cvt_rfc4175_422be12_to_422le12_dma(dma, 722, 111, MTL_SIMD_LEVEL_NONE, @@ -2941,9 +2686,9 @@ TEST(Cvt, rfc4175_422be12_to_422le12_avx512_dma) { mtl_udma_free(dma); } -static void -test_cvt_rfc4175_422le12_to_422be12(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422le12_to_422be12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_le *pg_le = @@ -2955,12 +2700,9 @@ test_cvt_rfc4175_422le12_to_422be12(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_le_2) - st_test_free(pg_le_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_le_2) st_test_free(pg_le_2); return; } @@ -2980,10 +2722,9 @@ test_cvt_rfc4175_422le12_to_422be12(int w, int h, enum mtl_simd_level cvt_level, st_test_free(pg_le_2); } -static void -test_cvt_rfc4175_422le12_to_422be12_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_422le12_to_422be12_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_le *pg_le = @@ -2995,19 +2736,15 @@ test_cvt_rfc4175_422le12_to_422be12_2(int w, int h, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_422be12_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -3032,8 +2769,8 @@ TEST(Cvt, rfc4175_422le12_to_422be12_scalar) { } static void test_rotate_rfc4175_422be12_422le12_yuv422p12le( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_be *pg_be = @@ -3047,14 +2784,10 @@ static void test_rotate_rfc4175_422be12_422le12_yuv422p12le( if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p12_u16) - st_test_free(p12_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p12_u16) st_test_free(p12_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -3067,9 +2800,8 @@ static void test_rotate_rfc4175_422be12_422le12_yuv422p12le( (p12_u16 + w * h * 3 / 2), w, h); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422be12_simd(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 3 / 2), - pg_be_2, w, h, cvt3_level); + ret = st20_yuv422p12le_to_rfc4175_422be12_simd( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_be_2, w, h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg2_size)); @@ -3082,13 +2814,12 @@ static void test_rotate_rfc4175_422be12_422le12_yuv422p12le( TEST(Cvt, rotate_rfc4175_422be12_422le12_yuv422p12le_scalar) { test_rotate_rfc4175_422be12_422le12_yuv422p12le( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } static void test_rotate_rfc4175_422be12_yuv422p12le_422le12( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { + int w, int h, enum mtl_simd_level cvt1_level, enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 6 / 2; struct st20_rfc4175_422_12_pg2_be *pg_be = @@ -3102,26 +2833,21 @@ static void test_rotate_rfc4175_422be12_yuv422p12le_422le12( if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p12_u16) - st_test_free(p12_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p12_u16) st_test_free(p12_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_422be12_to_yuv422p12le_simd( - pg_be, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h, - cvt1_level); + pg_be, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), w, h, cvt1_level); EXPECT_EQ(0, ret); - ret = st20_yuv422p12le_to_rfc4175_422le12( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 3 / 2), pg_le, w, h); + ret = st20_yuv422p12le_to_rfc4175_422le12(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 3 / 2), pg_le, w, h); EXPECT_EQ(0, ret); ret = st20_rfc4175_422le12_to_422be12(pg_le, pg_be_2, w, h); @@ -3137,14 +2863,12 @@ static void test_rotate_rfc4175_422be12_yuv422p12le_422le12( TEST(Cvt, rotate_rfc4175_422be12_yuv422p12le_422le12_scalar) { test_rotate_rfc4175_422be12_yuv422p12le_422le12( - 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + 1920, 1080, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444be10_to_444p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444be10_to_444p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_be *pg = @@ -3156,24 +2880,20 @@ test_cvt_rfc4175_444be10_to_444p10le(int w, int h, if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p10_u16) st_test_free(p10_u16); return; } st_test_rand_data((uint8_t *)pg, fb_pg4_size, 0); - ret = st20_rfc4175_444be10_to_444p10le_simd( - pg, p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), w, h, cvt_level); + ret = st20_rfc4175_444be10_to_444p10le_simd(pg, p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_444p10le_to_rfc4175_444be10_simd(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 2), pg_2, w, h, - back_level); + ret = st20_444p10le_to_rfc4175_444be10_simd( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg4_size)); @@ -3193,10 +2913,9 @@ TEST(Cvt, rfc4175_444be10_to_444p10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_444p10le_to_rfc4175_444be10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_444p10le_to_rfc4175_444be10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_be *pg = @@ -3207,12 +2926,9 @@ test_cvt_444p10le_to_rfc4175_444be10(int w, int h, if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p10_u16_2) - st_test_free(p10_u16_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (p10_u16_2) st_test_free(p10_u16_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -3220,13 +2936,12 @@ test_cvt_444p10le_to_rfc4175_444be10(int w, int h, p10_u16[i] = rand() & 0x3ff; /* only 10 bit */ } - ret = st20_444p10le_to_rfc4175_444be10_simd( - p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), pg, w, h, cvt_level); + ret = st20_444p10le_to_rfc4175_444be10_simd(p10_u16, (p10_u16 + w * h), + (p10_u16 + w * h * 2), pg, w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_rfc4175_444be10_to_444p10le_simd( - pg, p10_u16_2, (p10_u16_2 + w * h), (p10_u16_2 + w * h * 2), w, h, - back_level); + ret = st20_rfc4175_444be10_to_444p10le_simd(pg, p10_u16_2, (p10_u16_2 + w * h), + (p10_u16_2 + w * h * 2), w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p10_u16, p10_u16_2, planar_size)); @@ -3246,10 +2961,9 @@ TEST(Cvt, 444p10le_to_rfc4175_444be10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444le10_to_yuv444p10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le10_to_yuv444p10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_le *pg = @@ -3261,12 +2975,9 @@ test_cvt_rfc4175_444le10_to_yuv444p10le(int w, int h, if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -3297,10 +3008,9 @@ TEST(Cvt, rfc4175_444le10_to_yuv444p10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444le10_to_gbrp10le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le10_to_gbrp10le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_le *pg = @@ -3312,12 +3022,9 @@ test_cvt_rfc4175_444le10_to_gbrp10le(int w, int h, if (!pg || !pg_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -3348,10 +3055,9 @@ TEST(Cvt, rfc4175_444le10_to_gbrp10le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_yuv444p10le_to_rfc4175_444le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_yuv444p10le_to_rfc4175_444le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_le *pg = @@ -3362,12 +3068,9 @@ test_cvt_yuv444p10le_to_rfc4175_444le10(int w, int h, if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p10_u16_2) - st_test_free(p10_u16_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (p10_u16_2) st_test_free(p10_u16_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -3400,10 +3103,9 @@ TEST(Cvt, yuv444p10le_to_rfc4175_444le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_gbrp10le_to_rfc4175_444le10(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_gbrp10le_to_rfc4175_444le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_le *pg = @@ -3414,12 +3116,9 @@ test_cvt_gbrp10le_to_rfc4175_444le10(int w, int h, if (!pg || !p10_u16_2 || !p10_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p10_u16_2) - st_test_free(p10_u16_2); - if (p10_u16) - st_test_free(p10_u16); + if (pg) st_test_free(pg); + if (p10_u16_2) st_test_free(p10_u16_2); + if (p10_u16) st_test_free(p10_u16); return; } @@ -3452,9 +3151,9 @@ TEST(Cvt, gbrp10le_to_rfc4175_444le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444be10_to_444le10(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444be10_to_444le10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_be *pg_be = @@ -3466,12 +3165,9 @@ test_cvt_rfc4175_444be10_to_444le10(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -3491,8 +3187,7 @@ test_cvt_rfc4175_444be10_to_444le10(int w, int h, enum mtl_simd_level cvt_level, } TEST(Cvt, rfc4175_444be10_to_444le10) { - test_cvt_rfc4175_444be10_to_444le10(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_444be10_to_444le10(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_444be10_to_444le10_scalar) { @@ -3500,9 +3195,9 @@ TEST(Cvt, rfc4175_444be10_to_444le10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444le10_to_444be10(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le10_to_444be10(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_le *pg_le = @@ -3514,12 +3209,9 @@ test_cvt_rfc4175_444le10_to_444be10(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_le_2) - st_test_free(pg_le_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_le_2) st_test_free(pg_le_2); return; } @@ -3538,10 +3230,9 @@ test_cvt_rfc4175_444le10_to_444be10(int w, int h, enum mtl_simd_level cvt_level, st_test_free(pg_le_2); } -static void -test_cvt_rfc4175_444le10_to_444be10_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le10_to_444be10_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg4_size = w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_le *pg_le = @@ -3553,19 +3244,15 @@ test_cvt_rfc4175_444le10_to_444be10_2(int w, int h, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_le, fb_pg4_size, 0); - ret = st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_444le10_to_444be10_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -3588,9 +3275,10 @@ TEST(Cvt, rfc4175_444le10_to_444be10_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be10_444le10_444p10le( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be10_444le10_444p10le(int w, int h, + enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_be *pg_be = @@ -3604,14 +3292,10 @@ static void test_rotate_rfc4175_444be10_444le10_444p10le( if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p10_u16) - st_test_free(p10_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p10_u16) st_test_free(p10_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -3624,9 +3308,8 @@ static void test_rotate_rfc4175_444be10_444le10_444p10le( (p10_u16 + w * h * 2), w, h); EXPECT_EQ(0, ret); - ret = st20_444p10le_to_rfc4175_444be10_simd(p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 2), pg_be_2, w, - h, cvt3_level); + ret = st20_444p10le_to_rfc4175_444be10_simd( + p10_u16, (p10_u16 + w * h), (p10_u16 + w * h * 2), pg_be_2, w, h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg4_size)); @@ -3639,13 +3322,13 @@ static void test_rotate_rfc4175_444be10_444le10_444p10le( TEST(Cvt, rotate_rfc4175_444be10_444le10_444p10le_scalar) { test_rotate_rfc4175_444be10_444le10_444p10le(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be10_444p10le_444le10( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be10_444p10le_444le10(int w, int h, + enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg4_size = (size_t)w * h * 15 / 4; struct st20_rfc4175_444_10_pg4_be *pg_be = @@ -3659,22 +3342,17 @@ static void test_rotate_rfc4175_444be10_444p10le_444le10( if (!pg_le || !pg_be || !p10_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p10_u16) - st_test_free(p10_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p10_u16) st_test_free(p10_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg4_size, 0); ret = st20_rfc4175_444be10_to_444p10le_simd(pg_be, p10_u16, (p10_u16 + w * h), - (p10_u16 + w * h * 2), w, h, - cvt1_level); + (p10_u16 + w * h * 2), w, h, cvt1_level); EXPECT_EQ(0, ret); ret = st20_444p10le_to_rfc4175_444le10(p10_u16, (p10_u16 + w * h), @@ -3694,14 +3372,12 @@ static void test_rotate_rfc4175_444be10_444p10le_444le10( TEST(Cvt, rotate_rfc4175_444be10_444p10le_444le10_scalar) { test_rotate_rfc4175_444be10_444p10le_444le10(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444be12_to_444p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444be12_to_444p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_be *pg = @@ -3713,24 +3389,20 @@ test_cvt_rfc4175_444be12_to_444p12le(int w, int h, if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p12_u16) st_test_free(p12_u16); return; } st_test_rand_data((uint8_t *)pg, fb_pg2_size, 0); - ret = st20_rfc4175_444be12_to_444p12le_simd( - pg, p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), w, h, cvt_level); + ret = st20_rfc4175_444be12_to_444p12le_simd(pg, p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 2), w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_444p12le_to_rfc4175_444be12_simd(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 2), pg_2, w, h, - back_level); + ret = st20_444p12le_to_rfc4175_444be12_simd( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), pg_2, w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg, pg_2, fb_pg2_size)); @@ -3750,10 +3422,9 @@ TEST(Cvt, rfc4175_444be12_to_444p12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_444p12le_to_rfc4175_444be12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_444p12le_to_rfc4175_444be12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_be *pg = @@ -3764,12 +3435,9 @@ test_cvt_444p12le_to_rfc4175_444be12(int w, int h, if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p12_u16_2) - st_test_free(p12_u16_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (p12_u16_2) st_test_free(p12_u16_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -3777,13 +3445,12 @@ test_cvt_444p12le_to_rfc4175_444be12(int w, int h, p12_u16[i] = rand() & 0xfff; /* only 12 bit */ } - ret = st20_444p12le_to_rfc4175_444be12_simd( - p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), pg, w, h, cvt_level); + ret = st20_444p12le_to_rfc4175_444be12_simd(p12_u16, (p12_u16 + w * h), + (p12_u16 + w * h * 2), pg, w, h, cvt_level); EXPECT_EQ(0, ret); - ret = st20_rfc4175_444be12_to_444p12le_simd( - pg, p12_u16_2, (p12_u16_2 + w * h), (p12_u16_2 + w * h * 2), w, h, - back_level); + ret = st20_rfc4175_444be12_to_444p12le_simd(pg, p12_u16_2, (p12_u16_2 + w * h), + (p12_u16_2 + w * h * 2), w, h, back_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(p12_u16, p12_u16_2, planar_size)); @@ -3803,10 +3470,9 @@ TEST(Cvt, 444p12le_to_rfc4175_444be12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444le12_to_yuv444p12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le12_to_yuv444p12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_le *pg = @@ -3818,12 +3484,9 @@ test_cvt_rfc4175_444le12_to_yuv444p12le(int w, int h, if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -3854,10 +3517,9 @@ TEST(Cvt, rfc4175_444le12_to_yuv444p12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444le12_to_gbrp12le(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le12_to_gbrp12le(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_le *pg = @@ -3869,12 +3531,9 @@ test_cvt_rfc4175_444le12_to_gbrp12le(int w, int h, if (!pg || !pg_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (pg_2) - st_test_free(pg_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (pg_2) st_test_free(pg_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -3905,10 +3564,9 @@ TEST(Cvt, rfc4175_444le12_to_gbrp12le_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_yuv444p12le_to_rfc4175_444le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_yuv444p12le_to_rfc4175_444le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_le *pg = @@ -3919,12 +3577,9 @@ test_cvt_yuv444p12le_to_rfc4175_444le12(int w, int h, if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p12_u16_2) - st_test_free(p12_u16_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (p12_u16_2) st_test_free(p12_u16_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -3957,10 +3612,9 @@ TEST(Cvt, yuv444p12le_to_rfc4175_444le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_gbrp12le_to_rfc4175_444le12(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_gbrp12le_to_rfc4175_444le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_le *pg = @@ -3971,12 +3625,9 @@ test_cvt_gbrp12le_to_rfc4175_444le12(int w, int h, if (!pg || !p12_u16_2 || !p12_u16) { EXPECT_EQ(0, 1); - if (pg) - st_test_free(pg); - if (p12_u16_2) - st_test_free(p12_u16_2); - if (p12_u16) - st_test_free(p12_u16); + if (pg) st_test_free(pg); + if (p12_u16_2) st_test_free(p12_u16_2); + if (p12_u16) st_test_free(p12_u16); return; } @@ -4009,9 +3660,9 @@ TEST(Cvt, gbrp12le_to_rfc4175_444le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444be12_to_444le12(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444be12_to_444le12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_be *pg_be = @@ -4023,12 +3674,9 @@ test_cvt_rfc4175_444be12_to_444le12(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -4048,8 +3696,7 @@ test_cvt_rfc4175_444be12_to_444le12(int w, int h, enum mtl_simd_level cvt_level, } TEST(Cvt, rfc4175_444be12_to_444le12) { - test_cvt_rfc4175_444be12_to_444le12(1920, 1080, MTL_SIMD_LEVEL_MAX, - MTL_SIMD_LEVEL_MAX); + test_cvt_rfc4175_444be12_to_444le12(1920, 1080, MTL_SIMD_LEVEL_MAX, MTL_SIMD_LEVEL_MAX); } TEST(Cvt, rfc4175_444be12_to_444le12_scalar) { @@ -4057,9 +3704,9 @@ TEST(Cvt, rfc4175_444be12_to_444le12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void -test_cvt_rfc4175_444le12_to_444be12(int w, int h, enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le12_to_444be12(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_le *pg_le = @@ -4071,12 +3718,9 @@ test_cvt_rfc4175_444le12_to_444be12(int w, int h, enum mtl_simd_level cvt_level, if (!pg_be || !pg_le || !pg_le_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_le_2) - st_test_free(pg_le_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_le_2) st_test_free(pg_le_2); return; } @@ -4095,10 +3739,9 @@ test_cvt_rfc4175_444le12_to_444be12(int w, int h, enum mtl_simd_level cvt_level, st_test_free(pg_le_2); } -static void -test_cvt_rfc4175_444le12_to_444be12_2(int w, int h, - enum mtl_simd_level cvt_level, - enum mtl_simd_level back_level) { +static void test_cvt_rfc4175_444le12_to_444be12_2(int w, int h, + enum mtl_simd_level cvt_level, + enum mtl_simd_level back_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_le *pg_le = @@ -4110,19 +3753,15 @@ test_cvt_rfc4175_444le12_to_444be12_2(int w, int h, if (!pg_be || !pg_le || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_be) - st_test_free(pg_be); - if (pg_le) - st_test_free(pg_le); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_be) st_test_free(pg_be); + if (pg_le) st_test_free(pg_le); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_le, fb_pg2_size, 0); - ret = st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, - MTL_SIMD_LEVEL_NONE); + ret = st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be, w, h, MTL_SIMD_LEVEL_NONE); EXPECT_EQ(0, ret); ret = st20_rfc4175_444le12_to_444be12_simd(pg_le, pg_be_2, w, h, cvt_level); @@ -4145,9 +3784,10 @@ TEST(Cvt, rfc4175_444le12_to_444be12_scalar) { MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be12_444le12_444p12le( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be12_444le12_444p12le(int w, int h, + enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_be *pg_be = @@ -4161,14 +3801,10 @@ static void test_rotate_rfc4175_444be12_444le12_444p12le( if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p12_u16) - st_test_free(p12_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p12_u16) st_test_free(p12_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } @@ -4181,9 +3817,8 @@ static void test_rotate_rfc4175_444be12_444le12_444p12le( (p12_u16 + w * h * 2), w, h); EXPECT_EQ(0, ret); - ret = st20_444p12le_to_rfc4175_444be12_simd(p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 2), pg_be_2, w, - h, cvt3_level); + ret = st20_444p12le_to_rfc4175_444be12_simd( + p12_u16, (p12_u16 + w * h), (p12_u16 + w * h * 2), pg_be_2, w, h, cvt3_level); EXPECT_EQ(0, ret); EXPECT_EQ(0, memcmp(pg_be, pg_be_2, fb_pg2_size)); @@ -4196,13 +3831,13 @@ static void test_rotate_rfc4175_444be12_444le12_444p12le( TEST(Cvt, rotate_rfc4175_444be12_444le12_444p12le_scalar) { test_rotate_rfc4175_444be12_444le12_444p12le(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } -static void test_rotate_rfc4175_444be12_444p12le_444le12( - int w, int h, enum mtl_simd_level cvt1_level, - enum mtl_simd_level cvt2_level, enum mtl_simd_level cvt3_level) { +static void test_rotate_rfc4175_444be12_444p12le_444le12(int w, int h, + enum mtl_simd_level cvt1_level, + enum mtl_simd_level cvt2_level, + enum mtl_simd_level cvt3_level) { int ret; size_t fb_pg2_size = (size_t)w * h * 9 / 2; struct st20_rfc4175_444_12_pg2_be *pg_be = @@ -4216,22 +3851,17 @@ static void test_rotate_rfc4175_444be12_444p12le_444le12( if (!pg_le || !pg_be || !p12_u16 || !pg_be_2) { EXPECT_EQ(0, 1); - if (pg_le) - st_test_free(pg_le); - if (pg_be) - st_test_free(pg_be); - if (p12_u16) - st_test_free(p12_u16); - if (pg_be_2) - st_test_free(pg_be_2); + if (pg_le) st_test_free(pg_le); + if (pg_be) st_test_free(pg_be); + if (p12_u16) st_test_free(p12_u16); + if (pg_be_2) st_test_free(pg_be_2); return; } st_test_rand_data((uint8_t *)pg_be, fb_pg2_size, 0); ret = st20_rfc4175_444be12_to_444p12le_simd(pg_be, p12_u16, (p12_u16 + w * h), - (p12_u16 + w * h * 2), w, h, - cvt1_level); + (p12_u16 + w * h * 2), w, h, cvt1_level); EXPECT_EQ(0, ret); ret = st20_444p12le_to_rfc4175_444le12(p12_u16, (p12_u16 + w * h), @@ -4251,8 +3881,7 @@ static void test_rotate_rfc4175_444be12_444p12le_444le12( TEST(Cvt, rotate_rfc4175_444be12_444p12le_444le12_scalar) { test_rotate_rfc4175_444be12_444p12le_444le12(1920, 1080, MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE, - MTL_SIMD_LEVEL_NONE); + MTL_SIMD_LEVEL_NONE, MTL_SIMD_LEVEL_NONE); } static void test_am824_to_aes3(int blocks) { @@ -4260,18 +3889,13 @@ static void test_am824_to_aes3(int blocks) { int subframes = blocks * 2 * 192; size_t blocks_size = subframes * 4; struct st31_aes3 *b_aes3 = (struct st31_aes3 *)st_test_zmalloc(blocks_size); - struct st31_am824 *b_am824 = - (struct st31_am824 *)st_test_zmalloc(blocks_size); - struct st31_am824 *b_am824_2 = - (struct st31_am824 *)st_test_zmalloc(blocks_size); + struct st31_am824 *b_am824 = (struct st31_am824 *)st_test_zmalloc(blocks_size); + struct st31_am824 *b_am824_2 = (struct st31_am824 *)st_test_zmalloc(blocks_size); if (!b_aes3 || !b_am824 || !b_am824_2) { EXPECT_EQ(0, 1); - if (b_aes3) - st_test_free(b_aes3); - if (b_am824) - st_test_free(b_am824); - if (b_am824_2) - st_test_free(b_am824_2); + if (b_aes3) st_test_free(b_aes3); + if (b_am824) st_test_free(b_am824); + if (b_am824_2) st_test_free(b_am824_2); return; } @@ -4317,17 +3941,13 @@ static void test_aes3_to_am824(int blocks) { int subframes = blocks * 2 * 192; size_t blocks_size = subframes * 4; struct st31_aes3 *b_aes3 = (struct st31_aes3 *)st_test_zmalloc(blocks_size); - struct st31_am824 *b_am824 = - (struct st31_am824 *)st_test_zmalloc(blocks_size); + struct st31_am824 *b_am824 = (struct st31_am824 *)st_test_zmalloc(blocks_size); struct st31_aes3 *b_aes3_2 = (struct st31_aes3 *)st_test_zmalloc(blocks_size); if (!b_aes3 || !b_am824 || !b_aes3_2) { EXPECT_EQ(0, 1); - if (b_aes3) - st_test_free(b_aes3); - if (b_am824) - st_test_free(b_am824); - if (b_aes3_2) - st_test_free(b_aes3_2); + if (b_aes3) st_test_free(b_aes3); + if (b_am824) st_test_free(b_am824); + if (b_aes3_2) st_test_free(b_aes3_2); return; } @@ -4368,15 +3988,12 @@ static void frame_malloc(struct st_frame *frame, uint8_t rand, bool align) { int planes = st_frame_fmt_planes(frame->fmt); size_t fb_size = 0; for (int plane = 0; plane < planes; plane++) { - size_t least_line_size = - st_frame_least_linesize(frame->fmt, frame->width, plane); - frame->linesize[plane] = - align ? MTL_ALIGN(least_line_size, 512) : least_line_size; + size_t least_line_size = st_frame_least_linesize(frame->fmt, frame->width, plane); + frame->linesize[plane] = align ? MTL_ALIGN(least_line_size, 512) : least_line_size; fb_size += frame->linesize[plane] * frame->height; } uint8_t *fb = (uint8_t *)st_test_zmalloc(fb_size); - if (!fb) - return; + if (!fb) return; if (rand) { /* fill the framebuffer */ st_test_rand_data(fb, fb_size, rand); if (frame->fmt == ST_FRAME_FMT_YUV422PLANAR10LE) { @@ -4400,15 +4017,14 @@ static void frame_malloc(struct st_frame *frame, uint8_t rand, bool align) { } frame->addr[0] = fb; for (int plane = 1; plane < planes; plane++) { - frame->addr[plane] = (uint8_t *)frame->addr[plane - 1] + - st_frame_plane_size(frame, plane - 1); + frame->addr[plane] = + (uint8_t *)frame->addr[plane - 1] + st_frame_plane_size(frame, plane - 1); } frame->data_size = frame->buffer_size = fb_size; } static void frame_free(struct st_frame *frame) { - if (frame->addr[0]) - st_test_free(frame->addr[0]); + if (frame->addr[0]) st_test_free(frame->addr[0]); int planes = st_frame_fmt_planes(frame->fmt); for (int plane = 0; plane < planes; plane++) { frame->addr[plane] = NULL; @@ -4427,9 +4043,8 @@ static int frame_compare_each_line(struct st_frame *old_frame, (uint8_t *)old_frame->addr[plane] + old_frame->linesize[plane] * line; uint8_t *new_addr = (uint8_t *)new_frame->addr[plane] + new_frame->linesize[plane] * line; - if (memcmp( - old_addr, new_addr, - st_frame_least_linesize(old_frame->fmt, old_frame->width, plane))) + if (memcmp(old_addr, new_addr, + st_frame_least_linesize(old_frame->fmt, old_frame->width, plane))) ret += -EIO; } } @@ -4645,14 +4260,10 @@ static void test_field_to_frame(mtl_handle mt, uint32_t width, uint32_t height, if (!frame || !first || !second || !back) { EXPECT_EQ(0, 1); - if (frame) - st_frame_free(frame); - if (first) - st_frame_free(first); - if (second) - st_frame_free(second); - if (back) - st_frame_free(back); + if (frame) st_frame_free(frame); + if (first) st_frame_free(first); + if (second) st_frame_free(second); + if (back) st_frame_free(back); return; } second->second_field = true; @@ -4674,7 +4285,6 @@ static void test_field_to_frame(mtl_handle mt, uint32_t width, uint32_t height, TEST(Cvt, field_to_frame) { struct st_tests_context *ctx = st_test_ctx(); - test_field_to_frame(ctx->handle, 1920, 1080, - ST_FRAME_FMT_YUV422RFC4175PG2BE10); + test_field_to_frame(ctx->handle, 1920, 1080, ST_FRAME_FMT_YUV422RFC4175PG2BE10); test_field_to_frame(ctx->handle, 1920, 1080, ST_FRAME_FMT_YUV422PLANAR10LE); } diff --git a/tests/src/dma_test.cpp b/tests/src/dma_test.cpp index cce201902..7610fa567 100644 --- a/tests/src/dma_test.cpp +++ b/tests/src/dma_test.cpp @@ -11,8 +11,7 @@ static int test_dma_cnt(struct st_tests_context *ctx) { int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) - return ret; + if (ret < 0) return ret; return var.dma_dev_cnt; } @@ -40,8 +39,7 @@ static void test_dma_create_max(struct st_tests_context *ctx) { dma_idx = 0; while (true) { dma[dma_idx] = mtl_udma_create(handle, 128, MTL_PORT_P); - if (!dma[dma_idx]) - break; + if (!dma[dma_idx]) break; dma_idx++; cnt = test_dma_cnt(ctx); EXPECT_EQ(base_cnt + dma_idx, cnt); @@ -58,8 +56,7 @@ static void test_dma_create_max(struct st_tests_context *ctx) { TEST(Dma, create) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_create_one(ctx); } @@ -67,8 +64,7 @@ TEST(Dma, create) { TEST(Dma, create_max) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_create_max(ctx); } @@ -76,11 +72,9 @@ TEST(Dma, create_max) { TEST(Dma, create_multi) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; - for (int i = 0; i < 10; i++) - test_dma_create_one(ctx); + for (int i = 0; i < 10; i++) test_dma_create_one(ctx); } static void _test_dma_copy(mtl_handle st, mtl_udma_handle dma, uint32_t off, @@ -113,8 +107,7 @@ static void _test_dma_copy(mtl_handle st, mtl_udma_handle dma, uint32_t off, mtl_hp_free(st, src); } -static void test_dma_copy(struct st_tests_context *ctx, uint32_t off, - uint32_t len) { +static void test_dma_copy(struct st_tests_context *ctx, uint32_t off, uint32_t len) { mtl_handle st = ctx->handle; mtl_udma_handle dma; int ret; @@ -183,13 +176,11 @@ static void test_dma_copy_fill_async(struct st_tests_context *ctx, bool fill) { /* try to copy */ while (fb_src_iova_off < fb_size) { if (fill) - ret = mtl_udma_fill_u8(dma, fb_dst_iova + fb_src_iova_off, pattern, - element_size); + ret = mtl_udma_fill_u8(dma, fb_dst_iova + fb_src_iova_off, pattern, element_size); else ret = mtl_udma_copy(dma, fb_dst_iova + fb_src_iova_off, fb_src_iova + fb_src_iova_off, element_size); - if (ret < 0) - break; + if (ret < 0) break; fb_src_iova_off += element_size; } /* submit */ @@ -214,8 +205,7 @@ static void test_dma_copy_fill_async(struct st_tests_context *ctx, bool fill) { TEST(Dma, copy) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_copy(ctx, 0, 1024); test_dma_copy(ctx, 128, 1024 * 4); @@ -224,8 +214,7 @@ TEST(Dma, copy) { TEST(Dma, copy_odd) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_copy(ctx, 33, 1024); test_dma_copy(ctx, 33, 1024 - 33); @@ -234,8 +223,7 @@ TEST(Dma, copy_odd) { TEST(Dma, copy_sanity) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_copy_sanity(ctx); } @@ -243,14 +231,13 @@ TEST(Dma, copy_sanity) { TEST(Dma, copy_async) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_copy_fill_async(ctx, false); } -static void _test_dma_fill(mtl_handle st, mtl_udma_handle dma, uint32_t off, - uint32_t len, uint8_t pattern) { +static void _test_dma_fill(mtl_handle st, mtl_udma_handle dma, uint32_t off, uint32_t len, + uint8_t pattern) { void *dst = NULL, *src = NULL; mtl_iova_t dst_iova; int ret; @@ -278,8 +265,8 @@ static void _test_dma_fill(mtl_handle st, mtl_udma_handle dma, uint32_t off, mtl_hp_free(st, src); } -static void test_dma_fill(struct st_tests_context *ctx, uint32_t off, - uint32_t len, uint8_t pattern) { +static void test_dma_fill(struct st_tests_context *ctx, uint32_t off, uint32_t len, + uint8_t pattern) { mtl_handle st = ctx->handle; mtl_udma_handle dma; int ret; @@ -316,8 +303,7 @@ static void test_dma_fill_sanity(struct st_tests_context *ctx) { TEST(Dma, fill) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_fill(ctx, 0, 1024, 0xa5); test_dma_fill(ctx, 128, 1024 * 4, 0x5a); @@ -326,8 +312,7 @@ TEST(Dma, fill) { TEST(Dma, fill_odd) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_fill(ctx, 33, 1024, 0x5a); test_dma_fill(ctx, 33, 1024 - 33, 0xa5); @@ -336,8 +321,7 @@ TEST(Dma, fill_odd) { TEST(Dma, fill_sanity) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_fill_sanity(ctx); } @@ -345,8 +329,7 @@ TEST(Dma, fill_sanity) { TEST(Dma, fill_async) { struct st_tests_context *ctx = st_test_ctx(); - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; test_dma_copy_fill_async(ctx, true); } @@ -399,8 +382,7 @@ TEST(Dma, map_fail) { free(p); } -static void test_dma_map_continues(struct st_tests_context *ctx, size_t size, - int count) { +static void test_dma_map_continues(struct st_tests_context *ctx, size_t size, int count) { auto st = ctx->handle; size_t pg_sz = mtl_page_size(st); /* 2 more pages to hold the head and tail */ @@ -480,16 +462,14 @@ TEST(Dma, map_remap) { test_dma_remap(ctx, 64 * mtl_page_size(st)); } -static void test_dma_map_copy(mtl_handle st, mtl_udma_handle dma, - size_t copy_size) { +static void test_dma_map_copy(mtl_handle st, mtl_udma_handle dma, size_t copy_size) { void *dst = NULL, *src = NULL; size_t pg_sz = mtl_page_size(st); /* 2 more pages to hold the head and tail */ size_t size = copy_size + 2 * pg_sz; dst = (uint8_t *)malloc(size); - if (!dst) - return; + if (!dst) return; src = (uint8_t *)malloc(size); if (!src) { free(dst); @@ -528,8 +508,7 @@ TEST(Dma, map_copy) { struct st_tests_context *ctx = st_test_ctx(); auto st = ctx->handle; - if (!st_test_dma_available(ctx)) - return; + if (!st_test_dma_available(ctx)) return; mtl_udma_handle dma = mtl_udma_create(st, 128, MTL_PORT_P); ASSERT_TRUE(dma != NULL); diff --git a/tests/src/log.h b/tests/src/log.h index ead3a3c62..8cd9ae7b4 100644 --- a/tests/src/log.h +++ b/tests/src/log.h @@ -10,24 +10,24 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) diff --git a/tests/src/sch_test.cpp b/tests/src/sch_test.cpp index 3a622c63e..7586d7ce0 100644 --- a/tests/src/sch_test.cpp +++ b/tests/src/sch_test.cpp @@ -41,8 +41,7 @@ static void sch_create_max_test(mtl_handle mt, int max) { for (int i = 0; i < max; i++) { mtl_sch_handle sch = mtl_sch_create(mt, &sch_ops); - if (!sch) - break; + if (!sch) break; ret = mtl_sch_start(sch); if (ret < 0) { ret = mtl_sch_free(sch); @@ -113,8 +112,7 @@ static int test_tasklet_handler(void *priv) { return 0; } -static void sch_tasklet_digest_test(mtl_handle mt, - struct sch_digest_test_para *para) { +static void sch_tasklet_digest_test(mtl_handle mt, struct sch_digest_test_para *para) { const int sch_cnt = para->sch_cnt; int tasklet_cnt = para->tasklets; std::vector schs(sch_cnt); diff --git a/tests/src/st20_test.cpp b/tests/src/st20_test.cpp index 5db26fc30..41c7885eb 100644 --- a/tests/src/st20_test.cpp +++ b/tests/src/st20_test.cpp @@ -17,12 +17,11 @@ static int tx_next_video_frame(void *priv, uint16_t *next_frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ if (ctx->slice) { - uint8_t *fb = (uint8_t *)st20_tx_get_framebuffer( - (st20_tx_handle)ctx->handle, ctx->fb_idx); + uint8_t *fb = + (uint8_t *)st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, ctx->fb_idx); memset(fb, 0x0, ctx->frame_size); ctx->lines_ready[ctx->fb_idx] = 0; } @@ -30,11 +29,9 @@ static int tx_next_video_frame(void *priv, uint16_t *next_frame_idx, *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -42,8 +39,7 @@ static int tx_next_video_frame_timestamp(void *priv, uint16_t *next_frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ if (!ctx->ptp_time_first_frame) { ctx->ptp_time_first_frame = mtl_ptp_read_time(ctx->ctx->handle); @@ -53,20 +49,17 @@ static int tx_next_video_frame_timestamp(void *priv, uint16_t *next_frame_idx, if (ctx->user_pacing) { meta->tfmt = ST10_TIMESTAMP_FMT_TAI; - meta->timestamp = - ctx->ptp_time_first_frame + ctx->frame_time * ctx->fb_send * 2; + meta->timestamp = ctx->ptp_time_first_frame + ctx->frame_time * ctx->fb_send * 2; } else if (ctx->user_timestamp) { meta->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; meta->timestamp = ctx->fb_send; } - dbg("%s, next_frame_idx %u timestamp %" PRIu64 "\n", __func__, - *next_frame_idx, meta->timestamp); + dbg("%s, next_frame_idx %u timestamp %" PRIu64 "\n", __func__, *next_frame_idx, + meta->timestamp); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -74,8 +67,7 @@ static int tx_next_ext_video_frame(void *priv, uint16_t *next_frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ if (ctx->ext_fb_in_use[ctx->fb_idx]) { err("%s, ext frame %d not available\n", __func__, ctx->fb_idx); @@ -85,8 +77,7 @@ static int tx_next_ext_video_frame(void *priv, uint16_t *next_frame_idx, int ret = st20_tx_set_ext_frame((st20_tx_handle)ctx->handle, ctx->fb_idx, &ctx->ext_frames[ctx->fb_idx]); if (ret < 0) { - err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, - ctx->fb_idx); + err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, ctx->fb_idx); return -EIO; } ctx->ext_fb_in_use[ctx->fb_idx] = true; @@ -94,11 +85,9 @@ static int tx_next_ext_video_frame(void *priv, uint16_t *next_frame_idx, *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -106,8 +95,7 @@ static int tx_next_ext_video_field(void *priv, uint16_t *next_frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ if (ctx->ext_fb_in_use[ctx->fb_idx]) { err("%s, ext frame %d not available\n", __func__, ctx->fb_idx); @@ -117,8 +105,7 @@ static int tx_next_ext_video_field(void *priv, uint16_t *next_frame_idx, int ret = st20_tx_set_ext_frame((st20_tx_handle)ctx->handle, ctx->fb_idx, &ctx->ext_frames[ctx->fb_idx]); if (ret < 0) { - err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, - ctx->fb_idx); + err("%s, set ext framebuffer fail %d fb_idx %d\n", __func__, ret, ctx->fb_idx); return -EIO; } ctx->ext_fb_in_use[ctx->fb_idx] = true; @@ -127,11 +114,9 @@ static int tx_next_ext_video_field(void *priv, uint16_t *next_frame_idx, meta->second_field = ctx->fb_send % 2 ? true : false; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -139,11 +124,9 @@ static int tx_notify_ext_frame_done(void *priv, uint16_t frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ - void *frame_addr = - st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, frame_idx); + void *frame_addr = st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, frame_idx); for (int i = 0; i < ctx->fb_cnt; ++i) { if (frame_addr == ctx->ext_frames[i].buf_addr) { ctx->ext_fb_in_use[i] = false; @@ -159,12 +142,10 @@ static int tx_notify_timestamp_frame_done(void *priv, uint16_t frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ if (ctx->user_timestamp && !ctx->user_pacing) { - dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, - ctx->pre_timestamp); + dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, ctx->pre_timestamp); } ctx->pre_timestamp = meta->timestamp; @@ -173,22 +154,22 @@ static int tx_notify_timestamp_frame_done(void *priv, uint16_t frame_idx, static enum st_fps tmstamp_delta_to_fps(int delta) { switch (delta) { - case 1500: - return ST_FPS_P60; - case 1501: - case 1502: - return ST_FPS_P59_94; - case 1800: - return ST_FPS_P50; - case 3000: - return ST_FPS_P30; - case 3003: - return ST_FPS_P29_97; - case 3600: - return ST_FPS_P25; - default: - dbg("%s, err delta %d\n", __func__, delta); - break; + case 1500: + return ST_FPS_P60; + case 1501: + case 1502: + return ST_FPS_P59_94; + case 1800: + return ST_FPS_P50; + case 3000: + return ST_FPS_P30; + case 3003: + return ST_FPS_P29_97; + case 3600: + return ST_FPS_P25; + default: + dbg("%s, err delta %d\n", __func__, delta); + break; } return ST_FPS_MAX; } @@ -197,8 +178,7 @@ static int tx_notify_frame_done_check_tmstamp(void *priv, uint16_t frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) { if (ctx->rtp_tmstamp == 0) @@ -220,18 +200,15 @@ static int tx_next_video_field(void *priv, uint16_t *next_frame_idx, struct st20_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; meta->second_field = ctx->fb_send % 2 ? true : false; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -239,11 +216,10 @@ static int tx_frame_lines_ready(void *priv, uint16_t frame_idx, struct st20_tx_slice_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ - uint8_t *fb = (uint8_t *)st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, - frame_idx); + uint8_t *fb = + (uint8_t *)st20_tx_get_framebuffer((st20_tx_handle)ctx->handle, frame_idx); int offset = ctx->lines_ready[frame_idx] * ctx->stride; uint16_t lines = ctx->lines_per_slice; if (ctx->lines_ready[frame_idx] + lines > ctx->height) @@ -271,11 +247,9 @@ static int tx_video_build_ooo_mapping(tests_context *s) { } int ooo_pkts = rand() % 4; - if (ooo_pkts <= 0) - ooo_pkts = 4; + if (ooo_pkts <= 0) ooo_pkts = 4; int ooo_start = rand() % 10; - if (ooo_start <= 0) - ooo_start = 10; + if (ooo_start <= 0) ooo_start = 10; int ooo_end = ooo_start + ooo_pkts; int ooo_step = total_pkts / 40; while (ooo_end < total_pkts) { @@ -298,8 +272,7 @@ static int tx_video_build_ooo_mapping(tests_context *s) { return 0; } -static int tx_video_build_rtp_packet(tests_context *s, - struct st20_rfc4175_rtp_hdr *rtp, +static int tx_video_build_rtp_packet(tests_context *s, struct st20_rfc4175_rtp_hdr *rtp, uint16_t *pkt_len) { struct st20_rfc4175_extra_rtp_hdr *e_rtp = NULL; int offset; @@ -307,20 +280,17 @@ static int tx_video_build_rtp_packet(tests_context *s, uint16_t row_number, row_offset; uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); int pkt_idx = s->pkt_idx; - if (s->out_of_order_pkt) - pkt_idx = s->ooo_mapping[s->pkt_idx]; + if (s->out_of_order_pkt) pkt_idx = s->ooo_mapping[s->pkt_idx]; if (s->single_line) { row_number = pkt_idx / s->pkts_in_line; int pixels_in_pkt = s->pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; row_offset = pixels_in_pkt * (pkt_idx % s->pkts_in_line); - offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * - s->st20_pg.size; + offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; } else { offset = s->pkt_data_len * pkt_idx; row_number = offset / s->bytes_in_line; - row_offset = - (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; + row_offset = (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; if ((offset + s->pkt_data_len > (row_number + 1) * s->bytes_in_line) && (offset + s->pkt_data_len < frame_size)) { e_rtp = (struct st20_rfc4175_extra_rtp_hdr *)payload; @@ -344,10 +314,9 @@ static int tx_video_build_rtp_packet(tests_context *s, rtp->base.seq_number = htons(s->seq_id); rtp->seq_number_ext = htons((uint16_t)(s->seq_id >> 16)); s->seq_id++; - int temp = - s->single_line - ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (frame_size - offset); + int temp = s->single_line + ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (frame_size - offset); uint16_t data_len = s->pkt_data_len > temp ? temp : s->pkt_data_len; rtp->row_length = htons(data_len); *pkt_len = data_len + sizeof(*rtp); @@ -362,8 +331,7 @@ static int tx_video_build_rtp_packet(tests_context *s, *pkt_len += sizeof(*e_rtp); } if (s->check_sha) { - mtl_memcpy(payload, s->frame_buf[s->fb_idx % TEST_SHA_HIST_NUM] + offset, - data_len); + mtl_memcpy(payload, s->frame_buf[s->fb_idx % TEST_SHA_HIST_NUM] + offset, data_len); } s->pkt_idx++; @@ -400,16 +368,14 @@ static void tx_feed_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - tx_video_build_rtp_packet(ctx, (struct st20_rfc4175_rtp_hdr *)usrptr, - &mbuf_len); + tx_video_build_rtp_packet(ctx, (struct st20_rfc4175_rtp_hdr *)usrptr, &mbuf_len); st20_tx_put_mbuf((st20_tx_handle)ctx->handle, mbuf, mbuf_len); } @@ -417,25 +383,21 @@ static void tx_feed_packet(void *args) { static int tx_rtp_done(void *args) { auto ctx = (tests_context *)args; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } static int rx_rtp_ready(void *args) { auto ctx = (tests_context *)args; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -464,8 +426,7 @@ static void rx_handle_rtp(tests_context *s, struct st20_rfc4175_rtp_hdr *hdr, row_number = ntohs(hdr->row_number); row_offset = ntohs(hdr->row_offset); row_length = ntohs(hdr->row_length); - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, - row_length); + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row_number, row_offset, row_length); if (row_offset & ST20_SRD_OFFSET_CONTINUATION) { /* additional Sample Row Data */ row_offset &= ~ST20_SRD_OFFSET_CONTINUATION; @@ -474,11 +435,11 @@ static void rx_handle_rtp(tests_context *s, struct st20_rfc4175_rtp_hdr *hdr, } /* copy the payload to target frame */ - uint32_t offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * - s->st20_pg.size; + uint32_t offset = + (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; if ((offset + row_length) > s->frame_size) { - err("%s(%d: invalid offset %u frame size %" PRIu64 "\n", __func__, idx, - offset, s->frame_size); + err("%s(%d: invalid offset %u frame size %" PRIu64 "\n", __func__, idx, offset, + s->frame_size); return; } mtl_memcpy(frame + offset, payload, row_length); @@ -487,13 +448,12 @@ static void rx_handle_rtp(tests_context *s, struct st20_rfc4175_rtp_hdr *hdr, uint16_t row2_offset = ntohs(e_hdr->row_offset); uint16_t row2_length = ntohs(e_hdr->row_length); - dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, - row2_length); - uint32_t offset2 = (row2_number * s->width + row2_offset) / - s->st20_pg.coverage * s->st20_pg.size; + dbg("%s(%d), row: %d %d %d\n", __func__, idx, row2_number, row2_offset, row2_length); + uint32_t offset2 = + (row2_number * s->width + row2_offset) / s->st20_pg.coverage * s->st20_pg.size; if ((offset2 + row2_length) > s->frame_size) { - err("%s(%d: invalid offset %u frame size %" PRIu64 " for extra hdr\n", - __func__, idx, offset2, s->frame_size); + err("%s(%d: invalid offset %u frame size %" PRIu64 " for extra hdr\n", __func__, + idx, offset2, s->frame_size); return; } mtl_memcpy(frame + offset2, payload + row_length, row2_length); @@ -519,8 +479,7 @@ static void rx_get_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } @@ -544,12 +503,10 @@ static void rx_get_packet(void *args) { } } -static int st20_rx_frame_ready(void *priv, void *frame, - struct st20_rx_frame_meta *meta) { +static int st20_rx_frame_ready(void *priv, void *frame, struct st20_rx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; if (st_is_frame_complete(meta->status)) { ctx->fb_rec++; @@ -558,8 +515,7 @@ static int st20_rx_frame_ready(void *priv, void *frame, ctx->start_time = st_test_get_monotonic_time(); } } - if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) - ctx->rtp_tmstamp = meta->timestamp; + if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) ctx->rtp_tmstamp = meta->timestamp; st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); return 0; } @@ -571,8 +527,7 @@ static void st20_tx_ops_init(tests_context *st20, struct st20_tx_ops *ops) { ops->name = "st20_test"; ops->priv = st20; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; + if (ctx->same_dual_port) ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -606,8 +561,7 @@ static void st20_rx_ops_init(tests_context *st20, struct st20_rx_ops *ops) { ops->name = "st20_test"; ops->priv = st20; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; + if (ctx->same_dual_port) ops->num_port = 1; memcpy(ops->ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -656,13 +610,21 @@ static void st20_rx_assert_cnt(int expect_s20_rx_cnt) { EXPECT_EQ(var.st20_rx_sessions_cnt, expect_s20_rx_cnt); } -TEST(St20_tx, create_free_single) { create_free_test(st20_tx, 0, 1, 1); } -TEST(St20_tx, create_free_multi) { create_free_test(st20_tx, 0, 1, 6); } -TEST(St20_tx, create_free_mix) { create_free_test(st20_tx, 2, 3, 4); } +TEST(St20_tx, create_free_single) { + create_free_test(st20_tx, 0, 1, 1); +} +TEST(St20_tx, create_free_multi) { + create_free_test(st20_tx, 0, 1, 6); +} +TEST(St20_tx, create_free_mix) { + create_free_test(st20_tx, 2, 3, 4); +} TEST(St20_tx, create_free_max) { create_free_max(st20_tx, TEST_CREATE_FREE_MAX); } -TEST(St20_tx, create_expect_fail) { expect_fail_test(st20_tx); } +TEST(St20_tx, create_expect_fail) { + expect_fail_test(st20_tx); +} TEST(St20_tx, create_expect_fail_fb_cnt) { uint16_t fbcnt = 1; expect_fail_test_fb_cnt(st20_tx, fbcnt); @@ -696,13 +658,21 @@ TEST(St20_tx, rtp_pkt_size) { expect_test_rtp_pkt_size(st20_tx, ST20_TYPE_RTP_LEVEL, rtp_pkt_size, false); } -TEST(St20_rx, create_free_single) { create_free_test(st20_rx, 0, 1, 1); } -TEST(St20_rx, create_free_multi) { create_free_test(st20_rx, 0, 1, 6); } -TEST(St20_rx, create_free_mix) { create_free_test(st20_rx, 2, 3, 4); } +TEST(St20_rx, create_free_single) { + create_free_test(st20_rx, 0, 1, 1); +} +TEST(St20_rx, create_free_multi) { + create_free_test(st20_rx, 0, 1, 6); +} +TEST(St20_rx, create_free_mix) { + create_free_test(st20_rx, 2, 3, 4); +} TEST(St20_rx, create_free_max) { create_free_max(st20_rx, TEST_CREATE_FREE_MAX); } -TEST(St20_rx, create_expect_fail) { expect_fail_test(st20_rx); } +TEST(St20_rx, create_expect_fail) { + expect_fail_test(st20_rx); +} TEST(St20_rx, create_expect_fail_fb_cnt) { uint16_t fbcnt = 0; expect_fail_test_fb_cnt(st20_rx, fbcnt); @@ -716,41 +686,35 @@ TEST(St20_rx, create_expect_fail_ring_sz) { expect_fail_test_rtp_ring(st20_rx, ST20_TYPE_RTP_LEVEL, ring_size); } -static void rtp_tx_specific_init(struct st20_tx_ops *ops, - tests_context *test_ctx) { +static void rtp_tx_specific_init(struct st20_tx_ops *ops, tests_context *test_ctx) { int ret; ret = st20_get_pgroup(ops->fmt, &test_ctx->st20_pg); ASSERT_TRUE(ret == 0); /* 4800 if 1080p yuv422 */ - size_t bytes_in_line = - ops->width * test_ctx->st20_pg.size / test_ctx->st20_pg.coverage; + size_t bytes_in_line = ops->width * test_ctx->st20_pg.size / test_ctx->st20_pg.coverage; if (ops->packing == ST20_PACKING_GPM_SL) { /* calculate pkts in line for rtp */ - size_t bytes_in_pkt = - MTL_PKT_MAX_RTP_BYTES - sizeof(struct st20_rfc4175_rtp_hdr); + size_t bytes_in_pkt = MTL_PKT_MAX_RTP_BYTES - sizeof(struct st20_rfc4175_rtp_hdr); int pkts_in_line = (bytes_in_line / bytes_in_pkt) + 1; test_ctx->total_pkts_in_frame = ops->height * pkts_in_line; int pixels_in_pkts = (ops->width + pkts_in_line - 1) / pkts_in_line; test_ctx->pkt_data_len = (pixels_in_pkts + test_ctx->st20_pg.coverage - 1) / - test_ctx->st20_pg.coverage * - test_ctx->st20_pg.size; + test_ctx->st20_pg.coverage * test_ctx->st20_pg.size; test_ctx->pkts_in_line = pkts_in_line; } else if (ops->packing == ST20_PACKING_BPM) { test_ctx->pkt_data_len = 1260; - int pixels_in_pkts = test_ctx->pkt_data_len * test_ctx->st20_pg.coverage / - test_ctx->st20_pg.size; + int pixels_in_pkts = + test_ctx->pkt_data_len * test_ctx->st20_pg.coverage / test_ctx->st20_pg.size; test_ctx->total_pkts_in_frame = ceil((double)ops->width * ops->height / pixels_in_pkts); } else if (ops->packing == ST20_PACKING_GPM) { - int max_data_len = MTL_PKT_MAX_RTP_BYTES - - sizeof(struct st20_rfc4175_rtp_hdr) - + int max_data_len = MTL_PKT_MAX_RTP_BYTES - sizeof(struct st20_rfc4175_rtp_hdr) - sizeof(struct st20_rfc4175_extra_rtp_hdr); int pg_per_pkt = max_data_len / test_ctx->st20_pg.size; - test_ctx->total_pkts_in_frame = - (ceil)((double)ops->width * ops->height / - (test_ctx->st20_pg.coverage * pg_per_pkt)); + test_ctx->total_pkts_in_frame = (ceil)((double)ops->width * ops->height / + (test_ctx->st20_pg.coverage * pg_per_pkt)); test_ctx->pkt_data_len = pg_per_pkt * test_ctx->st20_pg.size; } else { err("%s, invalid packing mode: %d\n", __func__, ops->packing); @@ -763,22 +727,20 @@ static void rtp_tx_specific_init(struct st20_tx_ops *ops, test_ctx->bytes_in_line = bytes_in_line; test_ctx->width = ops->width; test_ctx->single_line = (ops->packing == ST20_PACKING_GPM_SL); - test_ctx->frame_size = ops->width * ops->height * test_ctx->st20_pg.size / - test_ctx->st20_pg.coverage; + test_ctx->frame_size = + ops->width * ops->height * test_ctx->st20_pg.size / test_ctx->st20_pg.coverage; ops->rtp_frame_total_pkts = test_ctx->total_pkts_in_frame; - ops->rtp_pkt_size = - test_ctx->pkt_data_len + sizeof(struct st20_rfc4175_rtp_hdr); + ops->rtp_pkt_size = test_ctx->pkt_data_len + sizeof(struct st20_rfc4175_rtp_hdr); if (ops->packing != ST20_PACKING_GPM_SL) /* no extra for GPM_SL */ ops->rtp_pkt_size += sizeof(struct st20_rfc4175_extra_rtp_hdr); ops->notify_rtp_done = tx_rtp_done; ops->rtp_ring_size = 1024; } -static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], - int width[], int height[], enum st20_fmt fmt, - enum st_test_level level, int sessions = 1, - bool ext_buf = false) { +static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], int width[], + int height[], enum st20_fmt fmt, enum st_test_level level, + int sessions = 1, bool ext_buf = false) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -791,8 +753,7 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], std::vector rtp_thread; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ext_buf) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -843,23 +804,20 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], sizeof(*test_ctx[i]->ext_frames) * test_ctx[i]->fb_cnt); size_t pg_sz = mtl_page_size(m_handle); size_t fb_size = test_ctx[i]->frame_size * test_ctx[i]->fb_cnt; - test_ctx[i]->ext_fb_iova_map_sz = - mtl_size_page_align(fb_size, pg_sz); /* align */ + test_ctx[i]->ext_fb_iova_map_sz = mtl_size_page_align(fb_size, pg_sz); /* align */ size_t fb_size_malloc = test_ctx[i]->ext_fb_iova_map_sz + pg_sz; test_ctx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx[i]->ext_fb_malloc != NULL); test_ctx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx[i]->ext_fb_malloc, pg_sz); - test_ctx[i]->ext_fb_iova = mtl_dma_map(m_handle, test_ctx[i]->ext_fb, - test_ctx[i]->ext_fb_iova_map_sz); + test_ctx[i]->ext_fb_iova = + mtl_dma_map(m_handle, test_ctx[i]->ext_fb, test_ctx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx[i]->ext_fb); ASSERT_TRUE(test_ctx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx[i]->fb_cnt; j++) { - test_ctx[i]->ext_frames[j].buf_addr = - test_ctx[i]->ext_fb + j * frame_size; - test_ctx[i]->ext_frames[j].buf_iova = - test_ctx[i]->ext_fb_iova + j * frame_size; + test_ctx[i]->ext_frames[j].buf_addr = test_ctx[i]->ext_fb + j * frame_size; + test_ctx[i]->ext_frames[j].buf_iova = test_ctx[i]->ext_fb_iova + j * frame_size; test_ctx[i]->ext_frames[j].buf_len = frame_size; } } @@ -881,8 +839,7 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx[i]->fb_send / time_sec; if (type[i] == ST20_TYPE_RTP_LEVEL) { test_ctx[i]->stop = true; @@ -899,8 +856,8 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx[i]->fb_send, 0); EXPECT_LE(test_ctx[i]->tx_tmstamp_delta_fail_cnt, 1); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, - test_ctx[i]->fb_send, framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx[i]->fb_send, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_tx_free(handle[i]); EXPECT_GE(ret, 0); @@ -913,25 +870,24 @@ static void st20_tx_fps_test(enum st20_type type[], enum st_fps fps[], } } -static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], - int width[], int height[], enum st20_fmt fmt, - enum st_test_level level, int sessions = 1, - bool ext_buf = false) { +static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], int width[], + int height[], enum st20_fmt fmt, enum st_test_level level, + int sessions = 1, bool ext_buf = false) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ext_buf) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -972,11 +928,11 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -1024,14 +980,13 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( - m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); + test_ctx_rx[i]->ext_fb_iova = mtl_dma_map(m_handle, test_ctx_rx[i]->ext_fb, + test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - test_ctx_rx[i]->ext_frames[j].buf_addr = - test_ctx_rx[i]->ext_fb + j * frame_size; + test_ctx_rx[i]->ext_frames[j].buf_addr = test_ctx_rx[i]->ext_fb + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_iova = test_ctx_rx[i]->ext_fb_iova + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_len = frame_size; @@ -1084,8 +1039,7 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST20_TYPE_RTP_LEVEL) { @@ -1108,16 +1062,15 @@ static void st20_rx_fps_test(enum st20_type type[], enum st_fps fps[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); ret = st20_rx_free(rx_handle[i]); EXPECT_GE(ret, 0); if (ext_buf) { - mtl_dma_unmap(m_handle, test_ctx_rx[i]->ext_fb, - test_ctx_rx[i]->ext_fb_iova, + mtl_dma_unmap(m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova, test_ctx_rx[i]->ext_fb_iova_map_sz); } tests_context_unit(test_ctx_tx[i]); @@ -1132,64 +1085,56 @@ TEST(St20_tx, rtp_1080p_fps59_94_s1) { enum st_fps fps[1] = {ST_FPS_P59_94}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps29_97_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P29_97}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps50_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps30_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P30}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_fps60_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P60}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, rtp_720p_fps50_s1) { enum st20_type type[1] = {ST20_TYPE_RTP_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1280}; int height[1] = {720}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_yuv422_8bit_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_8BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_8BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, frame_1080p_yuv420_10bit_s1) { enum st20_type type[1] = {ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, - ST_TEST_LEVEL_ALL); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_tx, mix_1080p_fps59_94_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL, @@ -1197,8 +1142,8 @@ TEST(St20_tx, mix_1080p_fps59_94_s3) { enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P59_94, ST_FPS_P59_94}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 3); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 3); } TEST(St20_tx, mix_720p_fps29_97_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL, @@ -1206,24 +1151,24 @@ TEST(St20_tx, mix_720p_fps29_97_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P29_97, ST_FPS_P29_97}; int width[3] = {1280, 1280, 1280}; int height[3] = {720, 720, 720}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 3); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 3); } TEST(St20_tx, mix_1080p_fps50_fps29_97) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P29_97}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 2); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 2); } TEST(St20_tx, mix_1080p_fps50_fps59_94) { enum st20_type type[2] = {ST20_TYPE_RTP_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 2); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 2); } TEST(St20_tx, ext_frame_1080p_fps_mix_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1231,8 +1176,8 @@ TEST(St20_tx, ext_frame_1080p_fps_mix_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P59_94, ST_FPS_P50}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 3, true); + st20_tx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, 3, + true); } TEST(St20_rx, frame_1080p_fps50_s1) { @@ -1240,8 +1185,7 @@ TEST(St20_rx, frame_1080p_fps50_s1) { enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1920}; int height[1] = {1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, - ST_TEST_LEVEL_ALL); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_rx, mix_1080p_fps50_s3) { enum st20_type type[3] = {ST20_TYPE_RTP_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1249,24 +1193,22 @@ TEST(St20_rx, mix_1080p_fps50_s3) { enum st_fps fps[3] = {ST_FPS_P50, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 3); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 3); } TEST(St20_rx, rtp_1080p_fps59_94_s1) { enum st20_type type[1] = {ST20_TYPE_RTP_LEVEL}; enum st_fps fps[1] = {ST_FPS_P59_94}; int width[1] = {1920}; int height[1] = {1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, - ST_TEST_LEVEL_ALL); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_420_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_rx, rtp_1080p_fps29_97_s1) { enum st20_type type[1] = {ST20_TYPE_RTP_LEVEL}; enum st_fps fps[1] = {ST_FPS_P29_97}; int width[1] = {1920}; int height[1] = {1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL); } TEST(St20_rx, frame_1080p_fps29_97_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1274,32 +1216,32 @@ TEST(St20_rx, frame_1080p_fps29_97_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P29_97, ST_FPS_P29_97}; int width[3] = {1920, 1920, 1920}; int height[3] = {1080, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 3); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 3); } TEST(St20_rx, mix_1080p_fps29_97_fp50) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; enum st_fps fps[2] = {ST_FPS_P29_97, ST_FPS_P50}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 2); } TEST(St20_rx, mix_1080p_fps59_94_fp50) { enum st20_type type[2] = {ST20_TYPE_RTP_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P50}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 2); } TEST(St20_rx, mix_1080p_fps29_97_720p_fp50) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; enum st_fps fps[2] = {ST_FPS_P29_97, ST_FPS_P50}; int width[2] = {1920, 1280}; int height[2] = {1080, 720}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 2); } TEST(St20_rx, ext_frame_1080p_fps_mix_s3) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, @@ -1307,8 +1249,8 @@ TEST(St20_rx, ext_frame_1080p_fps_mix_s3) { enum st_fps fps[3] = {ST_FPS_P29_97, ST_FPS_P59_94, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 3, true); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, 3, + true); } TEST(St20_tx, mix_s3) { @@ -1335,8 +1277,8 @@ TEST(St20_rx, frame_s3) { enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P29_97}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 3); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 3); } TEST(St20_rx, mix_s2) { enum st20_type type[2] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_RTP_LEVEL}; @@ -1351,8 +1293,8 @@ TEST(St20_rx, frame_mix_4k_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P50}; int width[2] = {1280, 3840}; int height[2] = {720, 2160}; - st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, - ST_TEST_LEVEL_ALL, 2); + st20_rx_fps_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, ST_TEST_LEVEL_ALL, + 2); } TEST(St20_rx, ext_frame_mix_s2) { enum st20_type type[3] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; @@ -1363,26 +1305,25 @@ TEST(St20_rx, ext_frame_mix_s2) { ST_TEST_LEVEL_MANDATORY, 2, true); } -static void -st20_rx_update_src_test(enum st20_type type, int tx_sessions, - enum st_test_level level = ST_TEST_LEVEL_ALL) { +static void st20_rx_update_src_test(enum st20_type type, int tx_sessions, + enum st_test_level level = ST_TEST_LEVEL_ALL) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } ASSERT_TRUE(tx_sessions >= 1); bool tx_update_dst = (tx_sessions == 1); /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; int rx_sessions = 1; // 1501/1502 for one frame, max two frames. @@ -1422,17 +1363,17 @@ st20_rx_update_src_test(enum st20_type type, int tx_sessions, ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -1490,8 +1431,7 @@ st20_rx_update_src_test(enum st20_type type, int tx_sessions, ops_rx.notify_frame_ready = st20_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; ops_rx.rtp_ring_size = 1024; - ops_rx.flags = - ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; + ops_rx.flags = ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; rx_handle[i] = st20_rx_create(m_handle, &ops_rx); test_ctx_rx[i]->total_pkts_in_frame = test_ctx_tx[i]->total_pkts_in_frame; @@ -1536,8 +1476,7 @@ st20_rx_update_src_test(enum st20_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1566,8 +1505,7 @@ st20_rx_update_src_test(enum st20_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1605,8 +1543,7 @@ st20_rx_update_src_test(enum st20_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1683,8 +1620,7 @@ static int st20_digest_rx_frame_ready(void *priv, void *frame, *in_use = false; } - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; ctx->slice_recv_timestamp = 0; ctx->slice_recv_lines = 0; @@ -1711,8 +1647,8 @@ static int st20_digest_rx_frame_ready(void *priv, void *frame, } if (meta->fpt > (ctx->frame_time / 10)) { ctx->meta_timing_fail_cnt++; - dbg("%s(%d), fpt %" PRId64 ", frame time %fms\n", __func__, ctx->idx, - meta->fpt, ctx->frame_time / NS_PER_MS); + dbg("%s(%d), fpt %" PRId64 ", frame time %fms\n", __func__, ctx->idx, meta->fpt, + ctx->frame_time / NS_PER_MS); } double rx_time = (double)meta->timestamp_last_pkt - meta->timestamp_first_pkt; if (rx_time > ctx->frame_time) { @@ -1721,8 +1657,7 @@ static int st20_digest_rx_frame_ready(void *priv, void *frame, } if (ctx->user_timestamp && !ctx->user_pacing) { - dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, - ctx->pre_timestamp); + dbg("%s, timestamp %u %u\n", __func__, (uint32_t)meta->timestamp, ctx->pre_timestamp); if (ctx->pre_timestamp) { if ((uint32_t)meta->timestamp != (ctx->pre_timestamp + 1)) { ctx->incomplete_frame_cnt++; @@ -1739,8 +1674,7 @@ static int st20_digest_rx_frame_ready(void *priv, void *frame, st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); } ctx->fb_rec++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -1749,9 +1683,8 @@ static int st20_digest_rx_frame_ready(void *priv, void *frame, static void dump_slice_meta(struct st20_rx_slice_meta *meta) { info("%s, width %u height %u fps %d fmd %d field %d\n", __func__, meta->width, meta->height, meta->fps, meta->fmt, meta->second_field); - info("%s, frame total size %" PRIu64 " recv size %" PRIu64 " recv lines %u\n", - __func__, meta->frame_total_size, meta->frame_recv_size, - meta->frame_recv_lines); + info("%s, frame total size %" PRIu64 " recv size %" PRIu64 " recv lines %u\n", __func__, + meta->frame_total_size, meta->frame_recv_size, meta->frame_recv_lines); } #endif @@ -1759,23 +1692,17 @@ static int st20_digest_rx_slice_ready(void *priv, void *frame, struct st20_rx_slice_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; #if DUMP_INCOMPLITE_SLICE int old_incomplete_slice_cnt = ctx->incomplete_slice_cnt; #endif ctx->slice_cnt++; - struct st20_rx_slice_meta *expect_meta = - (struct st20_rx_slice_meta *)ctx->priv; - if (expect_meta->width != meta->width) - ctx->incomplete_slice_cnt++; - if (expect_meta->height != meta->height) - ctx->incomplete_slice_cnt++; - if (expect_meta->fps != meta->fps) - ctx->incomplete_slice_cnt++; - if (expect_meta->fmt != meta->fmt) - ctx->incomplete_slice_cnt++; + struct st20_rx_slice_meta *expect_meta = (struct st20_rx_slice_meta *)ctx->priv; + if (expect_meta->width != meta->width) ctx->incomplete_slice_cnt++; + if (expect_meta->height != meta->height) ctx->incomplete_slice_cnt++; + if (expect_meta->fps != meta->fps) ctx->incomplete_slice_cnt++; + if (expect_meta->fmt != meta->fmt) ctx->incomplete_slice_cnt++; if (expect_meta->frame_total_size != meta->frame_total_size) { ctx->incomplete_slice_cnt++; } @@ -1786,8 +1713,8 @@ static int st20_digest_rx_slice_ready(void *priv, void *frame, meta->frame_recv_lines * meta->width * st20_pg.size / st20_pg.coverage; if (meta->frame_recv_size < frame_ready_size) { ctx->incomplete_slice_cnt++; - dbg("%s, recv_size err %" PRIu64 " %" PRIu64 "\n", __func__, - meta->frame_recv_size, frame_ready_size); + dbg("%s, recv_size err %" PRIu64 " %" PRIu64 "\n", __func__, meta->frame_recv_size, + frame_ready_size); } if (meta->frame_recv_lines < ctx->slice_recv_lines) { ctx->incomplete_slice_cnt++; @@ -1798,8 +1725,8 @@ static int st20_digest_rx_slice_ready(void *priv, void *frame, } else { if (ctx->slice_recv_timestamp != meta->timestamp) { ctx->incomplete_slice_cnt++; - dbg("%s, time stamp err %" PRIu64 " %" PRIu64 "\n", __func__, - meta->timestamp, ctx->slice_recv_timestamp); + dbg("%s, time stamp err %" PRIu64 " %" PRIu64 "\n", __func__, meta->timestamp, + ctx->slice_recv_timestamp); } } #if DUMP_INCOMPLITE_SLICE @@ -1816,8 +1743,7 @@ static int st20_digest_rx_field_ready(void *priv, void *frame, struct st20_rx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; ctx->slice_recv_timestamp = 0; ctx->slice_recv_lines = 0; @@ -1852,8 +1778,7 @@ static int st20_digest_rx_field_ready(void *priv, void *frame, st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); } ctx->fb_rec++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); dbg("%s, frame %p\n", __func__, frame); return 0; } @@ -1865,8 +1790,7 @@ static void st20_digest_rx_frame_check(void *args) { while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } else { @@ -1874,12 +1798,11 @@ static void st20_digest_rx_frame_check(void *args) { ctx->buf_q.pop(); dbg("%s, frame %p\n", __func__, frame); int i; - SHA256((unsigned char *)frame, - ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, result); + SHA256((unsigned char *)frame, ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, + result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20_rx_error_sha", result); @@ -1898,8 +1821,7 @@ static void st20_digest_rx_field_check(void *args) { while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } else { @@ -1909,12 +1831,11 @@ static void st20_digest_rx_field_check(void *args) { ctx->second_field_q.pop(); dbg("%s, frame %p\n", __func__, frame); int i; - SHA256((unsigned char *)frame, - ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, result); + SHA256((unsigned char *)frame, ctx->uframe_size ? ctx->uframe_size : ctx->fb_size, + result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20_rx_error_sha", result); @@ -1931,13 +1852,13 @@ static void st20_digest_rx_field_check(void *args) { } } -static void -st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], - enum st20_packing packing[], enum st_fps fps[], int width[], - int height[], bool interlaced[], enum st20_fmt fmt[], - bool check_fps, enum st_test_level level, int sessions = 1, - bool out_of_order = false, bool hdr_split = false, - bool enable_rtcp = false) { +static void st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], + enum st20_packing packing[], enum st_fps fps[], + int width[], int height[], bool interlaced[], + enum st20_fmt fmt[], bool check_fps, + enum st_test_level level, int sessions = 1, + bool out_of_order = false, bool hdr_split = false, + bool enable_rtcp = false) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -1945,13 +1866,13 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -1993,11 +1914,11 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); if (hdr_split) @@ -2014,8 +1935,7 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], ops_tx.fmt = fmt[i]; ops_tx.payload_type = ST20_TEST_PAYLOAD_TYPE; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; - ops_tx.get_next_frame = - interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; ops_tx.query_frame_lines_ready = tx_frame_lines_ready; if (tx_type[i] == ST20_TYPE_RTP_LEVEL) { rtp_tx_specific_init(&ops_tx, test_ctx_tx[i]); @@ -2027,8 +1947,8 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], // out of order if (out_of_order) { - test_ctx_tx[i]->ooo_mapping = (int *)st_test_zmalloc( - sizeof(int) * test_ctx_tx[i]->total_pkts_in_frame); + test_ctx_tx[i]->ooo_mapping = + (int *)st_test_zmalloc(sizeof(int) * test_ctx_tx[i]->total_pkts_in_frame); ASSERT_TRUE(test_ctx_tx[i]->ooo_mapping != NULL); tx_video_build_ooo_mapping(test_ctx_tx[i]); } @@ -2040,14 +1960,11 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = - ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) - frame_size = frame_size >> 1; + size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) frame_size = frame_size >> 1; if (tx_type[i] == ST20_TYPE_FRAME_LEVEL) { EXPECT_EQ(st20_tx_get_framebuffer_size(tx_handle[i]), frame_size); - EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), - test_ctx_tx[i]->fb_cnt); + EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), test_ctx_tx[i]->fb_cnt); } test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->slice = (tx_type[i] == ST20_TYPE_SLICE_LEVEL); @@ -2059,8 +1976,7 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], if (tx_type[i] == ST20_TYPE_FRAME_LEVEL) { fb = (uint8_t *)st20_tx_get_framebuffer(tx_handle[i], frame); } else { - test_ctx_tx[i]->frame_buf[frame] = - (uint8_t *)st_test_zmalloc(frame_size); + test_ctx_tx[i]->frame_buf[frame] = (uint8_t *)st_test_zmalloc(frame_size); fb = test_ctx_tx[i]->frame_buf[frame]; } ASSERT_TRUE(fb != NULL); @@ -2117,8 +2033,7 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], ops_rx.notify_rtp_ready = rx_rtp_ready; ops_rx.rtp_ring_size = 1024 * 2; ops_rx.flags = ST20_RX_FLAG_DMA_OFFLOAD; - if (hdr_split) - ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; + if (hdr_split) ops_rx.flags |= ST20_RX_FLAG_HDR_SPLIT; if (enable_rtcp) { ops_rx.flags |= ST20_RX_FLAG_ENABLE_RTCP | ST20_RX_FLAG_SIMULATE_PKT_LOSS; ops_rx.rtcp.nack_interval_us = 250; @@ -2130,8 +2045,8 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { /* set expect meta data to private */ - auto meta = (struct st20_rx_slice_meta *)st_test_zmalloc( - sizeof(struct st20_rx_slice_meta)); + auto meta = + (struct st20_rx_slice_meta *)st_test_zmalloc(sizeof(struct st20_rx_slice_meta)); ASSERT_TRUE(meta != NULL); meta->width = ops_rx.width; meta->height = ops_rx.height; @@ -2164,11 +2079,9 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], } else { test_ctx_rx[i]->stop = false; if (interlaced[i]) { - rtp_thread_rx[i] = - std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + rtp_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - rtp_thread_rx[i] = - std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + rtp_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } } @@ -2190,8 +2103,7 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (tx_type[i] == ST20_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -2239,10 +2151,8 @@ st20_rx_digest_test(enum st20_type tx_type[], enum st20_type rx_type[], test_ctx_rx[i]->fb_rec, framerate[i], test_ctx_tx[i]->fb_send); if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { int expect_slice_cnt = test_ctx_rx[i]->fb_rec * slices_per_frame; - if (interlaced[i]) - expect_slice_cnt /= 2; - EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, - expect_slice_cnt * 0.1); + if (interlaced[i]) expect_slice_cnt /= 2; + EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, expect_slice_cnt * 0.1); } if (check_fps) { EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); @@ -2267,8 +2177,8 @@ TEST(St20_rx, digest_frame_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, true, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest20_field_1080p_fps59_94_s1) { @@ -2280,8 +2190,8 @@ TEST(St20_rx, digest20_field_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, true, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_720p_fps59_94_s1_gpm) { @@ -2293,8 +2203,8 @@ TEST(St20_rx, digest_frame_720p_fps59_94_s1_gpm) { int height[1] = {720}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, true, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest20_field_720p_fps59_94_s1_gpm) { @@ -2306,8 +2216,8 @@ TEST(St20_rx, digest20_field_720p_fps59_94_s1_gpm) { int height[1] = {720}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, true, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_720p_fps29_97_s1_bpm) { @@ -2319,8 +2229,8 @@ TEST(St20_rx, digest_frame_720p_fps29_97_s1_bpm) { int height[1] = {720}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, true, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest20_field_720p_fps29_97_s1_bpm) { @@ -2332,8 +2242,8 @@ TEST(St20_rx, digest20_field_720p_fps29_97_s1_bpm) { int height[1] = {720}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, true, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_rtp_1080p_fps59_94_s1) { @@ -2345,8 +2255,8 @@ TEST(St20_rx, digest_rtp_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, true, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_720p_fps59_94_s3) { @@ -2362,8 +2272,8 @@ TEST(St20_rx, digest_frame_720p_fps59_94_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest20_field_720p_fps59_94_s3) { @@ -2379,8 +2289,8 @@ TEST(St20_rx, digest20_field_720p_fps59_94_s3) { bool interlaced[3] = {true, false, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest_frame_1080p_fps_mix_s3) { @@ -2396,8 +2306,8 @@ TEST(St20_rx, digest_frame_1080p_fps_mix_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest20_field_1080p_fps59_94_s3) { @@ -2413,8 +2323,8 @@ TEST(St20_rx, digest20_field_1080p_fps59_94_s3) { bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest_frame_1080p_fps59_94_s4_8bit) { @@ -2430,8 +2340,8 @@ TEST(St20_rx, digest_frame_1080p_fps59_94_s4_8bit) { bool interlaced[4] = {false, false, false, false}; enum st20_fmt fmt[4] = {ST20_FMT_YUV_422_8BIT, ST20_FMT_YUV_420_8BIT, ST20_FMT_YUV_444_8BIT, ST20_FMT_RGB_8BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 4); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 4); } TEST(St20_rx, digest20_field_4320p_fps59_94_s1) { @@ -2443,8 +2353,8 @@ TEST(St20_rx, digest20_field_4320p_fps59_94_s1) { int height[1] = {1080 * 4}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_s3) { @@ -2460,8 +2370,8 @@ TEST(St20_rx, digest_frame_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, digest_frame_field_s3) { @@ -2477,8 +2387,8 @@ TEST(St20_rx, digest_frame_field_s3) { bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 3); } TEST(St20_rx, digest_frame_rtp_s3) { @@ -2494,8 +2404,8 @@ TEST(St20_rx, digest_frame_rtp_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, digest_frame_s4_8bit) { @@ -2505,15 +2415,14 @@ TEST(St20_rx, digest_frame_s4_8bit) { ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st20_packing packing[4] = {ST20_PACKING_GPM_SL, ST20_PACKING_GPM_SL, ST20_PACKING_BPM, ST20_PACKING_GPM}; - enum st_fps fps[4] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P59_94, - ST_FPS_P119_88}; + enum st_fps fps[4] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P59_94, ST_FPS_P119_88}; int width[4] = {1920, 1920, 1920, 1280}; int height[4] = {1080, 1080, 1080, 720}; bool interlaced[4] = {false, false, false, false}; enum st20_fmt fmt[4] = {ST20_FMT_YUV_422_8BIT, ST20_FMT_YUV_420_8BIT, ST20_FMT_YUV_444_8BIT, ST20_FMT_RGB_8BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 4); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 4); } TEST(St20_rx, digest_frame_s4_10bit) { @@ -2521,16 +2430,16 @@ TEST(St20_rx, digest_frame_s4_10bit) { ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; enum st20_type rx_type[4] = {ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL, ST20_TYPE_FRAME_LEVEL}; - enum st20_packing packing[4] = {ST20_PACKING_GPM_SL, ST20_PACKING_GPM, - ST20_PACKING_BPM, ST20_PACKING_BPM}; + enum st20_packing packing[4] = {ST20_PACKING_GPM_SL, ST20_PACKING_GPM, ST20_PACKING_BPM, + ST20_PACKING_BPM}; enum st_fps fps[4] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P59_94, ST_FPS_P50}; int width[4] = {1920, 1920, 1920, 1280}; int height[4] = {1080, 1080, 1080, 720}; bool interlaced[4] = {false, false, false, false}; enum st20_fmt fmt[4] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_420_10BIT, ST20_FMT_YUV_444_10BIT, ST20_FMT_RGB_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 4); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 4); } TEST(St20_rx, digest_rtp_s3) { @@ -2546,8 +2455,8 @@ TEST(St20_rx, digest_rtp_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, digest_ooo_frame_s3) { @@ -2563,8 +2472,8 @@ TEST(St20_rx, digest_ooo_frame_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 3, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 3, true); } TEST(St20_rx, digest_tx_slice_s3) { @@ -2580,8 +2489,8 @@ TEST(St20_rx, digest_tx_slice_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 3, false); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 3, false); } TEST(St20_rx, digest_slice_s3) { @@ -2597,8 +2506,8 @@ TEST(St20_rx, digest_slice_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 3, false); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 3, false); } TEST(St20_rx, digest20_field_slice_s3) { @@ -2614,8 +2523,8 @@ TEST(St20_rx, digest20_field_slice_s3) { bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 3, false); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL, 3, false); } TEST(St20_rx, digest_ooo_slice_s3) { @@ -2631,8 +2540,8 @@ TEST(St20_rx, digest_ooo_slice_s3) { bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 3, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 3, true); } TEST(St20_rx, digest_frame_4320p_fps59_94_s1) { @@ -2644,8 +2553,8 @@ TEST(St20_rx, digest_frame_4320p_fps59_94_s1) { int height[1] = {1080 * 4}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, digest_frame_4096_2160_fps59_94_12bit_yuv444_s1) { @@ -2657,8 +2566,8 @@ TEST(St20_rx, digest_frame_4096_2160_fps59_94_12bit_yuv444_s1) { int height[1] = {2160}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_444_12BIT}; - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 1); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 1); } TEST(St20_rx, digest_slice_4320p) { @@ -2671,8 +2580,8 @@ TEST(St20_rx, digest_slice_4320p) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; if (st_test_dma_available(st_test_ctx())) { - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_ALL, 1); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, + false, ST_TEST_LEVEL_ALL, 1); } else { info("%s, skip as no dma available\n", __func__); } @@ -2688,8 +2597,8 @@ TEST(St20_rx, digest_ooo_slice_4320p) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; if (st_test_dma_available(st_test_ctx())) { - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 1, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, + false, ST_TEST_LEVEL_MANDATORY, 1, true); } else { info("%s, skip as no dma available\n", __func__); } @@ -2705,8 +2614,8 @@ TEST(St20_rx, digest_hdr_split) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; if (st_test_ctx()->hdr_split) { - st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, - fmt, false, ST_TEST_LEVEL_MANDATORY, 1, false, true); + st20_rx_digest_test(type, rx_type, packing, fps, width, height, interlaced, fmt, + false, ST_TEST_LEVEL_MANDATORY, 1, false, true); } else { info("%s, skip as no dma available\n", __func__); } @@ -2721,8 +2630,8 @@ TEST(St20_rx, digest_rtcp_s1) { bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; /* check fps */ - st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, - true, ST_TEST_LEVEL_ALL, 1, false, false, true); + st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL, 1, false, false, true); } TEST(St20_rx, digest_rtcp_s3) { @@ -2737,12 +2646,11 @@ TEST(St20_rx, digest_rtcp_s3) { enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; /* no fps check */ - st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, - false, ST_TEST_LEVEL_MANDATORY, 3, false, false, true); + st20_rx_digest_test(type, type, packing, fps, width, height, interlaced, fmt, false, + ST_TEST_LEVEL_MANDATORY, 3, false, false, true); } -static int st20_tx_meta_build_rtp(tests_context *s, - struct st20_rfc4175_rtp_hdr *rtp, +static int st20_tx_meta_build_rtp(tests_context *s, struct st20_rfc4175_rtp_hdr *rtp, uint16_t *pkt_len) { struct st20_rfc4175_extra_rtp_hdr *e_rtp = NULL; int offset; @@ -2755,13 +2663,11 @@ static int st20_tx_meta_build_rtp(tests_context *s, row_number = pkt_idx / s->pkts_in_line; int pixels_in_pkt = s->pkt_data_len / s->st20_pg.size * s->st20_pg.coverage; row_offset = pixels_in_pkt * (pkt_idx % s->pkts_in_line); - offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * - s->st20_pg.size; + offset = (row_number * s->width + row_offset) / s->st20_pg.coverage * s->st20_pg.size; } else { offset = s->pkt_data_len * pkt_idx; row_number = offset / s->bytes_in_line; - row_offset = - (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; + row_offset = (offset % s->bytes_in_line) * s->st20_pg.coverage / s->st20_pg.size; if ((offset + s->pkt_data_len > (row_number + 1) * s->bytes_in_line) && (offset + s->pkt_data_len < frame_size)) { e_rtp = (struct st20_rfc4175_extra_rtp_hdr *)payload; @@ -2783,10 +2689,9 @@ static int st20_tx_meta_build_rtp(tests_context *s, rtp->base.seq_number = htons(s->seq_id); rtp->seq_number_ext = htons((uint16_t)(s->seq_id >> 16)); s->seq_id++; - int temp = - s->single_line - ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) - : (frame_size - offset); + int temp = s->single_line + ? ((s->width - row_offset) / s->st20_pg.coverage * s->st20_pg.size) + : (frame_size - offset); uint16_t data_len = s->pkt_data_len > temp ? temp : s->pkt_data_len; rtp->row_length = htons(data_len); *pkt_len = data_len + sizeof(*rtp); @@ -2804,11 +2709,9 @@ static int st20_tx_meta_build_rtp(tests_context *s, s->pkt_idx++; /* build incomplete frame */ - if (s->pkt_idx >= s->total_pkts_in_frame) - marker = true; + if (s->pkt_idx >= s->total_pkts_in_frame) marker = true; if (s->fb_send % 2) { - if (s->pkt_idx >= (s->total_pkts_in_frame / 2)) - marker = true; + if (s->pkt_idx >= (s->total_pkts_in_frame / 2)) marker = true; } if (marker) { /* end of current frame */ @@ -2838,16 +2741,14 @@ static void st20_rx_meta_feed_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - st20_tx_meta_build_rtp(ctx, (struct st20_rfc4175_rtp_hdr *)usrptr, - &mbuf_len); + st20_tx_meta_build_rtp(ctx, (struct st20_rfc4175_rtp_hdr *)usrptr, &mbuf_len); st20_tx_put_mbuf((st20_tx_handle)ctx->handle, mbuf, mbuf_len); } @@ -2858,30 +2759,21 @@ static int st20_rx_meta_frame_ready(void *priv, void *frame, auto ctx = (tests_context *)priv; auto expect_meta = (struct st20_rx_frame_meta *)ctx->priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; ctx->fb_rec++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); - if (expect_meta->width != meta->width) - ctx->rx_meta_fail_cnt++; - if (expect_meta->height != meta->height) - ctx->rx_meta_fail_cnt++; - if (expect_meta->fps != meta->fps) - ctx->rx_meta_fail_cnt++; - if (expect_meta->fmt != meta->fmt) - ctx->rx_meta_fail_cnt++; - if (expect_meta->timestamp == meta->timestamp) - ctx->rx_meta_fail_cnt++; + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (expect_meta->width != meta->width) ctx->rx_meta_fail_cnt++; + if (expect_meta->height != meta->height) ctx->rx_meta_fail_cnt++; + if (expect_meta->fps != meta->fps) ctx->rx_meta_fail_cnt++; + if (expect_meta->fmt != meta->fmt) ctx->rx_meta_fail_cnt++; + if (expect_meta->timestamp == meta->timestamp) ctx->rx_meta_fail_cnt++; expect_meta->timestamp = meta->timestamp; if (!st_is_frame_complete(meta->status)) { ctx->incomplete_frame_cnt++; - if (meta->frame_total_size <= meta->frame_recv_size) - ctx->rx_meta_fail_cnt++; + if (meta->frame_total_size <= meta->frame_recv_size) ctx->rx_meta_fail_cnt++; } else { - if (meta->frame_total_size != meta->frame_recv_size) - ctx->rx_meta_fail_cnt++; + if (meta->frame_total_size != meta->frame_recv_size) ctx->rx_meta_fail_cnt++; } st20_rx_put_framebuff((st20_rx_handle)ctx->handle, frame); @@ -2896,9 +2788,10 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -2932,11 +2825,11 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -2986,8 +2879,7 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], ops_rx.fps = fps[i]; ops_rx.fmt = fmt; ops_rx.payload_type = ST20_TEST_PAYLOAD_TYPE; - ops_rx.flags = - ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; + ops_rx.flags = ST20_RX_FLAG_RECEIVE_INCOMPLETE_FRAME | ST20_RX_FLAG_DMA_OFFLOAD; ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st20_rx_meta_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -2998,8 +2890,8 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->stop = false; /* set expect meta data to private */ - auto meta = (struct st20_rx_frame_meta *)st_test_zmalloc( - sizeof(struct st20_rx_frame_meta)); + auto meta = + (struct st20_rx_frame_meta *)st_test_zmalloc(sizeof(struct st20_rx_frame_meta)); ASSERT_TRUE(meta != NULL); meta->width = ops_rx.width; meta->height = ops_rx.height; @@ -3017,8 +2909,7 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; /* stop all thread */ @@ -3037,13 +2928,12 @@ static void st20_rx_meta_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); float expect_incomplete_frame_cnt = (float)test_ctx_rx[i]->fb_rec / 2; - EXPECT_NEAR(test_ctx_rx[i]->incomplete_frame_cnt, - expect_incomplete_frame_cnt, expect_incomplete_frame_cnt * 0.1); + EXPECT_NEAR(test_ctx_rx[i]->incomplete_frame_cnt, expect_incomplete_frame_cnt, + expect_incomplete_frame_cnt * 0.1); EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); EXPECT_EQ(test_ctx_rx[i]->rx_meta_fail_cnt, 0); - info("%s, session %d fb_rec %d fb_incomplete %d framerate %f\n", __func__, - i, test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->incomplete_frame_cnt, - framerate[i]); + info("%s, session %d fb_rec %d fb_incomplete %d framerate %f\n", __func__, i, + test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->incomplete_frame_cnt, framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); @@ -3064,9 +2954,8 @@ TEST(St20_rx, frame_meta_1080p_fps59_94_s1) { } static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], - int width[], int height[], - enum st20_fmt fmt, int sessions, - int repeat, enum st_test_level level) { + int width[], int height[], enum st20_fmt fmt, + int sessions, int repeat, enum st_test_level level) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -3074,13 +2963,13 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -3120,11 +3009,11 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3162,11 +3051,11 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3197,8 +3086,7 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; /* stop rx rtp if */ @@ -3214,8 +3102,8 @@ static void st20_rx_after_start_test(enum st20_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_rx_free(rx_handle[i]); EXPECT_GE(ret, 0); @@ -3255,8 +3143,8 @@ TEST(St20_rx, after_start_frame_720p_fps50_s1_r1) { enum st_fps fps[1] = {ST_FPS_P50}; int width[1] = {1280}; int height[1] = {720}; - st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, - 1, ST_TEST_LEVEL_MANDATORY); + st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, 1, + ST_TEST_LEVEL_MANDATORY); } TEST(St20_rx, after_start_frame_720p_fps29_97_s1_r2) { @@ -3264,8 +3152,8 @@ TEST(St20_rx, after_start_frame_720p_fps29_97_s1_r2) { enum st_fps fps[1] = {ST_FPS_P29_97}; int width[1] = {1280}; int height[1] = {720}; - st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, - 2, ST_TEST_LEVEL_ALL); + st20_rx_after_start_test(type, fps, width, height, ST20_FMT_YUV_422_10BIT, 1, 2, + ST_TEST_LEVEL_ALL); } static int st20_rx_uframe_pg_callback(void *priv, void *frame, @@ -3288,10 +3176,9 @@ static int st20_rx_uframe_pg_callback(void *priv, void *frame, return 0; } -static void st20_rx_uframe_test(enum st20_type rx_type[], - enum st20_packing packing[], enum st_fps fps[], - int width[], int height[], bool interlaced[], - enum st20_fmt fmt, bool check_fps, +static void st20_rx_uframe_test(enum st20_type rx_type[], enum st20_packing packing[], + enum st_fps fps[], int width[], int height[], + bool interlaced[], enum st20_fmt fmt, bool check_fps, enum st_test_level level, int sessions = 1) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; @@ -3300,13 +3187,13 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -3344,11 +3231,11 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3362,8 +3249,7 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], ops_tx.fmt = fmt; ops_tx.payload_type = ST20_TEST_PAYLOAD_TYPE; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; - ops_tx.get_next_frame = - interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; tx_handle[i] = st20_tx_create(m_handle, &ops_tx); ASSERT_TRUE(tx_handle[i] != NULL); @@ -3371,24 +3257,19 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = - ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) - frame_size = frame_size >> 1; + size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) frame_size = frame_size >> 1; test_ctx_tx[i]->frame_size = frame_size; /* uframe fmt: yuv422 10bit planar */ - size_t uframe_size = - (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); - if (interlaced[i]) - uframe_size = uframe_size >> 1; + size_t uframe_size = (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); + if (interlaced[i]) uframe_size = uframe_size >> 1; test_ctx_tx[i]->uframe_size = uframe_size; test_ctx_tx[i]->slice = false; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; uint8_t *fb; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - test_ctx_tx[i]->frame_buf[frame] = - (uint8_t *)st_test_zmalloc(uframe_size); + test_ctx_tx[i]->frame_buf[frame] = (uint8_t *)st_test_zmalloc(uframe_size); fb = test_ctx_tx[i]->frame_buf[frame]; ASSERT_TRUE(fb != NULL); uint16_t *p10_u16 = (uint16_t *)fb; @@ -3400,8 +3281,8 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], test_sha_dump("st20_rx", result); struct st20_rfc4175_422_10_pg2_be *pg = - (struct st20_rfc4175_422_10_pg2_be *)st20_tx_get_framebuffer( - tx_handle[i], frame); + (struct st20_rfc4175_422_10_pg2_be *)st20_tx_get_framebuffer(tx_handle[i], + frame); st20_yuv422p10le_to_rfc4175_422be10( p10_u16, (p10_u16 + ops_tx.width * ops_tx.height), (p10_u16 + ops_tx.width * ops_tx.height * 3 / 2), pg, ops_tx.width, @@ -3449,15 +3330,14 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], ops_rx.notify_rtp_ready = rx_rtp_ready; ops_rx.rtp_ring_size = 1024 * 2; /* uframe fmt: yuv422 10bit planar */ - ops_rx.uframe_size = - (size_t)ops_rx.width * ops_rx.height * 2 * sizeof(uint16_t); + ops_rx.uframe_size = (size_t)ops_rx.width * ops_rx.height * 2 * sizeof(uint16_t); ops_rx.uframe_pg_callback = st20_rx_uframe_pg_callback; ops_rx.flags = ST20_RX_FLAG_DMA_OFFLOAD; if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { /* set expect meta data to private */ - auto meta = (struct st20_rx_slice_meta *)st_test_zmalloc( - sizeof(struct st20_rx_slice_meta)); + auto meta = + (struct st20_rx_slice_meta *)st_test_zmalloc(sizeof(struct st20_rx_slice_meta)); ASSERT_TRUE(meta != NULL); meta->width = ops_rx.width; meta->height = ops_rx.height; @@ -3483,11 +3363,9 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], test_ctx_rx[i]->handle = rx_handle[i]; test_ctx_rx[i]->stop = false; if (interlaced[i]) { - digest_thread_rx[i] = - std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + digest_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - digest_thread_rx[i] = - std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + digest_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } } @@ -3498,8 +3376,7 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -3520,14 +3397,12 @@ static void st20_rx_uframe_test(enum st20_type rx_type[], EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); else EXPECT_LE(test_ctx_rx[i]->sha_fail_cnt, 2); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { int expect_slice_cnt = test_ctx_rx[i]->fb_rec * slices_per_frame; - if (interlaced[i]) - expect_slice_cnt /= 2; - EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, - expect_slice_cnt * 0.1); + if (interlaced[i]) expect_slice_cnt /= 2; + EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, expect_slice_cnt * 0.1); } if (check_fps) { EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); @@ -3569,33 +3444,27 @@ static int st20_rx_detected(void *priv, const struct st20_detect_meta *meta, struct st20_detect_reply *reply) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ struct st20_rx_slice_meta *s_meta = (struct st20_rx_slice_meta *)ctx->priv; ctx->lines_per_slice = meta->height / 32; - if (s_meta) - reply->slice_lines = ctx->lines_per_slice; + if (s_meta) reply->slice_lines = ctx->lines_per_slice; if (ctx->uframe_size != 0) { /* uframe fmt: yuv422 10bit planar */ - ctx->uframe_size = - (size_t)meta->width * meta->height * 2 * sizeof(uint16_t); + ctx->uframe_size = (size_t)meta->width * meta->height * 2 * sizeof(uint16_t); reply->uframe_size = ctx->uframe_size; - if (s_meta) - s_meta->uframe_total_size = ctx->uframe_size; + if (s_meta) s_meta->uframe_total_size = ctx->uframe_size; } return 0; } -static void st20_rx_detect_test(enum st20_type tx_type[], - enum st20_type rx_type[], +static void st20_rx_detect_test(enum st20_type tx_type[], enum st20_type rx_type[], enum st20_packing packing[], enum st_fps fps[], int width[], int height[], bool interlaced[], - bool user_frame, enum st20_fmt fmt, - bool check_fps, enum st_test_level level, - int sessions = 1) { + bool user_frame, enum st20_fmt fmt, bool check_fps, + enum st_test_level level, int sessions = 1) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -3603,13 +3472,13 @@ static void st20_rx_detect_test(enum st20_type tx_type[], struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -3649,11 +3518,11 @@ static void st20_rx_detect_test(enum st20_type tx_type[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -3667,8 +3536,7 @@ static void st20_rx_detect_test(enum st20_type tx_type[], ops_tx.fmt = fmt; ops_tx.payload_type = ST20_TEST_PAYLOAD_TYPE; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; - ops_tx.get_next_frame = - interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; ops_tx.query_frame_lines_ready = tx_frame_lines_ready; tx_handle[i] = st20_tx_create(m_handle, &ops_tx); @@ -3677,25 +3545,20 @@ static void st20_rx_detect_test(enum st20_type tx_type[], /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = - ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) - frame_size = frame_size >> 1; + size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) frame_size = frame_size >> 1; test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; uint8_t *fb; if (user_frame) { /* uframe fmt: yuv422 10bit planar */ - size_t uframe_size = - (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); - if (interlaced[i]) - uframe_size = uframe_size >> 1; + size_t uframe_size = (size_t)ops_tx.width * ops_tx.height * 2 * sizeof(uint16_t); + if (interlaced[i]) uframe_size = uframe_size >> 1; test_ctx_tx[i]->uframe_size = uframe_size; test_ctx_tx[i]->slice = false; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - test_ctx_tx[i]->frame_buf[frame] = - (uint8_t *)st_test_zmalloc(uframe_size); + test_ctx_tx[i]->frame_buf[frame] = (uint8_t *)st_test_zmalloc(uframe_size); fb = test_ctx_tx[i]->frame_buf[frame]; ASSERT_TRUE(fb != NULL); uint16_t *p10_u16 = (uint16_t *)fb; @@ -3707,8 +3570,8 @@ static void st20_rx_detect_test(enum st20_type tx_type[], test_sha_dump("st20_rx", result); struct st20_rfc4175_422_10_pg2_be *pg = - (struct st20_rfc4175_422_10_pg2_be *)st20_tx_get_framebuffer( - tx_handle[i], frame); + (struct st20_rfc4175_422_10_pg2_be *)st20_tx_get_framebuffer(tx_handle[i], + frame); st20_yuv422p10le_to_rfc4175_422be10( p10_u16, (p10_u16 + ops_tx.width * ops_tx.height), (p10_u16 + ops_tx.width * ops_tx.height * 3 / 2), pg, ops_tx.width, @@ -3776,8 +3639,8 @@ static void st20_rx_detect_test(enum st20_type tx_type[], if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { /* set expect meta data to private */ - auto meta = (struct st20_rx_slice_meta *)st_test_zmalloc( - sizeof(struct st20_rx_slice_meta)); + auto meta = + (struct st20_rx_slice_meta *)st_test_zmalloc(sizeof(struct st20_rx_slice_meta)); ASSERT_TRUE(meta != NULL); meta->width = width[i]; meta->height = height[i]; @@ -3804,11 +3667,9 @@ static void st20_rx_detect_test(enum st20_type tx_type[], test_ctx_rx[i]->handle = rx_handle[i]; test_ctx_rx[i]->stop = false; if (interlaced[i]) { - rtp_thread_rx[i] = - std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + rtp_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - rtp_thread_rx[i] = - std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + rtp_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } } @@ -3819,8 +3680,7 @@ static void st20_rx_detect_test(enum st20_type tx_type[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -3844,14 +3704,12 @@ static void st20_rx_detect_test(enum st20_type tx_type[], EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); else EXPECT_LE(test_ctx_rx[i]->sha_fail_cnt, 2); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); if (rx_type[i] == ST20_TYPE_SLICE_LEVEL) { int expect_slice_cnt = test_ctx_rx[i]->fb_rec * slices_per_frame; - if (interlaced[i]) - expect_slice_cnt /= 2; - EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, - expect_slice_cnt * 0.1); + if (interlaced[i]) expect_slice_cnt /= 2; + EXPECT_NEAR(test_ctx_rx[i]->slice_cnt, expect_slice_cnt, expect_slice_cnt * 0.1); } if (check_fps) { EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); @@ -3876,9 +3734,8 @@ TEST(St20_rx, detect_1080p_fps59_94_s1) { int width[1] = {1920}; int height[1] = {1080}; bool interlaced[1] = {false}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, - false, ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_ALL, - 1); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, false, + ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_ALL, 1); } TEST(St20_rx, detect_uframe_mix_s2) { @@ -3889,9 +3746,8 @@ TEST(St20_rx, detect_uframe_mix_s2) { int width[2] = {1280, 1280}; int height[2] = {720, 720}; bool interlaced[2] = {false, false}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, - true, ST20_FMT_YUV_422_10BIT, false, - ST_TEST_LEVEL_MANDATORY, 2); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, true, + ST20_FMT_YUV_422_10BIT, false, ST_TEST_LEVEL_MANDATORY, 2); } TEST(St20_rx, detect_mix_frame_s3) { @@ -3905,9 +3761,8 @@ TEST(St20_rx, detect_mix_frame_s3) { int width[3] = {1280, 1920, 3840}; int height[3] = {720, 1080, 2160}; bool interlaced[3] = {false, false, true}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, - false, ST20_FMT_YUV_422_10BIT, true, - ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, false, + ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, detect_mix_slice_s3) { @@ -3921,23 +3776,22 @@ TEST(St20_rx, detect_mix_slice_s3) { int width[3] = {1280, 1920, 3840}; int height[3] = {720, 1080, 2160}; bool interlaced[3] = {false, false, true}; - st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, - false, ST20_FMT_YUV_422_10BIT, true, - ST_TEST_LEVEL_MANDATORY, 3); + st20_rx_detect_test(tx_type, rx_type, packing, fps, width, height, interlaced, false, + ST20_FMT_YUV_422_10BIT, true, ST_TEST_LEVEL_MANDATORY, 3); } -static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], - int width[], int height[], enum st20_fmt fmt, - int sessions = 1) { +static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], int width[], + int height[], enum st20_fmt fmt, int sessions = 1) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st20_tx_ops ops_tx; struct st20_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -3978,11 +3832,11 @@ static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -4065,14 +3919,12 @@ static void st20_rx_dump_test(enum st20_type type[], enum st_fps fps[], EXPECT_GE(ret, 0); EXPECT_EQ(meta.dumped_packets[MTL_SESSION_PORT_P], max_dump_packets); dbg("%s, file_name %s\n", __func__, meta.file_name[MTL_SESSION_PORT_P]); - if (ret >= 0) - remove(meta.file_name[MTL_SESSION_PORT_P]); + if (ret >= 0) remove(meta.file_name[MTL_SESSION_PORT_P]); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST20_TYPE_RTP_LEVEL) { @@ -4116,8 +3968,7 @@ TEST(St20_rx, pcap_dump) { static int rx_query_ext_frame(void *priv, st20_ext_frame *ext_frame, struct st20_rx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ int i = ctx->ext_idx; /* check ext_fb_in_use */ @@ -4135,15 +3986,15 @@ static int rx_query_ext_frame(void *priv, st20_ext_frame *ext_frame, ext_frame->opaque = &ctx->ext_fb_in_use[i]; - if (++ctx->ext_idx >= ctx->fb_cnt) - ctx->ext_idx = 0; + if (++ctx->ext_idx >= ctx->fb_cnt) ctx->ext_idx = 0; return 0; } -static void st20_tx_ext_frame_rx_digest_test( - enum st20_packing packing[], enum st_fps fps[], int width[], int height[], - bool interlaced[], enum st20_fmt fmt[], bool check_fps, - enum st_test_level level, int sessions = 1, bool dynamic = false) { +static void st20_tx_ext_frame_rx_digest_test(enum st20_packing packing[], + enum st_fps fps[], int width[], int height[], + bool interlaced[], enum st20_fmt fmt[], + bool check_fps, enum st_test_level level, + int sessions = 1, bool dynamic = false) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -4151,8 +4002,7 @@ static void st20_tx_ext_frame_rx_digest_test( struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->iova == MTL_IOVA_MODE_PA) { info("%s, skip as it's PA iova mode\n", __func__); @@ -4160,9 +4010,10 @@ static void st20_tx_ext_frame_rx_digest_test( } if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -4203,11 +4054,11 @@ static void st20_tx_ext_frame_rx_digest_test( ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -4232,13 +4083,10 @@ static void st20_tx_ext_frame_rx_digest_test( /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = - ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) - frame_size = frame_size >> 1; + size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) frame_size = frame_size >> 1; EXPECT_EQ(st20_tx_get_framebuffer_size(tx_handle[i]), frame_size); - EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), - test_ctx_tx[i]->fb_cnt); + EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), test_ctx_tx[i]->fb_cnt); test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; @@ -4248,21 +4096,19 @@ static void st20_tx_ext_frame_rx_digest_test( sizeof(*test_ctx_tx[i]->ext_frames) * test_ctx_tx[i]->fb_cnt); size_t pg_sz = mtl_page_size(m_handle); size_t fb_size = test_ctx_tx[i]->frame_size * test_ctx_tx[i]->fb_cnt; - test_ctx_tx[i]->ext_fb_iova_map_sz = - mtl_size_page_align(fb_size, pg_sz); /* align */ + test_ctx_tx[i]->ext_fb_iova_map_sz = mtl_size_page_align(fb_size, pg_sz); /* align */ size_t fb_size_malloc = test_ctx_tx[i]->ext_fb_iova_map_sz + pg_sz; test_ctx_tx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_malloc != NULL); test_ctx_tx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); - test_ctx_tx[i]->ext_fb_iova = mtl_dma_map( - m_handle, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); + test_ctx_tx[i]->ext_fb_iova = + mtl_dma_map(m_handle, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_iova != MTL_BAD_IOVA); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_tx[i]->ext_fb); for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { - test_ctx_tx[i]->ext_frames[j].buf_addr = - test_ctx_tx[i]->ext_fb + j * frame_size; + test_ctx_tx[i]->ext_frames[j].buf_addr = test_ctx_tx[i]->ext_fb + j * frame_size; test_ctx_tx[i]->ext_frames[j].buf_iova = test_ctx_tx[i]->ext_fb_iova + j * frame_size; test_ctx_tx[i]->ext_frames[j].buf_len = frame_size; @@ -4297,21 +4143,19 @@ static void st20_tx_ext_frame_rx_digest_test( size_t frame_size = st20_frame_size(fmt[i], width[i], height[i]); size_t pg_sz = mtl_page_size(m_handle); size_t fb_size = frame_size * test_ctx_rx[i]->fb_cnt; - test_ctx_rx[i]->ext_fb_iova_map_sz = - mtl_size_page_align(fb_size, pg_sz); /* align */ + test_ctx_rx[i]->ext_fb_iova_map_sz = mtl_size_page_align(fb_size, pg_sz); /* align */ size_t fb_size_malloc = test_ctx_rx[i]->ext_fb_iova_map_sz + pg_sz; test_ctx_rx[i]->ext_fb_malloc = st_test_zmalloc(fb_size_malloc); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( - m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); + test_ctx_rx[i]->ext_fb_iova = + mtl_dma_map(m_handle, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - test_ctx_rx[i]->ext_frames[j].buf_addr = - test_ctx_rx[i]->ext_fb + j * frame_size; + test_ctx_rx[i]->ext_frames[j].buf_addr = test_ctx_rx[i]->ext_fb + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_iova = test_ctx_rx[i]->ext_fb_iova + j * frame_size; test_ctx_rx[i]->ext_frames[j].buf_len = frame_size; @@ -4363,11 +4207,9 @@ static void st20_tx_ext_frame_rx_digest_test( test_ctx_rx[i]->stop = false; if (interlaced[i]) { - rtp_thread_rx[i] = - std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); + rtp_thread_rx[i] = std::thread(st20_digest_rx_field_check, test_ctx_rx[i]); } else { - rtp_thread_rx[i] = - std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); + rtp_thread_rx[i] = std::thread(st20_digest_rx_frame_check, test_ctx_rx[i]); } bool dma_enabled = st20_rx_dma_enabled(rx_handle[i]); @@ -4388,8 +4230,7 @@ static void st20_tx_ext_frame_rx_digest_test( for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -4436,8 +4277,8 @@ TEST(St20_rx, ext_frame_digest_frame_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, - true, ST_TEST_LEVEL_ALL); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, ext_frame_digest20_field_1080p_fps59_94_s1) { @@ -4447,8 +4288,8 @@ TEST(St20_rx, ext_frame_digest20_field_1080p_fps59_94_s1) { int height[1] = {1080}; bool interlaced[1] = {true}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, - true, ST_TEST_LEVEL_ALL); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, ext_frame_digest_frame_720p_fps59_94_s1_gpm) { @@ -4458,54 +4299,49 @@ TEST(St20_rx, ext_frame_digest_frame_720p_fps59_94_s1_gpm) { int height[1] = {720}; bool interlaced[1] = {false}; enum st20_fmt fmt[1] = {ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, - true, ST_TEST_LEVEL_ALL); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_ALL); } TEST(St20_rx, ext_frame_s3) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, - ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; bool interlaced[3] = {true, true, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, - true, ST_TEST_LEVEL_MANDATORY, 3); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, ext_frame_s3_2) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, - ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; bool interlaced[3] = {true, false, true}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_12BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_8BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, - true, ST_TEST_LEVEL_MANDATORY, 3); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, dynamic_ext_frame_s3) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, - ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_BPM, ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P29_97}; int width[3] = {1280, 1280, 1920}; int height[3] = {720, 720, 1080}; bool interlaced[3] = {false, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, - true, ST_TEST_LEVEL_MANDATORY, 3, true); + st20_tx_ext_frame_rx_digest_test(packing, fps, width, height, interlaced, fmt, true, + ST_TEST_LEVEL_MANDATORY, 3, true); } -static void st20_tx_user_pacing_test(int width[], int height[], - enum st20_fmt fmt[], bool user_pacing[], - bool user_timestamp[], - enum st_test_level level, - int sessions = 1) { +static void st20_tx_user_pacing_test(int width[], int height[], enum st20_fmt fmt[], + bool user_pacing[], bool user_timestamp[], + enum st_test_level level, int sessions = 1) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -4513,13 +4349,13 @@ static void st20_tx_user_pacing_test(int width[], int height[], struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -4565,11 +4401,11 @@ static void st20_tx_user_pacing_test(int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -4585,10 +4421,8 @@ static void st20_tx_user_pacing_test(int width[], int height[], ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_next_video_frame_timestamp; ops_tx.notify_frame_done = tx_notify_timestamp_frame_done; - if (user_pacing[i]) - ops_tx.flags |= ST20_TX_FLAG_USER_PACING; - if (user_timestamp[i]) - ops_tx.flags |= ST20_TX_FLAG_USER_TIMESTAMP; + if (user_pacing[i]) ops_tx.flags |= ST20_TX_FLAG_USER_PACING; + if (user_timestamp[i]) ops_tx.flags |= ST20_TX_FLAG_USER_TIMESTAMP; tx_handle[i] = st20_tx_create(m_handle, &ops_tx); ASSERT_TRUE(tx_handle[i] != NULL); @@ -4596,8 +4430,7 @@ static void st20_tx_user_pacing_test(int width[], int height[], /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = - ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; @@ -4670,8 +4503,7 @@ static void st20_tx_user_pacing_test(int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; rx_framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; tx_framerate[i] = test_ctx_tx[i]->fb_send / time_sec; @@ -4691,15 +4523,13 @@ static void st20_tx_user_pacing_test(int width[], int height[], EXPECT_LT(test_ctx_rx[i]->incomplete_frame_cnt, 2); EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, rx_framerate[i]); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, tx_framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + rx_framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + tx_framerate[i]); - EXPECT_NEAR(tx_framerate[i], expect_framerate[i], - expect_framerate[i] * 0.1); - EXPECT_NEAR(rx_framerate[i], expect_framerate[i], - expect_framerate[i] * 0.1); + EXPECT_NEAR(tx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); + EXPECT_NEAR(rx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st20_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); ret = st20_rx_free(rx_handle[i]); @@ -4722,9 +4552,8 @@ TEST(St20_tx, tx_user_pacing) { ST_TEST_LEVEL_MANDATORY, 3); } -static void st20_linesize_digest_test(enum st20_packing packing[], - enum st_fps fps[], int width[], - int height[], int linesize[], +static void st20_linesize_digest_test(enum st20_packing packing[], enum st_fps fps[], + int width[], int height[], int linesize[], bool interlaced[], enum st20_fmt fmt[], bool check_fps, enum st_test_level level, int sessions = 1, bool ext = false) { @@ -4735,8 +4564,7 @@ static void st20_linesize_digest_test(enum st20_packing packing[], struct st20_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ext) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -4746,9 +4574,10 @@ static void st20_linesize_digest_test(enum st20_packing packing[], } if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -4785,11 +4614,11 @@ static void st20_linesize_digest_test(enum st20_packing packing[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 10000 + i * 2; @@ -4811,8 +4640,7 @@ static void st20_linesize_digest_test(enum st20_packing packing[], interlaced[i] ? tx_next_ext_video_field : tx_next_ext_video_frame; ops_tx.notify_frame_done = tx_notify_ext_frame_done; } else { - ops_tx.get_next_frame = - interlaced[i] ? tx_next_video_field : tx_next_video_frame; + ops_tx.get_next_frame = interlaced[i] ? tx_next_video_field : tx_next_video_frame; } tx_handle[i] = st20_tx_create(m_handle, &ops_tx); @@ -4821,10 +4649,8 @@ static void st20_linesize_digest_test(enum st20_packing packing[], /* sha calculate */ struct st20_pgroup st20_pg; st20_get_pgroup(ops_tx.fmt, &st20_pg); - size_t frame_size = - ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; - if (interlaced[i]) - frame_size = frame_size >> 1; + size_t frame_size = ops_tx.width * ops_tx.height * st20_pg.size / st20_pg.coverage; + if (interlaced[i]) frame_size = frame_size >> 1; test_ctx_tx[i]->frame_size = frame_size; test_ctx_tx[i]->height = ops_tx.height; test_ctx_tx[i]->stride = ops_tx.width / st20_pg.coverage * st20_pg.size; @@ -4833,13 +4659,11 @@ static void st20_linesize_digest_test(enum st20_packing packing[], if (linesize[i] > test_ctx_tx[i]->stride) { test_ctx_tx[i]->stride = linesize[i]; fb_size = (size_t)linesize[i] * height[i]; - if (interlaced[i]) - fb_size = fb_size >> 1; + if (interlaced[i]) fb_size = fb_size >> 1; } test_ctx_tx[i]->fb_size = fb_size; EXPECT_EQ(st20_tx_get_framebuffer_size(tx_handle[i]), fb_size); - EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), - test_ctx_tx[i]->fb_cnt); + EXPECT_EQ(st20_tx_get_framebuffer_count(tx_handle[i]), test_ctx_tx[i]->fb_cnt); if (ext) { test_ctx_tx[i]->ext_frames = (struct st20_ext_frame *)malloc( @@ -4852,18 +4676,15 @@ static void st20_linesize_digest_test(enum st20_packing packing[], for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { test_ctx_tx[i]->ext_frames[j].buf_addr = (uint8_t *)mtl_dma_mem_addr(dma_mem) + j * fb_size; - test_ctx_tx[i]->ext_frames[j].buf_iova = - mtl_dma_mem_iova(dma_mem) + j * fb_size; + test_ctx_tx[i]->ext_frames[j].buf_iova = mtl_dma_mem_iova(dma_mem) + j * fb_size; test_ctx_tx[i]->ext_frames[j].buf_len = fb_size; } } uint8_t *fb; int total_lines = height[i]; - size_t bytes_per_line = - (size_t)ops_tx.width / st20_pg.coverage * st20_pg.size; - if (interlaced[i]) - total_lines /= 2; + size_t bytes_per_line = (size_t)ops_tx.width / st20_pg.coverage * st20_pg.size; + if (interlaced[i]) total_lines /= 2; for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { if (ext) { fb = (uint8_t *)test_ctx_tx[i]->ext_frames[frame].buf_addr; @@ -4874,8 +4695,7 @@ static void st20_linesize_digest_test(enum st20_packing packing[], ASSERT_TRUE(fb != NULL); for (int line = 0; line < total_lines; line++) { - st_test_rand_data(fb + test_ctx_tx[i]->stride * line, bytes_per_line, - frame); + st_test_rand_data(fb + test_ctx_tx[i]->stride * line, bytes_per_line, frame); } unsigned char *result = test_ctx_tx[i]->shas[frame]; SHA256((unsigned char *)fb, fb_size, result); @@ -4941,8 +4761,7 @@ static void st20_linesize_digest_test(enum st20_packing packing[], ops_rx.notify_frame_ready = interlaced[i] ? st20_digest_rx_field_ready : st20_digest_rx_frame_ready; ops_rx.flags = ST20_RX_FLAG_DMA_OFFLOAD; - if (ext) - ops_rx.ext_frames = test_ctx_rx[i]->ext_frames; + if (ext) ops_rx.ext_frames = test_ctx_rx[i]->ext_frames; rx_handle[i] = st20_rx_create(m_handle, &ops_rx); @@ -4980,8 +4799,7 @@ static void st20_linesize_digest_test(enum st20_packing packing[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; { @@ -5031,13 +4849,12 @@ TEST(St20_rx, linesize_digest_s3) { bool interlaced[3] = {false, true, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, - fmt, true, ST_TEST_LEVEL_MANDATORY, 3); + st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, fmt, true, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, linesize_digest_crosslines_s3) { - enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_GPM, - ST20_PACKING_BPM}; + enum st20_packing packing[3] = {ST20_PACKING_BPM, ST20_PACKING_GPM, ST20_PACKING_BPM}; enum st_fps fps[3] = {ST_FPS_P59_94, ST_FPS_P50, ST_FPS_P50}; int width[3] = {1280, 1920, 1920}; int height[3] = {720, 1080, 1080}; @@ -5045,8 +4862,8 @@ TEST(St20_rx, linesize_digest_crosslines_s3) { bool interlaced[3] = {true, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, - fmt, true, ST_TEST_LEVEL_MANDATORY, 3); + st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, fmt, true, + ST_TEST_LEVEL_MANDATORY, 3); } TEST(St20_rx, linesize_digest_ext_s3) { @@ -5059,6 +4876,6 @@ TEST(St20_rx, linesize_digest_ext_s3) { bool interlaced[3] = {true, false, false}; enum st20_fmt fmt[3] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, - fmt, true, ST_TEST_LEVEL_MANDATORY, 3, true); + st20_linesize_digest_test(packing, fps, width, height, linesize, interlaced, fmt, true, + ST_TEST_LEVEL_MANDATORY, 3, true); } \ No newline at end of file diff --git a/tests/src/st20p_test.cpp b/tests/src/st20p_test.cpp index 97367fe0a..bf0266e2a 100644 --- a/tests/src/st20p_test.cpp +++ b/tests/src/st20p_test.cpp @@ -15,28 +15,20 @@ static int test_convert_frame(struct test_converter_session *s, struct st20_converter_create_req *req = &s->req; /* check frame sanity */ - if (frame->src->width != req->width) - return -EIO; - if (frame->dst->width != req->width) - return -EIO; - if (frame->src->height != req->height) - return -EIO; - if (frame->dst->height != req->height) - return -EIO; - if (frame->src->fmt != req->input_fmt) - return -EIO; - if (frame->dst->fmt != req->output_fmt) - return -EIO; + if (frame->src->width != req->width) return -EIO; + if (frame->dst->width != req->width) return -EIO; + if (frame->src->height != req->height) return -EIO; + if (frame->dst->height != req->height) return -EIO; + if (frame->src->fmt != req->input_fmt) return -EIO; + if (frame->dst->fmt != req->output_fmt) return -EIO; /* copy src sha to the start of convert frame */ if (req->input_fmt == ST_FRAME_FMT_YUV422PLANAR10LE) memcpy(frame->dst->addr[0], - (uint8_t *)frame->src->addr[0] + frame->src->data_size - - SHA256_DIGEST_LENGTH, + (uint8_t *)frame->src->addr[0] + frame->src->data_size - SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH); else - memcpy((uint8_t *)frame->dst->addr[0] + frame->dst->data_size - - SHA256_DIGEST_LENGTH, + memcpy((uint8_t *)frame->dst->addr[0] + frame->dst->data_size - SHA256_DIGEST_LENGTH, frame->src->addr[0], SHA256_DIGEST_LENGTH); st_usleep(s->sleep_time_us); @@ -69,8 +61,7 @@ static void *test_convert_thread(void *arg) { frame = st20_converter_get_frame(session_p); if (!frame) { /* no frame */ st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); continue; } @@ -82,19 +73,16 @@ static void *test_convert_thread(void *arg) { return NULL; } -static st20_convert_priv -test_converter_create_session(void *priv, st20p_convert_session session_p, - struct st20_converter_create_req *req) { +static st20_convert_priv test_converter_create_session( + void *priv, st20p_convert_session session_p, struct st20_converter_create_req *req) { struct st_tests_context *ctx = (struct st_tests_context *)priv; struct test_converter_session *session = NULL; int ret; for (int i = 0; i < MAX_TEST_CONVERTER_SESSIONS; i++) { - if (ctx->converter_sessions[i]) - continue; + if (ctx->converter_sessions[i]) continue; session = (struct test_converter_session *)malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->idx = i; st_pthread_mutex_init(&session->wake_mutex, NULL); @@ -103,16 +91,14 @@ test_converter_create_session(void *priv, st20p_convert_session session_p, session->req = *req; session->session_p = session_p; double fps = st_frame_rate(req->fps); - if (!fps) - fps = 60; + if (!fps) fps = 60; session->sleep_time_us = 1000 * 1000 / fps / 2; dbg("%s(%d), sleep_time_us %d\n", __func__, i, session->sleep_time_us); session->fail_interval = ctx->plugin_fail_interval; session->timeout_interval = ctx->plugin_timeout_interval; session->timeout_ms = ctx->plugin_timeout_ms; - ret = pthread_create(&session->convert_thread, NULL, test_convert_thread, - session); + ret = pthread_create(&session->convert_thread, NULL, test_convert_thread, session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -146,8 +132,7 @@ static int test_converter_free_session(void *priv, st20_convert_priv session) { st_pthread_mutex_destroy(&converter_sessions->wake_mutex); st_pthread_cond_destroy(&converter_sessions->wake_cond); - dbg("%s(%d), total %d convert frames\n", __func__, idx, - converter_sessions->frame_cnt); + dbg("%s(%d), total %d convert frames\n", __func__, idx, converter_sessions->frame_cnt); free(converter_sessions); ctx->converter_sessions[idx] = NULL; return 0; @@ -182,10 +167,8 @@ int st_test_convert_plugin_register(struct st_tests_context *ctx) { c_dev.name = "test_converter"; c_dev.priv = ctx; c_dev.target_device = ST_PLUGIN_DEVICE_TEST; - c_dev.input_fmt_caps = - ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; - c_dev.output_fmt_caps = - ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; + c_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; + c_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422RFC4175PG2BE10; c_dev.create_session = test_converter_create_session; c_dev.free_session = test_converter_free_session; c_dev.notify_frame_available = test_converter_frame_available; @@ -215,12 +198,11 @@ static void plugin_register_test(const char *so_name, bool expect_succ) { } TEST(St20p, plugin_register_single) { - plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", - true); + plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", true); } TEST(St20p, plugin_register_fail) { - plugin_register_test( - "/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", false); + plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", + false); } static int test_st20p_tx_frame_available(void *priv) { @@ -234,13 +216,11 @@ static int test_st20p_tx_frame_available(void *priv) { static int test_st20p_tx_frame_done(void *priv, struct st_frame *frame) { tests_context *s = (tests_context *)priv; - if (!s->handle) - return -EIO; /* not ready */ + if (!s->handle) return -EIO; /* not ready */ s->fb_send_done++; - if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) - return 0; + if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) return 0; for (int i = 0; i < s->fb_cnt; ++i) { if (frame->addr[0] == s->ext_fb + i * s->frame_size) { @@ -262,16 +242,15 @@ static int test_st20p_rx_frame_available(void *priv) { return 0; } -static void st20p_tx_ops_init(tests_context *st20, - struct st20p_tx_ops *ops_tx) { +static void st20p_tx_ops_init(tests_context *st20, struct st20p_tx_ops *ops_tx) { auto ctx = st20->ctx; memset(ops_tx, 0, sizeof(*ops_tx)); ops_tx->name = "st20p_test"; ops_tx->priv = st20; ops_tx->port.num_port = 1; - memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx->port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + st20->idx; @@ -285,20 +264,19 @@ static void st20p_tx_ops_init(tests_context *st20, ops_tx->framebuff_cnt = st20->fb_cnt; ops_tx->notify_frame_available = test_st20p_tx_frame_available; ops_tx->notify_event = test_ctx_notify_event; - st20->frame_size = st_frame_size(ops_tx->input_fmt, ops_tx->width, - ops_tx->height, ops_tx->interlaced); + st20->frame_size = + st_frame_size(ops_tx->input_fmt, ops_tx->width, ops_tx->height, ops_tx->interlaced); } -static void st20p_rx_ops_init(tests_context *st20, - struct st20p_rx_ops *ops_rx) { +static void st20p_rx_ops_init(tests_context *st20, struct st20p_rx_ops *ops_rx) { auto ctx = st20->ctx; memset(ops_rx, 0, sizeof(*ops_rx)); ops_rx->name = "st20p_test"; ops_rx->priv = st20; ops_rx->port.num_port = 1; - memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx->port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + st20->idx; @@ -312,8 +290,8 @@ static void st20p_rx_ops_init(tests_context *st20, ops_rx->framebuff_cnt = st20->fb_cnt; ops_rx->notify_frame_available = test_st20p_rx_frame_available; ops_rx->notify_event = test_ctx_notify_event; - st20->frame_size = st_frame_size(ops_rx->output_fmt, ops_rx->width, - ops_rx->height, ops_rx->interlaced); + st20->frame_size = st_frame_size(ops_rx->output_fmt, ops_rx->width, ops_rx->height, + ops_rx->interlaced); } static void st20p_tx_assert_cnt(int expect_st20_tx_cnt) { @@ -362,8 +340,12 @@ TEST(St20p, tx_create_free_max) { TEST(St20p, rx_create_free_max) { pipeline_create_free_max(st20p_rx, TEST_CREATE_FREE_MAX); } -TEST(St20p, tx_create_expect_fail) { pipeline_expect_fail_test(st20p_tx); } -TEST(St20p, rx_create_expect_fail) { pipeline_expect_fail_test(st20p_rx); } +TEST(St20p, tx_create_expect_fail) { + pipeline_expect_fail_test(st20p_tx); +} +TEST(St20p, rx_create_expect_fail) { + pipeline_expect_fail_test(st20p_rx); +} TEST(St20p, tx_create_expect_fail_fb_cnt) { uint16_t fbcnt = 1; pipeline_expect_fail_test_fb_cnt(st20p_tx, fbcnt); @@ -390,22 +372,16 @@ static void test_st20p_tx_frame_thread(void *args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) - s->cv.wait(lck); + if (!s->stop) s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->width != s->width) - s->incomplete_frame_cnt++; - if (frame->height != s->height) - s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) - s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->width != s->width) s->incomplete_frame_cnt++; + if (frame->height != s->height) s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; if (s->user_timestamp) { frame->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; frame->timestamp = s->fb_send; @@ -422,14 +398,12 @@ static void test_st20p_tx_frame_thread(void *args) { int ret = st20p_tx_put_ext_frame((st20p_tx_handle)handle, frame, &s->p_ext_frames[s->ext_idx]); if (ret < 0) { - err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, - s->ext_idx); + err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, s->ext_idx); continue; } s->ext_fb_in_use[s->ext_idx] = true; s->ext_idx++; - if (s->ext_idx >= s->fb_cnt) - s->ext_idx = 0; + if (s->ext_idx >= s->fb_cnt) s->ext_idx = 0; } else { /* directly put */ st20p_tx_put_frame((st20p_tx_handle)handle, frame); @@ -453,15 +427,12 @@ static void test_st20p_rx_user_meta(tests_context *s, struct st_frame *frame) { dbg("%s(%d), meta idx session %d frame %d magic 0x%x\n", __func__, s->idx, meta->session_idx, meta->frame_idx, meta->magic); - if (frame->user_meta_size != sizeof(*meta)) - s->user_meta_fail_cnt++; - if (meta->magic != TEST_USER_META_MAGIC) - s->user_meta_fail_cnt++; - if (meta->session_idx != s->idx) - s->user_meta_fail_cnt++; + if (frame->user_meta_size != sizeof(*meta)) s->user_meta_fail_cnt++; + if (meta->magic != TEST_USER_META_MAGIC) s->user_meta_fail_cnt++; + if (meta->session_idx != s->idx) s->user_meta_fail_cnt++; if (meta->frame_idx <= s->last_user_meta_frame_idx) { - err("%s(%d), err user meta frame idx %d:%d\n", __func__, s->idx, - meta->frame_idx, s->last_user_meta_frame_idx); + err("%s(%d), err user meta frame idx %d:%d\n", __func__, s->idx, meta->frame_idx, + s->last_user_meta_frame_idx); s->user_meta_fail_cnt++; } s->last_user_meta_frame_idx = meta->frame_idx; @@ -480,15 +451,13 @@ static void test_st20p_rx_frame_thread(void *args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) - s->cv.wait(lck); + if (!s->stop) s->cv.wait(lck); lck.unlock(); } continue; } - if (s->user_meta) - test_st20p_rx_user_meta(s, frame); + if (s->user_meta) test_st20p_rx_user_meta(s, frame); if (!st_is_frame_complete(frame->status)) { s->incomplete_frame_cnt++; @@ -496,23 +465,16 @@ static void test_st20p_rx_frame_thread(void *args) { continue; } - if (frame->data_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->width != s->width) - s->incomplete_frame_cnt++; - if (frame->height != s->height) - s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) - s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->width != s->width) s->incomplete_frame_cnt++; + if (frame->height != s->height) s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) - s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; timestamp = frame->timestamp; if (s->rx_timing_parser) { - if (!frame->tp[MTL_SESSION_PORT_P]) - s->incomplete_frame_cnt++; + if (!frame->tp[MTL_SESSION_PORT_P]) s->incomplete_frame_cnt++; } /* check user timestamp if it has */ @@ -524,20 +486,19 @@ static void test_st20p_rx_frame_thread(void *args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", - __func__, s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, + s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; } - unsigned char *sha = (unsigned char *)frame->addr[0] + frame->data_size - - SHA256_DIGEST_LENGTH; + unsigned char *sha = + (unsigned char *)frame->addr[0] + frame->data_size - SHA256_DIGEST_LENGTH; int i = 0; for (i = 0; i < TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = s->shas[i]; - if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20p_rx_error_sha", sha); @@ -546,8 +507,7 @@ static void test_st20p_rx_frame_thread(void *args) { /* directly put */ st20p_rx_put_frame((st20p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) - s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } @@ -566,8 +526,7 @@ static void test_internal_st20p_rx_frame_thread(void *args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) - s->cv.wait(lck); + if (!s->stop) s->cv.wait(lck); lck.unlock(); } continue; @@ -580,8 +539,7 @@ static void test_internal_st20p_rx_frame_thread(void *args) { *in_use = false; } - if (s->user_meta) - test_st20p_rx_user_meta(s, frame); + if (s->user_meta) test_st20p_rx_user_meta(s, frame); if (!st_is_frame_complete(frame->status)) { s->incomplete_frame_cnt++; @@ -589,19 +547,13 @@ static void test_internal_st20p_rx_frame_thread(void *args) { continue; } - if (frame->data_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->width != s->width) - s->incomplete_frame_cnt++; - if (frame->height != s->height) - s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) - s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->width != s->width) s->incomplete_frame_cnt++; + if (frame->height != s->height) s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) - s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; timestamp = frame->timestamp; /* check user timestamp if it has */ @@ -613,8 +565,8 @@ static void test_internal_st20p_rx_frame_thread(void *args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", - __func__, s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, + s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; @@ -625,8 +577,7 @@ static void test_internal_st20p_rx_frame_thread(void *args) { SHA256(fb, s->frame_size, result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = s->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st20p_rx_error_sha", result); @@ -635,8 +586,7 @@ static void test_internal_st20p_rx_frame_thread(void *args) { /* directly put */ st20p_rx_put_frame((st20p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) - s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } @@ -657,8 +607,7 @@ static int test_st20p_rx_query_ext_frame(void *priv, st_ext_frame *ext_frame, ext_frame->opaque = &s->ext_fb_in_use[i]; - if (++s->ext_idx >= s->fb_cnt) - s->ext_idx = 0; + if (++s->ext_idx >= s->fb_cnt) s->ext_idx = 0; return 0; } @@ -692,8 +641,7 @@ struct st20p_rx_digest_test_para { bool zero_payload_type; }; -static void -test_st20p_init_rx_digest_para(struct st20p_rx_digest_test_para *para) { +static void test_st20p_init_rx_digest_para(struct st20p_rx_digest_test_para *para) { memset(para, 0, sizeof(*para)); para->device = ST_PLUGIN_DEVICE_TEST; @@ -723,8 +671,7 @@ test_st20p_init_rx_digest_para(struct st20p_rx_digest_test_para *para) { } static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], - enum st_frame_fmt tx_fmt[], - enum st20_fmt t_fmt[], + enum st_frame_fmt tx_fmt[], enum st20_fmt t_fmt[], enum st_frame_fmt rx_fmt[], struct st20p_rx_digest_test_para *para) { auto ctx = (struct st_tests_context *)st_test_ctx(); @@ -739,14 +686,12 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], st_test_jxs_timeout_ms(ctx, para->timeout_ms); if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled, one for tx and one for rx\n", - __func__); + info("%s, dual port should be enabled, one for tx and one for rx\n", __func__); return; } /* return if level lower than global */ - if (para->level < ctx->level) - return; + if (para->level < ctx->level) return; if (para->tx_ext || para->rx_ext) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -792,9 +737,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { expect_framerate_tx[i] = st_frame_rate(fps[i]); if (para->timeout_interval) { - expect_framerate_tx[i] = expect_framerate_tx[i] * - (para->timeout_interval - 1) / - para->timeout_interval; + expect_framerate_tx[i] = + expect_framerate_tx[i] * (para->timeout_interval - 1) / para->timeout_interval; } test_ctx_tx[i] = new tests_context(); @@ -816,16 +760,15 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + i * 2; - ops_tx.port.payload_type = - para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; + ops_tx.port.payload_type = para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; ops_tx.port.ssrc = para->ssrc; ops_tx.width = width[i]; ops_tx.height = height[i]; @@ -847,10 +790,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], if (para->tx_ext) { ops_tx.flags |= ST20P_TX_FLAG_EXT_FRAME; } - if (para->user_timestamp) - ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; - if (para->vsync) - ops_tx.flags |= ST20P_TX_FLAG_ENABLE_VSYNC; + if (para->user_timestamp) ops_tx.flags |= ST20P_TX_FLAG_USER_TIMESTAMP; + if (para->vsync) ops_tx.flags |= ST20P_TX_FLAG_ENABLE_VSYNC; if (para->rtcp) { ops_tx.flags |= ST20P_TX_FLAG_ENABLE_RTCP; @@ -892,14 +833,13 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ASSERT_TRUE(test_ctx_tx[i]->ext_fb_malloc != NULL); test_ctx_tx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); - test_ctx_tx[i]->ext_fb_iova = mtl_dma_map( - st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); + test_ctx_tx[i]->ext_fb_iova = + mtl_dma_map(st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_iova != MTL_BAD_IOVA); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_tx[i]->ext_fb); for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; - plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ test_ctx_tx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(rx_fmt[i], width[i], plane) + para->line_padding_size; @@ -932,14 +872,11 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], st_test_rand_data(fb, frame_size, frame); else { for (int plane = 0; plane < planes; plane++) { - size_t least_line_size = - st_frame_least_linesize(tx_fmt[i], width[i], plane); - uint8_t *start = - (uint8_t *)test_ctx_tx[i]->p_ext_frames[frame].addr[plane]; + size_t least_line_size = st_frame_least_linesize(tx_fmt[i], width[i], plane); + uint8_t *start = (uint8_t *)test_ctx_tx[i]->p_ext_frames[frame].addr[plane]; for (int line = 0; line < height[i]; line++) { uint8_t *cur_line = - start + - test_ctx_tx[i]->p_ext_frames[frame].linesize[plane] * line; + start + test_ctx_tx[i]->p_ext_frames[frame].linesize[plane] * line; st_test_rand_data(cur_line, least_line_size, frame); } } @@ -967,8 +904,7 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_sha_dump("st20p_tx", result); /* copy sha to the end of frame */ if (para->device == ST_PLUGIN_DEVICE_TEST) - memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, - SHA256_DIGEST_LENGTH); + memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, SHA256_DIGEST_LENGTH); } test_ctx_tx[i]->handle = tx_handle[i]; @@ -979,8 +915,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { if (para->fail_interval) { /* loss in the tx */ - expect_framerate_tx[i] = expect_framerate_tx[i] * - (para->fail_interval - 1) / para->fail_interval; + expect_framerate_tx[i] = + expect_framerate_tx[i] * (para->fail_interval - 1) / para->fail_interval; } expect_framerate_rx[i] = expect_framerate_tx[i]; test_ctx_rx[i] = new tests_context(); @@ -1008,9 +944,8 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], uint8_t planes = st_frame_fmt_planes(rx_fmt[i]); test_ctx_rx[i]->p_ext_frames = (struct st_ext_frame *)malloc( sizeof(*test_ctx_rx[i]->p_ext_frames) * test_ctx_rx[i]->fb_cnt); - size_t frame_size = - st_frame_size(rx_fmt[i], width[i], height[i], para->interlace) + - para->line_padding_size * height[i] * planes; + size_t frame_size = st_frame_size(rx_fmt[i], width[i], height[i], para->interlace) + + para->line_padding_size * height[i] * planes; size_t pg_sz = mtl_page_size(st); size_t fb_size = frame_size * test_ctx_rx[i]->fb_cnt; test_ctx_rx[i]->ext_fb_iova_map_sz = @@ -1020,14 +955,13 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( - st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); + test_ctx_rx[i]->ext_fb_iova = + mtl_dma_map(st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; - plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ test_ctx_rx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(rx_fmt[i], width[i], plane) + para->line_padding_size; @@ -1056,16 +990,15 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.priv = test_ctx_rx[i]; ops_rx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ST20P_TEST_UDP_PORT + i * 2; - ops_rx.port.payload_type = - para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; + ops_rx.port.payload_type = para->zero_payload_type ? 0 : ST20P_TEST_PAYLOAD_TYPE; ops_rx.port.ssrc = para->ssrc; ops_rx.width = width[i]; ops_rx.height = height[i]; @@ -1080,8 +1013,7 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.flags |= ST20P_RX_FLAG_BLOCK_GET; else ops_rx.notify_frame_available = test_st20p_rx_frame_available; - if (para->rx_timing_parser) - ops_rx.flags |= ST20P_RX_FLAG_TIMING_PARSER_META; + if (para->rx_timing_parser) ops_rx.flags |= ST20P_RX_FLAG_TIMING_PARSER_META; ops_rx.notify_event = test_ctx_notify_event; if (para->rx_ext) { if (para->rx_dedicated_ext) { @@ -1089,21 +1021,16 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], } else { ops_rx.flags |= ST20P_RX_FLAG_EXT_FRAME; ops_rx.query_ext_frame = test_st20p_rx_query_ext_frame; - if (st_frame_fmt_equal_transport(ops_rx.output_fmt, - ops_rx.transport_fmt)) + if (st_frame_fmt_equal_transport(ops_rx.output_fmt, ops_rx.transport_fmt)) ops_rx.flags |= ST20P_RX_FLAG_RECEIVE_INCOMPLETE_FRAME; } } - if (para->vsync) - ops_rx.flags |= ST20P_RX_FLAG_ENABLE_VSYNC; - if (para->pkt_convert) - ops_rx.flags |= ST20P_RX_FLAG_PKT_CONVERT; - if (para->rx_auto_detect) - ops_rx.flags |= ST20P_RX_FLAG_AUTO_DETECT; + if (para->vsync) ops_rx.flags |= ST20P_RX_FLAG_ENABLE_VSYNC; + if (para->pkt_convert) ops_rx.flags |= ST20P_RX_FLAG_PKT_CONVERT; + if (para->rx_auto_detect) ops_rx.flags |= ST20P_RX_FLAG_AUTO_DETECT; if (para->rtcp) { - ops_rx.flags |= - ST20P_RX_FLAG_ENABLE_RTCP | ST20P_RX_FLAG_SIMULATE_PKT_LOSS; + ops_rx.flags |= ST20P_RX_FLAG_ENABLE_RTCP | ST20P_RX_FLAG_SIMULATE_PKT_LOSS; ops_rx.rtcp.nack_interval_us = 250; ops_rx.rtcp.seq_bitmap_size = 64; ops_rx.rtcp.seq_skip_window = 0; @@ -1127,8 +1054,7 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], test_ctx_rx[i]->handle = rx_handle[i]; if (para->device == ST_PLUGIN_DEVICE_TEST_INTERNAL) - rx_thread[i] = - std::thread(test_internal_st20p_rx_frame_thread, test_ctx_rx[i]); + rx_thread[i] = std::thread(test_internal_st20p_rx_frame_thread, test_ctx_rx[i]); else rx_thread[i] = std::thread(test_st20p_rx_frame_thread, test_ctx_rx[i]); @@ -1147,23 +1073,19 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; framerate_tx[i] = test_ctx_tx[i]->fb_send / time_sec; /* vsync check */ - time_sec = - (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; + time_sec = (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; vsyncrate_tx[i] = test_ctx_tx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_tx[i], test_ctx_tx[i]->vsync_cnt, vsyncrate_tx[i]); EXPECT_GT(test_ctx_tx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), - st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); test_ctx_tx[i]->stop = true; - if (para->block_get) - st20p_tx_wake_block(tx_handle[i]); + if (para->block_get) st20p_tx_wake_block(tx_handle[i]); test_ctx_tx[i]->cv.notify_all(); tx_thread[i].join(); if (para->send_done_check) { @@ -1177,23 +1099,19 @@ static void st20p_rx_digest_test(enum st_fps fps[], int width[], int height[], } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate_rx[i] = test_ctx_rx[i]->fb_rec / time_sec; /* vsync check */ - time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; + time_sec = (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; vsyncrate_rx[i] = test_ctx_rx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_rx[i], test_ctx_rx[i]->vsync_cnt, vsyncrate_rx[i]); EXPECT_GT(test_ctx_rx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), - st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); test_ctx_rx[i]->stop = true; - if (para->block_get) - st20p_rx_wake_block(rx_handle[i]); + if (para->block_get) st20p_rx_wake_block(rx_handle[i]); test_ctx_rx[i]->cv.notify_all(); rx_thread[i].join(); } @@ -1359,11 +1277,9 @@ TEST(St20p, digest_1080p_internal_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1379,11 +1295,9 @@ TEST(St20p, digest_1080p_no_convert_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, - ST_FRAME_FMT_RGB8}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, ST_FRAME_FMT_RGB8}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_RGB_8BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, - ST_FRAME_FMT_RGB8}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422RFC4175PG2BE10, ST_FRAME_FMT_RGB8}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1398,11 +1312,9 @@ TEST(St20p, digest_1080p_packet_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1439,11 +1351,9 @@ TEST(St20p, tx_ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_V210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_V210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1480,11 +1390,9 @@ TEST(St20p, rx_ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_V210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_V210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1500,11 +1408,9 @@ TEST(St20p, rx_ext_digest_1080p_packet_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1543,11 +1449,9 @@ TEST(St20p, ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_V210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_V210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_V210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1566,11 +1470,9 @@ TEST(St20p, rx_dedicated_ext_digest_1080p_convert_s2) { enum st_fps fps[2] = {ST_FPS_P29_97, ST_FPS_P59_94}; int width[2] = {1920, 1280}; int height[2] = {1080, 720}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1586,11 +1488,9 @@ TEST(St20p, ext_digest_1080p_convert_with_padding_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1608,11 +1508,9 @@ TEST(St20p, rx_dedicated_ext_digest_1080p_convert_with_padding_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); @@ -1631,11 +1529,9 @@ TEST(St20p, ext_digest_1080p_packet_convert_with_padding_s2) { enum st_fps fps[2] = {ST_FPS_P59_94, ST_FPS_P59_94}; int width[2] = {1920, 1920}; int height[2] = {1080, 1080}; - enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt tx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; enum st20_fmt t_fmt[2] = {ST20_FMT_YUV_422_10BIT, ST20_FMT_YUV_422_10BIT}; - enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, - ST_FRAME_FMT_Y210}; + enum st_frame_fmt rx_fmt[2] = {ST_FRAME_FMT_YUV422PLANAR10LE, ST_FRAME_FMT_Y210}; struct st20p_rx_digest_test_para para; test_st20p_init_rx_digest_para(¶); diff --git a/tests/src/st22_test.cpp b/tests/src/st22_test.cpp index d7e8ce566..2bac6b8ff 100644 --- a/tests/src/st22_test.cpp +++ b/tests/src/st22_test.cpp @@ -12,26 +12,22 @@ static int st22_tx_rtp_done(void *args) { auto ctx = (tests_context *)args; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } static int st22_rx_rtp_ready(void *args) { auto ctx = (tests_context *)args; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -39,19 +35,16 @@ static int st22_next_video_frame(void *priv, uint16_t *next_frame_idx, struct st22_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; meta->codestream_size = ctx->frame_size; - dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, - *next_frame_idx, meta->codestream_size); + dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, *next_frame_idx, + meta->codestream_size); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -59,21 +52,18 @@ static int st22_next_video_frame_timestamp(void *priv, uint16_t *next_frame_idx, struct st22_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; meta->codestream_size = ctx->frame_size; meta->tfmt = ST10_TIMESTAMP_FMT_TAI; meta->timestamp = mtl_ptp_read_time(ctx->ctx->handle) + 35 * 1000 * 1000; - dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, - *next_frame_idx, meta->codestream_size); + dbg("%s, next_frame_idx %d frame_size %" PRIu64 "\n", __func__, *next_frame_idx, + meta->codestream_size); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -82,12 +72,10 @@ static int st22_frame_done(void *priv, uint16_t frame_idx, return 0; } -static int st22_rx_frame_ready(void *priv, void *frame, - struct st22_rx_frame_meta *meta) { +static int st22_rx_frame_ready(void *priv, void *frame, struct st22_rx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; ctx->fb_rec++; if (!ctx->start_time) { @@ -95,8 +83,7 @@ static int st22_rx_frame_ready(void *priv, void *frame, ctx->start_time = st_test_get_monotonic_time(); } - if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) - ctx->rtp_tmstamp = meta->timestamp; + if (meta->tfmt == ST10_TIMESTAMP_FMT_MEDIA_CLK) ctx->rtp_tmstamp = meta->timestamp; st22_rx_put_framebuff((st22_rx_handle)ctx->handle, frame); return 0; } @@ -108,8 +95,7 @@ static void st22_tx_ops_init(tests_context *st22, struct st22_tx_ops *ops) { ops->name = "st22_test"; ops->priv = st22; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; + if (ctx->same_dual_port) ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -144,8 +130,7 @@ static void st22_rx_ops_init(tests_context *st22, struct st22_rx_ops *ops) { ops->name = "st22_test"; ops->priv = st22; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; + if (ctx->same_dual_port) ops->num_port = 1; memcpy(ops->ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -193,13 +178,21 @@ static void st22_rx_assert_cnt(int expect_s22_rx_cnt) { EXPECT_EQ(var.st22_rx_sessions_cnt, expect_s22_rx_cnt); } -TEST(St22_tx, create_free_single) { create_free_test(st22_tx, 0, 1, 1); } -TEST(St22_tx, create_free_multi) { create_free_test(st22_tx, 0, 1, 6); } -TEST(St22_tx, create_free_mix) { create_free_test(st22_tx, 2, 3, 4); } +TEST(St22_tx, create_free_single) { + create_free_test(st22_tx, 0, 1, 1); +} +TEST(St22_tx, create_free_multi) { + create_free_test(st22_tx, 0, 1, 6); +} +TEST(St22_tx, create_free_mix) { + create_free_test(st22_tx, 2, 3, 4); +} TEST(St22_tx, create_free_max) { create_free_max(st22_tx, TEST_CREATE_FREE_MAX); } -TEST(St22_tx, create_expect_fail) { expect_fail_test(st22_tx); } +TEST(St22_tx, create_expect_fail) { + expect_fail_test(st22_tx); +} TEST(St22_tx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st22_tx, ST22_TYPE_RTP_LEVEL, ring_size); @@ -221,13 +214,21 @@ TEST(St22_tx, create_expect_fail_fb_cnt) { expect_fail_test_fb_cnt(st22_tx, fbcnt); } -TEST(St22_rx, create_free_single) { create_free_test(st22_rx, 0, 1, 1); } -TEST(St22_rx, create_free_multi) { create_free_test(st22_rx, 0, 1, 6); } -TEST(St22_rx, create_free_mix) { create_free_test(st22_rx, 2, 3, 4); } +TEST(St22_rx, create_free_single) { + create_free_test(st22_rx, 0, 1, 1); +} +TEST(St22_rx, create_free_multi) { + create_free_test(st22_rx, 0, 1, 6); +} +TEST(St22_rx, create_free_mix) { + create_free_test(st22_rx, 2, 3, 4); +} TEST(St22_rx, create_free_max) { create_free_max(st22_rx, TEST_CREATE_FREE_MAX); } -TEST(St22_rx, create_expect_fail) { expect_fail_test(st22_rx); } +TEST(St22_rx, create_expect_fail) { + expect_fail_test(st22_rx); +} TEST(St22_rx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st22_rx, ST22_TYPE_RTP_LEVEL, ring_size); @@ -241,8 +242,7 @@ TEST(St22_rx, create_expect_fail_fb_cnt) { expect_fail_test_fb_cnt(st22_rx, fbcnt); } -static int st22_tx_build_rtp_packet(tests_context *s, - struct st22_rfc9134_rtp_hdr *rtp, +static int st22_tx_build_rtp_packet(tests_context *s, struct st22_rfc9134_rtp_hdr *rtp, uint16_t *pkt_len) { /* update hdr */ rtp->base.csrc_count = 0; @@ -261,8 +261,7 @@ static int st22_tx_build_rtp_packet(tests_context *s, if (s->check_sha) { uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); mtl_memcpy(payload, - s->frame_buf[s->fb_idx % ST22_TEST_SHA_HIST_NUM] + - s->pkt_idx * data_len, + s->frame_buf[s->fb_idx % ST22_TEST_SHA_HIST_NUM] + s->pkt_idx * data_len, data_len); } @@ -295,24 +294,21 @@ static void st22_tx_feed_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - st22_tx_build_rtp_packet(ctx, (struct st22_rfc9134_rtp_hdr *)usrptr, - &mbuf_len); + st22_tx_build_rtp_packet(ctx, (struct st22_rfc9134_rtp_hdr *)usrptr, &mbuf_len); st22_tx_put_mbuf((st22_tx_handle)ctx->handle, mbuf, mbuf_len); } } -static void st22_rx_handle_rtp(tests_context *s, - struct st22_rfc9134_rtp_hdr *hdr, bool newframe, - int mbuf_len) { +static void st22_rx_handle_rtp(tests_context *s, struct st22_rfc9134_rtp_hdr *hdr, + bool newframe, int mbuf_len) { uint8_t *frame; uint8_t *payload; @@ -332,8 +328,7 @@ static void st22_rx_handle_rtp(tests_context *s, if (index < 0) { index = index + 0x10000; } - mtl_memcpy(frame + index * (mbuf_len - sizeof(*hdr)), payload, - mbuf_len - sizeof(*hdr)); + mtl_memcpy(frame + index * (mbuf_len - sizeof(*hdr)), payload, mbuf_len - sizeof(*hdr)); return; } @@ -354,8 +349,7 @@ static void st22_rx_get_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } @@ -377,25 +371,24 @@ static void st22_rx_get_packet(void *args) { } } -static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], - int width[], int height[], int pkt_data_len[], - int total_pkts[], enum st_test_level level, - int sessions = 1) { +static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], int width[], + int height[], int pkt_data_len[], int total_pkts[], + enum st_test_level level, int sessions = 1) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level lower than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; std::vector test_ctx_tx; std::vector test_ctx_rx; @@ -430,11 +423,11 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -448,10 +441,9 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * - test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = + (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -509,10 +501,9 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], ops_rx.rtp_ring_size = 1024; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * - test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = + (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -537,8 +528,7 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST22_TYPE_RTP_LEVEL) { @@ -561,8 +551,8 @@ static void st22_rx_fps_test(enum st22_type type[], enum st_fps fps[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st22_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); @@ -591,8 +581,8 @@ TEST(St22_rx, fps_mix_s2) { int height[2] = {1080, 720}; int pkt_data_len[2] = {1280, 1300}; int total_pkts[2] = {540, 150}; - st22_rx_fps_test(type, fps, width, height, pkt_data_len, total_pkts, - ST_TEST_LEVEL_ALL, 2); + st22_rx_fps_test(type, fps, width, height, pkt_data_len, total_pkts, ST_TEST_LEVEL_ALL, + 2); } static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { @@ -602,15 +592,15 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level lower than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; int rx_sessions = 1; @@ -644,17 +634,17 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -669,8 +659,8 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { test_ctx_tx[i]->pkt_data_len = 1280; test_ctx_tx[i]->total_pkts_in_frame = 520; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * - test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->frame_size = + (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -723,8 +713,8 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { test_ctx_rx[i]->pkt_data_len = 1280; test_ctx_rx[i]->total_pkts_in_frame = 520; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * - test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->frame_size = + (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -756,8 +746,7 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -782,8 +771,7 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -808,8 +796,7 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -834,11 +821,12 @@ static void st22_rx_update_src_test(int tx_sessions, enum st_test_level level) { } } -TEST(St22_rx, update_source) { st22_rx_update_src_test(2, ST_TEST_LEVEL_ALL); } +TEST(St22_rx, update_source) { + st22_rx_update_src_test(2, ST_TEST_LEVEL_ALL); +} -static void st22_rx_after_start_test(enum st_fps fps[], int width[], - int height[], int pkt_data_len[], - int total_pkts[], int sessions, +static void st22_rx_after_start_test(enum st_fps fps[], int width[], int height[], + int pkt_data_len[], int total_pkts[], int sessions, int repeat) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; @@ -846,9 +834,10 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -887,11 +876,11 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -906,8 +895,8 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; - test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * - test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->frame_size = + (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -940,11 +929,11 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -963,8 +952,8 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * - test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->frame_size = + (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -981,17 +970,16 @@ static void st22_rx_after_start_test(enum st_fps fps[], int width[], /* check fps, stop rx */ for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; } for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); EXPECT_LT(test_ctx_rx[i]->sha_fail_cnt, - 2); // the first frame may be incomplete + 2); // the first frame may be incomplete ret = st22_rx_free(rx_handle[i]); EXPECT_GE(ret, 0); } @@ -1018,17 +1006,17 @@ TEST(St22_rx, after_start_s2) { } static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], - int pkt_data_len[], int total_pkts[], - int sessions = 1) { + int pkt_data_len[], int total_pkts[], int sessions = 1) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st22_tx_ops ops_tx; struct st22_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -1066,11 +1054,11 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -1084,10 +1072,9 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * - test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = + (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -1138,10 +1125,9 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * - test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = + (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -1167,14 +1153,12 @@ static void st22_rx_dump_test(enum st_fps fps[], int width[], int height[], EXPECT_GE(ret, 0); EXPECT_EQ(meta.dumped_packets[MTL_SESSION_PORT_P], max_dump_packets); dbg("%s, file_name %s\n", __func__, meta.file_name[MTL_SESSION_PORT_P]); - if (ret >= 0) - remove(meta.file_name[MTL_SESSION_PORT_P]); + if (ret >= 0) remove(meta.file_name[MTL_SESSION_PORT_P]); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; } @@ -1203,8 +1187,7 @@ static int st22_digest_rx_frame_ready(void *priv, void *frame, struct st22_rx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; if (meta->frame_total_size != ctx->frame_size) { ctx->incomplete_frame_cnt++; @@ -1220,8 +1203,7 @@ static int st22_digest_rx_frame_ready(void *priv, void *frame, st22_rx_put_framebuff((st22_rx_handle)ctx->handle, frame); } ctx->fb_rec++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); dbg("%s, frame %p\n", __func__, frame); return 0; } @@ -1233,8 +1215,7 @@ static void st22_digest_rx_frame_check(void *args) { while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } else { @@ -1245,8 +1226,7 @@ static void st22_digest_rx_frame_check(void *args) { SHA256((unsigned char *)frame, ctx->frame_size, result); for (i = 0; i < ST22_TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= ST22_TEST_SHA_HIST_NUM) { test_sha_dump("st22_rx_error_sha", result); @@ -1270,13 +1250,13 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], struct st22_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -1311,11 +1291,11 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -1329,10 +1309,9 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * - test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = + (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -1408,10 +1387,9 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.rtp_ring_size = 1024; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * - test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = + (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -1441,8 +1419,7 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; @@ -1454,8 +1431,8 @@ static void st22_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); EXPECT_GT(test_ctx_rx[i]->check_sha_frame_cnt, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); EXPECT_EQ(test_ctx_rx[i]->sha_fail_cnt, 0); EXPECT_EQ(test_ctx_rx[i]->incomplete_frame_cnt, 0); @@ -1484,13 +1461,12 @@ TEST(St22_rx, digest_rtcp_s2) { int height[2] = {1080, 1080}; int pkt_data_len[2] = {1280, 1280}; int total_pkts[2] = {551, 1520}; - st22_rx_digest_test(fps, width, height, pkt_data_len, total_pkts, - ST_TEST_LEVEL_ALL, 2, true); + st22_rx_digest_test(fps, width, height, pkt_data_len, total_pkts, ST_TEST_LEVEL_ALL, 2, + true); } -static void st22_tx_user_pacing_test(int width[], int height[], - int pkt_data_len[], int total_pkts[], - enum st_test_level level, +static void st22_tx_user_pacing_test(int width[], int height[], int pkt_data_len[], + int total_pkts[], enum st_test_level level, int sessions = 1) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; @@ -1499,13 +1475,13 @@ static void st22_tx_user_pacing_test(int width[], int height[], struct st22_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -1542,11 +1518,11 @@ static void st22_tx_user_pacing_test(int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 15000 + i * 2; @@ -1561,10 +1537,9 @@ static void st22_tx_user_pacing_test(int width[], int height[], ops_tx.flags = ST22_TX_FLAG_USER_PACING; test_ctx_tx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_tx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_tx[i]->frame_size = (size_t)test_ctx_tx[i]->pkt_data_len * - test_ctx_tx[i]->total_pkts_in_frame; + test_ctx_tx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_tx[i]->frame_size = + (size_t)test_ctx_tx[i]->pkt_data_len * test_ctx_tx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_tx.framebuff_max_size = @@ -1609,10 +1584,9 @@ static void st22_tx_user_pacing_test(int width[], int height[], ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; test_ctx_rx[i]->pkt_data_len = pkt_data_len[i]; - test_ctx_rx[i]->total_pkts_in_frame = - total_pkts[i]; /* compress ratio 1/8, 4320/8 */ - test_ctx_rx[i]->frame_size = (size_t)test_ctx_rx[i]->pkt_data_len * - test_ctx_rx[i]->total_pkts_in_frame; + test_ctx_rx[i]->total_pkts_in_frame = total_pkts[i]; /* compress ratio 1/8, 4320/8 */ + test_ctx_rx[i]->frame_size = + (size_t)test_ctx_rx[i]->pkt_data_len * test_ctx_rx[i]->total_pkts_in_frame; /* set max to 100 extra */ ops_rx.framebuff_max_size = @@ -1632,8 +1606,7 @@ static void st22_tx_user_pacing_test(int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; rx_framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; tx_framerate[i] = test_ctx_tx[i]->fb_send / time_sec; @@ -1643,14 +1616,12 @@ static void st22_tx_user_pacing_test(int width[], int height[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, rx_framerate[i]); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, - test_ctx_tx[i]->fb_send, tx_framerate[i]); - EXPECT_NEAR(rx_framerate[i], expect_framerate[i], - expect_framerate[i] * 0.1); - EXPECT_NEAR(tx_framerate[i], expect_framerate[i], - expect_framerate[i] * 0.1); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + rx_framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx_tx[i]->fb_send, + tx_framerate[i]); + EXPECT_NEAR(rx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); + EXPECT_NEAR(tx_framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st22_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); ret = st22_rx_free(rx_handle[i]); @@ -1665,6 +1636,5 @@ TEST(St22_tx, tx_user_pacing) { int height[1] = {1080}; int pkt_data_len[1] = {1260}; int total_pkts[1] = {602}; - st22_tx_user_pacing_test(width, height, pkt_data_len, total_pkts, - ST_TEST_LEVEL_ALL, 1); + st22_tx_user_pacing_test(width, height, pkt_data_len, total_pkts, ST_TEST_LEVEL_ALL, 1); } diff --git a/tests/src/st22p_test.cpp b/tests/src/st22p_test.cpp index 654d9ed04..6358ac02b 100644 --- a/tests/src/st22p_test.cpp +++ b/tests/src/st22p_test.cpp @@ -16,23 +16,16 @@ static int test_encode_frame(struct test_st22_encoder_session *s, size_t codestream_size = req->max_codestream_size; /* check frame sanity */ - if (frame->src->width != req->width) - return -EIO; - if (frame->dst->width != req->width) - return -EIO; - if (frame->src->height != req->height) - return -EIO; - if (frame->dst->height != req->height) - return -EIO; - if (frame->src->fmt != req->input_fmt) - return -EIO; - if (frame->dst->fmt != req->output_fmt) - return -EIO; + if (frame->src->width != req->width) return -EIO; + if (frame->dst->width != req->width) return -EIO; + if (frame->src->height != req->height) return -EIO; + if (frame->dst->height != req->height) return -EIO; + if (frame->src->fmt != req->input_fmt) return -EIO; + if (frame->dst->fmt != req->output_fmt) return -EIO; /* copy src sha to the start of encode frame */ memcpy(frame->dst->addr[0], - (uint8_t *)frame->src->addr[0] + frame->src->data_size - - SHA256_DIGEST_LENGTH, + (uint8_t *)frame->src->addr[0] + frame->src->data_size - SHA256_DIGEST_LENGTH, SHA256_DIGEST_LENGTH); st_usleep(s->sleep_time_us); /* data size indicate the encode stream size for current frame */ @@ -43,8 +36,7 @@ static int test_encode_frame(struct test_st22_encoder_session *s, frame->dst->data_size = codestream_size; s->frame_cnt++; - dbg("%s(%d), succ, codestream_size %" PRIu64 "\n", __func__, s->idx, - codestream_size); + dbg("%s(%d), succ, codestream_size %" PRIu64 "\n", __func__, s->idx, codestream_size); /* simulate fail and timeout */ if (s->fail_interval) { @@ -68,8 +60,7 @@ static void *test_encode_thread(void *arg) { struct st22_encode_frame_meta *frame; int result; - if (ctx->encoder_use_block_get) - st22_encoder_set_block_timeout(session_p, NS_PER_S); + if (ctx->encoder_use_block_get) st22_encoder_set_block_timeout(session_p, NS_PER_S); dbg("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -77,8 +68,7 @@ static void *test_encode_thread(void *arg) { if (!frame) { /* no frame */ if (!ctx->encoder_use_block_get) { st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); } continue; @@ -91,19 +81,17 @@ static void *test_encode_thread(void *arg) { return NULL; } -static st22_encode_priv -test_encoder_create_session(void *priv, st22p_encode_session session_p, - struct st22_encoder_create_req *req) { +static st22_encode_priv test_encoder_create_session(void *priv, + st22p_encode_session session_p, + struct st22_encoder_create_req *req) { struct st_tests_context *ctx = (struct st_tests_context *)priv; struct test_st22_encoder_session *session = NULL; int ret; for (int i = 0; i < MAX_TEST_ENCODER_SESSIONS; i++) { - if (ctx->encoder_sessions[i]) - continue; + if (ctx->encoder_sessions[i]) continue; session = (struct test_st22_encoder_session *)malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->ctx = ctx; session->idx = i; @@ -111,14 +99,12 @@ test_encoder_create_session(void *priv, st22p_encode_session session_p, st_pthread_cond_init(&session->wake_cond, NULL); req->max_codestream_size = req->codestream_size; - if (ctx->encoder_use_block_get) - req->resp_flag |= ST22_ENCODER_RESP_FLAG_BLOCK_GET; + if (ctx->encoder_use_block_get) req->resp_flag |= ST22_ENCODER_RESP_FLAG_BLOCK_GET; session->req = *req; session->session_p = session_p; double fps = st_frame_rate(req->fps); - if (!fps) - fps = 60; + if (!fps) fps = 60; session->sleep_time_us = 1000 * 1000 / fps * 8 / 10; dbg("%s(%d), sleep_time_us %d\n", __func__, i, session->sleep_time_us); session->fail_interval = ctx->plugin_fail_interval; @@ -126,8 +112,7 @@ test_encoder_create_session(void *priv, st22p_encode_session session_p, session->timeout_ms = ctx->plugin_timeout_ms; session->rand_ratio = ctx->plugin_rand_ratio; - ret = pthread_create(&session->encode_thread, NULL, test_encode_thread, - session); + ret = pthread_create(&session->encode_thread, NULL, test_encode_thread, session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -166,20 +151,17 @@ static int test_encoder_free_session(void *priv, st22_encode_priv session) { st_pthread_mutex_destroy(&encoder_session->wake_mutex); st_pthread_cond_destroy(&encoder_session->wake_cond); - dbg("%s(%d), total %d encode frames\n", __func__, idx, - encoder_session->frame_cnt); + dbg("%s(%d), total %d encode frames\n", __func__, idx, encoder_session->frame_cnt); free(encoder_session); ctx->encoder_sessions[idx] = NULL; return 0; } static int test_encoder_frame_available(void *priv) { - struct test_st22_encoder_session *s = - (struct test_st22_encoder_session *)priv; + struct test_st22_encoder_session *s = (struct test_st22_encoder_session *)priv; struct st_tests_context *ctx = s->ctx; - if (ctx->encoder_use_block_get) - return 0; + if (ctx->encoder_use_block_get) return 0; // dbg("%s(%d)\n", __func__, s->idx); st_pthread_mutex_lock(&s->wake_mutex); @@ -194,24 +176,16 @@ static int test_decode_frame(struct test_st22_decoder_session *s, struct st22_decoder_create_req *req = &s->req; /* check frame sanity */ - if (frame->src->width != req->width) - return -EIO; - if (frame->dst->width != req->width) - return -EIO; - if (frame->src->height != req->height) - return -EIO; - if (frame->dst->height != req->height) - return -EIO; - if (frame->src->fmt != req->input_fmt) - return -EIO; - if (frame->dst->fmt != req->output_fmt) - return -EIO; - if (frame->src->data_size > frame->src->buffer_size) - return -EIO; + if (frame->src->width != req->width) return -EIO; + if (frame->dst->width != req->width) return -EIO; + if (frame->src->height != req->height) return -EIO; + if (frame->dst->height != req->height) return -EIO; + if (frame->src->fmt != req->input_fmt) return -EIO; + if (frame->dst->fmt != req->output_fmt) return -EIO; + if (frame->src->data_size > frame->src->buffer_size) return -EIO; /* copy sha to the end of decode frame */ - memcpy((uint8_t *)frame->dst->addr[0] + frame->dst->data_size - - SHA256_DIGEST_LENGTH, + memcpy((uint8_t *)frame->dst->addr[0] + frame->dst->data_size - SHA256_DIGEST_LENGTH, frame->src->addr[0], SHA256_DIGEST_LENGTH); st_usleep(s->sleep_time_us); @@ -240,8 +214,7 @@ static void *test_decode_thread(void *arg) { struct st22_decode_frame_meta *frame; int result; - if (ctx->encoder_use_block_get) - st22_decoder_set_block_timeout(session_p, NS_PER_S); + if (ctx->encoder_use_block_get) st22_decoder_set_block_timeout(session_p, NS_PER_S); dbg("%s(%d), start\n", __func__, s->idx); while (!s->stop) { @@ -249,8 +222,7 @@ static void *test_decode_thread(void *arg) { if (!frame) { /* no frame */ if (!ctx->decoder_use_block_get) { st_pthread_mutex_lock(&s->wake_mutex); - if (!s->stop) - st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); + if (!s->stop) st_pthread_cond_wait(&s->wake_cond, &s->wake_mutex); st_pthread_mutex_unlock(&s->wake_mutex); } continue; @@ -263,19 +235,17 @@ static void *test_decode_thread(void *arg) { return NULL; } -static st22_decode_priv -test_decoder_create_session(void *priv, st22p_decode_session session_p, - struct st22_decoder_create_req *req) { +static st22_decode_priv test_decoder_create_session(void *priv, + st22p_decode_session session_p, + struct st22_decoder_create_req *req) { struct st_tests_context *ctx = (struct st_tests_context *)priv; struct test_st22_decoder_session *session = NULL; int ret; for (int i = 0; i < MAX_TEST_DECODER_SESSIONS; i++) { - if (ctx->decoder_sessions[i]) - continue; + if (ctx->decoder_sessions[i]) continue; session = (struct test_st22_decoder_session *)malloc(sizeof(*session)); - if (!session) - return NULL; + if (!session) return NULL; memset(session, 0, sizeof(*session)); session->idx = i; session->ctx = ctx; @@ -289,16 +259,14 @@ test_decoder_create_session(void *priv, st22p_decode_session session_p, session->req = *req; session->session_p = session_p; double fps = st_frame_rate(req->fps); - if (!fps) - fps = 60; + if (!fps) fps = 60; session->sleep_time_us = 1000 * 1000 / fps * 8 / 10; dbg("%s(%d), sleep_time_us %d\n", __func__, i, session->sleep_time_us); session->fail_interval = ctx->plugin_fail_interval; session->timeout_interval = ctx->plugin_timeout_interval; session->timeout_ms = ctx->plugin_timeout_ms; - ret = pthread_create(&session->decode_thread, NULL, test_decode_thread, - session); + ret = pthread_create(&session->decode_thread, NULL, test_decode_thread, session); if (ret < 0) { err("%s(%d), thread create fail %d\n", __func__, i, ret); st_pthread_mutex_destroy(&session->wake_mutex); @@ -336,20 +304,17 @@ static int test_decoder_free_session(void *priv, st22_decode_priv session) { st_pthread_mutex_destroy(&decoder_session->wake_mutex); st_pthread_cond_destroy(&decoder_session->wake_cond); - dbg("%s(%d), total %d decode frames\n", __func__, idx, - decoder_session->frame_cnt); + dbg("%s(%d), total %d decode frames\n", __func__, idx, decoder_session->frame_cnt); free(decoder_session); ctx->decoder_sessions[idx] = NULL; return 0; } static int test_decoder_frame_available(void *priv) { - struct test_st22_decoder_session *s = - (struct test_st22_decoder_session *)priv; + struct test_st22_decoder_session *s = (struct test_st22_decoder_session *)priv; struct st_tests_context *ctx = s->ctx; - if (ctx->decoder_use_block_get) - return 0; + if (ctx->decoder_use_block_get) return 0; // dbg("%s(%d)\n", __func__, s->idx); st_pthread_mutex_lock(&s->wake_mutex); @@ -381,10 +346,8 @@ int st_test_st22_plugin_register(struct st_tests_context *ctx) { d_dev.name = "st22_test_decoder"; d_dev.priv = ctx; d_dev.target_device = ST_PLUGIN_DEVICE_TEST; - d_dev.input_fmt_caps = - ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; - d_dev.output_fmt_caps = - ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8; + d_dev.input_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + d_dev.output_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8; d_dev.create_session = test_decoder_create_session; d_dev.free_session = test_decoder_free_session; d_dev.notify_frame_available = test_decoder_frame_available; @@ -400,8 +363,7 @@ int st_test_st22_plugin_register(struct st_tests_context *ctx) { e_dev.priv = ctx; e_dev.target_device = ST_PLUGIN_DEVICE_TEST; e_dev.input_fmt_caps = ST_FMT_CAP_YUV422PLANAR10LE | ST_FMT_CAP_YUV422PLANAR8; - e_dev.output_fmt_caps = - ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; + e_dev.output_fmt_caps = ST_FMT_CAP_JPEGXS_CODESTREAM | ST_FMT_CAP_H264_CBR_CODESTREAM; e_dev.create_session = test_encoder_create_session; e_dev.free_session = test_encoder_free_session; e_dev.notify_frame_available = test_encoder_frame_available; @@ -431,17 +393,16 @@ static void plugin_register_test(const char *so_name, bool expect_succ) { } TEST(St22p, plugin_register_single) { - plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", - true); + plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample.so", true); } TEST(St22p, plugin_register_fail) { - plugin_register_test( - "/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", false); + plugin_register_test("/usr/local/lib/x86_64-linux-gnu/libst_plugin_sample_fail.so", + false); } static void frame_draw_logo_test(enum st_frame_fmt fmt, uint32_t w, uint32_t h, - uint32_t logo_w, uint32_t logo_h, uint32_t x, - uint32_t y, bool expect) { + uint32_t logo_w, uint32_t logo_h, uint32_t x, uint32_t y, + bool expect) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto st = ctx->handle; size_t logo_size = st_frame_size(fmt, logo_w, logo_h, false); @@ -480,18 +441,18 @@ static void frame_draw_logo_test(enum st_frame_fmt fmt, uint32_t w, uint32_t h, } TEST(St22p, draw_logo_rfc4175_1080p) { - frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 200, 200, - 16, 16, true); + frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 200, 200, 16, 16, + true); } TEST(St22p, draw_logo_rfc4175_1080p_full) { - frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, - 1080, 0, 0, true); + frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, 1080, 0, 0, + true); } TEST(St22p, draw_logo_rfc4175_1080p_fail) { - frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, - 1080, 100, 100, false); + frame_draw_logo_test(ST_FRAME_FMT_YUV422RFC4175PG2BE10, 1920, 1080, 1920, 1080, 100, + 100, false); } static int test_st22p_tx_frame_available(void *priv) { @@ -505,13 +466,11 @@ static int test_st22p_tx_frame_available(void *priv) { static int test_st22p_tx_frame_done(void *priv, struct st_frame *frame) { tests_context *s = (tests_context *)priv; - if (!s->handle) - return -EIO; /* not ready */ + if (!s->handle) return -EIO; /* not ready */ s->fb_send_done++; - if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) - return 0; + if (!(frame->flags & ST_FRAME_FLAG_EXT_BUF)) return 0; for (int i = 0; i < s->fb_cnt; ++i) { if (frame->addr[0] == s->ext_fb + i * s->frame_size) { @@ -536,8 +495,7 @@ static int test_st22p_rx_frame_available(void *priv) { static int test_st22p_rx_query_ext_frame(void *priv, st_ext_frame *ext_frame, struct st22_rx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ int i = ctx->ext_idx; /* check ext_fb_in_use */ @@ -547,27 +505,24 @@ static int test_st22p_rx_query_ext_frame(void *priv, st_ext_frame *ext_frame, } *ext_frame = ctx->p_ext_frames[i]; - dbg("%s(%d), set ext frame %d(%p) to use\n", __func__, ctx->idx, i, - ext_frame->addr); + dbg("%s(%d), set ext frame %d(%p) to use\n", __func__, ctx->idx, i, ext_frame->addr); ctx->ext_fb_in_use[i] = true; ext_frame->opaque = &ctx->ext_fb_in_use[i]; - if (++ctx->ext_idx >= ctx->fb_cnt) - ctx->ext_idx = 0; + if (++ctx->ext_idx >= ctx->fb_cnt) ctx->ext_idx = 0; return 0; } -static void st22p_tx_ops_init(tests_context *st22, - struct st22p_tx_ops *ops_tx) { +static void st22p_tx_ops_init(tests_context *st22, struct st22p_tx_ops *ops_tx) { auto ctx = st22->ctx; memset(ops_tx, 0, sizeof(*ops_tx)); ops_tx->name = "st22p_test"; ops_tx->priv = st22; ops_tx->port.num_port = 1; - memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx->port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + st22->idx; @@ -588,16 +543,15 @@ static void st22p_tx_ops_init(tests_context *st22, ops_tx->notify_event = test_ctx_notify_event; } -static void st22p_rx_ops_init(tests_context *st22, - struct st22p_rx_ops *ops_rx) { +static void st22p_rx_ops_init(tests_context *st22, struct st22p_rx_ops *ops_rx) { auto ctx = st22->ctx; memset(ops_rx, 0, sizeof(*ops_rx)); ops_rx->name = "st22p_test"; ops_rx->priv = st22; ops_rx->port.num_port = 1; - memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx->port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + st22->idx; @@ -662,8 +616,12 @@ TEST(St22p, tx_create_free_max) { TEST(St22p, rx_create_free_max) { pipeline_create_free_max(st22p_rx, TEST_CREATE_FREE_MAX); } -TEST(St22p, tx_create_expect_fail) { pipeline_expect_fail_test(st22p_tx); } -TEST(St22p, rx_create_expect_fail) { pipeline_expect_fail_test(st22p_rx); } +TEST(St22p, tx_create_expect_fail) { + pipeline_expect_fail_test(st22p_tx); +} +TEST(St22p, rx_create_expect_fail) { + pipeline_expect_fail_test(st22p_rx); +} TEST(St22p, tx_create_expect_fail_fb_cnt) { uint16_t fbcnt = 1; pipeline_expect_fail_test_fb_cnt(st22p_tx, fbcnt); @@ -689,22 +647,16 @@ static void test_st22p_tx_frame_thread(void *args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) - s->cv.wait(lck); + if (!s->stop) s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->width != s->width) - s->incomplete_frame_cnt++; - if (frame->height != s->height) - s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) - s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->width != s->width) s->incomplete_frame_cnt++; + if (frame->height != s->height) s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; if (s->user_timestamp) { frame->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; frame->timestamp = s->fb_send; @@ -714,14 +666,12 @@ static void test_st22p_tx_frame_thread(void *args) { int ret = st22p_tx_put_ext_frame((st22p_tx_handle)handle, frame, &s->p_ext_frames[s->ext_idx]); if (ret < 0) { - err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, - s->ext_idx); + err("%s, put ext framebuffer fail %d fb_idx %d\n", __func__, ret, s->ext_idx); continue; } s->ext_fb_in_use[s->ext_idx] = true; s->ext_idx++; - if (s->ext_idx >= s->fb_cnt) - s->ext_idx = 0; + if (s->ext_idx >= s->fb_cnt) s->ext_idx = 0; } else { /* directly put */ st22p_tx_put_frame((st22p_tx_handle)handle, frame); @@ -748,26 +698,19 @@ static void test_st22p_rx_frame_thread(void *args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) - s->cv.wait(lck); + if (!s->stop) s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->buffer_size < s->frame_size) - s->incomplete_frame_cnt++; - if (frame->width != s->width) - s->incomplete_frame_cnt++; - if (frame->height != s->height) - s->incomplete_frame_cnt++; - if (frame->fmt != s->fmt) - s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->buffer_size < s->frame_size) s->incomplete_frame_cnt++; + if (frame->width != s->width) s->incomplete_frame_cnt++; + if (frame->height != s->height) s->incomplete_frame_cnt++; + if (frame->fmt != s->fmt) s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) - s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; timestamp = frame->timestamp; if (frame->opaque) { @@ -786,20 +729,19 @@ static void test_st22p_rx_frame_thread(void *args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", - __func__, s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, + s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; } - unsigned char *sha = (unsigned char *)frame->addr[0] + frame->data_size - - SHA256_DIGEST_LENGTH; + unsigned char *sha = + (unsigned char *)frame->addr[0] + frame->data_size - SHA256_DIGEST_LENGTH; int i = 0; for (i = 0; i < ST22_TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = s->shas[i]; - if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(sha, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= ST22_TEST_SHA_HIST_NUM) { test_sha_dump("st22p_rx_error_sha", sha); @@ -808,8 +750,7 @@ static void test_st22p_rx_frame_thread(void *args) { /* directly put */ st22p_rx_put_frame((st22p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) - s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } @@ -834,8 +775,7 @@ struct st22p_rx_digest_test_para { bool derive; }; -static void -test_st22p_init_rx_digest_para(struct st22p_rx_digest_test_para *para) { +static void test_st22p_init_rx_digest_para(struct st22p_rx_digest_test_para *para) { memset(para, 0, sizeof(*para)); para->sessions = 1; @@ -857,8 +797,8 @@ test_st22p_init_rx_digest_para(struct st22p_rx_digest_test_para *para) { } static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], - enum st_frame_fmt fmt[], - enum st22_codec codec[], int compress_ratio[], + enum st_frame_fmt fmt[], enum st22_codec codec[], + int compress_ratio[], struct st22p_rx_digest_test_para *para) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto st = ctx->handle; @@ -874,14 +814,12 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], st_test_jxs_use_block_get(ctx, para->codec_block_get); if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled, one for tx and one for rx\n", - __func__); + info("%s, dual port should be enabled, one for tx and one for rx\n", __func__); return; } /* return if level lower than global */ - if (para->level < ctx->level) - return; + if (para->level < ctx->level) return; if (para->tx_ext || para->rx_ext) { if (ctx->iova == MTL_IOVA_MODE_PA) { @@ -919,9 +857,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { expect_framerate_tx[i] = st_frame_rate(fps[i]); if (para->timeout_interval) { - expect_framerate_tx[i] = expect_framerate_tx[i] * - (para->timeout_interval - 1) / - para->timeout_interval; + expect_framerate_tx[i] = + expect_framerate_tx[i] * (para->timeout_interval - 1) / para->timeout_interval; } test_ctx_tx[i] = new tests_context(); @@ -942,11 +879,11 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.priv = test_ctx_tx[i]; ops_tx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + i * 2; @@ -968,10 +905,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.notify_frame_available = test_st22p_tx_frame_available; ops_tx.notify_event = test_ctx_notify_event; ops_tx.notify_frame_done = test_st22p_tx_frame_done; - if (para->user_timestamp) - ops_tx.flags |= ST22P_TX_FLAG_USER_TIMESTAMP; - if (para->vsync) - ops_tx.flags |= ST22P_TX_FLAG_ENABLE_VSYNC; + if (para->user_timestamp) ops_tx.flags |= ST22P_TX_FLAG_USER_TIMESTAMP; + if (para->vsync) ops_tx.flags |= ST22P_TX_FLAG_ENABLE_VSYNC; if (para->tx_ext) { ops_tx.flags |= ST22P_TX_FLAG_EXT_FRAME; } @@ -985,8 +920,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_tx.codestream_size = ops_tx.width * ops_tx.height / compress_ratio[i]; test_ctx_tx[i]->frame_size = ops_tx.codestream_size; } else { - test_ctx_tx[i]->frame_size = st_frame_size( - ops_tx.input_fmt, ops_tx.width, ops_tx.height, ops_tx.interlaced); + test_ctx_tx[i]->frame_size = + st_frame_size(ops_tx.input_fmt, ops_tx.width, ops_tx.height, ops_tx.interlaced); ops_tx.codestream_size = test_ctx_tx[i]->frame_size / compress_ratio[i]; } @@ -1015,14 +950,13 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ASSERT_TRUE(test_ctx_tx[i]->ext_fb_malloc != NULL); test_ctx_tx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_tx[i]->ext_fb_malloc, pg_sz); - test_ctx_tx[i]->ext_fb_iova = mtl_dma_map( - st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); + test_ctx_tx[i]->ext_fb_iova = + mtl_dma_map(st, test_ctx_tx[i]->ext_fb, test_ctx_tx[i]->ext_fb_iova_map_sz); ASSERT_TRUE(test_ctx_tx[i]->ext_fb_iova != MTL_BAD_IOVA); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_tx[i]->ext_fb); for (int j = 0; j < test_ctx_tx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; - plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ test_ctx_tx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(fmt[i], width[i], plane); if (plane == 0) { @@ -1058,8 +992,7 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], SHA256((unsigned char *)fb, frame_size, result); test_sha_dump("st22p_tx", result); /* copy sha to the end of frame */ - memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, - SHA256_DIGEST_LENGTH); + memcpy(fb + frame_size - SHA256_DIGEST_LENGTH, result, SHA256_DIGEST_LENGTH); } test_ctx_tx[i]->handle = tx_handle[i]; @@ -1070,8 +1003,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { if (para->fail_interval) { /* loss in the tx */ - expect_framerate_tx[i] = expect_framerate_tx[i] * - (para->fail_interval - 1) / para->fail_interval; + expect_framerate_tx[i] = + expect_framerate_tx[i] * (para->fail_interval - 1) / para->fail_interval; } expect_framerate_rx[i] = expect_framerate_tx[i]; test_ctx_rx[i] = new tests_context(); @@ -1104,14 +1037,13 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ASSERT_TRUE(test_ctx_rx[i]->ext_fb_malloc != NULL); test_ctx_rx[i]->ext_fb = (uint8_t *)MTL_ALIGN((uint64_t)test_ctx_rx[i]->ext_fb_malloc, pg_sz); - test_ctx_rx[i]->ext_fb_iova = mtl_dma_map( - st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); + test_ctx_rx[i]->ext_fb_iova = + mtl_dma_map(st, test_ctx_rx[i]->ext_fb, test_ctx_rx[i]->ext_fb_iova_map_sz); info("%s, session %d ext_fb %p\n", __func__, i, test_ctx_rx[i]->ext_fb); ASSERT_TRUE(test_ctx_rx[i]->ext_fb_iova != MTL_BAD_IOVA); for (int j = 0; j < test_ctx_rx[i]->fb_cnt; j++) { - for (uint8_t plane = 0; plane < planes; - plane++) { /* assume planes continuous */ + for (uint8_t plane = 0; plane < planes; plane++) { /* assume planes continuous */ test_ctx_rx[i]->p_ext_frames[j].linesize[plane] = st_frame_least_linesize(fmt[i], width[i], plane); if (plane == 0) { @@ -1138,11 +1070,11 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], ops_rx.priv = test_ctx_rx[i]; ops_rx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ST22P_TEST_UDP_PORT + i * 2; @@ -1162,16 +1094,14 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], else ops_rx.notify_frame_available = test_st22p_rx_frame_available; ops_rx.notify_event = test_ctx_notify_event; - if (para->vsync) - ops_rx.flags |= ST22P_RX_FLAG_ENABLE_VSYNC; + if (para->vsync) ops_rx.flags |= ST22P_RX_FLAG_ENABLE_VSYNC; if (para->rx_ext) { ops_rx.flags |= ST22P_RX_FLAG_EXT_FRAME; ops_rx.query_ext_frame = test_st22p_rx_query_ext_frame; } if (para->rtcp) { - ops_rx.flags |= - ST22P_RX_FLAG_ENABLE_RTCP | ST22P_RX_FLAG_SIMULATE_PKT_LOSS; + ops_rx.flags |= ST22P_RX_FLAG_ENABLE_RTCP | ST22P_RX_FLAG_SIMULATE_PKT_LOSS; ops_rx.rtcp.nack_interval_us = 100; ops_rx.rtcp.seq_skip_window = 0; ops_rx.rtcp.burst_loss_max = 4; @@ -1181,8 +1111,8 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], if (para->derive) test_ctx_rx[i]->frame_size = test_ctx_tx[i]->frame_size; else - test_ctx_rx[i]->frame_size = st_frame_size( - ops_rx.output_fmt, ops_rx.width, ops_rx.height, ops_rx.interlaced); + test_ctx_rx[i]->frame_size = st_frame_size(ops_rx.output_fmt, ops_rx.width, + ops_rx.height, ops_rx.interlaced); rx_handle[i] = st22p_rx_create(st, &ops_rx); ASSERT_TRUE(rx_handle[i] != NULL); @@ -1212,45 +1142,37 @@ static void st22p_rx_digest_test(enum st_fps fps[], int width[], int height[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; framerate_tx[i] = test_ctx_tx[i]->fb_send / time_sec; /* vsync check */ - time_sec = - (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; + time_sec = (double)(cur_time_ns - test_ctx_tx[i]->first_vsync_time) / NS_PER_S; vsyncrate_tx[i] = test_ctx_tx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_tx[i], test_ctx_tx[i]->vsync_cnt, vsyncrate_tx[i]); EXPECT_GT(test_ctx_tx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), - st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_tx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); test_ctx_tx[i]->stop = true; - if (para->block_get) - st22p_tx_wake_block(tx_handle[i]); + if (para->block_get) st22p_tx_wake_block(tx_handle[i]); test_ctx_tx[i]->cv.notify_all(); tx_thread[i].join(); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate_rx[i] = test_ctx_rx[i]->fb_rec / time_sec; /* vsync check */ - time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; + time_sec = (double)(cur_time_ns - test_ctx_rx[i]->first_vsync_time) / NS_PER_S; vsyncrate_rx[i] = test_ctx_rx[i]->vsync_cnt / time_sec; dbg("%s(%d,%p), vsync_cnt %d vsyncrate %f\n", __func__, i, test_ctx_rx[i], test_ctx_rx[i]->vsync_cnt, vsyncrate_rx[i]); EXPECT_GT(test_ctx_rx[i]->vsync_cnt, 0); - EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), - st_frame_rate(fps[i]) * 0.1); + EXPECT_NEAR(vsyncrate_rx[i], st_frame_rate(fps[i]), st_frame_rate(fps[i]) * 0.1); test_ctx_rx[i]->stop = true; - if (para->block_get) - st22p_rx_wake_block(rx_handle[i]); + if (para->block_get) st22p_rx_wake_block(rx_handle[i]); test_ctx_rx[i]->cv.notify_all(); rx_thread[i].join(); } diff --git a/tests/src/st30_test.cpp b/tests/src/st30_test.cpp index 19bc970f5..4ea18a435 100644 --- a/tests/src/st30_test.cpp +++ b/tests/src/st30_test.cpp @@ -18,29 +18,24 @@ static int tx_audio_next_frame_timestamp(void *priv, uint16_t *next_frame_idx, struct st30_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ if (!ctx->ptp_time_first_frame) { ctx->ptp_time_first_frame = mtl_ptp_read_time(ctx->ctx->handle); } meta->tfmt = ST10_TIMESTAMP_FMT_TAI; - meta->timestamp = - ctx->ptp_time_first_frame + ctx->fb_send * ctx->frame_time * 2; + meta->timestamp = ctx->ptp_time_first_frame + ctx->fb_send * ctx->frame_time * 2; *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_audio_build_rtp_packet(tests_context *s, - struct st_rfc3550_rtp_hdr *rtp, +static int tx_audio_build_rtp_packet(tests_context *s, struct st_rfc3550_rtp_hdr *rtp, uint16_t *pkt_len) { /* rtp hdr */ memset(rtp, 0x0, sizeof(*rtp)); @@ -55,14 +50,12 @@ static int tx_audio_build_rtp_packet(tests_context *s, s->rtp_tmstamp++; rtp->seq_number = htons(s->seq_id); s->seq_id++; - if (s->seq_id == 0x10000) - s->seq_id = 0; + if (s->seq_id == 0x10000) s->seq_id = 0; if (s->check_sha) { uint8_t *payload = (uint8_t *)rtp + sizeof(*rtp); mtl_memcpy(payload, s->frame_buf[s->fb_idx], s->pkt_data_len); s->fb_idx++; - if (s->fb_idx >= TEST_SHA_HIST_NUM) - s->fb_idx = 0; + if (s->fb_idx >= TEST_SHA_HIST_NUM) s->fb_idx = 0; } *pkt_len = sizeof(struct st_rfc3550_rtp_hdr) + s->pkt_data_len; return 0; @@ -84,16 +77,14 @@ static void tx_feed_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - tx_audio_build_rtp_packet(ctx, (struct st_rfc3550_rtp_hdr *)usrptr, - &mbuf_len); + tx_audio_build_rtp_packet(ctx, (struct st_rfc3550_rtp_hdr *)usrptr, &mbuf_len); st30_tx_put_mbuf((st30_tx_handle)ctx->handle, mbuf, mbuf_len); } } @@ -101,13 +92,11 @@ static void tx_feed_packet(void *args) { static int tx_rtp_done(void *args) { auto ctx = (tests_context *)args; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); ctx->fb_send++; return 0; } @@ -115,13 +104,11 @@ static int tx_rtp_done(void *args) { static int rx_rtp_ready(void *args) { auto ctx = (tests_context *)args; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -141,8 +128,7 @@ static void rx_get_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } @@ -155,8 +141,7 @@ static void rx_get_packet(void *args) { int i; for (i = 0; i < TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st30_rx_error_sha", result); @@ -169,12 +154,10 @@ static void rx_get_packet(void *args) { } } -static int st30_rx_frame_ready(void *priv, void *frame, - struct st30_rx_frame_meta *meta) { +static int st30_rx_frame_ready(void *priv, void *frame, struct st30_rx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; /* direct do the sha check since frame_size is small */ if (ctx->check_sha) { @@ -183,8 +166,7 @@ static int st30_rx_frame_ready(void *priv, void *frame, int i; for (i = 0; i < TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("st30_rx_error_sha", result); @@ -195,8 +177,7 @@ static int st30_rx_frame_ready(void *priv, void *frame, st30_rx_put_framebuff((st30_rx_handle)ctx->handle, frame); ctx->fb_rec++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -207,18 +188,13 @@ static void st30_rx_ops_init(tests_context *st30, struct st30_rx_ops *ops) { ops->name = "st30_test"; ops->priv = st30; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; - memcpy(ops->ip_addr[MTL_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - snprintf(ops->port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", - ctx->para.port[MTL_PORT_P]); + if (ctx->same_dual_port) ops->num_port = 1; + memcpy(ops->ip_addr[MTL_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + snprintf(ops->port[MTL_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops->udp_port[MTL_PORT_P] = 20000 + st30->idx; if (ops->num_port == 2) { - memcpy(ops->ip_addr[MTL_PORT_R], ctx->mcast_ip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); - snprintf(ops->port[MTL_PORT_R], MTL_PORT_MAX_LEN, "%s", - ctx->para.port[MTL_PORT_R]); + memcpy(ops->ip_addr[MTL_PORT_R], ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + snprintf(ops->port[MTL_PORT_R], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops->udp_port[MTL_PORT_R] = 20000 + st30->idx; } ops->type = ST30_TYPE_FRAME_LEVEL; @@ -242,8 +218,7 @@ static void st30_tx_ops_init(tests_context *st30, struct st30_tx_ops *ops) { ops->name = "st30_test"; ops->priv = st30; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; + if (ctx->same_dual_port) ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -293,13 +268,21 @@ static void st30_rx_assert_cnt(int expect_s30_rx_cnt) { EXPECT_EQ(var.st30_rx_sessions_cnt, expect_s30_rx_cnt); } -TEST(St30_tx, create_free_single) { create_free_test(st30_tx, 0, 1, 1); } -TEST(St30_tx, create_free_multi) { create_free_test(st30_tx, 0, 1, 6); } -TEST(St30_tx, create_free_mix) { create_free_test(st30_tx, 2, 3, 4); } +TEST(St30_tx, create_free_single) { + create_free_test(st30_tx, 0, 1, 1); +} +TEST(St30_tx, create_free_multi) { + create_free_test(st30_tx, 0, 1, 6); +} +TEST(St30_tx, create_free_mix) { + create_free_test(st30_tx, 2, 3, 4); +} TEST(St30_tx, create_free_max) { create_free_max(st30_tx, TEST_CREATE_FREE_MAX); } -TEST(St30_tx, create_expect_fail) { expect_fail_test(st30_tx); } +TEST(St30_tx, create_expect_fail) { + expect_fail_test(st30_tx); +} TEST(St30_tx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st30_tx, ST30_TYPE_RTP_LEVEL, ring_size); @@ -319,13 +302,21 @@ TEST(St30_tx, get_framebuffer_expect_fail) { expect_fail_test_get_framebuffer(st30_tx, fbcnt); } -TEST(St30_rx, create_free_single) { create_free_test(st30_rx, 0, 1, 1); } -TEST(St30_rx, create_free_multi) { create_free_test(st30_rx, 0, 1, 6); } -TEST(St30_rx, create_free_mix) { create_free_test(st30_rx, 2, 3, 4); } +TEST(St30_rx, create_free_single) { + create_free_test(st30_rx, 0, 1, 1); +} +TEST(St30_rx, create_free_multi) { + create_free_test(st30_rx, 0, 1, 6); +} +TEST(St30_rx, create_free_mix) { + create_free_test(st30_rx, 2, 3, 4); +} TEST(St30_rx, create_free_max) { create_free_max(st30_rx, TEST_CREATE_FREE_MAX); } -TEST(St30_rx, create_expect_fail) { expect_fail_test(st30_rx); } +TEST(St30_rx, create_expect_fail) { + expect_fail_test(st30_rx); +} TEST(St30_rx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st30_rx, ST30_TYPE_RTP_LEVEL, ring_size); @@ -349,8 +340,7 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], std::vector rtp_thread; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; test_ctx.resize(sessions); handle.resize(sessions); @@ -375,8 +365,7 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops.payload_type = ST30_TEST_PAYLOAD_TYPE; ops.ptime = ptime[i]; ops.framebuff_size = st30_get_sample_size(ops.fmt) * - st30_get_sample_num(ops.ptime, ops.sampling) * - ops.channel; + st30_get_sample_num(ops.ptime, ops.sampling) * ops.channel; test_ctx[i]->pkt_data_len = st30_get_packet_size(ops.fmt, ops.ptime, ops.sampling, ops.channel); @@ -396,8 +385,7 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], sleep(5); for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx[i]->fb_send / time_sec; test_ctx[i]->stop = true; if (type[i] == ST30_TYPE_RTP_LEVEL) { @@ -413,8 +401,8 @@ static void st30_tx_fps_test(enum st30_type type[], enum st30_sampling sample[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx[i]->fb_send, 0); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, - test_ctx[i]->fb_send, framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx[i]->fb_send, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st30_tx_free(handle[i]); EXPECT_GE(ret, 0); @@ -433,15 +421,15 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; std::vector test_ctx_tx; std::vector test_ctx_rx; @@ -477,11 +465,11 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -493,8 +481,8 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops_tx.ssrc = i ? i + 0x66666666 : 0; ops_tx.ptime = ptime[i]; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = st30_get_packet_size( - ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = + st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); EXPECT_GE(ops_tx.framebuff_size, 0); ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_audio_next_frame; @@ -559,8 +547,8 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ssrc = i ? i + 0x66666666 : 0; ops_rx.ptime = ptime[i]; - ops_rx.framebuff_size = st30_get_packet_size( - ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = + st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -599,8 +587,7 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST30_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -626,8 +613,8 @@ static void st30_rx_fps_test(enum st30_type type[], enum st30_sampling sample[], if (check_sha) { EXPECT_GT(test_ctx_rx[i]->check_sha_frame_cnt, 0); } - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st30_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); @@ -650,8 +637,7 @@ TEST(St30_tx, frame_48k_mono_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {1}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, rtp_96k_mono_s1) { enum st30_type type[1] = {ST30_TYPE_RTP_LEVEL}; @@ -659,8 +645,7 @@ TEST(St30_tx, rtp_96k_mono_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {1}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_48k_stereo_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -668,8 +653,7 @@ TEST(St30_tx, frame_48k_stereo_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_48k_stereo_125us_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -677,8 +661,7 @@ TEST(St30_tx, frame_48k_stereo_125us_s1) { enum st30_ptime pt[1] = {ST30_PTIME_125US}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, rtp_48k_stereo_125us_s1) { enum st30_type type[1] = {ST30_TYPE_RTP_LEVEL}; @@ -686,8 +669,7 @@ TEST(St30_tx, rtp_48k_stereo_125us_s1) { enum st30_ptime pt[1] = {ST30_PTIME_125US}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, rtp_96k_stereo_s1) { enum st30_type type[1] = {ST30_TYPE_RTP_LEVEL}; @@ -695,8 +677,7 @@ TEST(St30_tx, rtp_96k_stereo_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_48k_sgrp_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -704,8 +685,7 @@ TEST(St30_tx, frame_48k_sgrp_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, frame_96k_sgrp_s1) { enum st30_type type[1] = {ST30_TYPE_FRAME_LEVEL}; @@ -713,14 +693,12 @@ TEST(St30_tx, frame_96k_sgrp_s1) { enum st30_ptime pt[1] = {ST30_PTIME_1MS}; uint16_t c[1] = {4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; - for (int i = 0; i < 3; i++) - st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); + for (int i = 0; i < 3; i++) st30_tx_fps_test(type, s, pt, c, &f[i], ST_TEST_LEVEL_ALL); } TEST(St30_tx, mix_96k_stereo_s3) { enum st30_type type[3] = {ST30_TYPE_RTP_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_RTP_LEVEL}; - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, - ST30_SAMPLING_96K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, ST30_SAMPLING_96K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_1MS}; uint16_t c[3] = {2, 2, 2}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -730,8 +708,7 @@ TEST(St30_tx, mix_96k_stereo_s3) { TEST(St30_tx, mix_48k_96_mix) { enum st30_type type[3] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_RTP_LEVEL, ST30_TYPE_RTP_LEVEL}; - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_1MS}; uint16_t c[3] = {2, 1, 4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -740,8 +717,7 @@ TEST(St30_tx, mix_48k_96_mix) { TEST(St30_rx, mix_48k_96_mix) { enum st30_type type[3] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_RTP_LEVEL, ST30_TYPE_RTP_LEVEL}; - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_1MS}; uint16_t c[3] = {2, 1, 4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -791,56 +767,52 @@ TEST(St30_rx, frame_digest_stereo_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K}; + enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K, ST30_SAMPLING_48K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_4MS, ST31_PTIME_80US}; uint16_t c[5] = {2, 2, 2, 2, 2}; - enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, - ST30_FMT_PCM16, ST31_FMT_AM824}; + enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, + ST31_FMT_AM824}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_ALL, 5, true); } TEST(St30_rx, frame_digest_max_channel_48k_16bit_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K}; + enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K, ST30_SAMPLING_48K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_1MS, ST30_PTIME_4MS}; uint16_t c[5] = {120, 60, 45, 15, 3}; - enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, - ST30_FMT_PCM16, ST30_FMT_PCM16}; + enum st30_fmt f[5] = {ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, ST30_FMT_PCM16, + ST30_FMT_PCM16}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_ALL, 5, true); } TEST(St30_rx, frame_digest_max_channel_48k_24bit_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K}; + enum st30_sampling s[5] = {ST30_SAMPLING_48K, ST30_SAMPLING_48K, ST30_SAMPLING_48K, + ST30_SAMPLING_48K, ST30_SAMPLING_48K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_1MS, ST30_PTIME_4MS}; uint16_t c[5] = {80, 40, 30, 10, 2}; - enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, - ST30_FMT_PCM24, ST30_FMT_PCM24}; + enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, + ST30_FMT_PCM24}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_MANDATORY, 5, true); } TEST(St30_rx, frame_digest_max_channel_96k_24bit_ptime_mix_s5) { enum st30_type type[5] = {ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL, ST30_TYPE_FRAME_LEVEL}; - enum st30_sampling s[5] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, - ST30_SAMPLING_96K, ST30_SAMPLING_96K, - ST30_SAMPLING_96K}; + enum st30_sampling s[5] = {ST30_SAMPLING_96K, ST30_SAMPLING_96K, ST30_SAMPLING_96K, + ST30_SAMPLING_96K, ST30_SAMPLING_96K}; enum st30_ptime pt[5] = {ST30_PTIME_125US, ST30_PTIME_250US, ST30_PTIME_333US, ST30_PTIME_1MS, ST30_PTIME_4MS}; uint16_t c[5] = {40, 20, 15, 5, 1}; - enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, - ST30_FMT_PCM24, ST30_FMT_PCM24}; + enum st30_fmt f[5] = {ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, ST30_FMT_PCM24, + ST30_FMT_PCM24}; st30_rx_fps_test(type, s, pt, c, f, ST_TEST_LEVEL_MANDATORY, 5, true); } @@ -853,14 +825,14 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, struct st30_tx_ops ops_tx; struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level lower than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; ASSERT_TRUE(tx_sessions >= 1); bool tx_update_dst = (tx_sessions == 1); @@ -897,17 +869,17 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -918,8 +890,8 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, ops_tx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_tx.ptime = ST30_PTIME_1MS; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = st30_get_packet_size( - ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = + st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_audio_next_frame; ops_tx.notify_rtp_done = tx_rtp_done; @@ -963,8 +935,8 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, ops_rx.fmt = ST30_FMT_PCM24; ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ptime = ST30_PTIME_1MS; - ops_rx.framebuff_size = st30_get_packet_size( - ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = + st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -1012,8 +984,7 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1039,8 +1010,7 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1075,8 +1045,7 @@ static void st30_rx_update_src_test(enum st30_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1141,20 +1110,14 @@ static int st30_rx_meta_frame_ready(void *priv, void *frame, auto ctx = (tests_context *)priv; auto expect_meta = (struct st30_rx_frame_meta *)ctx->priv; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; ctx->fb_rec++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); - if (expect_meta->sampling != meta->sampling) - ctx->rx_meta_fail_cnt++; - if (expect_meta->channel != meta->channel) - ctx->rx_meta_fail_cnt++; - if (expect_meta->fmt != meta->fmt) - ctx->rx_meta_fail_cnt++; - if (expect_meta->timestamp == meta->timestamp) - ctx->rx_meta_fail_cnt++; + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); + if (expect_meta->sampling != meta->sampling) ctx->rx_meta_fail_cnt++; + if (expect_meta->channel != meta->channel) ctx->rx_meta_fail_cnt++; + if (expect_meta->fmt != meta->fmt) ctx->rx_meta_fail_cnt++; + if (expect_meta->timestamp == meta->timestamp) ctx->rx_meta_fail_cnt++; expect_meta->timestamp = meta->timestamp; st30_rx_put_framebuff((st30_rx_handle)ctx->handle, frame); @@ -1162,24 +1125,23 @@ static int st30_rx_meta_frame_ready(void *priv, void *frame, return 0; } -static void st30_rx_meta_test(enum st30_fmt fmt[], - enum st30_sampling sampling[], uint16_t channel[], - enum st_test_level level, int sessions = 1, - bool user_timestamp = false) { +static void st30_rx_meta_test(enum st30_fmt fmt[], enum st30_sampling sampling[], + uint16_t channel[], enum st_test_level level, + int sessions = 1, bool user_timestamp = false) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; struct st30_tx_ops ops_tx; struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level lower than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; std::vector test_ctx_tx; std::vector test_ctx_rx; @@ -1188,8 +1150,7 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], double expect_framerate = 1000.0; std::vector framerate; - if (user_timestamp) - expect_framerate /= 2; + if (user_timestamp) expect_framerate /= 2; test_ctx_tx.resize(sessions); test_ctx_rx.resize(sessions); @@ -1210,11 +1171,11 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -1225,8 +1186,8 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], ops_tx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_tx.ptime = ST30_PTIME_1MS; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = st30_get_packet_size( - ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = + st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); ; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; if (user_timestamp) { @@ -1274,8 +1235,8 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], ops_rx.fmt = fmt[i]; ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ptime = ST30_PTIME_1MS; - ops_rx.framebuff_size = st30_get_packet_size( - ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = + st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_meta_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -1287,8 +1248,8 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], test_ctx_rx[i]->stop = false; /* set expect meta data to private */ - auto meta = (struct st30_rx_frame_meta *)st_test_zmalloc( - sizeof(struct st30_rx_frame_meta)); + auto meta = + (struct st30_rx_frame_meta *)st_test_zmalloc(sizeof(struct st30_rx_frame_meta)); ASSERT_TRUE(meta != NULL); meta->channel = ops_rx.channel; meta->sampling = ops_rx.sampling; @@ -1304,8 +1265,7 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; /* stop all thread */ @@ -1322,9 +1282,9 @@ static void st30_rx_meta_test(enum st30_fmt fmt[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d fail %d framerate %f, fb send %d\n", - __func__, i, test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->rx_meta_fail_cnt, - framerate[i], test_ctx_tx[i]->fb_send); + info("%s, session %d fb_rec %d fail %d framerate %f, fb send %d\n", __func__, i, + test_ctx_rx[i]->fb_rec, test_ctx_rx[i]->rx_meta_fail_cnt, framerate[i], + test_ctx_tx[i]->fb_send); EXPECT_LE(test_ctx_rx[i]->rx_meta_fail_cnt, 2); EXPECT_NEAR(framerate[i], expect_framerate, expect_framerate * 0.1); ret = st30_tx_free(tx_handle[i]); @@ -1352,10 +1312,9 @@ TEST(St30_rx, frame_user_timestamp) { } static void st30_create_after_start_test(enum st30_type type[], - enum st30_sampling sample[], - uint16_t channel[], - enum st30_fmt fmt[], int sessions, - int repeat, enum st_test_level level) { + enum st30_sampling sample[], uint16_t channel[], + enum st30_fmt fmt[], int sessions, int repeat, + enum st_test_level level) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -1363,14 +1322,14 @@ static void st30_create_after_start_test(enum st30_type type[], struct st30_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level lower than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; std::vector test_ctx_tx; std::vector test_ctx_rx; @@ -1406,11 +1365,11 @@ static void st30_create_after_start_test(enum st30_type type[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -1421,8 +1380,8 @@ static void st30_create_after_start_test(enum st30_type type[], ops_tx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_tx.ptime = ST30_PTIME_1MS; ops_tx.pacing_way = ctx->tx_audio_pacing_way; - ops_tx.framebuff_size = st30_get_packet_size( - ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); + ops_tx.framebuff_size = + st30_get_packet_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel); ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; ops_tx.get_next_frame = tx_audio_next_frame; ops_tx.notify_rtp_done = tx_rtp_done; @@ -1452,11 +1411,11 @@ static void st30_create_after_start_test(enum st30_type type[], ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 20000 + i * 2; @@ -1466,8 +1425,8 @@ static void st30_create_after_start_test(enum st30_type type[], ops_rx.fmt = fmt[i]; ops_rx.payload_type = ST30_TEST_PAYLOAD_TYPE; ops_rx.ptime = ST30_PTIME_1MS; - ops_rx.framebuff_size = st30_get_packet_size( - ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); + ops_rx.framebuff_size = + st30_get_packet_size(ops_rx.fmt, ops_rx.ptime, ops_rx.sampling, ops_rx.channel); ops_rx.framebuff_cnt = test_ctx_rx[i]->fb_cnt; ops_rx.notify_frame_ready = st30_rx_frame_ready; ops_rx.notify_rtp_ready = rx_rtp_ready; @@ -1488,8 +1447,7 @@ static void st30_create_after_start_test(enum st30_type type[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST30_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -1509,8 +1467,8 @@ static void st30_create_after_start_test(enum st30_type type[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate, expect_framerate * 0.1); ret = st30_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); diff --git a/tests/src/st30p_test.cpp b/tests/src/st30p_test.cpp index 9c976e0ff..4d3a0c57a 100644 --- a/tests/src/st30p_test.cpp +++ b/tests/src/st30p_test.cpp @@ -20,8 +20,7 @@ static int test_st30p_tx_frame_available(void *priv) { static int test_st30p_tx_frame_done(void *priv, struct st30_frame *frame) { tests_context *s = (tests_context *)priv; - if (!s->handle) - return -EIO; /* not ready */ + if (!s->handle) return -EIO; /* not ready */ s->fb_send_done++; return 0; @@ -34,16 +33,15 @@ static int test_st30p_rx_frame_available(void *priv) { return 0; } -static void st30p_tx_ops_init(tests_context *st30, - struct st30p_tx_ops *ops_tx) { +static void st30p_tx_ops_init(tests_context *st30, struct st30p_tx_ops *ops_tx) { auto ctx = st30->ctx; memset(ops_tx, 0, sizeof(*ops_tx)); ops_tx->name = "st30p_test"; ops_tx->priv = st30; ops_tx->port.num_port = 1; - memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx->port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_tx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx->port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + st30->idx; @@ -53,9 +51,9 @@ static void st30p_tx_ops_init(tests_context *st30, ops_tx->sampling = ST30_SAMPLING_48K; ops_tx->ptime = ST30_PTIME_1MS; /* count frame size for 10ms */ - ops_tx->framebuff_size = st30_calculate_framebuff_size( - ops_tx->fmt, ops_tx->ptime, ops_tx->sampling, ops_tx->channel, - 10 * NS_PER_MS, NULL); + ops_tx->framebuff_size = + st30_calculate_framebuff_size(ops_tx->fmt, ops_tx->ptime, ops_tx->sampling, + ops_tx->channel, 10 * NS_PER_MS, NULL); ops_tx->framebuff_cnt = st30->fb_cnt; ops_tx->notify_frame_available = test_st30p_tx_frame_available; @@ -63,16 +61,15 @@ static void st30p_tx_ops_init(tests_context *st30, st30->frame_size = ops_tx->framebuff_size; } -static void st30p_rx_ops_init(tests_context *st30, - struct st30p_rx_ops *ops_rx) { +static void st30p_rx_ops_init(tests_context *st30, struct st30p_rx_ops *ops_rx) { auto ctx = st30->ctx; memset(ops_rx, 0, sizeof(*ops_rx)); ops_rx->name = "st30p_test"; ops_rx->priv = st30; ops_rx->port.num_port = 1; - memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx->port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx->port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx->port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + st30->idx; @@ -82,9 +79,9 @@ static void st30p_rx_ops_init(tests_context *st30, ops_rx->sampling = ST30_SAMPLING_48K; ops_rx->ptime = ST30_PTIME_1MS; /* count frame size */ - ops_rx->framebuff_size = st30_calculate_framebuff_size( - ops_rx->fmt, ops_rx->ptime, ops_rx->sampling, ops_rx->channel, - 10 * NS_PER_MS, NULL); + ops_rx->framebuff_size = + st30_calculate_framebuff_size(ops_rx->fmt, ops_rx->ptime, ops_rx->sampling, + ops_rx->channel, 10 * NS_PER_MS, NULL); ops_rx->framebuff_cnt = st30->fb_cnt; ops_rx->notify_frame_available = test_st30p_rx_frame_available; @@ -137,8 +134,12 @@ TEST(St30p, tx_create_free_max) { TEST(St30p, rx_create_free_max) { pipeline_create_free_max(st30p_rx, TEST_CREATE_FREE_MAX); } -TEST(St30p, tx_create_expect_fail) { pipeline_expect_fail_test(st30p_tx); } -TEST(St30p, rx_create_expect_fail) { pipeline_expect_fail_test(st30p_rx); } +TEST(St30p, tx_create_expect_fail) { + pipeline_expect_fail_test(st30p_tx); +} +TEST(St30p, rx_create_expect_fail) { + pipeline_expect_fail_test(st30p_rx); +} static void test_st30p_tx_frame_thread(void *args) { tests_context *s = (tests_context *)args; @@ -152,24 +153,17 @@ static void test_st30p_tx_frame_thread(void *args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) - s->cv.wait(lck); + if (!s->stop) s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->fmt != s->audio_fmt) - s->incomplete_frame_cnt++; - if (frame->channel != s->audio_channel) - s->incomplete_frame_cnt++; - if (frame->ptime != s->audio_ptime) - s->incomplete_frame_cnt++; - if (frame->sampling != s->audio_sampling) - s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->fmt != s->audio_fmt) s->incomplete_frame_cnt++; + if (frame->channel != s->audio_channel) s->incomplete_frame_cnt++; + if (frame->ptime != s->audio_ptime) s->incomplete_frame_cnt++; + if (frame->sampling != s->audio_sampling) s->incomplete_frame_cnt++; if (s->user_timestamp) { frame->tfmt = ST10_TIMESTAMP_FMT_MEDIA_CLK; frame->timestamp = s->fb_send; @@ -200,29 +194,21 @@ static void test_st30p_rx_frame_thread(void *args) { if (!frame) { /* no frame */ if (!s->block_get) { lck.lock(); - if (!s->stop) - s->cv.wait(lck); + if (!s->stop) s->cv.wait(lck); lck.unlock(); } continue; } - if (frame->data_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->buffer_size != s->frame_size) - s->incomplete_frame_cnt++; - if (frame->fmt != s->audio_fmt) - s->incomplete_frame_cnt++; - if (frame->channel != s->audio_channel) - s->incomplete_frame_cnt++; - if (frame->ptime != s->audio_ptime) - s->incomplete_frame_cnt++; - if (frame->sampling != s->audio_sampling) - s->incomplete_frame_cnt++; + if (frame->data_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->buffer_size != s->frame_size) s->incomplete_frame_cnt++; + if (frame->fmt != s->audio_fmt) s->incomplete_frame_cnt++; + if (frame->channel != s->audio_channel) s->incomplete_frame_cnt++; + if (frame->ptime != s->audio_ptime) s->incomplete_frame_cnt++; + if (frame->sampling != s->audio_sampling) s->incomplete_frame_cnt++; dbg("%s(%d), timestamp %" PRIu64 "\n", __func__, s->idx, frame->timestamp); - if (frame->timestamp == timestamp) - s->incomplete_frame_cnt++; + if (frame->timestamp == timestamp) s->incomplete_frame_cnt++; timestamp = frame->timestamp; /* check user timestamp if it has */ @@ -234,8 +220,8 @@ static void test_st30p_rx_frame_thread(void *args) { */ if (((uint32_t)frame->timestamp - s->pre_timestamp) > 4) { s->incomplete_frame_cnt++; - err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", - __func__, s->idx, frame->timestamp, s->pre_timestamp); + err("%s(%d), frame user timestamp %" PRIu64 " pre_timestamp %u\n", __func__, + s->idx, frame->timestamp, s->pre_timestamp); } } s->pre_timestamp = (uint32_t)frame->timestamp; @@ -246,8 +232,7 @@ static void test_st30p_rx_frame_thread(void *args) { int i = 0; for (i = 0; i < TEST_MAX_SHA_HIST_NUM; i++) { unsigned char *target_sha = s->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_MAX_SHA_HIST_NUM) { test_sha_dump("st30p_rx_error_sha", result); @@ -256,8 +241,7 @@ static void test_st30p_rx_frame_thread(void *args) { /* directly put */ st30p_rx_put_frame((st30p_rx_handle)handle, frame); s->fb_rec++; - if (!s->start_time) - s->start_time = st_test_get_monotonic_time(); + if (!s->start_time) s->start_time = st_test_get_monotonic_time(); } dbg("%s(%d), stop\n", __func__, s->idx); } @@ -273,8 +257,7 @@ struct st30p_rx_digest_test_para { bool zero_payload_type; }; -static void -test_st30p_init_rx_digest_para(struct st30p_rx_digest_test_para *para) { +static void test_st30p_init_rx_digest_para(struct st30p_rx_digest_test_para *para) { memset(para, 0, sizeof(*para)); para->sessions = 1; @@ -288,8 +271,7 @@ test_st30p_init_rx_digest_para(struct st30p_rx_digest_test_para *para) { } static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], - enum st30_sampling sampling[], - enum st30_ptime ptime[], + enum st30_sampling sampling[], enum st30_ptime ptime[], struct st30p_rx_digest_test_para *para) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto st = ctx->handle; @@ -299,14 +281,12 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], int sessions = para->sessions; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled, one for tx and one for rx\n", - __func__); + info("%s, dual port should be enabled, one for tx and one for rx\n", __func__); return; } /* return if level lower than global */ - if (para->level < ctx->level) - return; + if (para->level < ctx->level) return; std::vector test_ctx_tx; std::vector test_ctx_rx; @@ -349,33 +329,30 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], ops_tx.priv = test_ctx_tx[i]; ops_tx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.port.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + i * 2; - ops_tx.port.payload_type = - para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; + ops_tx.port.payload_type = para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; ops_tx.port.ssrc = para->ssrc; ops_tx.fmt = fmt[i]; ops_tx.channel = channel[i]; ops_tx.sampling = sampling[i]; ops_tx.ptime = ptime[i]; double fps; - ops_tx.framebuff_size = - st30_calculate_framebuff_size(ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, - ops_tx.channel, 10 * NS_PER_MS, &fps); + ops_tx.framebuff_size = st30_calculate_framebuff_size( + ops_tx.fmt, ops_tx.ptime, ops_tx.sampling, ops_tx.channel, 10 * NS_PER_MS, &fps); expect_framerate_tx[i] = fps; ops_tx.framebuff_cnt = test_ctx_tx[i]->fb_cnt; if (para->block_get) ops_tx.flags |= ST30P_TX_FLAG_BLOCK_GET; else ops_tx.notify_frame_available = test_st30p_tx_frame_available; - if (para->dedicated_tx_queue) - ops_tx.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; + if (para->dedicated_tx_queue) ops_tx.flags |= ST30P_TX_FLAG_DEDICATE_QUEUE; ops_tx.notify_frame_done = test_st30p_tx_frame_done; test_ctx_tx[i]->frame_size = ops_tx.framebuff_size; @@ -431,16 +408,15 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], ops_rx.priv = test_ctx_rx[i]; ops_rx.port.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.port.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.port.udp_port[MTL_SESSION_PORT_P] = ST30P_TEST_UDP_PORT + i * 2; - ops_rx.port.payload_type = - para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; + ops_rx.port.payload_type = para->zero_payload_type ? 0 : ST30P_TEST_PAYLOAD_TYPE; ops_rx.port.ssrc = para->ssrc; ops_rx.fmt = fmt[i]; ops_rx.channel = channel[i]; @@ -472,26 +448,22 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_tx[i]->start_time) / NS_PER_S; framerate_tx[i] = test_ctx_tx[i]->fb_send / time_sec; test_ctx_tx[i]->stop = true; - if (para->block_get) - st30p_tx_wake_block(tx_handle[i]); + if (para->block_get) st30p_tx_wake_block(tx_handle[i]); test_ctx_tx[i]->cv.notify_all(); tx_thread[i].join(); } for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate_rx[i] = test_ctx_rx[i]->fb_rec / time_sec; test_ctx_rx[i]->stop = true; - if (para->block_get) - st30p_rx_wake_block(rx_handle[i]); + if (para->block_get) st30p_rx_wake_block(rx_handle[i]); test_ctx_rx[i]->cv.notify_all(); rx_thread[i].join(); } @@ -520,16 +492,14 @@ static void st30p_rx_digest_test(enum st30_fmt fmt[], uint16_t channel[], } EXPECT_LE(test_ctx_rx[i]->user_meta_fail_cnt, 2); if (para->check_fps) { - EXPECT_NEAR(framerate_rx[i], expect_framerate_rx[i], - expect_framerate_rx[i] * 0.1); + EXPECT_NEAR(framerate_rx[i], expect_framerate_rx[i], expect_framerate_rx[i] * 0.1); } delete test_ctx_rx[i]; } } TEST(St30p, digest_s3) { - enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, - ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST30_SAMPLING_96K, ST30_SAMPLING_48K, ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST30_PTIME_1MS, ST30_PTIME_1MS, ST30_PTIME_125US}; uint16_t c[3] = {8, 2, 4}; enum st30_fmt f[3] = {ST30_FMT_PCM8, ST30_FMT_PCM16, ST30_FMT_PCM24}; @@ -546,8 +516,7 @@ TEST(St30p, digest_s3) { } TEST(St30p, digest_s3_block) { - enum st30_sampling s[3] = {ST31_SAMPLING_44K, ST30_SAMPLING_96K, - ST30_SAMPLING_48K}; + enum st30_sampling s[3] = {ST31_SAMPLING_44K, ST30_SAMPLING_96K, ST30_SAMPLING_48K}; enum st30_ptime pt[3] = {ST31_PTIME_1_09MS, ST30_PTIME_1MS, ST30_PTIME_125US}; uint16_t c[3] = {3, 5, 7}; enum st30_fmt f[3] = {ST31_FMT_AM824, ST30_FMT_PCM16, ST30_FMT_PCM24}; diff --git a/tests/src/st40_test.cpp b/tests/src/st40_test.cpp index 490d782f8..85f0b3994 100644 --- a/tests/src/st40_test.cpp +++ b/tests/src/st40_test.cpp @@ -18,24 +18,20 @@ static int tx_anc_next_frame_timestamp(void *priv, uint16_t *next_frame_idx, struct st40_tx_frame_meta *meta) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ meta->tfmt = ST10_TIMESTAMP_FMT_TAI; meta->timestamp = mtl_ptp_read_time(ctx->ctx->handle) + 40 * 1000 * 1000; *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } -static int tx_anc_build_rtp_packet(tests_context *s, - struct st40_rfc8331_rtp_hdr *rtp, +static int tx_anc_build_rtp_packet(tests_context *s, struct st40_rfc8331_rtp_hdr *rtp, uint16_t *pkt_len) { /* rtp hdr */ memset(rtp, 0x0, sizeof(*rtp)); @@ -66,30 +62,24 @@ static int tx_anc_build_rtp_packet(tests_context *s, payload_hdr->second_hdr_chunk.did = st40_add_parity_bits(0x43); payload_hdr->second_hdr_chunk.sdid = st40_add_parity_bits(0x02); payload_hdr->second_hdr_chunk.data_count = st40_add_parity_bits(udw_size); - payload_hdr->swaped_first_hdr_chunk = - htonl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = - htonl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = htonl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); rtp->anc_count = 1; for (int i = 0; i < udw_size; i++) { - st40_set_udw( - i + 3, - st40_add_parity_bits(s->frame_buf[s->seq_id % TEST_SHA_HIST_NUM][i]), - (uint8_t *)&payload_hdr->second_hdr_chunk); + st40_set_udw(i + 3, + st40_add_parity_bits(s->frame_buf[s->seq_id % TEST_SHA_HIST_NUM][i]), + (uint8_t *)&payload_hdr->second_hdr_chunk); } - uint16_t check_sum = st40_calc_checksum( - 3 + udw_size, (uint8_t *)&payload_hdr->second_hdr_chunk); - st40_set_udw(udw_size + 3, check_sum, - (uint8_t *)&payload_hdr->second_hdr_chunk); - total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = - (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + - total_size; // Full size of one ANC + uint16_t check_sum = + st40_calc_checksum(3 + udw_size, (uint8_t *)&payload_hdr->second_hdr_chunk); + st40_set_udw(udw_size + 3, check_sum, (uint8_t *)&payload_hdr->second_hdr_chunk); + total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = + sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC rtp->length = htons(payload_len); *pkt_len = payload_len + sizeof(struct st40_rfc8331_rtp_hdr); } else { @@ -114,16 +104,14 @@ static void tx_feed_packet(void *args) { if (mbuf) { lck.unlock(); } else { - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } } /* build the rtp pkt */ - tx_anc_build_rtp_packet(ctx, (struct st40_rfc8331_rtp_hdr *)usrptr, - &mbuf_len); + tx_anc_build_rtp_packet(ctx, (struct st40_rfc8331_rtp_hdr *)usrptr, &mbuf_len); st40_tx_put_mbuf((st40_tx_handle)ctx->handle, mbuf, mbuf_len); } } @@ -131,13 +119,11 @@ static void tx_feed_packet(void *args) { static int tx_rtp_done(void *args) { auto ctx = (tests_context *)args; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ std::unique_lock lck(ctx->mtx); ctx->cv.notify_all(); - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); ctx->fb_send++; return 0; } @@ -149,10 +135,8 @@ static void rx_handle_rtp(tests_context *s, struct st40_rfc8331_rtp_hdr *hdr) { int idx, total_size, payload_len; for (idx = 0; idx < anc_count; idx++) { - payload_hdr->swaped_first_hdr_chunk = - ntohl(payload_hdr->swaped_first_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = - ntohl(payload_hdr->swaped_second_hdr_chunk); + payload_hdr->swaped_first_hdr_chunk = ntohl(payload_hdr->swaped_first_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = ntohl(payload_hdr->swaped_second_hdr_chunk); if (!st40_check_parity_bits(payload_hdr->second_hdr_chunk.did) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.sdid) || !st40_check_parity_bits(payload_hdr->second_hdr_chunk.data_count)) { @@ -164,13 +148,10 @@ static void rx_handle_rtp(tests_context *s, struct st40_rfc8331_rtp_hdr *hdr) { // verify checksum uint16_t checksum = 0; - checksum = - st40_get_udw(udw_size + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); - payload_hdr->swaped_second_hdr_chunk = - htonl(payload_hdr->swaped_second_hdr_chunk); + checksum = st40_get_udw(udw_size + 3, (uint8_t *)&payload_hdr->second_hdr_chunk); + payload_hdr->swaped_second_hdr_chunk = htonl(payload_hdr->swaped_second_hdr_chunk); if (checksum != - st40_calc_checksum(3 + udw_size, - (uint8_t *)&payload_hdr->second_hdr_chunk)) { + st40_calc_checksum(3 + udw_size, (uint8_t *)&payload_hdr->second_hdr_chunk)) { s->sha_fail_cnt++; return; } @@ -192,17 +173,15 @@ static void rx_handle_rtp(tests_context *s, struct st40_rfc8331_rtp_hdr *hdr) { s->cv.notify_all(); } - total_size = - ((3 + udw_size + 1) * 10) / 8; // Calculate size of the - // 10-bit words: DID, SDID, DATA_COUNT - // + size of buffer with data + checksum - total_size = - (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit - // word of ANC data packet - payload_len = sizeof(struct st40_rfc8331_payload_hdr) - 4 + - total_size; // Full size of one ANC - payload_hdr = (struct st40_rfc8331_payload_hdr *)((uint8_t *)payload_hdr + - payload_len); + total_size = ((3 + udw_size + 1) * 10) / 8; // Calculate size of the + // 10-bit words: DID, SDID, DATA_COUNT + // + size of buffer with data + checksum + total_size = (4 - total_size % 4) + total_size; // Calculate word align to the 32-bit + // word of ANC data packet + payload_len = + sizeof(struct st40_rfc8331_payload_hdr) - 4 + total_size; // Full size of one ANC + payload_hdr = + (struct st40_rfc8331_payload_hdr *)((uint8_t *)payload_hdr + payload_len); } } @@ -212,13 +191,11 @@ static int rx_rtp_ready(void *priv) { void *mbuf; uint16_t len; - if (!ctx->handle) - return -EIO; + if (!ctx->handle) return -EIO; while (1) { mbuf = st40_rx_get_mbuf((st40_rx_handle)ctx->handle, &useptr, &len); - if (!mbuf) - break; /* no mbuf */ + if (!mbuf) break; /* no mbuf */ if (ctx->check_sha) { rx_handle_rtp(ctx, (struct st40_rfc8331_rtp_hdr *)useptr); } @@ -226,8 +203,7 @@ static int rx_rtp_ready(void *priv) { ctx->fb_rec++; } - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -239,8 +215,7 @@ static void st40_rx_ops_init(tests_context *st40, struct st40_rx_ops *ops) { ops->name = "st40_test"; ops->priv = st40; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; + if (ctx->same_dual_port) ops->num_port = 1; memcpy(ops->ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -265,8 +240,7 @@ static void st40_tx_ops_init(tests_context *st40, struct st40_tx_ops *ops) { ops->name = "st40_test"; ops->priv = st40; ops->num_port = ctx->para.num_ports; - if (ctx->same_dual_port) - ops->num_port = 1; + if (ctx->same_dual_port) ops->num_port = 1; memcpy(ops->dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); snprintf(ops->port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", @@ -311,13 +285,21 @@ static void st40_rx_assert_cnt(int expect_s40_rx_cnt) { EXPECT_EQ(var.st40_rx_sessions_cnt, expect_s40_rx_cnt); } -TEST(St40_tx, create_free_single) { create_free_test(st40_tx, 0, 1, 1); } -TEST(St40_tx, create_free_multi) { create_free_test(st40_tx, 0, 1, 6); } -TEST(St40_tx, create_free_mix) { create_free_test(st40_tx, 2, 3, 4); } +TEST(St40_tx, create_free_single) { + create_free_test(st40_tx, 0, 1, 1); +} +TEST(St40_tx, create_free_multi) { + create_free_test(st40_tx, 0, 1, 6); +} +TEST(St40_tx, create_free_mix) { + create_free_test(st40_tx, 2, 3, 4); +} TEST(St40_tx, create_free_max) { create_free_max(st40_tx, TEST_CREATE_FREE_MAX); } -TEST(St40_tx, create_expect_fail) { expect_fail_test(st40_tx); } +TEST(St40_tx, create_expect_fail) { + expect_fail_test(st40_tx); +} TEST(St40_tx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring(st40_tx, ST40_TYPE_RTP_LEVEL, ring_size); @@ -337,13 +319,21 @@ TEST(St40_tx, get_framebuffer_expect_fail) { expect_fail_test_get_framebuffer(st40_tx, fbcnt); } -TEST(St40_rx, create_free_single) { create_free_test(st40_rx, 0, 1, 1); } -TEST(St40_rx, create_free_multi) { create_free_test(st40_rx, 0, 1, 6); } -TEST(St40_rx, create_free_mix) { create_free_test(st40_rx, 2, 3, 4); } +TEST(St40_rx, create_free_single) { + create_free_test(st40_rx, 0, 1, 1); +} +TEST(St40_rx, create_free_multi) { + create_free_test(st40_rx, 0, 1, 6); +} +TEST(St40_rx, create_free_mix) { + create_free_test(st40_rx, 2, 3, 4); +} TEST(St40_rx, create_free_max) { create_free_max(st40_rx, TEST_CREATE_FREE_MAX); } -TEST(St40_rx, create_expect_fail) { expect_fail_test(st40_rx); } +TEST(St40_rx, create_expect_fail) { + expect_fail_test(st40_rx); +} TEST(St40_rx, create_expect_fail_ring_sz) { uint16_t ring_size = 0; expect_fail_test_rtp_ring_2(st40_rx, ring_size); @@ -354,8 +344,7 @@ TEST(St40_rx, create_expect_fail_ring_sz) { static void st40_tx_frame_init(tests_context *st40, st40_tx_handle handle, enum st40_type type) { size_t frame_size = 240; - if (st40->st40_empty_frame) - frame_size = 0; + if (st40->st40_empty_frame) frame_size = 0; st40->pkt_data_len = frame_size; st40->frame_size = frame_size; @@ -410,8 +399,7 @@ static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], std::vector rtp_thread; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; test_ctx.resize(sessions); handle.resize(sessions); @@ -451,8 +439,7 @@ static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx[i]->fb_send / time_sec; if (type[i] == ST40_TYPE_RTP_LEVEL) { test_ctx[i]->stop = true; @@ -469,8 +456,8 @@ static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx[i]->fb_send, 0); - info("%s, session %d fb_send %d framerate %f\n", __func__, i, - test_ctx[i]->fb_send, framerate[i]); + info("%s, session %d fb_send %d framerate %f\n", __func__, i, test_ctx[i]->fb_send, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st40_tx_free(handle[i]); EXPECT_GE(ret, 0); @@ -481,8 +468,7 @@ static void st40_tx_fps_test(enum st40_type type[], enum st_fps fps[], static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], enum st_test_level level, int sessions = 1, - bool check_sha = false, - bool user_timestamp = false, + bool check_sha = false, bool user_timestamp = false, bool empty_frame = false, bool interlaced = false, bool dedicate_tx_queue = false) { auto ctx = (struct st_tests_context *)st_test_ctx(); @@ -492,13 +478,13 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], struct st40_rx_ops ops_rx; /* return if level small than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -524,8 +510,7 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], test_ctx_tx[i] = new tests_context(); ASSERT_TRUE(test_ctx_tx[i] != NULL); expect_framerate[i] = st_frame_rate(fps[i]); - if (user_timestamp) - expect_framerate[i] /= 2; + if (user_timestamp) expect_framerate[i] /= 2; test_ctx_tx[i]->idx = i; test_ctx_tx[i]->ctx = ctx; @@ -537,11 +522,11 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -557,8 +542,7 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], } else { ops_tx.get_next_frame = tx_anc_next_frame; } - if (dedicate_tx_queue) - ops_tx.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; + if (dedicate_tx_queue) ops_tx.flags |= ST40_TX_FLAG_DEDICATE_QUEUE; ops_tx.rtp_ring_size = 1024; ops_tx.notify_rtp_done = tx_rtp_done; @@ -637,8 +621,7 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST40_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -667,8 +650,8 @@ static void st40_rx_fps_test(enum st40_type type[], enum st_fps fps[], EXPECT_GE(ret, 0); for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); EXPECT_LE(test_ctx_rx[i]->sha_fail_cnt, 2); EXPECT_LE(test_ctx_rx[i]->rx_meta_fail_cnt, 2); @@ -748,8 +731,8 @@ TEST(St40_rx, frame_fps29_97_fps59_94) { TEST(St40_rx, mix_s2) { enum st40_type type[2] = {ST40_TYPE_RTP_LEVEL, ST40_TYPE_FRAME_LEVEL}; enum st_fps fps[2] = {ST_FPS_P50, ST_FPS_P59_94}; - st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 2, true, false, false, - false, true); + st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 2, true, false, false, false, + true); } TEST(St40_rx, frame_fps50_fps59_94_digest) { enum st40_type type[2] = {ST40_TYPE_FRAME_LEVEL, ST40_TYPE_FRAME_LEVEL}; @@ -770,8 +753,7 @@ TEST(St40_rx, frame_interlaced_empty) { enum st40_type type[1] = {ST40_TYPE_FRAME_LEVEL}; enum st_fps fps[1] = {ST_FPS_P50}; /* no sha check */ - st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 1, false, false, true, - true); + st40_rx_fps_test(type, fps, ST_TEST_LEVEL_MANDATORY, 1, false, false, true, true); } static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, @@ -783,14 +765,14 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, struct st40_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } /* return if level lower than global */ - if (level < ctx->level) - return; + if (level < ctx->level) return; ASSERT_TRUE(tx_sessions >= 1); bool tx_update_dst = (tx_sessions == 1); @@ -829,17 +811,17 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (2 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); else if (1 == i) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_2], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_2], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -926,8 +908,7 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -953,8 +934,7 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -989,8 +969,7 @@ static void st40_rx_update_src_test(enum st40_type type, int tx_sessions, /* check rx fps */ for (int i = 0; i < rx_sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); @@ -1035,8 +1014,8 @@ TEST(St40_tx, update_dest_rtp) { st40_rx_update_src_test(ST40_TYPE_RTP_LEVEL, 1, ST_TEST_LEVEL_ALL); } -static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], - int sessions, int repeat) { +static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], int sessions, + int repeat) { auto ctx = (struct st_tests_context *)st_test_ctx(); auto m_handle = ctx->handle; int ret; @@ -1044,9 +1023,10 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], struct st40_rx_ops ops_rx; if (ctx->para.num_ports != 2) { - info("%s, dual port should be enabled for tx test, one for tx and one for " - "rx\n", - __func__); + info( + "%s, dual port should be enabled for tx test, one for tx and one for " + "rx\n", + __func__); return; } @@ -1084,11 +1064,11 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], ops_tx.priv = test_ctx_tx[i]; ops_tx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); + memcpy(ops_tx.dip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_R], + MTL_IP_ADDR_LEN); snprintf(ops_tx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_P]); ops_tx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -1126,11 +1106,11 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], ops_rx.priv = test_ctx_rx[i]; ops_rx.num_port = 1; if (ctx->mcast_only) - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->mcast_ip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->mcast_ip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); else - memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], - ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + memcpy(ops_rx.ip_addr[MTL_SESSION_PORT_P], ctx->para.sip_addr[MTL_PORT_P], + MTL_IP_ADDR_LEN); snprintf(ops_rx.port[MTL_SESSION_PORT_P], MTL_PORT_MAX_LEN, "%s", ctx->para.port[MTL_PORT_R]); ops_rx.udp_port[MTL_SESSION_PORT_P] = 30000 + i * 2; @@ -1147,8 +1127,7 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], for (int i = 0; i < sessions; i++) { uint64_t cur_time_ns = st_test_get_monotonic_time(); - double time_sec = - (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; + double time_sec = (double)(cur_time_ns - test_ctx_rx[i]->start_time) / NS_PER_S; framerate[i] = test_ctx_rx[i]->fb_rec / time_sec; if (type[i] == ST40_TYPE_RTP_LEVEL) { test_ctx_tx[i]->stop = true; @@ -1163,8 +1142,8 @@ static void st40_after_start_test(enum st40_type type[], enum st_fps fps[], /* check fps */ for (int i = 0; i < sessions; i++) { EXPECT_GT(test_ctx_rx[i]->fb_rec, 0); - info("%s, session %d fb_rec %d framerate %f\n", __func__, i, - test_ctx_rx[i]->fb_rec, framerate[i]); + info("%s, session %d fb_rec %d framerate %f\n", __func__, i, test_ctx_rx[i]->fb_rec, + framerate[i]); EXPECT_NEAR(framerate[i], expect_framerate[i], expect_framerate[i] * 0.1); ret = st40_tx_free(tx_handle[i]); EXPECT_GE(ret, 0); diff --git a/tests/src/st_test.cpp b/tests/src/st_test.cpp index ce657120b..0846f20d3 100644 --- a/tests/src/st_test.cpp +++ b/tests/src/st_test.cpp @@ -11,8 +11,7 @@ int st_test_sch_cnt(struct st_tests_context *ctx) { int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) - return ret; + if (ret < 0) return ret; return var.sch_cnt; } @@ -29,12 +28,10 @@ bool st_test_dma_available(struct st_tests_context *ctx) { } ret = mtl_get_var_info(handle, &var); - if (ret < 0) - return ret; + if (ret < 0) return ret; ret = mtl_get_fix_info(handle, &fix); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (var.dma_dev_cnt < fix.dma_dev_cnt_max) return true; @@ -55,18 +52,15 @@ static void init_expect_fail_test(void) { handle = mtl_init(¶); EXPECT_TRUE(handle == NULL); - memcpy(mtl_p_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(mtl_p_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); handle = mtl_init(¶); EXPECT_TRUE(handle == NULL); - snprintf(para.port[MTL_PORT_P], sizeof(para.port[MTL_PORT_P]), - "0000:55:00.0"); + snprintf(para.port[MTL_PORT_P], sizeof(para.port[MTL_PORT_P]), "0000:55:00.0"); handle = mtl_init(¶); EXPECT_TRUE(handle == NULL); - memcpy(mtl_r_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_R], - MTL_IP_ADDR_LEN); + memcpy(mtl_r_sip_addr(¶), ctx->para.sip_addr[MTL_PORT_R], MTL_IP_ADDR_LEN); /* test with 0 num_ports */ para.num_ports = 0; @@ -84,7 +78,9 @@ static void init_expect_fail_test(void) { EXPECT_TRUE(handle == NULL); } -TEST(Main, init_expect_fail) { init_expect_fail_test(); } +TEST(Main, init_expect_fail) { + init_expect_fail_test(); +} static void reinit_expect_fail_test(void) { struct st_tests_context *ctx = st_test_ctx(); @@ -94,7 +90,9 @@ static void reinit_expect_fail_test(void) { EXPECT_TRUE(handle == NULL); } -TEST(Main, re_init_fail) { reinit_expect_fail_test(); } +TEST(Main, re_init_fail) { + reinit_expect_fail_test(); +} static void start_stop_test(int repeat) { struct st_tests_context *ctx = st_test_ctx(); @@ -109,9 +107,13 @@ static void start_stop_test(int repeat) { } } -TEST(Main, start_stop_single) { start_stop_test(1); } +TEST(Main, start_stop_single) { + start_stop_test(1); +} -TEST(Main, start_stop_multi) { start_stop_test(5); } +TEST(Main, start_stop_multi) { + start_stop_test(5); +} static void start_expect_fail_test(void) { struct st_tests_context *ctx = st_test_ctx(); @@ -126,7 +128,9 @@ static void start_expect_fail_test(void) { EXPECT_GE(ret, 0); } -TEST(Main, start_expect_fail) { start_expect_fail_test(); } +TEST(Main, start_expect_fail) { + start_expect_fail_test(); +} static void stop_expect_fail_test(void) { struct st_tests_context *ctx = st_test_ctx(); @@ -145,7 +149,9 @@ static void stop_expect_fail_test(void) { EXPECT_GE(ret, 0); } -TEST(Main, stop_expect_fail) { stop_expect_fail_test(); } +TEST(Main, stop_expect_fail) { + stop_expect_fail_test(); +} TEST(Main, get_fix) { struct st_tests_context *ctx = st_test_ctx(); @@ -175,8 +181,7 @@ static int test_lcore_cnt(struct st_tests_context *ctx) { int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) - return ret; + if (ret < 0) return ret; return var.lcore_cnt; } @@ -210,13 +215,11 @@ TEST(Main, lcore_max) { for (i = 0; i < max; i++) { ret = mtl_get_lcore(handle, &lcore[i]); - if (ret < 0) - break; + if (ret < 0) break; } EXPECT_EQ(test_lcore_cnt(ctx), base_cnt + i); max = i; - for (i = 0; i < max; i++) - mtl_put_lcore(handle, lcore[i]); + for (i = 0; i < max; i++) mtl_put_lcore(handle, lcore[i]); EXPECT_EQ(test_lcore_cnt(ctx), base_cnt); test_lcore_one(ctx); @@ -237,8 +240,7 @@ static bool test_dev_started(struct st_tests_context *ctx) { int ret; ret = mtl_get_var_info(handle, &var); - if (ret < 0) - return false; + if (ret < 0) return false; return var.dev_started; } @@ -257,14 +259,14 @@ TEST(Main, dev_started) { TEST(Main, bandwidth) { uint64_t bandwidth_1080p_mps = st20_1080p59_yuv422_10bit_bandwidth_mps(); uint64_t bandwidth_1080p = 0; - int ret = st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, - ST_FPS_P59_94, false, &bandwidth_1080p); + int ret = st20_get_bandwidth_bps(1920, 1080, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, + false, &bandwidth_1080p); EXPECT_GE(ret, 0); EXPECT_EQ(bandwidth_1080p / 1000 / 1000, bandwidth_1080p_mps); uint64_t bandwidth_720p = 0; - ret = st20_get_bandwidth_bps(1280, 720, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, - false, &bandwidth_720p); + ret = st20_get_bandwidth_bps(1280, 720, ST20_FMT_YUV_422_10BIT, ST_FPS_P59_94, false, + &bandwidth_720p); EXPECT_GE(ret, 0); EXPECT_GT(bandwidth_1080p, bandwidth_720p); } @@ -279,7 +281,9 @@ static void st20_frame_size_test() { EXPECT_EQ(size, expect_size); } -TEST(Main, st20_frame_size) { st20_frame_size_test(); } +TEST(Main, st20_frame_size) { + st20_frame_size_test(); +} static void fmt_frame_equal_transport_test() { bool equal; @@ -287,27 +291,25 @@ static void fmt_frame_equal_transport_test() { equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422RFC4175PG2BE10, ST20_FMT_YUV_422_10BIT); EXPECT_TRUE(equal); - equal = - st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_8BIT); + equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_8BIT); EXPECT_TRUE(equal); equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_RGB8, ST20_FMT_RGB_8BIT); EXPECT_TRUE(equal); - equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR10LE, - ST20_FMT_YUV_422_10BIT); - EXPECT_FALSE(equal); equal = - st_frame_fmt_equal_transport(ST_FRAME_FMT_V210, ST20_FMT_YUV_422_10BIT); + st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR10LE, ST20_FMT_YUV_422_10BIT); EXPECT_FALSE(equal); - equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR8, - ST20_FMT_YUV_422_8BIT); + equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_V210, ST20_FMT_YUV_422_10BIT); EXPECT_FALSE(equal); - equal = - st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_12BIT); + equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_YUV422PLANAR8, ST20_FMT_YUV_422_8BIT); + EXPECT_FALSE(equal); + equal = st_frame_fmt_equal_transport(ST_FRAME_FMT_UYVY, ST20_FMT_YUV_422_12BIT); EXPECT_FALSE(equal); } -TEST(Main, fmt_equal_transport) { fmt_frame_equal_transport_test(); } +TEST(Main, fmt_equal_transport) { + fmt_frame_equal_transport_test(); +} static void fmt_frame_fom_transport_test() { enum st_frame_fmt to_fmt; @@ -319,12 +321,13 @@ static void fmt_frame_fom_transport_test() { to_fmt = st_frame_fmt_from_transport(ST20_FMT_RGB_8BIT); EXPECT_TRUE(to_fmt == ST_FRAME_FMT_RGB8); - to_fmt = - st_frame_fmt_from_transport(ST20_FMT_YUV_444_16BIT); /* not support now */ + to_fmt = st_frame_fmt_from_transport(ST20_FMT_YUV_444_16BIT); /* not support now */ EXPECT_TRUE(to_fmt == ST_FRAME_FMT_MAX); } -TEST(Main, fmt_frame_transport) { fmt_frame_fom_transport_test(); } +TEST(Main, fmt_frame_transport) { + fmt_frame_fom_transport_test(); +} static void fmt_frame_to_transport_test() { enum st20_fmt to_fmt; @@ -342,7 +345,9 @@ static void fmt_frame_to_transport_test() { EXPECT_TRUE(to_fmt == ST20_FMT_MAX); } -TEST(Main, fmt_to_transport) { fmt_frame_to_transport_test(); } +TEST(Main, fmt_to_transport) { + fmt_frame_to_transport_test(); +} static void frame_api_test() { uint32_t w = 1920; @@ -368,8 +373,7 @@ static void frame_api_test() { EXPECT_GT(st_frame_least_linesize(fmt, w, 0), szero); } /* codestream */ - for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; - i++) { + for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; i++) { fmt = (enum st_frame_fmt)i; size = st_frame_size(fmt, w, h, false); EXPECT_EQ(size, szero); @@ -409,8 +413,7 @@ static void frame_name_test() { EXPECT_EQ(st_frame_name_to_fmt(name), fmt); } /* codestream */ - for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; - i++) { + for (int i = ST_FRAME_FMT_CODESTREAM_START; i < ST_FRAME_FMT_CODESTREAM_END; i++) { fmt = (enum st_frame_fmt)i; name = st_frame_fmt_name(fmt); EXPECT_NE(strcmp(fail, name), 0); @@ -430,8 +433,12 @@ static void frame_name_test() { EXPECT_EQ(st_frame_name_to_fmt(fail), ST_FRAME_FMT_MAX); } -TEST(Main, frame_api) { frame_api_test(); } -TEST(Main, frame_name) { frame_name_test(); } +TEST(Main, frame_api) { + frame_api_test(); +} +TEST(Main, frame_name) { + frame_name_test(); +} static void size_page_align_test() { size_t pg_sz = 4096; @@ -463,10 +470,11 @@ static void size_page_align_test() { EXPECT_EQ(sz, expect_sz); } -TEST(Main, size_page_align) { size_page_align_test(); } +TEST(Main, size_page_align) { + size_page_align_test(); +} -class fps_23_98 - : public ::testing::TestWithParam> {}; +class fps_23_98 : public ::testing::TestWithParam> {}; TEST_P(fps_23_98, conv_fps_to_st_fps_23_98_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -481,8 +489,7 @@ PARAMETERIZED_TEST(Main, fps_23_98, std::make_tuple(ST_FPS_P23_98, 23.99), std::make_tuple(ST_FPS_P24, 24.00))); -class fps_24 - : public ::testing::TestWithParam> {}; +class fps_24 : public ::testing::TestWithParam> {}; TEST_P(fps_24, conv_fps_to_st_fps_24_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -495,8 +502,7 @@ PARAMETERIZED_TEST(Main, fps_24, std::make_tuple(ST_FPS_P24, 24.99), std::make_tuple(ST_FPS_P25, 25.00))); -class fps_25 - : public ::testing::TestWithParam> {}; +class fps_25 : public ::testing::TestWithParam> {}; TEST_P(fps_25, conv_fps_to_st_fps_25_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -508,8 +514,7 @@ PARAMETERIZED_TEST(Main, fps_25, std::make_tuple(ST_FPS_P25, 26.00), std::make_tuple(ST_FPS_MAX, 27.00))); -class fps_29_97 - : public ::testing::TestWithParam> {}; +class fps_29_97 : public ::testing::TestWithParam> {}; TEST_P(fps_29_97, conv_fps_to_st_fps_29_97_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -523,8 +528,7 @@ PARAMETERIZED_TEST(Main, fps_29_97, std::make_tuple(ST_FPS_P29_97, 29.99), std::make_tuple(ST_FPS_P30, 30.00))); -class fps_30 - : public ::testing::TestWithParam> {}; +class fps_30 : public ::testing::TestWithParam> {}; TEST_P(fps_30, conv_fps_to_st_fps_30_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -537,8 +541,7 @@ PARAMETERIZED_TEST(Main, fps_30, std::make_tuple(ST_FPS_MAX, 31.01), std::make_tuple(ST_FPS_MAX, 32.00))); -class fps_50 - : public ::testing::TestWithParam> {}; +class fps_50 : public ::testing::TestWithParam> {}; TEST_P(fps_50, conv_fps_to_st_fps_50_test) { enum st_fps expect = st_frame_rate_to_st_fps(std::get<1>(GetParam())); @@ -554,8 +557,7 @@ PARAMETERIZED_TEST(Main, fps_50, std::make_tuple(ST_FPS_P50, 51.00), std::make_tuple(ST_FPS_MAX, 52.00))); -class fps_59_94 - : public ::testing::TestWithParam> {}; +class fps_59_94 : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_59_94, ::testing::Values(std::make_tuple(ST_FPS_MAX, 58.93), @@ -569,8 +571,7 @@ TEST_P(fps_59_94, conv_fps_to_st_fps_50_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_60 - : public ::testing::TestWithParam> {}; +class fps_60 : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_60, ::testing::Values(std::make_tuple(ST_FPS_P60, 60.00), @@ -583,8 +584,7 @@ TEST_P(fps_60, conv_fps_to_st_fps_60_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_100 - : public ::testing::TestWithParam> {}; +class fps_100 : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_100, ::testing::Values(std::make_tuple(ST_FPS_MAX, 98.99), @@ -598,8 +598,7 @@ TEST_P(fps_100, conv_fps_to_st_fps_100_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_119_98 - : public ::testing::TestWithParam> {}; +class fps_119_98 : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_119_98, ::testing::Values(std::make_tuple(ST_FPS_MAX, 118.87), @@ -613,8 +612,7 @@ TEST_P(fps_119_98, conv_fps_to_st_fps_119_98_test) { EXPECT_EQ(expect, std::get<0>(GetParam())); } -class fps_120 - : public ::testing::TestWithParam> {}; +class fps_120 : public ::testing::TestWithParam> {}; PARAMETERIZED_TEST(Main, fps_120, ::testing::Values(std::make_tuple(ST_FPS_P120, 120.00), diff --git a/tests/src/test_platform.h b/tests/src/test_platform.h index 59c9baf67..12ad6aed5 100644 --- a/tests/src/test_platform.h +++ b/tests/src/test_platform.h @@ -61,8 +61,7 @@ static inline int st_pthread_cond_init(pthread_cond_t *cond, return pthread_cond_init(cond, cond_attr); } -static inline int st_pthread_cond_wait(pthread_cond_t *cond, - pthread_mutex_t *mutex) { +static inline int st_pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { return pthread_cond_wait(cond, mutex); } @@ -74,8 +73,8 @@ static inline int st_pthread_cond_signal(pthread_cond_t *cond) { return pthread_cond_signal(cond); } -static inline void -st_usleep(useconds_t usec) { // windows usleep function precision is only 1~15ms +static inline void st_usleep( + useconds_t usec) { // windows usleep function precision is only 1~15ms #ifdef WINDOWSENV LARGE_INTEGER delay; HANDLE delay_timer_handle = NULL; diff --git a/tests/src/test_util.cpp b/tests/src/test_util.cpp index 24e5ded05..be860a49b 100644 --- a/tests/src/test_util.cpp +++ b/tests/src/test_util.cpp @@ -18,8 +18,7 @@ void test_sha_dump(const char *tag, unsigned char *sha) { int st_test_check_patter(uint8_t *p, size_t sz, uint8_t base) { for (size_t i = 0; i < sz; i++) { if (p[i] != ((base + i) & 0xFF)) { - err("%s, fail data 0x%x on %" PRIu64 " base 0x%x\n", __func__, p[i], i, - base); + err("%s, fail data 0x%x on %" PRIu64 " base 0x%x\n", __func__, p[i], i, base); return -EIO; } } @@ -30,8 +29,7 @@ int st_test_check_patter(uint8_t *p, size_t sz, uint8_t base) { int st_test_cmp(uint8_t *s1, uint8_t *s2, size_t sz) { for (size_t i = 0; i < sz; i++) { if (s1[i] != s2[i]) { - err("%s, mismatch on %" PRIu64 ", 0x%x 0x%x\n", __func__, i, s1[i], - s2[i]); + err("%s, mismatch on %" PRIu64 ", 0x%x 0x%x\n", __func__, i, s1[i], s2[i]); return -EIO; } } diff --git a/tests/src/test_util.h b/tests/src/test_util.h index 845332fb1..d4849e392 100644 --- a/tests/src/test_util.h +++ b/tests/src/test_util.h @@ -38,12 +38,13 @@ enum st_test_level { static inline void *st_test_zmalloc(size_t sz) { void *p = malloc(sz); - if (p) - memset(p, 0x0, sz); + if (p) memset(p, 0x0, sz); return p; } -static inline void st_test_free(void *p) { free(p); } +static inline void st_test_free(void *p) { + free(p); +} static inline void st_test_rand_data(uint8_t *p, size_t sz, uint8_t base) { for (size_t i = 0; i < sz; i++) { @@ -62,8 +63,7 @@ static inline void st_test_rand_v210(uint8_t *p, size_t sz, uint8_t base) { #else p[i] = rand(); #endif - if ((i % 4) == 3) - p[i] &= 0x3F; + if ((i % 4) == 3) p[i] &= 0x3F; } } diff --git a/tests/src/tests.cpp b/tests/src/tests.cpp index 419e0ad60..1105a2c1a 100644 --- a/tests/src/tests.cpp +++ b/tests/src/tests.cpp @@ -95,8 +95,7 @@ struct st_tests_context *st_test_ctx(void) { } static int test_args_dma_dev(struct mtl_init_params *p, const char *in_dev) { - if (!in_dev) - return -EIO; + if (!in_dev) return -EIO; char devs[128] = {0}; snprintf(devs, 128 - 1, "%s", in_dev); @@ -104,192 +103,189 @@ static int test_args_dma_dev(struct mtl_init_params *p, const char *in_dev) { char *next_dev = strtok(devs, ","); while (next_dev && (p->num_dma_dev_port < MTL_DMA_DEV_MAX)) { dbg("next_dev: %s\n", next_dev); - snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", - next_dev); + snprintf(p->dma_dev_port[p->num_dma_dev_port], MTL_PORT_MAX_LEN - 1, "%s", next_dev); p->num_dma_dev_port++; next_dev = strtok(NULL, ","); } return 0; } -static int test_parse_args(struct st_tests_context *ctx, - struct mtl_init_params *p, int argc, char **argv) { +static int test_parse_args(struct st_tests_context *ctx, struct mtl_init_params *p, + int argc, char **argv) { int cmd = -1, opt_idx = 0; int nb; while (1) { cmd = getopt_long_only(argc, argv, "hv", test_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case TEST_ARG_P_PORT: - snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); - p->num_ports++; - break; - case TEST_ARG_R_PORT: - snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); - p->num_ports++; - break; - case TEST_ARG_LCORES: - p->lcores = optarg; - break; - case TEST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ - nb = atoi(optarg); - if (nb > 0 && nb < 100) { - p->data_quota_mbs_per_sch = - nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); + case TEST_ARG_P_PORT: + snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); + p->num_ports++; + break; + case TEST_ARG_R_PORT: + snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); + p->num_ports++; + break; + case TEST_ARG_LCORES: + p->lcores = optarg; + break; + case TEST_ARG_SCH_SESSION_QUOTA: /* unit: 1080p tx */ + nb = atoi(optarg); + if (nb > 0 && nb < 100) { + p->data_quota_mbs_per_sch = nb * st20_1080p59_yuv422_10bit_bandwidth_mps(); + } + break; + case TEST_ARG_DMA_DEV: + test_args_dma_dev(p, optarg); + break; + case TEST_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case TEST_ARG_CNI_THREAD: + p->flags |= MTL_FLAG_CNI_THREAD; + break; + case TEST_ARG_RX_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + break; + case TEST_ARG_TX_MONO_POOL: + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case TEST_ARG_MONO_POOL: + p->flags |= MTL_FLAG_RX_MONO_POOL; + p->flags |= MTL_FLAG_TX_MONO_POOL; + break; + case TEST_ARG_RX_SEPARATE_VIDEO_LCORE: + p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; + break; + case TEST_ARG_MIGRATE_ENABLE: + p->flags |= MTL_FLAG_RX_VIDEO_MIGRATE; + p->flags |= MTL_FLAG_TX_VIDEO_MIGRATE; + break; + case TEST_ARG_MIGRATE_DISABLE: + p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; + p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; + break; + case TEST_ARG_LIB_PTP: + p->flags |= MTL_FLAG_PTP_ENABLE; + p->ptp_get_time_fn = NULL; /* clear the user ptp func */ + break; + case TEST_ARG_NB_TX_DESC: + p->nb_tx_desc = atoi(optarg); + break; + case TEST_ARG_NB_RX_DESC: + p->nb_rx_desc = atoi(optarg); + break; + case TEST_ARG_LEVEL: + if (!strcmp(optarg, "all")) + ctx->level = ST_TEST_LEVEL_ALL; + else if (!strcmp(optarg, "mandatory")) + ctx->level = ST_TEST_LEVEL_MANDATORY; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case TEST_ARG_AUTO_START_STOP: + p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; + break; + case TEST_ARG_AF_XDP_ZC_DISABLE: + p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; + break; + case TEST_ARG_QUEUE_CNT: { + uint16_t cnt = atoi(optarg); + p->tx_queues_cnt[MTL_PORT_P] = cnt; + p->tx_queues_cnt[MTL_PORT_R] = cnt; + p->rx_queues_cnt[MTL_PORT_P] = cnt; + p->rx_queues_cnt[MTL_PORT_R] = cnt; + break; } - break; - case TEST_ARG_DMA_DEV: - test_args_dma_dev(p, optarg); - break; - case TEST_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case TEST_ARG_CNI_THREAD: - p->flags |= MTL_FLAG_CNI_THREAD; - break; - case TEST_ARG_RX_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - break; - case TEST_ARG_TX_MONO_POOL: - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case TEST_ARG_MONO_POOL: - p->flags |= MTL_FLAG_RX_MONO_POOL; - p->flags |= MTL_FLAG_TX_MONO_POOL; - break; - case TEST_ARG_RX_SEPARATE_VIDEO_LCORE: - p->flags |= MTL_FLAG_RX_SEPARATE_VIDEO_LCORE; - break; - case TEST_ARG_MIGRATE_ENABLE: - p->flags |= MTL_FLAG_RX_VIDEO_MIGRATE; - p->flags |= MTL_FLAG_TX_VIDEO_MIGRATE; - break; - case TEST_ARG_MIGRATE_DISABLE: - p->flags &= ~MTL_FLAG_RX_VIDEO_MIGRATE; - p->flags &= ~MTL_FLAG_TX_VIDEO_MIGRATE; - break; - case TEST_ARG_LIB_PTP: - p->flags |= MTL_FLAG_PTP_ENABLE; - p->ptp_get_time_fn = NULL; /* clear the user ptp func */ - break; - case TEST_ARG_NB_TX_DESC: - p->nb_tx_desc = atoi(optarg); - break; - case TEST_ARG_NB_RX_DESC: - p->nb_rx_desc = atoi(optarg); - break; - case TEST_ARG_LEVEL: - if (!strcmp(optarg, "all")) - ctx->level = ST_TEST_LEVEL_ALL; - else if (!strcmp(optarg, "mandatory")) - ctx->level = ST_TEST_LEVEL_MANDATORY; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case TEST_ARG_AUTO_START_STOP: - p->flags |= MTL_FLAG_DEV_AUTO_START_STOP; - break; - case TEST_ARG_AF_XDP_ZC_DISABLE: - p->flags |= MTL_FLAG_AF_XDP_ZC_DISABLE; - break; - case TEST_ARG_QUEUE_CNT: { - uint16_t cnt = atoi(optarg); - p->tx_queues_cnt[MTL_PORT_P] = cnt; - p->tx_queues_cnt[MTL_PORT_R] = cnt; - p->rx_queues_cnt[MTL_PORT_P] = cnt; - p->rx_queues_cnt[MTL_PORT_R] = cnt; - break; - } - case TEST_ARG_HDR_SPLIT: - ctx->hdr_split = true; - break; - case TEST_ARG_TASKLET_THREAD: - p->flags |= MTL_FLAG_TASKLET_THREAD; - break; - case TEST_ARG_TSC_PACING: - p->pacing = ST21_TX_PACING_WAY_TSC; - break; - case TEST_ARG_RXTX_SIMD_512: - p->flags |= MTL_FLAG_RXTX_SIMD_512; - break; - case TEST_ARG_PACING_WAY: - if (!strcmp(optarg, "auto")) - p->pacing = ST21_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - p->pacing = ST21_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsn")) - p->pacing = ST21_TX_PACING_WAY_TSN; - else if (!strcmp(optarg, "tsc")) + case TEST_ARG_HDR_SPLIT: + ctx->hdr_split = true; + break; + case TEST_ARG_TASKLET_THREAD: + p->flags |= MTL_FLAG_TASKLET_THREAD; + break; + case TEST_ARG_TSC_PACING: p->pacing = ST21_TX_PACING_WAY_TSC; - else if (!strcmp(optarg, "ptp")) - p->pacing = ST21_TX_PACING_WAY_PTP; - else if (!strcmp(optarg, "be")) - p->pacing = ST21_TX_PACING_WAY_BE; - else - err("%s, unknow pacing way %s\n", __func__, optarg); - break; - case TEST_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case TEST_ARG_TX_NO_CHAIN: - p->flags |= MTL_FLAG_TX_NO_CHAIN; - break; - case TEST_ARG_IOVA_MODE: - if (!strcmp(optarg, "va")) - p->iova_mode = MTL_IOVA_MODE_VA; - else if (!strcmp(optarg, "pa")) - p->iova_mode = MTL_IOVA_MODE_PA; - else - err("%s, unknow iova mode %s\n", __func__, optarg); - break; - case TEST_ARG_MULTI_SRC_PORT: - p->flags |= MTL_FLAG_MULTI_SRC_PORT; - break; - case TEST_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; ++port) - p->net_proto[port] = MTL_PROTO_DHCP; - ctx->dhcp = true; - break; - case TEST_ARG_MCAST_ONLY: - ctx->mcast_only = true; - break; - case TEST_ARG_ALLOW_ACROSS_NUMA_CORE: - p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; - break; - case TEST_ARG_AUDIO_TX_PACING: - if (!strcmp(optarg, "auto")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; - else if (!strcmp(optarg, "rl")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; - else if (!strcmp(optarg, "tsc")) - ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; - else - err("%s, unknow audio tx pacing %s\n", __func__, optarg); - break; - default: - break; + break; + case TEST_ARG_RXTX_SIMD_512: + p->flags |= MTL_FLAG_RXTX_SIMD_512; + break; + case TEST_ARG_PACING_WAY: + if (!strcmp(optarg, "auto")) + p->pacing = ST21_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + p->pacing = ST21_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsn")) + p->pacing = ST21_TX_PACING_WAY_TSN; + else if (!strcmp(optarg, "tsc")) + p->pacing = ST21_TX_PACING_WAY_TSC; + else if (!strcmp(optarg, "ptp")) + p->pacing = ST21_TX_PACING_WAY_PTP; + else if (!strcmp(optarg, "be")) + p->pacing = ST21_TX_PACING_WAY_BE; + else + err("%s, unknow pacing way %s\n", __func__, optarg); + break; + case TEST_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case TEST_ARG_TX_NO_CHAIN: + p->flags |= MTL_FLAG_TX_NO_CHAIN; + break; + case TEST_ARG_IOVA_MODE: + if (!strcmp(optarg, "va")) + p->iova_mode = MTL_IOVA_MODE_VA; + else if (!strcmp(optarg, "pa")) + p->iova_mode = MTL_IOVA_MODE_PA; + else + err("%s, unknow iova mode %s\n", __func__, optarg); + break; + case TEST_ARG_MULTI_SRC_PORT: + p->flags |= MTL_FLAG_MULTI_SRC_PORT; + break; + case TEST_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; ++port) + p->net_proto[port] = MTL_PROTO_DHCP; + ctx->dhcp = true; + break; + case TEST_ARG_MCAST_ONLY: + ctx->mcast_only = true; + break; + case TEST_ARG_ALLOW_ACROSS_NUMA_CORE: + p->flags |= MTL_FLAG_ALLOW_ACROSS_NUMA_CORE; + break; + case TEST_ARG_AUDIO_TX_PACING: + if (!strcmp(optarg, "auto")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_AUTO; + else if (!strcmp(optarg, "rl")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_RL; + else if (!strcmp(optarg, "tsc")) + ctx->tx_audio_pacing_way = ST30_TX_PACING_WAY_TSC; + else + err("%s, unknow audio tx pacing %s\n", __func__, optarg); + break; + default: + break; } }; @@ -393,14 +389,11 @@ static void test_ctx_init(struct st_tests_context *ctx) { int cpus_add = 0; for (int cpu = 0; cpu < max_cpus; cpu++) { if (numa_node_of_cpu(cpu) == numa) { - int n = snprintf(lcores_list + pos, TEST_LCORE_LIST_MAX_LEN - pos, - ",%d", cpu); - if (n < 0 || n >= (TEST_LCORE_LIST_MAX_LEN - pos)) - break; + int n = snprintf(lcores_list + pos, TEST_LCORE_LIST_MAX_LEN - pos, ",%d", cpu); + if (n < 0 || n >= (TEST_LCORE_LIST_MAX_LEN - pos)) break; pos += n; cpus_add++; - if (cpus_add >= cpus_per_soc) - break; + if (cpus_add >= cpus_per_soc) break; } } } @@ -425,14 +418,14 @@ TEST(Misc, version) { } TEST(Misc, version_compare) { - auto version_next = MTL_VERSION_NUM(MTL_VERSION_MAJOR + 1, MTL_VERSION_MINOR, - MTL_VERSION_LAST); + auto version_next = + MTL_VERSION_NUM(MTL_VERSION_MAJOR + 1, MTL_VERSION_MINOR, MTL_VERSION_LAST); EXPECT_LT(MTL_VERSION, version_next); - version_next = MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR + 1, - MTL_VERSION_LAST); + version_next = + MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR + 1, MTL_VERSION_LAST); EXPECT_LT(MTL_VERSION, version_next); - version_next = MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR, - MTL_VERSION_LAST + 1); + version_next = + MTL_VERSION_NUM(MTL_VERSION_MAJOR, MTL_VERSION_MINOR, MTL_VERSION_LAST + 1); EXPECT_LT(MTL_VERSION, version_next); } @@ -441,8 +434,7 @@ static void mtl_memcpy_test(size_t size) { char *src = new char[size]; char *dst = new char[size]; - for (size_t i = 0; i < size; i++) - src[i] = i; + for (size_t i = 0; i < size; i++) src[i] = i; memset(dst, 0, size); mtl_memcpy(dst, src, size); @@ -458,8 +450,8 @@ TEST(Misc, memcpy) { mtl_memcpy_test(4096 + 100); } -static void hp_malloc_test(struct st_tests_context *ctx, size_t size, - enum mtl_port port, bool zero, bool expect_succ) { +static void hp_malloc_test(struct st_tests_context *ctx, size_t size, enum mtl_port port, + bool zero, bool expect_succ) { auto m_handle = ctx->handle; void *p; @@ -483,8 +475,7 @@ static void hp_malloc_test(struct st_tests_context *ctx, size_t size, } } -static void hp_malloc_tests(struct st_tests_context *ctx, enum mtl_port port, - bool zero) { +static void hp_malloc_tests(struct st_tests_context *ctx, enum mtl_port port, bool zero) { hp_malloc_test(ctx, 1, port, zero, true); hp_malloc_test(ctx, 1024, port, zero, true); hp_malloc_test(ctx, 1024 + 3, port, zero, true); @@ -495,8 +486,7 @@ TEST(Misc, hp_malloc) { int num_port = st_test_num_port(ctx); hp_malloc_tests(ctx, MTL_PORT_P, false); - if (num_port > 1) - hp_malloc_tests(ctx, MTL_PORT_R, false); + if (num_port > 1) hp_malloc_tests(ctx, MTL_PORT_R, false); } TEST(Misc, hp_zmalloc) { @@ -504,8 +494,7 @@ TEST(Misc, hp_zmalloc) { int num_port = st_test_num_port(ctx); hp_malloc_tests(ctx, MTL_PORT_P, true); - if (num_port > 1) - hp_malloc_tests(ctx, MTL_PORT_R, true); + if (num_port > 1) hp_malloc_tests(ctx, MTL_PORT_R, true); } TEST(Misc, hp_malloc_expect_fail) { @@ -513,8 +502,7 @@ TEST(Misc, hp_malloc_expect_fail) { int num_port = st_test_num_port(ctx); hp_malloc_test(ctx, 0, MTL_PORT_P, false, false); - if (num_port > 1) - hp_malloc_test(ctx, 0, MTL_PORT_R, false, false); + if (num_port > 1) hp_malloc_test(ctx, 0, MTL_PORT_R, false, false); } TEST(Misc, hp_zmalloc_expect_fail) { @@ -522,8 +510,7 @@ TEST(Misc, hp_zmalloc_expect_fail) { int num_port = st_test_num_port(ctx); hp_malloc_test(ctx, 0, MTL_PORT_P, true, false); - if (num_port > 1) - hp_malloc_test(ctx, 0, MTL_PORT_R, true, false); + if (num_port > 1) hp_malloc_test(ctx, 0, MTL_PORT_R, true, false); } TEST(Misc, ptp) { @@ -646,8 +633,8 @@ GTEST_API_ int main(int argc, char **argv) { mtl_port_ip_info(ctx->handle, (enum mtl_port)i, ctx->para.sip_addr[i], ctx->para.netmask[i], ctx->para.gateway[i]); uint8_t *ip = ctx->para.sip_addr[i]; - info("%s, if ip %u.%u.%u.%u for port %s\n", __func__, ip[0], ip[1], ip[2], - ip[3], ctx->para.port[i]); + info("%s, if ip %u.%u.%u.%u for port %s\n", __func__, ip[0], ip[1], ip[2], ip[3], + ctx->para.port[i]); } if (ctx->para.num_ports > 1) { @@ -672,8 +659,7 @@ GTEST_API_ int main(int argc, char **argv) { int time_least = 10; if (link_flap_wa && (time_s < time_least)) { /* wa for linkFlapErrDisabled in the hub */ - info("%s, sleep %ds before disable the port\n", __func__, - time_least - time_s); + info("%s, sleep %ds before disable the port\n", __func__, time_least - time_s); sleep(time_least - time_s); } @@ -687,17 +673,14 @@ GTEST_API_ int main(int argc, char **argv) { int tx_next_frame(void *priv, uint16_t *next_frame_idx) { auto ctx = (tests_context *)priv; - if (!ctx->handle) - return -EIO; /* not ready */ + if (!ctx->handle) return -EIO; /* not ready */ *next_frame_idx = ctx->fb_idx; dbg("%s, next_frame_idx %d\n", __func__, *next_frame_idx); ctx->fb_idx++; - if (ctx->fb_idx >= ctx->fb_cnt) - ctx->fb_idx = 0; + if (ctx->fb_idx >= ctx->fb_cnt) ctx->fb_idx = 0; ctx->fb_send++; - if (!ctx->start_time) - ctx->start_time = st_test_get_monotonic_time(); + if (!ctx->start_time) ctx->start_time = st_test_get_monotonic_time(); return 0; } @@ -708,8 +691,7 @@ void sha_frame_check(void *args) { while (!ctx->stop) { if (ctx->buf_q.empty()) { lck.lock(); - if (!ctx->stop) - ctx->cv.wait(lck); + if (!ctx->stop) ctx->cv.wait(lck); lck.unlock(); continue; } else { @@ -720,8 +702,7 @@ void sha_frame_check(void *args) { SHA256((unsigned char *)frame, ctx->frame_size, result); for (i = 0; i < TEST_SHA_HIST_NUM; i++) { unsigned char *target_sha = ctx->shas[i]; - if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) - break; + if (!memcmp(result, target_sha, SHA256_DIGEST_LENGTH)) break; } if (i >= TEST_SHA_HIST_NUM) { test_sha_dump("rx_error_sha", result); @@ -735,8 +716,7 @@ void sha_frame_check(void *args) { int tests_context_unit(tests_context *ctx) { for (int frame = 0; frame < TEST_SHA_HIST_NUM; frame++) { - if (ctx->frame_buf[frame]) - st_test_free(ctx->frame_buf[frame]); + if (ctx->frame_buf[frame]) st_test_free(ctx->frame_buf[frame]); ctx->frame_buf[frame] = NULL; } if (ctx->ooo_mapping) { @@ -763,12 +743,11 @@ int test_ctx_notify_event(void *priv, enum st_event event, void *args) { if (event == ST_EVENT_VSYNC) { tests_context *s = (tests_context *)priv; s->vsync_cnt++; - if (!s->first_vsync_time) - s->first_vsync_time = st_test_get_monotonic_time(); + if (!s->first_vsync_time) s->first_vsync_time = st_test_get_monotonic_time(); #ifdef DEBUG struct st10_vsync_meta *meta = (struct st10_vsync_meta *)args; - dbg("%s(%d,%p), epoch %" PRIu64 " vsync_cnt %d\n", __func__, s->idx, s, - meta->epoch, s->vsync_cnt); + dbg("%s(%d,%p), epoch %" PRIu64 " vsync_cnt %d\n", __func__, s->idx, s, meta->epoch, + s->vsync_cnt); #endif } return 0; diff --git a/tests/src/tests.h b/tests/src/tests.h index b249acf3b..bef5c7d04 100644 --- a/tests/src/tests.h +++ b/tests/src/tests.h @@ -113,8 +113,7 @@ struct st_tests_context { st20_converter_dev_handle converter_dev_handle; struct test_st22_encoder_session *encoder_sessions[MAX_TEST_ENCODER_SESSIONS]; struct test_st22_decoder_session *decoder_sessions[MAX_TEST_DECODER_SESSIONS]; - struct test_converter_session - *converter_sessions[MAX_TEST_CONVERTER_SESSIONS]; + struct test_converter_session *converter_sessions[MAX_TEST_CONVERTER_SESSIONS]; bool encoder_use_block_get; bool decoder_use_block_get; int plugin_fail_interval; @@ -129,8 +128,7 @@ static inline int st_test_num_port(struct st_tests_context *ctx) { return ctx->para.num_ports; } -static inline void st_test_jxs_fail_interval(struct st_tests_context *ctx, - int interval) { +static inline void st_test_jxs_fail_interval(struct st_tests_context *ctx, int interval) { ctx->plugin_fail_interval = interval; } @@ -139,18 +137,15 @@ static inline void st_test_jxs_timeout_interval(struct st_tests_context *ctx, ctx->plugin_timeout_interval = interval; } -static inline void st_test_jxs_timeout_ms(struct st_tests_context *ctx, - int ms) { +static inline void st_test_jxs_timeout_ms(struct st_tests_context *ctx, int ms) { ctx->plugin_timeout_ms = ms; } -static inline void st_test_jxs_rand_ratio(struct st_tests_context *ctx, - int rand_ratio) { +static inline void st_test_jxs_rand_ratio(struct st_tests_context *ctx, int rand_ratio) { ctx->plugin_rand_ratio = rand_ratio; } -static inline void st_test_jxs_use_block_get(struct st_tests_context *ctx, - bool block) { +static inline void st_test_jxs_use_block_get(struct st_tests_context *ctx, bool block) { ctx->decoder_use_block_get = block; ctx->encoder_use_block_get = block; } @@ -170,7 +165,7 @@ int st_test_convert_plugin_unregister(struct st_tests_context *ctx); void sha_frame_check(void *args); class tests_context { -public: + public: struct st_tests_context *ctx = NULL; int idx = 0; int fb_cnt = 0; @@ -274,477 +269,475 @@ int tx_next_frame(void *priv, uint16_t *next_frame_idx); #define TEST_CREATE_FREE_MAX (16) -#define create_free_max(A, max) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - auto act = 0; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - auto sch_cnt = st_test_sch_cnt(ctx); \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle[max]; \ - for (int i = 0; i < max; i++) { \ - handle[i] = A##_create(m_handle, &ops); \ - if (!handle[i]) \ - break; \ - ops.udp_port[MTL_SESSION_PORT_P]++; \ - ops.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - st_usleep(100 * 1000); \ - } \ - info("%s, max session cnt %d\n", __func__, expect_cnt); \ - act = expect_cnt; \ - for (int i = 0; i < act; i++) { \ - ret = A##_free(handle[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - st_usleep(100 * 1000); \ - } \ - \ - A##_assert_cnt(0); \ - EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ - \ - delete test_ctx; \ +#define create_free_max(A, max) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + auto act = 0; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + auto sch_cnt = st_test_sch_cnt(ctx); \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle[max]; \ + for (int i = 0; i < max; i++) { \ + handle[i] = A##_create(m_handle, &ops); \ + if (!handle[i]) break; \ + ops.udp_port[MTL_SESSION_PORT_P]++; \ + ops.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + st_usleep(100 * 1000); \ + } \ + info("%s, max session cnt %d\n", __func__, expect_cnt); \ + act = expect_cnt; \ + for (int i = 0; i < act; i++) { \ + ret = A##_free(handle[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + st_usleep(100 * 1000); \ + } \ + \ + A##_assert_cnt(0); \ + EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ + \ + delete test_ctx; \ } while (0) -#define create_free_test(A, base, step, repeat) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle_base[base]; \ - for (int i = 0; i < base; i++) { \ - handle_base[i] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle_base[i]); \ - ops.udp_port[MTL_SESSION_PORT_P]++; \ - ops.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - for (int i = 0; i < repeat; i++) { \ - A##_handle handle[step]; \ - \ - for (int j = 0; j < step; j++) { \ - handle[j] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle[j] != NULL); \ - ops.udp_port[MTL_SESSION_PORT_P]++; \ - ops.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - st_usleep(100 * 1000); \ - for (int j = 0; j < step; j++) { \ - ret = A##_free(handle[j]); \ - ASSERT_TRUE(ret >= 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - st_usleep(100 * 1000); \ - } \ - \ - for (int i = 0; i < base; i++) { \ - ret = A##_free(handle_base[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - A##_assert_cnt(0); \ - \ - delete test_ctx; \ +#define create_free_test(A, base, step, repeat) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle_base[base]; \ + for (int i = 0; i < base; i++) { \ + handle_base[i] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle_base[i]); \ + ops.udp_port[MTL_SESSION_PORT_P]++; \ + ops.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + for (int i = 0; i < repeat; i++) { \ + A##_handle handle[step]; \ + \ + for (int j = 0; j < step; j++) { \ + handle[j] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle[j] != NULL); \ + ops.udp_port[MTL_SESSION_PORT_P]++; \ + ops.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + st_usleep(100 * 1000); \ + for (int j = 0; j < step; j++) { \ + ret = A##_free(handle[j]); \ + ASSERT_TRUE(ret >= 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + st_usleep(100 * 1000); \ + } \ + \ + for (int i = 0; i < base; i++) { \ + ret = A##_free(handle_base[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + A##_assert_cnt(0); \ + \ + delete test_ctx; \ } while (0) -#define expect_fail_test(A) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - EXPECT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 0 num_port */ \ - ops.num_port = 0; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with crazy big num_port */ \ - ops.num_port = 100; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with negative num_port */ \ - ops.num_port = -1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with 2 num_port */ \ - if (ctx->para.num_ports != 2) { \ - ops.num_port = 2; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - } \ - delete test_ctx; \ +#define expect_fail_test(A) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + EXPECT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 0 num_port */ \ + ops.num_port = 0; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with crazy big num_port */ \ + ops.num_port = 100; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with negative num_port */ \ + ops.num_port = -1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with 2 num_port */ \ + if (ctx->para.num_ports != 2) { \ + ops.num_port = 2; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + } \ + delete test_ctx; \ } while (0) -#define expect_fail_test_fb_cnt(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define expect_fail_test_fb_cnt(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) -#define test_get_framebuffer(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle != NULL); \ - void *fb_buff; \ - for (uint16_t idx = 0; idx < fb_nb; idx++) { \ - fb_buff = A##_get_framebuffer(handle, idx); \ - EXPECT_TRUE(fb_buff != NULL); \ - } \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - delete test_ctx; \ +#define test_get_framebuffer(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle != NULL); \ + void *fb_buff; \ + for (uint16_t idx = 0; idx < fb_nb; idx++) { \ + fb_buff = A##_get_framebuffer(handle, idx); \ + EXPECT_TRUE(fb_buff != NULL); \ + } \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + delete test_ctx; \ } while (0) -#define expect_fail_test_get_framebuffer(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle != NULL); \ - void *fb_buff; \ - fb_buff = A##_get_framebuffer(handle, fb_nb); \ - EXPECT_TRUE(fb_buff == NULL); \ - fb_buff = A##_get_framebuffer(handle, fb_nb * 2); \ - EXPECT_TRUE(fb_buff == NULL); \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - delete test_ctx; \ +#define expect_fail_test_get_framebuffer(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle != NULL); \ + void *fb_buff; \ + fb_buff = A##_get_framebuffer(handle, fb_nb); \ + EXPECT_TRUE(fb_buff == NULL); \ + fb_buff = A##_get_framebuffer(handle, fb_nb * 2); \ + EXPECT_TRUE(fb_buff == NULL); \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + delete test_ctx; \ } while (0) -#define expect_fail_test_rtp_ring(A, s_type, ring_sz) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.type = s_type; \ - ops.rtp_ring_size = ring_sz; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define expect_fail_test_rtp_ring(A, s_type, ring_sz) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.type = s_type; \ + ops.rtp_ring_size = ring_sz; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) -#define expect_fail_test_rtp_ring_2(A, ring_sz) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.rtp_ring_size = ring_sz; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define expect_fail_test_rtp_ring_2(A, ring_sz) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.rtp_ring_size = ring_sz; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) -#define expect_test_rtp_pkt_size(A, s_type, pkt_sz, expect) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.type = s_type; \ - ops.rtp_ring_size = 1024; \ - ops.rtp_frame_total_pkts = 1024; \ - ops.rtp_pkt_size = pkt_sz; \ - handle = A##_create(m_handle, &ops); \ - if (expect) \ - EXPECT_TRUE(handle != NULL); \ - else \ - EXPECT_TRUE(handle == NULL); \ - if (handle) { \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - } \ - delete test_ctx; \ +#define expect_test_rtp_pkt_size(A, s_type, pkt_sz, expect) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.type = s_type; \ + ops.rtp_ring_size = 1024; \ + ops.rtp_frame_total_pkts = 1024; \ + ops.rtp_pkt_size = pkt_sz; \ + handle = A##_create(m_handle, &ops); \ + if (expect) \ + EXPECT_TRUE(handle != NULL); \ + else \ + EXPECT_TRUE(handle == NULL); \ + if (handle) { \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + } \ + delete test_ctx; \ } while (0) -#define expect_test_rtp_pkt_size_2(A, s_type, pkt_sz, expect) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.num_port = 1; \ - ops.rtp_ring_size = 1024; \ - ops.rtp_pkt_size = pkt_sz; \ - ops.type = s_type; \ - handle = A##_create(m_handle, &ops); \ - if (expect) \ - EXPECT_TRUE(handle != NULL); \ - else \ - EXPECT_TRUE(handle == NULL); \ - if (handle) { \ - auto ret = A##_free(handle); \ - EXPECT_GE(ret, 0); \ - } \ - delete test_ctx; \ +#define expect_test_rtp_pkt_size_2(A, s_type, pkt_sz, expect) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.num_port = 1; \ + ops.rtp_ring_size = 1024; \ + ops.rtp_pkt_size = pkt_sz; \ + ops.type = s_type; \ + handle = A##_create(m_handle, &ops); \ + if (expect) \ + EXPECT_TRUE(handle != NULL); \ + else \ + EXPECT_TRUE(handle == NULL); \ + if (handle) { \ + auto ret = A##_free(handle); \ + EXPECT_GE(ret, 0); \ + } \ + delete test_ctx; \ } while (0) /* pipeline test marco */ -#define pipeline_create_free_test(A, base, step, repeat) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle_base[base]; \ - for (int i = 0; i < base; i++) { \ - handle_base[i] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle_base[i]); \ - ops.port.udp_port[MTL_SESSION_PORT_P]++; \ - ops.port.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - for (int i = 0; i < repeat; i++) { \ - A##_handle handle[step]; \ - \ - for (int j = 0; j < step; j++) { \ - handle[j] = A##_create(m_handle, &ops); \ - ASSERT_TRUE(handle[j] != NULL); \ - ops.port.udp_port[MTL_SESSION_PORT_P]++; \ - ops.port.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - for (int j = 0; j < step; j++) { \ - ret = A##_free(handle[j]); \ - ASSERT_TRUE(ret >= 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - } \ - \ - for (int i = 0; i < base; i++) { \ - ret = A##_free(handle_base[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - A##_assert_cnt(0); \ - \ - delete test_ctx; \ +#define pipeline_create_free_test(A, base, step, repeat) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle_base[base]; \ + for (int i = 0; i < base; i++) { \ + handle_base[i] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle_base[i]); \ + ops.port.udp_port[MTL_SESSION_PORT_P]++; \ + ops.port.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + for (int i = 0; i < repeat; i++) { \ + A##_handle handle[step]; \ + \ + for (int j = 0; j < step; j++) { \ + handle[j] = A##_create(m_handle, &ops); \ + ASSERT_TRUE(handle[j] != NULL); \ + ops.port.udp_port[MTL_SESSION_PORT_P]++; \ + ops.port.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + for (int j = 0; j < step; j++) { \ + ret = A##_free(handle[j]); \ + ASSERT_TRUE(ret >= 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + } \ + \ + for (int i = 0; i < base; i++) { \ + ret = A##_free(handle_base[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + A##_assert_cnt(0); \ + \ + delete test_ctx; \ } while (0) -#define pipeline_create_free_max(A, max) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - auto act = 0; \ - int ret, expect_cnt = 0; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - auto sch_cnt = st_test_sch_cnt(ctx); \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - \ - A##_handle handle[max]; \ - for (int i = 0; i < max; i++) { \ - handle[i] = A##_create(m_handle, &ops); \ - if (!handle[i]) \ - break; \ - ops.port.udp_port[MTL_SESSION_PORT_P]++; \ - ops.port.udp_port[MTL_SESSION_PORT_R]++; \ - expect_cnt++; \ - A##_assert_cnt(expect_cnt); \ - } \ - info("%s, max session cnt %d\n", __func__, expect_cnt); \ - act = expect_cnt; \ - for (int i = 0; i < act; i++) { \ - ret = A##_free(handle[i]); \ - EXPECT_GE(ret, 0); \ - expect_cnt--; \ - A##_assert_cnt(expect_cnt); \ - } \ - \ - A##_assert_cnt(0); \ - EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ - \ - delete test_ctx; \ +#define pipeline_create_free_max(A, max) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + auto act = 0; \ + int ret, expect_cnt = 0; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + auto sch_cnt = st_test_sch_cnt(ctx); \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + \ + A##_handle handle[max]; \ + for (int i = 0; i < max; i++) { \ + handle[i] = A##_create(m_handle, &ops); \ + if (!handle[i]) break; \ + ops.port.udp_port[MTL_SESSION_PORT_P]++; \ + ops.port.udp_port[MTL_SESSION_PORT_R]++; \ + expect_cnt++; \ + A##_assert_cnt(expect_cnt); \ + } \ + info("%s, max session cnt %d\n", __func__, expect_cnt); \ + act = expect_cnt; \ + for (int i = 0; i < act; i++) { \ + ret = A##_free(handle[i]); \ + EXPECT_GE(ret, 0); \ + expect_cnt--; \ + A##_assert_cnt(expect_cnt); \ + } \ + \ + A##_assert_cnt(0); \ + EXPECT_EQ(sch_cnt, st_test_sch_cnt(ctx)); \ + \ + delete test_ctx; \ } while (0) -#define pipeline_expect_fail_test(A) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - EXPECT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = 2; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 0 num_port */ \ - ops.port.num_port = 0; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with crazy big num_port */ \ - ops.port.num_port = 100; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with negative num_port */ \ - ops.port.num_port = -1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - \ - /* test with 2 num_port */ \ - if (ctx->para.num_ports != 2) { \ - ops.port.num_port = 2; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - } \ - delete test_ctx; \ +#define pipeline_expect_fail_test(A) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + EXPECT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = 2; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 0 num_port */ \ + ops.port.num_port = 0; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with crazy big num_port */ \ + ops.port.num_port = 100; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with negative num_port */ \ + ops.port.num_port = -1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + \ + /* test with 2 num_port */ \ + if (ctx->para.num_ports != 2) { \ + ops.port.num_port = 2; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + } \ + delete test_ctx; \ } while (0) -#define pipeline_expect_fail_test_fb_cnt(A, fb_nb) \ - do { \ - auto ctx = st_test_ctx(); \ - auto m_handle = ctx->handle; \ - struct A##_ops ops; \ - auto test_ctx = new tests_context(); \ - ASSERT_TRUE(test_ctx != NULL); \ - A##_handle handle; \ - \ - test_ctx->idx = 0; \ - test_ctx->ctx = ctx; \ - test_ctx->fb_cnt = fb_nb; \ - test_ctx->fb_idx = 0; \ - A##_ops_init(test_ctx, &ops); \ - /* test with 1 port */ \ - ops.port.num_port = 1; \ - handle = A##_create(m_handle, &ops); \ - EXPECT_TRUE(handle == NULL); \ - delete test_ctx; \ +#define pipeline_expect_fail_test_fb_cnt(A, fb_nb) \ + do { \ + auto ctx = st_test_ctx(); \ + auto m_handle = ctx->handle; \ + struct A##_ops ops; \ + auto test_ctx = new tests_context(); \ + ASSERT_TRUE(test_ctx != NULL); \ + A##_handle handle; \ + \ + test_ctx->idx = 0; \ + test_ctx->ctx = ctx; \ + test_ctx->fb_cnt = fb_nb; \ + test_ctx->fb_idx = 0; \ + A##_ops_init(test_ctx, &ops); \ + /* test with 1 port */ \ + ops.port.num_port = 1; \ + handle = A##_create(m_handle, &ops); \ + EXPECT_TRUE(handle == NULL); \ + delete test_ctx; \ } while (0) diff --git a/tests/src/ufd_loop_test.cpp b/tests/src/ufd_loop_test.cpp index 31df67141..e0bd9bf79 100644 --- a/tests/src/ufd_loop_test.cpp +++ b/tests/src/ufd_loop_test.cpp @@ -80,56 +80,47 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { } else { mufd_init_sockaddr(&tx_addr[i], p->sip_addr[MTL_PORT_P], udp_port + i); mufd_init_sockaddr(&rx_addr[i], p->sip_addr[MTL_PORT_R], udp_port + i); - mufd_init_sockaddr(&tx_bind_addr[i], p->sip_addr[MTL_PORT_P], - udp_port + i); - mufd_init_sockaddr(&rx_bind_addr[i], p->sip_addr[MTL_PORT_R], - udp_port + i); + mufd_init_sockaddr(&tx_bind_addr[i], p->sip_addr[MTL_PORT_P], udp_port + i); + mufd_init_sockaddr(&rx_bind_addr[i], p->sip_addr[MTL_PORT_R], udp_port + i); } } for (int i = 0; i < sessions; i++) { ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_P); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; tx_fds[i] = ret; if (dual_loop) { ret = mufd_bind(tx_fds[i], (const struct sockaddr *)&tx_bind_addr[i], sizeof(tx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; - ret = - mufd_setsockopt(tx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + ret = mufd_setsockopt(tx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; } ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_R); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; rx_fds[i] = ret; ret = mufd_bind(rx_fds[i], (const struct sockaddr *)&rx_bind_addr[i], sizeof(rx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; ret = mufd_setsockopt(rx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; if (para->mcast) { struct ip_mreq mreq; @@ -137,13 +128,11 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); - ret = mufd_setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, - sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); + ret = + mufd_setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; } } @@ -155,13 +144,11 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { SHA256((unsigned char *)send_buf, payload_len, (unsigned char *)send_buf + payload_len); - send = - mufd_sendto(tx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr *)&rx_addr[i], sizeof(rx_addr[i])); + send = mufd_sendto(tx_fds[i], send_buf, udp_len, 0, + (const struct sockaddr *)&rx_addr[i], sizeof(rx_addr[i])); EXPECT_EQ((size_t)send, udp_len); } - if (para->tx_sleep_us) - st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); if (para->use_poll) { int poll_succ = 0; @@ -178,13 +165,11 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { EXPECT_GE(ret, 0); poll_succ = 0; for (int i = 0; i < sessions; i++) { - if (fds[i].revents) - poll_succ++; + if (fds[i].revents) poll_succ++; } dbg("%s, %d succ on sessions %d on %d\n", __func__, poll_succ, sessions, poll_retry); - if ((poll_succ >= sessions) && (poll_retry > 0)) - break; + if ((poll_succ >= sessions) && (poll_retry > 0)) break; poll_retry++; st_usleep(1000); @@ -199,8 +184,8 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { recv = mufd_recvfrom(rx_fds[i], recv_buf, udp_len, 0, NULL, NULL); if (recv < 0) { /* timeout */ rx_timeout[i]++; - err("%s, recv fail %d at session %d pkt %d fd %d\n", __func__, - (int)recv, i, loop, rx_fds[i]); + err("%s, recv fail %d at session %d pkt %d fd %d\n", __func__, (int)recv, i, loop, + rx_fds[i]); continue; } EXPECT_EQ((size_t)recv, udp_len); @@ -220,19 +205,17 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { SHA256((unsigned char *)send_buf, payload_len, (unsigned char *)send_buf + payload_len); send = mufd_sendto(rx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr *)&tx_addr[i], - sizeof(tx_addr[i])); + (const struct sockaddr *)&tx_addr[i], sizeof(tx_addr[i])); EXPECT_EQ((size_t)send, udp_len); } - if (para->tx_sleep_us) - st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); for (int i = 0; i < sessions; i++) { recv = mufd_recvfrom(tx_fds[i], recv_buf, udp_len, 0, NULL, NULL); if (recv < 0) { /* timeout */ rx_timeout[i]++; - err("%s, back recv fail %d at session %d pkt %d\n", __func__, - (int)recv, i, loop); + err("%s, back recv fail %d at session %d pkt %d\n", __func__, (int)recv, i, + loop); continue; } EXPECT_EQ((size_t)recv, udp_len); @@ -253,8 +236,7 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { exit: for (int i = 0; i < sessions; i++) { - if (tx_fds[i] > 0) - mufd_close(tx_fds[i]); + if (tx_fds[i] > 0) mufd_close(tx_fds[i]); if (rx_fds[i] > 0) { if (para->mcast) { struct ip_mreq mreq; @@ -262,8 +244,7 @@ static int loop_sanity_test(struct utest_ctx *ctx, struct loop_para *para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], - MTL_IP_ADDR_LEN); + memcpy(&mreq.imr_interface.s_addr, p->sip_addr[MTL_PORT_P], MTL_IP_ADDR_LEN); ret = mufd_setsockopt(rx_fds[i], IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); EXPECT_GE(ret, 0); diff --git a/tests/src/ufd_test.cpp b/tests/src/ufd_test.cpp index fb01796da..dcf879a86 100644 --- a/tests/src/ufd_test.cpp +++ b/tests/src/ufd_test.cpp @@ -40,61 +40,60 @@ static int utest_parse_args(struct utest_ctx *ctx, int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", utest_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case UTEST_ARG_P_PORT: - snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); - p->num_ports++; - break; - case UTEST_ARG_R_PORT: - snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); - p->num_ports++; - break; - case UTEST_ARG_LOG_LEVEL: - if (!strcmp(optarg, "debug")) - p->log_level = MTL_LOG_LEVEL_DEBUG; - else if (!strcmp(optarg, "info")) - p->log_level = MTL_LOG_LEVEL_INFO; - else if (!strcmp(optarg, "notice")) - p->log_level = MTL_LOG_LEVEL_NOTICE; - else if (!strcmp(optarg, "warning")) - p->log_level = MTL_LOG_LEVEL_WARNING; - else if (!strcmp(optarg, "error")) - p->log_level = MTL_LOG_LEVEL_ERR; - else - err("%s, unknow log level %s\n", __func__, optarg); - break; - case UTEST_ARG_QUEUE_MODE: - if (!strcmp(optarg, "shared")) - p->flags |= (MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); - else if (!strcmp(optarg, "dedicated")) - p->flags &= ~(MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); - else - err("%s, unknow queue mode %s\n", __func__, optarg); - break; - case UTEST_ARG_UDP_LCORE: - p->flags |= MTL_FLAG_UDP_LCORE; - break; - case UTEST_ARG_RSS_MODE: - if (!strcmp(optarg, "l3")) - p->rss_mode = MTL_RSS_MODE_L3; - else if (!strcmp(optarg, "l3_l4")) - p->rss_mode = MTL_RSS_MODE_L3_L4; - else if (!strcmp(optarg, "none")) - p->rss_mode = MTL_RSS_MODE_NONE; - else - err("%s, unknow rss mode %s\n", __func__, optarg); - break; - case UTEST_ARG_DHCP: - for (int port = 0; port < MTL_PORT_MAX; ++port) - p->net_proto[port] = MTL_PROTO_DHCP; - ctx->dhcp = true; - break; - default: - break; + case UTEST_ARG_P_PORT: + snprintf(p->port[MTL_PORT_P], sizeof(p->port[MTL_PORT_P]), "%s", optarg); + p->num_ports++; + break; + case UTEST_ARG_R_PORT: + snprintf(p->port[MTL_PORT_R], sizeof(p->port[MTL_PORT_R]), "%s", optarg); + p->num_ports++; + break; + case UTEST_ARG_LOG_LEVEL: + if (!strcmp(optarg, "debug")) + p->log_level = MTL_LOG_LEVEL_DEBUG; + else if (!strcmp(optarg, "info")) + p->log_level = MTL_LOG_LEVEL_INFO; + else if (!strcmp(optarg, "notice")) + p->log_level = MTL_LOG_LEVEL_NOTICE; + else if (!strcmp(optarg, "warning")) + p->log_level = MTL_LOG_LEVEL_WARNING; + else if (!strcmp(optarg, "error")) + p->log_level = MTL_LOG_LEVEL_ERR; + else + err("%s, unknow log level %s\n", __func__, optarg); + break; + case UTEST_ARG_QUEUE_MODE: + if (!strcmp(optarg, "shared")) + p->flags |= (MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); + else if (!strcmp(optarg, "dedicated")) + p->flags &= ~(MTL_FLAG_SHARED_TX_QUEUE | MTL_FLAG_SHARED_RX_QUEUE); + else + err("%s, unknow queue mode %s\n", __func__, optarg); + break; + case UTEST_ARG_UDP_LCORE: + p->flags |= MTL_FLAG_UDP_LCORE; + break; + case UTEST_ARG_RSS_MODE: + if (!strcmp(optarg, "l3")) + p->rss_mode = MTL_RSS_MODE_L3; + else if (!strcmp(optarg, "l3_l4")) + p->rss_mode = MTL_RSS_MODE_L3_L4; + else if (!strcmp(optarg, "none")) + p->rss_mode = MTL_RSS_MODE_NONE; + else + err("%s, unknow rss mode %s\n", __func__, optarg); + break; + case UTEST_ARG_DHCP: + for (int port = 0; port < MTL_PORT_MAX; ++port) + p->net_proto[port] = MTL_PROTO_DHCP; + ctx->dhcp = true; + break; + default: + break; } }; @@ -140,21 +139,26 @@ static void utest_ctx_init(struct utest_ctx *ctx) { p->tasklets_nb_per_sch = ctx->init_params.slots_nb_max + 8; } -static void utest_ctx_uinit(struct utest_ctx *ctx) { st_test_free(ctx); } +static void utest_ctx_uinit(struct utest_ctx *ctx) { + st_test_free(ctx); +} static void socket_single_test(enum mtl_port port) { int ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, port); EXPECT_GE(ret, 0); - if (ret < 0) - return; + if (ret < 0) return; int fd = ret; ret = mufd_close(fd); EXPECT_GE(ret, 0); } -TEST(Api, socket_single) { socket_single_test(MTL_PORT_P); } -TEST(Api, socket_single_r) { socket_single_test(MTL_PORT_R); } +TEST(Api, socket_single) { + socket_single_test(MTL_PORT_P); +} +TEST(Api, socket_single_r) { + socket_single_test(MTL_PORT_R); +} static void socket_expect_fail_test(enum mtl_port port) { int ret; @@ -165,8 +169,12 @@ static void socket_expect_fail_test(enum mtl_port port) { EXPECT_LT(ret, 0); } -TEST(Api, socket_expect_fail) { socket_expect_fail_test(MTL_PORT_P); } -TEST(Api, socket_expect_fail_r) { socket_expect_fail_test(MTL_PORT_R); } +TEST(Api, socket_expect_fail) { + socket_expect_fail_test(MTL_PORT_P); +} +TEST(Api, socket_expect_fail_r) { + socket_expect_fail_test(MTL_PORT_R); +} static void socket_max_test(enum mtl_port port) { int ret; @@ -194,15 +202,21 @@ static void socket_max_test(enum mtl_port port) { } } -TEST(Api, socket_max) { socket_max_test(MTL_PORT_P); } -TEST(Api, socket_max_r) { socket_max_test(MTL_PORT_R); } +TEST(Api, socket_max) { + socket_max_test(MTL_PORT_P); +} +TEST(Api, socket_max_r) { + socket_max_test(MTL_PORT_R); +} -template static void socketopt_double(OPT_TYPE *i) { +template +static void socketopt_double(OPT_TYPE *i) { OPT_TYPE value = *i; *i = value * 2; } -template static void socketopt_half(OPT_TYPE *i) { +template +static void socketopt_half(OPT_TYPE *i) { OPT_TYPE value = *i; *i = value / 2; } @@ -211,8 +225,7 @@ template static void socketopt_test(int level, int optname) { int ret = mufd_socket(AF_INET, SOCK_DGRAM, 0); EXPECT_GE(ret, 0); - if (ret < 0) - return; + if (ret < 0) return; int fd = ret; /* get */ @@ -253,15 +266,23 @@ static void socketopt_test(int level, int optname) { EXPECT_GE(ret, 0); } -TEST(Api, socket_snd_buf) { socketopt_test(SOL_SOCKET, SO_SNDBUF); } -TEST(Api, socket_rcv_buf) { socketopt_test(SOL_SOCKET, SO_RCVBUF); } -TEST(Api, socket_cookie) { socketopt_test(SOL_SOCKET, SO_COOKIE); } +TEST(Api, socket_snd_buf) { + socketopt_test(SOL_SOCKET, SO_SNDBUF); +} +TEST(Api, socket_rcv_buf) { + socketopt_test(SOL_SOCKET, SO_RCVBUF); +} +TEST(Api, socket_cookie) { + socketopt_test(SOL_SOCKET, SO_COOKIE); +} -template <> void socketopt_double(struct timeval *i) { +template <> +void socketopt_double(struct timeval *i) { i->tv_sec *= 2; i->tv_usec *= 2; } -template <> void socketopt_half(struct timeval *i) { +template <> +void socketopt_half(struct timeval *i) { i->tv_sec /= 2; i->tv_usec /= 2; } @@ -289,29 +310,25 @@ static int check_r_port_alive(struct mtl_init_params *p) { mufd_init_sockaddr(&rx_addr, p->sip_addr[MTL_PORT_R], 20000); ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_P); - if (ret < 0) - goto out; + if (ret < 0) goto out; tx_fd = ret; ret = mufd_socket_port(AF_INET, SOCK_DGRAM, 0, MTL_PORT_R); - if (ret < 0) - goto out; + if (ret < 0) goto out; rx_fd = ret; ret = mufd_bind(rx_fd, (const struct sockaddr *)&rx_addr, sizeof(rx_addr)); - if (ret < 0) - goto out; + if (ret < 0) goto out; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; ret = mufd_setsockopt(rx_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - if (ret < 0) - goto out; + if (ret < 0) goto out; while (retry < max_retry) { - if (mufd_sendto(tx_fd, send_buf, payload_len, 0, - (const struct sockaddr *)&rx_addr, sizeof(rx_addr)) < 0) + if (mufd_sendto(tx_fd, send_buf, payload_len, 0, (const struct sockaddr *)&rx_addr, + sizeof(rx_addr)) < 0) warn("%s, send buf fail at %d\n", __func__, retry); ssize_t recv = mufd_recvfrom(rx_fd, recv_buf, payload_len, 0, NULL, NULL); @@ -325,10 +342,8 @@ static int check_r_port_alive(struct mtl_init_params *p) { } out: - if (tx_fd > 0) - mufd_close(tx_fd); - if (rx_fd > 0) - mufd_close(rx_fd); + if (tx_fd > 0) mufd_close(tx_fd); + if (rx_fd > 0) mufd_close(rx_fd); delete[] send_buf; delete[] recv_buf; return ret; @@ -374,8 +389,7 @@ GTEST_API_ int main(int argc, char **argv) { if (ctx->dhcp) { for (int i = 0; i < ctx->init_params.mt_params.num_ports; i++) { /* get the assigned dhcp ip */ - mufd_port_ip_info((enum mtl_port)i, - ctx->init_params.mt_params.sip_addr[i], + mufd_port_ip_info((enum mtl_port)i, ctx->init_params.mt_params.sip_addr[i], ctx->init_params.mt_params.netmask[i], ctx->init_params.mt_params.gateway[i]); } @@ -386,16 +400,14 @@ GTEST_API_ int main(int argc, char **argv) { /* before test we should make sure the rx port is ready */ ret = check_r_port_alive(&ctx->init_params.mt_params); - if (ret >= 0) - ret = RUN_ALL_TESTS(); + if (ret >= 0) ret = RUN_ALL_TESTS(); uint64_t end_time_ns = st_test_get_monotonic_time(); int time_s = (end_time_ns - start_time_ns) / NS_PER_S; int time_least = 10; if (link_flap_wa && (time_s < time_least)) { /* wa for linkFlapErrDisabled in the hub */ - info("%s, sleep %ds before disable the port\n", __func__, - time_least - time_s); + info("%s, sleep %ds before disable the port\n", __func__, time_least - time_s); sleep(time_least - time_s); } diff --git a/tests/src/upl_loop_test.cpp b/tests/src/upl_loop_test.cpp index 1123a6318..1139d4889 100644 --- a/tests/src/upl_loop_test.cpp +++ b/tests/src/upl_loop_test.cpp @@ -54,8 +54,7 @@ static int loop_para_init(struct loop_para *para) { static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { int tx_sessions = para->sessions; - if (para->reuse_port) - tx_sessions = para->reuse_tx_sessions; + if (para->reuse_port) tx_sessions = para->reuse_tx_sessions; int rx_sessions = para->sessions; uint16_t udp_port = para->udp_port; int udp_len = para->udp_len; @@ -84,15 +83,13 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { for (int i = 0; i < tx_sessions; i++) { tx_fds[i] = -1; uint16_t fd_udp_port = udp_port + i; - if (para->reuse_port) - fd_udp_port = udp_port; + if (para->reuse_port) fd_udp_port = udp_port; if (para->mcast) { uplt_init_sockaddr(&tx_addr[i], ctx->mcast_ip_addr, fd_udp_port); uplt_init_sockaddr_any(&tx_bind_addr[i], fd_udp_port); } else { uplt_init_sockaddr(&tx_addr[i], ctx->sip_addr[UPLT_PORT_P], fd_udp_port); - uplt_init_sockaddr(&tx_bind_addr[i], ctx->sip_addr[UPLT_PORT_P], - fd_udp_port); + uplt_init_sockaddr(&tx_bind_addr[i], ctx->sip_addr[UPLT_PORT_P], fd_udp_port); } } for (int i = 0; i < rx_sessions; i++) { @@ -100,71 +97,62 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { rx_timeout[i] = 0; rx_pkts[i] = 0; uint16_t fd_udp_port = udp_port + i; - if (para->reuse_port) - fd_udp_port = udp_port; + if (para->reuse_port) fd_udp_port = udp_port; if (para->mcast) { uplt_init_sockaddr(&rx_addr[i], ctx->mcast_ip_addr, fd_udp_port); uplt_init_sockaddr_any(&rx_bind_addr[i], fd_udp_port); } else { uplt_init_sockaddr(&rx_addr[i], ctx->sip_addr[UPLT_PORT_R], fd_udp_port); - uplt_init_sockaddr(&rx_bind_addr[i], ctx->sip_addr[UPLT_PORT_R], - fd_udp_port); + uplt_init_sockaddr(&rx_bind_addr[i], ctx->sip_addr[UPLT_PORT_R], fd_udp_port); } } for (int i = 0; i < tx_sessions; i++) { ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_P); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; tx_fds[i] = ret; if (dual_loop) { ret = bind(tx_fds[i], (const struct sockaddr *)&tx_bind_addr[i], sizeof(tx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; ret = setsockopt(tx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; } } for (int i = 0; i < rx_sessions; i++) { ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_R); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; rx_fds[i] = ret; if (para->reuse_port) { int reuse = 1; - ret = setsockopt(rx_fds[i], SOL_SOCKET, SO_REUSEPORT, - (const void *)&reuse, sizeof(reuse)); + ret = setsockopt(rx_fds[i], SOL_SOCKET, SO_REUSEPORT, (const void *)&reuse, + sizeof(reuse)); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; } ret = bind(rx_fds[i], (const struct sockaddr *)&rx_bind_addr[i], sizeof(rx_bind_addr[i])); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = para->rx_timeout_us; ret = setsockopt(rx_fds[i], SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; if (para->mcast) { struct ip_mreq mreq; @@ -172,13 +160,10 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], - UPLT_IP_ADDR_LEN); - ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, - sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], UPLT_IP_ADDR_LEN); + ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); EXPECT_GE(ret, 0); - if (ret < 0) - goto exit; + if (ret < 0) goto exit; } } @@ -242,8 +227,8 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { msg.msg_controllen = sizeof(msg_control); struct cmsghdr *cmsg; cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = 17; // SOL_UDP; - cmsg->cmsg_type = 103; // UDP_SEGMENT; + cmsg->cmsg_level = 17; // SOL_UDP; + cmsg->cmsg_type = 103; // UDP_SEGMENT; cmsg->cmsg_len = CMSG_LEN(sizeof(uint16_t)); uint16_t *val_p; val_p = (uint16_t *)CMSG_DATA(cmsg); @@ -263,19 +248,16 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { EXPECT_EQ((size_t)send, udp_len); } else { if (para->reuse_port) { /* reuse test use same port */ - send = - sendto(tx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr *)&rx_addr[0], sizeof(rx_addr[0])); + send = sendto(tx_fds[i], send_buf, udp_len, 0, + (const struct sockaddr *)&rx_addr[0], sizeof(rx_addr[0])); } else { - send = - sendto(tx_fds[i], send_buf, udp_len, 0, - (const struct sockaddr *)&rx_addr[i], sizeof(rx_addr[i])); + send = sendto(tx_fds[i], send_buf, udp_len, 0, + (const struct sockaddr *)&rx_addr[i], sizeof(rx_addr[i])); } EXPECT_EQ((size_t)send, udp_len); } } - if (para->tx_sleep_us) - st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); int poll_succ = 0; int poll_retry = 0; @@ -299,13 +281,11 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { EXPECT_GE(ret, 0); poll_succ = 0; for (int i = 0; i < rx_sessions; i++) { - if (fds[i].revents) - poll_succ++; + if (fds[i].revents) poll_succ++; } - dbg("%s, poll %d succ on sessions %d on %d\n", __func__, poll_succ, - rx_sessions, poll_retry); - if (poll_succ >= rx_sessions) - break; + dbg("%s, poll %d succ on sessions %d on %d\n", __func__, poll_succ, rx_sessions, + poll_retry); + if (poll_succ >= rx_sessions) break; poll_retry++; st_usleep(1000); @@ -321,14 +301,12 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { timeout.tv_usec = para->rx_timeout_us; for (int i = 0; i < rx_sessions; i++) { FD_SET(rx_fds[i], &readfds); - if (rx_fds[i] > nfds) - nfds = rx_fds[i]; + if (rx_fds[i] > nfds) nfds = rx_fds[i]; dbg("%s, i %d fd %d\n", __func__, i, rx_fds[i]); } if (sfd > 0) { FD_SET(sfd, &readfds); - if (sfd > nfds) - nfds = sfd; + if (sfd > nfds) nfds = sfd; } nfds += 1; /* highest-numbered fd plus 1 */ ret = select(nfds, &readfds, NULL, NULL, &timeout); @@ -336,13 +314,11 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { dbg("%s, ret %d nfds %d\n", __func__, ret, nfds); poll_succ = 0; for (int i = 0; i < rx_sessions; i++) { - if (FD_ISSET(rx_fds[i], &readfds)) - poll_succ++; + if (FD_ISSET(rx_fds[i], &readfds)) poll_succ++; } - dbg("%s, select %d succ on sessions %d on %d\n", __func__, poll_succ, - rx_sessions, poll_retry); - if (poll_succ >= rx_sessions) - break; + dbg("%s, select %d succ on sessions %d on %d\n", __func__, poll_succ, rx_sessions, + poll_retry); + if (poll_succ >= rx_sessions) break; poll_retry++; st_usleep(1000); @@ -350,13 +326,11 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { } else if (para->use_epoll) { while (poll_retry < max_retry) { struct epoll_event *events = new struct epoll_event[rx_sessions]; - ret = epoll_wait(epoll_fd, events, rx_sessions, - para->rx_timeout_us / 1000); + ret = epoll_wait(epoll_fd, events, rx_sessions, para->rx_timeout_us / 1000); EXPECT_GE(ret, 0); poll_succ = ret; dbg("%s, ret %d\n", __func__, ret); - if (poll_succ >= rx_sessions) - break; + if (poll_succ >= rx_sessions) break; poll_retry++; st_usleep(1000); } @@ -401,8 +375,7 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { EXPECT_EQ(ret, 0); rx_pkts[i]++; // test_sha_dump("upd_loop_sha", sha_result); - if (para->sendmsg_gso || para->reuse_port) - goto session_rx; + if (para->sendmsg_gso || para->reuse_port) goto session_rx; } if (dual_loop) { @@ -415,8 +388,7 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { (const struct sockaddr *)&tx_addr[i], sizeof(tx_addr[i])); EXPECT_EQ((size_t)send, udp_len); } - if (para->tx_sleep_us) - st_usleep(para->tx_sleep_us); + if (para->tx_sleep_us) st_usleep(para->tx_sleep_us); for (int i = 0; i < tx_sessions; i++) { recv = recvfrom(tx_fds[i], recv_buf, udp_len, 0, NULL, NULL); @@ -460,8 +432,7 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { sfd = -1; } for (int i = 0; i < tx_sessions; i++) { - if (tx_fds[i] > 0) - close(tx_fds[i]); + if (tx_fds[i] > 0) close(tx_fds[i]); } for (int i = 0; i < rx_sessions; i++) { if (rx_fds[i] > 0) { @@ -471,10 +442,8 @@ static int loop_sanity_test(struct uplt_ctx *ctx, struct loop_para *para) { /* multicast addr */ mreq.imr_multiaddr.s_addr = rx_addr[i].sin_addr.s_addr; /* local nic src ip */ - memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], - UPLT_IP_ADDR_LEN); - ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, - sizeof(mreq)); + memcpy(&mreq.imr_interface.s_addr, ctx->sip_addr[UPLT_PORT_P], UPLT_IP_ADDR_LEN); + ret = setsockopt(rx_fds[i], IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); EXPECT_GE(ret, 0); } close(rx_fds[i]); diff --git a/tests/src/upl_test.cpp b/tests/src/upl_test.cpp index 2a12957af..c08da47c2 100644 --- a/tests/src/upl_test.cpp +++ b/tests/src/upl_test.cpp @@ -27,7 +27,9 @@ static void uplt_ctx_init(struct uplt_ctx *ctx) { p_ip[3] = rand() % 0xFF; } -static void uplt_ctx_uinit(struct uplt_ctx *ctx) { st_test_free(ctx); } +static void uplt_ctx_uinit(struct uplt_ctx *ctx) { + st_test_free(ctx); +} static int uplt_set_port(int port) { char port_u[16]; @@ -45,17 +47,22 @@ int uplt_socket_port(int domain, int type, int protocol, int port) { static void socket_single_test(int port) { int ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, port); EXPECT_GE(ret, 0); - if (ret < 0) - return; + if (ret < 0) return; int fd = ret; ret = close(fd); EXPECT_GE(ret, 0); } -TEST(Api, socket_single) { socket_single_test(UPLT_PORT_P); } -TEST(Api, socket_single_r) { socket_single_test(UPLT_PORT_R); } -TEST(Api, socket_single_port_max) { socket_single_test(32); } +TEST(Api, socket_single) { + socket_single_test(UPLT_PORT_P); +} +TEST(Api, socket_single_r) { + socket_single_test(UPLT_PORT_R); +} +TEST(Api, socket_single_port_max) { + socket_single_test(32); +} static int check_r_port_alive(struct uplt_ctx *ctx) { int tx_fd = -1; @@ -74,30 +81,26 @@ static int check_r_port_alive(struct uplt_ctx *ctx) { uplt_init_sockaddr(&rx_addr, ctx->sip_addr[1], 20000); ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_P); - if (ret < 0) - goto out; + if (ret < 0) goto out; tx_fd = ret; ret = uplt_socket_port(AF_INET, SOCK_DGRAM, 0, UPLT_PORT_R); - if (ret < 0) - goto out; + if (ret < 0) goto out; rx_fd = ret; ret = bind(rx_fd, (const struct sockaddr *)&rx_addr, sizeof(rx_addr)); - if (ret < 0) - goto out; + if (ret < 0) goto out; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 1000; ret = setsockopt(rx_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - if (ret < 0) - goto out; + if (ret < 0) goto out; info("%s, start to rx port status\n", __func__); while (retry < max_retry) { - if (sendto(tx_fd, send_buf, payload_len, 0, - (const struct sockaddr *)&rx_addr, sizeof(rx_addr)) < 0) + if (sendto(tx_fd, send_buf, payload_len, 0, (const struct sockaddr *)&rx_addr, + sizeof(rx_addr)) < 0) continue; ssize_t recv = recvfrom(rx_fd, recv_buf, payload_len, 0, NULL, NULL); if (recv > 0) { @@ -110,10 +113,8 @@ static int check_r_port_alive(struct uplt_ctx *ctx) { } out: - if (tx_fd > 0) - close(tx_fd); - if (rx_fd > 0) - close(rx_fd); + if (tx_fd > 0) close(tx_fd); + if (rx_fd > 0) close(rx_fd); delete[] send_buf; delete[] recv_buf; return ret; @@ -135,19 +136,18 @@ static int uplt_parse_args(struct uplt_ctx *ctx, int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", uplt_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; dbg("%s, cmd %d %s\n", __func__, cmd, optarg); switch (cmd) { - case UPLT_ARG_P_SIP: - inet_pton(AF_INET, optarg, ctx->sip_addr[0]); - break; - case UPLT_ARG_R_SIP: - inet_pton(AF_INET, optarg, ctx->sip_addr[1]); - break; - default: - break; + case UPLT_ARG_P_SIP: + inet_pton(AF_INET, optarg, ctx->sip_addr[0]); + break; + case UPLT_ARG_R_SIP: + inet_pton(AF_INET, optarg, ctx->sip_addr[1]); + break; + default: + break; } }; @@ -176,16 +176,14 @@ GTEST_API_ int main(int argc, char **argv) { /* before test we should make sure the rx port is ready */ ret = check_r_port_alive(ctx); - if (ret >= 0) - ret = RUN_ALL_TESTS(); + if (ret >= 0) ret = RUN_ALL_TESTS(); uint64_t end_time_ns = st_test_get_monotonic_time(); int time_s = (end_time_ns - start_time_ns) / NS_PER_S; int time_least = 10; if (link_flap_wa && (time_s < time_least)) { /* wa for linkFlapErrDisabled in the hub */ - info("%s, sleep %ds before disable the port\n", __func__, - time_least - time_s); + info("%s, sleep %ds before disable the port\n", __func__, time_least - time_s); sleep(time_least - time_s); } diff --git a/tests/src/upl_test.h b/tests/src/upl_test.h index 1760eba51..2086c742a 100644 --- a/tests/src/upl_test.h +++ b/tests/src/upl_test.h @@ -23,16 +23,14 @@ struct uplt_ctx *uplt_get_ctx(void); int uplt_socket_port(int domain, int type, int protocol, int port); static void inline uplt_init_sockaddr(struct sockaddr_in *saddr, - uint8_t ip[UPLT_IP_ADDR_LEN], - uint16_t port) { + uint8_t ip[UPLT_IP_ADDR_LEN], uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; memcpy(&saddr->sin_addr.s_addr, ip, UPLT_IP_ADDR_LEN); saddr->sin_port = htons(port); } -static void inline uplt_init_sockaddr_any(struct sockaddr_in *saddr, - uint16_t port) { +static void inline uplt_init_sockaddr_any(struct sockaddr_in *saddr, uint16_t port) { memset(saddr, 0, sizeof(*saddr)); saddr->sin_family = AF_INET; saddr->sin_addr.s_addr = INADDR_ANY; diff --git a/tools/ebpf/et.c b/tools/ebpf/et.c index 636ff262a..ff8ba37a0 100644 --- a/tools/ebpf/et.c +++ b/tools/ebpf/et.c @@ -31,9 +31,9 @@ static void et_sig_handler(int signo) { printf("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + stop = true; + break; } return; @@ -42,8 +42,8 @@ static void et_sig_handler(int signo) { static int udp_send_handler(void *ctx, void *data, size_t data_sz) { const struct udp_send_event *e = data; - printf("%s: pid %d, gso_size %u, bytes %u, duration_ns %llu\n", __func__, - e->pid, e->gso_size, e->udp_send_bytes, e->duration_ns); + printf("%s: pid %d, gso_size %u, bytes %u, duration_ns %llu\n", __func__, e->pid, + e->gso_size, e->udp_send_bytes, e->duration_ns); return 0; } @@ -66,8 +66,7 @@ static int et_fentry_loop() { printf("fentry_bpf__attach() succeeded\n"); - rb = ring_buffer__new(bpf_map__fd(skel->maps.rb), udp_send_handler, NULL, - NULL); + rb = ring_buffer__new(bpf_map__fd(skel->maps.rb), udp_send_handler, NULL, NULL); if (!rb) { ret = -1; fprintf(stderr, "failed to create ring buffer\n"); @@ -150,13 +149,15 @@ static void et_print_help() { printf("##### Usage: #####\n\n"); printf(" Params:\n"); - printf(" --help Print this help " - "information\n"); + printf( + " --help Print this help " + "information\n"); printf(" --print Print libbpf output\n"); printf("\n Prog Commands:\n"); - printf(" --prog Attach to program of " - "\n"); + printf( + " --prog Attach to program of " + "\n"); printf( " --prog xdp --ifname --xdp_path /path/to/xdp.o " "Load a custom " @@ -171,36 +172,35 @@ static int et_parse_args(struct et_ctx *ctx, int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", et_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; switch (cmd) { - case ET_ARG_PROG: - if (strcmp(optarg, "fentry") == 0) { - ctx->prog_type = ET_PROG_FENTRY; - } else if (strcmp(optarg, "xdp") == 0) { - ctx->prog_type = ET_PROG_XDP; - } - break; - case ET_ARG_PRINT_LIBBPF: - libbpf_set_print(libbpf_print_fn); - break; - case ET_ARG_IFNAME: - char *ifname; - ctx->xdp_if_cnt = 0; - ifname = strtok(optarg, ","); - while (ifname) { - ctx->xdp_ifindex[ctx->xdp_if_cnt++] = if_nametoindex(ifname); - ifname = strtok(NULL, ","); - } - break; - case ET_ARG_XDP_PATH: - ctx->xdp_path = optarg; - break; - case ET_ARG_HELP: - default: - et_print_help(); - return -1; + case ET_ARG_PROG: + if (strcmp(optarg, "fentry") == 0) { + ctx->prog_type = ET_PROG_FENTRY; + } else if (strcmp(optarg, "xdp") == 0) { + ctx->prog_type = ET_PROG_XDP; + } + break; + case ET_ARG_PRINT_LIBBPF: + libbpf_set_print(libbpf_print_fn); + break; + case ET_ARG_IFNAME: + char *ifname; + ctx->xdp_if_cnt = 0; + ifname = strtok(optarg, ","); + while (ifname) { + ctx->xdp_ifindex[ctx->xdp_if_cnt++] = if_nametoindex(ifname); + ifname = strtok(NULL, ","); + } + break; + case ET_ARG_XDP_PATH: + ctx->xdp_path = optarg; + break; + case ET_ARG_HELP: + default: + et_print_help(); + return -1; } } @@ -215,14 +215,14 @@ int main(int argc, char **argv) { printf("prog type is %s\n", prog_type_str[ctx.prog_type]); switch (ctx.prog_type) { - case ET_PROG_FENTRY: - et_fentry_loop(); - break; - case ET_PROG_XDP: - et_xdp_loop(&ctx); - break; - default: - break; + case ET_PROG_FENTRY: + et_fentry_loop(); + break; + case ET_PROG_XDP: + et_xdp_loop(&ctx); + break; + default: + break; } return 0; diff --git a/tools/ebpf/fentry.bpf.c b/tools/ebpf/fentry.bpf.c index b5cc6470f..3d9b96d2c 100644 --- a/tools/ebpf/fentry.bpf.c +++ b/tools/ebpf/fentry.bpf.c @@ -46,13 +46,11 @@ int BPF_PROG(udp_send_skb_exit, struct sk_buff *skb, struct flowi4 *fl4, pid = bpf_get_current_pid_tgid() >> 32; start_ts = bpf_map_lookup_elem(&start_time, &skb_addr); - if (start_ts) - duration_ns = bpf_ktime_get_ns() - *start_ts; + if (start_ts) duration_ns = bpf_ktime_get_ns() - *start_ts; bpf_map_delete_elem(&start_time, &skb_addr); e = bpf_ringbuf_reserve(&rb, sizeof(*e), 0); - if (!e) - return 0; + if (!e) return 0; e->pid = pid; e->gso_size = cork->gso_size; diff --git a/tools/ebpf/lcore_monitor.bpf.c b/tools/ebpf/lcore_monitor.bpf.c index d9fbb43d9..9853baf5f 100644 --- a/tools/ebpf/lcore_monitor.bpf.c +++ b/tools/ebpf/lcore_monitor.bpf.c @@ -52,12 +52,10 @@ static int lm_switch_event_submit(enum lcore_tid_event_type type, SEC("tracepoint/sched/sched_switch") int bpf_prog_sched_switch(struct trace_event_raw_sched_switch *args) { struct lcore_tid_cfg *cfg = lm_get_cfg(); - if (!cfg) - return 0; + if (!cfg) return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) - return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) return 0; if (cfg->bpf_trace) { char fmt[] = "sched_switch: prev_pid %d next_pid in %d\n"; @@ -153,12 +151,10 @@ static int lm_vector_event_submit(enum lcore_tid_event_type type, int vector) { SEC("raw_tp/irq_work_entry") int BPF_PROG(irq_work_entry, unsigned int vector) { struct lcore_tid_cfg *cfg = lm_get_cfg(); - if (!cfg) - return 0; + if (!cfg) return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) - return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) return 0; if (cfg->bpf_trace) { char fmt[] = "irq_work_entry, vector %d\n"; @@ -173,12 +169,10 @@ int BPF_PROG(irq_work_entry, unsigned int vector) { SEC("raw_tp/irq_work_exit") int BPF_PROG(irq_work_exit, unsigned int vector) { struct lcore_tid_cfg *cfg = lm_get_cfg(); - if (!cfg) - return 0; + if (!cfg) return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) - return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) return 0; if (cfg->bpf_trace) { char fmt[] = "irq_work_exit, vector %d\n"; @@ -211,12 +205,10 @@ static int lm_syscall_event_submit(enum lcore_tid_event_type type, int id) { SEC("tracepoint/raw_syscalls/sys_enter") int bpf_prog_sys_enter(struct trace_event_raw_sys_enter *args) { struct lcore_tid_cfg *cfg = lm_get_cfg(); - if (!cfg) - return 0; + if (!cfg) return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) - return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) return 0; if (cfg->bpf_trace) { char fmt[] = "sys_enter: id %d\n"; @@ -231,12 +223,10 @@ int bpf_prog_sys_enter(struct trace_event_raw_sys_enter *args) { SEC("tracepoint/raw_syscalls/sys_exit") int bpf_prog_sys_enxit(struct trace_event_raw_sys_exit *args) { struct lcore_tid_cfg *cfg = lm_get_cfg(); - if (!cfg) - return 0; + if (!cfg) return 0; /* core id check */ - if (bpf_get_smp_processor_id() != cfg->core_id) - return 0; + if (bpf_get_smp_processor_id() != cfg->core_id) return 0; if (cfg->bpf_trace) { char fmt[] = "sys_enter: id %d\n"; diff --git a/tools/ebpf/lcore_monitor.c b/tools/ebpf/lcore_monitor.c index c8090f7f8..567c09ff7 100644 --- a/tools/ebpf/lcore_monitor.c +++ b/tools/ebpf/lcore_monitor.c @@ -53,8 +53,9 @@ static void lm_print_help() { printf(" Params:\n"); printf(" --lcore Set the monitor lcore\n"); printf(" --t_pid Set the monitor t_pid\n"); - printf(" --filter_us Report the sch/irq event only if the time > " - "filter_us\n"); + printf( + " --filter_us Report the sch/irq event only if the time > " + "filter_us\n"); printf(" --bpf_trace Enable bpf trace\n"); printf(" --help Print help info\n"); @@ -66,26 +67,25 @@ static int lm_parse_args(struct lcore_monitor_ctx *ctx, int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", et_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; switch (cmd) { - case LM_ARG_CORE: - ctx->cfg.core_id = atoi(optarg); - break; - case LM_ARG_T_PID: - ctx->cfg.t_pid = atoi(optarg); - break; - case LM_ARG_BPF_TRACE: - ctx->cfg.bpf_trace = true; - break; - case LM_ARG_FILTER_US: - ctx->filter_ns = atoi(optarg) * 1000; - break; - case LM_ARG_HELP: - default: - lm_print_help(); - return -1; + case LM_ARG_CORE: + ctx->cfg.core_id = atoi(optarg); + break; + case LM_ARG_T_PID: + ctx->cfg.t_pid = atoi(optarg); + break; + case LM_ARG_BPF_TRACE: + ctx->cfg.bpf_trace = true; + break; + case LM_ARG_FILTER_US: + ctx->filter_ns = atoi(optarg) * 1000; + break; + case LM_ARG_HELP: + default: + lm_print_help(); + return -1; } } @@ -98,16 +98,15 @@ static void lm_sig_handler(int signo) { info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + stop = true; + break; } return; } -static int get_process_name_by_pid(pid_t pid, char *process_name, - size_t max_len) { +static int get_process_name_by_pid(pid_t pid, char *process_name, size_t max_len) { char path[128]; FILE *fp; @@ -146,16 +145,14 @@ static int lm_event_handler(void *pri, void *data, size_t data_sz) { } if (e->type == LCORE_SCHED_IN) { float ns = e->ns - ctx->sched_out.ns; - if (ns < ctx->filter_ns) - return 0; + if (ns < ctx->filter_ns) return 0; int next_pid = ctx->sched_out.next_pid; char process_name[64]; ret = get_process_name_by_pid(next_pid, process_name, sizeof(process_name)); if (ret < 0) info("%s: sched out %.3fus as pid: %d\n", __func__, ns / 1000, next_pid); else - info("%s: sched out %.3fus as comm: %s\n", __func__, ns / 1000, - process_name); + info("%s: sched out %.3fus as comm: %s\n", __func__, ns / 1000, process_name); return 0; } @@ -166,8 +163,7 @@ static int lm_event_handler(void *pri, void *data, size_t data_sz) { } if (e->type == LCORE_IRQ_EXIT) { float ns = e->ns - ctx->irq_entry.ns; - if (ns < ctx->filter_ns) - return 0; + if (ns < ctx->filter_ns) return 0; info("%s: sched out %.3fus as irq: %d\n", __func__, ns / 1000, e->irq); return 0; } @@ -179,10 +175,8 @@ static int lm_event_handler(void *pri, void *data, size_t data_sz) { } if (e->type == LCORE_VECTOR_EXIT) { float ns = e->ns - ctx->vector_entry.ns; - if (ns < ctx->filter_ns) - return 0; - info("%s: sched out %.3fus as vector: %d\n", __func__, ns / 1000, - e->vector); + if (ns < ctx->filter_ns) return 0; + info("%s: sched out %.3fus as vector: %d\n", __func__, ns / 1000, e->vector); return 0; } @@ -193,8 +187,7 @@ static int lm_event_handler(void *pri, void *data, size_t data_sz) { } if (e->type == LCORE_SYS_EXIT) { float ns = e->ns - ctx->syscall.ns; - if (ns < ctx->filter_ns) - return 0; + if (ns < ctx->filter_ns) return 0; info("%s: syscall out %.3fus as syscall: %d\n", __func__, ns / 1000, e->id); return 0; } @@ -209,8 +202,7 @@ int main(int argc, char **argv) { memset(&ctx, 0, sizeof(ctx)); ret = lm_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (!ctx.cfg.core_id) { err("%s, no core id define\n", __func__); lm_print_help(); @@ -266,9 +258,7 @@ int main(int argc, char **argv) { info("%s, stop now\n", __func__); exit: - if (rb) - ring_buffer__free(rb); - if (skel) - lcore_monitor_bpf__destroy(skel); + if (rb) ring_buffer__free(rb); + if (skel) lcore_monitor_bpf__destroy(skel); return 0; } diff --git a/tools/ebpf/log.h b/tools/ebpf/log.h index 95698495c..14f724a96 100644 --- a/tools/ebpf/log.h +++ b/tools/ebpf/log.h @@ -10,26 +10,26 @@ /* log define */ #ifdef DEBUG -#define dbg(...) \ - do { \ - printf(__VA_ARGS__); \ +#define dbg(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #else -#define dbg(...) \ - do { \ +#define dbg(...) \ + do { \ } while (0) #endif -#define info(...) \ - do { \ - printf(__VA_ARGS__); \ +#define info(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define warn(...) \ - do { \ - printf(__VA_ARGS__); \ +#define warn(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) -#define err(...) \ - do { \ - printf(__VA_ARGS__); \ +#define err(...) \ + do { \ + printf(__VA_ARGS__); \ } while (0) #endif \ No newline at end of file diff --git a/tools/ebpf/udp_monitor.bpf.c b/tools/ebpf/udp_monitor.bpf.c index 086813db0..a789e419e 100644 --- a/tools/ebpf/udp_monitor.bpf.c +++ b/tools/ebpf/udp_monitor.bpf.c @@ -33,21 +33,17 @@ int bpf_socket_handler(struct __sk_buff *skb) { if (proto != ETH_P_IP) { /* not ipv4 */ return 0; } - bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, protocol), &ip_proto, - 1); + bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, protocol), &ip_proto, 1); if (ip_proto != IPPROTO_UDP) { /* not udp */ return 0; } e = bpf_ringbuf_reserve(&udp_hdr_rb, sizeof(*e), 0); - if (!e) - return 0; + if (!e) return 0; /* fill src and dst ip */ - bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, saddr), - &(e->tuple.src_ip), 4); - bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, daddr), - &(e->tuple.dst_ip), 4); + bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, saddr), &(e->tuple.src_ip), 4); + bpf_skb_load_bytes(skb, nhoff + offsetof(struct iphdr, daddr), &(e->tuple.dst_ip), 4); /* fill src and dst port */ bpf_skb_load_bytes(skb, nhoff + 0, &verlen, 1); bpf_skb_load_bytes(skb, nhoff + ((verlen & 0xF) << 2), &(e->tuple.ports), 4); diff --git a/tools/ebpf/udp_monitor.c b/tools/ebpf/udp_monitor.c index 8c5ca69e8..3df2555b4 100644 --- a/tools/ebpf/udp_monitor.c +++ b/tools/ebpf/udp_monitor.c @@ -63,8 +63,7 @@ static struct option um_args_options[] = { static inline void *um_zmalloc(size_t sz) { void *p = malloc(sz); - if (p) - memset(p, 0x0, sz); + if (p) memset(p, 0x0, sz); return p; } @@ -99,50 +98,47 @@ static int um_parse_args(struct udp_monitor_ctx *ctx, int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", um_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; switch (cmd) { - case UM_ARG_INTERFACE: - ctx->interface = optarg; - break; - case UM_ARG_DUMP_PERIOD_S: - ctx->dump_period_s = atoi(optarg); - break; - case UM_ARG_NO_SKIP_SYS: - ctx->skip_sys = false; - break; - case UM_ARG_NO_PROMISC: - ctx->promisc = false; - break; - case UM_ARG_HELP: - default: - um_print_help(); - return -1; + case UM_ARG_INTERFACE: + ctx->interface = optarg; + break; + case UM_ARG_DUMP_PERIOD_S: + ctx->dump_period_s = atoi(optarg); + break; + case UM_ARG_NO_SKIP_SYS: + ctx->skip_sys = false; + break; + case UM_ARG_NO_PROMISC: + ctx->promisc = false; + break; + case UM_ARG_HELP: + default: + um_print_help(); + return -1; } } return 0; } -static int udp_hdr_list_dump(struct udp_monitor_ctx *ctx, bool clear, - bool skip_sys, double dump_period_s) { +static int udp_hdr_list_dump(struct udp_monitor_ctx *ctx, bool clear, bool skip_sys, + double dump_period_s) { struct udp_detect_list *list = &ctx->detect; struct udp_detect_entry *entry; TAILQ_FOREACH(entry, list, next) { - if (!entry->pkt_cnt) - continue; - if (skip_sys && entry->sys) - continue; + if (!entry->pkt_cnt) continue; + if (skip_sys && entry->sys) continue; uint8_t *dip = (uint8_t *)&entry->tuple.dst_ip; uint8_t *sip = (uint8_t *)&entry->tuple.src_ip; double rate_m = (double)entry->tx_bytes * 8 / dump_period_s / (1000 * 1000); - info("%u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, %f Mb/s pkts %u\n", sip[0], sip[1], - sip[2], sip[3], ntohs(entry->tuple.src_port), dip[0], dip[1], dip[2], - dip[3], ntohs(entry->tuple.dst_port), rate_m, entry->pkt_cnt); + info("%u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, %f Mb/s pkts %u\n", sip[0], sip[1], sip[2], + sip[3], ntohs(entry->tuple.src_port), dip[0], dip[1], dip[2], dip[3], + ntohs(entry->tuple.dst_port), rate_m, entry->pkt_cnt); if (clear) { entry->pkt_cnt = 0; entry->tx_bytes = 0; @@ -160,9 +156,9 @@ static int udp_hdr_entry_handler(void *pri, void *data, size_t data_sz) { uint8_t *dip = (uint8_t *)&e->tuple.dst_ip; uint8_t *sip = (uint8_t *)&e->tuple.src_ip; - dbg("%s, %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", __func__, sip[0], - sip[1], sip[2], sip[3], ntohs(e->tuple.src_port), dip[0], dip[1], dip[2], - dip[3], ntohs(e->tuple.dst_port), e->len); + dbg("%s, %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", __func__, sip[0], sip[1], sip[2], + sip[3], ntohs(e->tuple.src_port), dip[0], dip[1], dip[2], dip[3], + ntohs(e->tuple.dst_port), e->len); /* check if any exist */ TAILQ_FOREACH(entry, list, next) { @@ -182,16 +178,14 @@ static int udp_hdr_entry_handler(void *pri, void *data, size_t data_sz) { entry->pkt_cnt++; entry->tx_bytes += e->len; /* 224.0.1.129 */ - if (dip[0] == 224 && dip[1] == 0 && dip[2] == 1 && dip[3] == 129) - entry->sys = true; + if (dip[0] == 224 && dip[1] == 0 && dip[2] == 1 && dip[3] == 129) entry->sys = true; /* 255.255.255.255 */ - if (dip[0] == 255 && dip[1] == 255 && dip[2] == 255 && dip[3] == 255) - entry->sys = true; + if (dip[0] == 255 && dip[1] == 255 && dip[2] == 255 && dip[3] == 255) entry->sys = true; /* add to list */ TAILQ_INSERT_TAIL(list, entry, next); - info("%s, new detected stream: %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", - __func__, sip[0], sip[1], sip[2], sip[3], ntohs(e->tuple.src_port), - dip[0], dip[1], dip[2], dip[3], ntohs(e->tuple.dst_port), e->len); + info("%s, new detected stream: %u.%u.%u.%u:%u -> %u.%u.%u.%u:%u, len %u\n", __func__, + sip[0], sip[1], sip[2], sip[3], ntohs(e->tuple.src_port), dip[0], dip[1], dip[2], + dip[3], ntohs(e->tuple.dst_port), e->len); return 0; } @@ -201,8 +195,7 @@ static int open_raw_sock(const char *if_name) { int fd; int ret; - fd = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, - htons(ETH_P_ALL)); + fd = socket(PF_PACKET, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, htons(ETH_P_ALL)); if (fd < 0) { err("%s, failed to create raw socket\n", __func__); return -1; @@ -214,8 +207,7 @@ static int open_raw_sock(const char *if_name) { sll.sll_protocol = htons(ETH_P_ALL); ret = bind(fd, (struct sockaddr *)&sll, sizeof(sll)); if (ret < 0) { - err("%s, failed to bind to %s: %d, %s\n", __func__, if_name, ret, - strerror(errno)); + err("%s, failed to bind to %s: %d, %s\n", __func__, if_name, ret, strerror(errno)); close(fd); return ret; } @@ -256,9 +248,9 @@ static void um_sig_handler(int signo) { info("%s, signal %d\n", __func__, signo); switch (signo) { - case SIGINT: /* Interrupt from keyboard */ - g_um_stop = true; - break; + case SIGINT: /* Interrupt from keyboard */ + g_um_stop = true; + break; } return; @@ -280,8 +272,7 @@ int main(int argc, char **argv) { ctx.promisc = true; ret = um_parse_args(&ctx, argc, argv); - if (ret < 0) - return ret; + if (ret < 0) return ret; if (!ctx.interface) { err("%s, no interface assigned\n", __func__); um_print_help(); @@ -324,28 +315,27 @@ int main(int argc, char **argv) { /* Attach BPF program to raw socket */ prog_fd = bpf_program__fd(skel->progs.bpf_socket_handler); - ret = setsockopt(sock_raw_fd, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd, - sizeof(prog_fd)); + ret = setsockopt(sock_raw_fd, SOL_SOCKET, SO_ATTACH_BPF, &prog_fd, sizeof(prog_fd)); if (ret < 0) { err("%s, failed attach to raw socket %d\n", __func__, ret); goto exit; } - info("%s, attach bpf skeleton to %s succ, sock_raw_fd %d\n", __func__, - ctx.interface, sock_raw_fd); + info("%s, attach bpf skeleton to %s succ, sock_raw_fd %d\n", __func__, ctx.interface, + sock_raw_fd); if (ctx.promisc) { ret = enable_promisc(sock_fd, ctx.interface, 1); if (ret < 0) { err("%s, failed to enable promisc %d\n", __func__, ret); goto exit; } - info("%s, enable promisc for %s succ, sock_fd %d\n", __func__, - ctx.interface, sock_fd); + info("%s, enable promisc for %s succ, sock_fd %d\n", __func__, ctx.interface, + sock_fd); } signal(SIGINT, um_sig_handler); - info("%s, start to poll udp pkts for %s, dump period %ds\n", __func__, - ctx.interface, ctx.dump_period_s); + info("%s, start to poll udp pkts for %s, dump period %ds\n", __func__, ctx.interface, + ctx.dump_period_s); last_ns = um_get_monotonic_time(); while (!g_um_stop) { ret = ring_buffer__poll(rb, 100); @@ -370,18 +360,13 @@ int main(int argc, char **argv) { } info("%s, stop now\n", __func__); - if (sock_fd >= 0) - enable_promisc(sock_fd, ctx.interface, 0); + if (sock_fd >= 0) enable_promisc(sock_fd, ctx.interface, 0); exit: - if (rb) - ring_buffer__free(rb); - if (skel) - udp_monitor_bpf__destroy(skel); - if (sock_fd >= 0) - close(sock_fd); - if (sock_raw_fd >= 0) - close(sock_raw_fd); + if (rb) ring_buffer__free(rb); + if (skel) udp_monitor_bpf__destroy(skel); + if (sock_fd >= 0) close(sock_fd); + if (sock_raw_fd >= 0) close(sock_raw_fd); /* free all entries in list */ struct udp_detect_entry *entry; diff --git a/tools/readpcap/readpcap.c b/tools/readpcap/readpcap.c index 5a840364f..b0d95c833 100644 --- a/tools/readpcap/readpcap.c +++ b/tools/readpcap/readpcap.c @@ -16,7 +16,7 @@ #include #define NS_PER_S 1000000000 -#define TR_OFFSET_NS (500 * 1000) // 500us +#define TR_OFFSET_NS (500 * 1000) // 500us static inline uint64_t TimespecToNs(const struct timeval *ts) { return ((uint64_t)ts->tv_sec * NS_PER_S) + ts->tv_usec; @@ -62,8 +62,8 @@ int main(int argc, char **argv) { printf("target_frame %d\n", g_target_frame_idx); } - fp = pcap_open_offline_with_tstamp_precision( - argv[1], PCAP_TSTAMP_PRECISION_NANO, errbuf); + fp = pcap_open_offline_with_tstamp_precision(argv[1], PCAP_TSTAMP_PRECISION_NANO, + errbuf); if (fp == NULL) { fprintf(stderr, "pcap_open_offline() failed: %s\n", errbuf); return 0; diff --git a/tools/readpcap/readpcap_31.c b/tools/readpcap/readpcap_31.c index 30ebb513e..3f350bc66 100644 --- a/tools/readpcap/readpcap_31.c +++ b/tools/readpcap/readpcap_31.c @@ -75,9 +75,8 @@ static int g_pkt_idx = 0; void packetHandler(uint8_t *userData, const struct pcap_pkthdr *pkthdr, const uint8_t *packet) { struct user_data *ud = (struct user_data *)userData; - uint8_t *payload = packet + sizeof(struct ether_header) + - sizeof(struct iphdr) + sizeof(struct udphdr) + - RFC3550_RTP_HDR_LEN; + uint8_t *payload = packet + sizeof(struct ether_header) + sizeof(struct iphdr) + + sizeof(struct udphdr) + RFC3550_RTP_HDR_LEN; uint16_t payload_len = pkthdr->len - sizeof(struct ether_header) - sizeof(struct iphdr) - sizeof(struct udphdr) - RFC3550_RTP_HDR_LEN; @@ -86,20 +85,19 @@ void packetHandler(uint8_t *userData, const struct pcap_pkthdr *pkthdr, return; } int num_subframes = payload_len / 4; - int sample_per_packet = 48; // 48khz, 1ms packet time + int sample_per_packet = 48; // 48khz, 1ms packet time int num_channels = num_subframes / sample_per_packet; - printf("pkt %d, %d subframes of %d channels\n", g_pkt_idx, num_subframes, - num_channels); + printf("pkt %d, %d subframes of %d channels\n", g_pkt_idx, num_subframes, num_channels); am824_t *am = (am824_t *)payload; for (int i = 0; i < num_subframes; i++) { uint32_t am_32 = *(uint32_t *)am; - printf("pkt %d, subframe %d, hex: %08x, channel bit: %u\n", g_pkt_idx, i, - am_32, am->c); + printf("pkt %d, subframe %d, hex: %08x, channel bit: %u\n", g_pkt_idx, i, am_32, + am->c); if (am->f) { printf("pkt %d, subframe %d, first subframe of frame\n", g_pkt_idx, i); if (am->b) { - printf("pkt %d, subframe %d, first subframe of block %08x\n", g_pkt_idx, - i, am_32); + printf("pkt %d, subframe %d, first subframe of block %08x\n", g_pkt_idx, i, + am_32); } } diff --git a/tools/sch_smi_emulate/sch_smi_emulate.c b/tools/sch_smi_emulate/sch_smi_emulate.c index 85a2dba69..e39ff56c4 100644 --- a/tools/sch_smi_emulate/sch_smi_emulate.c +++ b/tools/sch_smi_emulate/sch_smi_emulate.c @@ -36,18 +36,17 @@ static int se_parse_args(struct se_context *ctx, int argc, char **argv) { while (1) { cmd = getopt_long_only(argc, argv, "hv", se_args_options, &opt_idx); - if (cmd == -1) - break; + if (cmd == -1) break; switch (cmd) { - case SE_ARG_SLEEP_MS: - ctx->sleep_time_ms = atoi(optarg); - break; - case SE_ARG_WORK_US: - ctx->work_time_us = atoi(optarg); - break; - default: - break; + case SE_ARG_SLEEP_MS: + ctx->sleep_time_ms = atoi(optarg); + break; + case SE_ARG_WORK_US: + ctx->work_time_us = atoi(optarg); + break; + default: + break; } }; @@ -71,8 +70,7 @@ static int se_loop(struct se_context *ctx) { uint64_t start, end; volatile int sum; - printf("sleep_time_ms %d work_time_us %d\n", ctx->sleep_time_ms, - ctx->work_time_us); + printf("sleep_time_ms %d work_time_us %d\n", ctx->sleep_time_ms, ctx->work_time_us); while (1) { usleep(ctx->sleep_time_ms * 1000); From df03a283b8227b7fc76779637d493bda5fdda38b Mon Sep 17 00:00:00 2001 From: zLukas Date: Tue, 25 Feb 2025 12:40:44 +0000 Subject: [PATCH 33/35] diable cpp lint --- .github/workflows/linter.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 0a889040a..d7755d646 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -33,6 +33,7 @@ jobs: env: DEFAULT_BRANCH: main + VALIDATE_CPP: false # conflicts with clang-format VALIDATE_JSCPD: false VALIDATE_JSON: false VALIDATE_JSON_PRETTIER: false From f57ed2dee1f48d9218ecaeaa3ff88a1023181bed Mon Sep 17 00:00:00 2001 From: zLukas Date: Tue, 25 Feb 2025 12:45:46 +0000 Subject: [PATCH 34/35] update format-coding.sh --- format-coding.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/format-coding.sh b/format-coding.sh index 640307e3a..3e8f7200b 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -18,6 +18,6 @@ find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymt # clean-up the copied .clang-format rm -rf .clang-format -# CONFIG=".github/linters/.pyproject.toml" -# black --config "$CONFIG" python/ -# isort --settings-path "$CONFIG" python/ +CONFIG=".github/linters/.pyproject.toml" +black --config "$CONFIG" python/ +isort --settings-path "$CONFIG" python/ From 9f8f0bb8ce7cfa10256f13fef897048ad4142ebd Mon Sep 17 00:00:00 2001 From: zLukas Date: Tue, 25 Feb 2025 12:56:50 +0000 Subject: [PATCH 35/35] update format-coding.sh --- format-coding.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/format-coding.sh b/format-coding.sh index 3e8f7200b..71d4ff758 100755 --- a/format-coding.sh +++ b/format-coding.sh @@ -13,11 +13,10 @@ cp .github/linters/.clang-format .clang-format echo "clang-format check" find . -path ./build -prune -o -regex '.*\.\(cpp\|hpp\|cc\|c\|h\)' ! -name 'pymtl_wrap.c' \ - ! -name 'vmlinux.h' ! -name '.clang-format' \ - -exec clang-format-17 --verbose -i {} + + ! -name 'vmlinux.h' ! -name '.clang-format' -exec clang-format-17 --verbose -i {} + # clean-up the copied .clang-format -rm -rf .clang-format +rm .clang-format CONFIG=".github/linters/.pyproject.toml" black --config "$CONFIG" python/ isort --settings-path "$CONFIG" python/