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

Add pthread_[s,g]etschedparam to emscripten. #2764

Closed

Conversation

iddm
Copy link
Contributor

@iddm iddm commented Apr 20, 2022

Closes #2754

The functions are available in emscripten when built with the posix threads support.

@rust-highfive
Copy link

r? @Amanieu

(rust-highfive has picked a reviewer for you, use r? to override)

@Amanieu
Copy link
Member

Amanieu commented Apr 20, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Apr 20, 2022

📌 Commit c79cb77 has been approved by Amanieu

bors added a commit that referenced this pull request Apr 20, 2022
…, r=Amanieu

Add pthread_[s,g]etschedparam to emscripten.

Closes #2754

The functions are available in emscripten when built with the posix threads support.
@bors
Copy link
Contributor

bors commented Apr 20, 2022

⌛ Testing commit c79cb77 with merge 108086c...

@bors
Copy link
Contributor

bors commented Apr 20, 2022

💔 Test failed - checks-actions

@iddm
Copy link
Contributor Author

iddm commented Apr 20, 2022

This

  = note: error: undefined symbol: pthread_getschedparam (referenced by top-level compiled C/C++ code)
          warning: Link with `-s LLD_REPORT_UNDEFINED` to get more information on undefined symbols
          warning: To disable errors for undefined symbols use `-s ERROR_ON_UNDEFINED_SYMBOLS=0`
          warning: _pthread_getschedparam may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
          error: undefined symbol: pthread_setschedparam (referenced by top-level compiled C/C++ code)
          warning: _pthread_setschedparam may need to be added to EXPORTED_FUNCTIONS if it arrives from a system library
          Error: Aborting compilation due to previous errors
          emcc: error: '/emsdk-portable/node/14.18.2_64bit/bin/node /emsdk-portable/upstream/emscripten/src/compiler.js /tmp/tmpfh4ef_lb.txt' failed (1)

makes sense in case the emscripten toolchain used in CI isn't told to use enable POSIX threads, and it is disabled by default The corresponding flag isn't given to emcc (-pthread) as far as I can see:

  = note: "emcc" "-s" "EXPORTED_FUNCTIONS=[\"_main\",\"_rust_eh_personality\"]" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.15up094qcbttvavh.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1764296d69jw2f8d.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1iblvzh99ot608co.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1mhlpcdn3o6xmbi5.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1nqlg58sutxkw6xc.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1p2n0hothx4ifin8.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1qc3w1uoer7fxk7b.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1qlv5m8yet8jal14.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1slwe4dr2hj06m2n.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.1w78sdxeej4gizs1.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.20tqbu2opnze7gt1.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.20wjitnl87abxvd0.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.217c8yajhuekok9a.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.28mvypeibnj7qgmn.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2fmczgu5fdu7us9o.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2jh71x3v3ng5oj6g.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2k3pfr0u62ccfa3q.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2lqonn2c4vmrk0l4.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2mim7diqip0r5vf1.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2o5559z2cfybbmk5.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2r0f5lmrx4z2wcmx.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2sd7ykl2dmm5kl7.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2ufjjik0exjac0n3.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2ulh7iroqpzy4poq.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2vxyhjbrw2qw6fu6.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2zq08zltcvo6ofrw.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.2zwahbku9g16jfv8.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.30ged4r4qg85kuq4.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.33o9j8bvj0icjb0i.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.37auzv0atd9yslcc.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.395g36lt9yh2c9rq.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3avya9j7hpfqx0nr.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3gqtcqqkxn47fwa7.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3hvghmz8lou3wnvr.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3kmh7ke2nlkk2g5r.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3n7og1rcboxo8l7i.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3p3u6w627yedykbc.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3vuy95k50imnmt8t.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.3w2u7iis5kh3ul2a.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.407cp6oeym8pl4fz.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.41b5kfqb4ttnse06.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.4d9e5hsq1bjdmvgt.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.4ilqj9uxv8f0peno.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.4mjzs7hfiy28s9q8.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.4nehgudgwr3mnphr.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.4tpmul9eubs6hh2q.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.59zey53gu8mas9qa.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.5c60rf054ozpp282.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.96e5k3dcpz0i39g.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.9gf1g2zww9khqia.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.da1b3qbby0jeoqr.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.iw7zp63dmp10h4w.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.ktiw7xywr9i22xj.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.lxcpmfamvkp15zl.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.n751hpa3xw5suny.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.vssba9843xh6spm.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.xh7mvwu0xcjmryj.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.zntepvn7f4p2ytp.rcgu.o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.ry0tav4az6k7gzn.rcgu.o" "-L" "/checkout/target/asmjs-unknown-emscripten/debug/deps" "-L" "/checkout/target/debug/deps" "-L" "/checkout/target/asmjs-unknown-emscripten/debug/build/libc-test-88d6cfa08cd77c60/out" "-L" "/checkout/target/asmjs-unknown-emscripten/debug/build/libc-test-88d6cfa08cd77c60/out" "-L" "/checkout/target/asmjs-unknown-emscripten/debug/build/libc-test-88d6cfa08cd77c60/out" "-L" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib" "-l" "cmsg" "-l" "sigrt" "-l" "main" "/checkout/target/asmjs-unknown-emscripten/debug/deps/liblibc-803239beef365e58.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libstd-65853ace44efd19c.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libpanic_unwind-3393e8338a4a0402.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/librustc_demangle-0ae527806e877ad1.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libstd_detect-db0fa1dfd9ce2ef5.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libhashbrown-cca9e4f20e1b16d7.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libminiz_oxide-a09d3f7f20256a3a.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libadler-ce5964b7ff78a2e1.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/librustc_std_workspace_alloc-c9d9376a47434381.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libunwind-1f32e1499c7b643e.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libcfg_if-b22cfd8171a41dec.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/liblibc-43bf4d086d5731a6.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/liballoc-ed0edd4f4b249fc5.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/librustc_std_workspace_core-0c6f27c724e91f00.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libcore-51fab1e142b49950.rlib" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/libcompiler_builtins-ad37fc26255f89b3.rlib" "-l" "c" "-s" "DISABLE_EXCEPTION_CATCHING=0" "-L" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib" "-L" "/rust/lib/rustlib/asmjs-unknown-emscripten/lib/self-contained" "-o" "/checkout/target/asmjs-unknown-emscripten/debug/deps/main-f141af560535c5c3.js" "-O0" "--memory-init-file" "0" "-g4" "-s" "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]" "-s" "ERROR_ON_UNDEFINED_SYMBOLS=1" "-s" "ASSERTIONS=1" "-s" "ABORTING_MALLOC=0" "-Wl,--fatal-warnings" "-s" "WASM=0"

I am curious, however, how does the pthread_create is there in the same file and links fine if this is the case?

Here is the code that works with emscripten on my machine:

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void *thread_callback()
{
    sleep(1);
    printf("Inside the thread.\n");
    return NULL;
}

int main()
{
    pthread_t thread_id;
    pthread_create(&thread_id, NULL, thread_callback, NULL);
    int policy = 0;
    struct sched_param param;
    pthread_getschedparam(thread_id, &policy, &param);
    printf("Thread policy=%d, param.prio=%d\n", policy, param.sched_priority);
    param.sched_priority = 50;
    pthread_setschedparam(thread_id, SCHED_FIFO, &param);
    pthread_getschedparam(thread_id, &policy, &param);
    printf("New thread policy=%d, param.prio=%d\n", policy, param.sched_priority);
    pthread_join(thread_id, NULL);

    return 0;
}

Compiling with emcc -pthread -s PTHREAD_POOL_SIZE=1 tt.c -o tt.js gives:

❯ node tt.js
Thread policy=0, param.prio=0
New thread policy=0, param.prio=50
Inside the thread.

@Amanieu
Copy link
Member

Amanieu commented Apr 22, 2022

To add a compiler flag to the C API checker, you need to add cfg.flag("-pthread") in libc-test/build.rs in the emscripten section.

However it could also be the case that the emcc version we are using in tests is too old. You can see this in ci/emscripten.sh which installs version 1.39.20.

@iddm
Copy link
Contributor Author

iddm commented Apr 22, 2022

Thanks a lot for your help! I'll try adding the pthread flag there.

@Amanieu
Copy link
Member

Amanieu commented Apr 22, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Apr 22, 2022

📌 Commit e4f4684 has been approved by Amanieu

bors added a commit that referenced this pull request Apr 22, 2022
…, r=Amanieu

Add pthread_[s,g]etschedparam to emscripten.

Closes #2754

The functions are available in emscripten when built with the posix threads support.
@bors
Copy link
Contributor

bors commented Apr 22, 2022

⌛ Testing commit e4f4684 with merge 73ad8ae...

@bors
Copy link
Contributor

bors commented Apr 22, 2022

💔 Test failed - checks-actions

@iddm
Copy link
Contributor Author

iddm commented Apr 22, 2022

Added the --shared_memory flag, let's see if it helps to address this:

  = note: wasm-ld: error: 'atomics' feature is used by main.o, so --shared-memory must be used

@iddm iddm force-pushed the add-more-posix-functions-for-emscripten branch from 78c2146 to 94b7c5e Compare April 22, 2022 14:28
@Amanieu
Copy link
Member

Amanieu commented Apr 22, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Apr 22, 2022

📌 Commit 94b7c5e has been approved by Amanieu

@bors
Copy link
Contributor

bors commented Sep 13, 2022

💔 Test failed - checks-actions

@iddm iddm force-pushed the add-more-posix-functions-for-emscripten branch from d4197b0 to 1515dd0 Compare September 13, 2022 09:52
@iddm
Copy link
Contributor Author

iddm commented Sep 13, 2022

I am sorry, all successful checks, or am I seeing it wrong?
I guess something didn't run and we need another "@bors try"?

@JohnTitor
Copy link
Member

Yeah, we don't run all the jobs on PR but do on bors as the number is huge and take a lot of time.
@bors delegate+

Now you can use @bors try, feel free to debug and ping me once it passes.

@bors
Copy link
Contributor

bors commented Sep 13, 2022

✌️ @vityafx can now approve this pull request

@iddm
Copy link
Contributor Author

iddm commented Sep 13, 2022

@JohnTitor Thanks!

@bors try

@bors
Copy link
Contributor

bors commented Sep 13, 2022

⌛ Trying commit 1515dd0 with merge c7a42c4...

bors added a commit that referenced this pull request Sep 13, 2022
…, r=<try>

Add pthread_[s,g]etschedparam to emscripten.

Closes #2754

The functions are available in emscripten when built with the posix threads support.
@bors
Copy link
Contributor

bors commented Sep 13, 2022

💔 Test failed - checks-actions

@iddm iddm force-pushed the add-more-posix-functions-for-emscripten branch from 1515dd0 to 78a91f3 Compare September 13, 2022 13:23
@iddm
Copy link
Contributor Author

iddm commented Sep 13, 2022

@bors try

@bors
Copy link
Contributor

bors commented Sep 13, 2022

⌛ Trying commit 78a91f3 with merge f15a98e...

bors added a commit that referenced this pull request Sep 13, 2022
…, r=<try>

Add pthread_[s,g]etschedparam to emscripten.

Closes #2754

The functions are available in emscripten when built with the posix threads support.
@bors
Copy link
Contributor

bors commented Sep 13, 2022

💔 Test failed - checks-actions

This should enable pthread functionality for emcc.
@iddm iddm force-pushed the add-more-posix-functions-for-emscripten branch from 78a91f3 to 43fba40 Compare September 13, 2022 14:46
@iddm
Copy link
Contributor Author

iddm commented Sep 13, 2022

@bors try

bors added a commit that referenced this pull request Sep 13, 2022
…, r=<try>

Add pthread_[s,g]etschedparam to emscripten.

Closes #2754

The functions are available in emscripten when built with the posix threads support.
@bors
Copy link
Contributor

bors commented Sep 13, 2022

⌛ Trying commit 43fba40 with merge ff8f5ce...

@bors
Copy link
Contributor

bors commented Sep 13, 2022

💔 Test failed - checks-actions

@iddm
Copy link
Contributor Author

iddm commented Sep 13, 2022

@iddm
Copy link
Contributor Author

iddm commented Sep 13, 2022

@bors try

@bors
Copy link
Contributor

bors commented Sep 13, 2022

⌛ Trying commit 43fba40 with merge 5d60243...

bors added a commit that referenced this pull request Sep 13, 2022
…, r=<try>

Add pthread_[s,g]etschedparam to emscripten.

Closes #2754

The functions are available in emscripten when built with the posix threads support.
@bors
Copy link
Contributor

bors commented Sep 13, 2022

💔 Test failed - checks-actions

@bors
Copy link
Contributor

bors commented Sep 28, 2022

☔ The latest upstream changes (presumably #2915) made this pull request unmergeable. Please resolve the merge conflicts.

@JohnTitor
Copy link
Member

Friendly-ping @vityafx, are still working on this?

@iddm
Copy link
Contributor Author

iddm commented Mar 3, 2023

No, not anymore. I'd like someone having more knowledge of how the libc crate is organised to finish the job. I have already done what I could and it has taken too much time digging all of this alone.

@JohnTitor
Copy link
Member

I'm going to close this then. Thanks for clarifying and submitting a PR anyway!

@JohnTitor JohnTitor closed this Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support pthread scheduling functions for WASM
5 participants