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

lib/*: Add syscall interfaces for dotnet runtime #1004

Closed
wants to merge 2 commits into from

Conversation

i-Pear
Copy link
Member

@i-Pear i-Pear commented Jul 25, 2023

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Description of changes

Stub the following syscall interfaces for dotnet runtime 7.0:

  • posix-mmap: SYS_mlock and SYS_msync
  • uksched: SYS_sched_getaffinity and SYS_sched_setaffinity

@i-Pear i-Pear marked this pull request as ready for review July 25, 2023 17:35
@i-Pear i-Pear requested review from a team as code owners July 25, 2023 17:35
@razvand razvand requested review from RaduNichita and StefanJum and removed request for a team July 25, 2023 18:03
@razvand razvand self-assigned this Jul 25, 2023
@razvand razvand added kind/enhancement New feature or request area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ topic/mm Topics pertaining to memory management topic/scheduling Topics pertaining to task scheduling topic/syscall Related to syscalls labels Jul 25, 2023
@razvand razvand added this to the v0.14.0 (Prometheus) milestone Jul 25, 2023
Copy link
Member

@StefanJum StefanJum left a comment

Choose a reason for hiding this comment

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

Thank you for this @i-Pear.
Please add a UK_WARN_STUBBED() in the stubbed syscalls (see an example here) and wrap the commit messages to ~50 characters per line.

Also, does the dotnet require the syscalls to return success? If not I would do an errno = ENOTSUP; return -1 where it is the case.

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

@StefanJum Thanks for your review. msync doesn't need to return success, so I changed it to -ENOTSUP. But others must return 0 to prevent the dotnet runtime from crashing.

@mschlumpp
Copy link
Member

msync doesn't need to return success, so I changed it to -ENOTSUP.

I think we should return zero from msync. It's unlikely that it breaks anything and we don't run into issues where software only checks for the documented error codes.

@StefanJum
Copy link
Member

I think we should return zero from msync. It's unlikely that it breaks anything and we don't run into issues where software only checks for the documented error codes.

Agree. I was a bit worried about the mknodat returning 0, the others I doubt will matter that much.

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

Changed msync to return zero.
The mknodat is for the dotnet runtime to create /tmp/clr-debug-pipe, seems to be pipes for connecting to the debugger.

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

I found that adding env COMPlus_EnableDiagnostics=0 can prevent creating these debug pipes. So just assert users will add this env, and remove mknodat from this PR? @StefanJum

However, I realize that the design of debugging through pipes is quite interesting. This means that we might be able to debug dotnet programs in unikernels, which is challenging to achieve with other languages.

@StefanJum
Copy link
Member

I found that adding env COMPlus_EnableDiagnostics=0 can prevent creating these debug pipes. So just assert users will add this env, and remove mknodat from this PR? @StefanJum

Yes, I think that would be safer than stubbing mknodat, just have the users set the env variable in the elfloader config.
Any thoughts @mschlumpp @razvand?

@i-Pear if this is selectable (via an env variable), could there be a way to completely disable it in the dotnet configuration step?

However, I realize that the design of debugging through pipes is quite interesting. This means that we might be able to debug dotnet programs in unikernels, which is challenging to achieve with other languages.

That would be nice indeed, it would require a proper implementation of mknodat though.

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

if this is selectable (via an env variable), could there be a way to completely disable it in the dotnet configuration step?

Do you mean build our own dotnet framework? I think it will be easy to modify the default value in the source code, if you think this is worth. As the number of applications grows, we might find ourselves in need of developing our own package manager to effectively manage them.

&& update: removed mknodat from this PR.

@StefanJum
Copy link
Member

Do you mean build our own dotnet framework? I think it will be easy to modify the default value in the source code, if you think this is worth. As the number of applications grows, we might find ourselves in need of developing our own package manager to effectively manage them.

We do have (or soon will have, I don't think there are any merged yet) dynamic apps that are build from source (this pr for example).
I think we could do the same here, provide a script that does everything, and in the end have 2 versions in the dynamic-apps repo, the one you opened a pr for, already built, where you will need to set the env variable, and the one that will be build from source.

In the meantime, we'll just state in the dynamic-apps/lang/c-sharp/README.md file that COMPlus_EnableDiagnostics=0 needs to be set.

Copy link
Member

@StefanJum StefanJum left a comment

Choose a reason for hiding this comment

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

Looks fine @i-Pear, just one more comment below.

lib/uksched/Makefile.uk Outdated Show resolved Hide resolved
@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

Looks fine @i-Pear, just one more comment below.

Fixed. Besides, while porting ASP.NET, I found it uses sched_getaffinity to get ncpus, and it must > 0, which cost me a lot of time. I think it would be better to return a positive value, while not having imported the affinity related functions and headers.

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

I think we could do the same here, provide a script that does everything, and in the end have 2 versions in the dynamic-apps repo, the one you opened a pr for, already built, where you will need to set the env variable, and the one that will be build from source.

It works. For backup:

  • Change EXTERNAL_EnableDiagnostics 's default value to 0.
  • And overwrite build/runtime/artifacts/source-build/self/src/artifacts/bin/coreclr/Linux.x64.Release/libcoreclr.so to /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.7/libcoreclr.so

@StefanJum
Copy link
Member

It works. For backup:

* Change [EXTERNAL_EnableDiagnostics](https://github.com/dotnet/runtime/blob/ef3fd8523ddc69e4f508df2d1875b088e2ee3833/src/coreclr/inc/clrconfigvalues.h#L167) 's default value to `0`.

* And overwrite `build/runtime/artifacts/source-build/self/src/artifacts/bin/coreclr/Linux.x64.Release/libcoreclr.so` to `/usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.7/libcoreclr.so`

Perfect, if it's just the libcoreclr.so we need to modify I saw we just overwrite that in the pr you opened on dynamic-apps.
We can still document the change in a README file.

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

Perfect, if it's just the libcoreclr.so we need to modify I saw we just overwrite that in the pr you opened on dynamic-apps. We can still document the change in a README file.

Done, the readme is here: https://github.com/unikraft/dynamic-apps/pull/60/files

Provided patched libcoreclr.so and origin libcoreclr.so.bak

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

I realized that unikraft doesn't support swap memory, so mlock doesn't make sense. Moreover, according to the description in [1], unikraft also doesn't support saving mmap data to file, causing msync also to be meaningless, it can simply return 0.

[1] https://github.com/unikraft/unikraft/blob/staging/lib/ukvmem/vma_file.c#L230

@i-Pear
Copy link
Member Author

i-Pear commented Jul 26, 2023

It also seems that unikraft only supports running on a single cpu. I tried to run qemu with -smp 4 but only one core is used. If so, sched_getaffinity and sched_setaffinity also seems meaningless -- there's only one cpu available.

@unikraft-bot
Copy link
Member

⚠️ Checkpatch passed with warnings

Beep boop! I ran Unikraft's checkpatch.pl support script on your pull request but it encountered warnings:

SHA commit checkpatch
783152c lib/uksched: Stub `sched_getaffinity` & `sched_setaffinity` ⚠️
34cb1ee lib/posix-mmap: Stub `mlock` & `msync`

Truncated logs starting from first warning 783152c:

WARNING:LONG_LINE: line over 80 characters
#46: FILE: lib/uksched/sched.c:396:
+UK_SYSCALL_R_DEFINE(int, sched_getaffinity, int, pid, long, cpusetsize, unsigned long*, mask)

WARNING:LONG_LINE: line over 80 characters
#63: FILE: lib/uksched/sched.c:413:
+UK_SYSCALL_R_DEFINE(int, sched_setaffinity, int, pid, long, cpusetsize, unsigned long*, mask)

total: 0 errors, 2 warnings, 39 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/tmp/build/a53d4c5b/patches/0001-lib-uksched-Stub-sched_getaffinity-sched_setaffinity.patch has style problems, please review.

NOTE: Ignored message types: ASSIGN_IN_IF FILE_PATH_CHANGES NEW_TYPEDEFS OBSOLETE

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.

View complete logs | Learn more about Unikraft's coding style and contribution guidelines.

@StefanJum
Copy link
Member

It also seems that unikraft only supports running on a single cpu. I tried to run qemu with -smp 4 but only one core is used. If so, sched_getaffinity and sched_setaffinity also seems meaningless -- there's only one cpu available.

Yes, that's being worked on, but we can go for the implementation you provided for now.

Copy link
Member

@StefanJum StefanJum left a comment

Choose a reason for hiding this comment

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

Few more comments @i-Pear, it looks fine besides those.

lib/uksched/Makefile.uk Outdated Show resolved Hide resolved
lib/uksched/sched.c Outdated Show resolved Hide resolved
lib/uksched/sched.c Outdated Show resolved Hide resolved
Signed-off-by: Tianyi Liu <i.pear@outlook.com>
Signed-off-by: Tianyi Liu <i.pear@outlook.com>
@i-Pear i-Pear requested a review from StefanJum July 28, 2023 09:41
@i-Pear
Copy link
Member Author

i-Pear commented Jul 28, 2023

Few more comments @i-Pear, it looks fine besides those.

Thanks, these have been fixed.

Copy link
Member

@StefanJum StefanJum left a comment

Choose a reason for hiding this comment

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

All good now, thank you @i-Pear.
Reviewed-by: Stefan Jumarea stefanjumarea02@gmail.com

Copy link
Contributor

@RaduNichita RaduNichita left a comment

Choose a reason for hiding this comment

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

All good with me.

Reviewed-by: Radu Nichita radunichita99@gmail.com

@RaduNichita RaduNichita self-requested a review July 30, 2023 13:12
Copy link
Contributor

@razvand razvand left a comment

Choose a reason for hiding this comment

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

Approved-by: Razvan Deaconescu razvand@unikraft.io

unikraft-bot pushed a commit that referenced this pull request Aug 7, 2023
Signed-off-by: Tianyi Liu <i.pear@outlook.com>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #1004
@unikraft-bot unikraft-bot added the ci/merged Merged by CI label Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Internal Unikraft Microlibrary ci/merged Merged by CI kind/enhancement New feature or request lang/c Issues or PRs to do with C/C++ lib/uksched topic/mm Topics pertaining to memory management topic/scheduling Topics pertaining to task scheduling topic/syscall Related to syscalls
Projects
Status: Done!
Development

Successfully merging this pull request may close these issues.

None yet

6 participants