Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(heaphook_rust): add aligned alloc #226

Merged
merged 6 commits into from
Oct 7, 2024
Merged

feat(heaphook_rust): add aligned alloc #226

merged 6 commits into from
Oct 7, 2024

Conversation

veqcc
Copy link
Contributor

@veqcc veqcc commented Oct 6, 2024

Description

heaphook_rust に、alignment に関する命令3つ(posix_memalign, aligned_alloc, memalign)を追加しました。
それに伴い、free と realloc の処理も alignment に対応したものに修正しました。

Related links

How was this PR tested?

  • sample application (required)
  • Autoware (required)

Autoware の pointcloud container が動作することを確認。具体的には、プロセスが死なずに Lsim tutorial で ego が最後まで走ることを確認した。

設定 pointcloud_container.launch.py

def launch_setup(context, *args, **kwargs):
    glog_component = ComposableNode(
        package="glog_component",
        plugin="GlogComponent",
        name="glog_component",
        namespace="pointcloud_container",
    )

    pointcloud_container = ComposableNodeContainer(
        name=LaunchConfiguration("container_name"),
        namespace="/",
        package="rclcpp_components",
        executable=LaunchConfiguration("container_executable"),
        composable_node_descriptions=[glog_component],
        output="both",
    )

    return [
        GroupAction(actions=[
            SetEnvironmentVariable(name="LD_PRELOAD", value="./src/agnocast/src/agnocast_heaphook_rust/target/debug/libagnocast_heaphook_rust.so"),
            SetEnvironmentVariable(name="MEMPOOL_SIZE", value="10737418240"), # 10.24GB
            pointcloud_container
        ])
    ]


def generate_launch_description():
    ...
    return LaunchDescription(
        [
            add_launch_arg("use_multithread", "false"),
            add_launch_arg("container_name", "pointcloud_container"),
            set_container_executable,
            set_container_mt_executable,
            # pointcloud_container
        ]
        + [OpaqueFunction(function=launch_setup)]
    )

Notes for reviewers

以下の部分がどうしても clippy の警告を回避できず、
#[allow(clippy::not_unsafe_ptr_arg_deref)] によって無理やり回避しています。代替案があれば。

unsafe { *memptr = aligned_alloc_wrapped(alignment, size) };

Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
veqcc added 3 commits October 7, 2024 10:41
Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
@atsushi421
Copy link
Contributor

@veqcc
output.txtがcommitされてしまったみたいです

Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
@veqcc
Copy link
Contributor Author

veqcc commented Oct 7, 2024

@atsushi421
ありがとうございます!消しました!

@Koichi98
Copy link
Contributor

Koichi98 commented Oct 7, 2024

以下の部分がどうしても clippy の警告を回避できず、
#[allow(clippy::not_unsafe_ptr_arg_deref)] によって無理やり回避しています。代替案があれば。
unsafe { *memptr = aligned_alloc_wrapped(alignment, size) };

この件、posix_memalign()とPosixMemalignTypeの第一引数の型を&mut *mut c_voidにすれば解決しそうなんですが、それでちゃんとposix_memalignをフックできるか確認していないのでそちらお願いできると助かります!(もしすでに試されてたらすみません)

atsushi421
atsushi421 previously approved these changes Oct 7, 2024
Signed-off-by: veqcc <ryuta.kambe@tier4.jp>
@veqcc
Copy link
Contributor Author

veqcc commented Oct 7, 2024

@Koichi98

この件、posix_memalign()とPosixMemalignTypeの第一引数の型を&mut *mut c_voidにすれば解決しそうなんですが、それでちゃんとposix_memalignをフックできるか確認していないのでそちらお願いできると助かります!(もしすでに試されてたらすみません)

こちらで動作確認しました!大丈夫そうです
90f908e

@veqcc veqcc added the run-build-test Run build-test in CI label Oct 7, 2024
@veqcc veqcc merged commit 16251cb into main Oct 7, 2024
4 checks passed
@veqcc veqcc deleted the feat/aligned_alloc branch October 7, 2024 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-build-test Run build-test in CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants